@sigmashake/ssg 0.29.117 → 0.29.120

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.
@@ -12,7 +12,7 @@ Error generating stack: `+e.message+`
12
12
  `),children:[c.size,` `,c.size===1?`agent`:`agents`]}),(0,D.jsx)(`a`,{href:`/graph`,className:`text-[10px] font-mono uppercase tracking-wider text-sky-300 hover:text-sky-200`,title:`Open full /graph page`,children:`expand ↗`})]}),(0,D.jsxs)(`div`,{className:`flex-1 min-h-0 relative`,children:[s.length===0?(0,D.jsx)(vo,{bursts:a,paused:!1,selectedId:n,onSelect:r,burstSeq:t}):(0,D.jsx)(`div`,{className:`absolute inset-0 grid gap-1 p-1`,style:{gridTemplateColumns:`repeat(${d}, minmax(0, 1fr))`,gridAutoRows:`1fr`},children:s.map(([e,t])=>(0,D.jsx)(Eo,{sessionKey:e,bursts:t,activePanelCount:s.length,selectedId:n,onSelect:r},e))}),(0,D.jsx)(To,{className:`absolute bottom-2 left-2 z-10 max-w-[calc(100%-1rem)]`})]})]})}function ko(e,t){return e.x<t.x+t.w&&e.x+e.w>t.x&&e.y<t.y+t.h&&e.y+e.h>t.y}function Ao(e){return{id:e.id,x:e.x,y:e.y,w:e.w,h:e.h}}function jo(e,t){let n=[Ao(e)],r=t.map(Ao);r.sort((e,t)=>e.y===t.y?e.x-t.x:e.y-t.y);for(let e of r){for(;;){let t=!1;for(let r of n)if(ko(e,r)){let n=r.y+r.h;n>e.y&&(e.y=n,t=!0)}if(!t)break}n.push(e)}return n}function Mo(e){if(e.length===0)return[];let t=[...e].map(Ao).sort((e,t)=>e.y===t.y?e.x-t.x:e.y-t.y),n=[];for(let e of t){let t=!0;for(;t;){t=!1;for(let r of n)ko(e,r)&&(e.y=r.y+r.h,t=!0)}n.push(e)}return n}function No(e,t,n){let r=e.findIndex(e=>e.id===t);if(r===-1)return{panels:e.map(Ao)};let i=jo({id:e[r].id,x:n.x,y:n.y,w:n.w,h:n.h},e.filter((e,t)=>t!==r)),a=new Map(i.map(e=>[e.id,e]));return{panels:Mo(e.map(e=>a.get(e.id)).filter(Boolean))}}function Po({size:e=24,children:t,...n}){return(0,D.jsx)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,width:e,height:e,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,...n,children:t})}var Fo=e=>(0,D.jsx)(Po,{...e,children:(0,D.jsx)(`path`,{d:`M20 6 9 17l-5-5`})}),Io=e=>(0,D.jsxs)(Po,{...e,children:[(0,D.jsx)(`path`,{d:`M18 6 6 18`}),(0,D.jsx)(`path`,{d:`m6 6 12 12`})]}),Lo=e=>(0,D.jsxs)(Po,{...e,children:[(0,D.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,D.jsx)(`path`,{d:`M7 10l5 5 5-5`}),(0,D.jsx)(`path`,{d:`M12 15V3`})]}),Ro=e=>(0,D.jsxs)(Po,{...e,children:[(0,D.jsx)(`path`,{d:`M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4`}),(0,D.jsx)(`path`,{d:`M17 8l-5-5-5 5`}),(0,D.jsx)(`path`,{d:`M12 3v12`})]}),zo=e=>(0,D.jsxs)(Po,{...e,children:[(0,D.jsx)(`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`}),(0,D.jsx)(`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`}),(0,D.jsx)(`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`})]}),Bo=e=>(0,D.jsxs)(Po,{...e,children:[(0,D.jsx)(`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`}),(0,D.jsx)(`path`,{d:`m15 5 4 4`})]}),Vo=e=>(0,D.jsxs)(Po,{...e,children:[(0,D.jsx)(`path`,{d:`M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8`}),(0,D.jsx)(`path`,{d:`M3 3v5h5`})]}),Ho=e=>(0,D.jsxs)(Po,{...e,children:[(0,D.jsx)(`path`,{d:`M3 6h18`}),(0,D.jsx)(`path`,{d:`M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6`}),(0,D.jsx)(`path`,{d:`M8 6V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2`}),(0,D.jsx)(`path`,{d:`M10 11v6`}),(0,D.jsx)(`path`,{d:`M14 11v6`})]}),Uo=e=>(0,D.jsxs)(Po,{...e,children:[(0,D.jsx)(`circle`,{cx:`12`,cy:`9`,r:`1`}),(0,D.jsx)(`circle`,{cx:`19`,cy:`9`,r:`1`}),(0,D.jsx)(`circle`,{cx:`5`,cy:`9`,r:`1`}),(0,D.jsx)(`circle`,{cx:`12`,cy:`15`,r:`1`}),(0,D.jsx)(`circle`,{cx:`19`,cy:`15`,r:`1`}),(0,D.jsx)(`circle`,{cx:`5`,cy:`15`,r:`1`})]}),Wo=[`hero-metrics`,`graph`,`latency-trace`,`throughput`,`decision-mix`,`telemetry-feed`,`system-pulse`,`pending-approvals`,`recent-blocks`],Go={"hero-metrics":`Hero metrics`,graph:`Graph intelligence`,"latency-trace":`Latency trace`,throughput:`Throughput`,"decision-mix":`Decision mix`,"telemetry-feed":`Telemetry feed`,"system-pulse":`System pulse`,"pending-approvals":`Pending approvals`,"recent-blocks":`Recent blocks`},Ko={"hero-metrics":{minW:6,minH:2,defaultW:12,defaultH:2},graph:{minW:4,minH:3,defaultW:8,defaultH:5},"latency-trace":{minW:4,minH:3,defaultW:8,defaultH:4},throughput:{minW:2,minH:2,defaultW:4,defaultH:2},"decision-mix":{minW:2,minH:2,defaultW:4,defaultH:2},"telemetry-feed":{minW:6,minH:3,defaultW:12,defaultH:4},"system-pulse":{minW:4,minH:3,defaultW:12,defaultH:3},"pending-approvals":{minW:3,minH:2,defaultW:6,defaultH:3},"recent-blocks":{minW:3,minH:2,defaultW:6,defaultH:3}};function qo({panel:e,isEditing:t,children:n,drag:r}){let i=(0,_.useRef)(null),a={gridColumn:`${e.x+1} / span ${e.w}`,gridRow:`${e.y+1} / span ${e.h}`};return(0,D.jsxs)(`div`,{ref:i,className:`grid-panel ${t?`grid-panel--edit`:``}`,style:a,role:t?`region`:void 0,"aria-label":t?Go[e.id]:void 0,tabIndex:t?0:void 0,onKeyDown:t?t=>r.onPanelKeyDown(t,e.id):void 0,"data-panel-id":e.id,children:[t&&(0,D.jsx)(`button`,{type:`button`,className:`grid-panel__drag-handle`,title:`Drag ${Go[e.id]} (or Arrow keys)`,"aria-label":`Drag ${Go[e.id]}`,onPointerDown:t=>{let n=i.current;n&&r.onDragPointerDown(t,e.id,n)},children:(0,D.jsx)(Uo,{size:12,strokeWidth:2})}),(0,D.jsx)(`div`,{className:`grid-panel__content`,"data-reveal":t?void 0:``,children:n}),t&&(0,D.jsx)(`button`,{type:`button`,className:`grid-panel__resize-handle`,title:`Resize ${Go[e.id]} (or Shift+Arrow keys)`,"aria-label":`Resize ${Go[e.id]}`,onPointerDown:t=>{let n=i.current;n&&r.onResizePointerDown(t,e.id,n)},children:(0,D.jsxs)(`svg`,{width:`10`,height:`10`,viewBox:`0 0 10 10`,"aria-hidden":!0,children:[(0,D.jsx)(`path`,{d:`M10 0 L10 10 L0 10 Z`,fill:`currentColor`,fillOpacity:`0.4`}),(0,D.jsx)(`path`,{d:`M3 10 L10 3 M6 10 L10 6 M9 10 L10 9`,stroke:`currentColor`,strokeWidth:`0.8`,fill:`none`})]})})]})}var Jo=(0,_.memo)(qo);function Yo(e){let t=getComputedStyle(e),n=e.getBoundingClientRect(),r=parseFloat(t.rowGap||t.gap||`0`)||0,i=r*11;return{cellWidthPx:(n.width-i)/12+r,cellHeightPx:72+r}}function Xo(e){let t=(0,_.useRef)(null),n=(0,_.useRef)(e);n.current=e;let r=(0,_.useCallback)(()=>{let e=t.current;if(e){e.element.style.transform=``,e.element.style.width=``,e.element.style.height=``,e.element.style.zIndex=``,e.element.classList.remove(`grid-panel--dragging`),e.element.classList.remove(`grid-panel--resizing`);try{e.element.releasePointerCapture(e.pointerId)}catch{}t.current=null}},[]);(0,_.useEffect)(()=>{function e(e){let n=t.current;if(!n||e.pointerId!==n.pointerId)return;let r=e.clientX-n.startPointerX,i=e.clientY-n.startPointerY;if(n.mode===`drag`)n.element.style.transform=`translate3d(${r}px, ${i}px, 0)`;else{let e=Ko[n.startPanel.id],t=e.minW*n.cellWidthPx-n.cellWidthPx+40,a=e.minH*n.cellHeightPx-n.cellHeightPx+40,o=Math.max(t,n.startRectW+r),s=Math.max(a,n.startRectH+i);n.element.style.width=`${o}px`,n.element.style.height=`${s}px`}}function i(e,t,n){let r=Ko[e.startPanel.id];if(e.mode===`drag`){let r=Math.round(t/e.cellWidthPx),i=Math.round(n/e.cellHeightPx),a=e.startPanel.x+r,o=e.startPanel.y+i;return a<0&&(a=0),a+e.startPanel.w>12&&(a=12-e.startPanel.w),o<0&&(o=0),{id:e.id,x:a,y:o,w:e.startPanel.w,h:e.startPanel.h}}let i=Math.round(t/e.cellWidthPx),a=Math.round(n/e.cellHeightPx),o=e.startPanel.w+i,s=e.startPanel.h+a;return o<r.minW&&(o=r.minW),s<r.minH&&(s=r.minH),e.startPanel.x+o>12&&(o=12-e.startPanel.x),{id:e.id,x:e.startPanel.x,y:e.startPanel.y,w:o,h:s}}function a(e){let a=t.current;if(!a||e.pointerId!==a.pointerId)return;let o=i(a,e.clientX-a.startPointerX,e.clientY-a.startPointerY);r(),o.x===a.startPanel.x&&o.y===a.startPanel.y&&o.w===a.startPanel.w&&o.h===a.startPanel.h||n.current.onCommit(o)}function o(e){let n=t.current;!n||e.pointerId!==n.pointerId||r()}function s(e){e.key===`Escape`&&t.current&&r()}function c(){document.visibilityState===`hidden`&&t.current&&r()}return document.addEventListener(`pointermove`,e),document.addEventListener(`pointerup`,a),document.addEventListener(`pointercancel`,o),document.addEventListener(`keydown`,s),document.addEventListener(`visibilitychange`,c),()=>{document.removeEventListener(`pointermove`,e),document.removeEventListener(`pointerup`,a),document.removeEventListener(`pointercancel`,o),document.removeEventListener(`keydown`,s),document.removeEventListener(`visibilitychange`,c),t.current&&r()}},[r]);let i=(0,_.useCallback)((e,r,i,a)=>{if(!n.current.enabled||t.current)return;let o=n.current.getPanel(r),s=n.current.gridRef.current;if(!o||!s)return;e.preventDefault(),e.stopPropagation();let{cellWidthPx:c,cellHeightPx:l}=Yo(s),u=i.getBoundingClientRect();t.current={id:r,mode:a,startPointerX:e.clientX,startPointerY:e.clientY,startPanel:o,element:i,cellWidthPx:c,cellHeightPx:l,pointerId:e.pointerId,startRectW:u.width,startRectH:u.height},i.classList.add(a===`drag`?`grid-panel--dragging`:`grid-panel--resizing`),i.style.zIndex=`10`;try{i.setPointerCapture(e.pointerId)}catch{}},[]);return{onDragPointerDown:(0,_.useCallback)((e,t,n)=>i(e,t,n,`drag`),[i]),onResizePointerDown:(0,_.useCallback)((e,t,n)=>i(e,t,n,`resize`),[i]),onPanelKeyDown:(0,_.useCallback)((e,t)=>{if(!n.current.enabled)return;let r=n.current.getPanel(t);if(!r)return;let i=e.shiftKey,a=0,o=0;switch(e.key){case`ArrowLeft`:a=-1;break;case`ArrowRight`:a=1;break;case`ArrowUp`:o=-1;break;case`ArrowDown`:o=1;break;default:return}e.preventDefault(),e.stopPropagation();let s=Ko[t];if(i){let e=r.w+a,i=r.h+o;if(e<s.minW&&(e=s.minW),i<s.minH&&(i=s.minH),r.x+e>12&&(e=12-r.x),e===r.w&&i===r.h)return;n.current.onCommit({id:t,x:r.x,y:r.y,w:e,h:i})}else{let e=r.x+a,i=r.y+o;if(e<0&&(e=0),e+r.w>12&&(e=12-r.w),i<0&&(i=0),e===r.x&&i===r.y)return;n.current.onCommit({id:t,x:e,y:i,w:r.w,h:r.h})}},[]),isGesturing:(0,_.useCallback)(()=>t.current!==null,[])}}function Zo({panels:e,isEditing:t,renderers:n,onPanelsChange:r}){let i=(0,_.useRef)(null),a=(0,_.useRef)(e);a.current=e;let o=(0,_.useMemo)(()=>{let t=new Map;for(let n of e)t.set(n.id,n);return t},[e]),s=Xo({gridRef:i,getPanel:(0,_.useCallback)(e=>o.get(e),[o]),onCommit:(0,_.useCallback)(e=>{let t=a.current,{panels:n}=No(t,e.id,{x:e.x,y:e.y,w:e.w,h:e.h});r(n)},[r]),enabled:t});return(0,D.jsx)(`div`,{ref:i,className:`grid-layout ${t?`grid-layout--editing`:``}`,"aria-live":t?`polite`:void 0,children:e.map(e=>(0,D.jsx)(Jo,{panel:e,isEditing:t,drag:s,children:n[e.id]()},e.id))})}function Qo({manager:e,isEditing:t,onToggleEditing:n}){let{config:r,activeLayout:i,canAddUserLayout:a,saveError:o,selectLayout:s,saveAs:c,renameActive:l,deleteLayout:u,resetActive:d,exportConfig:f,importConfig:p}=e,[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(!1),[y,b]=(0,_.useState)(``),[x,S]=(0,_.useState)(!1),[C,w]=(0,_.useState)(i.name),[T,E]=(0,_.useState)(!1),[O,k]=(0,_.useState)(!1),ee=(0,_.useRef)(null);(0,_.useEffect)(()=>{w(i.name)},[i.name]),(0,_.useEffect)(()=>{o&&h(o)},[o]),(0,_.useEffect)(()=>{if(!m)return;let e=setTimeout(()=>h(null),4e3);return()=>clearTimeout(e)},[m]);function A(){y.trim()&&(c(y.trim()),b(``),v(!1),h(`Saved "${y.trim()}"`))}function j(){C.trim()&&(l(C.trim()),S(!1),h(`Renamed`))}function M(){let e=i.name;u(i.id),k(!1),h(`Deleted "${e}"`)}function te(){d(),E(!1),h(`Reset to default`)}function N(){let e=f(),t=new Blob([e],{type:`application/json`}),n=URL.createObjectURL(t),r=new Date().toISOString().slice(0,10),i=document.createElement(`a`);i.href=n,i.download=`ssg-layout-${r}.json`,i.click(),URL.revokeObjectURL(n),h(`Layout exported`)}function P(e){let t=e.target.files?.[0];e.target.value=``,t&&t.text().then(e=>{h(p(e).message)}).catch(()=>h(`Import failed: could not read file`))}return(0,D.jsxs)(`div`,{className:`flex items-center justify-between gap-3 rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] px-3 py-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,D.jsx)(`span`,{className:`overline shrink-0`,children:`layout`}),(0,D.jsxs)(`select`,{value:r.activeLayoutId,onChange:e=>s(e.target.value),className:`bg-[var(--color-surface-2)] border border-[var(--color-line-1)] rounded-sm px-2 py-1 text-[11px] font-mono text-[var(--color-fg-1)] hover:border-[var(--color-line-2)] focus:outline-none focus:ring-1 focus:ring-[var(--color-brand)] cursor-pointer`,"aria-label":`Select layout`,children:[(0,D.jsx)(`optgroup`,{label:`Built-in`,children:r.layouts.filter(e=>e.builtIn).map(e=>(0,D.jsx)(`option`,{value:e.id,children:e.name},e.id))}),r.layouts.some(e=>!e.builtIn)&&(0,D.jsx)(`optgroup`,{label:`Your layouts`,children:r.layouts.filter(e=>!e.builtIn).map(e=>(0,D.jsx)(`option`,{value:e.id,children:e.name},e.id))})]}),i.builtIn&&(0,D.jsx)(`span`,{className:`chip text-[var(--color-fg-3)]`,title:`Built-in preset`,children:`built-in`})]}),(0,D.jsx)(`div`,{className:`flex items-center gap-1.5 shrink-0`,children:t?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(G,{variant:`secondary`,size:`sm`,onClick:()=>v(!0),disabled:!a,title:a?`Save the current arrangement as a new preset`:`Layout limit reached — delete one first`,children:[(0,D.jsx)(zo,{size:11,strokeWidth:2.25}),`Save as`]}),!i.builtIn&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:()=>{w(i.name),S(!0)},children:[(0,D.jsx)(Bo,{size:11,strokeWidth:2.25}),`Rename`]}),(0,D.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:()=>k(!0),children:[(0,D.jsx)(Ho,{size:11,strokeWidth:2.25}),`Delete`]})]}),(0,D.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:()=>E(!0),title:`Replace the current layout with the Default preset`,children:[(0,D.jsx)(Vo,{size:11,strokeWidth:2.25}),`Reset`]}),(0,D.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:N,title:`Download current layouts as JSON`,children:[(0,D.jsx)(Lo,{size:11,strokeWidth:2.25}),`Export`]}),(0,D.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:()=>ee.current?.click(),title:`Load layouts from a JSON file`,children:[(0,D.jsx)(Ro,{size:11,strokeWidth:2.25}),`Import`]}),(0,D.jsx)(`input`,{ref:ee,type:`file`,accept:`application/json,.json`,onChange:P,className:`hidden`,"aria-hidden":!0}),(0,D.jsxs)(G,{variant:`primary`,size:`sm`,onClick:()=>n(!1),children:[(0,D.jsx)(Fo,{size:11,strokeWidth:2.5}),`Done`]})]}):(0,D.jsxs)(G,{variant:`secondary`,size:`sm`,onClick:()=>n(!0),children:[(0,D.jsx)(Bo,{size:11,strokeWidth:2.25}),`Edit layout`]})}),g&&(0,D.jsx)($o,{title:`Save layout as`,value:y,placeholder:`My dashboard`,onChange:b,onConfirm:A,onCancel:()=>{v(!1),b(``)},confirmLabel:`Save`}),x&&(0,D.jsx)($o,{title:`Rename layout`,value:C,placeholder:i.name,onChange:w,onConfirm:j,onCancel:()=>S(!1),confirmLabel:`Rename`}),T&&(0,D.jsx)(es,{title:`Reset this layout?`,body:`The current arrangement will be replaced with the Default preset. Saved layouts are not affected.`,confirmLabel:`Reset`,onConfirm:te,onCancel:()=>E(!1),destructive:!1}),O&&(0,D.jsx)(es,{title:`Delete "${i.name}"?`,body:`This layout will be removed. You can always recreate it via Save as.`,confirmLabel:`Delete`,onConfirm:M,onCancel:()=>k(!1),destructive:!0}),m&&(0,D.jsx)(`div`,{role:`status`,className:`fixed bottom-5 left-1/2 -translate-x-1/2 z-50 rounded-sm border border-[var(--color-line-2)] bg-[var(--color-surface-3)] px-3 py-2 text-[11px] font-mono text-[var(--color-fg-1)] shadow-lg`,children:m})]})}function $o({title:e,value:t,placeholder:n,onChange:r,onConfirm:i,onCancel:a,confirmLabel:o}){return(0,D.jsx)(`div`,{role:`dialog`,"aria-modal":!0,"aria-label":e,className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:a,children:(0,D.jsxs)(`div`,{onClick:e=>e.stopPropagation(),className:`w-80 rounded-sm border border-[var(--color-line-2)] bg-[var(--color-surface-2)] p-4`,children:[(0,D.jsx)(`div`,{className:`overline mb-2`,children:e}),(0,D.jsx)(`input`,{value:t,onChange:e=>r(e.target.value),placeholder:n,onKeyDown:e=>{e.key===`Enter`&&i(),e.key===`Escape`&&a()},className:`w-full bg-[var(--color-surface-1)] border border-[var(--color-line-1)] rounded-sm px-2 py-1.5 text-[13px] font-mono text-[var(--color-fg-1)] focus:outline-none focus:border-[var(--color-brand)]`}),(0,D.jsxs)(`div`,{className:`mt-3 flex justify-end gap-2`,children:[(0,D.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:a,children:[(0,D.jsx)(Io,{size:11,strokeWidth:2.25}),`Cancel`]}),(0,D.jsx)(G,{variant:`primary`,size:`sm`,onClick:i,children:o})]})]})})}function es({title:e,body:t,confirmLabel:n,destructive:r,onConfirm:i,onCancel:a}){return(0,D.jsx)(`div`,{role:`dialog`,"aria-modal":!0,"aria-label":e,className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 backdrop-blur-sm`,onClick:a,children:(0,D.jsxs)(`div`,{onClick:e=>e.stopPropagation(),className:`w-96 rounded-sm border border-[var(--color-line-2)] bg-[var(--color-surface-2)] p-4`,children:[(0,D.jsx)(`div`,{className:`overline mb-2`,children:e}),(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-2)] leading-relaxed`,children:t}),(0,D.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,D.jsx)(G,{variant:`ghost`,size:`sm`,onClick:a,children:`Cancel`}),(0,D.jsx)(G,{variant:r?`danger`:`primary`,size:`sm`,onClick:i,children:n})]})]})})}var ts={default:`builtin-default`,focusLatency:`builtin-focus-latency`,focusApprovals:`builtin-focus-approvals`,compact:`builtin-compact`},ns={id:ts.default,name:`Default`,builtIn:!0,panels:[{id:`hero-metrics`,x:0,y:0,w:12,h:2},{id:`graph`,x:0,y:2,w:8,h:5},{id:`latency-trace`,x:8,y:2,w:4,h:3},{id:`throughput`,x:8,y:5,w:2,h:2},{id:`decision-mix`,x:10,y:5,w:2,h:2},{id:`telemetry-feed`,x:0,y:7,w:12,h:3},{id:`system-pulse`,x:0,y:10,w:12,h:3},{id:`pending-approvals`,x:0,y:13,w:6,h:3},{id:`recent-blocks`,x:6,y:13,w:6,h:3}]},rs={id:ts.focusLatency,name:`Focus · Latency`,builtIn:!0,panels:[{id:`hero-metrics`,x:0,y:0,w:12,h:2},{id:`latency-trace`,x:0,y:2,w:8,h:5},{id:`graph`,x:8,y:2,w:4,h:5},{id:`throughput`,x:0,y:7,w:6,h:2},{id:`decision-mix`,x:6,y:7,w:6,h:2},{id:`system-pulse`,x:0,y:9,w:12,h:3},{id:`telemetry-feed`,x:0,y:12,w:12,h:3},{id:`pending-approvals`,x:0,y:15,w:6,h:2},{id:`recent-blocks`,x:6,y:15,w:6,h:2}]},is={id:ts.focusApprovals,name:`Focus · Approvals`,builtIn:!0,panels:[{id:`pending-approvals`,x:0,y:0,w:8,h:4},{id:`graph`,x:8,y:0,w:4,h:4},{id:`recent-blocks`,x:0,y:4,w:12,h:3},{id:`hero-metrics`,x:0,y:7,w:12,h:2},{id:`latency-trace`,x:0,y:9,w:6,h:3},{id:`telemetry-feed`,x:6,y:9,w:6,h:3},{id:`system-pulse`,x:0,y:12,w:12,h:3},{id:`throughput`,x:0,y:15,w:6,h:2},{id:`decision-mix`,x:6,y:15,w:6,h:2}]},as={id:ts.compact,name:`Compact`,builtIn:!0,panels:[{id:`hero-metrics`,x:0,y:0,w:12,h:2},{id:`graph`,x:0,y:2,w:8,h:3},{id:`latency-trace`,x:8,y:2,w:4,h:3},{id:`system-pulse`,x:0,y:5,w:12,h:3},{id:`throughput`,x:0,y:8,w:4,h:2},{id:`decision-mix`,x:4,y:8,w:4,h:2},{id:`telemetry-feed`,x:0,y:10,w:12,h:3},{id:`pending-approvals`,x:0,y:13,w:6,h:2},{id:`recent-blocks`,x:6,y:13,w:6,h:2}]},os=Object.freeze([ns,rs,is,as]);function ss(){return os.map(e=>({...e,panels:e.panels.map(e=>({...e}))}))}function cs(){return{version:1,activeLayoutId:ts.default,layouts:ss()}}function ls(e){return Object.values(ts).includes(e)}var us=new Set(Wo),ds=new Set(os.map(e=>e.id));function fs(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function ps(e,t,n,r){if(typeof e!=`number`||!Number.isFinite(e))return r;let i=Math.floor(e);return i<t?t:i>n?n:i}function ms(e,t){let n=(typeof e==`string`?e:``).replace(/[\u0000-\u001F\u007F]/g,``).trim();return n.length===0?t:n.slice(0,40)}function hs(e){let t=e.find(e=>e.id===`system-pulse`);if(!t||t.h>=3)return e;let n=3-t.h,r=t.y+t.h;return e.map(e=>e.id===`system-pulse`?{...e,h:3}:e.y>=r?{...e,y:e.y+n}:e)}function gs(e){for(let t=0;t<e.length;t++){let n=e[t];for(let r=t+1;r<e.length;r++){let t=e[r];if(n.x<t.x+t.w&&n.x+n.w>t.x&&n.y<t.y+t.h&&n.y+n.h>t.y)return!0}}return!1}function _s(e){if(!fs(e))return null;let{id:t}=e;if(typeof t!=`string`||!us.has(t))return null;let n=t,r=Ko[n],i=ps(e.x,0,11,0),a=ps(e.w,r.minW,12,r.defaultW);return{id:n,x:i+a>12?12-a:i,y:ps(e.y,0,999,0),w:a,h:ps(e.h,r.minH,99,r.defaultH)}}function vs(e,t){if(!fs(e))return{layout:null,droppedPanels:0};let n=typeof e.id==`string`&&e.id.length>0?e.id:null;if(!n)return{layout:null,droppedPanels:0};let r=ms(e.name,t),i=ds.has(n),a=e.panels;if(!Array.isArray(a))return{layout:null,droppedPanels:0};let o=new Set,s=[],c=0;for(let e of a){let t=_s(e);if(!t){c+=1;continue}if(o.has(t.id)){c+=1;continue}o.add(t.id),s.push(t)}return s.length===0?{layout:null,droppedPanels:c}:{layout:{id:n,name:r,builtIn:i,panels:hs(s)},droppedPanels:c}}function ys(e){if(!fs(e)||e.version!==1)return{config:cs(),droppedPanels:0,prunedLayouts:0,fellBackToDefault:!0};let t=e.layouts;if(!Array.isArray(t)||t.length===0)return{config:cs(),droppedPanels:0,prunedLayouts:0,fellBackToDefault:!0};let n=[],r=0,i=0,a=0;for(let e of t){let{layout:t,droppedPanels:o}=vs(e,`Layout ${n.length+1}`);if(r+=o,t){if(!t.builtIn){if(i>=12){a+=1;continue}i+=1}n.push(t)}}if(n.length===0)return{config:cs(),droppedPanels:r,prunedLayouts:a,fellBackToDefault:!0};let o=new Set(n.map(e=>e.id));for(let e of os)o.has(e.id)||n.push({...e,panels:e.panels.map(e=>({...e}))});let s=new Map(os.map(e=>[e.id,e])),c=0,l=0;for(let e=0;e<n.length;e++){let t=n[e],r=s.get(t.id);if(!r)continue;if(gs(t.panels)){n[e]={...r,panels:r.panels.map(e=>({...e}))},l+=1;continue}let i=new Set(t.panels.map(e=>e.id)),a=r.panels.filter(e=>!i.has(e.id));if(a.length===0)continue;let o=t.panels.reduce((e,t)=>Math.max(e,t.y+t.h),0);for(let e of a)t.panels.push({id:e.id,x:0,y:o,w:e.w,h:e.h}),o+=e.h,c+=1}let u=e.activeLayoutId;return{config:{version:1,activeLayoutId:typeof u==`string`&&n.some(e=>e.id===u)?u:os[0].id,layouts:n},droppedPanels:r,prunedLayouts:a,fellBackToDefault:!1,backfilledPanels:c,refreshedBuiltins:l}}var bs=`ssg:dashboard-layout:v1`,xs=300;function Ss(){if(typeof localStorage>`u`)return null;try{let e=`__ssg_probe__`;return localStorage.setItem(e,`1`),localStorage.removeItem(e),localStorage}catch{return null}}var Cs;function ws(){return Cs===void 0&&(Cs=Ss()),Cs}function Ts(){let e=ws();if(!e)return{config:cs(),droppedPanels:0,prunedLayouts:0,fellBackToDefault:!1};let t=null;try{t=e.getItem(bs)}catch{t=null}if(t===null)return{config:cs(),droppedPanels:0,prunedLayouts:0,fellBackToDefault:!1};let n=null;try{n=JSON.parse(t)}catch{return{config:cs(),droppedPanels:0,prunedLayouts:0,fellBackToDefault:!0}}return ys(n)}var Es=null,Ds=null,Os=null;function ks(e){return Os=e,()=>{Os===e&&(Os=null)}}function As(e){Os?Os(e):typeof console<`u`&&console.warn(`[ssg-layout]`,e)}function js(){if(Ds=null,!Es)return;let e=ws();if(!e){Es=null;return}let t=Es;Es=null;try{e.setItem(bs,JSON.stringify(t))}catch(e){e instanceof Error&&e.name===`QuotaExceededError`?As(`Layout storage full — save skipped`):As(`Layout save failed: ${e instanceof Error?e.message:String(e)}`)}}function Ms(e){Es=e,Ds===null&&(Ds=setTimeout(js,xs))}function Ns(e){Es=e,Ds!==null&&(clearTimeout(Ds),Ds=null),js()}function Ps(e){let t=0;for(let n of e.layouts)n.builtIn||(t+=1);return t}function Fs(e){return e.map(e=>({...e}))}function Is(){return`user-${Math.random().toString(16).slice(2,11)}`}function Ls(){let[e,t]=(0,_.useState)(()=>Ts().config),[n,r]=(0,_.useState)(null);(0,_.useEffect)(()=>ks(e=>r(e)),[]),(0,_.useEffect)(()=>{Ms(e)},[e]);let i=e.layouts.find(t=>t.id===e.activeLayoutId)??e.layouts[0]??ss()[0],a=Ps(e)<12,o=(0,_.useCallback)(e=>{t(t=>t.layouts.some(t=>t.id===e)?{...t,activeLayoutId:e}:t)},[]),s=(0,_.useCallback)(e=>{t(t=>{let n=t.activeLayoutId;return{...t,layouts:t.layouts.map(t=>t.id===n?{...t,panels:Fs(e)}:t)}})},[]),c=(0,_.useCallback)(e=>{let n=e.trim();n&&t(e=>{if(Ps(e)>=12)return e;let t=e.layouts.find(t=>t.id===e.activeLayoutId)??e.layouts[0];if(!t)return e;let r={id:Is(),name:n,builtIn:!1,panels:Fs(t.panels)};return{...e,activeLayoutId:r.id,layouts:[...e.layouts,r]}})},[]),l=(0,_.useCallback)(e=>{let n=e.trim();n&&t(e=>({...e,layouts:e.layouts.map(t=>t.id===e.activeLayoutId&&!t.builtIn?{...t,name:n}:t)}))},[]),u=(0,_.useCallback)(e=>{t(t=>{let n=t.layouts.find(t=>t.id===e);if(!n||n.builtIn)return t;let r=t.layouts.filter(t=>t.id!==e),i=t.activeLayoutId===e?r[0]?.id??os[0]?.id:t.activeLayoutId;return{...t,activeLayoutId:i,layouts:r}})},[]),d=(0,_.useCallback)(()=>{t(e=>{let t=e.layouts.find(t=>t.id===e.activeLayoutId);if(!t)return e;let n=ls(t.id)?os.find(e=>e.id===t.id):os[0];return n?{...e,layouts:e.layouts.map(e=>e.id===t.id?{...e,panels:Fs(n.panels)}:e)}:e})},[]),f=(0,_.useCallback)(()=>JSON.stringify(e,null,2),[e]),p=(0,_.useCallback)(e=>{let n;try{n=JSON.parse(e)}catch{return{ok:!1,message:`Import failed: not valid JSON`}}let r=ys(n);if(r.fellBackToDefault)return{ok:!1,message:`Import rejected: schema invalid, no changes applied`};t(r.config),Ns(r.config);let i=[`Layout imported`];return r.droppedPanels>0&&i.push(`${r.droppedPanels} unrecognized panel(s) dropped`),r.prunedLayouts>0&&i.push(`${r.prunedLayouts} excess layout(s) pruned`),{ok:!0,message:i.join(` · `)}},[]);return(0,_.useEffect)(()=>{e.layouts.length===0&&t(cs())},[e.layouts.length]),{config:e,activeLayout:i,canAddUserLayout:a,saveError:n,selectLayout:o,updateActivePanels:s,saveAs:c,renameActive:l,deleteLayout:u,resetActive:d,exportConfig:f,importConfig:p}}var Rs=[`rules-changed`,`activity-updated`,`pending-changed`,`runtime-tick`,`limits-breach`],zs={critical:{border:`border-l-red-500/70`,iconBg:`bg-red-500/15`,iconFg:`text-red-400`,chipBg:`bg-red-500/10`,chipFg:`text-red-300`,label:`Critical`},warning:{border:`border-l-amber-400/70`,iconBg:`bg-amber-500/15`,iconFg:`text-amber-300`,chipBg:`bg-amber-500/10`,chipFg:`text-amber-200`,label:`Heads up`},info:{border:`border-l-sky-500/70`,iconBg:`bg-sky-500/15`,iconFg:`text-sky-300`,chipBg:`bg-sky-500/10`,chipFg:`text-sky-200`,label:`Tip`}};function Bs({severity:e}){return e===`critical`?(0,D.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,D.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,D.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]}):e===`warning`?(0,D.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`}),(0,D.jsx)(`line`,{x1:`12`,y1:`9`,x2:`12`,y2:`13`}),(0,D.jsx)(`line`,{x1:`12`,y1:`17`,x2:`12.01`,y2:`17`})]}):(0,D.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,D.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12`,y2:`12`}),(0,D.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12.01`,y2:`8`})]})}function Vs({notification:e,onAction:t}){let[n,r]=(0,_.useState)(`idle`),[i,a]=(0,_.useState)(null),o=zs[e.severity];return(0,D.jsxs)(`div`,{className:`hig-card border-l-2 ${o.border} flex items-start gap-3 px-3 py-2.5`,children:[(0,D.jsx)(`span`,{className:`shrink-0 mt-0.5 inline-flex items-center justify-center w-6 h-6 rounded-full ${o.iconBg} ${o.iconFg}`,"aria-hidden":!0,children:(0,D.jsx)(Bs,{severity:e.severity})}),(0,D.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,D.jsx)(`span`,{className:`text-[9px] font-mono font-medium uppercase tracking-wider px-1.5 py-0.5 rounded ${o.chipBg} ${o.chipFg}`,children:o.label}),(0,D.jsx)(`h3`,{className:`text-[13px] font-medium text-[var(--color-fg-0)] leading-tight`,children:e.title})]}),(0,D.jsx)(`p`,{className:`mt-1 text-[12px] text-[var(--color-fg-2)] leading-relaxed`,children:e.detail}),n===`error`&&i&&(0,D.jsxs)(`p`,{className:`mt-1.5 text-[11px] font-mono text-red-300`,children:[`Failed: `,i]}),n===`done`&&(0,D.jsx)(`p`,{className:`mt-1.5 text-[11px] font-mono text-emerald-300`,children:`✓ Done — refreshing…`})]}),(0,D.jsx)(`div`,{className:`shrink-0 self-center`,children:e.action?(0,D.jsx)(`button`,{type:`button`,onClick:async()=>{if(e.action&&!(e.action.confirm&&!confirm(e.action.confirm))){r(`loading`),a(null);try{await t(e),r(`done`)}catch(e){r(`error`),a(e instanceof Error?e.message:String(e))}}},disabled:n===`loading`||n===`done`,className:`inline-flex items-center gap-1 h-8 px-3 rounded-sm text-[11px] font-medium uppercase tracking-wider bg-[var(--color-surface-2)] text-[var(--color-fg-1)] border border-[var(--color-line-1)] hover:bg-[var(--color-surface-3)] hover:border-[var(--color-line-2)] transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed whitespace-nowrap`,children:n===`loading`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{className:`animate-spin`,children:`⟳`}),` working…`]}):n===`done`?(0,D.jsx)(D.Fragment,{children:`✓ done`}):e.action.label}):e.link?(0,D.jsxs)(`a`,{href:e.link.href,className:`inline-flex items-center gap-1 h-8 px-3 rounded-sm text-[11px] font-medium uppercase tracking-wider bg-[var(--color-surface-2)] text-[var(--color-fg-1)] border border-[var(--color-line-1)] hover:bg-[var(--color-surface-3)] hover:border-[var(--color-line-2)] transition-colors whitespace-nowrap`,children:[e.link.label,` →`]}):null})]})}function Hs({showEmptyState:e=!1,hideHeader:t=!1}={}){let n=V(Rs),{data:r,refetch:i}=k(`/api/json/maintenance`,[n[`rules-changed`],n[`activity-updated`],n[`pending-changed`],n[`runtime-tick`],n[`limits-breach`]]),a=async e=>{if(!e.action)return;let t=await fetch(e.action.url,{method:e.action.method,headers:{Accept:`application/json`,"Content-Type":`application/json`,...U()}});if(!t.ok){let e=await t.text().catch(()=>``);throw Error(e||`HTTP ${t.status}`)}setTimeout(()=>i(),600)},o=r?.notifications??[];return o.length===0&&!e?null:(0,D.jsxs)(`section`,{"data-reveal":!0,children:[!t&&(0,D.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,D.jsx)(`h2`,{className:`overline text-[11px]`,children:o.length===0?`maintenance · all clear`:`maintenance · ${o.length} item${o.length===1?``:`s`}`}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>i(),className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] transition-colors cursor-pointer`,title:`Re-check now`,children:`refresh`})]}),o.length===0?(0,D.jsxs)(`div`,{className:`hig-card border-l-2 border-l-emerald-500/60 px-4 py-5 flex items-center gap-3`,children:[(0,D.jsx)(`span`,{className:`inline-flex items-center justify-center w-8 h-8 rounded-full bg-emerald-500/15 text-emerald-300 shrink-0`,children:(0,D.jsx)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,D.jsx)(`path`,{d:`M20 6L9 17l-5-5`})})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h3`,{className:`text-[13px] font-medium text-[var(--color-fg-0)] leading-tight`,children:`Everything looks good`}),(0,D.jsx)(`p`,{className:`mt-1 text-[12px] text-[var(--color-fg-2)] leading-relaxed`,children:`No drift, no capacity warnings, no stalled daemons. We'll let you know if anything changes.`})]})]}):(0,D.jsx)(`div`,{className:`space-y-2`,children:o.map(e=>(0,D.jsx)(Vs,{notification:e,onAction:a},e.id))})]})}var Us=e=>Math.max(0,Math.round(e)).toLocaleString(void 0,{useGrouping:!0});function Ws(e,t){if(e===`spring`){let e=lr();return{ease:e.fn,durationMs:e.duration}}return e===`quart`?{ease:Gn.out,durationMs:t}:{ease:Wn.out,durationMs:t}}var Gs=250;function Ks({value:e,duration:t=320,format:n=Us,className:r,curve:i=`cubic`}){let[a,o]=(0,_.useState)(e),s=(0,_.useRef)(e),c=(0,_.useRef)(e),l=(0,_.useRef)(0),u=(0,_.useRef)(null),d=(0,_.useRef)(_r()),f=(0,_.useRef)(null),p=(0,_.useRef)(0);return p.current===0&&(p.current=performance.now()),(0,_.useEffect)(()=>{if(c.current===e)return;if(performance.now()-p.current<Gs){c.current=e,s.current=e,o(e);return}let n=f.current;if(n&&!d.current){for(let e of n.getAnimations())e.id===`lc-value-pulse`&&e.cancel();let e=n.animate([{textShadow:`0 0 0 rgba(245, 158, 11, 0)`},{textShadow:`0 0 10px rgba(245, 158, 11, 0.55)`,offset:.2},{textShadow:`0 0 0 rgba(245, 158, 11, 0)`}],{duration:520,easing:`ease-out`});e.id=`lc-value-pulse`}if(d.current){c.current=e,s.current=e,o(e);return}s.current=a,c.current=e,l.current=performance.now(),u.current!==null&&cancelAnimationFrame(u.current);let{ease:r,durationMs:m}=Ws(i,t),h=e=>{let t=Math.min(1,(e-l.current)/m),n=r(t);o(s.current+(c.current-s.current)*n),t<1?u.current=requestAnimationFrame(h):u.current=null};return u.current=requestAnimationFrame(h),()=>{u.current!==null&&(cancelAnimationFrame(u.current),u.current=null)}},[e,t,i,a]),(0,D.jsx)(`span`,{ref:f,className:In(`tabular-nums`,r),children:n(a)})}function qs({counters:e,className:t,showLegend:n=!0}){let r=[{key:`allow`,label:`Allow`,value:e.allow,color:`var(--color-decision-allow)`,textClass:`text-emerald-300`},{key:`ask`,label:`Ask`,value:e.ask,color:`var(--color-decision-ask)`,textClass:`text-amber-300`},{key:`block`,label:`Block`,value:e.block,color:`var(--color-decision-block)`,textClass:`text-red-300`},{key:`force`,label:`Force`,value:e.force,color:`var(--color-decision-force)`,textClass:`text-sky-300`},{key:`log`,label:`Log`,value:e.log,color:`var(--color-decision-log)`,textClass:`text-violet-300`},{key:`shadow`,label:`Shadow`,value:e.shadow,color:`var(--color-decision-shadow)`,textClass:`text-[var(--color-fg-3)]`}],i=r.reduce((e,t)=>e+t.value,0),a=(0,_.useRef)(null),o=(0,_.useRef)({});return(0,_.useEffect)(()=>{let e=a.current;if(!e)return;let t=e.querySelectorAll(`[data-seg]`);if(t.length===0)return;let n=_r();t.forEach(e=>{let t=e.dataset.seg,a=r.find(e=>e.key===t);if(!a)return;let s=i===0?0:a.value/i*100,c=o.current[t]??0;n||Math.abs(c-s)<.01?e.style.width=`${s}%`:Fr(e,{width:[`${c}%`,`${s}%`],duration:480,ease:`outExpo`}),o.current[t]=s})},[i,r.find]),(0,D.jsxs)(`div`,{className:In(`flex flex-col gap-2`,t),children:[(0,D.jsx)(`div`,{ref:a,className:`flex h-3 w-full overflow-hidden rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-2)]`,children:i===0?(0,D.jsx)(`div`,{className:`w-full bg-[var(--color-surface-3)]`}):r.map(e=>(0,D.jsx)(`div`,{"data-seg":e.key,style:{width:`${i===0?0:e.value/i*100}%`,background:e.color}},e.key))}),n?(0,D.jsx)(`div`,{className:`grid grid-cols-2 gap-x-3 gap-y-1 text-[11px] font-mono`,children:r.map(e=>(0,D.jsxs)(`div`,{className:`flex items-center justify-between gap-2 min-w-0`,children:[(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5 min-w-0`,children:[(0,D.jsx)(`span`,{className:`h-2 w-2 shrink-0 rounded-sm`,style:{background:e.color}}),(0,D.jsx)(`span`,{className:In(`uppercase tracking-wide truncate`,e.textClass),children:e.label})]}),(0,D.jsx)(Ks,{value:e.value,className:`shrink-0 tabular-nums text-[var(--color-fg-1)]`})]},e.key))}):null]})}function Js({data:e,width:t=80,height:n=24,color:r=`#38bdf8`,threshold:i,maxValue:a}){if(e.length<2)return(0,D.jsx)(`svg`,{width:t,height:n,className:`shrink-0`,children:(0,D.jsx)(`line`,{x1:0,y1:n/2,x2:t,y2:n/2,stroke:`var(--color-line-2)`,strokeWidth:1})});let o=a??Math.max(...e,1),s=t-2,c=n-2,l=e.map((t,n)=>{let r=1+n/(e.length-1)*s,i=1+c-t/o*c;return`${r.toFixed(1)},${i.toFixed(1)}`}),u=i===void 0?null:1+c-Math.min(i,o)/o*c;return(0,D.jsxs)(`svg`,{width:t,height:n,className:`shrink-0`,children:[(0,D.jsx)(`polyline`,{points:l.join(` `),fill:`none`,stroke:r,strokeWidth:1.5,strokeLinejoin:`round`,strokeLinecap:`round`}),u!==null&&(0,D.jsx)(`line`,{x1:1,y1:u,x2:t-1,y2:u,stroke:`var(--color-brand)`,strokeWidth:1,strokeDasharray:`3,2`,opacity:.7})]})}function Ys(){return typeof window>`u`||!window.matchMedia?!1:window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}function Xs({value:e,samples:t,maxValue:n,width:r=320,height:i=64,windowMs:a=6e4,color:o=`var(--color-brand)`,fillColor:s=`rgba(245, 158, 11, 0.12)`,className:c}){let l=(0,_.useRef)(null),u=(0,_.useRef)(null),d=(0,_.useRef)([]),f=(0,_.useRef)(t??null),p=(0,_.useRef)(e??0),m=(0,_.useRef)(Ys());return(0,_.useEffect)(()=>{f.current=t??null},[t]),(0,_.useEffect)(()=>{t===void 0&&e!==void 0&&e!==p.current&&(p.current=e,d.current.push({ts:Date.now(),v:e}),d.current.length>600&&d.current.splice(0,d.current.length-600))},[e,t]),(0,_.useEffect)(()=>{let e=()=>{let e=Date.now(),t=e-a,o;if(f.current){let e=f.current;o=[];for(let n of e)n.ts>=t&&o.push(n)}else{let n=d.current;for(;n.length>1&&n[1]?.ts<t;)n.shift();(n.length===0||n[n.length-1]?.ts<e-200)&&n.push({ts:e,v:p.current}),o=n.filter(e=>e.ts>=t)}if(o.length<2)l.current&&l.current.setAttribute(`points`,``),u.current&&u.current.setAttribute(`points`,``);else{let e=n??Math.max(1,...o.map(e=>e.v)),s=[];for(let n of o){let o=(n.ts-t)/a*r,c=i-n.v/e*(i-2)-1;s.push(`${o.toFixed(1)},${c.toFixed(1)}`)}let c=s.join(` `);if(l.current&&l.current.setAttribute(`points`,c),u.current){let e=s[0]?.split(`,`),t=s[s.length-1]?.split(`,`),n=`${e[0]},${i} ${c} ${t[0]},${i}`;u.current.setAttribute(`points`,n)}}};if(m.current){let t=window.setInterval(e,500);return()=>clearInterval(t)}let[t]=$a(e);return t},[r,i,a,n]),(0,D.jsxs)(`svg`,{width:`100%`,height:i,viewBox:`0 0 ${r} ${i}`,className:In(`block`,c),preserveAspectRatio:`none`,children:[(0,D.jsx)(`polygon`,{ref:u,fill:s,stroke:`none`}),(0,D.jsx)(`polyline`,{ref:l,fill:`none`,stroke:o,strokeWidth:1.5,strokeLinejoin:`round`,strokeLinecap:`round`})]})}var Zs=En(`hero-metric relative flex flex-col gap-2 rounded-sm border bg-[var(--color-surface-1)] border-[var(--color-line-1)] px-4 py-3 overflow-hidden`,{variants:{tone:{neutral:`hero-metric--neutral`,amber:`hero-metric--amber`,green:`hero-metric--green`,red:`hero-metric--red`,blue:`hero-metric--blue`,purple:`hero-metric--purple`,gray:`hero-metric--gray`}},defaultVariants:{tone:`neutral`}}),Qs={neutral:`var(--color-fg-1)`,amber:`var(--color-decision-ask)`,green:`var(--color-decision-allow)`,red:`var(--color-decision-block)`,blue:`var(--color-decision-force)`,purple:`var(--color-decision-log)`,gray:`var(--color-fg-3)`},$s={neutral:`color-mix(in srgb, var(--color-fg-1) 10%, transparent)`,amber:`color-mix(in srgb, var(--color-decision-ask) 14%, transparent)`,green:`color-mix(in srgb, var(--color-decision-allow) 14%, transparent)`,red:`color-mix(in srgb, var(--color-decision-block) 14%, transparent)`,blue:`color-mix(in srgb, var(--color-decision-force) 14%, transparent)`,purple:`color-mix(in srgb, var(--color-decision-log) 14%, transparent)`,gray:`color-mix(in srgb, var(--color-fg-3) 10%, transparent)`},ec={neutral:`text-[var(--color-fg-0)]`,amber:`text-amber-300`,green:`text-emerald-300`,red:`text-red-300`,blue:`text-sky-300`,purple:`text-violet-300`,gray:`text-[var(--color-fg-2)]`},tc=1e3,nc=.35;function rc(e,t,n){let r=Date.now(),i=r-n,a=Math.max(2,Math.floor(n/tc)),o=Array(a).fill(0);for(let n of e){if(t&&!t(n)||n.ts_ms<i||n.ts_ms>r)continue;let e=a-1-Math.floor((r-n.ts_ms)/tc);e>=0&&e<a&&o[e]++}let s=Array(a),c=o[0];for(let e=0;e<a;e++)c=nc*o[e]+(1-nc)*c,s[e]={ts:i+(e+1)*tc,v:c};return s}function ic({label:e,value:t,series:n,burstRing:r,filter:i,sparkWindowMs:a=6e4,sub:o,tone:s,format:c,className:l,...u}){let d=s??`neutral`,f=Qs[d]??Qs.neutral,p=$s[d]??$s.neutral,m=ec[d]??ec.neutral,h=(0,_.useRef)(null),g=(0,_.useRef)(t);(0,_.useEffect)(()=>{if(g.current===t)return;g.current=t;let e=h.current;e&&Fr(e,{"--tick":[0,1],duration:160,ease:`outCubic`,onComplete:()=>{Fr(e,{"--tick":[1,0],duration:520,ease:`outCubic`,onComplete:e=>{e.style.removeProperty(`--tick`)}})}})},[t]);let v=(0,_.useMemo)(()=>r?rc(r,i,a):null,[r,i,a]),y=v!==null,b=!y&&n&&n.length>=2;return(0,D.jsxs)(`div`,{ref:h,className:In(Zs({tone:s,className:l})),...u,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:e}),o?(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)] tabular-nums`,children:o}):null]}),(0,D.jsxs)(`div`,{className:`flex items-end justify-between gap-3`,children:[(0,D.jsx)(Ks,{value:t,format:c,className:In(`text-[2.4rem] leading-none font-semibold tracking-tight`,m)}),y?(0,D.jsx)(Xs,{samples:v,width:108,height:36,windowMs:a,color:f,fillColor:p,className:`shrink-0`}):b?(0,D.jsx)(Js,{data:n,width:96,height:28,color:f}):null]})]})}var ac={containerPaddingY:24,containerPaddingX:24,topToTrendGap:12,scatterHeaderH:18,scatterLegendH:16,scatterInnerGap:8,trendRowH:28,trendRowGap:6,trendTopPad:9,scatterAbsoluteMin:60,scatterAcceptableMin:70,gaugeFootprintFactor:1.36,gaugeAbsoluteMin:84,gaugeAbsoluteMax:240};function oc(e,t,n=200){let r=Math.max(0,Math.floor(e)),i=Math.max(0,Math.floor(t)),a=Math.max(0,r-ac.containerPaddingX),o=Math.max(0,i-ac.containerPaddingY),s=o-(ac.trendRowH*3+ac.trendRowGap*2+ac.trendTopPad+ac.topToTrendGap),c=s-ac.scatterHeaderH-ac.scatterLegendH-ac.scatterInnerGap>=ac.scatterAcceptableMin,l=c?s:o,u=l-ac.scatterHeaderH-ac.scatterLegendH-ac.scatterInnerGap,d=u>=ac.scatterAbsoluteMin,f=u>=ac.scatterAbsoluteMin&&l>=140,p=Math.floor(l/ac.gaugeFootprintFactor),m=Math.floor(a*.45/ac.gaugeFootprintFactor),h=Math.max(ac.gaugeAbsoluteMin,Math.min(ac.gaugeAbsoluteMax,n,p,m)),g=Math.ceil(h*ac.gaugeFootprintFactor+8),_=l-(d?ac.scatterHeaderH:0)-(f?ac.scatterLegendH:0)-ac.scatterInnerGap;return{gaugeSize:h,gaugeColumnMaxWidth:g,scatterMinHeight:Math.max(ac.scatterAbsoluteMin,Math.min(160,_)),showTrendRows:c,showScatterHeader:d,showLegend:f,variant:o>=480?`wide`:o>=300?`normal`:`compact`}}var sc=135,cc=405,lc=cc-sc,uc=`#34d399`,dc=`#f59e0b`,fc=`#ef4444`;function pc(e,t,n,r){let i=(r-90)*(Math.PI/180);return{x:e+n*Math.cos(i),y:t+n*Math.sin(i)}}function mc(e,t,n,r,i){let a=pc(e,t,n,r),o=pc(e,t,n,i),s=+(i-r>180);return`M ${a.x.toFixed(2)} ${a.y.toFixed(2)} A ${n} ${n} 0 ${s} 1 ${o.x.toFixed(2)} ${o.y.toFixed(2)}`}function hc(e,t){return sc+Math.max(0,Math.min(1,e/Math.max(t,1e-9)))*lc}function gc(e,t,n){return e+(t-e)*n}function _c(e){let t=parseInt(e.slice(1),16);return[t>>16&255,t>>8&255,t&255]}function vc(e,t,n){let[r,i,a]=_c(e),[o,s,c]=_c(t);return`rgb(${Math.round(gc(r,o,n))},${Math.round(gc(i,s,n))},${Math.round(gc(a,c,n))})`}function yc(e,t,n){let r=.04;return e<t-r?uc:e<t+r?vc(uc,dc,(e-(t-r))/(r*2)):e<n-r?dc:e<n+r?vc(dc,fc,(e-(n-r))/(r*2)):fc}function bc(){return typeof window>`u`||!window.matchMedia?!1:window.matchMedia(`(prefers-reduced-motion: reduce)`).matches}var xc=0;function Sc(){return xc=xc+1|0,xc.toString(36)}function Cc({value:e,max:t,warnAt:n=.7,critAt:r=.9,marker50:i,marker99:a,label:o,display:s,displayFormat:c,scaleLabels:l,mode:u=`needle`,size:d=180,className:f,revLights:p=!0,revLightCount:m=20}){let h=Math.ceil(u===`needle`&&l!==void 0?d*.2:d*.08),g=-h,v=-h,y=d+h*2,b=d+h*2,x=d/2,S=d/2,C=d*.42,w=Math.max(0,Math.min(1,e/Math.max(t,1e-9))),T=(0,_.useMemo)(()=>mc(x,S,C,sc,cc),[x,S,C]),E=(0,_.useMemo)(()=>mc(x,S,C-8,sc,cc),[x,S,C]),O=sc+n*lc,k=sc+r*lc,ee=(0,_.useMemo)(()=>mc(x,S,C,sc,O),[x,S,C,O]),A=(0,_.useMemo)(()=>mc(x,S,C,O,k),[x,S,C,O,k]),j=(0,_.useMemo)(()=>mc(x,S,C,k,cc),[x,S,C,k]),M=(0,_.useMemo)(()=>mc(x,S,C-14,300,420),[x,S,C]),te=sc+w*lc,N=(0,_.useMemo)(()=>mc(x,S,C,sc,Math.max(sc+.01,te)),[x,S,C,te]),P=yc(w,n,r),F=(0,_.useMemo)(()=>Sc(),[]),I=`lgf-${F}`,ne=`lgb-${F}`,re=`lgd-${F}`,ie=`lgh-${F}`,L=`lgg-${F}`,R=`lgl-${F}`,ae=(0,_.useMemo)(()=>{if(u!==`needle`)return[];let e=[];for(let t=0;t<=10;t++)e.push(sc+t/10*lc);return e},[u]),oe=(0,_.useMemo)(()=>{if(u!==`needle`)return[];let e=[];for(let t=0;t<=40;t++)t%4!=0&&e.push(sc+t/40*lc);return e},[u]),se=(0,_.useRef)(null),ce=(0,_.useRef)(null),le=(0,_.useRef)(null),z=(0,_.useRef)(null),ue=(0,_.useRef)(null),de=(0,_.useRef)(null),fe=(0,_.useRef)(null),pe=(0,_.useRef)(null),me=(0,_.useRef)([]),he=(0,_.useRef)(e),ge=(0,_.useRef)(t),_e=(0,_.useRef)(n),ve=(0,_.useRef)(r);(0,_.useEffect)(()=>{he.current=e,ge.current=t,_e.current=n,ve.current=r},[e,t,n,r]);let ye=(0,_.useMemo)(()=>{if(!p||u!==`needle`)return[];let e=Math.max(4,m),t=C-11,n=[];for(let r=0;r<e;r++){let i=sc+(r+.5)/e*lc;n.push(pc(x,S,t,i))}return n},[p,m,u,x,S,C]);me.current.length!==ye.length&&(me.current.length=ye.length);let be=x+C-6,xe=x+d*.04,Se=Math.max(2,d*.016),B=`${be},${S} ${xe},${S-Se} ${xe},${S+Se}`,Ce=x-d*.04,we=x-C*.24,Te=Math.max(1.4,d*.012),Ee=`${we},${S} ${Ce},${S-Te} ${Ce},${S+Te}`,De=d*.48,Oe=d*.17,ke=x-De/2,Ae=S+d*.16,je=Ae+Oe*.68;return(0,_.useEffect)(()=>{let e=bc(),t=performance.now(),n=he.current,r=0,i=he.current,a=0,o=he.current,s=``,l=``,d=``,f=-1,m=``,h=``,[g]=$a(()=>{let g=performance.now(),_=(g-t)/1e3;t=g;let v=Math.min(.04,Math.max(.001,_)),y=he.current,b=ge.current,w=_e.current,T=ve.current,E=Math.max(b,1e-9),D=y;if(e)n=y,i=y,o=y,r=0,a=0;else{let e=v/2;for(let t=0;t<2;t++){let t=-210*(n-D)-22*r;r+=t*e,n+=r*e;let o=-55*(i-n)-13*a;a+=o*e,i+=a*e}let t=1-Math.exp(-v*8);o+=(y-o)*t,Math.abs(n-y)<E*1e-5&&Math.abs(r)<1e-4&&(n=y,r=0),Math.abs(o-y)<E*1e-5&&(o=y)}let O=Math.max(0,Math.min(1,n/Math.max(b,1e-9))),k=sc+O*lc,ee=sc+Math.max(0,Math.min(1,i/Math.max(b,1e-9)))*lc,A=yc(O,w,T),j=`rotate(${(k-90).toFixed(3)} ${x} ${S})`;se.current&&j!==s&&(se.current.setAttribute(`transform`,j),s=j),A!==d&&(ce.current&&ce.current.setAttribute(`fill`,A),le.current&&le.current.setAttribute(`fill`,A),z.current&&z.current.setAttribute(`stroke`,A),de.current&&de.current.setAttribute(`fill`,A),d=A);let M=`rotate(${(ee-90).toFixed(3)} ${x} ${S})`;if(ue.current&&M!==l&&(ue.current.setAttribute(`transform`,M),l=M),fe.current&&c){let e=c(o);e!==h&&(fe.current.textContent=e,h=e)}if(pe.current&&u===`ring`){let e=mc(x,S,C,sc,Math.max(sc+.01,k));e!==m&&(pe.current.setAttribute(`d`,e),m=e)}if(p&&u===`needle`){let e=Math.round(O*1e3)/1e3;if(e!==f){f=e;let t=me.current,n=t.length;if(n>0){let e=1/n;for(let r=0;r<n;r++){let i=t[r];if(!i)continue;let a=(r+.5)/n,o=O-a,s=Math.max(0,Math.min(1,.5+o/e));i.setAttribute(`fill`,yc(a,w,T)),i.setAttribute(`opacity`,s.toFixed(3))}}}}});return g},[x,S,C,u,p,c]),(0,D.jsxs)(`div`,{className:In(`flex flex-col items-center justify-center gap-1 min-h-0 min-w-0`,f),children:[(0,D.jsxs)(`svg`,{width:y,height:b,viewBox:`${g} ${v} ${y} ${b}`,preserveAspectRatio:`xMidYMid meet`,className:`block max-w-full max-h-full min-h-0`,children:[(0,D.jsxs)(`defs`,{children:[(0,D.jsxs)(`filter`,{id:I,x:`-40%`,y:`-40%`,width:`180%`,height:`180%`,children:[(0,D.jsx)(`feGaussianBlur`,{stdDeviation:`1.2`,result:`blur`}),(0,D.jsxs)(`feMerge`,{children:[(0,D.jsx)(`feMergeNode`,{in:`blur`}),(0,D.jsx)(`feMergeNode`,{in:`SourceGraphic`})]})]}),(0,D.jsxs)(`radialGradient`,{id:ne,cx:`50%`,cy:`32%`,r:`80%`,children:[(0,D.jsx)(`stop`,{offset:`0%`,stopColor:`#4e535d`}),(0,D.jsx)(`stop`,{offset:`55%`,stopColor:`#2a2e36`}),(0,D.jsx)(`stop`,{offset:`100%`,stopColor:`#0b0d11`})]}),(0,D.jsxs)(`radialGradient`,{id:re,cx:`50%`,cy:`45%`,r:`75%`,children:[(0,D.jsx)(`stop`,{offset:`0%`,stopColor:`#1b1f27`}),(0,D.jsx)(`stop`,{offset:`80%`,stopColor:`#0a0c10`}),(0,D.jsx)(`stop`,{offset:`100%`,stopColor:`#05060a`})]}),(0,D.jsxs)(`radialGradient`,{id:ie,cx:`40%`,cy:`30%`,r:`70%`,children:[(0,D.jsx)(`stop`,{offset:`0%`,stopColor:`#f4f5f8`}),(0,D.jsx)(`stop`,{offset:`45%`,stopColor:`#aab1bd`}),(0,D.jsx)(`stop`,{offset:`100%`,stopColor:`#1c1f26`})]}),(0,D.jsxs)(`linearGradient`,{id:L,x1:`50%`,y1:`0%`,x2:`50%`,y2:`100%`,children:[(0,D.jsx)(`stop`,{offset:`0%`,stopColor:`#ffffff`,stopOpacity:`0.22`}),(0,D.jsx)(`stop`,{offset:`100%`,stopColor:`#ffffff`,stopOpacity:`0`})]}),(0,D.jsxs)(`linearGradient`,{id:R,x1:`50%`,y1:`0%`,x2:`50%`,y2:`100%`,children:[(0,D.jsx)(`stop`,{offset:`0%`,stopColor:`#0a0c11`}),(0,D.jsx)(`stop`,{offset:`100%`,stopColor:`#15181f`})]})]}),u===`needle`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`circle`,{cx:x,cy:S,r:C+12,fill:`url(#${ne})`,stroke:`#000`,strokeOpacity:.55,strokeWidth:1}),(0,D.jsx)(`circle`,{cx:x,cy:S,r:C+5,fill:`none`,stroke:`#0a0c11`,strokeWidth:1}),(0,D.jsx)(`circle`,{cx:x,cy:S,r:C-2,fill:`url(#${re})`})]}):null,(0,D.jsx)(`path`,{d:T,fill:`none`,stroke:`var(--color-line-1)`,strokeWidth:u===`ring`?12:3,strokeLinecap:`round`,opacity:u===`ring`?1:.35}),u===`needle`?(0,D.jsx)(`path`,{d:E,fill:`none`,stroke:`var(--color-line-0)`,strokeWidth:1,strokeLinecap:`round`,opacity:.55}):null,u===`needle`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`path`,{d:ee,fill:`none`,stroke:uc,strokeWidth:5,strokeLinecap:`round`,opacity:.78}),(0,D.jsx)(`path`,{d:A,fill:`none`,stroke:dc,strokeWidth:5,strokeLinecap:`round`,opacity:.82}),(0,D.jsx)(`path`,{d:j,fill:`none`,stroke:fc,strokeWidth:5,strokeLinecap:`round`,opacity:.9}),oe.map((e,t)=>{let n=pc(x,S,C-4,e),r=pc(x,S,C+2,e);return(0,D.jsx)(`line`,{x1:n.x,y1:n.y,x2:r.x,y2:r.y,stroke:`var(--color-fg-4)`,strokeWidth:.9,strokeLinecap:`round`,opacity:.7},`mi-${t}`)}),ae.map((e,t)=>{let n=pc(x,S,C-8,e),r=pc(x,S,C+4,e);return(0,D.jsx)(`line`,{x1:n.x,y1:n.y,x2:r.x,y2:r.y,stroke:`var(--color-fg-2)`,strokeWidth:1.8,strokeLinecap:`round`},`ma-${t}`)}),p?ye.map((e,t)=>(0,D.jsx)(`circle`,{ref:e=>{me.current[t]=e},cx:e.x,cy:e.y,r:Math.max(1.6,d*.013),fill:uc,opacity:0,filter:`url(#${I})`},t)):null,i===void 0?null:(0,D.jsx)(wc,{cx:x,cy:S,r:C,angle:hc(i,t),emphasis:!0}),a===void 0?null:(0,D.jsx)(wc,{cx:x,cy:S,r:C,angle:hc(a,t),emphasis:!0}),l?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(Tc,{cx:x,cy:S,r:C,angle:O,text:l(n),size:d}),(0,D.jsx)(Tc,{cx:x,cy:S,r:C,angle:k,text:l(r),size:d}),(0,D.jsx)(Tc,{cx:x,cy:S,r:C,angle:cc,text:l(1),size:d})]}):null,(0,D.jsx)(`path`,{d:M,fill:`none`,stroke:`url(#${L})`,strokeWidth:d*.14,strokeLinecap:`butt`}),c||s!==void 0?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`rect`,{x:ke,y:Ae,width:De,height:Oe,rx:d*.022,ry:d*.022,fill:`url(#${R})`,stroke:`#242a33`,strokeWidth:1}),(0,D.jsx)(`rect`,{x:ke+1,y:Ae+1,width:De-2,height:1,fill:`#ffffff`,opacity:.08})]}):null,(0,D.jsx)(`g`,{ref:ue,opacity:.28,children:(0,D.jsx)(`polygon`,{ref:de,points:B,fill:P})}),(0,D.jsxs)(`g`,{ref:se,children:[(0,D.jsx)(`polygon`,{ref:ce,points:B,fill:P,stroke:`#05070a`,strokeWidth:.6}),(0,D.jsx)(`polygon`,{ref:le,points:Ee,fill:P,opacity:.7})]}),(0,D.jsx)(`circle`,{cx:x,cy:S,r:d*.06,fill:`url(#${ie})`,stroke:`#06080c`,strokeWidth:1}),(0,D.jsx)(`circle`,{ref:z,cx:x,cy:S,r:d*.036,fill:`#0a0c11`,stroke:P,strokeWidth:1.4}),(0,D.jsx)(`circle`,{cx:x,cy:S,r:d*.012,fill:`#f5f7fb`,opacity:.9})]}):(0,D.jsx)(`path`,{ref:pe,d:N,fill:`none`,stroke:P,strokeWidth:12,strokeLinecap:`round`}),u===`needle`&&(c||s!==void 0)?c?(0,D.jsx)(`text`,{ref:fe,x,y:je,textAnchor:`middle`,dominantBaseline:`middle`,className:`font-mono tabular-nums`,fontSize:d*.1,fontWeight:600,fill:`#e8ecf3`,children:c(e)}):(0,D.jsx)(`text`,{x,y:je,textAnchor:`middle`,dominantBaseline:`middle`,className:`font-mono tabular-nums`,fontSize:d*.1,fontWeight:600,fill:`#e8ecf3`,children:s}):c?(0,D.jsx)(`text`,{ref:fe,x,y:S+4,textAnchor:`middle`,className:`font-mono tabular-nums`,fontSize:d*.13,fill:`var(--color-fg-0)`,children:c(e)}):s===void 0?null:(0,D.jsx)(`text`,{x,y:S+4,textAnchor:`middle`,className:`font-mono tabular-nums`,fontSize:d*.13,fill:`var(--color-fg-0)`,children:s})]}),o?(0,D.jsx)(`span`,{className:`overline shrink-0 tracking-[0.12em] uppercase`,children:o}):null]})}function wc({cx:e,cy:t,r:n,angle:r,emphasis:i=!1}){let a=pc(e,t,n-(i?10:6),r),o=pc(e,t,n+(i?8:6),r);return(0,D.jsx)(`line`,{x1:a.x,y1:a.y,x2:o.x,y2:o.y,stroke:i?`var(--color-fg-1)`:`var(--color-fg-2)`,strokeWidth:i?2:1.5,strokeLinecap:`round`})}function Tc({cx:e,cy:t,r:n,angle:r,text:i,size:a}){let o=pc(e,t,n+Math.max(16,a*.1),r),s=r>=135&&r<215?`end`:r>=325?`start`:`middle`;return(0,D.jsx)(`text`,{x:o.x,y:o.y,textAnchor:s,dominantBaseline:`middle`,className:`font-mono tabular-nums`,fontSize:a*.062,fontWeight:600,fill:`var(--color-fg-2)`,stroke:`var(--color-bg-0)`,strokeWidth:3,paintOrder:`stroke`,children:i})}var Ec={allow:`#34d399`,block:`#ef4444`,ask:`#f59e0b`,log:`#a78bfa`,force:`#38bdf8`,shadow:`#6e7076`};function Dc(e){return!Number.isFinite(e)||e<=0?`—`:e<1e3?`${e} ns`:e<1e6?`${(e/1e3).toFixed(1)} µs`:`${(e/1e6).toFixed(2)} ms`}function Oc({latency:e,bursts:t,gaugeMaxMs:n=10,windowMs:r=3e4,trendWindowSec:i=60,gaugeSize:a=200,compact:o=!1,className:s}){let c=e?e.p50_ns/1e6:0,l=e?e.p95_ns/1e6:0,u=e?e.p99_ns/1e6:0,d=(0,_.useRef)(null),[f,p]=(0,_.useState)((0,_.useMemo)(()=>oc(a*2,a*2,a),[a]));(0,_.useEffect)(()=>{let e=d.current;if(!e||typeof ResizeObserver>`u`)return;let t=0,n=0,r=0,i=e=>{let t=Math.round(e.width/4)*4,i=Math.round(e.height/4)*4;t===n&&i===r||(n=t,r=i,p(oc(t,i,a)))};i(e.getBoundingClientRect());let o=new ResizeObserver(e=>{let n=e[0];n&&(t&&cancelAnimationFrame(t),t=requestAnimationFrame(()=>{i(n.contentRect)}))});return o.observe(e),()=>{t&&cancelAnimationFrame(t),o.disconnect()}},[a]);let m=(0,_.useRef)(null),h=(0,_.useRef)([]),g=(0,_.useRef)(0);(0,_.useEffect)(()=>{if(t.length===0)return;let e=h.current,n=g.current,i=n;for(let r of t)r.ts_ms<=n||(e.push({ts:r.ts_ms,durationNs:r.duration_ns,color:Ec[r.decision]??`#6e7076`}),r.ts_ms>i&&(i=r.ts_ms));g.current=i;let a=Date.now()-r*2;for(;e.length&&e[0]?.ts<a;)e.shift()},[t,r]),(0,_.useEffect)(()=>{let e=m.current;if(!e)return;let t=e.getContext(`2d`);if(!t)return;let i=0,a=0,o=0,s=8e3,c=.25,l=1e3,u=n*1e6,d=Math.log10(l),f=Math.log10(u),[p]=$a(()=>{let n=window.devicePixelRatio||1,p=e.clientWidth,m=e.clientHeight;if(p===0||m===0)return;(p!==a||m!==o||n!==i)&&(e.width=Math.floor(p*n),e.height=Math.floor(m*n),t.setTransform(n,0,0,n,0,0),a=p,o=m,i=n),t.clearRect(0,0,p,m),t.strokeStyle=`rgba(110, 112, 118, 0.18)`,t.lineWidth=1,t.setLineDash([2,4]);let g=[{ns:1e5,label:`100µs`},{ns:1e6,label:`1ms`},{ns:1e7,label:`10ms`}];t.font=`9px ui-monospace, SFMono-Regular, Menlo, monospace`,t.textBaseline=`middle`,t.fillStyle=`rgba(110, 112, 118, 0.7)`;for(let e of g){if(e.ns<l||e.ns>u)continue;let n=m-(Math.log10(e.ns)-d)/(f-d)*m;t.beginPath(),t.moveTo(0,n),t.lineTo(p-28,n),t.stroke(),t.fillText(e.label,p-26,n)}t.setLineDash([]);let _=Date.now(),v=_-r,y=h.current;for(;y.length&&y[0]?.ts<v;)y.shift();t.globalCompositeOperation=`source-over`;for(let e of y){let n=(e.ts-v)/r*p,i=Math.max(l,Math.min(u,e.durationNs)),a=m-(Math.log10(i)-d)/(f-d)*m,o=_-e.ts,h;if(o<=s)h=1-o/s*(1-c);else{let e=r-s;h=e>0?Math.max(0,c*(1-(o-s)/e)):0}h<=0||(t.globalAlpha=h,t.fillStyle=e.color,t.beginPath(),t.arc(n,a,2.5,0,Math.PI*2),t.fill())}t.globalAlpha=1,t.fillStyle=`rgba(110, 112, 118, 0.55)`,t.font=`9px ui-monospace, SFMono-Regular, Menlo, monospace`,t.textBaseline=`bottom`,t.textAlign=`left`,t.fillText(`← ${Math.round(r/1e3)} s ago`,4,m-2),t.textAlign=`right`,t.fillText(`now →`,p-4,m-2),t.textAlign=`left`});return p},[r,n]);let v=(0,_.useRef)({p50:[],p95:[],p99:[]});(0,_.useEffect)(()=>{if(!e)return;let t=v.current,n=Date.now(),r=n-i*1e3,a=(e,t)=>{let i=t/1e6;for(e.length===0&&e.push({ts:r,v:i}),e.push({ts:n,v:i});e.length>1&&e[0]?.ts<r;)e.shift()};a(t.p50,e.p50_ns),a(t.p95,e.p95_ns),a(t.p99,e.p99_ns)},[e,i]);let y=(0,_.useMemo)(()=>{let e=v.current;return{p50:[...e.p50],p95:[...e.p95],p99:[...e.p99]}},[]);return(0,D.jsxs)(`div`,{ref:d,"data-lt-variant":f.variant,className:In(`flex h-full min-h-0 flex-col gap-3 overflow-hidden rounded-sm border bg-[var(--color-surface-1)] border-[var(--color-line-1)] p-3`,s),children:[(0,D.jsxs)(`div`,{className:In(`grid gap-3 min-h-0 flex-1`,`grid-cols-[auto_1fr]`),children:[(0,D.jsx)(`div`,{className:`flex items-stretch justify-center overflow-hidden min-h-0 min-w-0`,style:{maxWidth:f.gaugeColumnMaxWidth},children:(0,D.jsx)(Cc,{value:l,max:n,warnAt:Math.min(.85,.5/n),critAt:Math.min(.92,2/n),marker50:c,marker99:u,displayFormat:e=>Dc(e*1e6),scaleLabels:f.gaugeSize>=130?e=>Dc(e*n*1e6):void 0,size:f.gaugeSize,label:`p95 latency`})}),(0,D.jsxs)(`div`,{className:`flex flex-col gap-1 min-w-0 min-h-0 flex-1`,children:[f.showScatterHeader?(0,D.jsxs)(`div`,{className:`flex items-center justify-between gap-3 shrink-0 min-w-0`,children:[(0,D.jsx)(`span`,{className:`overline truncate min-w-0`,children:`live trace · 30 s scatter`}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] shrink min-w-0 truncate text-right`,children:[h.current.length,` live · log-Y`]})]}):null,f.showLegend?(0,D.jsx)(`div`,{className:`shrink-0`,children:(0,D.jsx)(kc,{})}):null,(0,D.jsx)(`canvas`,{ref:m,"data-testid":`latency-scatter-canvas`,className:`block w-full flex-1 min-h-0 rounded-sm bg-[var(--color-surface-0)] border border-[var(--color-line-0)]`,style:{minHeight:f.scatterMinHeight}})]})]}),f.showTrendRows?(0,D.jsxs)(`div`,{"data-testid":`latency-trend-rows`,className:`grid grid-cols-1 gap-1.5 pt-2 border-t border-[var(--color-line-0)]`,children:[(0,D.jsx)(Ac,{label:`p50 · median`,value:Dc(e?.p50_ns??0),color:`#34d399`,fill:`rgba(52, 211, 153, 0.14)`,samples:y.p50,windowMs:i*1e3}),(0,D.jsx)(Ac,{label:`p95 · 95th`,value:Dc(e?.p95_ns??0),color:`#38bdf8`,fill:`rgba(56, 189, 248, 0.14)`,samples:y.p95,windowMs:i*1e3}),(0,D.jsx)(Ac,{label:`p99 · 99th`,value:Dc(e?.p99_ns??0),color:`#6366f1`,fill:`rgba(99, 102, 241, 0.14)`,samples:y.p99,windowMs:i*1e3})]}):null]})}function kc(){return(0,D.jsx)(`div`,{className:`flex flex-wrap items-center gap-x-3 gap-y-1 text-[10px] font-mono text-[var(--color-fg-4)]`,children:[{key:`allow`,color:Ec.allow},{key:`ask`,color:Ec.ask},{key:`block`,color:Ec.block},{key:`force`,color:Ec.force},{key:`log`,color:Ec.log},{key:`shadow`,color:Ec.shadow}].map(e=>(0,D.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,D.jsx)(`span`,{className:`inline-block h-1.5 w-1.5 rounded-full`,style:{background:e.color}}),(0,D.jsx)(`span`,{className:`uppercase tracking-wide`,children:e.key})]},e.key))})}function Ac({label:e,value:t,color:n,fill:r,samples:i,windowMs:a}){return(0,D.jsxs)(`div`,{className:`grid grid-cols-[72px_minmax(0,1fr)_92px] items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`overline text-right truncate min-w-0`,children:e}),(0,D.jsx)(Xs,{samples:i,width:1200,height:28,windowMs:a,color:n,fillColor:r,className:`w-full h-7`}),(0,D.jsx)(`span`,{className:`text-[11px] font-mono tabular-nums text-right truncate min-w-0`,style:{color:n},title:t,children:t})]})}function jc(e){return e<60?`${Math.floor(e)}s`:e<3600?`${Math.floor(e/60)}m ${Math.floor(e%60)}s`:e<86400?`${Math.floor(e/3600)}h ${Math.floor(e%3600/60)}m`:`${Math.floor(e/86400)}d ${Math.floor(e%86400/3600)}h`}function Mc(e,t){if(t===void 0||t<=0)return`var(--color-brand)`;let n=e/t;return n>=.9?`var(--color-decision-block)`:n>=.7?`var(--color-decision-ask)`:`var(--color-decision-allow)`}function Nc(e){return e===`var(--color-decision-block)`?`color-mix(in srgb, var(--color-decision-block) 14%, transparent)`:e===`var(--color-decision-ask)`?`color-mix(in srgb, var(--color-decision-ask) 14%, transparent)`:e===`var(--color-decision-allow)`?`color-mix(in srgb, var(--color-decision-allow) 14%, transparent)`:e===`var(--color-decision-log)`?`color-mix(in srgb, var(--color-decision-log) 14%, transparent)`:`color-mix(in srgb, var(--color-brand) 12%, transparent)`}function Pc(e,t){if(e.length===0)return[];let n=Date.now(),r=t/Math.max(1,e.length),i=Array(e.length);for(let t=0;t<e.length;t++)i[t]={ts:n-(e.length-1-t)*r,v:e[t]};return i}function Fc({cpuPct:e,cpuSeries:t,cpuLimit:n,memMb:r,memSeries:i,memLimit:a,heapUsedMb:o,heapTotalMb:s,heapSeries:c,uptimeSec:l,className:u}){let d=6e4,f=Mc(e,n),p=Mc(r,a),m=`var(--color-decision-log)`,h=(0,_.useMemo)(()=>Pc(t,d),[t]),g=(0,_.useMemo)(()=>Pc(i,d),[i]),v=(0,_.useMemo)(()=>Pc(c,d),[c]),y=(0,_.useRef)([]);(0,_.useEffect)(()=>{let e=y.current.filter(e=>!!e);if(e.length===0)return;e.forEach(e=>{e.style.opacity=`0`,e.style.transform=`translateY(28px) scale(0.94)`});let t=Fr(e,{translateY:[28,0],scale:[.94,1],opacity:[0,1],duration:720,delay:pr(140),ease:`outBack(1.25)`,onComplete:e=>{e.style.transform=``}});return()=>t.cancel()},[]);let b=n!==void 0&&n>0&&e>=n*.9,x=a!==void 0&&a>0&&r>=a*.9;return(0,D.jsx)(`div`,{className:In(`rounded-sm border bg-[var(--color-surface-1)] border-[var(--color-line-1)] p-3`,u),children:(0,D.jsxs)(`div`,{className:`grid grid-cols-2 lg:grid-cols-4 gap-3`,children:[(0,D.jsx)(Ic,{registerRef:e=>y.current[0]=e,label:`CPU`,color:f,fill:Nc(f),pulse:b,valueNode:(0,D.jsxs)(`span`,{children:[(0,D.jsx)(Ks,{value:e,format:e=>e.toFixed(1),className:`text-[var(--color-fg-0)]`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] ml-1.5 text-base`,children:`%`})]}),subText:n?`limit ${n}%`:void 0,samples:h,maxValue:100,windowMs:d}),(0,D.jsx)(Ic,{registerRef:e=>y.current[1]=e,label:`Memory`,color:p,fill:Nc(p),pulse:x,valueNode:(0,D.jsxs)(`span`,{children:[(0,D.jsx)(Ks,{value:r,format:e=>e.toFixed(0),className:`text-[var(--color-fg-0)]`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] ml-1.5 text-base`,children:`MB`})]}),subText:a?`limit ${a} MB`:void 0,samples:g,maxValue:a?a*1.1:void 0,windowMs:d}),(0,D.jsx)(Ic,{registerRef:e=>y.current[2]=e,label:`Heap`,color:m,fill:Nc(m),valueNode:(0,D.jsxs)(`span`,{children:[(0,D.jsx)(Ks,{value:o,format:e=>e.toFixed(0),className:`text-[var(--color-fg-0)]`}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-3)] ml-1.5 text-base`,children:[`/ `,s.toFixed(0),` MB`]})]}),subText:s>0?`${(o/s*100).toFixed(0)}% used`:void 0,samples:v,maxValue:s>0?s:void 0,windowMs:d}),(0,D.jsx)(Ic,{registerRef:e=>y.current[3]=e,label:`Uptime`,color:`var(--color-fg-2)`,fill:`rgba(214, 215, 217, 0.04)`,valueNode:(0,D.jsx)(`span`,{className:`text-[var(--color-fg-0)] tabular-nums`,children:jc(l)}),subText:`since daemon start`})]})})}function Ic({label:e,valueNode:t,subText:n,color:r,fill:i,samples:a,maxValue:o,windowMs:s,pulse:c,registerRef:l}){let u=(0,_.useRef)(null);return(0,_.useEffect)(()=>{if(!c||!u.current)return;let e=!1,t=null,n=()=>{e||!u.current||(t=Fr(u.current,{"--breach":[0,1],duration:420,ease:`outCubic`,onComplete:()=>{e||!u.current||(t=Fr(u.current,{"--breach":[1,0],duration:560,ease:`outCubic`,onComplete:()=>{e||n()}}))}}))};return n(),()=>{e=!0,t?.cancel();let n=u.current;n&&n.style.removeProperty(`--breach`)}},[c]),(0,D.jsxs)(`div`,{ref:e=>{u.current=e,l(e)},className:`flex flex-col gap-2 rounded-sm border bg-[var(--color-surface-0)] border-[var(--color-line-1)] px-4 py-3 min-h-[140px] system-pulse__tile`,"data-breach":c?`true`:void 0,children:[(0,D.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:e}),n?(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] tabular-nums`,children:n}):null]}),(0,D.jsx)(`span`,{className:`text-[1.9rem] leading-none font-semibold tracking-tight font-mono`,style:{color:r},children:t}),a&&a.length>=2?(0,D.jsx)(`div`,{className:`mt-auto`,children:(0,D.jsx)(Xs,{samples:a,width:320,height:64,windowMs:s??6e4,color:r,fillColor:i,maxValue:o,className:`w-full`})}):(0,D.jsx)(`div`,{className:`mt-auto h-[64px] flex items-end`,children:(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:`— no series —`})})]})}var Lc=En(`relative font-mono text-[11px] overflow-hidden border bg-[var(--color-surface-1)] border-[var(--color-line-1)] rounded-sm`,{variants:{density:{compact:``,roomy:`text-[12px]`}},defaultVariants:{density:`compact`}}),Rc={allow:`#34d399`,block:`#ef4444`,ask:`#f59e0b`,log:`#a78bfa`,force:`#38bdf8`,shadow:`#6e7076`},zc={allow:`text-emerald-300`,block:`text-red-300`,ask:`text-amber-300`,log:`text-violet-300`,force:`text-sky-300`,shadow:`text-[var(--color-fg-3)]`};function Bc(e){let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}:${String(t.getSeconds()).padStart(2,`0`)}.${String(t.getMilliseconds()).padStart(3,`0`)}`}function Vc(e){return e<1e3?`${e} ns`:e<1e6?`${(e/1e3).toFixed(1)} µs`:e<1e9?`${(e/1e6).toFixed(2)} ms`:`${(e/1e9).toFixed(2)} s`}function Hc(e){return e.variant===`raw`?(0,D.jsx)(Wc,{...e}):(0,D.jsx)(Uc,{...e})}function Uc({bursts:e,windowSize:t=60,filterDecision:n,filterClient:r,className:i,density:a,height:o=260}){let[s,c]=(0,_.useState)(!1),l=(0,_.useRef)(null),u=(0,_.useMemo)(()=>{let i=e;n&&(i=i.filter(e=>e.decision===n)),r&&(i=i.filter(e=>e.client===r));let a=i.slice(-t),o=Array(a.length);for(let e=0;e<a.length;e++)o[e]=a[a.length-1-e];return o},[e,n,r,t]);s?l.current===null&&(l.current=u):l.current=null;let d=s&&l.current?l.current:u,f=(0,_.useRef)(null),p=(0,_.useRef)(0);return(0,_.useLayoutEffect)(()=>{if(s)return;let e=d[0];if(!e||e.ts_ms===p.current)return;p.current=e.ts_ms;let t=f.current;t&&(_r()||Fr(t,{translateX:[-10,0],opacity:[0,1],duration:220,ease:`outExpo`}))},[d,s]),(0,D.jsxs)(`div`,{className:In(Lc({density:a,className:i})),onMouseEnter:()=>c(!0),onMouseLeave:()=>c(!1),children:[(0,D.jsx)(`div`,{className:`overflow-auto`,style:{height:o},children:d.length===0?(0,D.jsx)(`div`,{className:`px-3 py-4 text-[var(--color-fg-4)]`,children:`— waiting for events —`}):d.map((e,t)=>{let n=e.input_preview&&e.input_preview.length>0?e.input_preview:e.rule_id?`rule: ${e.rule_id}`:`—`;return(0,D.jsxs)(`div`,{ref:t===0?f:void 0,className:`telemetry-row grid items-center gap-2 px-3 py-1 border-b border-[var(--color-line-0)] last:border-b-0 hover:bg-[var(--color-surface-2)]`,style:{gridTemplateColumns:`90px 56px minmax(80px, 130px) minmax(0, 1fr) 70px 80px`,borderLeft:`3px solid ${Rc[e.decision]??`#666`}`},children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] tabular-nums`,children:Bc(e.ts_ms)}),(0,D.jsx)(`span`,{className:In(`uppercase tracking-wide font-medium`,zc[e.decision]??`text-[var(--color-fg-2)]`),children:e.decision}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] truncate`,title:e.tool?`${e.tool} — ${Si(e.tool)}`:`unknown tool`,children:e.tool||`—`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)] truncate`,title:n,children:n}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)] tabular-nums text-right`,children:Vc(e.duration_ns)}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] truncate text-right`,title:e.client,children:e.client})]},e.audit_id??`${e.ts_ms}:${e.tool}`)})}),s?(0,D.jsx)(Gc,{}):null]})}function Wc({lines:e,windowSize:t=300,className:n,density:r,height:i=260}){let[a,o]=(0,_.useState)(!1),s=(0,_.useRef)(null),c=(0,_.useMemo)(()=>{let n=e.slice(-t),r=Array(n.length);for(let e=0;e<n.length;e++)r[e]=n[n.length-1-e];return r},[e,t]);a?s.current===null&&(s.current=c):s.current=null;let l=a&&s.current?s.current:c;return(0,D.jsxs)(`div`,{className:In(Lc({density:r,className:n})),onMouseEnter:()=>o(!0),onMouseLeave:()=>o(!1),children:[(0,D.jsx)(`div`,{className:`overflow-auto px-3 py-2 leading-relaxed text-[var(--color-fg-2)] whitespace-pre`,style:{height:i},children:l.length===0?(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`— empty —`}):l.map((e,t)=>(0,D.jsx)(`div`,{className:`hover:bg-[var(--color-surface-2)]`,children:e},`${t}:${e.slice(0,40)}`))}),a?(0,D.jsx)(Gc,{}):null]})}function Gc(){return(0,D.jsx)(`span`,{className:`absolute top-1 right-2 text-[10px] uppercase tracking-wider font-mono text-[var(--color-brand)] bg-[var(--color-surface-0)] px-1.5 py-0.5 border border-[var(--color-brand)]/40 rounded-sm`,children:`paused`})}function Kc(e={}){let t=(0,_.useRef)(null),n=(0,_.useRef)(!1),r=(0,_.useCallback)(()=>{if(n.current)return;let r=t.current;if(!r)return;let i=r.querySelectorAll(`[data-reveal]`);if(i.length===0)return;if(n.current=!0,_r()){i.forEach(e=>{e.style.opacity=`1`,e.style.transform=``});return}let a=e.staggerMs??40,o=e.maxStaggerMs??320,s=Math.min(a,Math.max(10,o/i.length)),c=e.translateY??14,l=e.durationMs??520,u=e.from??`center`;i.forEach(e=>{e.style.opacity=`0`,e.style.transform=`translateY(${c}px)`,e.style.willChange=`transform, opacity`}),Fr(Array.from(i),{opacity:[0,1],translateY:[c,0],duration:l,ease:`outBack(1.2)`,delay:pr(s,{from:u}),onComplete:e=>{e.style.willChange=``}})},[e.staggerMs,e.maxStaggerMs,e.durationMs,e.translateY,e.from]);return(0,_.useEffect)(()=>{let n=t.current;if(!n)return;if(typeof IntersectionObserver>`u`){r();return}let i=!1,a=new IntersectionObserver(e=>{for(let t of e)if(t.isIntersecting&&!i){r(),a.disconnect();return}},{threshold:.08});a.observe(n);let o=n.querySelectorAll(`[data-reveal]`);if(!_r()){let t=e.translateY??14;o.forEach(e=>{e.style.opacity=`0`,e.style.transform=`translateY(${t}px)`})}let s=n.getBoundingClientRect();return s.top<(window.innerHeight||document.documentElement.clientHeight)&&s.bottom>0&&(r(),a.disconnect()),()=>{i=!0,a.disconnect()}},[r,e.translateY]),t}var qc=`ssg.sfx.enabled`;function Jc(){if(typeof window>`u`)return!1;try{return window.localStorage.getItem(qc)===`true`}catch{return!1}}function Yc(e){if(!(typeof window>`u`))try{window.localStorage.setItem(qc,String(e))}catch{}}function Xc(e,t,n,r,i,a,o=`sine`){try{let s=e.createOscillator(),c=e.createGain(),l=i/1e3;s.type=o,s.frequency.setValueAtTime(n,e.currentTime),s.frequency.exponentialRampToValueAtTime(Math.max(1,r),e.currentTime+l),c.gain.setValueAtTime(a,e.currentTime),c.gain.exponentialRampToValueAtTime(.001,e.currentTime+l),s.connect(c),c.connect(t),s.start(e.currentTime),s.stop(e.currentTime+l+.02)}catch{}}function Zc(){let[e,t]=(0,_.useState)(Jc),n=(0,_.useRef)(null),r=(0,_.useRef)(null);return(0,_.useEffect)(()=>{let t=()=>{let t=n.current;t&&(document.hidden?t.suspend().catch(()=>{}):e&&t.resume().catch(()=>{}))};return document.addEventListener(`visibilitychange`,t),()=>document.removeEventListener(`visibilitychange`,t)},[e]),{enabled:e,toggle:(0,_.useCallback)(()=>{t(e=>{let t=!e;if(Yc(t),t){if(!n.current)try{let e=new AudioContext,t=e.createGain();t.gain.value=.8,t.connect(e.destination),n.current=e,r.current=t}catch{}n.current?.resume().catch(()=>{})}else n.current?.suspend().catch(()=>{});return t})},[]),play:(0,_.useCallback)(t=>{if(!e)return;let i=n.current,a=r.current;if(!(!i||!a||i.state===`suspended`))switch(t){case`block`:Xc(i,a,110,55,150,.08);break;case`force`:Xc(i,a,80,40,200,.1),Xc(i,a,160,80,200,.05,`square`);break;case`milestone`:{Xc(i,a,660,880,100,.06);let e=i,t=a;setTimeout(()=>{e.state!==`suspended`&&Xc(e,t,880,1320,100,.05)},115);break}case`record`:Xc(i,a,880,1320,350,.07);break}},[e])}}function Qc(e){return!Number.isFinite(e)||e<=0?`—`:e<1e3?`${e} ns`:e<1e6?`${(e/1e3).toFixed(1)} µs`:`${(e/1e6).toFixed(2)} ms`}async function $c(e,t){await fetch(`/api/decide/${e}?decision=${t}`,{method:`POST`,headers:U()})}var el=e=>!0,tl=e=>e.decision===`allow`,nl=e=>e.decision===`block`,rl=e=>e.decision===`ask`,il=e=>e.decision===`force`,al=e=>e.decision===`log`;function ol(){let e=new Date;return e.setHours(0,0,0,0),e.getTime()}function sl(){let e=V([`counters-updated`,`activity-updated`,`pending-changed`,`runtime-tick`]),t=qi();Yi();let n=Ji(),r=Zc();(0,_.useEffect)(()=>{t&&(t.decision===`block`?r.play(`block`):t.decision===`force`&&r.play(`force`))},[r.play,t]);let[i,a]=(0,_.useState)(()=>ol());(0,_.useEffect)(()=>{let e=()=>{if(document.visibilityState!==`visible`)return;let e=ol();a(t=>e===t?t:e)};return document.addEventListener(`visibilitychange`,e),()=>document.removeEventListener(`visibilitychange`,e)},[]);let{activeProject:o}=Be(),{data:s}=k(Ve(`/api/state/counters?since_ms=${i}`,o),[e[`counters-updated`],i,o]),{data:c}=k(`/api/state/runtime`,[e[`runtime-tick`]]),{data:l}=k(`/api/json/limits`,[e[`runtime-tick`]]),{data:u,refetch:d}=k(`/api/json/pending`,[e[`pending-changed`]]),{data:f}=k(`/api/json/blocked`,[e[`activity-updated`]]),p=Ls(),[m,h]=(0,_.useState)(!1),g=(0,_.useMemo)(()=>{let e=s?.allow??0,n=s?.block??0,r=s?.ask??0,i=s?.log??0,a=s?.force??0,o=e+n+r+i+a,c=t?.counters.total??0;return t&&c>=o&&t?{allow:t.counters.allow,block:t.counters.block,ask:t.counters.ask,log:t.counters.log,force:t.counters.force,shadow:t.counters.shadow,total:t.counters.total}:{allow:e,block:n,ask:r,log:i,force:a,shadow:0,total:o}},[t,s]),v=(0,_.useMemo)(()=>{if(n.length===0)return 0;let e=Date.now()-1e4;return n.filter(t=>t.ts_ms>=e).length/10},[n]),y=c?.history?.cpu_pct??[],b=c?.history?.memory_rss_mb??[],x=[],S=c?.latency,C=(0,_.useMemo)(()=>({"hero-metrics":()=>(0,D.jsx)(`div`,{className:`grid-bleed rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3 h-full`,children:(0,D.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-3 h-full`,children:[(0,D.jsx)(ic,{label:`Total`,value:g.total,tone:`amber`,sub:t?Qc(t.duration_ns):void 0,burstRing:n,filter:el}),(0,D.jsx)(ic,{label:`Allow`,value:g.allow,tone:`green`,burstRing:n,filter:tl}),(0,D.jsx)(ic,{label:`Block`,value:g.block,tone:`red`,burstRing:n,filter:nl}),(0,D.jsx)(ic,{label:`Ask`,value:g.ask,tone:`amber`,burstRing:n,filter:rl}),(0,D.jsx)(ic,{label:`Force`,value:g.force,tone:`blue`,burstRing:n,filter:il}),(0,D.jsx)(ic,{label:`Log`,value:g.log,tone:`purple`,burstRing:n,filter:al})]})}),graph:()=>(0,D.jsx)(Oo,{}),"latency-trace":()=>(0,D.jsx)(Oc,{latency:S,bursts:n,gaugeMaxMs:10,windowMs:3e4,trendWindowSec:60,gaugeSize:200}),throughput:()=>(0,D.jsxs)(K,{className:`h-full`,children:[(0,D.jsxs)(q,{children:[(0,D.jsx)(`span`,{className:`overline`,children:`throughput · evals/s`}),(0,D.jsxs)(W,{variant:`blue`,children:[v.toFixed(1),`/s`]})]}),(0,D.jsxs)(J,{children:[(0,D.jsx)(Xs,{value:v,width:360,height:96,windowMs:6e4,className:`w-full`}),(0,D.jsx)(`p`,{className:`overline mt-2 text-center`,children:`60-second rolling window`})]})]}),"decision-mix":()=>(0,D.jsxs)(K,{className:`h-full`,children:[(0,D.jsxs)(q,{children:[(0,D.jsx)(`span`,{className:`overline`,children:`decision mix`}),(0,D.jsx)(W,{variant:`gray`,children:g.total.toLocaleString()})]}),(0,D.jsx)(J,{children:(0,D.jsx)(qs,{counters:{allow:g.allow,block:g.block,ask:g.ask,log:g.log,force:g.force,shadow:g.shadow}})})]}),"telemetry-feed":()=>(0,D.jsxs)(K,{variant:`flush`,className:`h-full flex flex-col`,children:[(0,D.jsxs)(q,{children:[(0,D.jsx)(`span`,{className:`overline`,children:`telemetry · live · newest first`}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)]`,children:[`hover to pause · scroll for history · `,n.length,` events buffered`]})]}),(0,D.jsx)(J,{className:`p-0 flex-1 min-h-0`,children:(0,D.jsx)(Hc,{variant:`decision`,bursts:n,windowSize:80,height:360,className:`border-0 rounded-none`})})]}),"system-pulse":()=>(0,D.jsx)(Fc,{cpuPct:c?.cpu_pct??0,cpuSeries:y,cpuLimit:l?.config.cpuLimitPct,memMb:c?.memory_rss_mb??0,memSeries:b,memLimit:l?.config.memoryLimitMb,heapUsedMb:c?.heap_used_mb??0,heapTotalMb:c?.heap_total_mb??0,heapSeries:x,uptimeSec:(c?.uptime_ms??0)/1e3}),"pending-approvals":()=>(0,D.jsxs)(K,{className:`h-full`,children:[(0,D.jsxs)(q,{children:[(0,D.jsx)(`span`,{className:`overline`,children:`pending approvals`}),(0,D.jsx)(W,{variant:u&&u.length>0?`amber`:`gray`,children:u?.length??0})]}),(0,D.jsx)(J,{children:u&&u.length>0?(0,D.jsx)(`ul`,{className:`space-y-2`,children:u.slice(0,5).map(e=>(0,D.jsxs)(`li`,{className:`flex items-center justify-between gap-2 border-b border-[var(--color-line-0)] last:border-b-0 py-1.5 text-[12px] font-mono`,children:[(0,D.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,D.jsxs)(`div`,{className:`text-[var(--color-fg-1)] truncate`,children:[e.toolCall.tool,` · `,e.ruleId]}),(0,D.jsx)(`div`,{className:`text-[var(--color-fg-3)] text-[11px] truncate`,children:zn(e.toolCall.tool,JSON.stringify(e.toolCall.input??{}))})]}),(0,D.jsxs)(`div`,{className:`flex gap-1 shrink-0`,children:[(0,D.jsx)(G,{size:`sm`,variant:`primary`,onClick:()=>$c(e.id,`allow`).then(d),children:`allow`}),(0,D.jsx)(G,{size:`sm`,variant:`ghost`,onClick:()=>$c(e.id,`block`).then(d),children:`block`})]})]},e.id))}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)] py-3 text-center`,children:`— no pending approvals —`})})]}),"recent-blocks":()=>(0,D.jsxs)(K,{className:`h-full`,children:[(0,D.jsxs)(q,{children:[(0,D.jsx)(`span`,{className:`overline`,children:`recent blocks & forces`}),(0,D.jsx)(W,{variant:f&&f.length>0?`red`:`gray`,children:f?.length??0})]}),(0,D.jsx)(J,{children:f&&f.length>0?(0,D.jsx)(`ul`,{className:`space-y-1.5`,children:f.slice(0,6).map((e,t)=>(0,D.jsxs)(`li`,{className:`flex items-center gap-2 text-[12px] font-mono border-b border-[var(--color-line-0)] last:border-b-0 py-1.5`,children:[(0,D.jsx)(W,{variant:e.decision===`force`?`amber`:`red`,children:e.decision}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] truncate flex-1`,children:zn(e.tool,e.input)}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] truncate text-[11px] max-w-[120px]`,children:e.rule_id??`—`})]},`${e.timestamp}-${t}`))}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)] py-3 text-center`,children:`— no recent blocks —`})})]})}),[g,t,n,S,v,c,y,b,x,l,u,f,d]),w=Kc({from:`first`,translateY:22,durationMs:640,staggerMs:80,maxStaggerMs:520});return(0,D.jsxs)(`div`,{ref:m?void 0:w,className:`space-y-5`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,D.jsx)(`div`,{className:`flex-1`,"data-tutorial":`cb-layout`,children:(0,D.jsx)(Qo,{manager:p,isEditing:m,onToggleEditing:h})}),(0,D.jsx)(`button`,{type:`button`,onClick:r.toggle,className:`chip cursor-pointer hover:border-sky-500/50 hover:text-sky-300 transition-colors shrink-0`,title:r.enabled?`Mute stream sounds`:`Enable stream sounds`,children:r.enabled?`SFX ON`:`SFX OFF`})]}),(0,D.jsx)(Hs,{}),(0,D.jsx)(`div`,{"data-tutorial":`cb-grid`,children:(0,D.jsx)(Zo,{panels:p.activeLayout.panels,isEditing:m,renderers:C,onPanelsChange:p.updateActivePanels})})]})}var cl={centre:`#FF9500`,"cf-worker":`#5AC8FA`,bun:`#FFCC00`,elixir:`#AF52DE`,native:`#FF3B30`,unknown:`#8E8E93`},ll={centre:`monorepo`,"cf-worker":`CF Worker`,bun:`Bun / TS`,elixir:`Elixir`,native:`Native`,unknown:`Other`};function ul(e){let t=(0,_.useRef)(null),n=(0,_.useRef)(null),r=(0,_.useRef)([]),i=(0,_.useRef)(null),a=(0,_.useRef)(null),o=(0,_.useRef)(0),s=(0,_.useRef)(null),c=(0,_.useRef)({w:0,h:0}),l=(0,_.useRef)(!1),u=(0,_.useRef)(null),[d,f]=(0,_.useState)(null),[p,m]=(0,_.useState)(!1),[h,g]=(0,_.useState)({centre:0,"cf-worker":0,bun:0,elixir:0,native:0,unknown:0});return(0,_.useEffect)(()=>{let e=!1;return m(!1),f(null),fetch(`/api/json/monorepo/graph`).then(async e=>{let t=e.headers.get(`content-type`)??``;if(!e.ok)throw Error(`HTTP ${e.status}`);if(!t.includes(`application/json`))throw Error(`expected JSON, got ${t||`unknown`}`);return e.json()}).then(t=>{if(e)return;let i=n.current?.clientWidth??800,a=n.current?.clientHeight??420,s=i/2,c=a/2,l=Math.min(i,a)*.36,u=t.projects,d=[{id:t.centre.id,label:t.centre.label,type:`centre`,description:`Monorepo root — every sigmashake-* project lives here`,isCentre:!0,x:s,y:c,vx:0,vy:0,radius:0,phase:0},...u.map((e,t)=>{let n=t/Math.max(1,u.length)*Math.PI*2;return{id:e.id,label:e.label.replace(/^sigmashake-/,``),type:e.type,description:e.description||`${ll[e.type]} project`,isCentre:!1,x:s+Math.cos(n)*l,y:c+Math.sin(n)*l,vx:0,vy:0,radius:l,phase:n}})];r.current=d,o.current=0,g(d.reduce((e,t)=>(e[t.type]=(e[t.type]??0)+1,e),{centre:0,"cf-worker":0,bun:0,elixir:0,native:0,unknown:0})),m(!0)}).catch(t=>{e||f(t instanceof Error?t.message:String(t))}),()=>{e=!0}},[]),(0,_.useEffect)(()=>{if(typeof window>`u`||!window.matchMedia)return;let e=window.matchMedia(`(prefers-reduced-motion: reduce)`),t=()=>{l.current=e.matches};return t(),e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]),(0,_.useEffect)(()=>{let e=t.current,s=n.current;if(!e||!s)return;let u=e.getContext(`2d`,{alpha:!0});if(!u)return;let d=new ResizeObserver(t=>{for(let n of t){let t=n.contentRect,i=window.devicePixelRatio||1;c.current.w=t.width,c.current.h=t.height,e.width=Math.max(1,Math.floor(t.width*i)),e.height=Math.max(1,Math.floor(t.height*i)),e.style.width=`${t.width}px`,e.style.height=`${t.height}px`,u.setTransform(i,0,0,i,0,0);let a=r.current;if(a.length>0){let e=t.width/2,n=t.height/2,r=Math.min(t.width,t.height)*.36;for(let t of a){if(t.isCentre){t.x=e,t.y=n;continue}t.radius=r}}}});d.observe(s);let f=0,p=performance.now(),m=[],h=(e,t)=>{let n=new Map;e.forEach((e,t)=>n.set(e.id,t));let r=[];for(let e of t){let t=n.get(e.from),i=n.get(e.to);t===void 0||i===void 0||r.push([t,i])}return r},g=e=>{let t=Math.min(.05,(e-p)/1e3);p=e;let n=r.current,{w:s,h:d}=c.current,h=s/2,_=d/2,v=i.current,y=l.current||v?0:.06;o.current+=y*t;let b=5.5,x=.86;for(let e=0;e<n.length;e++){let r=n[e];if(r.isCentre||r.id===v)continue;let i=0,a=0;for(let t=0;t<n.length;t++){if(e===t)continue;let o=n[t];if(o.isCentre)continue;let s=r.x-o.x,c=r.y-o.y,l=s*s+c*c+.01,u=Math.sqrt(l),d=1700/l;i+=s/u*d,a+=c/u*d}let s=r.phase+o.current,c=h+Math.cos(s)*r.radius,l=_+Math.sin(s)*r.radius;i+=(c-r.x)*b,a+=(l-r.y)*b;let u=r.x-h,d=r.y-_,f=Math.sqrt(u*u+d*d)||1,p=r.radius-f;i+=u/f*p*.6,a+=d/f*p*.6,r.vx=(r.vx+i*t)*x,r.vy=(r.vy+a*t)*x,r.x+=r.vx*t,r.y+=r.vy*t}u.clearRect(0,0,s,d);let S=u.createRadialGradient(h,_,0,h,_,Math.max(s,d)/1.4);S.addColorStop(0,`rgba(255, 149, 0, 0.06)`),S.addColorStop(1,`rgba(255, 149, 0, 0)`),u.fillStyle=S,u.fillRect(0,0,s,d),u.lineCap=`round`;for(let e=1;e<n.length;e++){let t=n[0],r=n[e];dl(u,t,r,.1)}for(let[e,t]of m){let r=n[e],i=n[t];!r||!i||dl(u,r,i,.24,`#5AC8FA`)}let C=a.current;for(let e of n){let t=cl[e.type],n=C===e.id,r=v===e.id,i=e.isCentre?22:11,a=n||r?i+4:i;if(n||r||e.isCentre){let n=e.isCentre?a+14:a+8,r=u.createRadialGradient(e.x,e.y,a,e.x,e.y,n);r.addColorStop(0,t),r.addColorStop(1,`rgba(0,0,0,0)`),u.globalAlpha=e.isCentre?.22:.32,u.fillStyle=r,u.beginPath(),u.arc(e.x,e.y,n,0,Math.PI*2),u.fill(),u.globalAlpha=1}if(u.fillStyle=t,u.beginPath(),u.arc(e.x,e.y,a,0,Math.PI*2),u.fill(),u.lineWidth=e.isCentre?2:1.25,u.strokeStyle=`rgba(0,0,0,0.18)`,u.stroke(),u.font=e.isCentre?`600 12px ui-sans-serif, system-ui`:`500 10.5px ui-sans-serif, system-ui`,u.fillStyle=`rgba(60,60,67,0.85)`,u.textBaseline=`middle`,u.textAlign=`center`,e.isCentre)u.fillText(e.label,e.x,e.y+a+14);else{let t=e.x-h,n=e.y-_,r=Math.sqrt(t*t+n*n)||1,i=e.x+t/r*(a+12),o=e.y+n/r*(a+12);u.textAlign=t>=0?`left`:`right`,u.textBaseline=n>=0?`top`:`bottom`,u.fillText(e.label,i,o)}}u.textAlign=`start`,u.textBaseline=`alphabetic`,f=requestAnimationFrame(g)};f=requestAnimationFrame(g);let _=-1,v=``,y=setInterval(()=>{let e=r.current,t=window.__SSG_MONOREPO_EDGES__??``;e.length===_&&t===v||(_=e.length,v=t,m=h(e,t?JSON.parse(t):[]))},250);return()=>{cancelAnimationFrame(f),clearInterval(y),d.disconnect()}},[]),(0,_.useEffect)(()=>{let e=t.current;if(!e)return;let n=t=>{let n=e.getBoundingClientRect();return{x:t.clientX-n.left,y:t.clientY-n.top}},o=(e,t)=>{let n=r.current;for(let r=n.length-1;r>=0;r--){let i=n[r],a=i.x-e,o=i.y-t,s=i.isCentre?26:14;if(a*a+o*o<=s*s)return i}return null},c=t=>{let{x:s,y:c}=n(t),l=i.current;if(l){let e=r.current.find(e=>e.id===l);if(e&&!e.isCentre){let t=e.x,n=e.y;e.x=s,e.y=c,e.vx=(s-t)*12,e.vy=(c-n)*12}return}let d=o(s,c);a.current=d?.id??null,e.style.cursor=d&&!d.isCentre?`grab`:`default`,d&&u.current?(u.current.style.display=`block`,u.current.style.left=`${s+14}px`,u.current.style.top=`${c+14}px`,u.current.innerHTML=`<strong>${fl(d.id)}</strong><span class="mg-tooltip__kind">${ll[d.type]}</span>`+(d.description?`<p>${fl(d.description)}</p>`:``)):u.current&&(u.current.style.display=`none`)},l=t=>{let{x:r,y:a}=n(t),c=o(r,a);c&&!c.isCentre&&(i.current=c.id,e.setPointerCapture(t.pointerId),e.style.cursor=`grabbing`,s.current={x:r,y:a,downX:r,downY:a,downAt:performance.now()})},d=t=>{if(i.current)try{e.releasePointerCapture(t.pointerId)}catch{}i.current=null,e.style.cursor=`default`},f=()=>{a.current=null,u.current&&(u.current.style.display=`none`)};return e.addEventListener(`pointermove`,c),e.addEventListener(`pointerdown`,l),e.addEventListener(`pointerup`,d),e.addEventListener(`pointercancel`,d),e.addEventListener(`pointerleave`,f),()=>{e.removeEventListener(`pointermove`,c),e.removeEventListener(`pointerdown`,l),e.removeEventListener(`pointerup`,d),e.removeEventListener(`pointercancel`,d),e.removeEventListener(`pointerleave`,f)}},[]),(0,_.useEffect)(()=>{p&&fetch(`/api/json/monorepo/graph`).then(e=>e.json()).then(e=>{window.__SSG_MONOREPO_EDGES__=JSON.stringify(e.serviceEdges??[])}).catch(()=>{window.__SSG_MONOREPO_EDGES__=`[]`})},[p]),(0,D.jsxs)(`div`,{className:`mg`,ref:n,children:[(0,D.jsx)(`canvas`,{ref:t,className:`mg__canvas`,"aria-label":`Monorepo dependency graph`}),(0,D.jsxs)(`div`,{className:`mg__overlay`,children:[(0,D.jsxs)(`div`,{className:`mg__title`,children:[(0,D.jsx)(`strong`,{children:`monorepo map`}),(0,D.jsx)(`span`,{className:`mg__hint`,children:`drag to pluck a project • hover for details`})]}),d&&(0,D.jsx)(`div`,{className:`mg__error`,children:d}),(0,D.jsx)(`ul`,{className:`mg__legend`,children:[`cf-worker`,`bun`,`elixir`,`native`,`unknown`].map(e=>h[e]>0?(0,D.jsxs)(`li`,{children:[(0,D.jsx)(`span`,{className:`mg__swatch`,style:{background:cl[e]}}),(0,D.jsx)(`span`,{children:ll[e]}),(0,D.jsx)(`span`,{className:`mg__count`,children:h[e]})]},e):null)})]}),(0,D.jsx)(`div`,{ref:u,className:`mg-tooltip`})]})}function dl(e,t,n,r,i=`#FF9500`){let a=n.x-t.x,o=n.y-t.y,s=(t.x+n.x)/2-o*.05,c=(t.y+n.y)/2+a*.05;e.globalAlpha=r,e.strokeStyle=i,e.lineWidth=1.25,e.beginPath(),e.moveTo(t.x,t.y),e.quadraticCurveTo(s,c,n.x,n.y),e.stroke(),e.globalAlpha=1}function fl(e){return e.replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/"/g,`&quot;`)}function pl(e,t){let n=Array(t).fill(0);if(e.length===0)return n;let r=Date.now()-t*1e3;for(let i=e.length-1;i>=0;i--){let a=e[i];if(!a)continue;if(a.ts_ms<r)break;let o=Math.floor((a.ts_ms-r)/1e3);o>=0&&o<t&&n[o]++}return n}function ml({bins:e=60,height:t=38,className:n}){let r=Ji(),i=(0,_.useRef)(null),a=(0,_.useRef)([]),o=(0,_.useRef)(null);return(0,_.useEffect)(()=>{let t=i.current;if(!t)return;let n=t.getContext(`2d`);if(!n)return;let s=Math.min(window.devicePixelRatio??1,2),c=_r(),l=()=>{let i=pl(r,e);if(a.current.length!==e)a.current=i.slice();else if(c)a.current=i;else for(let t=0;t<e;t++){let e=a.current[t]??0,n=i[t]??0;a.current[t]=e+(n-e)*.18}let u=t.clientWidth,d=t.clientHeight;(t.width!==u*s||t.height!==d*s)&&(t.width=u*s,t.height=d*s,n.scale(s,s)),n.clearRect(0,0,u,d);let f=Math.max(1,...a.current),p=u/e;for(let t=0;t<e;t++){let e=a.current[t]??0,r=e/f*d,i=t*p,o=e/f;n.fillStyle=`rgba(${Math.round(56+o*199)},${Math.round(189-o*100)},${Math.round(248-o*200)},${.4+o*.55})`,n.fillRect(i+.5,d-r,Math.max(1,p-1),r)}n.strokeStyle=`rgba(148, 163, 184, 0.1)`,n.lineWidth=1,n.beginPath(),n.moveTo(0,d-.5),n.lineTo(u,d-.5),n.stroke(),o.current=requestAnimationFrame(l)};return o.current=requestAnimationFrame(l),()=>{o.current!==null&&cancelAnimationFrame(o.current),o.current=null}},[r,e]),(0,D.jsxs)(`div`,{className:In(`relative w-full`,n),style:{height:t},children:[(0,D.jsx)(`canvas`,{ref:i,className:`block w-full h-full`,style:{width:`100%`,height:`100%`}}),(0,D.jsxs)(`span`,{className:`absolute top-1 left-2 text-[9px] font-mono uppercase tracking-widest text-[var(--color-fg-4)] pointer-events-none`,children:[`bursts/sec · `,e,`s window`]})]})}var hl=8,gl=6,_l=Math.PI*.75,vl=Math.PI*2.25;function yl({size:e=110,className:t}){let n=Ji(),r=(0,_.useRef)(null),i=(0,_.useRef)(0),a=(0,_.useRef)(null);return(0,_.useEffect)(()=>{let t=r.current;if(!t)return;let o=t.getContext(`2d`);if(!o)return;let s=Math.min(window.devicePixelRatio??1,2),c=_r(),l=()=>{let r=Date.now()-1500,u=0;for(let e=n.length-1;e>=0;e--){let t=n[e];if(t){if(t.ts_ms<r)break;u++}}let d=u/1.5,f=Math.min(1,d/hl);c?i.current=f:i.current+=(f-i.current)*.16;let p=e,m=e;(t.width!==p*s||t.height!==m*s)&&(t.width=p*s,t.height=m*s,t.style.width=`${p}px`,t.style.height=`${m}px`,o.scale(s,s)),o.clearRect(0,0,p,m);let h=p/2,g=m/2+4,_=p/2-8;o.lineWidth=6,o.lineCap=`round`,o.strokeStyle=`rgba(148, 163, 184, 0.18)`,o.beginPath(),o.arc(h,g,_,_l,vl),o.stroke();let v=_l+gl/hl*(vl-_l);o.strokeStyle=`rgba(239, 68, 68, 0.45)`,o.beginPath(),o.arc(h,g,_,v,vl),o.stroke();let y=_l+i.current*(vl-_l),b=i.current*hl>=gl;o.strokeStyle=b?`rgba(239, 68, 68, 0.95)`:`rgba(56, 189, 248, 0.92)`,o.lineWidth=6,o.beginPath(),o.arc(h,g,_,_l,y),o.stroke();let x=h+Math.cos(y)*(_-2),S=g+Math.sin(y)*(_-2);o.strokeStyle=b?`#fca5a5`:`#e0e7ff`,o.lineWidth=2,o.beginPath(),o.moveTo(h,g),o.lineTo(x,S),o.stroke(),o.fillStyle=b?`#fca5a5`:`#e0e7ff`,o.beginPath(),o.arc(h,g,3,0,Math.PI*2),o.fill(),o.fillStyle=b?`#fca5a5`:`#e0e7ff`,o.font=`bold 20px ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace`,o.textAlign=`center`,o.fillText(d.toFixed(1),h,g+_*.55),o.fillStyle=`rgba(148, 163, 184, 0.85)`,o.font=`9px ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace`,o.fillText(`eps`,h,g+_*.55+12),a.current=requestAnimationFrame(l)};return a.current=requestAnimationFrame(l),()=>{a.current!==null&&cancelAnimationFrame(a.current),a.current=null}},[n,e]),(0,D.jsx)(`canvas`,{ref:r,className:In(`block`,t),style:{width:e,height:e}})}var bl={allow:`#22c55e`,block:`#ef4444`,force:`#a855f7`,ask:`#f59e0b`,log:`#60a5fa`,shadow:`#6b7280`},xl=[`allow`,`block`,`force`,`ask`,`log`];function Sl({windowSec:e=30,height:t=14,className:n}){let r=Ji(),[i,a]=(0,_.useState)({}),o=(0,_.useRef)(null);(0,_.useEffect)(()=>{let t=_r(),n=()=>{let i=Date.now()-e*1e3,s={},c=0;for(let e=r.length-1;e>=0;e--){let t=r[e];if(t){if(t.ts_ms<i)break;s[t.decision]=(s[t.decision]??0)+1,c++}}let l={};for(let e of xl)l[e]=c===0?0:(s[e]??0)/c;if(t){a(l);return}a(e=>{let t={};for(let n of xl){let r=e[n]??0;t[n]=r+((l[n]??0)-r)*.22}return t}),o.current=requestAnimationFrame(n)};return o.current=requestAnimationFrame(n),()=>{o.current!==null&&cancelAnimationFrame(o.current),o.current=null}},[r,e]);let s=xl.map(e=>({key:e,color:bl[e]??`#6b7280`,pct:Math.max(0,i[e]??0)})),c=s.reduce((e,t)=>e+t.pct,0)===0;return(0,D.jsxs)(`div`,{className:In(`w-full`,n),children:[(0,D.jsx)(`div`,{className:`flex w-full overflow-hidden rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)]`,style:{height:t},title:`decision mix · last ${e}s`,children:c?(0,D.jsx)(`div`,{className:`w-full h-full flex items-center justify-center text-[9px] font-mono uppercase tracking-widest text-[var(--color-fg-4)]`,children:`— idle —`}):s.map(e=>(0,D.jsx)(`div`,{style:{width:`${e.pct*100}%`,background:e.color,transition:`width 240ms ease-out`},title:`${e.key} · ${(e.pct*100).toFixed(1)}%`},e.key))}),(0,D.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-x-3 gap-y-0.5 text-[9px] font-mono uppercase tracking-widest text-[var(--color-fg-4)]`,children:s.map(e=>(0,D.jsxs)(`span`,{className:`inline-flex items-center gap-1`,children:[(0,D.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-full`,style:{background:e.color}}),e.key,` · `,(e.pct*100).toFixed(0),`%`]},e.key))})]})}var Cl={neutral:`text-[var(--color-fg-0)]`,green:`text-emerald-300`,red:`text-red-300`,amber:`text-amber-300`,blue:`text-sky-300`,purple:`text-violet-300`,gray:`text-[var(--color-fg-3)]`},wl={neutral:`bg-[var(--color-fg-3)]`,green:`bg-emerald-500`,red:`bg-red-500`,amber:`bg-[var(--color-brand)]`,blue:`bg-sky-500`,purple:`bg-violet-500`,gray:`bg-[var(--color-line-2)]`},Tl=[{label:`User code`,color:`#451a03`},{label:`Runtime (bun:/node:)`,color:`#172554`},{label:`Native/other`,color:`#1f2937`},{label:`GC/idle`,color:`#450a0a`}],El={neutral:`#d0d0d0`,green:`#34d399`,red:`#f87171`,amber:`#fbbf24`,blue:`#38bdf8`,purple:`#a78bfa`,gray:`#6e7076`};function Dl({label:e,value:t,sub:n,tone:r=`neutral`,align:i=`left`,labelPlacement:a=`above`,labelClassName:o,valueClassName:s,subClassName:c,trend:l,trendColor:u}){let d=(0,D.jsx)(`div`,{className:In(a===`above`?`overline mb-1.5`:`mt-1 text-[11px] text-[var(--color-fg-3)]`,o),children:e}),f=(0,D.jsx)(`div`,{className:In(`font-mono font-medium tabular-nums`,i===`center`&&`text-center`,Cl[r],s),children:t}),p=l&&l.length>1,m=u??El[r];return(0,D.jsxs)(D.Fragment,{children:[a===`above`&&d,p?(0,D.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[f,(0,D.jsx)(Js,{data:l,width:48,height:18,color:m})]}):f,a===`below`&&d,n&&(0,D.jsx)(`div`,{className:In(`mt-1 text-[10px] font-mono text-[var(--color-fg-3)]`,i===`center`&&`text-center`,c),children:n})]})}function Ol({className:e,contentClassName:t,label:n,value:r,sub:i,tone:a,align:o,labelPlacement:s,labelClassName:c,valueClassName:l,subClassName:u,trend:d,trendColor:f,...p}){return(0,D.jsx)(K,{className:e,...p,children:(0,D.jsx)(J,{className:In(`py-3`,o===`center`&&`text-center`,t),children:(0,D.jsx)(Dl,{label:n,value:r,sub:i,tone:a,align:o,labelPlacement:s,labelClassName:c,valueClassName:l,subClassName:u,trend:d,trendColor:f})})})}function kl({className:e,...t}){return(0,D.jsx)(`div`,{className:In(`rounded-sm border border-[var(--color-line-0)] bg-[var(--color-surface-1)] p-3`,t.align===`center`&&`text-center`,e),children:(0,D.jsx)(Dl,{...t})})}function Al({pct:e,tone:t=`green`,markerPct:n,className:r,barClassName:i,markerTitle:a}){let o=Math.max(0,Math.min(100,e)),s=n===void 0?null:Math.max(0,Math.min(100,n));return(0,D.jsxs)(`div`,{className:In(`relative w-full overflow-hidden rounded-sm bg-[var(--color-surface-3)]`,r),children:[(0,D.jsx)(`div`,{className:In(`h-full rounded-sm transition-all duration-500`,wl[t],i),style:{width:`${o}%`}}),s!==null&&(0,D.jsx)(`div`,{className:`absolute top-0 h-full w-0.5 bg-[var(--color-brand)]/70`,style:{left:`${s}%`},title:a})]})}function jl({label:e,value:t,tone:n=`neutral`,breached:r=!1,breachLabel:i=`limit exceeded`,trendData:a,trendColor:o,threshold:s,maxValue:c,footer:l,className:u,valueClassName:d}){return(0,D.jsxs)(K,{className:u,children:[(0,D.jsxs)(q,{className:`py-2`,children:[(0,D.jsx)(`span`,{className:`overline`,children:e}),r&&(0,D.jsx)(`span`,{className:`text-[10px] font-mono uppercase tracking-wider text-red-300`,children:i})]}),(0,D.jsxs)(J,{children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,D.jsx)(`div`,{className:In(`text-2xl font-mono font-medium tabular-nums`,Cl[n],d),children:t}),(a?.length??0)>1&&o&&(0,D.jsx)(Js,{data:a??[],width:80,height:28,color:o,threshold:s,maxValue:c})]}),l]})]})}function Ml({profile:e,children:t}){return(0,D.jsxs)(`div`,{className:`space-y-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-4 text-[11px] font-mono text-[var(--color-fg-3)]`,children:[(0,D.jsxs)(`span`,{children:[`nodes:`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:e.nodes.length})]}),(0,D.jsxs)(`span`,{children:[`duration:`,` `,(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-1)]`,children:[((e.endTime-e.startTime)/1e3).toFixed(0),`ms`]})]}),(0,D.jsxs)(`span`,{children:[`samples:`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:e.samples?.length??0})]})]}),(0,D.jsx)(`div`,{className:`flex gap-3 text-[10px] font-mono text-[var(--color-fg-3)]`,children:Tl.map(e=>(0,D.jsxs)(`span`,{className:`flex items-center`,children:[(0,D.jsx)(`span`,{className:`mr-1 inline-block h-2.5 w-2.5 rounded-[1px]`,style:{background:e.color}}),e.label]},e.label))}),t]})}function Nl({memory:e,formatValue:t}){return(0,D.jsx)(`div`,{className:`grid grid-cols-4 gap-3`,children:[{label:`RSS`,value:t(e.rss)},{label:`Heap Total`,value:t(e.heapTotal)},{label:`Heap Used`,value:t(e.heapUsed)},{label:`External`,value:t(e.external)}].map(e=>(0,D.jsx)(kl,{align:`center`,label:e.label,value:e.value,valueClassName:`text-lg font-medium text-[var(--color-fg-0)]`},e.label))})}var Pl=3;function Q(e){return e===null?`—`:e<1e6?`${(e/1e3).toFixed(0)}µs`:`${(e/1e6).toFixed(1)}ms`}var Fl=[`counters-updated`,`activity-updated`,`pending-changed`,`runtime-tick`,`limits-breach`];function Il({info:e}){let t=e.tier===`pro`||e.tier===`enterprise`,n=e.status===`needs_reauth`,r=e.pct_used??0,i=r>=90?`bg-red-500`:r>=70?`bg-amber-500`:`bg-emerald-500`;return(0,D.jsxs)(K,{className:n?`border-l-2 border-l-amber-500/70`:t?`border-l-2 border-l-emerald-500/70`:`border-l-2 border-l-sky-500/70`,children:[(0,D.jsxs)(q,{children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`text-xs font-mono uppercase tracking-wider text-[var(--color-fg-3)]`,children:`license`}),(0,D.jsx)(W,{variant:t?`green`:n?`amber`:`blue`,children:e.tier_label}),e.fleet_enrolled&&(0,D.jsx)(W,{variant:`gray`,children:`fleet`})]}),e.email&&(0,D.jsx)(`span`,{className:`text-xs text-[var(--color-fg-3)]`,children:e.email})]}),(0,D.jsxs)(J,{className:`space-y-3`,children:[n&&e.detail&&(0,D.jsxs)(`div`,{className:`rounded border border-amber-500/40 bg-amber-500/10 px-3 py-2 text-xs text-amber-200`,children:[e.detail,` — run`,` `,(0,D.jsx)(`code`,{className:`font-mono`,children:`ssg auth login`})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`flex justify-between text-xs text-[var(--color-fg-2)]`,children:[(0,D.jsx)(`span`,{children:`evals today`}),(0,D.jsxs)(`span`,{children:[(0,D.jsx)(Ks,{value:e.evals_today,curve:`spring`}),e.eval_daily_limit!==null&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)]`,children:` / `}),e.eval_daily_limit.toLocaleString()]}),e.eval_daily_limit===null&&(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)]`,children:` · unlimited`})]})]}),e.eval_daily_limit!==null&&(0,D.jsx)(`div`,{className:`mt-1 h-1.5 w-full overflow-hidden rounded-full bg-[var(--color-bg-2)]`,children:(0,D.jsx)(`div`,{className:`h-full transition-all duration-700 ease-out ${i}`,style:{width:`${r}%`}})})]}),!t&&(0,D.jsxs)(`a`,{href:e.upgrade_url,target:`_blank`,rel:`noopener noreferrer`,className:`inline-flex items-center gap-1 text-xs text-[var(--color-brand)] hover:underline`,children:[`Upgrade to Pro · $`,e.pricing.pro_monthly_usd,`/mo →`]}),t&&e.retention_days>0&&(0,D.jsxs)(`div`,{className:`text-[10px] text-[var(--color-fg-3)] font-mono uppercase tracking-wider`,children:[`cloud retention: `,e.retention_days,` days`]})]})]})}function Ll(e){return new Date(e*1e3).toLocaleTimeString()}function Rl(e,t=24){let n=(0,_.useRef)(null),[r,i]=(0,_.useState)([]);return(0,_.useEffect)(()=>{let r=n.current;if(n.current=e,r===null)return;let a=Math.max(0,e-r);i(e=>{let n=e.length>=t?e.slice(-(t-1)):e.slice();return n.push(a),n})},[e,t]),r}async function zl(e,t){await fetch(`/api/decide/${e}?decision=${t}`,{method:`POST`,headers:U()})}async function Bl(e,t){let n=await fetch(`/api/rules/toggle`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`,...U()},body:JSON.stringify({ruleId:e,file:t})});if(!n.ok)throw Error(`Toggle failed: ${n.status}`)}async function Vl(e,t){let n=await fetch(`/api/rules/toggle`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`,...U()},body:JSON.stringify({ruleId:e,file:t})});if(!n.ok)throw Error(`Toggle failed: ${n.status}`)}async function Hl(e,t){let n=await fetch(`/api/rules/update-decision`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({ruleId:e,file:t,decision:`ask`})});if(!n.ok)throw Error(`Update decision failed: ${n.status}`)}async function Ul(e,t){let n=await fetch(`/api/rules/update-decision`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({ruleId:e,file:t,decision:`block`})});if(!n.ok)throw Error(`Update decision failed: ${n.status}`)}function Wl({ruleId:e}){return e?(0,D.jsx)(`a`,{href:`/rules?highlight=${encodeURIComponent(e)}`,className:`text-[var(--color-brand)] hover:underline text-xs font-mono break-all`,title:`Go to rule: ${e}`,children:e}):(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`—`})}function Gl({title:e,right:t}){return(0,D.jsxs)(`div`,{className:`flex items-center justify-between mb-3`,children:[(0,D.jsx)(`h2`,{className:`overline text-[11px]`,children:e}),t]})}function Kl({children:e}){return(0,D.jsx)(`div`,{className:`rounded-sm border border-dashed border-[var(--color-line-1)] bg-[var(--color-surface-1)]/50 px-4 py-6 text-center text-[11px] font-mono text-[var(--color-fg-3)]`,children:e})}function ql({item:e,onDisable:t,onChangeToAsk:n,onUndo:r}){let[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(`idle`),[c,l]=(0,_.useState)(!1),u=zn(e.tool,e.input),d=e.rule_id&&e.source_file,f=e.decision===`force`?`force`:`block`,p=f===`force`?`amber`:`red`,m=async()=>{s(`loading`);try{await n(),s(`done-ask`)}catch{s(`error`)}},h=async()=>{s(`loading`);try{await t(),s(`done-disable`)}catch{s(`error`)}},g=async()=>{l(!0);try{await r(o===`done-disable`?`disable`:`ask`),s(`idle`)}catch{}finally{l(!1)}},v=o===`done-ask`||o===`done-disable`;return(0,D.jsx)(K,{className:`border-l-2 ${v?`border-l-[var(--color-line-1)]`:f===`force`?`border-l-amber-400/60`:`border-l-red-500/60`} ${v?`opacity-60`:``}`,children:(0,D.jsxs)(`div`,{className:`px-3 py-3`,children:[v&&(0,D.jsxs)(`div`,{className:`flex items-center justify-between rounded-sm px-2.5 py-1.5 mb-3 text-[11px] font-mono ${o===`done-ask`?`bg-sky-500/5 border border-sky-500/25 text-sky-300`:`bg-amber-500/5 border border-amber-500/25 text-amber-300`}`,children:[(0,D.jsx)(`span`,{className:`truncate`,children:o===`done-ask`?`✓ rule "${e.rule_id}" → ask · prompts next time`:`✓ rule "${e.rule_id}" disabled · no longer blocks`}),(0,D.jsx)(`button`,{onClick:g,disabled:c,className:`ml-3 shrink-0 px-2 py-0.5 rounded-sm border border-current/40 hover:bg-white/5 transition-colors cursor-pointer disabled:opacity-50 uppercase tracking-wider text-[10px]`,children:c?`…`:`↩ undo`})]}),o===`error`&&(0,D.jsxs)(`div`,{className:`flex items-center justify-between rounded-sm px-2.5 py-1.5 mb-3 text-[11px] font-mono bg-red-500/5 border border-red-500/25 text-red-300`,children:[(0,D.jsx)(`span`,{children:`failed to update rule — check server logs`}),(0,D.jsx)(`button`,{onClick:()=>s(`idle`),className:`ml-3 shrink-0 px-2 py-0.5 rounded-sm border border-current/40 hover:bg-white/5 transition-colors cursor-pointer uppercase tracking-wider text-[10px]`,children:`retry`})]}),(0,D.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,D.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5 flex-wrap`,children:[(0,D.jsx)(W,{variant:v?o===`done-ask`?`blue`:`gray`:p,children:v?o===`done-ask`?`ask`:`disabled`:f}),(0,D.jsx)(`code`,{className:`text-[var(--color-brand)] text-xs font-mono`,children:e.tool}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] text-xs`,children:`·`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] text-[11px] font-mono tabular-nums`,children:Ll(e.timestamp)}),e.repeat_count>1&&(0,D.jsxs)(W,{variant:`gray`,children:[`×`,e.repeat_count]})]}),(0,D.jsx)(`div`,{className:`text-xs font-mono truncate cursor-pointer hover:text-[var(--color-fg-0)] transition-colors ${v?`text-[var(--color-fg-4)] line-through`:`text-[var(--color-fg-1)]`}`,title:u,onClick:()=>a(e=>!e),children:u})]}),d&&!v&&o!==`error`&&(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5 shrink-0 pt-0.5`,children:[(0,D.jsxs)(`button`,{onClick:m,disabled:o===`loading`,className:`inline-flex items-center gap-1 h-7 px-2.5 rounded-sm text-[11px] font-medium uppercase tracking-wider bg-sky-500/8 text-sky-300 border border-sky-500/25 hover:bg-sky-500/15 hover:border-sky-500/40 transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed`,children:[o===`loading`?(0,D.jsx)(`span`,{className:`animate-spin`,children:`⟳`}):(0,D.jsxs)(`svg`,{width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,D.jsx)(`path`,{d:`M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3`}),(0,D.jsx)(`line`,{x1:`12`,y1:`17`,x2:`12.01`,y2:`17`})]}),`ask instead`]}),(0,D.jsxs)(`button`,{onClick:h,disabled:o===`loading`,className:`inline-flex items-center gap-1 h-7 px-2.5 rounded-sm text-[11px] font-medium uppercase tracking-wider bg-red-500/8 text-red-300 border border-red-500/25 hover:bg-red-500/15 hover:border-red-500/40 transition-colors cursor-pointer disabled:opacity-50 disabled:cursor-not-allowed`,children:[o===`loading`?(0,D.jsx)(`span`,{className:`animate-spin`,children:`⟳`}):(0,D.jsxs)(`svg`,{width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,D.jsx)(`line`,{x1:`15`,y1:`9`,x2:`9`,y2:`15`}),(0,D.jsx)(`line`,{x1:`9`,y1:`9`,x2:`15`,y2:`15`})]}),`disable rule`]})]})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-4 gap-y-1 mt-2 text-[11px] font-mono`,children:[e.rule_id&&(0,D.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] uppercase tracking-wider text-[10px]`,children:`rule`}),(0,D.jsx)(Wl,{ruleId:e.rule_id})]}),e.source_file&&(0,D.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] uppercase tracking-wider text-[10px]`,children:`src`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:e.source_file})]}),e.rules_evaluated!==null&&(0,D.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] uppercase tracking-wider text-[10px]`,children:`evals`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)] tabular-nums`,children:e.rules_evaluated})]}),(0,D.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] uppercase tracking-wider text-[10px]`,children:`latency`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)] tabular-nums`,children:Q(e.duration_ns)})]}),(0,D.jsx)(`button`,{onClick:()=>a(e=>!e),className:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-0)] transition-colors ml-auto cursor-pointer uppercase tracking-wider text-[10px]`,children:i?`▾ hide`:`▸ details`})]}),i&&(0,D.jsxs)(`div`,{className:`mt-3 pt-3 border-t border-[var(--color-line-0)]`,children:[(0,D.jsx)(`div`,{className:`overline mb-2`,children:`full input`}),(0,D.jsx)(zr,{children:(()=>{try{return JSON.stringify(JSON.parse(e.input),null,2)}catch{return e.input}})()})]})]})})}function Jl(){let e=V(Fl),t=[e[`counters-updated`],e[`activity-updated`],e[`pending-changed`]],{activeProject:n}=Be(),{data:r}=k(Ve(`/api/state/counters`,n),[...t,n]),{data:i,refetch:a}=k(`/api/json/pending`,t),{data:o,refetch:s}=k(`/api/json/blocked`,t),{data:c}=k(Ve(`/api/state/activity`,n),[...t,n]),{data:l}=k(`/api/state/runtime`,[e[`runtime-tick`]]),{data:u}=k(`/api/json/limits`,[e[`limits-breach`]]),{data:d}=k(`/api/json/license`,[e[`activity-updated`]]),[f,p]=(0,_.useState)(!1),m=o?.reduce((e,t)=>e+t.repeat_count,0)??0,h=r?.allow??0,g=(r?.block??0)+(r?.force??0),v=r?.force??0,y=r?.pending??0,b=r?.log??0,x=Rl(h),S=Rl(g),C=Rl(v),w=Rl(y),T=Rl(b),E=[{label:`allow`,value:h,tone:`green`,trend:x},{label:`block`,value:g,tone:`red`,trend:S},{label:`force`,value:v,tone:`amber`,trend:C},{label:`pending`,value:y,tone:`blue`,trend:w},{label:`log`,value:b,tone:`gray`,trend:T}];return(0,D.jsxs)(`div`,{ref:Kc({from:`first`}),className:`space-y-8`,children:[(0,D.jsx)(Hs,{}),(0,D.jsx)(`div`,{"data-reveal":!0,children:(0,D.jsx)(ul,{})}),(0,D.jsx)(`div`,{"data-tutorial":`dash-stats`,className:`grid grid-cols-2 sm:grid-cols-5 gap-2`,children:E.map(e=>(0,D.jsx)(Ol,{align:`left`,label:e.label,value:(0,D.jsx)(Ks,{value:e.value,curve:`spring`}),tone:e.tone,labelPlacement:`above`,contentClassName:`py-3`,valueClassName:`text-2xl font-medium`,trend:e.trend,"data-reveal":!0},e.label))}),(0,D.jsxs)(`div`,{"data-reveal":!0,"data-tutorial":`dash-meters`,className:`grid grid-cols-12 gap-2 items-stretch`,children:[(0,D.jsxs)(`div`,{className:`col-span-12 md:col-span-7 rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] px-3 py-2 flex flex-col gap-2`,children:[(0,D.jsx)(ml,{bins:60,height:42}),(0,D.jsx)(Sl,{windowSec:60,height:12})]}),(0,D.jsx)(`div`,{className:`col-span-12 md:col-span-5 rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] px-3 py-2 flex items-center justify-center`,children:(0,D.jsx)(yl,{size:130})})]}),d&&(0,D.jsx)(`div`,{"data-reveal":!0,children:(0,D.jsx)(Il,{info:d})}),l&&(0,D.jsxs)(`div`,{"data-reveal":!0,className:`grid grid-cols-2 gap-2`,children:[(0,D.jsx)(jl,{label:`cpu`,value:l.cpu_pct==null?`—`:(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(Ks,{value:l.cpu_pct,format:e=>Math.round(e).toString()}),`%`]}),tone:u?.breaches.cpu?`red`:(l.cpu_pct??0)>=60?`amber`:`green`,breached:u?.breaches.cpu??!1,trendData:l.history?.cpu_pct,trendColor:u?.breaches.cpu?`#f87171`:`#34d399`,threshold:u?.config.cpuLimitPct,maxValue:100,className:u?.breaches.cpu?`border-red-500/40`:``,footer:(0,D.jsx)(`a`,{href:`/monitor`,className:`mt-1 block text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-brand)]`,children:`view details →`})}),(0,D.jsx)(jl,{label:`memory rss`,value:l.memory_rss_mb==null?`—`:(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(Ks,{value:l.memory_rss_mb,format:e=>Math.round(e).toString()}),(0,D.jsx)(`span`,{className:`ml-1 text-sm text-[var(--color-fg-3)]`,children:`MB`})]}),tone:u?.breaches.memory?`red`:`neutral`,breached:u?.breaches.memory??!1,trendData:l.history?.memory_rss_mb,trendColor:u?.breaches.memory?`#f87171`:`#38bdf8`,threshold:u?.config.memoryLimitMb,className:u?.breaches.memory?`border-red-500/40`:``,footer:(0,D.jsx)(`a`,{href:`/monitor`,className:`mt-1 block text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-brand)]`,children:`view details →`})})]}),(0,D.jsxs)(`section`,{"data-reveal":!0,"data-tutorial":`dash-approvals`,children:[(0,D.jsx)(Gl,{title:`pending approvals`}),!i||i.length===0?(0,D.jsx)(Kl,{children:`no pending approvals`}):(0,D.jsx)(`div`,{className:`space-y-2`,children:i.map(e=>(0,D.jsxs)(K,{className:`border-l-2 border-l-sky-500/50`,children:[(0,D.jsxs)(q,{children:[(0,D.jsx)(`span`,{className:`text-sm text-[var(--color-fg-0)]`,children:e.ruleMessage}),(0,D.jsxs)(`div`,{className:`flex gap-2`,children:[(0,D.jsx)(G,{size:`sm`,variant:`primary`,onClick:async()=>{await zl(e.id,`allow`),a()},children:`approve`}),(0,D.jsx)(G,{size:`sm`,variant:`danger`,onClick:async()=>{await zl(e.id,`block`),a()},children:`deny`})]})]}),(0,D.jsxs)(J,{className:`space-y-2 text-xs`,children:[(0,D.jsxs)(`div`,{className:`flex gap-2 items-center`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`tool`}),(0,D.jsx)(`code`,{className:`text-[var(--color-brand)] font-mono`,children:e.toolCall.tool})]}),e.prompt&&(0,D.jsxs)(`div`,{className:`flex gap-2 items-start`,children:[(0,D.jsx)(`span`,{className:`overline pt-0.5`,children:`prompt`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] truncate`,children:e.prompt})]}),(0,D.jsx)(zr,{children:JSON.stringify(e.toolCall.input,null,2)})]})]},e.id))})]}),o&&o.length>0&&(0,D.jsxs)(`section`,{"data-reveal":!0,children:[(0,D.jsx)(Gl,{title:`blocked actions`,right:(0,D.jsxs)(`span`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:[o.length,` active`,m>o.length?` · ${m} total hits`:``]})}),(0,D.jsx)(`div`,{className:`space-y-2`,children:(f?o:o.slice(0,Pl)).map(e=>(0,D.jsx)(ql,{item:e,onDisable:async()=>{await Bl(e.rule_id,e.source_file),s()},onChangeToAsk:async()=>{await Hl(e.rule_id,e.source_file),s()},onUndo:async t=>{t===`disable`?await Vl(e.rule_id,e.source_file):await Ul(e.rule_id,e.source_file),s()}},`${e.decision}:${e.rule_id??`none`}:${e.tool}:${e.timestamp}:${e.input}`))}),o.length>Pl&&(0,D.jsx)(`div`,{className:`mt-3 flex justify-center`,children:(0,D.jsx)(G,{size:`sm`,variant:`secondary`,onClick:()=>p(e=>!e),children:f?`↑ show less`:`↓ show ${o.length-Pl} more`})})]}),(0,D.jsxs)(`section`,{"data-reveal":!0,"data-tutorial":`dash-audit`,children:[(0,D.jsx)(Gl,{title:`recent audit log`,right:c&&c.length>0?(0,D.jsx)(`a`,{href:`/audit`,className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-brand)] transition-colors`,children:`view all →`}):void 0}),!c||c.length===0?(0,D.jsx)(Kl,{children:`no audit entries yet`}):(0,D.jsx)(`div`,{className:`space-y-1.5`,children:c.slice(0,15).map(e=>(0,D.jsx)(zi,{row:e},e.id))})]})]})}var Yl=[{id:`rca`,label:`rca`,hint:`pre-computed root cause`},{id:`timeline`,label:`timeline`,hint:`recent frames across traces`},{id:`watch`,label:`watch`,hint:`subscribe to any ssg:// URI`},{id:`state`,label:`state`,hint:`daemon runtime snapshot`},{id:`metrics`,label:`metrics`,hint:`latency + counters`}],Xl={rca:{title:`Root Cause Analysis`,body:`When an eval errors, an ssqa finding arrives, or a daemon-level error fires, SSG auto-composes a diagnosis with ranked hypotheses, evidence, and suggested next actions — the same pack Claude reads through MCP.`,useWhen:`Something just broke and you want the short version before grepping logs.`},timeline:{title:`Eval Timeline`,body:`Flame-chart of the last 1024 frames across every rule and tool call. Each row is one tool call (trace_id); each bar is one pipeline stage colored by kind; a red outline means that stage errored.`,useWhen:`You want to see which stages a rule went through and how long each took. Click a bar to inspect the frame.`},watch:{title:`Live URI Watch`,body:`Subscribe to any ssg:// resource and watch it update as the daemon emits events. Every CLI, MCP, and dashboard surface ultimately reads through these same URIs.`,useWhen:`You know exactly which internal resource (rules, audit rows, frames, RCA pack, native stats) you want to inspect.`},state:{title:`Daemon Snapshot`,body:`Live vitals for the SSG daemon process — uptime, rules loaded, native FFI availability, frame ring size, eval quotas, audit worker readiness.`,useWhen:`The daemon feels off (slow, dropping events, refusing calls) and you want to confirm it's healthy.`},metrics:{title:`Performance Counters`,body:`Latency distributions and event counters for the eval pipeline (per-stage timings, native call overhead, audit throughput).`,useWhen:`Evals feel slow and you want to find the hot stage before optimizing.`}};function Zl(){let[e,t]=(0,_.useState)(`rca`);return(0,D.jsxs)(`div`,{className:`flex flex-col gap-4 min-h-[70vh]`,children:[(0,D.jsxs)(`header`,{className:`space-y-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,D.jsx)(`h1`,{className:`text-sm font-mono uppercase tracking-wider text-[var(--color-fg-1)]`,children:`ai-native debugger`}),(0,D.jsx)(`span`,{className:`chip text-sky-300 border-sky-500/30`,children:`ssg:// unified resolver`}),(0,D.jsx)(ru,{})]}),(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`one surface · cli · mcp · dashboard`})]}),(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-3)] max-w-3xl leading-snug`,children:`See exactly what happened inside SSG during recent rule evaluations — which stage ran, which rule matched, how long each step took, and what went wrong. The same data Claude reads via MCP.`})]}),(0,D.jsx)($l,{}),(0,D.jsx)(tu,{}),(0,D.jsx)(`nav`,{"data-tutorial":`debug-tabs`,className:`flex items-center gap-1 border-b border-[var(--color-line-1)]`,children:Yl.map(n=>(0,D.jsx)(`button`,{type:`button`,onClick:()=>t(n.id),title:n.hint,className:`px-3 py-1.5 text-[11px] font-mono uppercase tracking-wider border-b-2 transition-colors `+(e===n.id?`border-[var(--color-brand)] text-[var(--color-fg-1)]`:`border-transparent text-[var(--color-fg-4)] hover:text-[var(--color-fg-2)]`),children:n.label},n.id))}),(0,D.jsx)(nu,{tab:e}),(0,D.jsxs)(`section`,{"data-tutorial":`debug-pane`,className:`flex-1 min-h-0`,children:[e===`rca`&&(0,D.jsx)(iu,{}),e===`timeline`&&(0,D.jsx)(lu,{}),e===`watch`&&(0,D.jsx)(_u,{}),e===`state`&&(0,D.jsx)(vu,{uri:`ssg://daemon/state`}),e===`metrics`&&(0,D.jsx)(vu,{uri:`ssg://daemon/metrics`})]})]})}var Ql=`ssg.debug.intro.dismissed`;function $l(){let[e,t]=(0,_.useState)(()=>{if(typeof window>`u`)return!1;try{return window.localStorage.getItem(Ql)===`1`}catch{return!1}});return e?(0,D.jsx)(`div`,{className:`flex justify-end`,children:(0,D.jsx)(`button`,{type:`button`,onClick:()=>{t(!1);try{window.localStorage.removeItem(Ql)}catch{}},className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-4)] hover:text-[var(--color-fg-2)]`,children:`what is this?`})}):(0,D.jsx)(`aside`,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-4 space-y-3`,children:(0,D.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,D.jsxs)(`div`,{className:`space-y-3 min-w-0 flex-1`,children:[(0,D.jsx)(`p`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-4)]`,children:`who this page is for`}),(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-2)] leading-relaxed`,children:`SSG sits between your AI coding agent (Claude Code, Cursor, Copilot, …) and your filesystem/shell, deciding which tool calls to allow, block, or warn on. This page is the window into those decisions — useful any time SSG's behavior surprises you.`}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`p`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-4)] mb-1.5`,children:`what you'd use it for`}),(0,D.jsx)(`table`,{className:`text-[12px] text-[var(--color-fg-3)] w-full border-separate border-spacing-y-1`,children:(0,D.jsxs)(`tbody`,{children:[(0,D.jsx)(eu,{question:`Why did SSG block my agent from running this command?`,tab:`rca`,how:`open RCA — or find the trace in Timeline and read the deciding rule`}),(0,D.jsx)(eu,{question:`I just wrote a rule. Did it actually fire?`,tab:`timeline`,how:`trigger the tool call, find your trace, look for your rule_id in a match-stage bar`}),(0,D.jsx)(eu,{question:`Are my rules even loaded? Did a syntax error skip one?`,tab:`state`,how:`check the rules_loaded count — or open Watch and resolve ssg://rules/list`}),(0,D.jsx)(eu,{question:`My agent feels slow when SSG is on — is SSG the cause?`,tab:`metrics`,how:`look at per-stage latency; the hot stage tells you whether parse, match, native FFI, or audit is the culprit`}),(0,D.jsx)(eu,{question:`Something errored and I want a one-line diagnosis before reading logs`,tab:`rca`,how:`the latest RCA pack ranks hypotheses by confidence and suggests next actions`})]})})]}),(0,D.jsxs)(`p`,{className:`text-[11px] text-[var(--color-fg-4)] leading-relaxed`,children:[(0,D.jsx)(`span`,{className:`font-mono uppercase tracking-wider`,children:`heads up ·`}),` `,`The Timeline (every frame of every eval) is opt-in because it adds overhead. Restart the daemon with`,` `,(0,D.jsx)(`code`,{className:`text-amber-300 font-mono`,children:`SSG_DEBUG_ENABLED=1 ./ssg daemon`}),` `,`to turn it on. RCA, State, and Metrics work without it.`]})]}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>{t(!0);try{window.localStorage.setItem(Ql,`1`)}catch{}},className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-4)] hover:text-[var(--color-fg-2)] shrink-0`,title:`Hide this panel`,children:`hide`})]})})}function eu({question:e,tab:t,how:n}){return(0,D.jsxs)(`tr`,{children:[(0,D.jsx)(`td`,{className:`align-top pr-3 text-[12px] text-[var(--color-fg-2)] w-[55%]`,children:e}),(0,D.jsx)(`td`,{className:`align-top pr-3 w-[80px]`,children:(0,D.jsx)(`span`,{className:`chip text-[10px] uppercase tracking-wider text-sky-300 border-sky-500/30`,children:t})}),(0,D.jsx)(`td`,{className:`align-top text-[11px] text-[var(--color-fg-4)] leading-snug`,children:n})]})}function tu(){let{data:e}=k(`/api/json/debug?uri=ssg%3A%2F%2Fdaemon%2Fstate`,[]);return e?.data?.debug_enabled===!1?(0,D.jsxs)(`aside`,{className:`rounded-sm border border-amber-500/40 bg-amber-500/5 p-3 text-[12px] text-amber-200 space-y-1`,children:[(0,D.jsx)(`p`,{className:`text-[11px] font-mono uppercase tracking-wider text-amber-300`,children:`timeline disabled · frame collection is off`}),(0,D.jsx)(`p`,{className:`text-[12px] leading-snug`,children:`The daemon is running but not capturing per-stage eval frames — so the Timeline tab will stay empty no matter how many tool calls fire. RCA, State, and Metrics still work.`}),(0,D.jsxs)(`p`,{className:`text-[12px] leading-snug`,children:[`To turn frame capture on, restart with`,` `,(0,D.jsx)(`code`,{className:`text-amber-100 font-mono bg-amber-900/30 px-1.5 py-0.5 rounded-sm`,children:`SSG_DEBUG_ENABLED=1 ./ssg daemon`}),`. It's opt-in because collecting every frame adds overhead on the hot path.`]})]}):null}function nu({tab:e}){let t=Xl[e];return(0,D.jsxs)(`div`,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] px-3 py-2 space-y-1`,children:[(0,D.jsx)(`p`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-4)]`,children:t.title}),(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-2)] leading-snug`,children:t.body}),(0,D.jsxs)(`p`,{className:`text-[11px] text-[var(--color-fg-4)] leading-snug`,children:[(0,D.jsx)(`span`,{className:`font-mono uppercase tracking-wider`,children:`use when ·`}),` `,t.useWhen]})]})}function ru(){let e=V([`debug-frame`])[`debug-frame`]??0,{data:t}=k(`/api/json/debug?uri=ssg%3A%2F%2Fdaemon%2Fstate`,[e]),n=t?.data?.debug_enabled;return n===!1?(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] font-mono uppercase tracking-wider text-amber-300`,title:`Frame collection is OFF. Restart the daemon with SSG_DEBUG_ENABLED=1 to capture frames.`,children:[(0,D.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-sm bg-amber-400`}),`debug off`]}):n===void 0?(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-4)]`,children:[(0,D.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-sm bg-[var(--color-fg-4)]`}),`connecting…`]}):(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] font-mono uppercase tracking-wider text-emerald-300`,title:`Debug collection is on. ${e} debug-frame bursts received this session.`,children:[(0,D.jsx)(`span`,{className:`status-dot bg-emerald-400 pulse-soft`}),`live · `,e]})}function iu(){let e=V([`debug-frame`,`activity-updated`]),{data:t,loading:n,error:r,refetch:i}=k(`/api/json/debug?uri=ssg%3A%2F%2Frca%2Fcurrent`,[e[`debug-frame`],e[`activity-updated`]]),a=t?.data?.pack??null;return(0,D.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-[1fr_340px] gap-4`,children:[(0,D.jsxs)(`article`,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-4 space-y-3`,children:[n&&!t&&(0,D.jsx)(`p`,{className:`text-sm text-[var(--color-fg-4)]`,children:`loading RCA pack…`}),r&&(0,D.jsxs)(`p`,{className:`text-sm text-rose-300`,children:[`rca fetch error: `,r]}),!n&&!a&&(0,D.jsxs)(`div`,{className:`text-sm text-[var(--color-fg-3)] space-y-2`,children:[(0,D.jsx)(`p`,{className:`font-mono`,children:`no current RCA pack`}),(0,D.jsx)(`p`,{className:`text-[11px] text-[var(--color-fg-4)]`,children:`Packs are composed automatically when an eval errors, an ssqa finding arrives, or a daemon-level error fires. Nothing to diagnose yet — you're green.`})]}),a&&(0,D.jsx)(ou,{pack:a})]}),(0,D.jsxs)(`aside`,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3 text-[11px] font-mono text-[var(--color-fg-4)] space-y-2`,children:[(0,D.jsx)(`p`,{className:`uppercase tracking-wider text-[var(--color-fg-2)]`,children:`how claude sees this`}),(0,D.jsxs)(`pre`,{className:`text-[10px] whitespace-pre-wrap leading-snug`,children:[`ssg debug rca --current --json`,`
13
13
  `,`# or via MCP:`,`
14
14
  `,`ssg_debug_rca(`,`{`,`auto_current:true`,`}`,`)`]}),(0,D.jsx)(`button`,{type:`button`,onClick:i,className:`w-full mt-2 px-2 py-1 border border-[var(--color-line-1)] rounded-sm hover:bg-[var(--color-surface-2)]`,children:`refresh`}),t?.snapshot_hash&&(0,D.jsxs)(`p`,{className:`text-[10px] opacity-60`,children:[`hash `,t.snapshot_hash.slice(0,12),`…`]})]})]})}function au(e){return e===`critical`?`text-rose-400 border-rose-500/40`:e===`high`?`text-amber-300 border-amber-500/40`:e===`medium`?`text-sky-300 border-sky-500/40`:`text-[var(--color-fg-3)] border-[var(--color-line-1)]`}function ou({pack:e}){return(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`header`,{className:`flex items-start justify-between gap-4`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`p`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-4)]`,children:[`rca pack · `,new Date(e.ts_ms).toLocaleTimeString()]}),(0,D.jsx)(`h2`,{className:`text-[15px] font-medium text-[var(--color-fg-1)] mt-1`,children:e.summary}),e.trace_id&&(0,D.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)] mt-1`,children:[`trace_id · `,e.trace_id]})]}),(0,D.jsx)(`span`,{className:`chip uppercase text-[10px] tracking-wider `+au(e.severity),children:e.severity})]}),e.hypothesis&&e.hypothesis.length>0&&(0,D.jsxs)(`section`,{children:[(0,D.jsx)(`h3`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] mb-2`,children:`hypothesis`}),(0,D.jsx)(`ol`,{className:`space-y-2`,children:e.hypothesis.map((e,t)=>(0,D.jsxs)(`li`,{className:`p-2 rounded-sm bg-[var(--color-surface-2)] border border-[var(--color-line-1)]`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,D.jsx)(`p`,{className:`text-[13px] text-[var(--color-fg-1)]`,children:e.cause}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:[`conf `,(e.confidence*100).toFixed(0),`%`]})]}),e.evidence.length>0&&(0,D.jsx)(`ul`,{className:`mt-1 pl-3 text-[11px] text-[var(--color-fg-3)] list-disc list-inside space-y-0.5`,children:e.evidence.map((e,t)=>(0,D.jsx)(`li`,{children:e},t))})]},t))})]}),e.suggested_next_actions&&e.suggested_next_actions.length>0&&(0,D.jsxs)(`section`,{children:[(0,D.jsx)(`h3`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] mb-2`,children:`suggested next actions`}),(0,D.jsx)(`ul`,{className:`space-y-1 text-[13px] text-[var(--color-fg-2)]`,children:e.suggested_next_actions.map((e,t)=>(0,D.jsxs)(`li`,{className:`font-mono text-[12px]`,children:[`→ `,e]},t))})]}),e.state_snapshot&&e.state_snapshot.length>0&&(0,D.jsxs)(`section`,{children:[(0,D.jsx)(`h3`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] mb-2`,children:`expand`}),(0,D.jsx)(`ul`,{className:`space-y-1 text-[11px] font-mono`,children:e.state_snapshot.map(e=>(0,D.jsxs)(`li`,{className:`text-[var(--color-fg-3)]`,children:[(0,D.jsx)(`code`,{className:`text-sky-300`,children:e.uri}),(0,D.jsxs)(`span`,{className:`opacity-50 ml-2`,children:[e.hash.slice(0,10),`…`]})]},e.uri))})]})]})}var su=[`hook-ingress`,`parse`,`match`,`ffi-call`,`decide`,`audit`,`respond`],cu={"hook-ingress":`#6ea8ff`,parse:`#a78bfa`,match:`#60d394`,"ffi-call":`#f59e0b`,decide:`#f472b6`,audit:`#94a3b8`,respond:`#22d3ee`};function lu(){let{data:e,loading:t,error:n}=k(`/api/json/debug?uri=ssg%3A%2F%2Fframes%2Frecent%3Flimit%3D1024`,[V([`debug-frame`])[`debug-frame`]]),r=e?.data?.frames??[],i=e?.data?.dropped??0,[a,o]=(0,_.useState)(null);return(0,D.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-[1fr_320px] gap-4`,children:[(0,D.jsxs)(`article`,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3 space-y-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,D.jsxs)(`h3`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)]`,children:[`frames · `,r.length,i>0&&(0,D.jsxs)(`span`,{className:`ml-2 text-amber-300`,children:[`dropped · `,i]})]}),(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:`ssg://frames/recent`})]}),n&&(0,D.jsxs)(`p`,{className:`text-sm text-rose-300`,children:[`timeline fetch error: `,n]}),t&&r.length===0?(0,D.jsx)(`p`,{className:`text-sm text-[var(--color-fg-4)]`,children:`loading…`}):r.length===0?(0,D.jsx)(uu,{}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(fu,{frames:r,onSelect:o}),(0,D.jsx)(du,{})]})]}),(0,D.jsxs)(`aside`,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3 space-y-2 text-[11px] font-mono text-[var(--color-fg-3)]`,children:[(0,D.jsx)(`p`,{className:`uppercase tracking-wider text-[var(--color-fg-2)]`,children:`frame inspector`}),a?(0,D.jsx)(pu,{frame:a}):(0,D.jsx)(`p`,{className:`opacity-60`,children:`click a bar to inspect`})]})]})}function uu(){return(0,D.jsxs)(`div`,{className:`text-[12px] text-[var(--color-fg-3)] space-y-2 py-4`,children:[(0,D.jsx)(`p`,{className:`text-[13px] text-[var(--color-fg-2)]`,children:`no frames captured yet`}),(0,D.jsx)(`p`,{className:`text-[11px] text-[var(--color-fg-4)] leading-relaxed`,children:`Frame collection is opt-in so it adds zero cost when off. Restart the daemon with the env var below, then any tool call (Bash, Read, Edit, MCP) will stream frames into this view in real time:`}),(0,D.jsx)(`pre`,{className:`text-[11px] text-amber-300 font-mono bg-[var(--color-surface-2)] border border-[var(--color-line-1)] rounded-sm px-2 py-1.5`,children:`SSG_DEBUG_ENABLED=1 ./ssg daemon`}),(0,D.jsx)(`p`,{className:`text-[11px] text-[var(--color-fg-4)]`,children:`Each bar = one stage of one eval. Click a bar to inspect the frame — rule that matched, duration, error type, input preview.`})]})}function du(){return(0,D.jsx)(`div`,{className:`flex flex-wrap gap-3 text-[10px] font-mono text-[var(--color-fg-4)]`,children:su.map(e=>(0,D.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,D.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-sm`,style:{background:cu[e]}}),e]},e))})}function fu({frames:e,onSelect:t}){let n=(0,_.useRef)(null),r=(0,_.useRef)([]),[i,a]=(0,_.useState)(-1),{rows:o,tMin:s,tMax:c}=(0,_.useMemo)(()=>{let t=new Map;for(let n of e){let e=t.get(n.trace_id)??[];e.push(n),t.set(n.trace_id,e)}let n=Array.from(t.entries()).map(([e,t])=>({trace_id:e,frames:t.slice().sort((e,t)=>hu(e.ts_start_ns,t.ts_start_ns))}));n.sort((e,t)=>hu(e.frames[0].ts_start_ns,t.frames[0].ts_start_ns));let r=null,i=null;for(let t of e){let e=BigInt(t.ts_start_ns),n=BigInt(t.ts_end_ns);(r===null||e<r)&&(r=e),(i===null||n>i)&&(i=n)}return{rows:n,tMin:r??0n,tMax:i??1n}},[e]);(0,_.useEffect)(()=>{let e=n.current;if(!e)return;let t=window.devicePixelRatio||1,a=e.clientWidth,l=Math.max(120,o.length*22+24);e.width=a*t,e.height=l*t,e.style.height=`${l}px`;let u=e.getContext(`2d`);if(!u)return;u.setTransform(t,0,0,t,0,0),u.clearRect(0,0,a,l),u.strokeStyle=`rgba(255,255,255,0.04)`,u.lineWidth=1;for(let e=1;e<4;e++){let t=e*a/4;u.beginPath(),u.moveTo(t,0),u.lineTo(t,l),u.stroke()}let d=c>s?Number(c-s):1,f=a-110-8;u.font=`10px ui-monospace, monospace`,u.textBaseline=`middle`;let p=[];if(o.forEach((e,t)=>{let n=8+t*22;u.fillStyle=`rgba(255,255,255,0.55)`,u.fillText(e.trace_id.slice(0,10),6,n+18/2);for(let t of e.frames){let e=Number(BigInt(t.ts_start_ns)-s),r=Number(BigInt(t.ts_end_ns)-s),i=110+e/d*f,a=Math.max(2,(r-e)/d*f);u.fillStyle=cu[t.stage]??`#888`,u.globalAlpha=t.result===`error`?1:.82,u.fillRect(i,n,a,18),u.globalAlpha=1,t.result===`error`&&(u.strokeStyle=`#f43f5e`,u.lineWidth=1.5,u.strokeRect(i+.5,n+.5,a-1,17)),p.push({x:i,y:n,w:a,h:18,frame:t})}}),r.current=p,i>=0&&i<p.length){let e=p[i];u.strokeStyle=`#fff`,u.lineWidth=1.5,u.strokeRect(e.x+.5,e.y+.5,e.w-1,e.h-1)}},[o,s,c,i]);function l(e){let t=n.current;if(!t)return-1;let i=t.getBoundingClientRect(),a=e.clientX-i.left,o=e.clientY-i.top;for(let e=r.current.length-1;e>=0;e--){let t=r.current[e];if(a>=t.x&&a<=t.x+t.w&&o>=t.y&&o<=t.y+t.h)return e}return-1}return(0,D.jsx)(`canvas`,{ref:n,className:`w-full block cursor-crosshair`,onMouseMove:e=>a(l(e)),onMouseLeave:()=>a(-1),onClick:e=>{let n=l(e);t(n>=0?r.current[n].frame:null)}})}function pu({frame:e}){let t=Number(BigInt(e.ts_end_ns)-BigInt(e.ts_start_ns)),n=t>=1e6?`${(t/1e6).toFixed(2)}ms`:t>=1e3?`${(t/1e3).toFixed(1)}µs`:`${t}ns`;return(0,D.jsxs)(`dl`,{className:`space-y-1`,children:[(0,D.jsxs)(mu,{k:`stage`,children:[(0,D.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-sm mr-1 align-middle`,style:{background:cu[e.stage]??`#888`}}),e.stage]}),(0,D.jsx)(mu,{k:`tool`,children:e.tool}),(0,D.jsx)(mu,{k:`result`,children:(0,D.jsx)(`span`,{className:e.result===`error`?`text-rose-300`:e.result===`skip`?`text-[var(--color-fg-4)]`:`text-emerald-300`,children:e.result})}),(0,D.jsx)(mu,{k:`dur`,children:n}),e.rule_id&&(0,D.jsx)(mu,{k:`rule`,children:e.rule_id}),e.error&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(mu,{k:`err.type`,children:(0,D.jsx)(`span`,{className:`text-rose-300`,children:e.error.type})}),(0,D.jsx)(mu,{k:`err.msg`,children:(0,D.jsx)(`span`,{className:`text-rose-200`,children:e.error.message})})]}),e.input_preview&&(0,D.jsx)(mu,{k:`input`,children:(0,D.jsx)(`code`,{className:`text-[10px] break-all`,children:e.input_preview})}),(0,D.jsx)(mu,{k:`trace`,children:(0,D.jsx)(`code`,{className:`text-[10px]`,children:e.trace_id})}),(0,D.jsx)(mu,{k:`frame`,children:(0,D.jsx)(`code`,{className:`text-[10px]`,children:e.frame_id})})]})}function mu({k:e,children:t}){return(0,D.jsxs)(`div`,{className:`flex gap-2 text-[11px] leading-tight`,children:[(0,D.jsx)(`dt`,{className:`text-[var(--color-fg-4)] w-16 shrink-0 uppercase tracking-wider`,children:e}),(0,D.jsx)(`dd`,{className:`text-[var(--color-fg-2)] break-all min-w-0`,children:t})]})}function hu(e,t){let n=BigInt(e),r=BigInt(t);return n<r?-1:+(n>r)}var gu=[`ssg://daemon/state`,`ssg://daemon/metrics`,`ssg://audit/recent?limit=10`,`ssg://frames/recent?limit=32`,`ssg://rules/list`,`ssg://rca/current`,`ssg://native/stats`];function _u(){let[e,t]=(0,_.useState)(`ssg://daemon/state`),[n,r]=(0,_.useState)(`ssg://daemon/state`);return(0,D.jsxs)(`div`,{className:`space-y-3`,children:[(0,D.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:gu.map(e=>(0,D.jsx)(`button`,{type:`button`,onClick:()=>{t(e),r(e)},className:`chip text-[10px] `+(n===e?`border-[var(--color-brand)] text-[var(--color-fg-1)]`:`text-[var(--color-fg-3)]`),children:e},e))}),(0,D.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:t=>{t.preventDefault(),r(e)},children:[(0,D.jsx)(`input`,{value:e,onChange:e=>t(e.target.value),placeholder:`ssg://source/path?k=v`,className:`flex-1 px-3 py-1.5 text-[12px] font-mono rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] text-[var(--color-fg-1)]`}),(0,D.jsx)(`button`,{type:`submit`,className:`px-3 py-1.5 text-[11px] font-mono uppercase tracking-wider border border-[var(--color-line-1)] rounded-sm hover:bg-[var(--color-surface-2)]`,children:`resolve`})]}),(0,D.jsx)(vu,{uri:n})]})}function vu({uri:e}){let t=V([`debug-frame`,`activity-updated`,`counters-updated`]),{data:n,loading:r,error:i,refetch:a}=k(`/api/json/debug?uri=${encodeURIComponent(e)}`,[t[`debug-frame`],t[`activity-updated`],t[`counters-updated`],e]),o=n?JSON.stringify(n.data,null,2):``;return(0,D.jsxs)(`div`,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3 space-y-2`,children:[(0,D.jsxs)(`header`,{className:`flex items-center justify-between`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`h3`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)]`,children:e}),n?.snapshot_hash&&(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:[`hash `,n.snapshot_hash.slice(0,10),`…`]}),n?.stale&&(0,D.jsxs)(`span`,{className:`chip text-amber-300 border-amber-500/40 text-[10px]`,children:[`stale `,n.age_ms?`${Math.round(n.age_ms/1e3)}s`:``]})]}),(0,D.jsx)(`button`,{type:`button`,onClick:a,className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`,children:`refresh`})]}),r&&!n&&(0,D.jsx)(`p`,{className:`text-sm text-[var(--color-fg-4)]`,children:`resolving…`}),i&&(0,D.jsx)(`p`,{className:`text-sm text-rose-300`,children:i}),o&&(0,D.jsx)(`pre`,{className:`text-[11px] leading-snug font-mono text-[var(--color-fg-2)] overflow-auto max-h-[60vh] whitespace-pre-wrap break-all`,children:o})]})}var yu=200;function bu(e){let t=Date.now()-e;return t<2e3?`now`:t<6e4?`${Math.floor(t/1e3)}s ago`:t<36e5?`${Math.floor(t/6e4)}m ago`:`${Math.floor(t/36e5)}h ago`}function xu(e){let t=e/1e6;return t<1e3?`${Math.round(t)}ms`:t<6e4?`${(t/1e3).toFixed(1)}s`:`${Math.floor(t/6e4)}m${Math.floor(t%6e4/1e3)}s`}function Su(e){let{bursts:t,selectedId:n,onSelect:r}=e,i=(0,_.useMemo)(()=>{let e=new Map;for(let n of t){if(wi(n.tool))continue;let t=Xi(n),r=e.get(t);r||(r=[],e.set(t,r)),r.push(n)}let n=Array.from(e.entries());return n.sort((e,t)=>{let n=e[1][e[1].length-1]?.ts_ms??0;return(t[1][t[1].length-1]?.ts_ms??0)-n}),n},[t]);return t.length===0?(0,D.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center px-4`,children:[(0,D.jsx)(`p`,{className:`overline mb-2 text-[var(--color-fg-3)]`,children:`feed · idle`}),(0,D.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)] max-w-[260px]`,children:[`Each entry is one tool call your AI agent made.`,(0,D.jsx)(`br`,{}),`Color = the ssg rule decision.`]})]}):(0,D.jsx)(`div`,{className:`flex-1 min-h-0 overflow-y-auto px-3 py-3 space-y-5`,children:i.map(([e,t])=>{let i=e.indexOf(`:`),a=i>=0?e.slice(0,i):e,o=t[t.length-1],s=o?X[o.decision]??`#6b7280`:`#6b7280`,c=t.slice(-yu).reverse();return(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 mb-2 pb-1 border-b border-[var(--color-line-1)] text-[11px]`,children:[(0,D.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0`,style:{background:s}}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] font-medium`,children:Ci(a)}),(0,D.jsxs)(`span`,{className:`ml-auto text-[10px] text-[var(--color-fg-4)]`,children:[t.length,` `,t.length===1?`action`:`actions`]})]}),(0,D.jsxs)(`div`,{className:`relative pl-4`,children:[(0,D.jsx)(`div`,{className:`absolute left-[7px] top-0 bottom-0 w-px`,style:{background:`${s}33`}}),(0,D.jsx)(`div`,{className:`space-y-1.5`,children:c.map(e=>{let t=e.audit_id??`${e.ts_ms}:${e.tool}`,i=t===n,a=X[e.decision]??`#6b7280`,o=e.input_tokens??0,s=e.output_tokens??0,c=o>0||s>0;return(0,D.jsxs)(`div`,{className:`relative`,children:[(0,D.jsx)(`span`,{className:`absolute -left-[9px] top-1/2 -translate-y-1/2 w-[6px] h-[6px] rounded-full border border-[var(--color-surface-1)]`,style:{background:a}}),(0,D.jsxs)(`button`,{type:`button`,onClick:()=>r(i?null:t),className:`w-full text-left flex items-center gap-2 px-2.5 py-1.5 rounded-sm border text-[11.5px] transition-colors ${i?`border-sky-500/50 bg-sky-500/5 text-[var(--color-fg-1)]`:`border-[var(--color-line-1)] bg-[var(--color-surface-1)] text-[var(--color-fg-2)] hover:bg-white/3 hover:border-[var(--color-line-2)]`}`,children:[(0,D.jsx)(`span`,{className:`flex-1 font-medium truncate text-[var(--color-fg-1)]`,title:e.tool,children:Si(e.tool)}),(0,D.jsxs)(`span`,{className:`shrink-0 flex items-center gap-2 text-[9px] text-[var(--color-fg-4)]`,children:[c&&(0,D.jsxs)(`span`,{className:`font-mono`,title:`Input: ${o} tokens · Output: ${s} tokens`,children:[`↓`,ra(o),` ↑`,ra(s)]}),e.duration_ns>0&&(0,D.jsx)(`span`,{children:xu(e.duration_ns)}),(0,D.jsx)(`span`,{className:`px-1.5 py-px rounded text-[9px] font-semibold tracking-wide`,style:{color:a,background:`${a}22`},children:e.decision===`allow`?`Allowed`:e.decision===`block`?`Blocked`:e.decision===`ask`?`Held`:e.decision===`force`?`Forced`:e.decision===`log`?`Logged`:e.decision}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:bu(e.ts_ms)})]})]})]},t)})})]})]},e)})})}function Cu(e){let{sessionKey:t,entries:n,loading:r,error:i,playingIndex:a}=e,o=(0,_.useRef)(null),s=(0,_.useRef)(new Map),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(null),f=(0,_.useMemo)(()=>{let e=new Set;for(let t of n)e.add(t.decision);return[...e].sort()},[n]);(0,_.useEffect)(()=>{u&&!f.includes(u)&&d(null)},[u,f]);let p=(0,_.useMemo)(()=>{let e=c.trim().toLowerCase();return!e&&!u?n:n.filter(t=>u&&t.decision!==u?!1:e?t.tool.toLowerCase().includes(e)||t.decision.toLowerCase().includes(e)||(t.rule_id??``).toLowerCase().includes(e)||(t.rule_message??``).toLowerCase().includes(e)||t.input_preview.toLowerCase().includes(e):!0)},[n,c,u]),m=c.trim().length>0||u!==null,h=a>=0?n[a]?.id??null:null;(0,_.useEffect)(()=>{if(!h)return;let e=s.current.get(h);e&&e.scrollIntoView({behavior:`smooth`,block:`nearest`})},[h]);let g=e=>t=>{t?s.current.set(e,t):s.current.delete(e)},v=r?`loading…`:i?`error`:m?`${p.length} / ${n.length}`:`${n.length} event${n.length===1?``:`s`}`;return(0,D.jsxs)(`div`,{className:`flex flex-col h-full min-h-0 rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] overflow-hidden`,children:[(0,D.jsxs)(`header`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-[var(--color-line-1)] bg-black/30 shrink-0`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono`,children:[(0,D.jsx)(`span`,{className:`overline text-[var(--color-fg-3)]`,children:`audit log`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)] truncate`,title:t,children:t})]}),(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] tabular-nums`,children:v})]}),!i&&n.length>0&&(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-3 py-1.5 border-b border-[var(--color-line-1)] bg-black/20 shrink-0`,children:[(0,D.jsxs)(`div`,{className:`relative flex-1 min-w-[140px]`,children:[(0,D.jsx)(`input`,{type:`text`,value:c,onChange:e=>l(e.target.value),placeholder:`Search tool, rule, input…`,"aria-label":`Search audit log`,className:`w-full bg-black/40 border border-[var(--color-line-1)] rounded-sm pl-2 pr-6 py-1 text-[11px] font-mono text-[var(--color-fg-1)] placeholder:text-[var(--color-fg-4)] focus:outline-none focus:border-[var(--color-hig-blue)]/60`}),c&&(0,D.jsx)(`button`,{type:`button`,onClick:()=>l(``),"aria-label":`Clear search`,className:`absolute right-1 top-1/2 -translate-y-1/2 text-[var(--color-fg-4)] hover:text-[var(--color-fg-1)] text-[13px] leading-none px-1`,children:`×`})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:()=>d(null),className:`px-1.5 py-0.5 rounded-sm text-[10px] font-mono uppercase tracking-wider border transition-colors ${u===null?`border-[var(--color-hig-blue)]/60 bg-[var(--color-hig-blue)]/15 text-[var(--color-fg-1)]`:`border-[var(--color-line-1)] text-[var(--color-fg-4)] hover:text-[var(--color-fg-2)]`}`,children:`all`}),f.map(e=>{let t=X[e]??`#6b7280`,n=u===e;return(0,D.jsxs)(`button`,{type:`button`,onClick:()=>d(n?null:e),className:`flex items-center gap-1 px-1.5 py-0.5 rounded-sm text-[10px] font-mono uppercase tracking-wider border transition-colors ${n?`bg-white/[0.06] text-[var(--color-fg-1)]`:`border-[var(--color-line-1)] text-[var(--color-fg-4)] hover:text-[var(--color-fg-2)]`}`,style:n?{borderColor:t}:void 0,children:[(0,D.jsx)(`span`,{"aria-hidden":!0,className:`size-1.5 rounded-full shrink-0`,style:{background:t}}),e]},e)})]})]}),(0,D.jsxs)(`div`,{ref:o,className:`flex-1 min-h-0 overflow-y-auto divide-y divide-[var(--color-line-1)]/40`,children:[i&&(0,D.jsx)(`div`,{className:`px-3 py-4 text-[11px] font-mono text-rose-300`,children:i}),!i&&!r&&n.length===0&&(0,D.jsx)(`div`,{className:`px-3 py-4 text-[11px] font-mono text-[var(--color-fg-4)]`,children:`No audit entries for this session yet.`}),!i&&n.length>0&&p.length===0&&(0,D.jsx)(`div`,{className:`px-3 py-4 text-[11px] font-mono text-[var(--color-fg-4)]`,children:`No events match the current filter.`}),p.map(e=>{let t=X[e.decision]??`#6b7280`,n=e.id===h,r=e.duration_ns==null?null:e.duration_ns/1e6;return(0,D.jsxs)(`div`,{ref:g(e.id),className:`relative px-3 py-2 transition-colors ${n?`bg-white/[0.04] ring-1 ring-inset ring-sky-400/40`:`hover:bg-white/[0.02]`}`,children:[(0,D.jsx)(`span`,{"aria-hidden":!0,className:`absolute left-0 top-0 bottom-0 w-1`,style:{background:t}}),(0,D.jsxs)(`div`,{className:`flex items-center justify-between gap-2 text-[11px] font-mono`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,D.jsx)(`span`,{className:`uppercase tracking-wider shrink-0`,style:{color:t},children:e.decision}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] truncate`,children:e.tool})]}),(0,D.jsx)(`span`,{className:`shrink-0 text-[10px] text-[var(--color-fg-4)] tabular-nums`,children:wu(e.ts_ms)})]}),(e.rule_id||r!=null)&&(0,D.jsxs)(`div`,{className:`mt-0.5 flex items-center gap-2 text-[10px] font-mono text-[var(--color-fg-4)]`,children:[e.rule_id&&(0,D.jsxs)(`span`,{className:`truncate`,title:e.rule_id,children:[`rule · `,e.rule_id]}),r!=null&&(0,D.jsx)(`span`,{className:`tabular-nums shrink-0`,children:r<1?`${(r*1e3).toFixed(0)}µs`:`${r.toFixed(2)}ms`})]}),e.rule_message&&(0,D.jsx)(`div`,{className:`mt-1 text-[10px] font-mono text-[var(--color-fg-3)] break-words`,children:e.rule_message}),e.input_preview&&(0,D.jsx)(`pre`,{className:`mt-1 text-[10px] text-[var(--color-fg-3)] whitespace-pre-wrap break-all bg-black/30 rounded-sm px-2 py-1 max-h-24 overflow-y-auto`,children:e.input_preview})]},e.id)})]})]})}function wu(e){let t=new Date(e);return`${String(t.getHours()).padStart(2,`0`)}:${String(t.getMinutes()).padStart(2,`0`)}:${String(t.getSeconds()).padStart(2,`0`)}`}var Tu=[100,500,1e3,5e3,1e4,1e5];function Eu(e){return e>=1e5||e>=1e3?`${e/1e3|0}k`:String(e)}function Du(e){let t=Math.floor(e/100),n=Math.floor(t/600),r=Math.floor(t%600/10),i=t%10;return`${String(n).padStart(2,`0`)}:${String(r).padStart(2,`0`)}.${i}`}function Ou(e){let t=Math.floor(e/100);return`${Math.floor(t/10)}.${t%10}s`}function ku({className:e,onMilestone:t,onRecord:n}){let r=(0,_.useRef)(null),i=(0,_.useRef)(null),[a,o]=(0,_.useState)(0),[s,c]=(0,_.useState)(0),[l,u]=(0,_.useState)(0),[d,f]=(0,_.useState)(0),[p,m]=(0,_.useState)(0),[h,g]=(0,_.useState)(``),[v,y]=(0,_.useState)(!1),[b,x]=(0,_.useState)(!1),S=qi(),C=Yi(),w=Ji(),T=(0,_.useRef)(null),E=(0,_.useRef)(0),O=(0,_.useRef)(0),k=(0,_.useRef)(0),ee=(0,_.useRef)(0),A=(0,_.useRef)(new Set),j=(0,_.useRef)(performance.now());return(0,_.useEffect)(()=>{let e=performance.now();if(_r()){let t=setInterval(()=>{let t=performance.now();r.current&&(r.current.textContent=Du(t-e)),i.current&&(i.current.textContent=Ou(t-j.current))},1e3);return()=>clearInterval(t)}let[t]=$a(()=>{let t=performance.now();r.current&&(r.current.textContent=Du(t-e)),i.current&&(i.current.textContent=Ou(t-j.current))});return t},[]),(0,_.useEffect)(()=>{for(let e of w)e.rule_id&&A.current.add(e.rule_id);m(A.current.size)},[]),(0,_.useEffect)(()=>{let e=()=>{let e=Date.now(),t=w.filter(t=>e-t.ts_ms<=6e4),n=new Set(t.map(e=>`${e.client}:${e.agent_id??`solo`}`)).size;f(n)};e();let t=setInterval(e,1e3);return()=>clearInterval(t)},[w]),(0,_.useEffect)(()=>{if(T.current===null){T.current=C,E.current=C;return}if(C<=E.current)return;let e=C-E.current;E.current=C,u(n=>{let r=n+e,i=Tu.find(e=>e>ee.current&&r>=e);return i&&(ee.current=i,g(Eu(i)),x(!0),t?.(),setTimeout(()=>{g(``),x(!1)},700)),r}),S?.rule_id&&A.current.add(S.rule_id),m(A.current.size),S&&(S.decision===`block`?(O.current=0,o(0),j.current=performance.now()):(O.current+=e,O.current>k.current&&(k.current=O.current,c(k.current),y(!0),n?.(),setTimeout(()=>y(!1),450)),o(O.current)))},[C,S,t,n]),(0,D.jsxs)(`div`,{className:In(`pointer-events-none select-none`,`flex flex-col gap-2 p-3 rounded-md`,`bg-[var(--color-bg-2,#0c0d12)]/95`,`border border-[var(--color-border-1,#1c1f26)]`,`shadow-lg shadow-black/40`,`min-w-[180px] font-mono text-[11px]`,`text-[var(--color-fg-2,#9aa1ad)]`,b&&`milestone-ring`,e),"aria-label":`Live engagement counters`,children:[(0,D.jsx)(Au,{label:`uptime`,children:(0,D.jsx)(`span`,{ref:r,className:`tabular-nums text-[var(--color-fg-0,#e6e8ed)] text-[15px] tracking-tight`,children:`00:00.0`})}),(0,D.jsx)(Au,{label:`evals`,children:(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,D.jsx)(Ks,{value:l,className:`text-[var(--color-fg-0,#e6e8ed)] text-[15px]`}),h&&(0,D.jsxs)(`span`,{className:`text-[10px] text-emerald-400 uppercase tracking-wide`,children:[`+`,h]})]})}),(0,D.jsx)(Au,{label:`since block`,children:(0,D.jsx)(`span`,{ref:i,className:`tabular-nums text-emerald-300 text-[15px]`,children:`0.0s`})}),(0,D.jsx)(Au,{label:`streak / best`,children:(0,D.jsxs)(`span`,{className:In(`tabular-nums text-[15px]`,v?`record-beat`:`text-[var(--color-fg-0,#e6e8ed)]`),children:[(0,D.jsx)(Ks,{value:a,curve:`spring`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4,#5a6071)] mx-1`,children:`/`}),(0,D.jsx)(Ks,{value:s})]})}),(0,D.jsx)(Au,{label:`agents`,children:(0,D.jsx)(Ks,{value:d,className:`text-[var(--color-fg-0,#e6e8ed)] text-[15px]`})}),(0,D.jsx)(Au,{label:`rules`,children:(0,D.jsx)(Ks,{value:p,className:`text-[var(--color-fg-0,#e6e8ed)] text-[15px]`})})]})}function Au({label:e,children:t}){return(0,D.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[(0,D.jsx)(`span`,{className:`uppercase tracking-wider text-[10px] text-[var(--color-fg-4,#5a6071)]`,children:e}),t]})}function ju(e){let t=new Map;for(let n of e){let e=`${n.client}:${n.agent_id??`solo`}`,r=t.get(e);r?(r.count+=1,n.ts_ms>r.newest_ts_ms&&(r.newest_ts_ms=n.ts_ms)):t.set(e,{client:n.client,agent_id:n.agent_id??`solo`,count:1,newest_ts_ms:n.ts_ms})}return Array.from(t.values()).sort((e,t)=>t.newest_ts_ms===e.newest_ts_ms?t.count-e.count:t.newest_ts_ms-e.newest_ts_ms)}function Mu(e){let{bursts:t,allBursts:n}=e,r=n??t,{toolCounts:i,decisionCounts:a,ruleCounts:o,unmatchedCount:s}=(0,_.useMemo)(()=>{let e=new Map,n=new Map,r=new Map,i=0;for(let a of t)if(e.set(a.tool,(e.get(a.tool)??0)+1),n.set(a.decision,(n.get(a.decision)??0)+1),a.rule_id){let e=r.get(a.rule_id);e?(e.count+=1,e.decisions.add(a.decision)):r.set(a.rule_id,{count:1,decisions:new Set([a.decision])})}else i+=1;return{toolCounts:Array.from(e.entries()).sort((e,t)=>t[1]-e[1]),decisionCounts:Array.from(n.entries()),ruleCounts:Array.from(r.entries()).map(([e,t])=>({id:e,count:t.count,decisions:t.decisions})).sort((e,t)=>t.count-e.count),unmatchedCount:i}},[t]),c=(0,_.useMemo)(()=>ju(r),[r]),l=i[0]?.[1]??0,u=c[0]?.count??0,d=o[0]?.count??0,f=e=>{for(let t of[`block`,`ask`,`force`,`log`,`allow`,`shadow`])if(e.has(t))return X[t];return`#6b7280`};return(0,D.jsxs)(`div`,{className:`flex flex-col gap-3 text-[11px] font-mono`,children:[(0,D.jsx)(`div`,{className:`rounded-sm border border-[var(--color-line-0)] bg-[var(--color-surface-0)] p-2 text-[10px] text-[var(--color-fg-3)] leading-relaxed`,children:`Each dot is one tool call by an AI agent. Color encodes the ssg rule decision; lines link calls from the same agent in time order.`}),(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`overline text-[var(--color-fg-3)] mb-1`,children:[`rules · `,o.length,` matched`,s>0&&(0,D.jsxs)(`span`,{className:`ml-2 text-[var(--color-fg-4)] normal-case tracking-normal`,children:[s,` unmatched`]})]}),o.length===0?(0,D.jsx)(`p`,{className:`text-[var(--color-fg-4)]`,children:`no rules matched in window`}):(0,D.jsx)(`ul`,{className:`space-y-0.5`,children:o.slice(0,6).map(e=>{let t=d>0?e.count/d*100:0,n=f(e.decisions);return(0,D.jsxs)(`li`,{className:`grid grid-cols-[1fr_auto] items-center gap-2`,title:`${e.id} — decisions: ${Array.from(e.decisions).join(`, `)}`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,D.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0`,style:{background:n},"aria-hidden":!0}),(0,D.jsx)(`a`,{href:`/rules#${encodeURIComponent(e.id)}`,className:`truncate text-[var(--color-fg-2)] hover:text-[var(--color-fg-1)]`,children:e.id}),(0,D.jsx)(`div`,{className:`flex-1 h-1 bg-[var(--color-surface-1)] rounded-sm overflow-hidden`,children:(0,D.jsx)(`div`,{className:`h-full`,style:{background:n,width:`${t}%`,opacity:.6}})})]}),(0,D.jsx)(`span`,{className:`tabular-nums text-[var(--color-fg-4)]`,children:e.count})]},e.id)})})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline text-[var(--color-fg-3)] mb-1`,children:`decisions`}),(0,D.jsx)(`div`,{className:`flex flex-wrap gap-x-3 gap-y-1`,children:[`allow`,`block`,`ask`,`log`,`force`,`shadow`].map(e=>{let t=a.find(([t])=>t===e)?.[1]??0;return(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,D.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0`,style:{background:X[e]},"aria-hidden":!0}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)] uppercase tracking-wider`,children:e}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] tabular-nums`,children:t})]},e)})})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`overline text-[var(--color-fg-3)] mb-1`,children:[`agents · `,c.length,` active`,n&&n!==t&&(0,D.jsx)(`span`,{className:`ml-2 text-[var(--color-fg-4)] normal-case tracking-normal`,children:`roster: today`})]}),c.length===0?(0,D.jsx)(`p`,{className:`text-[var(--color-fg-4)]`,children:`no agents in window`}):(0,D.jsx)(`ul`,{className:`space-y-0.5`,children:c.slice(0,8).map(e=>{let t=u>0?e.count/u*100:0,n=`${e.client}:${e.agent_id}`,r=Date.now()-e.newest_ts_ms,i=r<5e3;return(0,D.jsxs)(`li`,{className:`grid grid-cols-[1fr_auto] items-center gap-2`,title:`${n} — last eval ${Math.max(0,Math.round(r/1e3))}s ago`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[i?(0,D.jsx)(`span`,{className:`status-dot bg-emerald-400 pulse-soft shrink-0`,"aria-hidden":!0}):(0,D.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 bg-[var(--color-fg-4)]/40`,"aria-hidden":!0}),(0,D.jsxs)(`span`,{className:`truncate text-[var(--color-fg-2)]`,children:[e.client,(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)]`,children:[`:`,e.agent_id]})]}),(0,D.jsx)(`div`,{className:`flex-1 h-1 bg-[var(--color-surface-1)] rounded-sm overflow-hidden`,children:(0,D.jsx)(`div`,{className:`h-full bg-violet-400/60`,style:{width:`${t}%`}})})]}),(0,D.jsx)(`span`,{className:`tabular-nums text-[var(--color-fg-4)]`,children:e.count})]},n)})})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`overline text-[var(--color-fg-3)] mb-1`,children:[`tools · `,t.length,` in window`]}),i.length===0?(0,D.jsx)(`p`,{className:`text-[var(--color-fg-4)]`,children:`no tool activity`}):(0,D.jsx)(`ul`,{className:`space-y-0.5`,children:i.slice(0,8).map(([e,t])=>{let n=l>0?t/l*100:0;return(0,D.jsxs)(`li`,{className:`grid grid-cols-[1fr_auto] items-center gap-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,D.jsx)(`span`,{className:`truncate text-[var(--color-fg-2)]`,children:e}),(0,D.jsx)(`div`,{className:`flex-1 h-1 bg-[var(--color-surface-1)] rounded-sm overflow-hidden`,children:(0,D.jsx)(`div`,{className:`h-full bg-sky-400/60`,style:{width:`${n}%`}})})]}),(0,D.jsx)(`span`,{className:`tabular-nums text-[var(--color-fg-4)]`,children:t})]},e)})})]})]})}var Nu=320,Pu=8,Fu=12;function Iu(e){let{burst:t,anchor:n,onClose:r}=e,i=(0,_.useRef)(null),[a,o]=(0,_.useState)({left:-9999,top:-9999});if((0,_.useEffect)(()=>{if(!t)return;let e=e=>{e.key===`Escape`&&r()},n=e=>{i.current&&!i.current.contains(e.target)&&r()};return document.addEventListener(`keydown`,e),document.addEventListener(`mousedown`,n),()=>{document.removeEventListener(`keydown`,e),document.removeEventListener(`mousedown`,n)}},[t,r]),(0,_.useLayoutEffect)(()=>{if(!t||!n||!i.current)return;let e=i.current.getBoundingClientRect(),r=window.innerWidth,a=window.innerHeight,s=e.height>0?e.height:280,c=n.x+Fu+Nu>r?n.x-Fu-Nu:n.x+Fu,l=n.y+Fu+s>a?n.y-Fu-s:n.y+Fu;c=Math.min(Math.max(Pu,c),r-Nu-Pu),l=Math.min(Math.max(Pu,l),a-s-Pu),o({left:c,top:l})},[t,n]),(0,_.useEffect)(()=>{o({left:-9999,top:-9999})},[]),!t||!n)return null;let s=X[t.decision]??`#6b7280`,c=t.duration_ns/1e6,l=Date.now()-t.ts_ms;return(0,D.jsxs)(`div`,{ref:i,className:`fixed z-50 flex flex-col gap-3 text-[12px] font-mono rounded-md border border-[var(--color-line-1)] bg-[var(--color-surface-1)] shadow-2xl p-4`,style:{left:a.left,top:a.top,width:Nu,maxHeight:`80vh`,overflowY:`auto`},children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline text-[var(--color-fg-3)]`,children:`node · inspect`}),(0,D.jsx)(`button`,{onClick:r,className:`text-[var(--color-fg-4)] hover:text-[var(--color-fg-1)] cursor-pointer`,title:`Close inspector`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`w-2 h-2 rounded-full`,style:{background:s},"aria-hidden":!0}),(0,D.jsx)(`span`,{className:`uppercase tracking-wider`,style:{color:s},children:t.decision}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:t.tool})]}),(0,D.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-[11px]`,children:[(0,D.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`rule`}),(0,D.jsx)(`dd`,{className:`text-[var(--color-fg-2)] break-all`,children:t.rule_id??`—`}),(0,D.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`client`}),(0,D.jsx)(`dd`,{className:`text-[var(--color-fg-2)]`,children:t.client}),(0,D.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`agent`}),(0,D.jsx)(`dd`,{className:`text-[var(--color-fg-2)]`,children:t.agent_id?(0,D.jsx)(`span`,{className:`chip text-violet-300 border-violet-500/30`,children:t.agent_id}):(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`—`})}),(0,D.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`eval duration`}),(0,D.jsx)(`dd`,{className:`text-[var(--color-fg-2)]`,children:c<1?`${(c*1e3).toFixed(0)}µs`:`${c.toFixed(2)}ms`}),t.complete_duration_ms!=null&&t.complete_duration_ms>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`tool duration`}),(0,D.jsx)(`dd`,{className:`text-[var(--color-fg-2)]`,children:t.complete_duration_ms>=1e3?`${(t.complete_duration_ms/1e3).toFixed(2)}s`:`${t.complete_duration_ms.toFixed(0)}ms`})]}),t.message&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`reason`}),(0,D.jsx)(`dd`,{className:`text-[var(--color-fg-2)] break-words`,children:t.message})]}),(t.input_tokens!=null||t.output_tokens!=null)&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`tokens`}),(0,D.jsx)(`dd`,{className:`text-[var(--color-fg-2)]`,children:zu(t.input_tokens,t.output_tokens)})]}),(0,D.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`age`}),(0,D.jsx)(`dd`,{className:`text-[var(--color-fg-2)]`,children:Lu(l)}),(0,D.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`timestamp`}),(0,D.jsx)(`dd`,{className:`text-[var(--color-fg-2)]`,children:new Date(t.ts_ms).toLocaleString()})]}),t.input_preview&&(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline text-[var(--color-fg-3)] mb-1`,children:`input`}),(0,D.jsx)(`pre`,{className:`bg-[var(--color-surface-0)] border border-[var(--color-line-0)] rounded-sm p-2 text-[10px] text-[var(--color-fg-2)] whitespace-pre-wrap break-all max-h-48 overflow-y-auto`,children:t.input_preview})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[t.audit_id&&(0,D.jsx)(`a`,{href:`/audit?id=${encodeURIComponent(t.audit_id)}`,className:`chip text-[var(--color-fg-3)] border-[var(--color-line-1)] hover:text-[var(--color-fg-1)]`,title:`Open full audit record`,children:`audit ↗`}),t.rule_id&&(0,D.jsx)(`a`,{href:`/rules#${encodeURIComponent(t.rule_id)}`,className:`chip text-[var(--color-fg-3)] border-[var(--color-line-1)] hover:text-[var(--color-fg-1)]`,title:`Jump to rule`,children:`rule ↗`})]})]})}function Lu(e){if(e<1500)return`just now`;let t=Math.floor(e/1e3);if(t<60)return`${t}s ago`;let n=Math.floor(t/60);return n<60?`${n}m${t%60}s ago`:`${Math.floor(n/60)}h${n%60}m ago`}function Ru(e){return e<1e3?String(e):e<1e4?`${(e/1e3).toFixed(1)}K`:e<1e6?`${Math.round(e/1e3)}K`:`${(e/1e6).toFixed(1)}M`}function zu(e,t){let n=[];return e!=null&&n.push(`${Ru(e)} in`),t!=null&&n.push(`${Ru(t)} out`),n.length>0?n.join(` · `):`—`}var Bu=900,Vu=180,Hu=320,Uu=800,Wu=4;function Gu({sessionKey:e}={}){let t=qi(),n=Yi(),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(`idle`),s=(0,_.useRef)([]),c=(0,_.useRef)(-1),l=(0,_.useRef)(0),u=(0,_.useRef)(null);if((0,_.useEffect)(()=>{if(!t||n===c.current||(c.current=n,t.decision!==`block`&&t.decision!==`force`)||e&&Xi(t)!==e)return;let u=Date.now(),d=s.current,f=d[0];if(f&&u-l.current<Uu){f.extra+=1,f.burst=t,f.seq=n,l.current=u;return}if(d.length>=Wu&&d.shift(),d.push({seq:n,burst:t,extra:0}),l.current=u,a===`idle`&&!r){let e=d.shift()??null;e&&(i(e),o(`in`))}},[n,t,e,a,r]),(0,_.useEffect)(()=>{if(a===`idle`)return;let e=null;return a===`in`?e=setTimeout(()=>o(`visible`),Vu):a===`visible`?e=setTimeout(()=>o(`out`),Bu):a===`out`&&(e=setTimeout(()=>{let e=s.current.shift()??null;e?(i(e),o(`in`)):(i(null),o(`idle`))},Hu)),u.current=e,()=>{e&&clearTimeout(e)}},[a]),!r)return null;let{burst:d,extra:f}=r,p=X[d.decision]??`#ef4444`,m=_r(),h=+(a===`in`||a===`visible`),g=m||a===`in`||a===`visible`?0:-8,v=d.rule_id??`rule`,y=d.decision===`block`?`BLOCKED`:`FORCED`,b=f>0?`${d.tool} · +${f} more in this burst`:`${d.tool} · ${d.client}${d.agent_id?`:${d.agent_id}`:``}`;return(0,D.jsx)(`div`,{className:e?`pointer-events-none absolute top-2 left-1/2 z-30 select-none`:`pointer-events-none fixed top-20 left-1/2 z-40 select-none`,style:{transform:`translateX(-50%) translateY(${g}px) scale(1)`,opacity:h,transition:m?`opacity ${Vu}ms ease-out`:`opacity ${Vu}ms ease-out, transform ${Vu}ms cubic-bezier(0.34, 1.56, 0.64, 1)`},"aria-live":`polite`,"aria-atomic":`true`,children:(0,D.jsxs)(`div`,{className:`flex items-center gap-3 px-5 py-3 rounded-md border bg-black/95 shadow-2xl`,style:{borderColor:p},children:[(0,D.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full shrink-0`,style:{background:p,boxShadow:m?`none`:`0 0 16px ${p}`}}),(0,D.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,D.jsxs)(`div`,{className:`text-[11px] font-mono uppercase tracking-[0.18em]`,style:{color:p},children:[y,` BY SSG`]}),(0,D.jsx)(`div`,{className:`text-[14px] font-mono text-[var(--color-fg-1)] truncate max-w-[420px]`,children:v}),(0,D.jsx)(`div`,{className:`text-[11px] font-mono text-[var(--color-fg-3)] truncate max-w-[420px]`,children:b})]})]})})}var Ku=(0,_.memo)(function(e){let{sessionKey:t,bursts:n,paused:r,selectedId:i,onSelect:a,burstSeq:o,isStale:s,isFadingOut:c,minHeight:l,pinned:u,minimized:d,isFullscreen:f,viewMode:p=`full`,thumbnail:m=!1,onPromote:h,activePanelCount:g=1,onTogglePin:v,onToggleMinimize:y,onToggleFullscreen:b,onClose:x,onFrameTime:S}=e,C=p===`broadcast`,w=!m&&(p===`stream`||p===`broadcast`||f)?`large`:`normal`,T=t.indexOf(`:`),E=T>=0?t.slice(0,T):t,O=T>=0?t.slice(T+1):``,k=(0,_.useRef)(null),[ee,A]=(0,_.useState)(!0),[j,M]=(0,_.useState)(null),te=()=>{let e=k.current;if(!e)return;let t=e.querySelector(`canvas`);t instanceof HTMLCanvasElement&&M(t.toDataURL(`image/png`))},N=()=>{if(!j)return;let e=document.createElement(`a`),n=t.replace(/[^a-z0-9._-]+/gi,`-`);e.href=j,e.download=`ssg-graph-${n}-${Date.now()}.png`,document.body.appendChild(e),e.click(),e.remove()},P=()=>{!j||!navigator.clipboard?.write||fetch(j).then(e=>e.blob()).then(e=>{let t=new ClipboardItem({"image/png":e});return navigator.clipboard.write([t])}).catch(()=>{})},F=typeof navigator<`u`&&typeof navigator.clipboard?.write==`function`&&typeof ClipboardItem<`u`;(0,_.useEffect)(()=>{if(f){A(!0);return}let e=k.current;if(!e)return;let t=new IntersectionObserver(e=>{for(let t of e)A(t.isIntersecting)},{threshold:.01});return t.observe(e),()=>t.disconnect()},[f]);let I=n.length>0?n[n.length-1]:null,ne=I?X[I.decision]??`#6b7280`:`#6b7280`,re=I?.decision??null,ie=I?.tool??null,L=r||!ee||d,R=(0,_.useMemo)(()=>n.length>24?n.slice(n.length-24):n,[n]);return(0,D.jsxs)(`div`,{ref:k,className:`relative flex flex-col shrink-0 rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] overflow-hidden${f?` flex-1 min-h-0`:``}`,style:{minHeight:d||f?void 0:l,opacity:+!c,transform:c?`scale(0.985)`:`scale(1)`,transformOrigin:`center center`,transition:`opacity 1100ms cubic-bezier(0.22, 1, 0.36, 1), transform 1100ms cubic-bezier(0.22, 1, 0.36, 1)`},children:[!C&&(0,D.jsxs)(`header`,{className:`group flex items-center justify-between px-3 py-1.5 border-b border-[var(--color-line-1)] bg-black/30 shrink-0 gap-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono min-w-0`,children:[u&&(0,D.jsx)(`span`,{className:`text-amber-300`,title:`Pinned`,children:`▲`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)] uppercase tracking-wider`,children:E}),O&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] truncate`,children:O})]})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono text-[var(--color-fg-4)] min-w-0`,children:[ie&&(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5 max-w-[180px] min-w-0`,title:re?`latest: ${ie} → ${re}`:`latest: ${ie}`,children:[(0,D.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0`,style:{background:ne}}),(0,D.jsx)(`span`,{className:`truncate text-[var(--color-fg-2)]`,children:ie})]}),(0,D.jsxs)(`span`,{className:`hidden md:inline text-[var(--color-fg-4)] shrink-0`,children:[n.length,`n`]}),s?(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5 text-amber-300 shrink-0`,children:[(0,D.jsx)(`span`,{className:`status-dot bg-amber-400`}),(0,D.jsx)(`span`,{className:`hidden sm:inline`,children:`idle`})]}):(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5 text-emerald-300 shrink-0`,children:[(0,D.jsx)(`span`,{className:`status-dot bg-emerald-400 pulse-soft`}),(0,D.jsx)(`span`,{className:`hidden sm:inline`,children:`live`})]}),!m&&(0,D.jsxs)(`div`,{className:`flex items-center gap-1 ml-1 shrink-0`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:v,className:`px-1.5 py-0.5 rounded border text-[10px] uppercase tracking-wider transition-colors ${u?`border-amber-500/60 text-amber-300`:`border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:text-amber-300 hover:border-amber-500/40`}`,title:u?`Unpin`:`Pin to top`,children:`pin`}),(0,D.jsx)(`button`,{type:`button`,onClick:y,className:`px-1.5 py-0.5 rounded border border-[var(--color-line-1)] text-[10px] text-[var(--color-fg-3)] hover:text-sky-300 hover:border-sky-500/40 transition-colors`,title:d?`Expand`:`Minimize`,children:d?`+`:`–`}),(0,D.jsx)(`button`,{type:`button`,onClick:te,className:`px-1.5 py-0.5 rounded border border-[var(--color-line-1)] text-[10px] text-[var(--color-fg-3)] hover:text-sky-300 hover:border-sky-500/40 transition-colors`,title:`Preview PNG snapshot of this panel`,children:`▣`}),(0,D.jsx)(`button`,{type:`button`,onClick:b,className:`px-1.5 py-0.5 rounded border border-[var(--color-line-1)] text-[10px] text-[var(--color-fg-3)] hover:text-sky-300 hover:border-sky-500/40 transition-colors`,title:f?`Exit fullscreen`:`Fullscreen`,children:f?`×`:`⛶`}),x&&(0,D.jsx)(`button`,{type:`button`,onClick:x,"aria-label":`Close session ${t}`,className:`px-1.5 py-0.5 rounded border border-[var(--color-line-1)] text-[10px] text-[var(--color-fg-3)] hover:text-rose-300 hover:border-rose-500/40 transition-colors`,title:`End this session on the graph`,children:`╳`})]})]})]}),!d&&!m&&!C&&(0,D.jsx)(To,{sessionKey:t,className:`rounded-none border-x-0 border-t-0 border-b border-[var(--color-line-1)] shrink-0`}),j&&(0,D.jsxs)(`div`,{className:`absolute inset-0 z-40 flex flex-col items-center justify-center gap-3 bg-black/80 backdrop-blur-sm p-4`,children:[(0,D.jsx)(`img`,{src:j,alt:`Panel snapshot`,className:`max-w-full max-h-[60%] rounded-sm border border-[var(--color-line-1)] object-contain`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[F&&(0,D.jsx)(`button`,{type:`button`,onClick:P,className:`px-3 py-1.5 rounded border border-[var(--color-line-1)] text-[11px] font-mono text-[var(--color-fg-2)] hover:text-sky-300 hover:border-sky-500/40 transition-colors`,children:`copy`}),(0,D.jsx)(`button`,{type:`button`,onClick:N,className:`px-3 py-1.5 rounded border border-[var(--color-line-1)] text-[11px] font-mono text-[var(--color-fg-2)] hover:text-sky-300 hover:border-sky-500/40 transition-colors`,children:`download`}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>M(null),className:`px-3 py-1.5 rounded border border-[var(--color-line-1)] text-[11px] font-mono text-[var(--color-fg-3)] hover:text-rose-300 hover:border-rose-500/40 transition-colors`,children:`close`})]})]}),!d&&(0,D.jsxs)(`div`,{className:`flex-1 min-h-0 relative`,children:[(0,D.jsx)(Gu,{sessionKey:t}),(0,D.jsx)(vo,{bursts:R,paused:L,selectedId:i,onSelect:a,burstSeq:o,compact:!0,activePanelCount:g,labelDensity:w,onFrameTime:S}),m&&(0,D.jsx)(`button`,{type:`button`,onClick:h,"aria-label":`Promote ${E} to spotlight`,title:`Spotlight ${E}${O?` · ${O}`:``}`,className:`absolute inset-0 cursor-pointer bg-transparent hover:bg-sky-400/5 transition-colors`})]})]})}),qu=200,Ju=.9,Yu=40,Xu=32,Zu=480,Qu=`transform 220ms cubic-bezier(0.22, 1, 0.36, 1), opacity 220ms ease-out, fill 320ms ease-out`;function $u(e){let{playback:t,bursts:n,rangeStart:r,rangeEnd:i,loading:a,onPlayhead:o,onLive:s,onPause:c,onResume:l,on24h:u}=e,d=(0,_.useRef)(null),f=(0,_.useRef)(!1),[p,m]=(0,_.useState)(null),h=Math.max(1,i-r),g=(t.playhead_ms-r)/h*100,v=Math.max(0,Math.min(100,g)),y=(0,_.useMemo)(()=>{let e=[];for(let t=0;t<qu;t++)e.push({allow:0,block:0,ask:0,other:0});for(let t of n){let n=t.ts_ms;if(n<r||n>i)continue;let a=e[Math.floor((n-r)/h*(qu-1))];t.decision===`allow`?a.allow++:t.decision===`block`||t.decision===`force`?a.block++:t.decision===`ask`?a.ask++:a.other++}return e},[n,r,i,h]),b=(0,_.useCallback)(e=>{let t=d.current;if(!t)return;let n=t.getBoundingClientRect(),i=Math.max(0,Math.min(1,(e-n.left)/n.width));if(i>=.98){s();return}o(r+i*h)},[r,h,o,s]),x=(0,_.useCallback)(e=>{let t=d.current;if(!t)return;let n=t.getBoundingClientRect(),i=Math.max(0,Math.min(1,(e-n.left)/n.width));m({rel:i,ts:r+i*h})},[r,h]);(0,_.useEffect)(()=>{let e=e=>{f.current&&b(e.clientX)},t=()=>{f.current=!1};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,t),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t)}},[b]);let S=t.mode===`live`,C=S?`left ${Zu}ms linear`:`none`;return(0,D.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono uppercase tracking-wider`,children:[(0,D.jsx)(`button`,{onClick:()=>S?c():l(),className:`px-2.5 py-1 rounded-sm border transition-colors cursor-pointer ${S?`border-emerald-500/40 text-emerald-300 hover:bg-emerald-500/10`:`border-amber-500/40 text-amber-300 hover:bg-amber-500/10`}`,title:S?`Pause the live stream`:`Resume updates at this playhead`,children:S?`⏸ pause`:`▶ resume`}),(0,D.jsx)(`button`,{onClick:s,disabled:S,className:`px-2.5 py-1 rounded-sm border transition-colors cursor-pointer ${S?`border-[var(--color-line-1)] text-[var(--color-fg-4)] opacity-50`:`border-sky-500/40 text-sky-300 hover:bg-sky-500/10`}`,title:`Jump to live (now)`,children:`⏭ live`}),(0,D.jsx)(`button`,{onClick:u,className:`px-2.5 py-1 rounded-sm border border-violet-500/40 text-violet-300 hover:bg-violet-500/10 transition-colors cursor-pointer`,title:`Expand to last 24h — window covers now−24h through now. Backfills audit_log so the scrubber shows all recent evals.`,children:`◉ 24h`}),(0,D.jsx)(`div`,{className:`flex-1`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`mode`}),(0,D.jsx)(`span`,{className:S?`text-emerald-300`:t.mode===`paused`?`text-amber-300`:`text-violet-300`,children:t.mode}),a&&(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] animate-pulse`,children:`· backfilling`}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)]`,children:[`· t=`,ed(t.playhead_ms)]})]}),(0,D.jsxs)(`div`,{ref:d,className:`relative h-10 w-full rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] cursor-pointer overflow-hidden select-none`,onPointerDown:e=>{f.current=!0,e.target.setPointerCapture?.(e.pointerId),b(e.clientX)},onPointerMove:e=>x(e.clientX),onPointerLeave:()=>m(null),children:[a&&(0,D.jsx)(`div`,{className:`absolute inset-0 pointer-events-none opacity-40 shimmer`,"aria-hidden":!0}),(0,D.jsxs)(`svg`,{viewBox:`0 0 ${qu} ${Yu}`,preserveAspectRatio:`none`,className:`absolute inset-0 w-full h-full pointer-events-none`,"aria-hidden":!0,children:[[.25,.5,.75].map(e=>(0,D.jsx)(`line`,{x1:e*qu,x2:e*qu,y1:0,y2:Yu,stroke:`var(--color-line-1)`,strokeWidth:.3,strokeDasharray:`1,2`,opacity:.55},e)),y.map((e,t)=>{let n=e.allow+e.block+e.ask+e.other,r=Math.min(Xu,n*3),i=n===0?0:r/Xu,a=e.block>0?X.block:e.ask>0?X.ask:e.other>0&&e.allow===0?X.log:X.allow;return(0,D.jsx)(`rect`,{x:t+.05,y:Yu-Xu,width:Ju,height:Xu,rx:.3,fill:a,style:{opacity:n===0?0:.78,transform:`scaleY(${i})`,transformOrigin:`50% 100%`,transformBox:`fill-box`,transition:Qu}},t)})]}),p&&(0,D.jsx)(`div`,{className:`absolute top-0 bottom-0 w-px bg-white/15 pointer-events-none`,style:{left:`${p.rel*100}%`},"aria-hidden":!0}),(0,D.jsx)(`div`,{className:`absolute top-0 bottom-0 pointer-events-none`,style:{left:`${v}%`,width:`1px`,background:`linear-gradient(to bottom, rgba(125,211,252,0.85), rgba(56,189,248,1) 30%, rgba(56,189,248,0.85))`,boxShadow:`0 0 6px rgba(56,189,248,0.55)`,transition:C,willChange:`left`},children:(0,D.jsx)(`div`,{className:`absolute -top-0.5 -translate-x-1/2 w-2 h-2 rotate-45 bg-sky-300`,style:{boxShadow:`0 0 6px rgba(56,189,248,0.7)`}})}),S&&(0,D.jsx)(`div`,{className:`absolute top-0 right-0 bottom-0 pointer-events-none`,style:{width:`8px`,background:`linear-gradient(to left, rgba(74,222,128,0.55), rgba(74,222,128,0))`},"aria-hidden":!0,children:(0,D.jsx)(`div`,{className:`absolute top-0 right-0 bottom-0 w-[2px] bg-emerald-400 pulse-soft`})})]}),(0,D.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] font-mono text-[var(--color-fg-4)]`,children:[(0,D.jsx)(`span`,{children:td(r)}),(0,D.jsx)(`span`,{className:`uppercase tracking-wider transition-colors ${p?`text-sky-300`:``}`,children:p?`↳ ${td(p.ts)}`:`${nd(t.window_ms)} window`}),(0,D.jsx)(`span`,{children:td(i)})]})]})}function ed(e){let t=Date.now()-e;if(Math.abs(t)<1500)return`live`;let n=Math.round(t/1e3);if(n<60)return`−${n}s`;let r=Math.floor(n/60);return r<60?`−${r}m${n%60}s`:`−${Math.floor(r/60)}h${r%60}m`}function td(e){return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function nd(e){return e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${Math.round(e/36e5)}h`}var rd=80,id=600,ad=Object.freeze({stop:()=>{},count:0}),od=new Set([`allow`,`block`,`ask`,`log`,`force`,`shadow`]);function sd(e){if(!Rt()||e.length===0)return ad;let t=[],n=!1,r=0;for(let i=0;i<e.length;i++){let a=e[i];if(i>0){let t=e[i-1],n=Math.max(0,a.ts_ms-t.ts_ms),o=rd+Math.log2(1+n)*14;r+=Math.max(rd,Math.min(id,o))}let o=od.has(a.decision)?a.decision:null;if(!o)continue;let s=setTimeout(()=>{n||Wt(o)},r);t.push(s)}return{count:t.length,stop(){if(!n){n=!0;for(let e of t)clearTimeout(e);t.length=0}}}}var cd=1200,ld=3e4,ud=3e3,dd=6,fd=3,pd=`graph.panelState.v1`,md=14400*1e3;function hd(e,t){let n=new Map;for(let t of e){let e=Xi(t),r=n.get(e);r?r.push(t):n.set(e,[t])}for(let[e,r]of n){let i=t.get(e);i&&i.length===r.length&&i[i.length-1]===r[r.length-1]&&n.set(e,i)}return n}function gd(){if(typeof window>`u`)return new Map;try{let e=window.localStorage.getItem(pd);if(!e)return new Map;let t=JSON.parse(e);return new Map(Object.entries(t))}catch{return new Map}}function _d(e){if(!(typeof window>`u`))try{let t={};for(let[n,r]of e)t[n]=r;window.localStorage.setItem(pd,JSON.stringify(t))}catch{}}function vd(){let e=ga(),t=Yi(),n=qi(),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(null),s=(0,_.useCallback)((e,t)=>{i(e),o(t??null)},[]),c=Zc();(0,_.useEffect)(()=>{n&&(n.decision===`block`?c.play(`block`):n.decision===`force`&&c.play(`force`))},[c.play,n]);let l=(0,_.useCallback)(()=>c.play(`milestone`),[c]),u=(0,_.useCallback)(()=>c.play(`record`),[c]),[d,f]=(0,_.useState)(()=>{if(typeof window>`u`)return`full`;try{let e=window.localStorage.getItem(`graph.viewMode.v1`);if(e===`full`||e===`feed`||e===`stream`||e===`broadcast`)return e}catch{}return`full`});(0,_.useEffect)(()=>{if(!(typeof window>`u`))try{window.localStorage.setItem(`graph.viewMode.v1`,d)}catch{}},[d]),(0,_.useEffect)(()=>{let e=e=>e===`full`?`feed`:e===`feed`?`stream`:e===`stream`?`broadcast`:`full`,t=t=>{if(t.key===`Escape`&&d!==`full`){f(`full`);return}if(t.key===`b`||t.key===`B`){let n=t.target?.tagName;if(n===`INPUT`||n===`TEXTAREA`)return;f(e)}};return window.addEventListener(`keydown`,t),()=>window.removeEventListener(`keydown`,t)},[d]);let p=d===`broadcast`,m=d===`stream`,h=d===`feed`,g=m||p,v=p,y=m,[b,x]=(0,_.useState)(()=>{if(typeof window>`u`)return!1;try{return window.localStorage.getItem(`ssg.sfx.enabled`)===null}catch{return!1}}),S=(0,_.useCallback)(()=>{c.toggle(),x(!1)},[c]),[C,w]=(0,_.useState)(()=>typeof window<`u`&&window.matchMedia(`(max-width: 767px)`).matches);(0,_.useEffect)(()=>{let e=window.matchMedia(`(max-width: 767px)`),t=e=>w(e.matches);return e.addEventListener(`change`,t),()=>e.removeEventListener(`change`,t)},[]);let[T,E]=(0,_.useState)(!1),O=(0,_.useRef)(null),ee=(0,_.useCallback)(async e=>{try{await fetch(`/api/json/graph/close-sessions`,{method:`POST`,headers:{"Content-Type":`application/json`},credentials:`same-origin`,body:JSON.stringify(e.length>0?{session_keys:e}:{})})}catch{}E(!1),O.current&&clearTimeout(O.current)},[]),A=(0,_.useCallback)(e=>{if(!T){E(!0),O.current&&clearTimeout(O.current),O.current=setTimeout(()=>E(!1),3e3);return}ee(e)},[T,ee]);(0,_.useEffect)(()=>()=>{O.current&&clearTimeout(O.current)},[]);let j=(0,_.useRef)(new Map),M=(0,_.useRef)(0),[te,N]=(0,_.useState)({fps:0,active:0,hitches:0}),P=(0,_.useCallback)((e,t)=>{j.current.set(e,t),t>33&&(M.current+=1)},[]);(0,_.useEffect)(()=>{let e=setInterval(()=>{let e=j.current,t=M.current;if(M.current=0,e.size===0){N(e=>e.active===0?e:{fps:0,active:0,hitches:0});return}let n=0;for(let t of e.values())n+=t;let r=n/e.size,i=r>0?Math.max(1,Math.round(1e3/r)):0;N(n=>n.fps===i&&n.active===e.size&&n.hitches===t?n:{fps:i,active:e.size,hitches:t})},1e3);return()=>clearInterval(e)},[]);let{bursts:F,playback:I,oldest_known_ms:ne,newest_known_ms:re,loading_backfill:ie}=e.snapshot,{activeProject:L}=Be(),[R,ae]=(0,_.useState)(0);(0,_.useEffect)(()=>{if(L===`all`)return;let e=setInterval(()=>ae(e=>e+1),15e3);return()=>clearInterval(e)},[L]);let{data:oe}=k(`/api/json/sessions/list?limit=1000`,[L,R]),se=(0,_.useMemo)(()=>{let e=new Map;for(let t of oe?.sessions??[])e.set(t.session_key,t.project_id);return e},[oe]),ce=(0,_.useRef)(new Map),le=(0,_.useMemo)(()=>{let e=hd(F,ce.current);if(ce.current=e,L===`all`)return e;let t=new Map;for(let[n,r]of e){let e=se.get(n);(e===void 0||e===L)&&t.set(n,r)}return t},[F,se,L]),[z,ue]=(0,_.useState)(()=>gd()),[de,fe]=(0,_.useState)(null);(0,_.useEffect)(()=>{_d(z)},[z]),(0,_.useEffect)(()=>{let e=Date.now(),t=!1,n=new Map(z);for(let r of le.keys())n.has(r)||(n.set(r,{pinned:!1,pinnedAt:0,minimized:!1,firstSeenAt:e}),t=!0);for(let[r,i]of n)le.has(r)||i.pinned||e-i.firstSeenAt<md||(n.delete(r),t=!0);t&&ue(n)},[le,z]);let pe=(0,_.useRef)(new Map),me=(0,_.useRef)(new Set),he=(0,_.useRef)(new Map),[,ge]=(0,_.useState)(0);(0,_.useEffect)(()=>{let e=performance.now(),t=pe.current,n=me.current,r=he.current,i=new Set;for(let[e,n]of le)i.add(e),r.set(e,n.slice()),t.delete(e);for(let a of n)if(!i.has(a)&&!t.has(a)){let n=r.get(a)??[],i=n[n.length-1]?.ts_ms??0;t.set(a,{bursts:n,diedAt:e,newestTs:i})}for(let[n,i]of t)e-i.diedAt>=cd&&(t.delete(n),r.delete(n));if(me.current=i,t.size>0){let n=1/0;for(let e of t.values())n=Math.min(n,e.diedAt+cd);let r=Math.max(16,n-e+16),i=setTimeout(()=>ge(e=>e+1),r);return()=>clearTimeout(i)}},[le]);let _e=(0,_.useCallback)(e=>{ue(t=>{let n=new Map(t),r=n.get(e)??{pinned:!1,pinnedAt:0,minimized:!1,firstSeenAt:Date.now()};return n.set(e,{...r,pinned:!r.pinned,pinnedAt:r.pinned?0:Date.now()}),n})},[]),ve=(0,_.useCallback)(e=>{ue(t=>{let n=new Map(t),r=n.get(e)??{pinned:!1,pinnedAt:0,minimized:!1,firstSeenAt:Date.now()};return n.set(e,{...r,minimized:!r.minimized}),n})},[]),ye=(0,_.useCallback)(e=>{fe(t=>t===e?null:e)},[]);(0,_.useEffect)(()=>{if(!de)return;let e=e=>{e.key===`Escape`&&fe(null)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[de]);let be=(0,_.useRef)(null),[xe,Se]=(0,_.useState)(null);(0,_.useEffect)(()=>{if(!de){be.current?.stop(),be.current=null,Se(null);return}let e=!1;Se({sessionKey:de,entries:[],loading:!0,error:null});let t=`/api/json/graph/session-audit?session_key=${encodeURIComponent(de)}`;return fetch(t,{credentials:`same-origin`}).then(e=>e.ok?e.json():Promise.reject(Error(`HTTP ${e.status}`))).then(t=>{if(e)return;let n=Array.isArray(t.rows)?t.rows:[];Se({sessionKey:de,entries:n,loading:!1,error:null});let r=n.map(e=>({ts_ms:e.ts_ms,decision:e.decision,tool:e.tool}));be.current?.stop(),be.current=sd(r)}).catch(t=>{e||Se({sessionKey:de,entries:[],loading:!1,error:t instanceof Error?t.message:`failed to load audit log`})}),()=>{e=!0,be.current?.stop(),be.current=null}},[de]);let B=(0,_.useMemo)(()=>{let e={pinned:!1,pinnedAt:0,minimized:!1,firstSeenAt:Date.now()},t=[];for(let[n,r]of le){let i=r[r.length-1]?.ts_ms??0;t.push({key:n,bursts:r,newestTs:i,fadingOutAt:null,state:z.get(n)??e})}for(let[n,r]of pe.current)le.has(n)||t.push({key:n,bursts:r.bursts,newestTs:r.newestTs,fadingOutAt:r.diedAt,state:z.get(n)??e});return t.sort((e,t)=>e.state.pinned===t.state.pinned?e.state.pinned&&t.state.pinned?e.state.pinnedAt-t.state.pinnedAt:e.state.firstSeenAt-t.state.firstSeenAt:e.state.pinned?-1:1),t},[le,z]),Ce=(0,_.useMemo)(()=>{if(!r)return null;for(let e of F)if((e.audit_id??`${e.ts_ms}:${e.tool}`)===r||r.startsWith(`${e.ts_ms}:${e.tool}`))return e;return null},[F,r]),[we,Te]=(0,_.useState)(null),Ee=(0,_.useRef)(null),De=(0,_.useMemo)(()=>{if(B.length===0)return Ee.current=null,null;if(we!=null&&B.some(e=>e.key===we))return Ee.current=we,we;let e=B.filter(e=>e.state.pinned);if(e.length>0)return e.sort((e,t)=>t.state.pinnedAt-e.state.pinnedAt),Ee.current=e[0].key,e[0].key;let t=B[0];for(let e of B)e.newestTs>t.newestTs&&(t=e);let n=Ee.current;if(n!=null&&n!==t.key){let e=B.find(e=>e.key===n);if(e&&Date.now()-e.newestTs<ud)return n}return Ee.current=t.key,t.key},[B,we]);(0,_.useEffect)(()=>{we!=null&&(B.some(e=>e.key===we)||Te(null))},[we,B]),(0,_.useEffect)(()=>{Te(null)},[]);let Oe=(0,_.useMemo)(()=>{if(B.length===0)return{hero:null,grid:[],rail:[],overflow:[]};if(d===`full`||d===`feed`)return{hero:null,grid:B.slice(0,dd),rail:B.slice(dd),overflow:[]};let e=B.find(e=>e.key===De)??B[B.length-1],t=B.filter(t=>t.key!==e.key);return d===`broadcast`?{hero:e,grid:[],rail:[],overflow:t}:{hero:e,grid:[],rail:t.slice(0,fd),overflow:t.slice(fd)}},[B,d,De]),ke=(0,_.useCallback)(e=>{Te(e)},[]),Ae=(0,_.useCallback)(()=>{Te(null)},[]),je=(0,_.useMemo)(()=>{let e=new Map,t=new Map,n=new Map,r=new Map,i=new Map,a=new Map;for(let o of B){let s=o.key;e.set(s,()=>_e(s)),t.set(s,()=>ve(s)),n.set(s,()=>ye(s)),r.set(s,()=>void ee([s])),i.set(s,e=>P(s,e)),a.set(s,()=>ke(s))}return{onTogglePin:e,onToggleMinimize:t,onToggleFullscreen:n,onClose:r,onFrameTime:i,onPromote:a}},[_e,ve,ye,ee,P,ke,B]);(0,_.useEffect)(()=>{let e=new Set(B.map(e=>e.key)),t=j.current;for(let n of Array.from(t.keys()))e.has(n)||t.delete(n)},[B]);let Me=(0,_.useMemo)(()=>{let e=n?.counters,t=e?.total??0,r=(e?.block??0)+(e?.force??0),i=0;if(F.length>0){let e=0,t=F.slice(-100);for(let n of t)e+=n.duration_ns;i=e/t.length/1e6}return{evals:t,blocks:r,avgMs:i,agents:B.length}},[n,F,B.length]),Ne=Math.min(ne,I.playhead_ms-I.window_ms),Pe=Math.max(re,I.playhead_ms),V=Oe.grid.length,Fe=C||V<=1?1:V<=4?2:3,Ie=Math.max(1,Math.ceil(Math.max(1,V)/Fe)),Le=V<=1||C?360:180,Re=de?B.find(e=>e.key===de):null,ze=e=>e>=1e4?`${Math.round(e/1e3)}k`:e.toLocaleString();return(0,D.jsxs)(`div`,{className:`grid gap-3 md:h-[calc(100dvh-4.5rem)] md:min-h-[560px] ${g?`grid-rows-[auto_minmax(0,1fr)]`:`grid-rows-[auto_minmax(0,1fr)_auto]`} ${p?`bg-black`:``}`,children:[(0,D.jsxs)(`header`,{className:`flex items-center justify-between flex-wrap gap-y-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,D.jsx)(`h1`,{className:`text-sm font-mono uppercase tracking-wider text-[var(--color-fg-1)]`,children:`graph intelligence`}),!p&&(0,D.jsx)(`span`,{className:`chip text-sky-300 border-sky-500/30`,children:`real-time tool-use`}),I.mode===`live`?(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] font-mono uppercase tracking-wider text-emerald-300`,children:[(0,D.jsx)(`span`,{className:`status-dot bg-emerald-400 pulse-soft`}),`streaming`]}):(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] font-mono uppercase tracking-wider text-amber-300`,children:[(0,D.jsx)(`span`,{className:`status-dot bg-amber-400`}),I.mode]}),(0,D.jsxs)(`span`,{className:`flex items-center gap-x-3 gap-y-1 flex-wrap text-[11px] font-mono text-[var(--color-fg-3)] pl-3 border-l border-[var(--color-line-1)]`,children:[(0,D.jsxs)(`span`,{title:`Total evaluations since daemon start`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`↑`}),` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:ze(Me.evals)}),` `,(0,D.jsx)(`span`,{className:`hidden sm:inline`,children:`evals`})]}),(0,D.jsxs)(`span`,{title:`Block + force decisions — dangerous tool calls intercepted by SSG rules`,children:[(0,D.jsx)(`span`,{className:`text-rose-400`,children:`⛔`}),` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:ze(Me.blocks)}),` `,(0,D.jsx)(`span`,{className:`hidden sm:inline`,children:`blocks`})]}),(0,D.jsxs)(`span`,{className:`hidden md:inline`,title:`Mean eval latency over the last 100 bursts`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`⏱`}),` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:Me.avgMs<1?`${(Me.avgMs*1e3).toFixed(0)}µs`:`${Me.avgMs.toFixed(1)}ms`})]}),(0,D.jsxs)(`span`,{title:`Concurrent agent sessions in this window`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`⌥`}),` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:Me.agents}),` `,(0,D.jsxs)(`span`,{className:`hidden sm:inline`,children:[`agent`,Me.agents===1?``:`s`]})]})]})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!p&&(0,D.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:[F.length,`n · window `,Math.round(I.window_ms/1e3),`s`]}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] tabular-nums`,title:`Average RAF interval across ${te.active} canvas${te.active===1?``:`es`}${te.hitches>0?` · ${te.hitches} hitch${te.hitches===1?``:`es`} (>33ms frames)`:``}`,children:[te.active===0?`—`:`${te.fps}fps${te.hitches>0?` (${te.hitches}h)`:``}`,` · `,te.active,`/`,B.length]}),(0,D.jsx)(`div`,{role:`group`,"aria-label":`Graph view mode`,"data-tutorial":`graph-views`,className:`inline-flex items-stretch rounded border border-[var(--color-line-1)] overflow-hidden text-[10px] font-mono uppercase tracking-wider`,title:`View mode — B cycles, Esc returns to full`,children:[`full`,`feed`,`stream`,`broadcast`].map(e=>{let t=d===e;return(0,D.jsx)(`button`,{type:`button`,onClick:()=>f(e),"aria-pressed":t,title:e===`full`?`Full dashboard — sidebar, timeline, all controls`:e===`feed`?`Feed mode — vertical timeline of tool calls for non-technical users`:e===`stream`?`Stream mode — spotlight layout for Twitch/YouTube viewers`:`Broadcast mode — pure canvas for OBS scenes (Esc to exit)`,className:`px-2 py-0.5 transition-colors cursor-pointer ${t?e===`broadcast`?`bg-amber-500/15 text-amber-300`:e===`stream`?`bg-sky-500/15 text-sky-300`:e===`feed`?`bg-emerald-500/15 text-emerald-300`:`bg-[var(--color-fg-4)]/10 text-[var(--color-fg-1)]`:`text-[var(--color-fg-4)] hover:text-[var(--color-fg-2)] hover:bg-white/5`}`,children:e===`broadcast`?`cast`:e},e)})}),(0,D.jsx)(`button`,{type:`button`,onClick:S,className:`chip cursor-pointer transition-colors ${b&&!c.enabled?`border-amber-500/60 text-amber-300 animate-pulse`:`hover:border-sky-500/50 hover:text-sky-300`}`,title:c.enabled?`Mute stream sounds`:`Enable stream sounds`,children:c.enabled?`SFX ON`:b?`🔊 enable cues`:`SFX OFF`}),!p&&B.length>0&&(0,D.jsx)(`div`,{"aria-live":`polite`,children:(0,D.jsx)(`button`,{type:`button`,"aria-label":`Clear all visible graph sessions`,"data-tutorial":`graph-clear`,onClick:()=>A(B.filter(e=>!e.fadingOutAt).map(e=>e.key)),className:`chip cursor-pointer transition-colors ${T?`border-rose-500/60 text-rose-300`:`hover:border-rose-500/40 hover:text-rose-300`}`,title:`Close all active sessions on the graph — equivalent to /clear but reflects on the graph`,children:T?`confirm clear ${B.filter(e=>!e.fadingOutAt).length}`:`clear`})})]})]}),(0,D.jsxs)(`div`,{"data-tutorial":`graph-panels`,className:`grid grid-cols-1 ${v?``:y?`lg:grid-cols-[1fr_240px]`:`lg:grid-cols-[1fr_300px]`} gap-3 min-h-0 md:overflow-hidden`,children:[(0,D.jsx)(`div`,{className:`flex flex-col gap-3 min-h-0 min-w-0`,children:h?(0,D.jsx)(`div`,{className:`flex-1 flex flex-col min-h-0 rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] overflow-hidden`,children:(0,D.jsx)(Su,{bursts:F,selectedId:r,onSelect:s})}):B.length===0?(0,D.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] text-center px-4`,style:{minHeight:240},children:[(0,D.jsx)(`p`,{className:`overline mb-2 text-[var(--color-fg-3)]`,children:`graph · idle`}),(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)] max-w-[280px]`,children:`No active sessions in the current window. Each session will render as its own tree as bursts arrive.`})]}):(0,D.jsxs)(D.Fragment,{children:[Oe.hero&&(de==null||de===Oe.hero.key)&&(0,D.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col gap-2`,children:[we!=null&&(0,D.jsx)(`button`,{type:`button`,onClick:Ae,className:`self-end chip text-amber-300 border-amber-500/40 hover:border-amber-400 cursor-pointer text-[10px]`,title:`Release manual spotlight — return to auto-follow`,children:`spotlight: locked · release ↺`}),(0,D.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,D.jsx)(Ku,{sessionKey:Oe.hero.key,bursts:Oe.hero.bursts,paused:I.mode!==`live`||Oe.hero.fadingOutAt!=null,selectedId:r,onSelect:s,burstSeq:t,isStale:Oe.hero.fadingOutAt!=null||I.playhead_ms-Oe.hero.newestTs>ld,isFadingOut:Oe.hero.fadingOutAt!=null,minHeight:0,pinned:Oe.hero.state.pinned,minimized:Oe.hero.state.minimized,isFullscreen:!1,viewMode:d,activePanelCount:1,onTogglePin:je.onTogglePin.get(Oe.hero.key),onToggleMinimize:je.onToggleMinimize.get(Oe.hero.key),onToggleFullscreen:je.onToggleFullscreen.get(Oe.hero.key),onClose:je.onClose.get(Oe.hero.key),onFrameTime:je.onFrameTime.get(Oe.hero.key)},Oe.hero.key)})]}),Oe.grid.length>0&&(0,D.jsx)(`div`,{className:`flex-1 grid gap-3 min-h-0 min-w-0`,style:{gridTemplateColumns:`repeat(${Fe}, minmax(0, 1fr))`,gridTemplateRows:`repeat(${Ie}, minmax(180px, 1fr))`},children:Oe.grid.map(e=>{let n=e.fadingOutAt!=null||I.playhead_ms-e.newestTs>ld;return de!=null&&de!==e.key?null:(0,D.jsx)(Ku,{sessionKey:e.key,bursts:e.bursts,paused:I.mode!==`live`||e.fadingOutAt!=null,selectedId:r,onSelect:s,burstSeq:t,isStale:n,isFadingOut:e.fadingOutAt!=null,minHeight:Le,pinned:e.state.pinned,minimized:e.state.minimized,isFullscreen:!1,viewMode:d,activePanelCount:Oe.grid.length,onTogglePin:je.onTogglePin.get(e.key),onToggleMinimize:je.onToggleMinimize.get(e.key),onToggleFullscreen:je.onToggleFullscreen.get(e.key),onClose:je.onClose.get(e.key),onFrameTime:je.onFrameTime.get(e.key)},e.key)})}),Oe.rail.length>0&&(0,D.jsxs)(`div`,{className:`shrink-0 flex flex-col gap-1`,children:[(0,D.jsxs)(`div`,{className:`flex items-baseline justify-between text-[10px] font-mono text-[var(--color-fg-4)] uppercase tracking-wider`,children:[(0,D.jsxs)(`span`,{children:[d===`full`?`overflow rail`:`spotlight rail`,` · `,Oe.rail.length,` session`,Oe.rail.length===1?``:`s`]}),Oe.overflow.length>0&&(0,D.jsxs)(`span`,{title:Oe.overflow.map(e=>e.key).join(`
15
- `),children:[`+`,Oe.overflow.length,` more`]})]}),(0,D.jsx)(`div`,{className:`grid gap-2`,style:{gridTemplateColumns:`repeat(${Math.min(Oe.rail.length,4)}, minmax(0, 1fr))`,gridAutoRows:`110px`},children:Oe.rail.map(e=>{let n=e.fadingOutAt!=null||I.playhead_ms-e.newestTs>ld;return de!=null&&de!==e.key?null:(0,D.jsx)(Ku,{sessionKey:e.key,bursts:e.bursts,paused:I.mode!==`live`||e.fadingOutAt!=null,selectedId:r,onSelect:s,burstSeq:t,isStale:n,isFadingOut:e.fadingOutAt!=null,minHeight:110,pinned:e.state.pinned,minimized:e.state.minimized,isFullscreen:!1,viewMode:d,thumbnail:!0,onPromote:je.onPromote.get(e.key),activePanelCount:Oe.rail.length+1,onTogglePin:je.onTogglePin.get(e.key),onToggleMinimize:je.onToggleMinimize.get(e.key),onToggleFullscreen:je.onToggleFullscreen.get(e.key),onClose:je.onClose.get(e.key),onFrameTime:je.onFrameTime.get(e.key)},e.key)})})]}),d===`broadcast`&&Oe.overflow.length>0&&(0,D.jsxs)(`div`,{className:`shrink-0 self-end pointer-events-none chip text-[var(--color-fg-3)] border-[var(--color-line-1)]`,children:[`+`,Oe.overflow.length,` more session`,Oe.overflow.length===1?``:`s`,` off-screen`]})]})}),!v&&(0,D.jsxs)(`aside`,{"data-tutorial":`graph-inspector`,className:`flex flex-col gap-2 min-w-0 min-h-0 overflow-y-auto`,children:[(0,D.jsx)(ku,{onMilestone:l,onRecord:u}),!y&&(0,D.jsx)(`section`,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3`,children:(0,D.jsx)(Mu,{bursts:F,allBursts:e.allBursts})}),(0,D.jsx)(Iu,{burst:Ce,anchor:a,onClose:()=>{i(null),o(null)}})]})]}),!g&&(0,D.jsx)(`section`,{"data-tutorial":`graph-timeline`,className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3`,children:(0,D.jsx)($u,{playback:I,bursts:F,rangeStart:Ne,rangeEnd:Pe,loading:ie,onPlayhead:t=>e.setPlayhead(t),onLive:()=>e.jumpToLive(),onPause:()=>e.setMode(`paused`),onResume:()=>e.setMode(`scrubbing`),on24h:()=>e.jumpTo24h()})}),p&&(0,D.jsxs)(`div`,{className:`pointer-events-none fixed bottom-3 right-4 flex flex-col items-end gap-1 z-30`,children:[(0,D.jsx)(`span`,{className:`text-[11px] font-mono uppercase tracking-[0.18em] text-[var(--color-fg-3)]`,children:`sigmashake gov`}),(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:`broadcast mode · press B or Esc to exit`})]}),Re&&(0,D.jsxs)(`div`,{className:`fixed inset-0 z-50 bg-black/90 backdrop-blur-sm flex p-6 gap-4`,children:[(0,D.jsx)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0`,children:(0,D.jsx)(Ku,{sessionKey:Re.key,bursts:Re.bursts,paused:I.mode!==`live`||Re.fadingOutAt!=null,selectedId:r,onSelect:s,burstSeq:t,isStale:Re.fadingOutAt!=null||I.playhead_ms-Re.newestTs>ld,isFadingOut:!1,minHeight:0,pinned:Re.state.pinned,minimized:!1,isFullscreen:!0,viewMode:d,onTogglePin:()=>_e(Re.key),onToggleMinimize:()=>ve(Re.key),onToggleFullscreen:()=>ye(Re.key)},`fs-${Re.key}`)}),(0,D.jsx)(`aside`,{className:`hidden md:flex shrink-0 w-[380px] lg:w-[420px] flex-col min-h-0`,children:(0,D.jsx)(Cu,{sessionKey:Re.key,entries:xe?.sessionKey===Re.key?xe.entries:[],loading:xe?.sessionKey===Re.key?xe.loading:!0,error:xe?.sessionKey===Re.key?xe.error:null,playingIndex:-1})})]})]})}function $(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(`idle`),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(!1);async function u(){l(!0),a(``);try{let e=await fetch(`/api/hub/device-start`,{method:`POST`,headers:{Accept:`application/json`,...U()}}),n=await e.json();if(!e.ok){let t=n;t.error===`not_configured`?(r(`not_configured`),s(t.setup_steps??[]),a(t.message??`GitHub OAuth not configured.`)):(a(n.error??`HTTP ${e.status}`),r(`error`));return}t(n),r(`polling`)}catch(e){a(e instanceof Error?e.message:`Failed to start`),r(`error`)}finally{l(!1)}}return(0,_.useEffect)(()=>{if(n!==`polling`||!e)return;let t=setInterval(async()=>{try{let n=await(await fetch(`/api/hub/device-poll?flow=${e.flow_id}`,{headers:{Accept:`application/json`}})).json();n.status===`complete`?(clearInterval(t),r(`done`),a(`connected as @${n.session?.login??`GitHub`} — you can now publish rulesets`)):(n.status===`expired`||n.status===`error`)&&(clearInterval(t),r(`error`),a(n.error??`Authentication failed`))}catch{}},3e3);return()=>clearInterval(t)},[n,e]),(0,D.jsxs)(`div`,{className:`max-w-lg mx-auto space-y-5`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`a`,{href:`/hub`,className:`inline-flex items-center gap-1.5 text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-brand)] transition-colors`,children:[(0,D.jsx)(`svg`,{width:`10`,height:`10`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,D.jsx)(`polyline`,{points:`15 18 9 12 15 6`})}),`back to hub`]}),(0,D.jsx)(`h1`,{className:`text-xl font-medium tracking-tight mt-2 text-[var(--color-fg-0)]`,children:`Connect GitHub`}),(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-3)] mt-1 font-mono`,children:`authenticate with github to publish rulesets to the hub`})]}),n===`not_configured`&&(0,D.jsx)(K,{children:(0,D.jsxs)(J,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,D.jsx)(`span`,{className:`text-amber-300 shrink-0 mt-0.5`,children:(0,D.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[(0,D.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,D.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,D.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`p`,{className:`text-sm font-medium text-[var(--color-fg-0)]`,children:`GitHub OAuth not configured`}),(0,D.jsx)(`p`,{className:`text-xs text-[var(--color-fg-2)] mt-1 leading-relaxed`,children:i})]})]}),(0,D.jsxs)(`div`,{className:`border-t border-[var(--color-line-0)] pt-4`,children:[(0,D.jsx)(`div`,{className:`overline mb-3`,children:`setup steps`}),(0,D.jsx)(`ol`,{className:`space-y-2`,children:o.map((e,t)=>(0,D.jsxs)(`li`,{className:`flex items-start gap-2.5 text-xs text-[var(--color-fg-1)]`,children:[(0,D.jsx)(`span`,{className:`shrink-0 w-5 h-5 rounded-sm bg-[var(--color-surface-2)] border border-[var(--color-line-1)] text-[var(--color-fg-3)] text-[10px] font-mono flex items-center justify-center tabular-nums`,children:t+1}),(0,D.jsx)(`span`,{className:`mt-0.5 leading-relaxed`,children:e.replace(/^\d+\.\s+/,``)})]},t))})]}),(0,D.jsxs)(`div`,{className:`bg-[var(--color-surface-0)] border border-[var(--color-line-1)] rounded-sm p-3`,children:[(0,D.jsx)(`div`,{className:`overline mb-1.5`,children:`quick start`}),(0,D.jsx)(`code`,{className:`text-[11px] text-[var(--color-brand)]/90 font-mono`,children:`export SSG_GITHUB_CLIENT_ID=<your-client-id>`}),(0,D.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)] mt-1`,children:[`then restart:`,` `,(0,D.jsx)(`code`,{className:`text-[var(--color-fg-1)]`,children:`ssg serve`})]})]}),(0,D.jsx)(`a`,{href:`https://github.com/settings/applications/new`,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1.5 text-[11px] font-mono uppercase tracking-wider text-[var(--color-brand)] hover:underline`,children:`create github oauth app →`})]})}),n===`idle`&&(0,D.jsx)(K,{children:(0,D.jsxs)(J,{children:[(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-2)] mb-4 leading-relaxed`,children:`This uses GitHub's device authorization flow — no redirect URIs needed. You'll be shown a code to enter at github.com.`}),(0,D.jsx)(G,{onClick:u,disabled:c,variant:`primary`,children:c?`starting…`:`connect with github`})]})}),e&&n===`polling`&&(0,D.jsx)(K,{children:(0,D.jsxs)(J,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{className:`text-center`,children:[(0,D.jsx)(`div`,{className:`overline mb-2`,children:`open this url in your browser`}),(0,D.jsx)(`a`,{href:e.verification_uri,target:`_blank`,rel:`noreferrer`,className:`text-sm text-[var(--color-brand)] hover:underline font-mono`,children:e.verification_uri})]}),(0,D.jsxs)(`div`,{className:`border border-[var(--color-line-1)] bg-[var(--color-surface-0)] rounded-sm py-5 text-center`,children:[(0,D.jsx)(`div`,{className:`overline mb-3`,children:`enter this code`}),(0,D.jsx)(`div`,{className:`text-4xl font-mono font-bold tracking-[0.3em] text-[var(--color-fg-0)]`,children:e.user_code})]}),(0,D.jsxs)(`p`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] text-center flex items-center justify-center gap-2`,children:[(0,D.jsx)(`svg`,{className:`animate-spin`,width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,D.jsx)(`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`})}),`waiting for github authorization…`]})]})}),n===`done`&&(0,D.jsxs)(`div`,{className:`rounded-sm border border-emerald-500/25 bg-emerald-500/5 p-4 text-sm text-emerald-200 space-y-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`svg`,{width:`15`,height:`15`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,D.jsx)(`polyline`,{points:`20 6 9 17 4 12`})}),(0,D.jsx)(`span`,{className:`font-mono text-xs`,children:i})]}),(0,D.jsx)(`a`,{href:`/hub/publish`,className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-brand)] hover:underline block mt-1`,children:`publish a ruleset →`})]}),n===`error`&&i&&(0,D.jsxs)(`div`,{className:`rounded-sm border border-red-500/25 bg-red-500/5 p-4`,children:[(0,D.jsx)(`p`,{className:`text-sm text-red-200 font-mono`,children:i}),(0,D.jsx)(`button`,{onClick:()=>{r(`idle`),a(``)},className:`text-[11px] font-mono text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] mt-3 cursor-pointer uppercase tracking-wider`,children:`← try again`})]})]})}var yd={deny:`red`,block:`red`,ask:`amber`,allow:`green`,log:`gray`,force:`blue`};function bd({id:e}){let{data:t,error:n}=k(`/api/json/hub/${e}`),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(!1);if(n)return(0,D.jsxs)(`div`,{className:`text-sm text-red-300 font-mono`,children:[(0,D.jsx)(`p`,{children:n}),(0,D.jsx)(`a`,{href:`/hub`,className:`text-[var(--color-brand)] hover:underline mt-3 block text-[11px] uppercase tracking-wider`,children:`← back to hub`})]});if(!t)return(0,D.jsx)(`p`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)]`,children:`loading ruleset…`});async function s(){o(!0);try{(await fetch(`/api/hub/install`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({id:e})})).ok&&i(!0)}finally{o(!1)}}return(0,D.jsxs)(`div`,{className:`space-y-5`,children:[(0,D.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,D.jsxs)(`div`,{className:`min-w-0`,children:[(0,D.jsx)(`a`,{href:`/hub`,className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-brand)]`,children:`← hub`}),(0,D.jsx)(`h1`,{className:`text-xl font-medium tracking-tight mt-1.5 text-[var(--color-fg-0)]`,children:t.title}),(0,D.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)] mt-1 tabular-nums`,children:[`@`,t.author,` · v`,t.version,` · `,t.rule_count,` rule`,t.rule_count===1?``:`s`]})]}),(0,D.jsx)(G,{variant:r?`secondary`:`primary`,onClick:s,disabled:a||r,children:r?`✓ installed`:a?`installing…`:`install`})]}),t.technologies.length>0&&(0,D.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.technologies.map(e=>(0,D.jsx)(W,{variant:`blue`,children:e},e))}),t.github_repo&&(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`source`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:t.github_repo})]}),(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsxs)(`span`,{className:`overline`,children:[`rules · `,t.rules.length]})}),(0,D.jsx)(J,{className:`space-y-4`,children:t.rules.map((e,t)=>(0,D.jsxs)(`div`,{className:t>0?`border-t border-[var(--color-line-0)] pt-4`:void 0,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 mb-2 flex-wrap`,children:[(0,D.jsx)(W,{variant:yd[e.decision]??`gray`,children:e.decision}),(0,D.jsx)(`code`,{className:`text-xs text-[var(--color-brand)] font-mono`,children:e.name}),e.capability&&(0,D.jsx)(W,{variant:`gray`,children:e.capability})]}),(0,D.jsx)(`p`,{className:`text-sm text-[var(--color-fg-1)] mb-2`,children:e.message}),(0,D.jsx)(zr,{children:e.raw_text})]},e.id))})]})]})}var xd=[{id:`safe-writes`,title:`Protect your files from accidents`,plainDescription:`Asks before AI overwrites or erases anything important — so you stay in control of what changes.`,example:`If AI tries to overwrite a config file, you get to approve it first.`,hubRulesetId:`safe-writes`,scenario:`any`,emoji:`🛡️`,details:{protects:[`Asks first before editing project manifests & lockfiles — package.json, Cargo.toml, go.mod, and friends`,`Asks first before editing shell startup files — .bashrc, .zshrc, .profile`,`Asks first before editing git config or git hooks`,`Asks first before editing CI / build pipeline files`,`Asks first before editing AI-agent instruction files — CLAUDE.md, .cursorrules, AGENTS.md`],tryThis:`Ask your AI to add a dependency to package.json. Instead of saving silently, it pauses for your approval first.`}},{id:`no-destructive-fs`,title:`Stop AI from erasing files`,plainDescription:`Blocks the kind of filesystem operations that can permanently delete your work.`,example:`If AI tries to wipe a folder, SSG blocks it automatically.`,hubRulesetId:`no-destructive-fs`,scenario:`coding`,emoji:`🗑️`,details:{protects:[`Blocks recursive force-deletes that can wipe an entire directory tree in a single command`,`Blocks bulk deletes through find with delete or exec-remove predicates`,`Blocks disk-wipe, format & partition tools — dd, mkfs, shred, fdisk`,`Blocks Windows recursive deletes — Remove-Item with Recurse, rmdir /s, del /s`,`Blocks git clean with its force flags, which erases untracked and ignored files alike`],tryThis:`Ask your AI to recursively delete a throwaway folder. The attempt is blocked outright — it never reaches your shell.`}},{id:`secrets-guard`,title:`Keep secrets and credentials safe`,plainDescription:`Watches for AI trying to read or write your passwords, API keys, and private keys.`,example:`Reading your .env file, SSH keys, or .netrc triggers an approval request.`,hubRulesetId:`secrets-guard`,scenario:`any`,emoji:`🔑`,details:{protects:[`Blocks reading .env files`,`Blocks reading private keys, SSH keys, .netrc & .pgpass`,`Blocks reading cloud credential stores — AWS, GCP, Azure, kube, docker`,`Blocks dumping secret files through cat / head / tail / type`,`Blocks writing hardcoded API keys — AWS, Anthropic, OpenAI — into source`,`Blocks writing PEM private keys into source files`],tryThis:`Ask your AI to read your .env file. The read is blocked, so the contents never land in the chat transcript.`}},{id:`email-guardrails`,title:`Ask before AI sends emails`,plainDescription:`Makes sure AI never sends a message on your behalf without your explicit OK.`,example:`Any outbound email action is queued for your approval before it goes.`,hubRulesetId:`email-guardrails`,scenario:`knowledge-work`,emoji:`📧`,details:{protects:[`Asks first before local mail commands — mail, sendmail, mutt, msmtp`,`Asks first before curl is used to talk SMTP directly`,`Asks first before calls to transactional-email APIs — SendGrid, Mailgun, Postmark, Resend, SES, and more`],tryThis:`Ask your AI to send a quick test email. It pauses and asks you to confirm the recipient and body before anything goes out.`}},{id:`no-paid-apis`,title:`Block surprise charges from paid APIs`,plainDescription:`Blocks AI from calling APIs that can rack up unexpected bills — cloud storage, AI providers, payment services.`,example:`A call to OpenAI, AWS S3, or Stripe triggers a block until you allow it.`,hubRulesetId:`no-paid-apis`,scenario:`any`,emoji:`💳`,details:{protects:[`Asks first before calls to paid LLM APIs — OpenAI, Anthropic, Groq, Bedrock, and more`,`Asks first before payment APIs — Stripe, PayPal, Square, Adyen`,`Asks first before SMS / voice APIs — Twilio, Vonage, MessageBird`,`Asks first before cloud-storage writes — aws s3 cp/sync, gsutil, az storage`],tryThis:`Ask your AI to call the OpenAI API. It checks with you before sending — so a runaway loop cannot quietly rack up spend.`}},{id:`read-only-mode`,title:`Read-only mode (maximum safety)`,plainDescription:`AI can look but not touch — all write operations are blocked. Great when you just want to explore safely.`,example:`AI can read your codebase and answer questions but cannot change any files.`,hubRulesetId:`read-only`,scenario:`any`,emoji:`🔒`,details:{protects:[`Blocks every file write and edit`,`Blocks state-changing shell commands — file deletes & moves, package installs, sudo, docker, kubectl, terraform`,`Blocks shell redirection that writes to disk`,`Blocks git commands that change state — commit, push, reset, checkout`,`Blocks network requests that are not GET — no POST, PUT, PATCH, DELETE`],tryThis:`Ask your AI to edit any file. Every write is refused until you remove this pack — but reading code and answering questions still works.`}}];function Sd(e){return e?xd.filter(t=>t.scenario===`any`||t.scenario===e):xd}function Cd({pack:e,installed:t,state:n,expanded:r,onInstall:i,onUninstall:a,onToggleDetails:o}){let s=n!==`idle`;return(0,D.jsxs)(`div`,{className:`ss-list-row ss-list-row--pack`,style:{cursor:`default`,background:t?`linear-gradient(180deg, color-mix(in oklab, var(--color-hig-green) 8%, transparent) 0%, transparent 60%), var(--color-surface-1)`:`var(--color-surface-1)`,borderColor:t?`color-mix(in oklab, var(--color-hig-green) 28%, var(--color-line-1))`:`var(--color-line-1)`},children:[(0,D.jsxs)(`div`,{className:`ss-pack-main`,children:[(0,D.jsx)(`span`,{className:`ss-pack-emoji`,"aria-hidden":`true`,children:e.emoji}),(0,D.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,D.jsx)(`h3`,{className:`ss-pack-title`,children:e.title}),t&&(0,D.jsxs)(`span`,{className:`agent-badge agent-badge--detected`,title:`This pack is currently active.`,children:[(0,D.jsx)(`span`,{className:`agent-badge-dot`}),`Installed`]})]}),(0,D.jsx)(`p`,{className:`ss-pack-desc`,children:e.plainDescription}),(0,D.jsxs)(`p`,{className:`ss-pack-example`,children:[(0,D.jsx)(`span`,{className:`ss-pack-example__label`,children:`Example`}),e.example]}),(0,D.jsx)(`button`,{type:`button`,className:`ss-pack-detail-toggle`,"aria-expanded":r,onClick:()=>o(e.id),children:r?`Hide details`:t?`What this is doing →`:`What's inside →`})]}),(0,D.jsx)(`div`,{className:`ss-pack-action`,children:t?(0,D.jsx)(`button`,{type:`button`,disabled:s,onClick:()=>a(e.id),className:`ss-btn ss-btn--secondary`,style:{height:30,padding:`0 12px`,fontSize:11},title:`Remove this pack from your machine.`,children:n===`uninstalling`?`Removing…`:`Remove`}):(0,D.jsx)(`button`,{type:`button`,disabled:s,onClick:()=>i(e.id),className:`ss-btn ss-btn--primary`,style:{height:30,padding:`0 14px`,fontSize:11},title:`Install this guardrail pack.`,children:n===`installing`?`Installing…`:`Install`})})]}),r&&(0,D.jsxs)(`div`,{className:`ss-pack-detail`,children:[(0,D.jsxs)(`div`,{className:`ss-pack-detail__section`,children:[(0,D.jsx)(`span`,{className:`ss-pack-detail__label`,children:t?`Installed`:`What gets installed`}),(0,D.jsxs)(`p`,{className:`ss-pack-detail__text`,children:[(0,D.jsxs)(`code`,{children:[e.hubRulesetId,`.rules`]}),` — one plain-text rules file`,t?` now living in `:`, written to `,`your `,(0,D.jsx)(`code`,{children:`.sigmashake/rules/`}),` folder.`,` `,t?`It's active right away — no restart needed.`:`Installing adds just this one file; removing the pack deletes it.`]})]}),(0,D.jsxs)(`div`,{className:`ss-pack-detail__section`,children:[(0,D.jsx)(`span`,{className:`ss-pack-detail__label`,children:`What it does`}),(0,D.jsx)(`ul`,{className:`ss-pack-detail__list`,children:e.details.protects.map(e=>(0,D.jsx)(`li`,{children:e},e))})]}),(0,D.jsxs)(`div`,{className:`ss-pack-detail__section`,children:[(0,D.jsx)(`span`,{className:`ss-pack-detail__label`,children:`See it working`}),(0,D.jsx)(`p`,{className:`ss-pack-detail__text`,children:e.details.tryThis}),(0,D.jsxs)(`p`,{className:`ss-pack-detail__hint`,children:[`Every block and approval prompt is logged on the`,` `,(0,D.jsx)(`a`,{href:`/audit`,children:`Activity`}),` page. To fire a rule on purpose without leaving the dashboard, open `,(0,D.jsx)(`a`,{href:`/try`,children:`Try It`}),`.`]})]})]})]})}function wd(){let e=new URLSearchParams(window.location.search).get(`starter`),t=Sd(e),[n,r]=(0,_.useState)(new Set),[i,a]=(0,_.useState)({}),[o,s]=(0,_.useState)(new Set),[c,l]=(0,_.useState)(null);function u(e){s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}(0,_.useEffect)(()=>{let e=!1;return fetch(`/api/json/hub/installed`).then(e=>e.json()).then(t=>{e||r(new Set(t.installed))}).catch(()=>{}),()=>{e=!0}},[]);function d(e,t){l({msg:e,type:t}),setTimeout(()=>l(null),5e3)}async function f(){try{let e=await(await fetch(`/api/json/hub/installed`)).json();r(new Set(e.installed))}catch{}}async function p(e){let t=xd.find(t=>t.id===e);if(t){a(t=>({...t,[e]:`installing`}));try{let n=await fetch(`/api/hub/install`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`,...U()},body:JSON.stringify({id:t.hubRulesetId})}),i=await n.text(),a=n.headers.get(`Content-Type`)??``,o=null;if(a.includes(`application/json`))try{o=JSON.parse(i)}catch{}o?.ok?(r(e=>new Set([...e,t.hubRulesetId])),s(t=>new Set([...t,e])),d(o.already_installed?`${t.title} — already installed`:`${t.title} — installed`,`ok`)):d(o?o.error??`Could not install ${t.title}`:i.replace(/<[^>]+>/g,``).trim()||`Could not install ${t.title} (HTTP ${n.status})`,`error`)}catch(e){d(`Could not reach the dashboard server (${e instanceof Error?e.message:String(e)})`,`error`)}finally{a(t=>({...t,[e]:`idle`})),f()}}}async function m(e){let t=xd.find(t=>t.id===e);if(t&&window.confirm(`Remove “${t.title}”?\n\nThe rules in this pack stop applying. You can install it again any time.`)){a(t=>({...t,[e]:`uninstalling`}));try{let e=await fetch(`/api/hub/uninstall`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`,...U()},body:JSON.stringify({id:t.hubRulesetId})}),n=await e.text(),i=e.headers.get(`Content-Type`)??``,a=null;if(i.includes(`application/json`))try{a=JSON.parse(n)}catch{}a?.ok||e.ok&&!a?(r(e=>{let n=new Set(e);return n.delete(t.hubRulesetId),n}),d(`${t.title} — removed`,`ok`)):d(a?a.error??`Could not remove ${t.title}`:n.replace(/<[^>]+>/g,``).trim()||`Could not remove ${t.title} (HTTP ${e.status})`,`error`)}catch(e){d(`Could not reach the dashboard server (${e instanceof Error?e.message:String(e)})`,`error`)}finally{a(t=>({...t,[e]:`idle`})),f()}}}let h={coding:`for coding with AI`,"knowledge-work":`for email and docs`},g=t.filter(e=>n.has(e.hubRulesetId)).length;return(0,D.jsxs)(`div`,{className:`max-w-3xl mx-auto space-y-6`,children:[(0,D.jsxs)(`section`,{"data-tutorial":`guard-hero`,className:`rounded-2xl p-5`,style:{border:`1px solid var(--color-line-1)`,background:`var(--color-surface-1)`},children:[(0,D.jsx)(`p`,{className:`ss-list-section-title`,style:{padding:0,marginBottom:8},children:`Guardrails`}),(0,D.jsxs)(`h1`,{className:`text-[18px] font-semibold text-[var(--color-fg-0)] tracking-tight`,children:[`One-tap protection`,e&&h[e]?` ${h[e]}`:``]}),(0,D.jsxs)(`p`,{className:`text-[12.5px] text-[var(--color-fg-2)] mt-1.5 leading-relaxed`,children:[`Each pack is a small set of rules that guard against a specific AI risk. Toggle them on and off — installing or removing only touches rule files in`,` `,(0,D.jsx)(`code`,{className:`text-[var(--color-brand)]`,children:`.sigmashake/`}),`.`]}),(0,D.jsxs)(`p`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] mt-3`,children:[g,` of `,t.length,` active`]})]}),c&&(0,D.jsx)(`div`,{className:`rounded-xl px-4 py-2.5 text-[12px]`,style:{border:`1px solid ${c.type===`ok`?`color-mix(in oklab, var(--color-hig-green) 36%, transparent)`:`color-mix(in oklab, var(--color-hig-red) 36%, transparent)`}`,background:c.type===`ok`?`color-mix(in oklab, var(--color-hig-green) 12%, var(--color-surface-1))`:`color-mix(in oklab, var(--color-hig-red) 12%, var(--color-surface-1))`,color:c.type===`ok`?`var(--color-hig-green)`:`var(--color-hig-red)`,backdropFilter:`saturate(180%) blur(10px)`},children:c.msg}),(0,D.jsx)(`div`,{"data-tutorial":`guard-packs`,className:`ss-list`,children:t.map(e=>(0,D.jsx)(Cd,{pack:e,installed:n.has(e.hubRulesetId),state:i[e.id]??`idle`,expanded:o.has(e.id),onInstall:p,onUninstall:m,onToggleDetails:u},e.id))}),(0,D.jsx)(`div`,{"data-tutorial":`guard-advanced`,className:`rounded-xl p-4`,style:{border:`1px dashed var(--color-line-1)`,background:`color-mix(in oklab, var(--color-surface-1) 50%, transparent)`},children:(0,D.jsxs)(`p`,{className:`text-[12px] text-[var(--color-fg-2)] leading-relaxed`,children:[`Want more control? The`,` `,(0,D.jsx)(`a`,{href:`/hub`,className:`text-[var(--color-brand)] hover:underline`,children:`advanced library`}),` `,`has the full set of community rulesets and lets you preview every rule before installing.`]})})]})}function Td(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Ed(e){let t=e;if(t.endsWith(`/.sigmashake/rules`)&&(t=t.slice(0,-18)),t.endsWith(`\\.sigmashake\\rules`)&&(t=t.slice(0,-18)),t.startsWith(`/home/`)){let e=t.slice(6),n=e.indexOf(`/`);return n>=0?`~/${e.slice(n+1)}`:`~`}if(t.startsWith(`C:\\Users\\`)){let e=t.slice(9),n=e.indexOf(`\\`);return n>=0?`~\\${e.slice(n+1)}`:`~`}if(t.length>40){let e=t.split(/[/\\]/);if(e.length>2)return`…/${e[e.length-1]}`}return t}var Dd=[{value:`downloads`,label:`most downloaded`},{value:`newest`,label:`newest`},{value:`rules`,label:`most rules`}],Od=[``,`critical`,`high`,`medium`,`low`],kd=[``,`deny`,`ask`,`allow`,`log`];function Ad(){return(0,D.jsxs)(`div`,{className:`rounded-sm border border-[var(--color-line-0)] bg-[var(--color-surface-1)] p-4 space-y-3 shimmer`,children:[(0,D.jsx)(`div`,{className:`h-4 bg-[var(--color-surface-3)] rounded-sm w-2/3`}),(0,D.jsx)(`div`,{className:`h-3 bg-[var(--color-surface-2)] rounded-sm w-1/3`}),(0,D.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,D.jsx)(`div`,{className:`h-5 bg-[var(--color-surface-3)] rounded-sm w-14`}),(0,D.jsx)(`div`,{className:`h-5 bg-[var(--color-surface-3)] rounded-sm w-10`})]}),(0,D.jsx)(`div`,{className:`h-7 bg-[var(--color-surface-3)] rounded-sm`})]})}function jd({tech:e}){return(0,D.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded-sm text-[10px] font-mono uppercase tracking-wider border ${{typescript:`bg-sky-500/8 text-sky-300 border-sky-500/25`,ts:`bg-sky-500/8 text-sky-300 border-sky-500/25`,javascript:`bg-amber-500/8 text-amber-300 border-amber-500/25`,js:`bg-amber-500/8 text-amber-300 border-amber-500/25`,python:`bg-emerald-500/8 text-emerald-300 border-emerald-500/25`,rust:`bg-orange-500/8 text-orange-300 border-orange-500/25`,go:`bg-cyan-500/8 text-cyan-300 border-cyan-500/25`,bash:`bg-violet-500/8 text-violet-300 border-violet-500/25`}[e.toLowerCase()]??`bg-[var(--color-surface-2)] text-[var(--color-fg-3)] border-[var(--color-line-1)]`}`,children:e})}function Md({install:e,onRemove:t,removing:n}){let r=Ed(e.path),i=e.in_sync?`bg-emerald-400`:`bg-amber-400 animate-pulse`;return(0,D.jsxs)(`div`,{className:`group/chip inline-flex items-center gap-1.5 max-w-full pl-1.5 pr-0.5 py-0.5 rounded-sm bg-[var(--color-surface-2)] border border-[var(--color-line-1)] text-[10px] font-mono text-[var(--color-fg-2)]`,title:e.in_sync?`In sync — files present in ${e.path}`:`Drift — ${e.drift_reason??`files missing or empty`} (${e.path})`,children:[(0,D.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 ${i}`,"aria-hidden":!0}),(0,D.jsx)(`span`,{className:`truncate`,title:e.path,children:r}),(0,D.jsx)(`button`,{type:`button`,onClick:r=>{r.preventDefault(),r.stopPropagation(),n||t(e.path)},disabled:n,title:`Remove from this location`,"aria-label":`Uninstall from ${e.path}`,className:`shrink-0 inline-flex items-center justify-center w-4 h-4 rounded-sm text-[var(--color-fg-4)] hover:text-red-300 hover:bg-red-500/10 transition-colors cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed`,children:n?(0,D.jsx)(`svg`,{className:`animate-spin`,width:`9`,height:`9`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,D.jsx)(`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`})}):(0,D.jsxs)(`svg`,{width:`9`,height:`9`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`3`,children:[(0,D.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,D.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})})]})}function Nd({isInstalling:e,hasInstalls:t,onInstallDefault:n,onPickPath:r}){let[i,a]=(0,_.useState)(!1),o=(0,_.useRef)(null);return(0,_.useEffect)(()=>{if(!i)return;function e(e){o.current&&(o.current.contains(e.target)||a(!1))}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[i]),(0,D.jsxs)(`div`,{ref:o,className:`relative flex w-full`,children:[(0,D.jsx)(`button`,{onClick:e=>{e.preventDefault(),e.stopPropagation(),n()},disabled:e,className:`flex-1 h-7 rounded-l-sm text-[11px] font-mono uppercase tracking-wider transition-colors cursor-pointer
15
+ `),children:[`+`,Oe.overflow.length,` more`]})]}),(0,D.jsx)(`div`,{className:`grid gap-2`,style:{gridTemplateColumns:`repeat(${Math.min(Oe.rail.length,4)}, minmax(0, 1fr))`,gridAutoRows:`110px`},children:Oe.rail.map(e=>{let n=e.fadingOutAt!=null||I.playhead_ms-e.newestTs>ld;return de!=null&&de!==e.key?null:(0,D.jsx)(Ku,{sessionKey:e.key,bursts:e.bursts,paused:I.mode!==`live`||e.fadingOutAt!=null,selectedId:r,onSelect:s,burstSeq:t,isStale:n,isFadingOut:e.fadingOutAt!=null,minHeight:110,pinned:e.state.pinned,minimized:e.state.minimized,isFullscreen:!1,viewMode:d,thumbnail:!0,onPromote:je.onPromote.get(e.key),activePanelCount:Oe.rail.length+1,onTogglePin:je.onTogglePin.get(e.key),onToggleMinimize:je.onToggleMinimize.get(e.key),onToggleFullscreen:je.onToggleFullscreen.get(e.key),onClose:je.onClose.get(e.key),onFrameTime:je.onFrameTime.get(e.key)},e.key)})})]}),d===`broadcast`&&Oe.overflow.length>0&&(0,D.jsxs)(`div`,{className:`shrink-0 self-end pointer-events-none chip text-[var(--color-fg-3)] border-[var(--color-line-1)]`,children:[`+`,Oe.overflow.length,` more session`,Oe.overflow.length===1?``:`s`,` off-screen`]})]})}),!v&&(0,D.jsxs)(`aside`,{"data-tutorial":`graph-inspector`,className:`flex flex-col gap-2 min-w-0 min-h-0 overflow-y-auto`,children:[(0,D.jsx)(ku,{onMilestone:l,onRecord:u}),!y&&(0,D.jsx)(`section`,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3`,children:(0,D.jsx)(Mu,{bursts:F,allBursts:e.allBursts})}),(0,D.jsx)(Iu,{burst:Ce,anchor:a,onClose:()=>{i(null),o(null)}})]})]}),!g&&(0,D.jsx)(`section`,{"data-tutorial":`graph-timeline`,className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3`,children:(0,D.jsx)($u,{playback:I,bursts:e.allBursts,rangeStart:Ne,rangeEnd:Pe,loading:ie,onPlayhead:t=>e.setPlayhead(t),onLive:()=>e.jumpToLive(),onPause:()=>e.setMode(`paused`),onResume:()=>e.setMode(`scrubbing`),on24h:()=>e.jumpTo24h()})}),p&&(0,D.jsxs)(`div`,{className:`pointer-events-none fixed bottom-3 right-4 flex flex-col items-end gap-1 z-30`,children:[(0,D.jsx)(`span`,{className:`text-[11px] font-mono uppercase tracking-[0.18em] text-[var(--color-fg-3)]`,children:`sigmashake gov`}),(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:`broadcast mode · press B or Esc to exit`})]}),Re&&(0,D.jsxs)(`div`,{className:`fixed inset-0 z-50 bg-black/90 backdrop-blur-sm flex p-6 gap-4`,children:[(0,D.jsx)(`div`,{className:`flex-1 flex flex-col min-w-0 min-h-0`,children:(0,D.jsx)(Ku,{sessionKey:Re.key,bursts:Re.bursts,paused:I.mode!==`live`||Re.fadingOutAt!=null,selectedId:r,onSelect:s,burstSeq:t,isStale:Re.fadingOutAt!=null||I.playhead_ms-Re.newestTs>ld,isFadingOut:!1,minHeight:0,pinned:Re.state.pinned,minimized:!1,isFullscreen:!0,viewMode:d,onTogglePin:()=>_e(Re.key),onToggleMinimize:()=>ve(Re.key),onToggleFullscreen:()=>ye(Re.key)},`fs-${Re.key}`)}),(0,D.jsx)(`aside`,{className:`hidden md:flex shrink-0 w-[380px] lg:w-[420px] flex-col min-h-0`,children:(0,D.jsx)(Cu,{sessionKey:Re.key,entries:xe?.sessionKey===Re.key?xe.entries:[],loading:xe?.sessionKey===Re.key?xe.loading:!0,error:xe?.sessionKey===Re.key?xe.error:null,playingIndex:-1})})]})]})}function $(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(`idle`),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(!1);async function u(){l(!0),a(``);try{let e=await fetch(`/api/hub/device-start`,{method:`POST`,headers:{Accept:`application/json`,...U()}}),n=await e.json();if(!e.ok){let t=n;t.error===`not_configured`?(r(`not_configured`),s(t.setup_steps??[]),a(t.message??`GitHub OAuth not configured.`)):(a(n.error??`HTTP ${e.status}`),r(`error`));return}t(n),r(`polling`)}catch(e){a(e instanceof Error?e.message:`Failed to start`),r(`error`)}finally{l(!1)}}return(0,_.useEffect)(()=>{if(n!==`polling`||!e)return;let t=setInterval(async()=>{try{let n=await(await fetch(`/api/hub/device-poll?flow=${e.flow_id}`,{headers:{Accept:`application/json`}})).json();n.status===`complete`?(clearInterval(t),r(`done`),a(`connected as @${n.session?.login??`GitHub`} — you can now publish rulesets`)):(n.status===`expired`||n.status===`error`)&&(clearInterval(t),r(`error`),a(n.error??`Authentication failed`))}catch{}},3e3);return()=>clearInterval(t)},[n,e]),(0,D.jsxs)(`div`,{className:`max-w-lg mx-auto space-y-5`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`a`,{href:`/hub`,className:`inline-flex items-center gap-1.5 text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-brand)] transition-colors`,children:[(0,D.jsx)(`svg`,{width:`10`,height:`10`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,D.jsx)(`polyline`,{points:`15 18 9 12 15 6`})}),`back to hub`]}),(0,D.jsx)(`h1`,{className:`text-xl font-medium tracking-tight mt-2 text-[var(--color-fg-0)]`,children:`Connect GitHub`}),(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-3)] mt-1 font-mono`,children:`authenticate with github to publish rulesets to the hub`})]}),n===`not_configured`&&(0,D.jsx)(K,{children:(0,D.jsxs)(J,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,D.jsx)(`span`,{className:`text-amber-300 shrink-0 mt-0.5`,children:(0,D.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[(0,D.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,D.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,D.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]})}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`p`,{className:`text-sm font-medium text-[var(--color-fg-0)]`,children:`GitHub OAuth not configured`}),(0,D.jsx)(`p`,{className:`text-xs text-[var(--color-fg-2)] mt-1 leading-relaxed`,children:i})]})]}),(0,D.jsxs)(`div`,{className:`border-t border-[var(--color-line-0)] pt-4`,children:[(0,D.jsx)(`div`,{className:`overline mb-3`,children:`setup steps`}),(0,D.jsx)(`ol`,{className:`space-y-2`,children:o.map((e,t)=>(0,D.jsxs)(`li`,{className:`flex items-start gap-2.5 text-xs text-[var(--color-fg-1)]`,children:[(0,D.jsx)(`span`,{className:`shrink-0 w-5 h-5 rounded-sm bg-[var(--color-surface-2)] border border-[var(--color-line-1)] text-[var(--color-fg-3)] text-[10px] font-mono flex items-center justify-center tabular-nums`,children:t+1}),(0,D.jsx)(`span`,{className:`mt-0.5 leading-relaxed`,children:e.replace(/^\d+\.\s+/,``)})]},t))})]}),(0,D.jsxs)(`div`,{className:`bg-[var(--color-surface-0)] border border-[var(--color-line-1)] rounded-sm p-3`,children:[(0,D.jsx)(`div`,{className:`overline mb-1.5`,children:`quick start`}),(0,D.jsx)(`code`,{className:`text-[11px] text-[var(--color-brand)]/90 font-mono`,children:`export SSG_GITHUB_CLIENT_ID=<your-client-id>`}),(0,D.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)] mt-1`,children:[`then restart:`,` `,(0,D.jsx)(`code`,{className:`text-[var(--color-fg-1)]`,children:`ssg serve`})]})]}),(0,D.jsx)(`a`,{href:`https://github.com/settings/applications/new`,target:`_blank`,rel:`noreferrer`,className:`inline-flex items-center gap-1.5 text-[11px] font-mono uppercase tracking-wider text-[var(--color-brand)] hover:underline`,children:`create github oauth app →`})]})}),n===`idle`&&(0,D.jsx)(K,{children:(0,D.jsxs)(J,{children:[(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-2)] mb-4 leading-relaxed`,children:`This uses GitHub's device authorization flow — no redirect URIs needed. You'll be shown a code to enter at github.com.`}),(0,D.jsx)(G,{onClick:u,disabled:c,variant:`primary`,children:c?`starting…`:`connect with github`})]})}),e&&n===`polling`&&(0,D.jsx)(K,{children:(0,D.jsxs)(J,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{className:`text-center`,children:[(0,D.jsx)(`div`,{className:`overline mb-2`,children:`open this url in your browser`}),(0,D.jsx)(`a`,{href:e.verification_uri,target:`_blank`,rel:`noreferrer`,className:`text-sm text-[var(--color-brand)] hover:underline font-mono`,children:e.verification_uri})]}),(0,D.jsxs)(`div`,{className:`border border-[var(--color-line-1)] bg-[var(--color-surface-0)] rounded-sm py-5 text-center`,children:[(0,D.jsx)(`div`,{className:`overline mb-3`,children:`enter this code`}),(0,D.jsx)(`div`,{className:`text-4xl font-mono font-bold tracking-[0.3em] text-[var(--color-fg-0)]`,children:e.user_code})]}),(0,D.jsxs)(`p`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] text-center flex items-center justify-center gap-2`,children:[(0,D.jsx)(`svg`,{className:`animate-spin`,width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,D.jsx)(`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`})}),`waiting for github authorization…`]})]})}),n===`done`&&(0,D.jsxs)(`div`,{className:`rounded-sm border border-emerald-500/25 bg-emerald-500/5 p-4 text-sm text-emerald-200 space-y-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`svg`,{width:`15`,height:`15`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,D.jsx)(`polyline`,{points:`20 6 9 17 4 12`})}),(0,D.jsx)(`span`,{className:`font-mono text-xs`,children:i})]}),(0,D.jsx)(`a`,{href:`/hub/publish`,className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-brand)] hover:underline block mt-1`,children:`publish a ruleset →`})]}),n===`error`&&i&&(0,D.jsxs)(`div`,{className:`rounded-sm border border-red-500/25 bg-red-500/5 p-4`,children:[(0,D.jsx)(`p`,{className:`text-sm text-red-200 font-mono`,children:i}),(0,D.jsx)(`button`,{onClick:()=>{r(`idle`),a(``)},className:`text-[11px] font-mono text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] mt-3 cursor-pointer uppercase tracking-wider`,children:`← try again`})]})]})}var yd={deny:`red`,block:`red`,ask:`amber`,allow:`green`,log:`gray`,force:`blue`};function bd({id:e}){let{data:t,error:n}=k(`/api/json/hub/${e}`),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(!1);if(n)return(0,D.jsxs)(`div`,{className:`text-sm text-red-300 font-mono`,children:[(0,D.jsx)(`p`,{children:n}),(0,D.jsx)(`a`,{href:`/hub`,className:`text-[var(--color-brand)] hover:underline mt-3 block text-[11px] uppercase tracking-wider`,children:`← back to hub`})]});if(!t)return(0,D.jsx)(`p`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)]`,children:`loading ruleset…`});async function s(){o(!0);try{(await fetch(`/api/hub/install`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({id:e})})).ok&&i(!0)}finally{o(!1)}}return(0,D.jsxs)(`div`,{className:`space-y-5`,children:[(0,D.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,D.jsxs)(`div`,{className:`min-w-0`,children:[(0,D.jsx)(`a`,{href:`/hub`,className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-brand)]`,children:`← hub`}),(0,D.jsx)(`h1`,{className:`text-xl font-medium tracking-tight mt-1.5 text-[var(--color-fg-0)]`,children:t.title}),(0,D.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)] mt-1 tabular-nums`,children:[`@`,t.author,` · v`,t.version,` · `,t.rule_count,` rule`,t.rule_count===1?``:`s`]})]}),(0,D.jsx)(G,{variant:r?`secondary`:`primary`,onClick:s,disabled:a||r,children:r?`✓ installed`:a?`installing…`:`install`})]}),t.technologies.length>0&&(0,D.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.technologies.map(e=>(0,D.jsx)(W,{variant:`blue`,children:e},e))}),t.github_repo&&(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`source`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:t.github_repo})]}),(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsxs)(`span`,{className:`overline`,children:[`rules · `,t.rules.length]})}),(0,D.jsx)(J,{className:`space-y-4`,children:t.rules.map((e,t)=>(0,D.jsxs)(`div`,{className:t>0?`border-t border-[var(--color-line-0)] pt-4`:void 0,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 mb-2 flex-wrap`,children:[(0,D.jsx)(W,{variant:yd[e.decision]??`gray`,children:e.decision}),(0,D.jsx)(`code`,{className:`text-xs text-[var(--color-brand)] font-mono`,children:e.name}),e.capability&&(0,D.jsx)(W,{variant:`gray`,children:e.capability})]}),(0,D.jsx)(`p`,{className:`text-sm text-[var(--color-fg-1)] mb-2`,children:e.message}),(0,D.jsx)(zr,{children:e.raw_text})]},e.id))})]})]})}var xd=[{id:`safe-writes`,title:`Protect your files from accidents`,plainDescription:`Asks before AI overwrites or erases anything important — so you stay in control of what changes.`,example:`If AI tries to overwrite a config file, you get to approve it first.`,hubRulesetId:`safe-writes`,scenario:`any`,emoji:`🛡️`,details:{protects:[`Asks first before editing project manifests & lockfiles — package.json, Cargo.toml, go.mod, and friends`,`Asks first before editing shell startup files — .bashrc, .zshrc, .profile`,`Asks first before editing git config or git hooks`,`Asks first before editing CI / build pipeline files`,`Asks first before editing AI-agent instruction files — CLAUDE.md, .cursorrules, AGENTS.md`],tryThis:`Ask your AI to add a dependency to package.json. Instead of saving silently, it pauses for your approval first.`}},{id:`no-destructive-fs`,title:`Stop AI from erasing files`,plainDescription:`Blocks the kind of filesystem operations that can permanently delete your work.`,example:`If AI tries to wipe a folder, SSG blocks it automatically.`,hubRulesetId:`no-destructive-fs`,scenario:`coding`,emoji:`🗑️`,details:{protects:[`Blocks recursive force-deletes that can wipe an entire directory tree in a single command`,`Blocks bulk deletes through find with delete or exec-remove predicates`,`Blocks disk-wipe, format & partition tools — dd, mkfs, shred, fdisk`,`Blocks Windows recursive deletes — Remove-Item with Recurse, rmdir /s, del /s`,`Blocks git clean with its force flags, which erases untracked and ignored files alike`],tryThis:`Ask your AI to recursively delete a throwaway folder. The attempt is blocked outright — it never reaches your shell.`}},{id:`secrets-guard`,title:`Keep secrets and credentials safe`,plainDescription:`Watches for AI trying to read or write your passwords, API keys, and private keys.`,example:`Reading your .env file, SSH keys, or .netrc triggers an approval request.`,hubRulesetId:`secrets-guard`,scenario:`any`,emoji:`🔑`,details:{protects:[`Blocks reading .env files`,`Blocks reading private keys, SSH keys, .netrc & .pgpass`,`Blocks reading cloud credential stores — AWS, GCP, Azure, kube, docker`,`Blocks dumping secret files through cat / head / tail / type`,`Blocks writing hardcoded API keys — AWS, Anthropic, OpenAI — into source`,`Blocks writing PEM private keys into source files`],tryThis:`Ask your AI to read your .env file. The read is blocked, so the contents never land in the chat transcript.`}},{id:`email-guardrails`,title:`Ask before AI sends emails`,plainDescription:`Makes sure AI never sends a message on your behalf without your explicit OK.`,example:`Any outbound email action is queued for your approval before it goes.`,hubRulesetId:`email-guardrails`,scenario:`knowledge-work`,emoji:`📧`,details:{protects:[`Asks first before local mail commands — mail, sendmail, mutt, msmtp`,`Asks first before curl is used to talk SMTP directly`,`Asks first before calls to transactional-email APIs — SendGrid, Mailgun, Postmark, Resend, SES, and more`],tryThis:`Ask your AI to send a quick test email. It pauses and asks you to confirm the recipient and body before anything goes out.`}},{id:`no-paid-apis`,title:`Block surprise charges from paid APIs`,plainDescription:`Blocks AI from calling APIs that can rack up unexpected bills — cloud storage, AI providers, payment services.`,example:`A call to OpenAI, AWS S3, or Stripe triggers a block until you allow it.`,hubRulesetId:`no-paid-apis`,scenario:`any`,emoji:`💳`,details:{protects:[`Asks first before calls to paid LLM APIs — OpenAI, Anthropic, Groq, Bedrock, and more`,`Asks first before payment APIs — Stripe, PayPal, Square, Adyen`,`Asks first before SMS / voice APIs — Twilio, Vonage, MessageBird`,`Asks first before cloud-storage writes — aws s3 cp/sync, gsutil, az storage`],tryThis:`Ask your AI to call the OpenAI API. It checks with you before sending — so a runaway loop cannot quietly rack up spend.`}},{id:`read-only-mode`,title:`Read-only mode (maximum safety)`,plainDescription:`AI can look but not touch — all write operations are blocked. Great when you just want to explore safely.`,example:`AI can read your codebase and answer questions but cannot change any files.`,hubRulesetId:`read-only`,scenario:`any`,emoji:`🔒`,details:{protects:[`Blocks every file write and edit`,`Blocks state-changing shell commands — file deletes & moves, package installs, sudo, docker, kubectl, terraform`,`Blocks shell redirection that writes to disk`,`Blocks git commands that change state — commit, push, reset, checkout`,`Blocks network requests that are not GET — no POST, PUT, PATCH, DELETE`],tryThis:`Ask your AI to edit any file. Every write is refused until you remove this pack — but reading code and answering questions still works.`}}];function Sd(e){return e?xd.filter(t=>t.scenario===`any`||t.scenario===e):xd}function Cd({pack:e,installed:t,state:n,expanded:r,onInstall:i,onUninstall:a,onToggleDetails:o}){let s=n!==`idle`;return(0,D.jsxs)(`div`,{className:`ss-list-row ss-list-row--pack`,style:{cursor:`default`,background:t?`linear-gradient(180deg, color-mix(in oklab, var(--color-hig-green) 8%, transparent) 0%, transparent 60%), var(--color-surface-1)`:`var(--color-surface-1)`,borderColor:t?`color-mix(in oklab, var(--color-hig-green) 28%, var(--color-line-1))`:`var(--color-line-1)`},children:[(0,D.jsxs)(`div`,{className:`ss-pack-main`,children:[(0,D.jsx)(`span`,{className:`ss-pack-emoji`,"aria-hidden":`true`,children:e.emoji}),(0,D.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,D.jsx)(`h3`,{className:`ss-pack-title`,children:e.title}),t&&(0,D.jsxs)(`span`,{className:`agent-badge agent-badge--detected`,title:`This pack is currently active.`,children:[(0,D.jsx)(`span`,{className:`agent-badge-dot`}),`Installed`]})]}),(0,D.jsx)(`p`,{className:`ss-pack-desc`,children:e.plainDescription}),(0,D.jsxs)(`p`,{className:`ss-pack-example`,children:[(0,D.jsx)(`span`,{className:`ss-pack-example__label`,children:`Example`}),e.example]}),(0,D.jsx)(`button`,{type:`button`,className:`ss-pack-detail-toggle`,"aria-expanded":r,onClick:()=>o(e.id),children:r?`Hide details`:t?`What this is doing →`:`What's inside →`})]}),(0,D.jsx)(`div`,{className:`ss-pack-action`,children:t?(0,D.jsx)(`button`,{type:`button`,disabled:s,onClick:()=>a(e.id),className:`ss-btn ss-btn--secondary`,style:{height:30,padding:`0 12px`,fontSize:11},title:`Remove this pack from your machine.`,children:n===`uninstalling`?`Removing…`:`Remove`}):(0,D.jsx)(`button`,{type:`button`,disabled:s,onClick:()=>i(e.id),className:`ss-btn ss-btn--primary`,style:{height:30,padding:`0 14px`,fontSize:11},title:`Install this guardrail pack.`,children:n===`installing`?`Installing…`:`Install`})})]}),r&&(0,D.jsxs)(`div`,{className:`ss-pack-detail`,children:[(0,D.jsxs)(`div`,{className:`ss-pack-detail__section`,children:[(0,D.jsx)(`span`,{className:`ss-pack-detail__label`,children:t?`Installed`:`What gets installed`}),(0,D.jsxs)(`p`,{className:`ss-pack-detail__text`,children:[(0,D.jsxs)(`code`,{children:[e.hubRulesetId,`.rules`]}),` — one plain-text rules file`,t?` now living in `:`, written to `,`your `,(0,D.jsx)(`code`,{children:`.sigmashake/rules/`}),` folder.`,` `,t?`It's active right away — no restart needed.`:`Installing adds just this one file; removing the pack deletes it.`]})]}),(0,D.jsxs)(`div`,{className:`ss-pack-detail__section`,children:[(0,D.jsx)(`span`,{className:`ss-pack-detail__label`,children:`What it does`}),(0,D.jsx)(`ul`,{className:`ss-pack-detail__list`,children:e.details.protects.map(e=>(0,D.jsx)(`li`,{children:e},e))})]}),(0,D.jsxs)(`div`,{className:`ss-pack-detail__section`,children:[(0,D.jsx)(`span`,{className:`ss-pack-detail__label`,children:`See it working`}),(0,D.jsx)(`p`,{className:`ss-pack-detail__text`,children:e.details.tryThis}),(0,D.jsxs)(`p`,{className:`ss-pack-detail__hint`,children:[`Every block and approval prompt is logged on the`,` `,(0,D.jsx)(`a`,{href:`/audit`,children:`Activity`}),` page. To fire a rule on purpose without leaving the dashboard, open `,(0,D.jsx)(`a`,{href:`/try`,children:`Try It`}),`.`]})]})]})]})}function wd(){let e=new URLSearchParams(window.location.search).get(`starter`),t=Sd(e),[n,r]=(0,_.useState)(new Set),[i,a]=(0,_.useState)({}),[o,s]=(0,_.useState)(new Set),[c,l]=(0,_.useState)(null);function u(e){s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}(0,_.useEffect)(()=>{let e=!1;return fetch(`/api/json/hub/installed`).then(e=>e.json()).then(t=>{e||r(new Set(t.installed))}).catch(()=>{}),()=>{e=!0}},[]);function d(e,t){l({msg:e,type:t}),setTimeout(()=>l(null),5e3)}async function f(){try{let e=await(await fetch(`/api/json/hub/installed`)).json();r(new Set(e.installed))}catch{}}async function p(e){let t=xd.find(t=>t.id===e);if(t){a(t=>({...t,[e]:`installing`}));try{let n=await fetch(`/api/hub/install`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`,...U()},body:JSON.stringify({id:t.hubRulesetId})}),i=await n.text(),a=n.headers.get(`Content-Type`)??``,o=null;if(a.includes(`application/json`))try{o=JSON.parse(i)}catch{}o?.ok?(r(e=>new Set([...e,t.hubRulesetId])),s(t=>new Set([...t,e])),d(o.already_installed?`${t.title} — already installed`:`${t.title} — installed`,`ok`)):d(o?o.error??`Could not install ${t.title}`:i.replace(/<[^>]+>/g,``).trim()||`Could not install ${t.title} (HTTP ${n.status})`,`error`)}catch(e){d(`Could not reach the dashboard server (${e instanceof Error?e.message:String(e)})`,`error`)}finally{a(t=>({...t,[e]:`idle`})),f()}}}async function m(e){let t=xd.find(t=>t.id===e);if(t&&window.confirm(`Remove “${t.title}”?\n\nThe rules in this pack stop applying. You can install it again any time.`)){a(t=>({...t,[e]:`uninstalling`}));try{let e=await fetch(`/api/hub/uninstall`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`,...U()},body:JSON.stringify({id:t.hubRulesetId})}),n=await e.text(),i=e.headers.get(`Content-Type`)??``,a=null;if(i.includes(`application/json`))try{a=JSON.parse(n)}catch{}a?.ok||e.ok&&!a?(r(e=>{let n=new Set(e);return n.delete(t.hubRulesetId),n}),d(`${t.title} — removed`,`ok`)):d(a?a.error??`Could not remove ${t.title}`:n.replace(/<[^>]+>/g,``).trim()||`Could not remove ${t.title} (HTTP ${e.status})`,`error`)}catch(e){d(`Could not reach the dashboard server (${e instanceof Error?e.message:String(e)})`,`error`)}finally{a(t=>({...t,[e]:`idle`})),f()}}}let h={coding:`for coding with AI`,"knowledge-work":`for email and docs`},g=t.filter(e=>n.has(e.hubRulesetId)).length;return(0,D.jsxs)(`div`,{className:`max-w-3xl mx-auto space-y-6`,children:[(0,D.jsxs)(`section`,{"data-tutorial":`guard-hero`,className:`rounded-2xl p-5`,style:{border:`1px solid var(--color-line-1)`,background:`var(--color-surface-1)`},children:[(0,D.jsx)(`p`,{className:`ss-list-section-title`,style:{padding:0,marginBottom:8},children:`Guardrails`}),(0,D.jsxs)(`h1`,{className:`text-[18px] font-semibold text-[var(--color-fg-0)] tracking-tight`,children:[`One-tap protection`,e&&h[e]?` ${h[e]}`:``]}),(0,D.jsxs)(`p`,{className:`text-[12.5px] text-[var(--color-fg-2)] mt-1.5 leading-relaxed`,children:[`Each pack is a small set of rules that guard against a specific AI risk. Toggle them on and off — installing or removing only touches rule files in`,` `,(0,D.jsx)(`code`,{className:`text-[var(--color-brand)]`,children:`.sigmashake/`}),`.`]}),(0,D.jsxs)(`p`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] mt-3`,children:[g,` of `,t.length,` active`]})]}),c&&(0,D.jsx)(`div`,{className:`rounded-xl px-4 py-2.5 text-[12px]`,style:{border:`1px solid ${c.type===`ok`?`color-mix(in oklab, var(--color-hig-green) 36%, transparent)`:`color-mix(in oklab, var(--color-hig-red) 36%, transparent)`}`,background:c.type===`ok`?`color-mix(in oklab, var(--color-hig-green) 12%, var(--color-surface-1))`:`color-mix(in oklab, var(--color-hig-red) 12%, var(--color-surface-1))`,color:c.type===`ok`?`var(--color-hig-green)`:`var(--color-hig-red)`,backdropFilter:`saturate(180%) blur(10px)`},children:c.msg}),(0,D.jsx)(`div`,{"data-tutorial":`guard-packs`,className:`ss-list`,children:t.map(e=>(0,D.jsx)(Cd,{pack:e,installed:n.has(e.hubRulesetId),state:i[e.id]??`idle`,expanded:o.has(e.id),onInstall:p,onUninstall:m,onToggleDetails:u},e.id))}),(0,D.jsx)(`div`,{"data-tutorial":`guard-advanced`,className:`rounded-xl p-4`,style:{border:`1px dashed var(--color-line-1)`,background:`color-mix(in oklab, var(--color-surface-1) 50%, transparent)`},children:(0,D.jsxs)(`p`,{className:`text-[12px] text-[var(--color-fg-2)] leading-relaxed`,children:[`Want more control? The`,` `,(0,D.jsx)(`a`,{href:`/hub`,className:`text-[var(--color-brand)] hover:underline`,children:`advanced library`}),` `,`has the full set of community rulesets and lets you preview every rule before installing.`]})})]})}function Td(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Ed(e){let t=e;if(t.endsWith(`/.sigmashake/rules`)&&(t=t.slice(0,-18)),t.endsWith(`\\.sigmashake\\rules`)&&(t=t.slice(0,-18)),t.startsWith(`/home/`)){let e=t.slice(6),n=e.indexOf(`/`);return n>=0?`~/${e.slice(n+1)}`:`~`}if(t.startsWith(`C:\\Users\\`)){let e=t.slice(9),n=e.indexOf(`\\`);return n>=0?`~\\${e.slice(n+1)}`:`~`}if(t.length>40){let e=t.split(/[/\\]/);if(e.length>2)return`…/${e[e.length-1]}`}return t}var Dd=[{value:`downloads`,label:`most downloaded`},{value:`newest`,label:`newest`},{value:`rules`,label:`most rules`}],Od=[``,`critical`,`high`,`medium`,`low`],kd=[``,`deny`,`ask`,`allow`,`log`];function Ad(){return(0,D.jsxs)(`div`,{className:`rounded-sm border border-[var(--color-line-0)] bg-[var(--color-surface-1)] p-4 space-y-3 shimmer`,children:[(0,D.jsx)(`div`,{className:`h-4 bg-[var(--color-surface-3)] rounded-sm w-2/3`}),(0,D.jsx)(`div`,{className:`h-3 bg-[var(--color-surface-2)] rounded-sm w-1/3`}),(0,D.jsxs)(`div`,{className:`flex gap-1.5`,children:[(0,D.jsx)(`div`,{className:`h-5 bg-[var(--color-surface-3)] rounded-sm w-14`}),(0,D.jsx)(`div`,{className:`h-5 bg-[var(--color-surface-3)] rounded-sm w-10`})]}),(0,D.jsx)(`div`,{className:`h-7 bg-[var(--color-surface-3)] rounded-sm`})]})}function jd({tech:e}){return(0,D.jsx)(`span`,{className:`inline-flex items-center px-1.5 py-0.5 rounded-sm text-[10px] font-mono uppercase tracking-wider border ${{typescript:`bg-sky-500/8 text-sky-300 border-sky-500/25`,ts:`bg-sky-500/8 text-sky-300 border-sky-500/25`,javascript:`bg-amber-500/8 text-amber-300 border-amber-500/25`,js:`bg-amber-500/8 text-amber-300 border-amber-500/25`,python:`bg-emerald-500/8 text-emerald-300 border-emerald-500/25`,rust:`bg-orange-500/8 text-orange-300 border-orange-500/25`,go:`bg-cyan-500/8 text-cyan-300 border-cyan-500/25`,bash:`bg-violet-500/8 text-violet-300 border-violet-500/25`}[e.toLowerCase()]??`bg-[var(--color-surface-2)] text-[var(--color-fg-3)] border-[var(--color-line-1)]`}`,children:e})}function Md({install:e,onRemove:t,removing:n}){let r=Ed(e.path),i=e.in_sync?`bg-emerald-400`:`bg-amber-400 animate-pulse`;return(0,D.jsxs)(`div`,{className:`group/chip inline-flex items-center gap-1.5 max-w-full pl-1.5 pr-0.5 py-0.5 rounded-sm bg-[var(--color-surface-2)] border border-[var(--color-line-1)] text-[10px] font-mono text-[var(--color-fg-2)]`,title:e.in_sync?`In sync — files present in ${e.path}`:`Drift — ${e.drift_reason??`files missing or empty`} (${e.path})`,children:[(0,D.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 ${i}`,"aria-hidden":!0}),(0,D.jsx)(`span`,{className:`truncate`,title:e.path,children:r}),(0,D.jsx)(`button`,{type:`button`,onClick:r=>{r.preventDefault(),r.stopPropagation(),n||t(e.path)},disabled:n,title:`Remove from this location`,"aria-label":`Uninstall from ${e.path}`,className:`shrink-0 inline-flex items-center justify-center w-4 h-4 rounded-sm text-[var(--color-fg-4)] hover:text-red-300 hover:bg-red-500/10 transition-colors cursor-pointer disabled:opacity-40 disabled:cursor-not-allowed`,children:n?(0,D.jsx)(`svg`,{className:`animate-spin`,width:`9`,height:`9`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,D.jsx)(`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`})}):(0,D.jsxs)(`svg`,{width:`9`,height:`9`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`3`,children:[(0,D.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,D.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})})]})}function Nd({isInstalling:e,hasInstalls:t,onInstallDefault:n,onPickPath:r}){let[i,a]=(0,_.useState)(!1),o=(0,_.useRef)(null);return(0,_.useEffect)(()=>{if(!i)return;function e(e){o.current&&(o.current.contains(e.target)||a(!1))}return document.addEventListener(`mousedown`,e),()=>document.removeEventListener(`mousedown`,e)},[i]),(0,D.jsxs)(`div`,{ref:o,className:`relative flex w-full`,children:[(0,D.jsx)(`button`,{onClick:e=>{e.preventDefault(),e.stopPropagation(),n()},disabled:e,className:`flex-1 h-7 rounded-l-sm text-[11px] font-mono uppercase tracking-wider transition-colors cursor-pointer
16
16
  bg-[var(--color-brand)]/8 text-[var(--color-brand)] border border-[var(--color-brand)]/30 border-r-0
17
17
  hover:bg-[var(--color-brand)]/15 hover:border-[var(--color-brand)]/50
18
18
  disabled:opacity-40 disabled:cursor-not-allowed`,children:e?(0,D.jsxs)(`span`,{className:`flex items-center justify-center gap-1.5`,children:[(0,D.jsx)(`svg`,{className:`animate-spin`,width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,D.jsx)(`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`})}),`installing…`]}):t?`install elsewhere`:`install`}),(0,D.jsx)(`button`,{type:`button`,onClick:e=>{e.preventDefault(),e.stopPropagation(),a(e=>!e)},disabled:e,title:`Install to another folder`,"aria-label":`Install to a custom folder`,className:`shrink-0 w-7 h-7 rounded-r-sm flex items-center justify-center cursor-pointer
@@ -25,7 +25,7 @@ Error generating stack: `+e.message+`
25
25
  ${O.type===`ok`?`bg-emerald-500/5 border-emerald-500/25 text-emerald-300`:`bg-red-500/5 border-red-500/25 text-red-300`}`,children:[(0,D.jsxs)(`span`,{children:[O.type===`ok`?`✓ `:`✗ `,O.msg]}),(0,D.jsx)(`button`,{onClick:()=>k(null),className:`ml-3 opacity-60 hover:opacity-100 cursor-pointer`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,D.jsxs)(`div`,{"data-tutorial":`hub-tabs`,className:`flex items-center bg-[var(--color-surface-1)] border border-[var(--color-line-1)] rounded-sm p-0.5 shrink-0`,children:[(0,D.jsx)(`button`,{onClick:()=>l(`all`),className:`px-3 h-6 rounded-sm text-[11px] font-mono uppercase tracking-wider transition-colors cursor-pointer
26
26
  ${c===`all`?`bg-[var(--color-surface-3)] text-[var(--color-fg-0)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,children:`all`}),(0,D.jsxs)(`button`,{onClick:()=>l(`installed`),className:`px-3 h-6 rounded-sm text-[11px] font-mono uppercase tracking-wider transition-colors cursor-pointer flex items-center gap-1.5
27
27
  ${c===`installed`?`bg-[var(--color-surface-3)] text-[var(--color-fg-0)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,children:[`installed`,ne>0&&(0,D.jsx)(`span`,{className:`text-[9px] bg-emerald-500/15 text-emerald-300 rounded-sm px-1 py-0.5 font-medium tabular-nums`,children:ne})]})]}),(0,D.jsxs)(`div`,{className:`relative flex-1 min-w-[160px]`,children:[(0,D.jsxs)(`svg`,{className:`absolute left-2.5 top-1/2 -translate-y-1/2 text-[var(--color-fg-4)]`,width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[(0,D.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,D.jsx)(`line`,{x1:`21`,y1:`21`,x2:`16.65`,y2:`16.65`})]}),(0,D.jsx)(`input`,{"data-tutorial":`hub-search`,type:`text`,placeholder:`search rulesets…`,value:e,onChange:e=>t(e.target.value),className:`w-full bg-[var(--color-surface-1)] border border-[var(--color-line-1)] text-[var(--color-fg-1)] text-xs rounded-sm pl-8 pr-3 h-8 focus:outline-none focus:border-[var(--color-brand)]/50 placeholder:text-[var(--color-fg-4)] font-mono`})]}),(0,D.jsx)(`select`,{value:n,onChange:e=>r(e.target.value),className:re,children:Dd.map(e=>(0,D.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,D.jsxs)(`select`,{"data-tutorial":`hub-filters`,value:i,onChange:e=>a(e.target.value),className:re,children:[(0,D.jsx)(`option`,{value:``,children:`any decision`}),kd.filter(Boolean).map(e=>(0,D.jsx)(`option`,{value:e,children:e},e))]}),(0,D.jsxs)(`select`,{value:o,onChange:e=>s(e.target.value),className:re,children:[(0,D.jsx)(`option`,{value:``,children:`any severity`}),Od.filter(Boolean).map(e=>(0,D.jsx)(`option`,{value:e,children:e},e))]})]}),g&&u.length===0?(0,D.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:Array.from({length:6}).map((e,t)=>(0,D.jsx)(Ad,{},t))}):I.length===0?(0,D.jsxs)(`div`,{className:`rounded-sm border border-dashed border-[var(--color-line-1)] py-16 flex flex-col items-center justify-center text-center`,children:[(0,D.jsxs)(`svg`,{className:`text-[var(--color-fg-4)] mb-3`,width:`36`,height:`36`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.5`,children:[(0,D.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,D.jsx)(`line`,{x1:`21`,y1:`21`,x2:`16.65`,y2:`16.65`})]}),(0,D.jsx)(`p`,{className:`text-xs font-mono text-[var(--color-fg-3)] uppercase tracking-wider`,children:c===`installed`?`no rulesets installed yet — browse and click install`:`no rulesets found${e?` matching "${e}"`:``}`})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{"data-tutorial":`hub-grid`,className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:I.map(e=>(0,D.jsx)(Pd,{rs:e,installs:y[e.id]??[],installingId:x,uninstallingKey:C,onInstall:N,onUninstall:F,onPickAndInstall:P,flashId:T},e.id))}),f&&c===`all`&&(0,D.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,D.jsx)(`button`,{onClick:j,disabled:g,className:`h-8 px-5 rounded-sm text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-2)] border border-[var(--color-line-1)] hover:text-[var(--color-fg-0)] hover:border-[var(--color-line-2)] transition-colors cursor-pointer disabled:opacity-40`,children:g?`loading…`:`load more`})})]})]})}function Ld(){let[e,t]=(0,_.useState)(``),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(null);async function o(t){if(t.preventDefault(),e.trim()){r(!0),a(null);try{a(await(await fetch(`/api/hub/publish`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({repo_url:e.trim()})})).json())}catch(e){a({ok:!1,error:e instanceof Error?e.message:`Unknown error`})}finally{r(!1)}}}return(0,D.jsxs)(`div`,{className:`max-w-md mx-auto space-y-5`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`a`,{href:`/hub`,className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-brand)]`,children:`← hub`}),(0,D.jsx)(`h1`,{className:`text-xl font-medium tracking-tight mt-2 text-[var(--color-fg-0)]`,children:`Publish Ruleset`}),(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-3)] mt-1 font-mono`,children:`publish a github repository containing .rules files to the hub`})]}),(0,D.jsx)(K,{children:(0,D.jsx)(J,{children:(0,D.jsxs)(`form`,{onSubmit:o,className:`space-y-4`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:`block overline mb-1.5`,children:`github repository url`}),(0,D.jsx)(`input`,{"data-tutorial":`hubpub-input`,type:`url`,placeholder:`https://github.com/owner/repo`,value:e,onChange:e=>t(e.target.value),required:!0,className:`w-full bg-[var(--color-surface-0)] border border-[var(--color-line-1)] text-[var(--color-fg-1)] text-sm rounded-sm px-3 py-2 focus:outline-none focus:border-[var(--color-brand)]/50 placeholder:text-[var(--color-fg-4)] font-mono`})]}),(0,D.jsx)(G,{type:`submit`,variant:`primary`,disabled:n,children:n?`publishing…`:`publish to hub`})]})})}),i&&(0,D.jsx)(`div`,{className:`rounded-sm border px-3 py-2 text-xs font-mono ${i.ok?`border-emerald-500/25 bg-emerald-500/5 text-emerald-300`:`border-red-500/25 bg-red-500/5 text-red-300`}`,children:i.ok?(0,D.jsxs)(D.Fragment,{children:[`✓ published!`,` `,i.id&&(0,D.jsx)(`a`,{href:`/hub/${i.id}`,className:`text-[var(--color-brand)] hover:underline uppercase tracking-wider text-[11px] ml-2`,children:`view ruleset →`})]}):i.error??`publish failed`})]})}function Rd(e){return e===0?`—`:e<1e3?`${e}ns`:e<1e6?`${(e/1e3).toFixed(1)}µs`:`${(e/1e6).toFixed(1)}ms`}function zd(e){let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${t%60}s`:`${Math.floor(n/60)}h ${n%60}m`}function Bd(e){let t=e<1e10?e*1e3:e,n=new Date(t);return`${String(n.getHours()).padStart(2,`0`)}:${String(n.getMinutes()).padStart(2,`0`)}:${String(n.getSeconds()).padStart(2,`0`)}`}function Vd(e){let t=Math.round((Date.now()-e)/1e3);if(t<5)return`just now`;if(t<60)return`${t}s ago`;let n=Math.floor(t/60);return n<60?`${n}m ago`:`${Math.floor(n/60)}h ago`}var Hd={allow:`text-emerald-300`,block:`text-red-300`,force:`text-violet-300`,log:`text-amber-300`,ask:`text-sky-300`,shadow:`text-[var(--color-fg-3)]`},Ud={allow:`✓`,block:`✗`,force:`→`,log:`·`,ask:`?`,shadow:`~`};function Wd({label:e,ns:t,maxNs:n}){let r=n>0?Math.min(100,t/n*100):0;return(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] w-8 text-right font-mono uppercase tracking-wider text-[10px]`,children:e}),(0,D.jsx)(Al,{pct:r,tone:t<1e5?`green`:t<1e6?`amber`:`red`,className:`h-1 flex-1`}),(0,D.jsx)(`span`,{className:`font-mono text-[var(--color-fg-1)] tabular-nums w-14 text-right`,children:Rd(t)})]})}function Gd({value:e,max:t,threshold:n,breached:r}){let i=t>0?Math.min(100,e/t*100):0,a=t>0?Math.min(100,n/t*100):0;return(0,D.jsx)(Al,{pct:i,tone:r?`red`:e/t>=.6?`amber`:`green`,markerPct:a,markerTitle:`limit: ${n}`,className:`h-1`})}function Kd({limitsData:e,onSaved:t}){let[n,r]=(0,_.useState)(String(e.config.cpuLimitPct)),[i,a]=(0,_.useState)(String(e.config.memoryLimitMb)),[o,s]=(0,_.useState)(e.config.breachAction),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(null);async function f(){l(!0),d(null);try{let e=await fetch(`/api/json/limits`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({cpu_limit_pct:parseFloat(n),memory_limit_mb:parseFloat(i),breach_action:o})});e.ok?t():d((await e.json()).error??`save failed`)}catch{d(`network error`)}finally{l(!1)}}let p=`w-full bg-[var(--color-surface-0)] border border-[var(--color-line-1)] rounded-sm px-2 py-1.5 text-[var(--color-fg-1)] font-mono text-xs focus:outline-none focus:border-[var(--color-brand)]/50`;return(0,D.jsxs)(`div`,{className:`space-y-3`,children:[(0,D.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:`overline block mb-1.5`,children:`cpu limit (%)`}),(0,D.jsx)(`input`,{type:`number`,min:1,max:100,value:n,onChange:e=>r(e.target.value),className:p})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:`overline block mb-1.5`,children:`memory limit (mb)`}),(0,D.jsx)(`input`,{type:`number`,min:1,value:i,onChange:e=>a(e.target.value),className:p})]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:`overline block mb-1.5`,children:`on breach`}),(0,D.jsxs)(`select`,{value:o,onChange:e=>s(e.target.value),className:p,children:[(0,D.jsx)(`option`,{value:`warn`,children:`warn in ui only`}),(0,D.jsx)(`option`,{value:`log`,children:`warn + write to audit log`})]})]}),u&&(0,D.jsx)(`p`,{className:`text-xs text-red-300 font-mono`,children:u}),(0,D.jsx)(G,{onClick:f,disabled:c,variant:`primary`,size:`sm`,children:c?`saving…`:`save limits`})]})}var qd={running:`green`,hibernating:`amber`,exhausted:`red`,stopped:`gray`,idle:`gray`};function Jd(e,t){let n=e-t;if(n<=0)return`any moment`;let r=Math.round(n/1e3);if(r<60)return`in ${r}s`;let i=Math.floor(r/60);return i<60?`in ${i}m ${r%60}s`:`in ${Math.floor(i/60)}h ${i%60}m`}function Yd({supervisors:e}){let[t,n]=(0,_.useState)(Date.now());return(0,_.useEffect)(()=>{let e=setInterval(()=>n(Date.now()),1e3);return()=>clearInterval(e)},[]),(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsxs)(`span`,{className:`flex items-center gap-2 overline`,children:[`supervisor health`,e.some(e=>e.state===`hibernating`||e.state===`exhausted`)&&(0,D.jsx)(W,{variant:`amber`,children:`degraded`})]}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono tabular-nums text-[var(--color-fg-4)]`,children:[e.length,` supervisor`,e.length===1?``:`s`]})]}),(0,D.jsx)(J,{children:e.length===0?(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`no supervisors registered yet`}):(0,D.jsx)(`div`,{className:`overflow-x-auto`,children:(0,D.jsxs)(`table`,{className:`w-full text-xs font-mono`,children:[(0,D.jsx)(`thead`,{children:(0,D.jsxs)(`tr`,{className:`text-[10px] uppercase tracking-wider text-[var(--color-fg-4)]`,children:[(0,D.jsx)(`th`,{className:`text-left font-normal pb-1.5`,children:`name`}),(0,D.jsx)(`th`,{className:`text-left font-normal pb-1.5`,children:`kind`}),(0,D.jsx)(`th`,{className:`text-left font-normal pb-1.5`,children:`state`}),(0,D.jsx)(`th`,{className:`text-right font-normal pb-1.5`,children:`restarts`}),(0,D.jsx)(`th`,{className:`text-left font-normal pb-1.5 pl-4`,children:`last restart`}),(0,D.jsx)(`th`,{className:`text-left font-normal pb-1.5 pl-4`,children:`next retry`})]})}),(0,D.jsx)(`tbody`,{children:e.map(e=>(0,D.jsxs)(`tr`,{className:`border-t border-[var(--color-line-0)]`,children:[(0,D.jsx)(`td`,{className:`py-1.5 text-[var(--color-fg-1)]`,children:e.name}),(0,D.jsx)(`td`,{className:`py-1.5 text-[var(--color-fg-3)]`,children:e.kind===`single`?`single`:`tree`}),(0,D.jsx)(`td`,{className:`py-1.5`,children:(0,D.jsx)(W,{variant:qd[e.state],children:e.state})}),(0,D.jsx)(`td`,{className:`py-1.5 text-right tabular-nums text-[var(--color-fg-1)]`,children:e.restarts}),(0,D.jsx)(`td`,{className:`py-1.5 pl-4 tabular-nums text-[var(--color-fg-3)]`,children:e.lastRestartAt>0?Vd(e.lastRestartAt):`—`}),(0,D.jsx)(`td`,{className:`py-1.5 pl-4 tabular-nums text-[var(--color-fg-3)]`,children:e.nextRetryAt>0?(0,D.jsx)(`span`,{title:e.hibernateReason?`reason: ${e.hibernateReason}`:void 0,children:Jd(e.nextRetryAt,t)}):`—`})]},e.name))})]})})})]})}function Xd(){let e=V([`runtime-tick`,`activity-updated`,`limits-breach`,`supervisor-changed`]),t=Ji(),[n,r]=(0,_.useState)(Date.now()),[i,a]=(0,_.useState)(0),[o,s]=(0,_.useState)([]),[c,l]=(0,_.useState)(0),[u,d]=(0,_.useState)(!1),f=(0,_.useRef)(null);(0,_.useEffect)(()=>{let e=setInterval(()=>r(Date.now()),1e3);return()=>clearInterval(e)},[]);let{data:p}=k(`/api/state/runtime`,[e[`runtime-tick`]]),{data:m,refetch:h}=k(`/api/json/limits`,[e[`limits-breach`]]),{data:g}=k(`/api/state/activity-tail?after=${i}&limit=50`,[e[`activity-updated`]]),{data:v}=k(`/api/json/supervisors`,[e[`supervisor-changed`],e[`runtime-tick`]]);(0,_.useEffect)(()=>{g&&g.rows.length>0&&(a(e=>Math.max(e,g.maxId)),s(e=>{let t=new Set(e.map(e=>e.id));return[...g.rows.filter(e=>!t.has(e.id)),...e].slice(0,100)}))},[g]),(0,_.useEffect)(()=>{let e=p!==null;f.current===!1&&e&&l(e=>e+1),f.current=e},[p]);let y=p?zd(p.uptime_ms):null,b=p&&p.last_eval_at>0?Vd(p.last_eval_at):null,x=m?.breaches.cpu??!1,S=m?.breaches.memory??!1,C=p?x?`text-red-300`:(p.cpu_pct??0)>=60?`text-amber-300`:`text-emerald-300`:`text-[var(--color-fg-1)]`,w=S?`text-red-300`:`text-[var(--color-fg-1)]`;return(0,D.jsxs)(`div`,{className:`space-y-5`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h1`,{className:`text-xl font-medium tracking-tight text-[var(--color-fg-0)]`,children:`Daemon Monitor`}),(0,D.jsx)(`p`,{className:`text-[12px] font-mono text-[var(--color-fg-3)] mt-0.5`,children:`live metrics · audit tail · resource limits`})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[c>0&&(0,D.jsxs)(W,{variant:`amber`,children:[c,` restart`,c===1?``:`s`]}),(0,D.jsx)(`span`,{className:`text-[11px] font-mono tabular-nums text-[var(--color-fg-3)]`,children:Bd(n)})]})]}),(0,D.jsx)(Zd,{cpuPct:p?.cpu_pct??0,cpuLimit:m?.config.cpuLimitPct,memMb:p?.memory_rss_mb??0,memLimit:m?.config.memoryLimitMb,decisions:p?.decisions,latency:p?.latency,burstBuffer:t,evalsTotal:p?.evals_total??0}),m&&(x||S)&&(0,D.jsxs)(`div`,{className:`rounded-sm border border-red-500/25 bg-red-500/[0.06] border-l-2 border-l-red-500/70 px-3 py-2.5 flex items-start gap-2.5`,children:[(0,D.jsx)(`span`,{className:`text-red-300 shrink-0 mt-0.5`,children:(0,D.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[(0,D.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0Z`}),(0,D.jsx)(`line`,{x1:`12`,y1:`9`,x2:`12`,y2:`13`}),(0,D.jsx)(`line`,{x1:`12`,y1:`17`,x2:`12.01`,y2:`17`})]})}),(0,D.jsxs)(`div`,{className:`space-y-0.5 text-xs font-mono`,children:[x&&(0,D.jsxs)(`div`,{className:`text-red-200`,children:[`cpu limit exceeded: `,p?.cpu_pct??`?`,`% >`,` `,m.config.cpuLimitPct,`%`]}),S&&(0,D.jsxs)(`div`,{className:`text-red-200`,children:[`memory limit exceeded: `,p?.memory_rss_mb??`?`,`mb >`,` `,m.config.memoryLimitMb,`mb`]})]})]}),(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsx)(`span`,{className:`overline`,children:`daemon status`})}),(0,D.jsx)(J,{children:p===null?(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,D.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-red-500 shrink-0`}),(0,D.jsx)(`span`,{className:`text-red-300 font-mono uppercase tracking-wider text-xs`,children:`down`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] text-xs font-mono`,children:`— socket not reachable`})]}):(0,D.jsxs)(`div`,{className:`flex items-center gap-5 flex-wrap text-xs font-mono`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-emerald-400 pulse-soft shrink-0`}),(0,D.jsx)(`span`,{className:`text-emerald-300 uppercase tracking-wider`,children:`up`})]}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-3)]`,children:[`pid`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] tabular-nums`,children:p.pid})]}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-3)]`,children:[`uptime`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] tabular-nums`,children:y})]}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-3)]`,children:[`mem`,` `,(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-1)] tabular-nums`,children:[p.memory_rss_mb,`MB`]})]}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-3)]`,children:[`cpu`,` `,(0,D.jsxs)(`span`,{className:`${C} tabular-nums`,children:[p.cpu_pct,`%`]})]}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-3)]`,children:[`last eval`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] tabular-nums`,children:b??`—`})]})]})})]}),(0,D.jsx)(Yd,{supervisors:v?.supervisors??[]}),(0,D.jsxs)(K,{"data-tutorial":`monitor-resources`,children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsxs)(`span`,{className:`flex items-center gap-2 overline`,children:[`system resources`,m&&(x||S)&&(0,D.jsx)(W,{variant:`red`,children:`limit exceeded`})]}),(0,D.jsx)(`button`,{onClick:()=>d(e=>!e),className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-brand)] transition-colors cursor-pointer`,children:u?`hide limits`:`configure limits`})]}),(0,D.jsxs)(J,{children:[p===null?(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`no data — daemon not running`}):(0,D.jsxs)(`div`,{className:`space-y-5`,children:[(0,D.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`cpu`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(p.history.cpu_pct.length??0)>1&&(0,D.jsx)(Js,{data:p.history.cpu_pct,width:80,height:20,color:x?`#f87171`:`#34d399`,threshold:m?.config.cpuLimitPct,maxValue:100}),(0,D.jsxs)(`span`,{className:`font-mono font-medium w-12 text-right tabular-nums ${C}`,children:[p.cpu_pct,`%`]})]})]}),(0,D.jsx)(Gd,{value:p.cpu_pct,max:100,threshold:m?.config.cpuLimitPct??90,breached:x}),m&&(0,D.jsxs)(`div`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:[`limit: `,m.config.cpuLimitPct,`%`]})]}),(0,D.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`memory rss`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(p.history.memory_rss_mb.length??0)>1&&(0,D.jsx)(Js,{data:p.history.memory_rss_mb,width:80,height:20,color:S?`#f87171`:`#38bdf8`,threshold:m?.config.memoryLimitMb}),(0,D.jsxs)(`span`,{className:`font-mono font-medium w-16 text-right tabular-nums ${w}`,children:[p.memory_rss_mb,`MB`]})]})]}),(0,D.jsx)(Gd,{value:p.memory_rss_mb,max:Math.max(p.memory_rss_mb*1.5,m?.config.memoryLimitMb??512),threshold:m?.config.memoryLimitMb??512,breached:S}),m&&(0,D.jsxs)(`div`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:[`limit: `,m.config.memoryLimitMb,`MB`]})]}),(0,D.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`heap`}),(0,D.jsxs)(`span`,{className:`font-mono text-[var(--color-fg-1)] tabular-nums`,children:[p.heap_used_mb,`MB / `,p.heap_total_mb,`MB`]})]}),(0,D.jsx)(Al,{pct:p.heap_total_mb>0?Math.min(100,p.heap_used_mb/p.heap_total_mb*100):0,tone:`blue`,className:`h-1`})]})]}),u&&m&&(0,D.jsxs)(`div`,{className:`mt-5 pt-4 border-t border-[var(--color-line-0)]`,children:[(0,D.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)] mb-3 leading-relaxed`,children:[`thresholds trigger ui warnings. values are persisted to`,` `,(0,D.jsx)(`code`,{className:`text-[var(--color-fg-1)]`,children:`.sigmashake/config.toml`}),`.`]}),(0,D.jsx)(Kd,{limitsData:m,onSaved:()=>{h(),d(!1)}})]})]})]}),(0,D.jsxs)(`div`,{"data-tutorial":`monitor-counters`,className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-2`,children:[(0,D.jsx)(kl,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)]`,labelPlacement:`above`,label:`total evals`,value:p?.evals_total??`—`,valueClassName:`text-xl font-medium tabular-nums text-[var(--color-fg-0)]`}),(0,D.jsx)(kl,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)]`,labelPlacement:`above`,label:`allow`,value:p?.decisions.allow??`—`,valueClassName:`text-xl font-medium tabular-nums text-emerald-300`}),(0,D.jsx)(kl,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)]`,labelPlacement:`above`,label:`block`,value:p?.decisions.block??`—`,valueClassName:`text-xl font-medium tabular-nums text-red-300`}),(0,D.jsx)(kl,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)]`,labelPlacement:`above`,label:`force`,value:p?.decisions.force??`—`,valueClassName:`text-xl font-medium tabular-nums text-violet-300`}),(0,D.jsx)(kl,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)]`,labelPlacement:`above`,label:`log`,value:p?.decisions.log??`—`,valueClassName:`text-xl font-medium tabular-nums text-amber-300`}),(0,D.jsx)(kl,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)]`,labelPlacement:`above`,label:`ask`,value:p?.decisions.ask??`—`,valueClassName:`text-xl font-medium tabular-nums text-sky-300`})]}),(0,D.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`eval latency`}),p&&(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)] tabular-nums`,children:[p.latency.samples,` samples`]})]}),(0,D.jsx)(J,{children:p===null?(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`no data`}):(0,D.jsxs)(`div`,{className:`space-y-2`,children:[(0,D.jsx)(Wd,{label:`p50`,ns:p.latency.p50_ns,maxNs:p.latency.max_ns}),(0,D.jsx)(Wd,{label:`p95`,ns:p.latency.p95_ns,maxNs:p.latency.max_ns}),(0,D.jsx)(Wd,{label:`p99`,ns:p.latency.p99_ns,maxNs:p.latency.max_ns}),(0,D.jsx)(Wd,{label:`max`,ns:p.latency.max_ns,maxNs:p.latency.max_ns})]})})]}),(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsx)(`span`,{className:`overline`,children:`engine`})}),(0,D.jsx)(J,{children:p===null?(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`no data`}):(0,D.jsx)(`div`,{className:`space-y-1.5 text-xs font-mono`,children:[[`native evals`,p.engine.native_evals],[`ts evals`,p.engine.ts_evals],[`native %`,`${p.engine.native_pct}%`],[`rule reloads`,p.rule_reloads],[`rate limit trips`,p.rate_limit_trips],[`loop guard blocks`,p.loop_guard_blocks],[`connection errors`,p.connection_errors]].map(([e,t])=>(0,D.jsxs)(`div`,{className:`flex justify-between py-0.5 border-b border-[var(--color-line-0)] last:border-0`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)]`,children:e}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] tabular-nums`,children:t})]},e))})})]})]}),(0,D.jsxs)(K,{"data-tutorial":`monitor-tail`,children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`live event tail`}),(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:`newest first · auto-updating`})]}),(0,D.jsx)(J,{children:o.length===0?(0,D.jsx)(`div`,{className:`rounded-sm border border-dashed border-[var(--color-line-1)] bg-[var(--color-surface-0)] px-4 py-6 text-center`,children:(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`no events yet`})}):(0,D.jsx)(`div`,{className:`font-mono text-[11px] max-h-96 overflow-y-auto divide-y divide-[var(--color-line-0)]`,children:o.map(e=>(0,D.jsxs)(`div`,{className:`flex items-center gap-2 py-1`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] shrink-0 w-16 tabular-nums`,children:Bd(e.timestamp)}),e.tool===`__daemon`?(0,D.jsxs)(`span`,{className:`text-sky-400`,children:[`daemon `,(()=>{try{let t=JSON.parse(e.input??`{}`);return`${t.event??e.decision}${t.detail?` (${t.detail})`:``}`}catch{return e.decision}})()]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`span`,{className:`shrink-0 w-16 uppercase tracking-wider text-[10px] ${Hd[e.decision]??`text-[var(--color-fg-3)]`}`,children:[Ud[e.decision]??`·`,` `,e.decision]}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] shrink-0 w-24 truncate`,children:e.tool}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] shrink-0 w-14 text-right tabular-nums`,children:Rd(e.duration_ns)}),e.rule_id&&(0,D.jsx)(`a`,{href:`/rules?highlight=${encodeURIComponent(e.rule_id)}`,className:`text-[var(--color-brand)]/80 hover:text-[var(--color-brand)] truncate transition-colors`,title:e.rule_id,children:e.rule_id})]})]},e.id))})})]}),(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsx)(`span`,{className:`overline`,children:`ai agent debug endpoints`})}),(0,D.jsxs)(J,{children:[(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)] mb-2.5`,children:`agents can query these endpoints directly for automated triage:`}),(0,D.jsx)(`div`,{className:`space-y-1 font-mono text-[11px]`,children:[[`/api/state/runtime`,`full metrics snapshot (cpu, memory, history, latency)`],[`/api/json/limits`,`resource limits config + breach state`],[`/api/state/activity-tail?after=0&limit=20`,`recent eval events`],[`/api/json/daemon-status`,`status, pid, log tail`],[`/healthz`,`process uptime`]].map(([e,t])=>(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`GET`}),(0,D.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`text-[var(--color-brand)]/80 hover:text-[var(--color-brand)] transition-colors`,children:e}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)]`,children:[`— `,t]})]},e))})]})]})]})}function Zd({cpuPct:e,cpuLimit:t,memMb:n,memLimit:r,decisions:i,latency:a,evalsTotal:o,burstBuffer:s}){let c=(0,_.useMemo)(()=>{if(s.length===0)return 0;let e=Date.now()-1e4;return s.filter(t=>t.ts_ms>=e).length/10},[s]);return(a?.p95_ns??0)/1e6,(a?.p50_ns??0)/1e6,(a?.p99_ns??0)/1e6,(0,D.jsxs)(`div`,{className:`grid-bleed rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3`,style:{contain:`layout paint`},children:[(0,D.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-12 gap-4 lg:min-h-[320px]`,children:[(0,D.jsxs)(`div`,{className:`lg:col-span-3 flex flex-col items-center justify-start gap-2 lg:max-h-[320px]`,children:[(0,D.jsx)(Cc,{mode:`ring`,value:e,max:100,warnAt:(t??90)/100*.7,critAt:(t??90)/100,display:`${e.toFixed(1)}%`,label:`cpu`,size:220,className:`max-h-[240px]`}),(0,D.jsx)(Xs,{value:e,width:260,height:56,windowMs:6e4,color:`#34d399`,fillColor:`rgba(52, 211, 153, 0.14)`,maxValue:100,className:`w-full`})]}),(0,D.jsxs)(`div`,{className:`lg:col-span-3 flex flex-col items-center justify-start gap-2 lg:max-h-[320px]`,children:[(0,D.jsx)(Cc,{mode:`ring`,value:n,max:r??1024,warnAt:.7,critAt:.9,display:`${n.toFixed(0)} MB`,label:`memory`,size:220,className:`max-h-[240px]`}),(0,D.jsx)(Xs,{value:n,width:260,height:56,windowMs:6e4,color:`#38bdf8`,fillColor:`rgba(56, 189, 248, 0.14)`,maxValue:r?r*1.1:void 0,className:`w-full`})]}),(0,D.jsx)(`div`,{className:`lg:col-span-6 lg:max-h-[320px]`,children:(0,D.jsx)(Oc,{latency:a,bursts:s,gaugeMaxMs:10,windowMs:3e4,trendWindowSec:60,gaugeSize:200})})]}),(0,D.jsxs)(`div`,{className:`mt-4 grid grid-cols-1 lg:grid-cols-2 gap-3`,children:[(0,D.jsx)(ic,{label:`Total Evals`,value:o,tone:`amber`,sub:`${c.toFixed(1)}/s`,burstRing:s}),(0,D.jsxs)(`div`,{className:`flex flex-col gap-2 rounded-sm border bg-[var(--color-surface-1)] border-[var(--color-line-1)] px-4 py-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`throughput · 60 s`}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)] tabular-nums`,children:[c.toFixed(1),`/s`]})]}),(0,D.jsx)(Xs,{value:c,width:420,height:56,windowMs:6e4,className:`w-full`})]})]}),i?(0,D.jsx)(`div`,{className:`mt-4 pt-3 border-t border-[var(--color-line-0)]`,children:(0,D.jsx)(qs,{counters:{allow:i.allow,block:i.block,ask:i.ask,log:i.log,force:i.force,shadow:i.shadow}})}):null,(0,D.jsxs)(`div`,{className:`mt-4 pt-3 border-t border-[var(--color-line-0)]`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`live event stream · newest first`}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)]`,children:[s.length,` buffered · hover to pause`]})]}),(0,D.jsx)(Hc,{variant:`decision`,bursts:s,windowSize:300,height:260})]})]})}function Qd(){return(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h1`,{className:`text-[20px] font-semibold tracking-tight text-[var(--color-fg-0)] leading-tight`,children:`Notifications`}),(0,D.jsx)(`p`,{className:`text-[12.5px] text-[var(--color-fg-3)] mt-1 leading-relaxed`,children:`Things that need your attention — rule drift, audit log capacity, daemon health, noisy rules. We update this list whenever something changes.`})]}),(0,D.jsx)(`div`,{"data-tutorial":`notif-list`,children:(0,D.jsx)(Hs,{showEmptyState:!0,hideHeader:!0})})]})}var $d=18,ef=5e-4;function tf(e,t){return t===`(garbage collector)`||t===`(idle)`?`#450a0a`:e?e.startsWith(`node:`)||e.startsWith(`bun:`)?`#172554`:e.startsWith(`file:`)||e.startsWith(`/`)||e.includes(`.ts`)||e.includes(`.js`)?`#451a03`:`#1f2937`:`#1f2937`}function nf(e,t){return t===`(garbage collector)`||t===`(idle)`?`#fca5a5`:e?e.startsWith(`node:`)||e.startsWith(`bun:`)?`#93c5fd`:e.startsWith(`file:`)||e.startsWith(`/`)||e.includes(`.ts`)||e.includes(`.js`)?`#fbbf24`:`#6b7280`:`#6b7280`}function rf(e,t){let n=new Map;for(let t of e.nodes)n.set(t.id,t);let r=new Map;function i(e){let t=n.get(e);if(!t)return 0;let a=t.hitCount??0;for(let e of t.children??[])a+=i(e);return r.set(e,a),a}let a=e.nodes[0];if(!a)return[];i(a.id);let o=t??a.id,s=r.get(o)??0;if(s===0)return[];let c=[];function l(e,t,i){let a=n.get(e);if(!a)return;let o=r.get(e)??0,u=o/s;if(u<ef)return;c.push({x:i,width:u,depth:t,node:a,subtreeHits:o});let d=i;for(let e of a.children??[]){let n=(r.get(e)??0)/s;l(e,t+1,d),d+=n}}return l(o,0,0),c}function af(e){return e<1e3?`${e}µs`:e<1e6?`${(e/1e3).toFixed(1)}ms`:`${(e/1e6).toFixed(2)}s`}function of({profile:e}){let t=(0,_.useRef)(null),[n,r]=(0,_.useState)(800),[i,a]=(0,_.useState)(null),[o,s]=(0,_.useState)(null);(0,_.useEffect)(()=>{let e=t.current;if(!e)return;let n=new ResizeObserver(e=>{let t=e[0]?.contentRect.width;t&&r(t)});return n.observe(e),r(e.clientWidth||800),()=>n.disconnect()},[]);let c=rf(e,i),l=(c.reduce((e,t)=>Math.max(e,t.depth),0)+1)*$d+4,u=e.endTime-e.startTime,d=(0,_.useCallback)(e=>{a(t=>t===e.node.id?null:e.node.id),s(null)},[]);return c.length===0?(0,D.jsx)(`p`,{className:`text-xs text-[#555] py-2`,children:`No samples — profile may be empty.`}):(0,D.jsxs)(`div`,{className:`relative select-none`,children:[i!==null&&(0,D.jsx)(`button`,{onClick:()=>a(null),className:`mb-2 text-xs text-amber-400 hover:underline`,children:`← Reset zoom`}),(0,D.jsx)(`div`,{ref:t,className:`overflow-x-hidden`,children:(0,D.jsx)(`svg`,{width:n,height:l,onMouseLeave:()=>s(null),children:c.map((e,t)=>{let r=e.x*n,a=Math.max(e.width*n,1),o=e.depth*$d+1,c=e.node.callFrame.functionName||`(anonymous)`,l=e.node.callFrame.url,f=i===e.node.id;return(0,D.jsxs)(`g`,{children:[(0,D.jsx)(`rect`,{x:r,y:o,width:a,height:$d-1,fill:f?`#92400e`:tf(l,c),stroke:`#080808`,strokeWidth:.5,style:{cursor:`pointer`},onClick:()=>d(e),onMouseMove:t=>s({clientX:t.clientX,clientY:t.clientY,rect:e,totalDuration:u})}),a>24&&(0,D.jsx)(`text`,{x:r+2,y:o+$d-5,fontSize:9,fill:nf(l,c),style:{pointerEvents:`none`,userSelect:`none`},clipPath:`url(#fc-clip-${t})`,children:c}),a>24&&(0,D.jsx)(`clipPath`,{id:`fc-clip-${t}`,children:(0,D.jsx)(`rect`,{x:r,y:o,width:a,height:$d})})]},t)})})}),o&&(0,D.jsxs)(`div`,{className:`fixed z-50 bg-[#111] border border-[#2a2a2a] rounded-lg p-2.5 text-xs shadow-xl pointer-events-none`,style:{left:o.clientX+14,top:o.clientY-8,maxWidth:320},children:[(0,D.jsx)(`div`,{className:`font-mono text-amber-400 truncate font-medium`,children:o.rect.node.callFrame.functionName||`(anonymous)`}),o.rect.node.callFrame.url&&(0,D.jsxs)(`div`,{className:`text-[#666] truncate mt-0.5 text-[10px]`,children:[o.rect.node.callFrame.url,`:`,o.rect.node.callFrame.lineNumber]}),(0,D.jsxs)(`div`,{className:`mt-1.5 space-y-0.5 text-[#aaa]`,children:[(0,D.jsxs)(`div`,{children:[`Samples:`,` `,(0,D.jsx)(`span`,{className:`text-white tabular-nums`,children:o.rect.subtreeHits})]}),(0,D.jsxs)(`div`,{children:[`Time share:`,` `,(0,D.jsxs)(`span`,{className:`text-white tabular-nums`,children:[(o.rect.width*100).toFixed(1),`%`]})]}),u>0&&(0,D.jsxs)(`div`,{children:[`Est. duration:`,` `,(0,D.jsx)(`span`,{className:`text-white tabular-nums`,children:af(Math.round(o.rect.width*u))})]})]}),o.rect.node.deoptReason&&(0,D.jsxs)(`div`,{className:`text-red-400 mt-1.5 text-[10px]`,children:[`⚠ `,o.rect.node.deoptReason]}),(0,D.jsx)(`div`,{className:`text-[#555] mt-1.5 text-[10px]`,children:`Click to zoom · click again to reset`})]})]})}var sf={ok:`green`,warn:`amber`,error:`red`,unknown:`gray`},cf={ok:`OK`,warn:`Warn`,error:`Error`,unknown:`Idle`};function lf({title:e,status:t=`unknown`,statusLabel:n,className:r,children:i}){return(0,D.jsxs)(K,{className:In(`flex flex-col`,r),children:[(0,D.jsxs)(q,{children:[(0,D.jsx)(`span`,{className:`overline text-[var(--color-fg-2)]`,children:e}),(0,D.jsx)(W,{variant:sf[t],children:n??cf[t]})]}),(0,D.jsx)(J,{className:`flex flex-col gap-2 text-[12px]`,children:i})]})}function uf({label:e,value:t,mono:n=!1,tone:r}){return(0,D.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3 border-b border-[var(--color-line-0)] last:border-b-0 py-1`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] uppercase tracking-wider text-[10px] font-mono`,children:e}),(0,D.jsx)(`span`,{className:In(n?`font-mono`:`font-sans`,`tabular-nums text-right truncate`,r===`good`?`text-emerald-300`:r===`warn`?`text-amber-300`:r===`bad`?`text-red-300`:`text-[var(--color-fg-1)]`),children:t})]})}function df(){let{data:e,refetch:t}=k(`/api/json/inspector-targets`),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(null),c=(0,_.useRef)(null),l=(0,_.useRef)(1),u=(0,_.useRef)(new Map),d=(0,_.useRef)(new Map),f=(0,_.useCallback)(()=>{let e=c.current;if(c.current=null,e)try{e.close()}catch{}r(!1),a(!1),s(null)},[]),p=(0,_.useCallback)(e=>{c.current&&f(),a(!0),s(null);let t=new WebSocket(`/ws/inspector?target=${encodeURIComponent(e)}`);c.current=t,t.onopen=()=>{r(!0),a(!1),s(null)},t.onclose=()=>{c.current=null,r(!1),a(!1)},t.onerror=()=>{a(!1),s(`Connection failed — is the inspector running with the correct target ID?`)},t.onmessage=e=>{try{let t=JSON.parse(e.data);if(t.id!=null){let e=u.current.get(t.id);e&&(u.current.delete(t.id),e(t.result))}else if(t.method){let e=d.current.get(t.method);if(e)for(let n of e)n(t.params)}}catch{}}},[f]),m=(0,_.useCallback)((e,t)=>new Promise((n,r)=>{let i=c.current;if(!i||i.readyState!==WebSocket.OPEN){r(Error(`Not connected`));return}let a=l.current++;u.current.set(a,e=>n(e)),i.send(JSON.stringify({id:a,method:e,params:t})),setTimeout(()=>{u.current.has(a)&&(u.current.delete(a),r(Error(`Command timed out`)))},1e4)}),[]),h=(0,_.useCallback)((e,t)=>{let n=d.current.get(e);return n||(n=new Set,d.current.set(e,n)),n.add(t),()=>{d.current.get(e)?.delete(t)}},[]),g=(0,_.useRef)(!1);return(0,_.useEffect)(()=>{e?.active&&e?.target&&!n&&!i&&!g.current&&(g.current=!0,p(e.target.id))},[e?.active,e?.target?.id,n,i,p,e?.target]),(0,_.useEffect)(()=>()=>{f()},[f]),{active:e?.active??!1,bunVersion:e?.version?.[`Bun-Version`]??null,preconfiguredTarget:e?.target??null,connected:n,connecting:i,error:o,connect:p,disconnect:f,sendCommand:m,onEvent:h,refetch:t}}function ff(e){return e===0?`0 B`:e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:e<1024*1024*1024?`${(e/(1024*1024)).toFixed(2)} MB`:`${(e/(1024*1024*1024)).toFixed(2)} GB`}function pf(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/1024/1024).toFixed(1)}MB`}function mf(e){let t=Math.floor(e/1e3);if(t<60)return`${t}s`;let n=Math.floor(t/60);return n<60?`${n}m ${t%60}s`:`${Math.floor(n/60)}h ${n%60}m`}function hf(e){return e?new Date(e*1e3).toLocaleString():`—`}function gf(e){if(!e||e===0)return`never`;let t=Math.round((Date.now()-e)/1e3);if(t<5)return`just now`;if(t<60)return`${t}s ago`;let n=Math.floor(t/60);return n<60?`${n}m ago`:`${Math.floor(n/60)}h ago`}function _f({children:e,className:t}){return(0,D.jsx)(`div`,{className:`overline mb-2.5 ${t??``}`,children:e})}function vf({label:e,value:t,mono:n=!0,accent:r}){return(0,D.jsxs)(`div`,{className:`flex items-baseline justify-between gap-4 py-1.5 border-b border-[var(--color-line-0)] last:border-0`,children:[(0,D.jsx)(`span`,{className:`text-xs text-[var(--color-fg-3)] shrink-0 font-mono`,children:e}),(0,D.jsx)(`span`,{className:`text-xs text-right truncate max-w-[65%] ${n?`font-mono tabular-nums`:``} ${r??`text-[var(--color-fg-1)]`}`,children:t})]})}function yf({ok:e,label:t,badLabel:n}){return e?(0,D.jsx)(W,{variant:`green`,children:t}):(0,D.jsx)(W,{variant:`red`,children:n??t})}function bf({pct:e,total:t,max:n}){let r=e<60?`green`:e<85?`amber`:`red`,i=e>=85?`text-red-300`:e>=60?`text-amber-300`:`text-emerald-300`;return(0,D.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between text-xs font-mono tabular-nums`,children:[(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-3)]`,children:[t.toLocaleString(),` / `,n.toLocaleString(),` rows`]}),(0,D.jsxs)(`span`,{className:i,children:[e,`%`]})]}),(0,D.jsx)(Al,{pct:e,tone:r,className:`h-1.5`})]})}var xf=3e3,Sf={log:`text-[var(--color-fg-1)]`,info:`text-sky-300`,warn:`text-amber-300`,error:`text-red-300`,debug:`text-[var(--color-fg-3)]`};function Cf(e){return e.value==null?e.description?e.description:`[${e.type}]`:String(e.value)}function wf(){let e=df(),[t,n]=(0,_.useState)(!1),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(!1),[d,f]=(0,_.useState)(!1),p=(0,_.useRef)(null),m=(0,_.useRef)(0),h=(0,_.useRef)(!0);(0,_.useEffect)(()=>{if(h.current){h.current=!1;return}let e=p.current;if(!e)return;let t=e.parentElement;t&&(t.scrollTop=t.scrollHeight)},[]),(0,_.useEffect)(()=>{if(e.connected)return e.sendCommand(`Runtime.enable`).catch(()=>{}),e.onEvent(`Runtime.consoleAPICalled`,e=>{let t=e;o(e=>{let n=[...e,{id:m.current++,type:t.type??`log`,args:t.args??[],timestamp:t.timestamp??Date.now()}];return n.length>500?n.slice(-500):n})})},[e.connected,e.onEvent,e.sendCommand]),(0,_.useEffect)(()=>{e.preconfiguredTarget&&!e.connected&&!e.connecting&&e.connect(e.preconfiguredTarget.id)},[e]),(0,_.useEffect)(()=>{!e.connected||d||t||r||(f(!0),(async()=>{try{await e.sendCommand(`Profiler.enable`),await e.sendCommand(`Profiler.start`),n(!0),setTimeout(async()=>{try{let t=await e.sendCommand(`Profiler.stop`);n(!1),i(t.profile)}catch{n(!1)}},xf)}catch{}})(),e.sendCommand(`Runtime.evaluate`,{expression:`JSON.stringify(process.memoryUsage())`,returnByValue:!0}).then(e=>{c(JSON.parse(e.result.value))}).catch(()=>{}))},[e.connected,d,t,r,e.sendCommand]);let g=(0,_.useCallback)(async()=>{try{await e.sendCommand(`Profiler.enable`),await e.sendCommand(`Profiler.start`),n(!0),i(null)}catch(e){console.error(`Profiler.start failed:`,e)}},[e]),v=(0,_.useCallback)(async()=>{try{let t=await e.sendCommand(`Profiler.stop`);n(!1),i(t.profile)}catch(e){console.error(`Profiler.stop failed:`,e),n(!1)}},[e]),y=(0,_.useCallback)(async()=>{u(!0);try{let t=await e.sendCommand(`Runtime.evaluate`,{expression:`JSON.stringify(process.memoryUsage())`,returnByValue:!0});c(JSON.parse(t.result.value))}catch{}finally{u(!1)}},[e]),b=(0,_.useCallback)(()=>{e.preconfiguredTarget&&e.connect(e.preconfiguredTarget.id)},[e]);return e.active?e.connected?(0,D.jsxs)(`div`,{className:`space-y-5`,children:[(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`runtime inspector`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] font-mono text-[var(--color-fg-2)]`,children:[(0,D.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-emerald-400`}),`connected`,e.bunVersion?` · bun v${e.bunVersion}`:``]}),(0,D.jsx)(G,{variant:`ghost`,size:`sm`,onClick:e.disconnect,children:`disconnect`})]})]}),e.error&&(0,D.jsx)(J,{children:(0,D.jsx)(`p`,{className:`text-xs text-red-300 font-mono`,children:e.error})})]}),(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`cpu profiler`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t&&(0,D.jsxs)(`span`,{className:`text-[10px] font-mono uppercase tracking-wider text-red-300 flex items-center gap-1.5`,children:[(0,D.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-red-400 pulse-soft`}),`recording`]}),t?(0,D.jsx)(G,{variant:`danger`,size:`sm`,onClick:v,children:`stop & render`}):(0,D.jsx)(G,{variant:`primary`,size:`sm`,onClick:g,children:`start recording`})]})]}),(0,D.jsx)(J,{children:r?(0,D.jsx)(Ml,{profile:r,children:(0,D.jsx)(`div`,{className:`bg-[var(--color-surface-0)] border border-[var(--color-line-1)] rounded-sm p-2 overflow-x-hidden`,children:(0,D.jsx)(of,{profile:r})})}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:t?`recording cpu profile (auto-captures ${xf/1e3}s)… perform actions in ssg to generate data.`:`click start recording, or wait for auto-capture on page load.`})})]}),(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`memory`}),(0,D.jsx)(G,{variant:`ghost`,size:`sm`,onClick:y,disabled:l,children:l?`…`:`refresh`})]}),(0,D.jsx)(J,{children:s?(0,D.jsx)(Nl,{memory:s,formatValue:pf}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:d?`fetching memory metrics…`:`click refresh to fetch process.memoryUsage().`})})]}),(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`console`}),(0,D.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>o([]),children:`clear`})]}),(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`bg-[var(--color-surface-0)] border border-[var(--color-line-1)] rounded-sm p-2 h-40 overflow-y-auto font-mono text-[11px]`,children:[a.length===0?(0,D.jsx)(`p`,{className:`text-[var(--color-fg-4)]`,children:`console output will appear here…`}):a.map(e=>(0,D.jsxs)(`div`,{className:`py-0.5 border-b border-[var(--color-line-0)] ${Sf[e.type]??`text-[var(--color-fg-1)]`}`,children:[(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)] mr-2 uppercase tracking-wider`,children:[`[`,e.type,`]`]}),e.args.map(Cf).join(` `)]},e.id)),(0,D.jsx)(`div`,{ref:p})]})})]})]}):(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`runtime inspector`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(W,{variant:`amber`,children:e.connecting?`connecting…`:`available`}),!e.connecting&&(0,D.jsx)(G,{variant:`ghost`,size:`sm`,onClick:b,children:`connect`})]})]}),(0,D.jsx)(J,{children:(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:e.connecting?`establishing websocket connection to bun inspector…`:`inspector is active but not connected. click connect to start profiling.`})})]}):(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`runtime inspector`}),(0,D.jsx)(W,{variant:`outline`,children:`inactive`})]}),(0,D.jsx)(J,{children:(0,D.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:[`the bun inspector is not active. restart`,` `,(0,D.jsx)(`code`,{className:`text-[var(--color-brand)]`,children:`ssg serve`}),` to enable it automatically.`]})})]})}function Tf(){let[e,t]=(0,_.useState)(0),{data:n}=k(`/api/json/evald-log`,[e]),r=(0,_.useRef)(null),i=(0,_.useRef)(!0);(0,_.useEffect)(()=>{let e=setInterval(()=>t(e=>e+1),5e3);return()=>clearInterval(e)},[]),(0,_.useEffect)(()=>{if(i.current){i.current=!1;return}let e=r.current;if(!e)return;let t=e.parentElement;t&&(t.scrollTop=t.scrollHeight)},[]);let a=n?.lines??[];return(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`daemon log`}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] truncate max-w-[60%]`,children:[n?.path?n.path:`loading…`,` · last 200 lines · 5s refresh`]})]}),(0,D.jsxs)(J,{children:[n?.error&&(0,D.jsx)(`p`,{className:`text-xs text-red-300 font-mono mb-2`,children:n.error}),a.length===0&&!n?.error&&(0,D.jsx)(`div`,{className:`rounded-sm border border-dashed border-[var(--color-line-1)] bg-[var(--color-surface-0)] px-4 py-6 text-center`,children:(0,D.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:[`no log entries yet. start the daemon with`,` `,(0,D.jsx)(`code`,{className:`text-[var(--color-brand)]`,children:`ssg serve`}),` to generate log output.`]})}),a.length>0&&(0,D.jsxs)(`pre`,{className:`bg-[var(--color-surface-0)] border border-[var(--color-line-1)] rounded-sm p-3 text-[10px] text-[var(--color-fg-2)] overflow-x-auto whitespace-pre-wrap break-all max-h-80 overflow-y-auto font-mono leading-relaxed`,children:[a.join(`
28
- `),(0,D.jsx)(`div`,{ref:r})]})]})]})}function Ef(){let e=V([`runtime-tick`,`rules-changed`]),{data:t,refetch:n}=k(`/api/json/observability`,[e[`runtime-tick`],e[`rules-changed`]]),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(Date.now()),[l,u]=(0,_.useState)(`idle`),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(`idle`);(0,_.useEffect)(()=>{t&&c(Date.now())},[t]);let h=(0,_.useCallback)(async()=>{u(`loading`);try{let e=await(await fetch(`/api/rules/sync-to-db`,{method:`POST`,headers:U()})).json();if(e.ok){u(`done`);let t=(e.pruned_count??0)>0?` (${e.pruned_count} orphan(s) pruned)`:``;f((e.message??`synced ${e.synced} rules`)+t),n()}else u(`error`),f(e.error??`sync failed`)}catch(e){u(`error`),f(String(e))}},[n]),g=(0,_.useCallback)(async()=>{m(`loading`);try{await fetch(`/api/rules/force-reload`,{method:`POST`,headers:U()}),m(`done`),n(),setTimeout(()=>m(`idle`),3e3)}catch{m(`idle`)}},[n]),v=t?.db,y=t?.rules,b=t?.audit,x=t?.process,S=t?.flight_recorder,C=y?.drift_detected??!1;return(0,D.jsxs)(`div`,{className:`space-y-5`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h1`,{className:`text-xl font-medium tracking-tight text-[var(--color-fg-0)]`,children:`Observability`}),(0,D.jsx)(`p`,{className:`text-[12px] font-mono text-[var(--color-fg-3)] mt-0.5`,children:`sqlite health · rule drift · runtime profiler · diagnostics`})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] tabular-nums`,children:[`refreshed `,gf(s)]}),(0,D.jsx)(G,{variant:`ghost`,size:`sm`,onClick:n,children:`refresh`})]})]}),(0,D.jsx)(Df,{db:v,audit:b,proc:x,flight:S,driftDetected:C}),(0,D.jsxs)(K,{"data-tutorial":`observ-drift`,className:C?`border-red-500/30 border-l-2 border-l-red-500/70`:`border-emerald-500/20 border-l-2 border-l-emerald-500/60`,children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`rule drift detector`}),(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:`— .rules files vs sqlite`}),(0,D.jsx)(`button`,{onClick:()=>o(e=>!e),"aria-expanded":a,"aria-label":`Explain these counts`,title:`Why do these numbers differ?`,className:`text-[10px] font-mono text-[var(--color-fg-4)] hover:text-[var(--color-fg-2)] border border-[var(--color-line-1)] rounded-sm px-1.5 py-0.5 transition-colors cursor-pointer`,children:a?`× close`:`? why these numbers`})]}),y&&(C?(0,D.jsx)(W,{variant:`red`,children:`⚠ drift detected`}):(0,D.jsx)(W,{variant:`green`,children:`✓ in sync`}))]}),(0,D.jsxs)(J,{children:[a&&(0,D.jsxs)(`div`,{className:`mb-4 rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-0)] px-3 py-2.5 space-y-2 text-[11px] font-mono leading-relaxed text-[var(--color-fg-3)]`,children:[(0,D.jsxs)(`div`,{className:`text-[var(--color-fg-2)]`,children:[(0,D.jsx)(`code`,{children:`.rules files`}),` and `,(0,D.jsx)(`code`,{children:`db rules`}),` are`,` `,(0,D.jsx)(`span`,{className:`text-amber-300`,children:`not auto-synced`}),`. A mismatch is usually expected:`]}),(0,D.jsxs)(`ul`,{className:`space-y-1 pl-3 list-disc marker:text-[var(--color-fg-4)]`,children:[(0,D.jsxs)(`li`,{children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:`one file can hold many rules`}),` `,`— compare `,(0,D.jsx)(`code`,{children:`db rules`}),` against`,` `,(0,D.jsx)(`code`,{children:`file_rule_count`}),`, not `,(0,D.jsx)(`code`,{children:`file_count`}),`.`]}),(0,D.jsxs)(`li`,{children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:`only in files`}),` `,`means unsynced edits — run`,` `,(0,D.jsx)(`code`,{className:`text-amber-300`,children:`ssg sync`}),` or click`,` `,(0,D.jsx)(`code`,{children:`↑ sync files → db`}),`.`]}),(0,D.jsxs)(`li`,{children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:`only in db`}),` `,`with `,(0,D.jsx)(`code`,{children:`source_file IS NULL`}),` is healthy — hub, fleet, or cloud-synced rules legitimately live only in the db.`]}),(0,D.jsxs)(`li`,{children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:`only in db`}),` `,`with `,(0,D.jsx)(`code`,{children:`source_file`}),` set means an orphan from a deleted file —`,` `,(0,D.jsx)(`code`,{className:`text-amber-300`,children:`ssg sync`}),` prunes it.`]}),(0,D.jsxs)(`li`,{children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:`db rules`}),` `,`includes disabled rows; `,(0,D.jsx)(`code`,{children:`db_enabled_count`}),` excludes them.`]})]}),(0,D.jsxs)(`div`,{className:`pt-1.5 border-t border-[var(--color-line-0)]`,children:[`full reference:`,` `,(0,D.jsx)(`a`,{href:`https://docs.sigmashake.com/rule-storage`,target:`_blank`,rel:`noopener noreferrer`,className:`text-[var(--color-fg-2)] underline decoration-dotted underline-offset-2 hover:text-amber-300 transition-colors`,children:`docs.sigmashake.com/rule-storage ↗`})]})]}),y?(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,children:[{label:`.rules files`,value:y.file_count,sub:`${y.file_rule_count} rules total`,tone:`neutral`},{label:`db rules`,value:y.db_rule_count,sub:`${y.db_enabled_count} enabled`,tone:`neutral`},{label:`only in files`,value:y.drift_details.only_in_files.length,tone:y.drift_details.only_in_files.length>0?`amber`:`gray`},{label:`only in db`,value:y.drift_details.only_in_db.length,tone:y.drift_details.only_in_db.length>0?`red`:`gray`}].map(({label:e,value:t,sub:n,tone:r})=>(0,D.jsx)(kl,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-0)]`,label:e,value:t,sub:n,tone:r,labelPlacement:`above`,subClassName:`text-[var(--color-fg-4)]`,valueClassName:`text-xl font-medium tabular-nums`},e))}),C&&(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`button`,{onClick:()=>i(e=>!e),className:`text-[10px] font-mono uppercase tracking-wider text-amber-300 hover:text-amber-200 flex items-center gap-1 transition-colors cursor-pointer`,children:[r?`▾`:`▸`,` view drift details`]}),r&&(0,D.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[y.drift_details.only_in_files.length>0&&(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`text-[10px] font-mono uppercase tracking-wider text-amber-300/80 mb-1.5`,children:[`in .rules files but not in db — run`,` `,(0,D.jsx)(`code`,{className:`text-amber-300`,children:`ssg sync`})]}),(0,D.jsx)(`div`,{className:`bg-[var(--color-surface-0)] border border-amber-400/20 rounded-sm p-2 space-y-0.5 max-h-40 overflow-y-auto`,children:y.drift_details.only_in_files.map(e=>(0,D.jsxs)(`div`,{className:`font-mono text-[11px] text-amber-200/80`,children:[`+ `,e]},e))})]}),y.drift_details.only_in_db.length>0&&(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-[10px] font-mono uppercase tracking-wider text-red-300/80 mb-1.5`,children:`in db but not in any .rules file — orphaned rules`}),(0,D.jsx)(`div`,{className:`bg-[var(--color-surface-0)] border border-red-400/20 rounded-sm p-2 space-y-0.5 max-h-40 overflow-y-auto`,children:y.drift_details.only_in_db.map(e=>(0,D.jsxs)(`div`,{className:`font-mono text-[11px] text-red-200/80`,children:[`− `,e]},e))})]})]})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pt-3 border-t border-[var(--color-line-0)]`,children:[(0,D.jsx)(G,{variant:`primary`,size:`sm`,onClick:h,disabled:l===`loading`,children:l===`loading`?`syncing…`:`↑ sync files → db`}),(0,D.jsx)(G,{variant:`ghost`,size:`sm`,onClick:g,disabled:p===`loading`,children:p===`loading`?`…`:p===`done`?`✓ reloaded`:`↻ force reload`}),(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] ml-auto`,children:y.db_rule_count===0?`⚠ db empty — daemon falls back to file-based loading`:`db has ${y.db_rule_count} rules — indexed queries`})]}),l===`done`&&(0,D.jsxs)(`div`,{className:`flex items-center justify-between rounded-sm border border-emerald-500/25 bg-emerald-500/[0.06] px-3 py-2 text-xs font-mono text-emerald-200`,children:[(0,D.jsxs)(`span`,{children:[`✓ `,d]}),(0,D.jsx)(`button`,{onClick:()=>u(`idle`),className:`ml-3 shrink-0 px-2 py-0.5 rounded-sm border border-emerald-500/30 hover:bg-emerald-500/10 transition-colors cursor-pointer uppercase tracking-wider text-[10px]`,children:`dismiss`})]}),l===`error`&&(0,D.jsxs)(`div`,{className:`flex items-center justify-between rounded-sm border border-red-500/25 bg-red-500/[0.06] px-3 py-2 text-xs font-mono text-red-200`,children:[(0,D.jsxs)(`span`,{children:[`✗ `,d]}),(0,D.jsx)(`button`,{onClick:()=>u(`idle`),className:`ml-3 shrink-0 px-2 py-0.5 rounded-sm border border-red-500/30 hover:bg-red-500/10 transition-colors cursor-pointer uppercase tracking-wider text-[10px]`,children:`dismiss`})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-4 text-[11px] font-mono text-[var(--color-fg-4)] pt-2 border-t border-[var(--color-line-0)]`,children:[(0,D.jsxs)(`span`,{children:[`rules dir:`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:y.rules_dir})]}),(0,D.jsxs)(`span`,{className:`ml-auto`,children:[`last reload:`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:gf(y.last_reload_at)})]})]})]}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`loading…`})]})]}),(0,D.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-5`,children:[(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`sqlite database`}),v&&!v.error&&(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,D.jsx)(yf,{ok:v.journal_mode===`wal`,label:`wal`,badLabel:`no wal`}),(0,D.jsx)(yf,{ok:v.synchronous===`NORMAL`,label:`normal`,badLabel:v.synchronous})]})]}),(0,D.jsx)(J,{children:v?v.error?(0,D.jsx)(`div`,{className:`text-xs text-red-300 font-mono bg-red-500/[0.06] border border-red-500/25 rounded-sm p-2`,children:v.error}):(0,D.jsxs)(`div`,{children:[(0,D.jsx)(_f,{children:`storage`}),(0,D.jsx)(vf,{label:`file path`,value:v.path}),(0,D.jsx)(vf,{label:`file size`,value:ff(v.file_size_bytes)}),(0,D.jsx)(vf,{label:`allocated`,value:`${ff(v.allocated_bytes)} (${v.page_count.toLocaleString()} pages × ${v.page_size}B)`}),(0,D.jsx)(_f,{className:`mt-4`,children:`pragma configuration`}),(0,D.jsx)(vf,{label:`journal_mode`,value:v.journal_mode,accent:v.journal_mode===`wal`?`text-emerald-300`:`text-amber-300`}),(0,D.jsx)(vf,{label:`synchronous`,value:v.synchronous,accent:v.synchronous===`NORMAL`?`text-emerald-300`:`text-amber-300`}),(0,D.jsx)(vf,{label:`cache_size`,value:`${v.cache_size_kb.toLocaleString()} KB (${Math.round(v.cache_size_kb/1024)} MB)`}),(0,D.jsx)(vf,{label:`page_size`,value:`${v.page_size.toLocaleString()} B`}),v.wal_checkpoint&&(0,D.jsx)(vf,{label:`wal checkpoint`,value:`log ${v.wal_checkpoint.log}, checkpointed ${v.wal_checkpoint.checkpointed}, busy ${v.wal_checkpoint.busy}`}),(0,D.jsx)(_f,{className:`mt-4`,children:`table row counts`}),v.tables.map(e=>(0,D.jsx)(vf,{label:e.name,value:e.row_count>=0?e.row_count.toLocaleString():`error`,accent:e.row_count<0?`text-red-300`:`text-[var(--color-fg-1)]`},e.name))]}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`loading…`})})]}),(0,D.jsxs)(`div`,{className:`space-y-5`,children:[(0,D.jsxs)(K,{"data-tutorial":`observ-capacity`,children:[(0,D.jsx)(q,{children:(0,D.jsx)(`span`,{className:`overline`,children:`audit log capacity`})}),(0,D.jsx)(J,{children:b?(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsx)(bf,{pct:b.utilization_pct,total:b.total_rows,max:b.max_rows}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(vf,{label:`total rows`,value:b.total_rows.toLocaleString()}),(0,D.jsx)(vf,{label:`rotation limit`,value:b.max_rows.toLocaleString()}),(0,D.jsx)(vf,{label:`utilization`,value:`${b.utilization_pct}%`,accent:b.utilization_pct>=85?`text-red-300`:b.utilization_pct>=60?`text-amber-300`:`text-emerald-300`}),(0,D.jsx)(vf,{label:`oldest entry`,value:hf(b.oldest_timestamp)}),(0,D.jsx)(vf,{label:`newest entry`,value:hf(b.newest_timestamp)})]}),b.utilization_pct>=85&&(0,D.jsx)(`div`,{className:`rounded-sm border border-red-500/25 bg-red-500/[0.06] px-3 py-2 text-[11px] font-mono text-red-200`,children:`⚠ audit log nearing rotation limit. oldest entries will be purged automatically.`})]}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`loading…`})})]}),(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsx)(`span`,{className:`overline`,children:`process & runtime`})}),(0,D.jsx)(J,{children:x?(0,D.jsxs)(`div`,{children:[(0,D.jsx)(vf,{label:`pid`,value:x.pid}),(0,D.jsx)(vf,{label:`uptime`,value:mf(x.uptime_ms)}),(0,D.jsx)(vf,{label:`memory (rss)`,value:`${x.memory_rss_mb} MB`}),(0,D.jsx)(vf,{label:`bun version`,value:x.bun_version}),(0,D.jsx)(vf,{label:`node compat`,value:x.node_version}),(0,D.jsx)(vf,{label:`platform`,value:`${x.platform} / ${x.arch}`})]}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`loading…`})})]})]})]}),(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsx)(`span`,{className:`overline`,children:`flight recorder`})}),(0,D.jsx)(J,{children:S?(0,D.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline mb-1.5`,children:`log file`}),(0,D.jsx)(`div`,{className:`text-xs font-mono text-[var(--color-fg-1)] truncate`,children:`…${S.path.slice(-50)}`})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline mb-1.5`,children:`file size`}),(0,D.jsx)(`div`,{className:`text-xs font-mono tabular-nums ${S.file_size_bytes===0?`text-[var(--color-fg-4)]`:`text-[var(--color-fg-1)]`}`,children:ff(S.file_size_bytes)})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline mb-1.5`,children:`approx. entries`}),(0,D.jsx)(`div`,{className:`text-xs font-mono tabular-nums ${S.approx_entries===0?`text-[var(--color-fg-4)]`:`text-[var(--color-fg-1)]`}`,children:S.approx_entries===0?`—`:S.approx_entries.toLocaleString()})]})]}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`loading…`})})]}),(0,D.jsx)(wf,{}),(0,D.jsx)(Tf,{}),(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsx)(`span`,{className:`overline`,children:`observability api`})}),(0,D.jsxs)(J,{children:[(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)] mb-2.5`,children:`machine-readable endpoints for automated monitoring and ai agent triage:`}),(0,D.jsx)(`div`,{className:`space-y-1 font-mono text-[11px]`,children:[[`/api/json/observability`,`sqlite health, rule drift, process info`],[`/api/state/runtime`,`eval latency, decision counters, memory`],[`/api/state/activity-tail?after=0&limit=20`,`recent eval events (live feed)`],[`/api/json/daemon-status`,`daemon pid, status, log tail`],[`/api/json/evald-log`,`last 200 lines of evald.log (daemon stderr)`],[`/healthz`,`process liveness`],[`/readyz`,`sqlite liveness`]].map(([e,t])=>(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`GET`}),(0,D.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`text-[var(--color-brand)]/80 hover:text-[var(--color-brand)] transition-colors`,children:e}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)] hidden sm:inline`,children:[`— `,t]})]},e))})]})]})]})}function Df({db:e,audit:t,proc:n,flight:r,driftDetected:i}){let a=e?e.error?`error`:e.journal_mode===`wal`&&e.synchronous===`NORMAL`?`ok`:`warn`:`unknown`,o=t?t.utilization_pct>=85?`error`:t.utilization_pct>=60?`warn`:`ok`:`unknown`,s=n?n.memory_rss_mb>600?`warn`:`ok`:`unknown`;return(0,D.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4`,children:[(0,D.jsxs)(lf,{title:`sqlite`,status:a,statusLabel:e?.journal_mode?.toUpperCase()??`idle`,children:[(0,D.jsx)(uf,{label:`size`,value:e?(0,D.jsx)(Ks,{value:e.file_size_bytes,format:e=>pf(e)}):`—`,mono:!0}),(0,D.jsx)(uf,{label:`journal`,value:e?.journal_mode??`—`,mono:!0}),(0,D.jsx)(uf,{label:`sync`,value:e?.synchronous??`—`,mono:!0}),(0,D.jsx)(uf,{label:`tables`,value:e?.tables.length??0,tone:i?`warn`:`neutral`})]}),(0,D.jsxs)(lf,{title:`audit log`,status:o,statusLabel:t?`${t.utilization_pct}%`:`idle`,children:[(0,D.jsx)(uf,{label:`rows`,value:t?(0,D.jsx)(Ks,{value:t.total_rows}):`—`}),(0,D.jsx)(uf,{label:`capacity`,value:t?`${(t.total_rows/Math.max(1,t.max_rows)*100).toFixed(1)}%`:`—`,tone:t&&t.utilization_pct>=85?`bad`:t&&t.utilization_pct>=60?`warn`:`good`}),(0,D.jsx)(uf,{label:`oldest`,value:hf(t?.oldest_timestamp??null),mono:!0}),(0,D.jsx)(uf,{label:`newest`,value:hf(t?.newest_timestamp??null),mono:!0})]}),(0,D.jsxs)(lf,{title:`process`,status:s,statusLabel:n?`pid ${n.pid}`:`idle`,children:[(0,D.jsx)(uf,{label:`uptime`,value:n?mf(n.uptime_ms):`—`,mono:!0}),(0,D.jsx)(uf,{label:`rss`,value:n?(0,D.jsxs)(`span`,{children:[(0,D.jsx)(Ks,{value:n.memory_rss_mb,format:e=>e.toFixed(0)}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] ml-1`,children:`MB`})]}):`—`}),(0,D.jsx)(uf,{label:`bun`,value:n?.bun_version??`—`,mono:!0}),(0,D.jsx)(uf,{label:`platform`,value:n?`${n.platform}/${n.arch}`:`—`,mono:!0})]}),(0,D.jsxs)(lf,{title:`flight recorder`,status:r&&r.file_size_bytes>0?`ok`:`unknown`,statusLabel:r?`${r.approx_entries.toLocaleString()} entries`:`idle`,children:[(0,D.jsx)(uf,{label:`size`,value:r?(0,D.jsx)(Ks,{value:r.file_size_bytes,format:e=>pf(e)}):`—`,mono:!0}),(0,D.jsx)(uf,{label:`entries`,value:r?(0,D.jsx)(Ks,{value:r.approx_entries}):`—`})]})]})}var Of=`https://hub.sigmashake.com/submit-plugin`,kf=`https://docs.sigmashake.com/docs/plugins/`,Af=[{cmd:`ssg plugins init my-plugin`,title:`Scaffold`,detail:`Creates plugin.toml plus a src/ template you can edit.`},{cmd:`ssg plugins build`,title:`Build & sign`,detail:`Bundles src/ into dist/<id>-<version>.tar.gz and an Ed25519-signed plugin.json.`},{cmd:`ssg plugins publish`,title:`Publish`,detail:`Pushes the source, cuts a GitHub release for the artifact, and opens the hub submission form prefilled.`}];function jf(){return(0,D.jsxs)(`div`,{className:`mx-auto max-w-2xl space-y-5`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`a`,{href:`/plugins`,className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-brand)]`,children:`← plugins`}),(0,D.jsx)(`h1`,{className:`mt-2 text-xl font-medium tracking-tight text-[var(--color-fg-0)]`,children:`Publish a plugin`}),(0,D.jsx)(`p`,{className:`mt-1 font-mono text-[12px] text-[var(--color-fg-3)]`,children:`build, sign, and submit a dashboard plugin to hub.sigmashake.com`})]}),(0,D.jsx)(K,{children:(0,D.jsxs)(J,{children:[(0,D.jsx)(`h2`,{className:`text-sm font-medium text-[var(--color-fg-1)]`,children:`Build it with the ssg CLI`}),(0,D.jsx)(`p`,{className:`mt-1 text-xs text-[var(--color-fg-3)]`,children:`Plugins are built, signed, and released from your machine — the CLI runs the whole flow. Run these from your plugin's directory:`}),(0,D.jsx)(`ol`,{className:`mt-3 space-y-3`,children:Af.map((e,t)=>(0,D.jsxs)(`li`,{className:`flex gap-3`,children:[(0,D.jsx)(`span`,{className:`mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full border border-[var(--color-line-1)] font-mono text-[11px] text-[var(--color-fg-3)]`,children:t+1}),(0,D.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,D.jsx)(`div`,{className:`text-xs font-medium text-[var(--color-fg-1)]`,children:e.title}),(0,D.jsx)(`pre`,{className:`mt-1 overflow-x-auto rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-0)] px-2.5 py-1.5 text-xs`,children:(0,D.jsx)(`code`,{className:`font-mono text-[var(--color-fg-1)]`,children:e.cmd})}),(0,D.jsx)(`p`,{className:`mt-1 text-[11px] text-[var(--color-fg-3)]`,children:e.detail})]})]},e.cmd))})]})}),(0,D.jsxs)(`div`,{className:`rounded-sm border border-amber-500/25 bg-amber-500/5 px-3 py-2 text-xs text-amber-200`,children:[`First time publishing? Register your signing key with`,` `,(0,D.jsx)(`code`,{className:`font-mono text-amber-100`,children:`ssg keys register`}),` so the hub can verify your plugin's Ed25519 signature against your account.`]}),(0,D.jsx)(K,{children:(0,D.jsxs)(J,{children:[(0,D.jsx)(`h2`,{className:`text-sm font-medium text-[var(--color-fg-1)]`,children:`Submit to the marketplace`}),(0,D.jsxs)(`p`,{className:`mt-1 text-xs text-[var(--color-fg-3)]`,children:[(0,D.jsx)(`code`,{className:`font-mono text-[var(--color-fg-2)]`,children:`ssg plugins publish`}),` `,`opens the hub submission form automatically once your release is up. If you've already built your plugin, open the form directly:`]}),(0,D.jsxs)(`a`,{href:Of,"data-tutorial":`pubplug-submit`,target:`_blank`,rel:`noreferrer`,className:`mt-3 inline-flex items-center gap-1.5 rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] px-3 py-1.5 text-xs font-medium text-[var(--color-fg-1)] transition-colors hover:border-[var(--color-hig-blue)] hover:text-[var(--color-hig-blue)]`,children:[`Open hub submission form`,(0,D.jsx)(`span`,{"aria-hidden":!0,children:`↗`})]}),(0,D.jsx)(`p`,{className:`mt-2 text-[11px] text-[var(--color-fg-4)]`,children:`Submitting needs a GitHub sign-in on hub.sigmashake.com — it opens in a new tab.`})]})}),(0,D.jsxs)(`p`,{className:`text-[11px] text-[var(--color-fg-3)]`,children:[`New to plugin authoring? Read the`,` `,(0,D.jsx)(`a`,{href:kf,target:`_blank`,rel:`noreferrer`,className:`text-[var(--color-hig-blue)] hover:underline`,children:`plugin documentation ↗`}),`.`]})]})}var Mf=[],Nf=`ssg:builtin-features:v1`,Pf=`ssg:builtin-features-change`,Ff={};function If(){try{let e=localStorage.getItem(Nf);if(!e)return{...Ff};let t=JSON.parse(e);if(typeof t!=`object`||!t)return{...Ff};let n={...Ff};for(let e of Object.keys(Ff)){let r=t[e];typeof r==`boolean`&&(n[e]=r)}return n}catch{return{...Ff}}}function Lf(e){try{localStorage.setItem(Nf,JSON.stringify(e))}catch{}}function Rf(e){window.dispatchEvent(new CustomEvent(Pf,{detail:e}))}function zf(){let[e,t]=(0,_.useState)(()=>If());return(0,_.useEffect)(()=>{let e=e=>{let n=e.detail;n&&t(n)};return window.addEventListener(Pf,e),()=>window.removeEventListener(Pf,e)},[]),{features:e,setFeature:(0,_.useCallback)((n,r)=>{let i={...e,[n]:r};t(i),Lf(i),Rf(i)},[e])}}async function Bf(){let e=await fetch(`/api/json/plugins`,{headers:{Accept:`application/json`}});if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}async function Vf(e=``,t={}){let n=new URLSearchParams;e&&n.set(`q`,e),t.category&&n.set(`category`,t.category),t.featured&&n.set(`featured`,`1`),t.sort&&n.set(`sort`,t.sort),t.page&&t.page>1&&n.set(`page`,String(t.page));let r=await fetch(`/api/json/plugins/available?${n.toString()}`,{headers:{Accept:`application/json`}});if(!r.ok)throw Error(`HTTP ${r.status}`);return r.json()}async function Hf(){let e=await fetch(`/api/json/plugins/categories`,{headers:{Accept:`application/json`}});if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}async function Uf(e,t){let n=await fetch(e,{method:`POST`,headers:{...U(),"Content-Type":`application/json`},body:JSON.stringify(t)}),r=await n.text(),i=null;if(r)try{i=JSON.parse(r)}catch{i={error:r}}if(!n.ok){let e=i&&typeof i==`object`&&i&&`error`in i&&typeof i.error==`string`?i.error:`HTTP ${n.status}`;throw Error(e)}return i}function Wf(e){return Uf(`/api/json/plugins/install`,{packId:e})}function Gf(e){return Uf(`/api/json/plugins/uninstall`,{id:e})}function Kf(e){return Uf(`/api/json/plugins/enable`,{id:e})}function qf(e){return Uf(`/api/json/plugins/disable`,{id:e})}var Jf=5e3,Yf=200,Xf=5,Zf={tools:`bg-sky-500/10 text-sky-300 border-sky-500/25`,observability:`bg-violet-500/10 text-violet-300 border-violet-500/25`,productivity:`bg-emerald-500/10 text-emerald-300 border-emerald-500/25`,integrations:`bg-amber-500/10 text-amber-300 border-amber-500/30`,developer:`bg-rose-500/10 text-rose-300 border-rose-500/25`};function Qf(e){return e?Zf[e]??`bg-[var(--color-surface-2)] text-[var(--color-fg-3)] border-[var(--color-line-1)]`:`bg-[var(--color-surface-2)] text-[var(--color-fg-3)] border-[var(--color-line-1)]`}function $f(e){if(!e)return``;let t=Date.parse(e);if(Number.isNaN(t))return``;let n=Date.now()-t,r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(o/12)}y ago`}function ep(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function tp(e){let t=e.split(/[\s\-_]+/).filter(Boolean);return t.length===0?`?`:t.length===1?t[0].slice(0,2).toUpperCase():(t[0][0]+t[1][0]).toUpperCase()}function np({icon:e,name:t,avatarUrl:n,large:r}){let i=r?`h-14 w-14 text-2xl`:`h-10 w-10 text-lg`,a=r?`text-sm`:`text-[11px]`;return e?(0,D.jsx)(`div`,{className:`flex ${i} shrink-0 items-center justify-center rounded-md bg-[var(--color-surface-2)] leading-none`,children:(0,D.jsx)(`span`,{"aria-hidden":!0,children:e})}):n?(0,D.jsx)(`img`,{src:n,alt:``,className:`${i} shrink-0 rounded-md object-cover`,loading:`lazy`}):(0,D.jsx)(`div`,{className:`flex ${i} shrink-0 items-center justify-center rounded-md bg-[var(--color-surface-2)] ${a} font-mono uppercase text-[var(--color-fg-3)]`,children:tp(t)})}function rp(){return(0,D.jsxs)(`svg`,{"aria-label":`Verified publisher`,width:`12`,height:`12`,viewBox:`0 0 12 12`,fill:`none`,className:`inline-block shrink-0 text-sky-400`,children:[(0,D.jsx)(`circle`,{cx:`6`,cy:`6`,r:`5.5`,stroke:`currentColor`,strokeWidth:`1`}),(0,D.jsx)(`path`,{d:`M3.5 6l1.8 1.8 3.2-3.6`,stroke:`currentColor`,strokeWidth:`1.2`,strokeLinecap:`round`,strokeLinejoin:`round`})]})}function ip(){return(0,D.jsx)(K,{children:(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`flex animate-pulse items-start gap-3`,children:[(0,D.jsx)(`div`,{className:`h-10 w-10 shrink-0 rounded-md bg-[var(--color-surface-2)]`}),(0,D.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,D.jsx)(`div`,{className:`h-3 w-1/3 rounded bg-[var(--color-surface-2)]`}),(0,D.jsx)(`div`,{className:`h-3 w-2/3 rounded bg-[var(--color-surface-2)]`}),(0,D.jsx)(`div`,{className:`h-3 w-1/4 rounded bg-[var(--color-surface-2)]`})]}),(0,D.jsx)(`div`,{className:`h-7 w-20 shrink-0 rounded bg-[var(--color-surface-2)]`})]})})})}function ap(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)({}),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(!0),[y,b]=(0,_.useState)(!0),[x,S]=(0,_.useState)(`browse`),[C,w]=(0,_.useState)(`all`),[T,E]=(0,_.useState)(`popular`),[O,k]=(0,_.useState)([]),{features:ee,setFeature:A}=zf(),j=(0,_.useMemo)(()=>Mf.filter(e=>ee[e.id]).length,[ee]),M=(0,_.useRef)(null),te=(0,_.useCallback)((e,t)=>{h({kind:e,message:t}),M.current&&clearTimeout(M.current),M.current=setTimeout(()=>{h(null),M.current=null},Jf)},[]);(0,_.useEffect)(()=>()=>{M.current&&clearTimeout(M.current)},[]),(0,_.useEffect)(()=>{let e=setTimeout(()=>d(c),Yf);return()=>clearTimeout(e)},[c]),(0,_.useEffect)(()=>{Hf().then(e=>k(e.categories)).catch(()=>{})},[]);let N=(0,_.useCallback)(async()=>{v(!0);try{let e=await Bf();t(e.plugins),r(e.errors)}catch(e){te(`err`,e instanceof Error?e.message:String(e))}finally{v(!1)}},[te]),P=(0,_.useCallback)(async(e,t,n)=>{b(!0),s(null);try{a((await Vf(e,{category:t===`all`?void 0:t,sort:n})).data??[])}catch(e){s(e instanceof Error?e.message:String(e)),a([])}finally{b(!1)}},[]);(0,_.useEffect)(()=>{N()},[N]),(0,_.useEffect)(()=>{P(u,C,T)},[u,C,T,P]);let F=(0,_.useMemo)(()=>new Set(e.map(e=>e.id)),[e]),I=(0,_.useMemo)(()=>e.filter(e=>e.enabled).length,[e]),ne=async(e,t,n,r)=>{p(n=>({...n,[e]:t}));try{await n(),te(`ok`,r),await Promise.all([N(),P(u,C,T)])}catch(e){te(`err`,e instanceof Error?e.message:String(e))}finally{p(t=>({...t,[e]:void 0}))}},re=(0,_.useMemo)(()=>{let e=new Map;for(let t of i)e.set(t.id,t.icon);return e},[i]),ie=(0,_.useMemo)(()=>i.filter(e=>e.featured),[i]),L=C===`all`&&ie.length>0;return(0,D.jsxs)(`div`,{className:`flex flex-col gap-5 p-6`,children:[(0,D.jsxs)(`header`,{className:`flex flex-col gap-3`,children:[(0,D.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3`,children:[(0,D.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`h1`,{className:`text-xl font-semibold`,children:`Plugin Marketplace`}),(0,D.jsxs)(`p`,{className:`max-w-2xl text-sm text-[var(--color-fg-3)]`,children:[`Extend the dashboard with Ed25519-signed plugins from`,` `,(0,D.jsx)(`a`,{href:`https://hub.sigmashake.com`,className:`text-[var(--color-hig-blue)] hover:underline`,target:`_blank`,rel:`noreferrer`,children:`hub.sigmashake.com`}),`. Each plugin is hash-verified and signature-checked before extraction; disable to hide from the sidebar without uninstalling.`]})]}),(0,D.jsx)(`a`,{href:`/publish-plugin`,className:`text-xs text-[var(--color-hig-blue)] hover:underline`,children:`Publish a plugin →`})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,D.jsxs)(`div`,{"data-tutorial":`plugins-tabs`,role:`tablist`,className:`inline-flex overflow-hidden rounded-md border border-[var(--color-line-1)]`,children:[(0,D.jsxs)(`button`,{role:`tab`,"aria-selected":x===`browse`,className:`px-3 py-1.5 text-xs transition-colors ${x===`browse`?`bg-[var(--color-surface-2)] text-[var(--color-fg-1)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,onClick:()=>S(`browse`),children:[`Browse`,i.length>0?` · ${i.length}`:``]}),(0,D.jsxs)(`button`,{role:`tab`,"aria-selected":x===`installed`,className:`border-l border-[var(--color-line-1)] px-3 py-1.5 text-xs transition-colors ${x===`installed`?`bg-[var(--color-surface-2)] text-[var(--color-fg-1)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,onClick:()=>S(`installed`),children:[`Installed · `,e.length,e.length>0&&I<e.length&&(0,D.jsxs)(`span`,{className:`ml-1 text-amber-300`,children:[`(`,e.length-I,` off)`]})]}),(0,D.jsxs)(`button`,{role:`tab`,"aria-selected":x===`builtin`,className:`border-l border-[var(--color-line-1)] px-3 py-1.5 text-xs transition-colors ${x===`builtin`?`bg-[var(--color-surface-2)] text-[var(--color-fg-1)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,onClick:()=>S(`builtin`),title:`Bundled features that behave like plugins — opt-in`,children:[`Built-in · `,j,`/`,Mf.length]})]}),x===`browse`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`relative ml-auto`,children:[(0,D.jsx)(`input`,{"data-tutorial":`plugins-search`,type:`search`,placeholder:`Search plugins…`,className:`w-64 rounded-sm border border-[var(--color-line-1)] bg-transparent px-2 py-1 text-xs focus:border-[var(--color-hig-blue)] focus:outline-none`,value:c,onChange:e=>l(e.target.value),"aria-label":`Search plugins`}),c&&(0,D.jsx)(`button`,{className:`absolute right-1 top-1/2 -translate-y-1/2 px-1 text-[var(--color-fg-4)] hover:text-[var(--color-fg-1)]`,onClick:()=>l(``),"aria-label":`Clear search`,children:`×`})]}),i.length>Xf&&(0,D.jsxs)(`select`,{value:T,onChange:e=>E(e.target.value),"aria-label":`Sort plugins`,className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] px-2 py-1 text-xs text-[var(--color-fg-2)] focus:outline-none`,children:[(0,D.jsx)(`option`,{value:`popular`,children:`Popular`}),(0,D.jsx)(`option`,{value:`recent`,children:`Recent`}),(0,D.jsx)(`option`,{value:`name`,children:`Name`})]})]}),x===`installed`&&(0,D.jsx)(G,{variant:`ghost`,size:`sm`,className:`ml-auto`,onClick:()=>void N(),children:`Refresh`})]}),x===`browse`&&O.length>0&&(0,D.jsxs)(`div`,{"data-tutorial":`plugins-categories`,className:`flex flex-wrap gap-1.5`,role:`group`,"aria-label":`Filter by category`,children:[(0,D.jsx)(`button`,{onClick:()=>w(`all`),className:`inline-flex items-center gap-1 rounded-full border px-2.5 py-0.5 text-[11px] font-medium transition-colors ${C===`all`?`border-[var(--color-hig-blue)] bg-sky-500/10 text-sky-300`:`border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,"aria-pressed":C===`all`,children:`All`}),O.map(e=>(0,D.jsxs)(`button`,{onClick:()=>w(C===e.name?`all`:e.name),className:`inline-flex items-center gap-1 rounded-full border px-2.5 py-0.5 text-[11px] font-medium capitalize transition-colors ${C===e.name?`border-transparent ${Qf(e.name)}`:`border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,"aria-pressed":C===e.name,children:[e.name,(0,D.jsx)(`span`,{className:`text-[10px] opacity-60`,children:e.count})]},e.name))]})]}),m&&(0,D.jsx)(`div`,{role:`status`,className:m.kind===`ok`?`rounded-md border border-emerald-700/40 bg-emerald-900/20 px-3 py-2 text-xs text-emerald-200`:`rounded-md border border-red-700/40 bg-red-900/20 px-3 py-2 text-xs text-red-200`,children:m.message}),n.length>0&&(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsxs)(`div`,{className:`text-xs uppercase tracking-wider text-amber-300`,children:[`Load errors (`,n.length,`)`]})}),(0,D.jsx)(J,{children:(0,D.jsx)(`ul`,{className:`space-y-1 text-xs text-amber-100/80`,children:n.map(e=>(0,D.jsxs)(`li`,{children:[(0,D.jsx)(`span`,{className:`font-mono text-amber-300`,children:e.id}),` ·`,` `,e.error]},e.id))})})]}),x===`browse`&&(0,D.jsx)(sp,{loading:y,error:o,available:i,featuredPlugins:ie,showFeatured:L,installedIds:F,busy:f,query:u,selectedCategory:C,onInstall:e=>ne(e.id,`install`,()=>Wf(e.id),`Installed ${e.name}`),onRetry:()=>void P(u,C,T)}),x===`installed`&&(0,D.jsx)(lp,{loading:g,installed:e,iconById:re,busy:f,onEnable:e=>ne(e.id,`toggle`,()=>Kf(e.id),`Enabled ${e.name}`),onDisable:e=>ne(e.id,`toggle`,()=>qf(e.id),`Disabled ${e.name}`),onUninstall:e=>ne(e.id,`uninstall`,()=>Gf(e.id),`Uninstalled ${e.name}`)}),x===`builtin`&&(0,D.jsx)(cp,{features:ee,onToggle:(e,t)=>{A(e,t);let n=Mf.find(t=>t.id===e),r=n?n.name:e;te(`ok`,t?`Enabled ${r}`:`Disabled ${r}`)}})]})}function op({plugin:e,installed:t,busy:n,onInstall:r}){return(0,D.jsxs)(`div`,{className:`flex w-56 shrink-0 flex-col gap-2 rounded-lg border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,D.jsx)(np,{name:e.name,icon:e.icon,large:!0}),e.verified&&(0,D.jsx)(`span`,{className:`mt-0.5`,children:(0,D.jsx)(rp,{})})]}),(0,D.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,D.jsx)(`span`,{className:`truncate text-sm font-semibold leading-tight`,children:e.name}),e.category&&(0,D.jsx)(`span`,{className:`inline-flex w-fit items-center rounded-sm border px-1 py-px text-[9px] font-mono font-medium uppercase tracking-wide ${Qf(e.category)}`,children:e.category})]}),e.description&&(0,D.jsx)(`p`,{className:`line-clamp-2 text-[11px] leading-relaxed text-[var(--color-fg-3)]`,children:e.description}),(0,D.jsxs)(`div`,{className:`mt-auto flex items-center justify-between gap-2`,children:[(0,D.jsxs)(`span`,{className:`text-[10px] text-[var(--color-fg-4)]`,children:[ep(e.install_count),` installs`]}),(0,D.jsx)(G,{variant:t?`ghost`:`primary`,size:`sm`,disabled:t||n,onClick:r,children:t?`Installed`:n?`Installing…`:`Install`})]})]})}function sp({loading:e,error:t,available:n,featuredPlugins:r,showFeatured:i,installedIds:a,busy:o,query:s,selectedCategory:c,onInstall:l,onRetry:u}){return e&&n.length===0?(0,D.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,D.jsx)(`div`,{className:`flex gap-3 overflow-x-auto pb-1`,children:Array.from({length:3}).map((e,t)=>(0,D.jsx)(`div`,{className:`h-40 w-56 shrink-0 animate-pulse rounded-lg bg-[var(--color-surface-2)]`},t))}),(0,D.jsx)(`div`,{className:`grid grid-cols-1 gap-3 lg:grid-cols-2`,children:Array.from({length:4}).map((e,t)=>(0,D.jsx)(ip,{},t))})]}):t?(0,D.jsx)(K,{children:(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,children:[(0,D.jsx)(`div`,{className:`text-sm font-medium text-[var(--color-fg-1)]`,children:`Hub unreachable`}),(0,D.jsx)(`div`,{className:`text-xs text-red-300`,children:t}),(0,D.jsx)(G,{variant:`secondary`,size:`sm`,onClick:u,children:`Retry`})]})})}):n.length===0?(0,D.jsx)(K,{children:(0,D.jsx)(J,{children:(0,D.jsx)(`div`,{className:`flex flex-col gap-2 py-4 text-sm text-[var(--color-fg-3)]`,children:s?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`font-medium text-[var(--color-fg-1)]`,children:[`No plugins match "`,s,`".`]}),(0,D.jsx)(`div`,{children:`Try a different search term, or browse the full catalog by clearing the search box.`})]}):c===`all`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`font-medium text-[var(--color-fg-1)]`,children:`No plugins on the hub yet.`}),(0,D.jsxs)(`div`,{children:[`The marketplace is brand new.`,` `,(0,D.jsx)(`a`,{href:`/publish-plugin`,className:`text-[var(--color-hig-blue)] hover:underline`,children:`Publish the first plugin →`})]})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`font-medium text-[var(--color-fg-1)]`,children:`No plugins in this category yet.`}),(0,D.jsx)(`div`,{children:`Try another category or view all plugins.`})]})})})}):(0,D.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[i&&(0,D.jsxs)(`section`,{"data-tutorial":`plugins-featured`,children:[(0,D.jsx)(`div`,{className:`mb-2 text-xs font-medium uppercase tracking-wider text-[var(--color-fg-4)]`,children:`Featured`}),(0,D.jsx)(`div`,{className:`flex gap-3 overflow-x-auto pb-2`,children:r.map(e=>(0,D.jsx)(op,{plugin:e,installed:a.has(e.id),busy:o[e.id]===`install`,onInstall:()=>l(e)},e.id))})]}),(0,D.jsxs)(`section`,{children:[i&&(0,D.jsx)(`div`,{className:`mb-2 text-xs font-medium uppercase tracking-wider text-[var(--color-fg-4)]`,children:`All Plugins`}),(0,D.jsx)(`div`,{className:`grid grid-cols-1 gap-3 lg:grid-cols-2`,children:n.map(e=>{let t=a.has(e.id),n=o[e.id]===`install`;return(0,D.jsx)(K,{variant:t?`default`:`interactive`,children:(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,D.jsx)(np,{name:e.name,icon:e.icon}),(0,D.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,D.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),e.verified&&(0,D.jsx)(rp,{}),(0,D.jsxs)(W,{variant:`outline`,children:[`v`,e.version]}),t&&(0,D.jsx)(W,{variant:`green`,children:`Installed`})]}),e.category&&(0,D.jsx)(`div`,{className:`mt-1`,children:(0,D.jsx)(`span`,{className:`inline-flex items-center rounded-sm border px-1 py-px text-[9px] font-mono font-medium uppercase tracking-wide ${Qf(e.category)}`,children:e.category})}),e.description&&(0,D.jsx)(`p`,{className:`mt-1 line-clamp-2 text-xs text-[var(--color-fg-3)]`,children:e.description}),(0,D.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-[var(--color-fg-4)]`,children:[e.author_github&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`span`,{children:[`by`,` `,(0,D.jsxs)(`a`,{href:`https://github.com/${e.author_github}`,target:`_blank`,rel:`noreferrer`,className:`hover:text-[var(--color-fg-2)] hover:underline`,children:[`@`,e.author_github]})]}),(0,D.jsx)(`span`,{children:`·`})]}),(0,D.jsxs)(`span`,{children:[ep(e.install_count),` installs`]}),e.platforms.length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{children:`·`}),(0,D.jsx)(`span`,{title:`Supports ${e.platforms.join(`, `)}`,children:e.platforms.length===1?e.platforms[0]:`${e.platforms.length} platforms`})]})]})]}),(0,D.jsx)(`div`,{className:`shrink-0`,children:(0,D.jsx)(G,{variant:t?`ghost`:`primary`,size:`sm`,disabled:t||n,onClick:()=>l(e),children:t?`Installed`:n?`Installing…`:`Install`})})]})})},e.id)})})]})]})}function cp({features:e,onToggle:t}){return(0,D.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,D.jsx)(`p`,{className:`text-xs text-[var(--color-fg-3)]`,children:`Bundled with the dashboard but opt-in. These features ship inside the ssg binary and run in-process; they don't need a separate install but stay dormant until enabled here.`}),(0,D.jsx)(`div`,{className:`grid grid-cols-1 gap-3 lg:grid-cols-2`,children:Mf.map(n=>{let r=e[n.id];return(0,D.jsx)(K,{children:(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,D.jsx)(`div`,{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-md bg-[var(--color-surface-2)] text-lg leading-none`,children:(0,D.jsx)(`span`,{"aria-hidden":!0,children:n.icon})}),(0,D.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`truncate font-medium`,children:n.name}),(0,D.jsx)(W,{variant:`gray`,children:`Built-in`}),r?(0,D.jsx)(W,{variant:`green`,children:`Enabled`}):(0,D.jsx)(W,{variant:`amber`,children:`Disabled`})]}),(0,D.jsx)(`p`,{className:`mt-1 text-xs text-[var(--color-fg-3)]`,children:n.description}),(0,D.jsx)(`div`,{className:`mt-2 text-[11px] text-[var(--color-fg-4)]`,children:`No download · runs in your browser`})]}),(0,D.jsx)(`div`,{className:`shrink-0`,children:(0,D.jsx)(G,{variant:r?`ghost`:`primary`,size:`sm`,onClick:()=>t(n.id,!r),children:r?`Disable`:`Enable`})})]})})},n.id)})})]})}function lp({loading:e,installed:t,iconById:n,busy:r,onEnable:i,onDisable:a,onUninstall:o}){return e&&t.length===0?(0,D.jsx)(`div`,{className:`grid grid-cols-1 gap-3 lg:grid-cols-2`,children:Array.from({length:2}).map((e,t)=>(0,D.jsx)(ip,{},t))}):t.length===0?(0,D.jsx)(K,{children:(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`flex flex-col gap-2 py-4 text-sm text-[var(--color-fg-3)]`,children:[(0,D.jsx)(`div`,{className:`font-medium text-[var(--color-fg-1)]`,children:`No plugins installed yet.`}),(0,D.jsx)(`div`,{children:`Switch to the Browse tab to discover plugins from the hub.`})]})})}):(0,D.jsx)(`div`,{className:`grid grid-cols-1 gap-3 lg:grid-cols-2`,children:t.map(e=>{let t=r[e.id]===`toggle`,s=r[e.id]===`uninstall`;return(0,D.jsx)(K,{children:(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,D.jsx)(np,{name:e.name,icon:e.icon??n.get(e.id)??null}),(0,D.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,D.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),(0,D.jsxs)(W,{variant:`outline`,children:[`v`,e.version]}),e.enabled?(0,D.jsx)(W,{variant:`green`,children:`Enabled`}):(0,D.jsx)(W,{variant:`amber`,children:`Disabled`})]}),e.category&&(0,D.jsx)(`div`,{className:`mt-1`,children:(0,D.jsx)(`span`,{className:`inline-flex items-center rounded-sm border px-1 py-px text-[9px] font-mono font-medium uppercase tracking-wide ${Qf(e.category)}`,children:e.category})}),e.description&&(0,D.jsx)(`p`,{className:`mt-1 line-clamp-2 text-xs text-[var(--color-fg-3)]`,children:e.description}),(0,D.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-[var(--color-fg-4)]`,children:[(0,D.jsx)(`span`,{className:`font-mono`,children:e.id}),(0,D.jsx)(`span`,{children:`·`}),(0,D.jsxs)(`span`,{title:e.signing_fingerprint,children:[`sig`,` `,(0,D.jsxs)(`span`,{className:`font-mono`,children:[e.signing_fingerprint.slice(0,12),`…`]})]}),(0,D.jsx)(`span`,{children:`·`}),(0,D.jsxs)(`span`,{title:e.installed_at,children:[`installed `,$f(e.installed_at)]}),e.nav.length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{children:`·`}),(0,D.jsxs)(`span`,{children:[e.nav.length,` nav`,` `,e.nav.length===1?`entry`:`entries`]})]})]}),(e.homepage_url||e.repo_url)&&(0,D.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-x-3 gap-y-0.5 text-[11px]`,children:[e.homepage_url&&(0,D.jsx)(`a`,{href:e.homepage_url,target:`_blank`,rel:`noreferrer`,className:`text-[var(--color-hig-blue)] hover:underline`,children:`Homepage`}),e.repo_url&&(0,D.jsx)(`a`,{href:e.repo_url,target:`_blank`,rel:`noreferrer`,className:`text-[var(--color-hig-blue)] hover:underline`,children:`Repository`})]})]}),(0,D.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-1.5`,children:[e.enabled?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(G,{variant:`primary`,size:`sm`,onClick:()=>{window.location.href=`/plugins/${e.id}`},children:`Open`}),(0,D.jsx)(G,{variant:`ghost`,size:`sm`,disabled:t,onClick:()=>a(e),children:t?`Disabling…`:`Disable`})]}):(0,D.jsx)(G,{variant:`secondary`,size:`sm`,disabled:t,onClick:()=>i(e),children:t?`Enabling…`:`Enable`}),(0,D.jsx)(G,{variant:`ghost`,size:`sm`,disabled:s,onClick:()=>o(e),children:s?`Removing…`:`Uninstall`})]})]})})},e.id)})})}function up(e){return e<1e6?`${(e/1e3).toFixed(0)}µs`:e<1e9?`${(e/1e6).toFixed(1)}ms`:`${(e/1e9).toFixed(2)}s`}function dp(e){return new Date(e*1e3).toLocaleString()}var fp={critical:`red`,high:`red`,medium:`amber`,low:`blue`},pp={critical:`border-l-red-500/70`,high:`border-l-red-500/50`,medium:`border-l-amber-400/60`,low:`border-l-sky-400/50`};function mp(){let{data:e}=k(`/api/json/profile`);if(!e)return(0,D.jsx)(`p`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)]`,children:`loading profile…`});let{diagnosis:t,sessions:n}=e;return!t||t.analyzed_evals===0?(0,D.jsx)(`div`,{className:`rounded-sm border border-dashed border-[var(--color-line-1)] bg-[var(--color-surface-1)]/50 px-4 py-6 text-center`,children:(0,D.jsxs)(`p`,{className:`text-[12px] text-[var(--color-fg-2)] font-mono`,children:[`no eval data yet — run`,` `,(0,D.jsx)(`code`,{className:`text-[var(--color-brand)]`,children:`ssg eval`}),` to start recording`]})}):(0,D.jsxs)(`div`,{className:`space-y-5`,children:[(0,D.jsx)(`div`,{"data-tutorial":`profile-metrics`,className:`grid grid-cols-2 lg:grid-cols-4 gap-2`,children:[{label:`evals analyzed`,value:String(t.analyzed_evals)},{label:`median (inside)`,value:up(t.median_eval_ns)},{label:`p99 (inside)`,value:up(t.p99_eval_ns)},{label:`bottleneck`,value:t.bottleneck??`—`}].map(e=>(0,D.jsx)(Ol,{label:e.label,value:e.value,labelPlacement:`above`,valueClassName:`text-xl font-medium tabular-nums text-[var(--color-fg-0)]`},e.label))}),t.phases.length>0&&(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsx)(`span`,{className:`overline`,children:`phase breakdown`})}),(0,D.jsx)(J,{children:(0,D.jsx)(`div`,{className:`space-y-2`,children:t.phases.filter(e=>e.median_ns>0).map(e=>{let n=e.name===t.bottleneck;return(0,D.jsxs)(`div`,{className:`flex items-center gap-3 text-xs`,children:[(0,D.jsx)(`span`,{className:`w-28 font-mono truncate ${n?`text-[var(--color-brand)] font-medium`:`text-[var(--color-fg-2)]`}`,title:n?`bottleneck`:void 0,children:e.name}),(0,D.jsx)(Al,{pct:Math.min(e.pct_of_total,100),tone:n?`amber`:`gray`,className:`h-1 flex-1`}),(0,D.jsx)(`span`,{className:`w-16 text-right text-[var(--color-fg-1)] tabular-nums font-mono`,children:up(e.median_ns)}),(0,D.jsxs)(`span`,{className:`w-10 text-right text-[var(--color-fg-3)] tabular-nums font-mono`,children:[e.pct_of_total,`%`]}),(0,D.jsxs)(`span`,{className:`w-20 text-right text-[var(--color-fg-4)] tabular-nums font-mono text-[10px]`,children:[`p95 `,up(e.p95_ns)]})]},e.name)})})})]}),t.recommendations.length>0&&(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsxs)(`span`,{className:`overline`,children:[`recommendations · `,t.recommendations.length]})}),(0,D.jsx)(J,{className:`space-y-2`,children:t.recommendations.map((e,t)=>(0,D.jsxs)(`div`,{className:`border border-[var(--color-line-1)] bg-[var(--color-surface-0)] rounded-sm px-3 py-2.5 border-l-2 ${pp[e.severity]??`border-l-[var(--color-line-2)]`}`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,D.jsx)(W,{variant:fp[e.severity]??`gray`,children:e.severity}),(0,D.jsx)(`span`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)]`,children:e.type})]}),(0,D.jsx)(`p`,{className:`text-sm text-[var(--color-fg-1)] leading-relaxed`,children:e.message}),e.fix_command&&(0,D.jsxs)(`code`,{className:`text-[11px] text-[var(--color-brand)] font-mono mt-1.5 block`,children:[`$ `,e.fix_command]})]},t))})]}),t.anomalies.length>0&&(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsxs)(`span`,{className:`overline`,children:[`anomalies · `,t.anomalies.length]})}),(0,D.jsx)(J,{children:(0,D.jsx)(`div`,{className:`divide-y divide-[var(--color-line-0)]`,children:t.anomalies.map((e,t)=>(0,D.jsxs)(`div`,{className:`py-2 flex items-center gap-4 text-xs font-mono`,children:[(0,D.jsx)(`span`,{className:`w-24 text-[var(--color-brand)] uppercase tracking-wider text-[10px]`,children:e.type}),(0,D.jsxs)(`span`,{className:`w-10 tabular-nums text-[var(--color-fg-1)]`,children:[e.count,`×`]}),(0,D.jsxs)(`span`,{className:`w-20 tabular-nums text-[var(--color-fg-1)]`,children:[e.max_ms,`ms max`]}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)]`,children:e.likely_cause})]},t))})})]}),n.length>0&&(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`session history`}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)] tabular-nums`,children:[n.length,` session`,n.length===1?``:`s`]})]}),(0,D.jsx)(J,{className:`p-0`,children:(0,D.jsx)(`div`,{className:`divide-y divide-[var(--color-line-0)]`,children:[...n].reverse().map((e,t)=>(0,D.jsxs)(`div`,{className:`px-4 py-2.5 flex flex-wrap items-center gap-x-5 gap-y-1 text-xs ${e.is_current?`bg-amber-400/[0.04] border-l-2 border-l-amber-400/60`:``}`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 w-48 shrink-0`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] tabular-nums font-mono`,children:dp(e.start_ts)}),e.is_current&&(0,D.jsx)(W,{variant:`amber`,children:`current`})]}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-2)] tabular-nums font-mono w-20`,children:[e.evals,` eval`,e.evals===1?``:`s`]}),(0,D.jsxs)(`span`,{className:`text-emerald-300 tabular-nums font-mono`,children:[e.allowed,` allow`]}),e.blocked>0&&(0,D.jsxs)(`span`,{className:`text-red-300 tabular-nums font-mono`,children:[e.blocked,` block (`,e.block_rate_pct,`%)`]}),e.asked>0&&(0,D.jsxs)(`span`,{className:`text-sky-300 tabular-nums font-mono`,children:[e.asked,` ask`]}),e.forced>0&&(0,D.jsxs)(`span`,{className:`text-violet-300 tabular-nums font-mono`,children:[e.forced,` force`]}),e.avg_ns>0&&(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-3)] tabular-nums ml-auto font-mono`,children:[`avg `,up(e.avg_ns)]}),e.top_rule&&(0,D.jsxs)(`a`,{href:`/rules?highlight=${encodeURIComponent(e.top_rule)}`,className:`text-[var(--color-fg-4)] hover:text-[var(--color-brand)] font-mono truncate max-w-xs transition-colors w-full pl-48`,title:`most blocked rule: ${e.top_rule}`,children:[`top block: `,e.top_rule]})]},t))})})]})]})}var hp={log:`text-[var(--color-fg-1)]`,info:`text-sky-300`,warn:`text-amber-300`,error:`text-red-300`,debug:`text-[var(--color-fg-3)]`};function gp(e){return e.value==null?e.description?e.description:`[${e.type}]`:String(e.value)}function _p(){let e=df(),[t,n]=(0,_.useState)(!1),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(!1),d=(0,_.useRef)(null),f=(0,_.useRef)(0);(0,_.useEffect)(()=>{d.current?.scrollIntoView({behavior:`smooth`})},[]),(0,_.useEffect)(()=>{if(e.connected)return e.sendCommand(`Runtime.enable`).catch(()=>{}),e.onEvent(`Runtime.consoleAPICalled`,e=>{let t=e;o(e=>{let n=[...e,{id:f.current++,type:t.type??`log`,args:t.args??[],timestamp:t.timestamp??Date.now()}];return n.length>500?n.slice(-500):n})})},[e.connected,e.sendCommand,e.onEvent]);let p=(0,_.useCallback)(()=>{e.preconfiguredTarget&&e.connect(e.preconfiguredTarget.id)},[e]),m=(0,_.useCallback)(async()=>{try{await e.sendCommand(`Profiler.enable`),await e.sendCommand(`Profiler.start`),n(!0),i(null)}catch(e){console.error(`Profiler.start failed:`,e)}},[e]),h=(0,_.useCallback)(async()=>{try{let t=await e.sendCommand(`Profiler.stop`);n(!1),i(t.profile)}catch(e){console.error(`Profiler.stop failed:`,e),n(!1)}},[e]),g=(0,_.useCallback)(async()=>{u(!0);try{let t=await e.sendCommand(`Runtime.evaluate`,{expression:`JSON.stringify(process.memoryUsage())`,returnByValue:!0});c(JSON.parse(t.result.value))}catch{}finally{u(!1)}},[e]);function v(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/1024/1024).toFixed(1)}MB`}let y=e.connected?`connected${e.bunVersion?` · bun v${e.bunVersion}`:``}`:e.connecting?`connecting…`:e.active?`inspector active, connecting…`:`inspector not available`,b=e.connected?`bg-emerald-400`:e.connecting?`bg-amber-400 pulse-soft`:e.active?`bg-sky-400`:`bg-[var(--color-line-2)]`;return(0,D.jsxs)(`div`,{className:`space-y-5`,children:[(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`runtime inspector`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] font-mono text-[var(--color-fg-2)]`,children:[(0,D.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full ${b}`}),y]}),e.connected?(0,D.jsx)(G,{variant:`ghost`,size:`sm`,onClick:e.disconnect,children:`disconnect`}):(0,D.jsx)(G,{variant:`ghost`,size:`sm`,onClick:e.preconfiguredTarget?p:e.refetch,disabled:e.connecting,children:e.preconfiguredTarget?`reconnect`:`refresh`})]})]}),e.error&&(0,D.jsx)(J,{children:(0,D.jsx)(`p`,{className:`text-xs text-red-300 font-mono`,children:e.error})})]}),e.connected&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`cpu profiler`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t&&(0,D.jsxs)(`span`,{className:`text-[10px] font-mono uppercase tracking-wider text-red-300 flex items-center gap-1.5`,children:[(0,D.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-red-400 pulse-soft`}),`recording`]}),t?(0,D.jsx)(G,{variant:`danger`,size:`sm`,onClick:h,children:`stop & render`}):(0,D.jsx)(G,{variant:`primary`,size:`sm`,onClick:m,children:`start recording`})]})]}),(0,D.jsx)(J,{children:r?(0,D.jsx)(Ml,{profile:r,children:(0,D.jsx)(`div`,{className:`bg-[var(--color-surface-0)] border border-[var(--color-line-1)] rounded-sm p-2 overflow-x-hidden`,children:(0,D.jsx)(of,{profile:r})})}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:t?`recording… perform actions in ssg, then stop.`:`click start recording, perform actions, then stop.`})})]}),(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`memory`}),(0,D.jsx)(G,{variant:`ghost`,size:`sm`,onClick:g,disabled:l,children:l?`…`:`refresh`})]}),(0,D.jsx)(J,{children:s?(0,D.jsx)(Nl,{memory:s,formatValue:v}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:`click refresh to fetch process.memoryUsage().`})})]}),(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`console`}),(0,D.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>o([]),children:`clear`})]}),(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`bg-[var(--color-surface-0)] border border-[var(--color-line-1)] rounded-sm p-2 h-56 overflow-y-auto font-mono text-[11px]`,children:[a.length===0?(0,D.jsx)(`p`,{className:`text-[var(--color-fg-4)]`,children:`console output will appear here…`}):a.map(e=>(0,D.jsxs)(`div`,{className:`py-0.5 border-b border-[var(--color-line-0)] ${hp[e.type]??`text-[var(--color-fg-1)]`}`,children:[(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)] mr-2 uppercase tracking-wider`,children:[`[`,e.type,`]`]}),e.args.map(gp).join(` `)]},e.id)),(0,D.jsx)(`div`,{ref:d})]})})]})]}),!e.connected&&!e.connecting&&(0,D.jsx)(`div`,{className:`rounded-sm border border-dashed border-[var(--color-line-1)] bg-[var(--color-surface-1)]/50 px-4 py-6 text-center`,children:(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:e.active?`waiting for inspector connection…`:`inspector auto-starts with ssg serve. profiler, memory, and console appear here once connected.`})})]})}function vp({active:e,onClick:t,children:n}){return(0,D.jsxs)(`button`,{onClick:t,className:`relative px-3 h-9 text-[11px] font-mono uppercase tracking-wider transition-colors cursor-pointer ${e?`text-[var(--color-fg-0)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,children:[n,e&&(0,D.jsx)(`span`,{className:`absolute inset-x-2 -bottom-px h-px bg-[var(--color-brand)]`})]})}function yp(){let[e,t]=(0,_.useState)(`eval`);return(0,D.jsxs)(`div`,{className:`space-y-0`,children:[(0,D.jsxs)(`div`,{"data-tutorial":`profile-tabs`,className:`flex items-center border-b border-[var(--color-line-0)] mb-5`,children:[(0,D.jsx)(vp,{active:e===`eval`,onClick:()=>t(`eval`),children:`eval profile`}),(0,D.jsx)(vp,{active:e===`inspector`,onClick:()=>t(`inspector`),children:`runtime inspector`})]}),e===`eval`?(0,D.jsx)(mp,{}):(0,D.jsx)(_p,{})]})}var bp=[{id:`destructive-ops`,title:`Destructive Operations`,description:`Commands that delete, overwrite, truncate, or irreversibly destroy files, data, or infrastructure.`,icon:`💥`,color:`#FF3B30`,attack:{id:`TA0040`,name:`Impact`},d3fend:`Harden`,security:!0,order:1},{id:`privilege-escalation`,title:`Privilege Escalation`,description:`sudo, permission and ownership changes, setuid manipulation, and capability grants.`,icon:`⬆️`,color:`#FF9500`,attack:{id:`TA0004`,name:`Privilege Escalation`},d3fend:`Isolate`,security:!0,order:2},{id:`code-execution`,title:`Untrusted Code Execution`,description:`Piping remote content into a shell, dynamic interpreters, and execution of unvetted code.`,icon:`⚙️`,color:`#FFCC00`,attack:{id:`TA0002`,name:`Execution`},d3fend:`Harden`,security:!0,order:3},{id:`credential-access`,title:`Credential & Secret Access`,description:`Reads of secrets, private keys, tokens, .env files, and cloud credentials.`,icon:`🔑`,color:`#AF52DE`,attack:{id:`TA0006`,name:`Credential Access`},d3fend:`Detect`,security:!0,order:4},{id:`network-egress`,title:`Network Egress & Exfiltration`,description:`Outbound network calls, uploads, reverse shells, and data leaving the machine.`,icon:`🌐`,color:`#5AC8FA`,attack:{id:`TA0010`,name:`Exfiltration`},d3fend:`Isolate`,security:!0,order:5},{id:`supply-chain`,title:`Supply Chain & Dependencies`,description:`Package installs, lockfile edits, registry changes, and dependency tampering.`,icon:`📦`,color:`#34C759`,attack:{id:`TA0042`,name:`Resource Development`},d3fend:`Harden`,security:!0,order:6},{id:`process-control`,title:`Process & System Control`,description:`Killing processes, daemonizing, service control, and resource exhaustion.`,icon:`🔌`,color:`#FF6482`,attack:{id:`TA0003`,name:`Persistence`},d3fend:`Isolate`,security:!0,order:7},{id:`version-control`,title:`Version Control Integrity`,description:`Force pushes, history rewrites, branch deletion, and git remote safety.`,icon:`🔀`,color:`#30B0C7`,attack:{id:`TA0005`,name:`Defense Evasion`},d3fend:`Harden`,security:!0,order:8},{id:`source-integrity`,title:`Source & Config Integrity`,description:`Edits to protected, generated, CI/CD, or governance-critical files.`,icon:`📐`,color:`#A2845E`,attack:{id:`TA0003`,name:`Persistence`},d3fend:`Harden`,security:!0,order:9},{id:`data-handling`,title:`Sensitive Data Handling`,description:`Database mutations, PII handling, and redaction of sensitive output.`,icon:`🗄️`,color:`#BF5AF2`,attack:{id:`TA0009`,name:`Collection`},d3fend:`Detect`,security:!0,order:10},{id:`agent-hygiene`,title:`Agent Hygiene & Efficiency`,description:`Tool-use best practices, token efficiency, and prompt hygiene — operational, not a security control.`,icon:`🧭`,color:`#8E8E93`,attack:null,d3fend:`Model`,security:!1,order:11},{id:`uncategorized`,title:`Uncategorized`,description:`Rules that have not declared a category.`,icon:`▫️`,color:`#636366`,attack:null,d3fend:`Model`,security:!1,order:99}],xp=new Map(bp.map(e=>[e.id,e]));bp.filter(e=>e.id!==`uncategorized`).map(e=>e.id);function Sp(e){return typeof e==`string`&&e!==`uncategorized`&&xp.has(e)}function Cp(e){return e!==void 0&&xp.get(e)||xp.get(`uncategorized`)}var wp=[{token:`destructive`,category:`destructive-ops`},{token:`exfil`,category:`network-egress`},{token:`credential`,category:`credential-access`},{token:`secret`,category:`credential-access`},{token:`privilege`,category:`privilege-escalation`},{token:`privesc`,category:`privilege-escalation`},{token:`powergate`,category:`process-control`},{token:`process`,category:`process-control`},{token:`powersafety`,category:`process-control`},{token:`injection`,category:`code-execution`},{token:`untrusted`,category:`code-execution`},{token:`supply`,category:`supply-chain`},{token:`dependenc`,category:`supply-chain`},{token:`npm`,category:`supply-chain`},{token:`pnpm`,category:`supply-chain`},{token:`cargo`,category:`supply-chain`},{token:`cicd`,category:`supply-chain`},{token:`publish`,category:`supply-chain`},{token:`git`,category:`version-control`},{token:`network`,category:`network-egress`},{token:`egress`,category:`network-egress`},{token:`database`,category:`data-handling`},{token:`sql`,category:`data-handling`},{token:`critical`,category:`source-integrity`},{token:`drm`,category:`source-integrity`},{token:`config`,category:`source-integrity`},{token:`integrity`,category:`source-integrity`},{token:`infra`,category:`source-integrity`},{token:`agent`,category:`agent-hygiene`},{token:`efficiency`,category:`agent-hygiene`},{token:`hygiene`,category:`agent-hygiene`}];function Tp(e,t){let n=(t??e.source_file??``).toLowerCase(),r=n?n.split(/[\\/]/).pop()??n:``,i=`${e.id.toLowerCase()} ${r}`;for(let e of wp)if(i.includes(e.token))return e.category;return e.target===`agent`?`agent-hygiene`:e.target===`network`?`network-egress`:`uncategorized`}function Ep(e,t){return e.category!==void 0&&Sp(e.category)?e.category:Tp(e,t)}function Dp(e,t){let n=new Map;for(let e of bp)n.set(e.id,{id:e.id,meta:e,total:0,enabled:0,enabledShell:0,decisions:{},status:`gap`});let r=0;for(let i of e){let e=Ep(i,t?.(i)),a=n.get(e);a.total++,e===`uncategorized`&&r++,i.enabled!==!1&&(a.enabled++,a.decisions[i.decision]=(a.decisions[i.decision]??0)+1,(i.target===`execution`||i.target===`any`)&&a.enabledShell++)}for(let e of n.values())e.status=e.enabled>0?`covered`:e.total>0?`inactive`:`gap`;let i=[...n.values()].sort((e,t)=>e.meta.order-t.meta.order),a=i.filter(e=>e.meta.security&&e.id!==`uncategorized`);return{categories:i,covered:a.filter(e=>e.status===`covered`).length,total:a.length,uncategorized:r}}var Op=new Set([`block`,`ask`,`force`,`deny`]),kp=[`rules-changed`],Ap=[`block`,`ask`,`log`,`allow`,`force`,`shadow`],jp={block:`text-red-300`,deny:`text-red-300`,ask:`text-sky-300`,allow:`text-emerald-300`,log:`text-[var(--color-fg-3)]`,force:`text-amber-300`,shadow:`text-violet-300`,ambient:`text-teal-300`},Mp={block:`#fca5a5`,deny:`#fca5a5`,ask:`#7dd3fc`,allow:`#6ee7b7`,log:`#a8a29e`,force:`#fcd34d`,shadow:`#c4b5fd`},Np=[{value:`today`,label:`today`},{value:`7d`,label:`7d`},{value:`30d`,label:`30d`},{value:`all`,label:`all`}],Pp=5e3;function Fp(e,t){return t<=0?e:`${e}${e.includes(`?`)?`&`:`?`}_t=${t}`}async function Ip(e,t){await fetch(`/api/rules/toggle`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`,...U()},body:JSON.stringify({ruleId:e,file:t})})}async function Lp(e,t,n){await fetch(`/api/rules/update-decision`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({ruleId:e,file:t,decision:n})})}async function Rp(e,t){return fetch(`/api/rules/bulk-set-enabled`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({targets:e,enabled:t})}).then(e=>e.json())}async function zp(e,t){return fetch(`/api/rules/bulk-update-decision`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({targets:e,decision:t})}).then(e=>e.json())}async function Bp(e){return fetch(`/api/rules/bulk-delete`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({targets:e})}).then(e=>e.json())}async function Vp(e,t={}){return fetch(`/api/rules/${e}`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify(t)}).then(e=>e.json())}function Hp(e){if(!e)return`never`;let t=Date.now()/1e3-e;return t<60?`${Math.floor(t)}s ago`:t<3600?`${Math.floor(t/60)}m ago`:t<86400?`${Math.floor(t/3600)}h ago`:`${Math.floor(t/86400)}d ago`}function Up(e,t,n,r){let i=Array(t).fill(0);if(!e||e.length===0)return i;let a=Date.now(),o=a-n,s=n/t;for(let n of e){let e=n.timestamp*1e3;if(e<o||e>a||r&&!r(n))continue;let c=Math.min(t-1,Math.floor((e-o)/s));i[c]+=1}return i}function Wp({active:e}){return(0,D.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] font-mono uppercase tracking-wider`,children:[(0,D.jsxs)(`span`,{className:`relative inline-flex h-2 w-2`,children:[e&&(0,D.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full bg-emerald-400/60`}),(0,D.jsx)(`span`,{className:`relative inline-flex h-2 w-2 rounded-full ${e?`bg-emerald-400`:`bg-[var(--color-fg-4)]`}`})]}),(0,D.jsx)(`span`,{className:e?`text-emerald-300`:`text-[var(--color-fg-4)]`,children:e?`live`:`paused`})]})}function Gp({mode:e,onChange:t}){return(0,D.jsxs)(`div`,{className:`flex items-center text-[10px] font-mono uppercase tracking-wider border border-[var(--color-line-1)] rounded-sm overflow-hidden`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:()=>t(`newcomer`),className:`px-2 py-1 cursor-pointer transition-colors ${e===`newcomer`?`bg-[var(--color-brand)]/15 text-[var(--color-fg-0)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,title:`Hide advanced controls (firewall, raw source, audit, AI hints)`,children:`simple`}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>t(`pro`),className:`px-2 py-1 cursor-pointer transition-colors border-l border-[var(--color-line-1)] ${e===`pro`?`bg-[var(--color-brand)]/15 text-[var(--color-fg-0)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,title:`Show everything: top-rules chart, performance, firewall, audit trails, raw source, curl recipes`,children:`advanced`})]})}function Kp({rule:e,file:t,onToggle:n}){let[r,i]=(0,_.useState)(!1);return(0,D.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,D.jsx)(`span`,{className:`text-[10px] font-mono uppercase tracking-wider ${e.enabled?`text-[var(--color-fg-1)]`:`text-[var(--color-fg-4)]`}`,children:e.enabled?`on`:`off`}),(0,D.jsx)(rn,{size:`sm`,checked:e.enabled,disabled:r,label:`${e.enabled?`Disable`:`Enable`} rule ${e.id}`,onChange:async()=>{i(!0);try{await n()}finally{i(!1)}}})]})}function qp(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(!1);(0,_.useEffect)(()=>{let e=!1;return(async()=>{try{let n=await fetch(`/api/json/rule-write-enforcement`,{headers:{Accept:`application/json`}});if(!n.ok)return;let r=await n.json();!e&&typeof r.enforced==`boolean`&&t(r.enforced)}catch{}})(),()=>{e=!0}},[]);async function o(e){r(!0);try{let n=await fetch(`/api/json/rule-write-enforcement`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({enforced:e})});if(n.ok){let e=await n.json();typeof e.enforced==`boolean`&&t(e.enforced)}}finally{r(!1),a(!1)}}if(e===null)return null;let s=!e;return(0,D.jsx)(K,{className:s?`border-amber-500/40 bg-amber-500/5`:`border-[var(--color-line-1)]`,children:(0,D.jsx)(J,{className:`px-3 py-2.5`,children:(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,D.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-1)]`,children:`rule-write protection`}),(0,D.jsx)(`span`,{className:`text-[11px] font-mono uppercase tracking-wider ${s?`text-amber-300`:`text-emerald-300`}`,children:s?`disabled`:`enforced`})]}),(0,D.jsx)(`p`,{className:`text-[11px] text-[var(--color-fg-3)] mt-1 leading-snug`,children:s?`Agents can currently Write/Edit .rules files. Turn this back on when you finish authoring.`:`Agents cannot Write/Edit/MultiEdit any .sigmashake/rules/**/*.rules file. Disable only when curating rulesets.`})]}),(0,D.jsx)(`div`,{className:`shrink-0`,children:i?(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,D.jsx)(`button`,{onClick:()=>o(!1),disabled:n,className:`text-[11px] font-mono uppercase tracking-wider bg-amber-500/10 border border-amber-500/40 text-amber-200 hover:bg-amber-500/20 rounded-sm px-2 py-0.5 cursor-pointer transition-colors disabled:opacity-50`,children:`disable`}),(0,D.jsx)(`button`,{onClick:()=>a(!1),disabled:n,className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer disabled:opacity-50`,children:`cancel`})]}):(0,D.jsx)(`button`,{onClick:()=>{e?a(!0):o(!0)},disabled:n,className:`text-[11px] font-mono uppercase tracking-wider border rounded-sm px-2.5 py-0.5 cursor-pointer transition-colors disabled:opacity-50 ${s?`bg-emerald-500/10 border-emerald-500/40 text-emerald-200 hover:bg-emerald-500/20`:`bg-[var(--color-surface-1)] border-[var(--color-line-1)] text-[var(--color-fg-1)] hover:bg-[var(--color-surface-2)]`}`,children:s?`enable`:`disable`})})]})})})}function Jp({perf:e,triggers:t,decisionAggregates:n,livePoll:r,onTogglePoll:i,statsWindow:a,onWindowChange:o,mode:s,onModeChange:c}){let l=t?.evalsLast60s??0,u=t?.evalsLastHour??0,d=(0,_.useMemo)(()=>Up(t?.rows,30,3600*1e3),[t?.rows]),f=(0,_.useMemo)(()=>Up(t?.rows,30,3600*1e3,e=>Op.has(e.decision)),[t?.rows]),p={allow:n.hits.allow??0,block:n.hits.block??0,ask:n.hits.ask??0,log:n.hits.log??0,force:n.hits.force??0,shadow:n.hits.shadow??0},m=Object.values(p).reduce((e,t)=>e+t,0),h=e?.totalRules??0,g=e?.activeRules??0,v=h>0?g/h*100:0,y=l/60;return(0,D.jsx)(K,{className:`border-[var(--color-line-1)]`,children:(0,D.jsxs)(J,{className:`px-4 py-3 space-y-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline text-[10px]`,children:`rules active`}),(0,D.jsxs)(`div`,{className:`font-mono text-2xl text-[var(--color-fg-0)] tabular-nums leading-none mt-0.5`,children:[(0,D.jsx)(Ks,{value:g}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)] text-base`,children:[`/`,h]})]}),(0,D.jsxs)(`div`,{className:`overline text-[10px] mt-1 text-[var(--color-fg-3)]`,children:[v.toFixed(0),`% on`]})]}),(0,D.jsx)(`div`,{className:`h-12 w-px bg-[var(--color-line-1)] hidden md:block`}),(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`overline text-[10px]`,children:`evals · last 60s`}),(0,D.jsx)(Wp,{active:r})]}),(0,D.jsx)(`div`,{className:`font-mono text-2xl text-emerald-300 tabular-nums leading-none mt-0.5`,children:(0,D.jsx)(Ks,{value:l,curve:`spring`})}),(0,D.jsxs)(`div`,{className:`overline text-[10px] mt-1 text-[var(--color-fg-3)]`,children:[`~`,y.toFixed(1),`/s`]})]}),(0,D.jsx)(`div`,{className:`h-12 w-px bg-[var(--color-line-1)] hidden md:block`}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline text-[10px]`,children:`last hour`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,D.jsx)(`span`,{className:`font-mono text-2xl text-[var(--color-fg-1)] tabular-nums leading-none`,children:(0,D.jsx)(Ks,{value:u})}),(0,D.jsx)(Js,{data:d,width:120,height:32,color:`var(--color-brand)`})]}),(0,D.jsx)(`div`,{className:`overline text-[10px] mt-1 text-[var(--color-fg-3)]`,children:`evals · 2-min buckets`})]}),(0,D.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,D.jsx)(Gp,{mode:s,onChange:c}),(0,D.jsx)(`button`,{type:`button`,onClick:i,className:`text-[10px] font-mono uppercase tracking-wider px-2 py-1 rounded-sm border border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer transition-colors`,title:r?`Pause auto-refresh`:`Resume auto-refresh`,children:r?`⏸ pause`:`▶ resume`}),(0,D.jsx)(`div`,{className:`flex items-center text-[10px] font-mono uppercase tracking-wider border border-[var(--color-line-1)] rounded-sm`,children:Np.map((e,t)=>(0,D.jsx)(`button`,{onClick:()=>o(e.value),className:`px-1.5 py-1 cursor-pointer transition-colors ${t>0?`border-l border-[var(--color-line-1)]`:``} ${a===e.value?`bg-[var(--color-brand)]/15 text-[var(--color-fg-0)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,children:e.label},e.value))})]})]}),(m>0||f.some(e=>e>0))&&(0,D.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-[1.4fr_1fr] gap-4 pt-2 border-t border-[var(--color-line-0)]`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,D.jsxs)(`span`,{className:`overline text-[10px]`,children:[`decision mix · `,a]}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)] tabular-nums`,children:[m.toLocaleString(),` hits`]})]}),(0,D.jsx)(qs,{counters:p,showLegend:!0})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,D.jsx)(`span`,{className:`overline text-[10px]`,children:`block/ask/force · last hour`}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-amber-300 tabular-nums`,children:[f.reduce((e,t)=>e+t,0),` actionable`]})]}),(0,D.jsx)(Js,{data:f,width:400,height:48,color:`#fca5a5`})]})]})]})})}function Yp({perf:e}){if(!e)return null;let t=e.avgEvalMs>50?`text-amber-300`:e.avgEvalMs>100?`text-red-300`:`text-emerald-300`;return(0,D.jsx)(K,{children:(0,D.jsxs)(J,{className:`px-3 py-2.5`,children:[(0,D.jsxs)(`div`,{className:`flex items-baseline gap-4 flex-wrap`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline text-[10px]`,children:`avg eval`}),(0,D.jsxs)(`div`,{className:`font-mono text-sm tabular-nums ${t}`,children:[e.avgEvalMs.toFixed(1),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] ml-0.5 text-[10px]`,children:`ms`})]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline text-[10px]`,children:`p95`}),(0,D.jsxs)(`div`,{className:`font-mono text-sm text-[var(--color-fg-1)] tabular-nums`,children:[e.p95EvalMs.toFixed(1),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] ml-0.5 text-[10px]`,children:`ms`})]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline text-[10px]`,children:`per-rule`}),(0,D.jsxs)(`div`,{className:`font-mono text-sm text-[var(--color-fg-1)] tabular-nums`,children:[`~`,e.perRuleMs.toFixed(3),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] ml-0.5 text-[10px]`,children:`ms`})]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline text-[10px]`,children:`evals today`}),(0,D.jsx)(`div`,{className:`font-mono text-sm text-[var(--color-fg-1)] tabular-nums`,children:e.evalsToday.toLocaleString()})]}),(0,D.jsxs)(`div`,{className:`ml-auto text-right`,children:[(0,D.jsx)(`div`,{className:`overline text-[10px]`,children:`all-time evals`}),(0,D.jsx)(`div`,{className:`font-mono text-sm text-[var(--color-fg-2)] tabular-nums`,children:e.evalsAllTime.toLocaleString()})]})]}),e.avgEvalMs>50&&(0,D.jsx)(`p`,{className:`mt-2 text-[11px] text-amber-300/80`,children:`⚡ avg eval > 50ms — consider trimming or disabling low-value rules.`})]})})}function Xp({stats:e,ruleIndex:t,triggers:n,statsWindow:r,onJump:i}){let a=(0,_.useMemo)(()=>{let r=Object.entries(e).filter(([,e])=>e.hits>0).sort(([,e],[,t])=>t.hits-e.hits).slice(0,10),i=r[0]?.[1].hits??1;return r.map(([e,r])=>{let a=t.get(e),o=Up(n,20,3600*1e3,t=>t.ruleId===e);return{id:e,stat:r,entry:a,pct:r.hits/i*100,sparkData:o,color:a?Mp[a.rule.decision]??`#a8a29e`:`#a8a29e`}})},[e,t,n]);return a.length===0?(0,D.jsx)(K,{children:(0,D.jsxs)(J,{className:`px-3 py-3`,children:[(0,D.jsxs)(`div`,{className:`overline text-[10px] mb-1`,children:[`top rules · `,r]}),(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:`no rules have fired in this window yet`})]})}):(0,D.jsx)(K,{children:(0,D.jsxs)(J,{className:`px-3 py-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,D.jsxs)(`span`,{className:`overline text-[10px]`,children:[`top rules · `,r]}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)] tabular-nums`,children:[`top `,a.length,` · click to jump`]})]}),(0,D.jsx)(`div`,{className:`space-y-1`,children:a.map(e=>(0,D.jsxs)(`button`,{type:`button`,onClick:()=>i(e.id),className:`w-full text-left group cursor-pointer`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono`,children:[(0,D.jsx)(`span`,{className:`uppercase tracking-wider w-12 shrink-0 ${e.entry?jp[e.entry.rule.decision]??`text-[var(--color-fg-2)]`:`text-[var(--color-fg-4)]`}`,children:e.entry?.rule.decision??`—`}),(0,D.jsx)(`code`,{className:`text-[var(--color-fg-1)] group-hover:text-[var(--color-fg-0)] truncate flex-1 min-w-0`,children:e.id}),(0,D.jsx)(Js,{data:e.sparkData,width:60,height:16,color:e.color}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] tabular-nums shrink-0 w-10 text-right`,children:e.stat.hits}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-3)] tabular-nums shrink-0 w-14 text-right`,children:[e.stat.avgDurationMs.toFixed(1),`ms`]}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] tabular-nums shrink-0 w-14 text-right`,children:Hp(e.stat.lastSeen)})]}),(0,D.jsx)(`div`,{className:`relative h-1 mt-1 mb-1 bg-[var(--color-surface-2)] rounded-sm overflow-hidden`,children:(0,D.jsx)(`div`,{className:`absolute inset-y-0 left-0 rounded-sm transition-[width] duration-500 ease-out`,style:{width:`${e.pct}%`,background:e.color,opacity:.6}})})]},e.id))})]})})}function Zp({totalRules:e,activeRules:t,onChanged:n}){let[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(null);async function s(e){i(e);try{e===`disable`?await Vp(`disable-all`):e===`enable`?await Vp(`enable-all`):await Vp(`uninstall-all`,{confirm:`UNINSTALL_ALL_RULES`}),n()}finally{i(null),o(null)}}return(0,D.jsx)(K,{className:`border-[var(--color-line-1)]`,children:(0,D.jsx)(J,{className:`px-3 py-2.5`,children:(0,D.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,D.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-1)]`,children:`rule firewall`}),(0,D.jsxs)(`span`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)]`,children:[t,`/`,e,` active`]})]}),(0,D.jsxs)(`p`,{className:`text-[11px] text-[var(--color-fg-3)] mt-1 leading-snug`,children:[`Master switches across every installed ruleset. Disable / enable are reversible; uninstall wipes `,(0,D.jsx)(`code`,{children:`~/.sigmashake/rules/`}),`.`]})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[a===`disable`?(0,D.jsx)(Qp,{onConfirm:()=>void s(`disable`),onCancel:()=>o(null),tone:`amber`,label:`disable ${t} rules`,disabled:r!==null}):(0,D.jsx)(`button`,{onClick:()=>o(`disable`),disabled:r!==null||t===0,className:`text-[11px] font-mono uppercase tracking-wider bg-amber-500/10 border border-amber-500/40 text-amber-200 hover:bg-amber-500/20 rounded-sm px-2.5 py-0.5 cursor-pointer transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:r===`disable`?`disabling…`:`disable all`}),a===`enable`?(0,D.jsx)(Qp,{onConfirm:()=>void s(`enable`),onCancel:()=>o(null),tone:`emerald`,label:`enable ${e-t} rules`,disabled:r!==null}):(0,D.jsx)(`button`,{onClick:()=>o(`enable`),disabled:r!==null||t===e,className:`text-[11px] font-mono uppercase tracking-wider bg-emerald-500/10 border border-emerald-500/40 text-emerald-200 hover:bg-emerald-500/20 rounded-sm px-2.5 py-0.5 cursor-pointer transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:r===`enable`?`enabling…`:`enable all`}),a===`uninstall`?(0,D.jsx)(Qp,{onConfirm:()=>void s(`uninstall`),onCancel:()=>o(null),tone:`red`,label:`UNINSTALL ${e} rules`,disabled:r!==null}):(0,D.jsx)(`button`,{onClick:()=>o(`uninstall`),disabled:r!==null||e===0,className:`text-[11px] font-mono uppercase tracking-wider bg-red-500/10 border border-red-500/40 text-red-200 hover:bg-red-500/20 rounded-sm px-2.5 py-0.5 cursor-pointer transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:r===`uninstall`?`uninstalling…`:`uninstall all`})]})]})})})}function Qp({onConfirm:e,onCancel:t,tone:n,label:r,disabled:i}){let a={amber:`bg-amber-500/10 border-amber-500/40 text-amber-200 hover:bg-amber-500/20`,emerald:`bg-emerald-500/10 border-emerald-500/40 text-emerald-200 hover:bg-emerald-500/20`,red:`bg-red-500/10 border-red-500/40 text-red-200 hover:bg-red-500/20`}[n];return(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,D.jsxs)(`button`,{onClick:e,disabled:i,className:`text-[11px] font-mono uppercase tracking-wider border rounded-sm px-2 py-0.5 cursor-pointer transition-colors disabled:opacity-50 ${a}`,children:[`confirm: `,r]}),(0,D.jsx)(`button`,{onClick:t,disabled:i,className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer disabled:opacity-50`,children:`cancel`})]})}function $p({selected:e,onClear:t,onApply:n}){let[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(`block`),[s,c]=(0,_.useState)(!1);if(e.length===0)return null;async function l(e,t){i(e);try{await n(e,t)}finally{i(null),c(!1)}}return(0,D.jsx)(`div`,{className:`sticky top-0 z-20 -mx-1 px-1`,children:(0,D.jsx)(K,{className:`border-sky-500/40 bg-sky-500/5 backdrop-blur`,children:(0,D.jsx)(J,{className:`px-3 py-2`,children:(0,D.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,D.jsxs)(`span`,{className:`text-[11px] font-mono uppercase tracking-wider text-sky-200`,children:[e.length,` selected`]}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsx)(`button`,{onClick:()=>void l(`enable`),disabled:r!==null,className:`text-[11px] font-mono uppercase tracking-wider bg-emerald-500/10 border border-emerald-500/40 text-emerald-200 hover:bg-emerald-500/20 rounded-sm px-2 py-0.5 cursor-pointer transition-colors disabled:opacity-50`,children:r===`enable`?`…`:`enable`}),(0,D.jsx)(`button`,{onClick:()=>void l(`disable`),disabled:r!==null,className:`text-[11px] font-mono uppercase tracking-wider bg-amber-500/10 border border-amber-500/40 text-amber-200 hover:bg-amber-500/20 rounded-sm px-2 py-0.5 cursor-pointer transition-colors disabled:opacity-50`,children:r===`disable`?`…`:`disable`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,D.jsx)(`select`,{value:a,onChange:e=>o(e.target.value),disabled:r!==null,className:`bg-[var(--color-surface-0)] border border-[var(--color-line-1)] rounded-sm px-1.5 py-0.5 text-[11px] font-mono uppercase tracking-wider cursor-pointer focus:outline-none focus:border-[var(--color-brand)]/50 ${jp[a]??`text-[var(--color-fg-2)]`}`,children:Ap.map(e=>(0,D.jsx)(`option`,{value:e,children:e},e))}),(0,D.jsx)(`button`,{onClick:()=>void l(`decision`,a),disabled:r!==null,className:`text-[11px] font-mono uppercase tracking-wider bg-sky-500/10 border border-sky-500/40 text-sky-200 hover:bg-sky-500/20 rounded-sm px-2 py-0.5 cursor-pointer transition-colors disabled:opacity-50`,children:r===`decision`?`…`:`set decision`})]}),s?(0,D.jsx)(Qp,{onConfirm:()=>void l(`delete`),onCancel:()=>c(!1),tone:`red`,label:`delete ${e.length}`,disabled:r!==null}):(0,D.jsx)(`button`,{onClick:()=>c(!0),disabled:r!==null,className:`text-[11px] font-mono uppercase tracking-wider bg-red-500/10 border border-red-500/40 text-red-200 hover:bg-red-500/20 rounded-sm px-2 py-0.5 cursor-pointer transition-colors disabled:opacity-50`,children:`delete…`}),(0,D.jsx)(`button`,{onClick:t,disabled:r!==null,className:`ml-auto text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer disabled:opacity-50`,children:`clear`})]})})})})}function em({ruleId:e}){let[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0);return(0,_.useEffect)(()=>{let t=!1;return i(!0),fetch(`/api/json/rule-audit?ruleId=${encodeURIComponent(e)}&limit=25`).then(e=>e.json()).then(e=>{t||n(e)}).catch(()=>{}).finally(()=>{t||i(!1)}),()=>{t=!0}},[e]),r?(0,D.jsx)(`p`,{className:`mt-1.5 text-[11px] font-mono text-[var(--color-fg-3)]`,children:`loading audit…`}):!t||t.rows.length===0?(0,D.jsx)(`p`,{className:`mt-1.5 text-[11px] font-mono text-[var(--color-fg-3)]`,children:`no audit entries for this rule`}):(0,D.jsxs)(`div`,{className:`mt-2 border border-[var(--color-line-0)] rounded-sm overflow-hidden`,children:[(0,D.jsx)(`div`,{className:`bg-[var(--color-surface-0)] px-2 py-1 flex items-center gap-2`,children:(0,D.jsxs)(`span`,{className:`overline text-[10px]`,children:[`audit log — last `,t.rows.length,` of `,t.total]})}),(0,D.jsx)(`div`,{className:`divide-y divide-[var(--color-line-0)] max-h-64 overflow-y-auto`,children:t.rows.map(e=>(0,D.jsxs)(`div`,{className:`px-2 py-1.5 flex items-center gap-3 text-[11px] font-mono`,children:[(0,D.jsx)(`span`,{className:`uppercase tracking-wider w-14 shrink-0 ${jp[e.decision]??`text-[var(--color-fg-2)]`}`,children:e.decision}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)] w-20 shrink-0 truncate`,children:e.tool}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] flex-1 min-w-0 truncate`,children:e.input}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] tabular-nums shrink-0`,children:e.duration_ns?`${Math.round(e.duration_ns/1e6)}ms`:`–`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] tabular-nums shrink-0 w-16 text-right`,children:Hp(e.timestamp)})]},e.id))})]})}function tm(){let[e,t]=(0,_.useState)(!1);return(0,D.jsx)(K,{children:(0,D.jsxs)(`details`,{open:e,onToggle:e=>t(e.target.open),children:[(0,D.jsxs)(`summary`,{className:`px-3 py-2 cursor-pointer list-none select-none flex items-center gap-2 hover:bg-[var(--color-surface-2)]/70`,children:[(0,D.jsx)(`span`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-1)]`,children:`ai-native config`}),(0,D.jsx)(`span`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:`curl recipes — every UI action is also a JSON endpoint`}),(0,D.jsx)(`svg`,{className:`ml-auto text-[var(--color-fg-3)]`,width:`10`,height:`10`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,D.jsx)(`polyline`,{points:e?`6 15 12 9 18 15`:`6 9 12 15 18 9`})})]}),(0,D.jsxs)(J,{className:`py-2`,children:[(0,D.jsxs)(`p`,{className:`text-[11px] text-[var(--color-fg-3)] mb-2 leading-snug`,children:[`Point an agent at `,(0,D.jsx)(`code`,{children:`http://127.0.0.1:7901`}),`. Every bulk action below is one POST — no UI scraping required.`]}),(0,D.jsx)(`pre`,{className:`text-[10px] font-mono text-[var(--color-fg-2)] bg-[var(--color-surface-0)] border border-[var(--color-line-0)] rounded-sm p-2 overflow-x-auto whitespace-pre`,children:`# list rules + stats
28
+ `),(0,D.jsx)(`div`,{ref:r})]})]})]})}function Ef(){let e=V([`runtime-tick`,`rules-changed`]),{data:t,refetch:n}=k(`/api/json/observability`,[e[`runtime-tick`],e[`rules-changed`]]),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(!1),[s,c]=(0,_.useState)(Date.now()),[l,u]=(0,_.useState)(`idle`),[d,f]=(0,_.useState)(``),[p,m]=(0,_.useState)(`idle`);(0,_.useEffect)(()=>{t&&c(Date.now())},[t]);let h=(0,_.useCallback)(async()=>{u(`loading`);try{let e=await(await fetch(`/api/rules/sync-to-db`,{method:`POST`,headers:U()})).json();if(e.ok){u(`done`);let t=(e.pruned_count??0)>0?` (${e.pruned_count} orphan(s) pruned)`:``;f((e.message??`synced ${e.synced} rules`)+t),n()}else u(`error`),f(e.error??`sync failed`)}catch(e){u(`error`),f(String(e))}},[n]),g=(0,_.useCallback)(async()=>{m(`loading`);try{await fetch(`/api/rules/force-reload`,{method:`POST`,headers:U()}),m(`done`),n(),setTimeout(()=>m(`idle`),3e3)}catch{m(`idle`)}},[n]),v=t?.db,y=t?.rules,b=t?.audit,x=t?.process,S=t?.flight_recorder,C=y?.drift_detected??!1;return(0,D.jsxs)(`div`,{className:`space-y-5`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h1`,{className:`text-xl font-medium tracking-tight text-[var(--color-fg-0)]`,children:`Observability`}),(0,D.jsx)(`p`,{className:`text-[12px] font-mono text-[var(--color-fg-3)] mt-0.5`,children:`sqlite health · rule drift · runtime profiler · diagnostics`})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] tabular-nums`,children:[`refreshed `,gf(s)]}),(0,D.jsx)(G,{variant:`ghost`,size:`sm`,onClick:n,children:`refresh`})]})]}),(0,D.jsx)(Df,{db:v,audit:b,proc:x,flight:S,driftDetected:C}),(0,D.jsxs)(K,{"data-tutorial":`observ-drift`,className:C?`border-red-500/30 border-l-2 border-l-red-500/70`:`border-emerald-500/20 border-l-2 border-l-emerald-500/60`,children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`rule drift detector`}),(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:`— .rules files vs sqlite`}),(0,D.jsx)(`button`,{onClick:()=>o(e=>!e),"aria-expanded":a,"aria-label":`Explain these counts`,title:`Why do these numbers differ?`,className:`text-[10px] font-mono text-[var(--color-fg-4)] hover:text-[var(--color-fg-2)] border border-[var(--color-line-1)] rounded-sm px-1.5 py-0.5 transition-colors cursor-pointer`,children:a?`× close`:`? why these numbers`})]}),y&&(C?(0,D.jsx)(W,{variant:`red`,children:`⚠ drift detected`}):(0,D.jsx)(W,{variant:`green`,children:`✓ in sync`}))]}),(0,D.jsxs)(J,{children:[a&&(0,D.jsxs)(`div`,{className:`mb-4 rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-0)] px-3 py-2.5 space-y-2 text-[11px] font-mono leading-relaxed text-[var(--color-fg-3)]`,children:[(0,D.jsxs)(`div`,{className:`text-[var(--color-fg-2)]`,children:[(0,D.jsx)(`code`,{children:`.rules files`}),` and `,(0,D.jsx)(`code`,{children:`db rules`}),` are`,` `,(0,D.jsx)(`span`,{className:`text-amber-300`,children:`not auto-synced`}),`. A mismatch is usually expected:`]}),(0,D.jsxs)(`ul`,{className:`space-y-1 pl-3 list-disc marker:text-[var(--color-fg-4)]`,children:[(0,D.jsxs)(`li`,{children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:`one file can hold many rules`}),` `,`— compare `,(0,D.jsx)(`code`,{children:`db rules`}),` against`,` `,(0,D.jsx)(`code`,{children:`file_rule_count`}),`, not `,(0,D.jsx)(`code`,{children:`file_count`}),`.`]}),(0,D.jsxs)(`li`,{children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:`only in files`}),` `,`means unsynced edits — run`,` `,(0,D.jsx)(`code`,{className:`text-amber-300`,children:`ssg sync`}),` or click`,` `,(0,D.jsx)(`code`,{children:`↑ sync files → db`}),`.`]}),(0,D.jsxs)(`li`,{children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:`only in db`}),` `,`with `,(0,D.jsx)(`code`,{children:`source_file IS NULL`}),` is healthy — hub, fleet, or cloud-synced rules legitimately live only in the db.`]}),(0,D.jsxs)(`li`,{children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:`only in db`}),` `,`with `,(0,D.jsx)(`code`,{children:`source_file`}),` set means an orphan from a deleted file —`,` `,(0,D.jsx)(`code`,{className:`text-amber-300`,children:`ssg sync`}),` prunes it.`]}),(0,D.jsxs)(`li`,{children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:`db rules`}),` `,`includes disabled rows; `,(0,D.jsx)(`code`,{children:`db_enabled_count`}),` excludes them.`]})]}),(0,D.jsxs)(`div`,{className:`pt-1.5 border-t border-[var(--color-line-0)]`,children:[`full reference:`,` `,(0,D.jsx)(`a`,{href:`https://docs.sigmashake.com/rule-storage`,target:`_blank`,rel:`noopener noreferrer`,className:`text-[var(--color-fg-2)] underline decoration-dotted underline-offset-2 hover:text-amber-300 transition-colors`,children:`docs.sigmashake.com/rule-storage ↗`})]})]}),y?(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-4 gap-2`,children:[{label:`.rules files`,value:y.file_count,sub:`${y.file_rule_count} rules total`,tone:`neutral`},{label:`db rules`,value:y.db_rule_count,sub:`${y.db_enabled_count} enabled`,tone:`neutral`},{label:`only in files`,value:y.drift_details.only_in_files.length,tone:y.drift_details.only_in_files.length>0?`amber`:`gray`},{label:`only in db`,value:y.drift_details.only_in_db.length,tone:y.drift_details.only_in_db.length>0?`red`:`gray`}].map(({label:e,value:t,sub:n,tone:r})=>(0,D.jsx)(kl,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-0)]`,label:e,value:t,sub:n,tone:r,labelPlacement:`above`,subClassName:`text-[var(--color-fg-4)]`,valueClassName:`text-xl font-medium tabular-nums`},e))}),C&&(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`button`,{onClick:()=>i(e=>!e),className:`text-[10px] font-mono uppercase tracking-wider text-amber-300 hover:text-amber-200 flex items-center gap-1 transition-colors cursor-pointer`,children:[r?`▾`:`▸`,` view drift details`]}),r&&(0,D.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[y.drift_details.only_in_files.length>0&&(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`text-[10px] font-mono uppercase tracking-wider text-amber-300/80 mb-1.5`,children:[`in .rules files but not in db — run`,` `,(0,D.jsx)(`code`,{className:`text-amber-300`,children:`ssg sync`})]}),(0,D.jsx)(`div`,{className:`bg-[var(--color-surface-0)] border border-amber-400/20 rounded-sm p-2 space-y-0.5 max-h-40 overflow-y-auto`,children:y.drift_details.only_in_files.map(e=>(0,D.jsxs)(`div`,{className:`font-mono text-[11px] text-amber-200/80`,children:[`+ `,e]},e))})]}),y.drift_details.only_in_db.length>0&&(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-[10px] font-mono uppercase tracking-wider text-red-300/80 mb-1.5`,children:`in db but not in any .rules file — orphaned rules`}),(0,D.jsx)(`div`,{className:`bg-[var(--color-surface-0)] border border-red-400/20 rounded-sm p-2 space-y-0.5 max-h-40 overflow-y-auto`,children:y.drift_details.only_in_db.map(e=>(0,D.jsxs)(`div`,{className:`font-mono text-[11px] text-red-200/80`,children:[`− `,e]},e))})]})]})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pt-3 border-t border-[var(--color-line-0)]`,children:[(0,D.jsx)(G,{variant:`primary`,size:`sm`,onClick:h,disabled:l===`loading`,children:l===`loading`?`syncing…`:`↑ sync files → db`}),(0,D.jsx)(G,{variant:`ghost`,size:`sm`,onClick:g,disabled:p===`loading`,children:p===`loading`?`…`:p===`done`?`✓ reloaded`:`↻ force reload`}),(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] ml-auto`,children:y.db_rule_count===0?`⚠ db empty — daemon falls back to file-based loading`:`db has ${y.db_rule_count} rules — indexed queries`})]}),l===`done`&&(0,D.jsxs)(`div`,{className:`flex items-center justify-between rounded-sm border border-emerald-500/25 bg-emerald-500/[0.06] px-3 py-2 text-xs font-mono text-emerald-200`,children:[(0,D.jsxs)(`span`,{children:[`✓ `,d]}),(0,D.jsx)(`button`,{onClick:()=>u(`idle`),className:`ml-3 shrink-0 px-2 py-0.5 rounded-sm border border-emerald-500/30 hover:bg-emerald-500/10 transition-colors cursor-pointer uppercase tracking-wider text-[10px]`,children:`dismiss`})]}),l===`error`&&(0,D.jsxs)(`div`,{className:`flex items-center justify-between rounded-sm border border-red-500/25 bg-red-500/[0.06] px-3 py-2 text-xs font-mono text-red-200`,children:[(0,D.jsxs)(`span`,{children:[`✗ `,d]}),(0,D.jsx)(`button`,{onClick:()=>u(`idle`),className:`ml-3 shrink-0 px-2 py-0.5 rounded-sm border border-red-500/30 hover:bg-red-500/10 transition-colors cursor-pointer uppercase tracking-wider text-[10px]`,children:`dismiss`})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-4 text-[11px] font-mono text-[var(--color-fg-4)] pt-2 border-t border-[var(--color-line-0)]`,children:[(0,D.jsxs)(`span`,{children:[`rules dir:`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:y.rules_dir})]}),(0,D.jsxs)(`span`,{className:`ml-auto`,children:[`last reload:`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:gf(y.last_reload_at)})]})]})]}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`loading…`})]})]}),(0,D.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-5`,children:[(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`sqlite database`}),v&&!v.error&&(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,D.jsx)(yf,{ok:v.journal_mode===`wal`,label:`wal`,badLabel:`no wal`}),(0,D.jsx)(yf,{ok:v.synchronous===`NORMAL`,label:`normal`,badLabel:v.synchronous})]})]}),(0,D.jsx)(J,{children:v?v.error?(0,D.jsx)(`div`,{className:`text-xs text-red-300 font-mono bg-red-500/[0.06] border border-red-500/25 rounded-sm p-2`,children:v.error}):(0,D.jsxs)(`div`,{children:[(0,D.jsx)(_f,{children:`storage`}),(0,D.jsx)(vf,{label:`file path`,value:v.path}),(0,D.jsx)(vf,{label:`file size`,value:ff(v.file_size_bytes)}),(0,D.jsx)(vf,{label:`allocated`,value:`${ff(v.allocated_bytes)} (${v.page_count.toLocaleString()} pages × ${v.page_size}B)`}),(0,D.jsx)(_f,{className:`mt-4`,children:`pragma configuration`}),(0,D.jsx)(vf,{label:`journal_mode`,value:v.journal_mode,accent:v.journal_mode===`wal`?`text-emerald-300`:`text-amber-300`}),(0,D.jsx)(vf,{label:`synchronous`,value:v.synchronous,accent:v.synchronous===`NORMAL`?`text-emerald-300`:`text-amber-300`}),(0,D.jsx)(vf,{label:`cache_size`,value:`${v.cache_size_kb.toLocaleString()} KB (${Math.round(v.cache_size_kb/1024)} MB)`}),(0,D.jsx)(vf,{label:`page_size`,value:`${v.page_size.toLocaleString()} B`}),v.wal_checkpoint&&(0,D.jsx)(vf,{label:`wal checkpoint`,value:`log ${v.wal_checkpoint.log}, checkpointed ${v.wal_checkpoint.checkpointed}, busy ${v.wal_checkpoint.busy}`}),(0,D.jsx)(_f,{className:`mt-4`,children:`table row counts`}),v.tables.map(e=>(0,D.jsx)(vf,{label:e.name,value:e.row_count>=0?e.row_count.toLocaleString():`error`,accent:e.row_count<0?`text-red-300`:`text-[var(--color-fg-1)]`},e.name))]}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`loading…`})})]}),(0,D.jsxs)(`div`,{className:`space-y-5`,children:[(0,D.jsxs)(K,{"data-tutorial":`observ-capacity`,children:[(0,D.jsx)(q,{children:(0,D.jsx)(`span`,{className:`overline`,children:`audit log capacity`})}),(0,D.jsx)(J,{children:b?(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsx)(bf,{pct:b.utilization_pct,total:b.total_rows,max:b.max_rows}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(vf,{label:`total rows`,value:b.total_rows.toLocaleString()}),(0,D.jsx)(vf,{label:`rotation limit`,value:b.max_rows.toLocaleString()}),(0,D.jsx)(vf,{label:`utilization`,value:`${b.utilization_pct}%`,accent:b.utilization_pct>=85?`text-red-300`:b.utilization_pct>=60?`text-amber-300`:`text-emerald-300`}),(0,D.jsx)(vf,{label:`oldest entry`,value:hf(b.oldest_timestamp)}),(0,D.jsx)(vf,{label:`newest entry`,value:hf(b.newest_timestamp)})]}),b.utilization_pct>=85&&(0,D.jsx)(`div`,{className:`rounded-sm border border-red-500/25 bg-red-500/[0.06] px-3 py-2 text-[11px] font-mono text-red-200`,children:`⚠ audit log nearing rotation limit. oldest entries will be purged automatically.`})]}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`loading…`})})]}),(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsx)(`span`,{className:`overline`,children:`process & runtime`})}),(0,D.jsx)(J,{children:x?(0,D.jsxs)(`div`,{children:[(0,D.jsx)(vf,{label:`pid`,value:x.pid}),(0,D.jsx)(vf,{label:`uptime`,value:mf(x.uptime_ms)}),(0,D.jsx)(vf,{label:`memory (rss)`,value:`${x.memory_rss_mb} MB`}),(0,D.jsx)(vf,{label:`bun version`,value:x.bun_version}),(0,D.jsx)(vf,{label:`node compat`,value:x.node_version}),(0,D.jsx)(vf,{label:`platform`,value:`${x.platform} / ${x.arch}`})]}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`loading…`})})]})]})]}),(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsx)(`span`,{className:`overline`,children:`flight recorder`})}),(0,D.jsx)(J,{children:S?(0,D.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline mb-1.5`,children:`log file`}),(0,D.jsx)(`div`,{className:`text-xs font-mono text-[var(--color-fg-1)] truncate`,children:`…${S.path.slice(-50)}`})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline mb-1.5`,children:`file size`}),(0,D.jsx)(`div`,{className:`text-xs font-mono tabular-nums ${S.file_size_bytes===0?`text-[var(--color-fg-4)]`:`text-[var(--color-fg-1)]`}`,children:ff(S.file_size_bytes)})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline mb-1.5`,children:`approx. entries`}),(0,D.jsx)(`div`,{className:`text-xs font-mono tabular-nums ${S.approx_entries===0?`text-[var(--color-fg-4)]`:`text-[var(--color-fg-1)]`}`,children:S.approx_entries===0?`—`:S.approx_entries.toLocaleString()})]})]}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`loading…`})})]}),(0,D.jsx)(wf,{}),(0,D.jsx)(Tf,{}),(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsx)(`span`,{className:`overline`,children:`observability api`})}),(0,D.jsxs)(J,{children:[(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)] mb-2.5`,children:`machine-readable endpoints for automated monitoring and ai agent triage:`}),(0,D.jsx)(`div`,{className:`space-y-1 font-mono text-[11px]`,children:[[`/api/json/observability`,`sqlite health, rule drift, process info`],[`/api/state/runtime`,`eval latency, decision counters, memory`],[`/api/state/activity-tail?after=0&limit=20`,`recent eval events (live feed)`],[`/api/json/daemon-status`,`daemon pid, status, log tail`],[`/api/json/evald-log`,`last 200 lines of evald.log (daemon stderr)`],[`/healthz`,`process liveness`],[`/readyz`,`sqlite liveness`]].map(([e,t])=>(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`GET`}),(0,D.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`text-[var(--color-brand)]/80 hover:text-[var(--color-brand)] transition-colors`,children:e}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)] hidden sm:inline`,children:[`— `,t]})]},e))})]})]})]})}function Df({db:e,audit:t,proc:n,flight:r,driftDetected:i}){let a=e?e.error?`error`:e.journal_mode===`wal`&&e.synchronous===`NORMAL`?`ok`:`warn`:`unknown`,o=t?t.utilization_pct>=85?`error`:t.utilization_pct>=60?`warn`:`ok`:`unknown`,s=n?n.memory_rss_mb>600?`warn`:`ok`:`unknown`;return(0,D.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4`,children:[(0,D.jsxs)(lf,{title:`sqlite`,status:a,statusLabel:e?.journal_mode?.toUpperCase()??`idle`,children:[(0,D.jsx)(uf,{label:`size`,value:e?(0,D.jsx)(Ks,{value:e.file_size_bytes,format:e=>pf(e)}):`—`,mono:!0}),(0,D.jsx)(uf,{label:`journal`,value:e?.journal_mode??`—`,mono:!0}),(0,D.jsx)(uf,{label:`sync`,value:e?.synchronous??`—`,mono:!0}),(0,D.jsx)(uf,{label:`tables`,value:e?.tables.length??0,tone:i?`warn`:`neutral`})]}),(0,D.jsxs)(lf,{title:`audit log`,status:o,statusLabel:t?`${t.utilization_pct}%`:`idle`,children:[(0,D.jsx)(uf,{label:`rows`,value:t?(0,D.jsx)(Ks,{value:t.total_rows}):`—`}),(0,D.jsx)(uf,{label:`capacity`,value:t?`${(t.total_rows/Math.max(1,t.max_rows)*100).toFixed(1)}%`:`—`,tone:t&&t.utilization_pct>=85?`bad`:t&&t.utilization_pct>=60?`warn`:`good`}),(0,D.jsx)(uf,{label:`oldest`,value:hf(t?.oldest_timestamp??null),mono:!0}),(0,D.jsx)(uf,{label:`newest`,value:hf(t?.newest_timestamp??null),mono:!0})]}),(0,D.jsxs)(lf,{title:`process`,status:s,statusLabel:n?`pid ${n.pid}`:`idle`,children:[(0,D.jsx)(uf,{label:`uptime`,value:n?mf(n.uptime_ms):`—`,mono:!0}),(0,D.jsx)(uf,{label:`rss`,value:n?(0,D.jsxs)(`span`,{children:[(0,D.jsx)(Ks,{value:n.memory_rss_mb,format:e=>e.toFixed(0)}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] ml-1`,children:`MB`})]}):`—`}),(0,D.jsx)(uf,{label:`bun`,value:n?.bun_version??`—`,mono:!0}),(0,D.jsx)(uf,{label:`platform`,value:n?`${n.platform}/${n.arch}`:`—`,mono:!0})]}),(0,D.jsxs)(lf,{title:`flight recorder`,status:r&&r.file_size_bytes>0?`ok`:`unknown`,statusLabel:r?`${r.approx_entries.toLocaleString()} entries`:`idle`,children:[(0,D.jsx)(uf,{label:`size`,value:r?(0,D.jsx)(Ks,{value:r.file_size_bytes,format:e=>pf(e)}):`—`,mono:!0}),(0,D.jsx)(uf,{label:`entries`,value:r?(0,D.jsx)(Ks,{value:r.approx_entries}):`—`})]})]})}var Of=`https://hub.sigmashake.com/submit-plugin`,kf=`https://docs.sigmashake.com/docs/plugins/`,Af=[{cmd:`ssg plugins init my-plugin`,title:`Scaffold`,detail:`Creates plugin.toml plus a src/ template you can edit.`},{cmd:`ssg plugins build`,title:`Build & sign`,detail:`Bundles src/ into dist/<id>-<version>.tar.gz and an Ed25519-signed plugin.json.`},{cmd:`ssg plugins publish`,title:`Publish`,detail:`Pushes the source, cuts a GitHub release for the artifact, and opens the hub submission form prefilled.`}];function jf(){return(0,D.jsxs)(`div`,{className:`mx-auto max-w-2xl space-y-5`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`a`,{href:`/plugins`,className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-brand)]`,children:`← plugins`}),(0,D.jsx)(`h1`,{className:`mt-2 text-xl font-medium tracking-tight text-[var(--color-fg-0)]`,children:`Publish a plugin`}),(0,D.jsx)(`p`,{className:`mt-1 font-mono text-[12px] text-[var(--color-fg-3)]`,children:`build, sign, and submit a dashboard plugin to hub.sigmashake.com`})]}),(0,D.jsx)(K,{children:(0,D.jsxs)(J,{children:[(0,D.jsx)(`h2`,{className:`text-sm font-medium text-[var(--color-fg-1)]`,children:`Build it with the ssg CLI`}),(0,D.jsx)(`p`,{className:`mt-1 text-xs text-[var(--color-fg-3)]`,children:`Plugins are built, signed, and released from your machine — the CLI runs the whole flow. Run these from your plugin's directory:`}),(0,D.jsx)(`ol`,{className:`mt-3 space-y-3`,children:Af.map((e,t)=>(0,D.jsxs)(`li`,{className:`flex gap-3`,children:[(0,D.jsx)(`span`,{className:`mt-0.5 flex h-5 w-5 shrink-0 items-center justify-center rounded-full border border-[var(--color-line-1)] font-mono text-[11px] text-[var(--color-fg-3)]`,children:t+1}),(0,D.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,D.jsx)(`div`,{className:`text-xs font-medium text-[var(--color-fg-1)]`,children:e.title}),(0,D.jsx)(`pre`,{className:`mt-1 overflow-x-auto rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-0)] px-2.5 py-1.5 text-xs`,children:(0,D.jsx)(`code`,{className:`font-mono text-[var(--color-fg-1)]`,children:e.cmd})}),(0,D.jsx)(`p`,{className:`mt-1 text-[11px] text-[var(--color-fg-3)]`,children:e.detail})]})]},e.cmd))})]})}),(0,D.jsxs)(`div`,{className:`rounded-sm border border-amber-500/25 bg-amber-500/5 px-3 py-2 text-xs text-amber-200`,children:[`First time publishing? Register your signing key with`,` `,(0,D.jsx)(`code`,{className:`font-mono text-amber-100`,children:`ssg keys register`}),` so the hub can verify your plugin's Ed25519 signature against your account.`]}),(0,D.jsx)(K,{children:(0,D.jsxs)(J,{children:[(0,D.jsx)(`h2`,{className:`text-sm font-medium text-[var(--color-fg-1)]`,children:`Submit to the marketplace`}),(0,D.jsxs)(`p`,{className:`mt-1 text-xs text-[var(--color-fg-3)]`,children:[(0,D.jsx)(`code`,{className:`font-mono text-[var(--color-fg-2)]`,children:`ssg plugins publish`}),` `,`opens the hub submission form automatically once your release is up. If you've already built your plugin, open the form directly:`]}),(0,D.jsxs)(`a`,{href:Of,"data-tutorial":`pubplug-submit`,target:`_blank`,rel:`noreferrer`,className:`mt-3 inline-flex items-center gap-1.5 rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] px-3 py-1.5 text-xs font-medium text-[var(--color-fg-1)] transition-colors hover:border-[var(--color-hig-blue)] hover:text-[var(--color-hig-blue)]`,children:[`Open hub submission form`,(0,D.jsx)(`span`,{"aria-hidden":!0,children:`↗`})]}),(0,D.jsx)(`p`,{className:`mt-2 text-[11px] text-[var(--color-fg-4)]`,children:`Submitting needs a GitHub sign-in on hub.sigmashake.com — it opens in a new tab.`})]})}),(0,D.jsxs)(`p`,{className:`text-[11px] text-[var(--color-fg-3)]`,children:[`New to plugin authoring? Read the`,` `,(0,D.jsx)(`a`,{href:kf,target:`_blank`,rel:`noreferrer`,className:`text-[var(--color-hig-blue)] hover:underline`,children:`plugin documentation ↗`}),`.`]})]})}var Mf=[],Nf=`ssg:builtin-features:v1`,Pf=`ssg:builtin-features-change`,Ff={};function If(){try{let e=localStorage.getItem(Nf);if(!e)return{...Ff};let t=JSON.parse(e);if(typeof t!=`object`||!t)return{...Ff};let n={...Ff};for(let e of Object.keys(Ff)){let r=t[e];typeof r==`boolean`&&(n[e]=r)}return n}catch{return{...Ff}}}function Lf(e){try{localStorage.setItem(Nf,JSON.stringify(e))}catch{}}function Rf(e){window.dispatchEvent(new CustomEvent(Pf,{detail:e}))}function zf(){let[e,t]=(0,_.useState)(()=>If());return(0,_.useEffect)(()=>{let e=e=>{let n=e.detail;n&&t(n)};return window.addEventListener(Pf,e),()=>window.removeEventListener(Pf,e)},[]),{features:e,setFeature:(0,_.useCallback)((n,r)=>{let i={...e,[n]:r};t(i),Lf(i),Rf(i)},[e])}}async function Bf(){let e=await fetch(`/api/json/plugins`,{headers:{Accept:`application/json`}});if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}async function Vf(e=``,t={}){let n=new URLSearchParams;e&&n.set(`q`,e),t.category&&n.set(`category`,t.category),t.featured&&n.set(`featured`,`1`),t.sort&&n.set(`sort`,t.sort),t.page&&t.page>1&&n.set(`page`,String(t.page));let r=await fetch(`/api/json/plugins/available?${n.toString()}`,{headers:{Accept:`application/json`}});if(!r.ok)throw Error(`HTTP ${r.status}`);return r.json()}async function Hf(){let e=await fetch(`/api/json/plugins/categories`,{headers:{Accept:`application/json`}});if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}async function Uf(){let e=await fetch(`/api/json/license`,{headers:{Accept:`application/json`}});if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}function Wf(e){return e===`pro`||e===`enterprise`?`private`:`public`}async function Gf(e,t){let n=await fetch(e,{method:`POST`,headers:{...U(),"Content-Type":`application/json`},body:JSON.stringify(t)}),r=await n.text(),i=null;if(r)try{i=JSON.parse(r)}catch{i={error:r}}if(!n.ok){let e=i&&typeof i==`object`&&i&&`error`in i&&typeof i.error==`string`?i.error:`HTTP ${n.status}`;throw Error(e)}return i}function Kf(e){return Gf(`/api/json/plugins/install`,{packId:e})}function qf(e){return Gf(`/api/json/plugins/uninstall`,{id:e})}function Jf(e){return Gf(`/api/json/plugins/enable`,{id:e})}function Yf(e){return Gf(`/api/json/plugins/disable`,{id:e})}var Xf=5e3,Zf=200,Qf=5,$f={tools:`bg-sky-500/10 text-sky-300 border-sky-500/25`,observability:`bg-violet-500/10 text-violet-300 border-violet-500/25`,productivity:`bg-emerald-500/10 text-emerald-300 border-emerald-500/25`,integrations:`bg-amber-500/10 text-amber-300 border-amber-500/30`,developer:`bg-rose-500/10 text-rose-300 border-rose-500/25`};function ep(e){return e?$f[e]??`bg-[var(--color-surface-2)] text-[var(--color-fg-3)] border-[var(--color-line-1)]`:`bg-[var(--color-surface-2)] text-[var(--color-fg-3)] border-[var(--color-line-1)]`}function tp(e){if(!e)return``;let t=Date.parse(e);if(Number.isNaN(t))return``;let n=Date.now()-t,r=Math.floor(n/6e4);if(r<1)return`just now`;if(r<60)return`${r}m ago`;let i=Math.floor(r/60);if(i<24)return`${i}h ago`;let a=Math.floor(i/24);if(a<30)return`${a}d ago`;let o=Math.floor(a/30);return o<12?`${o}mo ago`:`${Math.floor(o/12)}y ago`}function np(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function rp(e){let t=e.split(/[\s\-_]+/).filter(Boolean);return t.length===0?`?`:t.length===1?t[0].slice(0,2).toUpperCase():(t[0][0]+t[1][0]).toUpperCase()}function ip({icon:e,name:t,avatarUrl:n,large:r}){let i=r?`h-14 w-14 text-2xl`:`h-10 w-10 text-lg`,a=r?`text-sm`:`text-[11px]`;return e?(0,D.jsx)(`div`,{className:`flex ${i} shrink-0 items-center justify-center rounded-md bg-[var(--color-surface-2)] leading-none`,children:(0,D.jsx)(`span`,{"aria-hidden":!0,children:e})}):n?(0,D.jsx)(`img`,{src:n,alt:``,className:`${i} shrink-0 rounded-md object-cover`,loading:`lazy`}):(0,D.jsx)(`div`,{className:`flex ${i} shrink-0 items-center justify-center rounded-md bg-[var(--color-surface-2)] ${a} font-mono uppercase text-[var(--color-fg-3)]`,children:rp(t)})}function ap(){return(0,D.jsxs)(`svg`,{"aria-label":`Verified publisher`,width:`12`,height:`12`,viewBox:`0 0 12 12`,fill:`none`,className:`inline-block shrink-0 text-sky-400`,children:[(0,D.jsx)(`circle`,{cx:`6`,cy:`6`,r:`5.5`,stroke:`currentColor`,strokeWidth:`1`}),(0,D.jsx)(`path`,{d:`M3.5 6l1.8 1.8 3.2-3.6`,stroke:`currentColor`,strokeWidth:`1.2`,strokeLinecap:`round`,strokeLinejoin:`round`})]})}function op(){return(0,D.jsx)(K,{children:(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`flex animate-pulse items-start gap-3`,children:[(0,D.jsx)(`div`,{className:`h-10 w-10 shrink-0 rounded-md bg-[var(--color-surface-2)]`}),(0,D.jsxs)(`div`,{className:`flex-1 space-y-2`,children:[(0,D.jsx)(`div`,{className:`h-3 w-1/3 rounded bg-[var(--color-surface-2)]`}),(0,D.jsx)(`div`,{className:`h-3 w-2/3 rounded bg-[var(--color-surface-2)]`}),(0,D.jsx)(`div`,{className:`h-3 w-1/4 rounded bg-[var(--color-surface-2)]`})]}),(0,D.jsx)(`div`,{className:`h-7 w-20 shrink-0 rounded bg-[var(--color-surface-2)]`})]})})})}function sp({license:e}){let t=e?.tier??`unlicensed`,n=Wf(t),r=t===`pro`||t===`enterprise`,i=e?.tier_label??`Free (Starter)`;return(0,D.jsxs)(`div`,{className:`rounded-lg border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3 text-xs`,children:[(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`font-medium text-[var(--color-fg-2)]`,children:`Publishing visibility`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-3)]`,children:[`Plan: `,i]}),(0,D.jsx)(`span`,{className:`inline-flex items-center gap-1 rounded-sm border px-1.5 py-px font-mono text-[10px] uppercase tracking-wide ${n===`public`?`border-emerald-500/30 bg-emerald-500/10 text-emerald-300`:`border-amber-500/30 bg-amber-500/10 text-amber-300`}`,children:n===`public`?`🌐 public by default`:`🔒 private by default`})]}),(0,D.jsxs)(`p`,{className:`mt-1.5 leading-relaxed text-[var(--color-fg-3)]`,children:[r?`Plugins and rulesets you publish stay private to protect your governance IP. Share one publicly with `:`Plugins and rulesets you publish go to the public marketplace so others can install and fork them. Keep one private with `,(0,D.jsx)(`code`,{className:`rounded bg-[var(--color-surface-2)] px-1 py-px font-mono text-[10px]`,children:r?`ssg plugins publish --public`:`ssg plugins publish --private`}),r?`. A confirmation is required before anything becomes public.`:`.`]})]})}function cp(){let[e,t]=(0,_.useState)([]),[n,r]=(0,_.useState)([]),[i,a]=(0,_.useState)([]),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)(``),[f,p]=(0,_.useState)({}),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(!0),[y,b]=(0,_.useState)(!0),[x,S]=(0,_.useState)(`browse`),[C,w]=(0,_.useState)(`all`),[T,E]=(0,_.useState)(`popular`),[O,k]=(0,_.useState)([]),[ee,A]=(0,_.useState)(null),{features:j,setFeature:M}=zf(),te=(0,_.useMemo)(()=>Mf.filter(e=>j[e.id]).length,[j]),N=(0,_.useRef)(null),P=(0,_.useCallback)((e,t)=>{h({kind:e,message:t}),N.current&&clearTimeout(N.current),N.current=setTimeout(()=>{h(null),N.current=null},Xf)},[]),F=(0,_.useCallback)(e=>{let t=`ssg plugins fork ${e}`,n=navigator.clipboard;n?.writeText?n.writeText(t).then(()=>P(`ok`,`Copied: ${t}`)).catch(()=>P(`ok`,t)):P(`ok`,t)},[P]);(0,_.useEffect)(()=>()=>{N.current&&clearTimeout(N.current)},[]),(0,_.useEffect)(()=>{let e=setTimeout(()=>d(c),Zf);return()=>clearTimeout(e)},[c]),(0,_.useEffect)(()=>{Hf().then(e=>k(e.categories)).catch(()=>{})},[]),(0,_.useEffect)(()=>{Uf().then(A).catch(()=>{})},[]);let I=(0,_.useCallback)(async()=>{v(!0);try{let e=await Bf();t(e.plugins),r(e.errors)}catch(e){P(`err`,e instanceof Error?e.message:String(e))}finally{v(!1)}},[P]),ne=(0,_.useCallback)(async(e,t,n)=>{b(!0),s(null);try{a((await Vf(e,{category:t===`all`?void 0:t,sort:n})).data??[])}catch(e){s(e instanceof Error?e.message:String(e)),a([])}finally{b(!1)}},[]);(0,_.useEffect)(()=>{I()},[I]),(0,_.useEffect)(()=>{ne(u,C,T)},[u,C,T,ne]);let re=(0,_.useMemo)(()=>new Set(e.map(e=>e.id)),[e]),ie=(0,_.useMemo)(()=>e.filter(e=>e.enabled).length,[e]),L=async(e,t,n,r)=>{p(n=>({...n,[e]:t}));try{await n(),P(`ok`,r),await Promise.all([I(),ne(u,C,T)])}catch(e){P(`err`,e instanceof Error?e.message:String(e))}finally{p(t=>({...t,[e]:void 0}))}},R=(0,_.useMemo)(()=>{let e=new Map;for(let t of i)e.set(t.id,t.icon);return e},[i]),ae=(0,_.useMemo)(()=>i.filter(e=>e.featured),[i]),oe=C===`all`&&ae.length>0;return(0,D.jsxs)(`div`,{className:`flex flex-col gap-5 p-6`,children:[(0,D.jsxs)(`header`,{className:`flex flex-col gap-3`,children:[(0,D.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3`,children:[(0,D.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`h1`,{className:`text-xl font-semibold`,children:`Plugin Marketplace`}),(0,D.jsxs)(`p`,{className:`max-w-2xl text-sm text-[var(--color-fg-3)]`,children:[`Extend the dashboard with Ed25519-signed plugins from`,` `,(0,D.jsx)(`a`,{href:`https://hub.sigmashake.com`,className:`text-[var(--color-hig-blue)] hover:underline`,target:`_blank`,rel:`noreferrer`,children:`hub.sigmashake.com`}),`. Each plugin is hash-verified and signature-checked before extraction; disable to hide from the sidebar without uninstalling.`]})]}),(0,D.jsx)(`a`,{href:`/publish-plugin`,className:`text-xs text-[var(--color-hig-blue)] hover:underline`,children:`Publish a plugin →`})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,D.jsxs)(`div`,{"data-tutorial":`plugins-tabs`,role:`tablist`,className:`inline-flex overflow-hidden rounded-md border border-[var(--color-line-1)]`,children:[(0,D.jsxs)(`button`,{role:`tab`,"aria-selected":x===`browse`,className:`px-3 py-1.5 text-xs transition-colors ${x===`browse`?`bg-[var(--color-surface-2)] text-[var(--color-fg-1)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,onClick:()=>S(`browse`),children:[`Browse`,i.length>0?` · ${i.length}`:``]}),(0,D.jsxs)(`button`,{role:`tab`,"aria-selected":x===`installed`,className:`border-l border-[var(--color-line-1)] px-3 py-1.5 text-xs transition-colors ${x===`installed`?`bg-[var(--color-surface-2)] text-[var(--color-fg-1)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,onClick:()=>S(`installed`),children:[`Installed · `,e.length,e.length>0&&ie<e.length&&(0,D.jsxs)(`span`,{className:`ml-1 text-amber-300`,children:[`(`,e.length-ie,` off)`]})]}),(0,D.jsxs)(`button`,{role:`tab`,"aria-selected":x===`builtin`,className:`border-l border-[var(--color-line-1)] px-3 py-1.5 text-xs transition-colors ${x===`builtin`?`bg-[var(--color-surface-2)] text-[var(--color-fg-1)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,onClick:()=>S(`builtin`),title:`Bundled features that behave like plugins — opt-in`,children:[`Built-in · `,te,`/`,Mf.length]})]}),x===`browse`&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`relative ml-auto`,children:[(0,D.jsx)(`input`,{"data-tutorial":`plugins-search`,type:`search`,placeholder:`Search plugins…`,className:`w-64 rounded-sm border border-[var(--color-line-1)] bg-transparent px-2 py-1 text-xs focus:border-[var(--color-hig-blue)] focus:outline-none`,value:c,onChange:e=>l(e.target.value),"aria-label":`Search plugins`}),c&&(0,D.jsx)(`button`,{className:`absolute right-1 top-1/2 -translate-y-1/2 px-1 text-[var(--color-fg-4)] hover:text-[var(--color-fg-1)]`,onClick:()=>l(``),"aria-label":`Clear search`,children:`×`})]}),i.length>Qf&&(0,D.jsxs)(`select`,{value:T,onChange:e=>E(e.target.value),"aria-label":`Sort plugins`,className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] px-2 py-1 text-xs text-[var(--color-fg-2)] focus:outline-none`,children:[(0,D.jsx)(`option`,{value:`popular`,children:`Popular`}),(0,D.jsx)(`option`,{value:`recent`,children:`Recent`}),(0,D.jsx)(`option`,{value:`name`,children:`Name`})]})]}),x===`installed`&&(0,D.jsx)(G,{variant:`ghost`,size:`sm`,className:`ml-auto`,onClick:()=>void I(),children:`Refresh`})]}),x===`browse`&&O.length>0&&(0,D.jsxs)(`div`,{"data-tutorial":`plugins-categories`,className:`flex flex-wrap gap-1.5`,role:`group`,"aria-label":`Filter by category`,children:[(0,D.jsx)(`button`,{onClick:()=>w(`all`),className:`inline-flex items-center gap-1 rounded-full border px-2.5 py-0.5 text-[11px] font-medium transition-colors ${C===`all`?`border-[var(--color-hig-blue)] bg-sky-500/10 text-sky-300`:`border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,"aria-pressed":C===`all`,children:`All`}),O.map(e=>(0,D.jsxs)(`button`,{onClick:()=>w(C===e.name?`all`:e.name),className:`inline-flex items-center gap-1 rounded-full border px-2.5 py-0.5 text-[11px] font-medium capitalize transition-colors ${C===e.name?`border-transparent ${ep(e.name)}`:`border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,"aria-pressed":C===e.name,children:[e.name,(0,D.jsx)(`span`,{className:`text-[10px] opacity-60`,children:e.count})]},e.name))]})]}),m&&(0,D.jsx)(`div`,{role:`status`,className:m.kind===`ok`?`rounded-md border border-emerald-700/40 bg-emerald-900/20 px-3 py-2 text-xs text-emerald-200`:`rounded-md border border-red-700/40 bg-red-900/20 px-3 py-2 text-xs text-red-200`,children:m.message}),(0,D.jsx)(sp,{license:ee}),n.length>0&&(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsxs)(`div`,{className:`text-xs uppercase tracking-wider text-amber-300`,children:[`Load errors (`,n.length,`)`]})}),(0,D.jsx)(J,{children:(0,D.jsx)(`ul`,{className:`space-y-1 text-xs text-amber-100/80`,children:n.map(e=>(0,D.jsxs)(`li`,{children:[(0,D.jsx)(`span`,{className:`font-mono text-amber-300`,children:e.id}),` ·`,` `,e.error]},e.id))})})]}),x===`browse`&&(0,D.jsx)(up,{loading:y,error:o,available:i,featuredPlugins:ae,showFeatured:oe,installedIds:re,busy:f,query:u,selectedCategory:C,onInstall:e=>L(e.id,`install`,()=>Kf(e.id),`Installed ${e.name}`),onRetry:()=>void ne(u,C,T),onFork:e=>F(e.id)}),x===`installed`&&(0,D.jsx)(fp,{loading:g,installed:e,iconById:R,busy:f,onEnable:e=>L(e.id,`toggle`,()=>Jf(e.id),`Enabled ${e.name}`),onDisable:e=>L(e.id,`toggle`,()=>Yf(e.id),`Disabled ${e.name}`),onUninstall:e=>L(e.id,`uninstall`,()=>qf(e.id),`Uninstalled ${e.name}`)}),x===`builtin`&&(0,D.jsx)(dp,{features:j,onToggle:(e,t)=>{M(e,t);let n=Mf.find(t=>t.id===e),r=n?n.name:e;P(`ok`,t?`Enabled ${r}`:`Disabled ${r}`)}})]})}function lp({plugin:e,installed:t,busy:n,onInstall:r,onFork:i}){return(0,D.jsxs)(`div`,{className:`flex w-56 shrink-0 flex-col gap-2 rounded-lg border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-start justify-between gap-2`,children:[(0,D.jsx)(ip,{name:e.name,icon:e.icon,large:!0}),e.verified&&(0,D.jsx)(`span`,{className:`mt-0.5`,children:(0,D.jsx)(ap,{})})]}),(0,D.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,D.jsx)(`span`,{className:`truncate text-sm font-semibold leading-tight`,children:e.name}),e.category&&(0,D.jsx)(`span`,{className:`inline-flex w-fit items-center rounded-sm border px-1 py-px text-[9px] font-mono font-medium uppercase tracking-wide ${ep(e.category)}`,children:e.category})]}),e.description&&(0,D.jsx)(`p`,{className:`line-clamp-2 text-[11px] leading-relaxed text-[var(--color-fg-3)]`,children:e.description}),(0,D.jsxs)(`div`,{className:`mt-auto flex items-center justify-between gap-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-[var(--color-fg-4)]`,children:[(0,D.jsxs)(`span`,{children:[np(e.install_count),` installs`]}),(0,D.jsx)(`button`,{type:`button`,onClick:i,className:`hover:text-[var(--color-hig-blue)] hover:underline`,title:`Copy: ssg plugins fork ${e.id}`,children:`Fork`})]}),(0,D.jsx)(G,{variant:t?`ghost`:`primary`,size:`sm`,disabled:t||n,onClick:r,children:t?`Installed`:n?`Installing…`:`Install`})]})]})}function up({loading:e,error:t,available:n,featuredPlugins:r,showFeatured:i,installedIds:a,busy:o,query:s,selectedCategory:c,onInstall:l,onRetry:u,onFork:d}){return e&&n.length===0?(0,D.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[(0,D.jsx)(`div`,{className:`flex gap-3 overflow-x-auto pb-1`,children:Array.from({length:3}).map((e,t)=>(0,D.jsx)(`div`,{className:`h-40 w-56 shrink-0 animate-pulse rounded-lg bg-[var(--color-surface-2)]`},t))}),(0,D.jsx)(`div`,{className:`grid grid-cols-1 gap-3 lg:grid-cols-2`,children:Array.from({length:4}).map((e,t)=>(0,D.jsx)(op,{},t))})]}):t?(0,D.jsx)(K,{children:(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`flex flex-col items-start gap-2`,children:[(0,D.jsx)(`div`,{className:`text-sm font-medium text-[var(--color-fg-1)]`,children:`Hub unreachable`}),(0,D.jsx)(`div`,{className:`text-xs text-red-300`,children:t}),(0,D.jsx)(G,{variant:`secondary`,size:`sm`,onClick:u,children:`Retry`})]})})}):n.length===0?(0,D.jsx)(K,{children:(0,D.jsx)(J,{children:(0,D.jsx)(`div`,{className:`flex flex-col gap-2 py-4 text-sm text-[var(--color-fg-3)]`,children:s?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`div`,{className:`font-medium text-[var(--color-fg-1)]`,children:[`No plugins match "`,s,`".`]}),(0,D.jsx)(`div`,{children:`Try a different search term, or browse the full catalog by clearing the search box.`})]}):c===`all`?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`font-medium text-[var(--color-fg-1)]`,children:`No plugins on the hub yet.`}),(0,D.jsxs)(`div`,{children:[`The marketplace is brand new.`,` `,(0,D.jsx)(`a`,{href:`/publish-plugin`,className:`text-[var(--color-hig-blue)] hover:underline`,children:`Publish the first plugin →`})]})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`div`,{className:`font-medium text-[var(--color-fg-1)]`,children:`No plugins in this category yet.`}),(0,D.jsx)(`div`,{children:`Try another category or view all plugins.`})]})})})}):(0,D.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[i&&(0,D.jsxs)(`section`,{"data-tutorial":`plugins-featured`,children:[(0,D.jsx)(`div`,{className:`mb-2 text-xs font-medium uppercase tracking-wider text-[var(--color-fg-4)]`,children:`Featured`}),(0,D.jsx)(`div`,{className:`flex gap-3 overflow-x-auto pb-2`,children:r.map(e=>(0,D.jsx)(lp,{plugin:e,installed:a.has(e.id),busy:o[e.id]===`install`,onInstall:()=>l(e),onFork:()=>d(e)},e.id))})]}),(0,D.jsxs)(`section`,{children:[i&&(0,D.jsx)(`div`,{className:`mb-2 text-xs font-medium uppercase tracking-wider text-[var(--color-fg-4)]`,children:`All Plugins`}),(0,D.jsx)(`div`,{className:`grid grid-cols-1 gap-3 lg:grid-cols-2`,children:n.map(e=>{let t=a.has(e.id),n=o[e.id]===`install`;return(0,D.jsx)(K,{variant:t?`default`:`interactive`,children:(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,D.jsx)(ip,{name:e.name,icon:e.icon}),(0,D.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,D.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),e.verified&&(0,D.jsx)(ap,{}),(0,D.jsxs)(W,{variant:`outline`,children:[`v`,e.version]}),t&&(0,D.jsx)(W,{variant:`green`,children:`Installed`})]}),e.category&&(0,D.jsx)(`div`,{className:`mt-1`,children:(0,D.jsx)(`span`,{className:`inline-flex items-center rounded-sm border px-1 py-px text-[9px] font-mono font-medium uppercase tracking-wide ${ep(e.category)}`,children:e.category})}),e.description&&(0,D.jsx)(`p`,{className:`mt-1 line-clamp-2 text-xs text-[var(--color-fg-3)]`,children:e.description}),(0,D.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-[var(--color-fg-4)]`,children:[e.author_github&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(`span`,{children:[`by`,` `,(0,D.jsxs)(`a`,{href:`https://github.com/${e.author_github}`,target:`_blank`,rel:`noreferrer`,className:`hover:text-[var(--color-fg-2)] hover:underline`,children:[`@`,e.author_github]})]}),(0,D.jsx)(`span`,{children:`·`})]}),(0,D.jsxs)(`span`,{children:[np(e.install_count),` installs`]}),e.platforms.length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{children:`·`}),(0,D.jsx)(`span`,{title:`Supports ${e.platforms.join(`, `)}`,children:e.platforms.length===1?e.platforms[0]:`${e.platforms.length} platforms`})]})]})]}),(0,D.jsxs)(`div`,{className:`flex shrink-0 flex-col items-end gap-1`,children:[(0,D.jsx)(G,{variant:t?`ghost`:`primary`,size:`sm`,disabled:t||n,onClick:()=>l(e),children:t?`Installed`:n?`Installing…`:`Install`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-[10px] text-[var(--color-fg-4)]`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:()=>d(e),className:`hover:text-[var(--color-hig-blue)] hover:underline`,title:`Copy: ssg plugins fork ${e.id}`,children:`Fork`}),(0,D.jsx)(`a`,{href:`https://hub.sigmashake.com/plugin/${e.id}`,target:`_blank`,rel:`noreferrer`,className:`hover:text-[var(--color-hig-blue)] hover:underline`,children:`View source`})]})]})]})})},e.id)})})]})]})}function dp({features:e,onToggle:t}){return(0,D.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,D.jsx)(`p`,{className:`text-xs text-[var(--color-fg-3)]`,children:`Bundled with the dashboard but opt-in. These features ship inside the ssg binary and run in-process; they don't need a separate install but stay dormant until enabled here.`}),(0,D.jsx)(`div`,{className:`grid grid-cols-1 gap-3 lg:grid-cols-2`,children:Mf.map(n=>{let r=e[n.id];return(0,D.jsx)(K,{children:(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,D.jsx)(`div`,{className:`flex h-10 w-10 shrink-0 items-center justify-center rounded-md bg-[var(--color-surface-2)] text-lg leading-none`,children:(0,D.jsx)(`span`,{"aria-hidden":!0,children:n.icon})}),(0,D.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`truncate font-medium`,children:n.name}),(0,D.jsx)(W,{variant:`gray`,children:`Built-in`}),r?(0,D.jsx)(W,{variant:`green`,children:`Enabled`}):(0,D.jsx)(W,{variant:`amber`,children:`Disabled`})]}),(0,D.jsx)(`p`,{className:`mt-1 text-xs text-[var(--color-fg-3)]`,children:n.description}),(0,D.jsx)(`div`,{className:`mt-2 text-[11px] text-[var(--color-fg-4)]`,children:`No download · runs in your browser`})]}),(0,D.jsx)(`div`,{className:`shrink-0`,children:(0,D.jsx)(G,{variant:r?`ghost`:`primary`,size:`sm`,onClick:()=>t(n.id,!r),children:r?`Disable`:`Enable`})})]})})},n.id)})})]})}function fp({loading:e,installed:t,iconById:n,busy:r,onEnable:i,onDisable:a,onUninstall:o}){return e&&t.length===0?(0,D.jsx)(`div`,{className:`grid grid-cols-1 gap-3 lg:grid-cols-2`,children:Array.from({length:2}).map((e,t)=>(0,D.jsx)(op,{},t))}):t.length===0?(0,D.jsx)(K,{children:(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`flex flex-col gap-2 py-4 text-sm text-[var(--color-fg-3)]`,children:[(0,D.jsx)(`div`,{className:`font-medium text-[var(--color-fg-1)]`,children:`No plugins installed yet.`}),(0,D.jsx)(`div`,{children:`Switch to the Browse tab to discover plugins from the hub.`})]})})}):(0,D.jsx)(`div`,{className:`grid grid-cols-1 gap-3 lg:grid-cols-2`,children:t.map(e=>{let t=r[e.id]===`toggle`,s=r[e.id]===`uninstall`;return(0,D.jsx)(K,{children:(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,D.jsx)(ip,{name:e.name,icon:e.icon??n.get(e.id)??null}),(0,D.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1.5`,children:[(0,D.jsx)(`span`,{className:`truncate font-medium`,children:e.name}),(0,D.jsxs)(W,{variant:`outline`,children:[`v`,e.version]}),e.enabled?(0,D.jsx)(W,{variant:`green`,children:`Enabled`}):(0,D.jsx)(W,{variant:`amber`,children:`Disabled`})]}),e.category&&(0,D.jsx)(`div`,{className:`mt-1`,children:(0,D.jsx)(`span`,{className:`inline-flex items-center rounded-sm border px-1 py-px text-[9px] font-mono font-medium uppercase tracking-wide ${ep(e.category)}`,children:e.category})}),e.description&&(0,D.jsx)(`p`,{className:`mt-1 line-clamp-2 text-xs text-[var(--color-fg-3)]`,children:e.description}),(0,D.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-x-3 gap-y-1 text-[11px] text-[var(--color-fg-4)]`,children:[(0,D.jsx)(`span`,{className:`font-mono`,children:e.id}),(0,D.jsx)(`span`,{children:`·`}),(0,D.jsxs)(`span`,{title:e.signing_fingerprint,children:[`sig`,` `,(0,D.jsxs)(`span`,{className:`font-mono`,children:[e.signing_fingerprint.slice(0,12),`…`]})]}),(0,D.jsx)(`span`,{children:`·`}),(0,D.jsxs)(`span`,{title:e.installed_at,children:[`installed `,tp(e.installed_at)]}),e.nav.length>0&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{children:`·`}),(0,D.jsxs)(`span`,{children:[e.nav.length,` nav`,` `,e.nav.length===1?`entry`:`entries`]})]})]}),(e.homepage_url||e.repo_url)&&(0,D.jsxs)(`div`,{className:`mt-1.5 flex flex-wrap gap-x-3 gap-y-0.5 text-[11px]`,children:[e.homepage_url&&(0,D.jsx)(`a`,{href:e.homepage_url,target:`_blank`,rel:`noreferrer`,className:`text-[var(--color-hig-blue)] hover:underline`,children:`Homepage`}),e.repo_url&&(0,D.jsx)(`a`,{href:e.repo_url,target:`_blank`,rel:`noreferrer`,className:`text-[var(--color-hig-blue)] hover:underline`,children:`Repository`})]})]}),(0,D.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-1.5`,children:[e.enabled?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(G,{variant:`primary`,size:`sm`,onClick:()=>{window.location.href=`/plugins/${e.id}`},children:`Open`}),(0,D.jsx)(G,{variant:`ghost`,size:`sm`,disabled:t,onClick:()=>a(e),children:t?`Disabling…`:`Disable`})]}):(0,D.jsx)(G,{variant:`secondary`,size:`sm`,disabled:t,onClick:()=>i(e),children:t?`Enabling…`:`Enable`}),(0,D.jsx)(G,{variant:`ghost`,size:`sm`,disabled:s,onClick:()=>o(e),children:s?`Removing…`:`Uninstall`})]})]})})},e.id)})})}function pp(e){return e<1e6?`${(e/1e3).toFixed(0)}µs`:e<1e9?`${(e/1e6).toFixed(1)}ms`:`${(e/1e9).toFixed(2)}s`}function mp(e){return new Date(e*1e3).toLocaleString()}var hp={critical:`red`,high:`red`,medium:`amber`,low:`blue`},gp={critical:`border-l-red-500/70`,high:`border-l-red-500/50`,medium:`border-l-amber-400/60`,low:`border-l-sky-400/50`};function _p(){let{data:e}=k(`/api/json/profile`);if(!e)return(0,D.jsx)(`p`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)]`,children:`loading profile…`});let{diagnosis:t,sessions:n}=e;return!t||t.analyzed_evals===0?(0,D.jsx)(`div`,{className:`rounded-sm border border-dashed border-[var(--color-line-1)] bg-[var(--color-surface-1)]/50 px-4 py-6 text-center`,children:(0,D.jsxs)(`p`,{className:`text-[12px] text-[var(--color-fg-2)] font-mono`,children:[`no eval data yet — run`,` `,(0,D.jsx)(`code`,{className:`text-[var(--color-brand)]`,children:`ssg eval`}),` to start recording`]})}):(0,D.jsxs)(`div`,{className:`space-y-5`,children:[(0,D.jsx)(`div`,{"data-tutorial":`profile-metrics`,className:`grid grid-cols-2 lg:grid-cols-4 gap-2`,children:[{label:`evals analyzed`,value:String(t.analyzed_evals)},{label:`median (inside)`,value:pp(t.median_eval_ns)},{label:`p99 (inside)`,value:pp(t.p99_eval_ns)},{label:`bottleneck`,value:t.bottleneck??`—`}].map(e=>(0,D.jsx)(Ol,{label:e.label,value:e.value,labelPlacement:`above`,valueClassName:`text-xl font-medium tabular-nums text-[var(--color-fg-0)]`},e.label))}),t.phases.length>0&&(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsx)(`span`,{className:`overline`,children:`phase breakdown`})}),(0,D.jsx)(J,{children:(0,D.jsx)(`div`,{className:`space-y-2`,children:t.phases.filter(e=>e.median_ns>0).map(e=>{let n=e.name===t.bottleneck;return(0,D.jsxs)(`div`,{className:`flex items-center gap-3 text-xs`,children:[(0,D.jsx)(`span`,{className:`w-28 font-mono truncate ${n?`text-[var(--color-brand)] font-medium`:`text-[var(--color-fg-2)]`}`,title:n?`bottleneck`:void 0,children:e.name}),(0,D.jsx)(Al,{pct:Math.min(e.pct_of_total,100),tone:n?`amber`:`gray`,className:`h-1 flex-1`}),(0,D.jsx)(`span`,{className:`w-16 text-right text-[var(--color-fg-1)] tabular-nums font-mono`,children:pp(e.median_ns)}),(0,D.jsxs)(`span`,{className:`w-10 text-right text-[var(--color-fg-3)] tabular-nums font-mono`,children:[e.pct_of_total,`%`]}),(0,D.jsxs)(`span`,{className:`w-20 text-right text-[var(--color-fg-4)] tabular-nums font-mono text-[10px]`,children:[`p95 `,pp(e.p95_ns)]})]},e.name)})})})]}),t.recommendations.length>0&&(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsxs)(`span`,{className:`overline`,children:[`recommendations · `,t.recommendations.length]})}),(0,D.jsx)(J,{className:`space-y-2`,children:t.recommendations.map((e,t)=>(0,D.jsxs)(`div`,{className:`border border-[var(--color-line-1)] bg-[var(--color-surface-0)] rounded-sm px-3 py-2.5 border-l-2 ${gp[e.severity]??`border-l-[var(--color-line-2)]`}`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 mb-1.5`,children:[(0,D.jsx)(W,{variant:hp[e.severity]??`gray`,children:e.severity}),(0,D.jsx)(`span`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)]`,children:e.type})]}),(0,D.jsx)(`p`,{className:`text-sm text-[var(--color-fg-1)] leading-relaxed`,children:e.message}),e.fix_command&&(0,D.jsxs)(`code`,{className:`text-[11px] text-[var(--color-brand)] font-mono mt-1.5 block`,children:[`$ `,e.fix_command]})]},t))})]}),t.anomalies.length>0&&(0,D.jsxs)(K,{children:[(0,D.jsx)(q,{children:(0,D.jsxs)(`span`,{className:`overline`,children:[`anomalies · `,t.anomalies.length]})}),(0,D.jsx)(J,{children:(0,D.jsx)(`div`,{className:`divide-y divide-[var(--color-line-0)]`,children:t.anomalies.map((e,t)=>(0,D.jsxs)(`div`,{className:`py-2 flex items-center gap-4 text-xs font-mono`,children:[(0,D.jsx)(`span`,{className:`w-24 text-[var(--color-brand)] uppercase tracking-wider text-[10px]`,children:e.type}),(0,D.jsxs)(`span`,{className:`w-10 tabular-nums text-[var(--color-fg-1)]`,children:[e.count,`×`]}),(0,D.jsxs)(`span`,{className:`w-20 tabular-nums text-[var(--color-fg-1)]`,children:[e.max_ms,`ms max`]}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)]`,children:e.likely_cause})]},t))})})]}),n.length>0&&(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`session history`}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)] tabular-nums`,children:[n.length,` session`,n.length===1?``:`s`]})]}),(0,D.jsx)(J,{className:`p-0`,children:(0,D.jsx)(`div`,{className:`divide-y divide-[var(--color-line-0)]`,children:[...n].reverse().map((e,t)=>(0,D.jsxs)(`div`,{className:`px-4 py-2.5 flex flex-wrap items-center gap-x-5 gap-y-1 text-xs ${e.is_current?`bg-amber-400/[0.04] border-l-2 border-l-amber-400/60`:``}`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 w-48 shrink-0`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] tabular-nums font-mono`,children:mp(e.start_ts)}),e.is_current&&(0,D.jsx)(W,{variant:`amber`,children:`current`})]}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-2)] tabular-nums font-mono w-20`,children:[e.evals,` eval`,e.evals===1?``:`s`]}),(0,D.jsxs)(`span`,{className:`text-emerald-300 tabular-nums font-mono`,children:[e.allowed,` allow`]}),e.blocked>0&&(0,D.jsxs)(`span`,{className:`text-red-300 tabular-nums font-mono`,children:[e.blocked,` block (`,e.block_rate_pct,`%)`]}),e.asked>0&&(0,D.jsxs)(`span`,{className:`text-sky-300 tabular-nums font-mono`,children:[e.asked,` ask`]}),e.forced>0&&(0,D.jsxs)(`span`,{className:`text-violet-300 tabular-nums font-mono`,children:[e.forced,` force`]}),e.avg_ns>0&&(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-3)] tabular-nums ml-auto font-mono`,children:[`avg `,pp(e.avg_ns)]}),e.top_rule&&(0,D.jsxs)(`a`,{href:`/rules?highlight=${encodeURIComponent(e.top_rule)}`,className:`text-[var(--color-fg-4)] hover:text-[var(--color-brand)] font-mono truncate max-w-xs transition-colors w-full pl-48`,title:`most blocked rule: ${e.top_rule}`,children:[`top block: `,e.top_rule]})]},t))})})]})]})}var vp={log:`text-[var(--color-fg-1)]`,info:`text-sky-300`,warn:`text-amber-300`,error:`text-red-300`,debug:`text-[var(--color-fg-3)]`};function yp(e){return e.value==null?e.description?e.description:`[${e.type}]`:String(e.value)}function bp(){let e=df(),[t,n]=(0,_.useState)(!1),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)([]),[s,c]=(0,_.useState)(null),[l,u]=(0,_.useState)(!1),d=(0,_.useRef)(null),f=(0,_.useRef)(0);(0,_.useEffect)(()=>{d.current?.scrollIntoView({behavior:`smooth`})},[]),(0,_.useEffect)(()=>{if(e.connected)return e.sendCommand(`Runtime.enable`).catch(()=>{}),e.onEvent(`Runtime.consoleAPICalled`,e=>{let t=e;o(e=>{let n=[...e,{id:f.current++,type:t.type??`log`,args:t.args??[],timestamp:t.timestamp??Date.now()}];return n.length>500?n.slice(-500):n})})},[e.connected,e.sendCommand,e.onEvent]);let p=(0,_.useCallback)(()=>{e.preconfiguredTarget&&e.connect(e.preconfiguredTarget.id)},[e]),m=(0,_.useCallback)(async()=>{try{await e.sendCommand(`Profiler.enable`),await e.sendCommand(`Profiler.start`),n(!0),i(null)}catch(e){console.error(`Profiler.start failed:`,e)}},[e]),h=(0,_.useCallback)(async()=>{try{let t=await e.sendCommand(`Profiler.stop`);n(!1),i(t.profile)}catch(e){console.error(`Profiler.stop failed:`,e),n(!1)}},[e]),g=(0,_.useCallback)(async()=>{u(!0);try{let t=await e.sendCommand(`Runtime.evaluate`,{expression:`JSON.stringify(process.memoryUsage())`,returnByValue:!0});c(JSON.parse(t.result.value))}catch{}finally{u(!1)}},[e]);function v(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/1024/1024).toFixed(1)}MB`}let y=e.connected?`connected${e.bunVersion?` · bun v${e.bunVersion}`:``}`:e.connecting?`connecting…`:e.active?`inspector active, connecting…`:`inspector not available`,b=e.connected?`bg-emerald-400`:e.connecting?`bg-amber-400 pulse-soft`:e.active?`bg-sky-400`:`bg-[var(--color-line-2)]`;return(0,D.jsxs)(`div`,{className:`space-y-5`,children:[(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`runtime inspector`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,D.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] font-mono text-[var(--color-fg-2)]`,children:[(0,D.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full ${b}`}),y]}),e.connected?(0,D.jsx)(G,{variant:`ghost`,size:`sm`,onClick:e.disconnect,children:`disconnect`}):(0,D.jsx)(G,{variant:`ghost`,size:`sm`,onClick:e.preconfiguredTarget?p:e.refetch,disabled:e.connecting,children:e.preconfiguredTarget?`reconnect`:`refresh`})]})]}),e.error&&(0,D.jsx)(J,{children:(0,D.jsx)(`p`,{className:`text-xs text-red-300 font-mono`,children:e.error})})]}),e.connected&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`cpu profiler`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t&&(0,D.jsxs)(`span`,{className:`text-[10px] font-mono uppercase tracking-wider text-red-300 flex items-center gap-1.5`,children:[(0,D.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-red-400 pulse-soft`}),`recording`]}),t?(0,D.jsx)(G,{variant:`danger`,size:`sm`,onClick:h,children:`stop & render`}):(0,D.jsx)(G,{variant:`primary`,size:`sm`,onClick:m,children:`start recording`})]})]}),(0,D.jsx)(J,{children:r?(0,D.jsx)(Ml,{profile:r,children:(0,D.jsx)(`div`,{className:`bg-[var(--color-surface-0)] border border-[var(--color-line-1)] rounded-sm p-2 overflow-x-hidden`,children:(0,D.jsx)(of,{profile:r})})}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:t?`recording… perform actions in ssg, then stop.`:`click start recording, perform actions, then stop.`})})]}),(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`memory`}),(0,D.jsx)(G,{variant:`ghost`,size:`sm`,onClick:g,disabled:l,children:l?`…`:`refresh`})]}),(0,D.jsx)(J,{children:s?(0,D.jsx)(Nl,{memory:s,formatValue:v}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:`click refresh to fetch process.memoryUsage().`})})]}),(0,D.jsxs)(K,{children:[(0,D.jsxs)(q,{className:`flex items-center justify-between`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`console`}),(0,D.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>o([]),children:`clear`})]}),(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`bg-[var(--color-surface-0)] border border-[var(--color-line-1)] rounded-sm p-2 h-56 overflow-y-auto font-mono text-[11px]`,children:[a.length===0?(0,D.jsx)(`p`,{className:`text-[var(--color-fg-4)]`,children:`console output will appear here…`}):a.map(e=>(0,D.jsxs)(`div`,{className:`py-0.5 border-b border-[var(--color-line-0)] ${vp[e.type]??`text-[var(--color-fg-1)]`}`,children:[(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)] mr-2 uppercase tracking-wider`,children:[`[`,e.type,`]`]}),e.args.map(yp).join(` `)]},e.id)),(0,D.jsx)(`div`,{ref:d})]})})]})]}),!e.connected&&!e.connecting&&(0,D.jsx)(`div`,{className:`rounded-sm border border-dashed border-[var(--color-line-1)] bg-[var(--color-surface-1)]/50 px-4 py-6 text-center`,children:(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:e.active?`waiting for inspector connection…`:`inspector auto-starts with ssg serve. profiler, memory, and console appear here once connected.`})})]})}function xp({active:e,onClick:t,children:n}){return(0,D.jsxs)(`button`,{onClick:t,className:`relative px-3 h-9 text-[11px] font-mono uppercase tracking-wider transition-colors cursor-pointer ${e?`text-[var(--color-fg-0)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,children:[n,e&&(0,D.jsx)(`span`,{className:`absolute inset-x-2 -bottom-px h-px bg-[var(--color-brand)]`})]})}function Sp(){let[e,t]=(0,_.useState)(`eval`);return(0,D.jsxs)(`div`,{className:`space-y-0`,children:[(0,D.jsxs)(`div`,{"data-tutorial":`profile-tabs`,className:`flex items-center border-b border-[var(--color-line-0)] mb-5`,children:[(0,D.jsx)(xp,{active:e===`eval`,onClick:()=>t(`eval`),children:`eval profile`}),(0,D.jsx)(xp,{active:e===`inspector`,onClick:()=>t(`inspector`),children:`runtime inspector`})]}),e===`eval`?(0,D.jsx)(_p,{}):(0,D.jsx)(bp,{})]})}var Cp=[{id:`destructive-ops`,title:`Destructive Operations`,description:`Commands that delete, overwrite, truncate, or irreversibly destroy files, data, or infrastructure.`,icon:`💥`,color:`#FF3B30`,attack:{id:`TA0040`,name:`Impact`},d3fend:`Harden`,security:!0,order:1},{id:`privilege-escalation`,title:`Privilege Escalation`,description:`sudo, permission and ownership changes, setuid manipulation, and capability grants.`,icon:`⬆️`,color:`#FF9500`,attack:{id:`TA0004`,name:`Privilege Escalation`},d3fend:`Isolate`,security:!0,order:2},{id:`code-execution`,title:`Untrusted Code Execution`,description:`Piping remote content into a shell, dynamic interpreters, and execution of unvetted code.`,icon:`⚙️`,color:`#FFCC00`,attack:{id:`TA0002`,name:`Execution`},d3fend:`Harden`,security:!0,order:3},{id:`credential-access`,title:`Credential & Secret Access`,description:`Reads of secrets, private keys, tokens, .env files, and cloud credentials.`,icon:`🔑`,color:`#AF52DE`,attack:{id:`TA0006`,name:`Credential Access`},d3fend:`Detect`,security:!0,order:4},{id:`network-egress`,title:`Network Egress & Exfiltration`,description:`Outbound network calls, uploads, reverse shells, and data leaving the machine.`,icon:`🌐`,color:`#5AC8FA`,attack:{id:`TA0010`,name:`Exfiltration`},d3fend:`Isolate`,security:!0,order:5},{id:`supply-chain`,title:`Supply Chain & Dependencies`,description:`Package installs, lockfile edits, registry changes, and dependency tampering.`,icon:`📦`,color:`#34C759`,attack:{id:`TA0042`,name:`Resource Development`},d3fend:`Harden`,security:!0,order:6},{id:`process-control`,title:`Process & System Control`,description:`Killing processes, daemonizing, service control, and resource exhaustion.`,icon:`🔌`,color:`#FF6482`,attack:{id:`TA0003`,name:`Persistence`},d3fend:`Isolate`,security:!0,order:7},{id:`version-control`,title:`Version Control Integrity`,description:`Force pushes, history rewrites, branch deletion, and git remote safety.`,icon:`🔀`,color:`#30B0C7`,attack:{id:`TA0005`,name:`Defense Evasion`},d3fend:`Harden`,security:!0,order:8},{id:`source-integrity`,title:`Source & Config Integrity`,description:`Edits to protected, generated, CI/CD, or governance-critical files.`,icon:`📐`,color:`#A2845E`,attack:{id:`TA0003`,name:`Persistence`},d3fend:`Harden`,security:!0,order:9},{id:`data-handling`,title:`Sensitive Data Handling`,description:`Database mutations, PII handling, and redaction of sensitive output.`,icon:`🗄️`,color:`#BF5AF2`,attack:{id:`TA0009`,name:`Collection`},d3fend:`Detect`,security:!0,order:10},{id:`agent-hygiene`,title:`Agent Hygiene & Efficiency`,description:`Tool-use best practices, token efficiency, and prompt hygiene — operational, not a security control.`,icon:`🧭`,color:`#8E8E93`,attack:null,d3fend:`Model`,security:!1,order:11},{id:`uncategorized`,title:`Uncategorized`,description:`Rules that have not declared a category.`,icon:`▫️`,color:`#636366`,attack:null,d3fend:`Model`,security:!1,order:99}],wp=new Map(Cp.map(e=>[e.id,e]));Cp.filter(e=>e.id!==`uncategorized`).map(e=>e.id);function Tp(e){return typeof e==`string`&&e!==`uncategorized`&&wp.has(e)}function Ep(e){return e!==void 0&&wp.get(e)||wp.get(`uncategorized`)}var Dp=[{token:`destructive`,category:`destructive-ops`},{token:`exfil`,category:`network-egress`},{token:`credential`,category:`credential-access`},{token:`secret`,category:`credential-access`},{token:`privilege`,category:`privilege-escalation`},{token:`privesc`,category:`privilege-escalation`},{token:`powergate`,category:`process-control`},{token:`process`,category:`process-control`},{token:`powersafety`,category:`process-control`},{token:`injection`,category:`code-execution`},{token:`untrusted`,category:`code-execution`},{token:`supply`,category:`supply-chain`},{token:`dependenc`,category:`supply-chain`},{token:`npm`,category:`supply-chain`},{token:`pnpm`,category:`supply-chain`},{token:`cargo`,category:`supply-chain`},{token:`cicd`,category:`supply-chain`},{token:`publish`,category:`supply-chain`},{token:`git`,category:`version-control`},{token:`network`,category:`network-egress`},{token:`egress`,category:`network-egress`},{token:`database`,category:`data-handling`},{token:`sql`,category:`data-handling`},{token:`critical`,category:`source-integrity`},{token:`drm`,category:`source-integrity`},{token:`config`,category:`source-integrity`},{token:`integrity`,category:`source-integrity`},{token:`infra`,category:`source-integrity`},{token:`agent`,category:`agent-hygiene`},{token:`efficiency`,category:`agent-hygiene`},{token:`hygiene`,category:`agent-hygiene`}];function Op(e,t){let n=(t??e.source_file??``).toLowerCase(),r=n?n.split(/[\\/]/).pop()??n:``,i=`${e.id.toLowerCase()} ${r}`;for(let e of Dp)if(i.includes(e.token))return e.category;return e.target===`agent`?`agent-hygiene`:e.target===`network`?`network-egress`:`uncategorized`}function kp(e,t){return e.category!==void 0&&Tp(e.category)?e.category:Op(e,t)}function Ap(e,t){let n=new Map;for(let e of Cp)n.set(e.id,{id:e.id,meta:e,total:0,enabled:0,enabledShell:0,decisions:{},status:`gap`});let r=0;for(let i of e){let e=kp(i,t?.(i)),a=n.get(e);a.total++,e===`uncategorized`&&r++,i.enabled!==!1&&(a.enabled++,a.decisions[i.decision]=(a.decisions[i.decision]??0)+1,(i.target===`execution`||i.target===`any`)&&a.enabledShell++)}for(let e of n.values())e.status=e.enabled>0?`covered`:e.total>0?`inactive`:`gap`;let i=[...n.values()].sort((e,t)=>e.meta.order-t.meta.order),a=i.filter(e=>e.meta.security&&e.id!==`uncategorized`);return{categories:i,covered:a.filter(e=>e.status===`covered`).length,total:a.length,uncategorized:r}}var jp=new Set([`block`,`ask`,`force`,`deny`]),Mp=[`rules-changed`],Np=[`block`,`ask`,`log`,`allow`,`force`,`shadow`],Pp={block:`text-red-300`,deny:`text-red-300`,ask:`text-sky-300`,allow:`text-emerald-300`,log:`text-[var(--color-fg-3)]`,force:`text-amber-300`,shadow:`text-violet-300`,ambient:`text-teal-300`},Fp={block:`#fca5a5`,deny:`#fca5a5`,ask:`#7dd3fc`,allow:`#6ee7b7`,log:`#a8a29e`,force:`#fcd34d`,shadow:`#c4b5fd`},Ip=[{value:`today`,label:`today`},{value:`7d`,label:`7d`},{value:`30d`,label:`30d`},{value:`all`,label:`all`}],Lp=5e3;function Rp(e,t){return t<=0?e:`${e}${e.includes(`?`)?`&`:`?`}_t=${t}`}async function zp(e,t){await fetch(`/api/rules/toggle`,{method:`POST`,headers:{"Content-Type":`application/json`,Accept:`application/json`,...U()},body:JSON.stringify({ruleId:e,file:t})})}async function Bp(e,t,n){await fetch(`/api/rules/update-decision`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({ruleId:e,file:t,decision:n})})}async function Vp(e,t){return fetch(`/api/rules/bulk-set-enabled`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({targets:e,enabled:t})}).then(e=>e.json())}async function Hp(e,t){return fetch(`/api/rules/bulk-update-decision`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({targets:e,decision:t})}).then(e=>e.json())}async function Up(e){return fetch(`/api/rules/bulk-delete`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({targets:e})}).then(e=>e.json())}async function Wp(e,t={}){return fetch(`/api/rules/${e}`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify(t)}).then(e=>e.json())}function Gp(e){if(!e)return`never`;let t=Date.now()/1e3-e;return t<60?`${Math.floor(t)}s ago`:t<3600?`${Math.floor(t/60)}m ago`:t<86400?`${Math.floor(t/3600)}h ago`:`${Math.floor(t/86400)}d ago`}function Kp(e,t,n,r){let i=Array(t).fill(0);if(!e||e.length===0)return i;let a=Date.now(),o=a-n,s=n/t;for(let n of e){let e=n.timestamp*1e3;if(e<o||e>a||r&&!r(n))continue;let c=Math.min(t-1,Math.floor((e-o)/s));i[c]+=1}return i}function qp({active:e}){return(0,D.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-[10px] font-mono uppercase tracking-wider`,children:[(0,D.jsxs)(`span`,{className:`relative inline-flex h-2 w-2`,children:[e&&(0,D.jsx)(`span`,{className:`absolute inline-flex h-full w-full animate-ping rounded-full bg-emerald-400/60`}),(0,D.jsx)(`span`,{className:`relative inline-flex h-2 w-2 rounded-full ${e?`bg-emerald-400`:`bg-[var(--color-fg-4)]`}`})]}),(0,D.jsx)(`span`,{className:e?`text-emerald-300`:`text-[var(--color-fg-4)]`,children:e?`live`:`paused`})]})}function Jp({mode:e,onChange:t}){return(0,D.jsxs)(`div`,{className:`flex items-center text-[10px] font-mono uppercase tracking-wider border border-[var(--color-line-1)] rounded-sm overflow-hidden`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:()=>t(`newcomer`),className:`px-2 py-1 cursor-pointer transition-colors ${e===`newcomer`?`bg-[var(--color-brand)]/15 text-[var(--color-fg-0)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,title:`Hide advanced controls (firewall, raw source, audit, AI hints)`,children:`simple`}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>t(`pro`),className:`px-2 py-1 cursor-pointer transition-colors border-l border-[var(--color-line-1)] ${e===`pro`?`bg-[var(--color-brand)]/15 text-[var(--color-fg-0)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,title:`Show everything: top-rules chart, performance, firewall, audit trails, raw source, curl recipes`,children:`advanced`})]})}function Yp({rule:e,file:t,onToggle:n}){let[r,i]=(0,_.useState)(!1);return(0,D.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,D.jsx)(`span`,{className:`text-[10px] font-mono uppercase tracking-wider ${e.enabled?`text-[var(--color-fg-1)]`:`text-[var(--color-fg-4)]`}`,children:e.enabled?`on`:`off`}),(0,D.jsx)(rn,{size:`sm`,checked:e.enabled,disabled:r,label:`${e.enabled?`Disable`:`Enable`} rule ${e.id}`,onChange:async()=>{i(!0);try{await n()}finally{i(!1)}}})]})}function Xp(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(!1),[i,a]=(0,_.useState)(!1);(0,_.useEffect)(()=>{let e=!1;return(async()=>{try{let n=await fetch(`/api/json/rule-write-enforcement`,{headers:{Accept:`application/json`}});if(!n.ok)return;let r=await n.json();!e&&typeof r.enforced==`boolean`&&t(r.enforced)}catch{}})(),()=>{e=!0}},[]);async function o(e){r(!0);try{let n=await fetch(`/api/json/rule-write-enforcement`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({enforced:e})});if(n.ok){let e=await n.json();typeof e.enforced==`boolean`&&t(e.enforced)}}finally{r(!1),a(!1)}}if(e===null)return null;let s=!e;return(0,D.jsx)(K,{className:s?`border-amber-500/40 bg-amber-500/5`:`border-[var(--color-line-1)]`,children:(0,D.jsx)(J,{className:`px-3 py-2.5`,children:(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,D.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-1)]`,children:`rule-write protection`}),(0,D.jsx)(`span`,{className:`text-[11px] font-mono uppercase tracking-wider ${s?`text-amber-300`:`text-emerald-300`}`,children:s?`disabled`:`enforced`})]}),(0,D.jsx)(`p`,{className:`text-[11px] text-[var(--color-fg-3)] mt-1 leading-snug`,children:s?`Agents can currently Write/Edit .rules files. Turn this back on when you finish authoring.`:`Agents cannot Write/Edit/MultiEdit any .sigmashake/rules/**/*.rules file. Disable only when curating rulesets.`})]}),(0,D.jsx)(`div`,{className:`shrink-0`,children:i?(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,D.jsx)(`button`,{onClick:()=>o(!1),disabled:n,className:`text-[11px] font-mono uppercase tracking-wider bg-amber-500/10 border border-amber-500/40 text-amber-200 hover:bg-amber-500/20 rounded-sm px-2 py-0.5 cursor-pointer transition-colors disabled:opacity-50`,children:`disable`}),(0,D.jsx)(`button`,{onClick:()=>a(!1),disabled:n,className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer disabled:opacity-50`,children:`cancel`})]}):(0,D.jsx)(`button`,{onClick:()=>{e?a(!0):o(!0)},disabled:n,className:`text-[11px] font-mono uppercase tracking-wider border rounded-sm px-2.5 py-0.5 cursor-pointer transition-colors disabled:opacity-50 ${s?`bg-emerald-500/10 border-emerald-500/40 text-emerald-200 hover:bg-emerald-500/20`:`bg-[var(--color-surface-1)] border-[var(--color-line-1)] text-[var(--color-fg-1)] hover:bg-[var(--color-surface-2)]`}`,children:s?`enable`:`disable`})})]})})})}function Zp({perf:e,triggers:t,decisionAggregates:n,livePoll:r,onTogglePoll:i,statsWindow:a,onWindowChange:o,mode:s,onModeChange:c}){let l=t?.evalsLast60s??0,u=t?.evalsLastHour??0,d=(0,_.useMemo)(()=>Kp(t?.rows,30,3600*1e3),[t?.rows]),f=(0,_.useMemo)(()=>Kp(t?.rows,30,3600*1e3,e=>jp.has(e.decision)),[t?.rows]),p={allow:n.hits.allow??0,block:n.hits.block??0,ask:n.hits.ask??0,log:n.hits.log??0,force:n.hits.force??0,shadow:n.hits.shadow??0},m=Object.values(p).reduce((e,t)=>e+t,0),h=e?.totalRules??0,g=e?.activeRules??0,v=h>0?g/h*100:0,y=l/60;return(0,D.jsx)(K,{className:`border-[var(--color-line-1)]`,children:(0,D.jsxs)(J,{className:`px-4 py-3 space-y-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline text-[10px]`,children:`rules active`}),(0,D.jsxs)(`div`,{className:`font-mono text-2xl text-[var(--color-fg-0)] tabular-nums leading-none mt-0.5`,children:[(0,D.jsx)(Ks,{value:g}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)] text-base`,children:[`/`,h]})]}),(0,D.jsxs)(`div`,{className:`overline text-[10px] mt-1 text-[var(--color-fg-3)]`,children:[v.toFixed(0),`% on`]})]}),(0,D.jsx)(`div`,{className:`h-12 w-px bg-[var(--color-line-1)] hidden md:block`}),(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`overline text-[10px]`,children:`evals · last 60s`}),(0,D.jsx)(qp,{active:r})]}),(0,D.jsx)(`div`,{className:`font-mono text-2xl text-emerald-300 tabular-nums leading-none mt-0.5`,children:(0,D.jsx)(Ks,{value:l,curve:`spring`})}),(0,D.jsxs)(`div`,{className:`overline text-[10px] mt-1 text-[var(--color-fg-3)]`,children:[`~`,y.toFixed(1),`/s`]})]}),(0,D.jsx)(`div`,{className:`h-12 w-px bg-[var(--color-line-1)] hidden md:block`}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline text-[10px]`,children:`last hour`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2 mt-0.5`,children:[(0,D.jsx)(`span`,{className:`font-mono text-2xl text-[var(--color-fg-1)] tabular-nums leading-none`,children:(0,D.jsx)(Ks,{value:u})}),(0,D.jsx)(Js,{data:d,width:120,height:32,color:`var(--color-brand)`})]}),(0,D.jsx)(`div`,{className:`overline text-[10px] mt-1 text-[var(--color-fg-3)]`,children:`evals · 2-min buckets`})]}),(0,D.jsxs)(`div`,{className:`ml-auto flex items-center gap-2`,children:[(0,D.jsx)(Jp,{mode:s,onChange:c}),(0,D.jsx)(`button`,{type:`button`,onClick:i,className:`text-[10px] font-mono uppercase tracking-wider px-2 py-1 rounded-sm border border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer transition-colors`,title:r?`Pause auto-refresh`:`Resume auto-refresh`,children:r?`⏸ pause`:`▶ resume`}),(0,D.jsx)(`div`,{className:`flex items-center text-[10px] font-mono uppercase tracking-wider border border-[var(--color-line-1)] rounded-sm`,children:Ip.map((e,t)=>(0,D.jsx)(`button`,{onClick:()=>o(e.value),className:`px-1.5 py-1 cursor-pointer transition-colors ${t>0?`border-l border-[var(--color-line-1)]`:``} ${a===e.value?`bg-[var(--color-brand)]/15 text-[var(--color-fg-0)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,children:e.label},e.value))})]})]}),(m>0||f.some(e=>e>0))&&(0,D.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-[1.4fr_1fr] gap-4 pt-2 border-t border-[var(--color-line-0)]`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,D.jsxs)(`span`,{className:`overline text-[10px]`,children:[`decision mix · `,a]}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)] tabular-nums`,children:[m.toLocaleString(),` hits`]})]}),(0,D.jsx)(qs,{counters:p,showLegend:!0})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between mb-1.5`,children:[(0,D.jsx)(`span`,{className:`overline text-[10px]`,children:`block/ask/force · last hour`}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-amber-300 tabular-nums`,children:[f.reduce((e,t)=>e+t,0),` actionable`]})]}),(0,D.jsx)(Js,{data:f,width:400,height:48,color:`#fca5a5`})]})]})]})})}function Qp({perf:e}){if(!e)return null;let t=e.avgEvalMs>50?`text-amber-300`:e.avgEvalMs>100?`text-red-300`:`text-emerald-300`;return(0,D.jsx)(K,{children:(0,D.jsxs)(J,{className:`px-3 py-2.5`,children:[(0,D.jsxs)(`div`,{className:`flex items-baseline gap-4 flex-wrap`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline text-[10px]`,children:`avg eval`}),(0,D.jsxs)(`div`,{className:`font-mono text-sm tabular-nums ${t}`,children:[e.avgEvalMs.toFixed(1),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] ml-0.5 text-[10px]`,children:`ms`})]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline text-[10px]`,children:`p95`}),(0,D.jsxs)(`div`,{className:`font-mono text-sm text-[var(--color-fg-1)] tabular-nums`,children:[e.p95EvalMs.toFixed(1),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] ml-0.5 text-[10px]`,children:`ms`})]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline text-[10px]`,children:`per-rule`}),(0,D.jsxs)(`div`,{className:`font-mono text-sm text-[var(--color-fg-1)] tabular-nums`,children:[`~`,e.perRuleMs.toFixed(3),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] ml-0.5 text-[10px]`,children:`ms`})]})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`overline text-[10px]`,children:`evals today`}),(0,D.jsx)(`div`,{className:`font-mono text-sm text-[var(--color-fg-1)] tabular-nums`,children:e.evalsToday.toLocaleString()})]}),(0,D.jsxs)(`div`,{className:`ml-auto text-right`,children:[(0,D.jsx)(`div`,{className:`overline text-[10px]`,children:`all-time evals`}),(0,D.jsx)(`div`,{className:`font-mono text-sm text-[var(--color-fg-2)] tabular-nums`,children:e.evalsAllTime.toLocaleString()})]})]}),e.avgEvalMs>50&&(0,D.jsx)(`p`,{className:`mt-2 text-[11px] text-amber-300/80`,children:`⚡ avg eval > 50ms — consider trimming or disabling low-value rules.`})]})})}function $p({stats:e,ruleIndex:t,triggers:n,statsWindow:r,onJump:i}){let a=(0,_.useMemo)(()=>{let r=Object.entries(e).filter(([,e])=>e.hits>0).sort(([,e],[,t])=>t.hits-e.hits).slice(0,10),i=r[0]?.[1].hits??1;return r.map(([e,r])=>{let a=t.get(e),o=Kp(n,20,3600*1e3,t=>t.ruleId===e);return{id:e,stat:r,entry:a,pct:r.hits/i*100,sparkData:o,color:a?Fp[a.rule.decision]??`#a8a29e`:`#a8a29e`}})},[e,t,n]);return a.length===0?(0,D.jsx)(K,{children:(0,D.jsxs)(J,{className:`px-3 py-3`,children:[(0,D.jsxs)(`div`,{className:`overline text-[10px] mb-1`,children:[`top rules · `,r]}),(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:`no rules have fired in this window yet`})]})}):(0,D.jsx)(K,{children:(0,D.jsxs)(J,{className:`px-3 py-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,D.jsxs)(`span`,{className:`overline text-[10px]`,children:[`top rules · `,r]}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)] tabular-nums`,children:[`top `,a.length,` · click to jump`]})]}),(0,D.jsx)(`div`,{className:`space-y-1`,children:a.map(e=>(0,D.jsxs)(`button`,{type:`button`,onClick:()=>i(e.id),className:`w-full text-left group cursor-pointer`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono`,children:[(0,D.jsx)(`span`,{className:`uppercase tracking-wider w-12 shrink-0 ${e.entry?Pp[e.entry.rule.decision]??`text-[var(--color-fg-2)]`:`text-[var(--color-fg-4)]`}`,children:e.entry?.rule.decision??`—`}),(0,D.jsx)(`code`,{className:`text-[var(--color-fg-1)] group-hover:text-[var(--color-fg-0)] truncate flex-1 min-w-0`,children:e.id}),(0,D.jsx)(Js,{data:e.sparkData,width:60,height:16,color:e.color}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] tabular-nums shrink-0 w-10 text-right`,children:e.stat.hits}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-3)] tabular-nums shrink-0 w-14 text-right`,children:[e.stat.avgDurationMs.toFixed(1),`ms`]}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] tabular-nums shrink-0 w-14 text-right`,children:Gp(e.stat.lastSeen)})]}),(0,D.jsx)(`div`,{className:`relative h-1 mt-1 mb-1 bg-[var(--color-surface-2)] rounded-sm overflow-hidden`,children:(0,D.jsx)(`div`,{className:`absolute inset-y-0 left-0 rounded-sm transition-[width] duration-500 ease-out`,style:{width:`${e.pct}%`,background:e.color,opacity:.6}})})]},e.id))})]})})}function em({totalRules:e,activeRules:t,onChanged:n}){let[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(null);async function s(e){i(e);try{e===`disable`?await Wp(`disable-all`):e===`enable`?await Wp(`enable-all`):await Wp(`uninstall-all`,{confirm:`UNINSTALL_ALL_RULES`}),n()}finally{i(null),o(null)}}return(0,D.jsx)(K,{className:`border-[var(--color-line-1)]`,children:(0,D.jsx)(J,{className:`px-3 py-2.5`,children:(0,D.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,D.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-1)]`,children:`rule firewall`}),(0,D.jsxs)(`span`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)]`,children:[t,`/`,e,` active`]})]}),(0,D.jsxs)(`p`,{className:`text-[11px] text-[var(--color-fg-3)] mt-1 leading-snug`,children:[`Master switches across every installed ruleset. Disable / enable are reversible; uninstall wipes `,(0,D.jsx)(`code`,{children:`~/.sigmashake/rules/`}),`.`]})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[a===`disable`?(0,D.jsx)(tm,{onConfirm:()=>void s(`disable`),onCancel:()=>o(null),tone:`amber`,label:`disable ${t} rules`,disabled:r!==null}):(0,D.jsx)(`button`,{onClick:()=>o(`disable`),disabled:r!==null||t===0,className:`text-[11px] font-mono uppercase tracking-wider bg-amber-500/10 border border-amber-500/40 text-amber-200 hover:bg-amber-500/20 rounded-sm px-2.5 py-0.5 cursor-pointer transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:r===`disable`?`disabling…`:`disable all`}),a===`enable`?(0,D.jsx)(tm,{onConfirm:()=>void s(`enable`),onCancel:()=>o(null),tone:`emerald`,label:`enable ${e-t} rules`,disabled:r!==null}):(0,D.jsx)(`button`,{onClick:()=>o(`enable`),disabled:r!==null||t===e,className:`text-[11px] font-mono uppercase tracking-wider bg-emerald-500/10 border border-emerald-500/40 text-emerald-200 hover:bg-emerald-500/20 rounded-sm px-2.5 py-0.5 cursor-pointer transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:r===`enable`?`enabling…`:`enable all`}),a===`uninstall`?(0,D.jsx)(tm,{onConfirm:()=>void s(`uninstall`),onCancel:()=>o(null),tone:`red`,label:`UNINSTALL ${e} rules`,disabled:r!==null}):(0,D.jsx)(`button`,{onClick:()=>o(`uninstall`),disabled:r!==null||e===0,className:`text-[11px] font-mono uppercase tracking-wider bg-red-500/10 border border-red-500/40 text-red-200 hover:bg-red-500/20 rounded-sm px-2.5 py-0.5 cursor-pointer transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:r===`uninstall`?`uninstalling…`:`uninstall all`})]})]})})})}function tm({onConfirm:e,onCancel:t,tone:n,label:r,disabled:i}){let a={amber:`bg-amber-500/10 border-amber-500/40 text-amber-200 hover:bg-amber-500/20`,emerald:`bg-emerald-500/10 border-emerald-500/40 text-emerald-200 hover:bg-emerald-500/20`,red:`bg-red-500/10 border-red-500/40 text-red-200 hover:bg-red-500/20`}[n];return(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,D.jsxs)(`button`,{onClick:e,disabled:i,className:`text-[11px] font-mono uppercase tracking-wider border rounded-sm px-2 py-0.5 cursor-pointer transition-colors disabled:opacity-50 ${a}`,children:[`confirm: `,r]}),(0,D.jsx)(`button`,{onClick:t,disabled:i,className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer disabled:opacity-50`,children:`cancel`})]})}function nm({selected:e,onClear:t,onApply:n}){let[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(`block`),[s,c]=(0,_.useState)(!1);if(e.length===0)return null;async function l(e,t){i(e);try{await n(e,t)}finally{i(null),c(!1)}}return(0,D.jsx)(`div`,{className:`sticky top-0 z-20 -mx-1 px-1`,children:(0,D.jsx)(K,{className:`border-sky-500/40 bg-sky-500/5 backdrop-blur`,children:(0,D.jsx)(J,{className:`px-3 py-2`,children:(0,D.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,D.jsxs)(`span`,{className:`text-[11px] font-mono uppercase tracking-wider text-sky-200`,children:[e.length,` selected`]}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsx)(`button`,{onClick:()=>void l(`enable`),disabled:r!==null,className:`text-[11px] font-mono uppercase tracking-wider bg-emerald-500/10 border border-emerald-500/40 text-emerald-200 hover:bg-emerald-500/20 rounded-sm px-2 py-0.5 cursor-pointer transition-colors disabled:opacity-50`,children:r===`enable`?`…`:`enable`}),(0,D.jsx)(`button`,{onClick:()=>void l(`disable`),disabled:r!==null,className:`text-[11px] font-mono uppercase tracking-wider bg-amber-500/10 border border-amber-500/40 text-amber-200 hover:bg-amber-500/20 rounded-sm px-2 py-0.5 cursor-pointer transition-colors disabled:opacity-50`,children:r===`disable`?`…`:`disable`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-1`,children:[(0,D.jsx)(`select`,{value:a,onChange:e=>o(e.target.value),disabled:r!==null,className:`bg-[var(--color-surface-0)] border border-[var(--color-line-1)] rounded-sm px-1.5 py-0.5 text-[11px] font-mono uppercase tracking-wider cursor-pointer focus:outline-none focus:border-[var(--color-brand)]/50 ${Pp[a]??`text-[var(--color-fg-2)]`}`,children:Np.map(e=>(0,D.jsx)(`option`,{value:e,children:e},e))}),(0,D.jsx)(`button`,{onClick:()=>void l(`decision`,a),disabled:r!==null,className:`text-[11px] font-mono uppercase tracking-wider bg-sky-500/10 border border-sky-500/40 text-sky-200 hover:bg-sky-500/20 rounded-sm px-2 py-0.5 cursor-pointer transition-colors disabled:opacity-50`,children:r===`decision`?`…`:`set decision`})]}),s?(0,D.jsx)(tm,{onConfirm:()=>void l(`delete`),onCancel:()=>c(!1),tone:`red`,label:`delete ${e.length}`,disabled:r!==null}):(0,D.jsx)(`button`,{onClick:()=>c(!0),disabled:r!==null,className:`text-[11px] font-mono uppercase tracking-wider bg-red-500/10 border border-red-500/40 text-red-200 hover:bg-red-500/20 rounded-sm px-2 py-0.5 cursor-pointer transition-colors disabled:opacity-50`,children:`delete…`}),(0,D.jsx)(`button`,{onClick:t,disabled:r!==null,className:`ml-auto text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer disabled:opacity-50`,children:`clear`})]})})})})}function rm({ruleId:e}){let[t,n]=(0,_.useState)(null),[r,i]=(0,_.useState)(!0);return(0,_.useEffect)(()=>{let t=!1;return i(!0),fetch(`/api/json/rule-audit?ruleId=${encodeURIComponent(e)}&limit=25`).then(e=>e.json()).then(e=>{t||n(e)}).catch(()=>{}).finally(()=>{t||i(!1)}),()=>{t=!0}},[e]),r?(0,D.jsx)(`p`,{className:`mt-1.5 text-[11px] font-mono text-[var(--color-fg-3)]`,children:`loading audit…`}):!t||t.rows.length===0?(0,D.jsx)(`p`,{className:`mt-1.5 text-[11px] font-mono text-[var(--color-fg-3)]`,children:`no audit entries for this rule`}):(0,D.jsxs)(`div`,{className:`mt-2 border border-[var(--color-line-0)] rounded-sm overflow-hidden`,children:[(0,D.jsx)(`div`,{className:`bg-[var(--color-surface-0)] px-2 py-1 flex items-center gap-2`,children:(0,D.jsxs)(`span`,{className:`overline text-[10px]`,children:[`audit log — last `,t.rows.length,` of `,t.total]})}),(0,D.jsx)(`div`,{className:`divide-y divide-[var(--color-line-0)] max-h-64 overflow-y-auto`,children:t.rows.map(e=>(0,D.jsxs)(`div`,{className:`px-2 py-1.5 flex items-center gap-3 text-[11px] font-mono`,children:[(0,D.jsx)(`span`,{className:`uppercase tracking-wider w-14 shrink-0 ${Pp[e.decision]??`text-[var(--color-fg-2)]`}`,children:e.decision}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)] w-20 shrink-0 truncate`,children:e.tool}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] flex-1 min-w-0 truncate`,children:e.input}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] tabular-nums shrink-0`,children:e.duration_ns?`${Math.round(e.duration_ns/1e6)}ms`:`–`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] tabular-nums shrink-0 w-16 text-right`,children:Gp(e.timestamp)})]},e.id))})]})}function im(){let[e,t]=(0,_.useState)(!1);return(0,D.jsx)(K,{children:(0,D.jsxs)(`details`,{open:e,onToggle:e=>t(e.target.open),children:[(0,D.jsxs)(`summary`,{className:`px-3 py-2 cursor-pointer list-none select-none flex items-center gap-2 hover:bg-[var(--color-surface-2)]/70`,children:[(0,D.jsx)(`span`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-1)]`,children:`ai-native config`}),(0,D.jsx)(`span`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:`curl recipes — every UI action is also a JSON endpoint`}),(0,D.jsx)(`svg`,{className:`ml-auto text-[var(--color-fg-3)]`,width:`10`,height:`10`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,D.jsx)(`polyline`,{points:e?`6 15 12 9 18 15`:`6 9 12 15 18 9`})})]}),(0,D.jsxs)(J,{className:`py-2`,children:[(0,D.jsxs)(`p`,{className:`text-[11px] text-[var(--color-fg-3)] mb-2 leading-snug`,children:[`Point an agent at `,(0,D.jsx)(`code`,{children:`http://127.0.0.1:7901`}),`. Every bulk action below is one POST — no UI scraping required.`]}),(0,D.jsx)(`pre`,{className:`text-[10px] font-mono text-[var(--color-fg-2)] bg-[var(--color-surface-0)] border border-[var(--color-line-0)] rounded-sm p-2 overflow-x-auto whitespace-pre`,children:`# list rules + stats
29
29
  curl :7901/api/json/rules
30
30
  curl :7901/api/json/rules-stats?window=7d
31
31
  curl :7901/api/json/rules-performance
@@ -47,12 +47,12 @@ curl -X POST :7901/api/rules/disable-all
47
47
  curl -X POST :7901/api/rules/enable-all
48
48
  curl -X POST :7901/api/rules/uninstall-all \\
49
49
  -H 'content-type: application/json' \\
50
- -d '{"confirm":"UNINSTALL_ALL_RULES"}'`})]})]})})}function nm({entry:e,ruleId:t,onJump:n,onChanged:r}){return!e||!t?(0,D.jsx)(`span`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-4)] shrink-0`,children:`no rule`}):(0,D.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:async()=>{await Lp(t,e.file,`log`),r()},title:`Soften this rule to log-only — keeps the rule running but stops blocking/asking`,className:`px-1.5 py-0.5 rounded-sm border border-[var(--color-line-1)] text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-0)] hover:border-[var(--color-brand)]/60 cursor-pointer transition-colors`,children:`→ log`}),(0,D.jsx)(`button`,{type:`button`,onClick:async()=>{e.rule.enabled&&(await Ip(t,e.file),r())},disabled:!e.rule.enabled,title:e.rule.enabled?`Disable this rule entirely`:`Rule is already disabled`,className:`px-1.5 py-0.5 rounded-sm border border-[var(--color-line-1)] text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-red-300 hover:border-red-400/60 cursor-pointer transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:e.rule.enabled?`disable`:`disabled`}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>n(t),title:`Scroll to this rule below — clears search and filter`,className:`px-1.5 py-0.5 rounded-sm border border-[var(--color-brand)]/40 bg-[var(--color-brand)]/10 text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-0)] hover:bg-[var(--color-brand)]/20 cursor-pointer transition-colors`,children:`view`})]})}function rm({stats:e,ruleIndex:t,onJump:n,onChanged:r}){let i=(0,_.useMemo)(()=>{let n=[];for(let[r,i]of Object.entries(e)){let e=i.lastBlockAskSeen??0;e<=0||n.push({ruleId:r,lastBlockAskSeen:e,entry:t.get(r)})}return n.sort((e,t)=>t.lastBlockAskSeen-e.lastBlockAskSeen),n.slice(0,5)},[e,t]);return i.length===0?null:(0,D.jsx)(K,{children:(0,D.jsxs)(`details`,{open:!0,children:[(0,D.jsxs)(`summary`,{className:`px-3 py-2 cursor-pointer list-none select-none flex items-center gap-3 hover:bg-[var(--color-surface-2)]/70`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`recent block/ask activity`}),(0,D.jsxs)(`span`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:[i.length,` rule`,i.length===1?``:`s`,` — newest first`]})]}),(0,D.jsx)(J,{className:`py-2`,children:(0,D.jsx)(`div`,{className:`divide-y divide-[var(--color-line-0)]`,children:i.map(e=>{let t=e.entry?.rule.decision??`—`,i=e.entry?.rule.message??``;return(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono py-1.5`,children:[(0,D.jsx)(`span`,{className:`uppercase tracking-wider w-12 shrink-0 ${jp[t]??`text-[var(--color-fg-2)]`}`,children:t}),(0,D.jsx)(`code`,{className:`text-[var(--color-fg-0)] shrink-0 truncate w-48`,children:e.ruleId}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] truncate flex-1 min-w-0 hidden md:inline`,children:i}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] tabular-nums shrink-0 w-16 text-right`,children:Hp(e.lastBlockAskSeen)}),(0,D.jsx)(nm,{entry:e.entry,ruleId:e.ruleId,onJump:n,onChanged:r})]},e.ruleId)})})})]})})}function im({triggers:e,ruleIndex:t,onJump:n,onChanged:r}){let i=Math.floor(Date.now()/1e3),a=i-24*3600,o=i-4*3600,s=(e??[]).filter(e=>e.ruleId&&Op.has(e.decision)),c=s[0]??null,l=new Map;for(let e of s){if(e.timestamp<a||!e.ruleId)continue;let t=l.get(e.ruleId);t?(t.hits++,e.timestamp>t.lastSeen&&(t.lastSeen=e.timestamp,t.sample=e)):l.set(e.ruleId,{ruleId:e.ruleId,decision:e.decision,hits:1,lastSeen:e.timestamp,sample:e})}let u=[...l.values()].filter(e=>e.hits>=3).sort((e,t)=>t.hits-e.hits).slice(0,5),d=c&&c.timestamp>=o;return d||u.length>0?(0,D.jsx)(K,{children:(0,D.jsxs)(`details`,{open:!0,children:[(0,D.jsxs)(`summary`,{className:`px-3 py-2 cursor-pointer list-none select-none flex items-center gap-3 hover:bg-[var(--color-surface-2)]/70 flex-wrap`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`recent decisions`}),d&&c&&(0,D.jsxs)(`span`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:[`last:`,` `,(0,D.jsx)(`span`,{className:jp[c.decision]??`text-[var(--color-fg-2)]`,children:c.decision}),` `,`· `,Hp(c.timestamp)]}),u.length>0&&(0,D.jsxs)(`span`,{className:`text-[11px] font-mono text-amber-300/80 ml-auto`,children:[u.length,` rule`,u.length===1?``:`s`,` fired ≥3× in 24h`]})]}),(0,D.jsxs)(J,{className:`py-2 space-y-3`,children:[d&&c&&(0,D.jsxs)(`div`,{className:`space-y-1`,children:[(0,D.jsx)(`div`,{className:`overline`,children:`last decision`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono`,children:[(0,D.jsx)(`span`,{className:`uppercase tracking-wider w-12 shrink-0 ${jp[c.decision]??`text-[var(--color-fg-2)]`}`,children:c.decision}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)] w-20 shrink-0 truncate`,children:c.tool}),(0,D.jsx)(`code`,{className:`text-[var(--color-fg-1)] flex-1 min-w-0 truncate`,children:c.input||`—`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] tabular-nums shrink-0 w-16 text-right`,children:Hp(c.timestamp)}),(0,D.jsx)(nm,{entry:c.ruleId?t.get(c.ruleId):void 0,ruleId:c.ruleId,onJump:n,onChanged:r})]}),c.ruleId&&(0,D.jsxs)(`div`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] pl-14`,children:[`rule`,` `,(0,D.jsx)(`code`,{className:`text-[var(--color-fg-2)]`,children:c.ruleId})]})]}),u.length>0&&(0,D.jsxs)(`div`,{className:`space-y-1`,children:[(0,D.jsx)(`div`,{className:`overline`,children:`top fired in 24h (≥3 hits) — soften or disable to reduce noise`}),(0,D.jsx)(`div`,{className:`divide-y divide-[var(--color-line-0)]`,children:u.map(e=>{let i=t.get(e.ruleId);return(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono py-1.5`,children:[(0,D.jsxs)(`span`,{className:`text-amber-300 tabular-nums shrink-0 w-10`,children:[e.hits,`×`]}),(0,D.jsx)(`span`,{className:`uppercase tracking-wider w-12 shrink-0 ${jp[e.decision]??`text-[var(--color-fg-2)]`}`,children:e.decision}),(0,D.jsx)(`code`,{className:`text-[var(--color-fg-0)] truncate flex-1 min-w-0`,children:e.ruleId}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] truncate shrink-0 w-32 text-right hidden md:inline`,children:e.sample.tool}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] tabular-nums shrink-0 w-16 text-right`,children:Hp(e.lastSeen)}),(0,D.jsx)(nm,{entry:i,ruleId:e.ruleId,onJump:n,onChanged:r})]},e.ruleId)})})]})]})]})}):(0,D.jsx)(K,{children:(0,D.jsxs)(J,{className:`py-2 flex items-center gap-3 text-[11px] font-mono flex-wrap`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`recent decisions`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)]`,children:`no blocks or asks in the last 4h — search below to find any rule by id, message, or what it last blocked`})]})})}function am({chip:e,onChange:t,counts:n}){return(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,D.jsx)(`span`,{className:`overline text-[10px] mr-1`,children:`quick filters`}),[{key:`hot`,label:`🔥 hot now`,hint:`Rules that fired in the last hour`,color:`text-amber-300 border-amber-500/40 bg-amber-500/5 hover:bg-amber-500/10`},{key:`blocked`,label:`⛔ blocking`,hint:`Rules set to block and currently enabled`,color:`text-red-300 border-red-500/40 bg-red-500/5 hover:bg-red-500/10`},{key:`noisy`,label:`📢 noisy`,hint:`Fired ≥3 times in 24h — candidates to soften`,color:`text-amber-300 border-amber-500/40 bg-amber-500/5 hover:bg-amber-500/10`},{key:`slow`,label:`🐢 slow >50ms`,hint:`Rules with avg eval time over 50ms`,color:`text-rose-300 border-rose-500/40 bg-rose-500/5 hover:bg-rose-500/10`},{key:`never`,label:`💤 never fired`,hint:`Enabled rules that have never matched — possible dead code`,color:`text-[var(--color-fg-3)] border-[var(--color-line-1)] hover:bg-[var(--color-surface-2)]`},{key:`disabled`,label:`⏸ disabled`,hint:`Rules toggled off — not currently enforced`,color:`text-[var(--color-fg-3)] border-[var(--color-line-1)] hover:bg-[var(--color-surface-2)]`}].map(r=>{let i=e===r.key,a=n[r.key];return(0,D.jsxs)(`button`,{type:`button`,onClick:()=>t(i?`none`:r.key),title:r.hint,className:`px-2 py-1 rounded-sm border text-[11px] font-mono uppercase tracking-wider cursor-pointer transition-colors ${i?`border-[var(--color-brand)]/60 bg-[var(--color-brand)]/15 text-[var(--color-fg-0)]`:r.color}`,children:[r.label,(0,D.jsx)(`span`,{className:`ml-1.5 tabular-nums normal-case ${i?`text-[var(--color-fg-2)]`:`text-[var(--color-fg-4)]`}`,children:a})]},r.key)}),e!==`none`&&(0,D.jsx)(`button`,{type:`button`,onClick:()=>t(`none`),className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer ml-1`,children:`✕ clear`})]})}function om({value:e,onChange:t,matchCount:n,sortKey:r,onSortChange:i}){return(0,D.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,D.jsxs)(`div`,{className:`relative flex-1 min-w-[260px]`,children:[(0,D.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,className:`absolute left-2.5 top-1/2 -translate-y-1/2 text-[var(--color-fg-4)] pointer-events-none`,children:[(0,D.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,D.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),(0,D.jsx)(`input`,{type:`text`,placeholder:`search rule id, message, or paste a blocked command…`,title:`Searches rule id, message, AND recent audit-log inputs/tools — paste a blocked command to find its rule`,value:e,onChange:e=>t(e.target.value),className:`bg-[var(--color-surface-1)] border border-[var(--color-line-1)] text-[var(--color-fg-1)] text-xs rounded-sm pl-8 pr-24 py-2 w-full focus:outline-none focus:border-[var(--color-brand)]/60 placeholder:text-[var(--color-fg-4)] font-mono`}),e&&(0,D.jsxs)(`div`,{className:`absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-2`,children:[n!==null&&(0,D.jsxs)(`span`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] tabular-nums`,children:[n,` match`,n===1?``:`es`]}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>t(``),className:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer`,title:`Clear search`,"aria-label":`Clear search`,children:`✕`})]})]}),(0,D.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[10px] font-mono uppercase tracking-wider`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)]`,children:`sort`}),(0,D.jsxs)(`select`,{value:r,onChange:e=>i(e.target.value),className:`bg-[var(--color-surface-1)] border border-[var(--color-line-1)] text-[var(--color-fg-1)] rounded-sm px-1.5 py-1 cursor-pointer focus:outline-none focus:border-[var(--color-brand)]/50`,children:[(0,D.jsx)(`option`,{value:`default`,children:`default · by file`}),(0,D.jsx)(`option`,{value:`hits`,children:`most hits`}),(0,D.jsx)(`option`,{value:`slowest`,children:`slowest`}),(0,D.jsx)(`option`,{value:`recent`,children:`recently fired`}),(0,D.jsx)(`option`,{value:`alpha`,children:`alphabetical`})]})]})]})}function sm({decisionFilter:e,onChange:t,totalRules:n,ruleCount:r,hits:i,window:a}){let o=Object.values(i).reduce((e,t)=>e+t,0);return(0,D.jsx)(K,{children:(0,D.jsx)(J,{className:`px-3 py-2`,children:(0,D.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,D.jsxs)(`div`,{className:`flex flex-col`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`filter by decision`}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] uppercase tracking-wider`,children:[`rules · applied in `,a]})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-1 flex-wrap`,children:[(0,D.jsxs)(`button`,{type:`button`,onClick:()=>t(`all`),title:`Show all ${n} rules — ${o.toLocaleString()} applied in ${a}`,className:`px-2 py-1 rounded-sm border text-[11px] font-mono uppercase tracking-wider cursor-pointer transition-colors ${e===`all`?`border-[var(--color-brand)]/60 bg-[var(--color-brand)]/10 text-[var(--color-fg-0)]`:`border-[var(--color-line-1)] text-[var(--color-fg-2)] hover:border-[var(--color-brand)]/30 hover:text-[var(--color-fg-0)]`}`,children:[`all`,(0,D.jsx)(`span`,{className:`ml-1.5 text-[var(--color-fg-4)] tabular-nums normal-case`,children:n}),o>0&&(0,D.jsxs)(`span`,{className:`ml-1 text-[var(--color-fg-3)] tabular-nums normal-case`,children:[`· `,o.toLocaleString()]})]}),Ap.map(n=>{let o=r[n]??0,s=i[n]??0,c=e===n,l=o===0,u=jp[n]??`text-[var(--color-fg-2)]`;return(0,D.jsxs)(`button`,{type:`button`,onClick:()=>t(n),disabled:l,title:`${o} rule${o===1?``:`s`} set to ${n} · ${s.toLocaleString()} applied in ${a}`,className:`px-2 py-1 rounded-sm border text-[11px] font-mono uppercase tracking-wider cursor-pointer transition-colors disabled:opacity-30 disabled:cursor-not-allowed ${c?`border-[var(--color-brand)]/60 bg-[var(--color-brand)]/10 ${u}`:`border-[var(--color-line-1)] ${u} hover:border-[var(--color-brand)]/30`}`,children:[n,(0,D.jsx)(`span`,{className:`ml-1.5 text-[var(--color-fg-4)] tabular-nums normal-case`,children:o}),s>0&&(0,D.jsxs)(`span`,{className:`ml-1 text-[var(--color-fg-3)] tabular-nums normal-case`,children:[`· `,s.toLocaleString()]})]},n)})]})]})})})}var cm={covered:{label:`covered`,color:`var(--color-decision-allow)`},inactive:{label:`all off`,color:`var(--color-decision-ask)`},gap:{label:`no rules`,color:`var(--color-decision-block)`}};function lm({cov:e,active:t,onClick:n}){let r=cm[e.status];return(0,D.jsxs)(`button`,{type:`button`,onClick:n,title:e.meta.description,className:`text-left rounded-sm border px-2 py-1.5 transition-colors cursor-pointer ${t?`border-[var(--color-brand)] bg-[var(--color-brand)]/10`:`border-[var(--color-line-1)] hover:bg-[var(--color-surface-2)]/70`}`,style:{borderLeft:`2px solid ${e.meta.color}`},children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,D.jsx)(`span`,{"aria-hidden":!0,children:e.meta.icon}),(0,D.jsx)(`span`,{className:`text-[11px] text-[var(--color-fg-0)] font-medium truncate flex-1`,children:e.meta.title})]}),(0,D.jsxs)(`div`,{className:`flex items-center justify-between mt-1 gap-1`,children:[(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)] tabular-nums`,children:[e.total,` rule`,e.total===1?``:`s`,e.enabledShell>0&&(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)]`,children:[` · `,e.enabledShell,` shell`]})]}),(0,D.jsx)(`span`,{className:`text-[9px] uppercase tracking-wider font-mono`,style:{color:r.color},children:r.label})]}),e.meta.attack&&(0,D.jsxs)(`div`,{className:`text-[9px] font-mono text-[var(--color-fg-4)] mt-0.5 truncate`,children:[e.meta.attack.id,` `,e.meta.attack.name]})]})}function um({coverage:e,activeCategory:t,onPick:n}){let r=e.total>0?Math.round(e.covered/e.total*100):0,i=e.categories.filter(e=>e.meta.security||e.total>0),a=e.categories.reduce((e,t)=>e+t.enabledShell,0);return(0,D.jsx)(K,{children:(0,D.jsxs)(J,{className:`px-3 py-2.5 space-y-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3 flex-wrap`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{className:`overline text-[11px]`,children:`tool-use coverage`}),(0,D.jsx)(`p`,{className:`text-[11px] text-[var(--color-fg-3)] mt-0.5`,children:`rules categorized like Sigma detections · mapped to MITRE ATT&CK tactics`})]}),(0,D.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,D.jsxs)(`span`,{className:`font-mono text-sm text-[var(--color-fg-0)] tabular-nums`,children:[e.covered,(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)]`,children:[`/`,e.total]})]}),(0,D.jsx)(`span`,{className:`text-[11px] uppercase tracking-wider text-[var(--color-fg-3)]`,children:`aspects governed`})]})]}),(0,D.jsx)(`div`,{className:`h-1.5 rounded-full bg-[var(--color-surface-3)] overflow-hidden`,children:(0,D.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${r}%`,background:r>=80?`var(--color-decision-allow)`:r>=50?`var(--color-decision-ask)`:`var(--color-decision-block)`}})}),(0,D.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:[a,` active rule`,a===1?``:`s`,` govern shell / command execution`,e.uncategorized>0&&(0,D.jsxs)(D.Fragment,{children:[` · `,(0,D.jsxs)(`span`,{className:`text-amber-300`,children:[e.uncategorized,` uncategorized`]})]})]}),(0,D.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-1.5`,children:i.map(e=>(0,D.jsx)(lm,{cov:e,active:t===e.id,onClick:()=>n(e.id)},e.id))})]})})}function dm({category:e,inferred:t,onPick:n}){let r=Cp(e);return(0,D.jsxs)(`button`,{type:`button`,onClick:()=>n(e),title:`${r.title}${t?` (inferred — add an explicit CATEGORY directive)`:``} — ${r.description}`,className:`text-[9px] font-mono uppercase tracking-wider px-1 py-px rounded-sm border cursor-pointer shrink-0 inline-flex items-center gap-0.5`,style:{color:r.color,borderColor:`${r.color}55`},children:[(0,D.jsx)(`span`,{"aria-hidden":!0,children:r.icon}),(0,D.jsx)(`span`,{children:r.title}),t&&(0,D.jsx)(`span`,{className:`opacity-50`,children:`~`})]})}function fm(){let{mode:e,setMode:t}=Ct(),n=e===`pro`,r=V(kp)[`rules-changed`],[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(0);(0,_.useEffect)(()=>{if(!i)return;let e=setInterval(()=>{s(e=>e+1)},Pp);return()=>clearInterval(e)},[i]);let{data:c,refetch:l}=k(Fp(`/api/json/rules`,r+o),[r,o]),[u,d]=(0,_.useState)(`7d`),{data:f,refetch:p}=k(Fp(`/api/json/rules-stats?window=${u}`,o),[r,u,o]),{data:m,refetch:h}=k(Fp(`/api/json/rules-performance`,o),[r,o]),{data:g,refetch:v}=k(Fp(`/api/json/rule-triggers/recent?limit=500`,o),[r,o]),[y,b]=(0,_.useState)(``),[x,S]=(0,_.useState)(`all`),[C,w]=(0,_.useState)(`all`),[T,E]=(0,_.useState)(`none`),[O,ee]=(0,_.useState)(`default`),[A,j]=(0,_.useState)(`file`),[M,te]=(0,_.useState)(``),[N,P]=(0,_.useState)(new Set),[F,I]=(0,_.useState)(new Set),[ne,re]=(0,_.useState)(()=>new URLSearchParams(window.location.search).get(`highlight`)??``),ie=(0,_.useRef)(null);(0,_.useEffect)(()=>{ie.current&&ie.current.scrollIntoView({behavior:`smooth`,block:`center`})},[]);let L=f?.stats??{},R=(0,_.useMemo)(()=>{let e=new Map;if(!c)return e;for(let t of c.rulesets)for(let n of t.rules)e.set(n.id,{rule:n,file:t.file});return e},[c]),ae=(0,_.useMemo)(()=>{let e=[];if(c)for(let t of c.rulesets)for(let n of t.rules)e.push({id:n.id,target:n.target??`any`,decision:n.decision,category:n.category,enabled:n.enabled});return Dp(e)},[c]);function oe(){l(),p(),h(),v(),s(e=>e+1)}function se(e){b(``),S(`all`),w(`all`),E(`none`),te(``),re(e);let t=new URL(window.location.href);t.searchParams.set(`highlight`,e),window.history.replaceState(null,``,t.toString())}let ce=(0,_.useMemo)(()=>{let e=new Set;if(!g)return e;let t=Math.floor(Date.now()/1e3)-3600;for(let n of g.rows)n.ruleId&&n.timestamp>=t&&e.add(n.ruleId);return e},[g]),le=(0,_.useMemo)(()=>{let e=new Set;if(!g)return e;let t=Math.floor(Date.now()/1e3)-24*3600,n=new Map;for(let e of g.rows)!e.ruleId||e.timestamp<t||Op.has(e.decision)&&n.set(e.ruleId,(n.get(e.ruleId)??0)+1);for(let[t,r]of n)r>=3&&e.add(t);return e},[g]);if(!c)return(0,D.jsx)(`p`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)]`,children:`loading rules…`});if(c.rulesets.length===0)return(0,D.jsxs)(`div`,{className:`rounded-sm border border-dashed border-[var(--color-line-1)] bg-[var(--color-surface-1)]/50 p-10 text-center`,children:[(0,D.jsx)(`p`,{className:`text-sm text-[var(--color-fg-2)] mb-2`,children:`No .rules files found.`}),(0,D.jsx)(`a`,{href:`/hub`,className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-brand)] hover:underline`,children:`→ browse hub to install rulesets`})]});let z=y.toLowerCase(),ue=(()=>{let e=new Set;if(!z||!g)return e;for(let t of g.rows){if(!t.ruleId)continue;let n=(t.input??``).toLowerCase(),r=(t.tool??``).toLowerCase();(n.includes(z)||r.includes(z))&&e.add(t.ruleId)}return e})();function de(e){if(x===`enabled`&&!e.enabled||x===`disabled`&&e.enabled)return!1;let t=L[e.id],n=t?.hits??0;return!(x===`hit`&&n===0||x===`never`&&n>0||C!==`all`&&e.decision!==C||M&&(e.category??`uncategorized`)!==M||T===`hot`&&!ce.has(e.id)||T===`noisy`&&!le.has(e.id)||T===`blocked`&&!(e.decision===`block`&&e.enabled)||T===`slow`&&!(t&&t.avgDurationMs>50)||T===`never`&&!(e.enabled&&(!t||t.hits===0))||T===`disabled`&&e.enabled)}let fe=(()=>{let e={},t={};for(let n of c.rulesets)for(let r of n.rules){e[r.decision]=(e[r.decision]??0)+1;let n=L[r.id]?.hits??0;n>0&&(t[r.decision]=(t[r.decision]??0)+n)}return{ruleCount:e,hits:t}})(),pe={hot:0,blocked:0,noisy:le.size,slow:0,never:0,disabled:0};for(let e of c.rulesets)for(let t of e.rules){ce.has(t.id)&&pe.hot++,t.decision===`block`&&t.enabled&&pe.blocked++;let e=L[t.id];e&&e.avgDurationMs>50&&pe.slow++,t.enabled&&(!e||e.hits===0)&&pe.never++,t.enabled||pe.disabled++}let me=!!z||x!==`all`||C!==`all`||T!==`none`||M!==``;function he(e){return O===`default`?e:[...e].sort((e,t)=>O===`hits`?(L[t.id]?.hits??0)-(L[e.id]?.hits??0):O===`slowest`?(L[t.id]?.avgDurationMs??0)-(L[e.id]?.avgDurationMs??0):O===`recent`?(L[t.id]?.lastSeen??0)-(L[e.id]?.lastSeen??0):O===`alpha`?e.id.localeCompare(t.id):0)}let ge=[];for(let e of c.rulesets)for(let t of e.rules)ge.push({...t,file:e.file});let _e=ge.filter(e=>z&&!e.id.toLowerCase().includes(z)&&!e.message.toLowerCase().includes(z)&&!ue.has(e.id)?!1:de(e)),ve;if(A===`category`){let e=new Map;for(let t of _e){let n=t.category??`uncategorized`,r=e.get(n);r?r.push(t):e.set(n,[t])}ve=bp.filter(t=>e.has(t.id)).map(t=>({key:t.id,kind:`category`,label:t.title,icon:t.icon,accent:t.color,sublabel:t.attack?`${t.attack.id} · ${t.attack.name}`:`D3FEND · ${t.d3fend}`,rules:he(e.get(t.id)??[])}))}else{let e=new Map;for(let t of _e){let n=e.get(t.file);n?n.push(t):e.set(t.file,[t])}ve=c.rulesets.map(t=>({key:t.file,kind:`file`,label:t.file,content:t.content,rules:he(e.get(t.file)??[])})).filter(e=>e.rules.length>0||!me)}let ye=ge.length,be=ge.filter(e=>e.enabled).length,xe=new Set;for(let e of ve)for(let t of e.rules)xe.add(t.id);let Se=me?xe.size:null,B=[];for(let e of N){let t=R.get(e);t&&B.push({ruleId:e,file:t.file})}function Ce(e){P(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function we(e){P(t=>{let n=new Set(t);if(e.length>0&&e.every(e=>n.has(e.id)))for(let t of e)n.delete(t.id);else for(let t of e)n.add(t.id);return n})}function Te(e){if(M===e){te(``);return}te(e),j(`category`),re(``)}function Ee(){P(e=>{let t=new Set(e);for(let e of xe)t.add(e);return t})}function De(e){I(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}async function Oe(e,t){B.length!==0&&(e===`enable`?await Rp(B,!0):e===`disable`?await Rp(B,!1):e===`delete`?(await Bp(B),P(new Set)):e===`decision`&&t&&await zp(B,t),oe())}return(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsx)(`div`,{"data-tutorial":`rules-firewall`,children:(0,D.jsx)(Zp,{totalRules:ye,activeRules:be,onChanged:oe})}),(0,D.jsx)(qp,{}),(0,D.jsx)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h1`,{className:`overline text-[11px]`,children:`rules`}),(0,D.jsxs)(`div`,{className:`flex items-baseline gap-3 mt-1`,children:[(0,D.jsxs)(`span`,{className:`font-mono text-sm text-[var(--color-fg-0)] tabular-nums`,children:[be,(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)]`,children:[`/`,ye]}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] ml-1.5 text-[11px] uppercase tracking-wider`,children:`active`})]}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsxs)(`span`,{className:`font-mono text-[11px] text-[var(--color-fg-3)] uppercase tracking-wider`,children:[c.files.length,` file`,c.files.length===1?``:`s`]})]})]})}),(0,D.jsx)(`div`,{"data-tutorial":`rules-coverage`,children:(0,D.jsx)(um,{coverage:ae,activeCategory:M,onPick:Te})}),(0,D.jsx)(`div`,{"data-tutorial":`rules-stats`,children:(0,D.jsx)(Jp,{perf:m,triggers:g,decisionAggregates:fe,livePoll:i,onTogglePoll:()=>a(e=>!e),statsWindow:u,onWindowChange:d,mode:e,onModeChange:t})}),(0,D.jsx)(K,{children:(0,D.jsxs)(J,{className:`px-3 py-2.5 space-y-2.5`,children:[(0,D.jsx)(om,{value:y,onChange:b,matchCount:Se,sortKey:O,onSortChange:ee}),(0,D.jsx)(am,{chip:T,onChange:E,counts:pe}),(0,D.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap pt-1 border-t border-[var(--color-line-0)]`,children:[(0,D.jsx)(`span`,{className:`overline text-[10px]`,children:`state`}),(0,D.jsx)(`div`,{className:`flex items-center gap-1 text-[10px] font-mono uppercase tracking-wider`,children:[`all`,`enabled`,`disabled`,`hit`,`never`].map(e=>(0,D.jsx)(`button`,{onClick:()=>S(e),className:`px-1.5 py-0.5 rounded-sm border cursor-pointer transition-colors ${x===e?`border-[var(--color-brand)]/60 bg-[var(--color-brand)]/10 text-[var(--color-fg-0)]`:`border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,children:e},e))}),(0,D.jsx)(`span`,{className:`overline text-[10px] ml-1`,children:`group`}),(0,D.jsx)(`div`,{className:`flex items-center gap-1 text-[10px] font-mono uppercase tracking-wider`,children:[`file`,`category`].map(e=>(0,D.jsxs)(`button`,{onClick:()=>j(e),className:`px-1.5 py-0.5 rounded-sm border cursor-pointer transition-colors ${A===e?`border-[var(--color-brand)]/60 bg-[var(--color-brand)]/10 text-[var(--color-fg-0)]`:`border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,children:[`by `,e]},e))})]}),M&&(0,D.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap pt-1 border-t border-[var(--color-line-0)]`,children:[(0,D.jsx)(`span`,{className:`overline text-[10px]`,children:`category`}),(0,D.jsxs)(`span`,{className:`text-[11px] font-mono px-1.5 py-0.5 rounded-sm border`,style:{color:Cp(M).color,borderColor:`${Cp(M).color}66`},children:[Cp(M).icon,` `,Cp(M).title]}),(0,D.jsx)(`button`,{onClick:()=>te(``),className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer`,children:`clear ✕`})]})]})}),(0,D.jsx)(sm,{decisionFilter:C,onChange:w,totalRules:ye,ruleCount:fe.ruleCount,hits:fe.hits,window:u}),n&&(0,D.jsx)(`div`,{"data-tutorial":`rules-top`,children:(0,D.jsx)(Xp,{stats:L,ruleIndex:R,triggers:g?.rows,statsWindow:u,onJump:se})}),(0,D.jsx)(`div`,{"data-tutorial":`rules-activity`,children:(0,D.jsx)(rm,{stats:L,ruleIndex:R,onJump:se,onChanged:oe})}),(0,D.jsx)(`div`,{"data-tutorial":`rules-recent`,children:(0,D.jsx)(im,{triggers:g?.rows,ruleIndex:R,onJump:se,onChanged:oe})}),n&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(Yp,{perf:m}),(0,D.jsx)(tm,{})]}),(0,D.jsx)($p,{selected:B,onClear:()=>P(new Set),onApply:Oe}),xe.size>0&&(0,D.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] font-mono`,children:[(0,D.jsxs)(`button`,{onClick:Ee,className:`uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer`,children:[`select `,xe.size,` visible`]}),N.size>0&&(0,D.jsx)(`button`,{onClick:()=>P(new Set),className:`uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer`,children:`clear selection`})]}),ve.length===0&&(0,D.jsx)(`div`,{className:`rounded-sm border border-dashed border-[var(--color-line-1)] px-4 py-6 text-center text-[11px] font-mono text-[var(--color-fg-3)]`,children:`no rules match the current filter`}),(0,D.jsx)(`div`,{className:`space-y-3`,children:ve.map(e=>{let t=e.rules.some(e=>e.id===ne),r=e.rules.filter(e=>e.enabled).length,i=e.rules.length>0&&e.rules.every(e=>N.has(e.id)),a=!i&&e.rules.some(e=>N.has(e.id)),o=Up(g?.rows,20,3600*1e3,t=>t.ruleId?e.rules.some(e=>e.id===t.ruleId):!1),s=o.some(e=>e>0);return(0,D.jsx)(K,{children:(0,D.jsxs)(`details`,{open:t||me||O!==`default`,children:[(0,D.jsxs)(`summary`,{className:`flex items-center gap-2 px-3 py-2 cursor-pointer list-none select-none hover:bg-[var(--color-surface-2)]/70 border-b border-[var(--color-line-0)]`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:i,ref:e=>{e&&(e.indeterminate=a)},onChange:()=>we(e.rules),onClick:e=>e.stopPropagation(),className:`accent-[var(--color-brand)] cursor-pointer`,"aria-label":`Select all rules in ${e.label}`}),e.kind===`category`?(0,D.jsx)(`span`,{"aria-hidden":!0,className:`shrink-0 text-xs`,children:e.icon}):(0,D.jsxs)(`svg`,{className:`text-[var(--color-fg-3)] shrink-0`,width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[(0,D.jsx)(`path`,{d:`M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z`}),(0,D.jsx)(`polyline`,{points:`14 2 14 8 20 8`})]}),(0,D.jsx)(`code`,{className:`text-xs text-[var(--color-fg-0)] font-mono`,style:e.accent?{color:e.accent}:void 0,children:e.label}),e.sublabel&&(0,D.jsx)(`span`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-4)] shrink-0`,children:e.sublabel}),s&&(0,D.jsx)(Js,{data:o,width:60,height:16,color:`var(--color-brand)`}),(0,D.jsxs)(`span`,{className:`ml-auto font-mono text-[11px] text-[var(--color-fg-3)] tabular-nums`,children:[r,(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)]`,children:[`/`,e.rules.length]})]})]}),(0,D.jsxs)(J,{className:`py-0`,children:[e.rules.length===0?(0,D.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)] py-3`,children:[`no rules in this `,e.kind]}):(0,D.jsx)(`div`,{className:`divide-y divide-[var(--color-line-0)]`,children:e.rules.map(e=>{let t=e.id===ne,r=N.has(e.id),i=L[e.id],a=F.has(e.id),o=i&&i.hits>0?Up(g?.rows,20,3600*1e3,t=>t.ruleId===e.id):null;return(0,D.jsx)(`div`,{ref:t?ie:null,className:`py-2.5 ${t?`bg-amber-400/8 border-l-2 border-l-amber-400/60 -mx-3 px-3 -my-px`:r?`bg-sky-400/5`:``}`,children:(0,D.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,D.jsxs)(`div`,{className:`flex items-start gap-2 min-w-0 flex-1`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:r,onChange:()=>Ce(e.id),className:`mt-1 accent-[var(--color-brand)] cursor-pointer`,"aria-label":`Select rule ${e.id}`}),(0,D.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 mb-1 flex-wrap`,children:[e.ambient?(0,D.jsx)(`span`,{className:`bg-[var(--color-surface-0)] border border-teal-500/40 rounded-sm px-1.5 py-0.5 text-[11px] font-mono uppercase tracking-wider text-teal-300`,title:`Ambient knowledge rule — carries always-on project context surfaced to the agent at session start. It never gates a tool call, so it has no decision.`,children:`ambient`}):(0,D.jsx)(`select`,{value:e.decision,onChange:async t=>{await Lp(e.id,e.file,t.target.value),oe()},className:`bg-[var(--color-surface-0)] border border-[var(--color-line-1)] rounded-sm px-1.5 py-0.5 text-[11px] font-mono uppercase tracking-wider cursor-pointer focus:outline-none focus:border-[var(--color-brand)]/50 ${jp[e.decision]??`text-[var(--color-fg-2)]`}`,children:Ap.map(e=>(0,D.jsx)(`option`,{value:e,children:e},e))}),(0,D.jsx)(Wr,{ruleId:e.id,children:(0,D.jsx)(`code`,{className:`text-xs font-mono text-[var(--color-fg-0)] break-all`,children:e.id})}),A===`file`&&e.category&&(0,D.jsx)(dm,{category:e.category,inferred:e.categoryInferred,onPick:Te}),n&&e.tags&&e.tags.length>0&&e.tags.slice(0,5).map(e=>(0,D.jsx)(`span`,{className:`text-[9px] font-mono px-1 py-px rounded-sm bg-[var(--color-surface-3)] text-[var(--color-fg-3)] shrink-0`,children:e},e)),o&&(0,D.jsx)(Js,{data:o,width:50,height:14,color:Mp[e.decision]??`#a8a29e`}),i&&i.hits>0&&(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)] tabular-nums`,children:[`·`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:i.hits}),` `,`hit`,i.hits===1?``:`s`,i.avgDurationMs>0&&(0,D.jsxs)(D.Fragment,{children:[` · `,(0,D.jsxs)(`span`,{className:i.avgDurationMs>50?`text-amber-300`:`text-[var(--color-fg-1)]`,children:[i.avgDurationMs.toFixed(1),`ms`]}),` `,`avg`]}),` · `,Hp(i.lastSeen)]}),(!i||i.hits===0)&&(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] uppercase tracking-wider`,children:`· never fired`}),n&&(0,D.jsx)(`button`,{onClick:()=>De(e.id),className:`ml-auto text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer`,children:a?`hide audit`:`audit`})]}),(0,D.jsx)(`p`,{className:`text-xs text-[var(--color-fg-2)] truncate`,children:e.message}),n&&a&&(0,D.jsx)(em,{ruleId:e.id})]})]}),(0,D.jsx)(Kp,{rule:e,file:e.file,onToggle:async()=>{await Ip(e.id,e.file),oe()}})]})},e.id)})}),n&&e.content&&(0,D.jsxs)(`details`,{className:`mt-3 pb-3`,children:[(0,D.jsx)(`summary`,{className:`overline cursor-pointer hover:text-[var(--color-fg-1)] select-none`,children:`raw source`}),(0,D.jsx)(`pre`,{className:`mt-2 p-3 bg-[var(--color-surface-0)] border border-[var(--color-line-0)] rounded-sm text-[11px] text-[var(--color-fg-2)] overflow-x-auto whitespace-pre-wrap break-words font-mono`,children:e.content})]})]})]})},e.key)})})]})}var pm={allow:`#4ade80`,block:`#f87171`,ask:`#fbbf24`,force:`#a78bfa`,log:`#7dd3fc`,shadow:`#94a3b8`},mm=[`<1ms`,`1-10ms`,`10-100ms`,`100ms-1s`,`>1s`],hm=64;function gm(e){return e?new Date(e*1e3).toLocaleString():`—`}function _m(e){if(e<1)return`<1s`;if(e<60)return`${e}s`;if(e<3600)return`${Math.floor(e/60)}m ${e%60}s`;let t=Math.floor(e/3600),n=Math.floor(e%3600/60);return n>0?`${t}h ${n}m`:`${t}h`}function vm({title:e,hint:t,children:n}){return(0,D.jsxs)(`section`,{className:`flex flex-col rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] overflow-hidden`,children:[(0,D.jsxs)(`header`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-[var(--color-line-1)] bg-black/30 shrink-0`,children:[(0,D.jsx)(`span`,{className:`overline text-[var(--color-fg-3)]`,children:e}),t&&(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:t})]}),(0,D.jsx)(`div`,{className:`p-3 flex flex-col gap-2 flex-1 min-h-0`,children:n})]})}function ym({allowed:e,blocked:t,asked:n,forced:r}){let i=Math.max(0,e),a=Math.max(0,t),o=Math.max(0,n),s=Math.max(0,r),c=i+a+o+s;if(c===0)return(0,D.jsx)(`div`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`No evals recorded.`});let l=[{label:`allow`,value:i,color:pm.allow},{label:`block`,value:a,color:pm.block},{label:`ask`,value:o,color:pm.ask},{label:`force`,value:s,color:pm.force}].filter(e=>e.value>0),u=2*Math.PI*32,d=0;return(0,D.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,D.jsxs)(`svg`,{width:`92`,height:`92`,viewBox:`-46 -46 92 92`,className:`shrink-0`,children:[(0,D.jsx)(`circle`,{r:32,fill:`none`,stroke:`#222`,strokeWidth:`12`}),l.map(e=>{let t=e.value/c*u,n=(0,D.jsx)(`circle`,{r:32,fill:`none`,stroke:e.color,strokeWidth:`12`,strokeDasharray:`${t} ${u-t}`,strokeDashoffset:-d,transform:`rotate(-90)`},e.label);return d+=t,n}),(0,D.jsx)(`text`,{textAnchor:`middle`,dy:`0.35em`,fontSize:`14`,fontFamily:`ui-monospace, monospace`,fill:`var(--color-fg-1)`,children:c})]}),(0,D.jsx)(`ul`,{className:`flex-1 flex flex-col gap-1 text-[11px] font-mono`,children:l.map(e=>{let t=Math.round(e.value/c*1e3)/10;return(0,D.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`size-2 rounded-sm shrink-0`,style:{background:e.color}}),(0,D.jsx)(`span`,{className:`uppercase tracking-wide text-[var(--color-fg-2)] w-12`,children:e.label}),(0,D.jsx)(`span`,{className:`tabular-nums text-[var(--color-fg-1)] font-semibold`,children:e.value}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)]`,children:[t,`%`]})]},e.label)})})]})}function bm({rows:e,maxRows:t=10,emptyMessage:n}){if(e.length===0)return(0,D.jsx)(`div`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:n});let r=e.slice(0,t).map(e=>({...e,value:Math.max(0,e.value)})),i=Math.max(...r.map(e=>e.value),1);return(0,D.jsx)(`ul`,{className:`flex flex-col gap-1.5 text-[11px] font-mono`,children:r.map(e=>{let t=Math.max(2,e.value/i*100);return(0,D.jsxs)(`li`,{className:`flex flex-col gap-0.5`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,D.jsx)(`span`,{className:`truncate text-[var(--color-fg-2)]`,title:e.label,children:e.label}),(0,D.jsx)(`span`,{className:`tabular-nums text-[var(--color-fg-1)] font-semibold shrink-0`,children:e.value})]}),(0,D.jsx)(`div`,{className:`h-1 rounded-sm bg-white/5 overflow-hidden`,children:(0,D.jsx)(`div`,{className:`h-full bg-[var(--color-hig-blue)]/70`,style:{width:`${t}%`}})}),e.sublabel&&(0,D.jsx)(`span`,{className:`text-[10px] text-[var(--color-fg-4)] truncate`,title:e.sublabel,children:e.sublabel})]},e.label)})})}function xm({latency:e}){let t={};for(let n of e)t[n.bucket]=Math.max(0,n.hits);let n=Math.max(...Object.values(t),1);return Object.values(t).reduce((e,t)=>e+t,0)===0?(0,D.jsx)(`div`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`No latency data.`}):(0,D.jsx)(`div`,{className:`flex items-end gap-2`,children:mm.map(e=>{let r=t[e]??0,i=Math.round(r/n*hm);return(0,D.jsxs)(`div`,{className:`flex flex-1 min-w-0 flex-col items-center gap-1`,children:[(0,D.jsx)(`div`,{className:`flex w-full items-end`,style:{height:`${hm}px`},children:(0,D.jsx)(`div`,{className:`w-full rounded-sm bg-[var(--color-hig-blue)]/60`,style:{height:`${i}px`,minHeight:r>0?`4px`:`0px`},title:`${r} evals in ${e}`})}),(0,D.jsx)(`span`,{className:`w-full truncate text-center text-[10px] font-mono leading-tight text-[var(--color-fg-3)]`,title:e,children:e}),(0,D.jsx)(`span`,{className:`text-[10px] font-mono leading-tight text-[var(--color-fg-4)] tabular-nums`,children:r})]},e)})})}function Sm({sessionKey:e}){let[t,n]=(0,_.useState)(0),{data:r,loading:i,error:a}=k(`/api/json/sessions/detail?session_key=${encodeURIComponent(e)}&audit_limit=500`,[t]),o=V([`activity-updated`])[`activity-updated`]??0;(0,_.useEffect)(()=>{o>0&&r?.summary.is_active&&n(e=>e+1)},[o,r?.summary.is_active]);let s=(0,_.useMemo)(()=>{if(!r)return[];let e=r.tools.top.map(e=>({label:e.tool,value:Math.max(0,e.hits)}));return r.tools.other>0&&e.push({label:`(${r.tools.other} other)`,value:Math.max(0,r.tools.other)}),e},[r]),c=(0,_.useMemo)(()=>{if(!r)return[];if(r.rules.length>0)return r.rules.map(e=>({label:e.rule_id,sublabel:e.rule_message,value:Math.max(0,e.hits)}));let e=new Map;for(let t of r.audit){if(!t.rule_id)continue;let n=e.get(t.rule_id);n?n.hits+=1:e.set(t.rule_id,{message:t.rule_message,hits:1})}return[...e.entries()].map(([e,t])=>({label:e,sublabel:t.message,value:t.hits})).sort((e,t)=>t.value-e.value)},[r]);if(a)return(0,D.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,D.jsxs)(`header`,{children:[(0,D.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Session inspector`}),(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-3)] mt-1 font-mono`,children:e})]}),(0,D.jsxs)(`div`,{className:`rounded-sm border border-rose-500/30 bg-rose-500/5 p-4 text-[12px] font-mono text-rose-300`,children:[a.includes(`404`)?`No audit entries found for this session. It may have been pruned, or the URL is malformed.`:`Failed to load session: ${a}`,(0,D.jsx)(`div`,{className:`mt-2`,children:(0,D.jsx)(`a`,{href:`/sessions`,className:`text-[var(--color-hig-blue)] hover:underline`,children:`← Back to sessions`})})]})]});if(i&&!r)return(0,D.jsxs)(`div`,{className:`p-4 text-[12px] font-mono text-[var(--color-fg-3)]`,children:[`Loading session `,e,`…`]});if(!r)return null;let{summary:l,audit:u,latency:d}=r,f={...l,evals:Math.max(0,l.evals),allowed:Math.max(0,l.allowed),blocked:Math.max(0,l.blocked),asked:Math.max(0,l.asked),forced:Math.max(0,l.forced),duration_s:Math.max(0,l.duration_s)},p=f.evals>0?Math.round(f.blocked/f.evals*1e3)/10:0;return(0,D.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 h-full min-h-0`,children:[(0,D.jsxs)(`header`,{className:`flex flex-col gap-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] font-mono text-[var(--color-fg-3)]`,children:[(0,D.jsx)(`a`,{href:`/sessions`,"data-tutorial":`sd-back`,className:`hover:underline`,children:`← Sessions`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`/`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] font-semibold`,children:f.agent_id})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`h1`,{className:`text-lg font-semibold`,children:[f.client,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] font-mono text-[14px] ml-2`,children:f.agent_id})]}),(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)] mt-1 break-all`,children:f.session_id??`(no session_id — solo bucket)`})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-[11px] font-mono`,children:[(0,D.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-sm border ${f.is_active?`bg-emerald-500/10 border-emerald-500/30 text-emerald-300`:`bg-white/5 border-white/10 text-[var(--color-fg-3)]`}`,children:[(0,D.jsx)(`span`,{className:`size-1.5 rounded-full ${f.is_active?`bg-emerald-400 animate-pulse`:`bg-[var(--color-fg-4)]`}`}),f.is_active?`Live`:`Closed`]}),(0,D.jsx)(Cm,{label:`Evals`,value:f.evals.toLocaleString()}),(0,D.jsx)(Cm,{label:`Blocked`,value:f.blocked>0?`${f.blocked} (${p}%)`:`0`,color:f.blocked>0?`text-rose-300`:void 0}),(0,D.jsx)(Cm,{label:`Asked`,value:f.asked.toLocaleString(),color:`text-amber-300`}),(0,D.jsx)(Cm,{label:`Started`,value:gm(f.started_at)}),(0,D.jsx)(Cm,{label:`Duration`,value:_m(f.duration_s)})]})]})]}),(0,D.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-4 gap-3`,children:[(0,D.jsx)(vm,{title:`Decisions`,hint:`${f.evals} evals`,children:(0,D.jsx)(ym,{allowed:f.allowed,blocked:f.blocked,asked:f.asked,forced:f.forced})}),(0,D.jsx)(vm,{title:`Top tools`,hint:`${r.tools.top.length+ +(r.tools.other>0)} buckets`,children:(0,D.jsx)(bm,{rows:s,emptyMessage:`No tool activity.`})}),(0,D.jsx)(vm,{title:`Top rules`,hint:`${c.length} rule${c.length===1?``:`s`}`,children:(0,D.jsx)(bm,{rows:c,emptyMessage:f.evals>0?`No rule matched any of the ${f.evals} tool call${f.evals===1?``:`s`} in this session — all allowed by the default policy.`:`No rule activity recorded for this session.`})}),(0,D.jsx)(vm,{title:`Latency`,hint:`duration buckets`,children:(0,D.jsx)(xm,{latency:d})})]}),(0,D.jsx)(`div`,{"data-tutorial":`sd-audit`,className:`flex-1 min-h-[400px]`,children:(0,D.jsx)(Cu,{sessionKey:e,entries:u,loading:i,error:null,playingIndex:-1})})]})}function Cm({label:e,value:t,color:n}){return(0,D.jsxs)(`div`,{className:`flex flex-col`,children:[(0,D.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-[var(--color-fg-4)]`,children:e}),(0,D.jsx)(`span`,{className:`tabular-nums ${n??`text-[var(--color-fg-1)]`}`,children:t})]})}var wm=100,Tm={"claude-code":`bg-orange-500/15 text-orange-300 border-orange-500/30`,cursor:`bg-sky-500/15 text-sky-300 border-sky-500/30`,copilot:`bg-emerald-500/15 text-emerald-300 border-emerald-500/30`,gemini:`bg-blue-500/15 text-blue-300 border-blue-500/30`,antigravity:`bg-purple-500/15 text-purple-300 border-purple-500/30`,codex:`bg-pink-500/15 text-pink-300 border-pink-500/30`,pi:`bg-amber-500/15 text-amber-300 border-amber-500/30`,generic:`bg-slate-500/15 text-slate-300 border-slate-500/30`};function Em(e){if(!e)return`—`;let t=new Date(e*1e3),n=new Date,r=t.toLocaleTimeString(`en-US`,{hour:`2-digit`,minute:`2-digit`,hour12:!1});if(t.toDateString()===n.toDateString())return`Today ${r}`;let i=new Date(n);return i.setDate(i.getDate()-1),t.toDateString()===i.toDateString()?`Yesterday ${r}`:`${t.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})} ${r}`}function Dm(e){if(e<1)return`—`;if(e<60)return`${e}s`;if(e<3600)return`${Math.floor(e/60)}m`;let t=Math.floor(e/3600),n=Math.floor(e%3600/60);return n>0?`${t}h ${n}m`:`${t}h`}function Om({client:e}){return(0,D.jsx)(`span`,{className:`inline-flex items-center rounded-sm border px-1.5 py-0.5 text-[10px] font-mono uppercase tracking-wide ${Tm[e]??`bg-white/5 text-[var(--color-fg-3)] border-white/10`}`,children:e})}function km({onOpenSession:e}={}){let{activeProject:t}=Be(),[n,r]=(0,_.useState)(0),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(0);(0,_.useEffect)(()=>{r(0)},[t]);let{data:c,loading:l,error:u,refetch:d}=k(Ve(`/api/json/sessions/list?limit=${wm}&offset=${n}`,t),[o,t]),f=V([`activity-updated`])[`activity-updated`]??0;(0,_.useEffect)(()=>{f>0&&s(e=>e+1)},[f]);let p=c?.sessions??[],m=c?.total??0,h=(0,_.useMemo)(()=>{if(!i.trim())return p;let e=i.toLowerCase();return p.filter(t=>t.session_key.toLowerCase().includes(e)||t.client.toLowerCase().includes(e)||(t.top_tool??``).toLowerCase().includes(e)||(t.top_rule??``).toLowerCase().includes(e))},[p,i]),g=p.filter(e=>e.is_active).length,v=p.reduce((e,t)=>e+Math.max(0,t.evals),0),y=p.reduce((e,t)=>e+Math.max(0,t.blocked),0),b=v>0?Math.round(y/v*1e3)/10:0;return(0,D.jsxs)(`div`,{className:`flex flex-col gap-4 p-4`,children:[(0,D.jsxs)(`header`,{className:`flex flex-col gap-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Sessions`}),(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-3)] mt-1`,children:`Every AI agent session recorded by the daemon. Click a row to open its inspector — graph, charts, and full audit log.`})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] font-mono text-[var(--color-fg-3)]`,children:[(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] font-semibold`,children:m.toLocaleString()}),` `,`total`]}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`span`,{className:`text-emerald-300 font-semibold`,children:g}),` `,`active`]}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] font-semibold`,children:v.toLocaleString()}),` `,`evals on page`]}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsxs)(`span`,{children:[(0,D.jsxs)(`span`,{className:b>0?`text-rose-300 font-semibold`:`text-emerald-300`,children:[b,`%`]}),` `,`blocked`]})]})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`input`,{"data-tutorial":`sessions-filter`,type:`search`,value:i,onChange:e=>a(e.target.value),placeholder:`Filter by client, session, tool, or rule…`,className:`flex-1 bg-[var(--color-surface-1)] border border-[var(--color-line-1)] rounded-sm px-3 py-1.5 text-[12px] font-mono focus:outline-none focus:ring-1 focus:ring-[var(--color-hig-blue)]`}),(0,D.jsx)(`button`,{"data-tutorial":`sessions-refresh`,type:`button`,onClick:()=>d(),className:`px-3 py-1.5 text-[11px] font-mono uppercase tracking-wide border border-[var(--color-line-1)] rounded-sm hover:bg-white/5`,children:`Refresh`})]})]}),(0,D.jsx)(`div`,{className:`border border-[var(--color-line-1)] rounded-sm overflow-hidden`,children:(0,D.jsx)(`div`,{className:`overflow-x-auto`,children:(0,D.jsxs)(`table`,{"data-tutorial":`sessions-table`,className:`w-full text-[12px] font-mono`,children:[(0,D.jsx)(`thead`,{className:`bg-black/30 text-[var(--color-fg-3)] uppercase tracking-wide text-[10px]`,children:(0,D.jsxs)(`tr`,{children:[(0,D.jsx)(`th`,{className:`text-left px-3 py-2`,children:`Status`}),(0,D.jsx)(`th`,{className:`text-left px-3 py-2`,children:`Client`}),(0,D.jsx)(`th`,{className:`text-left px-3 py-2`,children:`Session`}),(0,D.jsx)(`th`,{className:`text-left px-3 py-2`,children:`Started`}),(0,D.jsx)(`th`,{className:`text-left px-3 py-2`,children:`Duration`}),(0,D.jsx)(`th`,{className:`text-right px-3 py-2`,children:`Evals`}),(0,D.jsx)(`th`,{className:`text-right px-3 py-2 text-emerald-300/80`,children:`Allowed`}),(0,D.jsx)(`th`,{className:`text-right px-3 py-2 text-rose-300/80`,children:`Blocked`}),(0,D.jsx)(`th`,{className:`text-right px-3 py-2 text-amber-300/80`,children:`Asked`}),(0,D.jsx)(`th`,{className:`text-left px-3 py-2`,children:`Top Tool`}),(0,D.jsx)(`th`,{className:`text-left px-3 py-2`,children:`Top Rule`})]})}),(0,D.jsxs)(`tbody`,{className:`divide-y divide-[var(--color-line-1)]/40`,children:[l&&h.length===0&&(0,D.jsx)(`tr`,{children:(0,D.jsx)(`td`,{colSpan:11,className:`px-3 py-6 text-center text-[var(--color-fg-4)]`,children:`Loading sessions…`})}),u&&(0,D.jsx)(`tr`,{children:(0,D.jsxs)(`td`,{colSpan:11,className:`px-3 py-6 text-center text-rose-300`,children:[`Failed to load sessions: `,u]})}),!l&&!u&&h.length===0&&(0,D.jsx)(`tr`,{children:(0,D.jsx)(`td`,{colSpan:11,className:`px-3 py-6 text-center text-[var(--color-fg-4)]`,children:p.length===0?`No sessions recorded yet.`:`No sessions match "${i}".`})}),h.map(t=>{let n={...t,evals:Math.max(0,t.evals),allowed:Math.max(0,t.allowed),blocked:Math.max(0,t.blocked),asked:Math.max(0,t.asked),forced:Math.max(0,t.forced),duration_s:Math.max(0,t.duration_s)},r=n.evals>0?Math.round(n.blocked/n.evals*1e3)/10:0;return(0,D.jsxs)(`tr`,{className:`hover:bg-white/[0.03] cursor-pointer`,children:[(0,D.jsx)(`td`,{className:`px-3 py-2`,children:(0,D.jsx)(`a`,{href:`/sessions/${encodeURIComponent(n.session_key)}`,className:`flex items-center gap-1.5 no-underline`,onClick:t=>{e&&(t.preventDefault(),e(n.session_key,n.agent_id))},children:n.is_active?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{className:`size-1.5 rounded-full bg-emerald-400 animate-pulse`}),(0,D.jsx)(`span`,{className:`text-emerald-300 text-[10px] uppercase tracking-wide`,children:`Live`})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{className:`size-1.5 rounded-full bg-[var(--color-fg-4)]`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] text-[10px] uppercase tracking-wide`,children:`Closed`})]})})}),(0,D.jsx)(`td`,{className:`px-3 py-2`,children:(0,D.jsx)(Om,{client:n.client})}),(0,D.jsx)(`td`,{className:`px-3 py-2`,children:(0,D.jsx)(`a`,{href:`/sessions/${encodeURIComponent(n.session_key)}`,className:`text-[var(--color-fg-1)] hover:text-[var(--color-hig-blue)] hover:underline`,onClick:t=>{e&&(t.preventDefault(),e(n.session_key,n.agent_id))},children:n.agent_id})}),(0,D.jsx)(`td`,{className:`px-3 py-2 text-[var(--color-fg-3)]`,children:Em(n.started_at)}),(0,D.jsx)(`td`,{className:`px-3 py-2 text-[var(--color-fg-3)]`,children:Dm(n.duration_s)}),(0,D.jsx)(`td`,{className:`px-3 py-2 text-right font-semibold`,children:n.evals.toLocaleString()}),(0,D.jsx)(`td`,{className:`px-3 py-2 text-right text-emerald-300`,children:n.allowed.toLocaleString()}),(0,D.jsx)(`td`,{className:`px-3 py-2 text-right`,children:n.blocked>0?(0,D.jsxs)(`span`,{className:`text-rose-300`,children:[n.blocked.toLocaleString(),r>0&&(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)] ml-1 text-[10px]`,children:[`(`,r,`%)`]})]}):(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`0`})}),(0,D.jsx)(`td`,{className:`px-3 py-2 text-right text-amber-300`,children:n.asked>0?n.asked.toLocaleString():(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`0`})}),(0,D.jsx)(`td`,{className:`px-3 py-2 text-[var(--color-fg-2)] max-w-[180px] truncate`,children:n.top_tool??(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`—`})}),(0,D.jsx)(`td`,{className:`px-3 py-2 text-[var(--color-fg-2)] max-w-[200px] truncate`,children:n.top_rule??(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`—`})})]},n.session_key)})]})]})})}),m>wm&&(0,D.jsxs)(`footer`,{className:`flex items-center justify-between text-[11px] font-mono text-[var(--color-fg-3)]`,children:[(0,D.jsxs)(`span`,{children:[n+1,`–`,Math.min(n+wm,m),` of`,` `,m.toLocaleString()]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`button`,{type:`button`,disabled:n===0,onClick:()=>r(Math.max(0,n-wm)),className:`px-3 py-1 border border-[var(--color-line-1)] rounded-sm disabled:opacity-30 hover:bg-white/5`,children:`← Prev`}),(0,D.jsx)(`button`,{type:`button`,disabled:n+wm>=m,onClick:()=>r(n+wm),className:`px-3 py-1 border border-[var(--color-line-1)] rounded-sm disabled:opacity-30 hover:bg-white/5`,children:`Next →`})]})]})]})}function Am(e){return`ssg:session-subtabs:${e}`}function jm(e){try{let t=localStorage.getItem(Am(e));if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>typeof e==`object`&&!!e&&typeof e.key==`string`&&typeof e.label==`string`):[]}catch{return[]}}function Mm(e){return`shrink-0 rounded-sm border px-2.5 py-1 text-[11px] font-mono transition-colors ${e?`border-[var(--color-hig-blue)]/50 bg-[var(--color-hig-blue)]/15 text-[var(--color-fg-1)]`:`border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:bg-white/5`}`}function Nm(){let{activeProject:e}=Be(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(null);(0,_.useEffect)(()=>{n(jm(e)),i(null)},[e]);let a=(0,_.useCallback)(t=>{try{localStorage.setItem(Am(e),JSON.stringify(t))}catch{}},[e]),o=(0,_.useCallback)((e,t)=>{n(n=>{let r=n.some(t=>t.key===e)?n:[...n,{key:e,label:t}];return a(r),r}),i(e)},[a]),s=(0,_.useCallback)(e=>{n(t=>{let n=t.findIndex(t=>t.key===e),r=t.filter(t=>t.key!==e);return a(r),i(t=>t===e?r.length===0?null:r[Math.max(0,n-1)].key:t),r})},[a]);return(0,D.jsxs)(`div`,{className:`flex flex-col`,children:[t.length>0&&(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5 overflow-x-auto border-b border-[var(--color-line-1)] px-4 py-1.5`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:()=>i(null),className:Mm(r===null),children:`Sessions list`}),t.map(e=>(0,D.jsxs)(`span`,{className:`group inline-flex items-center gap-1.5 ${Mm(r===e.key)}`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:()=>i(e.key),className:`max-w-[160px] truncate`,children:e.label}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>s(e.key),"aria-label":`Close ${e.label}`,className:`text-[var(--color-fg-4)] hover:text-rose-300`,children:`×`})]},e.key))]}),r===null?(0,D.jsx)(km,{onOpenSession:o}):(0,D.jsx)(Sm,{sessionKey:r})]})}function Pm({status:e,className:t=``}){return(0,D.jsx)(`span`,{className:`status-dot ${e===`ok`?`bg-[var(--color-decision-allow)]`:e===`warn`?`bg-[var(--color-decision-ask)]`:e===`fail`?`bg-[var(--color-decision-block)]`:`bg-[var(--color-fg-3)]`} ${t}`})}function Fm({status:e}){let t=e===`ok`?`text-[var(--color-decision-allow)]`:e===`warn`?`text-[var(--color-decision-ask)]`:e===`fail`?`text-[var(--color-decision-block)]`:`text-[var(--color-fg-3)]`,n=e===`ok`?`OK`:e===`warn`?`Warn`:e===`fail`?`Fail`:`Skipped`;return(0,D.jsx)(`span`,{className:`text-[10.5px] font-medium uppercase tracking-wide ${t}`,children:n})}function Im(e){return e===void 0?``:e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Lm(e){if(!e)return``;let t=Math.floor((Date.now()-e)/1e3);return t<60?`${t}s ago`:t<3600?`${Math.floor(t/60)}m ago`:t<86400?`${Math.floor(t/3600)}h ago`:`${Math.floor(t/86400)}d ago`}function Rm(e,t){return t&&e.startsWith(`${t}/`)?`~/${e.slice(t.length+1)}`:e===t?`~`:e}function zm({file:e,home:t,wired:n}){return(0,D.jsxs)(`div`,{className:`flex items-center gap-2 py-1 border-b border-[var(--color-line-0)] last:border-0 text-[11.5px]`,children:[(0,D.jsx)(Pm,{status:e.exists?n===void 0||n?`ok`:`warn`:`skip`}),(0,D.jsx)(`code`,{className:`flex-1 truncate text-[var(--color-fg-1)]`,title:e.path,children:Rm(e.path,t)}),e.exists?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{className:`text-[10.5px] text-[var(--color-fg-3)]`,children:Im(e.size)}),(0,D.jsx)(`span`,{className:`text-[10.5px] text-[var(--color-fg-3)] min-w-[60px] text-right`,children:Lm(e.modified_at)}),n===!1&&(0,D.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-[var(--color-decision-ask)]`,title:`File exists but does not appear to contain SSG wiring`,children:`no ssg`}),n===!0&&(0,D.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-[var(--color-decision-allow)]`,title:`File contains SSG hook / MCP entries`,children:`wired`})]}):(0,D.jsx)(`span`,{className:`text-[10.5px] text-[var(--color-fg-3)]`,children:`missing`})]})}function Bm({title:e,status:t,children:n,hint:r}){return(0,D.jsxs)(`section`,{className:`hig-card hig-card-padded`,children:[(0,D.jsxs)(`header`,{className:`flex items-center justify-between mb-3`,children:[(0,D.jsxs)(`h2`,{className:`text-[13px] font-semibold text-[var(--color-fg-0)] flex items-center gap-2`,children:[t!==void 0&&(0,D.jsx)(Pm,{status:t}),e]}),r&&(0,D.jsx)(`span`,{className:`text-[10.5px] text-[var(--color-fg-3)]`,children:r})]}),(0,D.jsx)(`div`,{children:n})]})}function Vm({k:e,v:t,mono:n=!1}){return(0,D.jsxs)(`div`,{className:`flex items-baseline gap-3 py-1 text-[11.5px] border-b border-[var(--color-line-0)] last:border-0`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] min-w-[110px]`,children:e}),(0,D.jsx)(`span`,{className:`flex-1 text-[var(--color-fg-1)] ${n?`font-mono text-[11px]`:``}`,children:t})]})}var Hm={"claude-code":`Claude Code`,cursor:`Cursor`,codex:`Codex CLI`,pi:`Pi Agent`,gemini:`Gemini CLI`,antigravity:`Antigravity`,copilot:`GitHub Copilot`};function Um({adapter:e,home:t}){let n=Hm[e.id]??e.id,r=e.artifacts.filter(e=>e.exists&&e.ssg_wired).length,i=e.artifacts.filter(e=>e.exists).length;return(0,D.jsxs)(`div`,{className:`rounded-md border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(Pm,{status:e.status}),(0,D.jsx)(`span`,{className:`text-[12.5px] font-semibold text-[var(--color-fg-0)]`,children:n}),e.active&&(0,D.jsx)(`span`,{className:`text-[9.5px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded-sm text-[var(--color-hig-blue)] bg-[color-mix(in_oklab,var(--color-hig-blue)_14%,transparent)]`,title:`This is the adapter ssg is currently using at runtime`,children:`Active`})]}),(0,D.jsxs)(`span`,{className:`text-[10px] text-[var(--color-fg-3)]`,children:[r,`/`,e.artifacts.length,` wired`]})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-2 text-[10.5px]`,children:[(0,D.jsx)(`span`,{className:e.detected?`text-[var(--color-decision-allow)]`:`text-[var(--color-fg-3)]`,children:e.detected?`● detected`:`○ not detected`}),(0,D.jsx)(`span`,{className:e.healthy?`text-[var(--color-decision-allow)]`:`text-[var(--color-fg-3)]`,children:e.healthy?`● binary healthy`:`○ binary missing`}),i===0&&(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)]`,children:`○ no config files on disk`})]}),e.artifacts.length>0&&(0,D.jsx)(`div`,{className:`border-t border-[var(--color-line-0)] pt-1`,children:e.artifacts.map(e=>(0,D.jsx)(zm,{file:e,home:t,wired:e.exists?e.ssg_wired:void 0},e.path))}),e.status===`warn`&&i===0&&(0,D.jsxs)(`div`,{className:`mt-2 text-[10.5px] text-[var(--color-fg-3)]`,children:[`Wire it up with:`,` `,(0,D.jsxs)(`code`,{className:`font-mono text-[var(--color-fg-1)]`,children:[`ssg init --client=`,e.id]})]})]})}function Wm(){let{data:e,loading:t,error:n,refetch:r}=k(`/api/json/setup-status`);if(t&&!e)return(0,D.jsx)(`div`,{className:`py-12 text-center text-[var(--color-fg-3)] text-[12px]`,children:`Reading setup status…`});if(n||!e)return(0,D.jsxs)(`div`,{className:`hig-card hig-card-padded text-[12px]`,children:[(0,D.jsxs)(`p`,{className:`text-[var(--color-decision-block)] mb-2`,children:[`Could not load /api/json/setup-status: `,n??`no response`]}),(0,D.jsx)(`button`,{onClick:r,className:`hig-button hig-button-small`,children:`Retry`})]});let{summary:i,license:a,daemon:o,dashboard:s,native:c,db:l,mcp:u,rules:d,init_files:f,adapters:p,hub:m,checks:h,home:g,cwd:_}=e;return(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{className:`flex items-end justify-between`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h1`,{className:`text-[20px] font-semibold tracking-tight text-[var(--color-fg-0)] leading-tight`,children:`Setup Status`}),(0,D.jsxs)(`p`,{className:`text-[12.5px] text-[var(--color-fg-3)] mt-1 leading-relaxed`,children:[`What `,(0,D.jsx)(`code`,{className:`font-mono`,children:`ssg init`}),` wrote and whether every piece is wired up — license, hooks, MCP, native engine, daemon, rules, and hub packages.`]})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,D.jsxs)(`span`,{className:`text-[11px] text-[var(--color-fg-3)]`,children:[`ssg v`,e.version]}),(0,D.jsx)(`button`,{onClick:r,className:`hig-button hig-button-small`,children:`Refresh`})]})]}),(0,D.jsxs)(`section`,{"data-tutorial":`setup-summary`,className:`hig-card hig-card-padded flex items-center gap-6`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(Pm,{status:i.overall,className:`!w-3 !h-3`}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-[11px] uppercase tracking-wide text-[var(--color-fg-3)]`,children:`Overall`}),(0,D.jsx)(`div`,{className:`text-[14px] font-semibold text-[var(--color-fg-0)]`,children:i.overall===`ok`?`Healthy`:i.overall===`warn`?`Needs attention`:i.overall===`fail`?`Broken`:`Skipped`})]})]}),(0,D.jsxs)(`div`,{className:`flex gap-4 text-[12px]`,children:[(0,D.jsxs)(`span`,{className:`text-[var(--color-decision-allow)]`,children:[`● `,i.ok,` ok`]}),(0,D.jsxs)(`span`,{className:`text-[var(--color-decision-ask)]`,children:[`● `,i.warn,` warn`]}),i.fail>0&&(0,D.jsxs)(`span`,{className:`text-[var(--color-decision-block)]`,children:[`● `,i.fail,` fail`]}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-3)]`,children:[`○ `,i.skip,` skipped`]})]}),(0,D.jsxs)(`div`,{className:`ml-auto text-right`,children:[(0,D.jsx)(`div`,{className:`text-[10.5px] uppercase tracking-wide text-[var(--color-fg-3)]`,children:`Working dir`}),(0,D.jsx)(`code`,{className:`text-[11px] text-[var(--color-fg-1)]`,title:_,children:Rm(_,g)})]})]}),(0,D.jsx)(Bm,{title:`Checks`,hint:`${h.length} probes`,children:(0,D.jsx)(`div`,{children:h.map(e=>(0,D.jsxs)(`div`,{className:`flex items-start gap-3 py-1.5 border-b border-[var(--color-line-0)] last:border-0`,children:[(0,D.jsx)(Pm,{status:e.status,className:`mt-1`}),(0,D.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,D.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,D.jsx)(`span`,{className:`text-[12px] font-medium text-[var(--color-fg-0)]`,children:e.name}),(0,D.jsx)(Fm,{status:e.status})]}),(0,D.jsx)(`div`,{className:`text-[11px] text-[var(--color-fg-2)] mt-0.5 break-words`,children:e.detail}),e.fix&&(0,D.jsxs)(`div`,{className:`text-[11px] text-[var(--color-hig-blue)] font-mono mt-0.5`,children:[`→ `,e.fix]})]})]},e.name))})}),(0,D.jsxs)(Bm,{title:`License & authentication`,status:a.status===`healthy`||a.status===`healthy_free`?`ok`:`warn`,children:[(0,D.jsx)(Vm,{k:`Tier`,v:a.tier_label}),(0,D.jsx)(Vm,{k:`Status`,v:a.status}),(0,D.jsx)(Vm,{k:`Account`,v:a.email??`—`}),(0,D.jsx)(Vm,{k:`Auth method`,v:a.auth_method??`—`}),(0,D.jsx)(Vm,{k:`Evals today`,v:a.eval_daily_limit===null?`${a.evals_today.toLocaleString()} (unlimited)`:`${a.evals_today.toLocaleString()} / ${a.eval_daily_limit.toLocaleString()}`}),(0,D.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-[var(--color-line-0)]`,children:[(0,D.jsx)(`div`,{className:`text-[10.5px] uppercase tracking-wide text-[var(--color-fg-3)] mb-1`,children:`Credential files`}),(0,D.jsx)(zm,{file:a.license_file,home:g}),(0,D.jsx)(zm,{file:a.hosts_file,home:g})]})]}),(0,D.jsxs)(Bm,{title:`Runtime processes`,status:o.alive&&s.alive?`ok`:`warn`,children:[(0,D.jsx)(Vm,{k:`Daemon (evald)`,v:o.alive?`running — PID ${o.pid}`:o.pid?`stale — PID ${o.pid} in pidfile but process gone`:`not running`}),(0,D.jsx)(Vm,{k:`Daemon socket`,v:o.socket_exists?`present`:`missing`,mono:!0}),(0,D.jsx)(Vm,{k:`Dashboard (serve)`,v:s.alive?`running — PID ${s.pid}`:`not running`}),(0,D.jsx)(Vm,{k:`Native engine`,v:c.available?`loaded — sub-ms eval available`:`unavailable — TypeScript fallback`})]}),(0,D.jsxs)(Bm,{title:`Database & MCP`,status:l.status,children:[(0,D.jsx)(Vm,{k:`Rules in DB`,v:l.rules.toLocaleString()}),(0,D.jsx)(Vm,{k:`Audit log rows`,v:l.audit_rows.toLocaleString()}),(0,D.jsx)(Vm,{k:`DB path`,v:Rm(l.path,g),mono:!0}),(0,D.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-[var(--color-line-0)]`,children:[(0,D.jsx)(`div`,{className:`text-[10.5px] uppercase tracking-wide text-[var(--color-fg-3)] mb-1`,children:`MCP server`}),(0,D.jsx)(Vm,{k:`Status`,v:u.status===`active`?`active — ${u.recent_5min.toLocaleString()} calls in last 5 min`:u.status===`configured`?`configured — ${u.total.toLocaleString()} historical calls, none recent`:`no MCP traffic recorded yet`}),(0,D.jsx)(Vm,{k:`All-time calls`,v:u.total.toLocaleString()})]})]}),(0,D.jsxs)(Bm,{title:`Rules directories`,status:d.local_count>0?`ok`:`warn`,children:[(0,D.jsx)(Vm,{k:`Local`,v:`${d.local_count} .rules file${d.local_count===1?``:`s`}`}),(0,D.jsx)(Vm,{k:`Local path`,v:Rm(d.local_dir,g),mono:!0}),(0,D.jsx)(Vm,{k:`Global`,v:`${d.global_count} .rules file${d.global_count===1?``:`s`}`}),(0,D.jsx)(Vm,{k:`Global path`,v:Rm(d.global_dir,g),mono:!0})]}),(0,D.jsx)(Bm,{title:`Project init files`,hint:`${f.filter(e=>e.exists).length}/${f.length} present`,children:(0,D.jsx)(`div`,{children:f.map(e=>(0,D.jsx)(zm,{file:e,home:g},e.path))})}),(0,D.jsx)(Bm,{title:`Adapters, hooks & MCP files`,hint:e.active_adapter?`Active: ${Hm[e.active_adapter]??e.active_adapter}`:`No active adapter`,children:(0,D.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-1 lg:grid-cols-2`,children:p.map(e=>(0,D.jsx)(Um,{adapter:e,home:g},e.id))})}),(0,D.jsxs)(Bm,{title:`Hub-installed rulesets`,status:m.installs.length===0?`skip`:m.drift===0?`ok`:`warn`,hint:m.installs.length===0?`none installed`:`${m.in_sync} in sync${m.drift>0?`, ${m.drift} drift`:``}`,children:[(0,D.jsx)(zm,{file:m.pins_file,home:g}),m.installs.length===0?(0,D.jsxs)(`p`,{className:`text-[11.5px] text-[var(--color-fg-3)] mt-2`,children:[`Install rulesets from the Hub tab. Each install is recorded per project path in `,(0,D.jsx)(`code`,{className:`font-mono`,children:`hub-pins.json`}),`.`]}):(0,D.jsx)(`div`,{className:`mt-2 space-y-2`,children:m.installs.map((e,t)=>(0,D.jsxs)(`div`,{className:`rounded-md border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-2 text-[11.5px]`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,D.jsx)(Pm,{status:e.in_sync?`ok`:`warn`}),(0,D.jsx)(`span`,{className:`font-semibold text-[var(--color-fg-0)]`,children:e.id}),(0,D.jsx)(`span`,{className:`text-[10.5px] text-[var(--color-fg-3)]`,children:e.version}),(0,D.jsx)(`span`,{className:`ml-auto text-[10.5px] text-[var(--color-fg-3)]`,children:Lm(e.installed_at)})]}),(0,D.jsx)(`code`,{className:`block truncate text-[11px] text-[var(--color-fg-2)]`,title:e.path,children:Rm(e.path,g)}),e.files.length>0&&(0,D.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:e.files.map(e=>(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-2)] bg-[var(--color-surface-2)] border border-[var(--color-line-0)] rounded-sm px-1.5 py-0.5`,children:e},e))}),!e.in_sync&&e.drift_reason&&(0,D.jsxs)(`div`,{className:`mt-1 text-[10.5px] text-[var(--color-decision-ask)]`,children:[`Drift: `,e.drift_reason]})]},`${e.id}-${e.path}-${t}`))})]})]})}var Gm=[{id:`files`,label:`Files & folders`,blurb:`Deleting or changing things on your hard drive`},{id:`secrets`,label:`Secrets & keys`,blurb:`Reading or overwriting credentials and private files`},{id:`network`,label:`Network calls`,blurb:`Reaching out to websites and external APIs`},{id:`install`,label:`Installing software`,blurb:`Pulling new code or packages from the internet`},{id:`communication`,label:`Sending messages`,blurb:`Outgoing emails, posts, or chat messages`}],Km=[{id:`erase-folder`,label:`AI tries to erase a folder`,plainEffect:`Permanently deletes every file inside the "output" folder. Recovery is hard.`,category:`files`,emoji:`🗑️`,toolCall:{tool:`Bash`,input:{command:`find ./output -type f -delete`}},displayByOs:{windows:`Remove-Item .\\output -Recurse -Force`,macos:`find ./output -type f -delete`,linux:`find ./output -type f -delete`}},{id:`write-env`,label:`AI tries to write your .env file`,plainEffect:`Overwrites the file that holds your API keys, passwords, and other secrets.`,category:`secrets`,emoji:`⚠️`,toolCall:{tool:`Write`,input:{file_path:`.env`,content:`API_KEY=test`}}},{id:`read-ssh-key`,label:`AI tries to read your private key`,plainEffect:`Opens the SSH key that proves you are you on remote servers. Copying it is identity theft.`,category:`secrets`,emoji:`🔑`,toolCall:{tool:`Read`,input:{file_path:`~/.ssh/id_rsa`}},displayByOs:{windows:`Read C:\\Users\\You\\.ssh\\id_rsa`,macos:`Read ~/.ssh/id_rsa`,linux:`Read ~/.ssh/id_rsa`}},{id:`install-package`,label:`AI tries to install a package`,plainEffect:`Downloads code from a public registry and adds it to your project. The code runs with your permissions.`,category:`install`,emoji:`📦`,toolCall:{tool:`Bash`,input:{command:`npm install some-package --save`}}},{id:`fetch-web`,label:`AI tries to fetch a URL`,plainEffect:`Makes a web request to an outside service. Could leak data or pull in instructions.`,category:`network`,emoji:`🌐`,toolCall:{tool:`WebFetch`,input:{url:`https://api.example.com/data`,prompt:``}}},{id:`send-email`,label:`AI tries to send an email`,plainEffect:`Sends an email from your machine without your review. Anyone could end up CC’d.`,category:`communication`,emoji:`📧`,toolCall:{tool:`Bash`,input:{command:`sendmail -t < message.txt`}},displayByOs:{windows:`Send-MailMessage -To you@example.com -Subject "..." -Body (Get-Content message.txt)`,macos:`sendmail -t < message.txt`,linux:`sendmail -t < message.txt`}}],qm=`ssg.tryit.intro-dismissed.v1`,Jm=`ssg.tryit.os.v1`,Ym={allow:{label:`Allowed`,color:`text-emerald-300`,bg:`border-emerald-500/30 bg-emerald-500/5`,icon:`✓`,headline:`SSG would let this happen.`,next:`In real life, the AI would go ahead. If you would rather it didn’t, add a rule on the Rules page.`},block:{label:`Blocked`,color:`text-red-300`,bg:`border-red-500/30 bg-red-500/5`,icon:`✕`,headline:`SSG would stop this from running.`,next:`The AI never gets to perform the action. No files change, no commands run, no requests go out.`},ask:{label:`Ask first`,color:`text-amber-300`,bg:`border-amber-500/30 bg-amber-500/5`,icon:`?`,headline:`SSG would pause and ask you first.`,next:`You’d get a prompt on the Approvals page. Nothing happens until you click Allow or Deny.`},log:{label:`Logged`,color:`text-sky-300`,bg:`border-sky-500/30 bg-sky-500/5`,icon:`≡`,headline:`SSG would allow it but write it down.`,next:`The AI proceeds, and the action gets recorded in your Activity log for later review.`},force:{label:`Force-allow`,color:`text-violet-300`,bg:`border-violet-500/30 bg-violet-500/5`,icon:`→`,headline:`A high-priority rule explicitly allows this.`,next:`A “force” rule overrides anything that would have blocked or paused this action.`}};function Xm(){if(typeof window>`u`)return`linux`;try{let e=window.localStorage.getItem(Jm);if(e===`windows`||e===`macos`||e===`linux`)return e}catch{}let e=navigator.userAgent.toLowerCase();return e.includes(`win`)?`windows`:e.includes(`mac`)?`macos`:`linux`}function Zm(e){return e===`windows`?`Windows`:e===`macos`?`Mac`:`Linux`}function Qm(e){return e===`windows`?`⊞`:e===`macos`?`🍎`:`🐧`}function $m(e,t){let n=e.displayByOs?.[t];if(n)return n;let r=e.toolCall;return r.input.command?r.input.command:r.input.file_path?r.input.file_path:r.input.url?r.input.url:JSON.stringify(r.input)}function eh({n:e,label:t}){return(0,D.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,D.jsx)(`span`,{className:`flex items-center justify-center w-5 h-5 rounded-full bg-[var(--color-brand)]/15 text-[var(--color-brand)] text-[10px] font-semibold shrink-0`,children:e}),(0,D.jsx)(`span`,{className:`text-[11.5px] text-[var(--color-fg-2)] truncate`,children:t})]})}function th({os:e,setOs:t}){return(0,D.jsx)(`div`,{className:`inline-flex items-center gap-1 rounded-full border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-0.5`,children:[`windows`,`macos`,`linux`].map(n=>(0,D.jsxs)(`button`,{onClick:()=>t(n),className:`px-2.5 py-1 rounded-full text-[10.5px] font-medium cursor-pointer transition-colors ${n===e?`bg-[var(--color-brand)]/15 text-[var(--color-brand)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,title:`Show commands as they would look on ${Zm(n)}`,children:[Qm(n),` `,Zm(n)]},n))})}function nh({os:e,setOs:t,onDismiss:n}){return(0,D.jsxs)(`div`,{className:`rounded-2xl border border-[var(--color-brand)]/25 bg-[var(--color-brand)]/[0.04] p-4 sm:p-5 space-y-3.5`,children:[(0,D.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{className:`text-[15px] font-semibold text-[var(--color-fg-0)] leading-tight`,children:`What SSG does — and why this page is here`}),(0,D.jsxs)(`p`,{className:`text-[12.5px] text-[var(--color-fg-2)] mt-1 leading-relaxed max-w-[60ch]`,children:[`AI coding agents can run any command on your computer: delete files, read your secrets, send emails, install packages. SSG is the policy engine that decides which of those they’re actually allowed to do.`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-0)] font-medium`,children:`This sandbox shows SSG’s decisions in real time`}),`, without anything actually running. Pick a scenario, click Run, see what your guardrails would do.`]})]}),(0,D.jsx)(`button`,{onClick:n,className:`shrink-0 text-[var(--color-fg-4)] hover:text-[var(--color-fg-1)] cursor-pointer text-[14px] leading-none p-1 -m-1`,"aria-label":`Dismiss intro`,title:`Hide this primer`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1.5 text-[11.5px]`,children:[(0,D.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-emerald-300`,children:[(0,D.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-emerald-400`}),`Nothing executes`]}),(0,D.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-emerald-300`,children:[(0,D.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-emerald-400`}),`No files modified`]}),(0,D.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-emerald-300`,children:[(0,D.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-emerald-400`}),`No network traffic`]})]}),(0,D.jsxs)(`div`,{className:`rounded-xl border border-[var(--color-line-1)]/60 bg-[var(--color-surface-1)]/40 p-3`,children:[(0,D.jsx)(`p`,{className:`text-[10.5px] uppercase tracking-wide text-[var(--color-fg-3)] font-semibold mb-2`,children:`How it works`}),(0,D.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-3`,children:[(0,D.jsx)(eh,{n:1,label:`Pick a scenario below`}),(0,D.jsx)(eh,{n:2,label:`Click Run`}),(0,D.jsx)(eh,{n:3,label:`See the decision SSG would make`})]})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[(0,D.jsx)(`span`,{className:`text-[11.5px] text-[var(--color-fg-3)]`,children:`Showing commands as they look on`}),(0,D.jsx)(th,{os:e,setOs:t}),(0,D.jsx)(`span`,{className:`text-[10.5px] text-[var(--color-fg-4)]`,children:`(cosmetic — SSG’s decision is the same on every OS)`})]}),(0,D.jsxs)(`div`,{className:`flex items-center justify-between gap-3 flex-wrap pt-1`,children:[(0,D.jsx)(`p`,{className:`text-[11px] text-[var(--color-fg-4)] italic max-w-[44ch] leading-snug`,children:`Every AI agent will need a policy layer. This is what one looks like.`}),(0,D.jsx)(`button`,{onClick:n,className:`text-[11.5px] font-medium text-[var(--color-fg-2)] hover:text-[var(--color-fg-0)] cursor-pointer underline-offset-2 hover:underline`,children:`Got it, hide this primer`})]})]})}function rh({scenario:e,selected:t,os:n,onClick:r}){return(0,D.jsxs)(`button`,{onClick:r,className:`flex flex-col gap-1.5 rounded-xl border px-3.5 py-3 text-left cursor-pointer transition-all ${t?`border-[var(--color-brand)]/60 bg-[var(--color-brand)]/8 shadow-[0_0_0_3px_color-mix(in_oklab,var(--color-brand)_15%,transparent)]`:`border-[var(--color-line-1)] bg-[var(--color-surface-1)] hover:border-[var(--color-line-2)] hover:bg-[var(--color-surface-2)]/40`}`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`text-[18px] leading-none shrink-0`,children:e.emoji}),(0,D.jsx)(`span`,{className:`text-[13px] font-medium text-[var(--color-fg-0)] leading-snug flex-1 min-w-0`,children:e.label})]}),(0,D.jsx)(`p`,{className:`text-[11.5px] text-[var(--color-fg-3)] leading-snug`,children:e.plainEffect}),(0,D.jsx)(`p`,{className:`font-mono text-[10.5px] text-[var(--color-fg-4)] truncate`,children:$m(e,n)})]})}function ih(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(`Bash`),[f,p]=(0,_.useState)(`{"command": ""}`),[m,h]=(0,_.useState)(()=>{if(typeof window>`u`)return!1;try{return window.localStorage.getItem(qm)===`1`}catch{return!1}}),[g,v]=(0,_.useState)(()=>Xm()),[y,b]=(0,_.useState)(!1);function x(e){v(e);try{window.localStorage.setItem(Jm,e)}catch{}}function S(){h(!0);try{window.localStorage.setItem(qm,`1`)}catch{}}function C(){h(!1);try{window.localStorage.removeItem(qm)}catch{}}let w=Km.find(t=>t.id===e),T=(0,_.useMemo)(()=>{let e=new Map;for(let t of Km){let n=e.get(t.category)??[];n.push(t),e.set(t.category,n)}return Gm.filter(t=>e.has(t.id)).map(t=>({...t,scenarios:e.get(t.id)}))},[]);(0,_.useEffect)(()=>{(n||o)&&window.scrollTo({top:(document.getElementById(`tryit-result`)?.offsetTop??0)-80,behavior:`smooth`})},[n,o]),(0,_.useEffect)(()=>{if(typeof window>`u`)return;let e=new URLSearchParams(window.location.search).get(`scenario`);e&&Km.some(t=>t.id===e)&&t(e)},[]),(0,_.useEffect)(()=>{if(typeof window>`u`)return;let t=new URL(window.location.href);e?t.searchParams.set(`scenario`,e):t.searchParams.delete(`scenario`),window.history.replaceState({},``,t.toString())},[e]);function E(){if(!e)return;let t=new URL(window.location.href);t.searchParams.set(`scenario`,e),navigator.clipboard.writeText(t.toString()).then(()=>{b(!0),setTimeout(()=>b(!1),2e3)}).catch(()=>{})}async function O(e){a(!0),s(null),r(null);try{let t=await(await fetch(`/api/json/eval-dry-run`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify(e)})).json();t.error?s(t.error):r(t)}catch{s(`Could not reach the governance engine. Is SSG running?`)}finally{a(!1)}}function k(){w&&O(w.toolCall)}function ee(){let e;try{e=JSON.parse(f)}catch{s(`Invalid JSON in input field.`);return}if(typeof e!=`object`||!e){s(`Input must be a JSON object.`);return}O({tool:u,input:e})}let A=n?Ym[n.decision]??Ym.allow:null;return(0,D.jsxs)(`div`,{className:`max-w-3xl mx-auto py-4 space-y-4`,children:[(0,D.jsxs)(`header`,{className:`flex items-baseline justify-between gap-4 flex-wrap`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h1`,{className:`text-[22px] font-semibold text-[var(--color-fg-0)] tracking-tight leading-tight`,children:`Try it`}),(0,D.jsxs)(`p`,{className:`text-[13px] text-[var(--color-fg-2)] mt-0.5`,children:[`Your AI can run any command. SSG decides what it’s actually allowed to do.`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)]`,children:`Pick a scenario to see — nothing actually runs.`})]})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[m&&(0,D.jsx)(`button`,{onClick:C,className:`text-[11.5px] font-medium text-[var(--color-fg-3)] hover:text-[var(--color-fg-0)] cursor-pointer`,title:`Show the introduction again`,children:`What is Try It? →`}),(0,D.jsx)(`a`,{href:`/guardrails`,className:`text-[11.5px] font-medium text-[var(--color-brand)] hover:underline`,children:`Install more guardrails →`})]})]}),!m&&(0,D.jsx)(nh,{os:g,setOs:x,onDismiss:S}),m&&(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-1`,children:[(0,D.jsx)(`span`,{className:`text-[11px] text-[var(--color-fg-4)]`,children:`Commands shown as on`}),(0,D.jsx)(th,{os:g,setOs:x})]}),(0,D.jsx)(`div`,{"data-tutorial":`try-scenarios`,className:`space-y-4`,children:T.map(n=>(0,D.jsxs)(`section`,{className:`space-y-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-baseline gap-2 px-1`,children:[(0,D.jsx)(`h3`,{className:`text-[11px] uppercase tracking-wide text-[var(--color-fg-3)] font-semibold`,children:n.label}),(0,D.jsx)(`p`,{className:`text-[11px] text-[var(--color-fg-4)]`,children:n.blurb})]}),(0,D.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:n.scenarios.map(n=>(0,D.jsx)(rh,{scenario:n,selected:e===n.id,os:g,onClick:()=>{t(n.id),r(null),s(null)}},n.id))})]},n.id))}),w&&(0,D.jsxs)(`div`,{"data-tutorial":`try-detail`,className:`rounded-xl border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-4 space-y-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,D.jsx)(`span`,{className:`text-[22px] leading-none shrink-0`,children:w.emoji}),(0,D.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,D.jsx)(`p`,{className:`text-[13.5px] font-medium text-[var(--color-fg-0)]`,children:w.label}),(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-2)] mt-0.5 leading-relaxed`,children:w.plainEffect})]})]}),(0,D.jsxs)(`div`,{className:`rounded-lg border border-[var(--color-line-0)] bg-[var(--color-surface-0)] px-3 py-2`,children:[(0,D.jsxs)(`p`,{className:`text-[10px] uppercase tracking-wide text-[var(--color-fg-4)] font-semibold mb-1`,children:[`What the AI would run · `,Zm(g)]}),(0,D.jsx)(`code`,{className:`font-mono text-[12px] text-[var(--color-fg-1)] break-all`,children:$m(w,g)})]}),(0,D.jsxs)(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[(0,D.jsxs)(`p`,{className:`text-[11.5px] text-[var(--color-fg-3)]`,children:[`Click Run to see what SSG would decide.`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`The command does not actually execute.`})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,D.jsx)(`button`,{onClick:E,className:`inline-flex items-center gap-1 px-3 h-8 rounded-full text-[11.5px] font-medium cursor-pointer transition-colors
50
+ -d '{"confirm":"UNINSTALL_ALL_RULES"}'`})]})]})})}function am({entry:e,ruleId:t,onJump:n,onChanged:r}){return!e||!t?(0,D.jsx)(`span`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-4)] shrink-0`,children:`no rule`}):(0,D.jsxs)(`div`,{className:`flex items-center gap-1 shrink-0`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:async()=>{await Bp(t,e.file,`log`),r()},title:`Soften this rule to log-only — keeps the rule running but stops blocking/asking`,className:`px-1.5 py-0.5 rounded-sm border border-[var(--color-line-1)] text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-0)] hover:border-[var(--color-brand)]/60 cursor-pointer transition-colors`,children:`→ log`}),(0,D.jsx)(`button`,{type:`button`,onClick:async()=>{e.rule.enabled&&(await zp(t,e.file),r())},disabled:!e.rule.enabled,title:e.rule.enabled?`Disable this rule entirely`:`Rule is already disabled`,className:`px-1.5 py-0.5 rounded-sm border border-[var(--color-line-1)] text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-red-300 hover:border-red-400/60 cursor-pointer transition-colors disabled:opacity-40 disabled:cursor-not-allowed`,children:e.rule.enabled?`disable`:`disabled`}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>n(t),title:`Scroll to this rule below — clears search and filter`,className:`px-1.5 py-0.5 rounded-sm border border-[var(--color-brand)]/40 bg-[var(--color-brand)]/10 text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-0)] hover:bg-[var(--color-brand)]/20 cursor-pointer transition-colors`,children:`view`})]})}function om({stats:e,ruleIndex:t,onJump:n,onChanged:r}){let i=(0,_.useMemo)(()=>{let n=[];for(let[r,i]of Object.entries(e)){let e=i.lastBlockAskSeen??0;e<=0||n.push({ruleId:r,lastBlockAskSeen:e,entry:t.get(r)})}return n.sort((e,t)=>t.lastBlockAskSeen-e.lastBlockAskSeen),n.slice(0,5)},[e,t]);return i.length===0?null:(0,D.jsx)(K,{children:(0,D.jsxs)(`details`,{open:!0,children:[(0,D.jsxs)(`summary`,{className:`px-3 py-2 cursor-pointer list-none select-none flex items-center gap-3 hover:bg-[var(--color-surface-2)]/70`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`recent block/ask activity`}),(0,D.jsxs)(`span`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:[i.length,` rule`,i.length===1?``:`s`,` — newest first`]})]}),(0,D.jsx)(J,{className:`py-2`,children:(0,D.jsx)(`div`,{className:`divide-y divide-[var(--color-line-0)]`,children:i.map(e=>{let t=e.entry?.rule.decision??`—`,i=e.entry?.rule.message??``;return(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono py-1.5`,children:[(0,D.jsx)(`span`,{className:`uppercase tracking-wider w-12 shrink-0 ${Pp[t]??`text-[var(--color-fg-2)]`}`,children:t}),(0,D.jsx)(`code`,{className:`text-[var(--color-fg-0)] shrink-0 truncate w-48`,children:e.ruleId}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] truncate flex-1 min-w-0 hidden md:inline`,children:i}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] tabular-nums shrink-0 w-16 text-right`,children:Gp(e.lastBlockAskSeen)}),(0,D.jsx)(am,{entry:e.entry,ruleId:e.ruleId,onJump:n,onChanged:r})]},e.ruleId)})})})]})})}function sm({triggers:e,ruleIndex:t,onJump:n,onChanged:r}){let i=Math.floor(Date.now()/1e3),a=i-24*3600,o=i-4*3600,s=(e??[]).filter(e=>e.ruleId&&jp.has(e.decision)),c=s[0]??null,l=new Map;for(let e of s){if(e.timestamp<a||!e.ruleId)continue;let t=l.get(e.ruleId);t?(t.hits++,e.timestamp>t.lastSeen&&(t.lastSeen=e.timestamp,t.sample=e)):l.set(e.ruleId,{ruleId:e.ruleId,decision:e.decision,hits:1,lastSeen:e.timestamp,sample:e})}let u=[...l.values()].filter(e=>e.hits>=3).sort((e,t)=>t.hits-e.hits).slice(0,5),d=c&&c.timestamp>=o;return d||u.length>0?(0,D.jsx)(K,{children:(0,D.jsxs)(`details`,{open:!0,children:[(0,D.jsxs)(`summary`,{className:`px-3 py-2 cursor-pointer list-none select-none flex items-center gap-3 hover:bg-[var(--color-surface-2)]/70 flex-wrap`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`recent decisions`}),d&&c&&(0,D.jsxs)(`span`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:[`last:`,` `,(0,D.jsx)(`span`,{className:Pp[c.decision]??`text-[var(--color-fg-2)]`,children:c.decision}),` `,`· `,Gp(c.timestamp)]}),u.length>0&&(0,D.jsxs)(`span`,{className:`text-[11px] font-mono text-amber-300/80 ml-auto`,children:[u.length,` rule`,u.length===1?``:`s`,` fired ≥3× in 24h`]})]}),(0,D.jsxs)(J,{className:`py-2 space-y-3`,children:[d&&c&&(0,D.jsxs)(`div`,{className:`space-y-1`,children:[(0,D.jsx)(`div`,{className:`overline`,children:`last decision`}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono`,children:[(0,D.jsx)(`span`,{className:`uppercase tracking-wider w-12 shrink-0 ${Pp[c.decision]??`text-[var(--color-fg-2)]`}`,children:c.decision}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-2)] w-20 shrink-0 truncate`,children:c.tool}),(0,D.jsx)(`code`,{className:`text-[var(--color-fg-1)] flex-1 min-w-0 truncate`,children:c.input||`—`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] tabular-nums shrink-0 w-16 text-right`,children:Gp(c.timestamp)}),(0,D.jsx)(am,{entry:c.ruleId?t.get(c.ruleId):void 0,ruleId:c.ruleId,onJump:n,onChanged:r})]}),c.ruleId&&(0,D.jsxs)(`div`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] pl-14`,children:[`rule`,` `,(0,D.jsx)(`code`,{className:`text-[var(--color-fg-2)]`,children:c.ruleId})]})]}),u.length>0&&(0,D.jsxs)(`div`,{className:`space-y-1`,children:[(0,D.jsx)(`div`,{className:`overline`,children:`top fired in 24h (≥3 hits) — soften or disable to reduce noise`}),(0,D.jsx)(`div`,{className:`divide-y divide-[var(--color-line-0)]`,children:u.map(e=>{let i=t.get(e.ruleId);return(0,D.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono py-1.5`,children:[(0,D.jsxs)(`span`,{className:`text-amber-300 tabular-nums shrink-0 w-10`,children:[e.hits,`×`]}),(0,D.jsx)(`span`,{className:`uppercase tracking-wider w-12 shrink-0 ${Pp[e.decision]??`text-[var(--color-fg-2)]`}`,children:e.decision}),(0,D.jsx)(`code`,{className:`text-[var(--color-fg-0)] truncate flex-1 min-w-0`,children:e.ruleId}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] truncate shrink-0 w-32 text-right hidden md:inline`,children:e.sample.tool}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] tabular-nums shrink-0 w-16 text-right`,children:Gp(e.lastSeen)}),(0,D.jsx)(am,{entry:i,ruleId:e.ruleId,onJump:n,onChanged:r})]},e.ruleId)})})]})]})]})}):(0,D.jsx)(K,{children:(0,D.jsxs)(J,{className:`py-2 flex items-center gap-3 text-[11px] font-mono flex-wrap`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`recent decisions`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)]`,children:`no blocks or asks in the last 4h — search below to find any rule by id, message, or what it last blocked`})]})})}function cm({chip:e,onChange:t,counts:n}){return(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5 flex-wrap`,children:[(0,D.jsx)(`span`,{className:`overline text-[10px] mr-1`,children:`quick filters`}),[{key:`hot`,label:`🔥 hot now`,hint:`Rules that fired in the last hour`,color:`text-amber-300 border-amber-500/40 bg-amber-500/5 hover:bg-amber-500/10`},{key:`blocked`,label:`⛔ blocking`,hint:`Rules set to block and currently enabled`,color:`text-red-300 border-red-500/40 bg-red-500/5 hover:bg-red-500/10`},{key:`noisy`,label:`📢 noisy`,hint:`Fired ≥3 times in 24h — candidates to soften`,color:`text-amber-300 border-amber-500/40 bg-amber-500/5 hover:bg-amber-500/10`},{key:`slow`,label:`🐢 slow >50ms`,hint:`Rules with avg eval time over 50ms`,color:`text-rose-300 border-rose-500/40 bg-rose-500/5 hover:bg-rose-500/10`},{key:`never`,label:`💤 never fired`,hint:`Enabled rules that have never matched — possible dead code`,color:`text-[var(--color-fg-3)] border-[var(--color-line-1)] hover:bg-[var(--color-surface-2)]`},{key:`disabled`,label:`⏸ disabled`,hint:`Rules toggled off — not currently enforced`,color:`text-[var(--color-fg-3)] border-[var(--color-line-1)] hover:bg-[var(--color-surface-2)]`}].map(r=>{let i=e===r.key,a=n[r.key];return(0,D.jsxs)(`button`,{type:`button`,onClick:()=>t(i?`none`:r.key),title:r.hint,className:`px-2 py-1 rounded-sm border text-[11px] font-mono uppercase tracking-wider cursor-pointer transition-colors ${i?`border-[var(--color-brand)]/60 bg-[var(--color-brand)]/15 text-[var(--color-fg-0)]`:r.color}`,children:[r.label,(0,D.jsx)(`span`,{className:`ml-1.5 tabular-nums normal-case ${i?`text-[var(--color-fg-2)]`:`text-[var(--color-fg-4)]`}`,children:a})]},r.key)}),e!==`none`&&(0,D.jsx)(`button`,{type:`button`,onClick:()=>t(`none`),className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer ml-1`,children:`✕ clear`})]})}function lm({value:e,onChange:t,matchCount:n,sortKey:r,onSortChange:i}){return(0,D.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap`,children:[(0,D.jsxs)(`div`,{className:`relative flex-1 min-w-[260px]`,children:[(0,D.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,className:`absolute left-2.5 top-1/2 -translate-y-1/2 text-[var(--color-fg-4)] pointer-events-none`,children:[(0,D.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,D.jsx)(`path`,{d:`m21 21-4.3-4.3`})]}),(0,D.jsx)(`input`,{type:`text`,placeholder:`search rule id, message, or paste a blocked command…`,title:`Searches rule id, message, AND recent audit-log inputs/tools — paste a blocked command to find its rule`,value:e,onChange:e=>t(e.target.value),className:`bg-[var(--color-surface-1)] border border-[var(--color-line-1)] text-[var(--color-fg-1)] text-xs rounded-sm pl-8 pr-24 py-2 w-full focus:outline-none focus:border-[var(--color-brand)]/60 placeholder:text-[var(--color-fg-4)] font-mono`}),e&&(0,D.jsxs)(`div`,{className:`absolute right-2 top-1/2 -translate-y-1/2 flex items-center gap-2`,children:[n!==null&&(0,D.jsxs)(`span`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] tabular-nums`,children:[n,` match`,n===1?``:`es`]}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>t(``),className:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer`,title:`Clear search`,"aria-label":`Clear search`,children:`✕`})]})]}),(0,D.jsxs)(`label`,{className:`flex items-center gap-1.5 text-[10px] font-mono uppercase tracking-wider`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)]`,children:`sort`}),(0,D.jsxs)(`select`,{value:r,onChange:e=>i(e.target.value),className:`bg-[var(--color-surface-1)] border border-[var(--color-line-1)] text-[var(--color-fg-1)] rounded-sm px-1.5 py-1 cursor-pointer focus:outline-none focus:border-[var(--color-brand)]/50`,children:[(0,D.jsx)(`option`,{value:`default`,children:`default · by file`}),(0,D.jsx)(`option`,{value:`hits`,children:`most hits`}),(0,D.jsx)(`option`,{value:`slowest`,children:`slowest`}),(0,D.jsx)(`option`,{value:`recent`,children:`recently fired`}),(0,D.jsx)(`option`,{value:`alpha`,children:`alphabetical`})]})]})]})}function um({decisionFilter:e,onChange:t,totalRules:n,ruleCount:r,hits:i,window:a}){let o=Object.values(i).reduce((e,t)=>e+t,0);return(0,D.jsx)(K,{children:(0,D.jsx)(J,{className:`px-3 py-2`,children:(0,D.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,D.jsxs)(`div`,{className:`flex flex-col`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`filter by decision`}),(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] uppercase tracking-wider`,children:[`rules · applied in `,a]})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-1 flex-wrap`,children:[(0,D.jsxs)(`button`,{type:`button`,onClick:()=>t(`all`),title:`Show all ${n} rules — ${o.toLocaleString()} applied in ${a}`,className:`px-2 py-1 rounded-sm border text-[11px] font-mono uppercase tracking-wider cursor-pointer transition-colors ${e===`all`?`border-[var(--color-brand)]/60 bg-[var(--color-brand)]/10 text-[var(--color-fg-0)]`:`border-[var(--color-line-1)] text-[var(--color-fg-2)] hover:border-[var(--color-brand)]/30 hover:text-[var(--color-fg-0)]`}`,children:[`all`,(0,D.jsx)(`span`,{className:`ml-1.5 text-[var(--color-fg-4)] tabular-nums normal-case`,children:n}),o>0&&(0,D.jsxs)(`span`,{className:`ml-1 text-[var(--color-fg-3)] tabular-nums normal-case`,children:[`· `,o.toLocaleString()]})]}),Np.map(n=>{let o=r[n]??0,s=i[n]??0,c=e===n,l=o===0,u=Pp[n]??`text-[var(--color-fg-2)]`;return(0,D.jsxs)(`button`,{type:`button`,onClick:()=>t(n),disabled:l,title:`${o} rule${o===1?``:`s`} set to ${n} · ${s.toLocaleString()} applied in ${a}`,className:`px-2 py-1 rounded-sm border text-[11px] font-mono uppercase tracking-wider cursor-pointer transition-colors disabled:opacity-30 disabled:cursor-not-allowed ${c?`border-[var(--color-brand)]/60 bg-[var(--color-brand)]/10 ${u}`:`border-[var(--color-line-1)] ${u} hover:border-[var(--color-brand)]/30`}`,children:[n,(0,D.jsx)(`span`,{className:`ml-1.5 text-[var(--color-fg-4)] tabular-nums normal-case`,children:o}),s>0&&(0,D.jsxs)(`span`,{className:`ml-1 text-[var(--color-fg-3)] tabular-nums normal-case`,children:[`· `,s.toLocaleString()]})]},n)})]})]})})})}var dm={covered:{label:`covered`,color:`var(--color-decision-allow)`},inactive:{label:`all off`,color:`var(--color-decision-ask)`},gap:{label:`no rules`,color:`var(--color-decision-block)`}};function fm({cov:e,active:t,onClick:n}){let r=dm[e.status];return(0,D.jsxs)(`button`,{type:`button`,onClick:n,title:e.meta.description,className:`text-left rounded-sm border px-2 py-1.5 transition-colors cursor-pointer ${t?`border-[var(--color-brand)] bg-[var(--color-brand)]/10`:`border-[var(--color-line-1)] hover:bg-[var(--color-surface-2)]/70`}`,style:{borderLeft:`2px solid ${e.meta.color}`},children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,D.jsx)(`span`,{"aria-hidden":!0,children:e.meta.icon}),(0,D.jsx)(`span`,{className:`text-[11px] text-[var(--color-fg-0)] font-medium truncate flex-1`,children:e.meta.title})]}),(0,D.jsxs)(`div`,{className:`flex items-center justify-between mt-1 gap-1`,children:[(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)] tabular-nums`,children:[e.total,` rule`,e.total===1?``:`s`,e.enabledShell>0&&(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)]`,children:[` · `,e.enabledShell,` shell`]})]}),(0,D.jsx)(`span`,{className:`text-[9px] uppercase tracking-wider font-mono`,style:{color:r.color},children:r.label})]}),e.meta.attack&&(0,D.jsxs)(`div`,{className:`text-[9px] font-mono text-[var(--color-fg-4)] mt-0.5 truncate`,children:[e.meta.attack.id,` `,e.meta.attack.name]})]})}function pm({coverage:e,activeCategory:t,onPick:n}){let r=e.total>0?Math.round(e.covered/e.total*100):0,i=e.categories.filter(e=>e.meta.security||e.total>0),a=e.categories.reduce((e,t)=>e+t.enabledShell,0);return(0,D.jsx)(K,{children:(0,D.jsxs)(J,{className:`px-3 py-2.5 space-y-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3 flex-wrap`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{className:`overline text-[11px]`,children:`tool-use coverage`}),(0,D.jsx)(`p`,{className:`text-[11px] text-[var(--color-fg-3)] mt-0.5`,children:`rules categorized like Sigma detections · mapped to MITRE ATT&CK tactics`})]}),(0,D.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,D.jsxs)(`span`,{className:`font-mono text-sm text-[var(--color-fg-0)] tabular-nums`,children:[e.covered,(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)]`,children:[`/`,e.total]})]}),(0,D.jsx)(`span`,{className:`text-[11px] uppercase tracking-wider text-[var(--color-fg-3)]`,children:`aspects governed`})]})]}),(0,D.jsx)(`div`,{className:`h-1.5 rounded-full bg-[var(--color-surface-3)] overflow-hidden`,children:(0,D.jsx)(`div`,{className:`h-full rounded-full transition-all`,style:{width:`${r}%`,background:r>=80?`var(--color-decision-allow)`:r>=50?`var(--color-decision-ask)`:`var(--color-decision-block)`}})}),(0,D.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:[a,` active rule`,a===1?``:`s`,` govern shell / command execution`,e.uncategorized>0&&(0,D.jsxs)(D.Fragment,{children:[` · `,(0,D.jsxs)(`span`,{className:`text-amber-300`,children:[e.uncategorized,` uncategorized`]})]})]}),(0,D.jsx)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-1.5`,children:i.map(e=>(0,D.jsx)(fm,{cov:e,active:t===e.id,onClick:()=>n(e.id)},e.id))})]})})}function mm({category:e,inferred:t,onPick:n}){let r=Ep(e);return(0,D.jsxs)(`button`,{type:`button`,onClick:()=>n(e),title:`${r.title}${t?` (inferred — add an explicit CATEGORY directive)`:``} — ${r.description}`,className:`text-[9px] font-mono uppercase tracking-wider px-1 py-px rounded-sm border cursor-pointer shrink-0 inline-flex items-center gap-0.5`,style:{color:r.color,borderColor:`${r.color}55`},children:[(0,D.jsx)(`span`,{"aria-hidden":!0,children:r.icon}),(0,D.jsx)(`span`,{children:r.title}),t&&(0,D.jsx)(`span`,{className:`opacity-50`,children:`~`})]})}function hm(){let{mode:e,setMode:t}=Ct(),n=e===`pro`,r=V(Mp)[`rules-changed`],[i,a]=(0,_.useState)(!0),[o,s]=(0,_.useState)(0);(0,_.useEffect)(()=>{if(!i)return;let e=setInterval(()=>{s(e=>e+1)},Lp);return()=>clearInterval(e)},[i]);let{data:c,refetch:l}=k(Rp(`/api/json/rules`,r+o),[r,o]),[u,d]=(0,_.useState)(`7d`),{data:f,refetch:p}=k(Rp(`/api/json/rules-stats?window=${u}`,o),[r,u,o]),{data:m,refetch:h}=k(Rp(`/api/json/rules-performance`,o),[r,o]),{data:g,refetch:v}=k(Rp(`/api/json/rule-triggers/recent?limit=500`,o),[r,o]),[y,b]=(0,_.useState)(``),[x,S]=(0,_.useState)(`all`),[C,w]=(0,_.useState)(`all`),[T,E]=(0,_.useState)(`none`),[O,ee]=(0,_.useState)(`default`),[A,j]=(0,_.useState)(`file`),[M,te]=(0,_.useState)(``),[N,P]=(0,_.useState)(new Set),[F,I]=(0,_.useState)(new Set),[ne,re]=(0,_.useState)(()=>new URLSearchParams(window.location.search).get(`highlight`)??``),ie=(0,_.useRef)(null);(0,_.useEffect)(()=>{ie.current&&ie.current.scrollIntoView({behavior:`smooth`,block:`center`})},[]);let L=f?.stats??{},R=(0,_.useMemo)(()=>{let e=new Map;if(!c)return e;for(let t of c.rulesets)for(let n of t.rules)e.set(n.id,{rule:n,file:t.file});return e},[c]),ae=(0,_.useMemo)(()=>{let e=[];if(c)for(let t of c.rulesets)for(let n of t.rules)e.push({id:n.id,target:n.target??`any`,decision:n.decision,category:n.category,enabled:n.enabled});return Ap(e)},[c]);function oe(){l(),p(),h(),v(),s(e=>e+1)}function se(e){b(``),S(`all`),w(`all`),E(`none`),te(``),re(e);let t=new URL(window.location.href);t.searchParams.set(`highlight`,e),window.history.replaceState(null,``,t.toString())}let ce=(0,_.useMemo)(()=>{let e=new Set;if(!g)return e;let t=Math.floor(Date.now()/1e3)-3600;for(let n of g.rows)n.ruleId&&n.timestamp>=t&&e.add(n.ruleId);return e},[g]),le=(0,_.useMemo)(()=>{let e=new Set;if(!g)return e;let t=Math.floor(Date.now()/1e3)-24*3600,n=new Map;for(let e of g.rows)!e.ruleId||e.timestamp<t||jp.has(e.decision)&&n.set(e.ruleId,(n.get(e.ruleId)??0)+1);for(let[t,r]of n)r>=3&&e.add(t);return e},[g]);if(!c)return(0,D.jsx)(`p`,{className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)]`,children:`loading rules…`});if(c.rulesets.length===0)return(0,D.jsxs)(`div`,{className:`rounded-sm border border-dashed border-[var(--color-line-1)] bg-[var(--color-surface-1)]/50 p-10 text-center`,children:[(0,D.jsx)(`p`,{className:`text-sm text-[var(--color-fg-2)] mb-2`,children:`No .rules files found.`}),(0,D.jsx)(`a`,{href:`/hub`,className:`text-[11px] font-mono uppercase tracking-wider text-[var(--color-brand)] hover:underline`,children:`→ browse hub to install rulesets`})]});let z=y.toLowerCase(),ue=(()=>{let e=new Set;if(!z||!g)return e;for(let t of g.rows){if(!t.ruleId)continue;let n=(t.input??``).toLowerCase(),r=(t.tool??``).toLowerCase();(n.includes(z)||r.includes(z))&&e.add(t.ruleId)}return e})();function de(e){if(x===`enabled`&&!e.enabled||x===`disabled`&&e.enabled)return!1;let t=L[e.id],n=t?.hits??0;return!(x===`hit`&&n===0||x===`never`&&n>0||C!==`all`&&e.decision!==C||M&&(e.category??`uncategorized`)!==M||T===`hot`&&!ce.has(e.id)||T===`noisy`&&!le.has(e.id)||T===`blocked`&&!(e.decision===`block`&&e.enabled)||T===`slow`&&!(t&&t.avgDurationMs>50)||T===`never`&&!(e.enabled&&(!t||t.hits===0))||T===`disabled`&&e.enabled)}let fe=(()=>{let e={},t={};for(let n of c.rulesets)for(let r of n.rules){e[r.decision]=(e[r.decision]??0)+1;let n=L[r.id]?.hits??0;n>0&&(t[r.decision]=(t[r.decision]??0)+n)}return{ruleCount:e,hits:t}})(),pe={hot:0,blocked:0,noisy:le.size,slow:0,never:0,disabled:0};for(let e of c.rulesets)for(let t of e.rules){ce.has(t.id)&&pe.hot++,t.decision===`block`&&t.enabled&&pe.blocked++;let e=L[t.id];e&&e.avgDurationMs>50&&pe.slow++,t.enabled&&(!e||e.hits===0)&&pe.never++,t.enabled||pe.disabled++}let me=!!z||x!==`all`||C!==`all`||T!==`none`||M!==``;function he(e){return O===`default`?e:[...e].sort((e,t)=>O===`hits`?(L[t.id]?.hits??0)-(L[e.id]?.hits??0):O===`slowest`?(L[t.id]?.avgDurationMs??0)-(L[e.id]?.avgDurationMs??0):O===`recent`?(L[t.id]?.lastSeen??0)-(L[e.id]?.lastSeen??0):O===`alpha`?e.id.localeCompare(t.id):0)}let ge=[];for(let e of c.rulesets)for(let t of e.rules)ge.push({...t,file:e.file});let _e=ge.filter(e=>z&&!e.id.toLowerCase().includes(z)&&!e.message.toLowerCase().includes(z)&&!ue.has(e.id)?!1:de(e)),ve;if(A===`category`){let e=new Map;for(let t of _e){let n=t.category??`uncategorized`,r=e.get(n);r?r.push(t):e.set(n,[t])}ve=Cp.filter(t=>e.has(t.id)).map(t=>({key:t.id,kind:`category`,label:t.title,icon:t.icon,accent:t.color,sublabel:t.attack?`${t.attack.id} · ${t.attack.name}`:`D3FEND · ${t.d3fend}`,rules:he(e.get(t.id)??[])}))}else{let e=new Map;for(let t of _e){let n=e.get(t.file);n?n.push(t):e.set(t.file,[t])}ve=c.rulesets.map(t=>({key:t.file,kind:`file`,label:t.file,content:t.content,rules:he(e.get(t.file)??[])})).filter(e=>e.rules.length>0||!me)}let ye=ge.length,be=ge.filter(e=>e.enabled).length,xe=new Set;for(let e of ve)for(let t of e.rules)xe.add(t.id);let Se=me?xe.size:null,B=[];for(let e of N){let t=R.get(e);t&&B.push({ruleId:e,file:t.file})}function Ce(e){P(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}function we(e){P(t=>{let n=new Set(t);if(e.length>0&&e.every(e=>n.has(e.id)))for(let t of e)n.delete(t.id);else for(let t of e)n.add(t.id);return n})}function Te(e){if(M===e){te(``);return}te(e),j(`category`),re(``)}function Ee(){P(e=>{let t=new Set(e);for(let e of xe)t.add(e);return t})}function De(e){I(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}async function Oe(e,t){B.length!==0&&(e===`enable`?await Vp(B,!0):e===`disable`?await Vp(B,!1):e===`delete`?(await Up(B),P(new Set)):e===`decision`&&t&&await Hp(B,t),oe())}return(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsx)(`div`,{"data-tutorial":`rules-firewall`,children:(0,D.jsx)(em,{totalRules:ye,activeRules:be,onChanged:oe})}),(0,D.jsx)(Xp,{}),(0,D.jsx)(`div`,{className:`flex items-center gap-4 flex-wrap`,children:(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h1`,{className:`overline text-[11px]`,children:`rules`}),(0,D.jsxs)(`div`,{className:`flex items-baseline gap-3 mt-1`,children:[(0,D.jsxs)(`span`,{className:`font-mono text-sm text-[var(--color-fg-0)] tabular-nums`,children:[be,(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)]`,children:[`/`,ye]}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] ml-1.5 text-[11px] uppercase tracking-wider`,children:`active`})]}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsxs)(`span`,{className:`font-mono text-[11px] text-[var(--color-fg-3)] uppercase tracking-wider`,children:[c.files.length,` file`,c.files.length===1?``:`s`]})]})]})}),(0,D.jsx)(`div`,{"data-tutorial":`rules-coverage`,children:(0,D.jsx)(pm,{coverage:ae,activeCategory:M,onPick:Te})}),(0,D.jsx)(`div`,{"data-tutorial":`rules-stats`,children:(0,D.jsx)(Zp,{perf:m,triggers:g,decisionAggregates:fe,livePoll:i,onTogglePoll:()=>a(e=>!e),statsWindow:u,onWindowChange:d,mode:e,onModeChange:t})}),(0,D.jsx)(K,{children:(0,D.jsxs)(J,{className:`px-3 py-2.5 space-y-2.5`,children:[(0,D.jsx)(lm,{value:y,onChange:b,matchCount:Se,sortKey:O,onSortChange:ee}),(0,D.jsx)(cm,{chip:T,onChange:E,counts:pe}),(0,D.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap pt-1 border-t border-[var(--color-line-0)]`,children:[(0,D.jsx)(`span`,{className:`overline text-[10px]`,children:`state`}),(0,D.jsx)(`div`,{className:`flex items-center gap-1 text-[10px] font-mono uppercase tracking-wider`,children:[`all`,`enabled`,`disabled`,`hit`,`never`].map(e=>(0,D.jsx)(`button`,{onClick:()=>S(e),className:`px-1.5 py-0.5 rounded-sm border cursor-pointer transition-colors ${x===e?`border-[var(--color-brand)]/60 bg-[var(--color-brand)]/10 text-[var(--color-fg-0)]`:`border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,children:e},e))}),(0,D.jsx)(`span`,{className:`overline text-[10px] ml-1`,children:`group`}),(0,D.jsx)(`div`,{className:`flex items-center gap-1 text-[10px] font-mono uppercase tracking-wider`,children:[`file`,`category`].map(e=>(0,D.jsxs)(`button`,{onClick:()=>j(e),className:`px-1.5 py-0.5 rounded-sm border cursor-pointer transition-colors ${A===e?`border-[var(--color-brand)]/60 bg-[var(--color-brand)]/10 text-[var(--color-fg-0)]`:`border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,children:[`by `,e]},e))})]}),M&&(0,D.jsxs)(`div`,{className:`flex items-center gap-2 flex-wrap pt-1 border-t border-[var(--color-line-0)]`,children:[(0,D.jsx)(`span`,{className:`overline text-[10px]`,children:`category`}),(0,D.jsxs)(`span`,{className:`text-[11px] font-mono px-1.5 py-0.5 rounded-sm border`,style:{color:Ep(M).color,borderColor:`${Ep(M).color}66`},children:[Ep(M).icon,` `,Ep(M).title]}),(0,D.jsx)(`button`,{onClick:()=>te(``),className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer`,children:`clear ✕`})]})]})}),(0,D.jsx)(um,{decisionFilter:C,onChange:w,totalRules:ye,ruleCount:fe.ruleCount,hits:fe.hits,window:u}),n&&(0,D.jsx)(`div`,{"data-tutorial":`rules-top`,children:(0,D.jsx)($p,{stats:L,ruleIndex:R,triggers:g?.rows,statsWindow:u,onJump:se})}),(0,D.jsx)(`div`,{"data-tutorial":`rules-activity`,children:(0,D.jsx)(om,{stats:L,ruleIndex:R,onJump:se,onChanged:oe})}),(0,D.jsx)(`div`,{"data-tutorial":`rules-recent`,children:(0,D.jsx)(sm,{triggers:g?.rows,ruleIndex:R,onJump:se,onChanged:oe})}),n&&(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(Qp,{perf:m}),(0,D.jsx)(im,{})]}),(0,D.jsx)(nm,{selected:B,onClear:()=>P(new Set),onApply:Oe}),xe.size>0&&(0,D.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] font-mono`,children:[(0,D.jsxs)(`button`,{onClick:Ee,className:`uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer`,children:[`select `,xe.size,` visible`]}),N.size>0&&(0,D.jsx)(`button`,{onClick:()=>P(new Set),className:`uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer`,children:`clear selection`})]}),ve.length===0&&(0,D.jsx)(`div`,{className:`rounded-sm border border-dashed border-[var(--color-line-1)] px-4 py-6 text-center text-[11px] font-mono text-[var(--color-fg-3)]`,children:`no rules match the current filter`}),(0,D.jsx)(`div`,{className:`space-y-3`,children:ve.map(e=>{let t=e.rules.some(e=>e.id===ne),r=e.rules.filter(e=>e.enabled).length,i=e.rules.length>0&&e.rules.every(e=>N.has(e.id)),a=!i&&e.rules.some(e=>N.has(e.id)),o=Kp(g?.rows,20,3600*1e3,t=>t.ruleId?e.rules.some(e=>e.id===t.ruleId):!1),s=o.some(e=>e>0);return(0,D.jsx)(K,{children:(0,D.jsxs)(`details`,{open:t||me||O!==`default`,children:[(0,D.jsxs)(`summary`,{className:`flex items-center gap-2 px-3 py-2 cursor-pointer list-none select-none hover:bg-[var(--color-surface-2)]/70 border-b border-[var(--color-line-0)]`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:i,ref:e=>{e&&(e.indeterminate=a)},onChange:()=>we(e.rules),onClick:e=>e.stopPropagation(),className:`accent-[var(--color-brand)] cursor-pointer`,"aria-label":`Select all rules in ${e.label}`}),e.kind===`category`?(0,D.jsx)(`span`,{"aria-hidden":!0,className:`shrink-0 text-xs`,children:e.icon}):(0,D.jsxs)(`svg`,{className:`text-[var(--color-fg-3)] shrink-0`,width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[(0,D.jsx)(`path`,{d:`M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z`}),(0,D.jsx)(`polyline`,{points:`14 2 14 8 20 8`})]}),(0,D.jsx)(`code`,{className:`text-xs text-[var(--color-fg-0)] font-mono`,style:e.accent?{color:e.accent}:void 0,children:e.label}),e.sublabel&&(0,D.jsx)(`span`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-4)] shrink-0`,children:e.sublabel}),s&&(0,D.jsx)(Js,{data:o,width:60,height:16,color:`var(--color-brand)`}),(0,D.jsxs)(`span`,{className:`ml-auto font-mono text-[11px] text-[var(--color-fg-3)] tabular-nums`,children:[r,(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)]`,children:[`/`,e.rules.length]})]})]}),(0,D.jsxs)(J,{className:`py-0`,children:[e.rules.length===0?(0,D.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)] py-3`,children:[`no rules in this `,e.kind]}):(0,D.jsx)(`div`,{className:`divide-y divide-[var(--color-line-0)]`,children:e.rules.map(e=>{let t=e.id===ne,r=N.has(e.id),i=L[e.id],a=F.has(e.id),o=i&&i.hits>0?Kp(g?.rows,20,3600*1e3,t=>t.ruleId===e.id):null;return(0,D.jsx)(`div`,{ref:t?ie:null,className:`py-2.5 ${t?`bg-amber-400/8 border-l-2 border-l-amber-400/60 -mx-3 px-3 -my-px`:r?`bg-sky-400/5`:``}`,children:(0,D.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,D.jsxs)(`div`,{className:`flex items-start gap-2 min-w-0 flex-1`,children:[(0,D.jsx)(`input`,{type:`checkbox`,checked:r,onChange:()=>Ce(e.id),className:`mt-1 accent-[var(--color-brand)] cursor-pointer`,"aria-label":`Select rule ${e.id}`}),(0,D.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 mb-1 flex-wrap`,children:[e.ambient?(0,D.jsx)(`span`,{className:`bg-[var(--color-surface-0)] border border-teal-500/40 rounded-sm px-1.5 py-0.5 text-[11px] font-mono uppercase tracking-wider text-teal-300`,title:`Ambient knowledge rule — carries always-on project context surfaced to the agent at session start. It never gates a tool call, so it has no decision.`,children:`ambient`}):(0,D.jsx)(`select`,{value:e.decision,onChange:async t=>{await Bp(e.id,e.file,t.target.value),oe()},className:`bg-[var(--color-surface-0)] border border-[var(--color-line-1)] rounded-sm px-1.5 py-0.5 text-[11px] font-mono uppercase tracking-wider cursor-pointer focus:outline-none focus:border-[var(--color-brand)]/50 ${Pp[e.decision]??`text-[var(--color-fg-2)]`}`,children:Np.map(e=>(0,D.jsx)(`option`,{value:e,children:e},e))}),(0,D.jsx)(Wr,{ruleId:e.id,children:(0,D.jsx)(`code`,{className:`text-xs font-mono text-[var(--color-fg-0)] break-all`,children:e.id})}),A===`file`&&e.category&&(0,D.jsx)(mm,{category:e.category,inferred:e.categoryInferred,onPick:Te}),n&&e.tags&&e.tags.length>0&&e.tags.slice(0,5).map(e=>(0,D.jsx)(`span`,{className:`text-[9px] font-mono px-1 py-px rounded-sm bg-[var(--color-surface-3)] text-[var(--color-fg-3)] shrink-0`,children:e},e)),o&&(0,D.jsx)(Js,{data:o,width:50,height:14,color:Fp[e.decision]??`#a8a29e`}),i&&i.hits>0&&(0,D.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)] tabular-nums`,children:[`·`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:i.hits}),` `,`hit`,i.hits===1?``:`s`,i.avgDurationMs>0&&(0,D.jsxs)(D.Fragment,{children:[` · `,(0,D.jsxs)(`span`,{className:i.avgDurationMs>50?`text-amber-300`:`text-[var(--color-fg-1)]`,children:[i.avgDurationMs.toFixed(1),`ms`]}),` `,`avg`]}),` · `,Gp(i.lastSeen)]}),(!i||i.hits===0)&&(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] uppercase tracking-wider`,children:`· never fired`}),n&&(0,D.jsx)(`button`,{onClick:()=>De(e.id),className:`ml-auto text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] cursor-pointer`,children:a?`hide audit`:`audit`})]}),(0,D.jsx)(`p`,{className:`text-xs text-[var(--color-fg-2)] truncate`,children:e.message}),n&&a&&(0,D.jsx)(rm,{ruleId:e.id})]})]}),(0,D.jsx)(Yp,{rule:e,file:e.file,onToggle:async()=>{await zp(e.id,e.file),oe()}})]})},e.id)})}),n&&e.content&&(0,D.jsxs)(`details`,{className:`mt-3 pb-3`,children:[(0,D.jsx)(`summary`,{className:`overline cursor-pointer hover:text-[var(--color-fg-1)] select-none`,children:`raw source`}),(0,D.jsx)(`pre`,{className:`mt-2 p-3 bg-[var(--color-surface-0)] border border-[var(--color-line-0)] rounded-sm text-[11px] text-[var(--color-fg-2)] overflow-x-auto whitespace-pre-wrap break-words font-mono`,children:e.content})]})]})]})},e.key)})})]})}var gm={allow:`#4ade80`,block:`#f87171`,ask:`#fbbf24`,force:`#a78bfa`,log:`#7dd3fc`,shadow:`#94a3b8`},_m=[`<1ms`,`1-10ms`,`10-100ms`,`100ms-1s`,`>1s`],vm=64;function ym(e){return e?new Date(e*1e3).toLocaleString():`—`}function bm(e){if(e<1)return`<1s`;if(e<60)return`${e}s`;if(e<3600)return`${Math.floor(e/60)}m ${e%60}s`;let t=Math.floor(e/3600),n=Math.floor(e%3600/60);return n>0?`${t}h ${n}m`:`${t}h`}function xm({title:e,hint:t,children:n}){return(0,D.jsxs)(`section`,{className:`flex flex-col rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] overflow-hidden`,children:[(0,D.jsxs)(`header`,{className:`flex items-center justify-between px-3 py-1.5 border-b border-[var(--color-line-1)] bg-black/30 shrink-0`,children:[(0,D.jsx)(`span`,{className:`overline text-[var(--color-fg-3)]`,children:e}),t&&(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:t})]}),(0,D.jsx)(`div`,{className:`p-3 flex flex-col gap-2 flex-1 min-h-0`,children:n})]})}function Sm({allowed:e,blocked:t,asked:n,forced:r}){let i=Math.max(0,e),a=Math.max(0,t),o=Math.max(0,n),s=Math.max(0,r),c=i+a+o+s;if(c===0)return(0,D.jsx)(`div`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`No evals recorded.`});let l=[{label:`allow`,value:i,color:gm.allow},{label:`block`,value:a,color:gm.block},{label:`ask`,value:o,color:gm.ask},{label:`force`,value:s,color:gm.force}].filter(e=>e.value>0),u=2*Math.PI*32,d=0;return(0,D.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,D.jsxs)(`svg`,{width:`92`,height:`92`,viewBox:`-46 -46 92 92`,className:`shrink-0`,children:[(0,D.jsx)(`circle`,{r:32,fill:`none`,stroke:`#222`,strokeWidth:`12`}),l.map(e=>{let t=e.value/c*u,n=(0,D.jsx)(`circle`,{r:32,fill:`none`,stroke:e.color,strokeWidth:`12`,strokeDasharray:`${t} ${u-t}`,strokeDashoffset:-d,transform:`rotate(-90)`},e.label);return d+=t,n}),(0,D.jsx)(`text`,{textAnchor:`middle`,dy:`0.35em`,fontSize:`14`,fontFamily:`ui-monospace, monospace`,fill:`var(--color-fg-1)`,children:c})]}),(0,D.jsx)(`ul`,{className:`flex-1 flex flex-col gap-1 text-[11px] font-mono`,children:l.map(e=>{let t=Math.round(e.value/c*1e3)/10;return(0,D.jsxs)(`li`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`size-2 rounded-sm shrink-0`,style:{background:e.color}}),(0,D.jsx)(`span`,{className:`uppercase tracking-wide text-[var(--color-fg-2)] w-12`,children:e.label}),(0,D.jsx)(`span`,{className:`tabular-nums text-[var(--color-fg-1)] font-semibold`,children:e.value}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)]`,children:[t,`%`]})]},e.label)})})]})}function Cm({rows:e,maxRows:t=10,emptyMessage:n}){if(e.length===0)return(0,D.jsx)(`div`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:n});let r=e.slice(0,t).map(e=>({...e,value:Math.max(0,e.value)})),i=Math.max(...r.map(e=>e.value),1);return(0,D.jsx)(`ul`,{className:`flex flex-col gap-1.5 text-[11px] font-mono`,children:r.map(e=>{let t=Math.max(2,e.value/i*100);return(0,D.jsxs)(`li`,{className:`flex flex-col gap-0.5`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between gap-2`,children:[(0,D.jsx)(`span`,{className:`truncate text-[var(--color-fg-2)]`,title:e.label,children:e.label}),(0,D.jsx)(`span`,{className:`tabular-nums text-[var(--color-fg-1)] font-semibold shrink-0`,children:e.value})]}),(0,D.jsx)(`div`,{className:`h-1 rounded-sm bg-white/5 overflow-hidden`,children:(0,D.jsx)(`div`,{className:`h-full bg-[var(--color-hig-blue)]/70`,style:{width:`${t}%`}})}),e.sublabel&&(0,D.jsx)(`span`,{className:`text-[10px] text-[var(--color-fg-4)] truncate`,title:e.sublabel,children:e.sublabel})]},e.label)})})}function wm({latency:e}){let t={};for(let n of e)t[n.bucket]=Math.max(0,n.hits);let n=Math.max(...Object.values(t),1);return Object.values(t).reduce((e,t)=>e+t,0)===0?(0,D.jsx)(`div`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`No latency data.`}):(0,D.jsx)(`div`,{className:`flex items-end gap-2`,children:_m.map(e=>{let r=t[e]??0,i=Math.round(r/n*vm);return(0,D.jsxs)(`div`,{className:`flex flex-1 min-w-0 flex-col items-center gap-1`,children:[(0,D.jsx)(`div`,{className:`flex w-full items-end`,style:{height:`${vm}px`},children:(0,D.jsx)(`div`,{className:`w-full rounded-sm bg-[var(--color-hig-blue)]/60`,style:{height:`${i}px`,minHeight:r>0?`4px`:`0px`},title:`${r} evals in ${e}`})}),(0,D.jsx)(`span`,{className:`w-full truncate text-center text-[10px] font-mono leading-tight text-[var(--color-fg-3)]`,title:e,children:e}),(0,D.jsx)(`span`,{className:`text-[10px] font-mono leading-tight text-[var(--color-fg-4)] tabular-nums`,children:r})]},e)})})}function Tm({sessionKey:e}){let[t,n]=(0,_.useState)(0),{data:r,loading:i,error:a}=k(`/api/json/sessions/detail?session_key=${encodeURIComponent(e)}&audit_limit=500`,[t]),o=V([`activity-updated`])[`activity-updated`]??0;(0,_.useEffect)(()=>{o>0&&r?.summary.is_active&&n(e=>e+1)},[o,r?.summary.is_active]);let s=(0,_.useMemo)(()=>{if(!r)return[];let e=r.tools.top.map(e=>({label:e.tool,value:Math.max(0,e.hits)}));return r.tools.other>0&&e.push({label:`(${r.tools.other} other)`,value:Math.max(0,r.tools.other)}),e},[r]),c=(0,_.useMemo)(()=>{if(!r)return[];if(r.rules.length>0)return r.rules.map(e=>({label:e.rule_id,sublabel:e.rule_message,value:Math.max(0,e.hits)}));let e=new Map;for(let t of r.audit){if(!t.rule_id)continue;let n=e.get(t.rule_id);n?n.hits+=1:e.set(t.rule_id,{message:t.rule_message,hits:1})}return[...e.entries()].map(([e,t])=>({label:e,sublabel:t.message,value:t.hits})).sort((e,t)=>t.value-e.value)},[r]);if(a)return(0,D.jsxs)(`div`,{className:`flex flex-col gap-3 p-4`,children:[(0,D.jsxs)(`header`,{children:[(0,D.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Session inspector`}),(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-3)] mt-1 font-mono`,children:e})]}),(0,D.jsxs)(`div`,{className:`rounded-sm border border-rose-500/30 bg-rose-500/5 p-4 text-[12px] font-mono text-rose-300`,children:[a.includes(`404`)?`No audit entries found for this session. It may have been pruned, or the URL is malformed.`:`Failed to load session: ${a}`,(0,D.jsx)(`div`,{className:`mt-2`,children:(0,D.jsx)(`a`,{href:`/sessions`,className:`text-[var(--color-hig-blue)] hover:underline`,children:`← Back to sessions`})})]})]});if(i&&!r)return(0,D.jsxs)(`div`,{className:`p-4 text-[12px] font-mono text-[var(--color-fg-3)]`,children:[`Loading session `,e,`…`]});if(!r)return null;let{summary:l,audit:u,latency:d}=r,f={...l,evals:Math.max(0,l.evals),allowed:Math.max(0,l.allowed),blocked:Math.max(0,l.blocked),asked:Math.max(0,l.asked),forced:Math.max(0,l.forced),duration_s:Math.max(0,l.duration_s)},p=f.evals>0?Math.round(f.blocked/f.evals*1e3)/10:0;return(0,D.jsxs)(`div`,{className:`flex flex-col gap-4 p-4 h-full min-h-0`,children:[(0,D.jsxs)(`header`,{className:`flex flex-col gap-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] font-mono text-[var(--color-fg-3)]`,children:[(0,D.jsx)(`a`,{href:`/sessions`,"data-tutorial":`sd-back`,className:`hover:underline`,children:`← Sessions`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`/`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] font-semibold`,children:f.agent_id})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-end justify-between gap-3`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsxs)(`h1`,{className:`text-lg font-semibold`,children:[f.client,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] font-mono text-[14px] ml-2`,children:f.agent_id})]}),(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)] mt-1 break-all`,children:f.session_id??`(no session_id — solo bucket)`})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 text-[11px] font-mono`,children:[(0,D.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 px-2 py-0.5 rounded-sm border ${f.is_active?`bg-emerald-500/10 border-emerald-500/30 text-emerald-300`:`bg-white/5 border-white/10 text-[var(--color-fg-3)]`}`,children:[(0,D.jsx)(`span`,{className:`size-1.5 rounded-full ${f.is_active?`bg-emerald-400 animate-pulse`:`bg-[var(--color-fg-4)]`}`}),f.is_active?`Live`:`Closed`]}),(0,D.jsx)(Em,{label:`Evals`,value:f.evals.toLocaleString()}),(0,D.jsx)(Em,{label:`Blocked`,value:f.blocked>0?`${f.blocked} (${p}%)`:`0`,color:f.blocked>0?`text-rose-300`:void 0}),(0,D.jsx)(Em,{label:`Asked`,value:f.asked.toLocaleString(),color:`text-amber-300`}),(0,D.jsx)(Em,{label:`Started`,value:ym(f.started_at)}),(0,D.jsx)(Em,{label:`Duration`,value:bm(f.duration_s)})]})]})]}),(0,D.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 xl:grid-cols-4 gap-3`,children:[(0,D.jsx)(xm,{title:`Decisions`,hint:`${f.evals} evals`,children:(0,D.jsx)(Sm,{allowed:f.allowed,blocked:f.blocked,asked:f.asked,forced:f.forced})}),(0,D.jsx)(xm,{title:`Top tools`,hint:`${r.tools.top.length+ +(r.tools.other>0)} buckets`,children:(0,D.jsx)(Cm,{rows:s,emptyMessage:`No tool activity.`})}),(0,D.jsx)(xm,{title:`Top rules`,hint:`${c.length} rule${c.length===1?``:`s`}`,children:(0,D.jsx)(Cm,{rows:c,emptyMessage:f.evals>0?`No rule matched any of the ${f.evals} tool call${f.evals===1?``:`s`} in this session — all allowed by the default policy.`:`No rule activity recorded for this session.`})}),(0,D.jsx)(xm,{title:`Latency`,hint:`duration buckets`,children:(0,D.jsx)(wm,{latency:d})})]}),(0,D.jsx)(`div`,{"data-tutorial":`sd-audit`,className:`flex-1 min-h-[400px]`,children:(0,D.jsx)(Cu,{sessionKey:e,entries:u,loading:i,error:null,playingIndex:-1})})]})}function Em({label:e,value:t,color:n}){return(0,D.jsxs)(`div`,{className:`flex flex-col`,children:[(0,D.jsx)(`span`,{className:`text-[10px] uppercase tracking-wide text-[var(--color-fg-4)]`,children:e}),(0,D.jsx)(`span`,{className:`tabular-nums ${n??`text-[var(--color-fg-1)]`}`,children:t})]})}var Dm=100,Om={"claude-code":`bg-orange-500/15 text-orange-300 border-orange-500/30`,cursor:`bg-sky-500/15 text-sky-300 border-sky-500/30`,copilot:`bg-emerald-500/15 text-emerald-300 border-emerald-500/30`,gemini:`bg-blue-500/15 text-blue-300 border-blue-500/30`,antigravity:`bg-purple-500/15 text-purple-300 border-purple-500/30`,codex:`bg-pink-500/15 text-pink-300 border-pink-500/30`,pi:`bg-amber-500/15 text-amber-300 border-amber-500/30`,generic:`bg-slate-500/15 text-slate-300 border-slate-500/30`};function km(e){if(!e)return`—`;let t=new Date(e*1e3),n=new Date,r=t.toLocaleTimeString(`en-US`,{hour:`2-digit`,minute:`2-digit`,hour12:!1});if(t.toDateString()===n.toDateString())return`Today ${r}`;let i=new Date(n);return i.setDate(i.getDate()-1),t.toDateString()===i.toDateString()?`Yesterday ${r}`:`${t.toLocaleDateString(`en-US`,{month:`short`,day:`numeric`})} ${r}`}function Am(e){if(e<1)return`—`;if(e<60)return`${e}s`;if(e<3600)return`${Math.floor(e/60)}m`;let t=Math.floor(e/3600),n=Math.floor(e%3600/60);return n>0?`${t}h ${n}m`:`${t}h`}function jm({client:e}){return(0,D.jsx)(`span`,{className:`inline-flex items-center rounded-sm border px-1.5 py-0.5 text-[10px] font-mono uppercase tracking-wide ${Om[e]??`bg-white/5 text-[var(--color-fg-3)] border-white/10`}`,children:e})}function Mm({onOpenSession:e}={}){let{activeProject:t}=Be(),[n,r]=(0,_.useState)(0),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(0);(0,_.useEffect)(()=>{r(0)},[t]);let{data:c,loading:l,error:u,refetch:d}=k(Ve(`/api/json/sessions/list?limit=${Dm}&offset=${n}`,t),[o,t]),f=V([`activity-updated`])[`activity-updated`]??0;(0,_.useEffect)(()=>{f>0&&s(e=>e+1)},[f]);let p=c?.sessions??[],m=c?.total??0,h=(0,_.useMemo)(()=>{if(!i.trim())return p;let e=i.toLowerCase();return p.filter(t=>t.session_key.toLowerCase().includes(e)||t.client.toLowerCase().includes(e)||(t.top_tool??``).toLowerCase().includes(e)||(t.top_rule??``).toLowerCase().includes(e))},[p,i]),g=p.filter(e=>e.is_active).length,v=p.reduce((e,t)=>e+Math.max(0,t.evals),0),y=p.reduce((e,t)=>e+Math.max(0,t.blocked),0),b=v>0?Math.round(y/v*1e3)/10:0;return(0,D.jsxs)(`div`,{className:`flex flex-col gap-4 p-4`,children:[(0,D.jsxs)(`header`,{className:`flex flex-col gap-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h1`,{className:`text-lg font-semibold`,children:`Sessions`}),(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-3)] mt-1`,children:`Every AI agent session recorded by the daemon. Click a row to open its inspector — graph, charts, and full audit log.`})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-3 text-[11px] font-mono text-[var(--color-fg-3)]`,children:[(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] font-semibold`,children:m.toLocaleString()}),` `,`total`]}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`span`,{className:`text-emerald-300 font-semibold`,children:g}),` `,`active`]}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsxs)(`span`,{children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)] font-semibold`,children:v.toLocaleString()}),` `,`evals on page`]}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsxs)(`span`,{children:[(0,D.jsxs)(`span`,{className:b>0?`text-rose-300 font-semibold`:`text-emerald-300`,children:[b,`%`]}),` `,`blocked`]})]})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`input`,{"data-tutorial":`sessions-filter`,type:`search`,value:i,onChange:e=>a(e.target.value),placeholder:`Filter by client, session, tool, or rule…`,className:`flex-1 bg-[var(--color-surface-1)] border border-[var(--color-line-1)] rounded-sm px-3 py-1.5 text-[12px] font-mono focus:outline-none focus:ring-1 focus:ring-[var(--color-hig-blue)]`}),(0,D.jsx)(`button`,{"data-tutorial":`sessions-refresh`,type:`button`,onClick:()=>d(),className:`px-3 py-1.5 text-[11px] font-mono uppercase tracking-wide border border-[var(--color-line-1)] rounded-sm hover:bg-white/5`,children:`Refresh`})]})]}),(0,D.jsx)(`div`,{className:`border border-[var(--color-line-1)] rounded-sm overflow-hidden`,children:(0,D.jsx)(`div`,{className:`overflow-x-auto`,children:(0,D.jsxs)(`table`,{"data-tutorial":`sessions-table`,className:`w-full text-[12px] font-mono`,children:[(0,D.jsx)(`thead`,{className:`bg-black/30 text-[var(--color-fg-3)] uppercase tracking-wide text-[10px]`,children:(0,D.jsxs)(`tr`,{children:[(0,D.jsx)(`th`,{className:`text-left px-3 py-2`,children:`Status`}),(0,D.jsx)(`th`,{className:`text-left px-3 py-2`,children:`Client`}),(0,D.jsx)(`th`,{className:`text-left px-3 py-2`,children:`Session`}),(0,D.jsx)(`th`,{className:`text-left px-3 py-2`,children:`Started`}),(0,D.jsx)(`th`,{className:`text-left px-3 py-2`,children:`Duration`}),(0,D.jsx)(`th`,{className:`text-right px-3 py-2`,children:`Evals`}),(0,D.jsx)(`th`,{className:`text-right px-3 py-2 text-emerald-300/80`,children:`Allowed`}),(0,D.jsx)(`th`,{className:`text-right px-3 py-2 text-rose-300/80`,children:`Blocked`}),(0,D.jsx)(`th`,{className:`text-right px-3 py-2 text-amber-300/80`,children:`Asked`}),(0,D.jsx)(`th`,{className:`text-left px-3 py-2`,children:`Top Tool`}),(0,D.jsx)(`th`,{className:`text-left px-3 py-2`,children:`Top Rule`})]})}),(0,D.jsxs)(`tbody`,{className:`divide-y divide-[var(--color-line-1)]/40`,children:[l&&h.length===0&&(0,D.jsx)(`tr`,{children:(0,D.jsx)(`td`,{colSpan:11,className:`px-3 py-6 text-center text-[var(--color-fg-4)]`,children:`Loading sessions…`})}),u&&(0,D.jsx)(`tr`,{children:(0,D.jsxs)(`td`,{colSpan:11,className:`px-3 py-6 text-center text-rose-300`,children:[`Failed to load sessions: `,u]})}),!l&&!u&&h.length===0&&(0,D.jsx)(`tr`,{children:(0,D.jsx)(`td`,{colSpan:11,className:`px-3 py-6 text-center text-[var(--color-fg-4)]`,children:p.length===0?`No sessions recorded yet.`:`No sessions match "${i}".`})}),h.map(t=>{let n={...t,evals:Math.max(0,t.evals),allowed:Math.max(0,t.allowed),blocked:Math.max(0,t.blocked),asked:Math.max(0,t.asked),forced:Math.max(0,t.forced),duration_s:Math.max(0,t.duration_s)},r=n.evals>0?Math.round(n.blocked/n.evals*1e3)/10:0;return(0,D.jsxs)(`tr`,{className:`hover:bg-white/[0.03] cursor-pointer`,children:[(0,D.jsx)(`td`,{className:`px-3 py-2`,children:(0,D.jsx)(`a`,{href:`/sessions/${encodeURIComponent(n.session_key)}`,className:`flex items-center gap-1.5 no-underline`,onClick:t=>{e&&(t.preventDefault(),e(n.session_key,n.agent_id))},children:n.is_active?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{className:`size-1.5 rounded-full bg-emerald-400 animate-pulse`}),(0,D.jsx)(`span`,{className:`text-emerald-300 text-[10px] uppercase tracking-wide`,children:`Live`})]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{className:`size-1.5 rounded-full bg-[var(--color-fg-4)]`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)] text-[10px] uppercase tracking-wide`,children:`Closed`})]})})}),(0,D.jsx)(`td`,{className:`px-3 py-2`,children:(0,D.jsx)(jm,{client:n.client})}),(0,D.jsx)(`td`,{className:`px-3 py-2`,children:(0,D.jsx)(`a`,{href:`/sessions/${encodeURIComponent(n.session_key)}`,className:`text-[var(--color-fg-1)] hover:text-[var(--color-hig-blue)] hover:underline`,onClick:t=>{e&&(t.preventDefault(),e(n.session_key,n.agent_id))},children:n.agent_id})}),(0,D.jsx)(`td`,{className:`px-3 py-2 text-[var(--color-fg-3)]`,children:km(n.started_at)}),(0,D.jsx)(`td`,{className:`px-3 py-2 text-[var(--color-fg-3)]`,children:Am(n.duration_s)}),(0,D.jsx)(`td`,{className:`px-3 py-2 text-right font-semibold`,children:n.evals.toLocaleString()}),(0,D.jsx)(`td`,{className:`px-3 py-2 text-right text-emerald-300`,children:n.allowed.toLocaleString()}),(0,D.jsx)(`td`,{className:`px-3 py-2 text-right`,children:n.blocked>0?(0,D.jsxs)(`span`,{className:`text-rose-300`,children:[n.blocked.toLocaleString(),r>0&&(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-4)] ml-1 text-[10px]`,children:[`(`,r,`%)`]})]}):(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`0`})}),(0,D.jsx)(`td`,{className:`px-3 py-2 text-right text-amber-300`,children:n.asked>0?n.asked.toLocaleString():(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`0`})}),(0,D.jsx)(`td`,{className:`px-3 py-2 text-[var(--color-fg-2)] max-w-[180px] truncate`,children:n.top_tool??(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`—`})}),(0,D.jsx)(`td`,{className:`px-3 py-2 text-[var(--color-fg-2)] max-w-[200px] truncate`,children:n.top_rule??(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`—`})})]},n.session_key)})]})]})})}),m>Dm&&(0,D.jsxs)(`footer`,{className:`flex items-center justify-between text-[11px] font-mono text-[var(--color-fg-3)]`,children:[(0,D.jsxs)(`span`,{children:[n+1,`–`,Math.min(n+Dm,m),` of`,` `,m.toLocaleString()]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`button`,{type:`button`,disabled:n===0,onClick:()=>r(Math.max(0,n-Dm)),className:`px-3 py-1 border border-[var(--color-line-1)] rounded-sm disabled:opacity-30 hover:bg-white/5`,children:`← Prev`}),(0,D.jsx)(`button`,{type:`button`,disabled:n+Dm>=m,onClick:()=>r(n+Dm),className:`px-3 py-1 border border-[var(--color-line-1)] rounded-sm disabled:opacity-30 hover:bg-white/5`,children:`Next →`})]})]})]})}function Nm(e){return`ssg:session-subtabs:${e}`}function Pm(e){try{let t=localStorage.getItem(Nm(e));if(!t)return[];let n=JSON.parse(t);return Array.isArray(n)?n.filter(e=>typeof e==`object`&&!!e&&typeof e.key==`string`&&typeof e.label==`string`):[]}catch{return[]}}function Fm(e){return`shrink-0 rounded-sm border px-2.5 py-1 text-[11px] font-mono transition-colors ${e?`border-[var(--color-hig-blue)]/50 bg-[var(--color-hig-blue)]/15 text-[var(--color-fg-1)]`:`border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:bg-white/5`}`}function Im(){let{activeProject:e}=Be(),[t,n]=(0,_.useState)([]),[r,i]=(0,_.useState)(null);(0,_.useEffect)(()=>{n(Pm(e)),i(null)},[e]);let a=(0,_.useCallback)(t=>{try{localStorage.setItem(Nm(e),JSON.stringify(t))}catch{}},[e]),o=(0,_.useCallback)((e,t)=>{n(n=>{let r=n.some(t=>t.key===e)?n:[...n,{key:e,label:t}];return a(r),r}),i(e)},[a]),s=(0,_.useCallback)(e=>{n(t=>{let n=t.findIndex(t=>t.key===e),r=t.filter(t=>t.key!==e);return a(r),i(t=>t===e?r.length===0?null:r[Math.max(0,n-1)].key:t),r})},[a]);return(0,D.jsxs)(`div`,{className:`flex flex-col`,children:[t.length>0&&(0,D.jsxs)(`div`,{className:`flex items-center gap-1.5 overflow-x-auto border-b border-[var(--color-line-1)] px-4 py-1.5`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:()=>i(null),className:Fm(r===null),children:`Sessions list`}),t.map(e=>(0,D.jsxs)(`span`,{className:`group inline-flex items-center gap-1.5 ${Fm(r===e.key)}`,children:[(0,D.jsx)(`button`,{type:`button`,onClick:()=>i(e.key),className:`max-w-[160px] truncate`,children:e.label}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>s(e.key),"aria-label":`Close ${e.label}`,className:`text-[var(--color-fg-4)] hover:text-rose-300`,children:`×`})]},e.key))]}),r===null?(0,D.jsx)(Mm,{onOpenSession:o}):(0,D.jsx)(Tm,{sessionKey:r})]})}function Lm({status:e,className:t=``}){return(0,D.jsx)(`span`,{className:`status-dot ${e===`ok`?`bg-[var(--color-decision-allow)]`:e===`warn`?`bg-[var(--color-decision-ask)]`:e===`fail`?`bg-[var(--color-decision-block)]`:`bg-[var(--color-fg-3)]`} ${t}`})}function Rm({status:e}){let t=e===`ok`?`text-[var(--color-decision-allow)]`:e===`warn`?`text-[var(--color-decision-ask)]`:e===`fail`?`text-[var(--color-decision-block)]`:`text-[var(--color-fg-3)]`,n=e===`ok`?`OK`:e===`warn`?`Warn`:e===`fail`?`Fail`:`Skipped`;return(0,D.jsx)(`span`,{className:`text-[10.5px] font-medium uppercase tracking-wide ${t}`,children:n})}function zm(e){return e===void 0?``:e<1024?`${e} B`:e<1024*1024?`${(e/1024).toFixed(1)} KB`:`${(e/1024/1024).toFixed(1)} MB`}function Bm(e){if(!e)return``;let t=Math.floor((Date.now()-e)/1e3);return t<60?`${t}s ago`:t<3600?`${Math.floor(t/60)}m ago`:t<86400?`${Math.floor(t/3600)}h ago`:`${Math.floor(t/86400)}d ago`}function Vm(e,t){return t&&e.startsWith(`${t}/`)?`~/${e.slice(t.length+1)}`:e===t?`~`:e}function Hm({file:e,home:t,wired:n}){return(0,D.jsxs)(`div`,{className:`flex items-center gap-2 py-1 border-b border-[var(--color-line-0)] last:border-0 text-[11.5px]`,children:[(0,D.jsx)(Lm,{status:e.exists?n===void 0||n?`ok`:`warn`:`skip`}),(0,D.jsx)(`code`,{className:`flex-1 truncate text-[var(--color-fg-1)]`,title:e.path,children:Vm(e.path,t)}),e.exists?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`span`,{className:`text-[10.5px] text-[var(--color-fg-3)]`,children:zm(e.size)}),(0,D.jsx)(`span`,{className:`text-[10.5px] text-[var(--color-fg-3)] min-w-[60px] text-right`,children:Bm(e.modified_at)}),n===!1&&(0,D.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-[var(--color-decision-ask)]`,title:`File exists but does not appear to contain SSG wiring`,children:`no ssg`}),n===!0&&(0,D.jsx)(`span`,{className:`text-[10px] font-medium uppercase tracking-wide text-[var(--color-decision-allow)]`,title:`File contains SSG hook / MCP entries`,children:`wired`})]}):(0,D.jsx)(`span`,{className:`text-[10.5px] text-[var(--color-fg-3)]`,children:`missing`})]})}function Um({title:e,status:t,children:n,hint:r}){return(0,D.jsxs)(`section`,{className:`hig-card hig-card-padded`,children:[(0,D.jsxs)(`header`,{className:`flex items-center justify-between mb-3`,children:[(0,D.jsxs)(`h2`,{className:`text-[13px] font-semibold text-[var(--color-fg-0)] flex items-center gap-2`,children:[t!==void 0&&(0,D.jsx)(Lm,{status:t}),e]}),r&&(0,D.jsx)(`span`,{className:`text-[10.5px] text-[var(--color-fg-3)]`,children:r})]}),(0,D.jsx)(`div`,{children:n})]})}function Wm({k:e,v:t,mono:n=!1}){return(0,D.jsxs)(`div`,{className:`flex items-baseline gap-3 py-1 text-[11.5px] border-b border-[var(--color-line-0)] last:border-0`,children:[(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)] min-w-[110px]`,children:e}),(0,D.jsx)(`span`,{className:`flex-1 text-[var(--color-fg-1)] ${n?`font-mono text-[11px]`:``}`,children:t})]})}var Gm={"claude-code":`Claude Code`,cursor:`Cursor`,codex:`Codex CLI`,pi:`Pi Agent`,gemini:`Gemini CLI`,antigravity:`Antigravity`,copilot:`GitHub Copilot`};function Km({adapter:e,home:t}){let n=Gm[e.id]??e.id,r=e.artifacts.filter(e=>e.exists&&e.ssg_wired).length,i=e.artifacts.filter(e=>e.exists).length;return(0,D.jsxs)(`div`,{className:`rounded-md border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(Lm,{status:e.status}),(0,D.jsx)(`span`,{className:`text-[12.5px] font-semibold text-[var(--color-fg-0)]`,children:n}),e.active&&(0,D.jsx)(`span`,{className:`text-[9.5px] font-semibold uppercase tracking-wider px-1.5 py-0.5 rounded-sm text-[var(--color-hig-blue)] bg-[color-mix(in_oklab,var(--color-hig-blue)_14%,transparent)]`,title:`This is the adapter ssg is currently using at runtime`,children:`Active`})]}),(0,D.jsxs)(`span`,{className:`text-[10px] text-[var(--color-fg-3)]`,children:[r,`/`,e.artifacts.length,` wired`]})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap gap-2 mb-2 text-[10.5px]`,children:[(0,D.jsx)(`span`,{className:e.detected?`text-[var(--color-decision-allow)]`:`text-[var(--color-fg-3)]`,children:e.detected?`● detected`:`○ not detected`}),(0,D.jsx)(`span`,{className:e.healthy?`text-[var(--color-decision-allow)]`:`text-[var(--color-fg-3)]`,children:e.healthy?`● binary healthy`:`○ binary missing`}),i===0&&(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)]`,children:`○ no config files on disk`})]}),e.artifacts.length>0&&(0,D.jsx)(`div`,{className:`border-t border-[var(--color-line-0)] pt-1`,children:e.artifacts.map(e=>(0,D.jsx)(Hm,{file:e,home:t,wired:e.exists?e.ssg_wired:void 0},e.path))}),e.status===`warn`&&i===0&&(0,D.jsxs)(`div`,{className:`mt-2 text-[10.5px] text-[var(--color-fg-3)]`,children:[`Wire it up with:`,` `,(0,D.jsxs)(`code`,{className:`font-mono text-[var(--color-fg-1)]`,children:[`ssg init --client=`,e.id]})]})]})}function qm(){let{data:e,loading:t,error:n,refetch:r}=k(`/api/json/setup-status`);if(t&&!e)return(0,D.jsx)(`div`,{className:`py-12 text-center text-[var(--color-fg-3)] text-[12px]`,children:`Reading setup status…`});if(n||!e)return(0,D.jsxs)(`div`,{className:`hig-card hig-card-padded text-[12px]`,children:[(0,D.jsxs)(`p`,{className:`text-[var(--color-decision-block)] mb-2`,children:[`Could not load /api/json/setup-status: `,n??`no response`]}),(0,D.jsx)(`button`,{onClick:r,className:`hig-button hig-button-small`,children:`Retry`})]});let{summary:i,license:a,daemon:o,dashboard:s,native:c,db:l,mcp:u,rules:d,init_files:f,adapters:p,hub:m,checks:h,home:g,cwd:_}=e;return(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{className:`flex items-end justify-between`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h1`,{className:`text-[20px] font-semibold tracking-tight text-[var(--color-fg-0)] leading-tight`,children:`Setup Status`}),(0,D.jsxs)(`p`,{className:`text-[12.5px] text-[var(--color-fg-3)] mt-1 leading-relaxed`,children:[`What `,(0,D.jsx)(`code`,{className:`font-mono`,children:`ssg init`}),` wrote and whether every piece is wired up — license, hooks, MCP, native engine, daemon, rules, and hub packages.`]})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,D.jsxs)(`span`,{className:`text-[11px] text-[var(--color-fg-3)]`,children:[`ssg v`,e.version]}),(0,D.jsx)(`button`,{onClick:r,className:`hig-button hig-button-small`,children:`Refresh`})]})]}),(0,D.jsxs)(`section`,{"data-tutorial":`setup-summary`,className:`hig-card hig-card-padded flex items-center gap-6`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(Lm,{status:i.overall,className:`!w-3 !h-3`}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`text-[11px] uppercase tracking-wide text-[var(--color-fg-3)]`,children:`Overall`}),(0,D.jsx)(`div`,{className:`text-[14px] font-semibold text-[var(--color-fg-0)]`,children:i.overall===`ok`?`Healthy`:i.overall===`warn`?`Needs attention`:i.overall===`fail`?`Broken`:`Skipped`})]})]}),(0,D.jsxs)(`div`,{className:`flex gap-4 text-[12px]`,children:[(0,D.jsxs)(`span`,{className:`text-[var(--color-decision-allow)]`,children:[`● `,i.ok,` ok`]}),(0,D.jsxs)(`span`,{className:`text-[var(--color-decision-ask)]`,children:[`● `,i.warn,` warn`]}),i.fail>0&&(0,D.jsxs)(`span`,{className:`text-[var(--color-decision-block)]`,children:[`● `,i.fail,` fail`]}),(0,D.jsxs)(`span`,{className:`text-[var(--color-fg-3)]`,children:[`○ `,i.skip,` skipped`]})]}),(0,D.jsxs)(`div`,{className:`ml-auto text-right`,children:[(0,D.jsx)(`div`,{className:`text-[10.5px] uppercase tracking-wide text-[var(--color-fg-3)]`,children:`Working dir`}),(0,D.jsx)(`code`,{className:`text-[11px] text-[var(--color-fg-1)]`,title:_,children:Vm(_,g)})]})]}),(0,D.jsx)(Um,{title:`Checks`,hint:`${h.length} probes`,children:(0,D.jsx)(`div`,{children:h.map(e=>(0,D.jsxs)(`div`,{className:`flex items-start gap-3 py-1.5 border-b border-[var(--color-line-0)] last:border-0`,children:[(0,D.jsx)(Lm,{status:e.status,className:`mt-1`}),(0,D.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,D.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,D.jsx)(`span`,{className:`text-[12px] font-medium text-[var(--color-fg-0)]`,children:e.name}),(0,D.jsx)(Rm,{status:e.status})]}),(0,D.jsx)(`div`,{className:`text-[11px] text-[var(--color-fg-2)] mt-0.5 break-words`,children:e.detail}),e.fix&&(0,D.jsxs)(`div`,{className:`text-[11px] text-[var(--color-hig-blue)] font-mono mt-0.5`,children:[`→ `,e.fix]})]})]},e.name))})}),(0,D.jsxs)(Um,{title:`License & authentication`,status:a.status===`healthy`||a.status===`healthy_free`?`ok`:`warn`,children:[(0,D.jsx)(Wm,{k:`Tier`,v:a.tier_label}),(0,D.jsx)(Wm,{k:`Status`,v:a.status}),(0,D.jsx)(Wm,{k:`Account`,v:a.email??`—`}),(0,D.jsx)(Wm,{k:`Auth method`,v:a.auth_method??`—`}),(0,D.jsx)(Wm,{k:`Evals today`,v:a.eval_daily_limit===null?`${a.evals_today.toLocaleString()} (unlimited)`:`${a.evals_today.toLocaleString()} / ${a.eval_daily_limit.toLocaleString()}`}),(0,D.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-[var(--color-line-0)]`,children:[(0,D.jsx)(`div`,{className:`text-[10.5px] uppercase tracking-wide text-[var(--color-fg-3)] mb-1`,children:`Credential files`}),(0,D.jsx)(Hm,{file:a.license_file,home:g}),(0,D.jsx)(Hm,{file:a.hosts_file,home:g})]})]}),(0,D.jsxs)(Um,{title:`Runtime processes`,status:o.alive&&s.alive?`ok`:`warn`,children:[(0,D.jsx)(Wm,{k:`Daemon (evald)`,v:o.alive?`running — PID ${o.pid}`:o.pid?`stale — PID ${o.pid} in pidfile but process gone`:`not running`}),(0,D.jsx)(Wm,{k:`Daemon socket`,v:o.socket_exists?`present`:`missing`,mono:!0}),(0,D.jsx)(Wm,{k:`Dashboard (serve)`,v:s.alive?`running — PID ${s.pid}`:`not running`}),(0,D.jsx)(Wm,{k:`Native engine`,v:c.available?`loaded — sub-ms eval available`:`unavailable — TypeScript fallback`})]}),(0,D.jsxs)(Um,{title:`Database & MCP`,status:l.status,children:[(0,D.jsx)(Wm,{k:`Rules in DB`,v:l.rules.toLocaleString()}),(0,D.jsx)(Wm,{k:`Audit log rows`,v:l.audit_rows.toLocaleString()}),(0,D.jsx)(Wm,{k:`DB path`,v:Vm(l.path,g),mono:!0}),(0,D.jsxs)(`div`,{className:`mt-2 pt-2 border-t border-[var(--color-line-0)]`,children:[(0,D.jsx)(`div`,{className:`text-[10.5px] uppercase tracking-wide text-[var(--color-fg-3)] mb-1`,children:`MCP server`}),(0,D.jsx)(Wm,{k:`Status`,v:u.status===`active`?`active — ${u.recent_5min.toLocaleString()} calls in last 5 min`:u.status===`configured`?`configured — ${u.total.toLocaleString()} historical calls, none recent`:`no MCP traffic recorded yet`}),(0,D.jsx)(Wm,{k:`All-time calls`,v:u.total.toLocaleString()})]})]}),(0,D.jsxs)(Um,{title:`Rules directories`,status:d.local_count>0?`ok`:`warn`,children:[(0,D.jsx)(Wm,{k:`Local`,v:`${d.local_count} .rules file${d.local_count===1?``:`s`}`}),(0,D.jsx)(Wm,{k:`Local path`,v:Vm(d.local_dir,g),mono:!0}),(0,D.jsx)(Wm,{k:`Global`,v:`${d.global_count} .rules file${d.global_count===1?``:`s`}`}),(0,D.jsx)(Wm,{k:`Global path`,v:Vm(d.global_dir,g),mono:!0})]}),(0,D.jsx)(Um,{title:`Project init files`,hint:`${f.filter(e=>e.exists).length}/${f.length} present`,children:(0,D.jsx)(`div`,{children:f.map(e=>(0,D.jsx)(Hm,{file:e,home:g},e.path))})}),(0,D.jsx)(Um,{title:`Adapters, hooks & MCP files`,hint:e.active_adapter?`Active: ${Gm[e.active_adapter]??e.active_adapter}`:`No active adapter`,children:(0,D.jsx)(`div`,{className:`grid gap-3 sm:grid-cols-1 lg:grid-cols-2`,children:p.map(e=>(0,D.jsx)(Km,{adapter:e,home:g},e.id))})}),(0,D.jsxs)(Um,{title:`Hub-installed rulesets`,status:m.installs.length===0?`skip`:m.drift===0?`ok`:`warn`,hint:m.installs.length===0?`none installed`:`${m.in_sync} in sync${m.drift>0?`, ${m.drift} drift`:``}`,children:[(0,D.jsx)(Hm,{file:m.pins_file,home:g}),m.installs.length===0?(0,D.jsxs)(`p`,{className:`text-[11.5px] text-[var(--color-fg-3)] mt-2`,children:[`Install rulesets from the Hub tab. Each install is recorded per project path in `,(0,D.jsx)(`code`,{className:`font-mono`,children:`hub-pins.json`}),`.`]}):(0,D.jsx)(`div`,{className:`mt-2 space-y-2`,children:m.installs.map((e,t)=>(0,D.jsxs)(`div`,{className:`rounded-md border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-2 text-[11.5px]`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2 mb-1`,children:[(0,D.jsx)(Lm,{status:e.in_sync?`ok`:`warn`}),(0,D.jsx)(`span`,{className:`font-semibold text-[var(--color-fg-0)]`,children:e.id}),(0,D.jsx)(`span`,{className:`text-[10.5px] text-[var(--color-fg-3)]`,children:e.version}),(0,D.jsx)(`span`,{className:`ml-auto text-[10.5px] text-[var(--color-fg-3)]`,children:Bm(e.installed_at)})]}),(0,D.jsx)(`code`,{className:`block truncate text-[11px] text-[var(--color-fg-2)]`,title:e.path,children:Vm(e.path,g)}),e.files.length>0&&(0,D.jsx)(`div`,{className:`mt-1 flex flex-wrap gap-1`,children:e.files.map(e=>(0,D.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-2)] bg-[var(--color-surface-2)] border border-[var(--color-line-0)] rounded-sm px-1.5 py-0.5`,children:e},e))}),!e.in_sync&&e.drift_reason&&(0,D.jsxs)(`div`,{className:`mt-1 text-[10.5px] text-[var(--color-decision-ask)]`,children:[`Drift: `,e.drift_reason]})]},`${e.id}-${e.path}-${t}`))})]})]})}var Jm=[{id:`files`,label:`Files & folders`,blurb:`Deleting or changing things on your hard drive`},{id:`secrets`,label:`Secrets & keys`,blurb:`Reading or overwriting credentials and private files`},{id:`network`,label:`Network calls`,blurb:`Reaching out to websites and external APIs`},{id:`install`,label:`Installing software`,blurb:`Pulling new code or packages from the internet`},{id:`communication`,label:`Sending messages`,blurb:`Outgoing emails, posts, or chat messages`}],Ym=[{id:`erase-folder`,label:`AI tries to erase a folder`,plainEffect:`Permanently deletes every file inside the "output" folder. Recovery is hard.`,category:`files`,emoji:`🗑️`,toolCall:{tool:`Bash`,input:{command:`find ./output -type f -delete`}},displayByOs:{windows:`Remove-Item .\\output -Recurse -Force`,macos:`find ./output -type f -delete`,linux:`find ./output -type f -delete`}},{id:`write-env`,label:`AI tries to write your .env file`,plainEffect:`Overwrites the file that holds your API keys, passwords, and other secrets.`,category:`secrets`,emoji:`⚠️`,toolCall:{tool:`Write`,input:{file_path:`.env`,content:`API_KEY=test`}}},{id:`read-ssh-key`,label:`AI tries to read your private key`,plainEffect:`Opens the SSH key that proves you are you on remote servers. Copying it is identity theft.`,category:`secrets`,emoji:`🔑`,toolCall:{tool:`Read`,input:{file_path:`~/.ssh/id_rsa`}},displayByOs:{windows:`Read C:\\Users\\You\\.ssh\\id_rsa`,macos:`Read ~/.ssh/id_rsa`,linux:`Read ~/.ssh/id_rsa`}},{id:`install-package`,label:`AI tries to install a package`,plainEffect:`Downloads code from a public registry and adds it to your project. The code runs with your permissions.`,category:`install`,emoji:`📦`,toolCall:{tool:`Bash`,input:{command:`npm install some-package --save`}}},{id:`fetch-web`,label:`AI tries to fetch a URL`,plainEffect:`Makes a web request to an outside service. Could leak data or pull in instructions.`,category:`network`,emoji:`🌐`,toolCall:{tool:`WebFetch`,input:{url:`https://api.example.com/data`,prompt:``}}},{id:`send-email`,label:`AI tries to send an email`,plainEffect:`Sends an email from your machine without your review. Anyone could end up CC’d.`,category:`communication`,emoji:`📧`,toolCall:{tool:`Bash`,input:{command:`sendmail -t < message.txt`}},displayByOs:{windows:`Send-MailMessage -To you@example.com -Subject "..." -Body (Get-Content message.txt)`,macos:`sendmail -t < message.txt`,linux:`sendmail -t < message.txt`}}],Xm=`ssg.tryit.intro-dismissed.v1`,Zm=`ssg.tryit.os.v1`,Qm={allow:{label:`Allowed`,color:`text-emerald-300`,bg:`border-emerald-500/30 bg-emerald-500/5`,icon:`✓`,headline:`SSG would let this happen.`,next:`In real life, the AI would go ahead. If you would rather it didn’t, add a rule on the Rules page.`},block:{label:`Blocked`,color:`text-red-300`,bg:`border-red-500/30 bg-red-500/5`,icon:`✕`,headline:`SSG would stop this from running.`,next:`The AI never gets to perform the action. No files change, no commands run, no requests go out.`},ask:{label:`Ask first`,color:`text-amber-300`,bg:`border-amber-500/30 bg-amber-500/5`,icon:`?`,headline:`SSG would pause and ask you first.`,next:`You’d get a prompt on the Approvals page. Nothing happens until you click Allow or Deny.`},log:{label:`Logged`,color:`text-sky-300`,bg:`border-sky-500/30 bg-sky-500/5`,icon:`≡`,headline:`SSG would allow it but write it down.`,next:`The AI proceeds, and the action gets recorded in your Activity log for later review.`},force:{label:`Force-allow`,color:`text-violet-300`,bg:`border-violet-500/30 bg-violet-500/5`,icon:`→`,headline:`A high-priority rule explicitly allows this.`,next:`A “force” rule overrides anything that would have blocked or paused this action.`}};function $m(){if(typeof window>`u`)return`linux`;try{let e=window.localStorage.getItem(Zm);if(e===`windows`||e===`macos`||e===`linux`)return e}catch{}let e=navigator.userAgent.toLowerCase();return e.includes(`win`)?`windows`:e.includes(`mac`)?`macos`:`linux`}function eh(e){return e===`windows`?`Windows`:e===`macos`?`Mac`:`Linux`}function th(e){return e===`windows`?`⊞`:e===`macos`?`🍎`:`🐧`}function nh(e,t){let n=e.displayByOs?.[t];if(n)return n;let r=e.toolCall;return r.input.command?r.input.command:r.input.file_path?r.input.file_path:r.input.url?r.input.url:JSON.stringify(r.input)}function rh({n:e,label:t}){return(0,D.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,D.jsx)(`span`,{className:`flex items-center justify-center w-5 h-5 rounded-full bg-[var(--color-brand)]/15 text-[var(--color-brand)] text-[10px] font-semibold shrink-0`,children:e}),(0,D.jsx)(`span`,{className:`text-[11.5px] text-[var(--color-fg-2)] truncate`,children:t})]})}function ih({os:e,setOs:t}){return(0,D.jsx)(`div`,{className:`inline-flex items-center gap-1 rounded-full border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-0.5`,children:[`windows`,`macos`,`linux`].map(n=>(0,D.jsxs)(`button`,{onClick:()=>t(n),className:`px-2.5 py-1 rounded-full text-[10.5px] font-medium cursor-pointer transition-colors ${n===e?`bg-[var(--color-brand)]/15 text-[var(--color-brand)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,title:`Show commands as they would look on ${eh(n)}`,children:[th(n),` `,eh(n)]},n))})}function ah({os:e,setOs:t,onDismiss:n}){return(0,D.jsxs)(`div`,{className:`rounded-2xl border border-[var(--color-brand)]/25 bg-[var(--color-brand)]/[0.04] p-4 sm:p-5 space-y-3.5`,children:[(0,D.jsxs)(`div`,{className:`flex items-start justify-between gap-3`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h2`,{className:`text-[15px] font-semibold text-[var(--color-fg-0)] leading-tight`,children:`What SSG does — and why this page is here`}),(0,D.jsxs)(`p`,{className:`text-[12.5px] text-[var(--color-fg-2)] mt-1 leading-relaxed max-w-[60ch]`,children:[`AI coding agents can run any command on your computer: delete files, read your secrets, send emails, install packages. SSG is the policy engine that decides which of those they’re actually allowed to do.`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-0)] font-medium`,children:`This sandbox shows SSG’s decisions in real time`}),`, without anything actually running. Pick a scenario, click Run, see what your guardrails would do.`]})]}),(0,D.jsx)(`button`,{onClick:n,className:`shrink-0 text-[var(--color-fg-4)] hover:text-[var(--color-fg-1)] cursor-pointer text-[14px] leading-none p-1 -m-1`,"aria-label":`Dismiss intro`,title:`Hide this primer`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1.5 text-[11.5px]`,children:[(0,D.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-emerald-300`,children:[(0,D.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-emerald-400`}),`Nothing executes`]}),(0,D.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-emerald-300`,children:[(0,D.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-emerald-400`}),`No files modified`]}),(0,D.jsxs)(`span`,{className:`inline-flex items-center gap-1.5 text-emerald-300`,children:[(0,D.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full bg-emerald-400`}),`No network traffic`]})]}),(0,D.jsxs)(`div`,{className:`rounded-xl border border-[var(--color-line-1)]/60 bg-[var(--color-surface-1)]/40 p-3`,children:[(0,D.jsx)(`p`,{className:`text-[10.5px] uppercase tracking-wide text-[var(--color-fg-3)] font-semibold mb-2`,children:`How it works`}),(0,D.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-3 gap-3`,children:[(0,D.jsx)(rh,{n:1,label:`Pick a scenario below`}),(0,D.jsx)(rh,{n:2,label:`Click Run`}),(0,D.jsx)(rh,{n:3,label:`See the decision SSG would make`})]})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pt-1`,children:[(0,D.jsx)(`span`,{className:`text-[11.5px] text-[var(--color-fg-3)]`,children:`Showing commands as they look on`}),(0,D.jsx)(ih,{os:e,setOs:t}),(0,D.jsx)(`span`,{className:`text-[10.5px] text-[var(--color-fg-4)]`,children:`(cosmetic — SSG’s decision is the same on every OS)`})]}),(0,D.jsxs)(`div`,{className:`flex items-center justify-between gap-3 flex-wrap pt-1`,children:[(0,D.jsx)(`p`,{className:`text-[11px] text-[var(--color-fg-4)] italic max-w-[44ch] leading-snug`,children:`Every AI agent will need a policy layer. This is what one looks like.`}),(0,D.jsx)(`button`,{onClick:n,className:`text-[11.5px] font-medium text-[var(--color-fg-2)] hover:text-[var(--color-fg-0)] cursor-pointer underline-offset-2 hover:underline`,children:`Got it, hide this primer`})]})]})}function oh({scenario:e,selected:t,os:n,onClick:r}){return(0,D.jsxs)(`button`,{onClick:r,className:`flex flex-col gap-1.5 rounded-xl border px-3.5 py-3 text-left cursor-pointer transition-all ${t?`border-[var(--color-brand)]/60 bg-[var(--color-brand)]/8 shadow-[0_0_0_3px_color-mix(in_oklab,var(--color-brand)_15%,transparent)]`:`border-[var(--color-line-1)] bg-[var(--color-surface-1)] hover:border-[var(--color-line-2)] hover:bg-[var(--color-surface-2)]/40`}`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,D.jsx)(`span`,{className:`text-[18px] leading-none shrink-0`,children:e.emoji}),(0,D.jsx)(`span`,{className:`text-[13px] font-medium text-[var(--color-fg-0)] leading-snug flex-1 min-w-0`,children:e.label})]}),(0,D.jsx)(`p`,{className:`text-[11.5px] text-[var(--color-fg-3)] leading-snug`,children:e.plainEffect}),(0,D.jsx)(`p`,{className:`font-mono text-[10.5px] text-[var(--color-fg-4)] truncate`,children:nh(e,n)})]})}function sh(){let[e,t]=(0,_.useState)(null),[n,r]=(0,_.useState)(null),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(null),[c,l]=(0,_.useState)(!1),[u,d]=(0,_.useState)(`Bash`),[f,p]=(0,_.useState)(`{"command": ""}`),[m,h]=(0,_.useState)(()=>{if(typeof window>`u`)return!1;try{return window.localStorage.getItem(Xm)===`1`}catch{return!1}}),[g,v]=(0,_.useState)(()=>$m()),[y,b]=(0,_.useState)(!1);function x(e){v(e);try{window.localStorage.setItem(Zm,e)}catch{}}function S(){h(!0);try{window.localStorage.setItem(Xm,`1`)}catch{}}function C(){h(!1);try{window.localStorage.removeItem(Xm)}catch{}}let w=Ym.find(t=>t.id===e),T=(0,_.useMemo)(()=>{let e=new Map;for(let t of Ym){let n=e.get(t.category)??[];n.push(t),e.set(t.category,n)}return Jm.filter(t=>e.has(t.id)).map(t=>({...t,scenarios:e.get(t.id)}))},[]);(0,_.useEffect)(()=>{(n||o)&&window.scrollTo({top:(document.getElementById(`tryit-result`)?.offsetTop??0)-80,behavior:`smooth`})},[n,o]),(0,_.useEffect)(()=>{if(typeof window>`u`)return;let e=new URLSearchParams(window.location.search).get(`scenario`);e&&Ym.some(t=>t.id===e)&&t(e)},[]),(0,_.useEffect)(()=>{if(typeof window>`u`)return;let t=new URL(window.location.href);e?t.searchParams.set(`scenario`,e):t.searchParams.delete(`scenario`),window.history.replaceState({},``,t.toString())},[e]);function E(){if(!e)return;let t=new URL(window.location.href);t.searchParams.set(`scenario`,e),navigator.clipboard.writeText(t.toString()).then(()=>{b(!0),setTimeout(()=>b(!1),2e3)}).catch(()=>{})}async function O(e){a(!0),s(null),r(null);try{let t=await(await fetch(`/api/json/eval-dry-run`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify(e)})).json();t.error?s(t.error):r(t)}catch{s(`Could not reach the governance engine. Is SSG running?`)}finally{a(!1)}}function k(){w&&O(w.toolCall)}function ee(){let e;try{e=JSON.parse(f)}catch{s(`Invalid JSON in input field.`);return}if(typeof e!=`object`||!e){s(`Input must be a JSON object.`);return}O({tool:u,input:e})}let A=n?Qm[n.decision]??Qm.allow:null;return(0,D.jsxs)(`div`,{className:`max-w-3xl mx-auto py-4 space-y-4`,children:[(0,D.jsxs)(`header`,{className:`flex items-baseline justify-between gap-4 flex-wrap`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h1`,{className:`text-[22px] font-semibold text-[var(--color-fg-0)] tracking-tight leading-tight`,children:`Try it`}),(0,D.jsxs)(`p`,{className:`text-[13px] text-[var(--color-fg-2)] mt-0.5`,children:[`Your AI can run any command. SSG decides what it’s actually allowed to do.`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-3)]`,children:`Pick a scenario to see — nothing actually runs.`})]})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-3 shrink-0`,children:[m&&(0,D.jsx)(`button`,{onClick:C,className:`text-[11.5px] font-medium text-[var(--color-fg-3)] hover:text-[var(--color-fg-0)] cursor-pointer`,title:`Show the introduction again`,children:`What is Try It? →`}),(0,D.jsx)(`a`,{href:`/guardrails`,className:`text-[11.5px] font-medium text-[var(--color-brand)] hover:underline`,children:`Install more guardrails →`})]})]}),!m&&(0,D.jsx)(ah,{os:g,setOs:x,onDismiss:S}),m&&(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 px-1`,children:[(0,D.jsx)(`span`,{className:`text-[11px] text-[var(--color-fg-4)]`,children:`Commands shown as on`}),(0,D.jsx)(ih,{os:g,setOs:x})]}),(0,D.jsx)(`div`,{"data-tutorial":`try-scenarios`,className:`space-y-4`,children:T.map(n=>(0,D.jsxs)(`section`,{className:`space-y-2`,children:[(0,D.jsxs)(`div`,{className:`flex items-baseline gap-2 px-1`,children:[(0,D.jsx)(`h3`,{className:`text-[11px] uppercase tracking-wide text-[var(--color-fg-3)] font-semibold`,children:n.label}),(0,D.jsx)(`p`,{className:`text-[11px] text-[var(--color-fg-4)]`,children:n.blurb})]}),(0,D.jsx)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 gap-2`,children:n.scenarios.map(n=>(0,D.jsx)(oh,{scenario:n,selected:e===n.id,os:g,onClick:()=>{t(n.id),r(null),s(null)}},n.id))})]},n.id))}),w&&(0,D.jsxs)(`div`,{"data-tutorial":`try-detail`,className:`rounded-xl border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-4 space-y-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,D.jsx)(`span`,{className:`text-[22px] leading-none shrink-0`,children:w.emoji}),(0,D.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,D.jsx)(`p`,{className:`text-[13.5px] font-medium text-[var(--color-fg-0)]`,children:w.label}),(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-2)] mt-0.5 leading-relaxed`,children:w.plainEffect})]})]}),(0,D.jsxs)(`div`,{className:`rounded-lg border border-[var(--color-line-0)] bg-[var(--color-surface-0)] px-3 py-2`,children:[(0,D.jsxs)(`p`,{className:`text-[10px] uppercase tracking-wide text-[var(--color-fg-4)] font-semibold mb-1`,children:[`What the AI would run · `,eh(g)]}),(0,D.jsx)(`code`,{className:`font-mono text-[12px] text-[var(--color-fg-1)] break-all`,children:nh(w,g)})]}),(0,D.jsxs)(`div`,{className:`flex items-center justify-between gap-3 flex-wrap`,children:[(0,D.jsxs)(`p`,{className:`text-[11.5px] text-[var(--color-fg-3)]`,children:[`Click Run to see what SSG would decide.`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`The command does not actually execute.`})]}),(0,D.jsxs)(`div`,{className:`flex items-center gap-2 shrink-0`,children:[(0,D.jsx)(`button`,{onClick:E,className:`inline-flex items-center gap-1 px-3 h-8 rounded-full text-[11.5px] font-medium cursor-pointer transition-colors
51
51
  border border-[var(--color-line-1)] bg-[var(--color-surface-1)] text-[var(--color-fg-2)]
52
52
  hover:bg-[var(--color-surface-2)]/40 hover:text-[var(--color-fg-0)]`,title:`Copy a deep-link to this exact scenario`,children:y?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`svg`,{width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,D.jsx)(`path`,{d:`M20 6L9 17l-5-5`})}),`Link copied`]}):(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`svg`,{width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,D.jsx)(`path`,{d:`M10 13a5 5 0 0 0 7.07 0l3-3a5 5 0 0 0-7.07-7.07l-1.5 1.5M14 11a5 5 0 0 0-7.07 0l-3 3a5 5 0 0 0 7.07 7.07l1.5-1.5`})}),`Copy share link`]})}),(0,D.jsx)(`button`,{onClick:k,disabled:i,className:`inline-flex items-center gap-1.5 px-4 h-8 rounded-full text-[12px] font-medium cursor-pointer transition-colors
53
53
  bg-[var(--color-brand)] text-white hover:opacity-90
54
54
  disabled:opacity-40 disabled:cursor-not-allowed`,children:i?(0,D.jsxs)(D.Fragment,{children:[(0,D.jsx)(`svg`,{className:`animate-spin`,width:`12`,height:`12`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,D.jsx)(`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`})}),`Running`]}):(0,D.jsxs)(D.Fragment,{children:[`Run simulation`,(0,D.jsx)(`svg`,{width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,D.jsx)(`path`,{d:`M5 12h14M13 5l7 7-7 7`})})]})})]})]})]}),n&&A&&(0,D.jsxs)(`div`,{id:`tryit-result`,className:`rounded-xl border p-4 ${A.bg} space-y-3`,children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,D.jsx)(`span`,{className:`flex items-center justify-center w-9 h-9 rounded-full text-lg font-bold border ${A.bg} ${A.color}`,children:A.icon}),(0,D.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,D.jsx)(`p`,{className:`text-[15px] font-semibold ${A.color}`,children:A.label}),(0,D.jsx)(`p`,{className:`text-[12.5px] mt-0.5 ${A.color} opacity-90`,children:A.headline})]})]}),(0,D.jsx)(`p`,{className:`text-[12.5px] text-[var(--color-fg-1)] leading-relaxed`,children:A.next}),(0,D.jsxs)(`div`,{className:`rounded-lg bg-[var(--color-surface-0)]/60 border border-[var(--color-line-0)] px-3 py-2 space-y-1`,children:[(0,D.jsx)(`p`,{className:`text-[10px] uppercase tracking-wide text-[var(--color-fg-4)] font-semibold`,children:`Why this decision`}),(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-1)] leading-relaxed`,children:n.reason??`No specific rule matched this action — SSG defaults to allowing things that aren’t covered by a rule.`}),(0,D.jsxs)(`p`,{className:`text-[10.5px] text-[var(--color-fg-3)] mt-1.5`,children:[n.rules_evaluated,` rule`,n.rules_evaluated===1?``:`s`,` checked`,n.rule_id&&(0,D.jsxs)(D.Fragment,{children:[` `,`· matched`,` `,(0,D.jsx)(`a`,{href:`/rules?focus=${encodeURIComponent(n.rule_id)}`,className:`font-mono text-[var(--color-brand)] hover:underline`,children:n.rule_id})]})]})]}),w&&(0,D.jsxs)(`div`,{className:`rounded-lg border border-[var(--color-line-0)] bg-[var(--color-surface-0)]/60 px-3 py-2.5 flex items-start gap-2.5`,children:[(0,D.jsx)(`span`,{className:`text-[15px] leading-none mt-0.5 shrink-0`,children:n.decision===`block`?`🛡️`:n.decision===`allow`?`⚠️`:n.decision===`ask`?`⏸️`:`ℹ️`}),(0,D.jsxs)(`div`,{className:`min-w-0`,children:[(0,D.jsx)(`p`,{className:`text-[10.5px] uppercase tracking-wide text-[var(--color-fg-4)] font-semibold`,children:n.decision===`block`?`What you just avoided`:n.decision===`allow`?`What this would actually do`:n.decision===`ask`?`What you’d be asked to confirm`:`What gets recorded`}),(0,D.jsx)(`p`,{className:`text-[12.5px] text-[var(--color-fg-1)] leading-relaxed mt-0.5`,children:w.plainEffect})]})]}),n.decision===`allow`&&(0,D.jsxs)(`a`,{href:`/guardrails`,className:`inline-flex items-center gap-1.5 px-3.5 h-8 rounded-full text-[12px] font-medium
55
55
  bg-[var(--color-brand)] text-white hover:opacity-90 transition-colors`,children:[`Add a rule to block this`,(0,D.jsx)(`svg`,{width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,D.jsx)(`path`,{d:`M5 12h14M13 5l7 7-7 7`})})]}),(0,D.jsxs)(`div`,{className:`flex flex-wrap gap-x-4 gap-y-1.5 text-[11.5px] pt-1`,children:[n.decision===`block`&&(0,D.jsx)(`a`,{href:`/rules`,className:`font-medium text-[var(--color-brand)] hover:underline`,children:`See the rule that did this →`}),n.decision===`ask`&&(0,D.jsx)(`a`,{href:`/approvals`,className:`font-medium text-[var(--color-brand)] hover:underline`,children:`See where the prompt appears →`}),(0,D.jsx)(`a`,{href:`/audit`,className:`font-medium text-[var(--color-fg-2)] hover:text-[var(--color-fg-0)] hover:underline`,children:`See real decisions in your Activity log →`}),(0,D.jsx)(`a`,{href:`https://sigmashake.com`,target:`_blank`,rel:`noreferrer`,className:`font-medium text-[var(--color-fg-2)] hover:text-[var(--color-fg-0)] hover:underline`,children:`Tell a teammate about SSG ↗`})]})]}),o&&(0,D.jsx)(`div`,{className:`rounded-xl border border-red-500/30 bg-red-500/5 px-4 py-3 text-[12px] text-red-300`,children:o}),(0,D.jsxs)(`div`,{"data-tutorial":`try-advanced`,className:`pt-2`,children:[(0,D.jsx)(`button`,{onClick:()=>l(e=>!e),className:`text-[11px] text-[var(--color-fg-4)] hover:text-[var(--color-fg-2)] transition-colors cursor-pointer`,children:c?`▲ Hide custom input`:`▼ Advanced: write your own scenario`}),c&&(0,D.jsxs)(`div`,{className:`mt-3 rounded-xl border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3 space-y-2`,children:[(0,D.jsx)(`p`,{className:`text-[11px] text-[var(--color-fg-3)] leading-relaxed`,children:`Pick a tool the AI would call, and the input it would pass. Same idea as the scenarios above — still a simulation, still nothing actually runs.`}),(0,D.jsxs)(`div`,{className:`flex items-end gap-2 flex-wrap`,children:[(0,D.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,D.jsx)(`label`,{className:`text-[10px] font-mono text-[var(--color-fg-3)]`,children:`Tool`}),(0,D.jsx)(`select`,{value:u,onChange:e=>d(e.target.value),className:`bg-[var(--color-surface-0)] border border-[var(--color-line-1)] text-[var(--color-fg-1)] text-[11px] font-mono rounded-md px-2 h-8 focus:outline-none`,children:[`Bash`,`Read`,`Write`,`Edit`,`WebFetch`,`WebSearch`,`Agent`,`Glob`,`Grep`].map(e=>(0,D.jsx)(`option`,{value:e,children:e},e))})]}),(0,D.jsxs)(`div`,{className:`flex-1 min-w-[200px] flex flex-col gap-1`,children:[(0,D.jsx)(`label`,{className:`text-[10px] font-mono text-[var(--color-fg-3)]`,children:`Input JSON`}),(0,D.jsx)(`input`,{type:`text`,value:f,onChange:e=>p(e.target.value),className:`w-full bg-[var(--color-surface-0)] border border-[var(--color-line-1)] text-[var(--color-fg-1)] text-[11px] font-mono rounded-md px-2 h-8 focus:outline-none focus:border-[var(--color-brand)]/50`})]}),(0,D.jsx)(`button`,{onClick:ee,disabled:i,className:`px-3 h-8 rounded-full text-[11px] font-medium cursor-pointer transition-colors
56
56
  bg-[var(--color-fg-1)] text-[var(--color-bg)] hover:opacity-90
57
- disabled:opacity-40 disabled:cursor-not-allowed`,children:`Run`})]})]})]})]})}var ah=[{value:`issue`,label:`Bug / Issue`,hint:`Something is broken`},{value:`feature_request`,label:`Feature Request`,hint:`Suggest an improvement`},{value:`question`,label:`Question`,hint:`How does X work?`},{value:`incident`,label:`Incident`,hint:`Urgent outage or data concern`}],oh=[{value:`p4`,label:`P4 — Low`},{value:`p3`,label:`P3 — Normal`},{value:`p2`,label:`P2 — High (4h SLA)`},{value:`p1`,label:`P1 — Critical (1h SLA)`}],sh=5,ch=8*1024*1024;function lh(){let[e,t]=(0,_.useState)(`issue`),[n,r]=(0,_.useState)(`p3`),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(null),[y,b]=(0,_.useState)(!1),[x,S]=(0,_.useState)(``),C=(0,_.useRef)(null);(0,_.useEffect)(()=>{fetch(`/api/json/profile`,{headers:U()}).then(e=>e.ok?e.json():null).then(e=>{e?.email&&l(e.email)}).catch(()=>{})},[]),(0,_.useEffect)(()=>{!y||g||fetch(`/api/support/diagnostics?route=${encodeURIComponent(window.location.pathname)}`).then(e=>e.ok?e.json():null).then(e=>v(e)).catch(()=>{})},[y,g]),(0,_.useEffect)(()=>{let e=new URL(window.location.href),n=e.searchParams.get(`error`),r=e.searchParams.get(`from`);if(n||r){t(`issue`);let e=r?`Page: ${r}\n\n`:``,i=n?`Error: ${n}\n\n`:``;s(t=>t||`${e}${i}`)}},[]);function w(e){e.preventDefault(),E(Array.from(e.dataTransfer.files))}function T(e){E(Array.from(e.target.files??[])),C.current&&(C.current.value=``)}function E(e){S(``);let t=e.filter(e=>e.type.startsWith(`image/`));t.length<e.length&&S(`Only image files are accepted.`);let n=sh-u.length,r=t.slice(0,n);r.length<t.length&&S(`Maximum ${sh} images. Some were dropped.`);let i=r.filter(e=>e.size>ch);if(i.length>0){S(`"${i[0].name}" exceeds 8 MiB.`);return}let a=r.map(e=>({file:e,preview:URL.createObjectURL(e)}));d(e=>[...e,...a])}function O(e){d(t=>(URL.revokeObjectURL(t[e].preview),t.filter((t,n)=>n!==e)))}async function k(t){t.preventDefault(),p(!0),h(null);let r=new FormData;r.append(`category`,e),r.append(`severity`,n),r.append(`subject`,i.trim()),r.append(`description`,o.trim()),r.append(`contact_email`,c.trim()),r.append(`route`,window.location.pathname);for(let{file:e}of u)r.append(`images`,e,e.name);try{let e=await(await fetch(`/api/support/feedback`,{method:`POST`,headers:U(),body:r})).json();h(e),e.ok&&(a(``),s(``),d([]))}catch(e){h({ok:!1,error:e instanceof Error?e.message:`Network error`})}finally{p(!1)}}return(0,D.jsxs)(`div`,{className:`max-w-2xl mx-auto space-y-5`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h1`,{className:`text-xl font-medium tracking-tight text-[var(--color-fg-0)]`,children:`Support & Feedback`}),(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-3)] mt-1 font-mono`,children:`report a bug, request a feature, or ask a question`})]}),m?.ok?(0,D.jsx)(K,{children:(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`space-y-3 py-2`,children:[(0,D.jsxs)(`p`,{className:`text-sm text-emerald-400 font-mono`,children:[`✓ `,m.message??`Ticket created.`]}),m.ticket_id&&(0,D.jsxs)(`p`,{className:`text-xs text-[var(--color-fg-3)] font-mono`,children:[`Ticket ID:`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:m.ticket_id})]}),(0,D.jsx)(`button`,{className:`text-[12px] text-[var(--color-brand)] hover:underline font-mono`,onClick:()=>h(null),children:`Submit another`})]})})}):(0,D.jsxs)(`form`,{onSubmit:k,className:`space-y-4`,children:[(0,D.jsx)(K,{children:(0,D.jsxs)(J,{children:[(0,D.jsx)(`label`,{className:`block overline mb-2`,children:`type`}),(0,D.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:ah.map(n=>(0,D.jsxs)(`button`,{type:`button`,onClick:()=>t(n.value),className:`text-left px-3 py-2 rounded-sm border text-xs font-mono transition-colors ${e===n.value?`border-[var(--color-brand)]/50 bg-[var(--color-brand)]/10 text-[var(--color-fg-0)]`:`border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:border-[var(--color-line-0)]`}`,children:[(0,D.jsx)(`span`,{className:`block font-medium text-[var(--color-fg-1)]`,children:n.label}),(0,D.jsx)(`span`,{className:`block text-[11px] mt-0.5`,children:n.hint})]},n.value))})]})}),e===`incident`&&(0,D.jsx)(K,{children:(0,D.jsxs)(J,{children:[(0,D.jsx)(`label`,{className:`block overline mb-2`,children:`severity`}),(0,D.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:oh.map(e=>(0,D.jsx)(`button`,{type:`button`,onClick:()=>r(e.value),className:`px-3 py-1.5 rounded-sm border text-xs font-mono transition-colors ${n===e.value?`border-[var(--color-brand)]/50 bg-[var(--color-brand)]/10 text-[var(--color-fg-0)]`:`border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:border-[var(--color-line-0)]`}`,children:e.label},e.value))})]})}),(0,D.jsx)(K,{children:(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:`block overline mb-1.5`,children:`subject`}),(0,D.jsx)(`input`,{"data-tutorial":`support-subject`,type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`Short summary (required)`,maxLength:200,required:!0,className:`w-full bg-[var(--color-surface-0)] border border-[var(--color-line-1)] text-[var(--color-fg-1)] text-sm rounded-sm px-3 py-2 focus:outline-none focus:border-[var(--color-brand)]/50 placeholder:text-[var(--color-fg-4)] font-mono`})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:`block overline mb-1.5`,children:`description`}),(0,D.jsx)(`textarea`,{"data-tutorial":`support-desc`,value:o,onChange:e=>s(e.target.value),placeholder:`Describe the issue in detail (10–10000 characters)`,minLength:10,maxLength:1e4,required:!0,rows:6,className:`w-full bg-[var(--color-surface-0)] border border-[var(--color-line-1)] text-[var(--color-fg-1)] text-sm rounded-sm px-3 py-2 focus:outline-none focus:border-[var(--color-brand)]/50 placeholder:text-[var(--color-fg-4)] font-mono resize-y`})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:`block overline mb-1.5`,children:`contact email`}),(0,D.jsx)(`input`,{type:`email`,value:c,onChange:e=>l(e.target.value),placeholder:`your@email.com`,required:!0,className:`w-full bg-[var(--color-surface-0)] border border-[var(--color-line-1)] text-[var(--color-fg-1)] text-sm rounded-sm px-3 py-2 focus:outline-none focus:border-[var(--color-brand)]/50 placeholder:text-[var(--color-fg-4)] font-mono`})]})]})})}),(0,D.jsx)(K,{children:(0,D.jsxs)(J,{children:[(0,D.jsxs)(`label`,{className:`block overline mb-2`,children:[`screenshots / attachments`,` `,(0,D.jsxs)(`span`,{className:`normal-case text-[var(--color-fg-4)] font-mono font-normal`,children:[`(optional, up to `,sh,` images)`]})]}),u.length<sh&&(0,D.jsxs)(`div`,{"data-tutorial":`support-attach`,onDragOver:e=>e.preventDefault(),onDrop:w,onClick:()=>C.current?.click(),className:`border border-dashed border-[var(--color-line-1)] rounded-sm p-6 text-center cursor-pointer hover:border-[var(--color-brand)]/50 transition-colors`,children:[(0,D.jsxs)(`p`,{className:`text-xs text-[var(--color-fg-3)] font-mono`,children:[`drag & drop images, or`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-brand)]`,children:`click to browse`})]}),(0,D.jsx)(`p`,{className:`text-[11px] text-[var(--color-fg-4)] mt-1 font-mono`,children:`PNG · JPEG · WebP · GIF · HEIC — max 8 MiB each`})]}),(0,D.jsx)(`input`,{ref:C,type:`file`,accept:`image/*`,multiple:!0,className:`hidden`,onChange:T}),x&&(0,D.jsx)(`p`,{className:`text-xs text-red-400 font-mono mt-2`,children:x}),u.length>0&&(0,D.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:u.map((e,t)=>(0,D.jsxs)(`div`,{className:`relative group`,children:[(0,D.jsx)(`img`,{src:e.preview,alt:e.file.name,className:`h-20 w-20 object-cover rounded-sm border border-[var(--color-line-1)]`}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>O(t),className:`absolute -top-1.5 -right-1.5 w-5 h-5 rounded-full bg-[var(--color-surface-0)] border border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:text-red-400 text-[10px] font-mono flex items-center justify-center`,title:`Remove`,children:`✕`}),(0,D.jsx)(`p`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] mt-0.5 max-w-[80px] truncate`,children:e.file.name})]},t))})]})}),(0,D.jsxs)(`div`,{className:`rounded-sm border border-[var(--color-line-1)] overflow-hidden`,children:[(0,D.jsxs)(`button`,{type:`button`,onClick:()=>b(e=>!e),className:`w-full flex items-center justify-between px-3 py-2 text-xs font-mono text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] bg-[var(--color-surface-0)] transition-colors`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`diagnostics that will be attached`}),(0,D.jsx)(`span`,{children:y?`▲`:`▼`})]}),y&&(0,D.jsx)(`div`,{className:`px-3 py-2 bg-[var(--color-surface-0)] border-t border-[var(--color-line-1)] max-h-64 overflow-auto`,children:g?(0,D.jsx)(`pre`,{className:`text-[10px] font-mono text-[var(--color-fg-3)] whitespace-pre-wrap break-all`,children:JSON.stringify(g,null,2)}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`Loading…`})})]}),m&&!m.ok&&(0,D.jsx)(`div`,{className:`rounded-sm border border-red-500/25 bg-red-500/5 px-3 py-2 text-xs text-red-300 font-mono`,children:m.error??`Submission failed. Please try again.`}),(0,D.jsx)(G,{type:`submit`,variant:`primary`,disabled:f,children:f?`submitting…`:`submit feedback`})]})]})}function uh(e){let t=Date.now()-e,n=Math.floor(t/1e3);if(n<60)return`just now`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}var dh={block:`var(--color-hig-red)`,ask:`var(--color-hig-orange)`,log:`var(--color-hig-blue)`,allow:`var(--color-hig-green)`,force:`var(--color-hig-purple)`};function fh(e){switch(e){case`block`:return`Blocked`;case`ask`:return`Held for review`;case`log`:return`Logged`;case`force`:return`Force-allowed`;default:return`Allowed`}}function ph({type:e}){let t={fill:`none`,stroke:`currentColor`,strokeWidth:1.6,strokeLinecap:`round`,strokeLinejoin:`round`,viewBox:`0 0 24 24`};return e===`code`?(0,D.jsxs)(`svg`,{...t,width:`22`,height:`22`,children:[(0,D.jsx)(`path`,{d:`M9 7l-5 5 5 5M15 7l5 5-5 5`}),(0,D.jsx)(`path`,{d:`M14 4l-4 16`,opacity:`0.55`})]}):e===`docs`?(0,D.jsxs)(`svg`,{...t,width:`22`,height:`22`,children:[(0,D.jsx)(`path`,{d:`M5 4h9l5 5v11a1 1 0 01-1 1H5a1 1 0 01-1-1V5a1 1 0 011-1z`}),(0,D.jsx)(`path`,{d:`M14 4v5h5`}),(0,D.jsx)(`path`,{d:`M8 13h8M8 17h5`,opacity:`0.7`})]}):(0,D.jsxs)(`svg`,{...t,width:`22`,height:`22`,children:[(0,D.jsx)(`path`,{d:`M3 12a9 9 0 109-9`}),(0,D.jsx)(`path`,{d:`M12 3v9l6 3`})]})}function mh(){let{data:e}=k(`/api/json/counters`,[V([`counters-updated`])[`counters-updated`]]),t=e?.evals_today??0,n=e?.blocked_today??0,r=e?.asked_today??0;return(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2`,children:[(0,D.jsx)(hh,{value:t,label:`evaluated`,tone:`default`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsx)(hh,{value:n,label:`blocked`,tone:`red`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsx)(hh,{value:r,label:`held for you`,tone:`orange`}),(0,D.jsx)(`span`,{className:`text-[11px] ml-auto`,style:{color:`var(--color-fg-3)`},children:`Today`})]})}function hh({value:e,label:t,tone:n}){return(0,D.jsxs)(`span`,{className:`inline-flex items-baseline gap-1.5`,children:[(0,D.jsx)(`span`,{className:`font-semibold tabular-nums`,style:{color:n===`red`?`var(--color-hig-red)`:n===`orange`?`var(--color-hig-orange)`:`var(--color-fg-0)`,fontSize:`20px`,lineHeight:1,letterSpacing:`-0.018em`},children:e.toLocaleString()}),(0,D.jsx)(`span`,{style:{color:`var(--color-fg-3)`,fontSize:`12px`,letterSpacing:`-0.005em`},children:t})]})}function gh({href:e,title:t,desc:n,tone:r,type:i,cta:a}){let o=r===`orange`?`var(--color-hig-orange)`:r===`indigo`?`var(--color-hig-indigo)`:`var(--color-hig-blue)`;return(0,D.jsx)(`a`,{href:e,className:`group block rounded-2xl px-4 py-4 transition-all`,style:{border:`0.5px solid var(--color-line-1)`,background:`var(--color-surface-1)`,textDecoration:`none`,color:`inherit`,boxShadow:`var(--hig-shadow-1)`},children:(0,D.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,D.jsx)(`span`,{className:`flex items-center justify-center rounded-xl shrink-0`,style:{width:`40px`,height:`40px`,color:o,background:`color-mix(in oklab, ${o} 14%, transparent)`},children:(0,D.jsx)(ph,{type:i})}),(0,D.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,D.jsx)(`div`,{className:`text-[14px] font-semibold leading-tight`,style:{color:`var(--color-fg-0)`,letterSpacing:`-0.005em`},children:t}),(0,D.jsx)(`div`,{className:`text-[12px] mt-1 leading-snug`,style:{color:`var(--color-fg-2)`},children:n}),(0,D.jsxs)(`div`,{className:`text-[11.5px] mt-2 font-medium inline-flex items-center gap-1 transition-all`,style:{color:o},children:[a,(0,D.jsx)(`span`,{"aria-hidden":`true`,className:`transition-transform group-hover:translate-x-0.5`,children:`→`})]})]})]})})}function _h(){let{data:e}=k(`/api/state/activity?limit=5`,[V([`activity-updated`])[`activity-updated`]]),[,t]=(0,_.useState)(0);return(0,_.useEffect)(()=>{let e=setInterval(()=>t(e=>e+1),6e4);return()=>clearInterval(e)},[]),!e||e.length===0?(0,D.jsxs)(`div`,{className:`py-6 text-center`,style:{color:`var(--color-fg-3)`},children:[(0,D.jsx)(`p`,{style:{fontSize:`12.5px`,color:`var(--color-fg-2)`},children:`Waiting for your first agent action.`}),(0,D.jsx)(`p`,{style:{fontSize:`11px`,color:`var(--color-fg-3)`,marginTop:`4px`},children:`Anything your AI tries — read, write, run — will appear here in real time.`})]}):(0,D.jsx)(`div`,{children:e.slice(0,5).map((e,t)=>(0,D.jsxs)(`div`,{className:`hig-feed-row`,children:[(0,D.jsx)(`span`,{className:`hig-feed-row-dot`,style:{background:dh[e.decision]??`var(--color-fg-3)`,boxShadow:`0 0 0 3px ${e.decision===`block`?`color-mix(in oklab, var(--color-hig-red) 22%, transparent)`:e.decision===`ask`?`color-mix(in oklab, var(--color-hig-orange) 22%, transparent)`:`transparent`}`}}),(0,D.jsx)(`span`,{className:`hig-feed-row-decision`,style:{color:dh[e.decision]??`var(--color-fg-2)`},children:fh(e.decision)}),(0,D.jsx)(`span`,{style:{color:`var(--color-fg-3)`},children:`·`}),(0,D.jsx)(`span`,{className:`hig-feed-row-tool`,title:e.tool,children:Si(e.tool)}),(0,D.jsx)(`span`,{className:`hig-feed-row-time`,children:uh(e.timestamp)})]},e.id??t))})}function vh(){return(0,D.jsx)(`div`,{className:`relative`,children:(0,D.jsxs)(`div`,{className:`relative max-w-5xl mx-auto px-2 pt-6 pb-12 space-y-6`,children:[(0,D.jsxs)(`section`,{"data-tutorial":`wh-hero`,className:`rounded-2xl px-6 py-5 relative overflow-hidden`,style:{border:`0.5px solid var(--color-line-1)`,background:`radial-gradient(120% 100% at 0% 0%, color-mix(in oklab, var(--color-accent) 14%, transparent) 0%, transparent 55%), var(--color-surface-1)`,boxShadow:`var(--hig-shadow-1)`},children:[(0,D.jsx)(`div`,{className:`hig-eyebrow mb-2`,children:`SigmaShake · Guardrails for AI`}),(0,D.jsx)(`h1`,{className:`font-semibold tracking-tight leading-tight`,style:{color:`var(--color-fg-0)`,fontSize:`26px`,letterSpacing:`-0.018em`},children:`The seatbelt for AI agents.`}),(0,D.jsx)(`p`,{className:`mt-1.5 leading-relaxed`,style:{color:`var(--color-fg-2)`,fontSize:`13.5px`,maxWidth:`52ch`},children:`Watch every move your AI makes. Approve what matters, block what doesn't — without babysitting every step.`}),(0,D.jsx)(`div`,{className:`mt-4 pt-3`,style:{borderTop:`0.5px solid var(--color-line-0)`},children:(0,D.jsx)(mh,{})})]}),(0,D.jsx)(`section`,{children:(0,D.jsxs)(`div`,{"data-tutorial":`wh-actions`,className:`grid grid-cols-1 md:grid-cols-3 gap-3`,children:[(0,D.jsx)(gh,{href:`/guardrails?starter=coding`,tone:`orange`,type:`code`,title:`Code safely with AI`,desc:`Protect files, secrets, and git history from coding agents.`,cta:`Install pack`}),(0,D.jsx)(gh,{href:`/guardrails?starter=knowledge-work`,tone:`indigo`,type:`docs`,title:`Guard sensitive content`,desc:`Watch outbound email, file shares, and document changes.`,cta:`Install pack`}),(0,D.jsx)(gh,{href:`/audit`,tone:`blue`,type:`review`,title:`Review what your AI did`,desc:`Every action, decision, and reason — in one place.`,cta:`Open activity`})]})}),(0,D.jsxs)(`a`,{href:`/try`,"data-tutorial":`wh-try`,className:`group flex items-center justify-between gap-3 rounded-xl px-4 py-3 transition-all`,style:{border:`0.5px solid var(--color-line-1)`,background:`linear-gradient(90deg, color-mix(in oklab, var(--color-accent) 8%, transparent) 0%, transparent 60%), var(--color-surface-1)`,textDecoration:`none`,color:`inherit`},children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,D.jsx)(`span`,{className:`flex items-center justify-center w-8 h-8 rounded-full shrink-0`,style:{background:`linear-gradient(180deg, var(--color-accent) 0%, var(--color-brand-hover) 100%)`,color:`var(--color-accent-on)`,boxShadow:`inset 0 0.5px 0 rgba(255,255,255,0.30), 0 2px 8px color-mix(in oklab, var(--color-accent) 30%, transparent)`},children:(0,D.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,D.jsx)(`polygon`,{points:`6 4 20 12 6 20`,fill:`currentColor`,stroke:`none`})})}),(0,D.jsxs)(`div`,{className:`min-w-0`,children:[(0,D.jsx)(`div`,{className:`font-semibold text-[13.5px] leading-tight`,style:{color:`var(--color-fg-0)`,letterSpacing:`-0.005em`},children:`Try a scenario — see SigmaShake decide`}),(0,D.jsx)(`div`,{className:`text-[12px] mt-0.5`,style:{color:`var(--color-fg-3)`},children:`30-second dry-run · nothing actually runs.`})]})]}),(0,D.jsxs)(`span`,{className:`text-[12.5px] font-medium shrink-0 inline-flex items-center gap-1 transition-all`,style:{color:`var(--color-accent)`},children:[`Try it`,(0,D.jsx)(`span`,{"aria-hidden":`true`,className:`transition-transform group-hover:translate-x-0.5`,children:`→`})]})]}),(0,D.jsxs)(`section`,{children:[(0,D.jsxs)(`div`,{className:`flex items-baseline justify-between mb-2`,children:[(0,D.jsx)(`h2`,{className:`font-semibold tracking-tight`,style:{color:`var(--color-fg-0)`,fontSize:`15px`,letterSpacing:`-0.008em`},children:`Recent activity`}),(0,D.jsx)(`a`,{href:`/audit`,style:{fontSize:`12px`,color:`var(--color-hig-blue)`,fontWeight:500},children:`View all →`})]}),(0,D.jsx)(`div`,{style:{background:`var(--color-surface-1)`,border:`0.5px solid var(--color-line-1)`,borderRadius:`14px`,padding:`4px 16px`,boxShadow:`var(--hig-shadow-1)`},children:(0,D.jsx)(_h,{})})]})]})})}var yh={dashboard:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`rect`,{x:`3`,y:`3`,width:`7`,height:`9`,rx:`1.5`}),(0,D.jsx)(`rect`,{x:`14`,y:`3`,width:`7`,height:`5`,rx:`1.5`}),(0,D.jsx)(`rect`,{x:`14`,y:`12`,width:`7`,height:`9`,rx:`1.5`}),(0,D.jsx)(`rect`,{x:`3`,y:`16`,width:`7`,height:`5`,rx:`1.5`})]}),graph:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`circle`,{cx:`6`,cy:`18`,r:`2.4`}),(0,D.jsx)(`circle`,{cx:`18`,cy:`6`,r:`2.4`}),(0,D.jsx)(`circle`,{cx:`18`,cy:`18`,r:`2.4`}),(0,D.jsx)(`circle`,{cx:`12`,cy:`11`,r:`2.4`}),(0,D.jsx)(`path`,{d:`M7.5 16.5l3-4M13.5 11.5l3-3.5M13.5 12l3 4.5`})]}),rules:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M9 5h11M9 12h11M9 19h11`}),(0,D.jsx)(`path`,{d:`M4 5l1 1 2-2M4 12l1 1 2-2M4 19l1 1 2-2`})]}),hub:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,D.jsx)(`path`,{d:`M3 12h18`}),(0,D.jsx)(`path`,{d:`M12 3a14 14 0 010 18M12 3a14 14 0 000 18`})]}),audit:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`circle`,{cx:`11`,cy:`11`,r:`6.5`}),(0,D.jsx)(`path`,{d:`M21 21l-5-5`})]}),approvals:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M5 7h14v12a2 2 0 01-2 2H7a2 2 0 01-2-2z`}),(0,D.jsx)(`path`,{d:`M9 3v4M15 3v4`}),(0,D.jsx)(`path`,{d:`M9 13l2 2 4-4`})]}),profile:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`circle`,{cx:`12`,cy:`8`,r:`4`}),(0,D.jsx)(`path`,{d:`M4 21c0-4.4 3.6-8 8-8s8 3.6 8 8`})]}),monitor:(0,D.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,D.jsx)(`path`,{d:`M3 12h3l3-7 4 14 3-7h5`})}),observability:(0,D.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,D.jsx)(`path`,{d:`M4 20h16M7 16V8M11 16V4M15 16v-6M19 16v-3`})}),debug:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`rect`,{x:`7`,y:`7`,width:`10`,height:`12`,rx:`5`}),(0,D.jsx)(`path`,{d:`M12 7V4M9 4l3 3 3-3`}),(0,D.jsx)(`path`,{d:`M5 11l2-1M5 18l2-1M19 11l-2-1M19 18l-2-1`})]}),home:(0,D.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,D.jsx)(`path`,{d:`M3 11l9-7 9 7v9a2 2 0 01-2 2h-3v-7H10v7H5a2 2 0 01-2-2z`})}),guardrails:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M12 3l8 3.7v6.3c0 5-3.5 9.6-8 11-4.5-1.4-8-6-8-11V6.7L12 3z`}),(0,D.jsx)(`path`,{d:`M9 12l2 2 4-4`})]}),tryit:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M9 3v6L4.5 18a2 2 0 001.7 3h11.6a2 2 0 001.7-3L15 9V3`}),(0,D.jsx)(`path`,{d:`M8 3h8`})]}),agents:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`circle`,{cx:`8`,cy:`9`,r:`3`}),(0,D.jsx)(`circle`,{cx:`16`,cy:`9`,r:`3`}),(0,D.jsx)(`path`,{d:`M3 19c.7-2.5 2.6-4 5-4`}),(0,D.jsx)(`path`,{d:`M21 19c-.7-2.5-2.6-4-5-4`}),(0,D.jsx)(`path`,{d:`M9 17.5c.8-1 1.8-1.5 3-1.5s2.2.5 3 1.5`})]}),notifications:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M18 16v-5a6 6 0 1 0-12 0v5l-2 2h16z`}),(0,D.jsx)(`path`,{d:`M10 20a2 2 0 0 0 4 0`})]}),setup:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M9 12l2 2 4-4`}),(0,D.jsx)(`path`,{d:`M12 3l8 3.7v6.3c0 5-3.5 9.6-8 11-4.5-1.4-8-6-8-11V6.7L12 3z`})]}),support:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,D.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3.5`}),(0,D.jsx)(`path`,{d:`M12 2.5v6M12 15.5v6M2.5 12h6M15.5 12h6`})]}),workspace:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`rect`,{x:`3`,y:`4`,width:`18`,height:`14`,rx:`2`}),(0,D.jsx)(`path`,{d:`M3 9h18M8 14h2M14 14h2`}),(0,D.jsx)(`path`,{d:`M9 20h6`})]}),plugins:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M9 3v4a2 2 0 0 1-2 2H3`}),(0,D.jsx)(`path`,{d:`M15 3v4a2 2 0 0 0 2 2h4`}),(0,D.jsx)(`rect`,{x:`3`,y:`9`,width:`18`,height:`12`,rx:`2`}),(0,D.jsx)(`path`,{d:`M7 14h2M12 14h5M7 18h10`})]})},bh=[{title:`Overview`,items:[{path:`/`,label:`Dashboard`,icon:`dashboard`},{path:`/notifications`,label:`Notifications`,icon:`notifications`},{path:`/agents`,label:`Agents`,icon:`agents`},{path:`/graph`,label:`Graph`,icon:`graph`},{path:`/sessions`,label:`Sessions`,icon:`agents`}]},{title:`Rules`,items:[{path:`/rules`,label:`Rules`,icon:`rules`},{path:`/hub`,label:`Hub`,icon:`hub`},{path:`/approvals`,label:`Approvals`,icon:`approvals`}]},{title:`Activity`,items:[{path:`/audit`,label:`Audit`,icon:`audit`},{path:`/monitor`,label:`Monitor`,icon:`monitor`},{path:`/observability`,label:`Observability`,icon:`observability`}]},{title:`Tools`,items:[{path:`/plugins`,label:`Plugins`,icon:`plugins`},{path:`/setup`,label:`Setup`,icon:`setup`},{path:`/debug`,label:`Debug`,icon:`debug`},{path:`/profile`,label:`Profile`,icon:`profile`},{path:`/support`,label:`Support`,icon:`support`}]}],xh=[{title:`Get Started`,items:[{path:`/`,label:`Home`,icon:`home`},{path:`/agents`,label:`Agents`,icon:`agents`},{path:`/guardrails`,label:`Guardrails`,icon:`guardrails`},{path:`/try`,label:`Try It`,icon:`tryit`}]},{title:`Activity`,items:[{path:`/notifications`,label:`Notifications`,icon:`notifications`},{path:`/audit`,label:`Activity`,icon:`audit`},{path:`/approvals`,label:`Approvals`,icon:`approvals`}]},{title:`You`,items:[{path:`/setup`,label:`Setup`,icon:`setup`},{path:`/profile`,label:`Profile`,icon:`profile`},{path:`/support`,label:`Support`,icon:`support`}]}];function Sh(e){return Ch(e===`newcomer`?xh:bh)}function Ch(e){let t=window.__SSG_PLUGINS__;if(!t||t.nav.length===0)return e;let n=e=>{let t=e.toLowerCase();return t===`tools`?`Tools`:t===`activity`?`Activity`:t===`overview`?`Overview`:t===`rules`?`Rules`:e.charAt(0).toUpperCase()+e.slice(1)},r=e.map(e=>({...e,items:[...e.items]})),i=new Map;for(let e of t.nav){let t={path:e.path,label:e.label,icon:`plugins`},a=n(e.section),o=r.find(e=>e.title===a);if(o)o.items.push(t);else{let e=i.get(a)??[];e.push(t),i.set(a,e)}}for(let[e,t]of i)r.push({title:e,items:t});return r}function wh(e){let t=Math.max(0,e-Date.now()),n=Math.floor(t/1e3);if(n<60)return`${n}s`;let r=Math.floor(n/60);return r<60?`${r}m ${n%60}s`:`${Math.floor(r/60)}h ${r%60}m`}function Th(){let{data:e}=k(`/api/json/daemon-status`,[V([`counters-updated`])[`counters-updated`]]),[t,n]=(0,_.useState)(!1),[,r]=(0,_.useState)(0);(0,_.useEffect)(()=>{if(e?.status!==`degraded`||!e.hibernation)return;let t=setInterval(()=>r(e=>e+1),1e3);return()=>clearInterval(t)},[e?.status,e?.hibernation]);let i=e?.status??`starting`,a=i===`running`?`bg-[var(--color-decision-allow)]`:i===`starting`||i===`degraded`?`bg-[var(--color-decision-ask)]`:`bg-[var(--color-decision-block)]`,o=i===`starting`||i===`degraded`?`pulse-soft`:``,s=i===`degraded`&&e?.hibernation?wh(e.hibernation.nextRetryAt):null,c=i===`running`?`Daemon`:i===`starting`?`Booting`:i===`degraded`?`Retry ${s??`…`}`:i===`error`?`Error`:`Offline`;return(0,D.jsxs)(`div`,{className:`relative`,children:[(0,D.jsxs)(`button`,{onClick:()=>n(e=>!e),className:`chip cursor-pointer hover:bg-[var(--color-fill-2)] transition-colors`,title:i===`running`?`Daemon running`:i===`starting`?`Daemon starting…`:i===`degraded`?`Daemon hibernating — retry in ${s??`…`}`:i===`error`?`Daemon error`:`Daemon stopped`,children:[(0,D.jsx)(`span`,{className:`status-dot ${a} ${o}`}),(0,D.jsx)(`span`,{className:`hidden sm:inline`,children:c})]}),t&&(0,D.jsxs)(`div`,{className:`absolute right-0 top-7 z-50 w-72 hig-card hig-card-padded text-xs`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`Eval Daemon`}),(0,D.jsx)(`button`,{onClick:()=>n(!1),className:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-0)] cursor-pointer`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`space-y-1 text-[var(--color-fg-2)]`,children:[(0,D.jsxs)(`div`,{className:`font-mono text-[11px]`,children:[`status:`,` `,(0,D.jsx)(`span`,{className:i===`running`?`text-[var(--color-decision-allow)]`:i===`starting`||i===`degraded`?`text-[var(--color-decision-ask)]`:`text-[var(--color-decision-block)]`,children:i})]}),e?.pid&&(0,D.jsxs)(`div`,{className:`font-mono text-[11px]`,children:[`pid: `,e.pid]}),i===`degraded`&&e?.hibernation&&(0,D.jsxs)(`div`,{className:`mt-2 rounded-lg p-2 text-[11px] space-y-0.5`,style:{background:`color-mix(in oklab, var(--color-hig-orange) 14%, transparent)`,color:`color-mix(in oklab, var(--color-hig-orange) 90%, var(--color-fg-0))`},children:[(0,D.jsxs)(`div`,{children:[`next retry: `,(0,D.jsx)(`span`,{className:`font-medium`,children:s})]}),(0,D.jsxs)(`div`,{children:[`episode attempt: `,e.hibernation.attempt,e.hibernation.reason?` (${e.hibernation.reason})`:``]}),(0,D.jsx)(`div`,{className:`opacity-70`,children:`Slow-tier supervisor is retrying at long backoff — no manual restart required.`})]})]}),e?.logTail&&e.logTail.length>0&&(0,D.jsxs)(`div`,{className:`mt-3`,children:[(0,D.jsx)(`div`,{className:`overline mb-1`,children:`Recent log`}),(0,D.jsx)(`pre`,{className:`bg-[var(--color-surface-2)] border border-[var(--color-line-0)] rounded-md p-2 text-[10px] text-[var(--color-fg-2)] overflow-x-auto whitespace-pre-wrap break-all max-h-32 overflow-y-auto`,children:e.logTail.join(`
58
- `)})]})]})]})}function Eh(){let{data:e}=k(`/api/state/activity-degraded`);if(!e?.degraded)return null;let t=e.since?new Date(e.since).toLocaleTimeString():`recently`;return(0,D.jsxs)(`div`,{role:`status`,className:`hig-banner hig-banner-warning`,title:e.reason??`audit-worker degraded`,children:[(0,D.jsx)(`span`,{children:`⚠`}),(0,D.jsxs)(`span`,{children:[`Audit pipeline degraded since `,t,` — entries may be missing. Run`,` `,(0,D.jsx)(`code`,{className:`font-mono`,children:`ssg daemon --status`}),` to inspect.`]})]})}function Dh(){let{data:e}=k(`/api/json/license`,[V([`counters-updated`])[`counters-updated`]]);return!e||e.tier!==`unlicensed`||e.status===`needs_reauth`||e.status===`needs_login`||e.eval_daily_limit===null||e.evals_today<e.eval_daily_limit?null:(0,D.jsxs)(`div`,{role:`alert`,className:`hig-banner hig-banner-error`,title:`Free tier daily eval limit reached — rules are being bypassed until quota resets`,children:[(0,D.jsx)(`span`,{children:`●`}),(0,D.jsxs)(`span`,{children:[`Quota exhausted — `,e.evals_today.toLocaleString(),`/`,e.eval_daily_limit.toLocaleString(),` evals used today. BLOCK and ASK rules are being bypassed (fail-open) until daily reset.`,` `,(0,D.jsx)(`a`,{href:e.upgrade_url,target:`_blank`,rel:`noopener noreferrer`,className:`underline font-medium`,children:`Upgrade to Pro →`})]})]})}function Oh(){let{data:e}=k(`/api/json/license`,[V([`counters-updated`])[`counters-updated`]]);if(!e||e.status!==`needs_reauth`)return null;let t=e.detail??`License JWT invalid or expired`;return(0,D.jsxs)(`div`,{role:`alert`,className:`hig-banner hig-banner-warning`,title:`Re-authentication required — paid-tier features are paused until you re-login`,children:[(0,D.jsx)(`span`,{children:`⚠`}),(0,D.jsxs)(`span`,{children:[`Re-authentication required — `,t,`. Run`,` `,(0,D.jsx)(`code`,{className:`font-mono`,children:`ssg auth login`}),` in your terminal to restore your tier.`]})]})}function kh(){let{data:e,refetch:t}=k(`/api/json/ask-mode`),[n,r]=(0,_.useState)(!1),i=e?.mode??`tty`;async function a(e){if(!(n||e===i)){r(!0);try{await fetch(`/api/json/ask-mode`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({mode:e})}),t()}finally{r(!1)}}}let o=i===`tty`;return(0,D.jsxs)(`button`,{onClick:()=>a(o?`dashboard`:`tty`),disabled:n,className:`chip cursor-pointer hover:bg-[var(--color-fill-2)] transition-colors disabled:opacity-50`,title:o?`ASK decisions prompt in the native IDE/TTY. Click to route to dashboard.`:`ASK decisions queue on /approvals. Click to route to native prompt.`,children:[(0,D.jsx)(`span`,{className:`status-dot ${o?`bg-[var(--color-hig-blue)]`:`bg-[var(--color-hig-purple)]`}`}),(0,D.jsxs)(`span`,{className:`hidden sm:inline`,children:[`Ask · `,o?`Native`:`Dashboard`]})]})}function Ah(e){let t=new Date(e);return`${t.getHours().toString().padStart(2,`0`)}:${t.getMinutes().toString().padStart(2,`0`)}`}var jh={on:`soft`,soft:`audit`,audit:`off`,off:`on`};function Mh(){let{data:e,refetch:t}=k(`/api/json/mode`,[V([`mode-changed`])[`mode-changed`]]),[n,r]=(0,_.useState)(!1),i=e?.mode??`on`;async function a(e,i){if(!n){r(!0);try{let n={mode:e};typeof i==`number`&&i>0&&(n.forMs=i),await fetch(`/api/json/mode`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify(n)}),t()}finally{r(!1)}}}let o=i===`on`?`bg-[var(--color-hig-green)]`:i===`soft`?`bg-[var(--color-hig-yellow)]`:i===`audit`?`bg-[var(--color-hig-orange)]`:`bg-[var(--color-hig-red)]`,s=e?.rearmAt!==void 0&&i!==`on`?` · until ${Ah(e.rearmAt)}`:``,c=`SSG · ${i.toUpperCase()}${s}`;return(0,D.jsxs)(`button`,{"data-tutorial":`app-mode`,onClick:e=>{e.shiftKey?a(i===`off`?`audit`:`on`):a(jh[i])},disabled:n,className:`chip cursor-pointer hover:bg-[var(--color-fill-2)] transition-colors disabled:opacity-50`,title:i===`on`?`SSG ON — rules enforce normally. Click to cycle: On → Soft → Audit → Off.`:i===`soft`?`SSG SOFT — blocks downgraded to prompts, prompts downgraded to logs. Click for Audit; Shift+Click to resume On.`:i===`audit`?`SSG AUDIT — rules log only, nothing blocked or prompted. Click for Off; Shift+Click to resume On.`:`SSG OFF — kill switch engaged, evaluator returns allow. Click to resume On; Shift+Click for Audit.`,children:[(0,D.jsx)(`span`,{className:`status-dot ${o}`}),(0,D.jsx)(`span`,{className:`hidden sm:inline`,children:c})]})}function Nh(){let{data:e,refetch:t}=k(`/api/json/mode`,[V([`mode-changed`])[`mode-changed`]]),n=e?.mode??`on`;if(n===`on`)return null;let r=e?.rearmAt===void 0?``:` Auto-restores at ${Ah(e.rearmAt)}.`,i=n===`off`?`SSG is OFF — kill switch engaged.`:n===`soft`?`SSG is in SOFT mode — non-blocking enforcement.`:`SSG is in AUDIT mode — log-only.`,a=n===`off`?`Every tool call is being allowed without evaluation.${r}`:n===`soft`?`Block decisions are being downgraded to prompts and prompts to logs. Workflow keeps moving; signal still surfaces in the audit log.${r}`:`Rules still match for the audit log, but nothing is being blocked or prompted.${r}`,o=n===`off`?`hig-banner hig-banner-error`:`hig-banner hig-banner-warning`;async function s(){await fetch(`/api/json/mode`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({mode:`on`})}),t()}return(0,D.jsxs)(`div`,{className:o,children:[(0,D.jsxs)(`svg`,{className:`shrink-0`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`}),(0,D.jsx)(`line`,{x1:`12`,y1:`9`,x2:`12`,y2:`13`}),(0,D.jsx)(`line`,{x1:`12`,y1:`17`,x2:`12.01`,y2:`17`})]}),(0,D.jsxs)(`span`,{className:`flex-1`,children:[(0,D.jsx)(`span`,{className:`font-semibold`,children:i}),` `,a]}),(0,D.jsx)(`button`,{onClick:s,className:`hig-button hig-button-small`,title:`Re-enable normal rule enforcement`,children:`Resume`})]})}function Ph({onRefresh:e}){return(0,D.jsx)(`button`,{onClick:e,className:`hig-button`,title:`Reset page — clears stale graph state without dropping SSE`,"aria-label":`Refresh page`,children:(0,D.jsxs)(`svg`,{width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M21 12a9 9 0 1 1-3-6.7`}),(0,D.jsx)(`polyline`,{points:`21 3 21 9 15 9`})]})})}function Fh(){return(0,D.jsx)(`button`,{onClick:()=>{try{window.location.reload()}catch{}},className:`hig-button`,title:`Reload dashboard — fetches fresh assets (use after a desktop upgrade)`,"aria-label":`Reload dashboard`,children:(0,D.jsxs)(`svg`,{width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M3 12a9 9 0 1 1 3 6.7`}),(0,D.jsx)(`polyline`,{points:`3 21 3 15 9 15`}),(0,D.jsx)(`path`,{d:`M3 3v6h6`})]})})}function Ih(){let{data:e}=k(`/api/json/mcp-status`,[V([`activity-updated`])[`activity-updated`]]),t=e?.status??`inactive`;if(t===`inactive`)return null;let n=t===`active`?`bg-[var(--color-hig-blue)]`:`bg-[var(--color-fg-3)]`,r=t===`active`?`MCP active`:`MCP idle`;return(0,D.jsxs)(`div`,{className:`chip`,title:t===`active`?`MCP server: ${e?.recentCount??0} evals in last 5 min`:`MCP server: ${e?.totalCount??0} total evals`,children:[(0,D.jsx)(`span`,{className:`status-dot ${n}`}),(0,D.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function Lh(){let{data:e}=k(`/api/json/adapters`);if(!e)return null;let t=e.adapters.find(e=>e.active);if(!t)return null;let n=t.id===`generic`;return(0,D.jsxs)(`a`,{href:`/agents`,className:`chip ss-agent-chip cursor-pointer transition-all`,title:n?`No specific AI client detected — SSG is running in generic adapter mode. Click to wire one up.`:`Connected agent: ${t.displayName} (${t.vendor}). Click to manage.`,style:{"--agent-accent":t.accent},"data-generic":n?`true`:`false`,children:[(0,D.jsx)(`span`,{className:`status-dot`,style:{background:t.accent,boxShadow:`0 0 6px color-mix(in oklab, ${t.accent} 60%, transparent)`}}),(0,D.jsx)(`span`,{className:`hidden sm:inline`,children:t.displayName})]})}function Rh(e,t){if(e===`/`)return t===`newcomer`?(0,D.jsx)(vh,{}):(0,D.jsx)(sl,{});if(e===`/classic`)return(0,D.jsx)(Jl,{});if(e===`/graph`)return(0,D.jsx)(vd,{});if(e===`/sessions`)return(0,D.jsx)(Nm,{});if(e.startsWith(`/sessions/`)){let t=decodeURIComponent(e.slice(10));if(t)return(0,D.jsx)(Sm,{sessionKey:t})}if(e===`/debug`)return(0,D.jsx)(Zl,{});if(e===`/rules`)return(0,D.jsx)(fm,{});if(e===`/audit`)return(0,D.jsx)(Wi,{});if(e===`/approvals`)return(0,D.jsx)(mi,{});if(e===`/profile`)return(0,D.jsx)(yp,{});if(e===`/agents`)return(0,D.jsx)(bn,{});if(e===`/notifications`)return(0,D.jsx)(Qd,{});if(e===`/setup`)return(0,D.jsx)(Wm,{});if(e===`/try`)return(0,D.jsx)(ih,{});if(e===`/guardrails`)return(0,D.jsx)(wd,{});if(e===`/hub/connect`)return(0,D.jsx)($,{});if(e===`/hub/publish`)return(0,D.jsx)(Ld,{});if(e.startsWith(`/hub/`)){let t=e.slice(5);if(t)return(0,D.jsx)(bd,{id:t})}return e===`/hub`?(0,D.jsx)(Fd,{}):e===`/monitor`?(0,D.jsx)(Xd,{}):e===`/observability`?(0,D.jsx)(Ef,{}):e===`/plugins`?(0,D.jsx)(ap,{}):e===`/publish-plugin`?(0,D.jsx)(jf,{}):e===`/support`?(0,D.jsx)(lh,{}):(0,D.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-24 text-[var(--color-fg-3)]`,children:[(0,D.jsx)(`p`,{className:`overline mb-2`,children:`Error · 404`}),(0,D.jsx)(`p`,{className:`text-sm`,children:`Page not found`}),(0,D.jsx)(`a`,{href:`/`,className:`mt-4 text-[12px] text-[var(--color-hig-blue)] hover:underline`,children:`← Back to dashboard`})]})}function zh(e,t){return e===`/`?t===`newcomer`?`Home`:`Dashboard`:e===`/classic`?`Classic Dashboard`:e===`/graph`?`Graph`:e===`/sessions`?`Sessions`:e.startsWith(`/sessions/`)?`Session Inspector`:e===`/debug`?`Debug`:e===`/rules`?`Rules`:e===`/audit`?t===`newcomer`?`Activity`:`Audit`:e===`/approvals`?`Approvals`:e===`/profile`?`Profile`:e===`/agents`?`Agents`:e===`/notifications`?`Notifications`:e===`/setup`?`Setup Status`:e===`/try`?`Try It`:e===`/guardrails`?`Guardrails`:e===`/hub/connect`?`Connect Hub`:e===`/hub/publish`?`Publish to Hub`:e.startsWith(`/hub/`)||e===`/hub`?`Hub`:e===`/monitor`?`Monitor`:e===`/observability`?`Observability`:e===`/plugins`?`Plugins`:e===`/publish-plugin`?`Publish a Plugin`:e===`/support`?`Support & Feedback`:`SigmaShake`}function Bh(e){history.pushState(null,``,e),window.dispatchEvent(new PopStateEvent(`popstate`))}function Vh({count:e}){let[t,n]=(0,_.useState)(!1);return t||e===0?null:(0,D.jsxs)(`div`,{className:`hig-banner hig-banner-warning`,children:[(0,D.jsxs)(`svg`,{className:`shrink-0`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`}),(0,D.jsx)(`line`,{x1:`12`,y1:`9`,x2:`12`,y2:`13`}),(0,D.jsx)(`line`,{x1:`12`,y1:`17`,x2:`12.01`,y2:`17`})]}),(0,D.jsxs)(`span`,{className:`flex-1`,children:[(0,D.jsxs)(`span`,{className:`font-semibold`,children:[e,` other `,e===1?`tab`:`tabs`,` open.`]}),` `,`Each tab holds a live SSE connection. Browsers limit connections per origin — too many tabs will prevent this page from loading.`,` `,(0,D.jsx)(`span`,{className:`opacity-70`,children:`Close other tabs to restore full live-update functionality.`})]}),(0,D.jsx)(`button`,{onClick:()=>n(!0),className:`opacity-60 hover:opacity-100 transition-opacity shrink-0 cursor-pointer`,title:`Dismiss`,children:(0,D.jsxs)(`svg`,{width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,D.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})})]})}function Hh({onCollapse:e}){let{data:t}=k(`/api/health`),n=t?.version;return(0,D.jsxs)(`div`,{className:`hig-sidebar-footer`,children:[(0,D.jsx)(`span`,{className:`hig-sidebar-version`,title:n?`SigmaShake Governance v${n}`:`daemon version unavailable`,children:n?(0,D.jsxs)(D.Fragment,{children:[`ssg `,(0,D.jsxs)(`b`,{children:[`v`,n]})]}):`ssg`}),(0,D.jsx)(`button`,{type:`button`,className:`hig-sidebar-collapse`,"aria-label":`Collapse sidebar`,title:`Collapse sidebar`,onClick:e,children:(0,D.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M11 7l-5 5 5 5`}),(0,D.jsx)(`path`,{d:`M18 7l-5 5 5 5`})]})})]})}function Uh({pathname:e,navSections:t,open:n,onClose:r,onCollapse:i}){let a=t=>t===`/`?e===`/`:e.startsWith(t);return(0,D.jsxs)(`aside`,{className:`hig-sidebar ${n?`open`:``}`,"aria-label":`Primary`,"data-tutorial":`app-sidebar`,children:[(0,D.jsxs)(`div`,{className:`hig-sidebar-header`,children:[(0,D.jsx)(`span`,{className:`hig-app-icon`,"aria-hidden":`true`,children:`SS`}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`hig-app-name`,children:`SigmaShake`}),(0,D.jsx)(`div`,{className:`hig-app-meta`,children:`Governance`})]}),(0,D.jsx)(`button`,{className:`hig-sidebar-close`,"aria-label":`Close sidebar`,onClick:r,children:(0,D.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 18 18`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,children:[(0,D.jsx)(`line`,{x1:`4`,y1:`4`,x2:`14`,y2:`14`}),(0,D.jsx)(`line`,{x1:`14`,y1:`4`,x2:`4`,y2:`14`})]})})]}),(0,D.jsx)(`nav`,{className:`hig-sidebar-nav`,children:t.map(e=>(0,D.jsxs)(`div`,{className:`hig-sidebar-section`,children:[(0,D.jsx)(`div`,{className:`hig-sidebar-section-title`,children:e.title}),e.items.map(e=>(0,D.jsxs)(`a`,{href:e.path,onClick:r,className:`hig-sidebar-item`,"data-active":a(e.path)?`true`:`false`,children:[(0,D.jsx)(`span`,{className:`hig-sidebar-icon`,"aria-hidden":`true`,children:yh[e.icon]}),(0,D.jsx)(`span`,{children:e.label})]},e.path))]},e.title))}),(0,D.jsx)(Hh,{onCollapse:i})]})}function Wh(){let[e,t]=(0,_.useState)(window.location.pathname),[n,r]=(0,_.useState)(0),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(()=>{try{return localStorage.getItem(`ssg:sidebar-collapsed`)===`1`}catch{return!1}}),{otherTabCount:c}=$t(),{mode:l}=Ct(),u=Sh(l),d=zh(e,l);return(0,_.useEffect)(()=>{let e=()=>t(window.location.pathname);return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[]),(0,_.useEffect)(()=>{a(!1)},[]),(0,_.useEffect)(()=>{try{localStorage.setItem(`ssg:sidebar-collapsed`,o?`1`:`0`)}catch{}},[o]),(0,_.useEffect)(()=>{let e=e=>{let t=e.target.closest(`a`);if(!t)return;let n=t.getAttribute(`href`);!n||n.startsWith(`http`)||n.startsWith(`//`)||n===`/workspace`||n.startsWith(`/workspace/`)||n.startsWith(`/plugins/`)||(e.preventDefault(),Bh(n))};return document.addEventListener(`click`,e),()=>document.removeEventListener(`click`,e)},[]),(0,D.jsxs)(`div`,{className:`hig-app`,"data-sidebar-collapsed":o?`true`:`false`,children:[(0,D.jsx)(Uh,{pathname:e,navSections:u,open:i,onClose:()=>a(!1),onCollapse:()=>s(!0)}),i&&(0,D.jsx)(`div`,{className:`hig-sidebar-backdrop`,"aria-hidden":`true`,onClick:()=>a(!1)}),(0,D.jsxs)(`div`,{className:`hig-window`,children:[(0,D.jsxs)(`header`,{className:`hig-toolbar`,children:[(0,D.jsx)(`button`,{"aria-label":`Toggle sidebar`,className:`hig-sidebar-toggle hig-button hig-button-small`,onClick:()=>{window.matchMedia(`(min-width: 901px)`).matches?s(e=>!e):a(e=>!e)},children:(0,D.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 18 18`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,children:[(0,D.jsx)(`line`,{x1:`2`,y1:`5`,x2:`16`,y2:`5`}),(0,D.jsx)(`line`,{x1:`2`,y1:`9`,x2:`16`,y2:`9`}),(0,D.jsx)(`line`,{x1:`2`,y1:`13`,x2:`16`,y2:`13`})]})}),(0,D.jsx)(`h1`,{className:`hig-toolbar-title`,children:d}),(0,D.jsx)(ht,{pathname:e,mode:l}),(0,D.jsx)(`div`,{className:`hig-toolbar-spacer`}),(0,D.jsxs)(`div`,{className:`hig-toolbar-controls hidden md:flex`,children:[c>0&&(0,D.jsxs)(`span`,{className:`chip`,style:{color:`var(--color-hig-orange)`,background:`color-mix(in oklab, var(--color-hig-orange) 14%, transparent)`},title:`${c} other tab${c===1?``:`s`} open — may cause connection issues`,children:[c+1,` tabs`]}),(0,D.jsx)(qt,{}),(0,D.jsx)(Mh,{}),(0,D.jsx)(kh,{}),(0,D.jsx)(Lh,{}),(0,D.jsx)(Ih,{}),(0,D.jsx)(Th,{}),(0,D.jsx)(Ph,{onRefresh:()=>r(e=>e+1)}),(0,D.jsx)(Fh,{}),(0,D.jsx)(wt,{}),(0,D.jsx)(et,{}),(0,D.jsx)(O,{}),(0,D.jsx)(Gt,{})]})]}),(0,D.jsx)(Nh,{}),(0,D.jsx)(Vh,{count:c}),(0,D.jsx)(Oh,{}),(0,D.jsx)(Dh,{}),(0,D.jsx)(Eh,{}),(e===`/`||e===`/graph`||e===`/sessions`||e.startsWith(`/sessions/`)||e===`/audit`)&&(0,D.jsx)(Ue,{}),(0,D.jsx)(`main`,{className:`hig-content px-6 py-6`,children:Rh(e,l)},n)]})]})}var Gh=document.getElementById(`app-root`);if(!Gh)throw Error(`Missing #app-root`);g.createRoot(Gh).render((0,D.jsx)(_.StrictMode,{children:(0,D.jsx)(Wh,{})}));
57
+ disabled:opacity-40 disabled:cursor-not-allowed`,children:`Run`})]})]})]})]})}var ch=[{value:`issue`,label:`Bug / Issue`,hint:`Something is broken`},{value:`feature_request`,label:`Feature Request`,hint:`Suggest an improvement`},{value:`question`,label:`Question`,hint:`How does X work?`},{value:`incident`,label:`Incident`,hint:`Urgent outage or data concern`}],lh=[{value:`p4`,label:`P4 — Low`},{value:`p3`,label:`P3 — Normal`},{value:`p2`,label:`P2 — High (4h SLA)`},{value:`p1`,label:`P1 — Critical (1h SLA)`}],uh=5,dh=8*1024*1024;function fh(){let[e,t]=(0,_.useState)(`issue`),[n,r]=(0,_.useState)(`p3`),[i,a]=(0,_.useState)(``),[o,s]=(0,_.useState)(``),[c,l]=(0,_.useState)(``),[u,d]=(0,_.useState)([]),[f,p]=(0,_.useState)(!1),[m,h]=(0,_.useState)(null),[g,v]=(0,_.useState)(null),[y,b]=(0,_.useState)(!1),[x,S]=(0,_.useState)(``),C=(0,_.useRef)(null);(0,_.useEffect)(()=>{fetch(`/api/json/profile`,{headers:U()}).then(e=>e.ok?e.json():null).then(e=>{e?.email&&l(e.email)}).catch(()=>{})},[]),(0,_.useEffect)(()=>{!y||g||fetch(`/api/support/diagnostics?route=${encodeURIComponent(window.location.pathname)}`).then(e=>e.ok?e.json():null).then(e=>v(e)).catch(()=>{})},[y,g]),(0,_.useEffect)(()=>{let e=new URL(window.location.href),n=e.searchParams.get(`error`),r=e.searchParams.get(`from`);if(n||r){t(`issue`);let e=r?`Page: ${r}\n\n`:``,i=n?`Error: ${n}\n\n`:``;s(t=>t||`${e}${i}`)}},[]);function w(e){e.preventDefault(),E(Array.from(e.dataTransfer.files))}function T(e){E(Array.from(e.target.files??[])),C.current&&(C.current.value=``)}function E(e){S(``);let t=e.filter(e=>e.type.startsWith(`image/`));t.length<e.length&&S(`Only image files are accepted.`);let n=uh-u.length,r=t.slice(0,n);r.length<t.length&&S(`Maximum ${uh} images. Some were dropped.`);let i=r.filter(e=>e.size>dh);if(i.length>0){S(`"${i[0].name}" exceeds 8 MiB.`);return}let a=r.map(e=>({file:e,preview:URL.createObjectURL(e)}));d(e=>[...e,...a])}function O(e){d(t=>(URL.revokeObjectURL(t[e].preview),t.filter((t,n)=>n!==e)))}async function k(t){t.preventDefault(),p(!0),h(null);let r=new FormData;r.append(`category`,e),r.append(`severity`,n),r.append(`subject`,i.trim()),r.append(`description`,o.trim()),r.append(`contact_email`,c.trim()),r.append(`route`,window.location.pathname);for(let{file:e}of u)r.append(`images`,e,e.name);try{let e=await(await fetch(`/api/support/feedback`,{method:`POST`,headers:U(),body:r})).json();h(e),e.ok&&(a(``),s(``),d([]))}catch(e){h({ok:!1,error:e instanceof Error?e.message:`Network error`})}finally{p(!1)}}return(0,D.jsxs)(`div`,{className:`max-w-2xl mx-auto space-y-5`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`h1`,{className:`text-xl font-medium tracking-tight text-[var(--color-fg-0)]`,children:`Support & Feedback`}),(0,D.jsx)(`p`,{className:`text-[12px] text-[var(--color-fg-3)] mt-1 font-mono`,children:`report a bug, request a feature, or ask a question`})]}),m?.ok?(0,D.jsx)(K,{children:(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`space-y-3 py-2`,children:[(0,D.jsxs)(`p`,{className:`text-sm text-emerald-400 font-mono`,children:[`✓ `,m.message??`Ticket created.`]}),m.ticket_id&&(0,D.jsxs)(`p`,{className:`text-xs text-[var(--color-fg-3)] font-mono`,children:[`Ticket ID:`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:m.ticket_id})]}),(0,D.jsx)(`button`,{className:`text-[12px] text-[var(--color-brand)] hover:underline font-mono`,onClick:()=>h(null),children:`Submit another`})]})})}):(0,D.jsxs)(`form`,{onSubmit:k,className:`space-y-4`,children:[(0,D.jsx)(K,{children:(0,D.jsxs)(J,{children:[(0,D.jsx)(`label`,{className:`block overline mb-2`,children:`type`}),(0,D.jsx)(`div`,{className:`grid grid-cols-2 gap-2`,children:ch.map(n=>(0,D.jsxs)(`button`,{type:`button`,onClick:()=>t(n.value),className:`text-left px-3 py-2 rounded-sm border text-xs font-mono transition-colors ${e===n.value?`border-[var(--color-brand)]/50 bg-[var(--color-brand)]/10 text-[var(--color-fg-0)]`:`border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:border-[var(--color-line-0)]`}`,children:[(0,D.jsx)(`span`,{className:`block font-medium text-[var(--color-fg-1)]`,children:n.label}),(0,D.jsx)(`span`,{className:`block text-[11px] mt-0.5`,children:n.hint})]},n.value))})]})}),e===`incident`&&(0,D.jsx)(K,{children:(0,D.jsxs)(J,{children:[(0,D.jsx)(`label`,{className:`block overline mb-2`,children:`severity`}),(0,D.jsx)(`div`,{className:`flex gap-2 flex-wrap`,children:lh.map(e=>(0,D.jsx)(`button`,{type:`button`,onClick:()=>r(e.value),className:`px-3 py-1.5 rounded-sm border text-xs font-mono transition-colors ${n===e.value?`border-[var(--color-brand)]/50 bg-[var(--color-brand)]/10 text-[var(--color-fg-0)]`:`border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:border-[var(--color-line-0)]`}`,children:e.label},e.value))})]})}),(0,D.jsx)(K,{children:(0,D.jsx)(J,{children:(0,D.jsxs)(`div`,{className:`space-y-4`,children:[(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:`block overline mb-1.5`,children:`subject`}),(0,D.jsx)(`input`,{"data-tutorial":`support-subject`,type:`text`,value:i,onChange:e=>a(e.target.value),placeholder:`Short summary (required)`,maxLength:200,required:!0,className:`w-full bg-[var(--color-surface-0)] border border-[var(--color-line-1)] text-[var(--color-fg-1)] text-sm rounded-sm px-3 py-2 focus:outline-none focus:border-[var(--color-brand)]/50 placeholder:text-[var(--color-fg-4)] font-mono`})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:`block overline mb-1.5`,children:`description`}),(0,D.jsx)(`textarea`,{"data-tutorial":`support-desc`,value:o,onChange:e=>s(e.target.value),placeholder:`Describe the issue in detail (10–10000 characters)`,minLength:10,maxLength:1e4,required:!0,rows:6,className:`w-full bg-[var(--color-surface-0)] border border-[var(--color-line-1)] text-[var(--color-fg-1)] text-sm rounded-sm px-3 py-2 focus:outline-none focus:border-[var(--color-brand)]/50 placeholder:text-[var(--color-fg-4)] font-mono resize-y`})]}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`label`,{className:`block overline mb-1.5`,children:`contact email`}),(0,D.jsx)(`input`,{type:`email`,value:c,onChange:e=>l(e.target.value),placeholder:`your@email.com`,required:!0,className:`w-full bg-[var(--color-surface-0)] border border-[var(--color-line-1)] text-[var(--color-fg-1)] text-sm rounded-sm px-3 py-2 focus:outline-none focus:border-[var(--color-brand)]/50 placeholder:text-[var(--color-fg-4)] font-mono`})]})]})})}),(0,D.jsx)(K,{children:(0,D.jsxs)(J,{children:[(0,D.jsxs)(`label`,{className:`block overline mb-2`,children:[`screenshots / attachments`,` `,(0,D.jsxs)(`span`,{className:`normal-case text-[var(--color-fg-4)] font-mono font-normal`,children:[`(optional, up to `,uh,` images)`]})]}),u.length<uh&&(0,D.jsxs)(`div`,{"data-tutorial":`support-attach`,onDragOver:e=>e.preventDefault(),onDrop:w,onClick:()=>C.current?.click(),className:`border border-dashed border-[var(--color-line-1)] rounded-sm p-6 text-center cursor-pointer hover:border-[var(--color-brand)]/50 transition-colors`,children:[(0,D.jsxs)(`p`,{className:`text-xs text-[var(--color-fg-3)] font-mono`,children:[`drag & drop images, or`,` `,(0,D.jsx)(`span`,{className:`text-[var(--color-brand)]`,children:`click to browse`})]}),(0,D.jsx)(`p`,{className:`text-[11px] text-[var(--color-fg-4)] mt-1 font-mono`,children:`PNG · JPEG · WebP · GIF · HEIC — max 8 MiB each`})]}),(0,D.jsx)(`input`,{ref:C,type:`file`,accept:`image/*`,multiple:!0,className:`hidden`,onChange:T}),x&&(0,D.jsx)(`p`,{className:`text-xs text-red-400 font-mono mt-2`,children:x}),u.length>0&&(0,D.jsx)(`div`,{className:`mt-3 flex flex-wrap gap-2`,children:u.map((e,t)=>(0,D.jsxs)(`div`,{className:`relative group`,children:[(0,D.jsx)(`img`,{src:e.preview,alt:e.file.name,className:`h-20 w-20 object-cover rounded-sm border border-[var(--color-line-1)]`}),(0,D.jsx)(`button`,{type:`button`,onClick:()=>O(t),className:`absolute -top-1.5 -right-1.5 w-5 h-5 rounded-full bg-[var(--color-surface-0)] border border-[var(--color-line-1)] text-[var(--color-fg-3)] hover:text-red-400 text-[10px] font-mono flex items-center justify-center`,title:`Remove`,children:`✕`}),(0,D.jsx)(`p`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] mt-0.5 max-w-[80px] truncate`,children:e.file.name})]},t))})]})}),(0,D.jsxs)(`div`,{className:`rounded-sm border border-[var(--color-line-1)] overflow-hidden`,children:[(0,D.jsxs)(`button`,{type:`button`,onClick:()=>b(e=>!e),className:`w-full flex items-center justify-between px-3 py-2 text-xs font-mono text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] bg-[var(--color-surface-0)] transition-colors`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`diagnostics that will be attached`}),(0,D.jsx)(`span`,{children:y?`▲`:`▼`})]}),y&&(0,D.jsx)(`div`,{className:`px-3 py-2 bg-[var(--color-surface-0)] border-t border-[var(--color-line-1)] max-h-64 overflow-auto`,children:g?(0,D.jsx)(`pre`,{className:`text-[10px] font-mono text-[var(--color-fg-3)] whitespace-pre-wrap break-all`,children:JSON.stringify(g,null,2)}):(0,D.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`Loading…`})})]}),m&&!m.ok&&(0,D.jsx)(`div`,{className:`rounded-sm border border-red-500/25 bg-red-500/5 px-3 py-2 text-xs text-red-300 font-mono`,children:m.error??`Submission failed. Please try again.`}),(0,D.jsx)(G,{type:`submit`,variant:`primary`,disabled:f,children:f?`submitting…`:`submit feedback`})]})]})}function ph(e){let t=Date.now()-e,n=Math.floor(t/1e3);if(n<60)return`just now`;let r=Math.floor(n/60);if(r<60)return`${r}m ago`;let i=Math.floor(r/60);return i<24?`${i}h ago`:new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}var mh={block:`var(--color-hig-red)`,ask:`var(--color-hig-orange)`,log:`var(--color-hig-blue)`,allow:`var(--color-hig-green)`,force:`var(--color-hig-purple)`};function hh(e){switch(e){case`block`:return`Blocked`;case`ask`:return`Held for review`;case`log`:return`Logged`;case`force`:return`Force-allowed`;default:return`Allowed`}}function gh({type:e}){let t={fill:`none`,stroke:`currentColor`,strokeWidth:1.6,strokeLinecap:`round`,strokeLinejoin:`round`,viewBox:`0 0 24 24`};return e===`code`?(0,D.jsxs)(`svg`,{...t,width:`22`,height:`22`,children:[(0,D.jsx)(`path`,{d:`M9 7l-5 5 5 5M15 7l5 5-5 5`}),(0,D.jsx)(`path`,{d:`M14 4l-4 16`,opacity:`0.55`})]}):e===`docs`?(0,D.jsxs)(`svg`,{...t,width:`22`,height:`22`,children:[(0,D.jsx)(`path`,{d:`M5 4h9l5 5v11a1 1 0 01-1 1H5a1 1 0 01-1-1V5a1 1 0 011-1z`}),(0,D.jsx)(`path`,{d:`M14 4v5h5`}),(0,D.jsx)(`path`,{d:`M8 13h8M8 17h5`,opacity:`0.7`})]}):(0,D.jsxs)(`svg`,{...t,width:`22`,height:`22`,children:[(0,D.jsx)(`path`,{d:`M3 12a9 9 0 109-9`}),(0,D.jsx)(`path`,{d:`M12 3v9l6 3`})]})}function _h(){let{data:e}=k(`/api/json/counters`,[V([`counters-updated`])[`counters-updated`]]),t=e?.evals_today??0,n=e?.blocked_today??0,r=e?.asked_today??0;return(0,D.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-6 gap-y-2`,children:[(0,D.jsx)(vh,{value:t,label:`evaluated`,tone:`default`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsx)(vh,{value:n,label:`blocked`,tone:`red`}),(0,D.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,D.jsx)(vh,{value:r,label:`held for you`,tone:`orange`}),(0,D.jsx)(`span`,{className:`text-[11px] ml-auto`,style:{color:`var(--color-fg-3)`},children:`Today`})]})}function vh({value:e,label:t,tone:n}){return(0,D.jsxs)(`span`,{className:`inline-flex items-baseline gap-1.5`,children:[(0,D.jsx)(`span`,{className:`font-semibold tabular-nums`,style:{color:n===`red`?`var(--color-hig-red)`:n===`orange`?`var(--color-hig-orange)`:`var(--color-fg-0)`,fontSize:`20px`,lineHeight:1,letterSpacing:`-0.018em`},children:e.toLocaleString()}),(0,D.jsx)(`span`,{style:{color:`var(--color-fg-3)`,fontSize:`12px`,letterSpacing:`-0.005em`},children:t})]})}function yh({href:e,title:t,desc:n,tone:r,type:i,cta:a}){let o=r===`orange`?`var(--color-hig-orange)`:r===`indigo`?`var(--color-hig-indigo)`:`var(--color-hig-blue)`;return(0,D.jsx)(`a`,{href:e,className:`group block rounded-2xl px-4 py-4 transition-all`,style:{border:`0.5px solid var(--color-line-1)`,background:`var(--color-surface-1)`,textDecoration:`none`,color:`inherit`,boxShadow:`var(--hig-shadow-1)`},children:(0,D.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,D.jsx)(`span`,{className:`flex items-center justify-center rounded-xl shrink-0`,style:{width:`40px`,height:`40px`,color:o,background:`color-mix(in oklab, ${o} 14%, transparent)`},children:(0,D.jsx)(gh,{type:i})}),(0,D.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,D.jsx)(`div`,{className:`text-[14px] font-semibold leading-tight`,style:{color:`var(--color-fg-0)`,letterSpacing:`-0.005em`},children:t}),(0,D.jsx)(`div`,{className:`text-[12px] mt-1 leading-snug`,style:{color:`var(--color-fg-2)`},children:n}),(0,D.jsxs)(`div`,{className:`text-[11.5px] mt-2 font-medium inline-flex items-center gap-1 transition-all`,style:{color:o},children:[a,(0,D.jsx)(`span`,{"aria-hidden":`true`,className:`transition-transform group-hover:translate-x-0.5`,children:`→`})]})]})]})})}function bh(){let{data:e}=k(`/api/state/activity?limit=5`,[V([`activity-updated`])[`activity-updated`]]),[,t]=(0,_.useState)(0);return(0,_.useEffect)(()=>{let e=setInterval(()=>t(e=>e+1),6e4);return()=>clearInterval(e)},[]),!e||e.length===0?(0,D.jsxs)(`div`,{className:`py-6 text-center`,style:{color:`var(--color-fg-3)`},children:[(0,D.jsx)(`p`,{style:{fontSize:`12.5px`,color:`var(--color-fg-2)`},children:`Waiting for your first agent action.`}),(0,D.jsx)(`p`,{style:{fontSize:`11px`,color:`var(--color-fg-3)`,marginTop:`4px`},children:`Anything your AI tries — read, write, run — will appear here in real time.`})]}):(0,D.jsx)(`div`,{children:e.slice(0,5).map((e,t)=>(0,D.jsxs)(`div`,{className:`hig-feed-row`,children:[(0,D.jsx)(`span`,{className:`hig-feed-row-dot`,style:{background:mh[e.decision]??`var(--color-fg-3)`,boxShadow:`0 0 0 3px ${e.decision===`block`?`color-mix(in oklab, var(--color-hig-red) 22%, transparent)`:e.decision===`ask`?`color-mix(in oklab, var(--color-hig-orange) 22%, transparent)`:`transparent`}`}}),(0,D.jsx)(`span`,{className:`hig-feed-row-decision`,style:{color:mh[e.decision]??`var(--color-fg-2)`},children:hh(e.decision)}),(0,D.jsx)(`span`,{style:{color:`var(--color-fg-3)`},children:`·`}),(0,D.jsx)(`span`,{className:`hig-feed-row-tool`,title:e.tool,children:Si(e.tool)}),(0,D.jsx)(`span`,{className:`hig-feed-row-time`,children:ph(e.timestamp)})]},e.id??t))})}function xh(){return(0,D.jsx)(`div`,{className:`relative`,children:(0,D.jsxs)(`div`,{className:`relative max-w-5xl mx-auto px-2 pt-6 pb-12 space-y-6`,children:[(0,D.jsxs)(`section`,{"data-tutorial":`wh-hero`,className:`rounded-2xl px-6 py-5 relative overflow-hidden`,style:{border:`0.5px solid var(--color-line-1)`,background:`radial-gradient(120% 100% at 0% 0%, color-mix(in oklab, var(--color-accent) 14%, transparent) 0%, transparent 55%), var(--color-surface-1)`,boxShadow:`var(--hig-shadow-1)`},children:[(0,D.jsx)(`div`,{className:`hig-eyebrow mb-2`,children:`SigmaShake · Guardrails for AI`}),(0,D.jsx)(`h1`,{className:`font-semibold tracking-tight leading-tight`,style:{color:`var(--color-fg-0)`,fontSize:`26px`,letterSpacing:`-0.018em`},children:`The seatbelt for AI agents.`}),(0,D.jsx)(`p`,{className:`mt-1.5 leading-relaxed`,style:{color:`var(--color-fg-2)`,fontSize:`13.5px`,maxWidth:`52ch`},children:`Watch every move your AI makes. Approve what matters, block what doesn't — without babysitting every step.`}),(0,D.jsx)(`div`,{className:`mt-4 pt-3`,style:{borderTop:`0.5px solid var(--color-line-0)`},children:(0,D.jsx)(_h,{})})]}),(0,D.jsx)(`section`,{children:(0,D.jsxs)(`div`,{"data-tutorial":`wh-actions`,className:`grid grid-cols-1 md:grid-cols-3 gap-3`,children:[(0,D.jsx)(yh,{href:`/guardrails?starter=coding`,tone:`orange`,type:`code`,title:`Code safely with AI`,desc:`Protect files, secrets, and git history from coding agents.`,cta:`Install pack`}),(0,D.jsx)(yh,{href:`/guardrails?starter=knowledge-work`,tone:`indigo`,type:`docs`,title:`Guard sensitive content`,desc:`Watch outbound email, file shares, and document changes.`,cta:`Install pack`}),(0,D.jsx)(yh,{href:`/audit`,tone:`blue`,type:`review`,title:`Review what your AI did`,desc:`Every action, decision, and reason — in one place.`,cta:`Open activity`})]})}),(0,D.jsxs)(`a`,{href:`/try`,"data-tutorial":`wh-try`,className:`group flex items-center justify-between gap-3 rounded-xl px-4 py-3 transition-all`,style:{border:`0.5px solid var(--color-line-1)`,background:`linear-gradient(90deg, color-mix(in oklab, var(--color-accent) 8%, transparent) 0%, transparent 60%), var(--color-surface-1)`,textDecoration:`none`,color:`inherit`},children:[(0,D.jsxs)(`div`,{className:`flex items-center gap-3 min-w-0`,children:[(0,D.jsx)(`span`,{className:`flex items-center justify-center w-8 h-8 rounded-full shrink-0`,style:{background:`linear-gradient(180deg, var(--color-accent) 0%, var(--color-brand-hover) 100%)`,color:`var(--color-accent-on)`,boxShadow:`inset 0 0.5px 0 rgba(255,255,255,0.30), 0 2px 8px color-mix(in oklab, var(--color-accent) 30%, transparent)`},children:(0,D.jsx)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,D.jsx)(`polygon`,{points:`6 4 20 12 6 20`,fill:`currentColor`,stroke:`none`})})}),(0,D.jsxs)(`div`,{className:`min-w-0`,children:[(0,D.jsx)(`div`,{className:`font-semibold text-[13.5px] leading-tight`,style:{color:`var(--color-fg-0)`,letterSpacing:`-0.005em`},children:`Try a scenario — see SigmaShake decide`}),(0,D.jsx)(`div`,{className:`text-[12px] mt-0.5`,style:{color:`var(--color-fg-3)`},children:`30-second dry-run · nothing actually runs.`})]})]}),(0,D.jsxs)(`span`,{className:`text-[12.5px] font-medium shrink-0 inline-flex items-center gap-1 transition-all`,style:{color:`var(--color-accent)`},children:[`Try it`,(0,D.jsx)(`span`,{"aria-hidden":`true`,className:`transition-transform group-hover:translate-x-0.5`,children:`→`})]})]}),(0,D.jsxs)(`section`,{children:[(0,D.jsxs)(`div`,{className:`flex items-baseline justify-between mb-2`,children:[(0,D.jsx)(`h2`,{className:`font-semibold tracking-tight`,style:{color:`var(--color-fg-0)`,fontSize:`15px`,letterSpacing:`-0.008em`},children:`Recent activity`}),(0,D.jsx)(`a`,{href:`/audit`,style:{fontSize:`12px`,color:`var(--color-hig-blue)`,fontWeight:500},children:`View all →`})]}),(0,D.jsx)(`div`,{style:{background:`var(--color-surface-1)`,border:`0.5px solid var(--color-line-1)`,borderRadius:`14px`,padding:`4px 16px`,boxShadow:`var(--hig-shadow-1)`},children:(0,D.jsx)(bh,{})})]})]})})}var Sh={dashboard:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`rect`,{x:`3`,y:`3`,width:`7`,height:`9`,rx:`1.5`}),(0,D.jsx)(`rect`,{x:`14`,y:`3`,width:`7`,height:`5`,rx:`1.5`}),(0,D.jsx)(`rect`,{x:`14`,y:`12`,width:`7`,height:`9`,rx:`1.5`}),(0,D.jsx)(`rect`,{x:`3`,y:`16`,width:`7`,height:`5`,rx:`1.5`})]}),graph:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`circle`,{cx:`6`,cy:`18`,r:`2.4`}),(0,D.jsx)(`circle`,{cx:`18`,cy:`6`,r:`2.4`}),(0,D.jsx)(`circle`,{cx:`18`,cy:`18`,r:`2.4`}),(0,D.jsx)(`circle`,{cx:`12`,cy:`11`,r:`2.4`}),(0,D.jsx)(`path`,{d:`M7.5 16.5l3-4M13.5 11.5l3-3.5M13.5 12l3 4.5`})]}),rules:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M9 5h11M9 12h11M9 19h11`}),(0,D.jsx)(`path`,{d:`M4 5l1 1 2-2M4 12l1 1 2-2M4 19l1 1 2-2`})]}),hub:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,D.jsx)(`path`,{d:`M3 12h18`}),(0,D.jsx)(`path`,{d:`M12 3a14 14 0 010 18M12 3a14 14 0 000 18`})]}),audit:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`circle`,{cx:`11`,cy:`11`,r:`6.5`}),(0,D.jsx)(`path`,{d:`M21 21l-5-5`})]}),approvals:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M5 7h14v12a2 2 0 01-2 2H7a2 2 0 01-2-2z`}),(0,D.jsx)(`path`,{d:`M9 3v4M15 3v4`}),(0,D.jsx)(`path`,{d:`M9 13l2 2 4-4`})]}),profile:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`circle`,{cx:`12`,cy:`8`,r:`4`}),(0,D.jsx)(`path`,{d:`M4 21c0-4.4 3.6-8 8-8s8 3.6 8 8`})]}),monitor:(0,D.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,D.jsx)(`path`,{d:`M3 12h3l3-7 4 14 3-7h5`})}),observability:(0,D.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,D.jsx)(`path`,{d:`M4 20h16M7 16V8M11 16V4M15 16v-6M19 16v-3`})}),debug:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`rect`,{x:`7`,y:`7`,width:`10`,height:`12`,rx:`5`}),(0,D.jsx)(`path`,{d:`M12 7V4M9 4l3 3 3-3`}),(0,D.jsx)(`path`,{d:`M5 11l2-1M5 18l2-1M19 11l-2-1M19 18l-2-1`})]}),home:(0,D.jsx)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,D.jsx)(`path`,{d:`M3 11l9-7 9 7v9a2 2 0 01-2 2h-3v-7H10v7H5a2 2 0 01-2-2z`})}),guardrails:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M12 3l8 3.7v6.3c0 5-3.5 9.6-8 11-4.5-1.4-8-6-8-11V6.7L12 3z`}),(0,D.jsx)(`path`,{d:`M9 12l2 2 4-4`})]}),tryit:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M9 3v6L4.5 18a2 2 0 001.7 3h11.6a2 2 0 001.7-3L15 9V3`}),(0,D.jsx)(`path`,{d:`M8 3h8`})]}),agents:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`circle`,{cx:`8`,cy:`9`,r:`3`}),(0,D.jsx)(`circle`,{cx:`16`,cy:`9`,r:`3`}),(0,D.jsx)(`path`,{d:`M3 19c.7-2.5 2.6-4 5-4`}),(0,D.jsx)(`path`,{d:`M21 19c-.7-2.5-2.6-4-5-4`}),(0,D.jsx)(`path`,{d:`M9 17.5c.8-1 1.8-1.5 3-1.5s2.2.5 3 1.5`})]}),notifications:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M18 16v-5a6 6 0 1 0-12 0v5l-2 2h16z`}),(0,D.jsx)(`path`,{d:`M10 20a2 2 0 0 0 4 0`})]}),setup:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M9 12l2 2 4-4`}),(0,D.jsx)(`path`,{d:`M12 3l8 3.7v6.3c0 5-3.5 9.6-8 11-4.5-1.4-8-6-8-11V6.7L12 3z`})]}),support:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,D.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3.5`}),(0,D.jsx)(`path`,{d:`M12 2.5v6M12 15.5v6M2.5 12h6M15.5 12h6`})]}),workspace:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`rect`,{x:`3`,y:`4`,width:`18`,height:`14`,rx:`2`}),(0,D.jsx)(`path`,{d:`M3 9h18M8 14h2M14 14h2`}),(0,D.jsx)(`path`,{d:`M9 20h6`})]}),plugins:(0,D.jsxs)(`svg`,{viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.6`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M9 3v4a2 2 0 0 1-2 2H3`}),(0,D.jsx)(`path`,{d:`M15 3v4a2 2 0 0 0 2 2h4`}),(0,D.jsx)(`rect`,{x:`3`,y:`9`,width:`18`,height:`12`,rx:`2`}),(0,D.jsx)(`path`,{d:`M7 14h2M12 14h5M7 18h10`})]})},Ch=[{title:`Overview`,items:[{path:`/`,label:`Dashboard`,icon:`dashboard`},{path:`/notifications`,label:`Notifications`,icon:`notifications`},{path:`/agents`,label:`Agents`,icon:`agents`},{path:`/graph`,label:`Graph`,icon:`graph`},{path:`/sessions`,label:`Sessions`,icon:`agents`}]},{title:`Rules`,items:[{path:`/rules`,label:`Rules`,icon:`rules`},{path:`/hub`,label:`Hub`,icon:`hub`},{path:`/approvals`,label:`Approvals`,icon:`approvals`}]},{title:`Activity`,items:[{path:`/audit`,label:`Audit`,icon:`audit`},{path:`/monitor`,label:`Monitor`,icon:`monitor`},{path:`/observability`,label:`Observability`,icon:`observability`}]},{title:`Tools`,items:[{path:`/plugins`,label:`Plugins`,icon:`plugins`},{path:`/setup`,label:`Setup`,icon:`setup`},{path:`/debug`,label:`Debug`,icon:`debug`},{path:`/profile`,label:`Profile`,icon:`profile`},{path:`/support`,label:`Support`,icon:`support`}]}],wh=[{title:`Get Started`,items:[{path:`/`,label:`Home`,icon:`home`},{path:`/agents`,label:`Agents`,icon:`agents`},{path:`/guardrails`,label:`Guardrails`,icon:`guardrails`},{path:`/try`,label:`Try It`,icon:`tryit`}]},{title:`Activity`,items:[{path:`/notifications`,label:`Notifications`,icon:`notifications`},{path:`/audit`,label:`Activity`,icon:`audit`},{path:`/approvals`,label:`Approvals`,icon:`approvals`}]},{title:`You`,items:[{path:`/setup`,label:`Setup`,icon:`setup`},{path:`/profile`,label:`Profile`,icon:`profile`},{path:`/support`,label:`Support`,icon:`support`}]}];function Th(e){return Eh(e===`newcomer`?wh:Ch)}function Eh(e){let t=window.__SSG_PLUGINS__;if(!t||t.nav.length===0)return e;let n=e=>{let t=e.toLowerCase();return t===`tools`?`Tools`:t===`activity`?`Activity`:t===`overview`?`Overview`:t===`rules`?`Rules`:e.charAt(0).toUpperCase()+e.slice(1)},r=e.map(e=>({...e,items:[...e.items]})),i=new Map;for(let e of t.nav){let t={path:e.path,label:e.label,icon:`plugins`},a=n(e.section),o=r.find(e=>e.title===a);if(o)o.items.push(t);else{let e=i.get(a)??[];e.push(t),i.set(a,e)}}for(let[e,t]of i)r.push({title:e,items:t});return r}function Dh(e){let t=Math.max(0,e-Date.now()),n=Math.floor(t/1e3);if(n<60)return`${n}s`;let r=Math.floor(n/60);return r<60?`${r}m ${n%60}s`:`${Math.floor(r/60)}h ${r%60}m`}function Oh(){let{data:e}=k(`/api/json/daemon-status`,[V([`counters-updated`])[`counters-updated`]]),[t,n]=(0,_.useState)(!1),[,r]=(0,_.useState)(0);(0,_.useEffect)(()=>{if(e?.status!==`degraded`||!e.hibernation)return;let t=setInterval(()=>r(e=>e+1),1e3);return()=>clearInterval(t)},[e?.status,e?.hibernation]);let i=e?.status??`starting`,a=i===`running`?`bg-[var(--color-decision-allow)]`:i===`starting`||i===`degraded`?`bg-[var(--color-decision-ask)]`:`bg-[var(--color-decision-block)]`,o=i===`starting`||i===`degraded`?`pulse-soft`:``,s=i===`degraded`&&e?.hibernation?Dh(e.hibernation.nextRetryAt):null,c=i===`running`?`Daemon`:i===`starting`?`Booting`:i===`degraded`?`Retry ${s??`…`}`:i===`error`?`Error`:`Offline`;return(0,D.jsxs)(`div`,{className:`relative`,children:[(0,D.jsxs)(`button`,{onClick:()=>n(e=>!e),className:`chip cursor-pointer hover:bg-[var(--color-fill-2)] transition-colors`,title:i===`running`?`Daemon running`:i===`starting`?`Daemon starting…`:i===`degraded`?`Daemon hibernating — retry in ${s??`…`}`:i===`error`?`Daemon error`:`Daemon stopped`,children:[(0,D.jsx)(`span`,{className:`status-dot ${a} ${o}`}),(0,D.jsx)(`span`,{className:`hidden sm:inline`,children:c})]}),t&&(0,D.jsxs)(`div`,{className:`absolute right-0 top-7 z-50 w-72 hig-card hig-card-padded text-xs`,children:[(0,D.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,D.jsx)(`span`,{className:`overline`,children:`Eval Daemon`}),(0,D.jsx)(`button`,{onClick:()=>n(!1),className:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-0)] cursor-pointer`,children:`✕`})]}),(0,D.jsxs)(`div`,{className:`space-y-1 text-[var(--color-fg-2)]`,children:[(0,D.jsxs)(`div`,{className:`font-mono text-[11px]`,children:[`status:`,` `,(0,D.jsx)(`span`,{className:i===`running`?`text-[var(--color-decision-allow)]`:i===`starting`||i===`degraded`?`text-[var(--color-decision-ask)]`:`text-[var(--color-decision-block)]`,children:i})]}),e?.pid&&(0,D.jsxs)(`div`,{className:`font-mono text-[11px]`,children:[`pid: `,e.pid]}),i===`degraded`&&e?.hibernation&&(0,D.jsxs)(`div`,{className:`mt-2 rounded-lg p-2 text-[11px] space-y-0.5`,style:{background:`color-mix(in oklab, var(--color-hig-orange) 14%, transparent)`,color:`color-mix(in oklab, var(--color-hig-orange) 90%, var(--color-fg-0))`},children:[(0,D.jsxs)(`div`,{children:[`next retry: `,(0,D.jsx)(`span`,{className:`font-medium`,children:s})]}),(0,D.jsxs)(`div`,{children:[`episode attempt: `,e.hibernation.attempt,e.hibernation.reason?` (${e.hibernation.reason})`:``]}),(0,D.jsx)(`div`,{className:`opacity-70`,children:`Slow-tier supervisor is retrying at long backoff — no manual restart required.`})]})]}),e?.logTail&&e.logTail.length>0&&(0,D.jsxs)(`div`,{className:`mt-3`,children:[(0,D.jsx)(`div`,{className:`overline mb-1`,children:`Recent log`}),(0,D.jsx)(`pre`,{className:`bg-[var(--color-surface-2)] border border-[var(--color-line-0)] rounded-md p-2 text-[10px] text-[var(--color-fg-2)] overflow-x-auto whitespace-pre-wrap break-all max-h-32 overflow-y-auto`,children:e.logTail.join(`
58
+ `)})]})]})]})}function kh(){let{data:e}=k(`/api/state/activity-degraded`);if(!e?.degraded)return null;let t=e.since?new Date(e.since).toLocaleTimeString():`recently`;return(0,D.jsxs)(`div`,{role:`status`,className:`hig-banner hig-banner-warning`,title:e.reason??`audit-worker degraded`,children:[(0,D.jsx)(`span`,{children:`⚠`}),(0,D.jsxs)(`span`,{children:[`Audit pipeline degraded since `,t,` — entries may be missing. Run`,` `,(0,D.jsx)(`code`,{className:`font-mono`,children:`ssg daemon --status`}),` to inspect.`]})]})}function Ah(){let{data:e}=k(`/api/json/license`,[V([`counters-updated`])[`counters-updated`]]);return!e||e.tier!==`unlicensed`||e.status===`needs_reauth`||e.status===`needs_login`||e.eval_daily_limit===null||e.evals_today<e.eval_daily_limit?null:(0,D.jsxs)(`div`,{role:`alert`,className:`hig-banner hig-banner-error`,title:`Free tier daily eval limit reached — rules are being bypassed until quota resets`,children:[(0,D.jsx)(`span`,{children:`●`}),(0,D.jsxs)(`span`,{children:[`Quota exhausted — `,e.evals_today.toLocaleString(),`/`,e.eval_daily_limit.toLocaleString(),` evals used today. BLOCK and ASK rules are being bypassed (fail-open) until daily reset.`,` `,(0,D.jsx)(`a`,{href:e.upgrade_url,target:`_blank`,rel:`noopener noreferrer`,className:`underline font-medium`,children:`Upgrade to Pro →`})]})]})}function jh(){let{data:e}=k(`/api/json/license`,[V([`counters-updated`])[`counters-updated`]]);if(!e||e.status!==`needs_reauth`)return null;let t=e.detail??`License JWT invalid or expired`;return(0,D.jsxs)(`div`,{role:`alert`,className:`hig-banner hig-banner-warning`,title:`Re-authentication required — paid-tier features are paused until you re-login`,children:[(0,D.jsx)(`span`,{children:`⚠`}),(0,D.jsxs)(`span`,{children:[`Re-authentication required — `,t,`. Run`,` `,(0,D.jsx)(`code`,{className:`font-mono`,children:`ssg auth login`}),` in your terminal to restore your tier.`]})]})}function Mh(){let{data:e,refetch:t}=k(`/api/json/ask-mode`),[n,r]=(0,_.useState)(!1),i=e?.mode??`native`;async function a(e){if(!(n||e===i)){r(!0);try{await fetch(`/api/json/ask-mode`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({mode:e})}),t()}finally{r(!1)}}}let o=i===`dashboard`;return(0,D.jsxs)(`button`,{onClick:()=>a(o?`tty`:`dashboard`),disabled:n,className:`chip cursor-pointer hover:bg-[var(--color-fill-2)] transition-colors disabled:opacity-50`,title:o?`ASK decisions queue on /approvals. Click to route to native prompt.`:`ASK decisions prompt in the native IDE/TTY. Click to route to dashboard.`,children:[(0,D.jsx)(`span`,{className:`status-dot ${o?`bg-[var(--color-hig-purple)]`:`bg-[var(--color-hig-blue)]`}`}),(0,D.jsxs)(`span`,{className:`hidden sm:inline`,children:[`Ask · `,o?`Dashboard`:`Native`]})]})}function Nh(){let{data:e,refetch:t}=k(`/api/json/session-banner`),[n,r]=(0,_.useState)(!1),i=e?.enabled??!0;async function a(){if(!n){r(!0);try{await fetch(`/api/json/session-banner`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({enabled:!i})}),t()}finally{r(!1)}}}return(0,D.jsxs)(`button`,{onClick:a,disabled:n,className:`chip cursor-pointer hover:bg-[var(--color-fill-2)] transition-colors disabled:opacity-50`,title:i?`SessionStart banner is ON — every Claude Code session opens with the active-rule count + dashboard link. Click to hide it.`:`SessionStart banner is OFF. Click to show it at the start of each session.`,children:[(0,D.jsx)(`span`,{className:`status-dot ${i?`bg-[var(--color-hig-green)]`:`bg-[var(--color-fg-3)]`}`}),(0,D.jsxs)(`span`,{className:`hidden sm:inline`,children:[`Banner · `,i?`On`:`Off`]})]})}function Ph(e){let t=new Date(e);return`${t.getHours().toString().padStart(2,`0`)}:${t.getMinutes().toString().padStart(2,`0`)}`}var Fh={on:`soft`,soft:`audit`,audit:`off`,off:`on`};function Ih(){let{data:e,refetch:t}=k(`/api/json/mode`,[V([`mode-changed`])[`mode-changed`]]),[n,r]=(0,_.useState)(!1),i=e?.mode??`on`;async function a(e,i){if(!n){r(!0);try{let n={mode:e};typeof i==`number`&&i>0&&(n.forMs=i),await fetch(`/api/json/mode`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify(n)}),t()}finally{r(!1)}}}let o=i===`on`?`bg-[var(--color-hig-green)]`:i===`soft`?`bg-[var(--color-hig-yellow)]`:i===`audit`?`bg-[var(--color-hig-orange)]`:`bg-[var(--color-hig-red)]`,s=e?.rearmAt!==void 0&&i!==`on`?` · until ${Ph(e.rearmAt)}`:``,c=`SSG · ${i.toUpperCase()}${s}`;return(0,D.jsxs)(`button`,{"data-tutorial":`app-mode`,onClick:e=>{e.shiftKey?a(i===`off`?`audit`:`on`):a(Fh[i])},disabled:n,className:`chip cursor-pointer hover:bg-[var(--color-fill-2)] transition-colors disabled:opacity-50`,title:i===`on`?`SSG ON — rules enforce normally. Click to cycle: On → Soft → Audit → Off.`:i===`soft`?`SSG SOFT — blocks downgraded to prompts, prompts downgraded to logs. Click for Audit; Shift+Click to resume On.`:i===`audit`?`SSG AUDIT — rules log only, nothing blocked or prompted. Click for Off; Shift+Click to resume On.`:`SSG OFF — kill switch engaged, evaluator returns allow. Click to resume On; Shift+Click for Audit.`,children:[(0,D.jsx)(`span`,{className:`status-dot ${o}`}),(0,D.jsx)(`span`,{className:`hidden sm:inline`,children:c})]})}function Lh(){let{data:e,refetch:t}=k(`/api/json/mode`,[V([`mode-changed`])[`mode-changed`]]),n=e?.mode??`on`;if(n===`on`)return null;let r=e?.rearmAt===void 0?``:` Auto-restores at ${Ph(e.rearmAt)}.`,i=n===`off`?`SSG is OFF — kill switch engaged.`:n===`soft`?`SSG is in SOFT mode — non-blocking enforcement.`:`SSG is in AUDIT mode — log-only.`,a=n===`off`?`Every tool call is being allowed without evaluation.${r}`:n===`soft`?`Block decisions are being downgraded to prompts and prompts to logs. Workflow keeps moving; signal still surfaces in the audit log.${r}`:`Rules still match for the audit log, but nothing is being blocked or prompted.${r}`,o=n===`off`?`hig-banner hig-banner-error`:`hig-banner hig-banner-warning`;async function s(){await fetch(`/api/json/mode`,{method:`POST`,headers:{"Content-Type":`application/json`,...U()},body:JSON.stringify({mode:`on`})}),t()}return(0,D.jsxs)(`div`,{className:o,children:[(0,D.jsxs)(`svg`,{className:`shrink-0`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`}),(0,D.jsx)(`line`,{x1:`12`,y1:`9`,x2:`12`,y2:`13`}),(0,D.jsx)(`line`,{x1:`12`,y1:`17`,x2:`12.01`,y2:`17`})]}),(0,D.jsxs)(`span`,{className:`flex-1`,children:[(0,D.jsx)(`span`,{className:`font-semibold`,children:i}),` `,a]}),(0,D.jsx)(`button`,{onClick:s,className:`hig-button hig-button-small`,title:`Re-enable normal rule enforcement`,children:`Resume`})]})}function Rh({onRefresh:e}){return(0,D.jsx)(`button`,{onClick:e,className:`hig-button`,title:`Reset page — clears stale graph state without dropping SSE`,"aria-label":`Refresh page`,children:(0,D.jsxs)(`svg`,{width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M21 12a9 9 0 1 1-3-6.7`}),(0,D.jsx)(`polyline`,{points:`21 3 21 9 15 9`})]})})}function zh(){return(0,D.jsx)(`button`,{onClick:()=>{try{window.location.reload()}catch{}},className:`hig-button`,title:`Reload dashboard — fetches fresh assets (use after a desktop upgrade)`,"aria-label":`Reload dashboard`,children:(0,D.jsxs)(`svg`,{width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M3 12a9 9 0 1 1 3 6.7`}),(0,D.jsx)(`polyline`,{points:`3 21 3 15 9 15`}),(0,D.jsx)(`path`,{d:`M3 3v6h6`})]})})}function Bh(){let{data:e}=k(`/api/json/mcp-status`,[V([`activity-updated`])[`activity-updated`]]),t=e?.status??`inactive`;if(t===`inactive`)return null;let n=t===`active`?`bg-[var(--color-hig-blue)]`:`bg-[var(--color-fg-3)]`,r=t===`active`?`MCP active`:`MCP idle`;return(0,D.jsxs)(`div`,{className:`chip`,title:t===`active`?`MCP server: ${e?.recentCount??0} evals in last 5 min`:`MCP server: ${e?.totalCount??0} total evals`,children:[(0,D.jsx)(`span`,{className:`status-dot ${n}`}),(0,D.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function Vh(){let{data:e}=k(`/api/json/adapters`);if(!e)return null;let t=e.adapters.find(e=>e.active);if(!t)return null;let n=t.id===`generic`;return(0,D.jsxs)(`a`,{href:`/agents`,className:`chip ss-agent-chip cursor-pointer transition-all`,title:n?`No specific AI client detected — SSG is running in generic adapter mode. Click to wire one up.`:`Connected agent: ${t.displayName} (${t.vendor}). Click to manage.`,style:{"--agent-accent":t.accent},"data-generic":n?`true`:`false`,children:[(0,D.jsx)(`span`,{className:`status-dot`,style:{background:t.accent,boxShadow:`0 0 6px color-mix(in oklab, ${t.accent} 60%, transparent)`}}),(0,D.jsx)(`span`,{className:`hidden sm:inline`,children:t.displayName})]})}function Hh(e,t){if(e===`/`)return t===`newcomer`?(0,D.jsx)(xh,{}):(0,D.jsx)(sl,{});if(e===`/classic`)return(0,D.jsx)(Jl,{});if(e===`/graph`)return(0,D.jsx)(vd,{});if(e===`/sessions`)return(0,D.jsx)(Im,{});if(e.startsWith(`/sessions/`)){let t=decodeURIComponent(e.slice(10));if(t)return(0,D.jsx)(Tm,{sessionKey:t})}if(e===`/debug`)return(0,D.jsx)(Zl,{});if(e===`/rules`)return(0,D.jsx)(hm,{});if(e===`/audit`)return(0,D.jsx)(Wi,{});if(e===`/approvals`)return(0,D.jsx)(mi,{});if(e===`/profile`)return(0,D.jsx)(Sp,{});if(e===`/agents`)return(0,D.jsx)(bn,{});if(e===`/notifications`)return(0,D.jsx)(Qd,{});if(e===`/setup`)return(0,D.jsx)(qm,{});if(e===`/try`)return(0,D.jsx)(sh,{});if(e===`/guardrails`)return(0,D.jsx)(wd,{});if(e===`/hub/connect`)return(0,D.jsx)($,{});if(e===`/hub/publish`)return(0,D.jsx)(Ld,{});if(e.startsWith(`/hub/`)){let t=e.slice(5);if(t)return(0,D.jsx)(bd,{id:t})}return e===`/hub`?(0,D.jsx)(Fd,{}):e===`/monitor`?(0,D.jsx)(Xd,{}):e===`/observability`?(0,D.jsx)(Ef,{}):e===`/plugins`?(0,D.jsx)(cp,{}):e===`/publish-plugin`?(0,D.jsx)(jf,{}):e===`/support`?(0,D.jsx)(fh,{}):(0,D.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-24 text-[var(--color-fg-3)]`,children:[(0,D.jsx)(`p`,{className:`overline mb-2`,children:`Error · 404`}),(0,D.jsx)(`p`,{className:`text-sm`,children:`Page not found`}),(0,D.jsx)(`a`,{href:`/`,className:`mt-4 text-[12px] text-[var(--color-hig-blue)] hover:underline`,children:`← Back to dashboard`})]})}function Uh(e,t){return e===`/`?t===`newcomer`?`Home`:`Dashboard`:e===`/classic`?`Classic Dashboard`:e===`/graph`?`Graph`:e===`/sessions`?`Sessions`:e.startsWith(`/sessions/`)?`Session Inspector`:e===`/debug`?`Debug`:e===`/rules`?`Rules`:e===`/audit`?t===`newcomer`?`Activity`:`Audit`:e===`/approvals`?`Approvals`:e===`/profile`?`Profile`:e===`/agents`?`Agents`:e===`/notifications`?`Notifications`:e===`/setup`?`Setup Status`:e===`/try`?`Try It`:e===`/guardrails`?`Guardrails`:e===`/hub/connect`?`Connect Hub`:e===`/hub/publish`?`Publish to Hub`:e.startsWith(`/hub/`)||e===`/hub`?`Hub`:e===`/monitor`?`Monitor`:e===`/observability`?`Observability`:e===`/plugins`?`Plugins`:e===`/publish-plugin`?`Publish a Plugin`:e===`/support`?`Support & Feedback`:`SigmaShake`}function Wh(e){history.pushState(null,``,e),window.dispatchEvent(new PopStateEvent(`popstate`))}function Gh({count:e}){let[t,n]=(0,_.useState)(!1);return t||e===0?null:(0,D.jsxs)(`div`,{className:`hig-banner hig-banner-warning`,children:[(0,D.jsxs)(`svg`,{className:`shrink-0`,width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z`}),(0,D.jsx)(`line`,{x1:`12`,y1:`9`,x2:`12`,y2:`13`}),(0,D.jsx)(`line`,{x1:`12`,y1:`17`,x2:`12.01`,y2:`17`})]}),(0,D.jsxs)(`span`,{className:`flex-1`,children:[(0,D.jsxs)(`span`,{className:`font-semibold`,children:[e,` other `,e===1?`tab`:`tabs`,` open.`]}),` `,`Each tab holds a live SSE connection. Browsers limit connections per origin — too many tabs will prevent this page from loading.`,` `,(0,D.jsx)(`span`,{className:`opacity-70`,children:`Close other tabs to restore full live-update functionality.`})]}),(0,D.jsx)(`button`,{onClick:()=>n(!0),className:`opacity-60 hover:opacity-100 transition-opacity shrink-0 cursor-pointer`,title:`Dismiss`,children:(0,D.jsxs)(`svg`,{width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,D.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})})]})}function Kh({onCollapse:e}){let{data:t}=k(`/api/health`),n=t?.version;return(0,D.jsxs)(`div`,{className:`hig-sidebar-footer`,children:[(0,D.jsx)(`span`,{className:`hig-sidebar-version`,title:n?`SigmaShake Governance v${n}`:`daemon version unavailable`,children:n?(0,D.jsxs)(D.Fragment,{children:[`ssg `,(0,D.jsxs)(`b`,{children:[`v`,n]})]}):`ssg`}),(0,D.jsx)(`button`,{type:`button`,className:`hig-sidebar-collapse`,"aria-label":`Collapse sidebar`,title:`Collapse sidebar`,onClick:e,children:(0,D.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,D.jsx)(`path`,{d:`M11 7l-5 5 5 5`}),(0,D.jsx)(`path`,{d:`M18 7l-5 5 5 5`})]})})]})}function qh({pathname:e,navSections:t,open:n,onClose:r,onCollapse:i}){let a=t=>t===`/`?e===`/`:e.startsWith(t);return(0,D.jsxs)(`aside`,{className:`hig-sidebar ${n?`open`:``}`,"aria-label":`Primary`,"data-tutorial":`app-sidebar`,children:[(0,D.jsxs)(`div`,{className:`hig-sidebar-header`,children:[(0,D.jsx)(`span`,{className:`hig-app-icon`,"aria-hidden":`true`,children:`SS`}),(0,D.jsxs)(`div`,{children:[(0,D.jsx)(`div`,{className:`hig-app-name`,children:`SigmaShake`}),(0,D.jsx)(`div`,{className:`hig-app-meta`,children:`Governance`})]}),(0,D.jsx)(`button`,{className:`hig-sidebar-close`,"aria-label":`Close sidebar`,onClick:r,children:(0,D.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 18 18`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,children:[(0,D.jsx)(`line`,{x1:`4`,y1:`4`,x2:`14`,y2:`14`}),(0,D.jsx)(`line`,{x1:`14`,y1:`4`,x2:`4`,y2:`14`})]})})]}),(0,D.jsx)(`nav`,{className:`hig-sidebar-nav`,children:t.map(e=>(0,D.jsxs)(`div`,{className:`hig-sidebar-section`,children:[(0,D.jsx)(`div`,{className:`hig-sidebar-section-title`,children:e.title}),e.items.map(e=>(0,D.jsxs)(`a`,{href:e.path,onClick:r,className:`hig-sidebar-item`,"data-active":a(e.path)?`true`:`false`,children:[(0,D.jsx)(`span`,{className:`hig-sidebar-icon`,"aria-hidden":`true`,children:Sh[e.icon]}),(0,D.jsx)(`span`,{children:e.label})]},e.path))]},e.title))}),(0,D.jsx)(Kh,{onCollapse:i})]})}function Jh(){let[e,t]=(0,_.useState)(window.location.pathname),[n,r]=(0,_.useState)(0),[i,a]=(0,_.useState)(!1),[o,s]=(0,_.useState)(()=>{try{return localStorage.getItem(`ssg:sidebar-collapsed`)===`1`}catch{return!1}}),{otherTabCount:c}=$t(),{mode:l}=Ct(),u=Th(l),d=Uh(e,l);return(0,_.useEffect)(()=>{let e=()=>t(window.location.pathname);return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[]),(0,_.useEffect)(()=>{a(!1)},[]),(0,_.useEffect)(()=>{try{localStorage.setItem(`ssg:sidebar-collapsed`,o?`1`:`0`)}catch{}},[o]),(0,_.useEffect)(()=>{let e=e=>{let t=e.target.closest(`a`);if(!t)return;let n=t.getAttribute(`href`);!n||n.startsWith(`http`)||n.startsWith(`//`)||n===`/workspace`||n.startsWith(`/workspace/`)||n.startsWith(`/plugins/`)||(e.preventDefault(),Wh(n))};return document.addEventListener(`click`,e),()=>document.removeEventListener(`click`,e)},[]),(0,D.jsxs)(`div`,{className:`hig-app`,"data-sidebar-collapsed":o?`true`:`false`,children:[(0,D.jsx)(qh,{pathname:e,navSections:u,open:i,onClose:()=>a(!1),onCollapse:()=>s(!0)}),i&&(0,D.jsx)(`div`,{className:`hig-sidebar-backdrop`,"aria-hidden":`true`,onClick:()=>a(!1)}),(0,D.jsxs)(`div`,{className:`hig-window`,children:[(0,D.jsxs)(`header`,{className:`hig-toolbar`,children:[(0,D.jsx)(`button`,{"aria-label":`Toggle sidebar`,className:`hig-sidebar-toggle hig-button hig-button-small`,onClick:()=>{window.matchMedia(`(min-width: 901px)`).matches?s(e=>!e):a(e=>!e)},children:(0,D.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 18 18`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,children:[(0,D.jsx)(`line`,{x1:`2`,y1:`5`,x2:`16`,y2:`5`}),(0,D.jsx)(`line`,{x1:`2`,y1:`9`,x2:`16`,y2:`9`}),(0,D.jsx)(`line`,{x1:`2`,y1:`13`,x2:`16`,y2:`13`})]})}),(0,D.jsx)(`h1`,{className:`hig-toolbar-title`,children:d}),(0,D.jsx)(ht,{pathname:e,mode:l}),(0,D.jsx)(`div`,{className:`hig-toolbar-spacer`}),(0,D.jsxs)(`div`,{className:`hig-toolbar-controls hidden md:flex`,children:[c>0&&(0,D.jsxs)(`span`,{className:`chip`,style:{color:`var(--color-hig-orange)`,background:`color-mix(in oklab, var(--color-hig-orange) 14%, transparent)`},title:`${c} other tab${c===1?``:`s`} open — may cause connection issues`,children:[c+1,` tabs`]}),(0,D.jsx)(qt,{}),(0,D.jsx)(Ih,{}),(0,D.jsx)(Mh,{}),(0,D.jsx)(Nh,{}),(0,D.jsx)(Vh,{}),(0,D.jsx)(Bh,{}),(0,D.jsx)(Oh,{}),(0,D.jsx)(Rh,{onRefresh:()=>r(e=>e+1)}),(0,D.jsx)(zh,{}),(0,D.jsx)(wt,{}),(0,D.jsx)(et,{}),(0,D.jsx)(O,{}),(0,D.jsx)(Gt,{})]})]}),(0,D.jsx)(Lh,{}),(0,D.jsx)(Gh,{count:c}),(0,D.jsx)(jh,{}),(0,D.jsx)(Ah,{}),(0,D.jsx)(kh,{}),(e===`/`||e===`/graph`||e===`/sessions`||e.startsWith(`/sessions/`)||e===`/audit`)&&(0,D.jsx)(Ue,{}),(0,D.jsx)(`main`,{className:`hig-content px-6 py-6`,children:Hh(e,l)},n)]})]})}var Yh=document.getElementById(`app-root`);if(!Yh)throw Error(`Missing #app-root`);g.createRoot(Yh).render((0,D.jsx)(_.StrictMode,{children:(0,D.jsx)(Jh,{})}));