@sigmashake/ssg 0.29.54 → 0.29.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +3 -3
- package/public/assets/app.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sigmashake/ssg",
|
|
3
|
-
"version": "0.29.
|
|
3
|
+
"version": "0.29.55",
|
|
4
4
|
"description": "AI Agent Governance CLI — evaluate tool calls against rules, block dangerous operations, and surface blocked commands",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE",
|
|
6
6
|
"type": "module",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"README.md"
|
|
15
15
|
],
|
|
16
16
|
"optionalDependencies": {
|
|
17
|
-
"@sigmashake/ssg-linux-x64": "0.29.
|
|
18
|
-
"@sigmashake/ssg-linux-arm64": "0.29.
|
|
17
|
+
"@sigmashake/ssg-linux-x64": "0.29.55",
|
|
18
|
+
"@sigmashake/ssg-linux-arm64": "0.29.55",
|
|
19
19
|
"@sigmashake/ssg-darwin-arm64": "0.29.40",
|
|
20
20
|
"@sigmashake/ssg-darwin-x64": "0.29.40",
|
|
21
21
|
"@sigmashake/ssg-win32-x64": "0.29.39"
|
package/public/assets/app.js
CHANGED
|
@@ -17,7 +17,7 @@ Error generating stack: `+e.message+`
|
|
|
17
17
|
${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,W.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
|
|
18
18
|
${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`,te>0&&(0,W.jsx)(`span`,{className:`text-[9px] bg-emerald-500/15 text-emerald-300 rounded-sm px-1 py-0.5 font-medium tabular-nums`,children:te})]})]}),(0,W.jsxs)(`div`,{className:`relative flex-1 min-w-[160px]`,children:[(0,W.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,W.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,W.jsx)(`line`,{x1:`21`,y1:`21`,x2:`16.65`,y2:`16.65`})]}),(0,W.jsx)(`input`,{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,W.jsx)(`select`,{value:n,onChange:e=>r(e.target.value),className:k,children:bl.map(e=>(0,W.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,W.jsxs)(`select`,{value:i,onChange:e=>a(e.target.value),className:k,children:[(0,W.jsx)(`option`,{value:``,children:`any decision`}),Sl.filter(Boolean).map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))]}),(0,W.jsxs)(`select`,{value:o,onChange:e=>s(e.target.value),className:k,children:[(0,W.jsx)(`option`,{value:``,children:`any severity`}),xl.filter(Boolean).map(e=>(0,W.jsx)(`option`,{value:e,children:e},e))]})]}),g&&u.length===0?(0,W.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,W.jsx)(Cl,{},t))}):ee.length===0?(0,W.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,W.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,W.jsx)(`circle`,{cx:`11`,cy:`11`,r:`8`}),(0,W.jsx)(`line`,{x1:`21`,y1:`21`,x2:`16.65`,y2:`16.65`})]}),(0,W.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,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`div`,{className:`grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3`,children:ee.map(e=>(0,W.jsx)(Tl,{rs:e,installingId:y,onInstall:O,flashId:x},e.id))}),f&&c===`all`&&(0,W.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,W.jsx)(`button`,{onClick:E,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`})})]})]})}var Dl={deny:`red`,block:`red`,ask:`amber`,allow:`green`,log:`gray`,force:`blue`};function Ol({id:e}){let{data:t,error:n}=z(`/api/json/hub/${e}`),[r,i]=(0,_.useState)(!1),[a,o]=(0,_.useState)(!1);if(n)return(0,W.jsxs)(`div`,{className:`text-sm text-red-300 font-mono`,children:[(0,W.jsx)(`p`,{children:n}),(0,W.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,W.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`,...Ae()},body:JSON.stringify({id:e})})).ok&&i(!0)}finally{o(!1)}}return(0,W.jsxs)(`div`,{className:`space-y-5`,children:[(0,W.jsxs)(`div`,{className:`flex items-start justify-between gap-4`,children:[(0,W.jsxs)(`div`,{className:`min-w-0`,children:[(0,W.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,W.jsx)(`h1`,{className:`text-xl font-medium tracking-tight mt-1.5 text-[var(--color-fg-0)]`,children:t.title}),(0,W.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,W.jsx)(J,{variant:r?`secondary`:`primary`,onClick:s,disabled:a||r,children:r?`✓ installed`:a?`installing…`:`install`})]}),t.technologies.length>0&&(0,W.jsx)(`div`,{className:`flex flex-wrap gap-1.5`,children:t.technologies.map(e=>(0,W.jsx)(lr,{variant:`blue`,children:e},e))}),t.github_repo&&(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`source`}),(0,W.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:t.github_repo})]}),(0,W.jsxs)(G,{children:[(0,W.jsx)(K,{children:(0,W.jsxs)(`span`,{className:`overline`,children:[`rules · `,t.rules.length]})}),(0,W.jsx)(q,{className:`space-y-4`,children:t.rules.map((e,t)=>(0,W.jsxs)(`div`,{className:t>0?`border-t border-[var(--color-line-0)] pt-4`:void 0,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 mb-2 flex-wrap`,children:[(0,W.jsx)(lr,{variant:Dl[e.decision]??`gray`,children:e.decision}),(0,W.jsx)(`code`,{className:`text-xs text-[var(--color-brand)] font-mono`,children:e.name}),e.capability&&(0,W.jsx)(lr,{variant:`gray`,children:e.capability})]}),(0,W.jsx)(`p`,{className:`text-sm text-[var(--color-fg-1)] mb-2`,children:e.message}),(0,W.jsx)(Ys,{children:e.raw_text})]},e.id))})]})]})}function kl(){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`,...Ae()}}),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,W.jsxs)(`div`,{className:`max-w-lg mx-auto space-y-5`,children:[(0,W.jsxs)(`div`,{children:[(0,W.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,W.jsx)(`svg`,{width:`10`,height:`10`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:(0,W.jsx)(`polyline`,{points:`15 18 9 12 15 6`})}),`back to hub`]}),(0,W.jsx)(`h1`,{className:`text-xl font-medium tracking-tight mt-2 text-[var(--color-fg-0)]`,children:`Connect GitHub`}),(0,W.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,W.jsx)(G,{children:(0,W.jsxs)(q,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,W.jsx)(`span`,{className:`text-amber-300 shrink-0 mt-0.5`,children:(0,W.jsxs)(`svg`,{width:`16`,height:`16`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[(0,W.jsx)(`circle`,{cx:`12`,cy:`12`,r:`10`}),(0,W.jsx)(`line`,{x1:`12`,y1:`8`,x2:`12`,y2:`12`}),(0,W.jsx)(`line`,{x1:`12`,y1:`16`,x2:`12.01`,y2:`16`})]})}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`p`,{className:`text-sm font-medium text-[var(--color-fg-0)]`,children:`GitHub OAuth not configured`}),(0,W.jsx)(`p`,{className:`text-xs text-[var(--color-fg-2)] mt-1 leading-relaxed`,children:i})]})]}),(0,W.jsxs)(`div`,{className:`border-t border-[var(--color-line-0)] pt-4`,children:[(0,W.jsx)(`div`,{className:`overline mb-3`,children:`setup steps`}),(0,W.jsx)(`ol`,{className:`space-y-2`,children:o.map((e,t)=>(0,W.jsxs)(`li`,{className:`flex items-start gap-2.5 text-xs text-[var(--color-fg-1)]`,children:[(0,W.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,W.jsx)(`span`,{className:`mt-0.5 leading-relaxed`,children:e.replace(/^\d+\.\s+/,``)})]},t))})]}),(0,W.jsxs)(`div`,{className:`bg-[var(--color-surface-0)] border border-[var(--color-line-1)] rounded-sm p-3`,children:[(0,W.jsx)(`div`,{className:`overline mb-1.5`,children:`quick start`}),(0,W.jsx)(`code`,{className:`text-[11px] text-[var(--color-brand)]/90 font-mono`,children:`export SSG_GITHUB_CLIENT_ID=<your-client-id>`}),(0,W.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)] mt-1`,children:[`then restart:`,` `,(0,W.jsx)(`code`,{className:`text-[var(--color-fg-1)]`,children:`ssg serve`})]})]}),(0,W.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,W.jsx)(G,{children:(0,W.jsxs)(q,{children:[(0,W.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,W.jsx)(J,{onClick:u,disabled:c,variant:`primary`,children:c?`starting…`:`connect with github`})]})}),e&&n===`polling`&&(0,W.jsx)(G,{children:(0,W.jsxs)(q,{className:`space-y-4`,children:[(0,W.jsxs)(`div`,{className:`text-center`,children:[(0,W.jsx)(`div`,{className:`overline mb-2`,children:`open this url in your browser`}),(0,W.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,W.jsxs)(`div`,{className:`border border-[var(--color-line-1)] bg-[var(--color-surface-0)] rounded-sm py-5 text-center`,children:[(0,W.jsx)(`div`,{className:`overline mb-3`,children:`enter this code`}),(0,W.jsx)(`div`,{className:`text-4xl font-mono font-bold tracking-[0.3em] text-[var(--color-fg-0)]`,children:e.user_code})]}),(0,W.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,W.jsx)(`svg`,{className:`animate-spin`,width:`11`,height:`11`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,W.jsx)(`path`,{d:`M21 12a9 9 0 1 1-6.219-8.56`})}),`waiting for github authorization…`]})]})}),n===`done`&&(0,W.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,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`svg`,{width:`15`,height:`15`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,children:(0,W.jsx)(`polyline`,{points:`20 6 9 17 4 12`})}),(0,W.jsx)(`span`,{className:`font-mono text-xs`,children:i})]}),(0,W.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,W.jsxs)(`div`,{className:`rounded-sm border border-red-500/25 bg-red-500/5 p-4`,children:[(0,W.jsx)(`p`,{className:`text-sm text-red-200 font-mono`,children:i}),(0,W.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`})]})]})}function Al(){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`,...Ae()},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,W.jsxs)(`div`,{className:`max-w-md mx-auto space-y-5`,children:[(0,W.jsxs)(`div`,{children:[(0,W.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,W.jsx)(`h1`,{className:`text-xl font-medium tracking-tight mt-2 text-[var(--color-fg-0)]`,children:`Publish Ruleset`}),(0,W.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,W.jsx)(G,{children:(0,W.jsx)(q,{children:(0,W.jsxs)(`form`,{onSubmit:o,className:`space-y-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`block overline mb-1.5`,children:`github repository url`}),(0,W.jsx)(`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,W.jsx)(J,{type:`submit`,variant:`primary`,disabled:n,children:n?`publishing…`:`publish to hub`})]})})}),i&&(0,W.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,W.jsxs)(W.Fragment,{children:[`✓ published!`,` `,i.id&&(0,W.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 jl(e){return e===0?`—`:e<1e3?`${e}ns`:e<1e6?`${(e/1e3).toFixed(1)}µs`:`${(e/1e6).toFixed(1)}ms`}function Ml(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 Nl(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 Pl(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 Fl={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)]`},Z={allow:`✓`,block:`✗`,force:`→`,log:`·`,ask:`?`,shadow:`~`};function Q({label:e,ns:t,maxNs:n}){let r=n>0?Math.min(100,t/n*100):0;return(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-xs`,children:[(0,W.jsx)(`span`,{className:`text-[var(--color-fg-3)] w-8 text-right font-mono uppercase tracking-wider text-[10px]`,children:e}),(0,W.jsx)(rc,{pct:r,tone:t<1e5?`green`:t<1e6?`amber`:`red`,className:`h-1 flex-1`}),(0,W.jsx)(`span`,{className:`font-mono text-[var(--color-fg-1)] tabular-nums w-14 text-right`,children:jl(t)})]})}function Il({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,W.jsx)(rc,{pct:i,tone:r?`red`:e/t>=.6?`amber`:`green`,markerPct:a,markerTitle:`limit: ${n}`,className:`h-1`})}function Ll({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`,...Ae()},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,W.jsxs)(`div`,{className:`space-y-3`,children:[(0,W.jsxs)(`div`,{className:`grid grid-cols-2 gap-3`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`overline block mb-1.5`,children:`cpu limit (%)`}),(0,W.jsx)(`input`,{type:`number`,min:1,max:100,value:n,onChange:e=>r(e.target.value),className:p})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`overline block mb-1.5`,children:`memory limit (mb)`}),(0,W.jsx)(`input`,{type:`number`,min:1,value:i,onChange:e=>a(e.target.value),className:p})]})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`label`,{className:`overline block mb-1.5`,children:`on breach`}),(0,W.jsxs)(`select`,{value:o,onChange:e=>s(e.target.value),className:p,children:[(0,W.jsx)(`option`,{value:`warn`,children:`warn in ui only`}),(0,W.jsx)(`option`,{value:`log`,children:`warn + write to audit log`})]})]}),u&&(0,W.jsx)(`p`,{className:`text-xs text-red-300 font-mono`,children:u}),(0,W.jsx)(J,{onClick:f,disabled:c,variant:`primary`,size:`sm`,children:c?`saving…`:`save limits`})]})}var Rl={running:`green`,hibernating:`amber`,exhausted:`red`,stopped:`gray`,idle:`gray`};function zl(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 Bl({supervisors:e}){let[t,n]=(0,_.useState)(Date.now());return(0,_.useEffect)(()=>{let e=setInterval(()=>n(Date.now()),1e3);return()=>clearInterval(e)},[]),(0,W.jsxs)(G,{children:[(0,W.jsxs)(K,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`span`,{className:`flex items-center gap-2 overline`,children:[`supervisor health`,e.some(e=>e.state===`hibernating`||e.state===`exhausted`)&&(0,W.jsx)(lr,{variant:`amber`,children:`degraded`})]}),(0,W.jsxs)(`span`,{className:`text-[10px] font-mono tabular-nums text-[var(--color-fg-4)]`,children:[e.length,` supervisor`,e.length===1?``:`s`]})]}),(0,W.jsx)(q,{children:e.length===0?(0,W.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`no supervisors registered yet`}):(0,W.jsx)(`div`,{className:`overflow-x-auto`,children:(0,W.jsxs)(`table`,{className:`w-full text-xs font-mono`,children:[(0,W.jsx)(`thead`,{children:(0,W.jsxs)(`tr`,{className:`text-[10px] uppercase tracking-wider text-[var(--color-fg-4)]`,children:[(0,W.jsx)(`th`,{className:`text-left font-normal pb-1.5`,children:`name`}),(0,W.jsx)(`th`,{className:`text-left font-normal pb-1.5`,children:`kind`}),(0,W.jsx)(`th`,{className:`text-left font-normal pb-1.5`,children:`state`}),(0,W.jsx)(`th`,{className:`text-right font-normal pb-1.5`,children:`restarts`}),(0,W.jsx)(`th`,{className:`text-left font-normal pb-1.5 pl-4`,children:`last restart`}),(0,W.jsx)(`th`,{className:`text-left font-normal pb-1.5 pl-4`,children:`next retry`})]})}),(0,W.jsx)(`tbody`,{children:e.map(e=>(0,W.jsxs)(`tr`,{className:`border-t border-[var(--color-line-0)]`,children:[(0,W.jsx)(`td`,{className:`py-1.5 text-[var(--color-fg-1)]`,children:e.name}),(0,W.jsx)(`td`,{className:`py-1.5 text-[var(--color-fg-3)]`,children:e.kind===`single`?`single`:`tree`}),(0,W.jsx)(`td`,{className:`py-1.5`,children:(0,W.jsx)(lr,{variant:Rl[e.state],children:e.state})}),(0,W.jsx)(`td`,{className:`py-1.5 text-right tabular-nums text-[var(--color-fg-1)]`,children:e.restarts}),(0,W.jsx)(`td`,{className:`py-1.5 pl-4 tabular-nums text-[var(--color-fg-3)]`,children:e.lastRestartAt>0?Pl(e.lastRestartAt):`—`}),(0,W.jsx)(`td`,{className:`py-1.5 pl-4 tabular-nums text-[var(--color-fg-3)]`,children:e.nextRetryAt>0?(0,W.jsx)(`span`,{title:e.hibernateReason?`reason: ${e.hibernateReason}`:void 0,children:zl(e.nextRetryAt,t)}):`—`})]},e.name))})]})})})]})}function Vl(){let e=je([`runtime-tick`,`activity-updated`,`limits-breach`,`supervisor-changed`]),t=Oe(),[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}=z(`/api/state/runtime`,[e[`runtime-tick`]]),{data:m,refetch:h}=z(`/api/json/limits`,[e[`limits-breach`]]),{data:g}=z(`/api/state/activity-tail?after=${i}&limit=50`,[e[`activity-updated`]]),{data:v}=z(`/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?Ml(p.uptime_ms):null,b=p&&p.last_eval_at>0?Pl(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,W.jsxs)(`div`,{className:`space-y-5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h1`,{className:`text-xl font-medium tracking-tight text-[var(--color-fg-0)]`,children:`Daemon Monitor`}),(0,W.jsx)(`p`,{className:`text-[12px] font-mono text-[var(--color-fg-3)] mt-0.5`,children:`live metrics · audit tail · resource limits`})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[c>0&&(0,W.jsxs)(lr,{variant:`amber`,children:[c,` restart`,c===1?``:`s`]}),(0,W.jsx)(`span`,{className:`text-[11px] font-mono tabular-nums text-[var(--color-fg-3)]`,children:Nl(n)})]})]}),(0,W.jsx)(Hl,{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,W.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,W.jsx)(`span`,{className:`text-red-300 shrink-0 mt-0.5`,children:(0,W.jsxs)(`svg`,{width:`14`,height:`14`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,children:[(0,W.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,W.jsx)(`line`,{x1:`12`,y1:`9`,x2:`12`,y2:`13`}),(0,W.jsx)(`line`,{x1:`12`,y1:`17`,x2:`12.01`,y2:`17`})]})}),(0,W.jsxs)(`div`,{className:`space-y-0.5 text-xs font-mono`,children:[x&&(0,W.jsxs)(`div`,{className:`text-red-200`,children:[`cpu limit exceeded: `,p?.cpu_pct??`?`,`% >`,` `,m.config.cpuLimitPct,`%`]}),S&&(0,W.jsxs)(`div`,{className:`text-red-200`,children:[`memory limit exceeded: `,p?.memory_rss_mb??`?`,`mb >`,` `,m.config.memoryLimitMb,`mb`]})]})]}),(0,W.jsxs)(G,{children:[(0,W.jsx)(K,{children:(0,W.jsx)(`span`,{className:`overline`,children:`daemon status`})}),(0,W.jsx)(q,{children:p===null?(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-sm`,children:[(0,W.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-red-500 shrink-0`}),(0,W.jsx)(`span`,{className:`text-red-300 font-mono uppercase tracking-wider text-xs`,children:`down`}),(0,W.jsx)(`span`,{className:`text-[var(--color-fg-3)] text-xs font-mono`,children:`— socket not reachable`})]}):(0,W.jsxs)(`div`,{className:`flex items-center gap-5 flex-wrap text-xs font-mono`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-emerald-400 pulse-soft shrink-0`}),(0,W.jsx)(`span`,{className:`text-emerald-300 uppercase tracking-wider`,children:`up`})]}),(0,W.jsxs)(`span`,{className:`text-[var(--color-fg-3)]`,children:[`pid`,` `,(0,W.jsx)(`span`,{className:`text-[var(--color-fg-1)] tabular-nums`,children:p.pid})]}),(0,W.jsxs)(`span`,{className:`text-[var(--color-fg-3)]`,children:[`uptime`,` `,(0,W.jsx)(`span`,{className:`text-[var(--color-fg-1)] tabular-nums`,children:y})]}),(0,W.jsxs)(`span`,{className:`text-[var(--color-fg-3)]`,children:[`mem`,` `,(0,W.jsxs)(`span`,{className:`text-[var(--color-fg-1)] tabular-nums`,children:[p.memory_rss_mb,`MB`]})]}),(0,W.jsxs)(`span`,{className:`text-[var(--color-fg-3)]`,children:[`cpu`,` `,(0,W.jsxs)(`span`,{className:`${C} tabular-nums`,children:[p.cpu_pct,`%`]})]}),(0,W.jsxs)(`span`,{className:`text-[var(--color-fg-3)]`,children:[`last eval`,` `,(0,W.jsx)(`span`,{className:`text-[var(--color-fg-1)] tabular-nums`,children:b??`—`})]})]})})]}),(0,W.jsx)(Bl,{supervisors:v?.supervisors??[]}),(0,W.jsxs)(G,{children:[(0,W.jsxs)(K,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`span`,{className:`flex items-center gap-2 overline`,children:[`system resources`,m&&(x||S)&&(0,W.jsx)(lr,{variant:`red`,children:`limit exceeded`})]}),(0,W.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,W.jsxs)(q,{children:[p===null?(0,W.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`no data — daemon not running`}):(0,W.jsxs)(`div`,{className:`space-y-5`,children:[(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`cpu`}),(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(p.history.cpu_pct.length??0)>1&&(0,W.jsx)(hr,{data:p.history.cpu_pct,width:80,height:20,color:x?`#f87171`:`#34d399`,threshold:m?.config.cpuLimitPct,maxValue:100}),(0,W.jsxs)(`span`,{className:`font-mono font-medium w-12 text-right tabular-nums ${C}`,children:[p.cpu_pct,`%`]})]})]}),(0,W.jsx)(Il,{value:p.cpu_pct,max:100,threshold:m?.config.cpuLimitPct??90,breached:x}),m&&(0,W.jsxs)(`div`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:[`limit: `,m.config.cpuLimitPct,`%`]})]}),(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`memory rss`}),(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(p.history.memory_rss_mb.length??0)>1&&(0,W.jsx)(hr,{data:p.history.memory_rss_mb,width:80,height:20,color:S?`#f87171`:`#38bdf8`,threshold:m?.config.memoryLimitMb}),(0,W.jsxs)(`span`,{className:`font-mono font-medium w-16 text-right tabular-nums ${w}`,children:[p.memory_rss_mb,`MB`]})]})]}),(0,W.jsx)(Il,{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,W.jsxs)(`div`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:[`limit: `,m.config.memoryLimitMb,`MB`]})]}),(0,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between text-xs`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`heap`}),(0,W.jsxs)(`span`,{className:`font-mono text-[var(--color-fg-1)] tabular-nums`,children:[p.heap_used_mb,`MB / `,p.heap_total_mb,`MB`]})]}),(0,W.jsx)(rc,{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,W.jsxs)(`div`,{className:`mt-5 pt-4 border-t border-[var(--color-line-0)]`,children:[(0,W.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,W.jsx)(`code`,{className:`text-[var(--color-fg-1)]`,children:`.sigmashake/config.toml`}),`.`]}),(0,W.jsx)(Ll,{limitsData:m,onSaved:()=>{h(),d(!1)}})]})]})]}),(0,W.jsxs)(`div`,{className:`grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-2`,children:[(0,W.jsx)(nc,{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,W.jsx)(nc,{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,W.jsx)(nc,{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,W.jsx)(nc,{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,W.jsx)(nc,{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,W.jsx)(nc,{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,W.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-4`,children:[(0,W.jsxs)(G,{children:[(0,W.jsxs)(K,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`eval latency`}),p&&(0,W.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)] tabular-nums`,children:[p.latency.samples,` samples`]})]}),(0,W.jsx)(q,{children:p===null?(0,W.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`no data`}):(0,W.jsxs)(`div`,{className:`space-y-2`,children:[(0,W.jsx)(Q,{label:`p50`,ns:p.latency.p50_ns,maxNs:p.latency.max_ns}),(0,W.jsx)(Q,{label:`p95`,ns:p.latency.p95_ns,maxNs:p.latency.max_ns}),(0,W.jsx)(Q,{label:`p99`,ns:p.latency.p99_ns,maxNs:p.latency.max_ns}),(0,W.jsx)(Q,{label:`max`,ns:p.latency.max_ns,maxNs:p.latency.max_ns})]})})]}),(0,W.jsxs)(G,{children:[(0,W.jsx)(K,{children:(0,W.jsx)(`span`,{className:`overline`,children:`engine`})}),(0,W.jsx)(q,{children:p===null?(0,W.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`no data`}):(0,W.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,W.jsxs)(`div`,{className:`flex justify-between py-0.5 border-b border-[var(--color-line-0)] last:border-0`,children:[(0,W.jsx)(`span`,{className:`text-[var(--color-fg-3)]`,children:e}),(0,W.jsx)(`span`,{className:`text-[var(--color-fg-1)] tabular-nums`,children:t})]},e))})})]})]}),(0,W.jsxs)(G,{children:[(0,W.jsxs)(K,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`live event tail`}),(0,W.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:`newest first · auto-updating`})]}),(0,W.jsx)(q,{children:o.length===0?(0,W.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,W.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`no events yet`})}):(0,W.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,W.jsxs)(`div`,{className:`flex items-center gap-2 py-1`,children:[(0,W.jsx)(`span`,{className:`text-[var(--color-fg-4)] shrink-0 w-16 tabular-nums`,children:Nl(e.timestamp)}),e.tool===`__daemon`?(0,W.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,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`span`,{className:`shrink-0 w-16 uppercase tracking-wider text-[10px] ${Fl[e.decision]??`text-[var(--color-fg-3)]`}`,children:[Z[e.decision]??`·`,` `,e.decision]}),(0,W.jsx)(`span`,{className:`text-[var(--color-fg-1)] shrink-0 w-24 truncate`,children:e.tool}),(0,W.jsx)(`span`,{className:`text-[var(--color-fg-4)] shrink-0 w-14 text-right tabular-nums`,children:jl(e.duration_ns)}),e.rule_id&&(0,W.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,W.jsxs)(G,{children:[(0,W.jsx)(K,{children:(0,W.jsx)(`span`,{className:`overline`,children:`ai agent debug endpoints`})}),(0,W.jsxs)(q,{children:[(0,W.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,W.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,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`GET`}),(0,W.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`text-[var(--color-brand)]/80 hover:text-[var(--color-brand)] transition-colors`,children:e}),(0,W.jsxs)(`span`,{className:`text-[var(--color-fg-4)]`,children:[`— `,t]})]},e))})]})]})]})}function Hl({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,W.jsxs)(`div`,{className:`grid-bleed rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3`,children:[(0,W.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-12 gap-4`,children:[(0,W.jsxs)(`div`,{className:`lg:col-span-3 flex flex-col items-center gap-2`,children:[(0,W.jsx)(qr,{mode:`ring`,value:e,max:100,warnAt:(t??90)/100*.7,critAt:(t??90)/100,display:`${e.toFixed(1)}%`,label:`cpu`,size:220}),(0,W.jsx)(Sr,{value:e,width:260,height:56,windowMs:6e4,color:`#34d399`,fillColor:`rgba(52, 211, 153, 0.14)`,maxValue:100,className:`w-full`})]}),(0,W.jsxs)(`div`,{className:`lg:col-span-3 flex flex-col items-center gap-2`,children:[(0,W.jsx)(qr,{mode:`ring`,value:n,max:r??1024,warnAt:.7,critAt:.9,display:`${n.toFixed(0)} MB`,label:`memory`,size:220}),(0,W.jsx)(Sr,{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,W.jsx)(`div`,{className:`lg:col-span-6`,children:(0,W.jsx)(ei,{latency:a,bursts:s,gaugeMaxMs:10,windowMs:3e4,trendWindowSec:60,gaugeSize:200})})]}),(0,W.jsxs)(`div`,{className:`mt-4 grid grid-cols-1 lg:grid-cols-2 gap-3`,children:[(0,W.jsx)(Ar,{label:`Total Evals`,value:o,tone:`amber`,sub:`${c.toFixed(1)}/s`,burstRing:s}),(0,W.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,W.jsxs)(`div`,{className:`flex items-baseline justify-between`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`throughput · 60 s`}),(0,W.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)] tabular-nums`,children:[c.toFixed(1),`/s`]})]}),(0,W.jsx)(Sr,{value:c,width:420,height:56,windowMs:6e4,className:`w-full`})]})]}),i?(0,W.jsx)(`div`,{className:`mt-4 pt-3 border-t border-[var(--color-line-0)]`,children:(0,W.jsx)(ri,{counters:{allow:i.allow,block:i.block,ask:i.ask,log:i.log,force:i.force,shadow:i.shadow}})}):null,(0,W.jsxs)(`div`,{className:`mt-4 pt-3 border-t border-[var(--color-line-0)]`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`live event stream · newest first`}),(0,W.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-3)]`,children:[s.length,` buffered · hover to pause`]})]}),(0,W.jsx)(hi,{variant:`decision`,bursts:s,windowSize:300,height:260})]})]})}var Ul={ok:`green`,warn:`amber`,error:`red`,unknown:`gray`},Wl={ok:`OK`,warn:`Warn`,error:`Error`,unknown:`Idle`};function Gl({title:e,status:t=`unknown`,statusLabel:n,className:r,children:i}){return(0,W.jsxs)(G,{className:U(`flex flex-col`,r),children:[(0,W.jsxs)(K,{children:[(0,W.jsx)(`span`,{className:`overline text-[var(--color-fg-2)]`,children:e}),(0,W.jsx)(lr,{variant:Ul[t],children:n??Wl[t]})]}),(0,W.jsx)(q,{className:`flex flex-col gap-2 text-[12px]`,children:i})]})}function Kl({label:e,value:t,mono:n=!1,tone:r}){return(0,W.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,W.jsx)(`span`,{className:`text-[var(--color-fg-3)] uppercase tracking-wider text-[10px] font-mono`,children:e}),(0,W.jsx)(`span`,{className:U(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 ql(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 Jl(e){return e<1024?`${e}B`:e<1024*1024?`${(e/1024).toFixed(1)}KB`:`${(e/1024/1024).toFixed(1)}MB`}function Yl(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 Xl(e){return e?new Date(e*1e3).toLocaleString():`—`}function Zl(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 Ql({children:e,className:t}){return(0,W.jsx)(`div`,{className:`overline mb-2.5 ${t??``}`,children:e})}function $l({label:e,value:t,mono:n=!0,accent:r}){return(0,W.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,W.jsx)(`span`,{className:`text-xs text-[var(--color-fg-3)] shrink-0 font-mono`,children:e}),(0,W.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 eu({ok:e,label:t,badLabel:n}){return e?(0,W.jsx)(lr,{variant:`green`,children:t}):(0,W.jsx)(lr,{variant:`red`,children:n??t})}function tu({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,W.jsxs)(`div`,{className:`space-y-1.5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between text-xs font-mono tabular-nums`,children:[(0,W.jsxs)(`span`,{className:`text-[var(--color-fg-3)]`,children:[t.toLocaleString(),` / `,n.toLocaleString(),` rows`]}),(0,W.jsxs)(`span`,{className:i,children:[e,`%`]})]}),(0,W.jsx)(rc,{pct:e,tone:r,className:`h-1.5`})]})}var nu=3e3,ru={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 iu(e){return e.value==null?e.description?e.description:`[${e.type}]`:String(e.value)}function au(){let e=tl(),[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)},[a]),(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]),(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)}},nu)}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]);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,W.jsxs)(`div`,{className:`space-y-5`,children:[(0,W.jsxs)(G,{children:[(0,W.jsxs)(K,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`runtime inspector`}),(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] font-mono text-[var(--color-fg-2)]`,children:[(0,W.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-emerald-400`}),`connected`,e.bunVersion?` · bun v${e.bunVersion}`:``]}),(0,W.jsx)(J,{variant:`ghost`,size:`sm`,onClick:e.disconnect,children:`disconnect`})]})]}),e.error&&(0,W.jsx)(q,{children:(0,W.jsx)(`p`,{className:`text-xs text-red-300 font-mono`,children:e.error})})]}),(0,W.jsxs)(G,{children:[(0,W.jsxs)(K,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`cpu profiler`}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[t&&(0,W.jsxs)(`span`,{className:`text-[10px] font-mono uppercase tracking-wider text-red-300 flex items-center gap-1.5`,children:[(0,W.jsx)(`span`,{className:`inline-block w-1.5 h-1.5 rounded-full bg-red-400 pulse-soft`}),`recording`]}),t?(0,W.jsx)(J,{variant:`danger`,size:`sm`,onClick:v,children:`stop & render`}):(0,W.jsx)(J,{variant:`primary`,size:`sm`,onClick:g,children:`start recording`})]})]}),(0,W.jsx)(q,{children:r?(0,W.jsx)(ac,{profile:r,children:(0,W.jsx)(`div`,{className:`bg-[var(--color-surface-0)] border border-[var(--color-line-1)] rounded-sm p-2 overflow-x-hidden`,children:(0,W.jsx)(cl,{profile:r})})}):(0,W.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:t?`recording cpu profile (auto-captures ${nu/1e3}s)… perform actions in ssg to generate data.`:`click start recording, or wait for auto-capture on page load.`})})]}),(0,W.jsxs)(G,{children:[(0,W.jsxs)(K,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`memory`}),(0,W.jsx)(J,{variant:`ghost`,size:`sm`,onClick:y,disabled:l,children:l?`…`:`refresh`})]}),(0,W.jsx)(q,{children:s?(0,W.jsx)(oc,{memory:s,formatValue:Jl}):(0,W.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-3)]`,children:d?`fetching memory metrics…`:`click refresh to fetch process.memoryUsage().`})})]}),(0,W.jsxs)(G,{children:[(0,W.jsxs)(K,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`console`}),(0,W.jsx)(J,{variant:`ghost`,size:`sm`,onClick:()=>o([]),children:`clear`})]}),(0,W.jsx)(q,{children:(0,W.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,W.jsx)(`p`,{className:`text-[var(--color-fg-4)]`,children:`console output will appear here…`}):a.map(e=>(0,W.jsxs)(`div`,{className:`py-0.5 border-b border-[var(--color-line-0)] ${ru[e.type]??`text-[var(--color-fg-1)]`}`,children:[(0,W.jsxs)(`span`,{className:`text-[var(--color-fg-4)] mr-2 uppercase tracking-wider`,children:[`[`,e.type,`]`]}),e.args.map(iu).join(` `)]},e.id)),(0,W.jsx)(`div`,{ref:p})]})})]})]}):(0,W.jsxs)(G,{children:[(0,W.jsxs)(K,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`runtime inspector`}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(lr,{variant:`amber`,children:e.connecting?`connecting…`:`available`}),!e.connecting&&(0,W.jsx)(J,{variant:`ghost`,size:`sm`,onClick:b,children:`connect`})]})]}),(0,W.jsx)(q,{children:(0,W.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,W.jsxs)(G,{children:[(0,W.jsxs)(K,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`runtime inspector`}),(0,W.jsx)(lr,{variant:`outline`,children:`inactive`})]}),(0,W.jsx)(q,{children:(0,W.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:[`the bun inspector is not active. restart`,` `,(0,W.jsx)(`code`,{className:`text-[var(--color-brand)]`,children:`ssg serve`}),` to enable it automatically.`]})})]})}function ou(){let[e,t]=(0,_.useState)(0),{data:n}=z(`/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)},[n?.lines.length]);let a=n?.lines??[];return(0,W.jsxs)(G,{children:[(0,W.jsxs)(K,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`daemon log`}),(0,W.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,W.jsxs)(q,{children:[n?.error&&(0,W.jsx)(`p`,{className:`text-xs text-red-300 font-mono mb-2`,children:n.error}),a.length===0&&!n?.error&&(0,W.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,W.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:[`no log entries yet. start the daemon with`,` `,(0,W.jsx)(`code`,{className:`text-[var(--color-brand)]`,children:`ssg serve`}),` to generate log output.`]})}),a.length>0&&(0,W.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(`
|
|
19
19
|
`),(0,W.jsx)(`div`,{ref:r})]})]})]})}function su(){let e=je([`runtime-tick`,`rules-changed`]),{data:t,refetch:n}=z(`/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:Ae()})).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:Ae()}),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,W.jsxs)(`div`,{className:`space-y-5`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`h1`,{className:`text-xl font-medium tracking-tight text-[var(--color-fg-0)]`,children:`Observability`}),(0,W.jsx)(`p`,{className:`text-[12px] font-mono text-[var(--color-fg-3)] mt-0.5`,children:`sqlite health · rule drift · runtime profiler · diagnostics`})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] tabular-nums`,children:[`refreshed `,Zl(s)]}),(0,W.jsx)(J,{variant:`ghost`,size:`sm`,onClick:n,children:`refresh`})]})]}),(0,W.jsx)(cu,{db:v,audit:b,proc:x,flight:S,driftDetected:C}),(0,W.jsxs)(G,{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,W.jsxs)(K,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`rule drift detector`}),(0,W.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:`— .rules files vs sqlite`}),(0,W.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,W.jsx)(lr,{variant:`red`,children:`⚠ drift detected`}):(0,W.jsx)(lr,{variant:`green`,children:`✓ in sync`}))]}),(0,W.jsxs)(q,{children:[a&&(0,W.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,W.jsxs)(`div`,{className:`text-[var(--color-fg-2)]`,children:[(0,W.jsx)(`code`,{children:`.rules files`}),` and `,(0,W.jsx)(`code`,{children:`db rules`}),` are`,` `,(0,W.jsx)(`span`,{className:`text-amber-300`,children:`not auto-synced`}),`. A mismatch is usually expected:`]}),(0,W.jsxs)(`ul`,{className:`space-y-1 pl-3 list-disc marker:text-[var(--color-fg-4)]`,children:[(0,W.jsxs)(`li`,{children:[(0,W.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:`one file can hold many rules`}),` `,`— compare `,(0,W.jsx)(`code`,{children:`db rules`}),` against`,` `,(0,W.jsx)(`code`,{children:`file_rule_count`}),`, not `,(0,W.jsx)(`code`,{children:`file_count`}),`.`]}),(0,W.jsxs)(`li`,{children:[(0,W.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:`only in files`}),` `,`means unsynced edits — run`,` `,(0,W.jsx)(`code`,{className:`text-amber-300`,children:`ssg sync`}),` or click`,` `,(0,W.jsx)(`code`,{children:`↑ sync files → db`}),`.`]}),(0,W.jsxs)(`li`,{children:[(0,W.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:`only in db`}),` `,`with `,(0,W.jsx)(`code`,{children:`source_file IS NULL`}),` is healthy — hub, fleet, or cloud-synced rules legitimately live only in the db.`]}),(0,W.jsxs)(`li`,{children:[(0,W.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:`only in db`}),` `,`with `,(0,W.jsx)(`code`,{children:`source_file`}),` set means an orphan from a deleted file — `,(0,W.jsx)(`code`,{className:`text-amber-300`,children:`ssg sync`}),` `,`prunes it.`]}),(0,W.jsxs)(`li`,{children:[(0,W.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:`db rules`}),` `,`includes disabled rows; `,(0,W.jsx)(`code`,{children:`db_enabled_count`}),` `,`excludes them.`]})]}),(0,W.jsxs)(`div`,{className:`pt-1.5 border-t border-[var(--color-line-0)]`,children:[`full reference:`,` `,(0,W.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,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.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,W.jsx)(nc,{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,W.jsxs)(`div`,{children:[(0,W.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,W.jsxs)(`div`,{className:`mt-3 space-y-3`,children:[y.drift_details.only_in_files.length>0&&(0,W.jsxs)(`div`,{children:[(0,W.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,W.jsx)(`code`,{className:`text-amber-300`,children:`ssg sync`})]}),(0,W.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,W.jsxs)(`div`,{className:`font-mono text-[11px] text-amber-200/80`,children:[`+ `,e]},e))})]}),y.drift_details.only_in_db.length>0&&(0,W.jsxs)(`div`,{children:[(0,W.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,W.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,W.jsxs)(`div`,{className:`font-mono text-[11px] text-red-200/80`,children:[`− `,e]},e))})]})]})]}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2 pt-3 border-t border-[var(--color-line-0)]`,children:[(0,W.jsx)(J,{variant:`primary`,size:`sm`,onClick:h,disabled:l===`loading`,children:l===`loading`?`syncing…`:`↑ sync files → db`}),(0,W.jsx)(J,{variant:`ghost`,size:`sm`,onClick:g,disabled:p===`loading`,children:p===`loading`?`…`:p===`done`?`✓ reloaded`:`↻ force reload`}),(0,W.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,W.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,W.jsxs)(`span`,{children:[`✓ `,d]}),(0,W.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,W.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,W.jsxs)(`span`,{children:[`✗ `,d]}),(0,W.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,W.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,W.jsxs)(`span`,{children:[`rules dir:`,` `,(0,W.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:y.rules_dir})]}),(0,W.jsxs)(`span`,{className:`ml-auto`,children:[`last reload:`,` `,(0,W.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:Zl(y.last_reload_at)})]})]})]}):(0,W.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`loading…`})]})]}),(0,W.jsxs)(`div`,{className:`grid grid-cols-1 lg:grid-cols-2 gap-5`,children:[(0,W.jsxs)(G,{children:[(0,W.jsxs)(K,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`sqlite database`}),v&&!v.error&&(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,W.jsx)(eu,{ok:v.journal_mode===`wal`,label:`wal`,badLabel:`no wal`}),(0,W.jsx)(eu,{ok:v.synchronous===`NORMAL`,label:`normal`,badLabel:v.synchronous})]})]}),(0,W.jsx)(q,{children:v?v.error?(0,W.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,W.jsxs)(`div`,{children:[(0,W.jsx)(Ql,{children:`storage`}),(0,W.jsx)($l,{label:`file path`,value:v.path}),(0,W.jsx)($l,{label:`file size`,value:ql(v.file_size_bytes)}),(0,W.jsx)($l,{label:`allocated`,value:`${ql(v.allocated_bytes)} (${v.page_count.toLocaleString()} pages × ${v.page_size}B)`}),(0,W.jsx)(Ql,{className:`mt-4`,children:`pragma configuration`}),(0,W.jsx)($l,{label:`journal_mode`,value:v.journal_mode,accent:v.journal_mode===`wal`?`text-emerald-300`:`text-amber-300`}),(0,W.jsx)($l,{label:`synchronous`,value:v.synchronous,accent:v.synchronous===`NORMAL`?`text-emerald-300`:`text-amber-300`}),(0,W.jsx)($l,{label:`cache_size`,value:`${v.cache_size_kb.toLocaleString()} KB (${Math.round(v.cache_size_kb/1024)} MB)`}),(0,W.jsx)($l,{label:`page_size`,value:`${v.page_size.toLocaleString()} B`}),v.wal_checkpoint&&(0,W.jsx)($l,{label:`wal checkpoint`,value:`log ${v.wal_checkpoint.log}, checkpointed ${v.wal_checkpoint.checkpointed}, busy ${v.wal_checkpoint.busy}`}),(0,W.jsx)(Ql,{className:`mt-4`,children:`table row counts`}),v.tables.map(e=>(0,W.jsx)($l,{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,W.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`loading…`})})]}),(0,W.jsxs)(`div`,{className:`space-y-5`,children:[(0,W.jsxs)(G,{children:[(0,W.jsx)(K,{children:(0,W.jsx)(`span`,{className:`overline`,children:`audit log capacity`})}),(0,W.jsx)(q,{children:b?(0,W.jsxs)(`div`,{className:`space-y-4`,children:[(0,W.jsx)(tu,{pct:b.utilization_pct,total:b.total_rows,max:b.max_rows}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)($l,{label:`total rows`,value:b.total_rows.toLocaleString()}),(0,W.jsx)($l,{label:`rotation limit`,value:b.max_rows.toLocaleString()}),(0,W.jsx)($l,{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,W.jsx)($l,{label:`oldest entry`,value:Xl(b.oldest_timestamp)}),(0,W.jsx)($l,{label:`newest entry`,value:Xl(b.newest_timestamp)})]}),b.utilization_pct>=85&&(0,W.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,W.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`loading…`})})]}),(0,W.jsxs)(G,{children:[(0,W.jsx)(K,{children:(0,W.jsx)(`span`,{className:`overline`,children:`process & runtime`})}),(0,W.jsx)(q,{children:x?(0,W.jsxs)(`div`,{children:[(0,W.jsx)($l,{label:`pid`,value:x.pid}),(0,W.jsx)($l,{label:`uptime`,value:Yl(x.uptime_ms)}),(0,W.jsx)($l,{label:`memory (rss)`,value:`${x.memory_rss_mb} MB`}),(0,W.jsx)($l,{label:`bun version`,value:x.bun_version}),(0,W.jsx)($l,{label:`node compat`,value:x.node_version}),(0,W.jsx)($l,{label:`platform`,value:`${x.platform} / ${x.arch}`})]}):(0,W.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`loading…`})})]})]})]}),(0,W.jsxs)(G,{children:[(0,W.jsx)(K,{children:(0,W.jsx)(`span`,{className:`overline`,children:`flight recorder`})}),(0,W.jsx)(q,{children:S?(0,W.jsxs)(`div`,{className:`grid grid-cols-3 gap-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`overline mb-1.5`,children:`log file`}),(0,W.jsx)(`div`,{className:`text-xs font-mono text-[var(--color-fg-1)] truncate`,children:`…${S.path.slice(-50)}`})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`overline mb-1.5`,children:`file size`}),(0,W.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:ql(S.file_size_bytes)})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`overline mb-1.5`,children:`approx. entries`}),(0,W.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,W.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`loading…`})})]}),(0,W.jsx)(au,{}),(0,W.jsx)(ou,{}),(0,W.jsxs)(G,{children:[(0,W.jsx)(K,{children:(0,W.jsx)(`span`,{className:`overline`,children:`observability api`})}),(0,W.jsxs)(q,{children:[(0,W.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,W.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,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`GET`}),(0,W.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`text-[var(--color-brand)]/80 hover:text-[var(--color-brand)] transition-colors`,children:e}),(0,W.jsxs)(`span`,{className:`text-[var(--color-fg-4)] hidden sm:inline`,children:[`— `,t]})]},e))})]})]})]})}function cu({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,W.jsxs)(`div`,{className:`grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4`,children:[(0,W.jsxs)(Gl,{title:`sqlite`,status:a,statusLabel:e?.journal_mode?.toUpperCase()??`idle`,children:[(0,W.jsx)(Kl,{label:`size`,value:e?(0,W.jsx)(mr,{value:e.file_size_bytes,format:e=>Jl(e)}):`—`,mono:!0}),(0,W.jsx)(Kl,{label:`journal`,value:e?.journal_mode??`—`,mono:!0}),(0,W.jsx)(Kl,{label:`sync`,value:e?.synchronous??`—`,mono:!0}),(0,W.jsx)(Kl,{label:`tables`,value:e?.tables.length??0,tone:i?`warn`:`neutral`})]}),(0,W.jsxs)(Gl,{title:`audit log`,status:o,statusLabel:t?`${t.utilization_pct}%`:`idle`,children:[(0,W.jsx)(Kl,{label:`rows`,value:t?(0,W.jsx)(mr,{value:t.total_rows}):`—`}),(0,W.jsx)(Kl,{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,W.jsx)(Kl,{label:`oldest`,value:Xl(t?.oldest_timestamp??null),mono:!0}),(0,W.jsx)(Kl,{label:`newest`,value:Xl(t?.newest_timestamp??null),mono:!0})]}),(0,W.jsxs)(Gl,{title:`process`,status:s,statusLabel:n?`pid ${n.pid}`:`idle`,children:[(0,W.jsx)(Kl,{label:`uptime`,value:n?Yl(n.uptime_ms):`—`,mono:!0}),(0,W.jsx)(Kl,{label:`rss`,value:n?(0,W.jsxs)(`span`,{children:[(0,W.jsx)(mr,{value:n.memory_rss_mb,format:e=>e.toFixed(0)}),(0,W.jsx)(`span`,{className:`text-[var(--color-fg-3)] ml-1`,children:`MB`})]}):`—`}),(0,W.jsx)(Kl,{label:`bun`,value:n?.bun_version??`—`,mono:!0}),(0,W.jsx)(Kl,{label:`platform`,value:n?`${n.platform}/${n.arch}`:`—`,mono:!0})]}),(0,W.jsxs)(Gl,{title:`flight recorder`,status:r&&r.file_size_bytes>0?`ok`:`unknown`,statusLabel:r?`${r.approx_entries.toLocaleString()} entries`:`idle`,children:[(0,W.jsx)(Kl,{label:`size`,value:r?(0,W.jsx)(mr,{value:r.file_size_bytes,format:e=>Jl(e)}):`—`,mono:!0}),(0,W.jsx)(Kl,{label:`entries`,value:r?(0,W.jsx)(mr,{value:r.approx_entries}):`—`})]})]})}var lu=900,uu=180,du=320,fu=800,pu=4;function mu({sessionKey:e}={}){let t=De(),n=ke(),[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&&Ra(t)!==e)return;let u=Date.now(),d=s.current,f=d[0];if(f&&u-l.current<fu){f.extra+=1,f.burst=t,f.seq=n,l.current=u;return}if(d.length>=pu&&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]),(0,_.useEffect)(()=>{if(a===`idle`)return;let e=null;return a===`in`?e=setTimeout(()=>o(`visible`),uu):a===`visible`?e=setTimeout(()=>o(`out`),lu):a===`out`&&(e=setTimeout(()=>{let e=s.current.shift()??null;e?(i(e),o(`in`)):(i(null),o(`idle`))},du)),u.current=e,()=>{e&&clearTimeout(e)}},[a]),!r)return null;let{burst:d,extra:f}=r,p=za[d.decision]??`#ef4444`,m=ct(),h=a===`in`||a===`visible`?1:0,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,W.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 ${uu}ms ease-out`:`opacity ${uu}ms ease-out, transform ${uu}ms cubic-bezier(0.34, 1.56, 0.64, 1)`},"aria-live":`polite`,"aria-atomic":`true`,children:(0,W.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,W.jsx)(`div`,{className:`w-2.5 h-2.5 rounded-full shrink-0`,style:{background:p,boxShadow:m?`none`:`0 0 16px ${p}`}}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-0.5 min-w-0`,children:[(0,W.jsxs)(`div`,{className:`text-[11px] font-mono uppercase tracking-[0.18em]`,style:{color:p},children:[y,` BY SSG`]}),(0,W.jsx)(`div`,{className:`text-[14px] font-mono text-[var(--color-fg-1)] truncate max-w-[420px]`,children:v}),(0,W.jsx)(`div`,{className:`text-[11px] font-mono text-[var(--color-fg-3)] truncate max-w-[420px]`,children:b})]})]})})}var hu=(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,D=T>=0?t.slice(T+1):``,O=(0,_.useRef)(null),[ee,te]=(0,_.useState)(!0),[k,A]=(0,_.useState)(null),ne=()=>{let e=O.current;if(!e)return;let t=e.querySelector(`canvas`);t instanceof HTMLCanvasElement&&A(t.toDataURL(`image/png`))},re=()=>{if(!k)return;let e=document.createElement(`a`),n=t.replace(/[^a-z0-9._-]+/gi,`-`);e.href=k,e.download=`ssg-graph-${n}-${Date.now()}.png`,document.body.appendChild(e),e.click(),e.remove()},ie=()=>{!k||!navigator.clipboard?.write||fetch(k).then(e=>e.blob()).then(e=>{let t=new ClipboardItem({"image/png":e});return navigator.clipboard.write([t])}).catch(()=>{})},j=typeof navigator<`u`&&typeof navigator.clipboard?.write==`function`&&typeof ClipboardItem<`u`;(0,_.useEffect)(()=>{if(f){te(!0);return}let e=O.current;if(!e)return;let t=new IntersectionObserver(e=>{for(let t of e)te(t.isIntersecting)},{threshold:.01});return t.observe(e),()=>t.disconnect()},[f]);let M=n.length>0?n[n.length-1]:null,ae=M?za[M.decision]??`#6b7280`:`#6b7280`,oe=M?.decision??null,se=M?.tool??null,N=r||!ee||d,P=(0,_.useMemo)(()=>n.length>24?n.slice(n.length-24):n,[n]);return(0,W.jsxs)(`div`,{ref:O,className:`relative flex flex-col shrink-0 rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] overflow-hidden transition-opacity duration-1000${f?` flex-1 min-h-0`:``}`,style:{minHeight:d||f?void 0:l,opacity:c?0:1},children:[!C&&(0,W.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,W.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono min-w-0`,children:[u&&(0,W.jsx)(`span`,{className:`text-amber-300`,title:`Pinned`,children:`▲`}),(0,W.jsx)(`span`,{className:`text-[var(--color-fg-2)] uppercase tracking-wider`,children:E}),D&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,W.jsx)(`span`,{className:`text-[var(--color-fg-3)] truncate`,children:D})]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono text-[var(--color-fg-4)]`,children:[se&&(0,W.jsxs)(`span`,{className:`flex items-center gap-1.5 max-w-[180px]`,title:oe?`latest: ${se} → ${oe}`:`latest: ${se}`,children:[(0,W.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0`,style:{background:ae}}),(0,W.jsx)(`span`,{className:`truncate text-[var(--color-fg-2)]`,children:se})]}),(0,W.jsxs)(`span`,{className:`hidden md:inline opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity`,children:[n.length,`n`]}),s?(0,W.jsxs)(`span`,{className:`flex items-center gap-1.5 text-amber-300`,children:[(0,W.jsx)(`span`,{className:`status-dot bg-amber-400`}),(0,W.jsx)(`span`,{className:`hidden sm:inline`,children:`idle`})]}):(0,W.jsxs)(`span`,{className:`flex items-center gap-1.5 text-emerald-300`,children:[(0,W.jsx)(`span`,{className:`status-dot bg-emerald-400 pulse-soft`}),(0,W.jsx)(`span`,{className:`hidden sm:inline`,children:`live`})]}),!m&&(0,W.jsxs)(`div`,{className:`flex items-center gap-1 ml-1 opacity-0 group-hover:opacity-100 group-focus-within:opacity-100 transition-opacity duration-150`,children:[(0,W.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,W.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,W.jsx)(`button`,{type:`button`,onClick:ne,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,W.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,W.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,W.jsx)(Ss,{sessionKey:t,className:`rounded-none border-x-0 border-t-0 border-b border-[var(--color-line-1)] shrink-0`}),k&&(0,W.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,W.jsx)(`img`,{src:k,alt:`Panel snapshot`,className:`max-w-full max-h-[60%] rounded-sm border border-[var(--color-line-1)] object-contain`}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[j&&(0,W.jsx)(`button`,{type:`button`,onClick:ie,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,W.jsx)(`button`,{type:`button`,onClick:re,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,W.jsx)(`button`,{type:`button`,onClick:()=>A(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,W.jsxs)(`div`,{className:`flex-1 min-h-0 relative`,children:[(0,W.jsx)(mu,{sessionKey:t}),(0,W.jsx)(hs,{bursts:P,paused:N,selectedId:i,onSelect:a,burstSeq:o,compact:!0,activePanelCount:g,labelDensity:w,onFrameTime:S}),m&&(0,W.jsx)(`button`,{type:`button`,onClick:h,"aria-label":`Promote ${E} to spotlight`,title:`Spotlight ${E}${D?` · ${D}`:``}`,className:`absolute inset-0 cursor-pointer bg-transparent hover:bg-sky-400/5 transition-colors`})]})]})}),gu=200;function _u(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 vu(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 yu(e){let{bursts:t,selectedId:n,onSelect:r}=e,i=(0,_.useMemo)(()=>{let e=new Map;for(let n of t){let t=Ra(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,W.jsxs)(`div`,{className:`flex-1 flex flex-col items-center justify-center text-center px-4`,children:[(0,W.jsx)(`p`,{className:`overline mb-2 text-[var(--color-fg-3)]`,children:`feed · idle`}),(0,W.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,W.jsx)(`br`,{}),`Color = the ssg rule decision.`]})]}):(0,W.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=i>=0?e.slice(i+1):``,s=t[t.length-1],c=s?za[s.decision]??`#6b7280`:`#6b7280`,l=t.slice(-gu).reverse();return(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 mb-2 pb-1 border-b border-[var(--color-line-1)] text-[10px] font-mono uppercase tracking-wider`,children:[(0,W.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0`,style:{background:c}}),(0,W.jsx)(`span`,{className:`text-[var(--color-fg-2)]`,children:a}),o&&o!==`solo`&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,W.jsx)(`span`,{className:`text-[var(--color-fg-3)] truncate max-w-[120px]`,children:o})]}),(0,W.jsxs)(`span`,{className:`ml-auto text-[var(--color-fg-4)]`,children:[t.length,` calls`]})]}),(0,W.jsxs)(`div`,{className:`relative pl-4`,children:[(0,W.jsx)(`div`,{className:`absolute left-[7px] top-0 bottom-0 w-px`,style:{background:`${c}33`}}),(0,W.jsx)(`div`,{className:`space-y-1.5`,children:l.map(e=>{let t=e.audit_id??`${e.ts_ms}:${e.tool}`,i=t===n,a=za[e.decision]??`#6b7280`,o=e.input_tokens??0,s=e.output_tokens??0,c=o>0||s>0;return(0,W.jsxs)(`div`,{className:`relative`,children:[(0,W.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,W.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-[11px] font-mono 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,W.jsx)(`span`,{className:`flex-1 font-semibold truncate text-[var(--color-fg-1)]`,children:e.tool}),(0,W.jsxs)(`span`,{className:`shrink-0 flex items-center gap-2 text-[9px] text-[var(--color-fg-4)]`,children:[c&&(0,W.jsxs)(`span`,{className:`font-mono`,title:`Input: ${o} tokens · Output: ${s} tokens`,children:[`↓`,Ka(o),` `,`↑`,Ka(s)]}),e.duration_ns>0&&(0,W.jsx)(`span`,{children:vu(e.duration_ns)}),(0,W.jsx)(`span`,{className:`px-1 py-px rounded text-[8px] uppercase font-bold tracking-wide`,style:{color:a,background:`${a}22`},children:e.decision}),(0,W.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:_u(e.ts_ms)})]})]})]},t)})})]})]},e)})})}function bu(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=Math.max(1,i-r),m=(t.playhead_ms-r)/p*100,h=Math.max(0,Math.min(100,m)),g=(0,_.useMemo)(()=>{let e=[];for(let t=0;t<200;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)/p*199)];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,p]),v=(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*p)},[r,p,o,s]);(0,_.useEffect)(()=>{let e=e=>{f.current&&v(e.clientX)},t=()=>{f.current=!1};return window.addEventListener(`pointermove`,e),window.addEventListener(`pointerup`,t),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t)}},[v]);let y=t.mode===`live`;return(0,W.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 text-[11px] font-mono uppercase tracking-wider`,children:[(0,W.jsx)(`button`,{onClick:()=>y?c():l(),className:`px-2.5 py-1 rounded-sm border transition-colors cursor-pointer ${y?`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:y?`Pause the live stream`:`Resume updates at this playhead`,children:y?`⏸ pause`:`▶ resume`}),(0,W.jsx)(`button`,{onClick:s,disabled:y,className:`px-2.5 py-1 rounded-sm border transition-colors cursor-pointer ${y?`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,W.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,W.jsx)(`div`,{className:`flex-1`}),(0,W.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`mode`}),(0,W.jsx)(`span`,{className:y?`text-emerald-300`:t.mode===`paused`?`text-amber-300`:`text-violet-300`,children:t.mode}),a&&(0,W.jsx)(`span`,{className:`text-[var(--color-fg-4)] animate-pulse`,children:`· backfilling`}),(0,W.jsxs)(`span`,{className:`text-[var(--color-fg-4)]`,children:[`· t=`,xu(t.playhead_ms)]})]}),(0,W.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),v(e.clientX)},children:[(0,W.jsx)(`svg`,{viewBox:`0 0 200 40`,preserveAspectRatio:`none`,className:`absolute inset-0 w-full h-full`,"aria-hidden":!0,children:g.map((e,t)=>{let n=e.allow+e.block+e.ask+e.other;if(n===0)return null;let r=Math.min(32,n*3),i=e.block>0?za.block:e.ask>0?za.ask:za.allow;return(0,W.jsx)(`rect`,{x:t,y:40-r,width:.9,height:r,fill:i,opacity:.7},t)})}),(0,W.jsx)(`div`,{className:`absolute top-0 bottom-0 w-px bg-sky-300 pointer-events-none`,style:{left:`${h}%`},children:(0,W.jsx)(`div`,{className:`absolute -top-0.5 -translate-x-1/2 w-2 h-2 rotate-45 bg-sky-300`})}),y&&(0,W.jsx)(`div`,{className:`absolute top-0 right-0 bottom-0 w-[2px] bg-emerald-400 animate-pulse pointer-events-none`})]}),(0,W.jsxs)(`div`,{className:`flex items-center justify-between text-[10px] font-mono text-[var(--color-fg-4)]`,children:[(0,W.jsx)(`span`,{children:Su(r)}),(0,W.jsxs)(`span`,{className:`uppercase tracking-wider`,children:[Cu(t.window_ms),` window`]}),(0,W.jsx)(`span`,{children:Su(i)})]})]})}function xu(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 Su(e){return new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`,second:`2-digit`})}function Cu(e){return e<6e4?`${Math.round(e/1e3)}s`:e<36e5?`${Math.round(e/6e4)}m`:`${Math.round(e/36e5)}h`}var wu=320,Tu=8,Eu=12;function Du(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+Eu+wu>r?n.x-Eu-wu:n.x+Eu,l=n.y+Eu+s>a?n.y-Eu-s:n.y+Eu;c=Math.min(Math.max(Tu,c),r-wu-Tu),l=Math.min(Math.max(Tu,l),a-s-Tu),o({left:c,top:l})},[t,n]),(0,_.useEffect)(()=>{o({left:-9999,top:-9999})},[t]),!t||!n)return null;let s=za[t.decision]??`#6b7280`,c=t.duration_ns/1e6,l=Date.now()-t.ts_ms;return(0,W.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:wu,maxHeight:`80vh`,overflowY:`auto`},children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsx)(`span`,{className:`overline text-[var(--color-fg-3)]`,children:`node · inspect`}),(0,W.jsx)(`button`,{onClick:r,className:`text-[var(--color-fg-4)] hover:text-[var(--color-fg-1)] cursor-pointer`,title:`Close inspector`,children:`✕`})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`span`,{className:`w-2 h-2 rounded-full`,style:{background:s},"aria-hidden":!0}),(0,W.jsx)(`span`,{className:`uppercase tracking-wider`,style:{color:s},children:t.decision}),(0,W.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`·`}),(0,W.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:t.tool})]}),(0,W.jsxs)(`dl`,{className:`grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-[11px]`,children:[(0,W.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`rule`}),(0,W.jsx)(`dd`,{className:`text-[var(--color-fg-2)] break-all`,children:t.rule_id??`—`}),(0,W.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`client`}),(0,W.jsx)(`dd`,{className:`text-[var(--color-fg-2)]`,children:t.client}),(0,W.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`agent`}),(0,W.jsx)(`dd`,{className:`text-[var(--color-fg-2)]`,children:t.agent_id?(0,W.jsx)(`span`,{className:`chip text-violet-300 border-violet-500/30`,children:t.agent_id}):(0,W.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`—`})}),(0,W.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`eval duration`}),(0,W.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,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`tool duration`}),(0,W.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,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`reason`}),(0,W.jsx)(`dd`,{className:`text-[var(--color-fg-2)] break-words`,children:t.message})]}),(t.input_tokens!=null||t.output_tokens!=null)&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`tokens`}),(0,W.jsx)(`dd`,{className:`text-[var(--color-fg-2)]`,children:Au(t.input_tokens,t.output_tokens)})]}),(0,W.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`age`}),(0,W.jsx)(`dd`,{className:`text-[var(--color-fg-2)]`,children:Ou(l)}),(0,W.jsx)(`dt`,{className:`text-[var(--color-fg-4)]`,children:`timestamp`}),(0,W.jsx)(`dd`,{className:`text-[var(--color-fg-2)]`,children:new Date(t.ts_ms).toLocaleString()})]}),t.input_preview&&(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`overline text-[var(--color-fg-3)] mb-1`,children:`input`}),(0,W.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,W.jsxs)(`div`,{className:`flex flex-wrap gap-1`,children:[t.audit_id&&(0,W.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,W.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 Ou(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 ku(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 Au(e,t){let n=[];return e!=null&&n.push(`${ku(e)} in`),t!=null&&n.push(`${ku(t)} out`),n.length>0?n.join(` · `):`—`}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 za[t];return`#6b7280`};return(0,W.jsxs)(`div`,{className:`flex flex-col gap-3 text-[11px] font-mono`,children:[(0,W.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,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{className:`overline text-[var(--color-fg-3)] mb-1`,children:[`rules · `,o.length,` matched`,s>0&&(0,W.jsxs)(`span`,{className:`ml-2 text-[var(--color-fg-4)] normal-case tracking-normal`,children:[s,` unmatched`]})]}),o.length===0?(0,W.jsx)(`p`,{className:`text-[var(--color-fg-4)]`,children:`no rules matched in window`}):(0,W.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,W.jsxs)(`li`,{className:`grid grid-cols-[1fr_auto] items-center gap-2`,title:`${e.id} — decisions: ${Array.from(e.decisions).join(`, `)}`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,W.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0`,style:{background:n},"aria-hidden":!0}),(0,W.jsx)(`a`,{href:`/rules#${encodeURIComponent(e.id)}`,className:`truncate text-[var(--color-fg-2)] hover:text-[var(--color-fg-1)]`,children:e.id}),(0,W.jsx)(`div`,{className:`flex-1 h-1 bg-[var(--color-surface-1)] rounded-sm overflow-hidden`,children:(0,W.jsx)(`div`,{className:`h-full`,style:{background:n,width:`${t}%`,opacity:.6}})})]}),(0,W.jsx)(`span`,{className:`tabular-nums text-[var(--color-fg-4)]`,children:e.count})]},e.id)})})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsx)(`div`,{className:`overline text-[var(--color-fg-3)] mb-1`,children:`decisions`}),(0,W.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,W.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,W.jsx)(`span`,{className:`w-2 h-2 rounded-full shrink-0`,style:{background:za[e]},"aria-hidden":!0}),(0,W.jsx)(`span`,{className:`text-[var(--color-fg-2)] uppercase tracking-wider`,children:e}),(0,W.jsx)(`span`,{className:`text-[var(--color-fg-4)] tabular-nums`,children:t})]},e)})})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{className:`overline text-[var(--color-fg-3)] mb-1`,children:[`agents · `,c.length,` active`,n&&n!==t&&(0,W.jsx)(`span`,{className:`ml-2 text-[var(--color-fg-4)] normal-case tracking-normal`,children:`roster: today`})]}),c.length===0?(0,W.jsx)(`p`,{className:`text-[var(--color-fg-4)]`,children:`no agents in window`}):(0,W.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,W.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,W.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[i?(0,W.jsx)(`span`,{className:`status-dot bg-emerald-400 pulse-soft shrink-0`,"aria-hidden":!0}):(0,W.jsx)(`span`,{className:`w-1.5 h-1.5 rounded-full shrink-0 bg-[var(--color-fg-4)]/40`,"aria-hidden":!0}),(0,W.jsxs)(`span`,{className:`truncate text-[var(--color-fg-2)]`,children:[e.client,(0,W.jsxs)(`span`,{className:`text-[var(--color-fg-4)]`,children:[`:`,e.agent_id]})]}),(0,W.jsx)(`div`,{className:`flex-1 h-1 bg-[var(--color-surface-1)] rounded-sm overflow-hidden`,children:(0,W.jsx)(`div`,{className:`h-full bg-violet-400/60`,style:{width:`${t}%`}})})]}),(0,W.jsx)(`span`,{className:`tabular-nums text-[var(--color-fg-4)]`,children:e.count})]},n)})})]}),(0,W.jsxs)(`div`,{children:[(0,W.jsxs)(`div`,{className:`overline text-[var(--color-fg-3)] mb-1`,children:[`tools · `,t.length,` in window`]}),i.length===0?(0,W.jsx)(`p`,{className:`text-[var(--color-fg-4)]`,children:`no tool activity`}):(0,W.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,W.jsxs)(`li`,{className:`grid grid-cols-[1fr_auto] items-center gap-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2 min-w-0`,children:[(0,W.jsx)(`span`,{className:`truncate text-[var(--color-fg-2)]`,children:e}),(0,W.jsx)(`div`,{className:`flex-1 h-1 bg-[var(--color-surface-1)] rounded-sm overflow-hidden`,children:(0,W.jsx)(`div`,{className:`h-full bg-sky-400/60`,style:{width:`${n}%`}})})]}),(0,W.jsx)(`span`,{className:`tabular-nums text-[var(--color-fg-4)]`,children:t})]},e)})})]})]})}var Nu=[100,500,1e3,5e3,1e4,1e5];function Pu(e){return e>=1e5||e>=1e3?`${e/1e3|0}k`:String(e)}function Fu(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 Iu(e){let t=Math.floor(e/100);return`${Math.floor(t/10)}.${t%10}s`}function Lu({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=De(),C=ke(),w=Oe(),T=(0,_.useRef)(null),E=(0,_.useRef)(0),D=(0,_.useRef)(0),O=(0,_.useRef)(0),ee=(0,_.useRef)(0),te=(0,_.useRef)(new Set),k=(0,_.useRef)(performance.now());(0,_.useEffect)(()=>{let e=performance.now();if(ct()){let t=setInterval(()=>{let t=performance.now();r.current&&(r.current.textContent=Fu(t-e)),i.current&&(i.current.textContent=Iu(t-k.current))},1e3);return()=>clearInterval(t)}let[t]=br(()=>{let t=performance.now();r.current&&(r.current.textContent=Fu(t-e)),i.current&&(i.current.textContent=Iu(t-k.current))});return t},[]);let A=(0,_.useRef)(0);return(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=Nu.find(e=>e>ee.current&&r>=e);return i&&(ee.current=i,g(Pu(i)),x(!0),t?.(),setTimeout(()=>{g(``),x(!1)},700)),r});let r=Date.now();if(r-A.current>=1e3){A.current=r;let e=w.filter(e=>r-e.ts_ms<=6e4);f(new Set(e.map(e=>`${e.client}:${e.agent_id??`solo`}`)).size)}S?.rule_id&&te.current.add(S.rule_id),m(te.current.size),S&&(S.decision===`block`?(D.current=0,o(0),k.current=performance.now()):(D.current+=e,D.current>O.current&&(O.current=D.current,c(O.current),y(!0),n?.(),setTimeout(()=>y(!1),450)),o(D.current)))},[C,S,w,t,n]),(0,W.jsxs)(`div`,{className:U(`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,W.jsx)(Ru,{label:`uptime`,children:(0,W.jsx)(`span`,{ref:r,className:`tabular-nums text-[var(--color-fg-0,#e6e8ed)] text-[15px] tracking-tight`,children:`00:00.0`})}),(0,W.jsx)(Ru,{label:`evals`,children:(0,W.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,W.jsx)(mr,{value:l,className:`text-[var(--color-fg-0,#e6e8ed)] text-[15px]`}),h&&(0,W.jsxs)(`span`,{className:`text-[10px] text-emerald-400 uppercase tracking-wide`,children:[`+`,h]})]})}),(0,W.jsx)(Ru,{label:`since block`,children:(0,W.jsx)(`span`,{ref:i,className:`tabular-nums text-emerald-300 text-[15px]`,children:`0.0s`})}),(0,W.jsx)(Ru,{label:`streak / best`,children:(0,W.jsxs)(`span`,{className:U(`tabular-nums text-[15px]`,v?`record-beat`:`text-[var(--color-fg-0,#e6e8ed)]`),children:[(0,W.jsx)(mr,{value:a,curve:`spring`}),(0,W.jsx)(`span`,{className:`text-[var(--color-fg-4,#5a6071)] mx-1`,children:`/`}),(0,W.jsx)(mr,{value:s})]})}),(0,W.jsx)(Ru,{label:`agents`,children:(0,W.jsx)(mr,{value:d,className:`text-[var(--color-fg-0,#e6e8ed)] text-[15px]`})}),(0,W.jsx)(Ru,{label:`rules`,children:(0,W.jsx)(mr,{value:p,className:`text-[var(--color-fg-0,#e6e8ed)] text-[15px]`})})]})}function Ru({label:e,children:t}){return(0,W.jsxs)(`div`,{className:`flex items-baseline justify-between gap-3`,children:[(0,W.jsx)(`span`,{className:`uppercase tracking-wider text-[10px] text-[var(--color-fg-4,#5a6071)]`,children:e}),t]})}var zu=1200,Bu=3e4,Vu=3e3,Hu=6,Uu=3,Wu=`graph.panelState.v1`,Gu=14400*1e3;function Ku(e,t){let n=new Map;for(let t of e){let e=Ra(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 qu(){if(typeof window>`u`)return new Map;try{let e=window.localStorage.getItem(Wu);if(!e)return new Map;let t=JSON.parse(e);return new Map(Object.entries(t))}catch{return new Map}}function Ju(e){if(!(typeof window>`u`))try{let t={};for(let[n,r]of e)t[n]=r;window.localStorage.setItem(Wu,JSON.stringify(t))}catch{}}function Yu(){let e=to(),t=ke(),n=De(),[r,i]=(0,_.useState)(null),[a,o]=(0,_.useState)(null),s=(0,_.useCallback)((e,t)=>{i(e),o(t??null)},[]),c=As();(0,_.useEffect)(()=>{n&&(n.decision===`block`?c.play(`block`):n.decision===`force`&&c.play(`force`))},[t]);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),D=(0,_.useRef)(null),O=(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),D.current&&clearTimeout(D.current)},[]),ee=(0,_.useCallback)(e=>{if(!T){E(!0),D.current&&clearTimeout(D.current),D.current=setTimeout(()=>E(!1),3e3);return}O(e)},[T,O]);(0,_.useEffect)(()=>()=>{D.current&&clearTimeout(D.current)},[]);let te=(0,_.useRef)(new Map),k=(0,_.useRef)(0),[A,ne]=(0,_.useState)({fps:0,active:0,hitches:0}),re=(0,_.useCallback)((e,t)=>{te.current.set(e,t),t>33&&(k.current+=1)},[]);(0,_.useEffect)(()=>{let e=setInterval(()=>{let e=te.current,t=k.current;if(k.current=0,e.size===0){ne(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;ne(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:ie,playback:j,oldest_known_ms:M,newest_known_ms:ae,loading_backfill:oe}=e.snapshot,se=(0,_.useRef)(new Map),N=(0,_.useMemo)(()=>{let e=Ku(ie,se.current);return se.current=e,e},[ie]),[P,F]=(0,_.useState)(()=>qu()),[ce,I]=(0,_.useState)(null);(0,_.useEffect)(()=>{Ju(P)},[P]),(0,_.useEffect)(()=>{let e=Date.now(),t=!1,n=new Map(P);for(let r of N.keys())n.has(r)||(n.set(r,{pinned:!1,pinnedAt:0,minimized:!1,firstSeenAt:e}),t=!0);for(let[r,i]of n)N.has(r)||i.pinned||e-i.firstSeenAt<Gu||(n.delete(r),t=!0);t&&F(n)},[N,P]);let le=(0,_.useRef)(new Map),ue=(0,_.useRef)(new Set),de=(0,_.useRef)(new Map),[,fe]=(0,_.useState)(0);(0,_.useEffect)(()=>{let e=performance.now(),t=le.current,n=ue.current,r=de.current,i=new Set;for(let[e,n]of N)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>=zu&&(t.delete(n),r.delete(n));if(ue.current=i,t.size>0){let n=1/0;for(let e of t.values())n=Math.min(n,e.diedAt+zu);let r=Math.max(16,n-e+16),i=setTimeout(()=>fe(e=>e+1),r);return()=>clearTimeout(i)}},[N]);let pe=(0,_.useCallback)(e=>{F(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})},[]),me=(0,_.useCallback)(e=>{F(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})},[]),he=(0,_.useCallback)(e=>{I(t=>t===e?null:e)},[]);(0,_.useEffect)(()=>{if(!ce)return;let e=e=>{e.key===`Escape`&&I(null)};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)},[ce]);let L=(0,_.useMemo)(()=>{let e={pinned:!1,pinnedAt:0,minimized:!1,firstSeenAt:Date.now()},t=[];for(let[n,r]of N){let i=r[r.length-1]?.ts_ms??0;t.push({key:n,bursts:r,newestTs:i,fadingOutAt:null,state:P.get(n)??e})}for(let[n,r]of le.current)N.has(n)||t.push({key:n,bursts:r.bursts,newestTs:r.newestTs,fadingOutAt:r.diedAt,state:P.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},[N,P]),ge=(0,_.useMemo)(()=>{if(!r)return null;for(let e of ie)if((e.audit_id??`${e.ts_ms}:${e.tool}`)===r||r.startsWith(`${e.ts_ms}:${e.tool}`))return e;return null},[ie,r]),[_e,ve]=(0,_.useState)(null),ye=(0,_.useRef)(null),be=(0,_.useMemo)(()=>{if(L.length===0)return ye.current=null,null;if(_e!=null&&L.some(e=>e.key===_e))return ye.current=_e,_e;let e=L.filter(e=>e.state.pinned);if(e.length>0)return e.sort((e,t)=>t.state.pinnedAt-e.state.pinnedAt),ye.current=e[0].key,e[0].key;let t=L[0];for(let e of L)e.newestTs>t.newestTs&&(t=e);let n=ye.current;if(n!=null&&n!==t.key){let e=L.find(e=>e.key===n);if(e&&Date.now()-e.newestTs<Vu)return n}return ye.current=t.key,t.key},[L,_e]);(0,_.useEffect)(()=>{_e!=null&&(L.some(e=>e.key===_e)||ve(null))},[_e,L]),(0,_.useEffect)(()=>{ve(null)},[d]);let R=(0,_.useMemo)(()=>{if(L.length===0)return{hero:null,grid:[],rail:[],overflow:[]};if(d===`full`||d===`feed`)return{hero:null,grid:L.slice(0,Hu),rail:L.slice(Hu),overflow:[]};let e=L.find(e=>e.key===be)??L[L.length-1],t=L.filter(t=>t.key!==e.key);return d===`broadcast`?{hero:e,grid:[],rail:[],overflow:t}:{hero:e,grid:[],rail:t.slice(0,Uu),overflow:t.slice(Uu)}},[L,d,be]),xe=(0,_.useCallback)(e=>{ve(e)},[]),Se=(0,_.useCallback)(()=>{ve(null)},[]),Ce=(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 L){let s=o.key;e.set(s,()=>pe(s)),t.set(s,()=>me(s)),n.set(s,()=>he(s)),r.set(s,()=>void O([s])),i.set(s,e=>re(s,e)),a.set(s,()=>xe(s))}return{onTogglePin:e,onToggleMinimize:t,onToggleFullscreen:n,onClose:r,onFrameTime:i,onPromote:a}},[L.map(e=>e.key).join(`,`),pe,me,he,O,re,xe]);(0,_.useEffect)(()=>{let e=new Set(L.map(e=>e.key)),t=te.current;for(let n of Array.from(t.keys()))e.has(n)||t.delete(n)},[L]);let we=(0,_.useMemo)(()=>{let e=n?.counters,t=e?.total??0,r=(e?.block??0)+(e?.force??0),i=0;if(ie.length>0){let e=0,t=ie.slice(-100);for(let n of t)e+=n.duration_ns;i=e/t.length/1e6}return{evals:t,blocks:r,avgMs:i,agents:L.length}},[n,ie,L.length]),Te=Math.min(M,j.playhead_ms-j.window_ms),Ee=Math.max(ae,j.playhead_ms),Oe=R.grid.length,Ae=C||Oe<=1?1:Oe<=4?2:3,je=Math.max(1,Math.ceil(Math.max(1,Oe)/Ae)),z=Oe<=1||C?360:180,Me=ce?L.find(e=>e.key===ce):null,Ne=e=>e>=1e4?`${Math.round(e/1e3)}k`:e.toLocaleString();return(0,W.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,W.jsxs)(`header`,{className:`flex items-center justify-between flex-wrap gap-y-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3 flex-wrap`,children:[(0,W.jsx)(`h1`,{className:`text-sm font-mono uppercase tracking-wider text-[var(--color-fg-1)]`,children:`graph intelligence`}),!p&&(0,W.jsx)(`span`,{className:`chip text-sky-300 border-sky-500/30`,children:`real-time tool-use`}),j.mode===`live`?(0,W.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] font-mono uppercase tracking-wider text-emerald-300`,children:[(0,W.jsx)(`span`,{className:`status-dot bg-emerald-400 pulse-soft`}),`streaming`]}):(0,W.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] font-mono uppercase tracking-wider text-amber-300`,children:[(0,W.jsx)(`span`,{className:`status-dot bg-amber-400`}),j.mode]}),(0,W.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,W.jsxs)(`span`,{title:`Total evaluations since daemon start`,children:[(0,W.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`↑`}),` `,(0,W.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:Ne(we.evals)}),` `,(0,W.jsx)(`span`,{className:`hidden sm:inline`,children:`evals`})]}),(0,W.jsxs)(`span`,{title:`Block + force decisions — dangerous tool calls intercepted by SSG rules`,children:[(0,W.jsx)(`span`,{className:`text-rose-400`,children:`⛔`}),` `,(0,W.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:Ne(we.blocks)}),` `,(0,W.jsx)(`span`,{className:`hidden sm:inline`,children:`blocks`})]}),(0,W.jsxs)(`span`,{className:`hidden md:inline`,title:`Mean eval latency over the last 100 bursts`,children:[(0,W.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`⏱`}),` `,(0,W.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:we.avgMs<1?`${(we.avgMs*1e3).toFixed(0)}µs`:`${we.avgMs.toFixed(1)}ms`})]}),(0,W.jsxs)(`span`,{title:`Concurrent agent sessions in this window`,children:[(0,W.jsx)(`span`,{className:`text-[var(--color-fg-4)]`,children:`⌥`}),` `,(0,W.jsx)(`span`,{className:`text-[var(--color-fg-1)]`,children:we.agents}),` `,(0,W.jsxs)(`span`,{className:`hidden sm:inline`,children:[`agent`,we.agents===1?``:`s`]})]})]})]}),(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[!p&&(0,W.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:[ie.length,`n · window `,Math.round(j.window_ms/1e3),`s`]}),(0,W.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)] tabular-nums`,title:`Average RAF interval across ${A.active} canvas${A.active===1?``:`es`}${A.hitches>0?` · ${A.hitches} hitch${A.hitches===1?``:`es`} (>33ms frames)`:``}`,children:[A.active===0?`—`:`${A.fps}fps${A.hitches>0?` (${A.hitches}h)`:``}`,` · `,A.active,`/`,L.length]}),(0,W.jsx)(`div`,{role:`group`,"aria-label":`Graph view mode`,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,n=e===`broadcast`?`cast`:e,r=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)`;return(0,W.jsx)(`button`,{type:`button`,onClick:()=>f(e),"aria-pressed":t,title:r,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:n},e)})}),(0,W.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&&L.length>0&&(0,W.jsx)(`div`,{"aria-live":`polite`,children:(0,W.jsx)(`button`,{type:`button`,"aria-label":`Clear all visible graph sessions`,onClick:()=>ee(L.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 ${L.filter(e=>!e.fadingOutAt).length}`:`clear`})})]})]}),(0,W.jsxs)(`div`,{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,W.jsx)(`div`,{className:`flex flex-col gap-3 min-h-0 min-w-0`,children:h?(0,W.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,W.jsx)(yu,{bursts:ie,selectedId:r,onSelect:s})}):L.length===0?(0,W.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,W.jsx)(`p`,{className:`overline mb-2 text-[var(--color-fg-3)]`,children:`graph · idle`}),(0,W.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,W.jsxs)(W.Fragment,{children:[R.hero&&(ce==null||ce===R.hero.key)&&(0,W.jsxs)(`div`,{className:`flex-1 min-h-0 flex flex-col gap-2`,children:[_e!=null&&(0,W.jsx)(`button`,{type:`button`,onClick:Se,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,W.jsx)(`div`,{className:`flex-1 min-h-0`,children:(0,W.jsx)(hu,{sessionKey:R.hero.key,bursts:R.hero.bursts,paused:j.mode!==`live`||R.hero.fadingOutAt!=null,selectedId:r,onSelect:s,burstSeq:t,isStale:R.hero.fadingOutAt!=null||j.playhead_ms-R.hero.newestTs>Bu,isFadingOut:R.hero.fadingOutAt!=null,minHeight:0,pinned:R.hero.state.pinned,minimized:R.hero.state.minimized,isFullscreen:!1,viewMode:d,activePanelCount:1,onTogglePin:Ce.onTogglePin.get(R.hero.key),onToggleMinimize:Ce.onToggleMinimize.get(R.hero.key),onToggleFullscreen:Ce.onToggleFullscreen.get(R.hero.key),onClose:Ce.onClose.get(R.hero.key),onFrameTime:Ce.onFrameTime.get(R.hero.key)},R.hero.key)})]}),R.grid.length>0&&(0,W.jsx)(`div`,{className:`flex-1 grid gap-3 min-h-0 min-w-0`,style:{gridTemplateColumns:`repeat(${Ae}, minmax(0, 1fr))`,gridTemplateRows:`repeat(${je}, minmax(180px, 1fr))`},children:R.grid.map(e=>{let n=e.fadingOutAt!=null||j.playhead_ms-e.newestTs>Bu;return ce!=null&&ce!==e.key?null:(0,W.jsx)(hu,{sessionKey:e.key,bursts:e.bursts,paused:j.mode!==`live`||e.fadingOutAt!=null,selectedId:r,onSelect:s,burstSeq:t,isStale:n,isFadingOut:e.fadingOutAt!=null,minHeight:z,pinned:e.state.pinned,minimized:e.state.minimized,isFullscreen:!1,viewMode:d,activePanelCount:R.grid.length,onTogglePin:Ce.onTogglePin.get(e.key),onToggleMinimize:Ce.onToggleMinimize.get(e.key),onToggleFullscreen:Ce.onToggleFullscreen.get(e.key),onClose:Ce.onClose.get(e.key),onFrameTime:Ce.onFrameTime.get(e.key)},e.key)})}),R.rail.length>0&&(0,W.jsxs)(`div`,{className:`shrink-0 flex flex-col gap-1`,children:[(0,W.jsxs)(`div`,{className:`flex items-baseline justify-between text-[10px] font-mono text-[var(--color-fg-4)] uppercase tracking-wider`,children:[(0,W.jsxs)(`span`,{children:[d===`full`?`overflow rail`:`spotlight rail`,` · `,R.rail.length,` session`,R.rail.length===1?``:`s`]}),R.overflow.length>0&&(0,W.jsxs)(`span`,{title:R.overflow.map(e=>e.key).join(`
|
|
20
|
-
`),children:[`+`,R.overflow.length,` more`]})]}),(0,W.jsx)(`div`,{className:`grid gap-2`,style:{gridTemplateColumns:`repeat(${Math.min(R.rail.length,4)}, minmax(0, 1fr))`,gridAutoRows:`110px`},children:R.rail.map(e=>{let n=e.fadingOutAt!=null||j.playhead_ms-e.newestTs>Bu;return ce!=null&&ce!==e.key?null:(0,W.jsx)(hu,{sessionKey:e.key,bursts:e.bursts,paused:j.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:Ce.onPromote.get(e.key),activePanelCount:R.rail.length+1,onTogglePin:Ce.onTogglePin.get(e.key),onToggleMinimize:Ce.onToggleMinimize.get(e.key),onToggleFullscreen:Ce.onToggleFullscreen.get(e.key),onClose:Ce.onClose.get(e.key),onFrameTime:Ce.onFrameTime.get(e.key)},e.key)})})]}),d===`broadcast`&&R.overflow.length>0&&(0,W.jsxs)(`div`,{className:`shrink-0 self-end pointer-events-none chip text-[var(--color-fg-3)] border-[var(--color-line-1)]`,children:[`+`,R.overflow.length,` more session`,R.overflow.length===1?``:`s`,` off-screen`]})]})}),!v&&(0,W.jsxs)(`aside`,{className:`flex flex-col gap-2 min-w-0 min-h-0 overflow-y-auto`,children:[(0,W.jsx)(Lu,{onMilestone:l,onRecord:u}),!y&&(0,W.jsx)(`section`,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3`,children:(0,W.jsx)(Mu,{bursts:ie,allBursts:e.allBursts})}),(0,W.jsx)(Du,{burst:ge,anchor:a,onClose:()=>{i(null),o(null)}})]})]}),!g&&(0,W.jsx)(`section`,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3`,children:(0,W.jsx)(bu,{playback:j,bursts:ie,rangeStart:Te,rangeEnd:Ee,loading:oe,onPlayhead:t=>e.setPlayhead(t),onLive:()=>e.jumpToLive(),onPause:()=>e.setMode(`paused`),onResume:()=>e.setMode(`scrubbing`),on24h:()=>e.jumpTo24h()})}),p&&(0,W.jsxs)(`div`,{className:`pointer-events-none fixed bottom-3 right-4 flex flex-col items-end gap-1 z-30`,children:[(0,W.jsx)(`span`,{className:`text-[11px] font-mono uppercase tracking-[0.18em] text-[var(--color-fg-3)]`,children:`sigmashake gov`}),(0,W.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:`broadcast mode · press B or Esc to exit`})]}),Me&&(0,W.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/90 backdrop-blur-sm flex flex-col p-6`,children:(0,W.jsx)(hu,{sessionKey:Me.key,bursts:Me.bursts,paused:j.mode!==`live`||Me.fadingOutAt!=null,selectedId:r,onSelect:s,burstSeq:t,
|
|
20
|
+
`),children:[`+`,R.overflow.length,` more`]})]}),(0,W.jsx)(`div`,{className:`grid gap-2`,style:{gridTemplateColumns:`repeat(${Math.min(R.rail.length,4)}, minmax(0, 1fr))`,gridAutoRows:`110px`},children:R.rail.map(e=>{let n=e.fadingOutAt!=null||j.playhead_ms-e.newestTs>Bu;return ce!=null&&ce!==e.key?null:(0,W.jsx)(hu,{sessionKey:e.key,bursts:e.bursts,paused:j.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:Ce.onPromote.get(e.key),activePanelCount:R.rail.length+1,onTogglePin:Ce.onTogglePin.get(e.key),onToggleMinimize:Ce.onToggleMinimize.get(e.key),onToggleFullscreen:Ce.onToggleFullscreen.get(e.key),onClose:Ce.onClose.get(e.key),onFrameTime:Ce.onFrameTime.get(e.key)},e.key)})})]}),d===`broadcast`&&R.overflow.length>0&&(0,W.jsxs)(`div`,{className:`shrink-0 self-end pointer-events-none chip text-[var(--color-fg-3)] border-[var(--color-line-1)]`,children:[`+`,R.overflow.length,` more session`,R.overflow.length===1?``:`s`,` off-screen`]})]})}),!v&&(0,W.jsxs)(`aside`,{className:`flex flex-col gap-2 min-w-0 min-h-0 overflow-y-auto`,children:[(0,W.jsx)(Lu,{onMilestone:l,onRecord:u}),!y&&(0,W.jsx)(`section`,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3`,children:(0,W.jsx)(Mu,{bursts:ie,allBursts:e.allBursts})}),(0,W.jsx)(Du,{burst:ge,anchor:a,onClose:()=>{i(null),o(null)}})]})]}),!g&&(0,W.jsx)(`section`,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3`,children:(0,W.jsx)(bu,{playback:j,bursts:ie,rangeStart:Te,rangeEnd:Ee,loading:oe,onPlayhead:t=>e.setPlayhead(t),onLive:()=>e.jumpToLive(),onPause:()=>e.setMode(`paused`),onResume:()=>e.setMode(`scrubbing`),on24h:()=>e.jumpTo24h()})}),p&&(0,W.jsxs)(`div`,{className:`pointer-events-none fixed bottom-3 right-4 flex flex-col items-end gap-1 z-30`,children:[(0,W.jsx)(`span`,{className:`text-[11px] font-mono uppercase tracking-[0.18em] text-[var(--color-fg-3)]`,children:`sigmashake gov`}),(0,W.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:`broadcast mode · press B or Esc to exit`})]}),Me&&(0,W.jsx)(`div`,{className:`fixed inset-0 z-50 bg-black/90 backdrop-blur-sm flex flex-col p-6`,children:(0,W.jsx)(hu,{sessionKey:Me.key,bursts:Me.bursts,paused:j.mode!==`live`||Me.fadingOutAt!=null,selectedId:r,onSelect:s,burstSeq:t,isStale:Me.fadingOutAt!=null||j.playhead_ms-Me.newestTs>Bu,isFadingOut:!1,minHeight:0,pinned:Me.state.pinned,minimized:!1,isFullscreen:!0,viewMode:d,onTogglePin:()=>pe(Me.key),onToggleMinimize:()=>me(Me.key),onToggleFullscreen:()=>he(Me.key)},`fs-${Me.key}`)})]})}var Xu=[{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`}];function Zu(){let[e,t]=(0,_.useState)(`rca`);return(0,W.jsxs)(`div`,{className:`flex flex-col gap-4 min-h-[70vh]`,children:[(0,W.jsxs)(`header`,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsx)(`h1`,{className:`text-sm font-mono uppercase tracking-wider text-[var(--color-fg-1)]`,children:`ai-native debugger`}),(0,W.jsx)(`span`,{className:`chip text-sky-300 border-sky-500/30`,children:`ssg:// unified resolver`}),(0,W.jsx)(Qu,{})]}),(0,W.jsx)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)]`,children:`one surface · cli · mcp · dashboard`})]}),(0,W.jsx)(`nav`,{className:`flex items-center gap-1 border-b border-[var(--color-line-1)]`,children:Xu.map(n=>(0,W.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,W.jsxs)(`section`,{className:`flex-1 min-h-0`,children:[e===`rca`&&(0,W.jsx)($u,{}),e===`timeline`&&(0,W.jsx)(id,{}),e===`watch`&&(0,W.jsx)(fd,{}),e===`state`&&(0,W.jsx)(pd,{uri:`ssg://daemon/state`}),e===`metrics`&&(0,W.jsx)(pd,{uri:`ssg://daemon/metrics`})]})]})}function Qu(){let e=je([`debug-frame`])[`debug-frame`]??0;return(0,W.jsxs)(`span`,{className:`flex items-center gap-1.5 text-[11px] font-mono uppercase tracking-wider text-emerald-300`,title:`${e} debug-frame bursts received`,children:[(0,W.jsx)(`span`,{className:`status-dot bg-emerald-400 pulse-soft`}),`live · `,e]})}function $u(){let e=je([`debug-frame`,`activity-updated`]),{data:t,loading:n,error:r,refetch:i}=z(`/api/json/debug?uri=ssg%3A%2F%2Frca%2Fcurrent`,[e[`debug-frame`],e[`activity-updated`]]),a=t?.data?.pack??null;return(0,W.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-[1fr_340px] gap-4`,children:[(0,W.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,W.jsx)(`p`,{className:`text-sm text-[var(--color-fg-4)]`,children:`loading RCA pack…`}),r&&(0,W.jsxs)(`p`,{className:`text-sm text-rose-300`,children:[`rca fetch error: `,r]}),!n&&!a&&(0,W.jsxs)(`div`,{className:`text-sm text-[var(--color-fg-3)] space-y-2`,children:[(0,W.jsx)(`p`,{className:`font-mono`,children:`no current RCA pack`}),(0,W.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,W.jsx)(td,{pack:a})]}),(0,W.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,W.jsx)(`p`,{className:`uppercase tracking-wider text-[var(--color-fg-2)]`,children:`how claude sees this`}),(0,W.jsxs)(`pre`,{className:`text-[10px] whitespace-pre-wrap leading-snug`,children:[`ssg debug rca --current --json`,`
|
|
21
21
|
`,`# or via MCP:`,`
|
|
22
22
|
`,`ssg_debug_rca(`,`{`,`auto_current:true`,`}`,`)`]}),(0,W.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,W.jsxs)(`p`,{className:`text-[10px] opacity-60`,children:[`hash `,t.snapshot_hash.slice(0,12),`…`]})]})]})}function ed(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 td({pack:e}){return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(`header`,{className:`flex items-start justify-between gap-4`,children:[(0,W.jsxs)(`div`,{children:[(0,W.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,W.jsx)(`h2`,{className:`text-[15px] font-medium text-[var(--color-fg-1)] mt-1`,children:e.summary}),e.trace_id&&(0,W.jsxs)(`p`,{className:`text-[11px] font-mono text-[var(--color-fg-4)] mt-1`,children:[`trace_id · `,e.trace_id]})]}),(0,W.jsx)(`span`,{className:`chip uppercase text-[10px] tracking-wider `+ed(e.severity),children:e.severity})]}),e.hypothesis&&e.hypothesis.length>0&&(0,W.jsxs)(`section`,{children:[(0,W.jsx)(`h3`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] mb-2`,children:`hypothesis`}),(0,W.jsx)(`ol`,{className:`space-y-2`,children:e.hypothesis.map((e,t)=>(0,W.jsxs)(`li`,{className:`p-2 rounded-sm bg-[var(--color-surface-2)] border border-[var(--color-line-1)]`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between gap-3`,children:[(0,W.jsx)(`p`,{className:`text-[13px] text-[var(--color-fg-1)]`,children:e.cause}),(0,W.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:[`conf `,(e.confidence*100).toFixed(0),`%`]})]}),e.evidence.length>0&&(0,W.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,W.jsx)(`li`,{children:e},t))})]},t))})]}),e.suggested_next_actions&&e.suggested_next_actions.length>0&&(0,W.jsxs)(`section`,{children:[(0,W.jsx)(`h3`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] mb-2`,children:`suggested next actions`}),(0,W.jsx)(`ul`,{className:`space-y-1 text-[13px] text-[var(--color-fg-2)]`,children:e.suggested_next_actions.map((e,t)=>(0,W.jsxs)(`li`,{className:`font-mono text-[12px]`,children:[`→ `,e]},t))})]}),e.state_snapshot&&e.state_snapshot.length>0&&(0,W.jsxs)(`section`,{children:[(0,W.jsx)(`h3`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] mb-2`,children:`expand`}),(0,W.jsx)(`ul`,{className:`space-y-1 text-[11px] font-mono`,children:e.state_snapshot.map(e=>(0,W.jsxs)(`li`,{className:`text-[var(--color-fg-3)]`,children:[(0,W.jsx)(`code`,{className:`text-sky-300`,children:e.uri}),(0,W.jsxs)(`span`,{className:`opacity-50 ml-2`,children:[e.hash.slice(0,10),`…`]})]},e.uri))})]})]})}var nd=[`hook-ingress`,`parse`,`match`,`ffi-call`,`decide`,`audit`,`respond`],rd={"hook-ingress":`#6ea8ff`,parse:`#a78bfa`,match:`#60d394`,"ffi-call":`#f59e0b`,decide:`#f472b6`,audit:`#94a3b8`,respond:`#22d3ee`};function id(){let{data:e,loading:t,error:n}=z(`/api/json/debug?uri=ssg%3A%2F%2Fframes%2Frecent%3Flimit%3D1024`,[je([`debug-frame`])[`debug-frame`]]),r=e?.data?.frames??[],i=e?.data?.dropped??0,[a,o]=(0,_.useState)(null);return(0,W.jsxs)(`div`,{className:`grid grid-cols-1 xl:grid-cols-[1fr_320px] gap-4`,children:[(0,W.jsxs)(`article`,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3 space-y-2`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`h3`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)]`,children:[`frames · `,r.length,i>0&&(0,W.jsxs)(`span`,{className:`ml-2 text-amber-300`,children:[`dropped · `,i]})]}),(0,W.jsx)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:`ssg://frames/recent`})]}),n&&(0,W.jsxs)(`p`,{className:`text-sm text-rose-300`,children:[`timeline fetch error: `,n]}),t&&r.length===0?(0,W.jsx)(`p`,{className:`text-sm text-[var(--color-fg-4)]`,children:`loading…`}):r.length===0?(0,W.jsx)(ad,{}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(sd,{frames:r,onSelect:o}),(0,W.jsx)(od,{})]})]}),(0,W.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,W.jsx)(`p`,{className:`uppercase tracking-wider text-[var(--color-fg-2)]`,children:`frame inspector`}),a?(0,W.jsx)(cd,{frame:a}):(0,W.jsx)(`p`,{className:`opacity-60`,children:`click a bar to inspect`})]})]})}function ad(){return(0,W.jsxs)(`div`,{className:`text-[12px] text-[var(--color-fg-3)] space-y-1 py-4`,children:[(0,W.jsx)(`p`,{children:`no frames yet`}),(0,W.jsx)(`p`,{className:`text-[11px] text-[var(--color-fg-4)] font-mono`,children:`SSG_DEBUG_ENABLED=1 ssg daemon`}),(0,W.jsx)(`p`,{className:`text-[11px] text-[var(--color-fg-4)]`,children:`then fire an eval — frames stream in live.`})]})}function od(){return(0,W.jsx)(`div`,{className:`flex flex-wrap gap-3 text-[10px] font-mono text-[var(--color-fg-4)]`,children:nd.map(e=>(0,W.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,W.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-sm`,style:{background:rd[e]}}),e]},e))})}function sd({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)=>ud(e.ts_start_ns,t.ts_start_ns))}));n.sort((e,t)=>ud(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=rd[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,W.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 cd({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,W.jsxs)(`dl`,{className:`space-y-1`,children:[(0,W.jsxs)(ld,{k:`stage`,children:[(0,W.jsx)(`span`,{className:`inline-block w-2 h-2 rounded-sm mr-1 align-middle`,style:{background:rd[e.stage]??`#888`}}),e.stage]}),(0,W.jsx)(ld,{k:`tool`,children:e.tool}),(0,W.jsx)(ld,{k:`result`,children:(0,W.jsx)(`span`,{className:e.result===`error`?`text-rose-300`:e.result===`skip`?`text-[var(--color-fg-4)]`:`text-emerald-300`,children:e.result})}),(0,W.jsx)(ld,{k:`dur`,children:n}),e.rule_id&&(0,W.jsx)(ld,{k:`rule`,children:e.rule_id}),e.error&&(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(ld,{k:`err.type`,children:(0,W.jsx)(`span`,{className:`text-rose-300`,children:e.error.type})}),(0,W.jsx)(ld,{k:`err.msg`,children:(0,W.jsx)(`span`,{className:`text-rose-200`,children:e.error.message})})]}),e.input_preview&&(0,W.jsx)(ld,{k:`input`,children:(0,W.jsx)(`code`,{className:`text-[10px] break-all`,children:e.input_preview})}),(0,W.jsx)(ld,{k:`trace`,children:(0,W.jsx)(`code`,{className:`text-[10px]`,children:e.trace_id})}),(0,W.jsx)(ld,{k:`frame`,children:(0,W.jsx)(`code`,{className:`text-[10px]`,children:e.frame_id})})]})}function ld({k:e,children:t}){return(0,W.jsxs)(`div`,{className:`flex gap-2 text-[11px] leading-tight`,children:[(0,W.jsx)(`dt`,{className:`text-[var(--color-fg-4)] w-16 shrink-0 uppercase tracking-wider`,children:e}),(0,W.jsx)(`dd`,{className:`text-[var(--color-fg-2)] break-all min-w-0`,children:t})]})}function ud(e,t){let n=BigInt(e),r=BigInt(t);return n<r?-1:n>r?1:0}var dd=[`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 fd(){let[e,t]=(0,_.useState)(`ssg://daemon/state`),[n,r]=(0,_.useState)(`ssg://daemon/state`);return(0,W.jsxs)(`div`,{className:`space-y-3`,children:[(0,W.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:dd.map(e=>(0,W.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,W.jsxs)(`form`,{className:`flex items-center gap-2`,onSubmit:t=>{t.preventDefault(),r(e)},children:[(0,W.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,W.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,W.jsx)(pd,{uri:n})]})}function pd({uri:e}){let t=je([`debug-frame`,`activity-updated`,`counters-updated`]),{data:n,loading:r,error:i,refetch:a}=z(`/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,W.jsxs)(`div`,{className:`rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-3 space-y-2`,children:[(0,W.jsxs)(`header`,{className:`flex items-center justify-between`,children:[(0,W.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,W.jsx)(`h3`,{className:`text-[10px] font-mono uppercase tracking-wider text-[var(--color-fg-3)]`,children:e}),n?.snapshot_hash&&(0,W.jsxs)(`span`,{className:`text-[10px] font-mono text-[var(--color-fg-4)]`,children:[`hash `,n.snapshot_hash.slice(0,10),`…`]}),n?.stale&&(0,W.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,W.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,W.jsx)(`p`,{className:`text-sm text-[var(--color-fg-4)]`,children:`resolving…`}),i&&(0,W.jsx)(`p`,{className:`text-sm text-rose-300`,children:i}),o&&(0,W.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 md=`ssg-dashboard-tabs`,hd=2e3,gd=6e3;function _d(){return`tab-${Date.now()}-${Math.random().toString(36).slice(2,7)}`}function vd(){let[e,t]=(0,_.useState)(0),[n,r]=(0,_.useState)(!0),i=(0,_.useRef)(_d()),a=(0,_.useRef)(new Map);return(0,_.useEffect)(()=>{if(typeof BroadcastChannel>`u`)return;let e=new BroadcastChannel(md);function n(){let e=Date.now();for(let[t,n]of a.current.entries())e-n>gd&&a.current.delete(t);let n=a.current.size;t(n),r([...a.current.keys(),i.current].sort()[0]===i.current)}function o(e){let t=e.data;!t||t.id===i.current||(t.type===`leave`?a.current.delete(t.id):a.current.set(t.id,Date.now()),n())}e.addEventListener(`message`,o),e.postMessage({type:`join`,id:i.current});let s=setInterval(()=>{e.postMessage({type:`heartbeat`,id:i.current}),n()},hd),c=()=>{e.postMessage({type:`leave`,id:i.current})};return window.addEventListener(`beforeunload`,c),()=>{clearInterval(s),e.postMessage({type:`leave`,id:i.current}),e.removeEventListener(`message`,o),e.close(),window.removeEventListener(`beforeunload`,c)}},[]),{otherTabCount:e,isLeader:n}}var $=b;function yd(){(0,_.useEffect)(()=>we([]),[]);let e=(0,_.useSyncExternalStore)(ge,_e),[,t]=(0,_.useState)(0);(0,_.useEffect)(()=>{if(e.connected||e.lastErrorAt===null)return;let n=setInterval(()=>t(e=>e+1),1e3);return()=>clearInterval(n)},[e.connected,e.lastErrorAt]);let n=bd(e),r=n===`reconnecting`&&e.lastErrorAt!==null?Math.max(0,Math.ceil((e.lastErrorAt+e.reconnectDelayMs-Date.now())/1e3)):null,i=Math.round($/1e3);if(n===`connected`)return(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)]`,title:`Telemetry Live — SSE connected`,"data-testid":`sse-status-chip`,"data-state":`connected`,children:[(0,W.jsx)(`span`,{className:`status-dot bg-emerald-400`}),(0,W.jsx)(`span`,{className:`hidden sm:inline`,children:`sse · live`})]});let a=n===`reconnecting`,o=a?`border-amber-500/40 bg-amber-500/10 text-amber-200`:`border-red-500/40 bg-red-500/10 text-red-200`,s=a?`bg-amber-400`:`bg-red-400`,c=a?r===null?`reconnecting`:`reconnect · ${r}s`:`offline`,l=`live paused · ${i}s poll`,u=a?`Live stream down — reconnect in ${r??`…`}s (attempt ${e.reconnectAttempts}). Dashboard is polling every ${i}s until SSE recovers.`:`Live stream disconnected. Dashboard is polling every ${i}s — data still updates, just at a coarser cadence.`;return(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 rounded border px-2 py-0.5 text-[11px] font-mono uppercase tracking-wider ${o}`,title:u,"data-testid":`sse-status-chip`,"data-state":n,role:`status`,"aria-live":`polite`,children:[(0,W.jsx)(`span`,{className:`status-dot ${s} pulse-soft`}),(0,W.jsx)(`span`,{className:`hidden md:inline`,children:l}),(0,W.jsx)(`span`,{className:`md:hidden`,children:c})]})}function bd(e){return e.connected?`connected`:e.reconnectAttempts>0||e.lastErrorAt!==null?`reconnecting`:`disconnected`}var xd=`ssg:ui:font-scale:v1`,Sd=[{label:`S`,value:.9},{label:`M`,value:1},{label:`L`,value:1.15},{label:`XL`,value:1.3}],Cd=1;function wd(e){if(typeof e!=`number`||!Number.isFinite(e))return Cd;let t=Sd.find(t=>Math.abs(t.value-e)<.001);return t?t.value:Cd}function Td(){if(typeof localStorage>`u`)return Cd;try{let e=localStorage.getItem(xd);return e===null?Cd:wd(parseFloat(e))}catch{return Cd}}function Ed(e){if(!(typeof localStorage>`u`))try{localStorage.setItem(xd,String(e))}catch{}}function Dd(e){typeof document>`u`||(document.documentElement.style.setProperty(`--ssg-font-scale`,String(e)),document.documentElement.style.fontSize=`${16*e}px`)}function Od(){let[e,t]=(0,_.useState)(()=>{let e=Td();return Dd(e),e});return(0,_.useEffect)(()=>{Dd(e)},[e]),{scale:e,setScale:(0,_.useCallback)(e=>{t(e),Ed(e),Dd(e)},[])}}function kd(){let{scale:e,setScale:t}=Od();return(0,W.jsx)(`div`,{role:`radiogroup`,"aria-label":`Font size`,className:`flex items-center gap-0.5 rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] p-0.5`,children:Sd.map(n=>{let r=Math.abs(n.value-e)<.001;return(0,W.jsx)(`button`,{role:`radio`,"aria-checked":r,onClick:()=>t(n.value),title:`Font size: ${n.label} (${Math.round(n.value*100)}%)`,className:`px-1.5 py-0.5 text-[10px] font-mono uppercase tracking-wider cursor-pointer transition-colors rounded-sm `+(r?`bg-[var(--color-surface-3)] text-[var(--color-fg-0)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`),children:n.label},n.label)})})}var Ad=4200,jd=3,Md=700,Nd=[100,500,1e3,5e3,1e4,1e5],Pd=[25,50,100,250,500],Fd=[10,25,50,100],Id=[10,25,50,100,200],Ld={gold:`border-amber-400/60 bg-amber-500/10 text-amber-200`,green:`border-emerald-500/50 bg-emerald-500/10 text-emerald-200`,red:`border-red-500/50 bg-red-500/10 text-red-200`,sky:`border-sky-500/50 bg-sky-500/10 text-sky-200`},Rd={gold:`★`,green:`✓`,red:`⌖`,sky:`◆`};function zd(){let e=Oe(),[t,n]=(0,_.useState)([]),r=(0,_.useRef)(0),i=(0,_.useRef)({totalAnnounced:0,allowStreakAnnounced:0,blockStreakAnnounced:0,comboAnnounced:0,lastBurstTs:0,allowStreakLive:0,blockStreakLive:0,comboLive:0,firstOfDayDate:``,seenAuditIds:new Set});if((0,_.useEffect)(()=>{if(e.length===0)return;let t=i.current,a=[],o=e=>{a.push({...e,id:++r.current,bornAt:performance.now()})};for(let n=0;n<e.length;n++){let r=e[n];if(!r)continue;let i=r.audit_id??`${r.ts_ms}:${r.tool}:${n}`;if(t.seenAuditIds.has(i))continue;if(t.seenAuditIds.add(i),t.seenAuditIds.size>1500){let e=t.seenAuditIds.values().next().value;e!==void 0&&t.seenAuditIds.delete(e)}r.ts_ms-t.lastBurstTs<=Md?t.comboLive++:t.comboLive=1,t.lastBurstTs=r.ts_ms,r.decision===`allow`?(t.allowStreakLive++,t.blockStreakLive=0):r.decision===`block`||r.decision===`force`?(t.blockStreakLive++,t.allowStreakLive=0):(t.allowStreakLive=0,t.blockStreakLive=0);let a=new Date(r.ts_ms).toISOString().slice(0,10);t.firstOfDayDate!==a&&(t.firstOfDayDate!==``&&o({title:`NEW DAY · GOVERNANCE LIVE`,subtitle:`first burst at ${new Date(r.ts_ms).toLocaleTimeString()}`,tone:`sky`}),t.firstOfDayDate=a);for(let e of Id)if(t.comboLive>=e&&t.comboAnnounced<e){t.comboAnnounced=e,o({title:`${e}× COMBO`,subtitle:`agent is on fire`,tone:`gold`});break}t.comboLive<t.comboAnnounced&&(t.comboAnnounced=0);for(let e of Pd)if(t.allowStreakLive>=e&&t.allowStreakAnnounced<e){t.allowStreakAnnounced=e,o({title:`PERFECT STREAK · ${e} ALLOWS`,subtitle:`governance is letting work flow`,tone:`green`});break}t.allowStreakLive===0&&(t.allowStreakAnnounced=0);for(let e of Fd)if(t.blockStreakLive>=e&&t.blockStreakAnnounced<e){t.blockStreakAnnounced=e,o({title:`BLOCK STREAK · ${e}`,subtitle:`governance is doing real work`,tone:`red`});break}t.blockStreakLive===0&&(t.blockStreakAnnounced=0)}let s=e[e.length-1];if(s&&s.counters&&s.counters.total>0){for(let e of Nd)if(s.counters.total>=e&&t.totalAnnounced<e){t.totalAnnounced=e,o({title:`${e.toLocaleString()} EVALS TODAY`,subtitle:`you are shipping at scale`,tone:`gold`});break}}a.length>0&&n(e=>{let t=[...e,...a];return t.length>12?t.slice(-12):t})},[e]),(0,_.useEffect)(()=>{if(t.length===0)return;let e=setInterval(()=>{let e=performance.now();n(t=>t.filter(t=>e-t.bornAt<Ad))},1e3);return()=>clearInterval(e)},[t.length]),t.length===0)return null;let a=t.slice(-jd),o=ct();return(0,W.jsx)(`div`,{className:`fixed left-4 z-50 flex flex-col gap-2 pointer-events-none`,style:{maxWidth:320,bottom:112},children:a.map(e=>(0,W.jsxs)(`div`,{className:U(`flex items-start gap-2 px-3 py-2 rounded-sm border-l-2 font-mono text-[11px] shadow-lg`,Ld[e.tone],!o&&`achievement-toast-enter`),children:[(0,W.jsx)(`span`,{className:`text-base leading-none mt-0.5`,"aria-hidden":!0,children:Rd[e.tone]}),(0,W.jsxs)(`span`,{className:`flex flex-col`,children:[(0,W.jsx)(`span`,{className:`font-bold uppercase tracking-widest text-[11px]`,children:e.title}),(0,W.jsx)(`span`,{className:`text-[10px] opacity-80 normal-case tracking-normal`,children:e.subtitle})]})]},e.id))})}function Bd(){let[e,t]=(0,_.useState)(()=>Eo()),[n,r]=(0,_.useState)(()=>Oo()),[i,a]=(0,_.useState)(!1);return(0,_.useEffect)(()=>{Do(e)},[e]),(0,_.useEffect)(()=>{ko(n)},[n]),(0,W.jsxs)(`div`,{className:`relative flex items-center`,children:[(0,W.jsxs)(`button`,{onClick:()=>t(e=>!e),onContextMenu:e=>{e.preventDefault(),a(e=>!e)},className:`chip cursor-pointer transition-colors ${e?`text-emerald-300 border-emerald-500/40`:`text-[var(--color-fg-3)] border-[var(--color-line-1)]`}`,title:e?`Decision chimes ON · click to mute · right-click for volume`:`Decision chimes OFF · click to enable`,children:[e?`♪`:`♫`,` audio `,e?`on`:`off`]}),i&&(0,W.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-50 flex items-center gap-2 px-3 py-2 rounded-sm border border-[var(--color-line-1)] bg-[var(--color-surface-1)] shadow-lg`,onMouseLeave:()=>a(!1),children:[(0,W.jsx)(`span`,{className:`text-[10px] font-mono uppercase tracking-widest text-[var(--color-fg-4)]`,children:`volume`}),(0,W.jsx)(`input`,{type:`range`,min:0,max:1,step:.02,value:n,onChange:e=>r(parseFloat(e.target.value)),className:`w-24 accent-emerald-500`}),(0,W.jsx)(`span`,{className:`text-[10px] font-mono tabular-nums text-[var(--color-fg-2)] w-8 text-right`,children:Math.round(n*100)})]})]})}var Vd=[{path:`/`,label:`dashboard`},{path:`/graph`,label:`graph`},{path:`/rules`,label:`rules`},{path:`/audit`,label:`audit`},{path:`/approvals`,label:`approvals`},{path:`/hub`,label:`hub`},{path:`/profile`,label:`profile`},{path:`/monitor`,label:`monitor`},{path:`/observability`,label:`observability`},{path:`/debug`,label:`debug`}];function Hd(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 Ud(){let{data:e}=z(`/api/json/daemon-status`,[je([`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-emerald-400`:i===`starting`||i===`degraded`?`bg-amber-400`:`bg-red-400`,o=i===`starting`||i===`degraded`?`pulse-soft`:``,s=i===`degraded`&&e?.hibernation?Hd(e.hibernation.nextRetryAt):null,c=i===`running`?`daemon · online`:i===`starting`?`daemon · booting`:i===`degraded`?`daemon · retry ${s??`…`}`:i===`error`?`daemon · error`:`daemon · offline`;return(0,W.jsxs)(`div`,{className:`relative`,children:[(0,W.jsxs)(`button`,{onClick:()=>n(e=>!e),className:`flex items-center gap-1.5 text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] transition-colors cursor-pointer`,title:i===`running`?`Daemon running`:i===`starting`?`Daemon starting…`:i===`degraded`?`Daemon hibernating — retry in ${s??`…`}`:i===`error`?`Daemon error`:`Daemon stopped`,children:[(0,W.jsx)(`span`,{className:`status-dot ${a} ${o}`}),(0,W.jsx)(`span`,{className:`hidden sm:inline`,children:c})]}),t&&(0,W.jsxs)(`div`,{className:`absolute right-0 top-7 z-50 w-72 bg-[var(--color-surface-1)] border border-[var(--color-line-2)] rounded-sm shadow-xl p-3 text-xs`,children:[(0,W.jsxs)(`div`,{className:`flex items-center justify-between mb-2`,children:[(0,W.jsx)(`span`,{className:`overline`,children:`eval daemon`}),(0,W.jsx)(`button`,{onClick:()=>n(!1),className:`text-[var(--color-fg-4)] hover:text-[var(--color-fg-1)] cursor-pointer`,children:`✕`})]}),(0,W.jsxs)(`div`,{className:`space-y-1 text-[var(--color-fg-2)]`,children:[(0,W.jsxs)(`div`,{className:`font-mono text-[11px]`,children:[`status:`,` `,(0,W.jsx)(`span`,{className:i===`running`?`text-emerald-300`:i===`starting`||i===`degraded`?`text-amber-300`:`text-red-300`,children:i})]}),e?.pid&&(0,W.jsxs)(`div`,{className:`font-mono text-[11px]`,children:[`pid: `,e.pid]}),i===`degraded`&&e?.hibernation&&(0,W.jsxs)(`div`,{className:`mt-2 rounded-sm border border-amber-500/25 bg-amber-500/5 p-2 text-[11px] text-amber-300 space-y-0.5`,children:[(0,W.jsxs)(`div`,{children:[`next retry:`,` `,(0,W.jsx)(`span`,{className:`font-medium`,children:s})]}),(0,W.jsxs)(`div`,{children:[`episode attempt: `,e.hibernation.attempt,e.hibernation.reason?` (${e.hibernation.reason})`:``]}),(0,W.jsx)(`div`,{className:`text-amber-400/70`,children:`Slow-tier supervisor is retrying at long backoff — no manual restart required.`})]})]}),e?.logTail&&e.logTail.length>0&&(0,W.jsxs)(`div`,{className:`mt-3`,children:[(0,W.jsx)(`div`,{className:`overline mb-1`,children:`recent log`}),(0,W.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)] overflow-x-auto whitespace-pre-wrap break-all max-h-32 overflow-y-auto`,children:e.logTail.join(`
|
|
23
23
|
`)})]})]})]})}function Wd(){let{data:e}=z(`/api/state/activity-degraded`);if(!e?.degraded)return null;let t=e.since?new Date(e.since).toLocaleTimeString():`recently`;return(0,W.jsxs)(`div`,{role:`status`,className:`border-b border-amber-500/40 bg-amber-500/10 px-4 py-1.5 text-[11px] font-mono text-amber-200 text-center`,title:e.reason??`audit-worker degraded`,children:[`audit pipeline degraded since `,t,` — entries may be missing. Run`,` `,(0,W.jsx)(`code`,{className:`text-amber-100`,children:`ssg daemon --status`}),` to inspect.`]})}function Gd(){let{data:e}=z(`/api/json/license`,[je([`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,W.jsxs)(`div`,{role:`alert`,className:`border-b border-red-500/50 bg-red-500/10 px-4 py-1.5 text-[11px] font-mono text-red-200 text-center`,title:`Free tier daily eval limit reached — rules are being bypassed until quota resets`,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,W.jsx)(`a`,{href:e.upgrade_url,target:`_blank`,rel:`noopener noreferrer`,className:`text-red-100 underline hover:text-white`,children:`Upgrade to Pro →`})]})}function Kd(){let{data:e}=z(`/api/json/license`,[je([`counters-updated`])[`counters-updated`]]);return!e||e.status!==`needs_reauth`?null:(0,W.jsxs)(`div`,{role:`alert`,className:`border-b border-amber-500/50 bg-amber-500/10 px-4 py-1.5 text-[11px] font-mono text-amber-200 text-center`,title:`Re-authentication required — paid-tier features are paused until you re-login`,children:[`re-authentication required — `,e.detail??`License JWT invalid or expired`,`. Run`,` `,(0,W.jsx)(`code`,{className:`text-amber-100`,children:`ssg auth login`}),` in your terminal to restore your tier.`]})}function qd(){let{data:e,refetch:t}=z(`/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`,...Ae()},body:JSON.stringify({mode:e})}),t()}finally{r(!1)}}}let o=i===`tty`;return(0,W.jsxs)(`button`,{onClick:()=>a(o?`dashboard`:`tty`),disabled:n,className:`flex items-center gap-1.5 text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] transition-colors cursor-pointer 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,W.jsx)(`span`,{className:`status-dot ${o?`bg-sky-400`:`bg-violet-400`}`}),(0,W.jsx)(`span`,{className:`hidden sm:inline`,children:o?`ask · native`:`ask · dashboard`})]})}function Jd({onRefresh:e}){return(0,W.jsx)(`button`,{onClick:e,className:`flex items-center justify-center text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] transition-colors cursor-pointer p-1 rounded-sm`,title:`Reset page — clears stale graph state without dropping SSE`,"aria-label":`Refresh page`,children:(0,W.jsxs)(`svg`,{width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,W.jsx)(`path`,{d:`M21 12a9 9 0 1 1-3-6.7`}),(0,W.jsx)(`polyline`,{points:`21 3 21 9 15 9`})]})})}function Yd(){let{data:e}=z(`/api/json/mcp-status`,[je([`activity-updated`])[`activity-updated`]]),t=e?.status??`inactive`;if(t===`inactive`)return null;let n=t===`active`?`bg-sky-400`:`bg-[var(--color-fg-4)]`,r=t===`active`?`mcp · active`:`mcp · idle`;return(0,W.jsxs)(`div`,{className:`flex items-center gap-1.5 text-[11px] font-mono uppercase tracking-wider text-[var(--color-fg-3)]`,title:t===`active`?`MCP server: ${e?.recentCount??0} evals in last 5 min`:`MCP server: ${e?.totalCount??0} total evals`,children:[(0,W.jsx)(`span`,{className:`status-dot ${n}`}),(0,W.jsx)(`span`,{className:`hidden sm:inline`,children:r})]})}function Xd(e){if(e===`/`)return(0,W.jsx)(Bs,{});if(e===`/classic`)return(0,W.jsx)(Mc,{});if(e===`/graph`)return(0,W.jsx)(Yu,{});if(e===`/debug`)return(0,W.jsx)(Zu,{});if(e===`/rules`)return(0,W.jsx)(Bc,{});if(e===`/audit`)return(0,W.jsx)(Wc,{});if(e===`/approvals`)return(0,W.jsx)(el,{});if(e===`/profile`)return(0,W.jsx)(vl,{});if(e===`/hub/connect`)return(0,W.jsx)(kl,{});if(e===`/hub/publish`)return(0,W.jsx)(Al,{});if(e.startsWith(`/hub/`)){let t=e.slice(5);if(t)return(0,W.jsx)(Ol,{id:t})}return e===`/hub`?(0,W.jsx)(El,{}):e===`/monitor`?(0,W.jsx)(Vl,{}):e===`/observability`?(0,W.jsx)(su,{}):(0,W.jsxs)(`div`,{className:`flex flex-col items-center justify-center py-24 text-[var(--color-fg-3)]`,children:[(0,W.jsx)(`p`,{className:`overline mb-2`,children:`error · 404`}),(0,W.jsx)(`p`,{className:`text-sm`,children:`page not found`}),(0,W.jsx)(`a`,{href:`/`,className:`mt-4 text-[11px] font-mono uppercase tracking-wider text-[var(--color-brand)] hover:underline`,children:`← back to dashboard`})]})}function Zd(e){history.pushState(null,``,e),window.dispatchEvent(new PopStateEvent(`popstate`))}function Qd({count:e}){let[t,n]=(0,_.useState)(!1);return t||e===0?null:(0,W.jsx)(`div`,{className:`border-b border-amber-500/25 bg-amber-500/5 px-4 py-2`,children:(0,W.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,W.jsxs)(`svg`,{className:`shrink-0 text-amber-300`,width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,W.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,W.jsx)(`line`,{x1:`12`,y1:`9`,x2:`12`,y2:`13`}),(0,W.jsx)(`line`,{x1:`12`,y1:`17`,x2:`12.01`,y2:`17`})]}),(0,W.jsxs)(`p`,{className:`text-[11px] text-amber-200 flex-1 font-mono`,children:[(0,W.jsxs)(`span`,{className:`font-semibold uppercase tracking-wider`,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,W.jsx)(`span`,{className:`text-amber-400/70`,children:`Close other tabs to restore full live-update functionality.`})]}),(0,W.jsx)(`button`,{onClick:()=>n(!0),className:`text-amber-500/50 hover:text-amber-300 transition-colors shrink-0 cursor-pointer`,title:`Dismiss`,children:(0,W.jsxs)(`svg`,{width:`13`,height:`13`,viewBox:`0 0 24 24`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.5`,strokeLinecap:`round`,strokeLinejoin:`round`,children:[(0,W.jsx)(`line`,{x1:`18`,y1:`6`,x2:`6`,y2:`18`}),(0,W.jsx)(`line`,{x1:`6`,y1:`6`,x2:`18`,y2:`18`})]})})]})})}function $d(){let[e,t]=(0,_.useState)(window.location.pathname),[n,r]=(0,_.useState)(0),[i,a]=(0,_.useState)(!1),{otherTabCount:o}=vd();(0,_.useEffect)(()=>{let e=()=>t(window.location.pathname);return window.addEventListener(`popstate`,e),()=>window.removeEventListener(`popstate`,e)},[]),(0,_.useEffect)(()=>{a(!1)},[e]),(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(`//`)||(e.preventDefault(),Zd(n))};return document.addEventListener(`click`,e),()=>document.removeEventListener(`click`,e)},[]);let s=t=>t===`/`?e===`/`:e.startsWith(t);return(0,W.jsxs)(`div`,{className:`min-h-screen bg-[var(--color-surface-0)] text-[var(--color-fg-1)]`,children:[(0,W.jsxs)(`header`,{className:`border-b border-[var(--color-line-1)] sticky top-0 z-50 bg-[var(--color-surface-0)]/98`,children:[(0,W.jsxs)(`div`,{className:`px-6 flex items-center h-12 gap-5`,children:[(0,W.jsxs)(`a`,{href:`/`,className:`flex items-baseline gap-0.5 select-none`,title:`SigmaShake Governance`,children:[(0,W.jsx)(`span`,{className:`font-mono text-sm font-semibold text-[var(--color-brand)] tracking-tight`,children:`ssg`}),(0,W.jsx)(`span`,{className:`font-mono text-[11px] text-[var(--color-fg-3)] tracking-tight`,children:`/gov`})]}),(0,W.jsx)(`nav`,{className:`hidden md:flex items-center`,children:Vd.map(e=>{let t=s(e.path);return(0,W.jsxs)(`a`,{href:e.path,className:`relative px-3 py-1.5 text-[13px] font-mono tracking-wide transition-colors ${t?`text-[var(--color-fg-0)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)]`}`,children:[e.label,t&&(0,W.jsx)(`span`,{className:`absolute inset-x-2 -bottom-px h-px bg-[var(--color-brand)]`})]},e.path)})}),(0,W.jsxs)(`div`,{className:`hidden md:flex items-center gap-4 ml-auto`,children:[o>0&&(0,W.jsxs)(`span`,{className:`chip text-amber-300 border-amber-500/30`,title:`${o} other tab${o===1?``:`s`} open — may cause connection issues`,children:[o+1,` tabs`]}),(0,W.jsx)(yd,{}),(0,W.jsx)(qd,{}),(0,W.jsx)(Yd,{}),(0,W.jsx)(Ud,{}),(0,W.jsx)(Jd,{onRefresh:()=>r(e=>e+1)}),(0,W.jsx)(kd,{}),(0,W.jsx)(Bd,{})]}),(0,W.jsx)(`button`,{"aria-label":`menu`,className:`md:hidden ml-auto flex items-center justify-center w-8 h-8 text-[var(--color-fg-2)] hover:text-[var(--color-fg-0)] transition-colors cursor-pointer`,onClick:()=>a(e=>!e),children:i?(0,W.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 18 18`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,children:[(0,W.jsx)(`line`,{x1:`3`,y1:`3`,x2:`15`,y2:`15`}),(0,W.jsx)(`line`,{x1:`15`,y1:`3`,x2:`3`,y2:`15`})]}):(0,W.jsxs)(`svg`,{width:`18`,height:`18`,viewBox:`0 0 18 18`,fill:`none`,stroke:`currentColor`,strokeWidth:`1.8`,strokeLinecap:`round`,children:[(0,W.jsx)(`line`,{x1:`2`,y1:`5`,x2:`16`,y2:`5`}),(0,W.jsx)(`line`,{x1:`2`,y1:`9`,x2:`16`,y2:`9`}),(0,W.jsx)(`line`,{x1:`2`,y1:`13`,x2:`16`,y2:`13`})]})})]}),i&&(0,W.jsxs)(`div`,{className:`md:hidden border-t border-[var(--color-line-0)] bg-[var(--color-surface-0)]`,children:[(0,W.jsx)(`nav`,{className:`flex flex-col px-2 py-1`,children:Vd.map(e=>{let t=s(e.path);return(0,W.jsx)(`a`,{href:e.path,onClick:()=>a(!1),className:`px-3 py-2.5 text-[13px] font-mono tracking-wide transition-colors rounded-sm ${t?`text-[var(--color-fg-0)] bg-[var(--color-surface-1)]`:`text-[var(--color-fg-3)] hover:text-[var(--color-fg-1)] hover:bg-[var(--color-surface-1)]`}`,children:e.label},e.path)})}),(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center gap-3 px-4 py-2 border-t border-[var(--color-line-0)]`,children:[o>0&&(0,W.jsxs)(`span`,{className:`chip text-amber-300 border-amber-500/30`,title:`${o} other tab${o===1?``:`s`} open`,children:[o+1,` tabs`]}),(0,W.jsx)(yd,{}),(0,W.jsx)(qd,{}),(0,W.jsx)(Yd,{}),(0,W.jsx)(Ud,{}),(0,W.jsx)(Jd,{onRefresh:()=>r(e=>e+1)}),(0,W.jsx)(kd,{}),(0,W.jsx)(Bd,{})]})]}),(0,W.jsx)(Qd,{count:o}),(0,W.jsx)(Kd,{}),(0,W.jsx)(Gd,{}),(0,W.jsx)(Wd,{})]}),(0,W.jsx)(`main`,{className:`px-6 py-6`,children:Xd(e)},n),(0,W.jsx)(zd,{})]})}var ef=document.getElementById(`app-root`);if(!ef)throw Error(`Missing #app-root`);g.createRoot(ef).render((0,W.jsx)(_.StrictMode,{children:(0,W.jsx)($d,{})}));
|