ccdeck 3.26.3 → 3.26.4

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.
@@ -89,7 +89,7 @@ ${Ce.sessionId}`:Ce.sessionId,children:Ce.label??Ce.sessionId.slice(0,8)}),i.jsx
89
89
 
90
90
  ${n}`:`Sort by ${t}`,onClick:()=>a(kq(r,e)),children:[t,i.jsx("span",{className:"sd-sort-dir","aria-hidden":!0,children:l==="none"?"":l==="ascending"?"↑":"↓"})]})})}const Aq=3e3;function Rq(e,t,n){return e>=n?"hot":e>=t?"warn":"calm"}function Mq(e,t,n=Date.now()){const r=Math.max(0,Math.min(100,100-e));return{pct:r,value:`${r}%`,tone:r===0?"calm":r>=30?"hot":"warn",note:r>0?`CPU held to ${e}% of full speed to cool down`:t?`at full speed · held to ${100-t.peak}% ${Iq(t.lastMs,n)}`:"running at full speed, and never held back"}}function Iq(e,t=Date.now()){const n=Math.max(0,Math.floor((t-e)/6e4));if(n<2)return"just now";if(n<60)return`${n} minutes ago`;const r=Math.floor(n/60);return r===1?"an hour ago":`${r} hours ago`}function fc(e){return e>=1024**3?`${(e/1024**3).toFixed(1)} GB`:e>=1024**2?`${Math.round(e/1024**2)} MB`:`${Math.round(e/1024)} KB`}function $q(e){const t=Math.floor(e/86400),n=Math.floor(e%86400/3600),r=Math.floor(e%3600/60);return t>0?`${t}d ${n}h`:n>0?`${n}h ${r}m`:`${r}m`}function Oq(e){var n,r,a;const t=(r=(n=e.thermal)==null?void 0:n.throttle)==null?void 0:r.speedLimit;return t!=null&&t<100?`throttled to ${t}% of full speed`:e.memory&&e.memory.usedPct>=90?`physical memory ${Math.round(e.memory.usedPct)}% full`:(a=e.network)!=null&&a.api&&e.network.api.ms==null?"the Claude API is not answering":null}function Pq(){const[e,t]=x.useState(null),n=x.useRef(null);return x.useEffect(()=>{let r=!0;const a=async()=>{if(document.visibilityState!=="hidden")try{const f=await fetch("/api/system");if(!f.ok)return;const p=await f.json();r&&(p!=null&&p.ok)&&t(p)}catch{}},l=()=>{n.current==null&&(a(),n.current=window.setInterval(a,Aq))},c=()=>{n.current!=null&&(window.clearInterval(n.current),n.current=null)},u=()=>{if(document.visibilityState==="hidden"){c();return}l(),a()};return l(),document.addEventListener("visibilitychange",u),()=>{r=!1,c(),document.removeEventListener("visibilitychange",u)}},[]),e}function UN({usageOpen:e,leaving:t,sub:n,flag:r,onClose:a,children:l}){return i.jsxs("aside",{className:`sysdetail${e?" shifted":""}${t?" leaving":""}`,id:"system-panel","aria-labelledby":"sd-title",children:[i.jsxs("div",{className:"sd-top",children:[i.jsxs("div",{className:"sd-head",children:[i.jsx("h2",{className:"sd-title",id:"sd-title",children:"This machine"}),n&&i.jsx("span",{className:"sd-sub",children:n}),i.jsx("button",{type:"button",className:"glyph-btn sd-close",onClick:a,"aria-label":"Close",title:"Close",children:"×"})]}),r&&i.jsx("p",{className:"sd-flag",children:r})]}),l]})}function Lq({usageOpen:e,leaving:t,onClose:n}){const r=Pq();if(!r||r.cpu==null||!r.memory)return i.jsx(UN,{usageOpen:e,leaving:t,onClose:n,children:i.jsx("div",{className:"sd-note",children:"reading this machine…"})});const{memory:a,swap:l,perCore:c,loadavg:u,cores:f,uptimeSec:p,platform:h,thermal:m,network:y,cpu:w}=r;return i.jsxs(UN,{usageOpen:e,leaving:t,sub:`up ${$q(p)} · ${f} cores`,flag:Oq(r),onClose:n,children:[i.jsx(Dq,{cpu:w,perCore:c,loadavg:u,cores:f}),i.jsx(Fq,{memory:a,swap:l,platform:h}),y&&i.jsx(qq,{network:y}),i.jsx(Hq,{thermal:m}),i.jsx(Wq,{sys:r})]})}function Dq({cpu:e,perCore:t,loadavg:n,cores:r}){const a=!!t&&t.length>0;return!a&&!n?null:i.jsxs("div",{className:"sd-section sd-cpu",role:"group","aria-label":"CPU",children:[a&&i.jsx(Pc,{group:"cores",title:"Core history",action:"Show core history",label:"CPU",value:e==null?null:`${Math.round(e)}%`,children:i.jsx("div",{className:"sd-cores",role:"img","aria-label":`${t.length} logical cores, busiest at ${Math.round(Math.max(...t))}%`,children:t.map((l,c)=>i.jsx("span",{className:"sd-core",title:`logical core ${c+1} · ${l}% busy`,children:i.jsx("span",{className:"sd-core-fill",style:{transform:`scaleY(${Math.max(2,l)/100})`}})},c))})}),n&&i.jsxs(Pc,{group:"load",title:"Load history",action:"Show load history",label:"Load average",hint:"the queue for the cores, counted in tasks rather than as a share of them",children:[i.jsx("div",{className:"sd-figs",title:"The queue for this machine's cores, averaged over one, five and fifteen minutes. A count of tasks, not a share of the CPU.",children:n.map((l,c)=>i.jsx(Fx,{value:l.toFixed(2),cap:["1m","5m","15m"][c]},c))}),n[0]>r&&i.jsx("div",{className:"sd-note",children:`${(n[0]/r).toFixed(1)}× more work queued than cores to run it`})]})]})}function Fq({memory:e,swap:t,platform:n}){const r=e.total-e.available,a=n==="win32"?"Commit":"Swap",l=t&&t.total>0?t.used/t.total*100:0;return i.jsx("div",{className:"sd-section",role:"group","aria-label":"Memory",children:i.jsxs(Pc,{group:"memory",title:"Memory history",action:"Show memory history",label:"Memory",children:[i.jsx(sh,{label:"Physical",value:i.jsxs(i.Fragment,{children:[i.jsx("b",{children:fc(r)})," of ",fc(e.total)]}),pct:e.usedPct,tone:e.usedPct>=90?"warn":"calm",note:`${fc(e.available)} available`}),t&&t.total>0&&i.jsx(sh,{label:a,value:i.jsxs(i.Fragment,{children:[i.jsx("b",{children:fc(t.used)})," of ",fc(t.total)]}),pct:l,tone:l>=90?"warn":"calm"})]})})}function qq({network:e}){const{down:t,up:n,api:r,route:a}=e,[l,c]=x.useState(!1),u=r&&r.ms!=null?Ah(r.ms):null,f=t!=null&&n!=null;return i.jsxs("div",{className:"sd-section",role:"group","aria-label":"Network",children:[i.jsxs(Pc,{group:"network",title:"Network history",action:"Show network history",label:"Network",children:[(f||u)&&i.jsxs("div",{className:"sd-figs sd-figs-named",children:[f&&[["Download",t],["Upload",n]].map(([p,h])=>{const m=I0(h);return i.jsx(Fx,{value:m.value,unit:m.unit,cap:p},p)}),u&&i.jsx(Fx,{value:u.value,unit:u.unit,cap:"Claude API"})]}),!f&&i.jsx("div",{className:"sd-note",children:"measuring…"}),r&&r.ms==null&&i.jsx("div",{className:"sd-note sd-note-warn",children:"Can’t reach Claude"})]}),a&&i.jsxs(i.Fragment,{children:[i.jsxs("button",{type:"button",className:"sd-detail",id:"sd-conn","aria-expanded":l,"aria-haspopup":"dialog",onClick:()=>c(p=>!p),children:["Connection details",a.relay&&i.jsx("span",{className:"sd-route-relay",children:" · relayed"}),i.jsx("i",{className:"sd-row-more","aria-hidden":!0,children:"›"})]}),l&&i.jsx(zq,{route:a,api:r,onClose:()=>c(!1)})]})]})}function Fx({value:e,unit:t,cap:n}){return t?i.jsxs("span",{className:"sd-fig",children:[i.jsx("span",{className:"sd-fig-cap",children:n}),i.jsxs("span",{className:"sd-fig-read",children:[i.jsx("b",{children:e})," ",i.jsx("span",{className:"sd-fig-unit",children:t})]})]}):i.jsxs("span",{className:"sd-fig",children:[i.jsx("b",{children:e}),i.jsx("span",{className:"sd-fig-cap",children:n})]})}function Bq(e){return e.kind==="tailscale-exit"?e.node?`Tailscale exit node ${e.node}`:"a Tailscale exit node":e.kind==="tailscale"?"Tailscale":`${e.name?`${e.name} `:""}VPN${e.iface?` (${e.iface})`:""}`}function zq({route:e,api:t,onClose:n}){return i.jsxs(Dx,{anchorId:"sd-conn",boundaryId:"system-panel",id:"sd-conn-pop",className:"sd-pop",role:"dialog",labelledBy:"sd-conn-title",onClose:n,children:[i.jsx("p",{className:"sd-pop-title",id:"sd-conn-title",children:"Connection"}),i.jsxs("dl",{className:"sd-pop-rows",children:[i.jsxs("div",{className:"sd-pop-row",children:[i.jsx("dt",{children:e.to==="claude"?"Traffic to Claude":"Internet traffic"}),i.jsxs("dd",{children:["through ",Bq(e)]})]}),e.relay&&i.jsxs("div",{className:"sd-pop-row",children:[i.jsx("dt",{children:"Relay"}),i.jsxs("dd",{children:[i.jsx("span",{className:"sd-route-relay",children:e.relay})," — not a direct path, so every packet carries one more round trip than it has to"]})]}),t&&i.jsxs("div",{className:"sd-pop-row",children:[i.jsx("dt",{children:"Round trip"}),i.jsx("dd",{children:t.ms==null?`${t.host} did not answer`:`${Oc(Ah(t.ms))} to open a connection to ${t.host}`})]}),i.jsxs("div",{className:"sd-pop-row",children:[i.jsx("dt",{children:"Throughput"}),i.jsx("dd",{children:"every interface on this machine, not this path alone"})]})]})]})}function Pc({group:e,title:t,action:n,label:r,value:a,hint:l,children:c}){const[u,f]=x.useState(!1);return i.jsxs(i.Fragment,{children:[i.jsxs("button",{type:"button",className:"sd-open",onClick:()=>f(!0),title:n,"aria-label":a==null?n:`${n}, now ${a}`,"aria-describedby":l?`sd-hint-${e}`:void 0,children:[i.jsxs("div",{className:"sd-h","aria-hidden":!0,children:[r," ",i.jsx("i",{className:"sd-row-more",children:"›"}),a!=null&&i.jsx("span",{className:"sd-h-val",children:a})]}),c]}),l&&i.jsx("span",{id:`sd-hint-${e}`,className:"vis-hidden",children:l}),u&&i.jsx(lq,{group:e,title:t,onClose:()=>f(!1)})]})}function Hq({thermal:e}){if(!e)return null;const t=e.throttle?Mq(e.throttle.speedLimit,e.heldBack):null;return i.jsx("div",{className:"sd-section",role:"group","aria-label":"Thermal",children:i.jsxs(Pc,{group:"thermal",title:"Thermal history",action:"Show thermal history",label:"Thermal",children:[e.celsius.map(n=>i.jsx(sh,{label:n.label,value:i.jsxs(i.Fragment,{children:[i.jsx("b",{children:n.celsius})," °C"]}),pct:n.celsius/n.critAt*100,mark:n.warnAt/n.critAt*100,tone:Rq(n.celsius,n.warnAt,n.critAt),title:`bar runs 0–${n.critAt} °C · amber from ${n.warnAt} °C, red at ${n.critAt} °C`,trackLabel:`${n.celsius} °C on a bar that runs to ${n.critAt} °C, amber from ${n.warnAt} °C`},n.label)),t&&i.jsx(sh,{label:"Throttling",value:i.jsx("b",{children:t.value}),pct:t.pct,tone:t.tone,note:t.note})]})})}function Wq({sys:e}){const[t,n]=x.useState(!1);return i.jsxs("div",{className:"sd-section sd-door-section",children:[i.jsx("button",{type:"button",className:"sd-open sd-door",onClick:()=>n(!0),"aria-label":"Show every process the deck is watching",children:i.jsxs("span",{className:"sd-door-plate",children:[i.jsxs("span",{className:"sd-door-name",children:["Busiest processes",i.jsx("i",{className:"sd-row-more","aria-hidden":!0,children:"›"})]}),i.jsx("span",{className:"sd-door-sub",children:"every process, with its command line"})]})}),t&&i.jsx(Tq,{sys:e,onClose:()=>n(!1)})]})}function sh({label:e,value:t,pct:n,tone:r="calm",note:a,mark:l,title:c,trackLabel:u}){return i.jsxs("div",{className:"sd-row",title:c,children:[i.jsxs("div",{className:"sd-row-head",children:[i.jsx("span",{className:"sd-row-label",children:e}),i.jsx("span",{className:"sd-row-val",children:t})]}),i.jsxs("span",{className:"sd-track",role:u?"img":void 0,"aria-label":u,children:[i.jsx("span",{className:`sd-fill${r==="calm"?"":` ${r}`}`,style:{transform:`scaleX(${n<=0?0:Math.max(1,Math.min(100,n))/100})`}}),l!=null&&l>0&&l<100&&i.jsx("span",{className:"sd-mark",style:{left:`${l}%`},"aria-hidden":!0})]}),a&&i.jsx("div",{className:"sd-note",children:a})]})}const VN=18,Uq=1100,Pi=(e,t)=>{const n=Math.sin(e*12.9898+t*78.233)*43758.5453;return n-Math.floor(n)},Vq=Array.from({length:VN},(e,t)=>{const n=-72+144*t/(VN-1)+(Pi(t,1)-.5)*9,r=(n-90)*(Math.PI/180),a=(54+32*Math.cos(n*Math.PI/180))*(.74+Pi(t,2)*.52);return{dx:Math.cos(r)*a,dy:Math.sin(r)*a,rot:(t%2?1:-1)*(100+Pi(t,3)*260),delay:Math.round(Pi(t,4)*90),dur:760+Math.round(Pi(t,5)*260),scale:.8+Pi(t,6)*.45,hue:t%4,round:t%3===0}});function GN({anchor:e}){var a;const[t,n]=x.useState(null),r=typeof window<"u"&&((a=window.matchMedia)==null?void 0:a.call(window,"(prefers-reduced-motion: reduce)").matches);return x.useEffect(()=>{if(r)return;const l=e.current;if(!l)return;const c=l.getBoundingClientRect();n({x:c.left+c.width/2,y:c.top+c.height/2});const u=window.setTimeout(()=>n(null),Uq);return()=>window.clearTimeout(u)},[e,r]),r||!t?null:Kn.createPortal(i.jsx("div",{className:"confetti",style:{left:`${t.x}px`,top:`${t.y}px`},"aria-hidden":!0,children:Vq.map((l,c)=>i.jsx("span",{className:`confetti-bit${l.round?" round":""}`,"data-hue":l.hue,style:{"--dx":`${l.dx.toFixed(1)}px`,"--dy":`${l.dy.toFixed(1)}px`,"--rot":`${l.rot}deg`,"--s":l.scale.toFixed(2),animationDelay:`${l.delay}ms`,animationDuration:`${l.dur}ms, ${l.dur}ms`}},c))}),document.body)}const MR=new Set(["awaiting_url","awaiting_code","registering"]);function Gq(e){return e!=null&&MR.has(e)}function IR(e){return e!=null&&e!=="done"&&!MR.has(e)}const Kq="the sign-in ended before it finished — the deck restarted, or it was cancelled in another tab",Yq="the sign-in did not complete";function Xq({state:e,serverError:t,localError:n}){const r=e==="idle";return{title:r?"Sign-in ended":"Sign-in failed",message:n||t||(r?Kq:Yq)}}function Zq({restored:e,activeAccount:t}){if(e!==!1)return null;const n=(t==null?void 0:t.email)||((t==null?void 0:t.num)!=null?`account ${t.num}`:null);return n?`This machine is now signed in as ${n} — the account you were using could not be put back. Switch back from the accounts panel.`:"The account you were using could not be put back — check which account this machine is signed in as from the accounts panel."}const Qq="done";function Jq(){let e=!1;return{shouldAnnounce(t){return t!==Qq?(e=!1,!1):e?!1:(e=!0,!0)}}}function P0(e,t){return t&&Object.hasOwn(e,t)?e[t]:void 0}const e8={already_running:"a sign-in is already in progress",no_url:"the claude CLI did not offer a sign-in link — is it installed?",not_waiting:"that sign-in is no longer waiting for a code",not_prompted:"the CLI has not asked for a code yet",code_rejected:"that code was not accepted — copy it again from the browser",no_verdict:"the claude CLI has not answered — try the code again",empty_code:"paste the code from the browser first",login_failed:"the code was not accepted",no_identity:"signed in, but the CLI still reports nobody logged in",add_failed:"signed in, but claude-swap could not record the account",not_a_share:"that does not look like a shared account — it should start with ccdeck2:",corrupt:"that share is incomplete — copy the whole thing",wrong_version:`that share was made by a newer ${nn}`,expired:"that share has expired — make a new one",import_failed:"claude-swap refused the import",unreadable_export:"claude-swap wrote something this deck could not read — try again, and upgrade it if this repeats",mixed_versions:"claude-swap changed format part-way through — try again",nothing_to_share:"none of those accounts could be exported",too_many:"that is more accounts than one share can carry",not_in_bundle:"that account is not in this share",bad_value:"an alias can only use letters, numbers, spaces, dots, dashes and underscores, up to 64 characters, and cannot start with a dash",bad_email:"that does not look like an email address — it cannot contain spaces or start with a dash"},t8={no_cswap:"claude-swap could not be run — it is not on this deck's PATH. Set AGENTS_DECK_CSWAP to its full path",timeout:"claude-swap took too long and was stopped — try again",switch_failed:"claude-swap refused the switch",bad_account:"that is not an account claude-swap has",unknown_setting:"claude-swap has no such setting",out_of_range:"that value is outside what the setting allows",bad_value:"claude-swap does not accept that value",set_failed:"claude-swap refused the change",command_failed:"claude-swap refused the command"},n8=`claude-swap could not read the login keychain — start ${nn} from a Terminal window rather than a background service`,$R={401:"this deck did not accept the page as its own, so nothing was changed",403:"this deck refused a change from this address — open it on the address the deck prints, not through a proxy"};function qx(e,t,n){const r=n==null?null:$R[n];if(r)return r;if((e==null?void 0:e.reason)!=="no_cswap"&&/keychain/i.test(Lc(e)))return n8;const a=P0(t8,e==null?void 0:e.reason);return a||(e==null?void 0:e.reason)||t}function Lc(e){return((e==null?void 0:e.output)||(e==null?void 0:e.detail)||(e==null?void 0:e.error)||"").trim()}const r8={no_install:"ccusage is not installed, and AGENTS_DECK_NO_INSTALL=1 forbids fetching it — unset that variable and restart the deck, or install ccusage yourself so it is on this deck's PATH",bad_override:"AGENTS_DECK_CCUSAGE names a file that is not there — correct it to the full path of your ccusage, or unset it to let the deck find its own",timeout:"ccusage took more than 90 seconds and was stopped — a narrower range usually finishes",bad_output:"ccusage ran but printed no usage data — try again, and run ccusage daily --json in a terminal if it keeps happening",run_failed:"ccusage could not report usage — try again",bad_range:"that date range is not a YYYYMMDD date — reopen the modal and pick one of the presets",unreachable:"the deck did not answer — check it is still running, then try again"},s8="ccusage could not be started — npx is not on this deck's PATH. Install Node's npm/npx, or put ccusage on PATH yourself";function a8(e){return/\bnpx\b/i.test(e)&&/(command not found|not found|not recognized|ENOENT)/i.test(e)}const o8="ccusage could not be started — the deck launched npx and Node could not load the npm script it points at. An older deck asked cmd.exe for a bare npx.cmd, which made the shim look for that script under the deck's working directory instead of beside itself; update the deck and reopen this modal",i8="ccusage could not be started — the copy npx fetched will not load: Node could not resolve a file inside it. That copy is in npx's own cache, which the deck never rewrites, so clear it with `npm cache clean --force` and reopen this modal",l8=e=>/\b(?:ERR_)?MODULE_NOT_FOUND\b|cannot find (?:module|package)/i.test(e),c8=/node_modules[\\/]npm[\\/]bin[\\/]|\bnpm-prefix\.js\b|\bnp[mx][-.][\w.-]*cli\.js\b/i,u8=/[\\/]_npx[\\/]/i,d8=`the copy of ccusage ${nn} installed for itself`;function h8(e){const t=String((e==null?void 0:e.install)??"").replace(/\s+/g," ").trim();return t.length>240?`${t.slice(0,239)}…`:t}function JG(e,t){const n=f8(e,t),r=h8(e);switch(e==null?void 0:e.stage){case"npx":return r?`ccusage failed on both of its paths. The managed install failed first — ${r} — and the deck then fell back to npx, where ${pc(n)}`:`there is no managed copy of ccusage on this machine, and the npx fallback failed: ${pc(n)}`;case"managed":return`${d8} failed to run: ${pc(n)}`;case"path":return e.bin?`the ccusage this deck found at ${e.bin} failed to run: ${pc(n)}`:`the ccusage this deck found on your PATH failed to run: ${pc(n)}`;default:return n}}const pc=e=>/^[A-Z][a-z]/.test(e)?e[0].toLowerCase()+e.slice(1):e;function f8(e,t){const n=Lc(e);if(l8(n)){if(u8.test(n))return i8;if(c8.test(n))return o8}if(a8(n))return s8;const r=P0(r8,e==null?void 0:e.reason);return r||(e==null?void 0:e.reason)||t}function Hi(e,t,n){const r=n==null?null:$R[n];if(r)return r;if(e!=null&&e.detail)return e.detail;if(e!=null&&e.error&&IR(e.state))return e.error;const a=P0(e8,e==null?void 0:e.reason);return a||(e!=null&&e.error?e.error:(e==null?void 0:e.reason)||t)}function p8(e,t,n){if(n<=0||Sh(e))return{kind:"pass"};const r=t>=0&&t<n?t:-1;switch(e.key){case"ArrowRight":return{kind:"select",index:r===-1?0:(r+1)%n};case"ArrowLeft":return{kind:"select",index:r===-1?n-1:(r-1+n)%n};case"Home":return{kind:"select",index:0};case"End":return{kind:"select",index:n-1};default:return{kind:"pass"}}}function OR(e,t){const n=Math.round(e/1e3)-t;return n<=0?{text:"expired",tone:"gone"}:n<60?{text:`expires in ${n}s`,tone:"soon"}:{text:`expires in ${Math.round(n/60)}m`,tone:"ok"}}function m8(e){const t=new Map;for(const n of e){const r=(n.email??"").trim().toLowerCase();r&&t.set(r,(t.get(r)??0)+1)}return e.map(n=>{const r=(n.email??"").trim(),a=n.alias||r||`account ${n.num}`,l=[];return n.alias&&r&&l.push(r),r&&(t.get(r.toLowerCase())??0)>1&&l.push(n.org||`slot ${n.num}`),{num:n.num,label:a,sub:l.length?l.join(" · "):null}})}function g8(e){return e<=0?"Nothing picked yet.":e===1?"1 account — its sign-in token will be on your clipboard.":`${e} accounts — ${e} sign-in tokens will be on your clipboard.`}function y8(e){switch(e){case"imported":return"imported";case"healed":return"dead token replaced";case"updated":return"updated";case"present":return"already here";default:return"not imported"}}function w8(e){const t=e.length;if(!t)return"Nothing to import.";const n=p=>e.filter(h=>h.state===p).length,r=[],a=n("imported");a&&r.push(`${a} of ${t} imported`);const l=n("healed");l&&r.push(`${l} had a dead token replaced`);const c=n("updated");c&&r.push(`${c} updated`);const u=n("present");u&&r.push(`${u} already here`);const f=n("failed");return f&&r.push(`${f} did not arrive`),`${r.join(", ")}.`}const v8=1500,_d=[{id:"login",label:"Sign in"},{id:"paste",label:"Paste a share"}],KN="aa-panel",YN=e=>`aa-tab-${e}`;async function mc(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const Bx=me.forwardRef((e,t)=>i.jsxs("svg",{className:"aa-mark",viewBox:"0 0 44 44","aria-hidden":!0,ref:t,children:[i.jsx("circle",{className:"aa-mark-ring",cx:"22",cy:"22",r:"20"}),i.jsx("path",{className:"aa-mark-tick",d:"M13.5 22.5 L19.5 28.5 L31 17"})]}));Bx.displayName="SuccessMark";function x8({onClose:e,onChanged:t}){const[n,r]=x.useState("login"),[a,l]=x.useState(null),[c,u]=x.useState(""),[f,p]=x.useState(""),[h,m]=x.useState(!1),[y,w]=x.useState(null),[_,N]=x.useState(null),[j,b]=x.useState(null),[S,E]=x.useState(null),C=x.useRef(""),T=x.useRef(!1),R=x.useRef(!1),$=x.useRef(null),H=x.useRef(null),B=x.useRef(null),P=x.useRef(null),K=x.useRef([]),X=x.useRef(!1),J=x.useCallback(()=>{T.current&&mc({action:"login-cancel"}).catch(()=>{}),e()},[e]),M=un(J,{focusRef:B}),Z=x.useCallback(async()=>{if(!Ls(R.current))return;R.current=!0,m(!0),w(null),T.current=!0;const U=await mc({action:"login"}).catch(()=>null);if(R.current=!1,m(!1),!(U!=null&&U.ok)){w(Hi(U,"could not start the sign-in"));return}l(U)},[]);x.useEffect(()=>{if(!Gq(a==null?void 0:a.state))return;const U=window.setInterval(async()=>{try{const re=await fetch("/api/claude-accounts/login");re.ok&&l(await re.json())}catch{}},v8);return()=>window.clearInterval(U)},[a]);const V=x.useRef(t);V.current=t;const I=x.useState(Jq)[0];x.useEffect(()=>{var U;(a==null?void 0:a.state)==="awaiting_code"&&((U=$.current)==null||U.focus()),I.shouldAnnounce(a==null?void 0:a.state)&&V.current()},[a==null?void 0:a.state,I]),x.useEffect(()=>{var U;n==="paste"&&!X.current&&((U=H.current)==null||U.focus()),X.current=!1},[n]);const q=x.useCallback(U=>{var de;const re=p8(U,_d.findIndex(ge=>ge.id===n),_d.length);re.kind!=="pass"&&(U.preventDefault(),X.current=!0,r(_d[re.index].id),(de=K.current[re.index])==null||de.focus())},[n]),W=x.useCallback(async()=>{var re;if(!Ls(R.current))return;R.current=!0,m(!0),w(null);const U=await mc({action:"login-code",code:c}).catch(()=>null);if(R.current=!1,m(!1),!(U!=null&&U.ok)){w(Hi(U,"the code was not accepted")),U!=null&&U.state&&l(U),(re=$.current)==null||re.select();return}u(""),l(U)},[c,a]),G=x.useCallback(async()=>{if(!Ls(R.current))return;R.current=!0,m(!0),w(null);const U=await mc({action:"import",blob:f}).catch(()=>null);if(R.current=!1,m(!1),!(U!=null&&U.ok)){w(Hi(U,"the import failed"));return}C.current=f,p(""),E(null),N(U.results??[]),t()},[f,t]),F=x.useCallback(async U=>{const re=`${U.email}|${U.org??""}`;if(!Ls(R.current)||!C.current)return;R.current=!0,m(!0),b(re),E(null);const de=await mc({action:"import",blob:C.current,force:!0,only:{email:U.email,org:U.org??""}}).catch(()=>null);if(R.current=!1,m(!1),b(null),!(de!=null&&de.ok)){E({key:re,text:Hi(de,"that account could not be updated")});return}const ge=(de.results??[])[0];ge&&N(pe=>pe&&pe.map(ke=>`${ke.email}|${ke.org??""}`===re?ge:ke)),t()},[t]),D=(a==null?void 0:a.state)==="done"?a.account:null,ae=Zq({restored:a==null?void 0:a.restored,activeAccount:a==null?void 0:a.activeAccount}),z=IR(a==null?void 0:a.state)||!!(y&&T.current&&!h),Q=Xq({state:a==null?void 0:a.state,serverError:a==null?void 0:a.error,localError:y});return Kn.createPortal(i.jsx("div",{className:"modal-backdrop",onClick:J,role:"presentation",children:i.jsxs("div",{ref:M,className:"modal aa-modal",onClick:U=>U.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Add a Claude account",children:[i.jsxs("header",{className:"modal-head",children:[i.jsx("div",{className:"modal-title",children:i.jsx("span",{className:"aa-tabs",role:"tablist","aria-label":"How to add the account",onKeyDown:q,children:_d.map((U,re)=>i.jsx("button",{type:"button",role:"tab",id:YN(U.id),ref:de=>{K.current[re]=de},"aria-selected":n===U.id,"aria-controls":KN,tabIndex:n===U.id?0:-1,className:`aa-tab${n===U.id?" on":""}`,onClick:()=>{X.current=!1,r(U.id)},children:U.label},U.id))})}),i.jsx("div",{className:"modal-actions",children:i.jsx("button",{type:"button",className:"glyph-btn",onClick:J,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),i.jsx("section",{className:"modal-body aa-body",id:KN,role:"tabpanel","aria-labelledby":YN(n),children:n==="login"?D?i.jsxs("div",{className:"aa-done",children:[i.jsx(Bx,{ref:P}),i.jsx(GN,{anchor:P}),i.jsx("h4",{children:D.added?`Account ${D.num} added`:"Credentials refreshed"}),i.jsxs("p",{className:"aa-note",children:[i.jsx("strong",{children:D.email}),D.added?ae?" is in the rotation.":" is in the rotation. The account you were using is still active.":" was already managed, so its stored credentials were replaced."]}),ae?i.jsx("p",{className:"aa-note aa-warn",role:"status",children:ae}):null,i.jsx("button",{type:"button",className:"btn primary",onClick:e,children:"Done"})]}):(a==null?void 0:a.state)==="awaiting_code"||(a==null?void 0:a.state)==="registering"?i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"aa-step",children:[i.jsx("h4",{children:"1 · Approve in the browser"}),i.jsx("p",{className:"aa-note",children:"A tab should have opened. If not, use this link:"}),i.jsx("a",{className:"aa-link",href:a.url??"#",target:"_blank",rel:"noreferrer noopener",children:a.url})]}),i.jsxs("div",{className:"aa-step",children:[i.jsx("h4",{children:"2 · Paste a code, if the page shows one"}),i.jsx("p",{className:"aa-note",children:"It usually finishes on its own — if the page says you are all set, there is nothing to do here."}),i.jsxs("div",{className:"aa-field",children:[i.jsx("input",{ref:$,type:"text",value:c,onChange:U=>u(U.target.value),onKeyDown:U=>{U.key==="Enter"&&c.trim()&&!h&&W()},placeholder:"paste the code here",spellCheck:!1,autoComplete:"off","aria-label":"Sign-in code",disabled:a.state==="registering"}),i.jsx("button",{type:"button",className:"btn primary",...Aa(h,!c.trim()||a.state==="registering"),onClick:W,children:a.state==="registering"?"registering…":"Continue"})]}),(y||a.error)&&i.jsx("p",{className:"aa-err",children:y??a.error}),i.jsx("p",{className:"aa-note",children:"The code goes straight to the claude CLI on this machine. It is never stored or sent anywhere else."})]})]}):z?i.jsxs("div",{className:"aa-step",children:[i.jsx("h4",{children:Q.title}),i.jsx("p",{className:"aa-err",children:Q.message}),i.jsx("button",{type:"button",className:"btn",onClick:()=>{T.current=!1,l(null),w(null),Z()},children:"Try again"})]}):h||T.current?i.jsx("div",{className:"aa-step",children:i.jsx("p",{className:"aa-note",children:"Asking the claude CLI for a sign-in link…"})}):i.jsxs("div",{className:"aa-step aa-primer",children:[i.jsx("h4",{children:"Sign in to Anthropic"}),i.jsx("p",{className:"aa-note",children:"Opens a browser tab where you approve the sign-in. It normally completes by itself; only if the page hands you a code does it need pasting back here. claude-swap records the account when it completes, and the account you are using now stays active."}),i.jsx("div",{className:"aa-actions",children:i.jsx("button",{type:"button",ref:B,className:"btn primary",onClick:Z,children:"Open the sign-in page"})})]}):_?(()=>{const U=_.filter(re=>re.state==="imported").length;return i.jsxs("div",{className:"aa-done",children:[i.jsx(Bx,{ref:P}),U>0&&i.jsx(GN,{anchor:P}),i.jsx("h4",{children:w8(_)}),_.length>0&&i.jsx("ul",{className:"aa-results",children:_.map(re=>{const de=`${re.email}|${re.org??""}`;return i.jsxs("li",{className:`aa-result ${re.state}`,children:[i.jsx("span",{className:"aa-result-who",children:re.email||(re.num?`slot ${re.num}`:"an account")}),i.jsx("span",{className:"aa-result-what",children:y8(re.state)}),re.state==="present"&&i.jsx("button",{type:"button",className:"aa-result-fix","aria-busy":j===de,title:`Overwrite the stored login for ${re.email} with the one in this share. Do this when that account has stopped working here; if it works, leave it.`,onClick:()=>F(re),children:j===de?"updating…":"update anyway"}),(S==null?void 0:S.key)===de&&i.jsx("span",{className:"aa-result-err",children:S.text})]},de)})}),i.jsxs("p",{className:"aa-note",children:["Nothing changed on the deck you copied this from. An account already here is left as it is, unless its stored login was dead or you pressed",i.jsx("strong",{children:" update anyway"}),"."]}),i.jsxs("div",{className:"aa-actions",children:[i.jsx("button",{type:"button",className:"btn primary",onClick:e,children:"Done"}),i.jsx("button",{type:"button",className:"btn",onClick:()=>{C.current="",E(null),N(null)},children:"Import another"})]})]})})():i.jsxs("div",{className:"aa-step",children:[i.jsx("h4",{children:"Paste an account shared from another deck"}),i.jsxs("div",{className:"aa-field",children:[i.jsx("input",{ref:H,type:"text",value:f,onChange:U=>p(U.target.value),onKeyDown:U=>{U.key==="Enter"&&f.trim()&&!h&&G()},placeholder:"ccdeck2:…",spellCheck:!1,autoComplete:"off","aria-label":"Shared account"}),i.jsx("button",{type:"button",className:"btn primary",...Aa(h,!f.trim()),onClick:G,children:h?"importing…":"Import"})]}),y&&i.jsx("p",{className:"aa-err",children:y}),i.jsxs("p",{className:"aa-note",children:["Use ",i.jsx("strong",{children:"share"})," on one account in the other deck, or ",i.jsx("strong",{children:"↗"})," above its list to send several at once. A share carries a live login for every account in it and expires ten minutes after it is made."]})]})})]})}),document.body)}const b8=6;function k8(e,t){const n=e.filter(u=>u.ready);if(t.armed&&e.length>0&&n.length===0)return{text:"Auto-switch has nowhere to go",tone:"bad",free:null};const r=n.length===e.length?`${e.length} ready`:n.length===0?e.length===1?"not ready":`none of ${e.length} ready`:`${n.length} of ${e.length} ready`,a=n.length?"ok":"idle",l=t.strained&&!t.armed?N8(n):null,c=[r];return l!=null&&c.push(`${l}% free`),c.push(t.armed?`auto ${t.threshold??"on"}${t.threshold?"%":""}`:"auto off"),{text:c.join(" · "),tone:a,free:l}}function N8(e){const t=e.map(n=>n.headroom).filter(n=>typeof n=="number");return t.length?Math.max(...t):null}function _8(e){const t=[...e].sort((a,l)=>{if(a.ready!==l.ready)return a.ready?-1:1;if(!a.ready)return a.name.localeCompare(l.name);const c=a.headroom,u=l.headroom;return c==null&&u==null?a.name.localeCompare(l.name):c==null?1:u==null?-1:u-c}),n=t.slice(0,b8),r=t.length-n.length;return{title:e.some(a=>a.ready)?"Where you could switch":"Nothing to switch to",shown:n,rest:r>0?`and ${r} more`:null}}function PR({title:e,steps:t,finish:n,aside:r,onClose:a}){const l=x.useRef(null),c=un(a,{focusRef:l}),[u,f]=x.useState(0),p=u===t.length-1,h=t[u],m=_=>f(Math.max(0,Math.min(t.length-1,_))),y=_=>{_.key!=="ArrowRight"&&_.key!=="ArrowLeft"||(_.preventDefault(),_.stopPropagation(),m(_.key==="ArrowRight"?u+1:u-1))},w=()=>{if(!p){m(u+1);return}n?n.act():a()};return Kn.createPortal(i.jsx("div",{className:"modal-backdrop",onClick:a,role:"presentation",children:i.jsxs("div",{ref:c,className:"modal guide",onClick:_=>_.stopPropagation(),onKeyDown:y,role:"dialog","aria-modal":"true","aria-labelledby":"guide-title",children:[i.jsxs("header",{className:"modal-head",children:[i.jsxs("div",{className:"modal-title",children:[i.jsx("span",{id:"guide-title",className:"modal-tool-name",children:e}),i.jsxs("span",{className:"modal-tool-id",children:[u+1," / ",t.length]})]}),i.jsx("div",{className:"modal-actions",children:i.jsx("button",{type:"button",className:"glyph-btn",onClick:a,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),i.jsxs("section",{className:"modal-body",children:[i.jsx("div",{className:"guide-stage",children:h.art},u),i.jsx("p",{className:"guide-line","aria-live":"polite",children:h.line}),i.jsx("p",{className:"guide-tip",children:h.tip??""}),i.jsxs("div",{className:"guide-foot",children:[i.jsx("div",{className:"guide-dots",children:t.map((_,N)=>i.jsx("button",{type:"button",className:"glyph-btn guide-dot","aria-label":`Step ${N+1} of ${t.length}`,"aria-current":N===u?"step":void 0,onClick:()=>m(N)},N))}),p&&r&&i.jsx("button",{type:"button",className:"ap-lan-word guide-aside",onClick:r.act,children:r.label}),u>0&&i.jsx("button",{type:"button",className:"btn",onClick:()=>m(u-1),children:"Back"}),i.jsx("button",{ref:l,type:"button",className:"btn primary",onClick:w,children:p?(n==null?void 0:n.label)??"Done":"Next"})]})]})]})}),document.body)}const zx={ok:"ga-ok",warn:"ga-warn",accent:"ga-accent",flight:"ga-flight"};function br({children:e}){return i.jsx("svg",{className:"guide-art",viewBox:"0 0 440 200","aria-hidden":!0,focusable:"false",children:e})}function xr({x:e,y:t=34,w:n=176,h:r=132,label:a}){return i.jsxs(i.Fragment,{children:[a&&i.jsx("text",{x:e+2,y:t-9,className:"ga-cap",children:a}),i.jsx("rect",{x:e,y:t,width:n,height:r,rx:10,className:"ga-screen"})]})}function Wr({x:e,y:t,email:n,state:r,tone:a,bars:l}){return i.jsxs(i.Fragment,{children:[i.jsx("circle",{cx:e+3,cy:t-4,r:3,className:zx[a]}),i.jsx("text",{x:e+12,y:t,className:"ga-t ga-mono",children:n}),i.jsx("text",{x:e+12,y:t+16,className:`ga-s ${zx[a]}`,children:r}),l==null?void 0:l.map((c,u)=>i.jsxs("g",{children:[i.jsx("text",{x:e,y:t+40+u*18,className:"ga-s",children:u?"7d":"5h"}),i.jsx("rect",{x:e+22,y:t+35+u*18,width:96,height:4,rx:2,className:"ga-track"}),i.jsx("rect",{x:e+22,y:t+35+u*18,width:96*c/100,height:4,rx:2,className:"ga-accent"}),i.jsxs("text",{x:e+148,y:t+40+u*18,className:"ga-s ga-accent",textAnchor:"end",children:[c,"%"]})]},u))]})}function LR({x:e,y:t,on:n}){return i.jsxs(i.Fragment,{children:[i.jsx("rect",{x:e,y:t,width:30,height:18,rx:9,className:n?"ga-switch-on":"ga-switch"}),i.jsx("circle",{cx:n?e+21:e+9,cy:t+9,r:6,className:n?"ga-knob-on":"ga-knob"})]})}function Sd({x:e,y:t,name:n,here:r=!0}){return i.jsxs(i.Fragment,{children:[i.jsx("circle",{cx:e+3,cy:t-4,r:3,className:r?"ga-ok":"ga-dim"}),i.jsx("text",{x:e+12,y:t,className:r?"ga-t":"ga-s",children:n})]})}function XN({x:e,y:t,on:n}){return n?i.jsxs(i.Fragment,{children:[i.jsx("rect",{x:e,y:t,width:12,height:12,rx:3,className:"ga-accent"}),i.jsx("path",{d:`M${e+3} ${t+6.2}l2.3 2.3 4-4.6`,className:"ga-tick"})]}):i.jsx("rect",{x:e+.5,y:t+.5,width:11,height:11,rx:3,className:"ga-box"})}function ZN({x:e,y:t,d:n}){return i.jsx("path",{d:n,transform:`translate(${e} ${t})`,className:"ga-glyph"})}function L0({x:e,y:t}){return i.jsx("path",{d:`M${e} ${t}l0 13 3.4-3 2.4 5.2 2-.9-2.4-5.1 4.6-.2z`,className:"ga-pointer"})}function D0(){return i.jsxs(i.Fragment,{children:[i.jsx("circle",{r:9,className:"ga-key-bed"}),i.jsxs("g",{transform:"translate(-6 -6) scale(0.857)",className:"ga-key",children:[i.jsx("circle",{cx:4.6,cy:7,r:2.6}),i.jsx("path",{d:"M7.2 7h5.2M10.6 7v2.2M12.4 7v1.6"})]})]})}function Wi({x:e,y:t,w:n,title:r,sub:a,tone:l}){return i.jsxs(i.Fragment,{children:[i.jsx("rect",{x:e,y:t,width:n,height:40,rx:8,className:"ga-screen"}),i.jsx("rect",{x:e+6,y:t+10,width:3,height:20,rx:1.5,className:zx[l]}),i.jsx("text",{x:e+16,y:t+17,className:"ga-t ga-strong",children:r}),i.jsx("text",{x:e+16,y:t+31,className:"ga-s",children:a})]})}function Yi({x:e,y:t,label:n,live:r}){return i.jsxs(i.Fragment,{children:[i.jsx("rect",{x:e,y:t,width:46,height:20,rx:10,className:r?"ga-chip-live":"ga-chip"}),i.jsx("text",{x:e+23,y:t+14,className:"ga-s ga-mono",textAnchor:"middle",children:n})]})}function ah({x:e,y:t}){return i.jsxs(i.Fragment,{children:[i.jsx("text",{x:e,y:t,className:"ga-cap",children:"LOCAL NETWORK"}),i.jsx(LR,{x:e+118,y:t-13,on:!0})]})}function S8(){return i.jsxs(br,{children:[i.jsx("rect",{x:14,y:14,width:206,height:172,rx:10,className:"ga-screen"}),i.jsx("text",{x:28,y:38,className:"ga-t ga-strong",children:"Sessions"}),i.jsx("text",{x:206,y:38,className:"ga-s ga-warn",textAnchor:"end",children:"1 waiting"}),i.jsx("rect",{x:20,y:50,width:194,height:42,rx:6,className:"ga-bed-warn"}),i.jsx("circle",{cx:33,cy:64,r:7,className:"ga-ring-warn ga-ping"}),i.jsx("circle",{cx:33,cy:64,r:3.5,className:"ga-warn"}),i.jsx("text",{x:44,y:68,className:"ga-t",children:"api-server"}),i.jsx("text",{x:44,y:83,className:"ga-s ga-warn",children:"waiting 6m · Bash"}),i.jsx("circle",{cx:33,cy:108,r:3.5,className:"ga-flight"}),i.jsx("text",{x:44,y:112,className:"ga-t",children:"docs-site"}),i.jsx("text",{x:44,y:127,className:"ga-s",children:"running · 12 tools"}),i.jsx("circle",{cx:33,cy:150,r:3.5,className:"ga-ok"}),i.jsx("text",{x:44,y:154,className:"ga-t",children:"billing"}),i.jsx("text",{x:44,y:169,className:"ga-s",children:"done · $0.84"}),i.jsx("path",{d:"M216 71C234 71 230 100 244 100",className:"ga-arc"}),i.jsx("path",{d:"M239 96l5 4-5 4",className:"ga-arrow"}),i.jsx("rect",{x:248,y:44,width:178,height:112,rx:10,className:"ga-screen"}),i.jsx("text",{x:262,y:64,className:"ga-cap",children:"API-SERVER"}),i.jsx("line",{x1:248,y1:74,x2:426,y2:74,className:"ga-line"}),i.jsx("text",{x:262,y:96,className:"ga-s ga-mono",children:"Bash(npm test)"}),i.jsx("text",{x:262,y:116,className:"ga-t ga-mono ga-warn",children:"Allow this command?"}),i.jsx("text",{x:262,y:136,className:"ga-s ga-mono",children:"> 1. Yes 2. No"})]})}function j8(){return i.jsxs(br,{children:[i.jsx("path",{d:"M136 100C166 100 166 38 196 38",className:"ga-edge ga-flow"}),i.jsx("path",{d:"M136 100H196",className:"ga-edge ga-flow"}),i.jsx("path",{d:"M136 100C166 100 166 162 196 162",className:"ga-edge-done"}),i.jsx("path",{d:"M308 38H326M308 100H326",className:"ga-edge"}),i.jsx(Wi,{x:20,y:80,w:116,title:"main",sub:"Opus 5 · 9 tools",tone:"accent"}),i.jsx(Wi,{x:196,y:18,w:112,title:"explore",sub:"Haiku · 14 tools",tone:"flight"}),i.jsx(Wi,{x:196,y:80,w:112,title:"tests",sub:"Sonnet · 6 tools",tone:"flight"}),i.jsx(Wi,{x:196,y:142,w:112,title:"review",sub:"done · 38s",tone:"ok"}),i.jsx(Yi,{x:326,y:28,label:"Read"}),i.jsx(Yi,{x:380,y:28,label:"Grep",live:!0}),i.jsx(Yi,{x:326,y:90,label:"Bash",live:!0})]})}function QN({x:e,y:t,label:n,pct:r,note:a}){return i.jsxs(i.Fragment,{children:[i.jsx("text",{x:e,y:t,className:"ga-s",children:n}),i.jsxs("text",{x:e+194,y:t,className:"ga-s ga-accent",textAnchor:"end",children:[r,"%"]}),i.jsx("rect",{x:e,y:t+7,width:194,height:5,rx:2.5,className:"ga-track"}),i.jsx("rect",{x:e,y:t+7,width:194*r/100,height:5,rx:2.5,className:"ga-accent"}),i.jsx("text",{x:e,y:t+26,className:"ga-s",children:a})]})}function E8(){return i.jsxs(br,{children:[i.jsx("rect",{x:14,y:30,width:172,height:140,rx:10,className:"ga-screen"}),i.jsx("text",{x:30,y:56,className:"ga-cap",children:"THIS SESSION"}),i.jsx("text",{x:30,y:98,className:"ga-big",children:"$3.66"}),i.jsx("text",{x:30,y:122,className:"ga-s",children:"Opus 5 · 1.2M tokens"}),i.jsx("text",{x:30,y:150,className:"ga-s",children:"$21.40 today"}),i.jsx("rect",{x:200,y:30,width:226,height:140,rx:10,className:"ga-screen"}),i.jsx("text",{x:216,y:56,className:"ga-cap",children:"CLAUDE QUOTA"}),i.jsx(QN,{x:216,y:80,label:"5-hour window",pct:24,note:"resets in 53m"}),i.jsx(QN,{x:216,y:124,label:"7-day window",pct:61,note:"resets in 4d"})]})}function C8(){return i.jsxs(br,{children:[i.jsx("rect",{x:14,y:40,width:172,height:120,rx:10,className:"ga-canvas"}),i.jsx(Wi,{x:30,y:80,w:140,title:"tests",sub:"Sonnet 5 · 6 tools",tone:"flight"}),i.jsx(L0,{x:156,y:106}),i.jsx("path",{d:"M170 92C186 92 184 60 200 60",className:"ga-arc"}),i.jsx("path",{d:"M195 56l5 4-5 4",className:"ga-arrow"}),i.jsx(xr,{x:200,y:22,w:226,h:160}),i.jsx("text",{x:214,y:46,className:"ga-t ga-strong",children:"tests"}),i.jsx("text",{x:412,y:46,className:"ga-s",textAnchor:"end",children:"Sonnet 5 · 38s"}),i.jsx("line",{x1:200,y1:56,x2:426,y2:56,className:"ga-line"}),i.jsx("text",{x:214,y:76,className:"ga-cap",children:"PROMPT"}),i.jsx("text",{x:214,y:92,className:"ga-t",children:"Run the suite and fix what fails"}),i.jsx("text",{x:214,y:116,className:"ga-cap",children:"TOOLS · 6"}),i.jsx(Yi,{x:214,y:122,label:"Read"}),i.jsx(Yi,{x:266,y:122,label:"Edit"}),i.jsx(Yi,{x:318,y:122,label:"Bash",live:!0}),i.jsx("text",{x:214,y:164,className:"ga-cap",children:"TOKENS"}),i.jsx("text",{x:214,y:178,className:"ga-s ga-mono",children:"41k in · 2.1k out · $0.12"})]})}function T8(){const e=[18,24,28,14,22,26,30,16,24,28,20,26];return i.jsxs(br,{children:[i.jsx(xr,{x:14,y:20,w:412,h:160}),i.jsx("text",{x:28,y:44,className:"ga-t ga-strong",children:"This machine"}),i.jsx("text",{x:412,y:44,className:"ga-s",textAnchor:"end",children:"12 cores · up 10d"}),i.jsx("line",{x1:14,y1:56,x2:426,y2:56,className:"ga-line"}),i.jsx("text",{x:28,y:76,className:"ga-cap",children:"CORES"}),e.map((t,n)=>i.jsxs("g",{children:[i.jsx("rect",{x:28+n*15,y:82,width:10,height:30,rx:2,className:"ga-track"}),i.jsx("rect",{x:28+n*15,y:112-t,width:10,height:t,rx:2,className:"ga-accent"})]},n)),i.jsx("text",{x:28,y:136,className:"ga-cap",children:"MEMORY"}),i.jsx("rect",{x:28,y:143,width:178,height:5,rx:2.5,className:"ga-track"}),i.jsx("rect",{x:28,y:143,width:105,height:5,rx:2.5,className:"ga-accent"}),i.jsx("text",{x:28,y:165,className:"ga-s",children:"18.9 GB of 32.0 GB"}),i.jsx("text",{x:240,y:76,className:"ga-cap",children:"THERMAL"}),i.jsx("text",{x:240,y:100,className:"ga-big",children:"66 °C"}),i.jsx("text",{x:240,y:118,className:"ga-s ga-ok",children:"running at full speed"}),i.jsx("text",{x:240,y:142,className:"ga-cap",children:"BUSIEST PROCESSES"}),i.jsx("text",{x:240,y:160,className:"ga-s ga-mono",children:"node · claude"}),i.jsx("text",{x:412,y:160,className:"ga-s ga-mono",textAnchor:"end",children:"38%"}),i.jsx("text",{x:240,y:176,className:"ga-s ga-mono",children:"esbuild"}),i.jsx("text",{x:412,y:176,className:"ga-s ga-mono",textAnchor:"end",children:"21%"})]})}function A8(){return i.jsxs(br,{children:[i.jsx("rect",{x:14,y:40,width:188,height:120,rx:10,className:"ga-screen"}),i.jsx("text",{x:28,y:60,className:"ga-cap",children:"~/MY-PROJECT"}),i.jsx("line",{x1:14,y1:70,x2:202,y2:70,className:"ga-line"}),i.jsxs("text",{x:28,y:100,className:"ga-t ga-mono",children:[i.jsx("tspan",{className:"ga-accent",children:"$"})," claude"]}),i.jsx("rect",{x:86,y:90,width:7,height:13,className:"ga-caret ga-blink"}),i.jsx("text",{x:28,y:130,className:"ga-s ga-mono",children:"or: codex"}),i.jsx("path",{d:"M210 100H238",className:"ga-arc"}),i.jsx("path",{d:"M233 95l6 5-6 5",className:"ga-arrow"}),i.jsx("rect",{x:250,y:40,width:176,height:120,rx:10,className:"ga-canvas"}),i.jsx("g",{className:"ga-pop",children:i.jsx(Wi,{x:278,y:80,w:120,title:"my-project",sub:"Opus 5 · live",tone:"accent"})})]})}function R8(){return i.jsxs(br,{children:[i.jsx(xr,{x:14,y:16,w:232,h:170}),i.jsx("text",{x:28,y:40,className:"ga-t ga-strong",children:"Claude accounts"}),i.jsx(ZN,{x:196,y:33,d:"M7 2.2v9.6M2.2 7h9.6"}),i.jsx(ZN,{x:220,y:33,d:"M3.3 10.7L10.7 3.3M5.2 3.3h5.5v5.5"}),i.jsx("line",{x1:14,y1:52,x2:246,y2:52,className:"ga-line"}),i.jsx(Wr,{x:28,y:74,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),i.jsx("rect",{x:190,y:62,width:44,height:18,rx:9,className:"ga-accent"}),i.jsx("text",{x:212,y:74,className:"ga-s ga-on-accent",textAnchor:"middle",children:"active"}),i.jsx("line",{x1:14,y1:140,x2:246,y2:140,className:"ga-line"}),i.jsx(Wr,{x:28,y:160,email:"personal@me.dev",state:"signed in",tone:"ok"}),i.jsx("rect",{x:188,y:148,width:46,height:18,rx:9,className:"ga-chip"}),i.jsx("text",{x:211,y:160,className:"ga-s",textAnchor:"middle",children:"switch"}),i.jsx(L0,{x:221,y:161}),i.jsx("path",{d:"M250 40C270 40 262 78 282 78",className:"ga-arc"}),i.jsx("path",{d:"M277 74l5 4-5 4",className:"ga-arrow"}),i.jsx(xr,{x:282,y:62,w:144,h:64,label:"ANOTHER MACHINE"}),i.jsx("g",{className:"ga-pop",children:i.jsx(Wr,{x:296,y:92,email:"work@team.dev",state:"shared here",tone:"ok"})})]})}function M8(){return i.jsxs(br,{children:[i.jsx(xr,{x:14,label:"THIS MACHINE"}),i.jsx(ah,{x:28,y:60}),i.jsx("g",{className:"ga-swap-out",children:i.jsx(Wr,{x:28,y:98,email:"work@team.dev",state:"login expired",tone:"warn"})}),i.jsx("g",{className:"ga-swap-in",children:i.jsx(Wr,{x:28,y:98,email:"work@team.dev",state:"working again",tone:"ok",bars:[24,61]})}),i.jsx(xr,{x:250,label:"ANOTHER MACHINE"}),i.jsx(ah,{x:264,y:60}),i.jsx(Wr,{x:264,y:98,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),i.jsx("path",{d:"M246 120C234 80 206 80 194 120",className:"ga-arc"}),i.jsx("g",{className:"ga-travel ga-travel-low",transform:"translate(220 90)",children:i.jsx(D0,{})})]})}const I8=[{art:i.jsx(S8,{}),line:"Sessions waiting on you top the session list, longest wait first.",tip:"A tone and a system notification when one stops to ask. The speaker in the topbar."},{art:i.jsx(j8,{}),line:"Every agent and subagent is a node. Tool calls light up as they run."},{art:i.jsx(C8,{}),line:"Double-click any node: its prompt, every tool call, tokens and timing."},{art:i.jsx(E8,{}),line:"What each session costs, and how much quota is left."},{art:i.jsx(T8,{}),line:"Cores, memory and heat while the agents run, and what is hogging them."},{art:i.jsx(R8,{}),line:"Several Claude accounts: switch, add one, share one to another machine."},{art:i.jsx(M8,{}),line:"Your machines repair each other's expired logins over the local network.",tip:"Open it from the row at the foot of the Claude accounts panel."},{art:i.jsx(A8,{}),line:"Run claude or codex in any folder. It shows up here on its own."}];function $8(){return i.jsxs(br,{children:[i.jsx(xr,{x:14,label:"THIS MACHINE"}),i.jsx(Wr,{x:28,y:64,email:"work@team.dev",state:"login expired",tone:"warn"}),i.jsx("rect",{x:40,y:94,width:86,height:20,rx:10,className:"ga-pill-warn"}),i.jsx("text",{x:83,y:108,className:"ga-s ga-warn",textAnchor:"middle",children:"sign in again"}),i.jsx("line",{x1:198,y1:100,x2:242,y2:100,className:"ga-off"}),i.jsx(xr,{x:250,label:"ANOTHER MACHINE"}),i.jsx(Wr,{x:264,y:64,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]})]})}function O8(){return i.jsxs(br,{children:[i.jsx(xr,{x:14,label:"THIS MACHINE"}),i.jsx(ah,{x:28,y:60}),i.jsx(Sd,{x:28,y:92,name:"Ana's MacBook"}),i.jsx(Sd,{x:28,y:114,name:"Dorin's PC"}),i.jsx(xr,{x:250,label:"ANOTHER MACHINE"}),i.jsx(ah,{x:264,y:60}),i.jsx(Sd,{x:264,y:92,name:"Your MacBook"}),i.jsx(Sd,{x:264,y:114,name:"Dorin's PC"}),i.jsx("line",{x1:196,y1:100,x2:244,y2:100,className:"ga-arc"}),i.jsx("circle",{cx:220,cy:100,r:10,className:"ga-ring ga-ping"}),i.jsx("circle",{cx:220,cy:100,r:10,className:"ga-ring ga-ping ga-ping-2"}),i.jsx("circle",{cx:220,cy:100,r:3,className:"ga-accent"})]})}function P8(){return i.jsxs(br,{children:[i.jsx("rect",{x:90,y:18,width:260,height:164,rx:10,className:"ga-screen"}),i.jsx("text",{x:106,y:42,className:"ga-t ga-strong",children:"This deck on the network"}),i.jsx("line",{x1:90,y1:54,x2:350,y2:54,className:"ga-line"}),i.jsx("text",{x:106,y:76,className:"ga-cap",children:"SHARE THESE ACCOUNTS"}),i.jsx(XN,{x:106,y:88,on:!0}),i.jsx("text",{x:126,y:98,className:"ga-t ga-mono",children:"work@team.dev"}),i.jsx(XN,{x:106,y:112}),i.jsx("text",{x:126,y:122,className:"ga-s ga-mono",children:"personal@me.dev"}),i.jsx("text",{x:106,y:150,className:"ga-cap",children:"PAIRING"}),i.jsx("text",{x:106,y:168,className:"ga-s",children:"Say yes to every deck that asks"}),i.jsx(LR,{x:304,y:157,on:!0}),i.jsx(L0,{x:115,y:97})]})}function L8(){return i.jsxs(br,{children:[i.jsx(xr,{x:14,label:"THIS MACHINE"}),i.jsx("g",{className:"ga-swap-out",children:i.jsx(Wr,{x:28,y:64,email:"work@team.dev",state:"login expired",tone:"warn"})}),i.jsx("g",{className:"ga-swap-in",children:i.jsx(Wr,{x:28,y:64,email:"work@team.dev",state:"working again",tone:"ok",bars:[24,61]})}),i.jsx(xr,{x:250,label:"ANOTHER MACHINE"}),i.jsx(Wr,{x:264,y:64,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),i.jsx("path",{d:"M246 96C234 56 206 56 194 96",className:"ga-arc"}),i.jsx("g",{className:"ga-travel",transform:"translate(220 66)",children:i.jsx(D0,{})})]})}const D8=[{art:i.jsx($8,{}),line:"A login can expire on one machine while it still works on another."},{art:i.jsx(O8,{}),line:"Both decks are on. They find each other and ask to pair.",tip:"Not showing up? The + in the section reaches a machine by address or invite."},{art:i.jsx(P8,{}),line:"Tick which logins this machine may hand out. Nothing is shared until you do."},{art:i.jsx(L8,{}),line:"An expired login is copied from a paired machine within a minute."}];function F8(){return i.jsxs("svg",{className:"guide-art",viewBox:"0 0 232 60","aria-hidden":!0,focusable:"false",children:[i.jsx("rect",{x:1,y:14,width:78,height:42,rx:7,className:"ga-screen"}),i.jsx("circle",{cx:13,cy:29,r:3,className:"ga-warn"}),i.jsx("rect",{x:21,y:27,width:46,height:4,rx:2,className:"ga-track"}),i.jsx("rect",{x:13,y:39,width:40,height:3,rx:1.5,className:"ga-track"}),i.jsx("rect",{x:153,y:14,width:78,height:42,rx:7,className:"ga-screen"}),i.jsx("circle",{cx:165,cy:29,r:3,className:"ga-ok"}),i.jsx("rect",{x:173,y:27,width:46,height:4,rx:2,className:"ga-track"}),i.jsx("rect",{x:165,y:39,width:40,height:3,rx:1.5,className:"ga-accent"}),i.jsx("path",{d:"M150 36C138 6 94 6 82 36",className:"ga-arc"}),i.jsx("g",{transform:"translate(116 13)",children:i.jsx(D0,{})})]})}const q8={panel:"Nothing here is stuck: whoever pastes an invite is the one dialling out. Ask them for one and paste it behind the + above, where an address can be typed too.",dialog:"Nothing here is stuck: whoever pastes an invite is the one dialling out. Ask them for one and paste it below, or type their address."},B8=1600;function DR({reach:e,where:t}){const[n,r]=x.useState(!1),a=x.useRef(!0);x.useEffect(()=>()=>{a.current=!1},[]);const l=(e==null?void 0:e.steps)??[],c=x.useCallback(async()=>{await Eh(l.join(`
91
91
  `))&&a.current&&(r(!0),window.setTimeout(()=>{a.current&&r(!1)},B8))},[l]);if(!(e!=null&&e.blocked))return null;const u=e.shell==="sh";return i.jsxs("div",{className:"ap-lan-reach",children:[i.jsx("p",{className:"lan-warn",children:e.text}),i.jsx("p",{className:"lan-note",children:q8[t]}),l.length>0&&i.jsxs("details",{className:"ap-lan-reach-fix",children:[i.jsx("summary",{children:"or let them find this deck on their own"}),i.jsxs("p",{className:"lan-note",children:[u?i.jsx(i.Fragment,{children:"Run this in a terminal on this machine, then restart the deck."}):i.jsxs(i.Fragment,{children:["Run this in PowerShell ",i.jsx("strong",{children:"as Administrator"}),", then restart the deck."]}),e.category==="Public"&&i.jsx(i.Fragment,{children:" The first line marks this network as a home or office one — leave it out on a network you do not trust."}),e.unsure&&i.jsxs(i.Fragment,{children:[" ",e.unsure]})]}),i.jsx("pre",{className:"ap-lan-cmd",children:i.jsx("code",{children:l.join(`
92
- `)})}),i.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>void c(),title:u?"Copy these lines, then paste them into a terminal":"Copy these lines, then paste them into an elevated PowerShell",children:n?"copied":"copy command"})]})]})}async function Lp(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}const z8={not_an_invite:"That is not an invite — paste the whole line they sent you.",expired:"That invite has run out. Ask them for a fresh one.",not_running:"This deck is not on the network yet. Turn Local network on, then try again."},H8={not_running:"This deck is not on the network yet. Turn Local network on, then make one."};function JN(e,t,n){return(t==null?void 0:t.reason)&&e[t.reason]||tn(n,t)}function W8({status:e,manual:t,onClose:n,onChanged:r}){const a=x.useRef(null),l=un(n,{focusRef:a}),[c,u]=x.useState(""),[f,p]=x.useState(""),[h,m]=x.useState(null),[y,w]=x.useState(null),[_,N]=x.useState(null),[j,b]=x.useState(null),[S,E]=x.useState(()=>Date.now());x.useEffect(()=>{const I=window.setInterval(()=>E(Date.now()),1e3);return()=>window.clearInterval(I)},[]);const C=x.useRef(!0);x.useEffect(()=>()=>{C.current=!1},[]);const T=x.useRef(null),R=x.useCallback(I=>Th(T.current)?(T.current=I,N(I),!0):!1,[]),$=x.useCallback(()=>{T.current=null,C.current&&N(null)},[]),H=I=>{const q=La(_,I);return{disabled:q.disabled,"aria-busy":q.busy}},B=I=>(h==null?void 0:h.field)===I?{"aria-invalid":!0,"aria-describedby":"lan-add-failure"}:{},P=I=>m(q=>q&&q.field===I?null:q),K=x.useCallback(async()=>{const I=oB(c);if(!I){m({text:U8(c),field:"addr"});return}const q=`${I.addr}:${I.port}`,W=e.peers.find(G=>G.addr===I.addr&&G.port===I.port&&G.paired);if(W){m({text:`Already paired with ${W.name} at that address.`,field:"addr"});return}if(t.includes(q)){m({text:"This deck already calls that address.",field:"addr"});return}if(R("add"))try{const G=await Lp("/api/prefs",{lan:{manual:[...t,q]}});if(!C.current)return;G!=null&&G.ok?(m(null),u(""),r(),n()):m({text:tn("add that address",G),field:"addr"})}catch{C.current&&m({text:tn("add that address",null),field:"addr"})}finally{$()}},[c,t,e.peers,r,n,R,$]),X=x.useCallback(async I=>{if(!R(`invite:${I}`))return;const q=I==="make"?"make an invite":"cancel that invite";try{const W=await Lp("/api/lan/invite",{action:I});if(!C.current)return;W!=null&&W.ok?(m(null),w(null),r()):m({text:JN(H8,W,q)})}catch{C.current&&m({text:tn(q,null)})}finally{$()}},[r,R,$]),J=x.useCallback(async()=>{const I=f.trim();if(!(!I||!R("join"))){b(null);try{const q=await Lp("/api/lan/invite",{action:"join",token:I});if(!C.current)return;q!=null&&q.ok?(p(""),m(null),r(),n()):(q==null?void 0:q.reason)==="unreachable"&&Array.isArray(q.tried)&&q.tried.length?(b(q.tried),m(null)):(b(null),m({text:JN(z8,q,"use that invite"),field:"join"}))}catch{C.current&&m({text:tn("use that invite",null),field:"join"})}finally{$()}}},[f,r,n,R,$]),M=x.useCallback(async(I,q)=>{try{await navigator.clipboard.writeText(I),w(q),window.setTimeout(()=>{C.current&&w(W=>W===q?null:W)},1600)}catch{m({text:"Could not copy it — select the text and copy it by hand."})}},[]),Z=e.invite&&e.invite.expiresAt>S?e.invite:null,V=e.port!=null?(e.addrs??[]).map(I=>`${I}:${e.port}`):[];return Kn.createPortal(i.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:i.jsxs("div",{ref:l,className:"modal lan-add",onClick:I=>I.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-add-title",children:[i.jsxs("header",{className:"modal-head",children:[i.jsx("div",{className:"modal-title",children:i.jsx("span",{id:"lan-add-title",className:"modal-tool-name",children:"Add a deck"})}),i.jsx("div",{className:"modal-actions",children:i.jsx("button",{className:"glyph-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),i.jsxs("section",{className:"modal-body",children:[h&&i.jsxs("div",{className:"ap-failure",role:"alert",children:[i.jsx("span",{id:"lan-add-failure",className:"ap-failure-text",children:h.text}),i.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),i.jsx(DR,{reach:e.reach,where:"dialog"}),i.jsxs("div",{className:"modal-section",children:[i.jsx("h3",{className:"lan-h",children:"By address"}),i.jsxs("div",{className:"ap-lan-row",children:[i.jsx("input",{ref:a,className:"ap-manage-input ap-lan-input","aria-label":"Another deck's address",value:c,placeholder:"192.168.1.5:54340",spellCheck:!1,...B("addr"),onChange:I=>{u(I.target.value),P("addr")},onKeyDown:I=>{I.key==="Enter"&&K()}}),c.trim()!==""&&i.jsx("button",{type:"button",className:"ap-manage-btn",...H("add"),onClick:()=>void K(),title:"Add it to the decks this one calls, starting now.",children:"add"})]}),i.jsx("p",{className:"lan-note",children:"This deck calls that address until somebody there accepts."}),e.port!=null&&V.length>0&&i.jsxs("p",{className:"lan-note",children:["They type this deck’s own address into the same field on theirs:"," ",V.map((I,q)=>i.jsxs("span",{children:[q>0&&" or ",i.jsx("code",{className:"ap-lan-code",children:I})]},I)),i.jsx("button",{type:"button",className:"ap-lan-word lan-copy",...H("copy:mine"),onClick:()=>void M(V.join(" "),"mine"),title:"Copy this deck's address, to send to whoever is adding it",children:y==="mine"?"copied":"copy"})]})]}),i.jsxs("div",{className:"modal-section",children:[i.jsxs("h3",{className:"lan-h",children:["With an invite",!Z&&i.jsx("button",{type:"button",className:"ap-lan-word lan-h-act",...H("invite:make"),onClick:()=>void X("make"),title:"One piece of text you send them. They paste it, and the two decks pair — nobody has to press anything here.",children:_==="invite:make"?"making…":"make one to send"})]}),i.jsxs("div",{className:"ap-lan-row",children:[i.jsx("input",{className:"ap-manage-input ap-lan-input","aria-label":"An invite you were sent",value:f,placeholder:"paste one you were sent",spellCheck:!1,...B("join"),onChange:I=>{p(I.target.value),b(null),P("join")},onKeyDown:I=>{I.key==="Enter"&&J()}}),f.trim()!==""&&i.jsx("button",{type:"button",className:"ap-manage-btn",...H("join"),onClick:()=>void J(),title:"Reach that deck and pair with it. Nobody has to press anything there.",children:_==="join"?"joining…":"join"})]}),i.jsx("p",{className:"lan-note",children:"Pasting one pairs both decks on the spot — nobody has to accept."}),j&&i.jsxs("div",{className:"ap-lan-tried",children:[i.jsx("span",{className:"lan-note",children:"Nothing answered at any address in that invite. Check that deck is running with its Local network switch on."}),j.map(I=>i.jsxs("span",{className:"ap-lan-tried-row",children:[i.jsx("code",{className:"ap-lan-code",children:I.addr}),i.jsx("span",{className:"ap-lan-bad",children:I.why})]},I.addr))]}),Z&&i.jsxs("div",{className:"ap-lan-invite",children:[i.jsxs("div",{className:"ap-lan-invite-head",children:[i.jsx("span",{className:"ap-lan-invite-title",children:"Send this to them"}),i.jsxs("span",{className:"ap-lan-invite-left",children:[lB(Z.expiresAt,S)," left"]})]}),i.jsx("code",{className:"ap-lan-token",children:Z.token}),i.jsxs("div",{className:"ap-lan-acts",children:[i.jsx("button",{type:"button",className:"ap-manage-btn",...H("copy:invite"),onClick:()=>void M(Z.token,"invite"),title:"Copy it, and send it however you already talk to them",children:y==="invite"?"copied":"copy"}),i.jsx("button",{type:"button",className:"ap-manage-btn",...H("invite:withdraw"),onClick:()=>void X("withdraw"),title:"Cancel it. Anybody already holding the text can no longer use it.",children:"cancel"})]}),i.jsx("p",{className:"lan-warn",children:"Anyone who gets this text can pair with this deck until it runs out."})]})]})]})]})}),document.body)}function U8(e){const t=(e??"").trim();if(t==="")return"Type an address and a port, like 192.168.1.5:54340.";if(!t.startsWith("[")&&(t.match(/:/g)??[]).length>1)return"Too many colons to split. Use that deck's IPv4 address or its name, like 192.168.1.5:54340.";if(!t.includes(":"))return`Add the port too, like ${t}:54340.`;const n=t.slice(t.lastIndexOf(":")+1).trim();return n===""?"That is missing its port — try 192.168.1.5:54340.":/^\d+$/.test(n)?`A port runs from 1 to 65535, and this one is ${n}.`:`A port is a number, and this one is "${n}".`}const V8=1e3;function G8(e,t){const n=new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),r=hs(e,t);return`${n} · ${r==="now"?"just now":r}`}function e_(e){return e&&[e.version,e.os,e.arch].filter(Boolean).join(" · ")||null}function K8(){return i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M9.6 2.4l2 2L5 11l-2.6.6L3 9z"}),i.jsx("path",{d:"M8.4 3.6l2 2"})]})}function t_(){return i.jsxs("svg",{className:"lan-machine",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("rect",{x:"2.5",y:"3",width:"11",height:"7.5",rx:"1.2"}),i.jsx("path",{d:"M1 13h14"})]})}function jd({dir:e,gate:t=!1}){const n=t?12:8;return i.jsx("svg",{className:"lan-chev","data-dir":e,"data-gate":t||void 0,width:n,height:"8",viewBox:`0 0 ${n} 8`,fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:i.jsx("path",{d:e==="out"?"M2.8 1L6 4 2.8 7":t?"M1 1v6M9.6 1L6.4 4l3.2 3":"M5.2 1L2 4l3.2 3"})})}const Y8={works:"works here",expired:"expired here",missing:"not on this deck"},X8={works:"works there",broken:"broken there",unknown:"not offered by that deck"};function Z8(e){const t=e.in&&e.out?"offered both ways":e.in?"offered by that deck":"offered by this deck";return`${Y8[e.here]}, ${X8[e.there]}, ${t}${e.usedThere?", in use there":""}.`}function Q8({row:e,source:t,status:n,accounts:r,now:a,busy:l,onClose:c,onRename:u,onCheck:f,onVerb:p,onSettings:h,twins:m=[],onUnpair:y}){var vt,mt,_n,Et,zt;const w=x.useRef(null),_=un(c,{focusRef:w}),[N,j]=x.useState(null),[b,S]=x.useState(null),[E,C]=x.useState(!1),T=x.useRef(0),[R,$]=x.useState(null),[H,B]=x.useState(!1),[P,K]=x.useState(0),X=x.useRef(null),J=x.useRef(!0);x.useEffect(()=>()=>{J.current=!1},[]);const M=N!=null;x.useEffect(()=>{var fe;M&&((fe=X.current)==null||fe.select())},[M]),x.useEffect(()=>{if(!E)return;const fe=window.setTimeout(()=>C(!1),4e3);return()=>window.clearTimeout(fe)},[E]),x.useEffect(()=>{if(!R)return;const fe=window.setTimeout(()=>$(null),4e3);return()=>window.clearTimeout(fe)},[R]);const Z=fe=>{const nt=La(l,fe);return{disabled:nt.disabled,"aria-busy":nt.busy}},V=async fe=>{const nt=await fe();return J.current&&S(nt),nt==null},{peer:I,stranger:q}=t,W=e.kind==="paired",G=e.self??e.name,F=e.kind!=="dialling",D=e.kind==="dialling"?null:e.fp,ae=I?I.addr?`${I.addr}:${I.port}`:"":q?q.port?`${q.addr}:${q.port}`:q.addr:e.addr,z=(I==null?void 0:I.about)??null,Q=((vt=n.about)==null?void 0:vt.version)??null,U=async fe=>{const nt=fe.trim()===G?"":fe;await V(()=>u(nt))&&j(null)},re=async()=>{if(D)try{if(await navigator.clipboard.writeText(D),!J.current)return;B(!0),window.setTimeout(()=>{J.current&&B(!1)},1600)}catch{J.current&&S("Could not copy it — select the fingerprint and copy it by hand.")}},de=W?I!=null&&I.waiting?I.lastSeen!=null?"not said — it runs an older version":"not said yet — it says when it next calls":I!=null&&I.offers?"not said — it runs an older version":"not reached yet":"shown once paired",ge=e_(n.about),pe=e_(z),ke=z!=null&&z.version&&Q?yB(z.version,Q):null,Pe=I?FR(I.last,a):null,$e=I&&((mt=I.last)!=null&&mt.error)?aB({error:I.last.error,host:I.addr,port:I.port},[...n.strangers??[],...n.pending??[],...(n.peers??[]).filter(fe=>!fe.manual&&fe.addr).map(fe=>({fp:fe.fp,name:fe.name,addr:fe.addr,port:fe.port,at:fe.lastSeen??0}))],a):null,Ae=(_n=I==null?void 0:I.last)!=null&&_n.error&&Pe&&Pe.text!==I.last.error?I.last.error:null,je=((Et=I==null?void 0:I.last)==null?void 0:Et.done)??[],Qe=!!Pe&&!!Ae&&!e.quiet&&e.state.startsWith(Pe.text),Te=W||e.kind==="dialling",Se=((I==null?void 0:I.via)??e.via)==="tailscale",We=I?I.waiting?null:I.manual?Se?"added by its Tailscale address":"added by address":Se?"over Tailscale":"on this network":e.kind==="nearby"?Se?"heard over Tailscale":"heard on this network":Se?"asked this deck to pair, over Tailscale":"asked this deck to pair",dt=e.tone==="bad"?"bad":W?e.here?"up":"down":"loose",ct=l===`check:${e.fp}`,le=(I==null?void 0:I.offers)??null,Ne=dt==="up"?(le==null?void 0:le.current)??null:null,Me=Ne&&"key"in Ne?Ne.key:null,tt=!!Ne&&"hidden"in Ne,Ge=!!Ne&&"other"in Ne,Je=W?vB((le==null?void 0:le.accounts)??null,r,n.shared??[],Me):[],ye=Je.filter(fe=>fe.in==null&&fe.out==="cut"),Ce=Je.some(fe=>fe.in!=null),Ve=Je.some(fe=>fe.out!=null),ce=new Map(je.map(fe=>[fe.email,fe])),at=je.filter(fe=>!Je.some(nt=>nt.email===fe.email)),ut=W?le?le.accounts.length===0?"That deck offers nothing. Nobody there has chosen a login to share.":null:I!=null&&I.waiting?"What that deck offers is not known yet. A deck that calls in says so each time it calls — one on an older version never does.":(zt=I==null?void 0:I.last)!=null&&zt.error?"What that deck offers is not known — the last attempt to ask it did not get through.":"Nobody has asked that deck what it offers yet. The next round asks it.":null,rt=le&&(I!=null&&I.last)&&I.last.at-le.at>V8?hs(le.at,a):null,st=[];W&&(I!=null&&I.pairedAt)?st.push({label:"Paired",value:G8(I.pairedAt,a),tone:"meta"}):e.kind==="declined"&&q&&st.push({label:"Paired",value:`no · you said no ${q0(q.at,a)}`,tone:"meta"}),st.push({label:"Fingerprint",value:D?i.jsxs("span",{className:"lan-fp",children:[i.jsx("code",{className:"ap-lan-code",children:D}),i.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void re(),"aria-label":H?"Fingerprint copied":"Copy the fingerprint",children:H?"copied":"copy"})]}):"not known — nothing has answered there",tone:D?void 0:"quiet"});const jt=m.length?[{row:e,peer:I??null},...m]:[];return Kn.createPortal(i.jsx("div",{className:"modal-backdrop",onClick:c,role:"presentation",children:i.jsxs("div",{ref:_,className:"modal lan-peer","data-tone":e.tone,onClick:fe=>fe.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-peer-title","aria-describedby":"lan-peer-sub",children:[i.jsxs("header",{className:"modal-head lan-peer-head",children:[i.jsx("i",{className:e.here?"ap-pulse":"ap-dot","aria-hidden":!0}),i.jsxs("div",{className:"lan-peer-id",children:[M?i.jsxs("form",{className:"lan-peer-edit",onSubmit:fe=>{fe.preventDefault(),U(N??"")},children:[i.jsx("span",{id:"lan-peer-title",className:"vis-hidden",children:e.name}),i.jsx("input",{ref:X,className:"ap-manage-input lan-peer-input",value:N??"",maxLength:48,placeholder:G,"aria-label":"Name for this deck, shown on this deck only",onChange:fe=>j(fe.target.value)}),i.jsx("button",{type:"submit",className:"ap-manage-btn",...Z(`alias:${e.fp}`),children:"save"}),i.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>j(null),children:"cancel"})]}):i.jsxs("span",{className:"lan-peer-title",children:[i.jsx("span",{id:"lan-peer-title",className:"lan-peer-name",children:e.name}),F&&i.jsx("button",{type:"button",className:"glyph-btn lan-peer-rename",onClick:()=>{S(null),j(e.name)},"aria-label":`Rename ${e.name} on this deck`,title:"Give it a name of your own. Only this deck sees it.",children:i.jsx(K8,{})})]}),i.jsxs("p",{id:"lan-peer-sub",className:"lan-peer-sub",children:[e.self&&i.jsxs(i.Fragment,{children:["calls itself ",i.jsx("span",{className:"lan-peer-self",children:e.self}),M&&i.jsx("button",{type:"button",className:"ap-lan-word lan-peer-restore",...Z(`alias:${e.fp}`),onClick:()=>void U(""),children:"use this name"}),i.jsx("span",{className:"vis-hidden",children:". "}),!e.quiet&&i.jsx("span",{"aria-hidden":!0,children:" · "})]}),i.jsx("span",{className:e.quiet?"vis-hidden":"lan-peer-state",children:e.state})]})]}),i.jsx("div",{className:"modal-actions",children:i.jsx("button",{ref:w,type:"button",className:"glyph-btn",onClick:c,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),i.jsxs("section",{className:"modal-body lan-peer-body",children:[b&&i.jsxs("div",{className:"ap-failure",role:"alert",children:[i.jsx("span",{className:"ap-failure-text",children:b}),i.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>S(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),i.jsxs("div",{className:"lan-map","data-link":dt,"data-asking":ct||void 0,"data-bus":Je.length>0||void 0,children:[i.jsxs("div",{className:"lan-ends",children:[i.jsxs("p",{className:"lan-end",children:[i.jsx("span",{className:"lan-end-name",children:"This deck"}),ge&&i.jsx("span",{className:"lan-end-runs",children:ge}),W&&n.shareActive===!1&&i.jsx("span",{className:"lan-end-note",children:"current account hidden"})]}),i.jsxs("p",{className:"lan-end","data-side":"there",children:[i.jsx("span",{className:"lan-end-name",children:e.name}),e.kind!=="dialling"&&i.jsxs("span",{className:"lan-end-runs",children:[pe??(z?"not said":de),ke?` · ${ke<0?"older":"newer"}`:null]}),tt&&i.jsx("span",{className:"lan-end-note",children:"current account hidden"}),Ge&&i.jsx("span",{className:"lan-end-note",children:"on another account"})]})]}),i.jsxs("div",{className:"lan-link",children:[i.jsx(t_,{}),i.jsxs("span",{className:"lan-span",children:[i.jsxs("span",{className:"lan-wire","aria-hidden":!0,children:[i.jsx("i",{className:"lan-glint","data-dir":"out"}),i.jsx("i",{className:"lan-glint","data-dir":"in"})]}),i.jsx("span",{className:"lan-link-label",children:ae?i.jsx("code",{className:"ap-lan-code",children:ae}):"none here — it calls this deck"})]}),i.jsx(t_,{}),(ae&&We||Te)&&i.jsxs("p",{className:"lan-link-sub",children:[ae&&We,ae&&We&&Te&&" · ",Te&&(Pe?Qe?i.jsx("code",{className:"ap-lan-code",children:Ae}):i.jsx("span",{className:"lan-round","data-tone":Pe.tone,children:Pe.text.replace(/ · now$/," · just now")}):"not asked yet"),Te&&Ae&&!Qe&&i.jsx("code",{className:"lan-fact-raw",children:Ae})]}),at.length>0&&i.jsx("ul",{className:"lan-done",children:at.map(fe=>i.jsxs("li",{"data-ok":fe.ok,children:[fe.email," ",i.jsx("span",{className:"lan-done-what",children:fe.ok?"arrived":"did not arrive"})]},`${fe.email}:${fe.action}`))}),$e&&i.jsx("p",{className:"lan-note lan-link-note",children:$e}),(I==null?void 0:I.waiting)&&i.jsx("p",{className:"lan-note lan-link-note",children:e.hint})]}),Je.length>0&&i.jsx("ul",{className:"lan-lanes",role:"list","aria-label":`Logins between this deck and ${e.name}`,children:Je.map((fe,nt)=>{const Tt=ce.get(fe.email),Sn=fe.out==="live"||fe.in!=null&&fe.in!=="cut";return i.jsxs("li",{role:"listitem",className:"lan-lane","data-tone":fe.tone,"data-draw":fe.in&&fe.out?"both":fe.in?"in":"out","data-used-there":fe.usedThere||void 0,style:{"--i":nt},children:[i.jsx("i",{className:"lan-pip","data-end":"here","data-state":fe.here,"aria-hidden":!0}),i.jsxs("span",{className:"lan-track",children:[i.jsxs("span",{className:"lan-wire","data-flow":Sn?"live":"cut","aria-hidden":!0,children:[(fe.in==="live"||fe.in==="wait")&&i.jsx("i",{className:"lan-glint","data-dir":"in","data-tone":fe.in}),fe.out==="live"&&i.jsx("i",{className:"lan-glint","data-dir":"out"})]}),fe.in&&fe.in!=="cut"&&i.jsx(jd,{dir:"in",gate:fe.in==="blocked"}),fe.out==="live"&&i.jsx(jd,{dir:"out"}),i.jsx("span",{className:"lan-lane-email",children:fe.email})]}),i.jsx("i",{className:"lan-pip","data-end":"there","data-state":fe.there,"aria-hidden":!0}),i.jsx("span",{className:"vis-hidden",children:Z8(fe)}),(fe.caption||Tt)&&i.jsxs("span",{className:"lan-lane-note",children:[fe.caption,fe.caption&&Tt&&" · ",Tt&&i.jsx("span",{className:"lan-lane-done","data-ok":Tt.ok,children:Tt.ok?"arrived last round":"did not arrive last round"})]})]},fe.key)})},P),W&&i.jsxs(i.Fragment,{children:[ye.length>0&&i.jsxs("p",{className:"lan-spent",children:["Paired decks get nothing from ",ye.length===1?ye[0].email:"the expired ones"," until you sign in again here."]}),ut&&i.jsx("p",{className:"lan-empty",children:ut}),rt&&i.jsxs("p",{className:"lan-stale",children:["As of ",rt==="now"?"just now":rt,", when it last answered."]}),i.jsxs("div",{className:"lan-legend",children:[Ce&&i.jsxs("span",{className:"lan-key",children:[i.jsx("span",{className:"lan-key-wire","data-dir":"in","aria-hidden":!0,children:i.jsx(jd,{dir:"in"})}),"from ",e.name]}),Ve?i.jsxs("span",{className:"lan-key",children:[i.jsx("span",{className:"lan-key-wire","data-dir":"out","aria-hidden":!0,children:i.jsx(jd,{dir:"out"})}),"from this deck, to every paired deck"]}):i.jsx("span",{className:"lan-key",children:"This deck offers nothing yet."}),i.jsx("button",{type:"button",className:"ap-lan-word lan-legend-act",onClick:h,"aria-label":"Change what this deck offers",children:"change"})]})]})]}),i.jsx("dl",{className:"lan-facts",children:st.map(fe=>i.jsxs("div",{className:"lan-fact","data-tone":fe.tone,children:[i.jsx("dt",{children:fe.label}),i.jsx("dd",{children:fe.value})]},fe.label))}),jt.length>1&&i.jsxs("div",{className:"modal-section",children:[i.jsxs("h3",{className:"lan-h",children:[jt.length," decks on this machine"]}),i.jsx("ul",{className:"lan-twins",role:"list",children:jt.map((fe,nt)=>{var hn,jn,Ht,$n;const Tt=(hn=fe.peer)!=null&&hn.addr?`${fe.peer.addr}:${fe.peer.port}`:fe.row.addr,Sn=Tt||fe.row.fp,dn=(jn=fe.peer)!=null&&jn.pairedAt?hs(fe.peer.pairedAt,a):null,ir=[($n=(Ht=fe.peer)==null?void 0:Ht.about)!=null&&$n.version?`runs ${fe.peer.about.version}`:null,dn?`paired ${dn==="now"?"just now":dn}`:null,fe.row.state].filter(Boolean).join(" · "),It=fe.row.fp;return i.jsxs("li",{role:"listitem",className:"lan-twin","data-tone":fe.row.tone,children:[i.jsx("i",{className:fe.row.here?"ap-pulse":"ap-dot","aria-hidden":!0}),Tt?i.jsx("code",{className:"ap-lan-code lan-twin-at",children:Tt}):i.jsx("span",{className:"lan-twin-at lan-twin-none",children:"no address here"}),i.jsx("code",{className:"ap-lan-code lan-twin-fp",children:It}),nt>0&&y&&i.jsx("button",{type:"button",className:`ap-manage-btn danger lan-twin-do${R===It?" armed":""}`,...Z(`unpair:${It}`),onKeyDown:Yn=>{Yn.repeat&&Yn.preventDefault()},onClick:()=>{if(R!==It){$(It),T.current=Date.now();return}Date.now()-T.current<oh||($(null),V(()=>y(It)))},"aria-label":R===It?`Confirm unpairing ${Sn}`:`Unpair ${Sn}`,title:R===It?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this one of the machine's decks",children:l===`unpair:${It}`?"unpairing…":R===It?"confirm":"unpair"}),i.jsx("span",{className:"lan-twin-meta",children:nt===0?`${ir} · shown above`:ir})]},It)})})]})]}),i.jsxs("footer",{className:"lan-peer-foot",children:[e.kind==="asks"&&i.jsx("p",{className:"lan-foot-note",children:"This deck is now asking to pair. Answer it from the panel behind this."}),W&&!(I!=null&&I.waiting)&&i.jsx("button",{type:"button",className:"btn",...Z(`check:${e.fp}`),onClick:()=>void V(f).then(fe=>{fe&&J.current&&K(nt=>nt+1)}),title:"Ask this deck now instead of waiting for the next round",children:l===`check:${e.fp}`?"Checking…":"Check now"}),e.kind==="paired"&&i.jsx("button",{type:"button",className:`btn danger lan-peer-verb${E?" armed":""}`,...Z(`unpair:${e.fp}`),onKeyDown:fe=>{fe.repeat&&fe.preventDefault()},onClick:()=>{if(!E){C(!0),T.current=Date.now();return}Date.now()-T.current<oh||(C(!1),V(p))},"aria-label":E?`Confirm unpairing ${e.name}`:`Unpair ${e.name}`,title:E?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this deck from now on",children:l===`unpair:${e.fp}`?"Unpairing…":E?"Confirm unpair":"Unpair"}),e.kind==="nearby"&&i.jsx("button",{type:"button",className:"btn primary lan-peer-verb",...Z(`accept:${e.fp}`),onClick:()=>void V(p),title:"Send it a request. Somebody at that machine has to accept it before anything is shared.",children:l===`accept:${e.fp}`?"Asking…":"Ask to pair"}),e.kind==="dialling"&&i.jsx("button",{type:"button",className:"btn lan-peer-verb",...Z(`drop:${e.fp}`),onClick:()=>void V(p),title:"Stop trying this address. Nothing was ever paired here.",children:l===`drop:${e.fp}`?"Stopping…":"Stop dialling"}),e.kind==="declined"&&i.jsx("button",{type:"button",className:"btn lan-peer-verb",...Z(`allow:${e.fp}`),onClick:()=>void V(p),title:"Take the no back. That deck is still trying, so its request comes round again on its own.",children:l===`allow:${e.fp}`?"Allowing…":"Let it ask again"})]})]})}),document.body)}function J8(e){if(!e.running)return`Tailscale is ${e.state==="Stopped"?"turned off":e.state==="NeedsLogin"||e.state==="NeedsMachineAuth"?"signed out":e.state==="Starting"?"still starting":"not answering"} on this machine`;const t=e.login??"your Tailscale account";return e.on?`${e.devices} online · ${t}`:t}function eB({status:e,accounts:t,onClose:n,onChanged:r}){const a=un(n),[l,c]=x.useState(null),[u,f]=x.useState(null),[p,h]=x.useState(!1),[m,y]=x.useState(null),w=x.useRef(null),_=X=>{const J=La(m,X);return{disabled:J.disabled,"aria-busy":J.busy}},N=x.useRef(null),j=x.useRef(!0);x.useEffect(()=>()=>{j.current=!1},[]),x.useEffect(()=>{N.current&&iB(N.current,e.shared??[])&&(N.current=null)},[e.shared]);const b=x.useCallback(async(X,J,M="write")=>{w.current=M,y(M);try{const V=await(await fetch("/api/prefs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lan:X})})).json().catch(()=>null);return j.current?(V!=null&&V.ok?f(null):f(tn(J,V)),r(),(V==null?void 0:V.ok)===!0):!1}catch{return j.current&&f(tn(J,null)),!1}finally{w.current=null,j.current&&y(null)}},[r]),S=x.useCallback(async()=>{if(l!=null&&l!==(e.name??"")){if(!await b({name:l},"save the name","name"))return;j.current&&c(null)}n()},[l,e.name,b,n]),E=async()=>{if(!e.fp)return;const X=await Eh(e.fp);if(j.current){if(!X){f("Could not copy it — select the fingerprint and copy it by hand.");return}h(!0),window.setTimeout(()=>{j.current&&h(!1)},1600)}},C=new Set(N.current??e.shared??[]),T=e.autoAsk!==!1,R=e.autoAccept!==!1,$=e.shareActive!==!1,H=e.tailscale??null,B=!!(H!=null&&H.on),P=(H==null?void 0:H.ask)!==!1,K=(H==null?void 0:H.accept)!==!1;return Kn.createPortal(i.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:i.jsxs("div",{ref:a,className:"modal lan-modal",onClick:X=>X.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-modal-title",children:[i.jsxs("header",{className:"modal-head",children:[i.jsx("div",{className:"modal-title",children:i.jsx("span",{id:"lan-modal-title",className:"modal-tool-name",children:"This deck on the network"})}),i.jsx("div",{className:"modal-actions",children:i.jsx("button",{className:"glyph-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),i.jsxs("section",{className:"modal-body",children:[u&&i.jsxs("div",{className:"ap-failure",role:"alert",children:[i.jsx("span",{className:"ap-failure-text",children:u}),i.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>f(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),i.jsxs("div",{className:"modal-section",children:[i.jsx("h3",{className:"lan-h",children:"Name"}),i.jsxs("div",{className:"ap-lan-row",children:[i.jsx("span",{className:"ap-lan-label",children:"appear as"}),i.jsx("input",{className:"ap-manage-input ap-lan-input","aria-label":"This deck's name on the network",value:l??e.name??"",placeholder:"this machine",onChange:X=>c(X.target.value),onKeyDown:X=>{X.key!=="Enter"||l==null||(b({name:l},"save the name","name"),c(null))}}),l!=null&&l!==(e.name??"")&&i.jsx("button",{type:"button",className:"ap-manage-btn",..._("name"),onClick:()=>{b({name:l},"save the name","name"),c(null)},title:"Save it. This is the name other decks show for this one.",children:"save"})]}),i.jsxs("div",{className:"ap-lan-row",children:[i.jsx("span",{className:"ap-lan-label",children:"fingerprint"}),e.fp?i.jsxs("span",{className:"lan-fp",children:[i.jsx("code",{className:"ap-lan-code",children:e.fp}),i.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void E(),"aria-label":p?"Fingerprint copied":"Copy this deck's fingerprint",children:p?"copied":"copy"})]}):i.jsx("span",{className:"ap-lan-label",children:"not known yet"})]})]}),i.jsxs("div",{className:"modal-section",children:[i.jsx("h3",{className:"lan-h",children:"Share these accounts"}),i.jsxs("div",{className:"ap-lan-picks",children:[t.length===0&&i.jsx("span",{className:"ap-lan-empty",children:"No Claude accounts on this deck yet — add one with + at the top of this panel."}),t.map(X=>i.jsxs("label",{className:"ap-lan-pick",title:X.alive?"Offer this account to the decks you have paired with, so one whose copy has died can heal from yours. Unticking stops it being offered from now on; it does not take back a copy somebody already has.":"This deck cannot use this login, so it has nothing to offer — a deck that can will heal it",children:[i.jsx("input",{type:"checkbox",checked:C.has(X.key),onChange:J=>{const M=new Set(N.current??e.shared??[]);J.target.checked?M.add(X.key):M.delete(X.key),N.current=[...M],b({shared:[...M]},J.target.checked?"share that account":"stop sharing that account")}}),i.jsx("span",{className:"ap-lan-pick-name",children:X.email}),!X.alive&&i.jsx("span",{className:"ap-lan-dead",children:"not working here"})]},X.key))]}),t.length>0&&i.jsxs("div",{className:"lan-switch",children:[i.jsx("span",{className:"lan-switch-what",children:"Show paired decks which of these this deck is using"}),i.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":$,"aria-label":"Show paired decks which of these this deck is using",..._("current"),onClick:()=>void b({shareActive:!$},$?"stop showing which account this deck is using":"show which account this deck is using","current"),title:$?"Stop telling paired decks which account this one is on. They read “current account hidden” instead.":"Tell paired decks which of the ticked accounts this one is on. An unticked account is never named.",children:i.jsx("span",{className:"switch-knob"})})]})]}),i.jsxs("div",{className:"modal-section",children:[i.jsx("h3",{className:"lan-h",children:"Pairing"}),i.jsxs("div",{className:"lan-switches",children:[i.jsxs("div",{className:"lan-switch",children:[i.jsx("span",{className:"lan-switch-what",children:"Ask every deck this one finds"}),i.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":T,"aria-label":"Ask every deck this one finds",..._("ask"),onClick:()=>void b({autoAsk:!T},T?"stop asking automatically":"ask every deck this one finds","ask"),title:T?"Stop sending requests on their own. You press ask on the row instead.":"Send a pairing request to every deck heard on this network. Somebody over there still has to say yes.",children:i.jsx("span",{className:"switch-knob"})})]}),i.jsxs("div",{className:"lan-switch",children:[i.jsx("span",{className:"lan-switch-what",children:"Say yes to every deck that asks"}),i.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":R,"aria-label":"Say yes to every deck that asks","data-tone":"warn",..._("accept"),onKeyDown:X=>{X.repeat&&X.preventDefault()},onClick:()=>void b({autoAccept:!R},R?"stop accepting automatically":"accept every deck that asks","accept"),title:R?"Stop saying yes for you. A deck that asks waits in the panel again.":"Say yes for you. Every deck on this network that asks is paired without anybody being asked here.",children:i.jsx("span",{className:"switch-knob"})})]})]})]}),(H==null?void 0:H.found)&&i.jsxs("div",{className:"modal-section",children:[i.jsx("h3",{className:"lan-h",children:"Tailscale"}),i.jsxs("div",{className:"lan-switches",children:[i.jsxs("div",{className:"lan-switch",children:[i.jsxs("span",{className:"lan-switch-what",children:["Look for my devices",i.jsx("span",{id:"lan-ts-detail",className:"lan-switch-detail",children:J8(H)})]}),i.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":B,"aria-label":"Look for my devices over Tailscale","aria-describedby":"lan-ts-detail",..._("tailscale"),onClick:()=>void b({tailscale:!B},B?"stop looking over Tailscale":"look for your devices over Tailscale","tailscale"),title:B?"Stop. Nothing is looked for or answered over the tailnet; decks already paired stay paired.":"Find the decks on your other machines on Tailscale, wherever they are. Only machines signed in to your Tailscale account are asked.",children:i.jsx("span",{className:"switch-knob"})})]}),B&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"lan-switch",children:[i.jsx("span",{className:"lan-switch-what",children:"Ask each device it finds"}),i.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":P,"aria-label":"Ask each of my devices it finds over Tailscale",..._("tailscale-ask"),onClick:()=>void b({tailscaleAsk:!P},P?"stop asking your devices automatically":"ask your devices automatically","tailscale-ask"),title:P?"Stop sending requests on their own. You press ask on the row instead.":"Send a pairing request to every deck found on your devices over Tailscale.",children:i.jsx("span",{className:"switch-knob"})})]}),i.jsxs("div",{className:"lan-switch",children:[i.jsx("span",{className:"lan-switch-what",children:"Say yes to each device that asks"}),i.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":K,"aria-label":"Say yes to my devices when they ask over Tailscale","data-tone":"warn",..._("tailscale-accept"),onKeyDown:X=>{X.repeat&&X.preventDefault()},onClick:()=>void b({tailscaleAccept:!K},K?"stop accepting your devices automatically":"accept your devices automatically","tailscale-accept"),title:K?"Stop saying yes for you. A device that asks waits in the panel again.":"Say yes for you when a deck on one of your own devices asks. Anybody else on the tailnet still waits for a press.",children:i.jsx("span",{className:"switch-knob"})})]})]})]})]})]}),i.jsxs("footer",{className:"lan-setup-foot",children:[i.jsx("span",{className:"lan-foot-note",children:"Changes are saved as you make them."}),i.jsx("button",{type:"button",className:"btn primary",..._("name"),onClick:()=>void S(),children:"Done"})]})]})}),document.body)}function hs(e,t){if(e==null)return"not seen";const n=Math.max(0,Math.round((t-e)/1e3));if(n<90)return"now";const r=Math.round(n/60);if(r<60)return`${r}m ago`;const a=Math.round(r/60);return a<48?`${a}h ago`:`${Math.round(a/24)}d ago`}const F0={"waiting for the other deck to accept this one":{text:"waiting for them to say yes",tone:"idle"},"that deck said no":{text:"it said no",tone:"bad"}},tB={ECONNREFUSED:"not listening",EHOSTUNREACH:"no route to it",ENETUNREACH:"no network here",ETIMEDOUT:"no answer",ECONNRESET:"it hung up",EHOSTDOWN:"it is down",ENOTFOUND:"name not found",EACCES:"blocked here",EPIPE:"it hung up"};function nB(e){var r;const t=rB[e];if(t)return t;const n=(r=/\b(E[A-Z]{3,})\b/.exec(e))==null?void 0:r[1];return n&&tB[n]||e}const rB={"handshake timed out":"no answer","peer closed the connection":"it hung up","peer went quiet":"it stopped mid-sentence","bad reply":"it answered with nonsense","no manifest":"it would not say what it has","bad challenge":"it answered as somebody else","a different deck is answering at that address":"a different deck is at that address","that deck could not prove its own key":"it could not prove who it is","the other deck refused this one's proof":"it would not take this deck's word","the other deck refused this handshake":"it turned this deck away","that deck has this one pinned under a different key":"it knows this deck by another key"};function FR(e,t){if(!e)return null;if(e.error)return F0[e.error]??{text:nB(e.error),tone:"bad"};const n=e.done??[];if(!n.length)return{text:`all logins fine · ${hs(e.at,t)}`,tone:"idle"};const r=n.filter(l=>l.ok),a=r.length===1?"login":"logins";return r.length===n.length?{text:`${r.length} ${a} arrived · ${hs(e.at,t)}`,tone:"ok"}:{text:`${r.length} of ${n.length} logins arrived · ${hs(e.at,t)}`,tone:"bad"}}const sB=9e4;function aB({error:e,host:t,port:n},r,a,l=45317){if(e!=="handshake timed out")return null;const c=(t??"").trim();if(!c)return null;const u=r.filter(p=>p.addr===c&&p.port&&p.at>0&&a-p.at<sB);if(!u.length)return null;const f=[...new Set(u.map(p=>p.port))];if(n!=null&&!f.includes(n)){const p=f.length===1?`port ${f[0]}`:`ports ${f.join(" and ")}`;return`A deck at ${c} is announcing itself on ${p}, not on ${n}. This deck already hears it and dials it there, so this typed row has nothing to reach.`}return`That machine is running the deck — its beacon arrives here every half minute — and what this deck sends back never gets there. That is a firewall on ${c}, not a network fault. Whoever uses it can allow two ports: UDP ${l} and TCP ${n??f[0]}.`}const Hx=5e3,qR=6e4,oh=400;function oB(e){const t=(e??"").trim(),n=t.lastIndexOf(":");if(n<=0||n===t.length-1)return null;const r=t.slice(0,n).trim(),a=Number(t.slice(n+1).trim());return!r||!Number.isInteger(a)||a<1||a>65535||r.includes(":")&&!(r.startsWith("[")&&r.endsWith("]"))?null:{addr:r,port:a}}function tn(e,t){return t==null?`Could not ${e} — the deck did not answer.`:t.reason?`Could not ${e} — the deck refused it (${t.reason}).`:`Could not ${e}.`}function iB(e,t){if(e.length!==t.length)return!1;const n=new Set(e);return t.every(r=>n.has(r))}function lB(e,t){const n=Math.max(0,Math.round((e-t)/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function BR(e,t){var n,r;return(n=e.last)!=null&&n.error&&!F0[e.last.error]?!1:!!((r=e.last)!=null&&r.at&&t-e.last.at<ih||e.lastSeen!=null&&t-e.lastSeen<ih)}const ih=95e3,zR=160,cB=6,HR=140;function uB(e,t){const n=[],r=[];for(const a of e??[])(BR(a,t)?n:r).push(a);return{online:n,offline:r}}function dB(e){var t;return(t=e.tailscale)!=null&&t.exitNode?"Tailscale sends this machine's local network through an exit node, so decks on this network cannot find this one. Turn on Allow local network access in Tailscale's exit node menu to bring them back.":"This machine sends its local network through a VPN, so decks on this network cannot find this one. Allowing local network access in the VPN brings them back."}function hB(e,t){if(!e)return{text:"checking…",tone:"idle"};if(!e.enabled)return{text:"",tone:"idle"};if(e.stalled)return{text:`could not start — ${e.stalled}`,tone:"bad"};if(!e.running)return{text:"starting…",tone:"wait"};const n=(e.pending??[]).length;if(n)return{text:n===1?"1 deck is waiting for your answer":`${n} decks are waiting for your answer`,tone:"wait"};const r=(e.peers??[]).filter(w=>w.paired!==!1||w.met);if(!r.length)return{text:"no deck paired yet",tone:"idle"};const a=r.filter(w=>w.waiting),l=r.filter(w=>!w.waiting),c=a.filter(w=>{var _;return!((_=w.last)!=null&&_.error)&&w.lastSeen!=null&&t-w.lastSeen<ih}),{online:u,offline:f}=uB(l,t),p=[...f,...a.filter(w=>!c.includes(w))],h=u.length+c.length,m=u.filter(w=>{var _;return((_=w.last)==null?void 0:_.error)==="waiting for the other deck to accept this one"});if(h&&m.length===h)return{text:h===1?"1 deck found · waiting for them to accept":`${h} decks found · waiting for them to accept`,tone:"wait"};if(!h)return{text:p.length===1?"this deck cannot reach the one it is paired with":`this deck cannot reach any of its ${p.length} decks`,tone:"bad"};const y=h===1?"1 deck ready":`${h} decks ready`;return{text:p.length?`${y} · ${p.length} away`:y,tone:"ok"}}function fB(e,t,n){if(n)return"checking…";if(e==null)return"not checked yet";const r=hs(e,t);return r==="now"?"checked just now":`checked ${r}`}function q0(e,t){const n=Math.max(0,Math.round((t-e)/1e3));if(n<90)return"just now";const r=Math.round(n/60);return r<60?`${r}m ago`:`${Math.round(r/60)}h ago`}function pB(e,t){if(e==null)return{text:"one-way · has not called yet",here:!1};const n=t-e<ih;return{text:n?"online · one-way, it calls in":`one-way · last online ${hs(e,t)}`,here:n}}function n_(e,t,n){return t?"online":e.lastSeen!=null?`last online ${hs(e.lastSeen,n)}`:e.waiting?"has not called yet":"never reached"}function mB(e,t){var y,w,_,N,j;if(!e)return[];const n=[],r=new Set,a=(b,S)=>b.name.localeCompare(S.name,void 0,{numeric:!0}),l=e.aliases??{},c=(b,S)=>{const E=b?l[b]:void 0;return E&&E!==S?{name:E,self:S}:{name:S}};for(const b of e.pending??[]){if(!(b!=null&&b.fp)||r.has(b.fp))continue;r.add(b.fp);const S=c(b.fp,b.name||b.fp);n.push({fp:b.fp,name:S.name,...S.self?{self:S.self}:{},addr:b.addr??"",kind:"asks",state:`wants to pair · ${q0(b.at,t)}`,tone:"wait",here:!0,hint:`${S.name} at ${b.addr}${b.via==="tailscale"?", over Tailscale,":""} is waiting for an answer.`,...b.via==="tailscale"?{via:"tailscale"}:{}})}const u=[],f=[];for(const b of e.peers??[]){const S=b.peerFp??b.fp;if(!S||r.has(S))continue;r.add(S);const E=FR(b.last,t),C=BR(b,t),T=b.addr?`${b.addr}:${b.port}`:"";if(!b.paired&&b.manual&&!b.met){f.push({fp:T,name:T||b.name||S,addr:b.addr??"",kind:"dialling",state:E?E.text.replace(/ · .*$/,""):"trying…",tone:E?E.tone:"idle",here:!1,hint:(y=b.last)!=null&&y.error?`Nothing has answered at ${T} yet — ${b.last.error}.`:`Dialling ${T} until something answers.`,...b.via==="tailscale"?{via:"tailscale"}:{}});continue}const R=b.waiting?pB(b.lastSeen,t):null,$=R?R.here:C,H=!R&&E?$?`online · ${E.text.replace(/ · .*$/,"")}`:`${E.text.replace(/ · .*$/,"")} · ${n_(b,$,t)}`:R?R.text:n_(b,$,t),B=(w=b.last)!=null&&w.error?F0[b.last.error]:null,P=!R&&$&&!((_=b.last)!=null&&_.error)&&!(((N=b.last)==null?void 0:N.done)??[]).length,K=b.manual&&!b.met?{name:T}:c(S,b.name||S);u.push({fp:S,name:K.name,...K.self?{self:K.self}:{},addr:b.addr??"",kind:"paired",state:H,quiet:P,tone:B?B.tone==="bad"?"bad":"wait":E?E.tone:$?"ok":"idle",here:R?R.here:C,...b.via==="tailscale"?{via:"tailscale"}:{},hint:R?`${K.name} calls this deck, and this deck has no address to call back on — so it can repair its logins from here, and this deck cannot repair from it. ${b.lastSeen==null?"It has not called since this deck started.":`It last called ${hs(b.lastSeen,t)}.`} Add its address with the + at the top of this section to reach it either way.`:`${K.name}${T?` at ${T}`:""}${(j=b.last)!=null&&j.error?` — ${b.last.error}`:""}`})}n.push(...gB(u).sort(a),...f.sort(a));const p=[];for(const b of e.strangers??[]){if(!(b!=null&&b.fp)||r.has(b.fp))continue;r.add(b.fp);const S=c(b.fp,b.name||b.fp);p.push({fp:b.fp,name:S.name,...S.self?{self:S.self}:{},addr:b.addr??"",kind:"nearby",state:"not paired yet",tone:"idle",here:!0,hint:b.via==="tailscale"?`${S.name} at ${b.addr} is on your tailnet and nothing is shared with it.`:`${S.name} at ${b.addr} is on this network and nothing is shared with it.`,...b.via==="tailscale"?{via:"tailscale"}:{}})}n.push(...p.sort(a));const h=[];for(const b of e.declined??[]){if(!(b!=null&&b.fp)||r.has(b.fp))continue;r.add(b.fp);const S=c(b.fp,b.name||b.fp);h.push({fp:b.fp,name:S.name,...S.self?{self:S.self}:{},addr:b.addr??"",kind:"declined",state:"you said no",tone:"idle",here:!1,hint:`${S.name} asked and was turned away. It is not asking any more.`})}n.push(...h.sort(a));const m=new Map;for(const b of n)m.set(b.name,(m.get(b.name)??0)+1);for(const b of n)(m.get(b.name)??0)<2||!b.addr||(b.state=b.quiet||!b.state?b.addr:`${b.addr} · ${b.state}`,b.quiet=!1);return n}function gB(e){const t=new Map;for(const r of e){const a=t.get(r.name);a?a.push(r):t.set(r.name,[r])}const n=[];for(const r of t.values()){const a=[...new Set(r.filter(l=>l.addr).map(l=>l.addr))];if(a.length>1){for(const l of a)n.push(r_(r.filter(c=>c.addr===l)));n.push(...r.filter(l=>!l.addr))}else n.push(r_(r))}return n}function r_(e){const[t,...n]=[...e].sort((r,a)=>Number(a.here)-Number(r.here)||+!!a.addr-+!!r.addr);return n.length?{...t,twins:n}:t}function s_(e,t){return t?e.map(n=>t[n.fp]?{...n,name:t[n.fp]}:n):e}function a_(e,t){if(!e)return{};switch(t.kind){case"paired":return{peer:(e.peers??[]).find(n=>(n.peerFp??n.fp)===t.fp)??null};case"dialling":return{peer:(e.peers??[]).find(n=>n.manual&&!n.met&&`${n.addr}:${n.port}`===t.fp)??null};case"nearby":return{stranger:(e.strangers??[]).find(n=>n.fp===t.fp)??null};case"declined":return{stranger:(e.declined??[]).find(n=>n.fp===t.fp)??null};case"asks":return{stranger:(e.pending??[]).find(n=>n.fp===t.fp)??null}}}function yB(e,t){const n=/^(\d+)\.(\d+)\.(\d+)/.exec(e??""),r=/^(\d+)\.(\d+)\.(\d+)/.exec(t??"");if(!n||!r)return null;for(let a=1;a<=3;a++){const l=Number(n[a])-Number(r[a]);if(l)return Math.sign(l)}return 0}function wB(e,t,n){const r=t?t.alive?"works here":"expired here":"not on this deck";if(!e.alive){const a=t&&!t.alive?"neither copy works — sign in again here":null;return{there:"broken there",here:r,note:a,tone:a?"bad":"idle"}}return t?t.alive?{there:"works there",here:r,note:null,tone:"ok"}:n?{there:"works there",here:r,note:"repairs next round",tone:"wait"}:{there:"works there",here:r,note:"share it to repair",tone:"bad"}:{there:"works there",here:r,note:"arrives next round",tone:"wait"}}function vB(e,t,n,r=null){const a=new Map(t.map(f=>[f.key,f])),l=new Set(n),c=[],u=new Set;for(const f of e??[]){if(u.has(f.key))continue;u.add(f.key);const p=a.get(f.key)??null,h=l.has(f.key),m=wB(f,p,h),y=p?p.alive?"works":"expired":"missing",w=!f.alive&&p&&!p.alive?m.note:[y==="works"?null:m.here,f.alive?null:m.there,m.note].filter(Boolean).join(" · ")||null;c.push({key:f.key,email:f.email,here:y,there:f.alive?"works":"broken",in:f.alive?m.tone==="wait"?"wait":m.tone==="bad"?"blocked":"live":"cut",out:h&&p?p.alive?"live":"cut":null,caption:w,tone:m.tone,usedThere:r===f.key})}for(const f of n){const p=a.get(f);!p||u.has(f)||(u.add(f),c.push({key:f,email:p.email,here:p.alive?"works":"expired",there:"unknown",in:null,out:p.alive?"live":"cut",caption:p.alive?null:"expired here",tone:p.alive?"ok":"bad",usedThere:!1}))}return c}async function Li(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}function xB({anchorId:e,id:t,rows:n,onHold:r,onLet:a}){const l=x.useRef(null),c=n.filter(y=>y.kind==="paired"),u=c.filter(y=>y.here),f=u.slice(0,cB),p=c.length-u.length,h=u.length>f.length?`and ${u.length-f.length} more`:p>0?`${p} not on right now`:null,m=x.useCallback(()=>{const y=l.current,w=document.getElementById(e);if(!y||!w)return;const _=O0(w.getBoundingClientRect(),{width:y.offsetWidth,height:y.offsetHeight},{width:window.innerWidth,height:window.innerHeight});y.style.top=`${_.top}px`,y.style.left=`${_.left}px`,y.style.maxHeight=_.maxHeight==null?"":`${_.maxHeight}px`,y.dataset.side=_.side},[e]);return x.useLayoutEffect(()=>{m()}),x.useEffect(()=>(window.addEventListener("scroll",m,!0),window.addEventListener("resize",m),()=>{window.removeEventListener("scroll",m,!0),window.removeEventListener("resize",m)}),[m]),Kn.createPortal(i.jsxs("div",{ref:l,id:t,className:"ap-peek",role:"tooltip",onPointerEnter:r,onPointerLeave:a,children:[i.jsx("p",{className:"ap-peek-title",children:u.length?"On the network now":"Nobody on the network"}),f.length>0&&i.jsx("div",{className:"ap-peek-list",children:f.map(y=>i.jsxs("span",{className:"ap-peek-who",children:[i.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),i.jsxs("span",{children:[y.name,y.via==="tailscale"&&i.jsx("span",{className:"ap-lan-via",children:" · Tailscale"})]})]},`${y.kind}:${y.fp}`))}),h&&i.jsx("p",{className:"ap-peek-rest",children:h})]}),document.body)}function bB(e,t){var l;if(!e)return{text:"checking…",tone:"idle",live:!1};if(!e.enabled)return{text:"Off",tone:"idle",live:!1};if(e.stalled)return{text:"could not start",tone:"bad",live:!1};if(!e.running)return{text:"starting…",tone:"wait",live:!1};const n=t.filter(c=>c.kind==="asks").length;if(n)return{text:n===1?"1 deck wants to pair":`${n} decks want to pair`,tone:"wait",live:!1};if((l=e.reach)!=null&&l.blocked)return{text:"nothing can get in",tone:"bad",live:!1};const r=t.filter(c=>c.kind==="paired");if(!r.length)return{text:"On · none paired yet",tone:"idle",live:!1};const a=r.filter(c=>c.here).length;return a?a===r.length?{text:`${a} online`,tone:"ok",live:!0}:{text:`${a} of ${r.length} online`,tone:"ok",live:!0}:{text:`none of ${r.length} online`,tone:"idle",live:!1}}function kB({accounts:e,onChanged:t,view:n,onOpen:r,onBack:a,closeButton:l}){const[c,u]=x.useState(null),[f,p]=x.useState([]),[h,m]=x.useState(null),[y,w]=x.useState(!1),[_,N]=x.useState(null),j=x.useRef(0),[b,S]=x.useState(!1),[E,C]=x.useState(!1),[T,R]=x.useState(!1),$=x.useRef(0);x.useEffect(()=>()=>window.clearTimeout($.current),[]);const[H,B]=x.useState(!1),[P,K]=x.useState(null),X=x.useRef(null),J=x.useCallback(le=>Th(X.current)?(X.current=le,m(le),!0):!1,[]),M=x.useCallback(()=>{X.current=null,q.current&&m(null)},[]),Z=le=>{const Ne=La(h,le);return{disabled:Ne.disabled,"aria-busy":Ne.busy}},[V,I]=x.useState(()=>Date.now()),q=x.useRef(!0),W=x.useRef(Hx),G=x.useCallback(async()=>{var le,Ne;try{const[Me,tt]=await Promise.all([fetch("/api/lan").then(Ge=>Ge.json()),fetch("/api/prefs").then(Ge=>Ge.json())]);if(!q.current)return;Me!=null&&Me.ok&&u(Me),tt!=null&&tt.ok&&p(Array.isArray((Ne=(le=tt.prefs)==null?void 0:le.lan)==null?void 0:Ne.manual)?tt.prefs.lan.manual:[]),W.current=(Me==null?void 0:Me.enabled)===!0?Hx:qR}catch{}},[]);x.useEffect(()=>{q.current=!0;let le=0;const Ne=async()=>{I(Date.now()),await G(),q.current&&(le=window.setTimeout(Ne,W.current))};return Ne(),()=>{q.current=!1,window.clearTimeout(le)}},[G]);const F=x.useCallback(async()=>{const le=(c==null?void 0:c.enabled)===!0;if(J("switch"))try{const Ne=await Li("/api/prefs",{lan:{enabled:!le}});if(!q.current)return;Ne!=null&&Ne.ok?(K(null),le||w(!0)):K(tn(le?"turn this off":"turn this on",Ne)),await G()}catch{q.current&&K(tn(le?"turn this off":"turn this on",null))}finally{M()}},[c==null?void 0:c.enabled,G,J,M]),D=x.useCallback(async(le,Ne,Me)=>{if(!J(`${le}:${Ne}`))return null;let tt=null;try{const Ge=await Li("/api/lan/peer",{action:le,fp:Ne});if(!q.current)return null;Ge!=null&&Ge.ok?(u(Ge),K(null)):(tt=tn(Me,Ge),K(tt)),await G()}catch{tt=tn(Me,null),q.current&&K(tt)}finally{M()}return tt},[G,J,M]),ae=x.useCallback(async le=>{if(!J(`drop:${le}`))return null;let Ne=null;try{const Me=await Li("/api/prefs",{lan:{manual:f.filter(tt=>tt!==le)}});if(!q.current)return null;Me!=null&&Me.ok?(K(null),t()):(Ne=tn("stop dialling that address",Me),K(Ne)),await G()}catch{Ne=tn("stop dialling that address",null),q.current&&K(Ne)}finally{M()}return Ne},[f,G,t,J,M]),[z,Q]=x.useState(null),U=x.useCallback(async(le,Ne)=>{if(!J(`alias:${le}`))return"Something else is still being saved. Try again in a moment.";try{const Me=await Li("/api/lan/peer",{action:"alias",fp:le,name:Ne});return q.current?Me!=null&&Me.ok?(u(Me),null):tn("rename that deck",Me):null}catch{return tn("rename that deck",null)}finally{M()}},[J,M]),re=x.useCallback(async le=>{if(!J(`check:${le}`))return null;try{const Ne=await Li("/api/lan/sync",{fp:le});return q.current?Ne!=null&&Ne.ok?(u(Ne),t(),null):(Ne==null?void 0:Ne.reason)==="no_address"?"There is no address here to call it on. It calls this deck, and it is up to date each time it does.":tn("check that deck",Ne):null}catch{return tn("check that deck",null)}finally{M()}},[J,M,t]),de=x.useCallback(async()=>{if(J("check"))try{const le=await Li("/api/lan/sync",{});if(!q.current)return;le!=null&&le.ok?(u(le),K(null)):K(tn("check the other decks",le)),t()}catch{q.current&&K(tn("check the other decks",null))}finally{M()}},[J,M,t]),ge=(c==null?void 0:c.enabled)===!0,pe=mB(c,V),ke=z?pe.find(le=>{var Ne;return le.fp===z||((Ne=le.twins)==null?void 0:Ne.some(Me=>Me.fp===z))})??null:null;x.useEffect(()=>{z&&c&&!ke&&Q(null)},[z,c,ke]);const Pe=pe.filter(le=>le.kind==="asks"),$e=pe.filter(le=>le.kind!=="asks"),Ae=$e.filter(le=>le.here),je=$e.filter(le=>!le.here),Qe=je.filter(le=>le.tone==="bad").length,Te=H||Ae.length===0,Se=hB(c,V),We=$e.filter(le=>le.kind==="paired").length,dt=bB(c,pe),ct=i.jsxs(i.Fragment,{children:[b&&c&&i.jsx(W8,{status:c,manual:f,onClose:()=>S(!1),onChanged:()=>{G(),t()}}),E&&i.jsx(PR,{title:"How Local network works",steps:D8,finish:ge?void 0:{label:"Turn it on",act:()=>{C(!1),F()}},onClose:()=>C(!1)}),y&&c&&i.jsx(eB,{status:{...c,manualRows:f},accounts:e,manual:f,onClose:()=>w(!1),onChanged:()=>{G(),t()}}),ke&&c&&i.jsx(Q8,{row:ke,source:a_(c,ke),status:c,accounts:e,now:V,busy:h,onClose:()=>Q(null),onRename:le=>U(ke.fp,le),onCheck:()=>re(ke.fp),onVerb:()=>{switch(ke.kind){case"paired":return D("unpair",ke.fp,"unpair that deck");case"nearby":return D("accept",ke.fp,"reach that deck");case"declined":return D("allow",ke.fp,"let that deck ask again");case"dialling":return ae(ke.fp);default:return Promise.resolve(null)}},onSettings:()=>{Q(null),w(!0)},twins:(ke.twins??[]).map(le=>({row:le,peer:a_(c,le).peer??null})),onUnpair:le=>D("unpair",le,"unpair that deck")})]});if(!n){const le=Ge=>{window.clearTimeout($.current),$.current=window.setTimeout(()=>R(!0),Ge)},Ne=()=>{window.clearTimeout($.current),$.current=window.setTimeout(()=>R(!1),HR)},Me=()=>window.clearTimeout($.current),tt=()=>{window.clearTimeout($.current),R(!1)};return i.jsxs("div",{className:"ap-foot",children:[i.jsxs("button",{type:"button",id:"ap-lan-entry",className:"ap-nav",onClick:()=>{tt(),r()},"aria-describedby":T?"ap-lan-peek":void 0,onPointerEnter:Ge=>{Ge.pointerType==="mouse"&&le(zR)},onPointerLeave:Ne,onFocus:Ge=>{Ge.target.matches(":focus-visible")&&le(0)},onBlur:Ne,children:[i.jsxs("svg",{className:"ap-nav-glyph",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("rect",{x:"1.8",y:"2.3",width:"10.4",height:"7.2",rx:"1.2"}),i.jsx("path",{d:"M5 11.9h4M7 9.5v2.4"})]}),i.jsxs("span",{className:"ap-nav-text",children:[i.jsx("span",{className:"ap-nav-name",children:"Local network"}),i.jsxs("span",{className:"ap-nav-state","data-tone":dt.tone,children:[dt.live&&i.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),dt.text]})]}),i.jsx("svg",{className:"ap-nav-chev",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:i.jsx("path",{d:"M5.6 3.4 9.2 7l-3.6 3.6"})})]}),T&&i.jsx(xB,{anchorId:"ap-lan-entry",id:"ap-lan-peek",rows:pe,onHold:Me,onLet:Ne}),i.jsx("p",{className:"vis-hidden",role:"status",children:Se.tone==="ok"?"":Se.text}),ct]})}return i.jsxs("div",{className:"ap-lan-view",children:[i.jsxs("div",{className:"ap-header",children:[i.jsx("button",{type:"button",id:"ap-lan-back",className:"glyph-btn ap-back",onClick:a,"aria-label":"Back to Claude accounts",title:"Back to Claude accounts",children:i.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:i.jsx("path",{d:"M8.4 3.4 4.8 7l3.6 3.6"})})}),i.jsx("h2",{id:"ap-lan-title",children:"Local network"}),i.jsxs("div",{className:"ap-header-right",children:[ge&&i.jsx("button",{type:"button",className:"glyph-btn ap-lan-plus",onClick:()=>S(!0),"aria-label":"Add a deck",title:"Reach a deck that has not turned up on its own — by address, or with an invite",children:i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M6.1 7.9a2.6 2.6 0 0 0 3.7 0l1.9-1.9a2.6 2.6 0 0 0-3.7-3.7l-.9.9"}),i.jsx("path",{d:"M7.9 6.1a2.6 2.6 0 0 0-3.7 0L2.3 8a2.6 2.6 0 0 0 3.7 3.7l.9-.9"})]})}),ge&&We>0&&i.jsx("button",{type:"button",className:"glyph-btn ap-lan-check",...Z("check"),onClick:()=>void de(),"aria-label":h==="check"?"Checking every paired deck":"Check every paired deck now",title:"Ask every paired deck now for anything this deck's expired logins need, instead of waiting for the next round",children:i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("circle",{cx:"7",cy:"7",r:"1.1",fill:"currentColor",stroke:"none"}),i.jsx("path",{d:"M4.6 4.6a3.4 3.4 0 0 0 0 4.8M9.4 4.6a3.4 3.4 0 0 1 0 4.8"}),i.jsx("path",{d:"M2.6 2.6a6.2 6.2 0 0 0 0 8.8M11.4 2.6a6.2 6.2 0 0 1 0 8.8"})]})}),ge&&i.jsx("button",{type:"button",className:"glyph-btn ap-lan-set",...Z("setup"),onClick:()=>w(!0),"aria-label":"This deck's name and shared logins",title:"This deck's name on the network, and which of its logins it offers",children:i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M1.8 4.7h10.4M1.8 9.3h10.4"}),i.jsx("circle",{cx:"9.1",cy:"4.7",r:"1.6",fill:"var(--panel)"}),i.jsx("circle",{cx:"4.9",cy:"9.3",r:"1.6",fill:"var(--panel)"})]})}),l]})]}),i.jsx("div",{className:"ap-scroll",id:"ap-lan-scroll",children:i.jsxs("div",{className:"ap-lan",children:[i.jsxs("div",{className:"ap-policy",children:[i.jsx("h3",{className:"ap-auto-title",children:"Sync with paired decks"}),i.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":ge,"aria-label":"Sync with paired decks",...Z("switch"),onClick:()=>void F(),title:ge?"Stop talking to other decks. Nothing is shared while this is off.":"Let the decks you pair with repair this one's expired logins",children:i.jsx("span",{className:"switch-knob"})})]}),ge&&i.jsx(DR,{reach:c==null?void 0:c.reach,where:"panel"}),ge&&(c==null?void 0:c.deaf)&&i.jsx("p",{className:"ap-lan-fine",children:c.deaf}),ge&&(c==null?void 0:c.lanTunneled)&&i.jsx("p",{className:"ap-lan-fine",children:dB(c)}),!ge&&i.jsxs("button",{type:"button",className:"ap-lan-intro",onClick:()=>C(!0),title:"Four pictures: what this does, and what to do on each machine",children:[i.jsx(F8,{}),i.jsx("span",{className:"ap-lan-intro-text",children:"Paired machines repair each other's expired logins."}),i.jsx("span",{className:"ap-lan-intro-go",children:"See how it works"})]}),i.jsx("p",{className:`ap-lan-status ${Se.tone}`,role:"status",children:Se.tone==="ok"?"":Se.text}),P&&i.jsxs("div",{className:"ap-failure",role:"alert",children:[i.jsx("span",{className:"ap-failure-text",children:P}),i.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>K(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),ge&&i.jsxs(i.Fragment,{children:[Pe.length>0&&i.jsx("div",{className:"ap-lan-asks",role:"alert",children:Pe.map(le=>i.jsxs("div",{className:"ap-lan-ask",children:[i.jsxs("span",{className:"ap-lan-ask-what",children:[i.jsx("strong",{className:"ap-lan-peer-name",children:le.name})," at ",i.jsx("code",{className:"ap-lan-code",children:le.addr})," wants to pair"]}),i.jsxs("span",{className:"ap-lan-ask-fp",children:["fingerprint ",i.jsx("code",{className:"ap-lan-code",children:le.fp})]}),i.jsxs("span",{className:"ap-lan-ask-acts",children:[i.jsx("button",{type:"button",className:"ap-manage-btn",...Z(`accept:${le.fp}`),onClick:()=>void D("accept",le.fp,"accept that deck"),title:`Talk to this deck from now on. Its fingerprint is ${le.fp} — check it matches the one on their screen before you accept.`,children:"accept"}),i.jsx("button",{type:"button",className:"ap-manage-btn",...Z(`dismiss:${le.fp}`),onClick:()=>void D("dismiss",le.fp,"decline that request"),title:"Say no. Nothing is shared, and that deck is told rather than left waiting.",children:"decline"})]})]},le.fp))}),(Te?[...Ae,...je]:Ae).length>0&&i.jsx("ul",{className:"ap-lan-here",children:(Te?[...Ae,...je]:Ae).map((le,Ne)=>i.jsxs("li",{className:"ap-lan-who","data-tone":le.tone,children:[i.jsx("i",{className:le.here?"ap-pulse":"ap-dot","aria-hidden":!0}),i.jsxs("span",{className:"ap-lan-who-name","aria-hidden":!0,children:[le.name,le.via==="tailscale"&&i.jsx("span",{className:"ap-lan-via",children:" · Tailscale"})]}),i.jsx("button",{type:"button",className:"ap-lan-who-open","aria-haspopup":"dialog","aria-describedby":`lan-who-state-${Ne}`,onClick:()=>Q(le.fp),children:i.jsxs("span",{className:"vis-hidden",children:[le.name,le.via==="tailscale"?", over Tailscale":"",", details"]})}),i.jsx("span",{id:`lan-who-state-${Ne}`,className:le.quiet?"vis-hidden":"ap-lan-who-when",children:le.state}),le.kind==="nearby"&&i.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`accept:${le.fp}`),onClick:()=>void D("accept",le.fp,"reach that deck"),"aria-label":`Ask ${le.name} to pair`,title:`Send ${le.name} a request. Somebody at that machine has to accept it before anything is shared. Its fingerprint is ${le.fp}.`,children:"ask"}),le.kind==="paired"&&i.jsx("button",{type:"button",className:`ap-manage-btn ap-lan-do danger${_===le.fp?" armed":""}`,...Z(`unpair:${le.fp}`),onClick:()=>{if(_!==le.fp){N(le.fp),j.current=Date.now(),window.setTimeout(()=>N(Me=>Me===le.fp?null:Me),4e3);return}Date.now()-j.current<oh||(N(null),D("unpair",le.fp,"unpair that deck"))},"aria-label":_===le.fp?`Confirm unpairing ${le.name}`:`Unpair ${le.name}`,title:_===le.fp?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this deck from now on",children:_===le.fp?"confirm":"unpair"}),le.kind==="dialling"&&i.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`drop:${le.fp}`),onClick:()=>void ae(le.fp),"aria-label":`Stop dialling ${le.name}`,title:"Stop trying this address. Nothing was ever paired here.",children:"stop"}),le.kind==="declined"&&i.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`allow:${le.fp}`),onClick:()=>void D("allow",le.fp,"let that deck ask again"),"aria-label":`Let ${le.name} ask again`,title:"Take the no back. That deck is still trying, so the request comes round again on its own.",children:"allow"})]},`${le.kind}:${le.fp}`))}),(Ae.length>0&&je.length>0||ge&&We>0)&&i.jsxs("div",{className:"ap-lan-tail",children:[Ae.length>0&&je.length>0&&i.jsxs("button",{type:"button",className:"ap-lan-word ap-lan-more","aria-expanded":H,onClick:()=>B(le=>!le),title:H?"Show only the decks that are on":`Show the ${je.length} deck${je.length===1?"":"s"} that are not responding right now`,children:[i.jsx("span",{className:`ap-lan-chev${H?" open":""}`,"aria-hidden":!0,children:"›"}),H?"fewer":`${je.length} more`,!H&&Qe>0&&i.jsxs("span",{className:"ap-lan-more-bad",children:[" · ",Qe," not responding"]})]}),ge&&We>0&&i.jsx("span",{className:"ap-lan-checked",children:fB(c==null?void 0:c.checkedAt,V,h==="check")})]}),$e.length===0&&Pe.length===0&&!(c!=null&&c.stalled)&&!(c!=null&&c.deaf)&&!(c!=null&&c.lanTunneled)&&i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"ap-lan-fine",children:"No other deck yet. Decks on one network usually find each other on their own; when that has not happened, the link at the top of this view reaches one by address or by invite."}),i.jsx("button",{type:"button",className:"ap-lan-word ap-lan-how",onClick:()=>C(!0),children:"How it works"})]})]})]})}),ct]})}function NB({anchorId:e,id:t,peers:n,onHold:r,onLet:a}){const l=x.useRef(null),{title:c,shown:u,rest:f}=_8(n),p=x.useCallback(()=>{const h=l.current,m=document.getElementById(e);if(!h||!m)return;const y=O0(m.getBoundingClientRect(),{width:h.offsetWidth,height:h.offsetHeight},{width:window.innerWidth,height:window.innerHeight});h.style.top=`${y.top}px`,h.style.left=`${y.left}px`,h.style.maxHeight=y.maxHeight==null?"":`${y.maxHeight}px`,h.dataset.side=y.side},[e]);return x.useLayoutEffect(()=>{p()}),x.useEffect(()=>(window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}),[p]),Kn.createPortal(i.jsxs("div",{ref:l,id:t,className:"ap-peek ap-fold-peek",role:"tooltip",onPointerEnter:r,onPointerLeave:a,children:[i.jsx("p",{className:"ap-peek-title",children:c}),i.jsx("div",{className:"ap-peek-list",children:u.map(h=>i.jsxs("span",{className:"ap-peek-who ap-fold-who",children:[i.jsx("span",{className:"ap-fold-name",children:h.name}),i.jsx("span",{className:"ap-fold-state","data-tone":h.ready?"ok":h.warn?"warn":"idle",children:h.ready?h.headroom==null?"not read yet":`${h.headroom}% free`:h.why})]},h.key))}),f&&i.jsx("p",{className:"ap-peek-rest",children:f})]}),document.body)}function _B({peers:e,strained:t,armed:n,threshold:r,open:a,onToggle:l}){const[c,u]=x.useState(!1),f=x.useRef(0);x.useEffect(()=>()=>window.clearTimeout(f.current),[]),x.useEffect(()=>{a&&(window.clearTimeout(f.current),u(!1))},[a]);const p=_=>{a||(window.clearTimeout(f.current),f.current=window.setTimeout(()=>u(!0),_))},h=()=>{window.clearTimeout(f.current),f.current=window.setTimeout(()=>u(!1),HR)},m=()=>window.clearTimeout(f.current),y=()=>{window.clearTimeout(f.current),u(!1)},w=k8(e,{strained:t&&!a,armed:n,threshold:r});return i.jsxs("div",{className:"ap-rest",children:[i.jsxs("button",{type:"button",id:"ap-rest-entry",className:"ap-nav","aria-expanded":a,"aria-controls":a?"ap-rest-panel":void 0,"aria-describedby":c?"ap-rest-peek":void 0,onClick:()=>{y(),l()},onPointerEnter:_=>{_.pointerType==="mouse"&&p(zR)},onPointerLeave:h,onFocus:_=>{_.target.matches(":focus-visible")&&p(0)},onBlur:h,children:[i.jsxs("span",{className:"ap-nav-text",children:[i.jsx("span",{className:"ap-nav-name",children:"Other accounts"}),i.jsx("span",{className:"ap-nav-state","data-tone":w.tone,children:w.text})]}),i.jsx("svg",{className:"ap-nav-chev",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:i.jsx("path",{d:"M5.6 3.4 9.2 7l-3.6 3.6"})})]}),c&&i.jsx(NB,{anchorId:"ap-rest-entry",id:"ap-rest-peek",peers:e,onHold:m,onLet:h})]})}async function SB(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const jB=1800;function EB({accounts:e,onClose:t,copyText:n}){const[r,a]=x.useState([]),[l,c]=x.useState(null),[u,f]=x.useState(!1),[p,h]=x.useState(null),[m,y]=x.useState(!1),[w,_]=x.useState(()=>Math.floor(Date.now()/1e3)),N=x.useRef(null),j=x.useRef(!1),b=un(t,{focusRef:N});x.useEffect(()=>{if(!l)return;_(Math.floor(Date.now()/1e3));const P=window.setInterval(()=>_(Math.floor(Date.now()/1e3)),1e3);return()=>window.clearInterval(P)},[l]);const S=m8(e),E=e.filter(P=>!r.includes(P.num)).map(P=>P.num),C=E.length===e.length,T=P=>a(K=>K.includes(P)?K.filter(X=>X!==P):[...K,P]),R=x.useCallback(async()=>{if(!Ls(j.current)||!E.length)return;j.current=!0,f(!0),h(null),y(!1);const P=await SB({action:"share",accounts:E}).catch(()=>null);if(j.current=!1,f(!1),!(P!=null&&P.ok)){h(Hi(P,"the share could not be made"));return}c({blob:P.blob,expiresAt:P.expiresAt,shared:P.shared??[],failed:P.failed??[]})},[e,E]),$=l?OR(l.expiresAt,w):null,H=($==null?void 0:$.tone)==="gone",B=(l==null?void 0:l.shared.length)??0;return Kn.createPortal(i.jsx("div",{className:"modal-backdrop",onClick:t,role:"presentation",children:i.jsxs("div",{ref:b,className:"modal sa-modal",onClick:P=>P.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Share accounts with another deck",children:[i.jsxs("header",{className:"modal-head",children:[i.jsx("div",{className:"modal-title",children:i.jsx("h3",{children:"Share accounts"})}),i.jsx("div",{className:"modal-actions",children:i.jsx("button",{type:"button",className:"glyph-btn",onClick:t,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),i.jsx("section",{className:"modal-body sa-body",children:l?i.jsxs("div",{className:"sa-step",children:[i.jsx("h4",{children:H?"This share has expired":B===1?"1 account, ready to paste":`${B} accounts, ready to paste`}),i.jsx("code",{className:`ap-share-blob${H?" sa-dead":""}`,children:l.blob}),i.jsxs("div",{className:"ap-share-foot",children:[i.jsx("button",{type:"button",className:"ap-manage-btn",ref:N,onClick:async()=>{if(H){c(null),R();return}await n(l.blob)&&(y(!0),window.setTimeout(()=>y(!1),jB))},children:H?"make a new share":m?"copied":`copy ${B===1?"the share":"all "+B}`}),i.jsxs("span",{className:"ap-manage-hint",title:"This text is the sign-in for every account in it. It is base64 of plain JSON — the expiry inside it is not signed, so anyone holding a copy can change it, and the logins themselves are in there in the clear either way. The countdown only says how long another deck's import dialog will still accept it. If a copy escapes, sign those accounts out and back in.",children:[i.jsx("span",{className:"ap-share-warn",children:B===1?"this is the password":`this is ${B} passwords`})," · ",i.jsx("span",{className:`ap-share-expiry ${$==null?void 0:$.tone}`,children:$==null?void 0:$.text})]})]}),l.failed.length>0&&i.jsxs("div",{className:"sa-failed",role:"alert",children:[i.jsx("p",{className:"sa-failed-head",children:l.failed.length===1?"One account is not in this bundle:":`${l.failed.length} accounts are not in this bundle:`}),i.jsx("ul",{className:"sa-list",children:l.failed.map(P=>{var X;const K=!!(P.email&&((X=P.detail)!=null&&X.includes(P.email)));return i.jsxs("li",{children:[!K&&i.jsx("span",{className:"sa-who",children:P.email||`account ${P.num}`}),i.jsx("span",{className:"sa-why",children:P.detail||"could not be exported"})]},`${P.num}-${P.email}`)})})]}),i.jsx("p",{className:"sa-note",children:H?i.jsx(i.Fragment,{children:"Another deck will refuse this text now. Make a new one — the same accounts are still picked."}):i.jsxs(i.Fragment,{children:["Paste it into the other deck with ",i.jsx("strong",{children:"+"})," → ",i.jsx("strong",{children:"Paste a share"}),". Accounts it already holds are left exactly as they are."]})}),i.jsxs("div",{className:"sa-actions",children:[i.jsx("button",{type:"button",className:"btn",onClick:()=>{c(null),y(!1)},children:"Pick again"}),i.jsx("button",{type:"button",className:"btn primary",onClick:t,children:"Done"})]})]}):e.length===0?i.jsxs("div",{className:"sa-step",children:[i.jsx("h4",{children:"Nothing to share"}),i.jsxs("p",{className:"sa-note",children:["This deck is not holding any accounts right now. Sign one in with ",i.jsx("strong",{children:"+"}),", or wait — the panel is still reading the store."]}),i.jsx("div",{className:"sa-actions",children:i.jsx("button",{type:"button",className:"btn primary",ref:N,onClick:t,children:"Close"})})]}):i.jsxs("div",{className:"sa-step",children:[i.jsxs("h4",{children:["Which accounts go to the other ",nn,"?"]}),i.jsx("p",{className:`sa-count${E.length?"":" empty"}`,children:g8(E.length)}),i.jsx("ul",{className:"sa-list sa-pick",children:S.map(P=>i.jsx("li",{children:i.jsxs("label",{className:"sa-row",children:[i.jsx("input",{type:"checkbox",checked:E.includes(P.num),onChange:()=>T(P.num)}),i.jsx("span",{className:"sa-who",children:P.label}),P.sub&&i.jsx("span",{className:"sa-sub",children:P.sub})]})},P.num))}),p&&i.jsx("p",{className:"aa-err",children:p}),i.jsxs("div",{className:"sa-actions",children:[i.jsx("button",{type:"button",className:"btn",onClick:()=>a(C?e.map(P=>P.num):[]),children:C?"Clear all":"Select all"}),i.jsx("button",{type:"button",className:"btn primary",ref:N,...Aa(u,!E.length),onClick:R,children:u?"making the share…":E.length===0?"Share":E.length===1?"Share 1 account":`Share ${E.length} accounts`})]})]})})]})}),document.body)}function CB(e,t){const n=new Set(e),r=e.length?Math.max(...e):0;return[...new Set([...e,r+1])].sort((a,l)=>a-l).map(a=>{const l=a===t?"here":n.has(a)?"swap":"free";return{slot:a,kind:l,label:l==="here"?`slot ${a}`:`slot ${a} · ${l}`}})}function TB(e,t,n){if(!(n!=null&&n.ok))return null;const r=Number.isInteger(n.to)?n.to:null;if(r==null)return{menuFor:null,confirmRemove:null,shareFor:null,swapNote:null};const a=n.swapped===!0&&r!==t;return{menuFor:e.menuFor===t?r:a&&e.menuFor===r?t:e.menuFor,confirmRemove:null,shareFor:null,swapNote:a?{at:r,displaced:t}:null}}function AB(e,t,n){return t!=null&&e.some(r=>r.slot===t)?t:n}function RB(e,t,n){var a;const r=((a=e.find(l=>l.slot===t))==null?void 0:a.kind)??"here";return r==="swap"?{label:"swap",done:"swapped",sends:!0,swaps:!0,title:`Send this account to slot ${t}. That slot is taken, so the two accounts trade places and the one standing there moves to slot ${n}.`}:r==="free"?{label:"move",done:"moved",sends:!0,swaps:!1,title:`Send this account to slot ${t}. That slot is empty, so no other account moves.`}:{label:"move",done:"here",sends:!1,swaps:!1,title:`This account already holds slot ${n}.`}}function MB(e,t){return{label:"save",done:"saved",sends:e!==t,swaps:!1,title:`Switch the active account out once it passes ${e}% of its limit.`}}function o_(e){return typeof e.id=="string"&&e.id.startsWith("scoped-")}function IB(e){const t=e.filter(u=>!o_(u)),n=e.filter(u=>o_(u)),r=t.length?t:n,a=t.length?n:[],l=r.reduce((u,f)=>u&&u.pct>=f.pct?u:f,null);let c=null;for(const u of a)l&&u.pct<=l.pct||(!c||u.pct>c.pct)&&(c=u);return{shown:r,rest:a,fuller:c,peak:c??l}}const $B="\0";function lh(e){const t=typeof e.email=="string"?e.email.trim():"";if(!t)return`slot:${e.num}`;const n=typeof e.org=="string"?e.org.trim():"";return`acct:${t}${$B}${n}`}function OB(e,t){const n=lh(t);return e.includes(n)?e.filter(r=>r!==n):[...e,n]}function PB(e,t){if(!Array.isArray(t))return e;const n=new Set(t.map(lh)),r=e.filter(a=>n.has(a));return r.length===e.length?e:r}const LB=64;function DB(e,t){const n=e.trim();return{alias:n,commit:n!==(t??"").trim()}}const FB=Object.freeze({text:"couldn't reach the deck server",reload:!0}),qB=Object.freeze({text:"still waiting on the deck server — claude-swap can be slow to answer",reload:!0});async function i_(e){return e.ok?{ok:!0,status:e.status,body:null}:{ok:!1,status:e.status,body:await e.json().catch(()=>null)}}function BB(e){const t=e.find(r=>!r.ok);if(!t)return null;const n=Lc(t.body);return{text:qx(t.body,`the deck server answered ${t.status}`),...n?{raw:n}:{},reload:!0}}function l_(e,t){return t?e!=null&&e.reload&&e.text===t.text&&e.raw===t.raw?e:t:e!=null&&e.reload?null:e}const c_=15e3,zB=8e3,HB=1800,WB=3e4,Dp=[70,80,85,90,95];function Fp(e,t){return gR(t-Math.floor(e/1e3))}function UB(e,t){if(!e)return"";const n=Math.floor(e/1e3)-t;return n<=0?" · due":n<60?` · next in ${n}s`:` · next in ${Math.round(n/60)}m`}function wc(e){return e.charAt(0).toUpperCase()+e.slice(1)}function VB(e,t){const n="The deck can still see this account — its live usage is being read — but claude-swap's own stored copy of the login was rejected, so these numbers stopped updating.";if((e==null?void 0:e.state)==="running")return{text:"resuming…",hint:`${n} The deck is re-capturing it from the login you already have. No sign-in, no switch.`};if((e==null?void 0:e.state)==="failed"){const r=Math.max(1,Math.ceil((e.retryAt/1e3-t)/60)),a=e.reason?`Re-capturing it from the login you already have did not work (${e.reason}).`:"The deck re-captured it from the login you already have, and claude-swap still cannot read it.";return{text:"numbers paused",hint:`${n} ${a} It tries again in ${r}m. No sign-in, no switch.`}}return{text:"numbers paused",hint:n}}function GB(e){switch(e){case"invalid_grant":case"no_refresh_token":return{text:"login expired",hint:"claude-swap's stored login for this account was rejected and cannot be refreshed. Signing in again replaces it — the account keeps its slot, its alias and its history.",fixable:!0};case"http-401":return{text:"re-login needed",hint:"Anthropic refused this account's token.",fixable:!0};case"http-429":return{text:"rate limited",hint:"Anthropic is throttling requests for this account. It clears on its own.",fixable:!1};case"transient":return{text:"temporary error",hint:"A network or server hiccup while reading usage. The next collection retries.",fixable:!1};case"timeout":return{text:"timed out",hint:"Reading this account's usage took too long. The next collection retries.",fixable:!1};case"network":return{text:"unreachable",hint:"Could not reach Anthropic to read this account's usage.",fixable:!1};default:return{text:e,hint:`claude-swap reported "${e}" for this account.`,fixable:!1}}}function KB(e){switch(e){case"no_credentials":return{text:"no stored login",hint:"claude-swap holds no credentials for this account, so there is nothing to read its usage with and nothing to switch to. A paired deck that has them sends them on its own; signing in as this account puts them there by hand.",fix:"sign in"};case"relogin_required":return{text:"login expired",hint:"claude-swap's stored login for this account was rejected and cannot be refreshed. Signing in again replaces it — the account keeps its slot, its alias and its history.",fix:"sign in again"};case"keychain_unavailable":return{text:"keychain unreadable",hint:"This is about the deck, not the account: claude-swap could not open your keychain, so it cannot read any account's stored login. A deck started from a background session cannot reach the keychain at all — start it from a terminal, or let it start at login, and this clears."};case"token_expired":return{text:"token expired",hint:"The access token ran out and the refresh was deferred. The next collection retries."};case"foreign_credential":return{text:"wrong credential",hint:"The live credential belongs to a different account. Switching to this one repairs it."};case null:case void 0:return null;default:return{text:e,hint:`claude-swap reported "${e}" for this account.`}}}function Ed(e,t){if(e.staleCopy){const n=VB(e.repair??null,t);return{text:wc(n.text),hint:n.hint,fix:null,tone:"quiet",blocksSwitch:!1}}if(e.stopped){const n=KB(e.collector??null);if(!n)return{text:"Not collecting",hint:"claude-swap has collected nothing for this account in over half a day and has not said why. A paired deck holding a working copy of this account will replace it on its own. To do it by hand, sign in as this account from + Add.",fix:null,tone:"quiet",blocksSwitch:!1};const r=e.collector==="no_credentials"||e.collector==="relogin_required";return{text:wc(n.text),hint:n.hint,fix:n.fix?wc(n.fix):null,tone:r||e.collector==="keychain_unavailable"?"warn":"quiet",blocksSwitch:r}}if(e.error){const n=GB(e.error);return{text:wc(n.text),hint:n.hint,fix:n.fixable?"Sign in again":null,tone:n.fixable?"warn":"quiet",blocksSwitch:n.fixable}}return null}function qp(){return i.jsxs("svg",{className:"ap-warn-glyph",width:"12",height:"12",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M7 1.9 12.9 12H1.1Z"}),i.jsx("path",{d:"M7 5.6v2.9"}),i.jsx("path",{d:"M7 10.3v.05"})]})}function YB(e){return e>=90?"hi":e>=70?"mid":void 0}function XB(e){const t=Number(e);return[...Number.isFinite(t)&&t>0&&!Dp.includes(t)?[...Dp,t]:Dp].sort((r,a)=>r-a)}function ZB({lane:e,nowSec:t,frozen:n}){const r=Math.min(100,Math.max(0,e.pct)),a=n?"var(--muted)":r>=90?"var(--err)":r>=70?"var(--warn)":"var(--accent)",l=e.resetAt&&!n?yR(e.resetAt,t):null;return i.jsxs("div",{className:"ap-lane",children:[i.jsx("span",{className:"ap-lane-label",title:e.label,children:e.label}),i.jsx("div",{className:"ap-lane-track",children:i.jsx("div",{className:"ap-lane-fill",style:{width:`${r===0?1.5:r}%`,background:a,opacity:r===0||n?.4:1}})}),i.jsxs("span",{className:"ap-lane-pct",style:{color:a},children:[r,"%"]}),i.jsx("span",{className:"ap-lane-reset",title:l?`${e.label} resets in ${l}`:void 0,children:l&&i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"vis-hidden",children:"resets in "}),l]})})]})}async function u_(e){var n;let t=!1;try{t=await Promise.race([((n=navigator.clipboard)==null?void 0:n.writeText(e).then(()=>!0))??Promise.resolve(!1),new Promise(r=>window.setTimeout(()=>r(!1),500))])}catch{t=!1}if(t)return!0;try{const r=document.createElement("textarea");r.value=e,r.setAttribute("readonly",""),r.style.cssText="position:fixed;top:0;left:0;opacity:0",document.body.appendChild(r),r.select(),t=document.execCommand("copy"),r.remove()}catch{t=!1}return t}function QB({onClose:e,leaving:t}){var Hs,Ws,yn;const[n,r]=x.useState(null),[a,l]=x.useState(null),[c,u]=x.useState(null),[f,p]=x.useState(!1),[h,m]=x.useState(null),[y,w]=x.useState(null),[_,N]=x.useState("accounts"),[j,b]=x.useState(!1),[S,E]=x.useState(null),C=x.useRef(S);C.current=S;const[T,R]=x.useState(()=>Math.floor(Date.now()/1e3)),$=x.useRef(null),[H,B]=x.useState(null),P=(H==null?void 0:H.num)??null,K=x.useRef(H);K.current=H;const[X,J]=x.useState(null),[M,Z]=x.useState(!1),[V,I]=x.useState(""),[q,W]=x.useState(null),G=x.useRef(0),[F,D]=x.useState(null),[ae,z]=x.useState(!1),[Q,U]=x.useState(!1),[re,de]=x.useState(null),[ge,pe]=x.useState(null),[ke,Pe]=x.useState(null),[$e,Ae]=x.useState(!1),je=x.useRef(null),Qe=x.useRef(null),[Te,Se]=x.useState([]),[We,dt]=x.useState(!1),ct=x.useRef(null),le=x.useCallback(ee=>Th(ct.current)?(ct.current=ee,u(ee),!0):!1,[]),Ne=x.useCallback(()=>{ct.current=null,u(null)},[]),Me=(ee,Re=!1)=>{const Le=La(c,ee);return{disabled:Le.disabled,"aria-busy":Le.busy||Re}},tt=x.useCallback(ee=>{window.requestAnimationFrame(()=>{var Re;if(qN(((Re=document.activeElement)==null?void 0:Re.tagName)??null))for(const Le of HF(ee)){const Ie=document.querySelector(Le);if(Ie){Ie.focus();return}}})},[]),Ge=x.useCallback(async(ee=!1)=>{ee&&p(!0);const Re=new AbortController,Le=window.setTimeout(()=>Re.abort(),WB);try{const[Ie,ze]=await Promise.all([fetch(`/api/claude-accounts${ee?"?refresh=1":""}`,{signal:Re.signal}),fetch("/api/cswap-auto",{signal:Re.signal})]);if(Ie.ok){const Lt=await Ie.json();r(Lt),Se($t=>PB($t,Lt.accounts))}ze.ok&&l(await ze.json());const ht=BB([await i_(Ie),await i_(ze)]);m(Lt=>l_(Lt,ht))}catch{m(Ie=>l_(Ie,Re.signal.aborted?qB:FB))}finally{window.clearTimeout(Le),ee&&p(!1)}},[]),Je=x.useCallback(async(ee,Re,Le="panel")=>{if(!le(Re))return null;const Ie=Le==="menu"?J:m;Ie(null);try{const ze=await fetch("/api/cswap-auto",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(ee)}),ht=await ze.json().catch(()=>null);return ht!=null&&ht.ok||Ie({text:qx(ht,"command failed",ze.status),raw:Lc(ht)}),ht}catch{return Ie({text:"server unreachable"}),null}finally{Ne()}},[le,Ne]),ye=x.useCallback(async(ee,Re)=>{if(!le(Re))return null;m(null),J(null);try{const Le=await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(ee)}),Ie=await Le.json().catch(()=>null);return Ie!=null&&Ie.ok||J({text:Hi(Ie,"command failed",Le.status)}),Ie}catch{return J({text:"server unreachable"}),null}finally{Ne()}},[le,Ne]);x.useEffect(()=>(Ge(!0),$.current=window.setInterval(()=>Ge(!1),c_),()=>{$.current!=null&&window.clearInterval($.current)}),[Ge]),x.useEffect(()=>{const ee=window.setInterval(()=>R(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(ee)},[]);const Ce=((Hs=a==null?void 0:a.settings["autoswitch.threshold"])==null?void 0:Hs.value)??"90",Ve=ke??Ce,ce=MB(Ve,Ce),at=(Ws=n==null?void 0:n.accounts)==null?void 0:Ws.find(ee=>ee.active),ut=at?Ed(at,T):null,rt=(n==null?void 0:n.accounts)??[],st=at?rt.filter(ee=>!ee.active):[],jt=st.length?rt.filter(ee=>ee.active):rt,vt=st.map(ee=>{const Re=Ed(ee,T);return{key:lh(ee),name:ee.alias??ee.email??`account ${ee.num}`,ready:!ee.disabled&&!(Re!=null&&Re.blocksSwitch),why:ee.disabled?"held out":Re!=null&&Re.blocksSwitch?Re.text:null,warn:(Re==null?void 0:Re.tone)==="warn",headroom:ee.headroom}}),mt=Number(Ce),_n=(at==null?void 0:at.headroom)!=null&&Number.isFinite(mt)&&100-at.headroom>=mt,Et=(a==null?void 0:a.ok)===!0&&(a.enabled||a.external),zt=ee=>We&&st.some(Re=>Re.num===ee)?"ap-rest-list":"ap-scroll",fe=async(ee,Re)=>{if(le(`switch-${ee}`)){m(null),w(null);try{const Ie=await(await fetch("/api/claude-accounts/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({account:ee})})).json().catch(()=>null);Ie!=null&&Ie.ok?w({num:ee,name:Re}):m({text:qx(Ie,"the switch failed"),raw:Lc(Ie),row:ee}),await Ge(!0)}catch{m({text:"server unreachable",row:ee})}finally{Ne(),tt(ee)}}},nt=x.useCallback(()=>{B(null),J(null),W(null),D(null),U(!1)},[]),Tt=(ee,Re="first")=>{nt(),E(null),pe(null),B({num:ee,view:"menu",start:Re})},Sn=(ee,Re)=>{nt(),E(Le=>(Le==null?void 0:Le.anchor)===Re?null:{num:ee,anchor:Re})},dn=x.useCallback((ee=!1)=>{var Le;const Re=C.current;ee&&Re&&((Le=document.getElementById(Re.anchor))==null||Le.focus()),E(null)},[]),ir=()=>{nt(),E(null),N("lan")},It=x.useRef(_);x.useEffect(()=>{It.current!==_&&(It.current=_,window.requestAnimationFrame(()=>{var ee;(ee=document.getElementById(_==="lan"?"ap-lan-back":"ap-lan-entry"))==null||ee.focus()}))},[_]),x.useEffect(()=>{n!=null&&n.ok&&b(!0)},[n==null?void 0:n.ok]);const hn=x.useCallback(ee=>{var Ie,ze;const Re=K.current;if(!Re||ee!=null&&Re.num!==ee)return;const Le=document.getElementById(`ap-menu-${Re.num}`);(Le!=null&&Le.contains(document.activeElement)||qN(((Ie=document.activeElement)==null?void 0:Ie.tagName)??null))&&((ze=document.getElementById(`ap-more-${Re.num}`))==null||ze.focus()),nt()},[nt]);x.useEffect(()=>{t&&(nt(),E(null))},[t,nt]),x.useEffect(()=>{H&&(n!=null&&n.accounts)&&!n.accounts.some(ee=>ee.num===H.num)&&nt(),S&&(n!=null&&n.accounts)&&!n.accounts.some(ee=>ee.num===S.num)&&E(null)},[n,H,S,nt]);const jn=async ee=>{var Le;U(!1);const Re=await ye({action:"share",account:ee},`share-${ee}`);!(Re!=null&&Re.ok)||((Le=K.current)==null?void 0:Le.num)!==ee||(D({num:ee,blob:Re.blob,expiresAt:Re.expiresAt}),B({num:ee,view:"share"}))},Ht=async(ee,Re)=>{const{commit:Le,alias:Ie}=DB(V,Re);if(Le){const ze=await ye({action:"alias",account:ee,alias:Ie},`alias-${ee}`);if(await Ge(!0),!(ze!=null&&ze.ok))return}hn(ee)},$n=async(ee,Re)=>{var ze,ht;const Le=await ye({action:"move",account:ee,slot:Re},`move-${ee}`),Ie=TB({menuFor:((ze=K.current)==null?void 0:ze.num)??null,shareFor:(F==null?void 0:F.num)??null},ee,Le);if(await Ge(!0),Ie){((ht=K.current)==null?void 0:ht.num)===ee&&nt(),W(Ie.confirmRemove),Ie.shareFor==null&&(D(null),U(!1)),de(Ie.swapNote);const Lt=Ie.swapNote;Lt&&window.setTimeout(()=>de($t=>$t===Lt?null:$t),zB),pe(null),tt(Ie.menuFor)}return Le},Yn=async(ee,Re,Le)=>{if(!Le.sends){hn(ee);return}await $n(ee,Re)},On=async(ee,Re)=>{if(Re.sends){const Le=await Je({action:"setting",key:"autoswitch.threshold",value:ee},"threshold");if(await Ge(!0),!(Le!=null&&Le.ok))return;Pe(null)}Ae(!0),window.setTimeout(()=>{var Le;document.activeElement===Qe.current&&((Le=je.current)==null||Le.focus()),Ae(!1)},HB)},En=i.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close accounts panel",title:"Close (A)",children:i.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:i.jsx("path",{d:"M3.4 3.4l7.2 7.2M10.6 3.4l-7.2 7.2"})})}),_r=ee=>{const{shown:Re,fuller:Le}=IB(ee.lanes),Ie=Ed(ee,T),ze=ee.active||Te.includes(lh(ee)),ht=ee.alias??ee.email??`account ${ee.num}`,Lt=ee.stale||(Ie==null?void 0:Ie.blocksSwitch)===!0,$t=Le?[...Re,Le]:Re,Sr=ee.fetchedAt?Fp(ee.fetchedAt,T):null;return i.jsxs("li",{className:`ap-account${ee.active?" active":""}`,"aria-current":ee.active?"true":void 0,"data-open":ze?"":void 0,"data-frozen":Lt?"":void 0,children:[!ee.active&&i.jsx("button",{type:"button",className:"ap-row-open",id:`ap-row-${ee.num}`,"aria-expanded":ze,"aria-controls":ze?`ap-detail-${ee.num}`:void 0,"aria-describedby":!ze&&!(Ie!=null&&Ie.blocksSwitch)?`ap-quota-${ee.num}`:void 0,onClick:()=>Se(kt=>OB(kt,ee)),children:i.jsxs("span",{className:"vis-hidden",children:[ht,", ",ze?"hide details":"details"]})}),i.jsxs("div",{className:"ap-account-head",children:[ee.active?i.jsx("span",{className:"ap-live",title:`Active account · slot ${ee.num}`,children:i.jsxs("span",{className:"vis-hidden",children:["Active account, slot ",ee.num,":"]})}):i.jsx("span",{className:"ap-num",children:ee.num}),ee.alias&&i.jsx("span",{className:"ap-alias",title:ee.alias,children:ee.alias}),i.jsx("span",{className:"ap-email",title:ee.email??void 0,children:ee.email}),ee.disabled&&i.jsx("span",{className:"ap-held",children:"held out"}),!ee.active&&!ee.disabled&&!(Ie!=null&&Ie.blocksSwitch)&&i.jsx("button",{type:"button",className:"ap-switch",...Me(`switch-${ee.num}`),onClick:()=>fe(ee.num,ht),"aria-label":`Switch to ${ht}`,title:`Switch to ${ee.alias??ee.email}`,children:c===`switch-${ee.num}`?"…":"Switch"}),i.jsx("button",{type:"button",id:`ap-more-${ee.num}`,className:"ap-more","aria-label":`More actions for ${ee.email??ee.alias??`account ${ee.num}`}`,"aria-haspopup":"menu","aria-expanded":P===ee.num,"aria-controls":P===ee.num?`ap-menu-${ee.num}`:void 0,title:"More actions",onClick:()=>P===ee.num?hn():Tt(ee.num),onKeyDown:kt=>{kt.key!=="ArrowDown"&&kt.key!=="ArrowUp"||(kt.preventDefault(),Tt(ee.num,kt.key==="ArrowUp"?"last":"first"))},children:i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"currentColor","aria-hidden":!0,children:[i.jsx("circle",{cx:"2.8",cy:"7",r:"1.15"}),i.jsx("circle",{cx:"7",cy:"7",r:"1.15"}),i.jsx("circle",{cx:"11.2",cy:"7",r:"1.15"})]})})]}),(h==null?void 0:h.row)===ee.num&&i.jsxs("div",{className:"ap-failure ap-row-failure",role:"alert",children:[i.jsx("span",{className:"ap-failure-text",title:h.raw||void 0,children:h.text}),i.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),ee.active&&(y==null?void 0:y.num)===ee.num&&i.jsx("p",{className:"ap-switched",children:"Now active. New sessions start on it; ones already running pick it up on their next message, up to about 30 seconds later on macOS."}),(re==null?void 0:re.at)===ee.num&&(()=>{const kt=rt.find(Us=>Us.num===re.displaced),xt=(kt==null?void 0:kt.alias)??(kt==null?void 0:kt.email)??"the account that was there";return i.jsxs("p",{className:"ap-note ap-swap-note",title:`Slot ${re.at} was taken, so the two accounts traded places: ${xt} now holds slot ${re.displaced}.`,children:["swapped with slot ",re.displaced]})})(),Ie&&i.jsxs("div",{className:"ap-issue-line",children:[i.jsxs("button",{type:"button",id:`ap-issue-${ee.num}`,className:"ap-issue","data-tone":Ie.tone,"aria-haspopup":"dialog","aria-expanded":(S==null?void 0:S.anchor)===`ap-issue-${ee.num}`,"aria-controls":(S==null?void 0:S.anchor)===`ap-issue-${ee.num}`?"ap-issue-pop":void 0,onClick:()=>Sn(ee.num,`ap-issue-${ee.num}`),children:[Ie.tone==="warn"&&i.jsx(qp,{}),i.jsx("span",{className:"ap-issue-text",children:Ie.text})]}),!ze&&i.jsx("span",{className:"ap-issue-age",title:"When claude-swap last read this account's usage",children:Sr??"never collected"})]}),!ze&&!(Ie!=null&&Ie.blocksSwitch)&&i.jsxs("p",{className:"ap-quota",id:`ap-quota-${ee.num}`,children:[$t.length?$t.map(kt=>i.jsxs("span",{className:"ap-q",children:[i.jsx("span",{className:"ap-q-label",children:kt.label})," ",i.jsxs("span",{className:"ap-q-pct","data-level":Lt?void 0:YB(kt.pct),children:[Math.round(kt.pct),"%"]})]},kt.id)):i.jsx("span",{className:"ap-q-label",children:"no usage recorded yet"}),ee.stale&&!Ie&&i.jsx("span",{className:"ap-q-age","data-never":Sr?void 0:"",title:"When claude-swap last read this account's usage",children:Sr??"never collected"})]}),ze&&i.jsxs("div",{className:"ap-detail",id:`ap-detail-${ee.num}`,children:[i.jsx("div",{className:"ap-lanes",children:ee.lanes.length?ee.lanes.map(kt=>i.jsx(ZB,{lane:kt,nowSec:T,frozen:Lt},kt.id)):i.jsx("div",{className:"ap-hint",children:"No usage recorded yet."})}),i.jsx("div",{className:"ap-meta",children:ee.fetchedAt?i.jsxs("span",{className:`ap-age${ee.stale&&!Ie?" ap-stale":""}`,title:"When claude-swap last read this account's usage, and when it plans to read it again. It sets that interval itself — 3 minutes at the fastest, wider while an account is recovering from a rate limit — and every surface, including `cswap watch`, follows the same plan.",children:["collected ",Fp(ee.fetchedAt,T),Ie!=null&&Ie.blocksSwitch?"":UB(ee.nextAt,T)]}):i.jsx("span",{className:"ap-age ap-stale",title:"claude-swap has not read this account yet",children:"never collected"})})]})]},ee.num)},Kr=n!=null&&n.ok&&(a!=null&&a.ok)?i.jsxs("div",{className:"ap-policy-block",children:[i.jsxs("div",{className:"ap-policy",children:[i.jsx("h3",{className:"ap-auto-title",children:"Auto-switch"}),i.jsx("span",{className:"ap-field",title:"Switch once the active account passes this much of its limit",children:i.jsx("select",{ref:je,"aria-label":"Switch threshold",value:Ve,...Me("threshold"),onChange:ee=>Pe(ee.target.value),children:XB(Ce).map(ee=>i.jsxs("option",{value:ee,children:[ee,"%"]},ee))})}),(ce.sends||$e)&&i.jsx("button",{ref:Qe,type:"button",className:"ap-manage-btn",...Me("threshold"),title:ce.title,onClick:()=>On(Ve,ce),children:$e&&!ce.sends?ce.done:ce.label}),i.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":a.enabled,"aria-label":"Auto-switch",...Me("enable"),onClick:()=>Je({action:"enable",enabled:!a.enabled},"enable").then(()=>Ge(!0)),title:a.enabled?"Stop switching accounts automatically":"Switch accounts automatically when the active one nears its limit",children:i.jsx("span",{className:"switch-knob"})})]}),a.external&&i.jsxs("p",{className:"ap-auto-note",children:[i.jsx("i",{className:"ap-pulse","aria-hidden":!0})," A ",i.jsx("code",{children:"cswap auto"})," loop in your terminal is doing the switching. The deck stands down while it runs",a.enabled?" — this toggle takes over when you stop it.":"."]})]}):null;return i.jsxs("aside",{className:`accounts-panel${t?" leaving":""}`,id:"accounts-panel","aria-label":"Claude accounts",children:[_==="accounts"&&i.jsxs("div",{className:"ap-header",children:[i.jsx("h2",{children:"Claude accounts"}),i.jsxs("div",{className:"ap-header-right",children:[i.jsx("button",{type:"button",className:"glyph-btn ap-add",onClick:()=>Z(!0),"aria-label":"Add an account",title:"Sign in to another Claude account, or paste one shared from another deck",children:i.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:i.jsx("path",{d:"M7 2.2v9.6M2.2 7h9.6"})})}),(((yn=n==null?void 0:n.accounts)==null?void 0:yn.length)??0)>0&&i.jsx("button",{type:"button",className:"glyph-btn",onClick:()=>z(!0),"aria-label":"Share accounts with another deck",title:`Copy several accounts to another ${nn} in one paste. The text carries a live login for each one — treat it as those passwords.`,children:i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M3.3 10.7L10.7 3.3"}),i.jsx("path",{d:"M5.5 3.3h5.2v5.2"})]})}),i.jsx("button",{type:"button",className:"glyph-btn ap-refresh",onClick:()=>Ge(!0),...Me("reload",f),"aria-label":"Reload accounts",title:"Reload from claude-swap",children:i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M11.6 6.2A4.8 4.8 0 1 0 11 9.6"}),i.jsx("path",{d:"M11.9 2.6v3.7h-3.6"})]})}),En]})]}),_==="accounts"&&i.jsx("div",{className:"ap-scroll",id:"ap-scroll",children:n==null?h?i.jsxs("div",{className:"ap-empty",role:"alert",children:[i.jsx("span",{title:h.raw||void 0,children:h.text}),i.jsxs("span",{className:"ap-hint",children:["No accounts have arrived, so there is nothing to show yet. The panel keeps trying every ",c_/1e3," seconds."]}),i.jsx("button",{type:"button",className:"ap-fix",disabled:f,onClick:()=>Ge(!0),children:f?"trying…":"try again"})]}):i.jsx("div",{className:"ap-empty",children:"Checking…"}):n.ok?i.jsxs(i.Fragment,{children:[at&&(ut==null?void 0:ut.tone)==="warn"&&i.jsxs("div",{className:"ap-notice",children:[i.jsxs("button",{type:"button",id:"ap-notice",className:"ap-issue","data-tone":"warn","aria-haspopup":"dialog","aria-expanded":(S==null?void 0:S.anchor)==="ap-notice","aria-controls":(S==null?void 0:S.anchor)==="ap-notice"?"ap-issue-pop":void 0,onClick:()=>Sn(at.num,"ap-notice"),children:[i.jsx(qp,{}),i.jsx("span",{className:"ap-issue-text",children:"Current account needs attention"})]}),ut.fix&&i.jsx("button",{type:"button",className:"ap-notice-fix",onClick:()=>Z(!0),title:"Open the sign-in dialog. Signing in as this account replaces its stored login in place.",children:"Sign in"})]}),i.jsx("ul",{className:"ap-list",children:jt.map(_r)}),st.length>0&&i.jsx(_B,{peers:vt,strained:_n,armed:Et,threshold:a!=null&&a.ok?Ce:null,open:We,onToggle:()=>dt(ee=>!ee)}),st.length>0&&We&&i.jsxs("div",{className:"ap-rest-panel",id:"ap-rest-panel",children:[i.jsx("ul",{className:"ap-list ap-others",id:"ap-rest-list",children:st.map(_r)}),Kr]}),st.length===0&&Kr,h&&h.row==null&&i.jsxs("div",{className:"ap-failure",role:"alert",children:[i.jsx("span",{className:"ap-failure-text",title:h.raw||void 0,children:h.text}),i.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),H&&(()=>{var Ie;const ee=(Ie=n.accounts)==null?void 0:Ie.find(ze=>ze.num===H.num);if(!ee)return null;const Re=`ap-pop-title-${ee.num}`,Le=X&&i.jsx("p",{className:"ap-pop-error",role:"alert",title:X.raw||void 0,children:X.text});return i.jsxs(Dx,{anchorId:`ap-more-${ee.num}`,boundaryId:zt(ee.num),id:`ap-menu-${ee.num}`,className:"ap-pop",role:H.view==="menu"?"menu":"dialog",labelledBy:H.view==="menu"?`ap-more-${ee.num}`:Re,start:H.start,onClose:nt,children:[H.view==="menu"&&i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{I(ee.alias??""),J(null),B({num:ee.num,view:"rename"})},children:"Rename"}),i.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{pe(null),J(null),B({num:ee.num,view:"move"})},children:"Move to slot…"}),i.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",...Me(`share-${ee.num}`),title:`Copy this account to another ${nn}. Anyone who has the text can use the account — treat it as the password. The other deck stops accepting it after 10 minutes; that does not make an escaped copy safe.`,onClick:()=>jn(ee.num),children:c===`share-${ee.num}`?"Sharing…":"Share"}),(((a==null?void 0:a.enabled)||(a==null?void 0:a.external))&&!ee.active||ee.disabled)&&i.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",...Me(`rot-${ee.num}`),title:ee.disabled?"Return this account to auto-rotation":"Hold this account out of auto-rotation",onClick:()=>Je({action:"account",account:ee.num,enabled:ee.disabled},`rot-${ee.num}`,"menu").then(ze=>{Ge(!0),ze!=null&&ze.ok&&hn(ee.num)}),children:ee.disabled?"Put back in rotation":"Hold out of rotation"}),i.jsx("div",{role:"separator",className:"ap-menu-sep"}),i.jsx("button",{type:"button",role:"menuitem",className:`ap-menu-item danger${q===ee.num?" armed":""}`,...Me(`rm-${ee.num}`),"aria-label":q===ee.num?"Confirm remove":void 0,title:q===ee.num?"This deletes the stored credentials for this account":"Remove this account from claude-swap",onClick:()=>{if(q!==ee.num){W(ee.num),G.current=Date.now(),window.setTimeout(()=>W(ze=>ze===ee.num?null:ze),4e3);return}Date.now()-G.current<oh||(W(null),ye({action:"remove",account:ee.num},`rm-${ee.num}`).then(ze=>{var ht;Ge(!0),ze!=null&&ze.ok&&(((ht=K.current)==null?void 0:ht.num)===ee.num&&nt(),tt(null))}))},children:c===`rm-${ee.num}`?"Removing…":q===ee.num?"Confirm":"Remove"}),Le]}),H.view==="rename"&&i.jsxs("form",{className:"ap-pop-form",onSubmit:ze=>{ze.preventDefault(),Ht(ee.num,ee.alias)},children:[i.jsx("label",{className:"ap-pop-title",id:Re,htmlFor:`ap-alias-${ee.num}`,children:"Rename account"}),i.jsx("input",{id:`ap-alias-${ee.num}`,className:"ap-manage-input",type:"text",value:V,onChange:ze=>I(ze.target.value),maxLength:LB,placeholder:"e.g. work",spellCheck:!1,autoComplete:"off",autoFocus:!0,onFocus:ze=>ze.currentTarget.select()}),Le,i.jsxs("div",{className:"ap-pop-actions",children:[i.jsx("button",{type:"button",className:"btn",onClick:()=>hn(),children:"Cancel"}),i.jsx("button",{type:"submit",className:"btn primary",...Me(`alias-${ee.num}`),title:"A short name to show instead of the email",children:c===`alias-${ee.num}`?"…":"Save"})]})]}),H.view==="move"&&(()=>{const ze=CB((n.accounts??[]).map($t=>$t.num),ee.num),ht=AB(ze,ge,ee.num),Lt=RB(ze,ht,ee.num);return i.jsxs("div",{className:"ap-pop-form",children:[i.jsx("label",{className:"ap-pop-title",id:Re,htmlFor:`ap-slot-${ee.num}`,children:"Move to slot"}),i.jsx("span",{className:"ap-field",children:i.jsx("select",{id:`ap-slot-${ee.num}`,value:String(ht),...Me(`move-${ee.num}`),onChange:$t=>pe(Number($t.target.value)),autoFocus:!0,children:ze.map($t=>i.jsx("option",{value:$t.slot,children:$t.label},$t.slot))})}),Le,i.jsxs("div",{className:"ap-pop-actions",children:[i.jsx("button",{type:"button",className:"btn",onClick:()=>hn(),children:"Cancel"}),i.jsx("button",{type:"button",className:"btn primary",...Me(`move-${ee.num}`),title:Lt.title,onClick:()=>Yn(ee.num,ht,Lt),children:c===`move-${ee.num}`?"…":wc(Lt.label)})]})]})})(),H.view==="share"&&(F==null?void 0:F.num)===ee.num&&(()=>{const ze=OR(F.expiresAt,T),ht=ze.tone==="gone";return i.jsxs("div",{className:`ap-pop-form ap-share${ht?" expired":""}`,children:[i.jsx("p",{className:"ap-pop-title",id:Re,children:"Share account"}),i.jsx("code",{className:"ap-share-blob",children:F.blob}),i.jsxs("p",{className:"ap-pop-note",title:"This text is the account's password. It is base64 of plain JSON — the expiry inside it is not signed, so anyone holding a copy can change it, and the login itself is in there in the clear either way. The countdown only says how long another deck's import dialog will still accept it. If a copy escapes, sign the account out and back in.",children:[i.jsx("span",{className:"ap-share-warn",children:"This is the password"})," · ",i.jsx("span",{className:`ap-share-expiry ${ze.tone}`,children:ze.text})]}),Le,i.jsxs("div",{className:"ap-pop-actions",children:[i.jsx("button",{type:"button",className:"btn",onClick:()=>hn(),children:"Done"}),i.jsx("button",{type:"button",className:"btn primary",...Me(`share-${ee.num}`),autoFocus:!0,onClick:async()=>{if(ht){await jn(ee.num);return}await u_(F.blob)&&(U(!0),window.setTimeout(()=>U(!1),1800))},children:ht?"Make a new share":Q?"Copied":"Copy"})]})]})})()]})})(),S&&(()=>{var Le;const ee=(Le=n.accounts)==null?void 0:Le.find(Ie=>Ie.num===S.num),Re=ee?Ed(ee,T):null;return!ee||!Re?null:i.jsx(Dx,{anchorId:S.anchor,boundaryId:S.anchor==="ap-notice"?"ap-scroll":zt(ee.num),id:"ap-issue-pop",className:"ap-pop ap-issue-pop",role:"dialog",labelledBy:"ap-issue-title",onClose:()=>dn(),children:i.jsxs("div",{className:"ap-pop-form",children:[i.jsxs("p",{className:"ap-pop-title ap-issue-title",id:"ap-issue-title","data-tone":Re.tone,children:[Re.tone==="warn"&&i.jsx(qp,{}),Re.text]}),i.jsx("p",{className:"ap-pop-note ap-issue-hint",children:Re.hint}),i.jsxs("p",{className:"ap-pop-note ap-issue-when",children:[i.jsx("span",{className:"ap-issue-who",children:ee.alias??ee.email??`account ${ee.num}`})," · ",ee.fetchedAt?`last collected ${Fp(ee.fetchedAt,T)}`:"never collected"]}),i.jsxs("div",{className:"ap-pop-actions",children:[i.jsx("button",{type:"button",className:"btn",onClick:()=>dn(!0),children:"Done"}),Re.fix&&i.jsx("button",{type:"button",className:"btn primary",onClick:()=>{dn(!0),Z(!0)},title:"Open the sign-in dialog. Signing in as this account puts its login back in this slot — it keeps its slot, its alias and its history.",children:Re.fix})]})]})})})()]}):i.jsx("div",{className:"ap-empty",children:n.reason==="no_cswap"?i.jsxs(i.Fragment,{children:[i.jsx("span",{children:"claude-swap isn't installed."}),i.jsx("span",{className:"ap-hint",children:"This panel reads the account store claude-swap keeps — without it there is nothing to show. It is a separate tool, published on PyPI, so it does not come with this package."}),n.hint&&i.jsx("code",{className:"ap-cmd",children:n.hint}),i.jsxs("span",{className:"ap-hint",children:["Then add an account with the ",i.jsx("strong",{children:"+"})," button above."]})]}):n.reason==="no_accounts"?i.jsxs(i.Fragment,{children:[i.jsx("span",{children:"No accounts added yet."}),i.jsxs("span",{className:"ap-hint",children:["claude-swap is installed but has nothing in its store. Use the ",i.jsx("strong",{children:"+"})," above to sign one in, or to paste one shared from another deck."]})]}):i.jsxs(i.Fragment,{children:[i.jsx("span",{children:"Couldn't read the account store."}),i.jsxs("span",{className:"ap-hint",children:["claude-swap is installed, but its store could not be read",n.reason?` (${n.reason})`:"","."]})]})})}),i.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:y?`Now active: ${y.name}`:""}),j&&i.jsx(kB,{accounts:((n==null?void 0:n.accounts)??[]).map(ee=>({key:`${String(ee.email??"").trim().toLowerCase()}@@${ee.orgUuid??""}`,email:ee.email??"",alive:ee.alive===!0})),onChanged:()=>Ge(!0),view:_==="lan",onOpen:ir,onBack:()=>N("accounts"),closeButton:En}),M&&i.jsx(x8,{onClose:()=>Z(!1),onChanged:()=>Ge(!0)}),ae&&i.jsx(EB,{accounts:((n==null?void 0:n.accounts)??[]).map(ee=>({num:ee.num,email:ee.email,alias:ee.alias,org:ee.org})),onClose:()=>z(!1),copyText:u_})]})}const JB=3e4;function ez({bundle:e,running:t,lastTried:n}){return!t||e===t?!1:n!==t}function tz({bundle:e,running:t,pending:n,lastTried:r}){return t?ez({bundle:e,running:t,lastTried:r})?"reload":n==null||n&&n!==t?"wait":"confirm":"wait"}function nz(e){return!e||e.state!=="failed"?null:`${typeof e.at=="number"?e.at:0}:${e.error??""}`}function rz({asked:e,reported:t}){return t?t!==e:!1}function WR(e){const t=e.thresholdMs??JB;return!e.enabled||e.kind!=="restart"||!e.canRestart||!e.noticeOpen||!e.visible||e.busy?null:e.idleSince==null||e.now<e.idleSince?t:Math.max(0,t-(e.now-e.idleSince))}function sz(e){const t=Math.max(0,Math.ceil(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function az(e,t){return e?t==null?"auto when idle":`auto in ${sz(t)}`:"auto-restart off"}function d_(e){let t=0;for(const n of e)n.state==="active"&&t++;return t}function oz(e){return e<=0?{label:"Restart now",clause:"nothing is running"}:{label:"Restart anyway",clause:`${e===1?"1 agent is running":`${e} agents are running`} — their events during the restart are lost`}}function iz(e){const t=WR(e);return t==null?{idleSince:null,restart:!1,remainingMs:null}:e.idleSince==null||e.now<e.idleSince?{idleSince:e.now,restart:!1,remainingMs:t}:{idleSince:e.idleSince,restart:t===0,remainingMs:t}}function lz(e,t){return e==="confirmation"?t.confirmOpen?"clear":"ignore":t.modalOpen||t.confirmOpen?"ignore":"confirm"}function cz(e){if(!e||typeof e!="object")return null;const t=e;if(typeof t.decks!="number"||typeof t.mine!="boolean")return null;const n=t.owner&&typeof t.owner=="object"?t.owner.port:null;return{path:typeof t.path=="string"&&t.path!==""?t.path:null,decks:t.decks,mine:t.mine,ownerPort:typeof n=="number"?n:null}}function uz(e){return e<=0?null:e===1?"the one agent":`all ${e} agents`}function dz(e,t){const n=uz(e),r=(...c)=>[n?`${n} on the canvas`:null,...c,"layout, pins and selection"].filter(u=>u!==null),a="This cannot be undone.";if(!t)return{goes:r("the event log on disk — the file a restarted deck replays to rebuild what you see, and the file every deck on this machine shares unless one was told otherwise"),stays:[],final:a,confirm:"Clear everything"};if(!t.path)return{goes:r(),stays:[],final:`This deck keeps no event log, so nothing on disk changes — and nothing can bring the canvas back. ${a}`,confirm:"Clear everything"};if(!t.mine){const c=t.ownerPort===null?"another running deck owns that file":`the deck on port ${t.ownerPort} owns that file`,u=t.decks>2?`, one of ${t.decks} decks sharing it`:"";return{goes:r(),stays:[`the event log — ${c}${u}`,"restart this deck and the log replays back onto it"],final:null,confirm:"Clear this canvas"}}if(t.decks<=1)return{goes:r("this deck's event log — the file a restarted deck replays to rebuild what you see"),stays:[],final:a,confirm:"Clear everything"};const l=t.decks-1;return{goes:r(`the event log ${l===1?"1 other running deck shares":`${l} other running decks share`} with this one — every session recorded in it, not just the ones drawn here`),stays:[l===1?"what that deck shows, until it restarts — then it is gone there too":"what those decks show, until they restart — then it is gone there too"],final:a,confirm:"Clear everything"}}function hz({agentCount:e,onConfirm:t,onCancel:n}){const r=x.useRef(null),a=un(n,{focusRef:r,layer:x6}),[l,c]=x.useState(null);x.useEffect(()=>{let m=!1;return fetch("/api/clear").then(y=>y.ok?y.json():null).then(y=>{m||c(cz(y))}).catch(()=>{}),()=>{m=!0}},[]);const{goes:u,stays:f,final:p,confirm:h}=dz(e,l);return i.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:i.jsxs("div",{ref:a,className:"modal clear-confirm",onClick:m=>m.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"clear-confirm-title",children:[i.jsxs("header",{className:"modal-head",children:[i.jsxs("div",{className:"modal-title",children:[i.jsx("span",{className:"status-dot err","aria-hidden":!0}),i.jsx("span",{id:"clear-confirm-title",className:"modal-tool-name",children:"Clear the deck?"})]}),i.jsx("div",{className:"modal-actions",children:i.jsx("button",{type:"button",className:"glyph-btn",onClick:n,"aria-label":"Cancel (Esc)",title:"Cancel (Esc)",children:"×"})})]}),i.jsxs("section",{className:"modal-body",children:[i.jsxs("dl",{className:"cc-plan",children:[i.jsx("dt",{children:"Goes"}),i.jsx("dd",{children:u.map(m=>i.jsx("span",{children:m},m))}),i.jsx("dt",{children:"Stays"}),i.jsx("dd",{children:f.length>0?f.map(m=>i.jsx("span",{children:m},m)):i.jsx("span",{children:"nothing"})})]}),p&&i.jsx("p",{className:"cc-final",children:p}),i.jsxs("div",{className:"cc-actions",children:[i.jsx("button",{type:"button",ref:r,className:"btn",onClick:n,children:"Cancel"}),i.jsx("button",{type:"button",className:"btn danger",onClick:t,children:h})]})]})]})})}const fz="Press Esc first if a key does nothing.",pz=[{title:"Canvas",rows:[{cap:"Space",action:"pause or resume the stream",binds:[" "]},{cap:"J",action:"next agent",binds:["j","J"]},{cap:"K",action:"previous agent",binds:["k","K"]},{cap:"W",action:"the session waiting on you — oldest first, again for the next",binds:["w","W"]},{cap:"F",action:"fit every agent on screen",binds:["f","F"]},{cap:"Z",action:"zoom to the selected agent and its session",binds:["z","Z"]},{cap:"R",action:"re-arrange the canvas and drop the pins",binds:["r","R"]},{cap:"C",action:"clear the canvas and the event log — asks first",binds:["c","C"]}]},{title:"Panels and dialogs",rows:[{cap:"U",action:"usage panel",binds:["u","U"]},{cap:"L",action:"session list",binds:["l","L"]},{cap:"D",action:"detail panel",binds:["d","D"]},{cap:"H",action:"usage history",binds:["h","H"]},{cap:"A",action:"Claude accounts, where Claude Code is installed",binds:["a","A"]},{cap:"S",action:"this machine — cores, memory, temperature",binds:["s","S"]},{cap:"B",action:"Browser Watch",binds:["b","B"]},{cap:"V",action:"the sound menu — volume, tones, notifications",binds:["v","V"]},{cap:"?",action:"this sheet",binds:["?"]}]},{title:"Settings",rows:[{cap:"M",action:"sound on or off",binds:["m","M"]},{cap:"T",action:"light or dark theme",binds:["t","T"]}]},{title:"Focus and selection",rows:[{cap:"Tab",action:"reach the agent cards",binds:[]},{cap:"Enter",action:"select the focused card",binds:["Enter"]},{cap:"Shift + Enter",action:"add the focused card to the selection",binds:["Enter"]},{cap:"Esc",action:"close what is open, deselect, release focus",binds:["Escape"]}]},{title:"Mouse",rows:[{cap:"drag",action:"move a node, and pin it where you dropped it",binds:[]},{cap:"shift-click",action:"add an agent to the selection",binds:[]},{cap:"click",action:"a card: go to it and its session",binds:[]},{cap:"double-click",action:"a card: its prompt, every tool call, tokens and timing",binds:[]},{cap:"hover",action:"zoomed out, a card's name, state and numbers",binds:[]},{cap:"click",action:"the topbar speaker opens volume and sound settings",binds:[]}]}];function mz({onClose:e,onTour:t}){const n=un(e);return i.jsx("div",{className:"modal-backdrop",onClick:e,role:"presentation",children:i.jsxs("div",{ref:n,className:"modal key-help",onClick:r=>r.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"key-help-title",children:[i.jsxs("header",{className:"modal-head",children:[i.jsx("div",{className:"modal-title",children:i.jsx("span",{id:"key-help-title",className:"modal-tool-name",children:"Keyboard shortcuts"})}),i.jsx("div",{className:"modal-actions",children:i.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),i.jsxs("section",{className:"modal-body",children:[t&&i.jsxs("div",{className:"guide-door",children:[i.jsx("span",{children:"Eight pictures of what the deck shows."}),i.jsx("button",{type:"button",className:"btn",onClick:t,children:"Take the tour"})]}),i.jsx("div",{className:"shortcuts",children:pz.map(r=>i.jsxs(x.Fragment,{children:[i.jsx("h3",{className:"kh-group",children:r.title}),r.rows.map(a=>i.jsxs("div",{className:"sc",children:[i.jsx("kbd",{children:a.cap}),i.jsx("span",{children:a.action})]},`${r.title}:${a.cap}:${a.action}`))]},r.title))}),i.jsx("p",{className:"kh-foot",children:fz})]})]})})}const gz=["done","needs-input"],yz=[{id:"two",label:"Two notes",notes:[{at:0,hz:740,ms:90},{at:.085,hz:440,ms:150}]},{id:"arc",label:"Descent",notes:[{at:0,hz:988,ms:80},{at:.07,hz:659,ms:80},{at:.14,hz:440,ms:160}]},{id:"tap",label:"Double tap",notes:[{at:0,hz:740,ms:55},{at:.055,hz:740,ms:55},{at:.165,hz:440,ms:150}]},{id:"chord",label:"Chord",trim:.7,notes:[{at:0,hz:988,ms:110},{at:0,hz:740,ms:110},{at:.1,hz:440,ms:170}]},{id:"bell",label:"Bell",type:"triangle",notes:[{at:0,hz:740,ms:120},{at:.11,hz:440,ms:260}]},{id:"blip",label:"Blip",type:"square",trim:.7,notes:[{at:0,hz:740,ms:55},{at:.06,hz:440,ms:90}]}],wz=[{id:"two",label:"Two notes",notes:[{at:0,hz:440,ms:90},{at:.085,hz:740,ms:150}]},{id:"arc",label:"Ascent",notes:[{at:0,hz:440,ms:80},{at:.07,hz:659,ms:80},{at:.14,hz:988,ms:160}]},{id:"tap",label:"Double tap",notes:[{at:0,hz:440,ms:55},{at:.055,hz:440,ms:55},{at:.165,hz:740,ms:150}]},{id:"chord",label:"Chord",trim:.7,notes:[{at:0,hz:440,ms:110},{at:.1,hz:740,ms:170},{at:.1,hz:988,ms:170}]},{id:"bell",label:"Bell",type:"triangle",notes:[{at:0,hz:440,ms:120},{at:.11,hz:740,ms:260}]},{id:"blip",label:"Blip",type:"square",trim:.7,notes:[{at:0,hz:440,ms:55},{at:.06,hz:740,ms:90}]}],B0={done:yz,"needs-input":wz},al="two";function Wx(e,t){const n=B0[e];return n.find(r=>r.id===t)??n.find(r=>r.id===al)??n[0]}function UR(e,t){return B0[e].some(r=>r.id===t)?t:al}Wx("done",al).notes,Wx("needs-input",al).notes;const h_=.04,vz=.24,Hd=0,ch=100,Ux=5,Dc=50;function Fc(e){if(!Number.isFinite(e))return Dc;const t=Math.round(e/Ux)*Ux;return Math.min(ch,Math.max(Hd,t))}function xz(e){if(e==null)return Dc;const t=e.trim();return/^-?\d+(\.\d+)?$/.test(t)?Fc(Number(t)):Dc}function bz(e){const t=Fc(e),n=h_+(vz-h_)*(t/ch);return Math.round(n*1e4)/1e4}function kz(e,t){const n=t.trim,r=typeof n=="number"&&Number.isFinite(n)&&n>0&&n<=1?n:1;return Math.round(bz(e)*r*1e4)/1e4}const Nz=160,_z="agent-dag.soundLevel.done",Sz="agent-dag.soundLevel.needs-input",jz="agent-dag.soundFigure.done",Ez="agent-dag.soundFigure.needs-input",VR={done:_z,"needs-input":Sz},GR={done:jz,"needs-input":Ez},Vx={done:{level:Dc,figure:al},"needs-input":{level:Dc,figure:al}};function Cz(e){const t=n=>({level:xz(e(VR[n])),figure:UR(n,e(GR[n]))});return{done:t("done"),"needs-input":t("needs-input")}}const f_={Stop:"done",Notification:"needs-input"};function Tz(e,t){var r;if(t)return null;const n=(r=e==null?void 0:e.payload)==null?void 0:r.hook_event_name;return typeof n!="string"?null:Object.hasOwn(f_,n)?f_[n]:null}function Az(e={enabled:()=>!0}){const t=e.ctor??(typeof window<"u"?window.AudioContext??window.webkitAudioContext??null:null);let n=null,r=!1;const a=()=>e.enabled()?r&&(n==null?void 0:n.state)==="running"?"ready":"locked":"off",l=()=>{var f;return(f=e.onState)==null?void 0:f.call(e,a())};function c(){var f;if(!(!t||r))try{n=n??new t,(f=n.resume)==null||f.call(n).then(l,()=>{}),r=!0,l()}catch{}}function u(f,p=!1){var _;if(!p&&!e.enabled()||!n||n.state!=="running")return!1;const h=(((_=e.prefs)==null?void 0:_.call(e))??Vx)[f]??Vx[f],m=Wx(f,h.figure),y=kz(h.level,m),w=n.currentTime;for(const N of m.notes){const j=n.createOscillator(),b=n.createGain();j.type=m.type??"sine",j.frequency.value=N.hz;const S=w+N.at,E=S+N.ms/1e3;b.gain.setValueAtTime(1e-4,S),b.gain.exponentialRampToValueAtTime(y,S+.012),b.gain.exponentialRampToValueAtTime(1e-4,E),j.connect(b).connect(n.destination),j.start(S),j.stop(E+.02)}return!0}return{unlock:c,play:u,state:a,get context(){return n}}}const Rz="With no deck tab open, get a notification wherever a sound would have played.",Mz="With the ccdeck window closed, get a notification wherever a sound would have played.";function Iz(e){return e?Mz:Rz}const $z="Held off for this run — the deck was started with alerts disabled. Your choice is saved for the next start.",p_="Get notified when you're away from this tab.";function Oz(e){switch(e){case"granted":return{status:"Enabled",ask:!1,ok:!0,note:p_};case"default":return{status:null,ask:!0,ok:!1,note:p_};case"denied":return{status:"Blocked",ask:!1,ok:!1,note:"Your browser is blocking them; only its own site settings can undo that. You'll still be told once this tab is closed."};default:return{status:"Unavailable",ask:!1,ok:!1,note:"This browser cannot show them. You'll still be told once this tab is closed."}}}function Pz(e=typeof navigator>"u"?"":navigator.userAgent){return/\bccdeck-desktop\/\d/.test(e)}const m_={done:"Turn finished","needs-input":"Claude is asking"},Lz={done:"Plays when Claude or Codex finishes a turn.","needs-input":"Available in Claude Code only."};function Dz({onClose:e,soundOn:t,onToggleSound:n,prefs:r,onLevel:a,onFigure:l,onPreview:c,openerRef:u,notifyOn:f,onToggleNotify:p,notifyVetoed:h,notifyPermission:m,onAskNotify:y}){const w=Oz(m),_=Pz(),N=f&&!h&&!_,j=un(e),b=x.useRef(e);return b.current=e,x.useEffect(()=>{const S=E=>{var T,R;const C=E.target;C&&((T=j.current)!=null&&T.contains(C)||(R=u.current)!=null&&R.contains(C)||b.current())};return window.addEventListener("pointerdown",S,!0),()=>window.removeEventListener("pointerdown",S,!0)},[j,u]),i.jsxs("div",{ref:j,id:"sound-menu",className:"sound-menu",role:"dialog","aria-label":"Sound settings",children:[i.jsxs("div",{className:"sm-switches",children:[i.jsxs("label",{className:"sm-switch",children:[i.jsx("span",{className:"sm-switch-label",id:"sm-sound-label",children:"Sounds"}),i.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-labelledby":"sm-sound-label",className:"switch",onClick:n,title:"A tone when a turn finishes, and when Claude asks for something",children:i.jsx("span",{className:"switch-knob"})})]}),i.jsxs("div",{className:"sm-setting",children:[i.jsxs("label",{className:"sm-switch",children:[i.jsx("span",{className:"sm-switch-label",id:"sm-notify-label",children:"Notifications while closed"}),i.jsx("button",{type:"button",role:"switch","aria-checked":f,"aria-labelledby":"sm-notify-label",className:"switch",onClick:p,title:"With no deck tab open, a notification wherever a sound would play",children:i.jsx("span",{className:"switch-knob"})})]}),i.jsx("p",{className:"sm-note",children:h?$z:Iz(_)})]})]}),N&&i.jsxs("section",{className:"sm-channel","aria-labelledby":"sm-channel-name",children:[i.jsxs("div",{className:"sm-channel-head",children:[i.jsx("h3",{className:"sm-channel-name",id:"sm-channel-name",children:"Browser notifications"}),w.ask?i.jsx("button",{type:"button",className:"btn sm-channel-action",onClick:y,children:"Enable"}):i.jsxs("span",{className:"sm-channel-state","data-ok":w.ok||void 0,children:[w.ok&&i.jsx("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:i.jsx("path",{d:"M1.5 5.2 3.9 7.6 8.5 2.4"})}),w.status]})]}),i.jsx("p",{className:"sm-note",children:w.note})]}),!t&&i.jsx("span",{id:"sm-preview-note",className:"vis-hidden",children:"Plays even when Sounds is off, so you can set a tone before turning sounds back on."}),i.jsx("div",{className:"sm-tones",children:gz.map(S=>{const E=r[S],C=`sm-level-${S}`,T=`sm-figure-${S}`;return i.jsxs("section",{className:"sm-tone","aria-labelledby":`sm-name-${S}`,children:[i.jsxs("div",{className:"sm-tone-head",children:[i.jsx("h3",{className:"sm-tone-name",id:`sm-name-${S}`,children:m_[S]}),i.jsxs("button",{type:"button",className:"btn sm-hear",onClick:()=>c(S),"aria-label":`Hear the ${m_[S].toLowerCase()} tone`,title:t?"Play this tone now, at what it is set to":"Plays even when Sounds is off","aria-describedby":t?void 0:"sm-preview-note",children:[i.jsx("svg",{width:"11",height:"11",viewBox:"0 0 12 12",fill:"currentColor","aria-hidden":!0,children:i.jsx("path",{d:"M3 1.6v8.8l7-4.4z"})}),"Hear it"]})]}),i.jsxs("div",{className:"sm-row",children:[i.jsx("label",{htmlFor:C,children:"Volume"}),i.jsx("input",{id:C,type:"range",min:Hd,max:ch,step:Ux,value:E.level,onChange:R=>a(S,Number(R.target.value)),style:{"--sm-level":`${(E.level-Hd)/(ch-Hd)*100}%`}}),i.jsxs("span",{className:"sm-read",children:[E.level,"%"]})]}),i.jsxs("div",{className:"sm-row",children:[i.jsx("label",{htmlFor:T,children:"Tone"}),i.jsx("select",{id:T,className:"sm-select",value:E.figure,onChange:R=>l(S,R.target.value),children:B0[S].map(R=>i.jsx("option",{value:R.id,children:R.label},R.id))})]}),i.jsx("p",{className:"sm-note",children:Lz[S]})]},S)})}),i.jsxs("p",{className:"sm-foot",children:[i.jsx("kbd",{children:"M"}),"Mute or unmute sounds anywhere."]})]})}const Di=["light","dark"],Fz={light:"Light",dark:"Dark"};function qz({theme:e}){return i.jsx("span",{className:"appearance-preview","data-swatch":e,children:i.jsxs("svg",{viewBox:"0 0 112 56","aria-hidden":!0,focusable:"false",children:[i.jsx("rect",{className:"tp-canvas",width:"112",height:"56"}),i.jsx("rect",{className:"tp-surface",width:"112",height:"7"}),i.jsx("rect",{className:"tp-rule",y:"7",width:"112",height:"1"}),i.jsx("rect",{className:"tp-surface",y:"8",width:"25",height:"48"}),i.jsx("rect",{className:"tp-rule",x:"25",y:"8",width:"1",height:"48"}),i.jsx("rect",{className:"tp-card",x:"36.5",y:"27.5",width:"28",height:"14",rx:"2.5"}),i.jsx("rect",{className:"tp-tag",x:"39.5",y:"25.5",width:"13",height:"4",rx:"2"}),i.jsx("rect",{className:"tp-card",x:"76.5",y:"14.5",width:"29",height:"20",rx:"2.5"}),i.jsx("rect",{className:"tp-rule",x:"81",y:"23",width:"20",height:"2",rx:"1"}),i.jsx("rect",{className:"tp-accent",x:"81",y:"23",width:"12",height:"2",rx:"1"})]})})}function Bz({theme:e,onTheme:t,characterEnabled:n,onToggleCharacter:r,onClose:a,openerRef:l}){const c=un(a),u=x.useRef(a);u.current=a,x.useEffect(()=>{const h=m=>{var w,_;const y=m.target;!y||(w=c.current)!=null&&w.contains(y)||(_=l.current)!=null&&_.contains(y)||u.current()};return window.addEventListener("pointerdown",h,!0),()=>window.removeEventListener("pointerdown",h,!0)},[c,l]);const f=h=>{var w;if(!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(h.key))return;h.preventDefault();const y=(Di.indexOf(e)+(h.key==="ArrowLeft"||h.key==="ArrowUp"?-1:1)+Di.length)%Di.length;t(Di[y]),(w=h.currentTarget.querySelectorAll('[role="radio"]')[y])==null||w.focus()},p=h=>{var y;if(h.key===" "){h.stopPropagation();return}if(h.key!=="t"&&h.key!=="T"||h.ctrlKey||h.metaKey||h.altKey)return;h.preventDefault(),h.stopPropagation();const m=e==="dark"?"light":"dark";t(m),h.target.getAttribute("role")==="radio"&&((y=h.currentTarget.querySelectorAll('[role="radio"]')[Di.indexOf(m)])==null||y.focus())};return i.jsxs("div",{ref:c,id:"appearance-menu",className:"appearance-menu",role:"dialog","aria-labelledby":"appearance-title",onKeyDown:p,children:[i.jsx("div",{className:"appearance-head",children:i.jsx("h2",{id:"appearance-title",className:"appearance-title",children:"Appearance"})}),i.jsxs("section",{className:"appearance-section","aria-labelledby":"appearance-theme-caption",children:[i.jsxs("div",{className:"appearance-caption",children:[i.jsx("h3",{id:"appearance-theme-caption",children:"Color theme"}),i.jsx("kbd",{className:"appearance-key","aria-hidden":!0,title:"Press T anywhere to switch themes",children:"T"})]}),i.jsx("div",{className:"appearance-themes",role:"radiogroup","aria-labelledby":"appearance-theme-caption","aria-keyshortcuts":"T",onKeyDown:f,children:Di.map(h=>i.jsxs("button",{type:"button",className:"appearance-theme",role:"radio","aria-checked":e===h,tabIndex:e===h?0:-1,onClick:()=>t(h),children:[i.jsx(qz,{theme:h}),i.jsxs("span",{className:"appearance-theme-name",children:[Fz[h],i.jsx("svg",{className:"appearance-check",viewBox:"0 0 12 12","aria-hidden":!0,focusable:"false",children:i.jsx("path",{d:"M2.5 6.4 4.9 8.7 9.5 3.6"})})]})]},h))})]}),i.jsxs("section",{className:"appearance-section","aria-labelledby":"appearance-fm-caption",children:[i.jsx("div",{className:"appearance-caption",children:i.jsx("h3",{id:"appearance-fm-caption",children:"Claude FM"})}),i.jsxs("label",{className:"appearance-row",children:[i.jsx("span",{className:"appearance-row-label",id:"appearance-character-label",children:"Show character on minimap"}),i.jsx("button",{type:"button",className:"switch",role:"switch","aria-checked":n,"aria-labelledby":"appearance-character-label","aria-describedby":"appearance-character-note",onClick:r,children:i.jsx("span",{className:"switch-knob"})}),i.jsx("span",{className:"appearance-row-note",id:"appearance-character-note",children:"Press it to play the live stream"})]})]})]})}const Gx="https://www.youtube-nocookie.com";function zz(e,t){const n=new URLSearchParams({channel:e,enablejsapi:"1",autoplay:"1",playsinline:"1",rel:"0",modestbranding:"1",origin:t});return`${Gx}/embed/live_stream?${n.toString()}`}function g_(e,t=[]){return JSON.stringify({event:"command",func:e,args:t})}function Hz(e="claude-fm"){return JSON.stringify({event:"listening",id:e,channel:"widget"})}const Wz=[1,3],Uz=[0,2],Vz=[2,5,100,101,150];function Gz(e){let t=e;if(typeof e=="string")try{t=JSON.parse(e)}catch{return null}if(!t||typeof t!="object")return null;const{event:n,info:r}=t;if(n==="onReady")return{kind:"ready"};if(n==="onError"){const a=typeof r=="number"?r:Number(r==null?void 0:r.errorCode);return Number.isFinite(a)?{kind:"error",code:a}:null}if(n==="onStateChange"||n==="infoDelivery"){const a=typeof r=="number"?r:r==null?void 0:r.playerState;return typeof a!="number"||!Number.isFinite(a)?null:Wz.includes(a)?{kind:"playing",playing:!0}:Uz.includes(a)?{kind:"playing",playing:!1}:null}return null}const KR=["......aaaaaa......","....aa......aa....","...a..bbbbbs..a...","...cpcbbbbbscpc...","...cpcbebbescpc...","...cpcbbbbbscpc...","...cpcbbbbbscpc...","....ccbbbbbscc....","....bbbbbbbbbs....","....bbbbbbbbbs....","......bbbbbs......","......bb..bs......","......bb..bs......","......bb..bs......"],y_=18,Kz=KR.length,YR=new Set(["a","c","p"]);function Mh(e=KR){const t=[];return e.forEach((n,r)=>{let a=0;for(;a<n.length;){const l=n[a];if(l==="."){a+=1;continue}let c=1;for(;a+c<n.length&&n[a+c]===l;)c+=1;t.push({x:a,y:r,w:c,cell:l}),a+=c}}),t}const Io=148,w_=6e3,Yz=16e3,XR=46,Ma=34;function Xz(e,t,n=Io){let r=-Math.round(t()*n);if(Math.abs(r-e)<Ma){const a=e-Ma>=-n?-Ma:Ma;r=Math.max(-n,Math.min(0,Math.round(e+a)))}return{to:r,ms:Math.round(Math.abs(r-e)*XR)}}function Zz(e){return Math.round(w_+e()*(Yz-w_))}const v_=[{kind:"stroll",weight:44},{kind:"tidy",weight:17},{kind:"kick",weight:17},{kind:"sit",weight:12},{kind:"watch",weight:16},{kind:"leave",weight:7},{kind:"fish",weight:12},{kind:"skip",weight:10}];function Qz(e){const t=v_.reduce((r,a)=>r+a.weight,0);let n=e()*t;for(const r of v_)if(n-=r.weight,n<0)return r.kind;return"stroll"}const Jz=720,eH=260,tH=620,nH=220,x_=520,ZR=1600,b_=7e3,rH=15e3,k_=6e3,sH=14e3;function Fi(e,t,n=Io){let r=-Math.round(t()*n);if(Math.abs(r-e)<Ma){const a=e-Ma>=-n?-Ma:Ma;r=Math.max(-n,Math.min(0,Math.round(e+a)))}return r}const cn=(e,t)=>Math.round(Math.abs(t-e)*XR),Cd=0;function aH(e,t){const n=r=>({kind:"litter",at:t,...r});return[{x:t,prop:n({}),act:"walk",ms:cn(e,t)},{x:t,prop:n({}),act:"stoop",ms:Jz},{x:Cd,prop:n({held:!0}),act:"carry",ms:cn(t,Cd)},{x:Cd,prop:n({held:!0}),act:"windup",ms:eH},{x:Cd,prop:n({held:!0,leaving:!0}),act:"toss",ms:tH}]}function oH(e,t){const n=t>e?1:-1,r=t-n*Math.min(15,Math.abs(t-e)),a=(l={})=>({kind:"ball",at:t,...l});return[{x:r,prop:a(),act:"walk",ms:cn(e,r)},{x:r,prop:a(),act:"windup",ms:nH,facing:n>0?"right":"left"},{x:r,prop:a({leaving:!0}),act:"kick",ms:x_,facing:n>0?"right":"left"},{x:r,prop:a({leaving:!0}),act:"stand",ms:ZR-x_}]}const QR=640;function iH(e,t,n){const r=Math.max(-70,Math.min(-20,t)),a={x:r,prop:null,facing:"left"};return[{x:r,prop:null,act:"walk",ms:cn(e,r)},{...a,act:"sit",ms:600},{...a,act:"cast",ms:900},{...a,act:"fish",ms:6e3+Math.round(n()*4e3)},{...a,act:"reel",ms:1200},{...a,act:"stow",ms:500},{...a,act:"stand",ms:400},{x:0,prop:null,act:"walk",ms:cn(r,0)}]}function lH(e,t,n){const r=Math.max(-110,Math.min(-30,t)),a={x:r,prop:null};return[{...a,act:"walk",ms:cn(e,r)},{...a,act:"skip-ready",ms:500},{...a,act:"skip",ms:QR*(6+Math.floor(n()*5))},{...a,act:"skip-rest",ms:600},{...a,act:"stand",ms:350},{x:0,prop:null,act:"walk",ms:cn(r,0)}]}function cH(e,t,n){return[{x:t,prop:null,act:"walk",ms:cn(e,t)},{x:t,prop:null,act:"sit",ms:Math.round(k_+n()*(sH-k_))},{x:t,prop:null,act:"stand",ms:400}]}function uH(e,t,n){t=Math.max(-110,Math.min(0,t));const r=()=>({kind:"scope",at:t,held:!0});return[{x:t,prop:null,act:"walk",ms:cn(e,t)},{x:t,prop:r(),act:"watch",ms:Math.round(b_+n()*(rH-b_))},{x:t,prop:r(),act:"scope-pack",ms:480},{x:t,prop:null,act:"stand",ms:240}]}function N_(e,t,n){return e.facing?e.facing:e.act==="watch"||e.act==="scope-pack"?"left":e.x===t?n:e.x>t?"right":"left"}const dH=1500,hH=e=>Math.round(1e3*Math.sqrt(2*e/dH)),fH=115,pH=e=>Math.round(e/fH*1e3),mH=620,gH=200,yH=760,wH=600,vH=240;function xH(e,t,n){const a=-(t.ledgeSpan??Io),l=hH(t.ledgeH),c=pH(t.ledgeH),u=-Math.round(n()*t.floorSpan),f=-Math.round(n()*t.floorSpan);return[{x:a,act:"walk",prop:null,ms:cn(e,a)},{x:a,act:"peer",prop:null,ms:mH},{x:a,act:"fall",prop:null,ms:l,place:"floor"},{x:a,act:"land",prop:null,ms:gH,place:"floor"},{x:u,act:"walk",prop:null,ms:cn(a,u),place:"floor"},{x:f,act:"walk",prop:null,ms:cn(u,f),place:"floor"},{x:a,act:"walk",prop:null,ms:cn(f,a),place:"floor"},{x:a,act:"lasso",prop:null,ms:yH,place:"floor"},{x:a,act:"rope-throw",prop:null,ms:wH,place:"floor"},{x:a,act:"rope-catch",prop:null,ms:vH,place:"floor"},{x:a,act:"climb",prop:null,ms:c},{x:a,act:"pull-up",prop:null,ms:480}]}function bH(e,t,n){const r=(n==null?void 0:n.ledgeSpan)??Io;switch(Qz(t)){case"tidy":return aH(e,Fi(e,t,r));case"kick":return oH(e,Fi(e,t,r));case"sit":return cH(e,Fi(e,t,r),t);case"watch":return uH(e,Fi(e,t,r),t);case"fish":return iH(e,Fi(e,t,r),t);case"skip":return lH(e,Fi(e,t,r),t);case"leave":{if(!n||!(n.ledgeH>0)||!(n.floorSpan>0))break;return xH(e,n,t)}}const l=Xz(e,t,r);return[{x:l.to,prop:null,act:"walk",ms:l.ms}]}const kH=[".xx.","xxxx",".xx."],NH=["..xx..",".xsxx.","xssxxx","xxxxsx",".xxxx.","..xx.."],_H=["...xx...............","..xaax..............",".xaallx.............","xaallllx............",".xllllllx...........","..xllllllx..........","...xllllllx.........","....xllllllxx.......",".....xllllxsxx..xx..","......xllxsssx.xllxx",".......xxssssxxxllxx","........xssssssxx...",".........xssssx.....","..........xxxx......","..........xax.......",".........xxxxx......","........xx.x.xx.....","........xl.x.lx.....",".......xl..x..lx....",".......xl..x..lx....","......xl...x...lx...","......xl...x...lx...",".....xl....x....lx..","....xxx...xxx...xxx."],Bp={litter:kH,ball:NH,scope:_H},JR=["bob","sway","groove"],__=9e3,SH=16e3,eM=1e3,jH=.08;function EH(e,t){const n=JR.filter(l=>l!==e),r=n[Math.min(n.length-1,Math.floor(t()*n.length))],a=(t()*2-1)*jH;return{dance:r,beatMs:Math.round(eM*(1+a))}}function CH(e){return Math.round(__+e()*(SH-__))}const TH=["...hhhhhh...","...hhhhhh...","...kkkkkk...","hhhhhhhhhhhh"],AH=3,RH=-1,Kx=11,S_=9,MH=420;function IH(e,t,n){const r=t==="right"?n-e-18:e-18;return(t==="right"?1:-1)*Math.min(MH,Math.max(0,r))}const $H=260,OH=200;function PH(e,t,n){const r=(h,m=cn(e,h))=>({x:h,prop:null,act:"walk",ms:m,place:"floor"});if(!n||n.height<=0)return[r(t)];const a=Math.min(e,t);if(Math.max(e,t)<=n.left||a>=n.right)return[r(t)];const c=t>e,u=c?n.left:n.right,f=c?n.right:n.left,p={place:"floor",riser:n.height,prop:null};return[r(u,cn(e,u)),{...p,x:u,act:"mount",ms:$H},{...p,x:f,act:"walk",ms:cn(u,f)},{x:f,prop:null,act:"dismount",ms:OH,place:"floor"},{x:t,prop:null,act:"walk",ms:cn(f,t),place:"floor"}]}function j_(e){let t=null,n=null,r=0,a=0,l=!1;const c=()=>{t!==null&&clearTimeout(t),t=null},u=()=>{l||e.hidden||!n||t!==null||(a=performance.now(),t=setTimeout(()=>{t=null;const p=n;n=null,p==null||p()},r))},f=()=>{e.hidden&&t!==null?(r=Math.max(0,r-(performance.now()-a)),c()):e.hidden||u()};return e.addEventListener("visibilitychange",f),{schedule(p,h){l||(c(),n=p,r=Math.max(0,h),u())},dispose(){l=!0,c(),n=null,e.removeEventListener("visibilitychange",f)}}}function zp(e,t){var r;const n=((r=e[0])==null?void 0:r.length)??0;return i.jsx("svg",{viewBox:`0 0 ${n} ${e.length}`,shapeRendering:"crispEdges","aria-hidden":!0,children:Mh(e).map(a=>i.jsx("rect",{x:a.x,y:a.y,width:a.w,height:1,fill:a.cell==="s"?"var(--fm-prop-shadow, var(--bg))":a.cell==="l"?"var(--fm-prop-light, var(--text))":a.cell==="a"?"var(--accent)":void 0},`${t}${a.y}-${a.x}`))})}const Hp={e:"fm-eye",s:"fm-shade",p:"fm-pad"},uh=Mh().filter(e=>!YR.has(e.cell)),LH=Mh().filter(e=>YR.has(e.cell)),E_=uh.filter(e=>e.cell==="e"),DH=Mh(TH),FH=uh.filter(e=>e.y<Kx&&e.cell!=="e").map(e=>{if(e.y!==8&&e.y!==9)return e;const t=Math.max(6,e.x);return{...e,x:t,w:Math.max(0,Math.min(12,e.x+e.w)-t)}}).filter(e=>e.w>0),qH={left:uh.filter(e=>e.y>=Kx&&e.x<S_),right:uh.filter(e=>e.y>=Kx&&e.x>=S_)},C_={litter:zp(Bp.litter,"litter"),ball:zp(Bp.ball,"ball"),scope:zp(Bp.scope,"scope")},BH=x.memo(function({fetchImpl:t}){const[n,r]=x.useState(null),[a,l]=x.useState(!1),[c,u]=x.useState(!1),[f,p]=x.useState(!1),[h,m]=x.useState(0),[y,w]=x.useState(0),[_,N]=x.useState(null),[j,b]=x.useState(null),[S,E]=x.useState({x:0,drop:0}),[C,T]=x.useState("ledge"),[R,$]=x.useState("left"),[H,B]=x.useState(0),P=x.useRef(null),[K,X]=x.useState(()=>document.hidden);x.useEffect(()=>{const D=new Set,ae=()=>{var z;if(document.hidden){for(const Q of((z=P.current)==null?void 0:z.getAnimations({subtree:!0}))??[])if(Q.playState==="running"||Q.pending){const U=Q.currentTime;Q.pause(),U!==null&&(Q.currentTime=U),D.add(Q)}}else{for(const Q of D)Q.playState==="paused"&&Q.play();D.clear()}X(document.hidden)};return ae(),document.addEventListener("visibilitychange",ae),()=>document.removeEventListener("visibilitychange",ae)},[n,a]);const[J,M]=x.useState(null),[Z,V]=x.useState(eM),[I,q]=x.useState(()=>{var D;return((D=window.matchMedia)==null?void 0:D.call(window,"(prefers-reduced-motion: reduce)").matches)??!1});x.useEffect(()=>{var z;const D=(z=window.matchMedia)==null?void 0:z.call(window,"(prefers-reduced-motion: reduce)");if(!D)return;const ae=()=>q(D.matches);return ae(),D.addEventListener("change",ae),()=>D.removeEventListener("change",ae)},[]);const W=x.useRef(null),G=x.useCallback(D=>{var ae,z;(z=(ae=W.current)==null?void 0:ae.contentWindow)==null||z.postMessage(D,Gx)},[]);if(x.useEffect(()=>{let D=!0;return(t??fetch)("/api/claude-fm").then(z=>z.ok?z.json():null).then(z=>{D&&(z!=null&&z.live)&&(z!=null&&z.channel)&&r({live:!0,channel:z.channel})}).catch(()=>{}),()=>{D=!1}},[t]),x.useEffect(()=>{if(!c)return;const D=ae=>{var Q;if(ae.origin!==Gx||ae.source!==((Q=W.current)==null?void 0:Q.contentWindow))return;const z=Gz(ae.data);if(z){if(z.kind==="ready"){G(g_("playVideo"));return}if(z.kind==="playing"){p(z.playing);return}Vz.includes(z.code)&&(u(!1),p(!1),l(!0))}};return window.addEventListener("message",D),()=>window.removeEventListener("message",D)},[c,G]),x.useEffect(()=>{if(!n||a||I)return;const D=j_(document);let ae=0;m(pe=>ae=pe);const z=pe=>{var Te,Se;const[ke,...Pe]=pe;if(!ke){N(null),b(null),ge();return}N(ke.act),b(ke.prop),T(ke.place??"ledge"),B(ke.riser??0);const $e=de(ke),Ae=ae;if(ke.act==="kick"){const We=(Se=(Te=P.current)==null?void 0:Te.querySelector('.fm-prop[data-prop="ball"]'))==null?void 0:Se.getBoundingClientRect();We&&E({x:IH(We.x,N_(ke,Ae,"left"),window.innerWidth),drop:Math.max(48,window.innerHeight-We.y+24)})}const Qe=ke.act==="walk"||ke.act==="carry"?cn(Ae,$e):ke.ms;w(Qe),$(We=>N_({...ke,x:$e},Ae,We)),m($e),ae=$e,D.schedule(()=>z(Pe),Qe)},Q=()=>{const pe=P.current,ke=pe==null?void 0:pe.querySelector(".fm-sprite"),Pe=pe==null?void 0:pe.parentElement;if(!pe||!ke||!Pe)return null;const $e=pe.getBoundingClientRect(),Ae=Pe.getBoundingClientRect(),je=Ae.right-$e.right,Qe=Ae.width-je*2-ke.offsetWidth;return Qe>0?Qe:null},U=()=>{const pe=P.current,ke=pe==null?void 0:pe.querySelector(".fm-walker"),Pe=Q();if(!pe||!ke||Pe==null)return;const $e=pe.getBoundingClientRect().bottom-ke.getBoundingClientRect().bottom;if($e>0)return{ledgeH:$e,floorSpan:Pe}},re=()=>{const pe=P.current,ke=document.querySelector(".autofit-chip");if(!pe||!ke)return null;const Pe=pe.getBoundingClientRect(),$e=ke.getBoundingClientRect();return $e.width<=0||$e.height<=0?null:{left:$e.left-Pe.right,right:$e.right-Pe.right,height:$e.height}},de=pe=>{const ke=(pe.place??"ledge")==="floor"?Q()??Io:Io;return Math.max(-ke,Math.min(0,pe.x))},ge=()=>{D.schedule(()=>{const pe=bH(ae,Math.random,U()),ke=pe.some(Ae=>Ae.place==="floor")?re():null;let Pe=ae;const $e=pe.flatMap(Ae=>{const je=Pe;return Pe=Ae.x,Ae.place==="floor"&&Ae.act==="walk"?PH(je,Ae.x,ke):[Ae]});z($e)},Zz(Math.random))};return ge(),()=>{D.dispose(),T("ledge"),m(pe=>Math.max(-Io,Math.min(0,pe))),w(0),N(null),b(null),B(0)}},[n,a,I]),x.useEffect(()=>{if(!f||I){M(null);return}const D=j_(document),ae=z=>{const Q=EH(z,Math.random);M(Q.dance),V(Q.beatMs),D.schedule(()=>ae(Q.dance),CH(Math.random))};return ae(null),()=>D.dispose()},[f,I]),!n||a)return null;const F=()=>{if(!c){u(!0),p(!0);return}const D=!f;p(D),G(g_(D?"playVideo":"pauseVideo")),D||u(!1)};return i.jsxs("div",{ref:P,className:"fm","data-suspended":K?"":void 0,"data-place":C,style:{"--fm-beat":`${Z}ms`},children:[j&&!j.held&&i.jsx("div",{className:"fm-prop","data-prop":j.kind,"data-leaving":j.leaving?"":void 0,style:{"--fm-prop-x":`${j.at}px`,"--fm-roll-to":`${S.x}px`,"--fm-ball-drop":`${S.drop}px`,"--fm-ball-flight-ms":`${ZR}ms`,"--fm-ball-turn":R==="right"?"1080deg":"-1080deg"},children:C_[j.kind]}),(_==="lasso"||_==="rope-throw"||_==="rope-catch"||_==="climb"||_==="pull-up")&&i.jsxs("div",{className:"fm-rope","data-act":_,style:{"--fm-rope-x":`${h}px`,"--fm-rope-ms":`${y}ms`},children:[i.jsx("div",{className:"fm-rope-line"}),i.jsxs("svg",{className:"fm-rope-hook",viewBox:"0 0 9 9",shapeRendering:"crispEdges","aria-hidden":!0,children:[i.jsx("path",{d:"M4 8V3H3V1H1V3H0V5H2V4H3V6H5V4H6V5H8V3H7V1H5V3H4"}),i.jsx("rect",{className:"fm-rope-knot",x:"3",y:"6",width:"3",height:"2"})]})]}),i.jsxs("div",{className:"fm-walker","data-act":_??void 0,"data-place":C,"data-facing":R,style:{"--fm-x":`${h}px`,"--fm-walk-ms":`${y}ms`,"--fm-riser":`${H}px`,"--fm-skip-beat":`${QR}ms`},children:[(j==null?void 0:j.held)&&i.jsx("div",{className:"fm-held","data-prop":j.kind,"data-toss":j.leaving?"":void 0,children:C_[j.kind]}),["cast","fish","reel","stow"].includes(_)&&i.jsxs("svg",{className:"fm-fishing",viewBox:"0 0 24 32",shapeRendering:"crispEdges","aria-hidden":!0,children:[i.jsxs("g",{children:[i.jsx("path",{d:"M24 11H22V9H20V7H18V5H16V3H13V2H8"}),i.jsx("rect",{className:"fm-fishing-grip",x:"21",y:"9",width:"3",height:"3"})]}),i.jsxs("g",{className:"fm-fishing-line",children:[i.jsx("path",{d:"M8 2V26"}),i.jsxs("g",{className:"fm-float",children:[i.jsx("rect",{x:"7",y:"25",width:"3",height:"2"}),i.jsx("rect",{x:"8",y:"24",width:"1",height:"1"})]})]}),i.jsx("path",{className:"fm-ripple",d:"M3 28H6M10 28H14M5 30H12"})]}),["skip-ready","skip","skip-rest"].includes(_)&&i.jsxs("svg",{className:"fm-skipping-rope",viewBox:"0 0 26 26",shapeRendering:"crispEdges","aria-hidden":!0,children:[i.jsx("path",{className:"fm-skip-back",d:"M5 18H3V8H5V5H8V2H18V5H21V8H23V18H21"}),i.jsx("path",{className:"fm-skip-forward",d:"M5 18H3V14H5V11H8V9H18V11H21V14H23V18H21"}),i.jsx("path",{className:"fm-skip-front",d:"M5 18H3V21H5V23H8V25H18V23H21V21H23V18H21"}),i.jsx("path",{className:"fm-skip-return",d:"M5 18H3V19H8V20H18V19H23V18H21"}),i.jsx("path",{className:"fm-skip-handles",d:"M5 17V19M21 17V19"})]}),i.jsx("button",{type:"button",className:"fm-sprite","data-playing":f?"":void 0,"data-dance":f?J??JR[0]:void 0,"aria-pressed":f,onClick:F,title:f?"Stop Claude FM":"Play Claude FM — streams from YouTube","aria-label":f?"Stop Claude FM":"Play Claude FM",children:i.jsxs("svg",{viewBox:`0 0 ${y_} ${Kz}`,shapeRendering:"crispEdges","aria-hidden":!0,children:[i.jsx("g",{className:"fm-gear",children:i.jsx("g",{className:"fm-gear-motion",children:LH.map(D=>i.jsx("rect",{x:D.x,y:D.y,width:D.w,height:1,className:Hp[D.cell]},`g${D.y}-${D.x}`))})}),i.jsxs("g",{className:"fm-body",children:[E_.map(D=>i.jsx("rect",{x:D.x,y:D.y,width:D.w,height:1,fill:"var(--accent)"},`eye-bed-${D.x}`)),FH.map(D=>i.jsx("rect",{x:D.x,y:D.y,width:D.w,height:1,className:Hp[D.cell]},`b${D.y}-${D.x}`)),i.jsxs("g",{className:"fm-arms",children:[i.jsx("rect",{x:4,y:8,width:2,height:2}),i.jsx("rect",{x:12,y:8,width:1,height:2}),i.jsx("rect",{x:13,y:8,width:1,height:2,className:"fm-shade"})]}),E_.map(D=>i.jsx("rect",{x:D.x-(D.x>=y_/2?1:0)+(R==="right"?1:0),y:D.y,width:D.w,height:1,className:"fm-eye"},`eye-${D.x}`))]}),i.jsx("g",{className:"fm-hat",children:DH.map(D=>i.jsx("rect",{x:AH+D.x,y:RH+D.y,width:D.w,height:1,className:D.cell==="k"?"fm-hatband":void 0},`h${D.y}-${D.x}`))}),(_==="climb"||_==="rope-throw"||_==="rope-catch"||_==="pull-up")&&i.jsxs("g",{className:"fm-grip",children:[i.jsx("path",{className:"fm-grip-left",d:"M5 9H4V4H7V3H9V5H6V9Z"}),i.jsx("path",{className:"fm-grip-right",d:"M12 9H14V6H11V5H9V7H12Z"})]}),(_==="land"||_==="dismount")&&i.jsxs("g",{className:"fm-crouch-legs",children:[i.jsx("path",{d:"M6 11H8V13H6Z"}),i.jsx("path",{d:"M10 11H12V13H10Z"})]}),["sit","cast","fish","reel","stow"].includes(_)&&i.jsxs("g",{className:"fm-seated-legs",children:[i.jsx("path",{className:"fm-seated-far",d:"M10 10H12V11H11V14H8V13H9V11H10Z"}),i.jsx("path",{d:"M6 10H9V11H7V15H4V14H5V11H6Z"})]}),["left","right"].map(D=>i.jsx("g",{className:"fm-leg","data-side":D,children:qH[D].map(ae=>i.jsx("rect",{x:ae.x,y:ae.y,width:ae.w,height:1,className:Hp[ae.cell]},`${D}${ae.y}-${ae.x}`))},D))]})})]}),c&&n.channel&&i.jsx("iframe",{ref:W,className:"fm-frame",title:"Claude FM",src:zz(n.channel,window.location.origin),onLoad:()=>G(Hz()),allow:"autoplay; encrypted-media",sandbox:"allow-scripts allow-same-origin allow-presentation"})]})}),tM="agent-dag.character-enabled";function zH(e){return e!=="0"}function HH(){return zH(Da(tM))}const WH=15e3;function UH(e){return e.visibilityState==="visible"&&e.hasFocus()}function VH(e,t){return t||e===!0}function GH(){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}const KH={"//":["What a user would NOTICE. One key per version that has something to say,","and no key at all for a version that has nothing — which is most of them.","","The rule this file exists to serve: before every release, ask 'what would a","user notice?' and write the answer here. 'Nothing user-visible' is a valid","and expected answer, and it is spelled by adding no key. A release with no","key shows no modal, and that silence is what keeps the modal worth reading","on the day it is not silent.","","What belongs here: something that changed on the user's machine or under","their hands — a hook written to or removed from settings.json, a default","that flipped, a control that moved or went away, a stored preference that","changed meaning. What does not: bounds, races, assertions that could not","fire, anything that is invisible when it is correct.","","Write it for the person running the deck, not for the person reading the","diff. `title` is the sentence they scan; `body` is what they need in order","to act on it, or to stop worrying about it.","","Keys are versions exactly as package.json spells them. A key that is not a","version, or an entry missing either field, fails the suite rather than","being quietly dropped — see src/web/__tests__/release-notes-file.test.ts.","Ordering here is for humans; the deck sorts by version itself.","","A title may open with an emoji, and if it does, put exactly ONE space after","it. Not two: the dialog gives a leading emoji its own optical gap, because","a colour glyph is drawn edge to edge inside its advance and one word space","after one reads as none. A second space here would be a lie in the data","about a defect in the type, and the suite refuses both it and no space at","all.","","A release that genuinely has nothing to say is spelled TWICE: no key here,",'and its version written into "//nothing-to-say" below. One spelling on its',"own is ambiguous — a missing key reads the same whether it was a decision","or a forgotten step, and five releases in a row were once forgotten. The list","is what tells the two apart, and release-notes-current-version.test.ts fails","the release whose version is in neither place. Any key opening with // is a","note to the author and never a release."],"//nothing-to-say":["3.23.1","3.23.2","3.23.3","3.23.4","3.26.0","3.26.1","3.26.3"],"3.25.0":[{title:"🖱️ A click goes to the session, a double-click opens the details",body:"Clicking a card frames it with the rest of its session and leaves the detail panel shut. Double-click a card to open its details; `j`/`k`, the session list, Enter and `D` still open them too."},{title:"🔭 Cards stay readable when you zoom out",body:"At every zoom a card shows its name, its state and anything waiting on you, instead of shrinking to a coloured pill. Hover or focus a card to see it whole. Recap notes read at a distance too, and show the full recap on hover."},{title:"🌐 The Machine panel shows your network",body:"A new Network section shows download, upload and the round trip to Claude's API, and names the route when traffic goes through a VPN or a Tailscale exit node. Those checks run only while the panel is open. The panel is regrouped into CPU, Memory, Network and Thermal, with a flag at the top when something needs attention."},{title:"🎨 See each theme before you pick it",body:"The Appearance menu shows a small preview of the deck in Light and in Dark. Claude FM also keeps its volume when a notification chime plays, instead of dipping under it."}],"3.24.1":[{title:"🎛️ Appearance is one small menu now",body:"The topbar's appearance control opens a compact menu where you can choose Light or Dark and show or hide the character. The character stays on by default, and your choice is remembered."}],"3.24.0":[{title:"🎧 Claude FM plays from the minimap",body:"A small character stands on the minimap's top edge. Press it and the Claude channel's live stream plays; press it again and it stops. It only turns up when the channel is actually broadcasting, so a deck with no network never shows it at all."},{title:"🤠 And it gets on with its day",body:"It walks that edge, tidies up what it finds, kicks a ball along it, sits with its legs over the side, and watches the board through a scope. Now and then it drops onto the canvas and ropes its way back up. Headphones on while the music plays, a hat when it does not."}],"3.23.5":[{title:"🧭 The accounts panel opens on the account you are on",body:"Its windows, its resets and how old the numbers are — whole, at the top of the column. Every other account stands behind one row that says how many of them a switch could actually reach; press it to see them, or rest on it to be shown their names and how much room each has left."},{title:"⚙️ Auto-switch moved in there with them",body:"It is behind that same row now, after the accounts it switches between, rather than at the foot of the panel. The row says `auto 90%` or `auto off` so you can tell what the policy is doing without opening it — and says so in amber when it is armed with nowhere left to go."}],"3.23.0":[{title:"🧭 The accounts column leads with accounts",body:`The live account is the open row: its windows as bars, when each one resets, and how old the numbers are. Every other account rests on the two figures a switch is decided by, and opens with a click when you want the rest.
92
+ `)})}),i.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>void c(),title:u?"Copy these lines, then paste them into a terminal":"Copy these lines, then paste them into an elevated PowerShell",children:n?"copied":"copy command"})]})]})}async function Lp(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}const z8={not_an_invite:"That is not an invite — paste the whole line they sent you.",expired:"That invite has run out. Ask them for a fresh one.",not_running:"This deck is not on the network yet. Turn Local network on, then try again."},H8={not_running:"This deck is not on the network yet. Turn Local network on, then make one."};function JN(e,t,n){return(t==null?void 0:t.reason)&&e[t.reason]||tn(n,t)}function W8({status:e,manual:t,onClose:n,onChanged:r}){const a=x.useRef(null),l=un(n,{focusRef:a}),[c,u]=x.useState(""),[f,p]=x.useState(""),[h,m]=x.useState(null),[y,w]=x.useState(null),[_,N]=x.useState(null),[j,b]=x.useState(null),[S,E]=x.useState(()=>Date.now());x.useEffect(()=>{const I=window.setInterval(()=>E(Date.now()),1e3);return()=>window.clearInterval(I)},[]);const C=x.useRef(!0);x.useEffect(()=>()=>{C.current=!1},[]);const T=x.useRef(null),R=x.useCallback(I=>Th(T.current)?(T.current=I,N(I),!0):!1,[]),$=x.useCallback(()=>{T.current=null,C.current&&N(null)},[]),H=I=>{const q=La(_,I);return{disabled:q.disabled,"aria-busy":q.busy}},B=I=>(h==null?void 0:h.field)===I?{"aria-invalid":!0,"aria-describedby":"lan-add-failure"}:{},P=I=>m(q=>q&&q.field===I?null:q),K=x.useCallback(async()=>{const I=oB(c);if(!I){m({text:U8(c),field:"addr"});return}const q=`${I.addr}:${I.port}`,W=e.peers.find(G=>G.addr===I.addr&&G.port===I.port&&G.paired);if(W){m({text:`Already paired with ${W.name} at that address.`,field:"addr"});return}if(t.includes(q)){m({text:"This deck already calls that address.",field:"addr"});return}if(R("add"))try{const G=await Lp("/api/prefs",{lan:{manual:[...t,q]}});if(!C.current)return;G!=null&&G.ok?(m(null),u(""),r(),n()):m({text:tn("add that address",G),field:"addr"})}catch{C.current&&m({text:tn("add that address",null),field:"addr"})}finally{$()}},[c,t,e.peers,r,n,R,$]),X=x.useCallback(async I=>{if(!R(`invite:${I}`))return;const q=I==="make"?"make an invite":"cancel that invite";try{const W=await Lp("/api/lan/invite",{action:I});if(!C.current)return;W!=null&&W.ok?(m(null),w(null),r()):m({text:JN(H8,W,q)})}catch{C.current&&m({text:tn(q,null)})}finally{$()}},[r,R,$]),J=x.useCallback(async()=>{const I=f.trim();if(!(!I||!R("join"))){b(null);try{const q=await Lp("/api/lan/invite",{action:"join",token:I});if(!C.current)return;q!=null&&q.ok?(p(""),m(null),r(),n()):(q==null?void 0:q.reason)==="unreachable"&&Array.isArray(q.tried)&&q.tried.length?(b(q.tried),m(null)):(b(null),m({text:JN(z8,q,"use that invite"),field:"join"}))}catch{C.current&&m({text:tn("use that invite",null),field:"join"})}finally{$()}}},[f,r,n,R,$]),M=x.useCallback(async(I,q)=>{try{await navigator.clipboard.writeText(I),w(q),window.setTimeout(()=>{C.current&&w(W=>W===q?null:W)},1600)}catch{m({text:"Could not copy it — select the text and copy it by hand."})}},[]),Z=e.invite&&e.invite.expiresAt>S?e.invite:null,V=e.port!=null?(e.addrs??[]).map(I=>`${I}:${e.port}`):[];return Kn.createPortal(i.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:i.jsxs("div",{ref:l,className:"modal lan-add",onClick:I=>I.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-add-title",children:[i.jsxs("header",{className:"modal-head",children:[i.jsx("div",{className:"modal-title",children:i.jsx("span",{id:"lan-add-title",className:"modal-tool-name",children:"Add a deck"})}),i.jsx("div",{className:"modal-actions",children:i.jsx("button",{className:"glyph-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),i.jsxs("section",{className:"modal-body",children:[h&&i.jsxs("div",{className:"ap-failure",role:"alert",children:[i.jsx("span",{id:"lan-add-failure",className:"ap-failure-text",children:h.text}),i.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),i.jsx(DR,{reach:e.reach,where:"dialog"}),i.jsxs("div",{className:"modal-section",children:[i.jsx("h3",{className:"lan-h",children:"By address"}),i.jsxs("div",{className:"ap-lan-row",children:[i.jsx("input",{ref:a,className:"ap-manage-input ap-lan-input","aria-label":"Another deck's address",value:c,placeholder:"192.168.1.5:54340",spellCheck:!1,...B("addr"),onChange:I=>{u(I.target.value),P("addr")},onKeyDown:I=>{I.key==="Enter"&&K()}}),c.trim()!==""&&i.jsx("button",{type:"button",className:"ap-manage-btn",...H("add"),onClick:()=>void K(),title:"Add it to the decks this one calls, starting now.",children:"add"})]}),i.jsx("p",{className:"lan-note",children:"This deck calls that address until somebody there accepts."}),e.port!=null&&V.length>0&&i.jsxs("p",{className:"lan-note",children:["They type this deck’s own address into the same field on theirs:"," ",V.map((I,q)=>i.jsxs("span",{children:[q>0&&" or ",i.jsx("code",{className:"ap-lan-code",children:I})]},I)),i.jsx("button",{type:"button",className:"ap-lan-word lan-copy",...H("copy:mine"),onClick:()=>void M(V.join(" "),"mine"),title:"Copy this deck's address, to send to whoever is adding it",children:y==="mine"?"copied":"copy"})]})]}),i.jsxs("div",{className:"modal-section",children:[i.jsxs("h3",{className:"lan-h",children:["With an invite",!Z&&i.jsx("button",{type:"button",className:"ap-lan-word lan-h-act",...H("invite:make"),onClick:()=>void X("make"),title:"One piece of text you send them. They paste it, and the two decks pair — nobody has to press anything here.",children:_==="invite:make"?"making…":"make one to send"})]}),i.jsxs("div",{className:"ap-lan-row",children:[i.jsx("input",{className:"ap-manage-input ap-lan-input","aria-label":"An invite you were sent",value:f,placeholder:"paste one you were sent",spellCheck:!1,...B("join"),onChange:I=>{p(I.target.value),b(null),P("join")},onKeyDown:I=>{I.key==="Enter"&&J()}}),f.trim()!==""&&i.jsx("button",{type:"button",className:"ap-manage-btn",...H("join"),onClick:()=>void J(),title:"Reach that deck and pair with it. Nobody has to press anything there.",children:_==="join"?"joining…":"join"})]}),i.jsx("p",{className:"lan-note",children:"Pasting one pairs both decks on the spot — nobody has to accept."}),j&&i.jsxs("div",{className:"ap-lan-tried",children:[i.jsx("span",{className:"lan-note",children:"Nothing answered at any address in that invite. Check that deck is running with its Local network switch on."}),j.map(I=>i.jsxs("span",{className:"ap-lan-tried-row",children:[i.jsx("code",{className:"ap-lan-code",children:I.addr}),i.jsx("span",{className:"ap-lan-bad",children:I.why})]},I.addr))]}),Z&&i.jsxs("div",{className:"ap-lan-invite",children:[i.jsxs("div",{className:"ap-lan-invite-head",children:[i.jsx("span",{className:"ap-lan-invite-title",children:"Send this to them"}),i.jsxs("span",{className:"ap-lan-invite-left",children:[lB(Z.expiresAt,S)," left"]})]}),i.jsx("code",{className:"ap-lan-token",children:Z.token}),i.jsxs("div",{className:"ap-lan-acts",children:[i.jsx("button",{type:"button",className:"ap-manage-btn",...H("copy:invite"),onClick:()=>void M(Z.token,"invite"),title:"Copy it, and send it however you already talk to them",children:y==="invite"?"copied":"copy"}),i.jsx("button",{type:"button",className:"ap-manage-btn",...H("invite:withdraw"),onClick:()=>void X("withdraw"),title:"Cancel it. Anybody already holding the text can no longer use it.",children:"cancel"})]}),i.jsx("p",{className:"lan-warn",children:"Anyone who gets this text can pair with this deck until it runs out."})]})]})]})]})}),document.body)}function U8(e){const t=(e??"").trim();if(t==="")return"Type an address and a port, like 192.168.1.5:54340.";if(!t.startsWith("[")&&(t.match(/:/g)??[]).length>1)return"Too many colons to split. Use that deck's IPv4 address or its name, like 192.168.1.5:54340.";if(!t.includes(":"))return`Add the port too, like ${t}:54340.`;const n=t.slice(t.lastIndexOf(":")+1).trim();return n===""?"That is missing its port — try 192.168.1.5:54340.":/^\d+$/.test(n)?`A port runs from 1 to 65535, and this one is ${n}.`:`A port is a number, and this one is "${n}".`}const V8=1e3;function G8(e,t){const n=new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),r=hs(e,t);return`${n} · ${r==="now"?"just now":r}`}function e_(e){return e&&[e.version,e.os,e.arch].filter(Boolean).join(" · ")||null}function K8(){return i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M9.6 2.4l2 2L5 11l-2.6.6L3 9z"}),i.jsx("path",{d:"M8.4 3.6l2 2"})]})}function t_(){return i.jsxs("svg",{className:"lan-machine",width:"16",height:"16",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("rect",{x:"2.5",y:"3",width:"11",height:"7.5",rx:"1.2"}),i.jsx("path",{d:"M1 13h14"})]})}function jd({dir:e,gate:t=!1}){const n=t?12:8;return i.jsx("svg",{className:"lan-chev","data-dir":e,"data-gate":t||void 0,width:n,height:"8",viewBox:`0 0 ${n} 8`,fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:i.jsx("path",{d:e==="out"?"M2.8 1L6 4 2.8 7":t?"M1 1v6M9.6 1L6.4 4l3.2 3":"M5.2 1L2 4l3.2 3"})})}const Y8={works:"works here",expired:"expired here",missing:"not on this deck"},X8={works:"works there",broken:"broken there",unknown:"not offered by that deck"};function Z8(e){const t=e.in&&e.out?"offered both ways":e.in?"offered by that deck":"offered by this deck";return`${Y8[e.here]}, ${X8[e.there]}, ${t}${e.usedThere?", in use there":""}.`}function Q8({row:e,source:t,status:n,accounts:r,now:a,busy:l,onClose:c,onRename:u,onCheck:f,onVerb:p,onSettings:h,twins:m=[],onUnpair:y}){var vt,mt,_n,Et,zt;const w=x.useRef(null),_=un(c,{focusRef:w}),[N,j]=x.useState(null),[b,S]=x.useState(null),[E,C]=x.useState(!1),T=x.useRef(0),[R,$]=x.useState(null),[H,B]=x.useState(!1),[P,K]=x.useState(0),X=x.useRef(null),J=x.useRef(!0);x.useEffect(()=>()=>{J.current=!1},[]);const M=N!=null;x.useEffect(()=>{var fe;M&&((fe=X.current)==null||fe.select())},[M]),x.useEffect(()=>{if(!E)return;const fe=window.setTimeout(()=>C(!1),4e3);return()=>window.clearTimeout(fe)},[E]),x.useEffect(()=>{if(!R)return;const fe=window.setTimeout(()=>$(null),4e3);return()=>window.clearTimeout(fe)},[R]);const Z=fe=>{const nt=La(l,fe);return{disabled:nt.disabled,"aria-busy":nt.busy}},V=async fe=>{const nt=await fe();return J.current&&S(nt),nt==null},{peer:I,stranger:q}=t,W=e.kind==="paired",G=e.self??e.name,F=e.kind!=="dialling",D=e.kind==="dialling"?null:e.fp,ae=I?I.addr?`${I.addr}:${I.port}`:"":q?q.port?`${q.addr}:${q.port}`:q.addr:e.addr,z=(I==null?void 0:I.about)??null,Q=((vt=n.about)==null?void 0:vt.version)??null,U=async fe=>{const nt=fe.trim()===G?"":fe;await V(()=>u(nt))&&j(null)},re=async()=>{if(D)try{if(await navigator.clipboard.writeText(D),!J.current)return;B(!0),window.setTimeout(()=>{J.current&&B(!1)},1600)}catch{J.current&&S("Could not copy it — select the fingerprint and copy it by hand.")}},de=W?I!=null&&I.waiting?I.lastSeen!=null?"not said — it runs an older version":"not said yet — it says when it next calls":I!=null&&I.offers?"not said — it runs an older version":"not reached yet":"shown once paired",ge=e_(n.about),pe=e_(z),ke=z!=null&&z.version&&Q?yB(z.version,Q):null,Pe=I?FR(I.last,a):null,$e=I&&((mt=I.last)!=null&&mt.error)?aB({error:I.last.error,host:I.addr,port:I.port},[...n.strangers??[],...n.pending??[],...(n.peers??[]).filter(fe=>!fe.manual&&fe.addr).map(fe=>({fp:fe.fp,name:fe.name,addr:fe.addr,port:fe.port,at:fe.lastSeen??0}))],a):null,Ae=(_n=I==null?void 0:I.last)!=null&&_n.error&&Pe&&Pe.text!==I.last.error?I.last.error:null,je=((Et=I==null?void 0:I.last)==null?void 0:Et.done)??[],Qe=!!Pe&&!!Ae&&!e.quiet&&e.state.startsWith(Pe.text),Te=W||e.kind==="dialling",Se=((I==null?void 0:I.via)??e.via)==="tailscale",We=I?I.waiting?null:I.manual?Se?"added by its Tailscale address":"added by address":Se?"over Tailscale":"on this network":e.kind==="nearby"?Se?"heard over Tailscale":"heard on this network":Se?"asked this deck to pair, over Tailscale":"asked this deck to pair",dt=e.tone==="bad"?"bad":W?e.here?"up":"down":"loose",ct=l===`check:${e.fp}`,le=(I==null?void 0:I.offers)??null,Ne=dt==="up"?(le==null?void 0:le.current)??null:null,Me=Ne&&"key"in Ne?Ne.key:null,tt=!!Ne&&"hidden"in Ne,Ge=!!Ne&&"other"in Ne,Je=W?vB((le==null?void 0:le.accounts)??null,r,n.shared??[],Me):[],ye=Je.filter(fe=>fe.in==null&&fe.out==="cut"),Ce=Je.some(fe=>fe.in!=null),Ve=Je.some(fe=>fe.out!=null),ce=new Map(je.map(fe=>[fe.email,fe])),at=je.filter(fe=>!Je.some(nt=>nt.email===fe.email)),ut=W?le?le.accounts.length===0?"That deck offers nothing. Nobody there has chosen a login to share.":null:I!=null&&I.waiting?"What that deck offers is not known yet. A deck that calls in says so each time it calls — one on an older version never does.":(zt=I==null?void 0:I.last)!=null&&zt.error?"What that deck offers is not known — the last attempt to ask it did not get through.":"Nobody has asked that deck what it offers yet. The next round asks it.":null,rt=le&&(I!=null&&I.last)&&I.last.at-le.at>V8?hs(le.at,a):null,st=[];W&&(I!=null&&I.pairedAt)?st.push({label:"Paired",value:G8(I.pairedAt,a),tone:"meta"}):e.kind==="declined"&&q&&st.push({label:"Paired",value:`no · you said no ${q0(q.at,a)}`,tone:"meta"}),st.push({label:"Fingerprint",value:D?i.jsxs("span",{className:"lan-fp",children:[i.jsx("code",{className:"ap-lan-code",children:D}),i.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void re(),"aria-label":H?"Fingerprint copied":"Copy the fingerprint",children:H?"copied":"copy"})]}):"not known — nothing has answered there",tone:D?void 0:"quiet"});const jt=m.length?[{row:e,peer:I??null},...m]:[];return Kn.createPortal(i.jsx("div",{className:"modal-backdrop",onClick:c,role:"presentation",children:i.jsxs("div",{ref:_,className:"modal lan-peer","data-tone":e.tone,onClick:fe=>fe.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-peer-title","aria-describedby":"lan-peer-sub",children:[i.jsxs("header",{className:"modal-head lan-peer-head",children:[i.jsx("i",{className:e.here?"ap-pulse":"ap-dot","aria-hidden":!0}),i.jsxs("div",{className:"lan-peer-id",children:[M?i.jsxs("form",{className:"lan-peer-edit",onSubmit:fe=>{fe.preventDefault(),U(N??"")},children:[i.jsx("span",{id:"lan-peer-title",className:"vis-hidden",children:e.name}),i.jsx("input",{ref:X,className:"ap-manage-input lan-peer-input",value:N??"",maxLength:48,placeholder:G,"aria-label":"Name for this deck, shown on this deck only",onChange:fe=>j(fe.target.value)}),i.jsx("button",{type:"submit",className:"ap-manage-btn",...Z(`alias:${e.fp}`),children:"save"}),i.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>j(null),children:"cancel"})]}):i.jsxs("span",{className:"lan-peer-title",children:[i.jsx("span",{id:"lan-peer-title",className:"lan-peer-name",children:e.name}),F&&i.jsx("button",{type:"button",className:"glyph-btn lan-peer-rename",onClick:()=>{S(null),j(e.name)},"aria-label":`Rename ${e.name} on this deck`,title:"Give it a name of your own. Only this deck sees it.",children:i.jsx(K8,{})})]}),i.jsxs("p",{id:"lan-peer-sub",className:"lan-peer-sub",children:[e.self&&i.jsxs(i.Fragment,{children:["calls itself ",i.jsx("span",{className:"lan-peer-self",children:e.self}),M&&i.jsx("button",{type:"button",className:"ap-lan-word lan-peer-restore",...Z(`alias:${e.fp}`),onClick:()=>void U(""),children:"use this name"}),i.jsx("span",{className:"vis-hidden",children:". "}),!e.quiet&&i.jsx("span",{"aria-hidden":!0,children:" · "})]}),i.jsx("span",{className:e.quiet?"vis-hidden":"lan-peer-state",children:e.state})]})]}),i.jsx("div",{className:"modal-actions",children:i.jsx("button",{ref:w,type:"button",className:"glyph-btn",onClick:c,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),i.jsxs("section",{className:"modal-body lan-peer-body",children:[b&&i.jsxs("div",{className:"ap-failure",role:"alert",children:[i.jsx("span",{className:"ap-failure-text",children:b}),i.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>S(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),i.jsxs("div",{className:"lan-map","data-link":dt,"data-asking":ct||void 0,"data-bus":Je.length>0||void 0,children:[i.jsxs("div",{className:"lan-ends",children:[i.jsxs("p",{className:"lan-end",children:[i.jsx("span",{className:"lan-end-name",children:"This deck"}),ge&&i.jsx("span",{className:"lan-end-runs",children:ge}),W&&n.shareActive===!1&&i.jsx("span",{className:"lan-end-note",children:"current account hidden"})]}),i.jsxs("p",{className:"lan-end","data-side":"there",children:[i.jsx("span",{className:"lan-end-name",children:e.name}),e.kind!=="dialling"&&i.jsxs("span",{className:"lan-end-runs",children:[pe??(z?"not said":de),ke?` · ${ke<0?"older":"newer"}`:null]}),tt&&i.jsx("span",{className:"lan-end-note",children:"current account hidden"}),Ge&&i.jsx("span",{className:"lan-end-note",children:"on another account"})]})]}),i.jsxs("div",{className:"lan-link",children:[i.jsx(t_,{}),i.jsxs("span",{className:"lan-span",children:[i.jsxs("span",{className:"lan-wire","aria-hidden":!0,children:[i.jsx("i",{className:"lan-glint","data-dir":"out"}),i.jsx("i",{className:"lan-glint","data-dir":"in"})]}),i.jsx("span",{className:"lan-link-label",children:ae?i.jsx("code",{className:"ap-lan-code",children:ae}):"none here — it calls this deck"})]}),i.jsx(t_,{}),(ae&&We||Te)&&i.jsxs("p",{className:"lan-link-sub",children:[ae&&We,ae&&We&&Te&&" · ",Te&&(Pe?Qe?i.jsx("code",{className:"ap-lan-code",children:Ae}):i.jsx("span",{className:"lan-round","data-tone":Pe.tone,children:Pe.text.replace(/ · now$/," · just now")}):"not asked yet"),Te&&Ae&&!Qe&&i.jsx("code",{className:"lan-fact-raw",children:Ae})]}),at.length>0&&i.jsx("ul",{className:"lan-done",children:at.map(fe=>i.jsxs("li",{"data-ok":fe.ok,children:[fe.email," ",i.jsx("span",{className:"lan-done-what",children:fe.ok?"arrived":"did not arrive"})]},`${fe.email}:${fe.action}`))}),$e&&i.jsx("p",{className:"lan-note lan-link-note",children:$e}),(I==null?void 0:I.waiting)&&i.jsx("p",{className:"lan-note lan-link-note",children:e.hint})]}),Je.length>0&&i.jsx("ul",{className:"lan-lanes",role:"list","aria-label":`Logins between this deck and ${e.name}`,children:Je.map((fe,nt)=>{const Tt=ce.get(fe.email),Sn=fe.out==="live"||fe.in!=null&&fe.in!=="cut";return i.jsxs("li",{role:"listitem",className:"lan-lane","data-tone":fe.tone,"data-draw":fe.in&&fe.out?"both":fe.in?"in":"out","data-used-there":fe.usedThere||void 0,style:{"--i":nt},children:[i.jsx("i",{className:"lan-pip","data-end":"here","data-state":fe.here,"aria-hidden":!0}),i.jsxs("span",{className:"lan-track",children:[i.jsxs("span",{className:"lan-wire","data-flow":Sn?"live":"cut","aria-hidden":!0,children:[(fe.in==="live"||fe.in==="wait")&&i.jsx("i",{className:"lan-glint","data-dir":"in","data-tone":fe.in}),fe.out==="live"&&i.jsx("i",{className:"lan-glint","data-dir":"out"})]}),fe.in&&fe.in!=="cut"&&i.jsx(jd,{dir:"in",gate:fe.in==="blocked"}),fe.out==="live"&&i.jsx(jd,{dir:"out"}),i.jsx("span",{className:"lan-lane-email",children:fe.email})]}),i.jsx("i",{className:"lan-pip","data-end":"there","data-state":fe.there,"aria-hidden":!0}),i.jsx("span",{className:"vis-hidden",children:Z8(fe)}),(fe.caption||Tt)&&i.jsxs("span",{className:"lan-lane-note",children:[fe.caption,fe.caption&&Tt&&" · ",Tt&&i.jsx("span",{className:"lan-lane-done","data-ok":Tt.ok,children:Tt.ok?"arrived last round":"did not arrive last round"})]})]},fe.key)})},P),W&&i.jsxs(i.Fragment,{children:[ye.length>0&&i.jsxs("p",{className:"lan-spent",children:["Paired decks get nothing from ",ye.length===1?ye[0].email:"the expired ones"," until you sign in again here."]}),ut&&i.jsx("p",{className:"lan-empty",children:ut}),rt&&i.jsxs("p",{className:"lan-stale",children:["As of ",rt==="now"?"just now":rt,", when it last answered."]}),i.jsxs("div",{className:"lan-legend",children:[Ce&&i.jsxs("span",{className:"lan-key",children:[i.jsx("span",{className:"lan-key-wire","data-dir":"in","aria-hidden":!0,children:i.jsx(jd,{dir:"in"})}),"from ",e.name]}),Ve?i.jsxs("span",{className:"lan-key",children:[i.jsx("span",{className:"lan-key-wire","data-dir":"out","aria-hidden":!0,children:i.jsx(jd,{dir:"out"})}),"from this deck, to every paired deck"]}):i.jsx("span",{className:"lan-key",children:"This deck offers nothing yet."}),i.jsx("button",{type:"button",className:"ap-lan-word lan-legend-act",onClick:h,"aria-label":"Change what this deck offers",children:"change"})]})]})]}),i.jsx("dl",{className:"lan-facts",children:st.map(fe=>i.jsxs("div",{className:"lan-fact","data-tone":fe.tone,children:[i.jsx("dt",{children:fe.label}),i.jsx("dd",{children:fe.value})]},fe.label))}),jt.length>1&&i.jsxs("div",{className:"modal-section",children:[i.jsxs("h3",{className:"lan-h",children:[jt.length," decks on this machine"]}),i.jsx("ul",{className:"lan-twins",role:"list",children:jt.map((fe,nt)=>{var hn,jn,Ht,$n;const Tt=(hn=fe.peer)!=null&&hn.addr?`${fe.peer.addr}:${fe.peer.port}`:fe.row.addr,Sn=Tt||fe.row.fp,dn=(jn=fe.peer)!=null&&jn.pairedAt?hs(fe.peer.pairedAt,a):null,ir=[($n=(Ht=fe.peer)==null?void 0:Ht.about)!=null&&$n.version?`runs ${fe.peer.about.version}`:null,dn?`paired ${dn==="now"?"just now":dn}`:null,fe.row.state].filter(Boolean).join(" · "),It=fe.row.fp;return i.jsxs("li",{role:"listitem",className:"lan-twin","data-tone":fe.row.tone,children:[i.jsx("i",{className:fe.row.here?"ap-pulse":"ap-dot","aria-hidden":!0}),Tt?i.jsx("code",{className:"ap-lan-code lan-twin-at",children:Tt}):i.jsx("span",{className:"lan-twin-at lan-twin-none",children:"no address here"}),i.jsx("code",{className:"ap-lan-code lan-twin-fp",children:It}),nt>0&&y&&i.jsx("button",{type:"button",className:`ap-manage-btn danger lan-twin-do${R===It?" armed":""}`,...Z(`unpair:${It}`),onKeyDown:Yn=>{Yn.repeat&&Yn.preventDefault()},onClick:()=>{if(R!==It){$(It),T.current=Date.now();return}Date.now()-T.current<oh||($(null),V(()=>y(It)))},"aria-label":R===It?`Confirm unpairing ${Sn}`:`Unpair ${Sn}`,title:R===It?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this one of the machine's decks",children:l===`unpair:${It}`?"unpairing…":R===It?"confirm":"unpair"}),i.jsx("span",{className:"lan-twin-meta",children:nt===0?`${ir} · shown above`:ir})]},It)})})]})]}),i.jsxs("footer",{className:"lan-peer-foot",children:[e.kind==="asks"&&i.jsx("p",{className:"lan-foot-note",children:"This deck is now asking to pair. Answer it from the panel behind this."}),W&&!(I!=null&&I.waiting)&&i.jsx("button",{type:"button",className:"btn",...Z(`check:${e.fp}`),onClick:()=>void V(f).then(fe=>{fe&&J.current&&K(nt=>nt+1)}),title:"Ask this deck now instead of waiting for the next round",children:l===`check:${e.fp}`?"Checking…":"Check now"}),e.kind==="paired"&&i.jsx("button",{type:"button",className:`btn danger lan-peer-verb${E?" armed":""}`,...Z(`unpair:${e.fp}`),onKeyDown:fe=>{fe.repeat&&fe.preventDefault()},onClick:()=>{if(!E){C(!0),T.current=Date.now();return}Date.now()-T.current<oh||(C(!1),V(p))},"aria-label":E?`Confirm unpairing ${e.name}`:`Unpair ${e.name}`,title:E?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this deck from now on",children:l===`unpair:${e.fp}`?"Unpairing…":E?"Confirm unpair":"Unpair"}),e.kind==="nearby"&&i.jsx("button",{type:"button",className:"btn primary lan-peer-verb",...Z(`accept:${e.fp}`),onClick:()=>void V(p),title:"Send it a request. Somebody at that machine has to accept it before anything is shared.",children:l===`accept:${e.fp}`?"Asking…":"Ask to pair"}),e.kind==="dialling"&&i.jsx("button",{type:"button",className:"btn lan-peer-verb",...Z(`drop:${e.fp}`),onClick:()=>void V(p),title:"Stop trying this address. Nothing was ever paired here.",children:l===`drop:${e.fp}`?"Stopping…":"Stop dialling"}),e.kind==="declined"&&i.jsx("button",{type:"button",className:"btn lan-peer-verb",...Z(`allow:${e.fp}`),onClick:()=>void V(p),title:"Take the no back. That deck is still trying, so its request comes round again on its own.",children:l===`allow:${e.fp}`?"Allowing…":"Let it ask again"})]})]})}),document.body)}function J8(e){if(!e.running)return`Tailscale is ${e.state==="Stopped"?"turned off":e.state==="NeedsLogin"||e.state==="NeedsMachineAuth"?"signed out":e.state==="Starting"?"still starting":"not answering"} on this machine`;const t=e.login??"your Tailscale account";return e.on?`${e.devices} online · ${t}`:t}function eB({status:e,accounts:t,onClose:n,onChanged:r}){const a=un(n),[l,c]=x.useState(null),[u,f]=x.useState(null),[p,h]=x.useState(!1),[m,y]=x.useState(null),w=x.useRef(null),_=X=>{const J=La(m,X);return{disabled:J.disabled,"aria-busy":J.busy}},N=x.useRef(null),j=x.useRef(!0);x.useEffect(()=>()=>{j.current=!1},[]),x.useEffect(()=>{N.current&&iB(N.current,e.shared??[])&&(N.current=null)},[e.shared]);const b=x.useCallback(async(X,J,M="write")=>{w.current=M,y(M);try{const V=await(await fetch("/api/prefs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lan:X})})).json().catch(()=>null);return j.current?(V!=null&&V.ok?f(null):f(tn(J,V)),r(),(V==null?void 0:V.ok)===!0):!1}catch{return j.current&&f(tn(J,null)),!1}finally{w.current=null,j.current&&y(null)}},[r]),S=x.useCallback(async()=>{if(l!=null&&l!==(e.name??"")){if(!await b({name:l},"save the name","name"))return;j.current&&c(null)}n()},[l,e.name,b,n]),E=async()=>{if(!e.fp)return;const X=await Eh(e.fp);if(j.current){if(!X){f("Could not copy it — select the fingerprint and copy it by hand.");return}h(!0),window.setTimeout(()=>{j.current&&h(!1)},1600)}},C=new Set(N.current??e.shared??[]),T=e.autoAsk!==!1,R=e.autoAccept!==!1,$=e.shareActive!==!1,H=e.tailscale??null,B=!!(H!=null&&H.on),P=(H==null?void 0:H.ask)!==!1,K=(H==null?void 0:H.accept)!==!1;return Kn.createPortal(i.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:i.jsxs("div",{ref:a,className:"modal lan-modal",onClick:X=>X.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-modal-title",children:[i.jsxs("header",{className:"modal-head",children:[i.jsx("div",{className:"modal-title",children:i.jsx("span",{id:"lan-modal-title",className:"modal-tool-name",children:"This deck on the network"})}),i.jsx("div",{className:"modal-actions",children:i.jsx("button",{className:"glyph-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),i.jsxs("section",{className:"modal-body",children:[u&&i.jsxs("div",{className:"ap-failure",role:"alert",children:[i.jsx("span",{className:"ap-failure-text",children:u}),i.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>f(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),i.jsxs("div",{className:"modal-section",children:[i.jsx("h3",{className:"lan-h",children:"Name"}),i.jsxs("div",{className:"ap-lan-row",children:[i.jsx("span",{className:"ap-lan-label",children:"appear as"}),i.jsx("input",{className:"ap-manage-input ap-lan-input","aria-label":"This deck's name on the network",value:l??e.name??"",placeholder:"this machine",onChange:X=>c(X.target.value),onKeyDown:X=>{X.key!=="Enter"||l==null||(b({name:l},"save the name","name"),c(null))}}),l!=null&&l!==(e.name??"")&&i.jsx("button",{type:"button",className:"ap-manage-btn",..._("name"),onClick:()=>{b({name:l},"save the name","name"),c(null)},title:"Save it. This is the name other decks show for this one.",children:"save"})]}),i.jsxs("div",{className:"ap-lan-row",children:[i.jsx("span",{className:"ap-lan-label",children:"fingerprint"}),e.fp?i.jsxs("span",{className:"lan-fp",children:[i.jsx("code",{className:"ap-lan-code",children:e.fp}),i.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void E(),"aria-label":p?"Fingerprint copied":"Copy this deck's fingerprint",children:p?"copied":"copy"})]}):i.jsx("span",{className:"ap-lan-label",children:"not known yet"})]})]}),i.jsxs("div",{className:"modal-section",children:[i.jsx("h3",{className:"lan-h",children:"Share these accounts"}),i.jsxs("div",{className:"ap-lan-picks",children:[t.length===0&&i.jsx("span",{className:"ap-lan-empty",children:"No Claude accounts on this deck yet — add one with + at the top of this panel."}),t.map(X=>i.jsxs("label",{className:"ap-lan-pick",title:X.alive?"Offer this account to the decks you have paired with, so one whose copy has died can heal from yours. Unticking stops it being offered from now on; it does not take back a copy somebody already has.":"This deck cannot use this login, so it has nothing to offer — a deck that can will heal it",children:[i.jsx("input",{type:"checkbox",checked:C.has(X.key),onChange:J=>{const M=new Set(N.current??e.shared??[]);J.target.checked?M.add(X.key):M.delete(X.key),N.current=[...M],b({shared:[...M]},J.target.checked?"share that account":"stop sharing that account")}}),i.jsx("span",{className:"ap-lan-pick-name",children:X.email}),!X.alive&&i.jsx("span",{className:"ap-lan-dead",children:"not working here"})]},X.key))]}),t.length>0&&i.jsxs("div",{className:"lan-switch",children:[i.jsx("span",{className:"lan-switch-what",children:"Show paired decks which of these this deck is using"}),i.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":$,"aria-label":"Show paired decks which of these this deck is using",..._("current"),onClick:()=>void b({shareActive:!$},$?"stop showing which account this deck is using":"show which account this deck is using","current"),title:$?"Stop telling paired decks which account this one is on. They read “current account hidden” instead.":"Tell paired decks which of the ticked accounts this one is on. An unticked account is never named.",children:i.jsx("span",{className:"switch-knob"})})]})]}),i.jsxs("div",{className:"modal-section",children:[i.jsx("h3",{className:"lan-h",children:"Pairing"}),i.jsxs("div",{className:"lan-switches",children:[i.jsxs("div",{className:"lan-switch",children:[i.jsx("span",{className:"lan-switch-what",children:"Ask every deck this one finds"}),i.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":T,"aria-label":"Ask every deck this one finds",..._("ask"),onClick:()=>void b({autoAsk:!T},T?"stop asking automatically":"ask every deck this one finds","ask"),title:T?"Stop sending requests on their own. You press ask on the row instead.":"Send a pairing request to every deck heard on this network. Somebody over there still has to say yes.",children:i.jsx("span",{className:"switch-knob"})})]}),i.jsxs("div",{className:"lan-switch",children:[i.jsx("span",{className:"lan-switch-what",children:"Say yes to every deck that asks"}),i.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":R,"aria-label":"Say yes to every deck that asks","data-tone":"warn",..._("accept"),onKeyDown:X=>{X.repeat&&X.preventDefault()},onClick:()=>void b({autoAccept:!R},R?"stop accepting automatically":"accept every deck that asks","accept"),title:R?"Stop saying yes for you. A deck that asks waits in the panel again.":"Say yes for you. Every deck on this network that asks is paired without anybody being asked here.",children:i.jsx("span",{className:"switch-knob"})})]})]})]}),(H==null?void 0:H.found)&&i.jsxs("div",{className:"modal-section",children:[i.jsx("h3",{className:"lan-h",children:"Tailscale"}),i.jsxs("div",{className:"lan-switches",children:[i.jsxs("div",{className:"lan-switch",children:[i.jsxs("span",{className:"lan-switch-what",children:["Look for my devices",i.jsx("span",{id:"lan-ts-detail",className:"lan-switch-detail",children:J8(H)})]}),i.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":B,"aria-label":"Look for my devices over Tailscale","aria-describedby":"lan-ts-detail",..._("tailscale"),onClick:()=>void b({tailscale:!B},B?"stop looking over Tailscale":"look for your devices over Tailscale","tailscale"),title:B?"Stop. Nothing is looked for or answered over the tailnet; decks already paired stay paired.":"Find the decks on your other machines on Tailscale, wherever they are. Only machines signed in to your Tailscale account are asked.",children:i.jsx("span",{className:"switch-knob"})})]}),B&&i.jsxs(i.Fragment,{children:[i.jsxs("div",{className:"lan-switch",children:[i.jsx("span",{className:"lan-switch-what",children:"Ask each device it finds"}),i.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":P,"aria-label":"Ask each of my devices it finds over Tailscale",..._("tailscale-ask"),onClick:()=>void b({tailscaleAsk:!P},P?"stop asking your devices automatically":"ask your devices automatically","tailscale-ask"),title:P?"Stop sending requests on their own. You press ask on the row instead.":"Send a pairing request to every deck found on your devices over Tailscale.",children:i.jsx("span",{className:"switch-knob"})})]}),i.jsxs("div",{className:"lan-switch",children:[i.jsx("span",{className:"lan-switch-what",children:"Say yes to each device that asks"}),i.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":K,"aria-label":"Say yes to my devices when they ask over Tailscale","data-tone":"warn",..._("tailscale-accept"),onKeyDown:X=>{X.repeat&&X.preventDefault()},onClick:()=>void b({tailscaleAccept:!K},K?"stop accepting your devices automatically":"accept your devices automatically","tailscale-accept"),title:K?"Stop saying yes for you. A device that asks waits in the panel again.":"Say yes for you when a deck on one of your own devices asks. Anybody else on the tailnet still waits for a press.",children:i.jsx("span",{className:"switch-knob"})})]})]})]})]})]}),i.jsxs("footer",{className:"lan-setup-foot",children:[i.jsx("span",{className:"lan-foot-note",children:"Changes are saved as you make them."}),i.jsx("button",{type:"button",className:"btn primary",..._("name"),onClick:()=>void S(),children:"Done"})]})]})}),document.body)}function hs(e,t){if(e==null)return"not seen";const n=Math.max(0,Math.round((t-e)/1e3));if(n<90)return"now";const r=Math.round(n/60);if(r<60)return`${r}m ago`;const a=Math.round(r/60);return a<48?`${a}h ago`:`${Math.round(a/24)}d ago`}const F0={"waiting for the other deck to accept this one":{text:"waiting for them to say yes",tone:"idle"},"that deck said no":{text:"it said no",tone:"bad"}},tB={ECONNREFUSED:"not listening",EHOSTUNREACH:"no route to it",ENETUNREACH:"no network here",ETIMEDOUT:"no answer",ECONNRESET:"it hung up",EHOSTDOWN:"it is down",ENOTFOUND:"name not found",EACCES:"blocked here",EPIPE:"it hung up"};function nB(e){var r;const t=rB[e];if(t)return t;const n=(r=/\b(E[A-Z]{3,})\b/.exec(e))==null?void 0:r[1];return n&&tB[n]||e}const rB={"handshake timed out":"no answer","peer closed the connection":"it hung up","peer went quiet":"it stopped mid-sentence","bad reply":"it answered with nonsense","no manifest":"it would not say what it has","bad challenge":"it answered as somebody else","a different deck is answering at that address":"a different deck is at that address","that deck could not prove its own key":"it could not prove who it is","the other deck refused this one's proof":"it would not take this deck's word","the other deck refused this handshake":"it turned this deck away","that deck has this one pinned under a different key":"it knows this deck by another key"};function FR(e,t){if(!e)return null;if(e.error)return F0[e.error]??{text:nB(e.error),tone:"bad"};const n=e.done??[];if(!n.length)return{text:`all logins fine · ${hs(e.at,t)}`,tone:"idle"};const r=n.filter(l=>l.ok),a=r.length===1?"login":"logins";return r.length===n.length?{text:`${r.length} ${a} arrived · ${hs(e.at,t)}`,tone:"ok"}:{text:`${r.length} of ${n.length} logins arrived · ${hs(e.at,t)}`,tone:"bad"}}const sB=9e4;function aB({error:e,host:t,port:n},r,a,l=45317){if(e!=="handshake timed out")return null;const c=(t??"").trim();if(!c)return null;const u=r.filter(p=>p.addr===c&&p.port&&p.at>0&&a-p.at<sB);if(!u.length)return null;const f=[...new Set(u.map(p=>p.port))];if(n!=null&&!f.includes(n)){const p=f.length===1?`port ${f[0]}`:`ports ${f.join(" and ")}`;return`A deck at ${c} is announcing itself on ${p}, not on ${n}. This deck already hears it and dials it there, so this typed row has nothing to reach.`}return`That machine is running the deck — its beacon arrives here every half minute — and what this deck sends back never gets there. That is a firewall on ${c}, not a network fault. Whoever uses it can allow two ports: UDP ${l} and TCP ${n??f[0]}.`}const Hx=5e3,qR=6e4,oh=400;function oB(e){const t=(e??"").trim(),n=t.lastIndexOf(":");if(n<=0||n===t.length-1)return null;const r=t.slice(0,n).trim(),a=Number(t.slice(n+1).trim());return!r||!Number.isInteger(a)||a<1||a>65535||r.includes(":")&&!(r.startsWith("[")&&r.endsWith("]"))?null:{addr:r,port:a}}function tn(e,t){return t==null?`Could not ${e} — the deck did not answer.`:t.reason?`Could not ${e} — the deck refused it (${t.reason}).`:`Could not ${e}.`}function iB(e,t){if(e.length!==t.length)return!1;const n=new Set(e);return t.every(r=>n.has(r))}function lB(e,t){const n=Math.max(0,Math.round((e-t)/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function BR(e,t){var n,r;return(n=e.last)!=null&&n.error&&!F0[e.last.error]?!1:!!((r=e.last)!=null&&r.at&&t-e.last.at<ih||e.lastSeen!=null&&t-e.lastSeen<ih)}const ih=95e3,zR=160,cB=6,HR=140;function uB(e,t){const n=[],r=[];for(const a of e??[])(BR(a,t)?n:r).push(a);return{online:n,offline:r}}function dB(e){var t;return(t=e.tailscale)!=null&&t.exitNode?"Tailscale sends this machine's local network through an exit node, so decks on this network cannot find this one. Turn on Allow local network access in Tailscale's exit node menu to bring them back.":"This machine sends its local network through a VPN, so decks on this network cannot find this one. Allowing local network access in the VPN brings them back."}function hB(e,t){if(!e)return{text:"checking…",tone:"idle"};if(!e.enabled)return{text:"",tone:"idle"};if(e.stalled)return{text:`could not start — ${e.stalled}`,tone:"bad"};if(!e.running)return{text:"starting…",tone:"wait"};const n=(e.pending??[]).length;if(n)return{text:n===1?"1 deck is waiting for your answer":`${n} decks are waiting for your answer`,tone:"wait"};const r=(e.peers??[]).filter(w=>w.paired!==!1||w.met);if(!r.length)return{text:"no deck paired yet",tone:"idle"};const a=r.filter(w=>w.waiting),l=r.filter(w=>!w.waiting),c=a.filter(w=>{var _;return!((_=w.last)!=null&&_.error)&&w.lastSeen!=null&&t-w.lastSeen<ih}),{online:u,offline:f}=uB(l,t),p=[...f,...a.filter(w=>!c.includes(w))],h=u.length+c.length,m=u.filter(w=>{var _;return((_=w.last)==null?void 0:_.error)==="waiting for the other deck to accept this one"});if(h&&m.length===h)return{text:h===1?"1 deck found · waiting for them to accept":`${h} decks found · waiting for them to accept`,tone:"wait"};if(!h)return{text:p.length===1?"this deck cannot reach the one it is paired with":`this deck cannot reach any of its ${p.length} decks`,tone:"bad"};const y=h===1?"1 deck ready":`${h} decks ready`;return{text:p.length?`${y} · ${p.length} away`:y,tone:"ok"}}function fB(e,t,n){if(n)return"checking…";if(e==null)return"not checked yet";const r=hs(e,t);return r==="now"?"checked just now":`checked ${r}`}function q0(e,t){const n=Math.max(0,Math.round((t-e)/1e3));if(n<90)return"just now";const r=Math.round(n/60);return r<60?`${r}m ago`:`${Math.round(r/60)}h ago`}function pB(e,t){if(e==null)return{text:"one-way · has not called yet",here:!1};const n=t-e<ih;return{text:n?"online · one-way, it calls in":`one-way · last online ${hs(e,t)}`,here:n}}function n_(e,t,n){return t?"online":e.lastSeen!=null?`last online ${hs(e.lastSeen,n)}`:e.waiting?"has not called yet":"never reached"}function mB(e,t){var y,w,_,N,j;if(!e)return[];const n=[],r=new Set,a=(b,S)=>b.name.localeCompare(S.name,void 0,{numeric:!0}),l=e.aliases??{},c=(b,S)=>{const E=b?l[b]:void 0;return E&&E!==S?{name:E,self:S}:{name:S}};for(const b of e.pending??[]){if(!(b!=null&&b.fp)||r.has(b.fp))continue;r.add(b.fp);const S=c(b.fp,b.name||b.fp);n.push({fp:b.fp,name:S.name,...S.self?{self:S.self}:{},addr:b.addr??"",kind:"asks",state:`wants to pair · ${q0(b.at,t)}`,tone:"wait",here:!0,hint:`${S.name} at ${b.addr}${b.via==="tailscale"?", over Tailscale,":""} is waiting for an answer.`,...b.via==="tailscale"?{via:"tailscale"}:{}})}const u=[],f=[];for(const b of e.peers??[]){const S=b.peerFp??b.fp;if(!S||r.has(S))continue;r.add(S);const E=FR(b.last,t),C=BR(b,t),T=b.addr?`${b.addr}:${b.port}`:"";if(!b.paired&&b.manual&&!b.met){f.push({fp:T,name:T||b.name||S,addr:b.addr??"",kind:"dialling",state:E?E.text.replace(/ · .*$/,""):"trying…",tone:E?E.tone:"idle",here:!1,hint:(y=b.last)!=null&&y.error?`Nothing has answered at ${T} yet — ${b.last.error}.`:`Dialling ${T} until something answers.`,...b.via==="tailscale"?{via:"tailscale"}:{}});continue}const R=b.waiting?pB(b.lastSeen,t):null,$=R?R.here:C,H=!R&&E?$?`online · ${E.text.replace(/ · .*$/,"")}`:`${E.text.replace(/ · .*$/,"")} · ${n_(b,$,t)}`:R?R.text:n_(b,$,t),B=(w=b.last)!=null&&w.error?F0[b.last.error]:null,P=!R&&$&&!((_=b.last)!=null&&_.error)&&!(((N=b.last)==null?void 0:N.done)??[]).length,K=b.manual&&!b.met?{name:T}:c(S,b.name||S);u.push({fp:S,name:K.name,...K.self?{self:K.self}:{},addr:b.addr??"",kind:"paired",state:H,quiet:P,tone:B?B.tone==="bad"?"bad":"wait":E?E.tone:$?"ok":"idle",here:R?R.here:C,...b.via==="tailscale"?{via:"tailscale"}:{},hint:R?`${K.name} calls this deck, and this deck has no address to call back on — so it can repair its logins from here, and this deck cannot repair from it. ${b.lastSeen==null?"It has not called since this deck started.":`It last called ${hs(b.lastSeen,t)}.`} Add its address with the + at the top of this section to reach it either way.`:`${K.name}${T?` at ${T}`:""}${(j=b.last)!=null&&j.error?` — ${b.last.error}`:""}`})}n.push(...gB(u).sort(a),...f.sort(a));const p=[];for(const b of e.strangers??[]){if(!(b!=null&&b.fp)||r.has(b.fp))continue;r.add(b.fp);const S=c(b.fp,b.name||b.fp);p.push({fp:b.fp,name:S.name,...S.self?{self:S.self}:{},addr:b.addr??"",kind:"nearby",state:"not paired yet",tone:"idle",here:!0,hint:b.via==="tailscale"?`${S.name} at ${b.addr} is on your tailnet and nothing is shared with it.`:`${S.name} at ${b.addr} is on this network and nothing is shared with it.`,...b.via==="tailscale"?{via:"tailscale"}:{}})}n.push(...p.sort(a));const h=[];for(const b of e.declined??[]){if(!(b!=null&&b.fp)||r.has(b.fp))continue;r.add(b.fp);const S=c(b.fp,b.name||b.fp);h.push({fp:b.fp,name:S.name,...S.self?{self:S.self}:{},addr:b.addr??"",kind:"declined",state:"you said no",tone:"idle",here:!1,hint:`${S.name} asked and was turned away. It is not asking any more.`})}n.push(...h.sort(a));const m=new Map;for(const b of n)m.set(b.name,(m.get(b.name)??0)+1);for(const b of n)(m.get(b.name)??0)<2||!b.addr||(b.state=b.quiet||!b.state?b.addr:`${b.addr} · ${b.state}`,b.quiet=!1);return n}function gB(e){const t=new Map;for(const r of e){const a=t.get(r.name);a?a.push(r):t.set(r.name,[r])}const n=[];for(const r of t.values()){const a=[...new Set(r.filter(l=>l.addr).map(l=>l.addr))];if(a.length>1){for(const l of a)n.push(r_(r.filter(c=>c.addr===l)));n.push(...r.filter(l=>!l.addr))}else n.push(r_(r))}return n}function r_(e){const[t,...n]=[...e].sort((r,a)=>Number(a.here)-Number(r.here)||+!!a.addr-+!!r.addr);return n.length?{...t,twins:n}:t}function s_(e,t){return t?e.map(n=>t[n.fp]?{...n,name:t[n.fp]}:n):e}function a_(e,t){if(!e)return{};switch(t.kind){case"paired":return{peer:(e.peers??[]).find(n=>(n.peerFp??n.fp)===t.fp)??null};case"dialling":return{peer:(e.peers??[]).find(n=>n.manual&&!n.met&&`${n.addr}:${n.port}`===t.fp)??null};case"nearby":return{stranger:(e.strangers??[]).find(n=>n.fp===t.fp)??null};case"declined":return{stranger:(e.declined??[]).find(n=>n.fp===t.fp)??null};case"asks":return{stranger:(e.pending??[]).find(n=>n.fp===t.fp)??null}}}function yB(e,t){const n=/^(\d+)\.(\d+)\.(\d+)/.exec(e??""),r=/^(\d+)\.(\d+)\.(\d+)/.exec(t??"");if(!n||!r)return null;for(let a=1;a<=3;a++){const l=Number(n[a])-Number(r[a]);if(l)return Math.sign(l)}return 0}function wB(e,t,n){const r=t?t.alive?"works here":"expired here":"not on this deck";if(!e.alive){const a=t&&!t.alive?"neither copy works — sign in again here":null;return{there:"broken there",here:r,note:a,tone:a?"bad":"idle"}}return t?t.alive?{there:"works there",here:r,note:null,tone:"ok"}:n?{there:"works there",here:r,note:"repairs next round",tone:"wait"}:{there:"works there",here:r,note:"share it to repair",tone:"bad"}:{there:"works there",here:r,note:"arrives next round",tone:"wait"}}function vB(e,t,n,r=null){const a=new Map(t.map(f=>[f.key,f])),l=new Set(n),c=[],u=new Set;for(const f of e??[]){if(u.has(f.key))continue;u.add(f.key);const p=a.get(f.key)??null,h=l.has(f.key),m=wB(f,p,h),y=p?p.alive?"works":"expired":"missing",w=!f.alive&&p&&!p.alive?m.note:[y==="works"?null:m.here,f.alive?null:m.there,m.note].filter(Boolean).join(" · ")||null;c.push({key:f.key,email:f.email,here:y,there:f.alive?"works":"broken",in:f.alive?m.tone==="wait"?"wait":m.tone==="bad"?"blocked":"live":"cut",out:h&&p?p.alive?"live":"cut":null,caption:w,tone:m.tone,usedThere:r===f.key})}for(const f of n){const p=a.get(f);!p||u.has(f)||(u.add(f),c.push({key:f,email:p.email,here:p.alive?"works":"expired",there:"unknown",in:null,out:p.alive?"live":"cut",caption:p.alive?null:"expired here",tone:p.alive?"ok":"bad",usedThere:!1}))}return c}async function Li(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}function xB({anchorId:e,id:t,rows:n,onHold:r,onLet:a}){const l=x.useRef(null),c=n.filter(y=>y.kind==="paired"),u=c.filter(y=>y.here),f=u.slice(0,cB),p=c.length-u.length,h=u.length>f.length?`and ${u.length-f.length} more`:p>0?`${p} not on right now`:null,m=x.useCallback(()=>{const y=l.current,w=document.getElementById(e);if(!y||!w)return;const _=O0(w.getBoundingClientRect(),{width:y.offsetWidth,height:y.offsetHeight},{width:window.innerWidth,height:window.innerHeight});y.style.top=`${_.top}px`,y.style.left=`${_.left}px`,y.style.maxHeight=_.maxHeight==null?"":`${_.maxHeight}px`,y.dataset.side=_.side},[e]);return x.useLayoutEffect(()=>{m()}),x.useEffect(()=>(window.addEventListener("scroll",m,!0),window.addEventListener("resize",m),()=>{window.removeEventListener("scroll",m,!0),window.removeEventListener("resize",m)}),[m]),Kn.createPortal(i.jsxs("div",{ref:l,id:t,className:"ap-peek",role:"tooltip",onPointerEnter:r,onPointerLeave:a,children:[i.jsx("p",{className:"ap-peek-title",children:u.length?"On the network now":"Nobody on the network"}),f.length>0&&i.jsx("div",{className:"ap-peek-list",children:f.map(y=>i.jsxs("span",{className:"ap-peek-who",children:[i.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),i.jsxs("span",{children:[y.name,y.via==="tailscale"&&i.jsx("span",{className:"ap-lan-via",children:" · Tailscale"})]})]},`${y.kind}:${y.fp}`))}),h&&i.jsx("p",{className:"ap-peek-rest",children:h})]}),document.body)}function bB(e,t){var l;if(!e)return{text:"checking…",tone:"idle",live:!1};if(!e.enabled)return{text:"Off",tone:"idle",live:!1};if(e.stalled)return{text:"could not start",tone:"bad",live:!1};if(!e.running)return{text:"starting…",tone:"wait",live:!1};const n=t.filter(c=>c.kind==="asks").length;if(n)return{text:n===1?"1 deck wants to pair":`${n} decks want to pair`,tone:"wait",live:!1};if((l=e.reach)!=null&&l.blocked)return{text:"nothing can get in",tone:"bad",live:!1};const r=t.filter(c=>c.kind==="paired");if(!r.length)return{text:"On · none paired yet",tone:"idle",live:!1};const a=r.filter(c=>c.here).length;return a?a===r.length?{text:`${a} online`,tone:"ok",live:!0}:{text:`${a} of ${r.length} online`,tone:"ok",live:!0}:{text:`none of ${r.length} online`,tone:"idle",live:!1}}function kB({accounts:e,onChanged:t,view:n,onOpen:r,onBack:a,closeButton:l}){const[c,u]=x.useState(null),[f,p]=x.useState([]),[h,m]=x.useState(null),[y,w]=x.useState(!1),[_,N]=x.useState(null),j=x.useRef(0),[b,S]=x.useState(!1),[E,C]=x.useState(!1),[T,R]=x.useState(!1),$=x.useRef(0);x.useEffect(()=>()=>window.clearTimeout($.current),[]);const[H,B]=x.useState(!1),[P,K]=x.useState(null),X=x.useRef(null),J=x.useCallback(le=>Th(X.current)?(X.current=le,m(le),!0):!1,[]),M=x.useCallback(()=>{X.current=null,q.current&&m(null)},[]),Z=le=>{const Ne=La(h,le);return{disabled:Ne.disabled,"aria-busy":Ne.busy}},[V,I]=x.useState(()=>Date.now()),q=x.useRef(!0),W=x.useRef(Hx),G=x.useCallback(async()=>{var le,Ne;try{const[Me,tt]=await Promise.all([fetch("/api/lan").then(Ge=>Ge.json()),fetch("/api/prefs").then(Ge=>Ge.json())]);if(!q.current)return;Me!=null&&Me.ok&&u(Me),tt!=null&&tt.ok&&p(Array.isArray((Ne=(le=tt.prefs)==null?void 0:le.lan)==null?void 0:Ne.manual)?tt.prefs.lan.manual:[]),W.current=(Me==null?void 0:Me.enabled)===!0?Hx:qR}catch{}},[]);x.useEffect(()=>{q.current=!0;let le=0;const Ne=async()=>{I(Date.now()),await G(),q.current&&(le=window.setTimeout(Ne,W.current))};return Ne(),()=>{q.current=!1,window.clearTimeout(le)}},[G]);const F=x.useCallback(async()=>{const le=(c==null?void 0:c.enabled)===!0;if(J("switch"))try{const Ne=await Li("/api/prefs",{lan:{enabled:!le}});if(!q.current)return;Ne!=null&&Ne.ok?(K(null),le||w(!0)):K(tn(le?"turn this off":"turn this on",Ne)),await G()}catch{q.current&&K(tn(le?"turn this off":"turn this on",null))}finally{M()}},[c==null?void 0:c.enabled,G,J,M]),D=x.useCallback(async(le,Ne,Me)=>{if(!J(`${le}:${Ne}`))return null;let tt=null;try{const Ge=await Li("/api/lan/peer",{action:le,fp:Ne});if(!q.current)return null;Ge!=null&&Ge.ok?(u(Ge),K(null)):(tt=tn(Me,Ge),K(tt)),await G()}catch{tt=tn(Me,null),q.current&&K(tt)}finally{M()}return tt},[G,J,M]),ae=x.useCallback(async le=>{if(!J(`drop:${le}`))return null;let Ne=null;try{const Me=await Li("/api/prefs",{lan:{manual:f.filter(tt=>tt!==le)}});if(!q.current)return null;Me!=null&&Me.ok?(K(null),t()):(Ne=tn("stop dialling that address",Me),K(Ne)),await G()}catch{Ne=tn("stop dialling that address",null),q.current&&K(Ne)}finally{M()}return Ne},[f,G,t,J,M]),[z,Q]=x.useState(null),U=x.useCallback(async(le,Ne)=>{if(!J(`alias:${le}`))return"Something else is still being saved. Try again in a moment.";try{const Me=await Li("/api/lan/peer",{action:"alias",fp:le,name:Ne});return q.current?Me!=null&&Me.ok?(u(Me),null):tn("rename that deck",Me):null}catch{return tn("rename that deck",null)}finally{M()}},[J,M]),re=x.useCallback(async le=>{if(!J(`check:${le}`))return null;try{const Ne=await Li("/api/lan/sync",{fp:le});return q.current?Ne!=null&&Ne.ok?(u(Ne),t(),null):(Ne==null?void 0:Ne.reason)==="no_address"?"There is no address here to call it on. It calls this deck, and it is up to date each time it does.":tn("check that deck",Ne):null}catch{return tn("check that deck",null)}finally{M()}},[J,M,t]),de=x.useCallback(async()=>{if(J("check"))try{const le=await Li("/api/lan/sync",{});if(!q.current)return;le!=null&&le.ok?(u(le),K(null)):K(tn("check the other decks",le)),t()}catch{q.current&&K(tn("check the other decks",null))}finally{M()}},[J,M,t]),ge=(c==null?void 0:c.enabled)===!0,pe=mB(c,V),ke=z?pe.find(le=>{var Ne;return le.fp===z||((Ne=le.twins)==null?void 0:Ne.some(Me=>Me.fp===z))})??null:null;x.useEffect(()=>{z&&c&&!ke&&Q(null)},[z,c,ke]);const Pe=pe.filter(le=>le.kind==="asks"),$e=pe.filter(le=>le.kind!=="asks"),Ae=$e.filter(le=>le.here),je=$e.filter(le=>!le.here),Qe=je.filter(le=>le.tone==="bad").length,Te=H||Ae.length===0,Se=hB(c,V),We=$e.filter(le=>le.kind==="paired").length,dt=bB(c,pe),ct=i.jsxs(i.Fragment,{children:[b&&c&&i.jsx(W8,{status:c,manual:f,onClose:()=>S(!1),onChanged:()=>{G(),t()}}),E&&i.jsx(PR,{title:"How Local network works",steps:D8,finish:ge?void 0:{label:"Turn it on",act:()=>{C(!1),F()}},onClose:()=>C(!1)}),y&&c&&i.jsx(eB,{status:{...c,manualRows:f},accounts:e,manual:f,onClose:()=>w(!1),onChanged:()=>{G(),t()}}),ke&&c&&i.jsx(Q8,{row:ke,source:a_(c,ke),status:c,accounts:e,now:V,busy:h,onClose:()=>Q(null),onRename:le=>U(ke.fp,le),onCheck:()=>re(ke.fp),onVerb:()=>{switch(ke.kind){case"paired":return D("unpair",ke.fp,"unpair that deck");case"nearby":return D("accept",ke.fp,"reach that deck");case"declined":return D("allow",ke.fp,"let that deck ask again");case"dialling":return ae(ke.fp);default:return Promise.resolve(null)}},onSettings:()=>{Q(null),w(!0)},twins:(ke.twins??[]).map(le=>({row:le,peer:a_(c,le).peer??null})),onUnpair:le=>D("unpair",le,"unpair that deck")})]});if(!n){const le=Ge=>{window.clearTimeout($.current),$.current=window.setTimeout(()=>R(!0),Ge)},Ne=()=>{window.clearTimeout($.current),$.current=window.setTimeout(()=>R(!1),HR)},Me=()=>window.clearTimeout($.current),tt=()=>{window.clearTimeout($.current),R(!1)};return i.jsxs("div",{className:"ap-foot",children:[i.jsxs("button",{type:"button",id:"ap-lan-entry",className:"ap-nav",onClick:()=>{tt(),r()},"aria-describedby":T?"ap-lan-peek":void 0,onPointerEnter:Ge=>{Ge.pointerType==="mouse"&&le(zR)},onPointerLeave:Ne,onFocus:Ge=>{Ge.target.matches(":focus-visible")&&le(0)},onBlur:Ne,children:[i.jsxs("svg",{className:"ap-nav-glyph",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("rect",{x:"1.8",y:"2.3",width:"10.4",height:"7.2",rx:"1.2"}),i.jsx("path",{d:"M5 11.9h4M7 9.5v2.4"})]}),i.jsxs("span",{className:"ap-nav-text",children:[i.jsx("span",{className:"ap-nav-name",children:"Local network"}),i.jsxs("span",{className:"ap-nav-state","data-tone":dt.tone,children:[dt.live&&i.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),dt.text]})]}),i.jsx("svg",{className:"ap-nav-chev",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:i.jsx("path",{d:"M5.6 3.4 9.2 7l-3.6 3.6"})})]}),T&&i.jsx(xB,{anchorId:"ap-lan-entry",id:"ap-lan-peek",rows:pe,onHold:Me,onLet:Ne}),i.jsx("p",{className:"vis-hidden",role:"status",children:Se.tone==="ok"?"":Se.text}),ct]})}return i.jsxs("div",{className:"ap-lan-view",children:[i.jsxs("div",{className:"ap-header",children:[i.jsx("button",{type:"button",id:"ap-lan-back",className:"glyph-btn ap-back",onClick:a,"aria-label":"Back to Claude accounts",title:"Back to Claude accounts",children:i.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:i.jsx("path",{d:"M8.4 3.4 4.8 7l3.6 3.6"})})}),i.jsx("h2",{id:"ap-lan-title",children:"Local network"}),i.jsxs("div",{className:"ap-header-right",children:[ge&&i.jsx("button",{type:"button",className:"glyph-btn ap-lan-plus",onClick:()=>S(!0),"aria-label":"Add a deck",title:"Reach a deck that has not turned up on its own — by address, or with an invite",children:i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M6.1 7.9a2.6 2.6 0 0 0 3.7 0l1.9-1.9a2.6 2.6 0 0 0-3.7-3.7l-.9.9"}),i.jsx("path",{d:"M7.9 6.1a2.6 2.6 0 0 0-3.7 0L2.3 8a2.6 2.6 0 0 0 3.7 3.7l.9-.9"})]})}),ge&&We>0&&i.jsx("button",{type:"button",className:"glyph-btn ap-lan-check",...Z("check"),onClick:()=>void de(),"aria-label":h==="check"?"Checking every paired deck":"Check every paired deck now",title:"Ask every paired deck now for anything this deck's expired logins need, instead of waiting for the next round",children:i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("circle",{cx:"7",cy:"7",r:"1.1",fill:"currentColor",stroke:"none"}),i.jsx("path",{d:"M4.6 4.6a3.4 3.4 0 0 0 0 4.8M9.4 4.6a3.4 3.4 0 0 1 0 4.8"}),i.jsx("path",{d:"M2.6 2.6a6.2 6.2 0 0 0 0 8.8M11.4 2.6a6.2 6.2 0 0 1 0 8.8"})]})}),ge&&i.jsx("button",{type:"button",className:"glyph-btn ap-lan-set",...Z("setup"),onClick:()=>w(!0),"aria-label":"This deck's name and shared logins",title:"This deck's name on the network, and which of its logins it offers",children:i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M1.8 4.7h10.4M1.8 9.3h10.4"}),i.jsx("circle",{cx:"9.1",cy:"4.7",r:"1.6",fill:"var(--panel)"}),i.jsx("circle",{cx:"4.9",cy:"9.3",r:"1.6",fill:"var(--panel)"})]})}),l]})]}),i.jsx("div",{className:"ap-scroll",id:"ap-lan-scroll",children:i.jsxs("div",{className:"ap-lan",children:[i.jsxs("div",{className:"ap-policy",children:[i.jsx("h3",{className:"ap-auto-title",children:"Sync with paired decks"}),i.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":ge,"aria-label":"Sync with paired decks",...Z("switch"),onClick:()=>void F(),title:ge?"Stop talking to other decks. Nothing is shared while this is off.":"Let the decks you pair with repair this one's expired logins",children:i.jsx("span",{className:"switch-knob"})})]}),ge&&i.jsx(DR,{reach:c==null?void 0:c.reach,where:"panel"}),ge&&(c==null?void 0:c.deaf)&&i.jsx("p",{className:"ap-lan-fine",children:c.deaf}),ge&&(c==null?void 0:c.lanTunneled)&&i.jsx("p",{className:"ap-lan-fine",children:dB(c)}),!ge&&i.jsxs("button",{type:"button",className:"ap-lan-intro",onClick:()=>C(!0),title:"Four pictures: what this does, and what to do on each machine",children:[i.jsx(F8,{}),i.jsx("span",{className:"ap-lan-intro-text",children:"Paired machines repair each other's expired logins."}),i.jsx("span",{className:"ap-lan-intro-go",children:"See how it works"})]}),i.jsx("p",{className:`ap-lan-status ${Se.tone}`,role:"status",children:Se.tone==="ok"?"":Se.text}),P&&i.jsxs("div",{className:"ap-failure",role:"alert",children:[i.jsx("span",{className:"ap-failure-text",children:P}),i.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>K(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),ge&&i.jsxs(i.Fragment,{children:[Pe.length>0&&i.jsx("div",{className:"ap-lan-asks",role:"alert",children:Pe.map(le=>i.jsxs("div",{className:"ap-lan-ask",children:[i.jsxs("span",{className:"ap-lan-ask-what",children:[i.jsx("strong",{className:"ap-lan-peer-name",children:le.name})," at ",i.jsx("code",{className:"ap-lan-code",children:le.addr})," wants to pair"]}),i.jsxs("span",{className:"ap-lan-ask-fp",children:["fingerprint ",i.jsx("code",{className:"ap-lan-code",children:le.fp})]}),i.jsxs("span",{className:"ap-lan-ask-acts",children:[i.jsx("button",{type:"button",className:"ap-manage-btn",...Z(`accept:${le.fp}`),onClick:()=>void D("accept",le.fp,"accept that deck"),title:`Talk to this deck from now on. Its fingerprint is ${le.fp} — check it matches the one on their screen before you accept.`,children:"accept"}),i.jsx("button",{type:"button",className:"ap-manage-btn",...Z(`dismiss:${le.fp}`),onClick:()=>void D("dismiss",le.fp,"decline that request"),title:"Say no. Nothing is shared, and that deck is told rather than left waiting.",children:"decline"})]})]},le.fp))}),(Te?[...Ae,...je]:Ae).length>0&&i.jsx("ul",{className:"ap-lan-here",children:(Te?[...Ae,...je]:Ae).map((le,Ne)=>i.jsxs("li",{className:"ap-lan-who","data-tone":le.tone,children:[i.jsx("i",{className:le.here?"ap-pulse":"ap-dot","aria-hidden":!0}),i.jsxs("span",{className:"ap-lan-who-name","aria-hidden":!0,children:[le.name,le.via==="tailscale"&&i.jsx("span",{className:"ap-lan-via",children:" · Tailscale"})]}),i.jsx("button",{type:"button",className:"ap-lan-who-open","aria-haspopup":"dialog","aria-describedby":`lan-who-state-${Ne}`,onClick:()=>Q(le.fp),children:i.jsxs("span",{className:"vis-hidden",children:[le.name,le.via==="tailscale"?", over Tailscale":"",", details"]})}),i.jsx("span",{id:`lan-who-state-${Ne}`,className:le.quiet?"vis-hidden":"ap-lan-who-when",children:le.state}),le.kind==="nearby"&&i.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`accept:${le.fp}`),onClick:()=>void D("accept",le.fp,"reach that deck"),"aria-label":`Ask ${le.name} to pair`,title:`Send ${le.name} a request. Somebody at that machine has to accept it before anything is shared. Its fingerprint is ${le.fp}.`,children:"ask"}),le.kind==="paired"&&i.jsx("button",{type:"button",className:`ap-manage-btn ap-lan-do danger${_===le.fp?" armed":""}`,...Z(`unpair:${le.fp}`),onClick:()=>{if(_!==le.fp){N(le.fp),j.current=Date.now(),window.setTimeout(()=>N(Me=>Me===le.fp?null:Me),4e3);return}Date.now()-j.current<oh||(N(null),D("unpair",le.fp,"unpair that deck"))},"aria-label":_===le.fp?`Confirm unpairing ${le.name}`:`Unpair ${le.name}`,title:_===le.fp?"Press again to stop talking to this deck. Logins it already has stay with it.":"Stop talking to this deck from now on",children:_===le.fp?"confirm":"unpair"}),le.kind==="dialling"&&i.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`drop:${le.fp}`),onClick:()=>void ae(le.fp),"aria-label":`Stop dialling ${le.name}`,title:"Stop trying this address. Nothing was ever paired here.",children:"stop"}),le.kind==="declined"&&i.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...Z(`allow:${le.fp}`),onClick:()=>void D("allow",le.fp,"let that deck ask again"),"aria-label":`Let ${le.name} ask again`,title:"Take the no back. That deck is still trying, so the request comes round again on its own.",children:"allow"})]},`${le.kind}:${le.fp}`))}),(Ae.length>0&&je.length>0||ge&&We>0)&&i.jsxs("div",{className:"ap-lan-tail",children:[Ae.length>0&&je.length>0&&i.jsxs("button",{type:"button",className:"ap-lan-word ap-lan-more","aria-expanded":H,onClick:()=>B(le=>!le),title:H?"Show only the decks that are on":`Show the ${je.length} deck${je.length===1?"":"s"} that are not responding right now`,children:[i.jsx("span",{className:`ap-lan-chev${H?" open":""}`,"aria-hidden":!0,children:"›"}),H?"fewer":`${je.length} more`,!H&&Qe>0&&i.jsxs("span",{className:"ap-lan-more-bad",children:[" · ",Qe," not responding"]})]}),ge&&We>0&&i.jsx("span",{className:"ap-lan-checked",children:fB(c==null?void 0:c.checkedAt,V,h==="check")})]}),$e.length===0&&Pe.length===0&&!(c!=null&&c.stalled)&&!(c!=null&&c.deaf)&&!(c!=null&&c.lanTunneled)&&i.jsxs(i.Fragment,{children:[i.jsx("p",{className:"ap-lan-fine",children:"No other deck yet. Decks on one network usually find each other on their own; when that has not happened, the link at the top of this view reaches one by address or by invite."}),i.jsx("button",{type:"button",className:"ap-lan-word ap-lan-how",onClick:()=>C(!0),children:"How it works"})]})]})]})}),ct]})}function NB({anchorId:e,id:t,peers:n,onHold:r,onLet:a}){const l=x.useRef(null),{title:c,shown:u,rest:f}=_8(n),p=x.useCallback(()=>{const h=l.current,m=document.getElementById(e);if(!h||!m)return;const y=O0(m.getBoundingClientRect(),{width:h.offsetWidth,height:h.offsetHeight},{width:window.innerWidth,height:window.innerHeight});h.style.top=`${y.top}px`,h.style.left=`${y.left}px`,h.style.maxHeight=y.maxHeight==null?"":`${y.maxHeight}px`,h.dataset.side=y.side},[e]);return x.useLayoutEffect(()=>{p()}),x.useEffect(()=>(window.addEventListener("scroll",p,!0),window.addEventListener("resize",p),()=>{window.removeEventListener("scroll",p,!0),window.removeEventListener("resize",p)}),[p]),Kn.createPortal(i.jsxs("div",{ref:l,id:t,className:"ap-peek ap-fold-peek",role:"tooltip",onPointerEnter:r,onPointerLeave:a,children:[i.jsx("p",{className:"ap-peek-title",children:c}),i.jsx("div",{className:"ap-peek-list",children:u.map(h=>i.jsxs("span",{className:"ap-peek-who ap-fold-who",children:[i.jsx("span",{className:"ap-fold-name",children:h.name}),i.jsx("span",{className:"ap-fold-state","data-tone":h.ready?"ok":h.warn?"warn":"idle",children:h.ready?h.headroom==null?"not read yet":`${h.headroom}% free`:h.why})]},h.key))}),f&&i.jsx("p",{className:"ap-peek-rest",children:f})]}),document.body)}function _B({peers:e,strained:t,armed:n,threshold:r,open:a,onToggle:l}){const[c,u]=x.useState(!1),f=x.useRef(0);x.useEffect(()=>()=>window.clearTimeout(f.current),[]),x.useEffect(()=>{a&&(window.clearTimeout(f.current),u(!1))},[a]);const p=_=>{a||(window.clearTimeout(f.current),f.current=window.setTimeout(()=>u(!0),_))},h=()=>{window.clearTimeout(f.current),f.current=window.setTimeout(()=>u(!1),HR)},m=()=>window.clearTimeout(f.current),y=()=>{window.clearTimeout(f.current),u(!1)},w=k8(e,{strained:t&&!a,armed:n,threshold:r});return i.jsxs("div",{className:"ap-rest",children:[i.jsxs("button",{type:"button",id:"ap-rest-entry",className:"ap-nav","aria-expanded":a,"aria-controls":a?"ap-rest-panel":void 0,"aria-describedby":c?"ap-rest-peek":void 0,onClick:()=>{y(),l()},onPointerEnter:_=>{_.pointerType==="mouse"&&p(zR)},onPointerLeave:h,onFocus:_=>{_.target.matches(":focus-visible")&&p(0)},onBlur:h,children:[i.jsxs("span",{className:"ap-nav-text",children:[i.jsx("span",{className:"ap-nav-name",children:"Other accounts"}),i.jsx("span",{className:"ap-nav-state","data-tone":w.tone,children:w.text})]}),i.jsx("svg",{className:"ap-nav-chev",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:i.jsx("path",{d:"M5.6 3.4 9.2 7l-3.6 3.6"})})]}),c&&i.jsx(NB,{anchorId:"ap-rest-entry",id:"ap-rest-peek",peers:e,onHold:m,onLet:h})]})}async function SB(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const jB=1800;function EB({accounts:e,onClose:t,copyText:n}){const[r,a]=x.useState([]),[l,c]=x.useState(null),[u,f]=x.useState(!1),[p,h]=x.useState(null),[m,y]=x.useState(!1),[w,_]=x.useState(()=>Math.floor(Date.now()/1e3)),N=x.useRef(null),j=x.useRef(!1),b=un(t,{focusRef:N});x.useEffect(()=>{if(!l)return;_(Math.floor(Date.now()/1e3));const P=window.setInterval(()=>_(Math.floor(Date.now()/1e3)),1e3);return()=>window.clearInterval(P)},[l]);const S=m8(e),E=e.filter(P=>!r.includes(P.num)).map(P=>P.num),C=E.length===e.length,T=P=>a(K=>K.includes(P)?K.filter(X=>X!==P):[...K,P]),R=x.useCallback(async()=>{if(!Ls(j.current)||!E.length)return;j.current=!0,f(!0),h(null),y(!1);const P=await SB({action:"share",accounts:E}).catch(()=>null);if(j.current=!1,f(!1),!(P!=null&&P.ok)){h(Hi(P,"the share could not be made"));return}c({blob:P.blob,expiresAt:P.expiresAt,shared:P.shared??[],failed:P.failed??[]})},[e,E]),$=l?OR(l.expiresAt,w):null,H=($==null?void 0:$.tone)==="gone",B=(l==null?void 0:l.shared.length)??0;return Kn.createPortal(i.jsx("div",{className:"modal-backdrop",onClick:t,role:"presentation",children:i.jsxs("div",{ref:b,className:"modal sa-modal",onClick:P=>P.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Share accounts with another deck",children:[i.jsxs("header",{className:"modal-head",children:[i.jsx("div",{className:"modal-title",children:i.jsx("h3",{children:"Share accounts"})}),i.jsx("div",{className:"modal-actions",children:i.jsx("button",{type:"button",className:"glyph-btn",onClick:t,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),i.jsx("section",{className:"modal-body sa-body",children:l?i.jsxs("div",{className:"sa-step",children:[i.jsx("h4",{children:H?"This share has expired":B===1?"1 account, ready to paste":`${B} accounts, ready to paste`}),i.jsx("code",{className:`ap-share-blob${H?" sa-dead":""}`,children:l.blob}),i.jsxs("div",{className:"ap-share-foot",children:[i.jsx("button",{type:"button",className:"ap-manage-btn",ref:N,onClick:async()=>{if(H){c(null),R();return}await n(l.blob)&&(y(!0),window.setTimeout(()=>y(!1),jB))},children:H?"make a new share":m?"copied":`copy ${B===1?"the share":"all "+B}`}),i.jsxs("span",{className:"ap-manage-hint",title:"This text is the sign-in for every account in it. It is base64 of plain JSON — the expiry inside it is not signed, so anyone holding a copy can change it, and the logins themselves are in there in the clear either way. The countdown only says how long another deck's import dialog will still accept it. If a copy escapes, sign those accounts out and back in.",children:[i.jsx("span",{className:"ap-share-warn",children:B===1?"this is the password":`this is ${B} passwords`})," · ",i.jsx("span",{className:`ap-share-expiry ${$==null?void 0:$.tone}`,children:$==null?void 0:$.text})]})]}),l.failed.length>0&&i.jsxs("div",{className:"sa-failed",role:"alert",children:[i.jsx("p",{className:"sa-failed-head",children:l.failed.length===1?"One account is not in this bundle:":`${l.failed.length} accounts are not in this bundle:`}),i.jsx("ul",{className:"sa-list",children:l.failed.map(P=>{var X;const K=!!(P.email&&((X=P.detail)!=null&&X.includes(P.email)));return i.jsxs("li",{children:[!K&&i.jsx("span",{className:"sa-who",children:P.email||`account ${P.num}`}),i.jsx("span",{className:"sa-why",children:P.detail||"could not be exported"})]},`${P.num}-${P.email}`)})})]}),i.jsx("p",{className:"sa-note",children:H?i.jsx(i.Fragment,{children:"Another deck will refuse this text now. Make a new one — the same accounts are still picked."}):i.jsxs(i.Fragment,{children:["Paste it into the other deck with ",i.jsx("strong",{children:"+"})," → ",i.jsx("strong",{children:"Paste a share"}),". Accounts it already holds are left exactly as they are."]})}),i.jsxs("div",{className:"sa-actions",children:[i.jsx("button",{type:"button",className:"btn",onClick:()=>{c(null),y(!1)},children:"Pick again"}),i.jsx("button",{type:"button",className:"btn primary",onClick:t,children:"Done"})]})]}):e.length===0?i.jsxs("div",{className:"sa-step",children:[i.jsx("h4",{children:"Nothing to share"}),i.jsxs("p",{className:"sa-note",children:["This deck is not holding any accounts right now. Sign one in with ",i.jsx("strong",{children:"+"}),", or wait — the panel is still reading the store."]}),i.jsx("div",{className:"sa-actions",children:i.jsx("button",{type:"button",className:"btn primary",ref:N,onClick:t,children:"Close"})})]}):i.jsxs("div",{className:"sa-step",children:[i.jsxs("h4",{children:["Which accounts go to the other ",nn,"?"]}),i.jsx("p",{className:`sa-count${E.length?"":" empty"}`,children:g8(E.length)}),i.jsx("ul",{className:"sa-list sa-pick",children:S.map(P=>i.jsx("li",{children:i.jsxs("label",{className:"sa-row",children:[i.jsx("input",{type:"checkbox",checked:E.includes(P.num),onChange:()=>T(P.num)}),i.jsx("span",{className:"sa-who",children:P.label}),P.sub&&i.jsx("span",{className:"sa-sub",children:P.sub})]})},P.num))}),p&&i.jsx("p",{className:"aa-err",children:p}),i.jsxs("div",{className:"sa-actions",children:[i.jsx("button",{type:"button",className:"btn",onClick:()=>a(C?e.map(P=>P.num):[]),children:C?"Clear all":"Select all"}),i.jsx("button",{type:"button",className:"btn primary",ref:N,...Aa(u,!E.length),onClick:R,children:u?"making the share…":E.length===0?"Share":E.length===1?"Share 1 account":`Share ${E.length} accounts`})]})]})})]})}),document.body)}function CB(e,t){const n=new Set(e),r=e.length?Math.max(...e):0;return[...new Set([...e,r+1])].sort((a,l)=>a-l).map(a=>{const l=a===t?"here":n.has(a)?"swap":"free";return{slot:a,kind:l,label:l==="here"?`slot ${a}`:`slot ${a} · ${l}`}})}function TB(e,t,n){if(!(n!=null&&n.ok))return null;const r=Number.isInteger(n.to)?n.to:null;if(r==null)return{menuFor:null,confirmRemove:null,shareFor:null,swapNote:null};const a=n.swapped===!0&&r!==t;return{menuFor:e.menuFor===t?r:a&&e.menuFor===r?t:e.menuFor,confirmRemove:null,shareFor:null,swapNote:a?{at:r,displaced:t}:null}}function AB(e,t,n){return t!=null&&e.some(r=>r.slot===t)?t:n}function RB(e,t,n){var a;const r=((a=e.find(l=>l.slot===t))==null?void 0:a.kind)??"here";return r==="swap"?{label:"swap",done:"swapped",sends:!0,swaps:!0,title:`Send this account to slot ${t}. That slot is taken, so the two accounts trade places and the one standing there moves to slot ${n}.`}:r==="free"?{label:"move",done:"moved",sends:!0,swaps:!1,title:`Send this account to slot ${t}. That slot is empty, so no other account moves.`}:{label:"move",done:"here",sends:!1,swaps:!1,title:`This account already holds slot ${n}.`}}function MB(e,t){return{label:"save",done:"saved",sends:e!==t,swaps:!1,title:`Switch the active account out once it passes ${e}% of its limit.`}}function o_(e){return typeof e.id=="string"&&e.id.startsWith("scoped-")}function IB(e){const t=e.filter(u=>!o_(u)),n=e.filter(u=>o_(u)),r=t.length?t:n,a=t.length?n:[],l=r.reduce((u,f)=>u&&u.pct>=f.pct?u:f,null);let c=null;for(const u of a)l&&u.pct<=l.pct||(!c||u.pct>c.pct)&&(c=u);return{shown:r,rest:a,fuller:c,peak:c??l}}const $B="\0";function lh(e){const t=typeof e.email=="string"?e.email.trim():"";if(!t)return`slot:${e.num}`;const n=typeof e.org=="string"?e.org.trim():"";return`acct:${t}${$B}${n}`}function OB(e,t){const n=lh(t);return e.includes(n)?e.filter(r=>r!==n):[...e,n]}function PB(e,t){if(!Array.isArray(t))return e;const n=new Set(t.map(lh)),r=e.filter(a=>n.has(a));return r.length===e.length?e:r}const LB=64;function DB(e,t){const n=e.trim();return{alias:n,commit:n!==(t??"").trim()}}const FB=Object.freeze({text:"couldn't reach the deck server",reload:!0}),qB=Object.freeze({text:"still waiting on the deck server — claude-swap can be slow to answer",reload:!0});async function i_(e){return e.ok?{ok:!0,status:e.status,body:null}:{ok:!1,status:e.status,body:await e.json().catch(()=>null)}}function BB(e){const t=e.find(r=>!r.ok);if(!t)return null;const n=Lc(t.body);return{text:qx(t.body,`the deck server answered ${t.status}`),...n?{raw:n}:{},reload:!0}}function l_(e,t){return t?e!=null&&e.reload&&e.text===t.text&&e.raw===t.raw?e:t:e!=null&&e.reload?null:e}const c_=15e3,zB=8e3,HB=1800,WB=3e4,Dp=[70,80,85,90,95];function Fp(e,t){return gR(t-Math.floor(e/1e3))}function UB(e,t){if(!e)return"";const n=Math.floor(e/1e3)-t;return n<=0?" · due":n<60?` · next in ${n}s`:` · next in ${Math.round(n/60)}m`}function wc(e){return e.charAt(0).toUpperCase()+e.slice(1)}function VB(e,t){const n="The deck can still see this account — its live usage is being read — but claude-swap's own stored copy of the login was rejected, so these numbers stopped updating.";if((e==null?void 0:e.state)==="running")return{text:"resuming…",hint:`${n} The deck is re-capturing it from the login you already have. No sign-in, no switch.`};if((e==null?void 0:e.state)==="failed"){const r=Math.max(1,Math.ceil((e.retryAt/1e3-t)/60)),a=e.reason?`Re-capturing it from the login you already have did not work (${e.reason}).`:"The deck re-captured it from the login you already have, and claude-swap still cannot read it.";return{text:"numbers paused",hint:`${n} ${a} It tries again in ${r}m. No sign-in, no switch.`}}return{text:"numbers paused",hint:n}}function GB(e){switch(e){case"invalid_grant":case"no_refresh_token":return{text:"login expired",hint:"claude-swap's stored login for this account was rejected and cannot be refreshed. Signing in again replaces it — the account keeps its slot, its alias and its history.",fixable:!0};case"http-401":return{text:"re-login needed",hint:"Anthropic refused this account's token.",fixable:!0};case"http-429":return{text:"rate limited",hint:"Anthropic is throttling requests for this account. It clears on its own.",fixable:!1};case"transient":return{text:"temporary error",hint:"A network or server hiccup while reading usage. The next collection retries.",fixable:!1};case"timeout":return{text:"timed out",hint:"Reading this account's usage took too long. The next collection retries.",fixable:!1};case"network":return{text:"unreachable",hint:"Could not reach Anthropic to read this account's usage.",fixable:!1};default:return{text:e,hint:`claude-swap reported "${e}" for this account.`,fixable:!1}}}function KB(e){switch(e){case"no_credentials":return{text:"no stored login",hint:"claude-swap holds no credentials for this account, so there is nothing to read its usage with and nothing to switch to. A paired deck that has them sends them on its own; signing in as this account puts them there by hand.",fix:"sign in"};case"relogin_required":return{text:"login expired",hint:"claude-swap's stored login for this account was rejected and cannot be refreshed. Signing in again replaces it — the account keeps its slot, its alias and its history.",fix:"sign in again"};case"keychain_unavailable":return{text:"keychain unreadable",hint:"This is about the deck, not the account: claude-swap could not open your keychain, so it cannot read any account's stored login. A deck started from a background session cannot reach the keychain at all — start it from a terminal, or let it start at login, and this clears."};case"token_expired":return{text:"token expired",hint:"The access token ran out and the refresh was deferred. The next collection retries."};case"foreign_credential":return{text:"wrong credential",hint:"The live credential belongs to a different account. Switching to this one repairs it."};case null:case void 0:return null;default:return{text:e,hint:`claude-swap reported "${e}" for this account.`}}}function Ed(e,t){if(e.staleCopy){const n=VB(e.repair??null,t);return{text:wc(n.text),hint:n.hint,fix:null,tone:"quiet",blocksSwitch:!1}}if(e.stopped){const n=KB(e.collector??null);if(!n)return{text:"Not collecting",hint:"claude-swap has collected nothing for this account in over half a day and has not said why. A paired deck holding a working copy of this account will replace it on its own. To do it by hand, sign in as this account from + Add.",fix:null,tone:"quiet",blocksSwitch:!1};const r=e.collector==="no_credentials"||e.collector==="relogin_required";return{text:wc(n.text),hint:n.hint,fix:n.fix?wc(n.fix):null,tone:r||e.collector==="keychain_unavailable"?"warn":"quiet",blocksSwitch:r}}if(e.error){const n=GB(e.error);return{text:wc(n.text),hint:n.hint,fix:n.fixable?"Sign in again":null,tone:n.fixable?"warn":"quiet",blocksSwitch:n.fixable}}return null}function qp(){return i.jsxs("svg",{className:"ap-warn-glyph",width:"12",height:"12",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M7 1.9 12.9 12H1.1Z"}),i.jsx("path",{d:"M7 5.6v2.9"}),i.jsx("path",{d:"M7 10.3v.05"})]})}function YB(e){return e>=90?"hi":e>=70?"mid":void 0}function XB(e){const t=Number(e);return[...Number.isFinite(t)&&t>0&&!Dp.includes(t)?[...Dp,t]:Dp].sort((r,a)=>r-a)}function ZB({lane:e,nowSec:t,frozen:n}){const r=Math.min(100,Math.max(0,e.pct)),a=n?"var(--muted)":r>=90?"var(--err)":r>=70?"var(--warn)":"var(--accent)",l=e.resetAt&&!n?yR(e.resetAt,t):null;return i.jsxs("div",{className:"ap-lane",children:[i.jsx("span",{className:"ap-lane-label",title:e.label,children:e.label}),i.jsx("div",{className:"ap-lane-track",children:i.jsx("div",{className:"ap-lane-fill",style:{width:`${r===0?1.5:r}%`,background:a,opacity:r===0||n?.4:1}})}),i.jsxs("span",{className:"ap-lane-pct",style:{color:a},children:[r,"%"]}),i.jsx("span",{className:"ap-lane-reset",title:l?`${e.label} resets in ${l}`:void 0,children:l&&i.jsxs(i.Fragment,{children:[i.jsx("span",{className:"vis-hidden",children:"resets in "}),l]})})]})}async function u_(e){var n;let t=!1;try{t=await Promise.race([((n=navigator.clipboard)==null?void 0:n.writeText(e).then(()=>!0))??Promise.resolve(!1),new Promise(r=>window.setTimeout(()=>r(!1),500))])}catch{t=!1}if(t)return!0;try{const r=document.createElement("textarea");r.value=e,r.setAttribute("readonly",""),r.style.cssText="position:fixed;top:0;left:0;opacity:0",document.body.appendChild(r),r.select(),t=document.execCommand("copy"),r.remove()}catch{t=!1}return t}function QB({onClose:e,leaving:t}){var Hs,Ws,yn;const[n,r]=x.useState(null),[a,l]=x.useState(null),[c,u]=x.useState(null),[f,p]=x.useState(!1),[h,m]=x.useState(null),[y,w]=x.useState(null),[_,N]=x.useState("accounts"),[j,b]=x.useState(!1),[S,E]=x.useState(null),C=x.useRef(S);C.current=S;const[T,R]=x.useState(()=>Math.floor(Date.now()/1e3)),$=x.useRef(null),[H,B]=x.useState(null),P=(H==null?void 0:H.num)??null,K=x.useRef(H);K.current=H;const[X,J]=x.useState(null),[M,Z]=x.useState(!1),[V,I]=x.useState(""),[q,W]=x.useState(null),G=x.useRef(0),[F,D]=x.useState(null),[ae,z]=x.useState(!1),[Q,U]=x.useState(!1),[re,de]=x.useState(null),[ge,pe]=x.useState(null),[ke,Pe]=x.useState(null),[$e,Ae]=x.useState(!1),je=x.useRef(null),Qe=x.useRef(null),[Te,Se]=x.useState([]),[We,dt]=x.useState(!1),ct=x.useRef(null),le=x.useCallback(ee=>Th(ct.current)?(ct.current=ee,u(ee),!0):!1,[]),Ne=x.useCallback(()=>{ct.current=null,u(null)},[]),Me=(ee,Re=!1)=>{const Le=La(c,ee);return{disabled:Le.disabled,"aria-busy":Le.busy||Re}},tt=x.useCallback(ee=>{window.requestAnimationFrame(()=>{var Re;if(qN(((Re=document.activeElement)==null?void 0:Re.tagName)??null))for(const Le of HF(ee)){const Ie=document.querySelector(Le);if(Ie){Ie.focus();return}}})},[]),Ge=x.useCallback(async(ee=!1)=>{ee&&p(!0);const Re=new AbortController,Le=window.setTimeout(()=>Re.abort(),WB);try{const[Ie,ze]=await Promise.all([fetch(`/api/claude-accounts${ee?"?refresh=1":""}`,{signal:Re.signal}),fetch("/api/cswap-auto",{signal:Re.signal})]);if(Ie.ok){const Lt=await Ie.json();r(Lt),Se($t=>PB($t,Lt.accounts))}ze.ok&&l(await ze.json());const ht=BB([await i_(Ie),await i_(ze)]);m(Lt=>l_(Lt,ht))}catch{m(Ie=>l_(Ie,Re.signal.aborted?qB:FB))}finally{window.clearTimeout(Le),ee&&p(!1)}},[]),Je=x.useCallback(async(ee,Re,Le="panel")=>{if(!le(Re))return null;const Ie=Le==="menu"?J:m;Ie(null);try{const ze=await fetch("/api/cswap-auto",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(ee)}),ht=await ze.json().catch(()=>null);return ht!=null&&ht.ok||Ie({text:qx(ht,"command failed",ze.status),raw:Lc(ht)}),ht}catch{return Ie({text:"server unreachable"}),null}finally{Ne()}},[le,Ne]),ye=x.useCallback(async(ee,Re)=>{if(!le(Re))return null;m(null),J(null);try{const Le=await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(ee)}),Ie=await Le.json().catch(()=>null);return Ie!=null&&Ie.ok||J({text:Hi(Ie,"command failed",Le.status)}),Ie}catch{return J({text:"server unreachable"}),null}finally{Ne()}},[le,Ne]);x.useEffect(()=>(Ge(!0),$.current=window.setInterval(()=>Ge(!1),c_),()=>{$.current!=null&&window.clearInterval($.current)}),[Ge]),x.useEffect(()=>{const ee=window.setInterval(()=>R(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(ee)},[]);const Ce=((Hs=a==null?void 0:a.settings["autoswitch.threshold"])==null?void 0:Hs.value)??"90",Ve=ke??Ce,ce=MB(Ve,Ce),at=(Ws=n==null?void 0:n.accounts)==null?void 0:Ws.find(ee=>ee.active),ut=at?Ed(at,T):null,rt=(n==null?void 0:n.accounts)??[],st=at?rt.filter(ee=>!ee.active):[],jt=st.length?rt.filter(ee=>ee.active):rt,vt=st.map(ee=>{const Re=Ed(ee,T);return{key:lh(ee),name:ee.alias??ee.email??`account ${ee.num}`,ready:!ee.disabled&&!(Re!=null&&Re.blocksSwitch),why:ee.disabled?"held out":Re!=null&&Re.blocksSwitch?Re.text:null,warn:(Re==null?void 0:Re.tone)==="warn",headroom:ee.headroom}}),mt=Number(Ce),_n=(at==null?void 0:at.headroom)!=null&&Number.isFinite(mt)&&100-at.headroom>=mt,Et=(a==null?void 0:a.ok)===!0&&(a.enabled||a.external),zt=ee=>We&&st.some(Re=>Re.num===ee)?"ap-rest-list":"ap-scroll",fe=async(ee,Re)=>{if(le(`switch-${ee}`)){m(null),w(null);try{const Ie=await(await fetch("/api/claude-accounts/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({account:ee})})).json().catch(()=>null);Ie!=null&&Ie.ok?w({num:ee,name:Re}):m({text:qx(Ie,"the switch failed"),raw:Lc(Ie),row:ee}),await Ge(!0)}catch{m({text:"server unreachable",row:ee})}finally{Ne(),tt(ee)}}},nt=x.useCallback(()=>{B(null),J(null),W(null),D(null),U(!1)},[]),Tt=(ee,Re="first")=>{nt(),E(null),pe(null),B({num:ee,view:"menu",start:Re})},Sn=(ee,Re)=>{nt(),E(Le=>(Le==null?void 0:Le.anchor)===Re?null:{num:ee,anchor:Re})},dn=x.useCallback((ee=!1)=>{var Le;const Re=C.current;ee&&Re&&((Le=document.getElementById(Re.anchor))==null||Le.focus()),E(null)},[]),ir=()=>{nt(),E(null),N("lan")},It=x.useRef(_);x.useEffect(()=>{It.current!==_&&(It.current=_,window.requestAnimationFrame(()=>{var ee;(ee=document.getElementById(_==="lan"?"ap-lan-back":"ap-lan-entry"))==null||ee.focus()}))},[_]),x.useEffect(()=>{n!=null&&n.ok&&b(!0)},[n==null?void 0:n.ok]);const hn=x.useCallback(ee=>{var Ie,ze;const Re=K.current;if(!Re||ee!=null&&Re.num!==ee)return;const Le=document.getElementById(`ap-menu-${Re.num}`);(Le!=null&&Le.contains(document.activeElement)||qN(((Ie=document.activeElement)==null?void 0:Ie.tagName)??null))&&((ze=document.getElementById(`ap-more-${Re.num}`))==null||ze.focus()),nt()},[nt]);x.useEffect(()=>{t&&(nt(),E(null))},[t,nt]),x.useEffect(()=>{H&&(n!=null&&n.accounts)&&!n.accounts.some(ee=>ee.num===H.num)&&nt(),S&&(n!=null&&n.accounts)&&!n.accounts.some(ee=>ee.num===S.num)&&E(null)},[n,H,S,nt]);const jn=async ee=>{var Le;U(!1);const Re=await ye({action:"share",account:ee},`share-${ee}`);!(Re!=null&&Re.ok)||((Le=K.current)==null?void 0:Le.num)!==ee||(D({num:ee,blob:Re.blob,expiresAt:Re.expiresAt}),B({num:ee,view:"share"}))},Ht=async(ee,Re)=>{const{commit:Le,alias:Ie}=DB(V,Re);if(Le){const ze=await ye({action:"alias",account:ee,alias:Ie},`alias-${ee}`);if(await Ge(!0),!(ze!=null&&ze.ok))return}hn(ee)},$n=async(ee,Re)=>{var ze,ht;const Le=await ye({action:"move",account:ee,slot:Re},`move-${ee}`),Ie=TB({menuFor:((ze=K.current)==null?void 0:ze.num)??null,shareFor:(F==null?void 0:F.num)??null},ee,Le);if(await Ge(!0),Ie){((ht=K.current)==null?void 0:ht.num)===ee&&nt(),W(Ie.confirmRemove),Ie.shareFor==null&&(D(null),U(!1)),de(Ie.swapNote);const Lt=Ie.swapNote;Lt&&window.setTimeout(()=>de($t=>$t===Lt?null:$t),zB),pe(null),tt(Ie.menuFor)}return Le},Yn=async(ee,Re,Le)=>{if(!Le.sends){hn(ee);return}await $n(ee,Re)},On=async(ee,Re)=>{if(Re.sends){const Le=await Je({action:"setting",key:"autoswitch.threshold",value:ee},"threshold");if(await Ge(!0),!(Le!=null&&Le.ok))return;Pe(null)}Ae(!0),window.setTimeout(()=>{var Le;document.activeElement===Qe.current&&((Le=je.current)==null||Le.focus()),Ae(!1)},HB)},En=i.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close accounts panel",title:"Close (A)",children:i.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:i.jsx("path",{d:"M3.4 3.4l7.2 7.2M10.6 3.4l-7.2 7.2"})})}),_r=ee=>{const{shown:Re,fuller:Le}=IB(ee.lanes),Ie=Ed(ee,T),ze=ee.active||Te.includes(lh(ee)),ht=ee.alias??ee.email??`account ${ee.num}`,Lt=ee.stale||(Ie==null?void 0:Ie.blocksSwitch)===!0,$t=Le?[...Re,Le]:Re,Sr=ee.fetchedAt?Fp(ee.fetchedAt,T):null;return i.jsxs("li",{className:`ap-account${ee.active?" active":""}`,"aria-current":ee.active?"true":void 0,"data-open":ze?"":void 0,"data-frozen":Lt?"":void 0,children:[!ee.active&&i.jsx("button",{type:"button",className:"ap-row-open",id:`ap-row-${ee.num}`,"aria-expanded":ze,"aria-controls":ze?`ap-detail-${ee.num}`:void 0,"aria-describedby":!ze&&!(Ie!=null&&Ie.blocksSwitch)?`ap-quota-${ee.num}`:void 0,onClick:()=>Se(kt=>OB(kt,ee)),children:i.jsxs("span",{className:"vis-hidden",children:[ht,", ",ze?"hide details":"details"]})}),i.jsxs("div",{className:"ap-account-head",children:[ee.active?i.jsx("span",{className:"ap-live",title:`Active account · slot ${ee.num}`,children:i.jsxs("span",{className:"vis-hidden",children:["Active account, slot ",ee.num,":"]})}):i.jsx("span",{className:"ap-num",children:ee.num}),ee.alias&&i.jsx("span",{className:"ap-alias",title:ee.alias,children:ee.alias}),i.jsx("span",{className:"ap-email",title:ee.email??void 0,children:ee.email}),ee.disabled&&i.jsx("span",{className:"ap-held",children:"held out"}),!ee.active&&!ee.disabled&&!(Ie!=null&&Ie.blocksSwitch)&&i.jsx("button",{type:"button",className:"ap-switch",...Me(`switch-${ee.num}`),onClick:()=>fe(ee.num,ht),"aria-label":`Switch to ${ht}`,title:`Switch to ${ee.alias??ee.email}`,children:c===`switch-${ee.num}`?"…":"Switch"}),i.jsx("button",{type:"button",id:`ap-more-${ee.num}`,className:"ap-more","aria-label":`More actions for ${ee.email??ee.alias??`account ${ee.num}`}`,"aria-haspopup":"menu","aria-expanded":P===ee.num,"aria-controls":P===ee.num?`ap-menu-${ee.num}`:void 0,title:"More actions",onClick:()=>P===ee.num?hn():Tt(ee.num),onKeyDown:kt=>{kt.key!=="ArrowDown"&&kt.key!=="ArrowUp"||(kt.preventDefault(),Tt(ee.num,kt.key==="ArrowUp"?"last":"first"))},children:i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"currentColor","aria-hidden":!0,children:[i.jsx("circle",{cx:"2.8",cy:"7",r:"1.15"}),i.jsx("circle",{cx:"7",cy:"7",r:"1.15"}),i.jsx("circle",{cx:"11.2",cy:"7",r:"1.15"})]})})]}),(h==null?void 0:h.row)===ee.num&&i.jsxs("div",{className:"ap-failure ap-row-failure",role:"alert",children:[i.jsx("span",{className:"ap-failure-text",title:h.raw||void 0,children:h.text}),i.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),ee.active&&(y==null?void 0:y.num)===ee.num&&i.jsx("p",{className:"ap-switched",children:"Now active. New sessions start on it; ones already running pick it up on their next message, up to about 30 seconds later on macOS."}),(re==null?void 0:re.at)===ee.num&&(()=>{const kt=rt.find(Us=>Us.num===re.displaced),xt=(kt==null?void 0:kt.alias)??(kt==null?void 0:kt.email)??"the account that was there";return i.jsxs("p",{className:"ap-note ap-swap-note",title:`Slot ${re.at} was taken, so the two accounts traded places: ${xt} now holds slot ${re.displaced}.`,children:["swapped with slot ",re.displaced]})})(),Ie&&i.jsxs("div",{className:"ap-issue-line",children:[i.jsxs("button",{type:"button",id:`ap-issue-${ee.num}`,className:"ap-issue","data-tone":Ie.tone,"aria-haspopup":"dialog","aria-expanded":(S==null?void 0:S.anchor)===`ap-issue-${ee.num}`,"aria-controls":(S==null?void 0:S.anchor)===`ap-issue-${ee.num}`?"ap-issue-pop":void 0,onClick:()=>Sn(ee.num,`ap-issue-${ee.num}`),children:[Ie.tone==="warn"&&i.jsx(qp,{}),i.jsx("span",{className:"ap-issue-text",children:Ie.text})]}),!ze&&i.jsx("span",{className:"ap-issue-age",title:"When claude-swap last read this account's usage",children:Sr??"never collected"})]}),!ze&&!(Ie!=null&&Ie.blocksSwitch)&&i.jsxs("p",{className:"ap-quota",id:`ap-quota-${ee.num}`,children:[$t.length?$t.map(kt=>i.jsxs("span",{className:"ap-q",children:[i.jsx("span",{className:"ap-q-label",children:kt.label})," ",i.jsxs("span",{className:"ap-q-pct","data-level":Lt?void 0:YB(kt.pct),children:[Math.round(kt.pct),"%"]})]},kt.id)):i.jsx("span",{className:"ap-q-label",children:"no usage recorded yet"}),ee.stale&&!Ie&&i.jsx("span",{className:"ap-q-age","data-never":Sr?void 0:"",title:"When claude-swap last read this account's usage",children:Sr??"never collected"})]}),ze&&i.jsxs("div",{className:"ap-detail",id:`ap-detail-${ee.num}`,children:[i.jsx("div",{className:"ap-lanes",children:ee.lanes.length?ee.lanes.map(kt=>i.jsx(ZB,{lane:kt,nowSec:T,frozen:Lt},kt.id)):i.jsx("div",{className:"ap-hint",children:"No usage recorded yet."})}),i.jsx("div",{className:"ap-meta",children:ee.fetchedAt?i.jsxs("span",{className:`ap-age${ee.stale&&!Ie?" ap-stale":""}`,title:"When claude-swap last read this account's usage, and when it plans to read it again. It sets that interval itself — 3 minutes at the fastest, wider while an account is recovering from a rate limit — and every surface, including `cswap watch`, follows the same plan.",children:["collected ",Fp(ee.fetchedAt,T),Ie!=null&&Ie.blocksSwitch?"":UB(ee.nextAt,T)]}):i.jsx("span",{className:"ap-age ap-stale",title:"claude-swap has not read this account yet",children:"never collected"})})]})]},ee.num)},Kr=n!=null&&n.ok&&(a!=null&&a.ok)?i.jsxs("div",{className:"ap-policy-block",children:[i.jsxs("div",{className:"ap-policy",children:[i.jsx("h3",{className:"ap-auto-title",children:"Auto-switch"}),i.jsx("span",{className:"ap-field",title:"Switch once the active account passes this much of its limit",children:i.jsx("select",{ref:je,"aria-label":"Switch threshold",value:Ve,...Me("threshold"),onChange:ee=>Pe(ee.target.value),children:XB(Ce).map(ee=>i.jsxs("option",{value:ee,children:[ee,"%"]},ee))})}),(ce.sends||$e)&&i.jsx("button",{ref:Qe,type:"button",className:"ap-manage-btn",...Me("threshold"),title:ce.title,onClick:()=>On(Ve,ce),children:$e&&!ce.sends?ce.done:ce.label}),i.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":a.enabled,"aria-label":"Auto-switch",...Me("enable"),onClick:()=>Je({action:"enable",enabled:!a.enabled},"enable").then(()=>Ge(!0)),title:a.enabled?"Stop switching accounts automatically":"Switch accounts automatically when the active one nears its limit",children:i.jsx("span",{className:"switch-knob"})})]}),a.external&&i.jsxs("p",{className:"ap-auto-note",children:[i.jsx("i",{className:"ap-pulse","aria-hidden":!0})," A ",i.jsx("code",{children:"cswap auto"})," loop in your terminal is doing the switching. The deck stands down while it runs",a.enabled?" — this toggle takes over when you stop it.":"."]})]}):null;return i.jsxs("aside",{className:`accounts-panel${t?" leaving":""}`,id:"accounts-panel","aria-label":"Claude accounts",children:[_==="accounts"&&i.jsxs("div",{className:"ap-header",children:[i.jsx("h2",{children:"Claude accounts"}),i.jsxs("div",{className:"ap-header-right",children:[i.jsx("button",{type:"button",className:"glyph-btn ap-add",onClick:()=>Z(!0),"aria-label":"Add an account",title:"Sign in to another Claude account, or paste one shared from another deck",children:i.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:i.jsx("path",{d:"M7 2.2v9.6M2.2 7h9.6"})})}),(((yn=n==null?void 0:n.accounts)==null?void 0:yn.length)??0)>0&&i.jsx("button",{type:"button",className:"glyph-btn",onClick:()=>z(!0),"aria-label":"Share accounts with another deck",title:`Copy several accounts to another ${nn} in one paste. The text carries a live login for each one — treat it as those passwords.`,children:i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M3.3 10.7L10.7 3.3"}),i.jsx("path",{d:"M5.5 3.3h5.2v5.2"})]})}),i.jsx("button",{type:"button",className:"glyph-btn ap-refresh",onClick:()=>Ge(!0),...Me("reload",f),"aria-label":"Reload accounts",title:"Reload from claude-swap",children:i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M11.6 6.2A4.8 4.8 0 1 0 11 9.6"}),i.jsx("path",{d:"M11.9 2.6v3.7h-3.6"})]})}),En]})]}),_==="accounts"&&i.jsx("div",{className:"ap-scroll",id:"ap-scroll",children:n==null?h?i.jsxs("div",{className:"ap-empty",role:"alert",children:[i.jsx("span",{title:h.raw||void 0,children:h.text}),i.jsxs("span",{className:"ap-hint",children:["No accounts have arrived, so there is nothing to show yet. The panel keeps trying every ",c_/1e3," seconds."]}),i.jsx("button",{type:"button",className:"ap-fix",disabled:f,onClick:()=>Ge(!0),children:f?"trying…":"try again"})]}):i.jsx("div",{className:"ap-empty",children:"Checking…"}):n.ok?i.jsxs(i.Fragment,{children:[at&&(ut==null?void 0:ut.tone)==="warn"&&i.jsxs("div",{className:"ap-notice",children:[i.jsxs("button",{type:"button",id:"ap-notice",className:"ap-issue","data-tone":"warn","aria-haspopup":"dialog","aria-expanded":(S==null?void 0:S.anchor)==="ap-notice","aria-controls":(S==null?void 0:S.anchor)==="ap-notice"?"ap-issue-pop":void 0,onClick:()=>Sn(at.num,"ap-notice"),children:[i.jsx(qp,{}),i.jsx("span",{className:"ap-issue-text",children:"Current account needs attention"})]}),ut.fix&&i.jsx("button",{type:"button",className:"ap-notice-fix",onClick:()=>Z(!0),title:"Open the sign-in dialog. Signing in as this account replaces its stored login in place.",children:"Sign in"})]}),i.jsx("ul",{className:"ap-list",children:jt.map(_r)}),st.length>0&&i.jsx(_B,{peers:vt,strained:_n,armed:Et,threshold:a!=null&&a.ok?Ce:null,open:We,onToggle:()=>dt(ee=>!ee)}),st.length>0&&We&&i.jsxs("div",{className:"ap-rest-panel",id:"ap-rest-panel",children:[i.jsx("ul",{className:"ap-list ap-others",id:"ap-rest-list",children:st.map(_r)}),Kr]}),st.length===0&&Kr,h&&h.row==null&&i.jsxs("div",{className:"ap-failure",role:"alert",children:[i.jsx("span",{className:"ap-failure-text",title:h.raw||void 0,children:h.text}),i.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),H&&(()=>{var Ie;const ee=(Ie=n.accounts)==null?void 0:Ie.find(ze=>ze.num===H.num);if(!ee)return null;const Re=`ap-pop-title-${ee.num}`,Le=X&&i.jsx("p",{className:"ap-pop-error",role:"alert",title:X.raw||void 0,children:X.text});return i.jsxs(Dx,{anchorId:`ap-more-${ee.num}`,boundaryId:zt(ee.num),id:`ap-menu-${ee.num}`,className:"ap-pop",role:H.view==="menu"?"menu":"dialog",labelledBy:H.view==="menu"?`ap-more-${ee.num}`:Re,start:H.start,onClose:nt,children:[H.view==="menu"&&i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{I(ee.alias??""),J(null),B({num:ee.num,view:"rename"})},children:"Rename"}),i.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{pe(null),J(null),B({num:ee.num,view:"move"})},children:"Move to slot…"}),i.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",...Me(`share-${ee.num}`),title:`Copy this account to another ${nn}. Anyone who has the text can use the account — treat it as the password. The other deck stops accepting it after 10 minutes; that does not make an escaped copy safe.`,onClick:()=>jn(ee.num),children:c===`share-${ee.num}`?"Sharing…":"Share"}),(((a==null?void 0:a.enabled)||(a==null?void 0:a.external))&&!ee.active||ee.disabled)&&i.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",...Me(`rot-${ee.num}`),title:ee.disabled?"Return this account to auto-rotation":"Hold this account out of auto-rotation",onClick:()=>Je({action:"account",account:ee.num,enabled:ee.disabled},`rot-${ee.num}`,"menu").then(ze=>{Ge(!0),ze!=null&&ze.ok&&hn(ee.num)}),children:ee.disabled?"Put back in rotation":"Hold out of rotation"}),i.jsx("div",{role:"separator",className:"ap-menu-sep"}),i.jsx("button",{type:"button",role:"menuitem",className:`ap-menu-item danger${q===ee.num?" armed":""}`,...Me(`rm-${ee.num}`),"aria-label":q===ee.num?"Confirm remove":void 0,title:q===ee.num?"This deletes the stored credentials for this account":"Remove this account from claude-swap",onClick:()=>{if(q!==ee.num){W(ee.num),G.current=Date.now(),window.setTimeout(()=>W(ze=>ze===ee.num?null:ze),4e3);return}Date.now()-G.current<oh||(W(null),ye({action:"remove",account:ee.num},`rm-${ee.num}`).then(ze=>{var ht;Ge(!0),ze!=null&&ze.ok&&(((ht=K.current)==null?void 0:ht.num)===ee.num&&nt(),tt(null))}))},children:c===`rm-${ee.num}`?"Removing…":q===ee.num?"Confirm":"Remove"}),Le]}),H.view==="rename"&&i.jsxs("form",{className:"ap-pop-form",onSubmit:ze=>{ze.preventDefault(),Ht(ee.num,ee.alias)},children:[i.jsx("label",{className:"ap-pop-title",id:Re,htmlFor:`ap-alias-${ee.num}`,children:"Rename account"}),i.jsx("input",{id:`ap-alias-${ee.num}`,className:"ap-manage-input",type:"text",value:V,onChange:ze=>I(ze.target.value),maxLength:LB,placeholder:"e.g. work",spellCheck:!1,autoComplete:"off",autoFocus:!0,onFocus:ze=>ze.currentTarget.select()}),Le,i.jsxs("div",{className:"ap-pop-actions",children:[i.jsx("button",{type:"button",className:"btn",onClick:()=>hn(),children:"Cancel"}),i.jsx("button",{type:"submit",className:"btn primary",...Me(`alias-${ee.num}`),title:"A short name to show instead of the email",children:c===`alias-${ee.num}`?"…":"Save"})]})]}),H.view==="move"&&(()=>{const ze=CB((n.accounts??[]).map($t=>$t.num),ee.num),ht=AB(ze,ge,ee.num),Lt=RB(ze,ht,ee.num);return i.jsxs("div",{className:"ap-pop-form",children:[i.jsx("label",{className:"ap-pop-title",id:Re,htmlFor:`ap-slot-${ee.num}`,children:"Move to slot"}),i.jsx("span",{className:"ap-field",children:i.jsx("select",{id:`ap-slot-${ee.num}`,value:String(ht),...Me(`move-${ee.num}`),onChange:$t=>pe(Number($t.target.value)),autoFocus:!0,children:ze.map($t=>i.jsx("option",{value:$t.slot,children:$t.label},$t.slot))})}),Le,i.jsxs("div",{className:"ap-pop-actions",children:[i.jsx("button",{type:"button",className:"btn",onClick:()=>hn(),children:"Cancel"}),i.jsx("button",{type:"button",className:"btn primary",...Me(`move-${ee.num}`),title:Lt.title,onClick:()=>Yn(ee.num,ht,Lt),children:c===`move-${ee.num}`?"…":wc(Lt.label)})]})]})})(),H.view==="share"&&(F==null?void 0:F.num)===ee.num&&(()=>{const ze=OR(F.expiresAt,T),ht=ze.tone==="gone";return i.jsxs("div",{className:`ap-pop-form ap-share${ht?" expired":""}`,children:[i.jsx("p",{className:"ap-pop-title",id:Re,children:"Share account"}),i.jsx("code",{className:"ap-share-blob",children:F.blob}),i.jsxs("p",{className:"ap-pop-note",title:"This text is the account's password. It is base64 of plain JSON — the expiry inside it is not signed, so anyone holding a copy can change it, and the login itself is in there in the clear either way. The countdown only says how long another deck's import dialog will still accept it. If a copy escapes, sign the account out and back in.",children:[i.jsx("span",{className:"ap-share-warn",children:"This is the password"})," · ",i.jsx("span",{className:`ap-share-expiry ${ze.tone}`,children:ze.text})]}),Le,i.jsxs("div",{className:"ap-pop-actions",children:[i.jsx("button",{type:"button",className:"btn",onClick:()=>hn(),children:"Done"}),i.jsx("button",{type:"button",className:"btn primary",...Me(`share-${ee.num}`),autoFocus:!0,onClick:async()=>{if(ht){await jn(ee.num);return}await u_(F.blob)&&(U(!0),window.setTimeout(()=>U(!1),1800))},children:ht?"Make a new share":Q?"Copied":"Copy"})]})]})})()]})})(),S&&(()=>{var Le;const ee=(Le=n.accounts)==null?void 0:Le.find(Ie=>Ie.num===S.num),Re=ee?Ed(ee,T):null;return!ee||!Re?null:i.jsx(Dx,{anchorId:S.anchor,boundaryId:S.anchor==="ap-notice"?"ap-scroll":zt(ee.num),id:"ap-issue-pop",className:"ap-pop ap-issue-pop",role:"dialog",labelledBy:"ap-issue-title",onClose:()=>dn(),children:i.jsxs("div",{className:"ap-pop-form",children:[i.jsxs("p",{className:"ap-pop-title ap-issue-title",id:"ap-issue-title","data-tone":Re.tone,children:[Re.tone==="warn"&&i.jsx(qp,{}),Re.text]}),i.jsx("p",{className:"ap-pop-note ap-issue-hint",children:Re.hint}),i.jsxs("p",{className:"ap-pop-note ap-issue-when",children:[i.jsx("span",{className:"ap-issue-who",children:ee.alias??ee.email??`account ${ee.num}`})," · ",ee.fetchedAt?`last collected ${Fp(ee.fetchedAt,T)}`:"never collected"]}),i.jsxs("div",{className:"ap-pop-actions",children:[i.jsx("button",{type:"button",className:"btn",onClick:()=>dn(!0),children:"Done"}),Re.fix&&i.jsx("button",{type:"button",className:"btn primary",onClick:()=>{dn(!0),Z(!0)},title:"Open the sign-in dialog. Signing in as this account puts its login back in this slot — it keeps its slot, its alias and its history.",children:Re.fix})]})]})})})()]}):i.jsx("div",{className:"ap-empty",children:n.reason==="no_cswap"?i.jsxs(i.Fragment,{children:[i.jsx("span",{children:"claude-swap isn't installed."}),i.jsx("span",{className:"ap-hint",children:"This panel reads the account store claude-swap keeps — without it there is nothing to show. It is a separate tool, published on PyPI, so it does not come with this package."}),n.hint&&i.jsx("code",{className:"ap-cmd",children:n.hint}),i.jsxs("span",{className:"ap-hint",children:["Then add an account with the ",i.jsx("strong",{children:"+"})," button above."]})]}):n.reason==="no_accounts"?i.jsxs(i.Fragment,{children:[i.jsx("span",{children:"No accounts added yet."}),i.jsxs("span",{className:"ap-hint",children:["claude-swap is installed but has nothing in its store. Use the ",i.jsx("strong",{children:"+"})," above to sign one in, or to paste one shared from another deck."]})]}):i.jsxs(i.Fragment,{children:[i.jsx("span",{children:"Couldn't read the account store."}),i.jsxs("span",{className:"ap-hint",children:["claude-swap is installed, but its store could not be read",n.reason?` (${n.reason})`:"","."]})]})})}),i.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:y?`Now active: ${y.name}`:""}),j&&i.jsx(kB,{accounts:((n==null?void 0:n.accounts)??[]).map(ee=>({key:`${String(ee.email??"").trim().toLowerCase()}@@${ee.orgUuid??""}`,email:ee.email??"",alive:ee.alive===!0})),onChanged:()=>Ge(!0),view:_==="lan",onOpen:ir,onBack:()=>N("accounts"),closeButton:En}),M&&i.jsx(x8,{onClose:()=>Z(!1),onChanged:()=>Ge(!0)}),ae&&i.jsx(EB,{accounts:((n==null?void 0:n.accounts)??[]).map(ee=>({num:ee.num,email:ee.email,alias:ee.alias,org:ee.org})),onClose:()=>z(!1),copyText:u_})]})}const JB=3e4;function ez({bundle:e,running:t,lastTried:n}){return!t||e===t?!1:n!==t}function tz({bundle:e,running:t,pending:n,lastTried:r}){return t?ez({bundle:e,running:t,lastTried:r})?"reload":n==null||n&&n!==t?"wait":"confirm":"wait"}function nz(e){return!e||e.state!=="failed"?null:`${typeof e.at=="number"?e.at:0}:${e.error??""}`}function rz({asked:e,reported:t}){return t?t!==e:!1}function WR(e){const t=e.thresholdMs??JB;return!e.enabled||e.kind!=="restart"||!e.canRestart||!e.noticeOpen||!e.visible||e.busy?null:e.idleSince==null||e.now<e.idleSince?t:Math.max(0,t-(e.now-e.idleSince))}function sz(e){const t=Math.max(0,Math.ceil(e/1e3));return t<60?`${t}s`:`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`}function az(e,t){return e?t==null?"auto when idle":`auto in ${sz(t)}`:"auto-restart off"}function d_(e){let t=0;for(const n of e)n.state==="active"&&t++;return t}function oz(e){return e<=0?{label:"Restart now",clause:"nothing is running"}:{label:"Restart anyway",clause:`${e===1?"1 agent is running":`${e} agents are running`} — their events during the restart are lost`}}function iz(e){const t=WR(e);return t==null?{idleSince:null,restart:!1,remainingMs:null}:e.idleSince==null||e.now<e.idleSince?{idleSince:e.now,restart:!1,remainingMs:t}:{idleSince:e.idleSince,restart:t===0,remainingMs:t}}function lz(e,t){return e==="confirmation"?t.confirmOpen?"clear":"ignore":t.modalOpen||t.confirmOpen?"ignore":"confirm"}function cz(e){if(!e||typeof e!="object")return null;const t=e;if(typeof t.decks!="number"||typeof t.mine!="boolean")return null;const n=t.owner&&typeof t.owner=="object"?t.owner.port:null;return{path:typeof t.path=="string"&&t.path!==""?t.path:null,decks:t.decks,mine:t.mine,ownerPort:typeof n=="number"?n:null}}function uz(e){return e<=0?null:e===1?"the one agent":`all ${e} agents`}function dz(e,t){const n=uz(e),r=(...c)=>[n?`${n} on the canvas`:null,...c,"layout, pins and selection"].filter(u=>u!==null),a="This cannot be undone.";if(!t)return{goes:r("the event log on disk — the file a restarted deck replays to rebuild what you see, and the file every deck on this machine shares unless one was told otherwise"),stays:[],final:a,confirm:"Clear everything"};if(!t.path)return{goes:r(),stays:[],final:`This deck keeps no event log, so nothing on disk changes — and nothing can bring the canvas back. ${a}`,confirm:"Clear everything"};if(!t.mine){const c=t.ownerPort===null?"another running deck owns that file":`the deck on port ${t.ownerPort} owns that file`,u=t.decks>2?`, one of ${t.decks} decks sharing it`:"";return{goes:r(),stays:[`the event log — ${c}${u}`,"restart this deck and the log replays back onto it"],final:null,confirm:"Clear this canvas"}}if(t.decks<=1)return{goes:r("this deck's event log — the file a restarted deck replays to rebuild what you see"),stays:[],final:a,confirm:"Clear everything"};const l=t.decks-1;return{goes:r(`the event log ${l===1?"1 other running deck shares":`${l} other running decks share`} with this one — every session recorded in it, not just the ones drawn here`),stays:[l===1?"what that deck shows, until it restarts — then it is gone there too":"what those decks show, until they restart — then it is gone there too"],final:a,confirm:"Clear everything"}}function hz({agentCount:e,onConfirm:t,onCancel:n}){const r=x.useRef(null),a=un(n,{focusRef:r,layer:x6}),[l,c]=x.useState(null);x.useEffect(()=>{let m=!1;return fetch("/api/clear").then(y=>y.ok?y.json():null).then(y=>{m||c(cz(y))}).catch(()=>{}),()=>{m=!0}},[]);const{goes:u,stays:f,final:p,confirm:h}=dz(e,l);return i.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:i.jsxs("div",{ref:a,className:"modal clear-confirm",onClick:m=>m.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"clear-confirm-title",children:[i.jsxs("header",{className:"modal-head",children:[i.jsxs("div",{className:"modal-title",children:[i.jsx("span",{className:"status-dot err","aria-hidden":!0}),i.jsx("span",{id:"clear-confirm-title",className:"modal-tool-name",children:"Clear the deck?"})]}),i.jsx("div",{className:"modal-actions",children:i.jsx("button",{type:"button",className:"glyph-btn",onClick:n,"aria-label":"Cancel (Esc)",title:"Cancel (Esc)",children:"×"})})]}),i.jsxs("section",{className:"modal-body",children:[i.jsxs("dl",{className:"cc-plan",children:[i.jsx("dt",{children:"Goes"}),i.jsx("dd",{children:u.map(m=>i.jsx("span",{children:m},m))}),i.jsx("dt",{children:"Stays"}),i.jsx("dd",{children:f.length>0?f.map(m=>i.jsx("span",{children:m},m)):i.jsx("span",{children:"nothing"})})]}),p&&i.jsx("p",{className:"cc-final",children:p}),i.jsxs("div",{className:"cc-actions",children:[i.jsx("button",{type:"button",ref:r,className:"btn",onClick:n,children:"Cancel"}),i.jsx("button",{type:"button",className:"btn danger",onClick:t,children:h})]})]})]})})}const fz="Press Esc first if a key does nothing.",pz=[{title:"Canvas",rows:[{cap:"Space",action:"pause or resume the stream",binds:[" "]},{cap:"J",action:"next agent",binds:["j","J"]},{cap:"K",action:"previous agent",binds:["k","K"]},{cap:"W",action:"the session waiting on you — oldest first, again for the next",binds:["w","W"]},{cap:"F",action:"fit every agent on screen",binds:["f","F"]},{cap:"Z",action:"zoom to the selected agent and its session",binds:["z","Z"]},{cap:"R",action:"re-arrange the canvas and drop the pins",binds:["r","R"]},{cap:"C",action:"clear the canvas and the event log — asks first",binds:["c","C"]}]},{title:"Panels and dialogs",rows:[{cap:"U",action:"usage panel",binds:["u","U"]},{cap:"L",action:"session list",binds:["l","L"]},{cap:"D",action:"detail panel",binds:["d","D"]},{cap:"H",action:"usage history",binds:["h","H"]},{cap:"A",action:"Claude accounts, where Claude Code is installed",binds:["a","A"]},{cap:"S",action:"this machine — cores, memory, temperature",binds:["s","S"]},{cap:"B",action:"Browser Watch",binds:["b","B"]},{cap:"V",action:"the sound menu — volume, tones, notifications",binds:["v","V"]},{cap:"?",action:"this sheet",binds:["?"]}]},{title:"Settings",rows:[{cap:"M",action:"sound on or off",binds:["m","M"]},{cap:"T",action:"light or dark theme",binds:["t","T"]}]},{title:"Focus and selection",rows:[{cap:"Tab",action:"reach the agent cards",binds:[]},{cap:"Enter",action:"select the focused card",binds:["Enter"]},{cap:"Shift + Enter",action:"add the focused card to the selection",binds:["Enter"]},{cap:"Esc",action:"close what is open, deselect, release focus",binds:["Escape"]}]},{title:"Mouse",rows:[{cap:"drag",action:"move a node, and pin it where you dropped it",binds:[]},{cap:"shift-click",action:"add an agent to the selection",binds:[]},{cap:"click",action:"a card: go to it and its session",binds:[]},{cap:"double-click",action:"a card: its prompt, every tool call, tokens and timing",binds:[]},{cap:"hover",action:"zoomed out, a card's name, state and numbers",binds:[]},{cap:"click",action:"the topbar speaker opens volume and sound settings",binds:[]}]}];function mz({onClose:e,onTour:t}){const n=un(e);return i.jsx("div",{className:"modal-backdrop",onClick:e,role:"presentation",children:i.jsxs("div",{ref:n,className:"modal key-help",onClick:r=>r.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"key-help-title",children:[i.jsxs("header",{className:"modal-head",children:[i.jsx("div",{className:"modal-title",children:i.jsx("span",{id:"key-help-title",className:"modal-tool-name",children:"Keyboard shortcuts"})}),i.jsx("div",{className:"modal-actions",children:i.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),i.jsxs("section",{className:"modal-body",children:[t&&i.jsxs("div",{className:"guide-door",children:[i.jsx("span",{children:"Eight pictures of what the deck shows."}),i.jsx("button",{type:"button",className:"btn",onClick:t,children:"Take the tour"})]}),i.jsx("div",{className:"shortcuts",children:pz.map(r=>i.jsxs(x.Fragment,{children:[i.jsx("h3",{className:"kh-group",children:r.title}),r.rows.map(a=>i.jsxs("div",{className:"sc",children:[i.jsx("kbd",{children:a.cap}),i.jsx("span",{children:a.action})]},`${r.title}:${a.cap}:${a.action}`))]},r.title))}),i.jsx("p",{className:"kh-foot",children:fz})]})]})})}const gz=["done","needs-input"],yz=[{id:"two",label:"Two notes",notes:[{at:0,hz:740,ms:90},{at:.085,hz:440,ms:150}]},{id:"arc",label:"Descent",notes:[{at:0,hz:988,ms:80},{at:.07,hz:659,ms:80},{at:.14,hz:440,ms:160}]},{id:"tap",label:"Double tap",notes:[{at:0,hz:740,ms:55},{at:.055,hz:740,ms:55},{at:.165,hz:440,ms:150}]},{id:"chord",label:"Chord",trim:.7,notes:[{at:0,hz:988,ms:110},{at:0,hz:740,ms:110},{at:.1,hz:440,ms:170}]},{id:"bell",label:"Bell",type:"triangle",notes:[{at:0,hz:740,ms:120},{at:.11,hz:440,ms:260}]},{id:"blip",label:"Blip",type:"square",trim:.7,notes:[{at:0,hz:740,ms:55},{at:.06,hz:440,ms:90}]}],wz=[{id:"two",label:"Two notes",notes:[{at:0,hz:440,ms:90},{at:.085,hz:740,ms:150}]},{id:"arc",label:"Ascent",notes:[{at:0,hz:440,ms:80},{at:.07,hz:659,ms:80},{at:.14,hz:988,ms:160}]},{id:"tap",label:"Double tap",notes:[{at:0,hz:440,ms:55},{at:.055,hz:440,ms:55},{at:.165,hz:740,ms:150}]},{id:"chord",label:"Chord",trim:.7,notes:[{at:0,hz:440,ms:110},{at:.1,hz:740,ms:170},{at:.1,hz:988,ms:170}]},{id:"bell",label:"Bell",type:"triangle",notes:[{at:0,hz:440,ms:120},{at:.11,hz:740,ms:260}]},{id:"blip",label:"Blip",type:"square",trim:.7,notes:[{at:0,hz:440,ms:55},{at:.06,hz:740,ms:90}]}],B0={done:yz,"needs-input":wz},al="two";function Wx(e,t){const n=B0[e];return n.find(r=>r.id===t)??n.find(r=>r.id===al)??n[0]}function UR(e,t){return B0[e].some(r=>r.id===t)?t:al}Wx("done",al).notes,Wx("needs-input",al).notes;const h_=.04,vz=.24,Hd=0,ch=100,Ux=5,Dc=50;function Fc(e){if(!Number.isFinite(e))return Dc;const t=Math.round(e/Ux)*Ux;return Math.min(ch,Math.max(Hd,t))}function xz(e){if(e==null)return Dc;const t=e.trim();return/^-?\d+(\.\d+)?$/.test(t)?Fc(Number(t)):Dc}function bz(e){const t=Fc(e),n=h_+(vz-h_)*(t/ch);return Math.round(n*1e4)/1e4}function kz(e,t){const n=t.trim,r=typeof n=="number"&&Number.isFinite(n)&&n>0&&n<=1?n:1;return Math.round(bz(e)*r*1e4)/1e4}const Nz=160,_z="agent-dag.soundLevel.done",Sz="agent-dag.soundLevel.needs-input",jz="agent-dag.soundFigure.done",Ez="agent-dag.soundFigure.needs-input",VR={done:_z,"needs-input":Sz},GR={done:jz,"needs-input":Ez},Vx={done:{level:Dc,figure:al},"needs-input":{level:Dc,figure:al}};function Cz(e){const t=n=>({level:xz(e(VR[n])),figure:UR(n,e(GR[n]))});return{done:t("done"),"needs-input":t("needs-input")}}const f_={Stop:"done",Notification:"needs-input"};function Tz(e,t){var r;if(t)return null;const n=(r=e==null?void 0:e.payload)==null?void 0:r.hook_event_name;return typeof n!="string"?null:Object.hasOwn(f_,n)?f_[n]:null}function Az(e={enabled:()=>!0}){const t=e.ctor??(typeof window<"u"?window.AudioContext??window.webkitAudioContext??null:null);let n=null,r=!1;const a=()=>e.enabled()?r&&(n==null?void 0:n.state)==="running"?"ready":"locked":"off",l=()=>{var f;return(f=e.onState)==null?void 0:f.call(e,a())};function c(){var f;if(!(!t||r))try{n=n??new t,(f=n.resume)==null||f.call(n).then(l,()=>{}),r=!0,l()}catch{}}function u(f,p=!1){var _;if(!p&&!e.enabled()||!n||n.state!=="running")return!1;const h=(((_=e.prefs)==null?void 0:_.call(e))??Vx)[f]??Vx[f],m=Wx(f,h.figure),y=kz(h.level,m),w=n.currentTime;for(const N of m.notes){const j=n.createOscillator(),b=n.createGain();j.type=m.type??"sine",j.frequency.value=N.hz;const S=w+N.at,E=S+N.ms/1e3;b.gain.setValueAtTime(1e-4,S),b.gain.exponentialRampToValueAtTime(y,S+.012),b.gain.exponentialRampToValueAtTime(1e-4,E),j.connect(b).connect(n.destination),j.start(S),j.stop(E+.02)}return!0}return{unlock:c,play:u,state:a,get context(){return n}}}const Rz="With no deck tab open, get a notification wherever a sound would have played.",Mz="With the ccdeck window closed, get a notification wherever a sound would have played.";function Iz(e){return e?Mz:Rz}const $z="Held off for this run — the deck was started with alerts disabled. Your choice is saved for the next start.",p_="Get notified when you're away from this tab.";function Oz(e){switch(e){case"granted":return{status:"Enabled",ask:!1,ok:!0,note:p_};case"default":return{status:null,ask:!0,ok:!1,note:p_};case"denied":return{status:"Blocked",ask:!1,ok:!1,note:"Your browser is blocking them; only its own site settings can undo that. You'll still be told once this tab is closed."};default:return{status:"Unavailable",ask:!1,ok:!1,note:"This browser cannot show them. You'll still be told once this tab is closed."}}}function Pz(e=typeof navigator>"u"?"":navigator.userAgent){return/\bccdeck-desktop\/\d/.test(e)}const m_={done:"Turn finished","needs-input":"Claude is asking"},Lz={done:"Plays when Claude or Codex finishes a turn.","needs-input":"Available in Claude Code only."};function Dz({onClose:e,soundOn:t,onToggleSound:n,prefs:r,onLevel:a,onFigure:l,onPreview:c,openerRef:u,notifyOn:f,onToggleNotify:p,notifyVetoed:h,notifyPermission:m,onAskNotify:y}){const w=Oz(m),_=Pz(),N=f&&!h&&!_,j=un(e),b=x.useRef(e);return b.current=e,x.useEffect(()=>{const S=E=>{var T,R;const C=E.target;C&&((T=j.current)!=null&&T.contains(C)||(R=u.current)!=null&&R.contains(C)||b.current())};return window.addEventListener("pointerdown",S,!0),()=>window.removeEventListener("pointerdown",S,!0)},[j,u]),i.jsxs("div",{ref:j,id:"sound-menu",className:"sound-menu",role:"dialog","aria-label":"Sound settings",children:[i.jsxs("div",{className:"sm-switches",children:[i.jsxs("label",{className:"sm-switch",children:[i.jsx("span",{className:"sm-switch-label",id:"sm-sound-label",children:"Sounds"}),i.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-labelledby":"sm-sound-label",className:"switch",onClick:n,title:"A tone when a turn finishes, and when Claude asks for something",children:i.jsx("span",{className:"switch-knob"})})]}),i.jsxs("div",{className:"sm-setting",children:[i.jsxs("label",{className:"sm-switch",children:[i.jsx("span",{className:"sm-switch-label",id:"sm-notify-label",children:"Notifications while closed"}),i.jsx("button",{type:"button",role:"switch","aria-checked":f,"aria-labelledby":"sm-notify-label",className:"switch",onClick:p,title:"With no deck tab open, a notification wherever a sound would play",children:i.jsx("span",{className:"switch-knob"})})]}),i.jsx("p",{className:"sm-note",children:h?$z:Iz(_)})]})]}),N&&i.jsxs("section",{className:"sm-channel","aria-labelledby":"sm-channel-name",children:[i.jsxs("div",{className:"sm-channel-head",children:[i.jsx("h3",{className:"sm-channel-name",id:"sm-channel-name",children:"Browser notifications"}),w.ask?i.jsx("button",{type:"button",className:"btn sm-channel-action",onClick:y,children:"Enable"}):i.jsxs("span",{className:"sm-channel-state","data-ok":w.ok||void 0,children:[w.ok&&i.jsx("svg",{width:"9",height:"9",viewBox:"0 0 10 10",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:i.jsx("path",{d:"M1.5 5.2 3.9 7.6 8.5 2.4"})}),w.status]})]}),i.jsx("p",{className:"sm-note",children:w.note})]}),!t&&i.jsx("span",{id:"sm-preview-note",className:"vis-hidden",children:"Plays even when Sounds is off, so you can set a tone before turning sounds back on."}),i.jsx("div",{className:"sm-tones",children:gz.map(S=>{const E=r[S],C=`sm-level-${S}`,T=`sm-figure-${S}`;return i.jsxs("section",{className:"sm-tone","aria-labelledby":`sm-name-${S}`,children:[i.jsxs("div",{className:"sm-tone-head",children:[i.jsx("h3",{className:"sm-tone-name",id:`sm-name-${S}`,children:m_[S]}),i.jsxs("button",{type:"button",className:"btn sm-hear",onClick:()=>c(S),"aria-label":`Hear the ${m_[S].toLowerCase()} tone`,title:t?"Play this tone now, at what it is set to":"Plays even when Sounds is off","aria-describedby":t?void 0:"sm-preview-note",children:[i.jsx("svg",{width:"11",height:"11",viewBox:"0 0 12 12",fill:"currentColor","aria-hidden":!0,children:i.jsx("path",{d:"M3 1.6v8.8l7-4.4z"})}),"Hear it"]})]}),i.jsxs("div",{className:"sm-row",children:[i.jsx("label",{htmlFor:C,children:"Volume"}),i.jsx("input",{id:C,type:"range",min:Hd,max:ch,step:Ux,value:E.level,onChange:R=>a(S,Number(R.target.value)),style:{"--sm-level":`${(E.level-Hd)/(ch-Hd)*100}%`}}),i.jsxs("span",{className:"sm-read",children:[E.level,"%"]})]}),i.jsxs("div",{className:"sm-row",children:[i.jsx("label",{htmlFor:T,children:"Tone"}),i.jsx("select",{id:T,className:"sm-select",value:E.figure,onChange:R=>l(S,R.target.value),children:B0[S].map(R=>i.jsx("option",{value:R.id,children:R.label},R.id))})]}),i.jsx("p",{className:"sm-note",children:Lz[S]})]},S)})}),i.jsxs("p",{className:"sm-foot",children:[i.jsx("kbd",{children:"M"}),"Mute or unmute sounds anywhere."]})]})}const Di=["light","dark"],Fz={light:"Light",dark:"Dark"};function qz({theme:e}){return i.jsx("span",{className:"appearance-preview","data-swatch":e,children:i.jsxs("svg",{viewBox:"0 0 112 56","aria-hidden":!0,focusable:"false",children:[i.jsx("rect",{className:"tp-canvas",width:"112",height:"56"}),i.jsx("rect",{className:"tp-surface",width:"112",height:"7"}),i.jsx("rect",{className:"tp-rule",y:"7",width:"112",height:"1"}),i.jsx("rect",{className:"tp-surface",y:"8",width:"25",height:"48"}),i.jsx("rect",{className:"tp-rule",x:"25",y:"8",width:"1",height:"48"}),i.jsx("rect",{className:"tp-card",x:"36.5",y:"27.5",width:"28",height:"14",rx:"2.5"}),i.jsx("rect",{className:"tp-tag",x:"39.5",y:"25.5",width:"13",height:"4",rx:"2"}),i.jsx("rect",{className:"tp-card",x:"76.5",y:"14.5",width:"29",height:"20",rx:"2.5"}),i.jsx("rect",{className:"tp-rule",x:"81",y:"23",width:"20",height:"2",rx:"1"}),i.jsx("rect",{className:"tp-accent",x:"81",y:"23",width:"12",height:"2",rx:"1"})]})})}function Bz({theme:e,onTheme:t,characterEnabled:n,onToggleCharacter:r,onClose:a,openerRef:l}){const c=un(a),u=x.useRef(a);u.current=a,x.useEffect(()=>{const h=m=>{var w,_;const y=m.target;!y||(w=c.current)!=null&&w.contains(y)||(_=l.current)!=null&&_.contains(y)||u.current()};return window.addEventListener("pointerdown",h,!0),()=>window.removeEventListener("pointerdown",h,!0)},[c,l]);const f=h=>{var w;if(!["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(h.key))return;h.preventDefault();const y=(Di.indexOf(e)+(h.key==="ArrowLeft"||h.key==="ArrowUp"?-1:1)+Di.length)%Di.length;t(Di[y]),(w=h.currentTarget.querySelectorAll('[role="radio"]')[y])==null||w.focus()},p=h=>{var y;if(h.key===" "){h.stopPropagation();return}if(h.key!=="t"&&h.key!=="T"||h.ctrlKey||h.metaKey||h.altKey)return;h.preventDefault(),h.stopPropagation();const m=e==="dark"?"light":"dark";t(m),h.target.getAttribute("role")==="radio"&&((y=h.currentTarget.querySelectorAll('[role="radio"]')[Di.indexOf(m)])==null||y.focus())};return i.jsxs("div",{ref:c,id:"appearance-menu",className:"appearance-menu",role:"dialog","aria-labelledby":"appearance-title",onKeyDown:p,children:[i.jsx("div",{className:"appearance-head",children:i.jsx("h2",{id:"appearance-title",className:"appearance-title",children:"Appearance"})}),i.jsxs("section",{className:"appearance-section","aria-labelledby":"appearance-theme-caption",children:[i.jsxs("div",{className:"appearance-caption",children:[i.jsx("h3",{id:"appearance-theme-caption",children:"Color theme"}),i.jsx("kbd",{className:"appearance-key","aria-hidden":!0,title:"Press T anywhere to switch themes",children:"T"})]}),i.jsx("div",{className:"appearance-themes",role:"radiogroup","aria-labelledby":"appearance-theme-caption","aria-keyshortcuts":"T",onKeyDown:f,children:Di.map(h=>i.jsxs("button",{type:"button",className:"appearance-theme",role:"radio","aria-checked":e===h,tabIndex:e===h?0:-1,onClick:()=>t(h),children:[i.jsx(qz,{theme:h}),i.jsxs("span",{className:"appearance-theme-name",children:[Fz[h],i.jsx("svg",{className:"appearance-check",viewBox:"0 0 12 12","aria-hidden":!0,focusable:"false",children:i.jsx("path",{d:"M2.5 6.4 4.9 8.7 9.5 3.6"})})]})]},h))})]}),i.jsxs("section",{className:"appearance-section","aria-labelledby":"appearance-fm-caption",children:[i.jsx("div",{className:"appearance-caption",children:i.jsx("h3",{id:"appearance-fm-caption",children:"Claude FM"})}),i.jsxs("label",{className:"appearance-row",children:[i.jsx("span",{className:"appearance-row-label",id:"appearance-character-label",children:"Show character on minimap"}),i.jsx("button",{type:"button",className:"switch",role:"switch","aria-checked":n,"aria-labelledby":"appearance-character-label","aria-describedby":"appearance-character-note",onClick:r,children:i.jsx("span",{className:"switch-knob"})}),i.jsx("span",{className:"appearance-row-note",id:"appearance-character-note",children:"Press it to play the live stream"})]})]})]})}const Gx="https://www.youtube-nocookie.com";function zz(e,t){const n=new URLSearchParams({channel:e,enablejsapi:"1",autoplay:"1",playsinline:"1",rel:"0",modestbranding:"1",origin:t});return`${Gx}/embed/live_stream?${n.toString()}`}function g_(e,t=[]){return JSON.stringify({event:"command",func:e,args:t})}function Hz(e="claude-fm"){return JSON.stringify({event:"listening",id:e,channel:"widget"})}const Wz=[1,3],Uz=[0,2],Vz=[2,5,100,101,150];function Gz(e){let t=e;if(typeof e=="string")try{t=JSON.parse(e)}catch{return null}if(!t||typeof t!="object")return null;const{event:n,info:r}=t;if(n==="onReady")return{kind:"ready"};if(n==="onError"){const a=typeof r=="number"?r:Number(r==null?void 0:r.errorCode);return Number.isFinite(a)?{kind:"error",code:a}:null}if(n==="onStateChange"||n==="infoDelivery"){const a=typeof r=="number"?r:r==null?void 0:r.playerState;return typeof a!="number"||!Number.isFinite(a)?null:Wz.includes(a)?{kind:"playing",playing:!0}:Uz.includes(a)?{kind:"playing",playing:!1}:null}return null}const KR=["......aaaaaa......","....aa......aa....","...a..bbbbbs..a...","...cpcbbbbbscpc...","...cpcbebbescpc...","...cpcbbbbbscpc...","...cpcbbbbbscpc...","....ccbbbbbscc....","....bbbbbbbbbs....","....bbbbbbbbbs....","......bbbbbs......","......bb..bs......","......bb..bs......","......bb..bs......"],y_=18,Kz=KR.length,YR=new Set(["a","c","p"]);function Mh(e=KR){const t=[];return e.forEach((n,r)=>{let a=0;for(;a<n.length;){const l=n[a];if(l==="."){a+=1;continue}let c=1;for(;a+c<n.length&&n[a+c]===l;)c+=1;t.push({x:a,y:r,w:c,cell:l}),a+=c}}),t}const Io=148,w_=6e3,Yz=16e3,XR=46,Ma=34;function Xz(e,t,n=Io){let r=-Math.round(t()*n);if(Math.abs(r-e)<Ma){const a=e-Ma>=-n?-Ma:Ma;r=Math.max(-n,Math.min(0,Math.round(e+a)))}return{to:r,ms:Math.round(Math.abs(r-e)*XR)}}function Zz(e){return Math.round(w_+e()*(Yz-w_))}const v_=[{kind:"stroll",weight:44},{kind:"tidy",weight:17},{kind:"kick",weight:17},{kind:"sit",weight:12},{kind:"watch",weight:16},{kind:"leave",weight:7},{kind:"fish",weight:12},{kind:"skip",weight:10}];function Qz(e){const t=v_.reduce((r,a)=>r+a.weight,0);let n=e()*t;for(const r of v_)if(n-=r.weight,n<0)return r.kind;return"stroll"}const Jz=720,eH=260,tH=620,nH=220,x_=520,ZR=1600,b_=7e3,rH=15e3,k_=6e3,sH=14e3;function Fi(e,t,n=Io){let r=-Math.round(t()*n);if(Math.abs(r-e)<Ma){const a=e-Ma>=-n?-Ma:Ma;r=Math.max(-n,Math.min(0,Math.round(e+a)))}return r}const cn=(e,t)=>Math.round(Math.abs(t-e)*XR),Cd=0;function aH(e,t){const n=r=>({kind:"litter",at:t,...r});return[{x:t,prop:n({}),act:"walk",ms:cn(e,t)},{x:t,prop:n({}),act:"stoop",ms:Jz},{x:Cd,prop:n({held:!0}),act:"carry",ms:cn(t,Cd)},{x:Cd,prop:n({held:!0}),act:"windup",ms:eH},{x:Cd,prop:n({held:!0,leaving:!0}),act:"toss",ms:tH}]}function oH(e,t){const n=t>e?1:-1,r=t-n*Math.min(15,Math.abs(t-e)),a=(l={})=>({kind:"ball",at:t,...l});return[{x:r,prop:a(),act:"walk",ms:cn(e,r)},{x:r,prop:a(),act:"windup",ms:nH,facing:n>0?"right":"left"},{x:r,prop:a({leaving:!0}),act:"kick",ms:x_,facing:n>0?"right":"left"},{x:r,prop:a({leaving:!0}),act:"stand",ms:ZR-x_}]}const QR=640;function iH(e,t,n){const r=Math.max(-70,Math.min(-20,t)),a={x:r,prop:null,facing:"left"};return[{x:r,prop:null,act:"walk",ms:cn(e,r)},{...a,act:"sit",ms:600},{...a,act:"cast",ms:900},{...a,act:"fish",ms:6e3+Math.round(n()*4e3)},{...a,act:"reel",ms:1200},{...a,act:"stow",ms:500},{...a,act:"stand",ms:400},{x:0,prop:null,act:"walk",ms:cn(r,0)}]}function lH(e,t,n){const r=Math.max(-110,Math.min(-30,t)),a={x:r,prop:null};return[{...a,act:"walk",ms:cn(e,r)},{...a,act:"skip-ready",ms:500},{...a,act:"skip",ms:QR*(6+Math.floor(n()*5))},{...a,act:"skip-rest",ms:600},{...a,act:"stand",ms:350},{x:0,prop:null,act:"walk",ms:cn(r,0)}]}function cH(e,t,n){return[{x:t,prop:null,act:"walk",ms:cn(e,t)},{x:t,prop:null,act:"sit",ms:Math.round(k_+n()*(sH-k_))},{x:t,prop:null,act:"stand",ms:400}]}function uH(e,t,n){t=Math.max(-110,Math.min(0,t));const r=()=>({kind:"scope",at:t,held:!0});return[{x:t,prop:null,act:"walk",ms:cn(e,t)},{x:t,prop:r(),act:"watch",ms:Math.round(b_+n()*(rH-b_))},{x:t,prop:r(),act:"scope-pack",ms:480},{x:t,prop:null,act:"stand",ms:240}]}function N_(e,t,n){return e.facing?e.facing:e.act==="watch"||e.act==="scope-pack"?"left":e.x===t?n:e.x>t?"right":"left"}const dH=1500,hH=e=>Math.round(1e3*Math.sqrt(2*e/dH)),fH=115,pH=e=>Math.round(e/fH*1e3),mH=620,gH=200,yH=760,wH=600,vH=240;function xH(e,t,n){const a=-(t.ledgeSpan??Io),l=hH(t.ledgeH),c=pH(t.ledgeH),u=-Math.round(n()*t.floorSpan),f=-Math.round(n()*t.floorSpan);return[{x:a,act:"walk",prop:null,ms:cn(e,a)},{x:a,act:"peer",prop:null,ms:mH},{x:a,act:"fall",prop:null,ms:l,place:"floor"},{x:a,act:"land",prop:null,ms:gH,place:"floor"},{x:u,act:"walk",prop:null,ms:cn(a,u),place:"floor"},{x:f,act:"walk",prop:null,ms:cn(u,f),place:"floor"},{x:a,act:"walk",prop:null,ms:cn(f,a),place:"floor"},{x:a,act:"lasso",prop:null,ms:yH,place:"floor"},{x:a,act:"rope-throw",prop:null,ms:wH,place:"floor"},{x:a,act:"rope-catch",prop:null,ms:vH,place:"floor"},{x:a,act:"climb",prop:null,ms:c},{x:a,act:"pull-up",prop:null,ms:480}]}function bH(e,t,n){const r=(n==null?void 0:n.ledgeSpan)??Io;switch(Qz(t)){case"tidy":return aH(e,Fi(e,t,r));case"kick":return oH(e,Fi(e,t,r));case"sit":return cH(e,Fi(e,t,r),t);case"watch":return uH(e,Fi(e,t,r),t);case"fish":return iH(e,Fi(e,t,r),t);case"skip":return lH(e,Fi(e,t,r),t);case"leave":{if(!n||!(n.ledgeH>0)||!(n.floorSpan>0))break;return xH(e,n,t)}}const l=Xz(e,t,r);return[{x:l.to,prop:null,act:"walk",ms:l.ms}]}const kH=[".xx.","xxxx",".xx."],NH=["..xx..",".xsxx.","xssxxx","xxxxsx",".xxxx.","..xx.."],_H=["...xx...............","..xaax..............",".xaallx.............","xaallllx............",".xllllllx...........","..xllllllx..........","...xllllllx.........","....xllllllxx.......",".....xllllxsxx..xx..","......xllxsssx.xllxx",".......xxssssxxxllxx","........xssssssxx...",".........xssssx.....","..........xxxx......","..........xax.......",".........xxxxx......","........xx.x.xx.....","........xl.x.lx.....",".......xl..x..lx....",".......xl..x..lx....","......xl...x...lx...","......xl...x...lx...",".....xl....x....lx..","....xxx...xxx...xxx."],Bp={litter:kH,ball:NH,scope:_H},JR=["bob","sway","groove"],__=9e3,SH=16e3,eM=1e3,jH=.08;function EH(e,t){const n=JR.filter(l=>l!==e),r=n[Math.min(n.length-1,Math.floor(t()*n.length))],a=(t()*2-1)*jH;return{dance:r,beatMs:Math.round(eM*(1+a))}}function CH(e){return Math.round(__+e()*(SH-__))}const TH=["...hhhhhh...","...hhhhhh...","...kkkkkk...","hhhhhhhhhhhh"],AH=3,RH=-1,Kx=11,S_=9,MH=420;function IH(e,t,n){const r=t==="right"?n-e-18:e-18;return(t==="right"?1:-1)*Math.min(MH,Math.max(0,r))}const $H=260,OH=200;function PH(e,t,n){const r=(h,m=cn(e,h))=>({x:h,prop:null,act:"walk",ms:m,place:"floor"});if(!n||n.height<=0)return[r(t)];const a=Math.min(e,t);if(Math.max(e,t)<=n.left||a>=n.right)return[r(t)];const c=t>e,u=c?n.left:n.right,f=c?n.right:n.left,p={place:"floor",riser:n.height,prop:null};return[r(u,cn(e,u)),{...p,x:u,act:"mount",ms:$H},{...p,x:f,act:"walk",ms:cn(u,f)},{x:f,prop:null,act:"dismount",ms:OH,place:"floor"},{x:t,prop:null,act:"walk",ms:cn(f,t),place:"floor"}]}function j_(e){let t=null,n=null,r=0,a=0,l=!1;const c=()=>{t!==null&&clearTimeout(t),t=null},u=()=>{l||e.hidden||!n||t!==null||(a=performance.now(),t=setTimeout(()=>{t=null;const p=n;n=null,p==null||p()},r))},f=()=>{e.hidden&&t!==null?(r=Math.max(0,r-(performance.now()-a)),c()):e.hidden||u()};return e.addEventListener("visibilitychange",f),{schedule(p,h){l||(c(),n=p,r=Math.max(0,h),u())},dispose(){l=!0,c(),n=null,e.removeEventListener("visibilitychange",f)}}}function zp(e,t){var r;const n=((r=e[0])==null?void 0:r.length)??0;return i.jsx("svg",{viewBox:`0 0 ${n} ${e.length}`,shapeRendering:"crispEdges","aria-hidden":!0,children:Mh(e).map(a=>i.jsx("rect",{x:a.x,y:a.y,width:a.w,height:1,fill:a.cell==="s"?"var(--fm-prop-shadow, var(--bg))":a.cell==="l"?"var(--fm-prop-light, var(--text))":a.cell==="a"?"var(--accent)":void 0},`${t}${a.y}-${a.x}`))})}const Hp={e:"fm-eye",s:"fm-shade",p:"fm-pad"},uh=Mh().filter(e=>!YR.has(e.cell)),LH=Mh().filter(e=>YR.has(e.cell)),E_=uh.filter(e=>e.cell==="e"),DH=Mh(TH),FH=uh.filter(e=>e.y<Kx&&e.cell!=="e").map(e=>{if(e.y!==8&&e.y!==9)return e;const t=Math.max(6,e.x);return{...e,x:t,w:Math.max(0,Math.min(12,e.x+e.w)-t)}}).filter(e=>e.w>0),qH={left:uh.filter(e=>e.y>=Kx&&e.x<S_),right:uh.filter(e=>e.y>=Kx&&e.x>=S_)},C_={litter:zp(Bp.litter,"litter"),ball:zp(Bp.ball,"ball"),scope:zp(Bp.scope,"scope")},BH=x.memo(function({fetchImpl:t}){const[n,r]=x.useState(null),[a,l]=x.useState(!1),[c,u]=x.useState(!1),[f,p]=x.useState(!1),[h,m]=x.useState(0),[y,w]=x.useState(0),[_,N]=x.useState(null),[j,b]=x.useState(null),[S,E]=x.useState({x:0,drop:0}),[C,T]=x.useState("ledge"),[R,$]=x.useState("left"),[H,B]=x.useState(0),P=x.useRef(null),[K,X]=x.useState(()=>document.hidden);x.useEffect(()=>{const D=new Set,ae=()=>{var z;if(document.hidden){for(const Q of((z=P.current)==null?void 0:z.getAnimations({subtree:!0}))??[])if(Q.playState==="running"||Q.pending){const U=Q.currentTime;Q.pause(),U!==null&&(Q.currentTime=U),D.add(Q)}}else{for(const Q of D)Q.playState==="paused"&&Q.play();D.clear()}X(document.hidden)};return ae(),document.addEventListener("visibilitychange",ae),()=>document.removeEventListener("visibilitychange",ae)},[n,a]);const[J,M]=x.useState(null),[Z,V]=x.useState(eM),[I,q]=x.useState(()=>{var D;return((D=window.matchMedia)==null?void 0:D.call(window,"(prefers-reduced-motion: reduce)").matches)??!1});x.useEffect(()=>{var z;const D=(z=window.matchMedia)==null?void 0:z.call(window,"(prefers-reduced-motion: reduce)");if(!D)return;const ae=()=>q(D.matches);return ae(),D.addEventListener("change",ae),()=>D.removeEventListener("change",ae)},[]);const W=x.useRef(null),G=x.useCallback(D=>{var ae,z;(z=(ae=W.current)==null?void 0:ae.contentWindow)==null||z.postMessage(D,Gx)},[]);if(x.useEffect(()=>{let D=!0;return(t??fetch)("/api/claude-fm").then(z=>z.ok?z.json():null).then(z=>{D&&(z!=null&&z.live)&&(z!=null&&z.channel)&&r({live:!0,channel:z.channel})}).catch(()=>{}),()=>{D=!1}},[t]),x.useEffect(()=>{if(!c)return;const D=ae=>{var Q;if(ae.origin!==Gx||ae.source!==((Q=W.current)==null?void 0:Q.contentWindow))return;const z=Gz(ae.data);if(z){if(z.kind==="ready"){G(g_("playVideo"));return}if(z.kind==="playing"){p(z.playing);return}Vz.includes(z.code)&&(u(!1),p(!1),l(!0))}};return window.addEventListener("message",D),()=>window.removeEventListener("message",D)},[c,G]),x.useEffect(()=>{if(!n||a||I)return;const D=j_(document);let ae=0;m(pe=>ae=pe);const z=pe=>{var Te,Se;const[ke,...Pe]=pe;if(!ke){N(null),b(null),ge();return}N(ke.act),b(ke.prop),T(ke.place??"ledge"),B(ke.riser??0);const $e=de(ke),Ae=ae;if(ke.act==="kick"){const We=(Se=(Te=P.current)==null?void 0:Te.querySelector('.fm-prop[data-prop="ball"]'))==null?void 0:Se.getBoundingClientRect();We&&E({x:IH(We.x,N_(ke,Ae,"left"),window.innerWidth),drop:Math.max(48,window.innerHeight-We.y+24)})}const Qe=ke.act==="walk"||ke.act==="carry"?cn(Ae,$e):ke.ms;w(Qe),$(We=>N_({...ke,x:$e},Ae,We)),m($e),ae=$e,D.schedule(()=>z(Pe),Qe)},Q=()=>{const pe=P.current,ke=pe==null?void 0:pe.querySelector(".fm-sprite"),Pe=pe==null?void 0:pe.parentElement;if(!pe||!ke||!Pe)return null;const $e=pe.getBoundingClientRect(),Ae=Pe.getBoundingClientRect(),je=Ae.right-$e.right,Qe=Ae.width-je*2-ke.offsetWidth;return Qe>0?Qe:null},U=()=>{const pe=P.current,ke=pe==null?void 0:pe.querySelector(".fm-walker"),Pe=Q();if(!pe||!ke||Pe==null)return;const $e=pe.getBoundingClientRect().bottom-ke.getBoundingClientRect().bottom;if($e>0)return{ledgeH:$e,floorSpan:Pe}},re=()=>{const pe=P.current,ke=document.querySelector(".autofit-chip");if(!pe||!ke)return null;const Pe=pe.getBoundingClientRect(),$e=ke.getBoundingClientRect();return $e.width<=0||$e.height<=0?null:{left:$e.left-Pe.right,right:$e.right-Pe.right,height:$e.height}},de=pe=>{const ke=(pe.place??"ledge")==="floor"?Q()??Io:Io;return Math.max(-ke,Math.min(0,pe.x))},ge=()=>{D.schedule(()=>{const pe=bH(ae,Math.random,U()),ke=pe.some(Ae=>Ae.place==="floor")?re():null;let Pe=ae;const $e=pe.flatMap(Ae=>{const je=Pe;return Pe=Ae.x,Ae.place==="floor"&&Ae.act==="walk"?PH(je,Ae.x,ke):[Ae]});z($e)},Zz(Math.random))};return ge(),()=>{D.dispose(),T("ledge"),m(pe=>Math.max(-Io,Math.min(0,pe))),w(0),N(null),b(null),B(0)}},[n,a,I]),x.useEffect(()=>{if(!f||I){M(null);return}const D=j_(document),ae=z=>{const Q=EH(z,Math.random);M(Q.dance),V(Q.beatMs),D.schedule(()=>ae(Q.dance),CH(Math.random))};return ae(null),()=>D.dispose()},[f,I]),!n||a)return null;const F=()=>{if(!c){u(!0),p(!0);return}const D=!f;p(D),G(g_(D?"playVideo":"pauseVideo")),D||u(!1)};return i.jsxs("div",{ref:P,className:"fm","data-suspended":K?"":void 0,"data-place":C,style:{"--fm-beat":`${Z}ms`},children:[j&&!j.held&&i.jsx("div",{className:"fm-prop","data-prop":j.kind,"data-leaving":j.leaving?"":void 0,style:{"--fm-prop-x":`${j.at}px`,"--fm-roll-to":`${S.x}px`,"--fm-ball-drop":`${S.drop}px`,"--fm-ball-flight-ms":`${ZR}ms`,"--fm-ball-turn":R==="right"?"1080deg":"-1080deg"},children:C_[j.kind]}),(_==="lasso"||_==="rope-throw"||_==="rope-catch"||_==="climb"||_==="pull-up")&&i.jsxs("div",{className:"fm-rope","data-act":_,style:{"--fm-rope-x":`${h}px`,"--fm-rope-ms":`${y}ms`},children:[i.jsx("div",{className:"fm-rope-line"}),i.jsxs("svg",{className:"fm-rope-hook",viewBox:"0 0 9 9",shapeRendering:"crispEdges","aria-hidden":!0,children:[i.jsx("path",{d:"M4 8V3H3V1H1V3H0V5H2V4H3V6H5V4H6V5H8V3H7V1H5V3H4"}),i.jsx("rect",{className:"fm-rope-knot",x:"3",y:"6",width:"3",height:"2"})]})]}),i.jsxs("div",{className:"fm-walker","data-act":_??void 0,"data-place":C,"data-facing":R,style:{"--fm-x":`${h}px`,"--fm-walk-ms":`${y}ms`,"--fm-riser":`${H}px`,"--fm-skip-beat":`${QR}ms`},children:[(j==null?void 0:j.held)&&i.jsx("div",{className:"fm-held","data-prop":j.kind,"data-toss":j.leaving?"":void 0,children:C_[j.kind]}),["cast","fish","reel","stow"].includes(_)&&i.jsxs("svg",{className:"fm-fishing",viewBox:"0 0 24 32",shapeRendering:"crispEdges","aria-hidden":!0,children:[i.jsxs("g",{children:[i.jsx("path",{d:"M24 11H22V9H20V7H18V5H16V3H13V2H8"}),i.jsx("rect",{className:"fm-fishing-grip",x:"21",y:"9",width:"3",height:"3"})]}),i.jsxs("g",{className:"fm-fishing-line",children:[i.jsx("path",{d:"M8 2V26"}),i.jsxs("g",{className:"fm-float",children:[i.jsx("rect",{x:"7",y:"25",width:"3",height:"2"}),i.jsx("rect",{x:"8",y:"24",width:"1",height:"1"})]})]}),i.jsx("path",{className:"fm-ripple",d:"M3 28H6M10 28H14M5 30H12"})]}),["skip-ready","skip","skip-rest"].includes(_)&&i.jsxs("svg",{className:"fm-skipping-rope",viewBox:"0 0 26 26",shapeRendering:"crispEdges","aria-hidden":!0,children:[i.jsx("path",{className:"fm-skip-back",d:"M5 18H3V8H5V5H8V2H18V5H21V8H23V18H21"}),i.jsx("path",{className:"fm-skip-forward",d:"M5 18H3V14H5V11H8V9H18V11H21V14H23V18H21"}),i.jsx("path",{className:"fm-skip-front",d:"M5 18H3V21H5V23H8V25H18V23H21V21H23V18H21"}),i.jsx("path",{className:"fm-skip-return",d:"M5 18H3V19H8V20H18V19H23V18H21"}),i.jsx("path",{className:"fm-skip-handles",d:"M5 17V19M21 17V19"})]}),i.jsx("button",{type:"button",className:"fm-sprite","data-playing":f?"":void 0,"data-dance":f?J??JR[0]:void 0,"aria-pressed":f,onClick:F,title:f?"Stop Claude FM":"Play Claude FM — streams from YouTube","aria-label":f?"Stop Claude FM":"Play Claude FM",children:i.jsxs("svg",{viewBox:`0 0 ${y_} ${Kz}`,shapeRendering:"crispEdges","aria-hidden":!0,children:[i.jsx("g",{className:"fm-gear",children:i.jsx("g",{className:"fm-gear-motion",children:LH.map(D=>i.jsx("rect",{x:D.x,y:D.y,width:D.w,height:1,className:Hp[D.cell]},`g${D.y}-${D.x}`))})}),i.jsxs("g",{className:"fm-body",children:[E_.map(D=>i.jsx("rect",{x:D.x,y:D.y,width:D.w,height:1,fill:"var(--accent)"},`eye-bed-${D.x}`)),FH.map(D=>i.jsx("rect",{x:D.x,y:D.y,width:D.w,height:1,className:Hp[D.cell]},`b${D.y}-${D.x}`)),i.jsxs("g",{className:"fm-arms",children:[i.jsx("rect",{x:4,y:8,width:2,height:2}),i.jsx("rect",{x:12,y:8,width:1,height:2}),i.jsx("rect",{x:13,y:8,width:1,height:2,className:"fm-shade"})]}),E_.map(D=>i.jsx("rect",{x:D.x-(D.x>=y_/2?1:0)+(R==="right"?1:0),y:D.y,width:D.w,height:1,className:"fm-eye"},`eye-${D.x}`))]}),i.jsx("g",{className:"fm-hat",children:DH.map(D=>i.jsx("rect",{x:AH+D.x,y:RH+D.y,width:D.w,height:1,className:D.cell==="k"?"fm-hatband":void 0},`h${D.y}-${D.x}`))}),(_==="climb"||_==="rope-throw"||_==="rope-catch"||_==="pull-up")&&i.jsxs("g",{className:"fm-grip",children:[i.jsx("path",{className:"fm-grip-left",d:"M5 9H4V4H7V3H9V5H6V9Z"}),i.jsx("path",{className:"fm-grip-right",d:"M12 9H14V6H11V5H9V7H12Z"})]}),(_==="land"||_==="dismount")&&i.jsxs("g",{className:"fm-crouch-legs",children:[i.jsx("path",{d:"M6 11H8V13H6Z"}),i.jsx("path",{d:"M10 11H12V13H10Z"})]}),["sit","cast","fish","reel","stow"].includes(_)&&i.jsxs("g",{className:"fm-seated-legs",children:[i.jsx("path",{className:"fm-seated-far",d:"M10 10H12V11H11V14H8V13H9V11H10Z"}),i.jsx("path",{d:"M6 10H9V11H7V15H4V14H5V11H6Z"})]}),["left","right"].map(D=>i.jsx("g",{className:"fm-leg","data-side":D,children:qH[D].map(ae=>i.jsx("rect",{x:ae.x,y:ae.y,width:ae.w,height:1,className:Hp[ae.cell]},`${D}${ae.y}-${ae.x}`))},D))]})})]}),c&&n.channel&&i.jsx("iframe",{ref:W,className:"fm-frame",title:"Claude FM",src:zz(n.channel,window.location.origin),onLoad:()=>G(Hz()),allow:"autoplay; encrypted-media",sandbox:"allow-scripts allow-same-origin allow-presentation"})]})}),tM="agent-dag.character-enabled";function zH(e){return e!=="0"}function HH(){return zH(Da(tM))}const WH=15e3;function UH(e){return e.visibilityState==="visible"&&e.hasFocus()}function VH(e,t){return t||e===!0}function GH(){try{if(typeof crypto<"u"&&typeof crypto.randomUUID=="function")return crypto.randomUUID()}catch{}return`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`}const KH={"//":["What a user would NOTICE. One key per version that has something to say,","and no key at all for a version that has nothing — which is most of them.","","The rule this file exists to serve: before every release, ask 'what would a","user notice?' and write the answer here. 'Nothing user-visible' is a valid","and expected answer, and it is spelled by adding no key. A release with no","key shows no modal, and that silence is what keeps the modal worth reading","on the day it is not silent.","","What belongs here: something that changed on the user's machine or under","their hands — a hook written to or removed from settings.json, a default","that flipped, a control that moved or went away, a stored preference that","changed meaning. What does not: bounds, races, assertions that could not","fire, anything that is invisible when it is correct.","","Write it for the person running the deck, not for the person reading the","diff. `title` is the sentence they scan; `body` is what they need in order","to act on it, or to stop worrying about it.","","Keys are versions exactly as package.json spells them. A key that is not a","version, or an entry missing either field, fails the suite rather than","being quietly dropped — see src/web/__tests__/release-notes-file.test.ts.","Ordering here is for humans; the deck sorts by version itself.","","A title may open with an emoji, and if it does, put exactly ONE space after","it. Not two: the dialog gives a leading emoji its own optical gap, because","a colour glyph is drawn edge to edge inside its advance and one word space","after one reads as none. A second space here would be a lie in the data","about a defect in the type, and the suite refuses both it and no space at","all.","","A release that genuinely has nothing to say is spelled TWICE: no key here,",'and its version written into "//nothing-to-say" below. One spelling on its',"own is ambiguous — a missing key reads the same whether it was a decision","or a forgotten step, and five releases in a row were once forgotten. The list","is what tells the two apart, and release-notes-current-version.test.ts fails","the release whose version is in neither place. Any key opening with // is a","note to the author and never a release."],"//nothing-to-say":["3.23.1","3.23.2","3.23.3","3.23.4","3.26.0","3.26.1","3.26.3","3.26.4"],"3.25.0":[{title:"🖱️ A click goes to the session, a double-click opens the details",body:"Clicking a card frames it with the rest of its session and leaves the detail panel shut. Double-click a card to open its details; `j`/`k`, the session list, Enter and `D` still open them too."},{title:"🔭 Cards stay readable when you zoom out",body:"At every zoom a card shows its name, its state and anything waiting on you, instead of shrinking to a coloured pill. Hover or focus a card to see it whole. Recap notes read at a distance too, and show the full recap on hover."},{title:"🌐 The Machine panel shows your network",body:"A new Network section shows download, upload and the round trip to Claude's API, and names the route when traffic goes through a VPN or a Tailscale exit node. Those checks run only while the panel is open. The panel is regrouped into CPU, Memory, Network and Thermal, with a flag at the top when something needs attention."},{title:"🎨 See each theme before you pick it",body:"The Appearance menu shows a small preview of the deck in Light and in Dark. Claude FM also keeps its volume when a notification chime plays, instead of dipping under it."}],"3.24.1":[{title:"🎛️ Appearance is one small menu now",body:"The topbar's appearance control opens a compact menu where you can choose Light or Dark and show or hide the character. The character stays on by default, and your choice is remembered."}],"3.24.0":[{title:"🎧 Claude FM plays from the minimap",body:"A small character stands on the minimap's top edge. Press it and the Claude channel's live stream plays; press it again and it stops. It only turns up when the channel is actually broadcasting, so a deck with no network never shows it at all."},{title:"🤠 And it gets on with its day",body:"It walks that edge, tidies up what it finds, kicks a ball along it, sits with its legs over the side, and watches the board through a scope. Now and then it drops onto the canvas and ropes its way back up. Headphones on while the music plays, a hat when it does not."}],"3.23.5":[{title:"🧭 The accounts panel opens on the account you are on",body:"Its windows, its resets and how old the numbers are — whole, at the top of the column. Every other account stands behind one row that says how many of them a switch could actually reach; press it to see them, or rest on it to be shown their names and how much room each has left."},{title:"⚙️ Auto-switch moved in there with them",body:"It is behind that same row now, after the accounts it switches between, rather than at the foot of the panel. The row says `auto 90%` or `auto off` so you can tell what the policy is doing without opening it — and says so in amber when it is armed with nowhere left to go."}],"3.23.0":[{title:"🧭 The accounts column leads with accounts",body:`The live account is the open row: its windows as bars, when each one resets, and how old the numbers are. Every other account rests on the two figures a switch is decided by, and opens with a click when you want the rest.
93
93
 
94
94
  A problem stays on the row — an expired login, one that was never stored, a keychain the deck cannot open — with the reason and the sign-in one press away. Auto-switch is one row now: its threshold and its switch. Local network moved out of the column into a view of its own, reached from a row at the foot that says how many of the paired machines are on right now, and shows which ones when you hover it.`},{title:"💬 A resting session shows Claude Code's recap beside its card",body:"When a session stops, Claude Code's own recap of what it did is drawn beside the card — so a board you come back to says what happened without opening anything."},{title:"🪟 The chrome went quiet",body:`The topbar is borderless, one set of corners runs through the app, the canvas ground is flat, and the minimap, the zoom controls, the type filter and the Machine and Usage panels read as tooling rather than as cards.
95
95
 
@@ -287,7 +287,7 @@ Both CLIs get the finish tone. The second tone — Claude is waiting for you —
287
287
 
288
288
  Waiting for a click: this browser plays no sound until the page has been used at least once. Anything you press unlocks it.`:"";return c+u+f+`
289
289
 
290
- Click to set the volume and the sound of each tone, and to hear either one.`}function fh(e){const t=Math.max(0,Math.floor(e));return`${t} event${t===1?"":"s"}`}const o2=99;function lG(e){const t=Math.max(0,Math.floor(e));return t>o2?`${o2}+`:String(t)}const cG="Pause the canvas";function uG(e){if(!e.paused)return"Pause live updates — events keep arriving and are applied when you resume (Space)";const t=Math.max(0,Math.floor(e.dropped??0));return t>0?`The pause is full — ${fh(e.held)} held and ${t} older ${t===1?"one":"ones"} already dropped. Resume to follow the canvas again (Space)`:e.held<=0?"Nothing has arrived since you paused. Resume to follow the canvas again (Space)":`${fh(e.held)} arrived while paused and will be applied in order when you resume (Space)`}function dG(e){return e.connected||!e.paused?null:"The canvas is paused as well — Space resumes it, but nothing new arrives until the stream is back."}const vI="paused · full",hG=(e,t)=>t>0?vI:e>0?`paused · ${lG(e)}`:"paused";function fG(e){const t=Math.max(0,Math.floor(e.dropped??0));return e.connected?e.paused?{tone:"paused",resting:!1,label:hG(e.held,t),widest:vI,title:t>0?`Connected — the pause is full at ${fh(e.held)}; the oldest are being dropped as new ones arrive. Resume to catch up (Space)`:e.held>0?`Connected — ${fh(e.held)} held until you resume (Space)`:"Connected — updates held until you resume (Space)"}:{tone:"live",resting:!0,label:"live",widest:"live",title:"Receiving events"}:{tone:"dead",resting:!1,label:"offline",widest:"offline",title:e.paused?"SSE disconnected — and the canvas is paused, so resuming will not bring events back until it reconnects":"SSE disconnected"}}const pG=x.lazy(()=>y2(()=>import("./UsageHistoryModal-DfPKQO6q.js"),[])),mG=x.lazy(()=>y2(()=>import("./BrowserWatchModal-CjOjANxG.js"),[]));function i2(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()||""}const gG={agent:DD,sessionGroup:gF,recapNote:wF},yG={recapTie:vF},wG=300,l2=130,vG=160,xI="react-flow__node";function ux(e){var t,n;return!!e&&((n=(t=e.classList)==null?void 0:t.contains)==null?void 0:n.call(t,xI))===!0}const dx=80,hx=.86;function c2(e){if(!e)return 0;const t=e.getBoundingClientRect();let n=t.right;for(const r of document.querySelectorAll(".sysdetail:not(.leaving), .usage-panel:not(.leaving)")){const a=r.getBoundingClientRect();a.width>0&&a.left>t.left&&(n=Math.min(n,a.left))}return Math.max(0,t.right-n)}function xG(e){try{const t=document.querySelector(`.${xI}[data-id="${CSS.escape(e)}"]`);t==null||t.focus({preventScroll:!0})}catch{}}const bG=["a[href]","button:not(:disabled)","input:not(:disabled)","select:not(:disabled)","textarea:not(:disabled)","summary","[tabindex]"].join(","),kG=420,Id=18,u2=400,fx=450,lb="agent-dag.layout",cb="agent-dag.layoutFrame",ub="agent-dag.viewport",bI="agent-dag.sessionListOpen",kI="agent-dag.detailOpen",NI="agent-dag.usagePanelOpen",_I="agent-dag.systemPanelOpen",d2="agent-dag.accountsPanelOpen",px="agent-dag.versionNoticeDismissed",h2="agent-dag.oldNameNoticeDismissed",NG=15*6e4,mx={git_checkout:"this deck runs from a git checkout — pull instead:",npx:"npx runs from a cache that cannot be upgraded in place — run:",not_writable:"the install directory is not writable by this user — run:",opted_out:"installs are off (AGENTS_DECK_NO_INSTALL=1) — run:",retired_name:"this install came from a name that is no longer published — run:"},$d="agent-dag.autoRestart",f2="agent-dag.bundleReloadedFor";function _G(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(bI)==="1"}catch{return!1}}function SG(e){if(!(typeof window>"u"))try{window.localStorage.setItem(bI,e?"1":"0")}catch{}}function jG(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(kI)==="1"}catch{return!1}}function EG(e){if(!(typeof window>"u"))try{window.localStorage.setItem(kI,e?"1":"0")}catch{}}function CG(){const e=Da(NI);return e===null?!0:e==="1"}function TG(e){if(!(typeof window>"u"))try{window.localStorage.setItem(NI,e?"1":"0")}catch{}}function AG(){const e=Da(_I);return e===null?!0:e==="1"}function RG(e){if(!(typeof window>"u"))try{window.localStorage.setItem(_I,e?"1":"0")}catch{}}function MG(){const e={positions:[],pins:[]};if(typeof window>"u")return e;try{const t=window.localStorage.getItem(lb);if(!t)return e;const n=JSON.parse(t);if(!("v"in n)){const a=Object.entries(n).filter(([,l])=>l&&typeof l.x=="number"&&typeof l.y=="number");return{positions:a,pins:a.map(([l])=>l)}}return{positions:Object.entries(n.positions??{}).filter(([,a])=>a&&typeof a.x=="number"&&typeof a.y=="number"),pins:Array.isArray(n.pins)?n.pins:[]}}catch{return e}}function Od(e,t){if(!(typeof window>"u"))try{const n={};for(const[r,a]of e)n[r]=a;for(const[r,a]of t)n[r]=a;window.localStorage.setItem(lb,JSON.stringify({v:2,positions:n,pins:Array.from(t.keys())}))}catch{}}function IG(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(cb);if(!e)return null;const t=JSON.parse(e);return!(typeof(t==null?void 0:t.width)=="number"&&typeof(t==null?void 0:t.height)=="number")||!(t.width>0&&t.height>0)?null:{width:t.width,height:t.height}}catch{return null}}function $G(e){if(!(typeof window>"u"))try{window.localStorage.setItem(cb,JSON.stringify(e))}catch{}}function OG(){if(typeof window>"u")return null;try{return AV(window.localStorage.getItem(ub))}catch{return null}}function PG(e){if(!(typeof window>"u"))try{window.localStorage.setItem(ub,JSON.stringify(e))}catch{}}function p2(){if(!(typeof window>"u")){try{window.localStorage.removeItem(lb)}catch{}try{window.localStorage.removeItem(ub)}catch{}try{window.localStorage.removeItem(cb)}catch{}}}function LG(e,t){const n=e.agents.get(t);if(!n)return;const r=[];for(const h of e.agents.values())h.sessionId===t&&r.push(h);const a={schemaVersion:1,exportedAt:new Date().toISOString(),sessionId:t,label:n.label,cwd:n.cwd,startedAt:n.startedAt,endedAt:n.endedAt,model:n.model,agents:r.map(h=>({id:h.id,kind:h.kind,label:h.label,parentId:h.parentId,state:h.state,startedAt:h.startedAt,endedAt:h.endedAt,model:h.model,cwd:h.cwd,usage:h.usage,prompts:h.prompts,tools:h.tools.map(m=>({id:m.id,name:m.name,inputPreview:m.inputPreview,startedAt:m.startedAt,endedAt:m.endedAt,ok:m.ok,errorPreview:m.errorPreview,usage:m.usage}))}))},l=JSON.stringify(a,null,2),c=new Blob([l],{type:"application/json"}),u=URL.createObjectURL(c),f=document.createElement("a"),p=(n.label||"session").replace(/[^a-z0-9._-]/gi,"_");f.href=u,f.download=`${nn}-${p}-${t.slice(0,8)}.json`,document.body.appendChild(f),f.click(),document.body.removeChild(f),setTimeout(()=>URL.revokeObjectURL(u),1e3)}const SI={file:"📁",shell:"⚡",web:"🌐",agent:"🤖",task:"📋",plan:"🧭",mcp:"🔌",other:"✨"},DG={file:"M3.4 1.8h4.5l2.7 2.7v7.7H3.4z M7.9 1.8v2.7h2.7",shell:"M2.4 3.8 5.6 7l-3.2 3.2 M7.4 10.6h4.2",web:"M7 1.8a5.2 5.2 0 1 0 0 10.4A5.2 5.2 0 1 0 7 1.8z M1.8 7h10.4 M7 1.8c-1.5 1.4-2.3 3.1-2.3 5.2s.8 3.8 2.3 5.2c1.5-1.4 2.3-3.1 2.3-5.2S8.5 3.2 7 1.8z",agent:"M3.3 4.8h7.4a1.2 1.2 0 0 1 1.2 1.2v4.8a1.2 1.2 0 0 1-1.2 1.2H3.3a1.2 1.2 0 0 1-1.2-1.2V6a1.2 1.2 0 0 1 1.2-1.2z M7 4.8V2.4 M5.3 8.2h.01 M8.7 8.2h.01",task:"M2.2 4l1.2 1.2 2-2.2 M7.4 4.2h4.4 M2.2 9.4l1.2 1.2 2-2.2 M7.4 9.6h4.4",plan:"M7 1.8a5.2 5.2 0 1 0 0 10.4A5.2 5.2 0 1 0 7 1.8z M9 5 8 8 5 9l1-3z",mcp:"M5 1.8v2.6 M9 1.8v2.6 M3.6 4.4h6.8v2.2a3.4 3.4 0 0 1-6.8 0z M7 10v2.2",other:"M3.5 7h.01 M7 7h.01 M10.5 7h.01"};function FG({cat:e}){return i.jsx("svg",{className:"cat-glyph",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:i.jsx("path",{d:DG[e]})})}const ph={file:"file",shell:"shell",web:"web",agent:"agent",task:"task",plan:"plan",mcp:"mcp",other:"other"},jI=cR,m2=new WeakMap;function qG(e,t){let n=m2.get(e);(!n||n.revision!==e.revision||n.open!==t)&&(n={revision:e.revision,open:t,byId:new Map,branches:Q6(e.agents.values())},m2.set(e,n));const{byId:r,branches:a}=n;return l=>{let c=r.get(l.id);if(!c){const u=l.kind==="root"?a.get(l.sessionId):void 0;c=u?{...l,onOpenContext:t,branch:u}:{...l,onOpenContext:t},r.set(l.id,c)}return c}}function e0(e){const t=new Map;for(const n of e.agents.values())n.tools.length>0&&t.set(n.id,Math.min(4,n.tools.length));return t}function BG(e,t,n,r,a,l,c,u,f,p,h,m,y,w,_,N,j,b){var J,M,Z,V;const S=[],E=[],C=qG(e,b);for(const I of e.agents.values()){if(!j.has(I.id))continue;const q=I.exitAt!=null,W=N!=null&&!N.has(I.id),G=[q?"rf-exiting":"",W?"rf-spotlit-out":""].filter(Boolean).join(" ")||void 0,F=l.get(I.id);if(S.push({id:I.id,type:"agent",position:{x:0,y:0},data:C(I),className:G,ariaLabel:zD(I,t),...F?{width:F.width,height:F.height}:null}),I.parentId&&j.has(I.parentId)){const z=th(I.sessionId),Q=q,U=_.size>0&&(_.has(I.id)||_.has(I.parentId)),re=N!=null&&!N.has(I.id)&&!N.has(I.parentId),de=I.state==="active"?2:1.5,ge=U?de+1.5:de,pe=Q?.2:re?.12:1,ke=["sess-edge",I.state==="active"?"sess-live":"sess-idle",Q?"rf-edge-exiting":"",U?"rf-edge-selected":""].filter(Boolean).join(" ");E.push({id:`e:${I.parentId}->${I.id}`,source:I.parentId,target:I.id,animated:(I.state==="active"||U)&&!Q,type:"smoothstep",style:{"--session-hue":z,strokeWidth:`calc(${ge}px * var(--edge-k, 1))`,opacity:pe,transition:"var(--edge-transition)"},className:ke})}const D=I.kind==="root"?jh(I):null,ae=D?oR(I.sessionId,D.at):null;if(D&&ae&&!V6(ae)){const z=E0(I.id),Q=th(I.sessionId),U=l.get(z);S.push({id:z,type:"recapNote",position:{x:0,y:0},data:{sessionId:I.sessionId,parentId:I.id,recap:D,noteKey:ae,hue:Q},className:W?"rf-spotlit-out":void 0,selectable:!1,focusable:!1,ariaLabel:`Claude Code's recap for ${I.label}`,...U?{width:U.width,height:U.height}:null}),E.push({id:`e:recap:${I.id}`,source:z,target:I.id,type:"recapTie",className:"recap-edge",focusable:!1,style:{"--session-hue":Q}})}}const T=e0(e),R=`${y}#lanes:${fV(T)}`,$=new Set(S.filter(I=>I.type==="recapNote").map(I=>I.id));for(const I of Array.from(h.keys()))X6(I)&&!$.has(I)&&!a.has(I)&&(h.delete(I),m.delete(I));const H=S.filter(I=>kW(I.id,a,h,m));if(H.length>0||R!==w.current){if(H.length>0){const I=xV(yV(S,E,{direction:"LR",pinned:a,measured:l,availableWidth:n,availableHeight:r,lanes:T}),a,q=>Wd(q,h,m)?void 0:h.get(q));for(const q of I)Wd(q.id,h,m)&&M_(q.id,q.position,h,m);vV(S,h,a,l,new Set(H.filter(q=>q.type!=="recapNote").map(q=>q.id)),T,{width:n,height:r});for(const q of H){if(q.type!=="recapNote")continue;const W=(J=q.data)==null?void 0:J.parentId;if(!W)continue;const G=a.get(W)??(Wd(W,h,m)?void 0:h.get(W));if(!G)continue;const F=((M=l.get(q.id))==null?void 0:M.width)??wG,D=((Z=l.get(q.id))==null?void 0:Z.height)??l2,ae=((V=l.get(W))==null?void 0:V.height)??l2;M_(q.id,{x:G.x-vG-F,y:G.y+(ae-D)/2},h,m)}}wV(S,h,a,l,T),w.current=R}const B=bV(S,h,a,l,c,!f||p,T);B.length>0&&u(B);const P=vW(e.agents.values());Td(h,P),Td(m,P),Td(a,P),Td(l,wW(e.agents.values()));const K=[];let X=!1;for(const I of S){let q=a.get(I.id)??h.get(I.id);q||(q=NW(I.id,h,m),X=!0),K.push({...I,position:q})}return X&&(w.current=""),{nodes:K,edges:E}}function zG(){return i.jsx(v0,{children:i.jsx(UG,{})})}const HG=e=>e.transform[2]>=e.maxZoom,WG=e=>e.transform[2]<=e.minZoom;function UG(){var fi,pi,mi,gi;const e=kh(),t=wt(HG),n=wt(WG),r=Gt(),a=x.useState(Mx)[0],l=x.useRef(a),[,c]=x.useState(0),u=x.useCallback(()=>c(L=>L+1),[]),[f,p]=x.useState(jG);x.useEffect(()=>{EG(f)},[f]);const[h,m]=x.useState(()=>new Set),[y,w]=x.useState(null),[_,N]=x.useState(null),j=x.useCallback((L,O,ne=!O)=>{m(oe=>{if(!O)return new Set([L]);const be=new Set(oe);return be.has(L)?be.delete(L):be.add(L),be}),w(oe=>O&&oe===L?oe:L),!O&&ne&&p(!0)},[]),b=x.useCallback(()=>{m(new Set),w(null)},[]),[S,E]=x.useState(null),[C,T]=x.useState(null),R=x.useCallback(L=>T(L),[]),[$,H]=x.useState(!1),[B,P]=x.useState(!1),[K,X]=x.useState(!1),J=x.useRef(null),[M,Z]=x.useState(_G);x.useEffect(()=>{SG(M)},[M]);const[V,I]=x.useState(CG);x.useEffect(()=>{TG(V)},[V]);const[q,W]=x.useState(AG);x.useEffect(()=>{RG(q)},[q]);const G=x.useRef(!1),[F,D]=x.useState(()=>{const L=(()=>{try{const O=window.localStorage.getItem(d2);return O===null?!0:O==="1"}catch{return!0}})();return L&&M?(G.current=!0,!1):L});x.useEffect(()=>{if(!(!F&&G.current))try{window.localStorage.setItem(d2,F?"1":"0")}catch{}},[F]),x.useEffect(()=>{!M&&G.current&&(G.current=!1,D(!0))},[M]);const ae=Mp(F,200),z=Mp(V,130),Q=Mp(q,130),[U,re]=x.useState(null);x.useEffect(()=>{let L=null;try{L=localStorage.getItem("agent-dag.sound")}catch{}re(L===null?!0:L==="on")},[]);const de=x.useCallback(()=>{re(L=>{var ne;const O=L!==!0;try{localStorage.setItem("agent-dag.sound",O?"on":"off")}catch{}return O&&((ne=Me.current)==null||ne.unlock()),O})},[]),ge=x.useCallback(L=>{de()},[de]),pe=x.useRef(ge);pe.current=ge;const ke=x.useRef(U);ke.current=U;const[Pe,$e]=x.useState(()=>Cz(Da)),Ae=x.useRef(Pe);Ae.current=Pe;const je=x.useRef(null),Qe=x.useCallback((L,O=!1)=>{var ne,oe;if((ne=Me.current)==null||ne.unlock(),je.current!==null&&clearTimeout(je.current),je.current=null,!O){(oe=Me.current)==null||oe.play(L,!0);return}je.current=setTimeout(()=>{var be;je.current=null,(be=Me.current)==null||be.play(L,!0)},Nz)},[]),Te=x.useCallback((L,O)=>{$e(ne=>{const oe={level:Fc(O.level??ne[L].level),figure:UR(L,O.figure??ne[L].figure)};try{localStorage.setItem(VR[L],String(oe.level)),localStorage.setItem(GR[L],oe.figure)}catch{}return{...ne,[L]:oe}}),Qe(L,!0)},[Qe]);x.useEffect(()=>()=>{je.current!==null&&clearTimeout(je.current)},[]);const[Se,We]=x.useState(!1),dt=x.useRef(null),[ct,le]=x.useState(!1),Ne=x.useRef(null);x.useEffect(()=>{Se&&le(!1)},[Se]);const Me=x.useRef(null),[tt,Ge]=x.useState("locked");x.useEffect(()=>{const L=Az({enabled:()=>ke.current===!0,prefs:()=>Ae.current,onState:Ge});Me.current=L,Ge(L.state());const O=()=>L.unlock();return window.addEventListener("pointerdown",O,{once:!0,capture:!0}),window.addEventListener("keydown",O,{once:!0,capture:!0}),()=>{window.removeEventListener("pointerdown",O,{capture:!0}),window.removeEventListener("keydown",O,{capture:!0})}},[]);const[Je,ye]=x.useState(!1),[Ce,Ve]=x.useState(!1),[ce,at]=x.useState(null),[ut,rt]=x.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(px)??""}catch{return""}}),[st,jt]=x.useState(!1),vt=x.useRef(0),[mt,_n]=x.useState(!1),Et=x.useCallback((L=!1)=>(L&&(vt.current=Date.now(),_n(!0)),fetch(L?"/api/version?refresh=1":"/api/version").then(O=>O.ok?O.json():null).then(O=>{O&&at(O)}).catch(()=>{}).finally(()=>{L&&_n(!1)})),[]),zt=x.useCallback(()=>{Et(Date.now()-vt.current>=NG)},[Et]);x.useEffect(()=>{Et();const L=window.setInterval(zt,5*6e4),O=()=>{document.visibilityState==="visible"&&zt()};return document.addEventListener("visibilitychange",O),()=>{window.clearInterval(L),document.removeEventListener("visibilitychange",O)}},[Et,zt]),x.useEffect(()=>{Je&&Et()},[Je,Et]),x.useEffect(()=>{const L=GH();let O=null;const ne=De=>{fetch("/api/presence",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tab:L,looking:De}),keepalive:!0}).catch(()=>{})},oe=()=>{const De=UH(document);VH(O,De)&&ne(De),O=De},be=()=>{O&&ne(!1),O=!1};oe();const we=window.setInterval(oe,WH);return window.addEventListener("focus",oe),window.addEventListener("blur",oe),document.addEventListener("visibilitychange",oe),window.addEventListener("pagehide",be),()=>{window.clearInterval(we),window.removeEventListener("focus",oe),window.removeEventListener("blur",oe),document.removeEventListener("visibilitychange",oe),window.removeEventListener("pagehide",be),be()}},[]);const fe=(ce==null?void 0:ce.notice)??null,[nt,Tt]=x.useState(null),Sn=x.useRef(!1);x.useEffect(()=>{if(Sn.current)return;const L=R_(),O=nW(L),ne=lW({stored:O,running:(ce==null?void 0:ce.running)??null,notes:A_,remembers:rW(L)});if(ne.reason==="no-version")return;Sn.current=!0,ne.record&&sW(L,ne.record);const oe=iW({tourSeen:aW(L),decision:ne}),be=ne.show.length?{entries:ne.show,since:O,firstRun:!1}:null;oe.tour&&X(!0),oe.notes==="now"?Tt(be):oe.notes==="after"&&(J.current=be)},[ce==null?void 0:ce.running]);const dn=(ce==null?void 0:ce.running)??"3.26.3",ir=x.useMemo(()=>nM(A_,null,dn),[dn]),It=x.useCallback(()=>{Tt({entries:ir,since:null,firstRun:!1})},[ir]),[hn,jn]=x.useState(null),[Ht,$n]=x.useState(Jx);x.useEffect(()=>{let L=!1;return fetch("/api/health").then(O=>O.ok?O.json():null).then(O=>{L||($n(nG(O)),!(!O||typeof O.workspace!="string")&&jn(O.workspace))}).catch(()=>{}),()=>{L=!0}},[Je]);const Yn=x.useRef(Ht);Yn.current=Ht;const On=fe?`${fe.kind}:${fe.to}`:"",En=fe!=null&&ut!==On,_r=x.useCallback(()=>{rt("");try{window.localStorage.setItem(px,"")}catch{}},[]),Kr=x.useCallback(()=>{if(fe){rt(On);try{window.localStorage.setItem(px,On)}catch{}}},[fe,On]),[Hs,Ws]=x.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(h2)??""}catch{return""}}),yn=ce!=null&&ce.invokedAs&&ce.invokedAs!==nn?ce.invokedAs:null,ee=yn!=null&&Hs!==yn,Re=x.useCallback(()=>{if(yn){Ws(yn);try{window.localStorage.setItem(h2,yn)}catch{}}},[yn]),Le=((fi=ce==null?void 0:ce.upgrade)==null?void 0:fi.state)??"idle",Ie=nz(ce==null?void 0:ce.upgrade),ze=x.useRef(!1),ht=x.useCallback(async()=>{if(Ls(ze.current||Le==="running")){ze.current=!0;try{await fetch("/api/upgrade",{method:"POST"})}catch{}await Et(),ze.current=!1}},[Le,Et]);x.useEffect(()=>{if(Le!=="running")return;const L=window.setInterval(Et,3e3);return()=>window.clearInterval(L)},[Le,Et]);const Lt=x.useCallback(async()=>{const L=ce==null?void 0:ce.command;!L||!await Eh(L)||(jt(!0),window.setTimeout(()=>jt(!1),1600))},[ce==null?void 0:ce.command]),$t=x.useCallback(()=>{Z(L=>(L||D(O=>(O&&(G.current=!0),!1)),!L))},[]),Sr=x.useCallback(()=>{G.current=!1,D(L=>(L||Z(!1),!L))},[]),[kt,xt]=x.useState(!1),[Us,ms]=x.useState(!1),[qa,Vs]=x.useState(()=>{try{return Number(localStorage.getItem(I_))||0}catch{return 0}}),[Ba,Uo]=x.useState([]),[Yr,Cn]=x.useState(!1);x.useEffect(()=>{let L=!0;const O=()=>{fetch("/api/browser-watch?live=0").then(oe=>oe.ok?oe.json():null).then(oe=>{var be;!L||!(oe!=null&&oe.ok)||(Uo(oe.episodes??[]),Cn(((be=oe.settings)==null?void 0:be.enabled)===!0))}).catch(()=>{})};O();const ne=setInterval(O,5*6e4);return()=>{L=!1,clearInterval(ne)}},[]);const[za,wn]=x.useState([]),tu=x.useRef(new Set),[Vo,nu]=x.useState(null);x.useEffect(()=>{let L=!0,O=0;const ne=()=>{fetch("/api/lan").then(oe=>oe.ok?oe.json():null).then(oe=>L?(oe!=null&&oe.ok&&wn(s_(Array.isArray(oe.pending)?oe.pending:[],oe.aliases)),oe):null).catch(()=>null).then(oe=>{L&&(O=window.setTimeout(ne,(oe==null?void 0:oe.enabled)===!0?Hx:qR))})};return ne(),()=>{L=!1,window.clearTimeout(O)}},[]);const Ha=x.useCallback(async(L,O)=>{if(!Vo){nu(L);try{const oe=await(await fetch("/api/lan/peer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:L,fp:O})})).json().catch(()=>null);oe&&Array.isArray(oe.pending)?wn(s_(oe.pending,oe.aliases)):wn(be=>be.filter(we=>we.fp!==O))}catch{}finally{nu(null)}}},[Vo]),Xr=x.useMemo(()=>UW(Ba,qa).length,[Ba,qa]),[Wa,Ua]=x.useState(0),ru=x.useRef(null),[Zh,Go]=x.useState(!1),Gs=x.useRef(null),[ml,Ks]=x.useState(0),Xn=x.useState(()=>CW({protect:L=>z5(l.current,L)}))[0],[Ys,gt]=x.useState(!1),Ko=x.useCallback(()=>{const L=Xn.paused&&Xn.dropped>0,O=Xn.setPaused(!Xn.paused);L&&H5(l.current);for(const ne of O)l.current=eN(l.current,ne);gt(Xn.paused)},[Xn]),[Wt,gl]=x.useState(Date.now()),[jr,Va]=x.useState(()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem($d)!=="0"}catch{return!0}}),yl=x.useRef(!1),wl=x.useCallback(()=>{const L=!jr;yl.current=!0;try{window.localStorage.removeItem($d)}catch{}Va(L),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:L})}).then(O=>O.ok?O.json():null).then(O=>{var ne;O!=null&&O.ok&&Va(((ne=O.prefs)==null?void 0:ne.autoUpdate)!==!1)}).catch(()=>{})},[jr]),[Zn,Qn]=x.useState(!1),[Zr,Qr]=x.useState("restart"),[Xs,Zs]=x.useState(null),Tn=x.useRef(!1),su=x.useRef(null),vl=x.useRef(0),Er=x.useCallback(async L=>{if(!Ls(Tn.current))return;const O=(L==null?void 0:L.upgrade)===!0;Tn.current=!0,su.current=Ie;const ne=++vl.current;Qr(O?"npx":"restart"),Qn(!0);try{window.sessionStorage.setItem("agent-dag.restartPending",(fe==null?void 0:fe.to)??"")}catch{}try{await fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({upgrade:O})})}catch{}window.setTimeout(()=>{if(vl.current===ne&&Tn.current){Tn.current=!1,Qn(!1);try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}}},O?18e4:3e4)},[fe==null?void 0:fe.to,Ie]),xl=x.useRef(null);x.useEffect(()=>{const L=d_(l.current.agents.values())>0,O=iz({enabled:jr,kind:fe==null?void 0:fe.kind,canRestart:(ce==null?void 0:ce.canRestart)===!0,noticeOpen:En,visible:document.visibilityState==="visible",busy:L,idleSince:xl.current,now:Wt});xl.current=O.idleSince,O.restart&&Er()},[jr,fe==null?void 0:fe.kind,ce==null?void 0:ce.canRestart,En,Wt,Er]);const bl=d_(l.current.agents.values()),Ga=oz(bl),kl=WR({enabled:jr,kind:fe==null?void 0:fe.kind,canRestart:(ce==null?void 0:ce.canRestart)===!0,noticeOpen:En,visible:document.visibilityState==="visible",busy:bl>0,idleSince:xl.current,now:Wt});x.useEffect(()=>{const L=ce==null?void 0:ce.running;let O=null,ne=null;try{O=window.sessionStorage.getItem("agent-dag.restartPending"),ne=window.sessionStorage.getItem(f2)}catch{return}const oe=tz({bundle:"3.26.3",running:L,pending:O,lastTried:ne});if(oe==="reload"){try{window.sessionStorage.setItem(f2,L??"")}catch{return}window.location.reload();return}if(oe!=="confirm")return;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}Tn.current=!1,Qn(!1),Zs(L??null);const be=window.setTimeout(()=>Zs(null),6e3);return()=>window.clearTimeout(be)},[ce==null?void 0:ce.running]),x.useEffect(()=>{if(Zn&&rz({asked:su.current,reported:Ie})){try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}Tn.current=!1,Qn(!1)}},[Zn,Ie]);const au=x.useState(()=>TV(MG()))[0],At=x.useRef(au.pinned),Jr=x.useRef(null),Cr=x.useState(()=>OG())[0],[Qs,Qh]=x.useState(()=>new Set),[Js,Yo]=x.useState(RW),[es,Nl]=x.useState(HH),[gs,ts]=x.useState(()=>t2(i2)),Xo=x.useMemo(()=>EV(gs),[gs]),Zo=x.useCallback(L=>jV(L,Xo),[Xo]),[_l,Qo]=x.useState(!1);x.useEffect(()=>{document.documentElement.dataset.theme=Js;try{window.localStorage.setItem(oM,Js)}catch{}ts(L=>{const O=t2(i2);return CV(L,O)?L:O})},[Js]),x.useEffect(()=>{try{window.localStorage.setItem(tM,es?"1":"0")}catch{}},[es]);const vn=x.useCallback((L,O)=>{if(Md({durationMs:O,documentHidden:document.hidden})){e.setViewport(L,{duration:O});return}const{d3Zoom:ne,d3Selection:oe}=r.getState(),be=oe==null?void 0:oe.property("__zoom");if(ne&&oe&&be&&be.k>0&&L.zoom>0){ne.transform(oe,be.scale(L.zoom/be.k).translate((L.x-be.x)/L.zoom,(L.y-be.y)/L.zoom));return}e.setViewport(L,{duration:0})},[e,r]),ys=x.useRef(null),Yt=x.useRef(0),Tr=x.useRef(null),Jo=x.useRef(()=>{});x.useEffect(()=>{if(!Cr)return;const L=window.setTimeout(()=>{try{vn(Cr,0)}catch{}Jn.current=Date.now()},60);return()=>window.clearTimeout(L)},[vn,Cr]);const ea=x.useRef(!0),[Ka,ei]=x.useState(null);x.useEffect(()=>{const L=new EventSource("/events"),O=jW(u,{now:()=>Date.now(),setTimeout:(we,De)=>window.setTimeout(we,De),clearTimeout:we=>window.clearTimeout(we)});let ne=!1;const oe=typeof BroadcastChannel=="function"?OW(new BroadcastChannel(IW),Math.random().toString(36).slice(2),()=>ne):null,be=window.setInterval(()=>{ne||!oe||oe.ask(600).then(we=>{ne||Ve($W(we))})},3e3);return L.addEventListener("open",()=>{ye(!0),Qo(!0)}),L.addEventListener("error",()=>{ye(!1),ei(null)}),L.addEventListener("open",()=>{ne=!0,Ve(!1)}),L.addEventListener("error",()=>{ne=!1}),L.addEventListener("replay-end",()=>{ea.current=!1,O.flush(),ei(Date.now())}),L.addEventListener("hook",we=>{var De;try{const Ke=JSON.parse(we.data);if(!Xn.accept(Ke))return;l.current=eN(l.current,Ke);const ot=Ke.replay===!0||ea.current||Date.now()-Ke.receivedAt>3e4;ot?O.replay():O.live();const Ye=Tz(Ke,ot);Ye&&((De=Me.current)==null||De.play(Ye))}catch{}}),()=>{L.close(),O.cancel(),window.clearInterval(be),oe==null||oe.leave()}},[u]),x.useEffect(()=>{const L=setInterval(()=>{const O=Date.now();gl(O);let ne=W5(l.current,O,J1);U5(l.current,O,J1)&&(ne=!0);const oe=[],be=we=>{oe.push(we)};q5(l.current,O,DW,FW,be)&&(ne=!0),B5(l.current,O,qW,BW,be)&&(ne=!0),oe.length>0&&fetch("/api/forget",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({ids:oe})}).catch(()=>{}),m(we=>yW(we,l.current.agents)),w(we=>we!=null&&!l.current.agents.has(we)?null:we),T(we=>we!=null&&!l.current.agents.has(we)?null:we),E(we=>we!=null&&!l.current.agents.has(we)?null:we),ne&&u()},250);return()=>clearInterval(L)},[u]);const Ya=x.useRef(null),Jn=x.useRef(0),Xa=420,An=x.useCallback((L=500)=>{const O=dx,ne=1,oe=.2,be=hx;try{const we=document.querySelector(".canvas-wrap"),De=Array.from(document.querySelectorAll(".react-flow__node")).filter(bt=>bt.offsetWidth>0);if(!we||De.length===0)return;const Ke=we.getBoundingClientRect(),ot=e.getViewport();if(!Number.isFinite(ot.zoom)||ot.zoom<=0)return;const Ye=bt=>(bt-Ke.left-ot.x)/ot.zoom,Ct=bt=>(bt-Ke.top-ot.y)/ot.zoom,qt=De.map(bt=>bt.getBoundingClientRect()),Ss=Math.min(...qt.map(bt=>Ye(bt.left))),fo=Math.max(...qt.map(bt=>Ye(bt.right))),lr=Math.min(...qt.map(bt=>Ct(bt.top))),po=Math.max(...qt.map(bt=>Ct(bt.bottom))),js=fo-Ss,ha=po-lr;if(!(js>0&&ha>0))return;const Ul=c2(we),Es=bt=>Math.max(oe,Math.min(ne,(Ke.width-Ul-O*2)/(js+bt)*be,(Ke.height-O*2)/ha*be)),Dn=BV(Es(Xa),Es(0)),yt={x:O-Ss*Dn,y:Math.max(O,(Ke.height-ha*Dn)/2)-lr*Dn,zoom:Dn},Nt=++Yt.current;vn(yt,L),Jn.current=Date.now(),ys.current=Md({durationMs:L,documentHidden:document.hidden})?{target:yt,until:Date.now()+L+60}:null,window.setTimeout(()=>{var bt;try{if(((bt=ys.current)==null?void 0:bt.target)===yt&&(ys.current=null),Yt.current!==Nt)return;const Zt=e.getViewport();(Math.abs(Zt.zoom-Dn)>.01||Math.abs(Zt.x-yt.x)>2)&&vn(yt,0)}catch{}},L+60)}catch{}},[e,vn]);x.useEffect(()=>{const L=()=>{if(!document.hidden)return;const O=ys.current;if(ys.current=null,!(!O||Date.now()>O.until)){try{vn(O.target,0)}catch{}Jn.current=Date.now()}};return document.addEventListener("visibilitychange",L),()=>document.removeEventListener("visibilitychange",L)},[vn]);const Sl=x.useRef(""),jl=x.useRef(null),ou=x.useRef(0),ta=x.useCallback(()=>{ou.current=Date.now()},[]),El=x.useRef(null),iu=x.useRef(0),Cl=x.useCallback(()=>{iu.current=Date.now()},[]),Tl=x.useCallback(L=>({hasSourceEvent:!!L,at:Date.now(),lastDeckFitAt:Jn.current,lastCanvasInputAt:iu.current}),[]),Jh="agent-dag.autoFitDisabled",ns=x.useRef(!1),[Al,lu]=x.useState(!1);x.useEffect(()=>{try{window.localStorage.removeItem(Jh)}catch{}},[]);const Za=x.useCallback(()=>{ns.current||(ns.current=!0,lu(!0))},[]),cu=x.useCallback(()=>{ns.current=!1,lu(!1),An(400)},[e,An]);x.useEffect(()=>{const L=setInterval(()=>{if(ns.current||Date.now()-ou.current<800)return;const O=l.current,ne=Date.now(),oe=[];for(const we of O.agents.values())Xx(we,ne)&&oe.push({id:we.id});if(oe.length===0)return;const be=[];for(const{id:we}of oe){const De=Ar.current.get(we),Ke=At.current.get(we)??Xt.current.get(we);!De||!Ke||be.push({x:Ke.x,y:Ke.y,width:De.width,height:De.height})}OV({pane:El.current,viewport:e.getViewport(),boxes:be})&&An(600)},1500);return()=>clearInterval(L)},[e]);const na=x.useRef(!1),Ar=x.useRef(new Map),Rl=x.useRef(0),ef=x.useCallback(L=>{const O=Ar.current;let ne=!1;for(const oe of L.nodeInternals.values()){const be=oe.width,we=oe.height;if(be==null||we==null)continue;const De=O.get(oe.id);De?(Math.abs(De.height-we)>4||Math.abs(De.width-be)>4)&&(O.set(oe.id,{width:be,height:we}),ne=!0):(O.set(oe.id,{width:be,height:we}),ne=!0)}return ne&&(Rl.current+=1),Rl.current},[]),Ml=wt(ef),[uu,tf]=x.useState(0);x.useEffect(()=>{let L=0;const O=()=>{const oe=Ar.current;let be=!1;for(const we of document.querySelectorAll(".react-flow__node[data-id]")){const De=we.getAttribute("data-id");if(!De)continue;const Ke=we.offsetWidth,ot=we.offsetHeight;if(!Ke||!ot)continue;const Ye=oe.get(De);(!Ye||Math.abs(Ye.width-Ke)>4||Math.abs(Ye.height-ot)>4)&&(oe.set(De,{width:Ke,height:ot}),be=!0)}be&&tf(we=>we+1)};if(na.current)return;let ne=0;return document.visibilityState==="hidden"?ne=window.setTimeout(O,32):L=requestAnimationFrame(O),()=>{cancelAnimationFrame(L),window.clearTimeout(ne)}});const Xt=x.useRef(au.positions),du=x.useRef(new Set),ti=x.useRef(""),ra=x.useMemo(()=>{const L=[];for(const O of l.current.agents.values())Xx(O,Wt)&&L.push(O.id+(O.parentId?`>${O.parentId}`:""));return L.sort(),`${L.join("|")}#sv${Ml}.${uu}`},[l.current,l.current.revision,Wt,Ml,uu]),Qa=x.useRef(null);x.useEffect(()=>(Qa.current!=null&&window.clearTimeout(Qa.current),Qa.current=window.setTimeout(()=>{Od(Xt.current,At.current)},1500),()=>{Qa.current!=null&&window.clearTimeout(Qa.current)}),[ra]),x.useEffect(()=>{if(Sl.current===ra)return;const L=Sl.current;if(Sl.current=ra,!L||ns.current)return;Date.now()-Jn.current>1200&&An(400),Ya.current&&window.clearTimeout(Ya.current),Ya.current=window.setTimeout(()=>{ns.current||An(500)},280)},[ra,e,An]);const Ja=x.useMemo(()=>bW(l.current,h),[l.current,l.current.revision,h]),ws=x.useMemo(()=>NV(l.current,Wt),[l.current,l.current.revision,Wt]),vs=x.useRef(null),[sa,Il]=x.useState({w:0,h:0});x.useEffect(()=>{const L=vs.current;if(!L||typeof ResizeObserver>"u")return;const O=new ResizeObserver(ne=>{var be;const oe=(be=ne[0])==null?void 0:be.contentRect;oe&&(El.current={width:oe.width,height:oe.height},Il(we=>Math.abs(we.w-oe.width)>40||Math.abs(we.h-oe.height)>40?{w:oe.width,h:oe.height}:we))});return O.observe(L),El.current={width:L.clientWidth,height:L.clientHeight},Il({w:L.clientWidth,h:L.clientHeight}),()=>O.disconnect()},[]);const hu=x.useCallback(L=>{var ne,oe;const O=L.target;!(O!=null&&O.closest)||O.closest(bG)!==L.currentTarget||(L.preventDefault(),(oe=(ne=document.activeElement)==null?void 0:ne.blur)==null||oe.call(ne))},[]),fu=x.useRef(new Map),[eo,aa]=x.useState(!1);x.useEffect(()=>{const L=window.setTimeout(()=>aa(!0),2500);return()=>window.clearTimeout(L)},[]);const[nf,$l]=x.useState(!1),rs=x.useRef(null),[oa,Ol]=x.useState(!1),[to,no]=x.useState("detail"),xs=x.useRef(null),ia=x.useRef(null),rf=x.useCallback(()=>{var oe;const L=Rl.current;if(((oe=ia.current)==null?void 0:oe.version)===L)return ia.current.card;const O=[];for(const be of l.current.agents.keys()){const we=Ar.current.get(be);we&&O.push(we)}const ne=LV(O);return ia.current={version:L,card:ne},ne},[]),pu=x.useCallback(()=>{rs.current&&(window.clearTimeout(rs.current),rs.current=null),$l(!1)},[]),Pl=x.useCallback(L=>{L.length!==0&&queueMicrotask(()=>{$l(!0),rs.current&&window.clearTimeout(rs.current),rs.current=window.setTimeout(()=>$l(!1),kG+80)})},[]);x.useEffect(()=>()=>{rs.current&&window.clearTimeout(rs.current)},[]);const sn=y?l.current.agents.get(y):null,Ll=f&&sn!=null,[ni,mu]=x.useState(0);x.useEffect(()=>{const L=c2(vs.current);mu(O=>Math.abs(O-L)>40?L:O)},[Q,z,V,Ll,sa.w]);const Dl=x.useRef(ni);Dl.current=ni;const ri=sa.w>0?Math.max(0,(sa.w-ni-dx*2)*hx):0,si=sa.h>0?Math.max(0,(sa.h-dx*2)*hx):0,sf=Z6(),{nodes:ss,edges:Pn}=x.useMemo(()=>BG(l.current,Wt,ri,si,At.current,Ar.current,fu.current,Pl,eo,oa,Xt.current,du.current,ra,ti,h,Ja,ws,R),[l.current,l.current.revision,Wt,ri,si,eo,oa,ra,h,Ja,ws,R,Wa,sf]),ro=x.useState(IG)[0],Fl=x.useRef(ro);x.useEffect(()=>{if(!eo||oa)return;const L={width:ri,height:si};if(!(L.width>0&&L.height>0))return;const O=Fl.current;if(Fl.current=L,$G(L),!O||O.width===L.width&&O.height===L.height)return;const ne={direction:"LR",pinned:At.current,measured:Ar.current,lanes:e0(l.current)};if(!gV(ss,Pn,ne,O,L))return;const oe=Tr.current&&Date.now()-Tr.current.at<1500?Tr.current.id:null,be=oe??Ns.current,we=be?At.current.get(be)??Xt.current.get(be):void 0;for(const De of Array.from(Xt.current.keys()))At.current.has(De)||Xt.current.delete(De);du.current.clear(),ti.current="",u(),window.setTimeout(()=>{if(Od(Xt.current,At.current),ns.current){if(oe){Jo.current(oe);return}const De=be?At.current.get(be)??Xt.current.get(be):void 0;if(we&&De&&(De.x!==we.x||De.y!==we.y)){const Ke=e.getViewport();Yt.current+=1,vn({x:Ke.x-(De.x-we.x)*Ke.zoom,y:Ke.y-(De.y-we.y)*Ke.zoom,zoom:Ke.zoom},0),Jn.current=Date.now()}return}An(500)},80)},[ri,si,eo,oa,u,An,e,vn]);const ql=x.useMemo(()=>{const L=new Map;for(const ne of ss){const oe=ne.data;if(!(oe!=null&&oe.sessionId)||oe.exitAt!=null)continue;const be=ne.width,we=ne.height;if(be==null||we==null)continue;const De=ne.position.x,Ke=ne.position.y,ot=De+be,Ye=Ke+we,Ct=L.get(oe.sessionId);Ct?(Ct.minX=Math.min(Ct.minX,De),Ct.minY=Math.min(Ct.minY,Ke),Ct.maxX=Math.max(Ct.maxX,ot),Ct.maxY=Math.max(Ct.maxY,Ye)):L.set(oe.sessionId,{minX:De,minY:Ke,maxX:ot,maxY:Ye})}const O=[];for(const[ne,oe]of L){const be=oe.maxX-oe.minX+Id*2,we=oe.maxY-oe.minY+Id*2;O.push({id:`group:${ne}`,type:uI,position:{x:oe.minX-Id,y:oe.minY-Id},data:{sessionId:ne,w:be,h:we},width:be,height:we,style:{width:be,height:we},zIndex:-1,draggable:!0,selectable:!1,focusable:!1,deletable:!1,connectable:!1})}return O},[ss]),gu=x.useMemo(()=>{const L=[...ql,...ss],O=Gs.current;return!O||O.size===0?L:L.map(ne=>{const oe=O.get(ne.id);return oe?{...ne,position:oe}:ne})},[ql,ss,ml]),so=x.useMemo(()=>{const L=new Set;for(const O of l.current.agents.values())for(const ne of O.tools)L.add(jI(ne.name));return Object.keys(SI).filter(O=>L.has(O))},[l.current,l.current.revision]);x.useEffect(()=>{if(so.length<=1){Go(!1);return}let L=0;const O=()=>{const ne=ru.current;if(ne&&!document.hidden){const oe=ne.getBoundingClientRect(),be=Array.from(document.querySelectorAll(".react-flow__node, .tool-burst")).map(De=>De.getBoundingClientRect()),we=SV(oe,be,8);Go(De=>De===we?De:we)}L=window.setTimeout(O,300)};return O(),()=>window.clearTimeout(L)},[so.length]);const Bl=x.useCallback(L=>{Qh(O=>{const ne=new Set(O);return ne.has(L)?ne.delete(L):ne.add(L),ne})},[]),zl=_?$5(l.current.agents,_):null,yu=x.useCallback(async()=>{try{await fetch("/api/clear",{method:"POST"})}catch{}l.current=Mx(),At.current.clear(),Ar.current.clear(),Xt.current.clear(),ti.current="",p2(),b(),u()},[u,b]),bs=x.useRef($);bs.current=$;const ai=x.useRef(B);ai.current=B;const ks=x.useRef(!1);ks.current=zl!=null||kt||C!=null||K||S!=null||Us||B||nt!=null;const la=x.useCallback(L=>{const O=lz(L,{confirmOpen:bs.current,modalOpen:ks.current});O==="confirm"?H(!0):O==="clear"&&(H(!1),yu())},[yu]),oi=x.useCallback(()=>{At.current.clear(),Xt.current.clear(),ti.current="",p2(),u(),window.setTimeout(()=>An(500),80)},[u,e,An]),ao=x.useCallback(()=>An(500),[An]),Ln=x.useRef(ss);Ln.current=ss;const xn=x.useCallback(L=>{var Ct;const O=vs.current,ne=l.current.agents.get(L);if(!O||!ne)return;const oe=e0(l.current),be=(qt,Ss)=>{const fo=Ar.current.get(qt.id);if(!fo)return null;const lr=Ss&&oe.has(qt.id)?Xa:0;return{x:qt.position.x,y:qt.position.y,width:fo.width+lr,height:fo.height}},we=Ln.current.find(qt=>qt.id===L),De=we?be(we,!1):null;if(!De)return;const Ke=[];for(const qt of Ln.current){if(qt.type!=="agent"&&qt.type!=="recapNote"||((Ct=qt.data)==null?void 0:Ct.sessionId)!==ne.sessionId)continue;const Ss=be(qt,qt.type==="agent");Ss&&Ke.push(Ss)}const ot=O.getBoundingClientRect(),Ye=WV({pane:{width:ot.width,height:ot.height},insets:{top:56,left:72,bottom:32,right:Dl.current+32},context:UV(Ke)??De,anchor:De});ja(),Za(),Tr.current={id:L,at:Date.now()},Yt.current+=1,vn(Ye,fx),Jn.current=Date.now(),ys.current=Md({durationMs:fx,documentHidden:document.hidden})?{target:Ye,until:Date.now()+fx+60}:null},[vn,Za]);Jo.current=xn;const wu=x.useCallback(L=>{const O=Ln.current.find(ne=>ne.id===L&&ne.type==="agent");return O?O.data:void 0},[]),ii=x.useCallback(L=>{var O;return(O=l.current.agents.get(L))==null?void 0:O.label},[]),vu=x.useCallback(L=>{var oe;const O=Ln.current.find(be=>be.id===L&&be.type==="recapNote");if(!O)return;const ne=O.data;return{recap:ne.recap,hue:ne.hue,sessionLabel:(oe=l.current.agents.get(ne.parentId))==null?void 0:oe.label}},[]),xu=x.useCallback(()=>{var ne;const L=(ne=vs.current)==null?void 0:ne.getBoundingClientRect(),O=document.documentElement;return L?{width:L.right-Dl.current,height:L.bottom}:{width:O.clientWidth,height:O.clientHeight}},[]),Ns=x.useRef(y);Ns.current=y;const oo=x.useCallback(L=>{const O=Ln.current.filter(we=>we.type==="agent"),ne=hW(O.map(we=>({id:we.id,x:we.position.x,y:we.position.y})),Ns.current,L),oe=ne?O.find(we=>we.id===ne):void 0;if(!oe)return;const be=ux(document.activeElement);j(oe.id,!1),window.setTimeout(()=>{try{xn(oe.id)}catch{}be&&xG(oe.id)},30)},[j,xn]),li=x.useRef(null),_s=x.useCallback(L=>{j(L,!1),window.setTimeout(()=>{try{xn(L)}catch{}},60)},[j,xn]),Rr=x.useRef(null);x.useEffect(()=>{let L=-1/0;const O=()=>{L=performance.now()},ne=oe=>{Rr.current=performance.now()-L<250?oe.target:null};return window.addEventListener("pointerdown",O,!0),window.addEventListener("focusin",ne,!0),()=>{window.removeEventListener("pointerdown",O,!0),window.removeEventListener("focusin",ne,!0)}},[]),x.useEffect(()=>{const L=O=>{var Ke,ot;const ne=O.target,oe={tagName:ne==null?void 0:ne.tagName,isContentEditable:ne==null?void 0:ne.isContentEditable,role:(Ke=ne==null?void 0:ne.getAttribute)==null?void 0:Ke.call(ne,"role"),type:ne==null?void 0:ne.type,pointerFocused:ne!=null&&ne===Rr.current};if(O.key==="Escape"){const Ye=k6({overlayOpen:nh.depth()>0,typing:j0(oe)});Ye==="dismiss"?nh.dismissTop():Ye==="blur"?ne==null||ne.blur():(gW(oe)&&(ne==null||ne.blur()),b());return}if(Sh(O))return;const be=ux(ne)?(ot=ne==null?void 0:ne.getAttribute)==null?void 0:ot.call(ne,"data-id"):null,we=be&&Ln.current.some(Ye=>Ye.id===be)?be:null,De=pW(O,we);if(De.kind==="activate"){O.preventDefault(),j(De.nodeId,De.additive);return}if(De.kind!=="node"&&!(De.nodeId==null&&R6(oe,O.key))&&!M6({key:O.key,modalOpen:ks.current,sheetOpen:ai.current})){if(O.key===" "&&(O.preventDefault(),Ko()),(O.key==="c"||O.key==="C")&&la("shortcut"),(O.key==="r"||O.key==="R")&&oi(),(O.key==="f"||O.key==="F")&&ao(),(O.key==="z"||O.key==="Z")&&Ns.current&&xn(Ns.current),(O.key==="l"||O.key==="L")&&$t(),O.key==="d"||O.key==="D")if(Ns.current)p(Ye=>!Ye);else{const Ye=Tp(l.current.agents.values());Ye.length>0?_s(Ye[0].id):oo(1)}if((O.key==="h"||O.key==="H")&&xt(Ye=>!Ye),(O.key==="u"||O.key==="U")&&I(Ye=>!Ye),(O.key==="a"||O.key==="A")&&Yn.current.claude&&Sr(),(O.key==="j"||O.key==="J")&&oo(1),(O.key==="k"||O.key==="K")&&oo(-1),O.key==="w"||O.key==="W"){const Ye=h6(Tp(l.current.agents.values()),li.current);Ye&&(li.current=Ye.id,_s(Ye.id))}(O.key==="t"||O.key==="T")&&Yo(Ye=>Ye==="dark"?"light":"dark"),(O.key==="m"||O.key==="M")&&Yn.current.claude&&ke.current!==null&&pe.current(O.shiftKey),(O.key==="s"||O.key==="S")&&W(Ye=>!Ye),(O.key==="b"||O.key==="B")&&ms(Ye=>!Ye),(O.key==="v"||O.key==="V")&&Yn.current.claude&&ke.current!==null&&We(Ye=>!Ye),O.key==="?"&&P(Ye=>!Ye)}};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[la,oi,ao,b,j,oo,_s,xn,Ko]);const ci=l.current.agents.size,Ut=x.useMemo(()=>Tp(l.current.agents.values()),[l.current,l.current.revision]),bu=x.useMemo(()=>f6(l.current.agents.values()),[l.current,l.current.revision]),ku=x.useRef(null);x.useEffect(()=>{const L=PW({waiting:Ut.length,running:bu,connected:Je}),O=ku.current;if(ku.current=L,(O==null?void 0:O.title)!==L.title&&(document.title=L.title),(O==null?void 0:O.icon)!==L.icon){const ne=document.querySelector('link[rel="icon"]');ne&&(ne.href=LW[L.icon])}},[Ut.length,bu,Je]);const[io,af]=x.useState(""),Hl=HW(Ut);x.useEffect(()=>{af(L=>WW(L,Hl))},[Hl]);const[lo,St]=x.useState(()=>typeof Notification>"u"?"denied":Notification.permission),[Mr,ca]=x.useState(null),[as,ui]=x.useState(!1),[Wl,ua]=x.useState(!1);x.useEffect(()=>{let L=!0;return fetch("/api/prefs").then(O=>O.ok?O.json():null).then(O=>{var ne,oe,be;if(!(!L||!(O!=null&&O.ok))){if(!yl.current){let we=!1;try{we=window.localStorage.getItem($d)==="0",window.localStorage.removeItem($d)}catch{}we&&((ne=O.prefs)==null?void 0:ne.autoUpdate)!==!1?(Va(!1),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:!1})}).catch(()=>{})):Va(((oe=O.prefs)==null?void 0:oe.autoUpdate)!==!1)}ui(((be=O.prefs)==null?void 0:be.notifications)===!0),ua(O.notificationsVetoed===!0)}}).catch(()=>{}),()=>{L=!1}},[]);const co=x.useRef(()=>{}),da=x.useCallback(()=>{const L=!as;ui(L),L&&typeof Notification<"u"&&Notification.permission==="default"&&co.current(),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({notifications:L})}).then(O=>O.ok?O.json():null).then(O=>{var ne;O!=null&&O.ok&&(ui(((ne=O.prefs)==null?void 0:ne.notifications)===!0),ua(O.notificationsVetoed===!0))}).catch(()=>{})},[as]),Nu=typeof Notification<"u";x.useEffect(()=>{if(!Mr)return;const O=setTimeout(()=>ca(null),Mr==="blocked"?8e3:4e3);return()=>clearTimeout(O)},[Mr]);const _u=x.useCallback(()=>{typeof Notification>"u"||Notification.requestPermission().then(L=>{const O=L;St(O),O==="granted"?ca("on"):O==="denied"&&ca("blocked")})},[]);co.current=_u;const uo=x.useRef(new Set),di=x.useRef(null),hi=Ut.map(L=>_h(L.id,L.waiting)).join("|");x.useEffect(()=>{y6(di.current,lo)&&(di.current=lo,uo.current=Ap(Ut))},[lo]);const ho=x.useRef(!1);return x.useEffect(()=>{w6(ho.current,Ka)&&(ho.current=!0,uo.current=Ap(Ut))},[Ka]),x.useEffect(()=>{if(typeof Notification>"u"||Notification.permission!=="granted"||!v6(di.current,Ka))return;const L=typeof document>"u"||!document.hidden,O=m6(Ut,uo.current,L,as);for(const ne of O)try{const oe=new Notification(ne.title,{body:ne.body,tag:ne.key});oe.onclick=()=>{window.focus(),_s(ne.sessionId),oe.close()}}catch{}uo.current=L?Ap(Ut):g6(Ut,O,uo.current)},[hi,Ka]),i.jsxs("div",{className:"app",children:[i.jsx("a",{className:"skip-link",href:"#canvas",children:"Skip to the canvas"}),i.jsxs("header",{className:"topbar",children:[i.jsxs("div",{className:"readout",children:[i.jsxs("div",{className:"brand",children:[i.jsx("span",{className:"logo"}),i.jsx("h1",{children:nn}),fe?i.jsxs("button",{type:"button",className:"v stale",onClick:()=>{It(),_r()},"aria-haspopup":"dialog","aria-label":eG({...fe,open:En}),title:fe.kind==="restart"?`Running v${fe.from}; v${fe.to} is installed on disk. Restart to pick it up · click for what's new`:`Running v${fe.from}; v${fe.to} is on npm · click for what's new`,children:["v",fe.from,i.jsx("span",{className:"v-dot","aria-hidden":!0})]}):(()=>{const L={running:dn,latest:ce==null?void 0:ce.latest,latestPending:ce==null?void 0:ce.latestPending,checkedAgo:ce!=null&&ce.checkedAt?Bd(Wt-ce.checkedAt):null,checkFailedAgo:ce!=null&&ce.checkFailedAt&&ce.checkFailedAt>(ce.checkedAt??0)?Bd(Wt-ce.checkFailedAt):null,checkDisabled:ce==null?void 0:ce.checkDisabled,checking:mt};return i.jsxs("button",{type:"button",className:mt?"v checking":"v",onClick:()=>{It(),Et(!0)},"aria-busy":mt||void 0,"aria-haspopup":"dialog","aria-label":JV(L),title:QV(L),children:["v",L.running]})})()]}),i.jsx("span",{className:"status",children:(()=>{const L=fG({connected:Je,paused:Ys,held:Xn.size,dropped:Xn.dropped});return L.resting?null:i.jsx("span",{className:`pill ${L.tone}`,title:L.title,children:i.jsxs("span",{className:"pill-box",children:[i.jsx("span",{className:"pill-widest","aria-hidden":!0,children:L.widest}),i.jsx("span",{className:"pill-label",children:L.label})]})})})()}),i.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:io}),Ut.length>0&&i.jsxs("button",{type:"button",className:"waiting-stat",onClick:()=>{li.current=Ut[0].id,_s(Ut[0].id)},title:`Blocked waiting for you — click, or press W, to go to the one that has been stuck longest:
290
+ Click to set the volume and the sound of each tone, and to hear either one.`}function fh(e){const t=Math.max(0,Math.floor(e));return`${t} event${t===1?"":"s"}`}const o2=99;function lG(e){const t=Math.max(0,Math.floor(e));return t>o2?`${o2}+`:String(t)}const cG="Pause the canvas";function uG(e){if(!e.paused)return"Pause live updates — events keep arriving and are applied when you resume (Space)";const t=Math.max(0,Math.floor(e.dropped??0));return t>0?`The pause is full — ${fh(e.held)} held and ${t} older ${t===1?"one":"ones"} already dropped. Resume to follow the canvas again (Space)`:e.held<=0?"Nothing has arrived since you paused. Resume to follow the canvas again (Space)":`${fh(e.held)} arrived while paused and will be applied in order when you resume (Space)`}function dG(e){return e.connected||!e.paused?null:"The canvas is paused as well — Space resumes it, but nothing new arrives until the stream is back."}const vI="paused · full",hG=(e,t)=>t>0?vI:e>0?`paused · ${lG(e)}`:"paused";function fG(e){const t=Math.max(0,Math.floor(e.dropped??0));return e.connected?e.paused?{tone:"paused",resting:!1,label:hG(e.held,t),widest:vI,title:t>0?`Connected — the pause is full at ${fh(e.held)}; the oldest are being dropped as new ones arrive. Resume to catch up (Space)`:e.held>0?`Connected — ${fh(e.held)} held until you resume (Space)`:"Connected — updates held until you resume (Space)"}:{tone:"live",resting:!0,label:"live",widest:"live",title:"Receiving events"}:{tone:"dead",resting:!1,label:"offline",widest:"offline",title:e.paused?"SSE disconnected — and the canvas is paused, so resuming will not bring events back until it reconnects":"SSE disconnected"}}const pG=x.lazy(()=>y2(()=>import("./UsageHistoryModal-DlRe0P3F.js"),[])),mG=x.lazy(()=>y2(()=>import("./BrowserWatchModal-BUWNIaK8.js"),[]));function i2(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()||""}const gG={agent:DD,sessionGroup:gF,recapNote:wF},yG={recapTie:vF},wG=300,l2=130,vG=160,xI="react-flow__node";function ux(e){var t,n;return!!e&&((n=(t=e.classList)==null?void 0:t.contains)==null?void 0:n.call(t,xI))===!0}const dx=80,hx=.86;function c2(e){if(!e)return 0;const t=e.getBoundingClientRect();let n=t.right;for(const r of document.querySelectorAll(".sysdetail:not(.leaving), .usage-panel:not(.leaving)")){const a=r.getBoundingClientRect();a.width>0&&a.left>t.left&&(n=Math.min(n,a.left))}return Math.max(0,t.right-n)}function xG(e){try{const t=document.querySelector(`.${xI}[data-id="${CSS.escape(e)}"]`);t==null||t.focus({preventScroll:!0})}catch{}}const bG=["a[href]","button:not(:disabled)","input:not(:disabled)","select:not(:disabled)","textarea:not(:disabled)","summary","[tabindex]"].join(","),kG=420,Id=18,u2=400,fx=450,lb="agent-dag.layout",cb="agent-dag.layoutFrame",ub="agent-dag.viewport",bI="agent-dag.sessionListOpen",kI="agent-dag.detailOpen",NI="agent-dag.usagePanelOpen",_I="agent-dag.systemPanelOpen",d2="agent-dag.accountsPanelOpen",px="agent-dag.versionNoticeDismissed",h2="agent-dag.oldNameNoticeDismissed",NG=15*6e4,mx={git_checkout:"this deck runs from a git checkout — pull instead:",npx:"npx runs from a cache that cannot be upgraded in place — run:",not_writable:"the install directory is not writable by this user — run:",opted_out:"installs are off (AGENTS_DECK_NO_INSTALL=1) — run:",retired_name:"this install came from a name that is no longer published — run:"},$d="agent-dag.autoRestart",f2="agent-dag.bundleReloadedFor";function _G(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(bI)==="1"}catch{return!1}}function SG(e){if(!(typeof window>"u"))try{window.localStorage.setItem(bI,e?"1":"0")}catch{}}function jG(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(kI)==="1"}catch{return!1}}function EG(e){if(!(typeof window>"u"))try{window.localStorage.setItem(kI,e?"1":"0")}catch{}}function CG(){const e=Da(NI);return e===null?!0:e==="1"}function TG(e){if(!(typeof window>"u"))try{window.localStorage.setItem(NI,e?"1":"0")}catch{}}function AG(){const e=Da(_I);return e===null?!0:e==="1"}function RG(e){if(!(typeof window>"u"))try{window.localStorage.setItem(_I,e?"1":"0")}catch{}}function MG(){const e={positions:[],pins:[]};if(typeof window>"u")return e;try{const t=window.localStorage.getItem(lb);if(!t)return e;const n=JSON.parse(t);if(!("v"in n)){const a=Object.entries(n).filter(([,l])=>l&&typeof l.x=="number"&&typeof l.y=="number");return{positions:a,pins:a.map(([l])=>l)}}return{positions:Object.entries(n.positions??{}).filter(([,a])=>a&&typeof a.x=="number"&&typeof a.y=="number"),pins:Array.isArray(n.pins)?n.pins:[]}}catch{return e}}function Od(e,t){if(!(typeof window>"u"))try{const n={};for(const[r,a]of e)n[r]=a;for(const[r,a]of t)n[r]=a;window.localStorage.setItem(lb,JSON.stringify({v:2,positions:n,pins:Array.from(t.keys())}))}catch{}}function IG(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(cb);if(!e)return null;const t=JSON.parse(e);return!(typeof(t==null?void 0:t.width)=="number"&&typeof(t==null?void 0:t.height)=="number")||!(t.width>0&&t.height>0)?null:{width:t.width,height:t.height}}catch{return null}}function $G(e){if(!(typeof window>"u"))try{window.localStorage.setItem(cb,JSON.stringify(e))}catch{}}function OG(){if(typeof window>"u")return null;try{return AV(window.localStorage.getItem(ub))}catch{return null}}function PG(e){if(!(typeof window>"u"))try{window.localStorage.setItem(ub,JSON.stringify(e))}catch{}}function p2(){if(!(typeof window>"u")){try{window.localStorage.removeItem(lb)}catch{}try{window.localStorage.removeItem(ub)}catch{}try{window.localStorage.removeItem(cb)}catch{}}}function LG(e,t){const n=e.agents.get(t);if(!n)return;const r=[];for(const h of e.agents.values())h.sessionId===t&&r.push(h);const a={schemaVersion:1,exportedAt:new Date().toISOString(),sessionId:t,label:n.label,cwd:n.cwd,startedAt:n.startedAt,endedAt:n.endedAt,model:n.model,agents:r.map(h=>({id:h.id,kind:h.kind,label:h.label,parentId:h.parentId,state:h.state,startedAt:h.startedAt,endedAt:h.endedAt,model:h.model,cwd:h.cwd,usage:h.usage,prompts:h.prompts,tools:h.tools.map(m=>({id:m.id,name:m.name,inputPreview:m.inputPreview,startedAt:m.startedAt,endedAt:m.endedAt,ok:m.ok,errorPreview:m.errorPreview,usage:m.usage}))}))},l=JSON.stringify(a,null,2),c=new Blob([l],{type:"application/json"}),u=URL.createObjectURL(c),f=document.createElement("a"),p=(n.label||"session").replace(/[^a-z0-9._-]/gi,"_");f.href=u,f.download=`${nn}-${p}-${t.slice(0,8)}.json`,document.body.appendChild(f),f.click(),document.body.removeChild(f),setTimeout(()=>URL.revokeObjectURL(u),1e3)}const SI={file:"📁",shell:"⚡",web:"🌐",agent:"🤖",task:"📋",plan:"🧭",mcp:"🔌",other:"✨"},DG={file:"M3.4 1.8h4.5l2.7 2.7v7.7H3.4z M7.9 1.8v2.7h2.7",shell:"M2.4 3.8 5.6 7l-3.2 3.2 M7.4 10.6h4.2",web:"M7 1.8a5.2 5.2 0 1 0 0 10.4A5.2 5.2 0 1 0 7 1.8z M1.8 7h10.4 M7 1.8c-1.5 1.4-2.3 3.1-2.3 5.2s.8 3.8 2.3 5.2c1.5-1.4 2.3-3.1 2.3-5.2S8.5 3.2 7 1.8z",agent:"M3.3 4.8h7.4a1.2 1.2 0 0 1 1.2 1.2v4.8a1.2 1.2 0 0 1-1.2 1.2H3.3a1.2 1.2 0 0 1-1.2-1.2V6a1.2 1.2 0 0 1 1.2-1.2z M7 4.8V2.4 M5.3 8.2h.01 M8.7 8.2h.01",task:"M2.2 4l1.2 1.2 2-2.2 M7.4 4.2h4.4 M2.2 9.4l1.2 1.2 2-2.2 M7.4 9.6h4.4",plan:"M7 1.8a5.2 5.2 0 1 0 0 10.4A5.2 5.2 0 1 0 7 1.8z M9 5 8 8 5 9l1-3z",mcp:"M5 1.8v2.6 M9 1.8v2.6 M3.6 4.4h6.8v2.2a3.4 3.4 0 0 1-6.8 0z M7 10v2.2",other:"M3.5 7h.01 M7 7h.01 M10.5 7h.01"};function FG({cat:e}){return i.jsx("svg",{className:"cat-glyph",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:i.jsx("path",{d:DG[e]})})}const ph={file:"file",shell:"shell",web:"web",agent:"agent",task:"task",plan:"plan",mcp:"mcp",other:"other"},jI=cR,m2=new WeakMap;function qG(e,t){let n=m2.get(e);(!n||n.revision!==e.revision||n.open!==t)&&(n={revision:e.revision,open:t,byId:new Map,branches:Q6(e.agents.values())},m2.set(e,n));const{byId:r,branches:a}=n;return l=>{let c=r.get(l.id);if(!c){const u=l.kind==="root"?a.get(l.sessionId):void 0;c=u?{...l,onOpenContext:t,branch:u}:{...l,onOpenContext:t},r.set(l.id,c)}return c}}function e0(e){const t=new Map;for(const n of e.agents.values())n.tools.length>0&&t.set(n.id,Math.min(4,n.tools.length));return t}function BG(e,t,n,r,a,l,c,u,f,p,h,m,y,w,_,N,j,b){var J,M,Z,V;const S=[],E=[],C=qG(e,b);for(const I of e.agents.values()){if(!j.has(I.id))continue;const q=I.exitAt!=null,W=N!=null&&!N.has(I.id),G=[q?"rf-exiting":"",W?"rf-spotlit-out":""].filter(Boolean).join(" ")||void 0,F=l.get(I.id);if(S.push({id:I.id,type:"agent",position:{x:0,y:0},data:C(I),className:G,ariaLabel:zD(I,t),...F?{width:F.width,height:F.height}:null}),I.parentId&&j.has(I.parentId)){const z=th(I.sessionId),Q=q,U=_.size>0&&(_.has(I.id)||_.has(I.parentId)),re=N!=null&&!N.has(I.id)&&!N.has(I.parentId),de=I.state==="active"?2:1.5,ge=U?de+1.5:de,pe=Q?.2:re?.12:1,ke=["sess-edge",I.state==="active"?"sess-live":"sess-idle",Q?"rf-edge-exiting":"",U?"rf-edge-selected":""].filter(Boolean).join(" ");E.push({id:`e:${I.parentId}->${I.id}`,source:I.parentId,target:I.id,animated:(I.state==="active"||U)&&!Q,type:"smoothstep",style:{"--session-hue":z,strokeWidth:`calc(${ge}px * var(--edge-k, 1))`,opacity:pe,transition:"var(--edge-transition)"},className:ke})}const D=I.kind==="root"?jh(I):null,ae=D?oR(I.sessionId,D.at):null;if(D&&ae&&!V6(ae)){const z=E0(I.id),Q=th(I.sessionId),U=l.get(z);S.push({id:z,type:"recapNote",position:{x:0,y:0},data:{sessionId:I.sessionId,parentId:I.id,recap:D,noteKey:ae,hue:Q},className:W?"rf-spotlit-out":void 0,selectable:!1,focusable:!1,ariaLabel:`Claude Code's recap for ${I.label}`,...U?{width:U.width,height:U.height}:null}),E.push({id:`e:recap:${I.id}`,source:z,target:I.id,type:"recapTie",className:"recap-edge",focusable:!1,style:{"--session-hue":Q}})}}const T=e0(e),R=`${y}#lanes:${fV(T)}`,$=new Set(S.filter(I=>I.type==="recapNote").map(I=>I.id));for(const I of Array.from(h.keys()))X6(I)&&!$.has(I)&&!a.has(I)&&(h.delete(I),m.delete(I));const H=S.filter(I=>kW(I.id,a,h,m));if(H.length>0||R!==w.current){if(H.length>0){const I=xV(yV(S,E,{direction:"LR",pinned:a,measured:l,availableWidth:n,availableHeight:r,lanes:T}),a,q=>Wd(q,h,m)?void 0:h.get(q));for(const q of I)Wd(q.id,h,m)&&M_(q.id,q.position,h,m);vV(S,h,a,l,new Set(H.filter(q=>q.type!=="recapNote").map(q=>q.id)),T,{width:n,height:r});for(const q of H){if(q.type!=="recapNote")continue;const W=(J=q.data)==null?void 0:J.parentId;if(!W)continue;const G=a.get(W)??(Wd(W,h,m)?void 0:h.get(W));if(!G)continue;const F=((M=l.get(q.id))==null?void 0:M.width)??wG,D=((Z=l.get(q.id))==null?void 0:Z.height)??l2,ae=((V=l.get(W))==null?void 0:V.height)??l2;M_(q.id,{x:G.x-vG-F,y:G.y+(ae-D)/2},h,m)}}wV(S,h,a,l,T),w.current=R}const B=bV(S,h,a,l,c,!f||p,T);B.length>0&&u(B);const P=vW(e.agents.values());Td(h,P),Td(m,P),Td(a,P),Td(l,wW(e.agents.values()));const K=[];let X=!1;for(const I of S){let q=a.get(I.id)??h.get(I.id);q||(q=NW(I.id,h,m),X=!0),K.push({...I,position:q})}return X&&(w.current=""),{nodes:K,edges:E}}function zG(){return i.jsx(v0,{children:i.jsx(UG,{})})}const HG=e=>e.transform[2]>=e.maxZoom,WG=e=>e.transform[2]<=e.minZoom;function UG(){var fi,pi,mi,gi;const e=kh(),t=wt(HG),n=wt(WG),r=Gt(),a=x.useState(Mx)[0],l=x.useRef(a),[,c]=x.useState(0),u=x.useCallback(()=>c(L=>L+1),[]),[f,p]=x.useState(jG);x.useEffect(()=>{EG(f)},[f]);const[h,m]=x.useState(()=>new Set),[y,w]=x.useState(null),[_,N]=x.useState(null),j=x.useCallback((L,O,ne=!O)=>{m(oe=>{if(!O)return new Set([L]);const be=new Set(oe);return be.has(L)?be.delete(L):be.add(L),be}),w(oe=>O&&oe===L?oe:L),!O&&ne&&p(!0)},[]),b=x.useCallback(()=>{m(new Set),w(null)},[]),[S,E]=x.useState(null),[C,T]=x.useState(null),R=x.useCallback(L=>T(L),[]),[$,H]=x.useState(!1),[B,P]=x.useState(!1),[K,X]=x.useState(!1),J=x.useRef(null),[M,Z]=x.useState(_G);x.useEffect(()=>{SG(M)},[M]);const[V,I]=x.useState(CG);x.useEffect(()=>{TG(V)},[V]);const[q,W]=x.useState(AG);x.useEffect(()=>{RG(q)},[q]);const G=x.useRef(!1),[F,D]=x.useState(()=>{const L=(()=>{try{const O=window.localStorage.getItem(d2);return O===null?!0:O==="1"}catch{return!0}})();return L&&M?(G.current=!0,!1):L});x.useEffect(()=>{if(!(!F&&G.current))try{window.localStorage.setItem(d2,F?"1":"0")}catch{}},[F]),x.useEffect(()=>{!M&&G.current&&(G.current=!1,D(!0))},[M]);const ae=Mp(F,200),z=Mp(V,130),Q=Mp(q,130),[U,re]=x.useState(null);x.useEffect(()=>{let L=null;try{L=localStorage.getItem("agent-dag.sound")}catch{}re(L===null?!0:L==="on")},[]);const de=x.useCallback(()=>{re(L=>{var ne;const O=L!==!0;try{localStorage.setItem("agent-dag.sound",O?"on":"off")}catch{}return O&&((ne=Me.current)==null||ne.unlock()),O})},[]),ge=x.useCallback(L=>{de()},[de]),pe=x.useRef(ge);pe.current=ge;const ke=x.useRef(U);ke.current=U;const[Pe,$e]=x.useState(()=>Cz(Da)),Ae=x.useRef(Pe);Ae.current=Pe;const je=x.useRef(null),Qe=x.useCallback((L,O=!1)=>{var ne,oe;if((ne=Me.current)==null||ne.unlock(),je.current!==null&&clearTimeout(je.current),je.current=null,!O){(oe=Me.current)==null||oe.play(L,!0);return}je.current=setTimeout(()=>{var be;je.current=null,(be=Me.current)==null||be.play(L,!0)},Nz)},[]),Te=x.useCallback((L,O)=>{$e(ne=>{const oe={level:Fc(O.level??ne[L].level),figure:UR(L,O.figure??ne[L].figure)};try{localStorage.setItem(VR[L],String(oe.level)),localStorage.setItem(GR[L],oe.figure)}catch{}return{...ne,[L]:oe}}),Qe(L,!0)},[Qe]);x.useEffect(()=>()=>{je.current!==null&&clearTimeout(je.current)},[]);const[Se,We]=x.useState(!1),dt=x.useRef(null),[ct,le]=x.useState(!1),Ne=x.useRef(null);x.useEffect(()=>{Se&&le(!1)},[Se]);const Me=x.useRef(null),[tt,Ge]=x.useState("locked");x.useEffect(()=>{const L=Az({enabled:()=>ke.current===!0,prefs:()=>Ae.current,onState:Ge});Me.current=L,Ge(L.state());const O=()=>L.unlock();return window.addEventListener("pointerdown",O,{once:!0,capture:!0}),window.addEventListener("keydown",O,{once:!0,capture:!0}),()=>{window.removeEventListener("pointerdown",O,{capture:!0}),window.removeEventListener("keydown",O,{capture:!0})}},[]);const[Je,ye]=x.useState(!1),[Ce,Ve]=x.useState(!1),[ce,at]=x.useState(null),[ut,rt]=x.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(px)??""}catch{return""}}),[st,jt]=x.useState(!1),vt=x.useRef(0),[mt,_n]=x.useState(!1),Et=x.useCallback((L=!1)=>(L&&(vt.current=Date.now(),_n(!0)),fetch(L?"/api/version?refresh=1":"/api/version").then(O=>O.ok?O.json():null).then(O=>{O&&at(O)}).catch(()=>{}).finally(()=>{L&&_n(!1)})),[]),zt=x.useCallback(()=>{Et(Date.now()-vt.current>=NG)},[Et]);x.useEffect(()=>{Et();const L=window.setInterval(zt,5*6e4),O=()=>{document.visibilityState==="visible"&&zt()};return document.addEventListener("visibilitychange",O),()=>{window.clearInterval(L),document.removeEventListener("visibilitychange",O)}},[Et,zt]),x.useEffect(()=>{Je&&Et()},[Je,Et]),x.useEffect(()=>{const L=GH();let O=null;const ne=De=>{fetch("/api/presence",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tab:L,looking:De}),keepalive:!0}).catch(()=>{})},oe=()=>{const De=UH(document);VH(O,De)&&ne(De),O=De},be=()=>{O&&ne(!1),O=!1};oe();const we=window.setInterval(oe,WH);return window.addEventListener("focus",oe),window.addEventListener("blur",oe),document.addEventListener("visibilitychange",oe),window.addEventListener("pagehide",be),()=>{window.clearInterval(we),window.removeEventListener("focus",oe),window.removeEventListener("blur",oe),document.removeEventListener("visibilitychange",oe),window.removeEventListener("pagehide",be),be()}},[]);const fe=(ce==null?void 0:ce.notice)??null,[nt,Tt]=x.useState(null),Sn=x.useRef(!1);x.useEffect(()=>{if(Sn.current)return;const L=R_(),O=nW(L),ne=lW({stored:O,running:(ce==null?void 0:ce.running)??null,notes:A_,remembers:rW(L)});if(ne.reason==="no-version")return;Sn.current=!0,ne.record&&sW(L,ne.record);const oe=iW({tourSeen:aW(L),decision:ne}),be=ne.show.length?{entries:ne.show,since:O,firstRun:!1}:null;oe.tour&&X(!0),oe.notes==="now"?Tt(be):oe.notes==="after"&&(J.current=be)},[ce==null?void 0:ce.running]);const dn=(ce==null?void 0:ce.running)??"3.26.4",ir=x.useMemo(()=>nM(A_,null,dn),[dn]),It=x.useCallback(()=>{Tt({entries:ir,since:null,firstRun:!1})},[ir]),[hn,jn]=x.useState(null),[Ht,$n]=x.useState(Jx);x.useEffect(()=>{let L=!1;return fetch("/api/health").then(O=>O.ok?O.json():null).then(O=>{L||($n(nG(O)),!(!O||typeof O.workspace!="string")&&jn(O.workspace))}).catch(()=>{}),()=>{L=!0}},[Je]);const Yn=x.useRef(Ht);Yn.current=Ht;const On=fe?`${fe.kind}:${fe.to}`:"",En=fe!=null&&ut!==On,_r=x.useCallback(()=>{rt("");try{window.localStorage.setItem(px,"")}catch{}},[]),Kr=x.useCallback(()=>{if(fe){rt(On);try{window.localStorage.setItem(px,On)}catch{}}},[fe,On]),[Hs,Ws]=x.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(h2)??""}catch{return""}}),yn=ce!=null&&ce.invokedAs&&ce.invokedAs!==nn?ce.invokedAs:null,ee=yn!=null&&Hs!==yn,Re=x.useCallback(()=>{if(yn){Ws(yn);try{window.localStorage.setItem(h2,yn)}catch{}}},[yn]),Le=((fi=ce==null?void 0:ce.upgrade)==null?void 0:fi.state)??"idle",Ie=nz(ce==null?void 0:ce.upgrade),ze=x.useRef(!1),ht=x.useCallback(async()=>{if(Ls(ze.current||Le==="running")){ze.current=!0;try{await fetch("/api/upgrade",{method:"POST"})}catch{}await Et(),ze.current=!1}},[Le,Et]);x.useEffect(()=>{if(Le!=="running")return;const L=window.setInterval(Et,3e3);return()=>window.clearInterval(L)},[Le,Et]);const Lt=x.useCallback(async()=>{const L=ce==null?void 0:ce.command;!L||!await Eh(L)||(jt(!0),window.setTimeout(()=>jt(!1),1600))},[ce==null?void 0:ce.command]),$t=x.useCallback(()=>{Z(L=>(L||D(O=>(O&&(G.current=!0),!1)),!L))},[]),Sr=x.useCallback(()=>{G.current=!1,D(L=>(L||Z(!1),!L))},[]),[kt,xt]=x.useState(!1),[Us,ms]=x.useState(!1),[qa,Vs]=x.useState(()=>{try{return Number(localStorage.getItem(I_))||0}catch{return 0}}),[Ba,Uo]=x.useState([]),[Yr,Cn]=x.useState(!1);x.useEffect(()=>{let L=!0;const O=()=>{fetch("/api/browser-watch?live=0").then(oe=>oe.ok?oe.json():null).then(oe=>{var be;!L||!(oe!=null&&oe.ok)||(Uo(oe.episodes??[]),Cn(((be=oe.settings)==null?void 0:be.enabled)===!0))}).catch(()=>{})};O();const ne=setInterval(O,5*6e4);return()=>{L=!1,clearInterval(ne)}},[]);const[za,wn]=x.useState([]),tu=x.useRef(new Set),[Vo,nu]=x.useState(null);x.useEffect(()=>{let L=!0,O=0;const ne=()=>{fetch("/api/lan").then(oe=>oe.ok?oe.json():null).then(oe=>L?(oe!=null&&oe.ok&&wn(s_(Array.isArray(oe.pending)?oe.pending:[],oe.aliases)),oe):null).catch(()=>null).then(oe=>{L&&(O=window.setTimeout(ne,(oe==null?void 0:oe.enabled)===!0?Hx:qR))})};return ne(),()=>{L=!1,window.clearTimeout(O)}},[]);const Ha=x.useCallback(async(L,O)=>{if(!Vo){nu(L);try{const oe=await(await fetch("/api/lan/peer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:L,fp:O})})).json().catch(()=>null);oe&&Array.isArray(oe.pending)?wn(s_(oe.pending,oe.aliases)):wn(be=>be.filter(we=>we.fp!==O))}catch{}finally{nu(null)}}},[Vo]),Xr=x.useMemo(()=>UW(Ba,qa).length,[Ba,qa]),[Wa,Ua]=x.useState(0),ru=x.useRef(null),[Zh,Go]=x.useState(!1),Gs=x.useRef(null),[ml,Ks]=x.useState(0),Xn=x.useState(()=>CW({protect:L=>z5(l.current,L)}))[0],[Ys,gt]=x.useState(!1),Ko=x.useCallback(()=>{const L=Xn.paused&&Xn.dropped>0,O=Xn.setPaused(!Xn.paused);L&&H5(l.current);for(const ne of O)l.current=eN(l.current,ne);gt(Xn.paused)},[Xn]),[Wt,gl]=x.useState(Date.now()),[jr,Va]=x.useState(()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem($d)!=="0"}catch{return!0}}),yl=x.useRef(!1),wl=x.useCallback(()=>{const L=!jr;yl.current=!0;try{window.localStorage.removeItem($d)}catch{}Va(L),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:L})}).then(O=>O.ok?O.json():null).then(O=>{var ne;O!=null&&O.ok&&Va(((ne=O.prefs)==null?void 0:ne.autoUpdate)!==!1)}).catch(()=>{})},[jr]),[Zn,Qn]=x.useState(!1),[Zr,Qr]=x.useState("restart"),[Xs,Zs]=x.useState(null),Tn=x.useRef(!1),su=x.useRef(null),vl=x.useRef(0),Er=x.useCallback(async L=>{if(!Ls(Tn.current))return;const O=(L==null?void 0:L.upgrade)===!0;Tn.current=!0,su.current=Ie;const ne=++vl.current;Qr(O?"npx":"restart"),Qn(!0);try{window.sessionStorage.setItem("agent-dag.restartPending",(fe==null?void 0:fe.to)??"")}catch{}try{await fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({upgrade:O})})}catch{}window.setTimeout(()=>{if(vl.current===ne&&Tn.current){Tn.current=!1,Qn(!1);try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}}},O?18e4:3e4)},[fe==null?void 0:fe.to,Ie]),xl=x.useRef(null);x.useEffect(()=>{const L=d_(l.current.agents.values())>0,O=iz({enabled:jr,kind:fe==null?void 0:fe.kind,canRestart:(ce==null?void 0:ce.canRestart)===!0,noticeOpen:En,visible:document.visibilityState==="visible",busy:L,idleSince:xl.current,now:Wt});xl.current=O.idleSince,O.restart&&Er()},[jr,fe==null?void 0:fe.kind,ce==null?void 0:ce.canRestart,En,Wt,Er]);const bl=d_(l.current.agents.values()),Ga=oz(bl),kl=WR({enabled:jr,kind:fe==null?void 0:fe.kind,canRestart:(ce==null?void 0:ce.canRestart)===!0,noticeOpen:En,visible:document.visibilityState==="visible",busy:bl>0,idleSince:xl.current,now:Wt});x.useEffect(()=>{const L=ce==null?void 0:ce.running;let O=null,ne=null;try{O=window.sessionStorage.getItem("agent-dag.restartPending"),ne=window.sessionStorage.getItem(f2)}catch{return}const oe=tz({bundle:"3.26.4",running:L,pending:O,lastTried:ne});if(oe==="reload"){try{window.sessionStorage.setItem(f2,L??"")}catch{return}window.location.reload();return}if(oe!=="confirm")return;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}Tn.current=!1,Qn(!1),Zs(L??null);const be=window.setTimeout(()=>Zs(null),6e3);return()=>window.clearTimeout(be)},[ce==null?void 0:ce.running]),x.useEffect(()=>{if(Zn&&rz({asked:su.current,reported:Ie})){try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}Tn.current=!1,Qn(!1)}},[Zn,Ie]);const au=x.useState(()=>TV(MG()))[0],At=x.useRef(au.pinned),Jr=x.useRef(null),Cr=x.useState(()=>OG())[0],[Qs,Qh]=x.useState(()=>new Set),[Js,Yo]=x.useState(RW),[es,Nl]=x.useState(HH),[gs,ts]=x.useState(()=>t2(i2)),Xo=x.useMemo(()=>EV(gs),[gs]),Zo=x.useCallback(L=>jV(L,Xo),[Xo]),[_l,Qo]=x.useState(!1);x.useEffect(()=>{document.documentElement.dataset.theme=Js;try{window.localStorage.setItem(oM,Js)}catch{}ts(L=>{const O=t2(i2);return CV(L,O)?L:O})},[Js]),x.useEffect(()=>{try{window.localStorage.setItem(tM,es?"1":"0")}catch{}},[es]);const vn=x.useCallback((L,O)=>{if(Md({durationMs:O,documentHidden:document.hidden})){e.setViewport(L,{duration:O});return}const{d3Zoom:ne,d3Selection:oe}=r.getState(),be=oe==null?void 0:oe.property("__zoom");if(ne&&oe&&be&&be.k>0&&L.zoom>0){ne.transform(oe,be.scale(L.zoom/be.k).translate((L.x-be.x)/L.zoom,(L.y-be.y)/L.zoom));return}e.setViewport(L,{duration:0})},[e,r]),ys=x.useRef(null),Yt=x.useRef(0),Tr=x.useRef(null),Jo=x.useRef(()=>{});x.useEffect(()=>{if(!Cr)return;const L=window.setTimeout(()=>{try{vn(Cr,0)}catch{}Jn.current=Date.now()},60);return()=>window.clearTimeout(L)},[vn,Cr]);const ea=x.useRef(!0),[Ka,ei]=x.useState(null);x.useEffect(()=>{const L=new EventSource("/events"),O=jW(u,{now:()=>Date.now(),setTimeout:(we,De)=>window.setTimeout(we,De),clearTimeout:we=>window.clearTimeout(we)});let ne=!1;const oe=typeof BroadcastChannel=="function"?OW(new BroadcastChannel(IW),Math.random().toString(36).slice(2),()=>ne):null,be=window.setInterval(()=>{ne||!oe||oe.ask(600).then(we=>{ne||Ve($W(we))})},3e3);return L.addEventListener("open",()=>{ye(!0),Qo(!0)}),L.addEventListener("error",()=>{ye(!1),ei(null)}),L.addEventListener("open",()=>{ne=!0,Ve(!1)}),L.addEventListener("error",()=>{ne=!1}),L.addEventListener("replay-end",()=>{ea.current=!1,O.flush(),ei(Date.now())}),L.addEventListener("hook",we=>{var De;try{const Ke=JSON.parse(we.data);if(!Xn.accept(Ke))return;l.current=eN(l.current,Ke);const ot=Ke.replay===!0||ea.current||Date.now()-Ke.receivedAt>3e4;ot?O.replay():O.live();const Ye=Tz(Ke,ot);Ye&&((De=Me.current)==null||De.play(Ye))}catch{}}),()=>{L.close(),O.cancel(),window.clearInterval(be),oe==null||oe.leave()}},[u]),x.useEffect(()=>{const L=setInterval(()=>{const O=Date.now();gl(O);let ne=W5(l.current,O,J1);U5(l.current,O,J1)&&(ne=!0);const oe=[],be=we=>{oe.push(we)};q5(l.current,O,DW,FW,be)&&(ne=!0),B5(l.current,O,qW,BW,be)&&(ne=!0),oe.length>0&&fetch("/api/forget",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({ids:oe})}).catch(()=>{}),m(we=>yW(we,l.current.agents)),w(we=>we!=null&&!l.current.agents.has(we)?null:we),T(we=>we!=null&&!l.current.agents.has(we)?null:we),E(we=>we!=null&&!l.current.agents.has(we)?null:we),ne&&u()},250);return()=>clearInterval(L)},[u]);const Ya=x.useRef(null),Jn=x.useRef(0),Xa=420,An=x.useCallback((L=500)=>{const O=dx,ne=1,oe=.2,be=hx;try{const we=document.querySelector(".canvas-wrap"),De=Array.from(document.querySelectorAll(".react-flow__node")).filter(bt=>bt.offsetWidth>0);if(!we||De.length===0)return;const Ke=we.getBoundingClientRect(),ot=e.getViewport();if(!Number.isFinite(ot.zoom)||ot.zoom<=0)return;const Ye=bt=>(bt-Ke.left-ot.x)/ot.zoom,Ct=bt=>(bt-Ke.top-ot.y)/ot.zoom,qt=De.map(bt=>bt.getBoundingClientRect()),Ss=Math.min(...qt.map(bt=>Ye(bt.left))),fo=Math.max(...qt.map(bt=>Ye(bt.right))),lr=Math.min(...qt.map(bt=>Ct(bt.top))),po=Math.max(...qt.map(bt=>Ct(bt.bottom))),js=fo-Ss,ha=po-lr;if(!(js>0&&ha>0))return;const Ul=c2(we),Es=bt=>Math.max(oe,Math.min(ne,(Ke.width-Ul-O*2)/(js+bt)*be,(Ke.height-O*2)/ha*be)),Dn=BV(Es(Xa),Es(0)),yt={x:O-Ss*Dn,y:Math.max(O,(Ke.height-ha*Dn)/2)-lr*Dn,zoom:Dn},Nt=++Yt.current;vn(yt,L),Jn.current=Date.now(),ys.current=Md({durationMs:L,documentHidden:document.hidden})?{target:yt,until:Date.now()+L+60}:null,window.setTimeout(()=>{var bt;try{if(((bt=ys.current)==null?void 0:bt.target)===yt&&(ys.current=null),Yt.current!==Nt)return;const Zt=e.getViewport();(Math.abs(Zt.zoom-Dn)>.01||Math.abs(Zt.x-yt.x)>2)&&vn(yt,0)}catch{}},L+60)}catch{}},[e,vn]);x.useEffect(()=>{const L=()=>{if(!document.hidden)return;const O=ys.current;if(ys.current=null,!(!O||Date.now()>O.until)){try{vn(O.target,0)}catch{}Jn.current=Date.now()}};return document.addEventListener("visibilitychange",L),()=>document.removeEventListener("visibilitychange",L)},[vn]);const Sl=x.useRef(""),jl=x.useRef(null),ou=x.useRef(0),ta=x.useCallback(()=>{ou.current=Date.now()},[]),El=x.useRef(null),iu=x.useRef(0),Cl=x.useCallback(()=>{iu.current=Date.now()},[]),Tl=x.useCallback(L=>({hasSourceEvent:!!L,at:Date.now(),lastDeckFitAt:Jn.current,lastCanvasInputAt:iu.current}),[]),Jh="agent-dag.autoFitDisabled",ns=x.useRef(!1),[Al,lu]=x.useState(!1);x.useEffect(()=>{try{window.localStorage.removeItem(Jh)}catch{}},[]);const Za=x.useCallback(()=>{ns.current||(ns.current=!0,lu(!0))},[]),cu=x.useCallback(()=>{ns.current=!1,lu(!1),An(400)},[e,An]);x.useEffect(()=>{const L=setInterval(()=>{if(ns.current||Date.now()-ou.current<800)return;const O=l.current,ne=Date.now(),oe=[];for(const we of O.agents.values())Xx(we,ne)&&oe.push({id:we.id});if(oe.length===0)return;const be=[];for(const{id:we}of oe){const De=Ar.current.get(we),Ke=At.current.get(we)??Xt.current.get(we);!De||!Ke||be.push({x:Ke.x,y:Ke.y,width:De.width,height:De.height})}OV({pane:El.current,viewport:e.getViewport(),boxes:be})&&An(600)},1500);return()=>clearInterval(L)},[e]);const na=x.useRef(!1),Ar=x.useRef(new Map),Rl=x.useRef(0),ef=x.useCallback(L=>{const O=Ar.current;let ne=!1;for(const oe of L.nodeInternals.values()){const be=oe.width,we=oe.height;if(be==null||we==null)continue;const De=O.get(oe.id);De?(Math.abs(De.height-we)>4||Math.abs(De.width-be)>4)&&(O.set(oe.id,{width:be,height:we}),ne=!0):(O.set(oe.id,{width:be,height:we}),ne=!0)}return ne&&(Rl.current+=1),Rl.current},[]),Ml=wt(ef),[uu,tf]=x.useState(0);x.useEffect(()=>{let L=0;const O=()=>{const oe=Ar.current;let be=!1;for(const we of document.querySelectorAll(".react-flow__node[data-id]")){const De=we.getAttribute("data-id");if(!De)continue;const Ke=we.offsetWidth,ot=we.offsetHeight;if(!Ke||!ot)continue;const Ye=oe.get(De);(!Ye||Math.abs(Ye.width-Ke)>4||Math.abs(Ye.height-ot)>4)&&(oe.set(De,{width:Ke,height:ot}),be=!0)}be&&tf(we=>we+1)};if(na.current)return;let ne=0;return document.visibilityState==="hidden"?ne=window.setTimeout(O,32):L=requestAnimationFrame(O),()=>{cancelAnimationFrame(L),window.clearTimeout(ne)}});const Xt=x.useRef(au.positions),du=x.useRef(new Set),ti=x.useRef(""),ra=x.useMemo(()=>{const L=[];for(const O of l.current.agents.values())Xx(O,Wt)&&L.push(O.id+(O.parentId?`>${O.parentId}`:""));return L.sort(),`${L.join("|")}#sv${Ml}.${uu}`},[l.current,l.current.revision,Wt,Ml,uu]),Qa=x.useRef(null);x.useEffect(()=>(Qa.current!=null&&window.clearTimeout(Qa.current),Qa.current=window.setTimeout(()=>{Od(Xt.current,At.current)},1500),()=>{Qa.current!=null&&window.clearTimeout(Qa.current)}),[ra]),x.useEffect(()=>{if(Sl.current===ra)return;const L=Sl.current;if(Sl.current=ra,!L||ns.current)return;Date.now()-Jn.current>1200&&An(400),Ya.current&&window.clearTimeout(Ya.current),Ya.current=window.setTimeout(()=>{ns.current||An(500)},280)},[ra,e,An]);const Ja=x.useMemo(()=>bW(l.current,h),[l.current,l.current.revision,h]),ws=x.useMemo(()=>NV(l.current,Wt),[l.current,l.current.revision,Wt]),vs=x.useRef(null),[sa,Il]=x.useState({w:0,h:0});x.useEffect(()=>{const L=vs.current;if(!L||typeof ResizeObserver>"u")return;const O=new ResizeObserver(ne=>{var be;const oe=(be=ne[0])==null?void 0:be.contentRect;oe&&(El.current={width:oe.width,height:oe.height},Il(we=>Math.abs(we.w-oe.width)>40||Math.abs(we.h-oe.height)>40?{w:oe.width,h:oe.height}:we))});return O.observe(L),El.current={width:L.clientWidth,height:L.clientHeight},Il({w:L.clientWidth,h:L.clientHeight}),()=>O.disconnect()},[]);const hu=x.useCallback(L=>{var ne,oe;const O=L.target;!(O!=null&&O.closest)||O.closest(bG)!==L.currentTarget||(L.preventDefault(),(oe=(ne=document.activeElement)==null?void 0:ne.blur)==null||oe.call(ne))},[]),fu=x.useRef(new Map),[eo,aa]=x.useState(!1);x.useEffect(()=>{const L=window.setTimeout(()=>aa(!0),2500);return()=>window.clearTimeout(L)},[]);const[nf,$l]=x.useState(!1),rs=x.useRef(null),[oa,Ol]=x.useState(!1),[to,no]=x.useState("detail"),xs=x.useRef(null),ia=x.useRef(null),rf=x.useCallback(()=>{var oe;const L=Rl.current;if(((oe=ia.current)==null?void 0:oe.version)===L)return ia.current.card;const O=[];for(const be of l.current.agents.keys()){const we=Ar.current.get(be);we&&O.push(we)}const ne=LV(O);return ia.current={version:L,card:ne},ne},[]),pu=x.useCallback(()=>{rs.current&&(window.clearTimeout(rs.current),rs.current=null),$l(!1)},[]),Pl=x.useCallback(L=>{L.length!==0&&queueMicrotask(()=>{$l(!0),rs.current&&window.clearTimeout(rs.current),rs.current=window.setTimeout(()=>$l(!1),kG+80)})},[]);x.useEffect(()=>()=>{rs.current&&window.clearTimeout(rs.current)},[]);const sn=y?l.current.agents.get(y):null,Ll=f&&sn!=null,[ni,mu]=x.useState(0);x.useEffect(()=>{const L=c2(vs.current);mu(O=>Math.abs(O-L)>40?L:O)},[Q,z,V,Ll,sa.w]);const Dl=x.useRef(ni);Dl.current=ni;const ri=sa.w>0?Math.max(0,(sa.w-ni-dx*2)*hx):0,si=sa.h>0?Math.max(0,(sa.h-dx*2)*hx):0,sf=Z6(),{nodes:ss,edges:Pn}=x.useMemo(()=>BG(l.current,Wt,ri,si,At.current,Ar.current,fu.current,Pl,eo,oa,Xt.current,du.current,ra,ti,h,Ja,ws,R),[l.current,l.current.revision,Wt,ri,si,eo,oa,ra,h,Ja,ws,R,Wa,sf]),ro=x.useState(IG)[0],Fl=x.useRef(ro);x.useEffect(()=>{if(!eo||oa)return;const L={width:ri,height:si};if(!(L.width>0&&L.height>0))return;const O=Fl.current;if(Fl.current=L,$G(L),!O||O.width===L.width&&O.height===L.height)return;const ne={direction:"LR",pinned:At.current,measured:Ar.current,lanes:e0(l.current)};if(!gV(ss,Pn,ne,O,L))return;const oe=Tr.current&&Date.now()-Tr.current.at<1500?Tr.current.id:null,be=oe??Ns.current,we=be?At.current.get(be)??Xt.current.get(be):void 0;for(const De of Array.from(Xt.current.keys()))At.current.has(De)||Xt.current.delete(De);du.current.clear(),ti.current="",u(),window.setTimeout(()=>{if(Od(Xt.current,At.current),ns.current){if(oe){Jo.current(oe);return}const De=be?At.current.get(be)??Xt.current.get(be):void 0;if(we&&De&&(De.x!==we.x||De.y!==we.y)){const Ke=e.getViewport();Yt.current+=1,vn({x:Ke.x-(De.x-we.x)*Ke.zoom,y:Ke.y-(De.y-we.y)*Ke.zoom,zoom:Ke.zoom},0),Jn.current=Date.now()}return}An(500)},80)},[ri,si,eo,oa,u,An,e,vn]);const ql=x.useMemo(()=>{const L=new Map;for(const ne of ss){const oe=ne.data;if(!(oe!=null&&oe.sessionId)||oe.exitAt!=null)continue;const be=ne.width,we=ne.height;if(be==null||we==null)continue;const De=ne.position.x,Ke=ne.position.y,ot=De+be,Ye=Ke+we,Ct=L.get(oe.sessionId);Ct?(Ct.minX=Math.min(Ct.minX,De),Ct.minY=Math.min(Ct.minY,Ke),Ct.maxX=Math.max(Ct.maxX,ot),Ct.maxY=Math.max(Ct.maxY,Ye)):L.set(oe.sessionId,{minX:De,minY:Ke,maxX:ot,maxY:Ye})}const O=[];for(const[ne,oe]of L){const be=oe.maxX-oe.minX+Id*2,we=oe.maxY-oe.minY+Id*2;O.push({id:`group:${ne}`,type:uI,position:{x:oe.minX-Id,y:oe.minY-Id},data:{sessionId:ne,w:be,h:we},width:be,height:we,style:{width:be,height:we},zIndex:-1,draggable:!0,selectable:!1,focusable:!1,deletable:!1,connectable:!1})}return O},[ss]),gu=x.useMemo(()=>{const L=[...ql,...ss],O=Gs.current;return!O||O.size===0?L:L.map(ne=>{const oe=O.get(ne.id);return oe?{...ne,position:oe}:ne})},[ql,ss,ml]),so=x.useMemo(()=>{const L=new Set;for(const O of l.current.agents.values())for(const ne of O.tools)L.add(jI(ne.name));return Object.keys(SI).filter(O=>L.has(O))},[l.current,l.current.revision]);x.useEffect(()=>{if(so.length<=1){Go(!1);return}let L=0;const O=()=>{const ne=ru.current;if(ne&&!document.hidden){const oe=ne.getBoundingClientRect(),be=Array.from(document.querySelectorAll(".react-flow__node, .tool-burst")).map(De=>De.getBoundingClientRect()),we=SV(oe,be,8);Go(De=>De===we?De:we)}L=window.setTimeout(O,300)};return O(),()=>window.clearTimeout(L)},[so.length]);const Bl=x.useCallback(L=>{Qh(O=>{const ne=new Set(O);return ne.has(L)?ne.delete(L):ne.add(L),ne})},[]),zl=_?$5(l.current.agents,_):null,yu=x.useCallback(async()=>{try{await fetch("/api/clear",{method:"POST"})}catch{}l.current=Mx(),At.current.clear(),Ar.current.clear(),Xt.current.clear(),ti.current="",p2(),b(),u()},[u,b]),bs=x.useRef($);bs.current=$;const ai=x.useRef(B);ai.current=B;const ks=x.useRef(!1);ks.current=zl!=null||kt||C!=null||K||S!=null||Us||B||nt!=null;const la=x.useCallback(L=>{const O=lz(L,{confirmOpen:bs.current,modalOpen:ks.current});O==="confirm"?H(!0):O==="clear"&&(H(!1),yu())},[yu]),oi=x.useCallback(()=>{At.current.clear(),Xt.current.clear(),ti.current="",p2(),u(),window.setTimeout(()=>An(500),80)},[u,e,An]),ao=x.useCallback(()=>An(500),[An]),Ln=x.useRef(ss);Ln.current=ss;const xn=x.useCallback(L=>{var Ct;const O=vs.current,ne=l.current.agents.get(L);if(!O||!ne)return;const oe=e0(l.current),be=(qt,Ss)=>{const fo=Ar.current.get(qt.id);if(!fo)return null;const lr=Ss&&oe.has(qt.id)?Xa:0;return{x:qt.position.x,y:qt.position.y,width:fo.width+lr,height:fo.height}},we=Ln.current.find(qt=>qt.id===L),De=we?be(we,!1):null;if(!De)return;const Ke=[];for(const qt of Ln.current){if(qt.type!=="agent"&&qt.type!=="recapNote"||((Ct=qt.data)==null?void 0:Ct.sessionId)!==ne.sessionId)continue;const Ss=be(qt,qt.type==="agent");Ss&&Ke.push(Ss)}const ot=O.getBoundingClientRect(),Ye=WV({pane:{width:ot.width,height:ot.height},insets:{top:56,left:72,bottom:32,right:Dl.current+32},context:UV(Ke)??De,anchor:De});ja(),Za(),Tr.current={id:L,at:Date.now()},Yt.current+=1,vn(Ye,fx),Jn.current=Date.now(),ys.current=Md({durationMs:fx,documentHidden:document.hidden})?{target:Ye,until:Date.now()+fx+60}:null},[vn,Za]);Jo.current=xn;const wu=x.useCallback(L=>{const O=Ln.current.find(ne=>ne.id===L&&ne.type==="agent");return O?O.data:void 0},[]),ii=x.useCallback(L=>{var O;return(O=l.current.agents.get(L))==null?void 0:O.label},[]),vu=x.useCallback(L=>{var oe;const O=Ln.current.find(be=>be.id===L&&be.type==="recapNote");if(!O)return;const ne=O.data;return{recap:ne.recap,hue:ne.hue,sessionLabel:(oe=l.current.agents.get(ne.parentId))==null?void 0:oe.label}},[]),xu=x.useCallback(()=>{var ne;const L=(ne=vs.current)==null?void 0:ne.getBoundingClientRect(),O=document.documentElement;return L?{width:L.right-Dl.current,height:L.bottom}:{width:O.clientWidth,height:O.clientHeight}},[]),Ns=x.useRef(y);Ns.current=y;const oo=x.useCallback(L=>{const O=Ln.current.filter(we=>we.type==="agent"),ne=hW(O.map(we=>({id:we.id,x:we.position.x,y:we.position.y})),Ns.current,L),oe=ne?O.find(we=>we.id===ne):void 0;if(!oe)return;const be=ux(document.activeElement);j(oe.id,!1),window.setTimeout(()=>{try{xn(oe.id)}catch{}be&&xG(oe.id)},30)},[j,xn]),li=x.useRef(null),_s=x.useCallback(L=>{j(L,!1),window.setTimeout(()=>{try{xn(L)}catch{}},60)},[j,xn]),Rr=x.useRef(null);x.useEffect(()=>{let L=-1/0;const O=()=>{L=performance.now()},ne=oe=>{Rr.current=performance.now()-L<250?oe.target:null};return window.addEventListener("pointerdown",O,!0),window.addEventListener("focusin",ne,!0),()=>{window.removeEventListener("pointerdown",O,!0),window.removeEventListener("focusin",ne,!0)}},[]),x.useEffect(()=>{const L=O=>{var Ke,ot;const ne=O.target,oe={tagName:ne==null?void 0:ne.tagName,isContentEditable:ne==null?void 0:ne.isContentEditable,role:(Ke=ne==null?void 0:ne.getAttribute)==null?void 0:Ke.call(ne,"role"),type:ne==null?void 0:ne.type,pointerFocused:ne!=null&&ne===Rr.current};if(O.key==="Escape"){const Ye=k6({overlayOpen:nh.depth()>0,typing:j0(oe)});Ye==="dismiss"?nh.dismissTop():Ye==="blur"?ne==null||ne.blur():(gW(oe)&&(ne==null||ne.blur()),b());return}if(Sh(O))return;const be=ux(ne)?(ot=ne==null?void 0:ne.getAttribute)==null?void 0:ot.call(ne,"data-id"):null,we=be&&Ln.current.some(Ye=>Ye.id===be)?be:null,De=pW(O,we);if(De.kind==="activate"){O.preventDefault(),j(De.nodeId,De.additive);return}if(De.kind!=="node"&&!(De.nodeId==null&&R6(oe,O.key))&&!M6({key:O.key,modalOpen:ks.current,sheetOpen:ai.current})){if(O.key===" "&&(O.preventDefault(),Ko()),(O.key==="c"||O.key==="C")&&la("shortcut"),(O.key==="r"||O.key==="R")&&oi(),(O.key==="f"||O.key==="F")&&ao(),(O.key==="z"||O.key==="Z")&&Ns.current&&xn(Ns.current),(O.key==="l"||O.key==="L")&&$t(),O.key==="d"||O.key==="D")if(Ns.current)p(Ye=>!Ye);else{const Ye=Tp(l.current.agents.values());Ye.length>0?_s(Ye[0].id):oo(1)}if((O.key==="h"||O.key==="H")&&xt(Ye=>!Ye),(O.key==="u"||O.key==="U")&&I(Ye=>!Ye),(O.key==="a"||O.key==="A")&&Yn.current.claude&&Sr(),(O.key==="j"||O.key==="J")&&oo(1),(O.key==="k"||O.key==="K")&&oo(-1),O.key==="w"||O.key==="W"){const Ye=h6(Tp(l.current.agents.values()),li.current);Ye&&(li.current=Ye.id,_s(Ye.id))}(O.key==="t"||O.key==="T")&&Yo(Ye=>Ye==="dark"?"light":"dark"),(O.key==="m"||O.key==="M")&&Yn.current.claude&&ke.current!==null&&pe.current(O.shiftKey),(O.key==="s"||O.key==="S")&&W(Ye=>!Ye),(O.key==="b"||O.key==="B")&&ms(Ye=>!Ye),(O.key==="v"||O.key==="V")&&Yn.current.claude&&ke.current!==null&&We(Ye=>!Ye),O.key==="?"&&P(Ye=>!Ye)}};return window.addEventListener("keydown",L),()=>window.removeEventListener("keydown",L)},[la,oi,ao,b,j,oo,_s,xn,Ko]);const ci=l.current.agents.size,Ut=x.useMemo(()=>Tp(l.current.agents.values()),[l.current,l.current.revision]),bu=x.useMemo(()=>f6(l.current.agents.values()),[l.current,l.current.revision]),ku=x.useRef(null);x.useEffect(()=>{const L=PW({waiting:Ut.length,running:bu,connected:Je}),O=ku.current;if(ku.current=L,(O==null?void 0:O.title)!==L.title&&(document.title=L.title),(O==null?void 0:O.icon)!==L.icon){const ne=document.querySelector('link[rel="icon"]');ne&&(ne.href=LW[L.icon])}},[Ut.length,bu,Je]);const[io,af]=x.useState(""),Hl=HW(Ut);x.useEffect(()=>{af(L=>WW(L,Hl))},[Hl]);const[lo,St]=x.useState(()=>typeof Notification>"u"?"denied":Notification.permission),[Mr,ca]=x.useState(null),[as,ui]=x.useState(!1),[Wl,ua]=x.useState(!1);x.useEffect(()=>{let L=!0;return fetch("/api/prefs").then(O=>O.ok?O.json():null).then(O=>{var ne,oe,be;if(!(!L||!(O!=null&&O.ok))){if(!yl.current){let we=!1;try{we=window.localStorage.getItem($d)==="0",window.localStorage.removeItem($d)}catch{}we&&((ne=O.prefs)==null?void 0:ne.autoUpdate)!==!1?(Va(!1),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:!1})}).catch(()=>{})):Va(((oe=O.prefs)==null?void 0:oe.autoUpdate)!==!1)}ui(((be=O.prefs)==null?void 0:be.notifications)===!0),ua(O.notificationsVetoed===!0)}}).catch(()=>{}),()=>{L=!1}},[]);const co=x.useRef(()=>{}),da=x.useCallback(()=>{const L=!as;ui(L),L&&typeof Notification<"u"&&Notification.permission==="default"&&co.current(),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({notifications:L})}).then(O=>O.ok?O.json():null).then(O=>{var ne;O!=null&&O.ok&&(ui(((ne=O.prefs)==null?void 0:ne.notifications)===!0),ua(O.notificationsVetoed===!0))}).catch(()=>{})},[as]),Nu=typeof Notification<"u";x.useEffect(()=>{if(!Mr)return;const O=setTimeout(()=>ca(null),Mr==="blocked"?8e3:4e3);return()=>clearTimeout(O)},[Mr]);const _u=x.useCallback(()=>{typeof Notification>"u"||Notification.requestPermission().then(L=>{const O=L;St(O),O==="granted"?ca("on"):O==="denied"&&ca("blocked")})},[]);co.current=_u;const uo=x.useRef(new Set),di=x.useRef(null),hi=Ut.map(L=>_h(L.id,L.waiting)).join("|");x.useEffect(()=>{y6(di.current,lo)&&(di.current=lo,uo.current=Ap(Ut))},[lo]);const ho=x.useRef(!1);return x.useEffect(()=>{w6(ho.current,Ka)&&(ho.current=!0,uo.current=Ap(Ut))},[Ka]),x.useEffect(()=>{if(typeof Notification>"u"||Notification.permission!=="granted"||!v6(di.current,Ka))return;const L=typeof document>"u"||!document.hidden,O=m6(Ut,uo.current,L,as);for(const ne of O)try{const oe=new Notification(ne.title,{body:ne.body,tag:ne.key});oe.onclick=()=>{window.focus(),_s(ne.sessionId),oe.close()}}catch{}uo.current=L?Ap(Ut):g6(Ut,O,uo.current)},[hi,Ka]),i.jsxs("div",{className:"app",children:[i.jsx("a",{className:"skip-link",href:"#canvas",children:"Skip to the canvas"}),i.jsxs("header",{className:"topbar",children:[i.jsxs("div",{className:"readout",children:[i.jsxs("div",{className:"brand",children:[i.jsx("span",{className:"logo"}),i.jsx("h1",{children:nn}),fe?i.jsxs("button",{type:"button",className:"v stale",onClick:()=>{It(),_r()},"aria-haspopup":"dialog","aria-label":eG({...fe,open:En}),title:fe.kind==="restart"?`Running v${fe.from}; v${fe.to} is installed on disk. Restart to pick it up · click for what's new`:`Running v${fe.from}; v${fe.to} is on npm · click for what's new`,children:["v",fe.from,i.jsx("span",{className:"v-dot","aria-hidden":!0})]}):(()=>{const L={running:dn,latest:ce==null?void 0:ce.latest,latestPending:ce==null?void 0:ce.latestPending,checkedAgo:ce!=null&&ce.checkedAt?Bd(Wt-ce.checkedAt):null,checkFailedAgo:ce!=null&&ce.checkFailedAt&&ce.checkFailedAt>(ce.checkedAt??0)?Bd(Wt-ce.checkFailedAt):null,checkDisabled:ce==null?void 0:ce.checkDisabled,checking:mt};return i.jsxs("button",{type:"button",className:mt?"v checking":"v",onClick:()=>{It(),Et(!0)},"aria-busy":mt||void 0,"aria-haspopup":"dialog","aria-label":JV(L),title:QV(L),children:["v",L.running]})})()]}),i.jsx("span",{className:"status",children:(()=>{const L=fG({connected:Je,paused:Ys,held:Xn.size,dropped:Xn.dropped});return L.resting?null:i.jsx("span",{className:`pill ${L.tone}`,title:L.title,children:i.jsxs("span",{className:"pill-box",children:[i.jsx("span",{className:"pill-widest","aria-hidden":!0,children:L.widest}),i.jsx("span",{className:"pill-label",children:L.label})]})})})()}),i.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:io}),Ut.length>0&&i.jsxs("button",{type:"button",className:"waiting-stat",onClick:()=>{li.current=Ut[0].id,_s(Ut[0].id)},title:`Blocked waiting for you — click, or press W, to go to the one that has been stuck longest:
291
291
  ${Ut.map(L=>` ${L.label}: ${sl(L.waiting)} (${Bd(Wt-L.waiting.since)})`).join(`
292
292
  `)}`,"aria-label":`${Ut.length} session${Ut.length===1?"":"s"} waiting for you`,children:[i.jsx("span",{className:"ap-pulse","aria-hidden":!0}),i.jsx("b",{children:Ut.length})," ",i.jsx("span",{className:"ws-word",children:"waiting"})]}),Mr&&i.jsx("span",{className:Mr==="on"?"notify-said":"notify-said notify-said-blocked",role:"status",title:Mr==="on"?"The deck will raise a system notification when a session blocks on you and this tab is in the background":"Notifications are blocked for this page. Only your browser can undo that — its site settings for this address",children:Mr==="on"?"notifications on":"notifications blocked"})]}),sn&&(()=>{const L=Gn(sn),O=Math.max(0,((sn.endedAt??Wt)-sn.startedAt)/1e3),ne=sn.state==="active"?N0(L.total,O):null,oe=h.size-1;return i.jsxs("button",{type:"button",className:"selected-ribbon",title:`Zoom to ${sn.label} and its session (Z)`,onClick:()=>{try{xn(sn.id)}catch{}},children:[i.jsx("span",{className:`state-pill state-${sn.state}`,children:sn.state==="active"?"live":sn.state}),i.jsx("span",{className:"selected-label",children:sn.label}),L.total>0&&i.jsxs("span",{className:"selected-cost",children:[_t(L.total),ne?i.jsxs("span",{className:"selected-rate",children:[" · ",ne]}):null]}),oe>0&&i.jsxs("span",{className:"selected-extra",children:["+",oe]}),i.jsx("span",{"aria-hidden":!0,className:"selected-close",onClick:be=>{be.stopPropagation(),b()},children:"×"})]})})(),i.jsxs("div",{className:"actions",children:[i.jsxs("div",{className:"action-run",children:[i.jsxs("button",{className:"btn icon-btn",onClick:$t,title:`${M?"Hide":"Show"} session list (L)`,"aria-label":"Toggle session list","aria-expanded":M,"aria-controls":M?"session-list":void 0,children:[i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M5.4 3.6h6.6M5.4 7h6.6M5.4 10.4h6.6"}),i.jsx("path",{d:"M2.2 3.6h.2M2.2 7h.2M2.2 10.4h.2"})]}),i.jsx("span",{className:"tb-word",children:"Session list"})]}),i.jsxs("button",{className:"btn icon-btn",onClick:()=>I(L=>!L),title:`${V?"Hide":"Show"} usage panel (U)`,"aria-label":"Toggle usage panel","aria-expanded":V,"aria-controls":V?"usage-panel":void 0,children:[i.jsxs("svg",{className:"tb-glyph-narrow",width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M9.4 4.5C9 3.6 8.1 3.1 7 3.1c-1.4 0-2.4.8-2.4 1.9 0 1.2 1.2 1.6 2.4 2s2.4.8 2.4 2c0 1.1-1 1.9-2.4 1.9-1.1 0-2-.5-2.4-1.4"}),i.jsx("path",{d:"M7 1.6v1.5M7 10.9v1.5"})]}),i.jsx("span",{className:"tb-word",children:"Usage"})]}),i.jsxs("button",{className:"btn icon-btn",onClick:()=>xt(L=>!L),title:"Usage history — ccusage (H)","aria-label":"Open usage history","aria-haspopup":"dialog",children:[i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("line",{x1:"3",y1:"11.5",x2:"3",y2:"7"}),i.jsx("line",{x1:"7",y1:"11.5",x2:"7",y2:"3"}),i.jsx("line",{x1:"11",y1:"11.5",x2:"11",y2:"8.5"})]}),i.jsx("span",{className:"tb-word",children:"History"})]})]}),i.jsxs("div",{className:"action-run",children:[Ht.claude&&i.jsxs("button",{className:"btn icon-btn",onClick:Sr,title:`${F?"Hide":"Show"} accounts (A)`,"aria-label":"Toggle accounts panel","aria-expanded":F,"aria-controls":F?"accounts-panel":void 0,children:[i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("circle",{cx:"7",cy:"4.6",r:"2.4"}),i.jsx("path",{d:"M2.4 12c0-2.3 2.1-3.7 4.6-3.7s4.6 1.4 4.6 3.7"})]}),i.jsx("span",{className:"tb-word",children:"Accounts"})]}),i.jsxs("button",{className:"btn icon-btn",onClick:()=>W(L=>!L),title:`${q?"Hide":"Show"} this machine — cores, memory, temperature (S)`,"aria-label":"Toggle machine detail","aria-expanded":q,"aria-controls":q?"system-panel":void 0,children:[i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("rect",{x:"3.6",y:"3.6",width:"6.8",height:"6.8",rx:"1.2"}),i.jsx("path",{d:"M5.8 1.4v2.2M8.2 1.4v2.2M5.8 10.4v2.2M8.2 10.4v2.2M1.4 5.8h2.2M1.4 8.2h2.2M10.4 5.8h2.2M10.4 8.2h2.2"})]}),i.jsx("span",{className:"tb-word",children:"Machine"})]}),i.jsxs("button",{className:"btn icon-btn bw-btn",onClick:()=>ms(L=>!L),title:Yr?"Browser watch — watching; the deck is keeping its own copy (B)":"Browser watch — not watching; reading the browser's history live (B)","aria-label":`Browser watch, ${Yr?"watching":"not watching"}`+(Xr>0?`, ${Xr} unread`:""),"aria-haspopup":"dialog",children:[i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M0.9 7s2.2-4 6.1-4 6.1 4 6.1 4-2.2 4-6.1 4S0.9 7 0.9 7Z"}),Yr||Xr>0?i.jsx("circle",{cx:"7",cy:"7",r:"1.8",fill:"currentColor",stroke:"none"}):i.jsx("line",{x1:"2.4",y1:"11.6",x2:"11.6",y2:"2.4"})]}),i.jsx("span",{className:"tb-word",children:"Browser watch"}),Xr>0&&i.jsx("span",{className:"bw-badge","aria-hidden":!0,children:Xr})]})]}),i.jsxs("div",{className:"action-run action-run-utility",children:[Ht.claude&&U!==null&&i.jsxs("div",{className:"sound-slot",children:[i.jsxs("button",{ref:dt,className:"btn icon-btn",onClick:()=>We(L=>!L),...Aa(!1),title:iG(Ht,{on:U===!0,locked:tt==="locked",prefs:Pe}),"aria-label":`Sound settings, ${U?"on":"off"}`,"aria-haspopup":"dialog","aria-expanded":Se,"aria-controls":Se?"sound-menu":void 0,children:[i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("path",{d:"M3.2 5.2h2L7.8 3v8L5.2 8.8h-2z"}),U?i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M9.8 5.4a2.4 2.4 0 0 1 0 3.2"}),i.jsx("path",{d:"M11.3 3.9a4.6 4.6 0 0 1 0 6.2"})]}):i.jsxs(i.Fragment,{children:[i.jsx("path",{d:"M10 5.6l2.6 2.8"}),i.jsx("path",{d:"M12.6 5.6L10 8.4"})]})]}),i.jsx("span",{className:"tb-word",children:"Sound"})]}),Se&&i.jsx(Dz,{onClose:()=>We(!1),soundOn:U===!0,onToggleSound:de,prefs:Pe,onLevel:(L,O)=>Te(L,{level:O}),onFigure:(L,O)=>Te(L,{figure:O}),onPreview:L=>Qe(L),notifyOn:as,onToggleNotify:da,notifyVetoed:Wl,notifyPermission:Nu?lo:"unsupported",onAskNotify:_u,openerRef:dt})]}),i.jsxs("div",{className:"appearance-slot",children:[i.jsx("button",{ref:Ne,className:"btn icon-btn",onClick:()=>{We(!1),le(L=>!L)},title:"Appearance settings","aria-label":`Appearance settings, ${Js} theme, character ${es?"shown":"hidden"}`,"aria-haspopup":"dialog","aria-expanded":ct,"aria-controls":ct?"appearance-menu":void 0,children:Js==="dark"?i.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:[i.jsx("circle",{cx:"7",cy:"7",r:"2.5"}),i.jsx("path",{d:"M7 1.5v1.2M7 11.3v1.2M1.5 7h1.2M11.3 7h1.2M3.1 3.1l.85.85M10.05 10.05l.85.85M3.1 10.9l.85-.85M10.05 3.95l.85-.85"})]}):i.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":!0,children:i.jsx("path",{d:"M11.8 8.4A5 5 0 1 1 5.6 2.2a4 4 0 0 0 6.2 6.2Z"})})}),ct&&i.jsx(Bz,{theme:Js,onTheme:Yo,characterEnabled:es,onToggleCharacter:()=>Nl(L=>!L),onClose:()=>le(!1),openerRef:Ne})]})]})]})]}),Xs?i.jsxs("div",{className:"ver-banner done",role:"status",children:[i.jsx("span",{className:"ver-dot"}),i.jsxs("strong",{children:["Restarted — now running v",Xs,"."]}),i.jsx("span",{className:"ver-sub",children:"The canvas replayed from the event log."})]}):_l&&!Je?i.jsxs("div",{className:"conn-banner",role:"alert",children:[i.jsx("span",{className:"conn-dot"}),Zn?Zr==="npx"?"Fetching the new version with npx — this can take a minute…":`Restarting ${nn}…`:(()=>{const L=dG({connected:Je,paused:Ys});return i.jsxs(i.Fragment,{children:[`Lost connection to the ${nn} server. Reconnecting…`,L&&i.jsx("span",{className:"conn-sub",children:L})]})})()]}):En&&fe?i.jsxs("div",{className:`ver-banner ${fe.kind}`,role:"status",children:[i.jsx("span",{className:`ver-dot${kl==null?"":" armed"}`}),fe.kind==="restart"?i.jsxs(i.Fragment,{children:[i.jsxs("strong",{children:["v",fe.to," is installed — this deck still runs v",fe.from,"."]}),ce!=null&&ce.canRestart?i.jsxs(i.Fragment,{children:[i.jsx("button",{type:"button",className:"ver-act",onClick:()=>Er(),...Aa(Zn),title:`Stop this process and bring it back on the same port. The canvas replays from the event log.
293
293