ccdeck 3.23.2 → 3.23.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/web/assets/{BrowserWatchModal-plr3Bmmv.js → BrowserWatchModal-Cro433q6.js} +1 -1
- package/dist/web/assets/{UsageHistoryModal-DEZjEWrd.js → UsageHistoryModal-D1sRtUUY.js} +1 -1
- package/dist/web/assets/{index-DuAcNsxl.js → index-gPPlJnr8.js} +2 -2
- package/dist/web/index.html +1 -1
- package/package.json +1 -1
- package/release-notes.json +1 -1
|
@@ -88,7 +88,7 @@ ${Ne.sessionId}`:Ne.sessionId,children:Ne.label??Ne.sessionId.slice(0,8)}),l.jsx
|
|
|
88
88
|
|
|
89
89
|
${n}`:`Sort by ${t}`,onClick:()=>a(sq(s,e)),children:[t,l.jsx("span",{className:"sd-sort-dir","aria-hidden":!0,children:i==="none"?"":i==="ascending"?"↑":"↓"})]})})}const hq=3e3;function fq(e,t,n){return e>=n?"hot":e>=t?"warn":"calm"}function pq(e,t,n=Date.now()){const s=Math.max(0,Math.min(100,100-e));return{pct:s,value:`${s}%`,tone:s===0?"calm":s>=30?"hot":"warn",note:s>0?`CPU held to ${e}% of full speed to cool down`:t?`at full speed · held to ${100-t.peak}% ${mq(t.lastMs,n)}`:"running at full speed, and never held back"}}function mq(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 s=Math.floor(n/60);return s===1?"an hour ago":`${s} hours ago`}function Kl(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 gq(e){const t=Math.floor(e/86400),n=Math.floor(e%86400/3600),s=Math.floor(e%3600/60);return t>0?`${t}d ${n}h`:n>0?`${n}h ${s}m`:`${s}m`}function yq(){const[e,t]=x.useState(null),n=x.useRef(null);return x.useEffect(()=>{let s=!0;const a=async()=>{if(document.visibilityState!=="hidden")try{const f=await fetch("/api/system");if(!f.ok)return;const p=await f.json();s&&(p!=null&&p.ok)&&t(p)}catch{}},i=()=>{n.current==null&&(a(),n.current=window.setInterval(a,hq))},c=()=>{n.current!=null&&(window.clearInterval(n.current),n.current=null)},u=()=>{if(document.visibilityState==="hidden"){c();return}i(),a()};return i(),document.addEventListener("visibilitychange",u),()=>{s=!1,c(),document.removeEventListener("visibilitychange",u)}},[]),e}function a_({usageOpen:e,leaving:t,sub:n,onClose:s,children:a}){return l.jsxs("aside",{className:`sysdetail${e?" shifted":""}${t?" leaving":""}`,id:"system-panel","aria-labelledby":"sd-title",children:[l.jsxs("div",{className:"sd-head",children:[l.jsx("h2",{className:"sd-title",id:"sd-title",children:"This machine"}),n&&l.jsx("span",{className:"sd-sub",children:n}),l.jsx("button",{type:"button",className:"glyph-btn sd-close",onClick:s,"aria-label":"Close",title:"Close",children:"×"})]}),a]})}function wq({usageOpen:e,leaving:t,onClose:n}){const s=yq();if(!s||s.cpu==null||!s.memory)return l.jsx(a_,{usageOpen:e,leaving:t,onClose:n,children:l.jsx("div",{className:"sd-note",children:"reading this machine…"})});const{memory:a,swap:i,perCore:c,loadavg:u,cores:f,uptimeSec:p,platform:h,thermal:m}=s,y=a?a.total-a.available:0,w=h==="win32"?"Commit":"Swap",N=i&&i.total>0?i.used/i.total*100:0;return l.jsxs(a_,{usageOpen:e,leaving:t,sub:`up ${gq(p)} · ${f} cores`,onClose:n,children:[c&&c.length>0&&l.jsx("div",{className:"sd-section",role:"group","aria-label":"Cores",children:l.jsx(vd,{group:"cores",title:"Core history",action:"Show core history",label:"Cores",children:l.jsx("div",{className:"sd-cores",children:c.map((_,S)=>l.jsx("span",{className:"sd-core",title:`core ${S+1}: ${_}%`,children:l.jsx("span",{className:"sd-core-fill",style:{transform:`scaleY(${Math.max(2,_)/100})`}})},S))})})}),l.jsx("div",{className:"sd-section",role:"group","aria-label":"Memory",children:l.jsxs(vd,{group:"memory",title:"Memory history",action:"Show memory history",label:"Memory",children:[a&&l.jsx(Ld,{label:"Physical",value:l.jsxs(l.Fragment,{children:[l.jsx("b",{children:Kl(y)})," of ",Kl(a.total)]}),pct:a.usedPct,tone:a.usedPct>=90?"warn":"calm",note:`${Kl(a.available)} available`}),i&&i.total>0&&l.jsx(Ld,{label:w,value:l.jsxs(l.Fragment,{children:[l.jsx("b",{children:Kl(i.used)})," of ",Kl(i.total)]}),pct:N,tone:N>=90?"warn":"calm",note:N>=50?"paging to disk":void 0})]})}),u&&l.jsx("div",{className:"sd-section",role:"group","aria-label":"Load average",children:l.jsxs(vd,{group:"load",title:"Load history",action:"Show load history",label:"Load average",children:[l.jsx("div",{className:"sd-load",children:u.map((_,S)=>l.jsxs("span",{className:`sd-load-item${_>f?" over":""}`,children:[l.jsx("b",{children:_.toFixed(2)}),l.jsx("span",{children:["1m","5m","15m"][S]})]},S))}),l.jsx("div",{className:"sd-note",children:u[0]>f?`${(u[0]/f).toFixed(1)}× more work queued than cores to run it`:`within ${f} cores`})]})}),l.jsx(vq,{thermal:m}),l.jsx(xq,{sys:s})]})}function vd({group:e,title:t,action:n,label:s,children:a}){const[i,c]=x.useState(!1);return l.jsxs(l.Fragment,{children:[l.jsxs("button",{type:"button",className:"sd-open",onClick:()=>c(!0),title:n,"aria-label":n,children:[l.jsxs("div",{className:"sd-h","aria-hidden":!0,children:[s," ",l.jsx("i",{className:"sd-row-more",children:"›"})]}),a]}),i&&l.jsx(GD,{group:e,title:t,onClose:()=>c(!1)})]})}function vq({thermal:e}){if(!e)return null;const t=e.throttle?pq(e.throttle.speedLimit,e.heldBack):null;return l.jsx("div",{className:"sd-section",role:"group","aria-label":"Thermal",children:l.jsxs(vd,{group:"thermal",title:"Thermal history",action:"Show thermal history",label:"Thermal",children:[e.celsius.map(n=>l.jsx(Ld,{label:n.label,value:l.jsxs(l.Fragment,{children:[l.jsx("b",{children:n.celsius})," °C"]}),pct:n.celsius,tone:fq(n.celsius,n.warnAt,n.critAt)},n.label)),t&&l.jsx(Ld,{label:"Throttling",value:t.value,pct:t.pct,tone:t.tone,note:t.note})]})})}function xq({sys:e}){const[t,n]=x.useState(!1);return l.jsxs("div",{className:"sd-section sd-door-section",children:[l.jsx("button",{type:"button",className:"sd-open sd-door",onClick:()=>n(!0),"aria-label":"Show every process the deck is watching",children:l.jsxs("span",{className:"sd-door-plate",children:[l.jsxs("span",{className:"sd-door-name",children:["Busiest processes",l.jsx("i",{className:"sd-row-more","aria-hidden":!0,children:"›"})]}),l.jsx("span",{className:"sd-door-sub",children:"every process, with its command line"})]})}),t&&l.jsx(dq,{sys:e,onClose:()=>n(!1)})]})}function Ld({label:e,value:t,pct:n,tone:s="calm",note:a}){return l.jsxs("div",{className:"sd-row",children:[l.jsxs("div",{className:"sd-row-head",children:[l.jsx("span",{className:"sd-row-label",children:e}),l.jsx("span",{className:"sd-row-val",children:t})]}),l.jsx("span",{className:"sd-track",children:l.jsx("span",{className:`sd-fill${s==="calm"?"":` ${s}`}`,style:{transform:`scaleX(${n<=0?0:Math.max(1,Math.min(100,n))/100})`}})}),a&&l.jsx("div",{className:"sd-note",children:a})]})}const o_=18,bq=1100,Ni=(e,t)=>{const n=Math.sin(e*12.9898+t*78.233)*43758.5453;return n-Math.floor(n)},kq=Array.from({length:o_},(e,t)=>{const n=-72+144*t/(o_-1)+(Ni(t,1)-.5)*9,s=(n-90)*(Math.PI/180),a=(54+32*Math.cos(n*Math.PI/180))*(.74+Ni(t,2)*.52);return{dx:Math.cos(s)*a,dy:Math.sin(s)*a,rot:(t%2?1:-1)*(100+Ni(t,3)*260),delay:Math.round(Ni(t,4)*90),dur:760+Math.round(Ni(t,5)*260),scale:.8+Ni(t,6)*.45,hue:t%4,round:t%3===0}});function i_({anchor:e}){var a;const[t,n]=x.useState(null),s=typeof window<"u"&&((a=window.matchMedia)==null?void 0:a.call(window,"(prefers-reduced-motion: reduce)").matches);return x.useEffect(()=>{if(s)return;const i=e.current;if(!i)return;const c=i.getBoundingClientRect();n({x:c.left+c.width/2,y:c.top+c.height/2});const u=window.setTimeout(()=>n(null),bq);return()=>window.clearTimeout(u)},[e,s]),s||!t?null:$r.createPortal(l.jsx("div",{className:"confetti",style:{left:`${t.x}px`,top:`${t.y}px`},"aria-hidden":!0,children:kq.map((i,c)=>l.jsx("span",{className:`confetti-bit${i.round?" round":""}`,"data-hue":i.hue,style:{"--dx":`${i.dx.toFixed(1)}px`,"--dy":`${i.dy.toFixed(1)}px`,"--rot":`${i.rot}deg`,"--s":i.scale.toFixed(2),animationDelay:`${i.delay}ms`,animationDuration:`${i.dur}ms, ${i.dur}ms`}},c))}),document.body)}const RA=new Set(["awaiting_url","awaiting_code","registering"]);function _q(e){return e!=null&&RA.has(e)}function MA(e){return e!=null&&e!=="done"&&!RA.has(e)}const Nq="the sign-in ended before it finished — the deck restarted, or it was cancelled in another tab",Sq="the sign-in did not complete";function jq({state:e,serverError:t,localError:n}){const s=e==="idle";return{title:s?"Sign-in ended":"Sign-in failed",message:n||t||(s?Nq:Sq)}}function Eq({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 Cq="done";function Tq(){let e=!1;return{shouldAnnounce(t){return t!==Cq?(e=!1,!1):e?!1:(e=!0,!0)}}}function Zx(e,t){return t&&Object.hasOwn(e,t)?e[t]:void 0}const Aq={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 ${Zt}`,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"},Rq={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"},Mq=`claude-swap could not read the login keychain — start ${Zt} from a Terminal window rather than a background service`;function ux(e,t){if((e==null?void 0:e.reason)!=="no_cswap"&&/keychain/i.test(gc(e)))return Mq;const n=Zx(Rq,e==null?void 0:e.reason);return n||(e==null?void 0:e.reason)||t}function gc(e){return((e==null?void 0:e.output)||(e==null?void 0:e.detail)||(e==null?void 0:e.error)||"").trim()}const Iq={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"},$q="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 Oq(e){return/\bnpx\b/i.test(e)&&/(command not found|not found|not recognized|ENOENT)/i.test(e)}const Pq="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",Lq="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",Dq=e=>/\b(?:ERR_)?MODULE_NOT_FOUND\b|cannot find (?:module|package)/i.test(e),qq=/node_modules[\\/]npm[\\/]bin[\\/]|\bnpm-prefix\.js\b|\bnp[mx][-.][\w.-]*cli\.js\b/i,Fq=/[\\/]_npx[\\/]/i,Bq=`the copy of ccusage ${Zt} installed for itself`;function zq(e){const t=String((e==null?void 0:e.install)??"").replace(/\s+/g," ").trim();return t.length>240?`${t.slice(0,239)}…`:t}function n9(e,t){const n=Uq(e,t),s=zq(e);switch(e==null?void 0:e.stage){case"npx":return s?`ccusage failed on both of its paths. The managed install failed first — ${s} — and the deck then fell back to npx, where ${Xl(n)}`:`there is no managed copy of ccusage on this machine, and the npx fallback failed: ${Xl(n)}`;case"managed":return`${Bq} failed to run: ${Xl(n)}`;case"path":return e.bin?`the ccusage this deck found at ${e.bin} failed to run: ${Xl(n)}`:`the ccusage this deck found on your PATH failed to run: ${Xl(n)}`;default:return n}}const Xl=e=>/^[A-Z][a-z]/.test(e)?e[0].toLowerCase()+e.slice(1):e;function Uq(e,t){const n=gc(e);if(Dq(n)){if(Fq.test(n))return Lq;if(qq.test(n))return Pq}if(Oq(n))return $q;const s=Zx(Iq,e==null?void 0:e.reason);return s||(e==null?void 0:e.reason)||t}function Ti(e,t){if(e!=null&&e.detail)return e.detail;if(e!=null&&e.error&&MA(e.state))return e.error;const n=Zx(Aq,e==null?void 0:e.reason);return n||(e!=null&&e.error?e.error:(e==null?void 0:e.reason)||t)}function Wq(e,t,n){if(n<=0||th(e))return{kind:"pass"};const s=t>=0&&t<n?t:-1;switch(e.key){case"ArrowRight":return{kind:"select",index:s===-1?0:(s+1)%n};case"ArrowLeft":return{kind:"select",index:s===-1?n-1:(s-1+n)%n};case"Home":return{kind:"select",index:0};case"End":return{kind:"select",index:n-1};default:return{kind:"pass"}}}function IA(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 Hq(e){const t=new Map;for(const n of e){const s=(n.email??"").trim().toLowerCase();s&&t.set(s,(t.get(s)??0)+1)}return e.map(n=>{const s=(n.email??"").trim(),a=n.alias||s||`account ${n.num}`,i=[];return n.alias&&s&&i.push(s),s&&(t.get(s.toLowerCase())??0)>1&&i.push(n.org||`slot ${n.num}`),{num:n.num,label:a,sub:i.length?i.join(" · "):null}})}function Gq(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 Vq(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 Yq(e){const t=e.length;if(!t)return"Nothing to import.";const n=p=>e.filter(h=>h.state===p).length,s=[],a=n("imported");a&&s.push(`${a} of ${t} imported`);const i=n("healed");i&&s.push(`${i} had a dead token replaced`);const c=n("updated");c&&s.push(`${c} updated`);const u=n("present");u&&s.push(`${u} already here`);const f=n("failed");return f&&s.push(`${f} did not arrive`),`${s.join(", ")}.`}const Kq=1500,rd=[{id:"login",label:"Sign in"},{id:"paste",label:"Paste a share"}],l_="aa-panel",c_=e=>`aa-tab-${e}`;async function Zl(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const dx=fe.forwardRef((e,t)=>l.jsxs("svg",{className:"aa-mark",viewBox:"0 0 44 44","aria-hidden":!0,ref:t,children:[l.jsx("circle",{className:"aa-mark-ring",cx:"22",cy:"22",r:"20"}),l.jsx("path",{className:"aa-mark-tick",d:"M13.5 22.5 L19.5 28.5 L31 17"})]}));dx.displayName="SuccessMark";function Xq({onClose:e,onChanged:t}){const[n,s]=x.useState("login"),[a,i]=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),[S,b]=x.useState(null),[j,E]=x.useState(null),C=x.useRef(""),T=x.useRef(!1),R=x.useRef(!1),I=x.useRef(null),L=x.useRef(null),H=x.useRef(null),$=x.useRef(null),V=x.useRef([]),Q=x.useRef(!1),J=x.useCallback(()=>{T.current&&Zl({action:"login-cancel"}).catch(()=>{}),e()},[e]),M=dn(J,{focusRef:H}),X=x.useCallback(async()=>{if(!ws(R.current))return;R.current=!0,m(!0),w(null),T.current=!0;const U=await Zl({action:"login"}).catch(()=>null);if(R.current=!1,m(!1),!(U!=null&&U.ok)){w(Ti(U,"could not start the sign-in"));return}i(U)},[]);x.useEffect(()=>{if(!_q(a==null?void 0:a.state))return;const U=window.setInterval(async()=>{try{const re=await fetch("/api/claude-accounts/login");re.ok&&i(await re.json())}catch{}},Kq);return()=>window.clearInterval(U)},[a]);const G=x.useRef(t);G.current=t;const P=x.useState(Tq)[0];x.useEffect(()=>{var U;(a==null?void 0:a.state)==="awaiting_code"&&((U=I.current)==null||U.focus()),P.shouldAnnounce(a==null?void 0:a.state)&&G.current()},[a==null?void 0:a.state,P]),x.useEffect(()=>{var U;n==="paste"&&!Q.current&&((U=L.current)==null||U.focus()),Q.current=!1},[n]);const B=x.useCallback(U=>{var de;const re=Wq(U,rd.findIndex(pe=>pe.id===n),rd.length);re.kind!=="pass"&&(U.preventDefault(),Q.current=!0,s(rd[re.index].id),(de=V.current[re.index])==null||de.focus())},[n]),W=x.useCallback(async()=>{var re;if(!ws(R.current))return;R.current=!0,m(!0),w(null);const U=await Zl({action:"login-code",code:c}).catch(()=>null);if(R.current=!1,m(!1),!(U!=null&&U.ok)){w(Ti(U,"the code was not accepted")),U!=null&&U.state&&i(U),(re=I.current)==null||re.select();return}u(""),i(U)},[c,a]),Y=x.useCallback(async()=>{if(!ws(R.current))return;R.current=!0,m(!0),w(null);const U=await Zl({action:"import",blob:f}).catch(()=>null);if(R.current=!1,m(!1),!(U!=null&&U.ok)){w(Ti(U,"the import failed"));return}C.current=f,p(""),E(null),_(U.results??[]),t()},[f,t]),O=x.useCallback(async U=>{const re=`${U.email}|${U.org??""}`;if(!ws(R.current)||!C.current)return;R.current=!0,m(!0),b(re),E(null);const de=await Zl({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:Ti(de,"that account could not be updated")});return}const pe=(de.results??[])[0];pe&&_(ge=>ge&&ge.map(Te=>`${Te.email}|${Te.org??""}`===re?pe:Te)),t()},[t]),F=(a==null?void 0:a.state)==="done"?a.account:null,oe=Eq({restored:a==null?void 0:a.restored,activeAccount:a==null?void 0:a.activeAccount}),z=MA(a==null?void 0:a.state)||!!(y&&T.current&&!h),Z=jq({state:a==null?void 0:a.state,serverError:a==null?void 0:a.error,localError:y});return $r.createPortal(l.jsx("div",{className:"modal-backdrop",onClick:J,role:"presentation",children:l.jsxs("div",{ref:M,className:"modal aa-modal",onClick:U=>U.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Add a Claude account",children:[l.jsxs("header",{className:"modal-head",children:[l.jsx("div",{className:"modal-title",children:l.jsx("span",{className:"aa-tabs",role:"tablist","aria-label":"How to add the account",onKeyDown:B,children:rd.map((U,re)=>l.jsx("button",{type:"button",role:"tab",id:c_(U.id),ref:de=>{V.current[re]=de},"aria-selected":n===U.id,"aria-controls":l_,tabIndex:n===U.id?0:-1,className:`aa-tab${n===U.id?" on":""}`,onClick:()=>{Q.current=!1,s(U.id)},children:U.label},U.id))})}),l.jsx("div",{className:"modal-actions",children:l.jsx("button",{type:"button",className:"glyph-btn",onClick:J,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),l.jsx("section",{className:"modal-body aa-body",id:l_,role:"tabpanel","aria-labelledby":c_(n),children:n==="login"?F?l.jsxs("div",{className:"aa-done",children:[l.jsx(dx,{ref:$}),l.jsx(i_,{anchor:$}),l.jsx("h4",{children:F.added?`Account ${F.num} added`:"Credentials refreshed"}),l.jsxs("p",{className:"aa-note",children:[l.jsx("strong",{children:F.email}),F.added?oe?" 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."]}),oe?l.jsx("p",{className:"aa-note aa-warn",role:"status",children:oe}):null,l.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"?l.jsxs(l.Fragment,{children:[l.jsxs("div",{className:"aa-step",children:[l.jsx("h4",{children:"1 · Approve in the browser"}),l.jsx("p",{className:"aa-note",children:"A tab should have opened. If not, use this link:"}),l.jsx("a",{className:"aa-link",href:a.url??"#",target:"_blank",rel:"noreferrer noopener",children:a.url})]}),l.jsxs("div",{className:"aa-step",children:[l.jsx("h4",{children:"2 · Paste a code, if the page shows one"}),l.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."}),l.jsxs("div",{className:"aa-field",children:[l.jsx("input",{ref:I,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"}),l.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)&&l.jsx("p",{className:"aa-err",children:y??a.error}),l.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?l.jsxs("div",{className:"aa-step",children:[l.jsx("h4",{children:Z.title}),l.jsx("p",{className:"aa-err",children:Z.message}),l.jsx("button",{type:"button",className:"btn",onClick:()=>{T.current=!1,i(null),w(null),X()},children:"Try again"})]}):h||T.current?l.jsx("div",{className:"aa-step",children:l.jsx("p",{className:"aa-note",children:"Asking the claude CLI for a sign-in link…"})}):l.jsxs("div",{className:"aa-step aa-primer",children:[l.jsx("h4",{children:"Sign in to Anthropic"}),l.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."}),l.jsx("div",{className:"aa-actions",children:l.jsx("button",{type:"button",ref:H,className:"btn primary",onClick:X,children:"Open the sign-in page"})})]}):N?(()=>{const U=N.filter(re=>re.state==="imported").length;return l.jsxs("div",{className:"aa-done",children:[l.jsx(dx,{ref:$}),U>0&&l.jsx(i_,{anchor:$}),l.jsx("h4",{children:Yq(N)}),N.length>0&&l.jsx("ul",{className:"aa-results",children:N.map(re=>{const de=`${re.email}|${re.org??""}`;return l.jsxs("li",{className:`aa-result ${re.state}`,children:[l.jsx("span",{className:"aa-result-who",children:re.email||(re.num?`slot ${re.num}`:"an account")}),l.jsx("span",{className:"aa-result-what",children:Vq(re.state)}),re.state==="present"&&l.jsx("button",{type:"button",className:"aa-result-fix","aria-busy":S===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:()=>O(re),children:S===de?"updating…":"update anyway"}),(j==null?void 0:j.key)===de&&l.jsx("span",{className:"aa-result-err",children:j.text})]},de)})}),l.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",l.jsx("strong",{children:" update anyway"}),"."]}),l.jsxs("div",{className:"aa-actions",children:[l.jsx("button",{type:"button",className:"btn primary",onClick:e,children:"Done"}),l.jsx("button",{type:"button",className:"btn",onClick:()=>{C.current="",E(null),_(null)},children:"Import another"})]})]})})():l.jsxs("div",{className:"aa-step",children:[l.jsx("h4",{children:"Paste an account shared from another deck"}),l.jsxs("div",{className:"aa-field",children:[l.jsx("input",{ref:L,type:"text",value:f,onChange:U=>p(U.target.value),onKeyDown:U=>{U.key==="Enter"&&f.trim()&&!h&&Y()},placeholder:"ccdeck2:…",spellCheck:!1,autoComplete:"off","aria-label":"Shared account"}),l.jsx("button",{type:"button",className:"btn primary",...aa(h,!f.trim()),onClick:Y,children:h?"importing…":"Import"})]}),y&&l.jsx("p",{className:"aa-err",children:y}),l.jsxs("p",{className:"aa-note",children:["Use ",l.jsx("strong",{children:"share"})," on one account in the other deck, or ",l.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)}function Zq(e,t,n){if(n<=0||th(e))return{kind:"pass"};const s=t>=0&&t<n?t:-1;switch(e.key){case"ArrowDown":return{kind:"focus",index:s===-1?0:(s+1)%n};case"ArrowUp":return{kind:"focus",index:s===-1?n-1:(s-1+n)%n};case"Home":return{kind:"focus",index:0};case"End":return{kind:"focus",index:n-1};default:return{kind:"pass"}}}const oa=4,Er=8;function Qq(e,t,n){const s=n.width-Er-(e.right+oa),a=e.left-oa-Er,i=t.width<=s||s>=a?"right":"left",c=i==="right"?e.right+oa:e.left-oa-t.width,u=n.height-Er*2,f=t.height<=u,p=f?t.height:Math.max(0,u);return{top:Math.max(Er,Math.min(e.top,n.height-Er-p)),left:Math.max(Er,c),side:i,maxHeight:f?null:p}}function Jq(e,t,n){const s=n.height-Er-(e.bottom+oa),a=e.top-oa-Er,i=t.height<=s||s>=a?"below":"above",c=i==="below"?s:a,u=t.height<=c,f=u?t.height:Math.max(0,c),p=i==="below"?e.bottom+oa:e.top-oa-f,h=Math.max(Er,Math.min(e.right-t.width,n.width-Er-t.width));return{top:Math.max(Er,p),left:h,side:i,maxHeight:u?null:f}}const $A='[role="menuitem"]';function u_(e){return e?Array.from(e.querySelectorAll($A)).filter(t=>!t.disabled):[]}function d_({anchorId:e,boundaryId:t,id:n,className:s,role:a,labelledBy:i,start:c="first",onClose:u,children:f}){const p=x.useRef(u);p.current=u;const h=dn(()=>{var _;(_=document.getElementById(e))==null||_.focus(),p.current()}),m=x.useCallback(()=>{var C;const _=h.current;if(!_)return;const S=document.getElementById(e);if(!S){p.current();return}const b=S.getBoundingClientRect(),j=t?(C=document.getElementById(t))==null?void 0:C.getBoundingClientRect():null;if(j&&(b.bottom<=j.top||b.top>=j.bottom)){_.contains(document.activeElement)&&S.focus({preventScroll:!0}),p.current();return}_.style.maxHeight="";const E=Jq(b,{width:_.offsetWidth,height:_.offsetHeight},{width:window.innerWidth,height:window.innerHeight});_.style.top=`${E.top}px`,_.style.left=`${E.left}px`,_.style.maxHeight=E.maxHeight==null?"":`${E.maxHeight}px`,_.dataset.side=E.side},[e,t,h]);x.useLayoutEffect(()=>{m()}),x.useEffect(()=>{const _=S=>{var b;(b=h.current)!=null&&b.contains(S.target)||m()};return window.addEventListener("scroll",_,!0),window.addEventListener("resize",m),()=>{window.removeEventListener("scroll",_,!0),window.removeEventListener("resize",m)}},[m,h]),x.useEffect(()=>{const _=S=>{var j,E;const b=S.target;!b||(j=h.current)!=null&&j.contains(b)||(E=document.getElementById(e))!=null&&E.contains(b)||p.current()};return window.addEventListener("pointerdown",_,!0),()=>window.removeEventListener("pointerdown",_,!0)},[e,h]),x.useEffect(()=>{var S;if(a!=="menu")return;const _=u_(h.current);(S=c==="last"?_[_.length-1]:_[0])==null||S.focus()},[]);const y=_=>{var S;if(a==="menu"&&_.key==="Tab"){_.stopPropagation(),(S=document.getElementById(e))==null||S.focus(),_.shiftKey&&_.preventDefault(),p.current();return}if(a==="menu"){const b=u_(h.current),j=Zq(_,b.indexOf(document.activeElement),b.length);j.kind==="focus"&&(_.preventDefault(),b[j.index].focus())}_.key.length===1&&_.stopPropagation()},w=_=>{_.target.closest("button, input, select, textarea, code")||_.preventDefault()},N=_=>{if(a!=="menu"||_.pointerType==="touch")return;const S=_.target.closest($A);S&&!S.disabled&&document.activeElement!==S&&S.focus({preventScroll:!0})};return $r.createPortal(l.jsx("div",{ref:h,id:n,className:`anchored-popover${s?` ${s}`:""}`,role:a,"aria-labelledby":i,onKeyDown:y,onMouseDown:w,onPointerMove:N,children:f}),document.body)}async function eF(e){return(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)})).json().catch(()=>null)}const tF=1800;function nF({accounts:e,onClose:t,copyText:n}){const[s,a]=x.useState([]),[i,c]=x.useState(null),[u,f]=x.useState(!1),[p,h]=x.useState(null),[m,y]=x.useState(!1),[w,N]=x.useState(()=>Math.floor(Date.now()/1e3)),_=x.useRef(null),S=x.useRef(!1),b=dn(t,{focusRef:_});x.useEffect(()=>{if(!i)return;N(Math.floor(Date.now()/1e3));const $=window.setInterval(()=>N(Math.floor(Date.now()/1e3)),1e3);return()=>window.clearInterval($)},[i]);const j=Hq(e),E=e.filter($=>!s.includes($.num)).map($=>$.num),C=E.length===e.length,T=$=>a(V=>V.includes($)?V.filter(Q=>Q!==$):[...V,$]),R=x.useCallback(async()=>{if(!ws(S.current)||!E.length)return;S.current=!0,f(!0),h(null),y(!1);const $=await eF({action:"share",accounts:E}).catch(()=>null);if(S.current=!1,f(!1),!($!=null&&$.ok)){h(Ti($,"the share could not be made"));return}c({blob:$.blob,expiresAt:$.expiresAt,shared:$.shared??[],failed:$.failed??[]})},[e,E]),I=i?IA(i.expiresAt,w):null,L=(I==null?void 0:I.tone)==="gone",H=(i==null?void 0:i.shared.length)??0;return $r.createPortal(l.jsx("div",{className:"modal-backdrop",onClick:t,role:"presentation",children:l.jsxs("div",{ref:b,className:"modal sa-modal",onClick:$=>$.stopPropagation(),role:"dialog","aria-modal":"true","aria-label":"Share accounts with another deck",children:[l.jsxs("header",{className:"modal-head",children:[l.jsx("div",{className:"modal-title",children:l.jsx("h3",{children:"Share accounts"})}),l.jsx("div",{className:"modal-actions",children:l.jsx("button",{type:"button",className:"glyph-btn",onClick:t,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),l.jsx("section",{className:"modal-body sa-body",children:i?l.jsxs("div",{className:"sa-step",children:[l.jsx("h4",{children:L?"This share has expired":H===1?"1 account, ready to paste":`${H} accounts, ready to paste`}),l.jsx("code",{className:`ap-share-blob${L?" sa-dead":""}`,children:i.blob}),l.jsxs("div",{className:"ap-share-foot",children:[l.jsx("button",{type:"button",className:"ap-manage-btn",ref:_,onClick:async()=>{if(L){c(null),R();return}await n(i.blob)&&(y(!0),window.setTimeout(()=>y(!1),tF))},children:L?"make a new share":m?"copied":`copy ${H===1?"the share":"all "+H}`}),l.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:[l.jsx("span",{className:"ap-share-warn",children:H===1?"this is the password":`this is ${H} passwords`})," · ",l.jsx("span",{className:`ap-share-expiry ${I==null?void 0:I.tone}`,children:I==null?void 0:I.text})]})]}),i.failed.length>0&&l.jsxs("div",{className:"sa-failed",role:"alert",children:[l.jsx("p",{className:"sa-failed-head",children:i.failed.length===1?"One account is not in this bundle:":`${i.failed.length} accounts are not in this bundle:`}),l.jsx("ul",{className:"sa-list",children:i.failed.map($=>{var Q;const V=!!($.email&&((Q=$.detail)!=null&&Q.includes($.email)));return l.jsxs("li",{children:[!V&&l.jsx("span",{className:"sa-who",children:$.email||`account ${$.num}`}),l.jsx("span",{className:"sa-why",children:$.detail||"could not be exported"})]},`${$.num}-${$.email}`)})})]}),l.jsx("p",{className:"sa-note",children:L?l.jsx(l.Fragment,{children:"Another deck will refuse this text now. Make a new one — the same accounts are still picked."}):l.jsxs(l.Fragment,{children:["Paste it into the other deck with ",l.jsx("strong",{children:"+"})," → ",l.jsx("strong",{children:"Paste a share"}),". Accounts it already holds are left exactly as they are."]})}),l.jsxs("div",{className:"sa-actions",children:[l.jsx("button",{type:"button",className:"btn",onClick:()=>{c(null),y(!1)},children:"Pick again"}),l.jsx("button",{type:"button",className:"btn primary",onClick:t,children:"Done"})]})]}):e.length===0?l.jsxs("div",{className:"sa-step",children:[l.jsx("h4",{children:"Nothing to share"}),l.jsxs("p",{className:"sa-note",children:["This deck is not holding any accounts right now. Sign one in with ",l.jsx("strong",{children:"+"}),", or wait — the panel is still reading the store."]}),l.jsx("div",{className:"sa-actions",children:l.jsx("button",{type:"button",className:"btn primary",ref:_,onClick:t,children:"Close"})})]}):l.jsxs("div",{className:"sa-step",children:[l.jsxs("h4",{children:["Which accounts go to the other ",Zt,"?"]}),l.jsx("p",{className:`sa-count${E.length?"":" empty"}`,children:Gq(E.length)}),l.jsx("ul",{className:"sa-list sa-pick",children:j.map($=>l.jsx("li",{children:l.jsxs("label",{className:"sa-row",children:[l.jsx("input",{type:"checkbox",checked:E.includes($.num),onChange:()=>T($.num)}),l.jsx("span",{className:"sa-who",children:$.label}),$.sub&&l.jsx("span",{className:"sa-sub",children:$.sub})]})},$.num))}),p&&l.jsx("p",{className:"aa-err",children:p}),l.jsxs("div",{className:"sa-actions",children:[l.jsx("button",{type:"button",className:"btn",onClick:()=>a(C?e.map($=>$.num):[]),children:C?"Clear all":"Select all"}),l.jsx("button",{type:"button",className:"btn primary",ref:_,...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 rF(e,t){const n=new Set(e),s=e.length?Math.max(...e):0;return[...new Set([...e,s+1])].sort((a,i)=>a-i).map(a=>{const i=a===t?"here":n.has(a)?"swap":"free";return{slot:a,kind:i,label:i==="here"?`slot ${a}`:`slot ${a} · ${i}`}})}function sF(e,t,n){if(!(n!=null&&n.ok))return null;const s=Number.isInteger(n.to)?n.to:null;if(s==null)return{menuFor:null,confirmRemove:null,shareFor:null,swapNote:null};const a=n.swapped===!0&&s!==t;return{menuFor:e.menuFor===t?s:a&&e.menuFor===s?t:e.menuFor,confirmRemove:null,shareFor:null,swapNote:a?{at:s,displaced:t}:null}}function aF(e,t,n){return t!=null&&e.some(s=>s.slot===t)?t:n}function oF(e,t,n){var a;const s=((a=e.find(i=>i.slot===t))==null?void 0:a.kind)??"here";return s==="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}.`}:s==="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 iF(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 h_(e){return typeof e.id=="string"&&e.id.startsWith("scoped-")}function lF(e){const t=e.filter(u=>!h_(u)),n=e.filter(u=>h_(u)),s=t.length?t:n,a=t.length?n:[],i=s.reduce((u,f)=>u&&u.pct>=f.pct?u:f,null);let c=null;for(const u of a)i&&u.pct<=i.pct||(!c||u.pct>c.pct)&&(c=u);return{shown:s,rest:a,fuller:c,peak:c??i}}const cF="\0";function Qx(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}${cF}${n}`}function uF(e,t){const n=Qx(t);return e.includes(n)?e.filter(s=>s!==n):[...e,n]}function dF(e,t){if(!Array.isArray(t))return e;const n=new Set(t.map(Qx)),s=e.filter(a=>n.has(a));return s.length===e.length?e:s}const hF=64;function fF(e,t){const n=e.trim();return{alias:n,commit:n!==(t??"").trim()}}const pF=Object.freeze({text:"couldn't reach the deck server",reload:!0}),mF=Object.freeze({text:"still waiting on the deck server — claude-swap can be slow to answer",reload:!0});async function f_(e){return e.ok?{ok:!0,status:e.status,body:null}:{ok:!1,status:e.status,body:await e.json().catch(()=>null)}}function gF(e){const t=e.find(s=>!s.ok);if(!t)return null;const n=gc(t.body);return{text:ux(t.body,`the deck server answered ${t.status}`),...n?{raw:n}:{},reload:!0}}function p_(e,t){return t?e!=null&&e.reload&&e.text===t.text&&e.raw===t.raw?e:t:e!=null&&e.reload?null:e}function OA({title:e,steps:t,finish:n,aside:s,onClose:a}){const i=x.useRef(null),c=dn(a,{focusRef:i}),[u,f]=x.useState(0),p=u===t.length-1,h=t[u],m=N=>f(Math.max(0,Math.min(t.length-1,N))),y=N=>{N.key!=="ArrowRight"&&N.key!=="ArrowLeft"||(N.preventDefault(),N.stopPropagation(),m(N.key==="ArrowRight"?u+1:u-1))},w=()=>{if(!p){m(u+1);return}n?n.act():a()};return $r.createPortal(l.jsx("div",{className:"modal-backdrop",onClick:a,role:"presentation",children:l.jsxs("div",{ref:c,className:"modal guide",onClick:N=>N.stopPropagation(),onKeyDown:y,role:"dialog","aria-modal":"true","aria-labelledby":"guide-title",children:[l.jsxs("header",{className:"modal-head",children:[l.jsxs("div",{className:"modal-title",children:[l.jsx("span",{id:"guide-title",className:"modal-tool-name",children:e}),l.jsxs("span",{className:"modal-tool-id",children:[u+1," / ",t.length]})]}),l.jsx("div",{className:"modal-actions",children:l.jsx("button",{type:"button",className:"glyph-btn",onClick:a,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),l.jsxs("section",{className:"modal-body",children:[l.jsx("div",{className:"guide-stage",children:h.art},u),l.jsx("p",{className:"guide-line","aria-live":"polite",children:h.line}),l.jsx("p",{className:"guide-tip",children:h.tip??""}),l.jsxs("div",{className:"guide-foot",children:[l.jsx("div",{className:"guide-dots",children:t.map((N,_)=>l.jsx("button",{type:"button",className:"glyph-btn guide-dot","aria-label":`Step ${_+1} of ${t.length}`,"aria-current":_===u?"step":void 0,onClick:()=>m(_)},_))}),p&&s&&l.jsx("button",{type:"button",className:"ap-lan-word guide-aside",onClick:s.act,children:s.label}),u>0&&l.jsx("button",{type:"button",className:"btn",onClick:()=>m(u-1),children:"Back"}),l.jsx("button",{ref:i,type:"button",className:"btn primary",onClick:w,children:p?(n==null?void 0:n.label)??"Done":"Next"})]})]})]})}),document.body)}const hx={ok:"ga-ok",warn:"ga-warn",accent:"ga-accent",flight:"ga-flight"};function lr({children:e}){return l.jsx("svg",{className:"guide-art",viewBox:"0 0 440 200","aria-hidden":!0,focusable:"false",children:e})}function ir({x:e,y:t=34,w:n=176,h:s=132,label:a}){return l.jsxs(l.Fragment,{children:[a&&l.jsx("text",{x:e+2,y:t-9,className:"ga-cap",children:a}),l.jsx("rect",{x:e,y:t,width:n,height:s,rx:10,className:"ga-screen"})]})}function Rr({x:e,y:t,email:n,state:s,tone:a,bars:i}){return l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:e+3,cy:t-4,r:3,className:hx[a]}),l.jsx("text",{x:e+12,y:t,className:"ga-t ga-mono",children:n}),l.jsx("text",{x:e+12,y:t+16,className:`ga-s ${hx[a]}`,children:s}),i==null?void 0:i.map((c,u)=>l.jsxs("g",{children:[l.jsx("text",{x:e,y:t+40+u*18,className:"ga-s",children:u?"7d":"5h"}),l.jsx("rect",{x:e+22,y:t+35+u*18,width:96,height:4,rx:2,className:"ga-track"}),l.jsx("rect",{x:e+22,y:t+35+u*18,width:96*c/100,height:4,rx:2,className:"ga-accent"}),l.jsxs("text",{x:e+148,y:t+40+u*18,className:"ga-s ga-accent",textAnchor:"end",children:[c,"%"]})]},u))]})}function PA({x:e,y:t,on:n}){return l.jsxs(l.Fragment,{children:[l.jsx("rect",{x:e,y:t,width:30,height:18,rx:9,className:n?"ga-switch-on":"ga-switch"}),l.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:s=!0}){return l.jsxs(l.Fragment,{children:[l.jsx("circle",{cx:e+3,cy:t-4,r:3,className:s?"ga-ok":"ga-dim"}),l.jsx("text",{x:e+12,y:t,className:s?"ga-t":"ga-s",children:n})]})}function m_({x:e,y:t,on:n}){return n?l.jsxs(l.Fragment,{children:[l.jsx("rect",{x:e,y:t,width:12,height:12,rx:3,className:"ga-accent"}),l.jsx("path",{d:`M${e+3} ${t+6.2}l2.3 2.3 4-4.6`,className:"ga-tick"})]}):l.jsx("rect",{x:e+.5,y:t+.5,width:11,height:11,rx:3,className:"ga-box"})}function g_({x:e,y:t,d:n}){return l.jsx("path",{d:n,transform:`translate(${e} ${t})`,className:"ga-glyph"})}function Jx({x:e,y:t}){return l.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 e0(){return l.jsxs(l.Fragment,{children:[l.jsx("circle",{r:9,className:"ga-key-bed"}),l.jsxs("g",{transform:"translate(-6 -6) scale(0.857)",className:"ga-key",children:[l.jsx("circle",{cx:4.6,cy:7,r:2.6}),l.jsx("path",{d:"M7.2 7h5.2M10.6 7v2.2M12.4 7v1.6"})]})]})}function Ai({x:e,y:t,w:n,title:s,sub:a,tone:i}){return l.jsxs(l.Fragment,{children:[l.jsx("rect",{x:e,y:t,width:n,height:40,rx:8,className:"ga-screen"}),l.jsx("rect",{x:e+6,y:t+10,width:3,height:20,rx:1.5,className:hx[i]}),l.jsx("text",{x:e+16,y:t+17,className:"ga-t ga-strong",children:s}),l.jsx("text",{x:e+16,y:t+31,className:"ga-s",children:a})]})}function $i({x:e,y:t,label:n,live:s}){return l.jsxs(l.Fragment,{children:[l.jsx("rect",{x:e,y:t,width:46,height:20,rx:10,className:s?"ga-chip-live":"ga-chip"}),l.jsx("text",{x:e+23,y:t+14,className:"ga-s ga-mono",textAnchor:"middle",children:n})]})}function Dd({x:e,y:t}){return l.jsxs(l.Fragment,{children:[l.jsx("text",{x:e,y:t,className:"ga-cap",children:"LOCAL NETWORK"}),l.jsx(PA,{x:e+118,y:t-13,on:!0})]})}function yF(){return l.jsxs(lr,{children:[l.jsx("rect",{x:14,y:14,width:206,height:172,rx:10,className:"ga-screen"}),l.jsx("text",{x:28,y:38,className:"ga-t ga-strong",children:"Sessions"}),l.jsx("text",{x:206,y:38,className:"ga-s ga-warn",textAnchor:"end",children:"1 waiting"}),l.jsx("rect",{x:20,y:50,width:194,height:42,rx:6,className:"ga-bed-warn"}),l.jsx("circle",{cx:33,cy:64,r:7,className:"ga-ring-warn ga-ping"}),l.jsx("circle",{cx:33,cy:64,r:3.5,className:"ga-warn"}),l.jsx("text",{x:44,y:68,className:"ga-t",children:"api-server"}),l.jsx("text",{x:44,y:83,className:"ga-s ga-warn",children:"waiting 6m · Bash"}),l.jsx("circle",{cx:33,cy:108,r:3.5,className:"ga-flight"}),l.jsx("text",{x:44,y:112,className:"ga-t",children:"docs-site"}),l.jsx("text",{x:44,y:127,className:"ga-s",children:"running · 12 tools"}),l.jsx("circle",{cx:33,cy:150,r:3.5,className:"ga-ok"}),l.jsx("text",{x:44,y:154,className:"ga-t",children:"billing"}),l.jsx("text",{x:44,y:169,className:"ga-s",children:"done · $0.84"}),l.jsx("path",{d:"M216 71C234 71 230 100 244 100",className:"ga-arc"}),l.jsx("path",{d:"M239 96l5 4-5 4",className:"ga-arrow"}),l.jsx("rect",{x:248,y:44,width:178,height:112,rx:10,className:"ga-screen"}),l.jsx("text",{x:262,y:64,className:"ga-cap",children:"API-SERVER"}),l.jsx("line",{x1:248,y1:74,x2:426,y2:74,className:"ga-line"}),l.jsx("text",{x:262,y:96,className:"ga-s ga-mono",children:"Bash(npm test)"}),l.jsx("text",{x:262,y:116,className:"ga-t ga-mono ga-warn",children:"Allow this command?"}),l.jsx("text",{x:262,y:136,className:"ga-s ga-mono",children:"> 1. Yes 2. No"})]})}function wF(){return l.jsxs(lr,{children:[l.jsx("path",{d:"M136 100C166 100 166 38 196 38",className:"ga-edge ga-flow"}),l.jsx("path",{d:"M136 100H196",className:"ga-edge ga-flow"}),l.jsx("path",{d:"M136 100C166 100 166 162 196 162",className:"ga-edge-done"}),l.jsx("path",{d:"M308 38H326M308 100H326",className:"ga-edge"}),l.jsx(Ai,{x:20,y:80,w:116,title:"main",sub:"Opus 5 · 9 tools",tone:"accent"}),l.jsx(Ai,{x:196,y:18,w:112,title:"explore",sub:"Haiku · 14 tools",tone:"flight"}),l.jsx(Ai,{x:196,y:80,w:112,title:"tests",sub:"Sonnet · 6 tools",tone:"flight"}),l.jsx(Ai,{x:196,y:142,w:112,title:"review",sub:"done · 38s",tone:"ok"}),l.jsx($i,{x:326,y:28,label:"Read"}),l.jsx($i,{x:380,y:28,label:"Grep",live:!0}),l.jsx($i,{x:326,y:90,label:"Bash",live:!0})]})}function y_({x:e,y:t,label:n,pct:s,note:a}){return l.jsxs(l.Fragment,{children:[l.jsx("text",{x:e,y:t,className:"ga-s",children:n}),l.jsxs("text",{x:e+194,y:t,className:"ga-s ga-accent",textAnchor:"end",children:[s,"%"]}),l.jsx("rect",{x:e,y:t+7,width:194,height:5,rx:2.5,className:"ga-track"}),l.jsx("rect",{x:e,y:t+7,width:194*s/100,height:5,rx:2.5,className:"ga-accent"}),l.jsx("text",{x:e,y:t+26,className:"ga-s",children:a})]})}function vF(){return l.jsxs(lr,{children:[l.jsx("rect",{x:14,y:30,width:172,height:140,rx:10,className:"ga-screen"}),l.jsx("text",{x:30,y:56,className:"ga-cap",children:"THIS SESSION"}),l.jsx("text",{x:30,y:98,className:"ga-big",children:"$3.66"}),l.jsx("text",{x:30,y:122,className:"ga-s",children:"Opus 5 · 1.2M tokens"}),l.jsx("text",{x:30,y:150,className:"ga-s",children:"$21.40 today"}),l.jsx("rect",{x:200,y:30,width:226,height:140,rx:10,className:"ga-screen"}),l.jsx("text",{x:216,y:56,className:"ga-cap",children:"CLAUDE QUOTA"}),l.jsx(y_,{x:216,y:80,label:"5-hour window",pct:24,note:"resets in 53m"}),l.jsx(y_,{x:216,y:124,label:"7-day window",pct:61,note:"resets in 4d"})]})}function xF(){return l.jsxs(lr,{children:[l.jsx("rect",{x:14,y:40,width:172,height:120,rx:10,className:"ga-canvas"}),l.jsx(Ai,{x:30,y:80,w:140,title:"tests",sub:"Sonnet 5 · 6 tools",tone:"flight"}),l.jsx(Jx,{x:156,y:106}),l.jsx("path",{d:"M170 92C186 92 184 60 200 60",className:"ga-arc"}),l.jsx("path",{d:"M195 56l5 4-5 4",className:"ga-arrow"}),l.jsx(ir,{x:200,y:22,w:226,h:160}),l.jsx("text",{x:214,y:46,className:"ga-t ga-strong",children:"tests"}),l.jsx("text",{x:412,y:46,className:"ga-s",textAnchor:"end",children:"Sonnet 5 · 38s"}),l.jsx("line",{x1:200,y1:56,x2:426,y2:56,className:"ga-line"}),l.jsx("text",{x:214,y:76,className:"ga-cap",children:"PROMPT"}),l.jsx("text",{x:214,y:92,className:"ga-t",children:"Run the suite and fix what fails"}),l.jsx("text",{x:214,y:116,className:"ga-cap",children:"TOOLS · 6"}),l.jsx($i,{x:214,y:122,label:"Read"}),l.jsx($i,{x:266,y:122,label:"Edit"}),l.jsx($i,{x:318,y:122,label:"Bash",live:!0}),l.jsx("text",{x:214,y:164,className:"ga-cap",children:"TOKENS"}),l.jsx("text",{x:214,y:178,className:"ga-s ga-mono",children:"41k in · 2.1k out · $0.12"})]})}function bF(){const e=[18,24,28,14,22,26,30,16,24,28,20,26];return l.jsxs(lr,{children:[l.jsx(ir,{x:14,y:20,w:412,h:160}),l.jsx("text",{x:28,y:44,className:"ga-t ga-strong",children:"This machine"}),l.jsx("text",{x:412,y:44,className:"ga-s",textAnchor:"end",children:"12 cores · up 10d"}),l.jsx("line",{x1:14,y1:56,x2:426,y2:56,className:"ga-line"}),l.jsx("text",{x:28,y:76,className:"ga-cap",children:"CORES"}),e.map((t,n)=>l.jsxs("g",{children:[l.jsx("rect",{x:28+n*15,y:82,width:10,height:30,rx:2,className:"ga-track"}),l.jsx("rect",{x:28+n*15,y:112-t,width:10,height:t,rx:2,className:"ga-accent"})]},n)),l.jsx("text",{x:28,y:136,className:"ga-cap",children:"MEMORY"}),l.jsx("rect",{x:28,y:143,width:178,height:5,rx:2.5,className:"ga-track"}),l.jsx("rect",{x:28,y:143,width:105,height:5,rx:2.5,className:"ga-accent"}),l.jsx("text",{x:28,y:165,className:"ga-s",children:"18.9 GB of 32.0 GB"}),l.jsx("text",{x:240,y:76,className:"ga-cap",children:"THERMAL"}),l.jsx("text",{x:240,y:100,className:"ga-big",children:"66 °C"}),l.jsx("text",{x:240,y:118,className:"ga-s ga-ok",children:"running at full speed"}),l.jsx("text",{x:240,y:142,className:"ga-cap",children:"BUSIEST PROCESSES"}),l.jsx("text",{x:240,y:160,className:"ga-s ga-mono",children:"node · claude"}),l.jsx("text",{x:412,y:160,className:"ga-s ga-mono",textAnchor:"end",children:"38%"}),l.jsx("text",{x:240,y:176,className:"ga-s ga-mono",children:"esbuild"}),l.jsx("text",{x:412,y:176,className:"ga-s ga-mono",textAnchor:"end",children:"21%"})]})}function kF(){return l.jsxs(lr,{children:[l.jsx("rect",{x:14,y:40,width:188,height:120,rx:10,className:"ga-screen"}),l.jsx("text",{x:28,y:60,className:"ga-cap",children:"~/MY-PROJECT"}),l.jsx("line",{x1:14,y1:70,x2:202,y2:70,className:"ga-line"}),l.jsxs("text",{x:28,y:100,className:"ga-t ga-mono",children:[l.jsx("tspan",{className:"ga-accent",children:"$"})," claude"]}),l.jsx("rect",{x:86,y:90,width:7,height:13,className:"ga-caret ga-blink"}),l.jsx("text",{x:28,y:130,className:"ga-s ga-mono",children:"or: codex"}),l.jsx("path",{d:"M210 100H238",className:"ga-arc"}),l.jsx("path",{d:"M233 95l6 5-6 5",className:"ga-arrow"}),l.jsx("rect",{x:250,y:40,width:176,height:120,rx:10,className:"ga-canvas"}),l.jsx("g",{className:"ga-pop",children:l.jsx(Ai,{x:278,y:80,w:120,title:"my-project",sub:"Opus 5 · live",tone:"accent"})})]})}function _F(){return l.jsxs(lr,{children:[l.jsx(ir,{x:14,y:16,w:232,h:170}),l.jsx("text",{x:28,y:40,className:"ga-t ga-strong",children:"Claude accounts"}),l.jsx(g_,{x:196,y:33,d:"M7 2.2v9.6M2.2 7h9.6"}),l.jsx(g_,{x:220,y:33,d:"M3.3 10.7L10.7 3.3M5.2 3.3h5.5v5.5"}),l.jsx("line",{x1:14,y1:52,x2:246,y2:52,className:"ga-line"}),l.jsx(Rr,{x:28,y:74,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),l.jsx("rect",{x:190,y:62,width:44,height:18,rx:9,className:"ga-accent"}),l.jsx("text",{x:212,y:74,className:"ga-s ga-on-accent",textAnchor:"middle",children:"active"}),l.jsx("line",{x1:14,y1:140,x2:246,y2:140,className:"ga-line"}),l.jsx(Rr,{x:28,y:160,email:"personal@me.dev",state:"signed in",tone:"ok"}),l.jsx("rect",{x:188,y:148,width:46,height:18,rx:9,className:"ga-chip"}),l.jsx("text",{x:211,y:160,className:"ga-s",textAnchor:"middle",children:"switch"}),l.jsx(Jx,{x:221,y:161}),l.jsx("path",{d:"M250 40C270 40 262 78 282 78",className:"ga-arc"}),l.jsx("path",{d:"M277 74l5 4-5 4",className:"ga-arrow"}),l.jsx(ir,{x:282,y:62,w:144,h:64,label:"ANOTHER MACHINE"}),l.jsx("g",{className:"ga-pop",children:l.jsx(Rr,{x:296,y:92,email:"work@team.dev",state:"shared here",tone:"ok"})})]})}function NF(){return l.jsxs(lr,{children:[l.jsx(ir,{x:14,label:"THIS MACHINE"}),l.jsx(Dd,{x:28,y:60}),l.jsx("g",{className:"ga-swap-out",children:l.jsx(Rr,{x:28,y:98,email:"work@team.dev",state:"login expired",tone:"warn"})}),l.jsx("g",{className:"ga-swap-in",children:l.jsx(Rr,{x:28,y:98,email:"work@team.dev",state:"working again",tone:"ok",bars:[24,61]})}),l.jsx(ir,{x:250,label:"ANOTHER MACHINE"}),l.jsx(Dd,{x:264,y:60}),l.jsx(Rr,{x:264,y:98,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),l.jsx("path",{d:"M246 120C234 80 206 80 194 120",className:"ga-arc"}),l.jsx("g",{className:"ga-travel ga-travel-low",transform:"translate(220 90)",children:l.jsx(e0,{})})]})}const SF=[{art:l.jsx(yF,{}),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:l.jsx(wF,{}),line:"Every agent and subagent is a node. Tool calls light up as they run."},{art:l.jsx(xF,{}),line:"Click any node: its prompt, every tool call, tokens and timing."},{art:l.jsx(vF,{}),line:"What each session costs, and how much quota is left."},{art:l.jsx(bF,{}),line:"Cores, memory and heat while the agents run, and what is hogging them."},{art:l.jsx(_F,{}),line:"Several Claude accounts: switch, add one, share one to another machine."},{art:l.jsx(NF,{}),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:l.jsx(kF,{}),line:"Run claude or codex in any folder. It shows up here on its own."}];function jF(){return l.jsxs(lr,{children:[l.jsx(ir,{x:14,label:"THIS MACHINE"}),l.jsx(Rr,{x:28,y:64,email:"work@team.dev",state:"login expired",tone:"warn"}),l.jsx("rect",{x:40,y:94,width:86,height:20,rx:10,className:"ga-pill-warn"}),l.jsx("text",{x:83,y:108,className:"ga-s ga-warn",textAnchor:"middle",children:"sign in again"}),l.jsx("line",{x1:198,y1:100,x2:242,y2:100,className:"ga-off"}),l.jsx(ir,{x:250,label:"ANOTHER MACHINE"}),l.jsx(Rr,{x:264,y:64,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]})]})}function EF(){return l.jsxs(lr,{children:[l.jsx(ir,{x:14,label:"THIS MACHINE"}),l.jsx(Dd,{x:28,y:60}),l.jsx(sd,{x:28,y:92,name:"Ana's MacBook"}),l.jsx(sd,{x:28,y:114,name:"Dorin's PC"}),l.jsx(ir,{x:250,label:"ANOTHER MACHINE"}),l.jsx(Dd,{x:264,y:60}),l.jsx(sd,{x:264,y:92,name:"Your MacBook"}),l.jsx(sd,{x:264,y:114,name:"Dorin's PC"}),l.jsx("line",{x1:196,y1:100,x2:244,y2:100,className:"ga-arc"}),l.jsx("circle",{cx:220,cy:100,r:10,className:"ga-ring ga-ping"}),l.jsx("circle",{cx:220,cy:100,r:10,className:"ga-ring ga-ping ga-ping-2"}),l.jsx("circle",{cx:220,cy:100,r:3,className:"ga-accent"})]})}function CF(){return l.jsxs(lr,{children:[l.jsx("rect",{x:90,y:18,width:260,height:164,rx:10,className:"ga-screen"}),l.jsx("text",{x:106,y:42,className:"ga-t ga-strong",children:"This deck on the network"}),l.jsx("line",{x1:90,y1:54,x2:350,y2:54,className:"ga-line"}),l.jsx("text",{x:106,y:76,className:"ga-cap",children:"SHARE THESE ACCOUNTS"}),l.jsx(m_,{x:106,y:88,on:!0}),l.jsx("text",{x:126,y:98,className:"ga-t ga-mono",children:"work@team.dev"}),l.jsx(m_,{x:106,y:112}),l.jsx("text",{x:126,y:122,className:"ga-s ga-mono",children:"personal@me.dev"}),l.jsx("text",{x:106,y:150,className:"ga-cap",children:"PAIRING"}),l.jsx("text",{x:106,y:168,className:"ga-s",children:"Say yes to every deck that asks"}),l.jsx(PA,{x:304,y:157,on:!0}),l.jsx(Jx,{x:115,y:97})]})}function TF(){return l.jsxs(lr,{children:[l.jsx(ir,{x:14,label:"THIS MACHINE"}),l.jsx("g",{className:"ga-swap-out",children:l.jsx(Rr,{x:28,y:64,email:"work@team.dev",state:"login expired",tone:"warn"})}),l.jsx("g",{className:"ga-swap-in",children:l.jsx(Rr,{x:28,y:64,email:"work@team.dev",state:"working again",tone:"ok",bars:[24,61]})}),l.jsx(ir,{x:250,label:"ANOTHER MACHINE"}),l.jsx(Rr,{x:264,y:64,email:"work@team.dev",state:"working",tone:"ok",bars:[24,61]}),l.jsx("path",{d:"M246 96C234 56 206 56 194 96",className:"ga-arc"}),l.jsx("g",{className:"ga-travel",transform:"translate(220 66)",children:l.jsx(e0,{})})]})}const AF=[{art:l.jsx(jF,{}),line:"A login can expire on one machine while it still works on another."},{art:l.jsx(EF,{}),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:l.jsx(CF,{}),line:"Tick which logins this machine may hand out. Nothing is shared until you do."},{art:l.jsx(TF,{}),line:"An expired login is copied from a paired machine within a minute."}];function RF(){return l.jsxs("svg",{className:"guide-art",viewBox:"0 0 232 60","aria-hidden":!0,focusable:"false",children:[l.jsx("rect",{x:1,y:14,width:78,height:42,rx:7,className:"ga-screen"}),l.jsx("circle",{cx:13,cy:29,r:3,className:"ga-warn"}),l.jsx("rect",{x:21,y:27,width:46,height:4,rx:2,className:"ga-track"}),l.jsx("rect",{x:13,y:39,width:40,height:3,rx:1.5,className:"ga-track"}),l.jsx("rect",{x:153,y:14,width:78,height:42,rx:7,className:"ga-screen"}),l.jsx("circle",{cx:165,cy:29,r:3,className:"ga-ok"}),l.jsx("rect",{x:173,y:27,width:46,height:4,rx:2,className:"ga-track"}),l.jsx("rect",{x:165,y:39,width:40,height:3,rx:1.5,className:"ga-accent"}),l.jsx("path",{d:"M150 36C138 6 94 6 82 36",className:"ga-arc"}),l.jsx("g",{transform:"translate(116 13)",children:l.jsx(e0,{})})]})}async function fp(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}const MF={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."},IF={not_running:"This deck is not on the network yet. Turn Local network on, then make one."};function w_(e,t,n){return(t==null?void 0:t.reason)&&e[t.reason]||Xt(n,t)}function $F({status:e,manual:t,onClose:n,onChanged:s}){var W,Y,O;const a=x.useRef(null),i=dn(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),[S,b]=x.useState(null),[j,E]=x.useState(()=>Date.now());x.useEffect(()=>{const F=window.setInterval(()=>E(Date.now()),1e3);return()=>window.clearInterval(F)},[]);const C=x.useRef(!0);x.useEffect(()=>()=>{C.current=!1},[]);const T=x.useRef(null),R=x.useCallback(F=>ah(T.current)?(T.current=F,_(F),!0):!1,[]),I=x.useCallback(()=>{T.current=null,C.current&&_(null)},[]),L=F=>{const oe=ua(N,F);return{disabled:oe.disabled,"aria-busy":oe.busy}},H=F=>(h==null?void 0:h.field)===F?{"aria-invalid":!0,"aria-describedby":"lan-add-failure"}:{},$=F=>m(oe=>oe&&oe.field===F?null:oe),V=x.useCallback(async()=>{const F=KF(c);if(!F){m({text:OF(c),field:"addr"});return}const oe=`${F.addr}:${F.port}`,z=e.peers.find(Z=>Z.addr===F.addr&&Z.port===F.port&&Z.paired);if(z){m({text:`Already paired with ${z.name} at that address.`,field:"addr"});return}if(t.includes(oe)){m({text:"This deck already calls that address.",field:"addr"});return}if(R("add"))try{const Z=await fp("/api/prefs",{lan:{manual:[...t,oe]}});if(!C.current)return;Z!=null&&Z.ok?(m(null),u(""),s(),n()):m({text:Xt("add that address",Z),field:"addr"})}catch{C.current&&m({text:Xt("add that address",null),field:"addr"})}finally{I()}},[c,t,e.peers,s,n,R,I]),Q=x.useCallback(async F=>{if(!R(`invite:${F}`))return;const oe=F==="make"?"make an invite":"cancel that invite";try{const z=await fp("/api/lan/invite",{action:F});if(!C.current)return;z!=null&&z.ok?(m(null),w(null),s()):m({text:w_(IF,z,oe)})}catch{C.current&&m({text:Xt(oe,null)})}finally{I()}},[s,R,I]),J=x.useCallback(async()=>{const F=f.trim();if(!(!F||!R("join"))){b(null);try{const oe=await fp("/api/lan/invite",{action:"join",token:F});if(!C.current)return;oe!=null&&oe.ok?(p(""),m(null),s(),n()):(oe==null?void 0:oe.reason)==="unreachable"&&Array.isArray(oe.tried)&&oe.tried.length?(b(oe.tried),m(null)):(b(null),m({text:w_(MF,oe,"use that invite"),field:"join"}))}catch{C.current&&m({text:Xt("use that invite",null),field:"join"})}finally{I()}}},[f,s,n,R,I]),M=x.useCallback(async(F,oe)=>{try{await navigator.clipboard.writeText(F),w(oe),window.setTimeout(()=>{C.current&&w(z=>z===oe?null:z)},1600)}catch{m({text:"Could not copy it — select the text and copy it by hand."})}},[]),X=e.invite&&e.invite.expiresAt>j?e.invite:null,G=((W=e.reach)==null?void 0:W.steps)??[],P=((Y=e.reach)==null?void 0:Y.shell)==="sh",B=e.port!=null?(e.addrs??[]).map(F=>`${F}:${e.port}`):[];return $r.createPortal(l.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:l.jsxs("div",{ref:i,className:"modal lan-add",onClick:F=>F.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-add-title",children:[l.jsxs("header",{className:"modal-head",children:[l.jsx("div",{className:"modal-title",children:l.jsx("span",{id:"lan-add-title",className:"modal-tool-name",children:"Add a deck"})}),l.jsx("div",{className:"modal-actions",children:l.jsx("button",{className:"glyph-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),l.jsxs("section",{className:"modal-body",children:[h&&l.jsxs("div",{className:"ap-failure",role:"alert",children:[l.jsx("span",{id:"lan-add-failure",className:"ap-failure-text",children:h.text}),l.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),((O=e.reach)==null?void 0:O.blocked)&&l.jsxs("div",{className:"ap-lan-reach",children:[l.jsx("p",{className:"lan-warn",children:e.reach.text}),l.jsx("p",{className:"lan-note",children:"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."}),G.length>0&&l.jsxs("details",{className:"ap-lan-reach-fix",children:[l.jsx("summary",{children:"or let them find this deck on their own"}),l.jsxs("p",{className:"lan-note",children:[P?l.jsx(l.Fragment,{children:"Run this in a terminal on this machine, then restart the deck."}):l.jsxs(l.Fragment,{children:["Run this in PowerShell ",l.jsx("strong",{children:"as Administrator"}),", then restart the deck."]}),e.reach.category==="Public"&&l.jsx(l.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.reach.unsure&&l.jsxs(l.Fragment,{children:[" ",e.reach.unsure]})]}),l.jsx("pre",{className:"ap-lan-cmd",children:l.jsx("code",{children:G.join(`
|
|
90
90
|
`)})}),l.jsx("button",{type:"button",className:"ap-manage-btn",...L("copy:fix"),onClick:()=>void M(G.join(`
|
|
91
|
-
`),"fix"),title:P?"Copy these lines, then paste them into a terminal":"Copy these lines, then paste them into an elevated PowerShell",children:y==="fix"?"copied":"copy command"})]})]}),l.jsxs("div",{className:"modal-section",children:[l.jsx("h3",{className:"lan-h",children:"By address"}),l.jsxs("div",{className:"ap-lan-row",children:[l.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,...H("addr"),onChange:F=>{u(F.target.value),$("addr")},onKeyDown:F=>{F.key==="Enter"&&V()}}),c.trim()!==""&&l.jsx("button",{type:"button",className:"ap-manage-btn",...L("add"),onClick:()=>void V(),title:"Add it to the decks this one calls, starting now.",children:"add"})]}),l.jsx("p",{className:"lan-note",children:"This deck calls that address until somebody there accepts."}),e.port!=null&&B.length>0&&l.jsxs("p",{className:"lan-note",children:["They type this deck’s own address into the same field on theirs:"," ",B.map((F,oe)=>l.jsxs("span",{children:[oe>0&&" or ",l.jsx("code",{className:"ap-lan-code",children:F})]},F)),l.jsx("button",{type:"button",className:"ap-lan-word lan-copy",...L("copy:mine"),onClick:()=>void M(B.join(" "),"mine"),title:"Copy this deck's address, to send to whoever is adding it",children:y==="mine"?"copied":"copy"})]})]}),l.jsxs("div",{className:"modal-section",children:[l.jsxs("h3",{className:"lan-h",children:["With an invite",!X&&l.jsx("button",{type:"button",className:"ap-lan-word lan-h-act",...L("invite:make"),onClick:()=>void Q("make"),title:"One piece of text you send them. They paste it, and the two decks pair — nobody has to press anything here.",children:N==="invite:make"?"making…":"make one to send"})]}),l.jsxs("div",{className:"ap-lan-row",children:[l.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,...H("join"),onChange:F=>{p(F.target.value),b(null),$("join")},onKeyDown:F=>{F.key==="Enter"&&J()}}),f.trim()!==""&&l.jsx("button",{type:"button",className:"ap-manage-btn",...L("join"),onClick:()=>void J(),title:"Reach that deck and pair with it. Nobody has to press anything there.",children:N==="join"?"joining…":"join"})]}),l.jsx("p",{className:"lan-note",children:"Pasting one pairs both decks on the spot — nobody has to accept."}),S&&l.jsxs("div",{className:"ap-lan-tried",children:[l.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."}),S.map(F=>l.jsxs("span",{className:"ap-lan-tried-row",children:[l.jsx("code",{className:"ap-lan-code",children:F.addr}),l.jsx("span",{className:"ap-lan-bad",children:F.why})]},F.addr))]}),X&&l.jsxs("div",{className:"ap-lan-invite",children:[l.jsxs("div",{className:"ap-lan-invite-head",children:[l.jsx("span",{className:"ap-lan-invite-title",children:"Send this to them"}),l.jsxs("span",{className:"ap-lan-invite-left",children:[ZF(X.expiresAt,j)," left"]})]}),l.jsx("code",{className:"ap-lan-token",children:X.token}),l.jsxs("div",{className:"ap-lan-acts",children:[l.jsx("button",{type:"button",className:"ap-manage-btn",...L("copy:invite"),onClick:()=>void M(X.token,"invite"),title:"Copy it, and send it however you already talk to them",children:y==="invite"?"copied":"copy"}),l.jsx("button",{type:"button",className:"ap-manage-btn",...L("invite:withdraw"),onClick:()=>void Q("withdraw"),title:"Cancel it. Anybody already holding the text can no longer use it.",children:"cancel"})]}),l.jsx("p",{className:"lan-warn",children:"Anyone who gets this text can pair with this deck until it runs out."})]})]})]})]})}),document.body)}function OF(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 PF=1e3;function LF(e,t){const n=new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),s=Kr(e,t);return`${n} · ${s==="now"?"just now":s}`}function v_(e){return e&&[e.version,e.os,e.arch].filter(Boolean).join(" · ")||null}function DF(){return l.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:[l.jsx("path",{d:"M9.6 2.4l2 2L5 11l-2.6.6L3 9z"}),l.jsx("path",{d:"M8.4 3.6l2 2"})]})}function x_(){return l.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:[l.jsx("rect",{x:"2.5",y:"3",width:"11",height:"7.5",rx:"1.2"}),l.jsx("path",{d:"M1 13h14"})]})}function ad({dir:e,gate:t=!1}){const n=t?12:8;return l.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:l.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 qF={works:"works here",expired:"expired here",missing:"not on this deck"},FF={works:"works there",broken:"broken there",unknown:"not offered by that deck"};function BF(e){const t=e.in&&e.out?"offered both ways":e.in?"offered by that deck":"offered by this deck";return`${qF[e.here]}, ${FF[e.there]}, ${t}${e.usedThere?", in use there":""}.`}function zF({row:e,source:t,status:n,accounts:s,now:a,busy:i,onClose:c,onRename:u,onCheck:f,onVerb:p,onSettings:h,twins:m=[],onUnpair:y}){var bt,st,mt,ze,Dt;const w=x.useRef(null),N=dn(c,{focusRef:w}),[_,S]=x.useState(null),[b,j]=x.useState(null),[E,C]=x.useState(!1),T=x.useRef(0),[R,I]=x.useState(null),[L,H]=x.useState(!1),[$,V]=x.useState(0),Q=x.useRef(null),J=x.useRef(!0);x.useEffect(()=>()=>{J.current=!1},[]);const M=_!=null;x.useEffect(()=>{var me;M&&((me=Q.current)==null||me.select())},[M]),x.useEffect(()=>{if(!E)return;const me=window.setTimeout(()=>C(!1),4e3);return()=>window.clearTimeout(me)},[E]),x.useEffect(()=>{if(!R)return;const me=window.setTimeout(()=>I(null),4e3);return()=>window.clearTimeout(me)},[R]);const X=me=>{const gt=ua(i,me);return{disabled:gt.disabled,"aria-busy":gt.busy}},G=async me=>{const gt=await me();return J.current&&j(gt),gt==null},{peer:P,stranger:B}=t,W=e.kind==="paired",Y=e.self??e.name,O=e.kind!=="dialling",F=e.kind==="dialling"?null:e.fp,oe=P?P.addr?`${P.addr}:${P.port}`:"":B?B.port?`${B.addr}:${B.port}`:B.addr:e.addr,z=(P==null?void 0:P.about)??null,Z=((bt=n.about)==null?void 0:bt.version)??null,U=async me=>{const gt=me.trim()===Y?"":me;await G(()=>u(gt))&&S(null)},re=async()=>{if(F)try{if(await navigator.clipboard.writeText(F),!J.current)return;H(!0),window.setTimeout(()=>{J.current&&H(!1)},1600)}catch{J.current&&j("Could not copy it — select the fingerprint and copy it by hand.")}},de=W?P!=null&&P.waiting?P.lastSeen!=null?"not said — it runs an older version":"not said yet — it says when it next calls":P!=null&&P.offers?"not said — it runs an older version":"not reached yet":"shown once paired",pe=v_(n.about),ge=v_(z),Te=z!=null&&z.version&&Z?i8(z.version,Z):null,Ue=P?LA(P.last,a):null,He=P&&((st=P.last)!=null&&st.error)?YF({error:P.last.error,host:P.addr,port:P.port},[...n.strangers??[],...n.pending??[],...(n.peers??[]).filter(me=>!me.manual&&me.addr).map(me=>({fp:me.fp,name:me.name,addr:me.addr,port:me.port,at:me.lastSeen??0}))],a):null,Pe=(mt=P==null?void 0:P.last)!=null&&mt.error&&Ue&&Ue.text!==P.last.error?P.last.error:null,Se=((ze=P==null?void 0:P.last)==null?void 0:ze.done)??[],nt=!!Ue&&!!Pe&&!e.quiet&&e.state.startsWith(Ue.text),je=W||e.kind==="dialling",be=P?P.waiting?null:P.manual?"added by address":"on this network":e.kind==="nearby"?"heard on this network":"asked this deck to pair",Ke=e.tone==="bad"?"bad":W?e.here?"up":"down":"loose",ct=i===`check:${e.fp}`,Ye=(P==null?void 0:P.offers)??null,ce=Ke==="up"?(Ye==null?void 0:Ye.current)??null:null,ke=ce&&"key"in ce?ce.key:null,Ee=!!ce&&"hidden"in ce,Ze=!!ce&&"other"in ce,Xe=W?c8((Ye==null?void 0:Ye.accounts)??null,s,n.shared??[],ke):[],ut=Xe.filter(me=>me.in==null&&me.out==="cut"),ee=Xe.some(me=>me.in!=null),Ne=Xe.some(me=>me.out!=null),Be=new Map(Se.map(me=>[me.email,me])),et=Se.filter(me=>!Xe.some(gt=>gt.email===me.email)),pt=W?Ye?Ye.accounts.length===0?"That deck offers nothing. Nobody there has chosen a login to share.":null:P!=null&&P.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.":(Dt=P==null?void 0:P.last)!=null&&Dt.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,tt=Ye&&(P!=null&&P.last)&&P.last.at-Ye.at>PF?Kr(Ye.at,a):null,rt=[];W&&(P!=null&&P.pairedAt)?rt.push({label:"Paired",value:LF(P.pairedAt,a),tone:"meta"}):e.kind==="declined"&&B&&rt.push({label:"Paired",value:`no · you said no ${n0(B.at,a)}`,tone:"meta"}),rt.push({label:"Fingerprint",value:F?l.jsxs("span",{className:"lan-fp",children:[l.jsx("code",{className:"ap-lan-code",children:F}),l.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void re(),"aria-label":L?"Fingerprint copied":"Copy the fingerprint",children:L?"copied":"copy"})]}):"not known — nothing has answered there",tone:F?void 0:"quiet"});const lt=m.length?[{row:e,peer:P??null},...m]:[];return $r.createPortal(l.jsx("div",{className:"modal-backdrop",onClick:c,role:"presentation",children:l.jsxs("div",{ref:N,className:"modal lan-peer","data-tone":e.tone,onClick:me=>me.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-peer-title","aria-describedby":"lan-peer-sub",children:[l.jsxs("header",{className:"modal-head lan-peer-head",children:[l.jsx("i",{className:e.here?"ap-pulse":"ap-dot","aria-hidden":!0}),l.jsxs("div",{className:"lan-peer-id",children:[M?l.jsxs("form",{className:"lan-peer-edit",onSubmit:me=>{me.preventDefault(),U(_??"")},children:[l.jsx("span",{id:"lan-peer-title",className:"vis-hidden",children:e.name}),l.jsx("input",{ref:Q,className:"ap-manage-input lan-peer-input",value:_??"",maxLength:48,placeholder:Y,"aria-label":"Name for this deck, shown on this deck only",onChange:me=>S(me.target.value)}),l.jsx("button",{type:"submit",className:"ap-manage-btn",...X(`alias:${e.fp}`),children:"save"}),l.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>S(null),children:"cancel"})]}):l.jsxs("span",{className:"lan-peer-title",children:[l.jsx("span",{id:"lan-peer-title",className:"lan-peer-name",children:e.name}),O&&l.jsx("button",{type:"button",className:"glyph-btn lan-peer-rename",onClick:()=>{j(null),S(e.name)},"aria-label":`Rename ${e.name} on this deck`,title:"Give it a name of your own. Only this deck sees it.",children:l.jsx(DF,{})})]}),l.jsxs("p",{id:"lan-peer-sub",className:"lan-peer-sub",children:[e.self&&l.jsxs(l.Fragment,{children:["calls itself ",l.jsx("span",{className:"lan-peer-self",children:e.self}),M&&l.jsx("button",{type:"button",className:"ap-lan-word lan-peer-restore",...X(`alias:${e.fp}`),onClick:()=>void U(""),children:"use this name"}),l.jsx("span",{className:"vis-hidden",children:". "}),!e.quiet&&l.jsx("span",{"aria-hidden":!0,children:" · "})]}),l.jsx("span",{className:e.quiet?"vis-hidden":"lan-peer-state",children:e.state})]})]}),l.jsx("div",{className:"modal-actions",children:l.jsx("button",{ref:w,type:"button",className:"glyph-btn",onClick:c,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),l.jsxs("section",{className:"modal-body lan-peer-body",children:[b&&l.jsxs("div",{className:"ap-failure",role:"alert",children:[l.jsx("span",{className:"ap-failure-text",children:b}),l.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>j(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),l.jsxs("div",{className:"lan-map","data-link":Ke,"data-asking":ct||void 0,"data-bus":Xe.length>0||void 0,children:[l.jsxs("div",{className:"lan-ends",children:[l.jsxs("p",{className:"lan-end",children:[l.jsx("span",{className:"lan-end-name",children:"This deck"}),pe&&l.jsx("span",{className:"lan-end-runs",children:pe}),W&&n.shareActive===!1&&l.jsx("span",{className:"lan-end-note",children:"current account hidden"})]}),l.jsxs("p",{className:"lan-end","data-side":"there",children:[l.jsx("span",{className:"lan-end-name",children:e.name}),e.kind!=="dialling"&&l.jsxs("span",{className:"lan-end-runs",children:[ge??(z?"not said":de),Te?` · ${Te<0?"older":"newer"}`:null]}),Ee&&l.jsx("span",{className:"lan-end-note",children:"current account hidden"}),Ze&&l.jsx("span",{className:"lan-end-note",children:"on another account"})]})]}),l.jsxs("div",{className:"lan-link",children:[l.jsx(x_,{}),l.jsxs("span",{className:"lan-span",children:[l.jsxs("span",{className:"lan-wire","aria-hidden":!0,children:[l.jsx("i",{className:"lan-glint","data-dir":"out"}),l.jsx("i",{className:"lan-glint","data-dir":"in"})]}),l.jsx("span",{className:"lan-link-label",children:oe?l.jsx("code",{className:"ap-lan-code",children:oe}):"none here — it calls this deck"})]}),l.jsx(x_,{}),(oe&&be||je)&&l.jsxs("p",{className:"lan-link-sub",children:[oe&&be,oe&&be&&je&&" · ",je&&(Ue?nt?l.jsx("code",{className:"ap-lan-code",children:Pe}):l.jsx("span",{className:"lan-round","data-tone":Ue.tone,children:Ue.text.replace(/ · now$/," · just now")}):"not asked yet"),je&&Pe&&!nt&&l.jsx("code",{className:"lan-fact-raw",children:Pe})]}),et.length>0&&l.jsx("ul",{className:"lan-done",children:et.map(me=>l.jsxs("li",{"data-ok":me.ok,children:[me.email," ",l.jsx("span",{className:"lan-done-what",children:me.ok?"arrived":"did not arrive"})]},`${me.email}:${me.action}`))}),He&&l.jsx("p",{className:"lan-note lan-link-note",children:He}),(P==null?void 0:P.waiting)&&l.jsx("p",{className:"lan-note lan-link-note",children:e.hint})]}),Xe.length>0&&l.jsx("ul",{className:"lan-lanes",role:"list","aria-label":`Logins between this deck and ${e.name}`,children:Xe.map((me,gt)=>{const kt=Be.get(me.email),jn=me.out==="live"||me.in!=null&&me.in!=="cut";return l.jsxs("li",{role:"listitem",className:"lan-lane","data-tone":me.tone,"data-draw":me.in&&me.out?"both":me.in?"in":"out","data-used-there":me.usedThere||void 0,style:{"--i":gt},children:[l.jsx("i",{className:"lan-pip","data-end":"here","data-state":me.here,"aria-hidden":!0}),l.jsxs("span",{className:"lan-track",children:[l.jsxs("span",{className:"lan-wire","data-flow":jn?"live":"cut","aria-hidden":!0,children:[(me.in==="live"||me.in==="wait")&&l.jsx("i",{className:"lan-glint","data-dir":"in","data-tone":me.in}),me.out==="live"&&l.jsx("i",{className:"lan-glint","data-dir":"out"})]}),me.in&&me.in!=="cut"&&l.jsx(ad,{dir:"in",gate:me.in==="blocked"}),me.out==="live"&&l.jsx(ad,{dir:"out"}),l.jsx("span",{className:"lan-lane-email",children:me.email})]}),l.jsx("i",{className:"lan-pip","data-end":"there","data-state":me.there,"aria-hidden":!0}),l.jsx("span",{className:"vis-hidden",children:BF(me)}),(me.caption||kt)&&l.jsxs("span",{className:"lan-lane-note",children:[me.caption,me.caption&&kt&&" · ",kt&&l.jsx("span",{className:"lan-lane-done","data-ok":kt.ok,children:kt.ok?"arrived last round":"did not arrive last round"})]})]},me.key)})},$),W&&l.jsxs(l.Fragment,{children:[ut.length>0&&l.jsxs("p",{className:"lan-spent",children:["Paired decks get nothing from ",ut.length===1?ut[0].email:"the expired ones"," until you sign in again here."]}),pt&&l.jsx("p",{className:"lan-empty",children:pt}),tt&&l.jsxs("p",{className:"lan-stale",children:["As of ",tt==="now"?"just now":tt,", when it last answered."]}),l.jsxs("div",{className:"lan-legend",children:[ee&&l.jsxs("span",{className:"lan-key",children:[l.jsx("span",{className:"lan-key-wire","data-dir":"in","aria-hidden":!0,children:l.jsx(ad,{dir:"in"})}),"from ",e.name]}),Ne?l.jsxs("span",{className:"lan-key",children:[l.jsx("span",{className:"lan-key-wire","data-dir":"out","aria-hidden":!0,children:l.jsx(ad,{dir:"out"})}),"from this deck, to every paired deck"]}):l.jsx("span",{className:"lan-key",children:"This deck offers nothing yet."}),l.jsx("button",{type:"button",className:"ap-lan-word lan-legend-act",onClick:h,"aria-label":"Change what this deck offers",children:"change"})]})]})]}),l.jsx("dl",{className:"lan-facts",children:rt.map(me=>l.jsxs("div",{className:"lan-fact","data-tone":me.tone,children:[l.jsx("dt",{children:me.label}),l.jsx("dd",{children:me.value})]},me.label))}),lt.length>1&&l.jsxs("div",{className:"modal-section",children:[l.jsxs("h3",{className:"lan-h",children:[lt.length," decks on this machine"]}),l.jsx("ul",{className:"lan-twins",role:"list",children:lt.map((me,gt)=>{var Ft,Kn,te,Ae;const kt=(Ft=me.peer)!=null&&Ft.addr?`${me.peer.addr}:${me.peer.port}`:me.row.addr,jn=kt||me.row.fp,En=(Kn=me.peer)!=null&&Kn.pairedAt?Kr(me.peer.pairedAt,a):null,Yn=[(Ae=(te=me.peer)==null?void 0:te.about)!=null&&Ae.version?`runs ${me.peer.about.version}`:null,En?`paired ${En==="now"?"just now":En}`:null,me.row.state].filter(Boolean).join(" · "),qt=me.row.fp;return l.jsxs("li",{role:"listitem",className:"lan-twin","data-tone":me.row.tone,children:[l.jsx("i",{className:me.row.here?"ap-pulse":"ap-dot","aria-hidden":!0}),kt?l.jsx("code",{className:"ap-lan-code lan-twin-at",children:kt}):l.jsx("span",{className:"lan-twin-at lan-twin-none",children:"no address here"}),l.jsx("code",{className:"ap-lan-code lan-twin-fp",children:qt}),gt>0&&y&&l.jsx("button",{type:"button",className:`ap-manage-btn danger lan-twin-do${R===qt?" armed":""}`,...X(`unpair:${qt}`),onKeyDown:Ie=>{Ie.repeat&&Ie.preventDefault()},onClick:()=>{if(R!==qt){I(qt),T.current=Date.now();return}Date.now()-T.current<qd||(I(null),G(()=>y(qt)))},"aria-label":R===qt?`Confirm unpairing ${jn}`:`Unpair ${jn}`,title:R===qt?"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:i===`unpair:${qt}`?"unpairing…":R===qt?"confirm":"unpair"}),l.jsx("span",{className:"lan-twin-meta",children:gt===0?`${Yn} · shown above`:Yn})]},qt)})})]})]}),l.jsxs("footer",{className:"lan-peer-foot",children:[e.kind==="asks"&&l.jsx("p",{className:"lan-foot-note",children:"This deck is now asking to pair. Answer it from the panel behind this."}),W&&!(P!=null&&P.waiting)&&l.jsx("button",{type:"button",className:"btn",...X(`check:${e.fp}`),onClick:()=>void G(f).then(me=>{me&&J.current&&V(gt=>gt+1)}),title:"Ask this deck now instead of waiting for the next round",children:i===`check:${e.fp}`?"Checking…":"Check now"}),e.kind==="paired"&&l.jsx("button",{type:"button",className:`btn danger lan-peer-verb${E?" armed":""}`,...X(`unpair:${e.fp}`),onKeyDown:me=>{me.repeat&&me.preventDefault()},onClick:()=>{if(!E){C(!0),T.current=Date.now();return}Date.now()-T.current<qd||(C(!1),G(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:i===`unpair:${e.fp}`?"Unpairing…":E?"Confirm unpair":"Unpair"}),e.kind==="nearby"&&l.jsx("button",{type:"button",className:"btn primary lan-peer-verb",...X(`accept:${e.fp}`),onClick:()=>void G(p),title:"Send it a request. Somebody at that machine has to accept it before anything is shared.",children:i===`accept:${e.fp}`?"Asking…":"Ask to pair"}),e.kind==="dialling"&&l.jsx("button",{type:"button",className:"btn lan-peer-verb",...X(`drop:${e.fp}`),onClick:()=>void G(p),title:"Stop trying this address. Nothing was ever paired here.",children:i===`drop:${e.fp}`?"Stopping…":"Stop dialling"}),e.kind==="declined"&&l.jsx("button",{type:"button",className:"btn lan-peer-verb",...X(`allow:${e.fp}`),onClick:()=>void G(p),title:"Take the no back. That deck is still trying, so its request comes round again on its own.",children:i===`allow:${e.fp}`?"Allowing…":"Let it ask again"})]})]})}),document.body)}function UF({status:e,accounts:t,onClose:n,onChanged:s}){const a=dn(n),[i,c]=x.useState(null),[u,f]=x.useState(null),[p,h]=x.useState(!1),[m,y]=x.useState(null),w=x.useRef(null),N=L=>{const H=ua(m,L);return{disabled:H.disabled,"aria-busy":H.busy}},_=x.useRef(null),S=x.useRef(!0);x.useEffect(()=>()=>{S.current=!1},[]),x.useEffect(()=>{_.current&&XF(_.current,e.shared??[])&&(_.current=null)},[e.shared]);const b=x.useCallback(async(L,H,$="write")=>{w.current=$,y($);try{const Q=await(await fetch("/api/prefs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lan:L})})).json().catch(()=>null);return S.current?(Q!=null&&Q.ok?f(null):f(Xt(H,Q)),s(),(Q==null?void 0:Q.ok)===!0):!1}catch{return S.current&&f(Xt(H,null)),!1}finally{w.current=null,S.current&&y(null)}},[s]),j=x.useCallback(async()=>{if(i!=null&&i!==(e.name??"")){if(!await b({name:i},"save the name","name"))return;S.current&&c(null)}n()},[i,e.name,b,n]),E=async()=>{if(!e.fp)return;const L=await Vx(e.fp);if(S.current){if(!L){f("Could not copy it — select the fingerprint and copy it by hand.");return}h(!0),window.setTimeout(()=>{S.current&&h(!1)},1600)}},C=new Set(_.current??e.shared??[]),T=e.autoAsk!==!1,R=e.autoAccept!==!1,I=e.shareActive!==!1;return $r.createPortal(l.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:l.jsxs("div",{ref:a,className:"modal lan-modal",onClick:L=>L.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-modal-title",children:[l.jsxs("header",{className:"modal-head",children:[l.jsx("div",{className:"modal-title",children:l.jsx("span",{id:"lan-modal-title",className:"modal-tool-name",children:"This deck on the network"})}),l.jsx("div",{className:"modal-actions",children:l.jsx("button",{className:"glyph-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),l.jsxs("section",{className:"modal-body",children:[u&&l.jsxs("div",{className:"ap-failure",role:"alert",children:[l.jsx("span",{className:"ap-failure-text",children:u}),l.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>f(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),l.jsxs("div",{className:"modal-section",children:[l.jsx("h3",{className:"lan-h",children:"Name"}),l.jsxs("div",{className:"ap-lan-row",children:[l.jsx("span",{className:"ap-lan-label",children:"appear as"}),l.jsx("input",{className:"ap-manage-input ap-lan-input","aria-label":"This deck's name on the network",value:i??e.name??"",placeholder:"this machine",onChange:L=>c(L.target.value),onKeyDown:L=>{L.key!=="Enter"||i==null||(b({name:i},"save the name","name"),c(null))}}),i!=null&&i!==(e.name??"")&&l.jsx("button",{type:"button",className:"ap-manage-btn",...N("name"),onClick:()=>{b({name:i},"save the name","name"),c(null)},title:"Save it. This is the name other decks show for this one.",children:"save"})]}),l.jsxs("div",{className:"ap-lan-row",children:[l.jsx("span",{className:"ap-lan-label",children:"fingerprint"}),e.fp?l.jsxs("span",{className:"lan-fp",children:[l.jsx("code",{className:"ap-lan-code",children:e.fp}),l.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"})]}):l.jsx("span",{className:"ap-lan-label",children:"not known yet"})]})]}),l.jsxs("div",{className:"modal-section",children:[l.jsx("h3",{className:"lan-h",children:"Share these accounts"}),l.jsxs("div",{className:"ap-lan-picks",children:[t.length===0&&l.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(L=>l.jsxs("label",{className:"ap-lan-pick",title:L.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:[l.jsx("input",{type:"checkbox",checked:C.has(L.key),onChange:H=>{const $=new Set(_.current??e.shared??[]);H.target.checked?$.add(L.key):$.delete(L.key),_.current=[...$],b({shared:[...$]},H.target.checked?"share that account":"stop sharing that account")}}),l.jsx("span",{className:"ap-lan-pick-name",children:L.email}),!L.alive&&l.jsx("span",{className:"ap-lan-dead",children:"not working here"})]},L.key))]}),t.length>0&&l.jsxs("div",{className:"lan-switch",children:[l.jsx("span",{className:"lan-switch-what",children:"Show paired decks which of these this deck is using"}),l.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":I,"aria-label":"Show paired decks which of these this deck is using",...N("current"),onClick:()=>void b({shareActive:!I},I?"stop showing which account this deck is using":"show which account this deck is using","current"),title:I?"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:l.jsx("span",{className:"switch-knob"})})]})]}),l.jsxs("div",{className:"modal-section",children:[l.jsx("h3",{className:"lan-h",children:"Pairing"}),l.jsxs("div",{className:"lan-switches",children:[l.jsxs("div",{className:"lan-switch",children:[l.jsx("span",{className:"lan-switch-what",children:"Ask every deck this one finds"}),l.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":T,"aria-label":"Ask every deck this one finds",...N("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:l.jsx("span",{className:"switch-knob"})})]}),l.jsxs("div",{className:"lan-switch",children:[l.jsx("span",{className:"lan-switch-what",children:"Say yes to every deck that asks"}),l.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",...N("accept"),onKeyDown:L=>{L.repeat&&L.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:l.jsx("span",{className:"switch-knob"})})]})]})]})]}),l.jsxs("footer",{className:"lan-setup-foot",children:[l.jsx("span",{className:"lan-foot-note",children:"Changes are saved as you make them."}),l.jsx("button",{type:"button",className:"btn primary",...N("name"),onClick:()=>void j(),children:"Done"})]})]})}),document.body)}function Kr(e,t){if(e==null)return"not seen";const n=Math.max(0,Math.round((t-e)/1e3));if(n<90)return"now";const s=Math.round(n/60);if(s<60)return`${s}m ago`;const a=Math.round(s/60);return a<48?`${a}h ago`:`${Math.round(a/24)}d ago`}const t0={"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"}},WF={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 HF(e){var s;const t=GF[e];if(t)return t;const n=(s=/\b(E[A-Z]{3,})\b/.exec(e))==null?void 0:s[1];return n&&WF[n]||e}const GF={"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 LA(e,t){if(!e)return null;if(e.error)return t0[e.error]??{text:HF(e.error),tone:"bad"};const n=e.done??[];if(!n.length)return{text:`all logins fine · ${Kr(e.at,t)}`,tone:"idle"};const s=n.filter(i=>i.ok),a=s.length===1?"login":"logins";return s.length===n.length?{text:`${s.length} ${a} arrived · ${Kr(e.at,t)}`,tone:"ok"}:{text:`${s.length} of ${n.length} logins arrived · ${Kr(e.at,t)}`,tone:"bad"}}const VF=9e4;function YF({error:e,host:t,port:n},s,a,i=45317){if(e!=="handshake timed out")return null;const c=(t??"").trim();if(!c)return null;const u=s.filter(p=>p.addr===c&&p.port&&p.at>0&&a-p.at<VF);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 ${i} and TCP ${n??f[0]}.`}const fx=5e3,DA=6e4,qd=400;function KF(e){const t=(e??"").trim(),n=t.lastIndexOf(":");if(n<=0||n===t.length-1)return null;const s=t.slice(0,n).trim(),a=Number(t.slice(n+1).trim());return!s||!Number.isInteger(a)||a<1||a>65535||s.includes(":")&&!(s.startsWith("[")&&s.endsWith("]"))?null:{addr:s,port:a}}function Xt(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 XF(e,t){if(e.length!==t.length)return!1;const n=new Set(e);return t.every(s=>n.has(s))}function ZF(e,t){const n=Math.max(0,Math.round((e-t)/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function qA(e,t){var n,s;return(n=e.last)!=null&&n.error&&!t0[e.last.error]?!1:!!((s=e.last)!=null&&s.at&&t-e.last.at<Fd||e.lastSeen!=null&&t-e.lastSeen<Fd)}const Fd=95e3,QF=160,JF=6,e8=140;function t8(e,t){const n=[],s=[];for(const a of e??[])(qA(a,t)?n:s).push(a);return{online:n,offline:s}}function n8(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 s=(e.peers??[]).filter(w=>w.paired!==!1||w.met);if(!s.length)return{text:"no deck paired yet",tone:"idle"};const a=s.filter(w=>w.waiting),i=s.filter(w=>!w.waiting),c=a.filter(w=>{var N;return!((N=w.last)!=null&&N.error)&&w.lastSeen!=null&&t-w.lastSeen<Fd}),{online:u,offline:f}=t8(i,t),p=[...f,...a.filter(w=>!c.includes(w))],h=u.length+c.length,m=u.filter(w=>{var N;return((N=w.last)==null?void 0:N.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 r8(e,t,n){if(n)return"checking…";if(e==null)return"not checked yet";const s=Kr(e,t);return s==="now"?"checked just now":`checked ${s}`}function n0(e,t){const n=Math.max(0,Math.round((t-e)/1e3));if(n<90)return"just now";const s=Math.round(n/60);return s<60?`${s}m ago`:`${Math.round(s/60)}h ago`}function s8(e,t){if(e==null)return{text:"one-way · has not called yet",here:!1};const n=t-e<Fd;return{text:n?"online · one-way, it calls in":`one-way · last online ${Kr(e,t)}`,here:n}}function b_(e,t,n){return t?"online":e.lastSeen!=null?`last online ${Kr(e.lastSeen,n)}`:e.waiting?"has not called yet":"never reached"}function a8(e,t){var y,w,N,_,S;if(!e)return[];const n=[],s=new Set,a=(b,j)=>b.name.localeCompare(j.name,void 0,{numeric:!0}),i=e.aliases??{},c=(b,j)=>{const E=b?i[b]:void 0;return E&&E!==j?{name:E,self:j}:{name:j}};for(const b of e.pending??[]){if(!(b!=null&&b.fp)||s.has(b.fp))continue;s.add(b.fp);const j=c(b.fp,b.name||b.fp);n.push({fp:b.fp,name:j.name,...j.self?{self:j.self}:{},addr:b.addr??"",kind:"asks",state:`wants to pair · ${n0(b.at,t)}`,tone:"wait",here:!0,hint:`${j.name} at ${b.addr} is waiting for an answer.`})}const u=[],f=[];for(const b of e.peers??[]){const j=b.peerFp??b.fp;if(!j||s.has(j))continue;s.add(j);const E=LA(b.last,t),C=qA(b,t),T=b.addr?`${b.addr}:${b.port}`:"";if(!b.paired&&b.manual&&!b.met){f.push({fp:T,name:T||b.name||j,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.`});continue}const R=b.waiting?s8(b.lastSeen,t):null,I=R?R.here:C,L=!R&&E?I?`online · ${E.text.replace(/ · .*$/,"")}`:`${E.text.replace(/ · .*$/,"")} · ${b_(b,I,t)}`:R?R.text:b_(b,I,t),H=(w=b.last)!=null&&w.error?t0[b.last.error]:null,$=!R&&I&&!((N=b.last)!=null&&N.error)&&!(((_=b.last)==null?void 0:_.done)??[]).length,V=b.manual&&!b.met?{name:T}:c(j,b.name||j);u.push({fp:j,name:V.name,...V.self?{self:V.self}:{},addr:b.addr??"",kind:"paired",state:L,quiet:$,tone:H?H.tone==="bad"?"bad":"wait":E?E.tone:I?"ok":"idle",here:R?R.here:C,hint:R?`${V.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 ${Kr(b.lastSeen,t)}.`} Add its address with the + at the top of this section to reach it either way.`:`${V.name}${T?` at ${T}`:""}${(S=b.last)!=null&&S.error?` — ${b.last.error}`:""}`})}n.push(...o8(u).sort(a),...f.sort(a));const p=[];for(const b of e.strangers??[]){if(!(b!=null&&b.fp)||s.has(b.fp))continue;s.add(b.fp);const j=c(b.fp,b.name||b.fp);p.push({fp:b.fp,name:j.name,...j.self?{self:j.self}:{},addr:b.addr??"",kind:"nearby",state:"not paired yet",tone:"idle",here:!0,hint:`${j.name} at ${b.addr} is on this network and nothing is shared with it.`})}n.push(...p.sort(a));const h=[];for(const b of e.declined??[]){if(!(b!=null&&b.fp)||s.has(b.fp))continue;s.add(b.fp);const j=c(b.fp,b.name||b.fp);h.push({fp:b.fp,name:j.name,...j.self?{self:j.self}:{},addr:b.addr??"",kind:"declined",state:"you said no",tone:"idle",here:!1,hint:`${j.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 o8(e){const t=new Map;for(const s of e){const a=t.get(s.name);a?a.push(s):t.set(s.name,[s])}const n=[];for(const s of t.values()){const a=[...new Set(s.filter(i=>i.addr).map(i=>i.addr))];if(a.length>1){for(const i of a)n.push(k_(s.filter(c=>c.addr===i)));n.push(...s.filter(i=>!i.addr))}else n.push(k_(s))}return n}function k_(e){const[t,...n]=[...e].sort((s,a)=>Number(a.here)-Number(s.here)||+!!a.addr-+!!s.addr);return n.length?{...t,twins:n}:t}function __(e,t){return t?e.map(n=>t[n.fp]?{...n,name:t[n.fp]}:n):e}function N_(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 i8(e,t){const n=/^(\d+)\.(\d+)\.(\d+)/.exec(e??""),s=/^(\d+)\.(\d+)\.(\d+)/.exec(t??"");if(!n||!s)return null;for(let a=1;a<=3;a++){const i=Number(n[a])-Number(s[a]);if(i)return Math.sign(i)}return 0}function l8(e,t,n){const s=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:s,note:a,tone:a?"bad":"idle"}}return t?t.alive?{there:"works there",here:s,note:null,tone:"ok"}:n?{there:"works there",here:s,note:"repairs next round",tone:"wait"}:{there:"works there",here:s,note:"share it to repair",tone:"bad"}:{there:"works there",here:s,note:"arrives next round",tone:"wait"}}function c8(e,t,n,s=null){const a=new Map(t.map(f=>[f.key,f])),i=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=i.has(f.key),m=l8(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:s===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 Si(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}function u8({anchorId:e,id:t,rows:n,onHold:s,onLet:a}){const i=x.useRef(null),c=n.filter(y=>y.kind==="paired"),u=c.filter(y=>y.here),f=u.slice(0,JF),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=i.current,w=document.getElementById(e);if(!y||!w)return;const N=Qq(w.getBoundingClientRect(),{width:y.offsetWidth,height:y.offsetHeight},{width:window.innerWidth,height:window.innerHeight});y.style.top=`${N.top}px`,y.style.left=`${N.left}px`,y.style.maxHeight=N.maxHeight==null?"":`${N.maxHeight}px`,y.dataset.side=N.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]),$r.createPortal(l.jsxs("div",{ref:i,id:t,className:"ap-peek",role:"tooltip",onPointerEnter:s,onPointerLeave:a,children:[l.jsx("p",{className:"ap-peek-title",children:u.length?"On the network now":"Nobody on the network"}),f.length>0&&l.jsx("div",{className:"ap-peek-list",children:f.map(y=>l.jsxs("span",{className:"ap-peek-who",children:[l.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),l.jsx("span",{children:y.name})]},`${y.kind}:${y.fp}`))}),h&&l.jsx("p",{className:"ap-peek-rest",children:h})]}),document.body)}function d8(e,t){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(i=>i.kind==="asks").length;if(n)return{text:n===1?"1 deck wants to pair":`${n} decks want to pair`,tone:"wait",live:!1};const s=t.filter(i=>i.kind==="paired");if(!s.length)return{text:"On · none paired yet",tone:"idle",live:!1};const a=s.filter(i=>i.here).length;return a?a===s.length?{text:`${a} online`,tone:"ok",live:!0}:{text:`${a} of ${s.length} online`,tone:"ok",live:!0}:{text:`none of ${s.length} online`,tone:"idle",live:!1}}function h8({accounts:e,onChanged:t,view:n,onOpen:s,onBack:a,closeButton:i}){const[c,u]=x.useState(null),[f,p]=x.useState([]),[h,m]=x.useState(null),[y,w]=x.useState(!1),[N,_]=x.useState(null),S=x.useRef(0),[b,j]=x.useState(!1),[E,C]=x.useState(!1),[T,R]=x.useState(!1),I=x.useRef(0);x.useEffect(()=>()=>window.clearTimeout(I.current),[]);const[L,H]=x.useState(!1),[$,V]=x.useState(null),Q=x.useRef(null),J=x.useCallback(ce=>ah(Q.current)?(Q.current=ce,m(ce),!0):!1,[]),M=x.useCallback(()=>{Q.current=null,B.current&&m(null)},[]),X=ce=>{const ke=ua(h,ce);return{disabled:ke.disabled,"aria-busy":ke.busy}},[G,P]=x.useState(()=>Date.now()),B=x.useRef(!0),W=x.useRef(fx),Y=x.useCallback(async()=>{var ce,ke;try{const[Ee,Ze]=await Promise.all([fetch("/api/lan").then(Xe=>Xe.json()),fetch("/api/prefs").then(Xe=>Xe.json())]);if(!B.current)return;Ee!=null&&Ee.ok&&u(Ee),Ze!=null&&Ze.ok&&p(Array.isArray((ke=(ce=Ze.prefs)==null?void 0:ce.lan)==null?void 0:ke.manual)?Ze.prefs.lan.manual:[]),W.current=(Ee==null?void 0:Ee.enabled)===!0?fx:DA}catch{}},[]);x.useEffect(()=>{B.current=!0;let ce=0;const ke=async()=>{P(Date.now()),await Y(),B.current&&(ce=window.setTimeout(ke,W.current))};return ke(),()=>{B.current=!1,window.clearTimeout(ce)}},[Y]);const O=x.useCallback(async()=>{const ce=(c==null?void 0:c.enabled)===!0;if(J("switch"))try{const ke=await Si("/api/prefs",{lan:{enabled:!ce}});if(!B.current)return;ke!=null&&ke.ok?(V(null),ce||w(!0)):V(Xt(ce?"turn this off":"turn this on",ke)),await Y()}catch{B.current&&V(Xt(ce?"turn this off":"turn this on",null))}finally{M()}},[c==null?void 0:c.enabled,Y,J,M]),F=x.useCallback(async(ce,ke,Ee)=>{if(!J(`${ce}:${ke}`))return null;let Ze=null;try{const Xe=await Si("/api/lan/peer",{action:ce,fp:ke});if(!B.current)return null;Xe!=null&&Xe.ok?(u(Xe),V(null)):(Ze=Xt(Ee,Xe),V(Ze)),await Y()}catch{Ze=Xt(Ee,null),B.current&&V(Ze)}finally{M()}return Ze},[Y,J,M]),oe=x.useCallback(async ce=>{if(!J(`drop:${ce}`))return null;let ke=null;try{const Ee=await Si("/api/prefs",{lan:{manual:f.filter(Ze=>Ze!==ce)}});if(!B.current)return null;Ee!=null&&Ee.ok?(V(null),t()):(ke=Xt("stop dialling that address",Ee),V(ke)),await Y()}catch{ke=Xt("stop dialling that address",null),B.current&&V(ke)}finally{M()}return ke},[f,Y,t,J,M]),[z,Z]=x.useState(null),U=x.useCallback(async(ce,ke)=>{if(!J(`alias:${ce}`))return"Something else is still being saved. Try again in a moment.";try{const Ee=await Si("/api/lan/peer",{action:"alias",fp:ce,name:ke});return B.current?Ee!=null&&Ee.ok?(u(Ee),null):Xt("rename that deck",Ee):null}catch{return Xt("rename that deck",null)}finally{M()}},[J,M]),re=x.useCallback(async ce=>{if(!J(`check:${ce}`))return null;try{const ke=await Si("/api/lan/sync",{fp:ce});return B.current?ke!=null&&ke.ok?(u(ke),t(),null):(ke==null?void 0:ke.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.":Xt("check that deck",ke):null}catch{return Xt("check that deck",null)}finally{M()}},[J,M,t]),de=x.useCallback(async()=>{if(J("check"))try{const ce=await Si("/api/lan/sync",{});if(!B.current)return;ce!=null&&ce.ok?(u(ce),V(null)):V(Xt("check the other decks",ce)),t()}catch{B.current&&V(Xt("check the other decks",null))}finally{M()}},[J,M,t]),pe=(c==null?void 0:c.enabled)===!0,ge=a8(c,G),Te=z?ge.find(ce=>{var ke;return ce.fp===z||((ke=ce.twins)==null?void 0:ke.some(Ee=>Ee.fp===z))})??null:null;x.useEffect(()=>{z&&c&&!Te&&Z(null)},[z,c,Te]);const Ue=ge.filter(ce=>ce.kind==="asks"),He=ge.filter(ce=>ce.kind!=="asks"),Pe=He.filter(ce=>ce.here),Se=He.filter(ce=>!ce.here),nt=Se.filter(ce=>ce.tone==="bad").length,je=L||Pe.length===0,be=n8(c,G),Ke=He.filter(ce=>ce.kind==="paired").length,ct=d8(c,ge),Ye=l.jsxs(l.Fragment,{children:[b&&c&&l.jsx($F,{status:c,manual:f,onClose:()=>j(!1),onChanged:()=>{Y(),t()}}),E&&l.jsx(OA,{title:"How Local network works",steps:AF,finish:pe?void 0:{label:"Turn it on",act:()=>{C(!1),O()}},onClose:()=>C(!1)}),y&&c&&l.jsx(UF,{status:{...c,manualRows:f},accounts:e,manual:f,onClose:()=>w(!1),onChanged:()=>{Y(),t()}}),Te&&c&&l.jsx(zF,{row:Te,source:N_(c,Te),status:c,accounts:e,now:G,busy:h,onClose:()=>Z(null),onRename:ce=>U(Te.fp,ce),onCheck:()=>re(Te.fp),onVerb:()=>{switch(Te.kind){case"paired":return F("unpair",Te.fp,"unpair that deck");case"nearby":return F("accept",Te.fp,"reach that deck");case"declined":return F("allow",Te.fp,"let that deck ask again");case"dialling":return oe(Te.fp);default:return Promise.resolve(null)}},onSettings:()=>{Z(null),w(!0)},twins:(Te.twins??[]).map(ce=>({row:ce,peer:N_(c,ce).peer??null})),onUnpair:ce=>F("unpair",ce,"unpair that deck")})]});if(!n){const ce=Xe=>{window.clearTimeout(I.current),I.current=window.setTimeout(()=>R(!0),Xe)},ke=()=>{window.clearTimeout(I.current),I.current=window.setTimeout(()=>R(!1),e8)},Ee=()=>window.clearTimeout(I.current),Ze=()=>{window.clearTimeout(I.current),R(!1)};return l.jsxs("div",{className:"ap-foot",children:[l.jsxs("button",{type:"button",id:"ap-lan-entry",className:"ap-nav",onClick:()=>{Ze(),s()},"aria-describedby":T?"ap-lan-peek":void 0,onPointerEnter:Xe=>{Xe.pointerType==="mouse"&&ce(QF)},onPointerLeave:ke,onFocus:Xe=>{Xe.target.matches(":focus-visible")&&ce(0)},onBlur:ke,children:[l.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:[l.jsx("rect",{x:"1.8",y:"2.3",width:"10.4",height:"7.2",rx:"1.2"}),l.jsx("path",{d:"M5 11.9h4M7 9.5v2.4"})]}),l.jsxs("span",{className:"ap-nav-text",children:[l.jsx("span",{className:"ap-nav-name",children:"Local network"}),l.jsxs("span",{className:"ap-nav-state","data-tone":ct.tone,children:[ct.live&&l.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),ct.text]})]}),l.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:l.jsx("path",{d:"M5.6 3.4 9.2 7l-3.6 3.6"})})]}),T&&l.jsx(u8,{anchorId:"ap-lan-entry",id:"ap-lan-peek",rows:ge,onHold:Ee,onLet:ke}),l.jsx("p",{className:"vis-hidden",role:"status",children:be.tone==="ok"?"":be.text}),Ye]})}return l.jsxs("div",{className:"ap-lan-view",children:[l.jsxs("div",{className:"ap-header",children:[l.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:l.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:l.jsx("path",{d:"M8.4 3.4 4.8 7l3.6 3.6"})})}),l.jsx("h2",{id:"ap-lan-title",children:"Local network"}),l.jsxs("div",{className:"ap-header-right",children:[pe&&l.jsx("button",{type:"button",className:"glyph-btn ap-lan-plus",onClick:()=>j(!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:l.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:[l.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"}),l.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"})]})}),pe&&Ke>0&&l.jsx("button",{type:"button",className:"glyph-btn ap-lan-check",...X("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:l.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:[l.jsx("circle",{cx:"7",cy:"7",r:"1.1",fill:"currentColor",stroke:"none"}),l.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"}),l.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"})]})}),pe&&l.jsx("button",{type:"button",className:"glyph-btn ap-lan-set",...X("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:l.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:[l.jsx("path",{d:"M1.8 4.7h10.4M1.8 9.3h10.4"}),l.jsx("circle",{cx:"9.1",cy:"4.7",r:"1.6",fill:"var(--panel)"}),l.jsx("circle",{cx:"4.9",cy:"9.3",r:"1.6",fill:"var(--panel)"})]})}),i]})]}),l.jsx("div",{className:"ap-scroll",id:"ap-lan-scroll",children:l.jsxs("div",{className:"ap-lan",children:[l.jsxs("div",{className:"ap-policy",children:[l.jsx("h3",{className:"ap-auto-title",children:"Sync with paired decks"}),l.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":pe,"aria-label":"Sync with paired decks",...X("switch"),onClick:()=>void O(),title:pe?"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:l.jsx("span",{className:"switch-knob"})})]}),!pe&&l.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:[l.jsx(RF,{}),l.jsx("span",{className:"ap-lan-intro-text",children:"Paired machines repair each other's expired logins."}),l.jsx("span",{className:"ap-lan-intro-go",children:"See how it works"})]}),l.jsx("p",{className:`ap-lan-status ${be.tone}`,role:"status",children:be.tone==="ok"?"":be.text}),$&&l.jsxs("div",{className:"ap-failure",role:"alert",children:[l.jsx("span",{className:"ap-failure-text",children:$}),l.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>V(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),pe&&l.jsxs(l.Fragment,{children:[Ue.length>0&&l.jsx("div",{className:"ap-lan-asks",role:"alert",children:Ue.map(ce=>l.jsxs("div",{className:"ap-lan-ask",children:[l.jsxs("span",{className:"ap-lan-ask-what",children:[l.jsx("strong",{className:"ap-lan-peer-name",children:ce.name})," at ",l.jsx("code",{className:"ap-lan-code",children:ce.addr})," wants to pair"]}),l.jsxs("span",{className:"ap-lan-ask-fp",children:["fingerprint ",l.jsx("code",{className:"ap-lan-code",children:ce.fp})]}),l.jsxs("span",{className:"ap-lan-ask-acts",children:[l.jsx("button",{type:"button",className:"ap-manage-btn",...X(`accept:${ce.fp}`),onClick:()=>void F("accept",ce.fp,"accept that deck"),title:`Talk to this deck from now on. Its fingerprint is ${ce.fp} — check it matches the one on their screen before you accept.`,children:"accept"}),l.jsx("button",{type:"button",className:"ap-manage-btn",...X(`dismiss:${ce.fp}`),onClick:()=>void F("dismiss",ce.fp,"decline that request"),title:"Say no. Nothing is shared, and that deck is told rather than left waiting.",children:"decline"})]})]},ce.fp))}),(je?[...Pe,...Se]:Pe).length>0&&l.jsx("ul",{className:"ap-lan-here",children:(je?[...Pe,...Se]:Pe).map((ce,ke)=>l.jsxs("li",{className:"ap-lan-who","data-tone":ce.tone,children:[l.jsx("i",{className:ce.here?"ap-pulse":"ap-dot","aria-hidden":!0}),l.jsx("span",{className:"ap-lan-who-name","aria-hidden":!0,children:ce.name}),l.jsx("button",{type:"button",className:"ap-lan-who-open","aria-haspopup":"dialog","aria-describedby":`lan-who-state-${ke}`,onClick:()=>Z(ce.fp),children:l.jsxs("span",{className:"vis-hidden",children:[ce.name,", details"]})}),l.jsx("span",{id:`lan-who-state-${ke}`,className:ce.quiet?"vis-hidden":"ap-lan-who-when",children:ce.state}),ce.kind==="nearby"&&l.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...X(`accept:${ce.fp}`),onClick:()=>void F("accept",ce.fp,"reach that deck"),"aria-label":`Ask ${ce.name} to pair`,title:`Send ${ce.name} a request. Somebody at that machine has to accept it before anything is shared. Its fingerprint is ${ce.fp}.`,children:"ask"}),ce.kind==="paired"&&l.jsx("button",{type:"button",className:`ap-manage-btn ap-lan-do danger${N===ce.fp?" armed":""}`,...X(`unpair:${ce.fp}`),onClick:()=>{if(N!==ce.fp){_(ce.fp),S.current=Date.now(),window.setTimeout(()=>_(Ee=>Ee===ce.fp?null:Ee),4e3);return}Date.now()-S.current<qd||(_(null),F("unpair",ce.fp,"unpair that deck"))},"aria-label":N===ce.fp?`Confirm unpairing ${ce.name}`:`Unpair ${ce.name}`,title:N===ce.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:N===ce.fp?"confirm":"unpair"}),ce.kind==="dialling"&&l.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...X(`drop:${ce.fp}`),onClick:()=>void oe(ce.fp),"aria-label":`Stop dialling ${ce.name}`,title:"Stop trying this address. Nothing was ever paired here.",children:"stop"}),ce.kind==="declined"&&l.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...X(`allow:${ce.fp}`),onClick:()=>void F("allow",ce.fp,"let that deck ask again"),"aria-label":`Let ${ce.name} ask again`,title:"Take the no back. That deck is still trying, so the request comes round again on its own.",children:"allow"})]},`${ce.kind}:${ce.fp}`))}),(Pe.length>0&&Se.length>0||pe&&Ke>0)&&l.jsxs("div",{className:"ap-lan-tail",children:[Pe.length>0&&Se.length>0&&l.jsxs("button",{type:"button",className:"ap-lan-word ap-lan-more","aria-expanded":L,onClick:()=>H(ce=>!ce),title:L?"Show only the decks that are on":`Show the ${Se.length} deck${Se.length===1?"":"s"} that are not responding right now`,children:[l.jsx("span",{className:`ap-lan-chev${L?" open":""}`,"aria-hidden":!0,children:"›"}),L?"fewer":`${Se.length} more`,!L&&nt>0&&l.jsxs("span",{className:"ap-lan-more-bad",children:[" · ",nt," not responding"]})]}),pe&&Ke>0&&l.jsx("span",{className:"ap-lan-checked",children:r8(c==null?void 0:c.checkedAt,G,h==="check")})]}),He.length===0&&Ue.length===0&&l.jsxs(l.Fragment,{children:[l.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."}),l.jsx("button",{type:"button",className:"ap-lan-word ap-lan-how",onClick:()=>C(!0),children:"How it works"})]})]})]})}),Ye]})}const S_=15e3,f8=8e3,p8=1800,m8=3e4,pp=[70,80,85,90,95];function mp(e,t){return dA(t-Math.floor(e/1e3))}function g8(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 ec(e){return e.charAt(0).toUpperCase()+e.slice(1)}function y8(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 s=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 ${s}m. No sign-in, no switch.`}}return{text:"numbers paused",hint:n}}function w8(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 v8(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 gp(e,t){if(e.staleCopy){const n=y8(e.repair??null,t);return{text:ec(n.text),hint:n.hint,fix:null,tone:"quiet",blocksSwitch:!1}}if(e.stopped){const n=v8(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 s=e.collector==="no_credentials"||e.collector==="relogin_required";return{text:ec(n.text),hint:n.hint,fix:n.fix?ec(n.fix):null,tone:s||e.collector==="keychain_unavailable"?"warn":"quiet",blocksSwitch:s}}if(e.error){const n=w8(e.error);return{text:ec(n.text),hint:n.hint,fix:n.fixable?"Sign in again":null,tone:n.fixable?"warn":"quiet",blocksSwitch:n.fixable}}return null}function yp(){return l.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:[l.jsx("path",{d:"M7 1.9 12.9 12H1.1Z"}),l.jsx("path",{d:"M7 5.6v2.9"}),l.jsx("path",{d:"M7 10.3v.05"})]})}function x8(e){return e>=90?"hi":e>=70?"mid":void 0}function b8(e){const t=Number(e);return[...Number.isFinite(t)&&t>0&&!pp.includes(t)?[...pp,t]:pp].sort((s,a)=>s-a)}function k8({lane:e,nowSec:t,frozen:n}){const s=Math.min(100,Math.max(0,e.pct)),a=n?"var(--muted)":s>=90?"var(--err)":s>=70?"var(--warn)":"var(--accent)",i=e.resetAt&&!n?hA(e.resetAt,t):null;return l.jsxs("div",{className:"ap-lane",children:[l.jsx("span",{className:"ap-lane-label",title:e.label,children:e.label}),l.jsx("div",{className:"ap-lane-track",children:l.jsx("div",{className:"ap-lane-fill",style:{width:`${s===0?1.5:s}%`,background:a,opacity:s===0||n?.4:1}})}),l.jsxs("span",{className:"ap-lane-pct",style:{color:a},children:[s,"%"]}),l.jsx("span",{className:"ap-lane-reset",title:i?`${e.label} resets in ${i}`:void 0,children:i&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"vis-hidden",children:"resets in "}),i]})})]})}async function j_(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(s=>window.setTimeout(()=>s(!1),500))])}catch{t=!1}if(t)return!0;try{const s=document.createElement("textarea");s.value=e,s.setAttribute("readonly",""),s.style.cssText="position:fixed;top:0;left:0;opacity:0",document.body.appendChild(s),s.select(),t=document.execCommand("copy"),s.remove()}catch{t=!1}return t}function _8({onClose:e,leaving:t}){var Yn,qt,Ft,Kn;const[n,s]=x.useState(null),[a,i]=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"),[S,b]=x.useState(!1),[j,E]=x.useState(null),C=x.useRef(j);C.current=j;const[T,R]=x.useState(()=>Math.floor(Date.now()/1e3)),I=x.useRef(null),[L,H]=x.useState(null),$=(L==null?void 0:L.num)??null,V=x.useRef(L);V.current=L;const[Q,J]=x.useState(null),[M,X]=x.useState(!1),[G,P]=x.useState(""),[B,W]=x.useState(null),Y=x.useRef(0),[O,F]=x.useState(null),[oe,z]=x.useState(!1),[Z,U]=x.useState(!1),[re,de]=x.useState(null),[pe,ge]=x.useState(null),[Te,Ue]=x.useState(null),[He,Pe]=x.useState(!1),Se=x.useRef(null),nt=x.useRef(null),[je,be]=x.useState([]),Ke=x.useRef(null),ct=x.useCallback(te=>ah(Ke.current)?(Ke.current=te,u(te),!0):!1,[]),Ye=x.useCallback(()=>{Ke.current=null,u(null)},[]),ce=(te,Ae=!1)=>{const Ie=ua(c,te);return{disabled:Ie.disabled,"aria-busy":Ie.busy||Ae}},ke=x.useCallback(te=>{window.requestAnimationFrame(()=>{var Ae;if(t_(((Ae=document.activeElement)==null?void 0:Ae.tagName)??null))for(const Ie of ED(te)){const Me=document.querySelector(Ie);if(Me){Me.focus();return}}})},[]),Ee=x.useCallback(async(te=!1)=>{te&&p(!0);const Ae=new AbortController,Ie=window.setTimeout(()=>Ae.abort(),m8);try{const[Me,De]=await Promise.all([fetch(`/api/claude-accounts${te?"?refresh=1":""}`,{signal:Ae.signal}),fetch("/api/cswap-auto",{signal:Ae.signal})]);if(Me.ok){const Tt=await Me.json();s(Tt),be(vt=>dF(vt,Tt.accounts))}De.ok&&i(await De.json());const dt=gF([await f_(Me),await f_(De)]);m(Tt=>p_(Tt,dt))}catch{m(Me=>p_(Me,Ae.signal.aborted?mF:pF))}finally{window.clearTimeout(Ie),te&&p(!1)}},[]),Ze=x.useCallback(async(te,Ae,Ie="panel")=>{if(!ct(Ae))return null;const Me=Ie==="menu"?J:m;Me(null);try{const dt=await(await fetch("/api/cswap-auto",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(te)})).json().catch(()=>null);return dt!=null&&dt.ok||Me({text:ux(dt,"command failed"),raw:gc(dt)}),dt}catch{return Me({text:"server unreachable"}),null}finally{Ye()}},[ct,Ye]),Xe=x.useCallback(async(te,Ae)=>{if(!ct(Ae))return null;m(null),J(null);try{const Me=await(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(te)})).json().catch(()=>null);return Me!=null&&Me.ok||J({text:Ti(Me,"command failed")}),Me}catch{return J({text:"server unreachable"}),null}finally{Ye()}},[ct,Ye]);x.useEffect(()=>(Ee(!0),I.current=window.setInterval(()=>Ee(!1),S_),()=>{I.current!=null&&window.clearInterval(I.current)}),[Ee]),x.useEffect(()=>{const te=window.setInterval(()=>R(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(te)},[]);const ut=((Yn=a==null?void 0:a.settings["autoswitch.threshold"])==null?void 0:Yn.value)??"90",ee=Te??ut,Ne=iF(ee,ut),Be=(qt=n==null?void 0:n.accounts)==null?void 0:qt.find(te=>te.active),et=Be?gp(Be,T):null,pt=async(te,Ae)=>{if(ct(`switch-${te}`)){m(null),w(null);try{const Me=await(await fetch("/api/claude-accounts/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({account:te})})).json().catch(()=>null);Me!=null&&Me.ok?w({num:te,name:Ae}):m({text:ux(Me,"the switch failed"),raw:gc(Me),row:te}),await Ee(!0)}catch{m({text:"server unreachable",row:te})}finally{Ye(),ke(te)}}},tt=x.useCallback(()=>{H(null),J(null),W(null),F(null),U(!1)},[]),rt=(te,Ae="first")=>{tt(),E(null),ge(null),H({num:te,view:"menu",start:Ae})},lt=(te,Ae)=>{tt(),E(Ie=>(Ie==null?void 0:Ie.anchor)===Ae?null:{num:te,anchor:Ae})},bt=x.useCallback((te=!1)=>{var Ie;const Ae=C.current;te&&Ae&&((Ie=document.getElementById(Ae.anchor))==null||Ie.focus()),E(null)},[]),st=()=>{tt(),E(null),_("lan")},mt=x.useRef(N);x.useEffect(()=>{mt.current!==N&&(mt.current=N,window.requestAnimationFrame(()=>{var te;(te=document.getElementById(N==="lan"?"ap-lan-back":"ap-lan-entry"))==null||te.focus()}))},[N]),x.useEffect(()=>{n!=null&&n.ok&&b(!0)},[n==null?void 0:n.ok]);const ze=x.useCallback(te=>{var Me,De;const Ae=V.current;if(!Ae||te!=null&&Ae.num!==te)return;const Ie=document.getElementById(`ap-menu-${Ae.num}`);(Ie!=null&&Ie.contains(document.activeElement)||t_(((Me=document.activeElement)==null?void 0:Me.tagName)??null))&&((De=document.getElementById(`ap-more-${Ae.num}`))==null||De.focus()),tt()},[tt]);x.useEffect(()=>{t&&(tt(),E(null))},[t,tt]),x.useEffect(()=>{L&&(n!=null&&n.accounts)&&!n.accounts.some(te=>te.num===L.num)&&tt(),j&&(n!=null&&n.accounts)&&!n.accounts.some(te=>te.num===j.num)&&E(null)},[n,L,j,tt]);const Dt=async te=>{var Ie;U(!1);const Ae=await Xe({action:"share",account:te},`share-${te}`);!(Ae!=null&&Ae.ok)||((Ie=V.current)==null?void 0:Ie.num)!==te||(F({num:te,blob:Ae.blob,expiresAt:Ae.expiresAt}),H({num:te,view:"share"}))},me=async(te,Ae)=>{const{commit:Ie,alias:Me}=fF(G,Ae);if(Ie){const De=await Xe({action:"alias",account:te,alias:Me},`alias-${te}`);if(await Ee(!0),!(De!=null&&De.ok))return}ze(te)},gt=async(te,Ae)=>{var De,dt;const Ie=await Xe({action:"move",account:te,slot:Ae},`move-${te}`),Me=sF({menuFor:((De=V.current)==null?void 0:De.num)??null,shareFor:(O==null?void 0:O.num)??null},te,Ie);if(await Ee(!0),Me){((dt=V.current)==null?void 0:dt.num)===te&&tt(),W(Me.confirmRemove),Me.shareFor==null&&(F(null),U(!1)),de(Me.swapNote);const Tt=Me.swapNote;Tt&&window.setTimeout(()=>de(vt=>vt===Tt?null:vt),f8),ge(null),ke(Me.menuFor)}return Ie},kt=async(te,Ae,Ie)=>{if(!Ie.sends){ze(te);return}await gt(te,Ae)},jn=async(te,Ae)=>{if(Ae.sends){const Ie=await Ze({action:"setting",key:"autoswitch.threshold",value:te},"threshold");if(await Ee(!0),!(Ie!=null&&Ie.ok))return;Ue(null)}Pe(!0),window.setTimeout(()=>{var Ie;document.activeElement===nt.current&&((Ie=Se.current)==null||Ie.focus()),Pe(!1)},p8)},En=l.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close accounts panel",title:"Close (A)",children:l.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:l.jsx("path",{d:"M3.4 3.4l7.2 7.2M10.6 3.4l-7.2 7.2"})})});return l.jsxs("aside",{className:`accounts-panel${t?" leaving":""}`,id:"accounts-panel","aria-label":"Claude accounts",children:[N==="accounts"&&l.jsxs("div",{className:"ap-header",children:[l.jsx("h2",{children:"Claude accounts"}),l.jsxs("div",{className:"ap-header-right",children:[l.jsx("button",{type:"button",className:"glyph-btn ap-add",onClick:()=>X(!0),"aria-label":"Add an account",title:"Sign in to another Claude account, or paste one shared from another deck",children:l.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:l.jsx("path",{d:"M7 2.2v9.6M2.2 7h9.6"})})}),(((Ft=n==null?void 0:n.accounts)==null?void 0:Ft.length)??0)>0&&l.jsx("button",{type:"button",className:"glyph-btn",onClick:()=>z(!0),"aria-label":"Share accounts with another deck",title:`Copy several accounts to another ${Zt} in one paste. The text carries a live login for each one — treat it as those passwords.`,children:l.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:[l.jsx("path",{d:"M3.3 10.7L10.7 3.3"}),l.jsx("path",{d:"M5.5 3.3h5.2v5.2"})]})}),l.jsx("button",{type:"button",className:"glyph-btn ap-refresh",onClick:()=>Ee(!0),...ce("reload",f),"aria-label":"Reload accounts",title:"Reload from claude-swap",children:l.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:[l.jsx("path",{d:"M11.6 6.2A4.8 4.8 0 1 0 11 9.6"}),l.jsx("path",{d:"M11.9 2.6v3.7h-3.6"})]})}),En]})]}),N==="accounts"&&l.jsx("div",{className:"ap-scroll",id:"ap-scroll",children:n==null?h?l.jsxs("div",{className:"ap-empty",role:"alert",children:[l.jsx("span",{title:h.raw||void 0,children:h.text}),l.jsxs("span",{className:"ap-hint",children:["No accounts have arrived, so there is nothing to show yet. The panel keeps trying every ",S_/1e3," seconds."]}),l.jsx("button",{type:"button",className:"ap-fix",disabled:f,onClick:()=>Ee(!0),children:f?"trying…":"try again"})]}):l.jsx("div",{className:"ap-empty",children:"Checking…"}):n.ok?l.jsxs(l.Fragment,{children:[Be&&(et==null?void 0:et.tone)==="warn"&&l.jsxs("div",{className:"ap-notice",children:[l.jsxs("button",{type:"button",id:"ap-notice",className:"ap-issue","data-tone":"warn","aria-haspopup":"dialog","aria-expanded":(j==null?void 0:j.anchor)==="ap-notice","aria-controls":(j==null?void 0:j.anchor)==="ap-notice"?"ap-issue-pop":void 0,onClick:()=>lt(Be.num,"ap-notice"),children:[l.jsx(yp,{}),l.jsx("span",{className:"ap-issue-text",children:"Current account needs attention"})]}),et.fix&&l.jsx("button",{type:"button",className:"ap-notice-fix",onClick:()=>X(!0),title:"Open the sign-in dialog. Signing in as this account replaces its stored login in place.",children:"Sign in"})]}),l.jsx("ul",{className:"ap-list",children:(Kn=n.accounts)==null?void 0:Kn.map(te=>{const{shown:Ae,fuller:Ie}=lF(te.lanes),Me=gp(te,T),De=te.active||je.includes(Qx(te)),dt=te.alias??te.email??`account ${te.num}`,Tt=te.stale||(Me==null?void 0:Me.blocksSwitch)===!0,vt=Ie?[...Ae,Ie]:Ae,Qr=te.fetchedAt?mp(te.fetchedAt,T):null;return l.jsxs("li",{className:`ap-account${te.active?" active":""}`,"aria-current":te.active?"true":void 0,"data-open":De?"":void 0,"data-frozen":Tt?"":void 0,children:[!te.active&&l.jsx("button",{type:"button",className:"ap-row-open",id:`ap-row-${te.num}`,"aria-expanded":De,"aria-controls":De?`ap-detail-${te.num}`:void 0,"aria-describedby":!De&&!(Me!=null&&Me.blocksSwitch)?`ap-quota-${te.num}`:void 0,onClick:()=>be(_t=>uF(_t,te)),children:l.jsxs("span",{className:"vis-hidden",children:[dt,", ",De?"hide details":"details"]})}),l.jsxs("div",{className:"ap-account-head",children:[te.active?l.jsx("span",{className:"ap-live",title:`Active account · slot ${te.num}`,children:l.jsxs("span",{className:"vis-hidden",children:["Active account, slot ",te.num,":"]})}):l.jsx("span",{className:"ap-num",children:te.num}),te.alias&&l.jsx("span",{className:"ap-alias",title:te.alias,children:te.alias}),l.jsx("span",{className:"ap-email",title:te.email??void 0,children:te.email}),te.disabled&&l.jsx("span",{className:"ap-held",children:"held out"}),!te.active&&!te.disabled&&!(Me!=null&&Me.blocksSwitch)&&l.jsx("button",{type:"button",className:"ap-switch",...ce(`switch-${te.num}`),onClick:()=>pt(te.num,dt),"aria-label":`Switch to ${dt}`,title:`Switch to ${te.alias??te.email}`,children:c===`switch-${te.num}`?"…":"Switch"}),l.jsx("button",{type:"button",id:`ap-more-${te.num}`,className:"ap-more","aria-label":`More actions for ${te.email??te.alias??`account ${te.num}`}`,"aria-haspopup":"menu","aria-expanded":$===te.num,"aria-controls":$===te.num?`ap-menu-${te.num}`:void 0,title:"More actions",onClick:()=>$===te.num?ze():rt(te.num),onKeyDown:_t=>{_t.key!=="ArrowDown"&&_t.key!=="ArrowUp"||(_t.preventDefault(),rt(te.num,_t.key==="ArrowUp"?"last":"first"))},children:l.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"currentColor","aria-hidden":!0,children:[l.jsx("circle",{cx:"2.8",cy:"7",r:"1.15"}),l.jsx("circle",{cx:"7",cy:"7",r:"1.15"}),l.jsx("circle",{cx:"11.2",cy:"7",r:"1.15"})]})})]}),(h==null?void 0:h.row)===te.num&&l.jsxs("div",{className:"ap-failure ap-row-failure",role:"alert",children:[l.jsx("span",{className:"ap-failure-text",title:h.raw||void 0,children:h.text}),l.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),te.active&&(y==null?void 0:y.num)===te.num&&l.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)===te.num&&(()=>{var rn;const _t=(rn=n.accounts)==null?void 0:rn.find(Pr=>Pr.num===re.displaced),Jt=(_t==null?void 0:_t.alias)??(_t==null?void 0:_t.email)??"the account that was there";return l.jsxs("p",{className:"ap-note ap-swap-note",title:`Slot ${re.at} was taken, so the two accounts traded places: ${Jt} now holds slot ${re.displaced}.`,children:["swapped with slot ",re.displaced]})})(),Me&&l.jsxs("div",{className:"ap-issue-line",children:[l.jsxs("button",{type:"button",id:`ap-issue-${te.num}`,className:"ap-issue","data-tone":Me.tone,"aria-haspopup":"dialog","aria-expanded":(j==null?void 0:j.anchor)===`ap-issue-${te.num}`,"aria-controls":(j==null?void 0:j.anchor)===`ap-issue-${te.num}`?"ap-issue-pop":void 0,onClick:()=>lt(te.num,`ap-issue-${te.num}`),children:[Me.tone==="warn"&&l.jsx(yp,{}),l.jsx("span",{className:"ap-issue-text",children:Me.text})]}),!De&&l.jsx("span",{className:"ap-issue-age",title:"When claude-swap last read this account's usage",children:Qr??"never collected"})]}),!De&&!(Me!=null&&Me.blocksSwitch)&&l.jsxs("p",{className:"ap-quota",id:`ap-quota-${te.num}`,children:[vt.length?vt.map(_t=>l.jsxs("span",{className:"ap-q",children:[l.jsx("span",{className:"ap-q-label",children:_t.label})," ",l.jsxs("span",{className:"ap-q-pct","data-level":Tt?void 0:x8(_t.pct),children:[Math.round(_t.pct),"%"]})]},_t.id)):l.jsx("span",{className:"ap-q-label",children:"no usage recorded yet"}),te.stale&&!Me&&l.jsx("span",{className:"ap-q-age","data-never":Qr?void 0:"",title:"When claude-swap last read this account's usage",children:Qr??"never collected"})]}),De&&l.jsxs("div",{className:"ap-detail",id:`ap-detail-${te.num}`,children:[l.jsx("div",{className:"ap-lanes",children:te.lanes.length?te.lanes.map(_t=>l.jsx(k8,{lane:_t,nowSec:T,frozen:Tt},_t.id)):l.jsx("div",{className:"ap-hint",children:"No usage recorded yet."})}),l.jsx("div",{className:"ap-meta",children:te.fetchedAt?l.jsxs("span",{className:`ap-age${te.stale&&!Me?" 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 ",mp(te.fetchedAt,T),Me!=null&&Me.blocksSwitch?"":g8(te.nextAt,T)]}):l.jsx("span",{className:"ap-age ap-stale",title:"claude-swap has not read this account yet",children:"never collected"})})]})]},te.num)})}),L&&(()=>{var Me;const te=(Me=n.accounts)==null?void 0:Me.find(De=>De.num===L.num);if(!te)return null;const Ae=`ap-pop-title-${te.num}`,Ie=Q&&l.jsx("p",{className:"ap-pop-error",role:"alert",title:Q.raw||void 0,children:Q.text});return l.jsxs(d_,{anchorId:`ap-more-${te.num}`,boundaryId:"ap-scroll",id:`ap-menu-${te.num}`,className:"ap-pop",role:L.view==="menu"?"menu":"dialog",labelledBy:L.view==="menu"?`ap-more-${te.num}`:Ae,start:L.start,onClose:tt,children:[L.view==="menu"&&l.jsxs(l.Fragment,{children:[l.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{P(te.alias??""),J(null),H({num:te.num,view:"rename"})},children:"Rename"}),l.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{ge(null),J(null),H({num:te.num,view:"move"})},children:"Move to slot…"}),l.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",...ce(`share-${te.num}`),title:`Copy this account to another ${Zt}. 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:()=>Dt(te.num),children:c===`share-${te.num}`?"Sharing…":"Share"}),(((a==null?void 0:a.enabled)||(a==null?void 0:a.external))&&!te.active||te.disabled)&&l.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",...ce(`rot-${te.num}`),title:te.disabled?"Return this account to auto-rotation":"Hold this account out of auto-rotation",onClick:()=>Ze({action:"account",account:te.num,enabled:te.disabled},`rot-${te.num}`,"menu").then(De=>{Ee(!0),De!=null&&De.ok&&ze(te.num)}),children:te.disabled?"Put back in rotation":"Hold out of rotation"}),l.jsx("div",{role:"separator",className:"ap-menu-sep"}),l.jsx("button",{type:"button",role:"menuitem",className:`ap-menu-item danger${B===te.num?" armed":""}`,...ce(`rm-${te.num}`),"aria-label":B===te.num?"Confirm remove":void 0,title:B===te.num?"This deletes the stored credentials for this account":"Remove this account from claude-swap",onClick:()=>{if(B!==te.num){W(te.num),Y.current=Date.now(),window.setTimeout(()=>W(De=>De===te.num?null:De),4e3);return}Date.now()-Y.current<qd||(W(null),Xe({action:"remove",account:te.num},`rm-${te.num}`).then(De=>{var dt;Ee(!0),De!=null&&De.ok&&(((dt=V.current)==null?void 0:dt.num)===te.num&&tt(),ke(null))}))},children:c===`rm-${te.num}`?"Removing…":B===te.num?"Confirm":"Remove"}),Ie]}),L.view==="rename"&&l.jsxs("form",{className:"ap-pop-form",onSubmit:De=>{De.preventDefault(),me(te.num,te.alias)},children:[l.jsx("label",{className:"ap-pop-title",id:Ae,htmlFor:`ap-alias-${te.num}`,children:"Rename account"}),l.jsx("input",{id:`ap-alias-${te.num}`,className:"ap-manage-input",type:"text",value:G,onChange:De=>P(De.target.value),maxLength:hF,placeholder:"e.g. work",spellCheck:!1,autoComplete:"off",autoFocus:!0,onFocus:De=>De.currentTarget.select()}),Ie,l.jsxs("div",{className:"ap-pop-actions",children:[l.jsx("button",{type:"button",className:"btn",onClick:()=>ze(),children:"Cancel"}),l.jsx("button",{type:"submit",className:"btn primary",...ce(`alias-${te.num}`),title:"A short name to show instead of the email",children:c===`alias-${te.num}`?"…":"Save"})]})]}),L.view==="move"&&(()=>{const De=rF((n.accounts??[]).map(vt=>vt.num),te.num),dt=aF(De,pe,te.num),Tt=oF(De,dt,te.num);return l.jsxs("div",{className:"ap-pop-form",children:[l.jsx("label",{className:"ap-pop-title",id:Ae,htmlFor:`ap-slot-${te.num}`,children:"Move to slot"}),l.jsx("span",{className:"ap-field",children:l.jsx("select",{id:`ap-slot-${te.num}`,value:String(dt),...ce(`move-${te.num}`),onChange:vt=>ge(Number(vt.target.value)),autoFocus:!0,children:De.map(vt=>l.jsx("option",{value:vt.slot,children:vt.label},vt.slot))})}),Ie,l.jsxs("div",{className:"ap-pop-actions",children:[l.jsx("button",{type:"button",className:"btn",onClick:()=>ze(),children:"Cancel"}),l.jsx("button",{type:"button",className:"btn primary",...ce(`move-${te.num}`),title:Tt.title,onClick:()=>kt(te.num,dt,Tt),children:c===`move-${te.num}`?"…":ec(Tt.label)})]})]})})(),L.view==="share"&&(O==null?void 0:O.num)===te.num&&(()=>{const De=IA(O.expiresAt,T),dt=De.tone==="gone";return l.jsxs("div",{className:`ap-pop-form ap-share${dt?" expired":""}`,children:[l.jsx("p",{className:"ap-pop-title",id:Ae,children:"Share account"}),l.jsx("code",{className:"ap-share-blob",children:O.blob}),l.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:[l.jsx("span",{className:"ap-share-warn",children:"This is the password"})," · ",l.jsx("span",{className:`ap-share-expiry ${De.tone}`,children:De.text})]}),Ie,l.jsxs("div",{className:"ap-pop-actions",children:[l.jsx("button",{type:"button",className:"btn",onClick:()=>ze(),children:"Done"}),l.jsx("button",{type:"button",className:"btn primary",...ce(`share-${te.num}`),autoFocus:!0,onClick:async()=>{if(dt){await Dt(te.num);return}await j_(O.blob)&&(U(!0),window.setTimeout(()=>U(!1),1800))},children:dt?"Make a new share":Z?"Copied":"Copy"})]})]})})()]})})(),j&&(()=>{var Ie;const te=(Ie=n.accounts)==null?void 0:Ie.find(Me=>Me.num===j.num),Ae=te?gp(te,T):null;return!te||!Ae?null:l.jsx(d_,{anchorId:j.anchor,boundaryId:"ap-scroll",id:"ap-issue-pop",className:"ap-pop ap-issue-pop",role:"dialog",labelledBy:"ap-issue-title",onClose:()=>bt(),children:l.jsxs("div",{className:"ap-pop-form",children:[l.jsxs("p",{className:"ap-pop-title ap-issue-title",id:"ap-issue-title","data-tone":Ae.tone,children:[Ae.tone==="warn"&&l.jsx(yp,{}),Ae.text]}),l.jsx("p",{className:"ap-pop-note ap-issue-hint",children:Ae.hint}),l.jsxs("p",{className:"ap-pop-note ap-issue-when",children:[l.jsx("span",{className:"ap-issue-who",children:te.alias??te.email??`account ${te.num}`})," · ",te.fetchedAt?`last collected ${mp(te.fetchedAt,T)}`:"never collected"]}),l.jsxs("div",{className:"ap-pop-actions",children:[l.jsx("button",{type:"button",className:"btn",onClick:()=>bt(!0),children:"Done"}),Ae.fix&&l.jsx("button",{type:"button",className:"btn primary",onClick:()=>{bt(!0),X(!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:Ae.fix})]})]})})})()]}):l.jsx("div",{className:"ap-empty",children:n.reason==="no_cswap"?l.jsxs(l.Fragment,{children:[l.jsx("span",{children:"claude-swap isn't installed."}),l.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&&l.jsx("code",{className:"ap-cmd",children:n.hint}),l.jsxs("span",{className:"ap-hint",children:["Then add an account with the ",l.jsx("strong",{children:"+"})," button above."]})]}):n.reason==="no_accounts"?l.jsxs(l.Fragment,{children:[l.jsx("span",{children:"No accounts added yet."}),l.jsxs("span",{className:"ap-hint",children:["claude-swap is installed but has nothing in its store. Use the ",l.jsx("strong",{children:"+"})," above to sign one in, or to paste one shared from another deck."]})]}):l.jsxs(l.Fragment,{children:[l.jsx("span",{children:"Couldn't read the account store."}),l.jsxs("span",{className:"ap-hint",children:["claude-swap is installed, but its store could not be read",n.reason?` (${n.reason})`:"","."]})]})})}),N==="accounts"&&n!=null&&h&&h.row==null&&l.jsxs("div",{className:"ap-failure",role:"alert",children:[l.jsx("span",{className:"ap-failure-text",title:h.raw||void 0,children:h.text}),l.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),N==="accounts"&&(n==null?void 0:n.ok)&&(a==null?void 0:a.ok)&&l.jsxs("div",{className:"ap-foot",children:[l.jsxs("div",{className:"ap-policy",children:[l.jsx("h3",{className:"ap-auto-title",children:"Auto-switch"}),l.jsx("span",{className:"ap-field",title:"Switch once the active account passes this much of its limit",children:l.jsx("select",{ref:Se,"aria-label":"Switch threshold",value:ee,...ce("threshold"),onChange:te=>Ue(te.target.value),children:b8(ut).map(te=>l.jsxs("option",{value:te,children:[te,"%"]},te))})}),(Ne.sends||He)&&l.jsx("button",{ref:nt,type:"button",className:"ap-manage-btn",...ce("threshold"),title:Ne.title,onClick:()=>jn(ee,Ne),children:He&&!Ne.sends?Ne.done:Ne.label}),l.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":a.enabled,"aria-label":"Auto-switch",...ce("enable"),onClick:()=>Ze({action:"enable",enabled:!a.enabled},"enable").then(()=>Ee(!0)),title:a.enabled?"Stop switching accounts automatically":"Switch accounts automatically when the active one nears its limit",children:l.jsx("span",{className:"switch-knob"})})]}),a.external&&l.jsxs("p",{className:"ap-auto-note",children:[l.jsx("i",{className:"ap-pulse","aria-hidden":!0})," A ",l.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.":"."]})]}),l.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:y?`Now active: ${y.name}`:""}),S&&l.jsx(h8,{accounts:((n==null?void 0:n.accounts)??[]).map(te=>({key:`${String(te.email??"").trim().toLowerCase()}@@${te.orgUuid??""}`,email:te.email??"",alive:te.alive===!0})),onChanged:()=>Ee(!0),view:N==="lan",onOpen:st,onBack:()=>_("accounts"),closeButton:En}),M&&l.jsx(Xq,{onClose:()=>X(!1),onChanged:()=>Ee(!0)}),oe&&l.jsx(nF,{accounts:((n==null?void 0:n.accounts)??[]).map(te=>({num:te.num,email:te.email,alias:te.alias,org:te.org})),onClose:()=>z(!1),copyText:j_})]})}const N8=3e4;function S8({bundle:e,running:t,lastTried:n}){return!t||e===t?!1:n!==t}function j8({bundle:e,running:t,pending:n,lastTried:s}){return t?S8({bundle:e,running:t,lastTried:s})?"reload":n==null||n&&n!==t?"wait":"confirm":"wait"}function E8(e){return!e||e.state!=="failed"?null:`${typeof e.at=="number"?e.at:0}:${e.error??""}`}function C8({asked:e,reported:t}){return t?t!==e:!1}function FA(e){const t=e.thresholdMs??N8;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 T8(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 A8(e,t){return e?t==null?"auto when idle":`auto in ${T8(t)}`:"auto-restart off"}function E_(e){let t=0;for(const n of e)n.state==="active"&&t++;return t}function R8(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 M8(e){const t=FA(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 I8(e,t){return e==="confirmation"?t.confirmOpen?"clear":"ignore":t.modalOpen||t.confirmOpen?"ignore":"confirm"}function $8(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 O8(e){return e<=0?null:e===1?"the one agent":`all ${e} agents`}function P8(e,t){const n=O8(e),s=(...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:s("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:s(),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:s(),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:s("this deck's event log — the file a restarted deck replays to rebuild what you see"),stays:[],final:a,confirm:"Clear everything"};const i=t.decks-1;return{goes:s(`the event log ${i===1?"1 other running deck shares":`${i} other running decks share`} with this one — every session recorded in it, not just the ones drawn here`),stays:[i===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 L8({agentCount:e,onConfirm:t,onCancel:n}){const s=x.useRef(null),a=dn(n,{focusRef:s,layer:o5}),[i,c]=x.useState(null);x.useEffect(()=>{let m=!1;return fetch("/api/clear").then(y=>y.ok?y.json():null).then(y=>{m||c($8(y))}).catch(()=>{}),()=>{m=!0}},[]);const{goes:u,stays:f,final:p,confirm:h}=P8(e,i);return l.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:l.jsxs("div",{ref:a,className:"modal clear-confirm",onClick:m=>m.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"clear-confirm-title",children:[l.jsxs("header",{className:"modal-head",children:[l.jsxs("div",{className:"modal-title",children:[l.jsx("span",{className:"status-dot err","aria-hidden":!0}),l.jsx("span",{id:"clear-confirm-title",className:"modal-tool-name",children:"Clear the deck?"})]}),l.jsx("div",{className:"modal-actions",children:l.jsx("button",{type:"button",className:"glyph-btn",onClick:n,"aria-label":"Cancel (Esc)",title:"Cancel (Esc)",children:"×"})})]}),l.jsxs("section",{className:"modal-body",children:[l.jsxs("dl",{className:"cc-plan",children:[l.jsx("dt",{children:"Goes"}),l.jsx("dd",{children:u.map(m=>l.jsx("span",{children:m},m))}),l.jsx("dt",{children:"Stays"}),l.jsx("dd",{children:f.length>0?f.map(m=>l.jsx("span",{children:m},m)):l.jsx("span",{children:"nothing"})})]}),p&&l.jsx("p",{className:"cc-final",children:p}),l.jsxs("div",{className:"cc-actions",children:[l.jsx("button",{type:"button",ref:s,className:"btn",onClick:n,children:"Cancel"}),l.jsx("button",{type:"button",className:"btn danger",onClick:t,children:h})]})]})]})})}const D8="Press Esc first if a key does nothing.",q8=[{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:"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:"the topbar speaker opens volume and sound settings",binds:[]}]}];function F8({onClose:e,onTour:t}){const n=dn(e);return l.jsx("div",{className:"modal-backdrop",onClick:e,role:"presentation",children:l.jsxs("div",{ref:n,className:"modal key-help",onClick:s=>s.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"key-help-title",children:[l.jsxs("header",{className:"modal-head",children:[l.jsx("div",{className:"modal-title",children:l.jsx("span",{id:"key-help-title",className:"modal-tool-name",children:"Keyboard shortcuts"})}),l.jsx("div",{className:"modal-actions",children:l.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),l.jsxs("section",{className:"modal-body",children:[t&&l.jsxs("div",{className:"guide-door",children:[l.jsx("span",{children:"Eight pictures of what the deck shows."}),l.jsx("button",{type:"button",className:"btn",onClick:t,children:"Take the tour"})]}),l.jsx("div",{className:"shortcuts",children:q8.map(s=>l.jsxs(x.Fragment,{children:[l.jsx("h3",{className:"kh-group",children:s.title}),s.rows.map(a=>l.jsxs("div",{className:"sc",children:[l.jsx("kbd",{children:a.cap}),l.jsx("span",{children:a.action})]},`${s.title}:${a.cap}:${a.action}`))]},s.title))}),l.jsx("p",{className:"kh-foot",children:D8})]})]})})}const B8=["done","needs-input"],z8=[{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}]}],U8=[{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}]}],r0={done:z8,"needs-input":U8},zi="two";function px(e,t){const n=r0[e];return n.find(s=>s.id===t)??n.find(s=>s.id===zi)??n[0]}function BA(e,t){return r0[e].some(s=>s.id===t)?t:zi}px("done",zi).notes,px("needs-input",zi).notes;const C_=.04,W8=.24,xd=0,Bd=100,mx=5,yc=50;function wc(e){if(!Number.isFinite(e))return yc;const t=Math.round(e/mx)*mx;return Math.min(Bd,Math.max(xd,t))}function H8(e){if(e==null)return yc;const t=e.trim();return/^-?\d+(\.\d+)?$/.test(t)?wc(Number(t)):yc}function G8(e){const t=wc(e),n=C_+(W8-C_)*(t/Bd);return Math.round(n*1e4)/1e4}function V8(e,t){const n=t.trim,s=typeof n=="number"&&Number.isFinite(n)&&n>0&&n<=1?n:1;return Math.round(G8(e)*s*1e4)/1e4}const Y8=160,K8="agent-dag.soundLevel.done",X8="agent-dag.soundLevel.needs-input",Z8="agent-dag.soundFigure.done",Q8="agent-dag.soundFigure.needs-input",zA={done:K8,"needs-input":X8},UA={done:Z8,"needs-input":Q8},gx={done:{level:yc,figure:zi},"needs-input":{level:yc,figure:zi}};function J8(e){const t=n=>({level:H8(e(zA[n])),figure:BA(n,e(UA[n]))});return{done:t("done"),"needs-input":t("needs-input")}}const T_={Stop:"done",Notification:"needs-input"};function eB(e,t){var s;if(t)return null;const n=(s=e==null?void 0:e.payload)==null?void 0:s.hook_event_name;return typeof n!="string"?null:Object.hasOwn(T_,n)?T_[n]:null}function tB(e={enabled:()=>!0}){const t=e.ctor??(typeof window<"u"?window.AudioContext??window.webkitAudioContext??null:null);let n=null,s=!1;const a=()=>e.enabled()?s&&(n==null?void 0:n.state)==="running"?"ready":"locked":"off",i=()=>{var f;return(f=e.onState)==null?void 0:f.call(e,a())};function c(){var f;if(!(!t||s))try{n=n??new t,(f=n.resume)==null||f.call(n).then(i,()=>{}),s=!0,i()}catch{}}function u(f,p=!1){var N;if(!p&&!e.enabled()||!n||n.state!=="running")return!1;const h=(((N=e.prefs)==null?void 0:N.call(e))??gx)[f]??gx[f],m=px(f,h.figure),y=V8(h.level,m),w=n.currentTime;for(const _ of m.notes){const S=n.createOscillator(),b=n.createGain();S.type=m.type??"sine",S.frequency.value=_.hz;const j=w+_.at,E=j+_.ms/1e3;b.gain.setValueAtTime(1e-4,j),b.gain.exponentialRampToValueAtTime(y,j+.012),b.gain.exponentialRampToValueAtTime(1e-4,E),S.connect(b).connect(n.destination),S.start(j),S.stop(E+.02)}return!0}return{unlock:c,play:u,state:a,get context(){return n}}}const nB="Notify me when a session needs my attention.",rB="Held off for this run — the deck was started with alerts disabled. Your choice is saved for the next start.",A_="Get notified when you're away from this tab.";function sB(e){switch(e){case"granted":return{status:"Enabled",ask:!1,ok:!0,note:A_};case"default":return{status:null,ask:!0,ok:!1,note:A_};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."}}}const R_={done:"Turn finished","needs-input":"Claude is asking"},aB={done:"Plays when Claude or Codex finishes a turn.","needs-input":"Available in Claude Code only."};function oB({onClose:e,soundOn:t,onToggleSound:n,prefs:s,onLevel:a,onFigure:i,onPreview:c,openerRef:u,notifyOn:f,onToggleNotify:p,notifyVetoed:h,notifyPermission:m,onAskNotify:y}){const w=sB(m),N=f&&!h,_=dn(e),S=x.useRef(e);return S.current=e,x.useEffect(()=>{const b=j=>{var C,T;const E=j.target;E&&((C=_.current)!=null&&C.contains(E)||(T=u.current)!=null&&T.contains(E)||S.current())};return window.addEventListener("pointerdown",b,!0),()=>window.removeEventListener("pointerdown",b,!0)},[_,u]),l.jsxs("div",{ref:_,id:"sound-menu",className:"sound-menu",role:"dialog","aria-label":"Sound settings",children:[l.jsxs("div",{className:"sm-switches",children:[l.jsxs("label",{className:"sm-switch",children:[l.jsx("span",{className:"sm-switch-label",id:"sm-sound-label",children:"Sounds"}),l.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:l.jsx("span",{className:"switch-knob"})})]}),l.jsxs("div",{className:"sm-setting",children:[l.jsxs("label",{className:"sm-switch",children:[l.jsx("span",{className:"sm-switch-label",id:"sm-notify-label",children:"Notifications"}),l.jsx("button",{type:"button",role:"switch","aria-checked":f,"aria-labelledby":"sm-notify-label",className:"switch",onClick:p,title:"A system notification when a session blocks on you",children:l.jsx("span",{className:"switch-knob"})})]}),l.jsx("p",{className:"sm-note",children:h?rB:nB})]})]}),N&&l.jsxs("section",{className:"sm-channel","aria-labelledby":"sm-channel-name",children:[l.jsxs("div",{className:"sm-channel-head",children:[l.jsx("h3",{className:"sm-channel-name",id:"sm-channel-name",children:"Browser notifications"}),w.ask?l.jsx("button",{type:"button",className:"btn sm-channel-action",onClick:y,children:"Enable"}):l.jsxs("span",{className:"sm-channel-state","data-ok":w.ok||void 0,children:[w.ok&&l.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:l.jsx("path",{d:"M1.5 5.2 3.9 7.6 8.5 2.4"})}),w.status]})]}),l.jsx("p",{className:"sm-note",children:w.note})]}),!t&&l.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."}),l.jsx("div",{className:"sm-tones",children:B8.map(b=>{const j=s[b],E=`sm-level-${b}`,C=`sm-figure-${b}`;return l.jsxs("section",{className:"sm-tone","aria-labelledby":`sm-name-${b}`,children:[l.jsxs("div",{className:"sm-tone-head",children:[l.jsx("h3",{className:"sm-tone-name",id:`sm-name-${b}`,children:R_[b]}),l.jsxs("button",{type:"button",className:"btn sm-hear",onClick:()=>c(b),"aria-label":`Hear the ${R_[b].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:[l.jsx("svg",{width:"11",height:"11",viewBox:"0 0 12 12",fill:"currentColor","aria-hidden":!0,children:l.jsx("path",{d:"M3 1.6v8.8l7-4.4z"})}),"Hear it"]})]}),l.jsxs("div",{className:"sm-row",children:[l.jsx("label",{htmlFor:E,children:"Volume"}),l.jsx("input",{id:E,type:"range",min:xd,max:Bd,step:mx,value:j.level,onChange:T=>a(b,Number(T.target.value)),style:{"--sm-level":`${(j.level-xd)/(Bd-xd)*100}%`}}),l.jsxs("span",{className:"sm-read",children:[j.level,"%"]})]}),l.jsxs("div",{className:"sm-row",children:[l.jsx("label",{htmlFor:C,children:"Tone"}),l.jsx("select",{id:C,className:"sm-select",value:j.figure,onChange:T=>i(b,T.target.value),children:r0[b].map(T=>l.jsx("option",{value:T.id,children:T.label},T.id))})]}),l.jsx("p",{className:"sm-note",children:aB[b]})]},b)})}),l.jsxs("p",{className:"sm-foot",children:[l.jsx("kbd",{children:"M"}),"Mute or unmute sounds anywhere."]})]})}const iB=15e3;function lB(e){return e.visibilityState==="visible"&&e.hasFocus()}function cB(e,t){return t||e===!0}function uB(){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 dB={"//":["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.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.
|
|
91
|
+
`),"fix"),title:P?"Copy these lines, then paste them into a terminal":"Copy these lines, then paste them into an elevated PowerShell",children:y==="fix"?"copied":"copy command"})]})]}),l.jsxs("div",{className:"modal-section",children:[l.jsx("h3",{className:"lan-h",children:"By address"}),l.jsxs("div",{className:"ap-lan-row",children:[l.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,...H("addr"),onChange:F=>{u(F.target.value),$("addr")},onKeyDown:F=>{F.key==="Enter"&&V()}}),c.trim()!==""&&l.jsx("button",{type:"button",className:"ap-manage-btn",...L("add"),onClick:()=>void V(),title:"Add it to the decks this one calls, starting now.",children:"add"})]}),l.jsx("p",{className:"lan-note",children:"This deck calls that address until somebody there accepts."}),e.port!=null&&B.length>0&&l.jsxs("p",{className:"lan-note",children:["They type this deck’s own address into the same field on theirs:"," ",B.map((F,oe)=>l.jsxs("span",{children:[oe>0&&" or ",l.jsx("code",{className:"ap-lan-code",children:F})]},F)),l.jsx("button",{type:"button",className:"ap-lan-word lan-copy",...L("copy:mine"),onClick:()=>void M(B.join(" "),"mine"),title:"Copy this deck's address, to send to whoever is adding it",children:y==="mine"?"copied":"copy"})]})]}),l.jsxs("div",{className:"modal-section",children:[l.jsxs("h3",{className:"lan-h",children:["With an invite",!X&&l.jsx("button",{type:"button",className:"ap-lan-word lan-h-act",...L("invite:make"),onClick:()=>void Q("make"),title:"One piece of text you send them. They paste it, and the two decks pair — nobody has to press anything here.",children:N==="invite:make"?"making…":"make one to send"})]}),l.jsxs("div",{className:"ap-lan-row",children:[l.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,...H("join"),onChange:F=>{p(F.target.value),b(null),$("join")},onKeyDown:F=>{F.key==="Enter"&&J()}}),f.trim()!==""&&l.jsx("button",{type:"button",className:"ap-manage-btn",...L("join"),onClick:()=>void J(),title:"Reach that deck and pair with it. Nobody has to press anything there.",children:N==="join"?"joining…":"join"})]}),l.jsx("p",{className:"lan-note",children:"Pasting one pairs both decks on the spot — nobody has to accept."}),S&&l.jsxs("div",{className:"ap-lan-tried",children:[l.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."}),S.map(F=>l.jsxs("span",{className:"ap-lan-tried-row",children:[l.jsx("code",{className:"ap-lan-code",children:F.addr}),l.jsx("span",{className:"ap-lan-bad",children:F.why})]},F.addr))]}),X&&l.jsxs("div",{className:"ap-lan-invite",children:[l.jsxs("div",{className:"ap-lan-invite-head",children:[l.jsx("span",{className:"ap-lan-invite-title",children:"Send this to them"}),l.jsxs("span",{className:"ap-lan-invite-left",children:[ZF(X.expiresAt,j)," left"]})]}),l.jsx("code",{className:"ap-lan-token",children:X.token}),l.jsxs("div",{className:"ap-lan-acts",children:[l.jsx("button",{type:"button",className:"ap-manage-btn",...L("copy:invite"),onClick:()=>void M(X.token,"invite"),title:"Copy it, and send it however you already talk to them",children:y==="invite"?"copied":"copy"}),l.jsx("button",{type:"button",className:"ap-manage-btn",...L("invite:withdraw"),onClick:()=>void Q("withdraw"),title:"Cancel it. Anybody already holding the text can no longer use it.",children:"cancel"})]}),l.jsx("p",{className:"lan-warn",children:"Anyone who gets this text can pair with this deck until it runs out."})]})]})]})]})}),document.body)}function OF(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 PF=1e3;function LF(e,t){const n=new Date(e).toLocaleDateString("en-US",{month:"short",day:"numeric",year:"numeric"}),s=Kr(e,t);return`${n} · ${s==="now"?"just now":s}`}function v_(e){return e&&[e.version,e.os,e.arch].filter(Boolean).join(" · ")||null}function DF(){return l.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:[l.jsx("path",{d:"M9.6 2.4l2 2L5 11l-2.6.6L3 9z"}),l.jsx("path",{d:"M8.4 3.6l2 2"})]})}function x_(){return l.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:[l.jsx("rect",{x:"2.5",y:"3",width:"11",height:"7.5",rx:"1.2"}),l.jsx("path",{d:"M1 13h14"})]})}function ad({dir:e,gate:t=!1}){const n=t?12:8;return l.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:l.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 qF={works:"works here",expired:"expired here",missing:"not on this deck"},FF={works:"works there",broken:"broken there",unknown:"not offered by that deck"};function BF(e){const t=e.in&&e.out?"offered both ways":e.in?"offered by that deck":"offered by this deck";return`${qF[e.here]}, ${FF[e.there]}, ${t}${e.usedThere?", in use there":""}.`}function zF({row:e,source:t,status:n,accounts:s,now:a,busy:i,onClose:c,onRename:u,onCheck:f,onVerb:p,onSettings:h,twins:m=[],onUnpair:y}){var bt,st,mt,ze,Dt;const w=x.useRef(null),N=dn(c,{focusRef:w}),[_,S]=x.useState(null),[b,j]=x.useState(null),[E,C]=x.useState(!1),T=x.useRef(0),[R,I]=x.useState(null),[L,H]=x.useState(!1),[$,V]=x.useState(0),Q=x.useRef(null),J=x.useRef(!0);x.useEffect(()=>()=>{J.current=!1},[]);const M=_!=null;x.useEffect(()=>{var me;M&&((me=Q.current)==null||me.select())},[M]),x.useEffect(()=>{if(!E)return;const me=window.setTimeout(()=>C(!1),4e3);return()=>window.clearTimeout(me)},[E]),x.useEffect(()=>{if(!R)return;const me=window.setTimeout(()=>I(null),4e3);return()=>window.clearTimeout(me)},[R]);const X=me=>{const gt=ua(i,me);return{disabled:gt.disabled,"aria-busy":gt.busy}},G=async me=>{const gt=await me();return J.current&&j(gt),gt==null},{peer:P,stranger:B}=t,W=e.kind==="paired",Y=e.self??e.name,O=e.kind!=="dialling",F=e.kind==="dialling"?null:e.fp,oe=P?P.addr?`${P.addr}:${P.port}`:"":B?B.port?`${B.addr}:${B.port}`:B.addr:e.addr,z=(P==null?void 0:P.about)??null,Z=((bt=n.about)==null?void 0:bt.version)??null,U=async me=>{const gt=me.trim()===Y?"":me;await G(()=>u(gt))&&S(null)},re=async()=>{if(F)try{if(await navigator.clipboard.writeText(F),!J.current)return;H(!0),window.setTimeout(()=>{J.current&&H(!1)},1600)}catch{J.current&&j("Could not copy it — select the fingerprint and copy it by hand.")}},de=W?P!=null&&P.waiting?P.lastSeen!=null?"not said — it runs an older version":"not said yet — it says when it next calls":P!=null&&P.offers?"not said — it runs an older version":"not reached yet":"shown once paired",pe=v_(n.about),ge=v_(z),Te=z!=null&&z.version&&Z?i8(z.version,Z):null,Ue=P?LA(P.last,a):null,He=P&&((st=P.last)!=null&&st.error)?YF({error:P.last.error,host:P.addr,port:P.port},[...n.strangers??[],...n.pending??[],...(n.peers??[]).filter(me=>!me.manual&&me.addr).map(me=>({fp:me.fp,name:me.name,addr:me.addr,port:me.port,at:me.lastSeen??0}))],a):null,Pe=(mt=P==null?void 0:P.last)!=null&&mt.error&&Ue&&Ue.text!==P.last.error?P.last.error:null,Se=((ze=P==null?void 0:P.last)==null?void 0:ze.done)??[],nt=!!Ue&&!!Pe&&!e.quiet&&e.state.startsWith(Ue.text),je=W||e.kind==="dialling",be=P?P.waiting?null:P.manual?"added by address":"on this network":e.kind==="nearby"?"heard on this network":"asked this deck to pair",Ke=e.tone==="bad"?"bad":W?e.here?"up":"down":"loose",ct=i===`check:${e.fp}`,Ye=(P==null?void 0:P.offers)??null,ce=Ke==="up"?(Ye==null?void 0:Ye.current)??null:null,ke=ce&&"key"in ce?ce.key:null,Ee=!!ce&&"hidden"in ce,Ze=!!ce&&"other"in ce,Xe=W?c8((Ye==null?void 0:Ye.accounts)??null,s,n.shared??[],ke):[],ut=Xe.filter(me=>me.in==null&&me.out==="cut"),ee=Xe.some(me=>me.in!=null),Ne=Xe.some(me=>me.out!=null),Be=new Map(Se.map(me=>[me.email,me])),et=Se.filter(me=>!Xe.some(gt=>gt.email===me.email)),pt=W?Ye?Ye.accounts.length===0?"That deck offers nothing. Nobody there has chosen a login to share.":null:P!=null&&P.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.":(Dt=P==null?void 0:P.last)!=null&&Dt.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,tt=Ye&&(P!=null&&P.last)&&P.last.at-Ye.at>PF?Kr(Ye.at,a):null,rt=[];W&&(P!=null&&P.pairedAt)?rt.push({label:"Paired",value:LF(P.pairedAt,a),tone:"meta"}):e.kind==="declined"&&B&&rt.push({label:"Paired",value:`no · you said no ${n0(B.at,a)}`,tone:"meta"}),rt.push({label:"Fingerprint",value:F?l.jsxs("span",{className:"lan-fp",children:[l.jsx("code",{className:"ap-lan-code",children:F}),l.jsx("button",{type:"button",className:"ap-lan-word lan-copy",onClick:()=>void re(),"aria-label":L?"Fingerprint copied":"Copy the fingerprint",children:L?"copied":"copy"})]}):"not known — nothing has answered there",tone:F?void 0:"quiet"});const lt=m.length?[{row:e,peer:P??null},...m]:[];return $r.createPortal(l.jsx("div",{className:"modal-backdrop",onClick:c,role:"presentation",children:l.jsxs("div",{ref:N,className:"modal lan-peer","data-tone":e.tone,onClick:me=>me.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-peer-title","aria-describedby":"lan-peer-sub",children:[l.jsxs("header",{className:"modal-head lan-peer-head",children:[l.jsx("i",{className:e.here?"ap-pulse":"ap-dot","aria-hidden":!0}),l.jsxs("div",{className:"lan-peer-id",children:[M?l.jsxs("form",{className:"lan-peer-edit",onSubmit:me=>{me.preventDefault(),U(_??"")},children:[l.jsx("span",{id:"lan-peer-title",className:"vis-hidden",children:e.name}),l.jsx("input",{ref:Q,className:"ap-manage-input lan-peer-input",value:_??"",maxLength:48,placeholder:Y,"aria-label":"Name for this deck, shown on this deck only",onChange:me=>S(me.target.value)}),l.jsx("button",{type:"submit",className:"ap-manage-btn",...X(`alias:${e.fp}`),children:"save"}),l.jsx("button",{type:"button",className:"ap-manage-btn",onClick:()=>S(null),children:"cancel"})]}):l.jsxs("span",{className:"lan-peer-title",children:[l.jsx("span",{id:"lan-peer-title",className:"lan-peer-name",children:e.name}),O&&l.jsx("button",{type:"button",className:"glyph-btn lan-peer-rename",onClick:()=>{j(null),S(e.name)},"aria-label":`Rename ${e.name} on this deck`,title:"Give it a name of your own. Only this deck sees it.",children:l.jsx(DF,{})})]}),l.jsxs("p",{id:"lan-peer-sub",className:"lan-peer-sub",children:[e.self&&l.jsxs(l.Fragment,{children:["calls itself ",l.jsx("span",{className:"lan-peer-self",children:e.self}),M&&l.jsx("button",{type:"button",className:"ap-lan-word lan-peer-restore",...X(`alias:${e.fp}`),onClick:()=>void U(""),children:"use this name"}),l.jsx("span",{className:"vis-hidden",children:". "}),!e.quiet&&l.jsx("span",{"aria-hidden":!0,children:" · "})]}),l.jsx("span",{className:e.quiet?"vis-hidden":"lan-peer-state",children:e.state})]})]}),l.jsx("div",{className:"modal-actions",children:l.jsx("button",{ref:w,type:"button",className:"glyph-btn",onClick:c,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),l.jsxs("section",{className:"modal-body lan-peer-body",children:[b&&l.jsxs("div",{className:"ap-failure",role:"alert",children:[l.jsx("span",{className:"ap-failure-text",children:b}),l.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>j(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),l.jsxs("div",{className:"lan-map","data-link":Ke,"data-asking":ct||void 0,"data-bus":Xe.length>0||void 0,children:[l.jsxs("div",{className:"lan-ends",children:[l.jsxs("p",{className:"lan-end",children:[l.jsx("span",{className:"lan-end-name",children:"This deck"}),pe&&l.jsx("span",{className:"lan-end-runs",children:pe}),W&&n.shareActive===!1&&l.jsx("span",{className:"lan-end-note",children:"current account hidden"})]}),l.jsxs("p",{className:"lan-end","data-side":"there",children:[l.jsx("span",{className:"lan-end-name",children:e.name}),e.kind!=="dialling"&&l.jsxs("span",{className:"lan-end-runs",children:[ge??(z?"not said":de),Te?` · ${Te<0?"older":"newer"}`:null]}),Ee&&l.jsx("span",{className:"lan-end-note",children:"current account hidden"}),Ze&&l.jsx("span",{className:"lan-end-note",children:"on another account"})]})]}),l.jsxs("div",{className:"lan-link",children:[l.jsx(x_,{}),l.jsxs("span",{className:"lan-span",children:[l.jsxs("span",{className:"lan-wire","aria-hidden":!0,children:[l.jsx("i",{className:"lan-glint","data-dir":"out"}),l.jsx("i",{className:"lan-glint","data-dir":"in"})]}),l.jsx("span",{className:"lan-link-label",children:oe?l.jsx("code",{className:"ap-lan-code",children:oe}):"none here — it calls this deck"})]}),l.jsx(x_,{}),(oe&&be||je)&&l.jsxs("p",{className:"lan-link-sub",children:[oe&&be,oe&&be&&je&&" · ",je&&(Ue?nt?l.jsx("code",{className:"ap-lan-code",children:Pe}):l.jsx("span",{className:"lan-round","data-tone":Ue.tone,children:Ue.text.replace(/ · now$/," · just now")}):"not asked yet"),je&&Pe&&!nt&&l.jsx("code",{className:"lan-fact-raw",children:Pe})]}),et.length>0&&l.jsx("ul",{className:"lan-done",children:et.map(me=>l.jsxs("li",{"data-ok":me.ok,children:[me.email," ",l.jsx("span",{className:"lan-done-what",children:me.ok?"arrived":"did not arrive"})]},`${me.email}:${me.action}`))}),He&&l.jsx("p",{className:"lan-note lan-link-note",children:He}),(P==null?void 0:P.waiting)&&l.jsx("p",{className:"lan-note lan-link-note",children:e.hint})]}),Xe.length>0&&l.jsx("ul",{className:"lan-lanes",role:"list","aria-label":`Logins between this deck and ${e.name}`,children:Xe.map((me,gt)=>{const kt=Be.get(me.email),jn=me.out==="live"||me.in!=null&&me.in!=="cut";return l.jsxs("li",{role:"listitem",className:"lan-lane","data-tone":me.tone,"data-draw":me.in&&me.out?"both":me.in?"in":"out","data-used-there":me.usedThere||void 0,style:{"--i":gt},children:[l.jsx("i",{className:"lan-pip","data-end":"here","data-state":me.here,"aria-hidden":!0}),l.jsxs("span",{className:"lan-track",children:[l.jsxs("span",{className:"lan-wire","data-flow":jn?"live":"cut","aria-hidden":!0,children:[(me.in==="live"||me.in==="wait")&&l.jsx("i",{className:"lan-glint","data-dir":"in","data-tone":me.in}),me.out==="live"&&l.jsx("i",{className:"lan-glint","data-dir":"out"})]}),me.in&&me.in!=="cut"&&l.jsx(ad,{dir:"in",gate:me.in==="blocked"}),me.out==="live"&&l.jsx(ad,{dir:"out"}),l.jsx("span",{className:"lan-lane-email",children:me.email})]}),l.jsx("i",{className:"lan-pip","data-end":"there","data-state":me.there,"aria-hidden":!0}),l.jsx("span",{className:"vis-hidden",children:BF(me)}),(me.caption||kt)&&l.jsxs("span",{className:"lan-lane-note",children:[me.caption,me.caption&&kt&&" · ",kt&&l.jsx("span",{className:"lan-lane-done","data-ok":kt.ok,children:kt.ok?"arrived last round":"did not arrive last round"})]})]},me.key)})},$),W&&l.jsxs(l.Fragment,{children:[ut.length>0&&l.jsxs("p",{className:"lan-spent",children:["Paired decks get nothing from ",ut.length===1?ut[0].email:"the expired ones"," until you sign in again here."]}),pt&&l.jsx("p",{className:"lan-empty",children:pt}),tt&&l.jsxs("p",{className:"lan-stale",children:["As of ",tt==="now"?"just now":tt,", when it last answered."]}),l.jsxs("div",{className:"lan-legend",children:[ee&&l.jsxs("span",{className:"lan-key",children:[l.jsx("span",{className:"lan-key-wire","data-dir":"in","aria-hidden":!0,children:l.jsx(ad,{dir:"in"})}),"from ",e.name]}),Ne?l.jsxs("span",{className:"lan-key",children:[l.jsx("span",{className:"lan-key-wire","data-dir":"out","aria-hidden":!0,children:l.jsx(ad,{dir:"out"})}),"from this deck, to every paired deck"]}):l.jsx("span",{className:"lan-key",children:"This deck offers nothing yet."}),l.jsx("button",{type:"button",className:"ap-lan-word lan-legend-act",onClick:h,"aria-label":"Change what this deck offers",children:"change"})]})]})]}),l.jsx("dl",{className:"lan-facts",children:rt.map(me=>l.jsxs("div",{className:"lan-fact","data-tone":me.tone,children:[l.jsx("dt",{children:me.label}),l.jsx("dd",{children:me.value})]},me.label))}),lt.length>1&&l.jsxs("div",{className:"modal-section",children:[l.jsxs("h3",{className:"lan-h",children:[lt.length," decks on this machine"]}),l.jsx("ul",{className:"lan-twins",role:"list",children:lt.map((me,gt)=>{var Ft,Kn,te,Ae;const kt=(Ft=me.peer)!=null&&Ft.addr?`${me.peer.addr}:${me.peer.port}`:me.row.addr,jn=kt||me.row.fp,En=(Kn=me.peer)!=null&&Kn.pairedAt?Kr(me.peer.pairedAt,a):null,Yn=[(Ae=(te=me.peer)==null?void 0:te.about)!=null&&Ae.version?`runs ${me.peer.about.version}`:null,En?`paired ${En==="now"?"just now":En}`:null,me.row.state].filter(Boolean).join(" · "),qt=me.row.fp;return l.jsxs("li",{role:"listitem",className:"lan-twin","data-tone":me.row.tone,children:[l.jsx("i",{className:me.row.here?"ap-pulse":"ap-dot","aria-hidden":!0}),kt?l.jsx("code",{className:"ap-lan-code lan-twin-at",children:kt}):l.jsx("span",{className:"lan-twin-at lan-twin-none",children:"no address here"}),l.jsx("code",{className:"ap-lan-code lan-twin-fp",children:qt}),gt>0&&y&&l.jsx("button",{type:"button",className:`ap-manage-btn danger lan-twin-do${R===qt?" armed":""}`,...X(`unpair:${qt}`),onKeyDown:Ie=>{Ie.repeat&&Ie.preventDefault()},onClick:()=>{if(R!==qt){I(qt),T.current=Date.now();return}Date.now()-T.current<qd||(I(null),G(()=>y(qt)))},"aria-label":R===qt?`Confirm unpairing ${jn}`:`Unpair ${jn}`,title:R===qt?"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:i===`unpair:${qt}`?"unpairing…":R===qt?"confirm":"unpair"}),l.jsx("span",{className:"lan-twin-meta",children:gt===0?`${Yn} · shown above`:Yn})]},qt)})})]})]}),l.jsxs("footer",{className:"lan-peer-foot",children:[e.kind==="asks"&&l.jsx("p",{className:"lan-foot-note",children:"This deck is now asking to pair. Answer it from the panel behind this."}),W&&!(P!=null&&P.waiting)&&l.jsx("button",{type:"button",className:"btn",...X(`check:${e.fp}`),onClick:()=>void G(f).then(me=>{me&&J.current&&V(gt=>gt+1)}),title:"Ask this deck now instead of waiting for the next round",children:i===`check:${e.fp}`?"Checking…":"Check now"}),e.kind==="paired"&&l.jsx("button",{type:"button",className:`btn danger lan-peer-verb${E?" armed":""}`,...X(`unpair:${e.fp}`),onKeyDown:me=>{me.repeat&&me.preventDefault()},onClick:()=>{if(!E){C(!0),T.current=Date.now();return}Date.now()-T.current<qd||(C(!1),G(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:i===`unpair:${e.fp}`?"Unpairing…":E?"Confirm unpair":"Unpair"}),e.kind==="nearby"&&l.jsx("button",{type:"button",className:"btn primary lan-peer-verb",...X(`accept:${e.fp}`),onClick:()=>void G(p),title:"Send it a request. Somebody at that machine has to accept it before anything is shared.",children:i===`accept:${e.fp}`?"Asking…":"Ask to pair"}),e.kind==="dialling"&&l.jsx("button",{type:"button",className:"btn lan-peer-verb",...X(`drop:${e.fp}`),onClick:()=>void G(p),title:"Stop trying this address. Nothing was ever paired here.",children:i===`drop:${e.fp}`?"Stopping…":"Stop dialling"}),e.kind==="declined"&&l.jsx("button",{type:"button",className:"btn lan-peer-verb",...X(`allow:${e.fp}`),onClick:()=>void G(p),title:"Take the no back. That deck is still trying, so its request comes round again on its own.",children:i===`allow:${e.fp}`?"Allowing…":"Let it ask again"})]})]})}),document.body)}function UF({status:e,accounts:t,onClose:n,onChanged:s}){const a=dn(n),[i,c]=x.useState(null),[u,f]=x.useState(null),[p,h]=x.useState(!1),[m,y]=x.useState(null),w=x.useRef(null),N=L=>{const H=ua(m,L);return{disabled:H.disabled,"aria-busy":H.busy}},_=x.useRef(null),S=x.useRef(!0);x.useEffect(()=>()=>{S.current=!1},[]),x.useEffect(()=>{_.current&&XF(_.current,e.shared??[])&&(_.current=null)},[e.shared]);const b=x.useCallback(async(L,H,$="write")=>{w.current=$,y($);try{const Q=await(await fetch("/api/prefs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({lan:L})})).json().catch(()=>null);return S.current?(Q!=null&&Q.ok?f(null):f(Xt(H,Q)),s(),(Q==null?void 0:Q.ok)===!0):!1}catch{return S.current&&f(Xt(H,null)),!1}finally{w.current=null,S.current&&y(null)}},[s]),j=x.useCallback(async()=>{if(i!=null&&i!==(e.name??"")){if(!await b({name:i},"save the name","name"))return;S.current&&c(null)}n()},[i,e.name,b,n]),E=async()=>{if(!e.fp)return;const L=await Vx(e.fp);if(S.current){if(!L){f("Could not copy it — select the fingerprint and copy it by hand.");return}h(!0),window.setTimeout(()=>{S.current&&h(!1)},1600)}},C=new Set(_.current??e.shared??[]),T=e.autoAsk!==!1,R=e.autoAccept!==!1,I=e.shareActive!==!1;return $r.createPortal(l.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:l.jsxs("div",{ref:a,className:"modal lan-modal",onClick:L=>L.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"lan-modal-title",children:[l.jsxs("header",{className:"modal-head",children:[l.jsx("div",{className:"modal-title",children:l.jsx("span",{id:"lan-modal-title",className:"modal-tool-name",children:"This deck on the network"})}),l.jsx("div",{className:"modal-actions",children:l.jsx("button",{className:"glyph-btn",onClick:n,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),l.jsxs("section",{className:"modal-body",children:[u&&l.jsxs("div",{className:"ap-failure",role:"alert",children:[l.jsx("span",{className:"ap-failure-text",children:u}),l.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>f(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),l.jsxs("div",{className:"modal-section",children:[l.jsx("h3",{className:"lan-h",children:"Name"}),l.jsxs("div",{className:"ap-lan-row",children:[l.jsx("span",{className:"ap-lan-label",children:"appear as"}),l.jsx("input",{className:"ap-manage-input ap-lan-input","aria-label":"This deck's name on the network",value:i??e.name??"",placeholder:"this machine",onChange:L=>c(L.target.value),onKeyDown:L=>{L.key!=="Enter"||i==null||(b({name:i},"save the name","name"),c(null))}}),i!=null&&i!==(e.name??"")&&l.jsx("button",{type:"button",className:"ap-manage-btn",...N("name"),onClick:()=>{b({name:i},"save the name","name"),c(null)},title:"Save it. This is the name other decks show for this one.",children:"save"})]}),l.jsxs("div",{className:"ap-lan-row",children:[l.jsx("span",{className:"ap-lan-label",children:"fingerprint"}),e.fp?l.jsxs("span",{className:"lan-fp",children:[l.jsx("code",{className:"ap-lan-code",children:e.fp}),l.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"})]}):l.jsx("span",{className:"ap-lan-label",children:"not known yet"})]})]}),l.jsxs("div",{className:"modal-section",children:[l.jsx("h3",{className:"lan-h",children:"Share these accounts"}),l.jsxs("div",{className:"ap-lan-picks",children:[t.length===0&&l.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(L=>l.jsxs("label",{className:"ap-lan-pick",title:L.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:[l.jsx("input",{type:"checkbox",checked:C.has(L.key),onChange:H=>{const $=new Set(_.current??e.shared??[]);H.target.checked?$.add(L.key):$.delete(L.key),_.current=[...$],b({shared:[...$]},H.target.checked?"share that account":"stop sharing that account")}}),l.jsx("span",{className:"ap-lan-pick-name",children:L.email}),!L.alive&&l.jsx("span",{className:"ap-lan-dead",children:"not working here"})]},L.key))]}),t.length>0&&l.jsxs("div",{className:"lan-switch",children:[l.jsx("span",{className:"lan-switch-what",children:"Show paired decks which of these this deck is using"}),l.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":I,"aria-label":"Show paired decks which of these this deck is using",...N("current"),onClick:()=>void b({shareActive:!I},I?"stop showing which account this deck is using":"show which account this deck is using","current"),title:I?"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:l.jsx("span",{className:"switch-knob"})})]})]}),l.jsxs("div",{className:"modal-section",children:[l.jsx("h3",{className:"lan-h",children:"Pairing"}),l.jsxs("div",{className:"lan-switches",children:[l.jsxs("div",{className:"lan-switch",children:[l.jsx("span",{className:"lan-switch-what",children:"Ask every deck this one finds"}),l.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":T,"aria-label":"Ask every deck this one finds",...N("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:l.jsx("span",{className:"switch-knob"})})]}),l.jsxs("div",{className:"lan-switch",children:[l.jsx("span",{className:"lan-switch-what",children:"Say yes to every deck that asks"}),l.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",...N("accept"),onKeyDown:L=>{L.repeat&&L.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:l.jsx("span",{className:"switch-knob"})})]})]})]})]}),l.jsxs("footer",{className:"lan-setup-foot",children:[l.jsx("span",{className:"lan-foot-note",children:"Changes are saved as you make them."}),l.jsx("button",{type:"button",className:"btn primary",...N("name"),onClick:()=>void j(),children:"Done"})]})]})}),document.body)}function Kr(e,t){if(e==null)return"not seen";const n=Math.max(0,Math.round((t-e)/1e3));if(n<90)return"now";const s=Math.round(n/60);if(s<60)return`${s}m ago`;const a=Math.round(s/60);return a<48?`${a}h ago`:`${Math.round(a/24)}d ago`}const t0={"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"}},WF={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 HF(e){var s;const t=GF[e];if(t)return t;const n=(s=/\b(E[A-Z]{3,})\b/.exec(e))==null?void 0:s[1];return n&&WF[n]||e}const GF={"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 LA(e,t){if(!e)return null;if(e.error)return t0[e.error]??{text:HF(e.error),tone:"bad"};const n=e.done??[];if(!n.length)return{text:`all logins fine · ${Kr(e.at,t)}`,tone:"idle"};const s=n.filter(i=>i.ok),a=s.length===1?"login":"logins";return s.length===n.length?{text:`${s.length} ${a} arrived · ${Kr(e.at,t)}`,tone:"ok"}:{text:`${s.length} of ${n.length} logins arrived · ${Kr(e.at,t)}`,tone:"bad"}}const VF=9e4;function YF({error:e,host:t,port:n},s,a,i=45317){if(e!=="handshake timed out")return null;const c=(t??"").trim();if(!c)return null;const u=s.filter(p=>p.addr===c&&p.port&&p.at>0&&a-p.at<VF);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 ${i} and TCP ${n??f[0]}.`}const fx=5e3,DA=6e4,qd=400;function KF(e){const t=(e??"").trim(),n=t.lastIndexOf(":");if(n<=0||n===t.length-1)return null;const s=t.slice(0,n).trim(),a=Number(t.slice(n+1).trim());return!s||!Number.isInteger(a)||a<1||a>65535||s.includes(":")&&!(s.startsWith("[")&&s.endsWith("]"))?null:{addr:s,port:a}}function Xt(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 XF(e,t){if(e.length!==t.length)return!1;const n=new Set(e);return t.every(s=>n.has(s))}function ZF(e,t){const n=Math.max(0,Math.round((e-t)/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`}function qA(e,t){var n,s;return(n=e.last)!=null&&n.error&&!t0[e.last.error]?!1:!!((s=e.last)!=null&&s.at&&t-e.last.at<Fd||e.lastSeen!=null&&t-e.lastSeen<Fd)}const Fd=95e3,QF=160,JF=6,e8=140;function t8(e,t){const n=[],s=[];for(const a of e??[])(qA(a,t)?n:s).push(a);return{online:n,offline:s}}function n8(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 s=(e.peers??[]).filter(w=>w.paired!==!1||w.met);if(!s.length)return{text:"no deck paired yet",tone:"idle"};const a=s.filter(w=>w.waiting),i=s.filter(w=>!w.waiting),c=a.filter(w=>{var N;return!((N=w.last)!=null&&N.error)&&w.lastSeen!=null&&t-w.lastSeen<Fd}),{online:u,offline:f}=t8(i,t),p=[...f,...a.filter(w=>!c.includes(w))],h=u.length+c.length,m=u.filter(w=>{var N;return((N=w.last)==null?void 0:N.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 r8(e,t,n){if(n)return"checking…";if(e==null)return"not checked yet";const s=Kr(e,t);return s==="now"?"checked just now":`checked ${s}`}function n0(e,t){const n=Math.max(0,Math.round((t-e)/1e3));if(n<90)return"just now";const s=Math.round(n/60);return s<60?`${s}m ago`:`${Math.round(s/60)}h ago`}function s8(e,t){if(e==null)return{text:"one-way · has not called yet",here:!1};const n=t-e<Fd;return{text:n?"online · one-way, it calls in":`one-way · last online ${Kr(e,t)}`,here:n}}function b_(e,t,n){return t?"online":e.lastSeen!=null?`last online ${Kr(e.lastSeen,n)}`:e.waiting?"has not called yet":"never reached"}function a8(e,t){var y,w,N,_,S;if(!e)return[];const n=[],s=new Set,a=(b,j)=>b.name.localeCompare(j.name,void 0,{numeric:!0}),i=e.aliases??{},c=(b,j)=>{const E=b?i[b]:void 0;return E&&E!==j?{name:E,self:j}:{name:j}};for(const b of e.pending??[]){if(!(b!=null&&b.fp)||s.has(b.fp))continue;s.add(b.fp);const j=c(b.fp,b.name||b.fp);n.push({fp:b.fp,name:j.name,...j.self?{self:j.self}:{},addr:b.addr??"",kind:"asks",state:`wants to pair · ${n0(b.at,t)}`,tone:"wait",here:!0,hint:`${j.name} at ${b.addr} is waiting for an answer.`})}const u=[],f=[];for(const b of e.peers??[]){const j=b.peerFp??b.fp;if(!j||s.has(j))continue;s.add(j);const E=LA(b.last,t),C=qA(b,t),T=b.addr?`${b.addr}:${b.port}`:"";if(!b.paired&&b.manual&&!b.met){f.push({fp:T,name:T||b.name||j,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.`});continue}const R=b.waiting?s8(b.lastSeen,t):null,I=R?R.here:C,L=!R&&E?I?`online · ${E.text.replace(/ · .*$/,"")}`:`${E.text.replace(/ · .*$/,"")} · ${b_(b,I,t)}`:R?R.text:b_(b,I,t),H=(w=b.last)!=null&&w.error?t0[b.last.error]:null,$=!R&&I&&!((N=b.last)!=null&&N.error)&&!(((_=b.last)==null?void 0:_.done)??[]).length,V=b.manual&&!b.met?{name:T}:c(j,b.name||j);u.push({fp:j,name:V.name,...V.self?{self:V.self}:{},addr:b.addr??"",kind:"paired",state:L,quiet:$,tone:H?H.tone==="bad"?"bad":"wait":E?E.tone:I?"ok":"idle",here:R?R.here:C,hint:R?`${V.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 ${Kr(b.lastSeen,t)}.`} Add its address with the + at the top of this section to reach it either way.`:`${V.name}${T?` at ${T}`:""}${(S=b.last)!=null&&S.error?` — ${b.last.error}`:""}`})}n.push(...o8(u).sort(a),...f.sort(a));const p=[];for(const b of e.strangers??[]){if(!(b!=null&&b.fp)||s.has(b.fp))continue;s.add(b.fp);const j=c(b.fp,b.name||b.fp);p.push({fp:b.fp,name:j.name,...j.self?{self:j.self}:{},addr:b.addr??"",kind:"nearby",state:"not paired yet",tone:"idle",here:!0,hint:`${j.name} at ${b.addr} is on this network and nothing is shared with it.`})}n.push(...p.sort(a));const h=[];for(const b of e.declined??[]){if(!(b!=null&&b.fp)||s.has(b.fp))continue;s.add(b.fp);const j=c(b.fp,b.name||b.fp);h.push({fp:b.fp,name:j.name,...j.self?{self:j.self}:{},addr:b.addr??"",kind:"declined",state:"you said no",tone:"idle",here:!1,hint:`${j.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 o8(e){const t=new Map;for(const s of e){const a=t.get(s.name);a?a.push(s):t.set(s.name,[s])}const n=[];for(const s of t.values()){const a=[...new Set(s.filter(i=>i.addr).map(i=>i.addr))];if(a.length>1){for(const i of a)n.push(k_(s.filter(c=>c.addr===i)));n.push(...s.filter(i=>!i.addr))}else n.push(k_(s))}return n}function k_(e){const[t,...n]=[...e].sort((s,a)=>Number(a.here)-Number(s.here)||+!!a.addr-+!!s.addr);return n.length?{...t,twins:n}:t}function __(e,t){return t?e.map(n=>t[n.fp]?{...n,name:t[n.fp]}:n):e}function N_(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 i8(e,t){const n=/^(\d+)\.(\d+)\.(\d+)/.exec(e??""),s=/^(\d+)\.(\d+)\.(\d+)/.exec(t??"");if(!n||!s)return null;for(let a=1;a<=3;a++){const i=Number(n[a])-Number(s[a]);if(i)return Math.sign(i)}return 0}function l8(e,t,n){const s=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:s,note:a,tone:a?"bad":"idle"}}return t?t.alive?{there:"works there",here:s,note:null,tone:"ok"}:n?{there:"works there",here:s,note:"repairs next round",tone:"wait"}:{there:"works there",here:s,note:"share it to repair",tone:"bad"}:{there:"works there",here:s,note:"arrives next round",tone:"wait"}}function c8(e,t,n,s=null){const a=new Map(t.map(f=>[f.key,f])),i=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=i.has(f.key),m=l8(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:s===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 Si(e,t){return(await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})).json().catch(()=>null)}function u8({anchorId:e,id:t,rows:n,onHold:s,onLet:a}){const i=x.useRef(null),c=n.filter(y=>y.kind==="paired"),u=c.filter(y=>y.here),f=u.slice(0,JF),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=i.current,w=document.getElementById(e);if(!y||!w)return;const N=Qq(w.getBoundingClientRect(),{width:y.offsetWidth,height:y.offsetHeight},{width:window.innerWidth,height:window.innerHeight});y.style.top=`${N.top}px`,y.style.left=`${N.left}px`,y.style.maxHeight=N.maxHeight==null?"":`${N.maxHeight}px`,y.dataset.side=N.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]),$r.createPortal(l.jsxs("div",{ref:i,id:t,className:"ap-peek",role:"tooltip",onPointerEnter:s,onPointerLeave:a,children:[l.jsx("p",{className:"ap-peek-title",children:u.length?"On the network now":"Nobody on the network"}),f.length>0&&l.jsx("div",{className:"ap-peek-list",children:f.map(y=>l.jsxs("span",{className:"ap-peek-who",children:[l.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),l.jsx("span",{children:y.name})]},`${y.kind}:${y.fp}`))}),h&&l.jsx("p",{className:"ap-peek-rest",children:h})]}),document.body)}function d8(e,t){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(i=>i.kind==="asks").length;if(n)return{text:n===1?"1 deck wants to pair":`${n} decks want to pair`,tone:"wait",live:!1};const s=t.filter(i=>i.kind==="paired");if(!s.length)return{text:"On · none paired yet",tone:"idle",live:!1};const a=s.filter(i=>i.here).length;return a?a===s.length?{text:`${a} online`,tone:"ok",live:!0}:{text:`${a} of ${s.length} online`,tone:"ok",live:!0}:{text:`none of ${s.length} online`,tone:"idle",live:!1}}function h8({accounts:e,onChanged:t,view:n,onOpen:s,onBack:a,closeButton:i}){const[c,u]=x.useState(null),[f,p]=x.useState([]),[h,m]=x.useState(null),[y,w]=x.useState(!1),[N,_]=x.useState(null),S=x.useRef(0),[b,j]=x.useState(!1),[E,C]=x.useState(!1),[T,R]=x.useState(!1),I=x.useRef(0);x.useEffect(()=>()=>window.clearTimeout(I.current),[]);const[L,H]=x.useState(!1),[$,V]=x.useState(null),Q=x.useRef(null),J=x.useCallback(ce=>ah(Q.current)?(Q.current=ce,m(ce),!0):!1,[]),M=x.useCallback(()=>{Q.current=null,B.current&&m(null)},[]),X=ce=>{const ke=ua(h,ce);return{disabled:ke.disabled,"aria-busy":ke.busy}},[G,P]=x.useState(()=>Date.now()),B=x.useRef(!0),W=x.useRef(fx),Y=x.useCallback(async()=>{var ce,ke;try{const[Ee,Ze]=await Promise.all([fetch("/api/lan").then(Xe=>Xe.json()),fetch("/api/prefs").then(Xe=>Xe.json())]);if(!B.current)return;Ee!=null&&Ee.ok&&u(Ee),Ze!=null&&Ze.ok&&p(Array.isArray((ke=(ce=Ze.prefs)==null?void 0:ce.lan)==null?void 0:ke.manual)?Ze.prefs.lan.manual:[]),W.current=(Ee==null?void 0:Ee.enabled)===!0?fx:DA}catch{}},[]);x.useEffect(()=>{B.current=!0;let ce=0;const ke=async()=>{P(Date.now()),await Y(),B.current&&(ce=window.setTimeout(ke,W.current))};return ke(),()=>{B.current=!1,window.clearTimeout(ce)}},[Y]);const O=x.useCallback(async()=>{const ce=(c==null?void 0:c.enabled)===!0;if(J("switch"))try{const ke=await Si("/api/prefs",{lan:{enabled:!ce}});if(!B.current)return;ke!=null&&ke.ok?(V(null),ce||w(!0)):V(Xt(ce?"turn this off":"turn this on",ke)),await Y()}catch{B.current&&V(Xt(ce?"turn this off":"turn this on",null))}finally{M()}},[c==null?void 0:c.enabled,Y,J,M]),F=x.useCallback(async(ce,ke,Ee)=>{if(!J(`${ce}:${ke}`))return null;let Ze=null;try{const Xe=await Si("/api/lan/peer",{action:ce,fp:ke});if(!B.current)return null;Xe!=null&&Xe.ok?(u(Xe),V(null)):(Ze=Xt(Ee,Xe),V(Ze)),await Y()}catch{Ze=Xt(Ee,null),B.current&&V(Ze)}finally{M()}return Ze},[Y,J,M]),oe=x.useCallback(async ce=>{if(!J(`drop:${ce}`))return null;let ke=null;try{const Ee=await Si("/api/prefs",{lan:{manual:f.filter(Ze=>Ze!==ce)}});if(!B.current)return null;Ee!=null&&Ee.ok?(V(null),t()):(ke=Xt("stop dialling that address",Ee),V(ke)),await Y()}catch{ke=Xt("stop dialling that address",null),B.current&&V(ke)}finally{M()}return ke},[f,Y,t,J,M]),[z,Z]=x.useState(null),U=x.useCallback(async(ce,ke)=>{if(!J(`alias:${ce}`))return"Something else is still being saved. Try again in a moment.";try{const Ee=await Si("/api/lan/peer",{action:"alias",fp:ce,name:ke});return B.current?Ee!=null&&Ee.ok?(u(Ee),null):Xt("rename that deck",Ee):null}catch{return Xt("rename that deck",null)}finally{M()}},[J,M]),re=x.useCallback(async ce=>{if(!J(`check:${ce}`))return null;try{const ke=await Si("/api/lan/sync",{fp:ce});return B.current?ke!=null&&ke.ok?(u(ke),t(),null):(ke==null?void 0:ke.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.":Xt("check that deck",ke):null}catch{return Xt("check that deck",null)}finally{M()}},[J,M,t]),de=x.useCallback(async()=>{if(J("check"))try{const ce=await Si("/api/lan/sync",{});if(!B.current)return;ce!=null&&ce.ok?(u(ce),V(null)):V(Xt("check the other decks",ce)),t()}catch{B.current&&V(Xt("check the other decks",null))}finally{M()}},[J,M,t]),pe=(c==null?void 0:c.enabled)===!0,ge=a8(c,G),Te=z?ge.find(ce=>{var ke;return ce.fp===z||((ke=ce.twins)==null?void 0:ke.some(Ee=>Ee.fp===z))})??null:null;x.useEffect(()=>{z&&c&&!Te&&Z(null)},[z,c,Te]);const Ue=ge.filter(ce=>ce.kind==="asks"),He=ge.filter(ce=>ce.kind!=="asks"),Pe=He.filter(ce=>ce.here),Se=He.filter(ce=>!ce.here),nt=Se.filter(ce=>ce.tone==="bad").length,je=L||Pe.length===0,be=n8(c,G),Ke=He.filter(ce=>ce.kind==="paired").length,ct=d8(c,ge),Ye=l.jsxs(l.Fragment,{children:[b&&c&&l.jsx($F,{status:c,manual:f,onClose:()=>j(!1),onChanged:()=>{Y(),t()}}),E&&l.jsx(OA,{title:"How Local network works",steps:AF,finish:pe?void 0:{label:"Turn it on",act:()=>{C(!1),O()}},onClose:()=>C(!1)}),y&&c&&l.jsx(UF,{status:{...c,manualRows:f},accounts:e,manual:f,onClose:()=>w(!1),onChanged:()=>{Y(),t()}}),Te&&c&&l.jsx(zF,{row:Te,source:N_(c,Te),status:c,accounts:e,now:G,busy:h,onClose:()=>Z(null),onRename:ce=>U(Te.fp,ce),onCheck:()=>re(Te.fp),onVerb:()=>{switch(Te.kind){case"paired":return F("unpair",Te.fp,"unpair that deck");case"nearby":return F("accept",Te.fp,"reach that deck");case"declined":return F("allow",Te.fp,"let that deck ask again");case"dialling":return oe(Te.fp);default:return Promise.resolve(null)}},onSettings:()=>{Z(null),w(!0)},twins:(Te.twins??[]).map(ce=>({row:ce,peer:N_(c,ce).peer??null})),onUnpair:ce=>F("unpair",ce,"unpair that deck")})]});if(!n){const ce=Xe=>{window.clearTimeout(I.current),I.current=window.setTimeout(()=>R(!0),Xe)},ke=()=>{window.clearTimeout(I.current),I.current=window.setTimeout(()=>R(!1),e8)},Ee=()=>window.clearTimeout(I.current),Ze=()=>{window.clearTimeout(I.current),R(!1)};return l.jsxs("div",{className:"ap-foot",children:[l.jsxs("button",{type:"button",id:"ap-lan-entry",className:"ap-nav",onClick:()=>{Ze(),s()},"aria-describedby":T?"ap-lan-peek":void 0,onPointerEnter:Xe=>{Xe.pointerType==="mouse"&&ce(QF)},onPointerLeave:ke,onFocus:Xe=>{Xe.target.matches(":focus-visible")&&ce(0)},onBlur:ke,children:[l.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:[l.jsx("rect",{x:"1.8",y:"2.3",width:"10.4",height:"7.2",rx:"1.2"}),l.jsx("path",{d:"M5 11.9h4M7 9.5v2.4"})]}),l.jsxs("span",{className:"ap-nav-text",children:[l.jsx("span",{className:"ap-nav-name",children:"Local network"}),l.jsxs("span",{className:"ap-nav-state","data-tone":ct.tone,children:[ct.live&&l.jsx("i",{className:"ap-nav-live","aria-hidden":!0}),ct.text]})]}),l.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:l.jsx("path",{d:"M5.6 3.4 9.2 7l-3.6 3.6"})})]}),T&&l.jsx(u8,{anchorId:"ap-lan-entry",id:"ap-lan-peek",rows:ge,onHold:Ee,onLet:ke}),l.jsx("p",{className:"vis-hidden",role:"status",children:be.tone==="ok"?"":be.text}),Ye]})}return l.jsxs("div",{className:"ap-lan-view",children:[l.jsxs("div",{className:"ap-header",children:[l.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:l.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:l.jsx("path",{d:"M8.4 3.4 4.8 7l3.6 3.6"})})}),l.jsx("h2",{id:"ap-lan-title",children:"Local network"}),l.jsxs("div",{className:"ap-header-right",children:[pe&&l.jsx("button",{type:"button",className:"glyph-btn ap-lan-plus",onClick:()=>j(!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:l.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:[l.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"}),l.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"})]})}),pe&&Ke>0&&l.jsx("button",{type:"button",className:"glyph-btn ap-lan-check",...X("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:l.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:[l.jsx("circle",{cx:"7",cy:"7",r:"1.1",fill:"currentColor",stroke:"none"}),l.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"}),l.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"})]})}),pe&&l.jsx("button",{type:"button",className:"glyph-btn ap-lan-set",...X("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:l.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:[l.jsx("path",{d:"M1.8 4.7h10.4M1.8 9.3h10.4"}),l.jsx("circle",{cx:"9.1",cy:"4.7",r:"1.6",fill:"var(--panel)"}),l.jsx("circle",{cx:"4.9",cy:"9.3",r:"1.6",fill:"var(--panel)"})]})}),i]})]}),l.jsx("div",{className:"ap-scroll",id:"ap-lan-scroll",children:l.jsxs("div",{className:"ap-lan",children:[l.jsxs("div",{className:"ap-policy",children:[l.jsx("h3",{className:"ap-auto-title",children:"Sync with paired decks"}),l.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":pe,"aria-label":"Sync with paired decks",...X("switch"),onClick:()=>void O(),title:pe?"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:l.jsx("span",{className:"switch-knob"})})]}),!pe&&l.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:[l.jsx(RF,{}),l.jsx("span",{className:"ap-lan-intro-text",children:"Paired machines repair each other's expired logins."}),l.jsx("span",{className:"ap-lan-intro-go",children:"See how it works"})]}),l.jsx("p",{className:`ap-lan-status ${be.tone}`,role:"status",children:be.tone==="ok"?"":be.text}),$&&l.jsxs("div",{className:"ap-failure",role:"alert",children:[l.jsx("span",{className:"ap-failure-text",children:$}),l.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>V(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),pe&&l.jsxs(l.Fragment,{children:[Ue.length>0&&l.jsx("div",{className:"ap-lan-asks",role:"alert",children:Ue.map(ce=>l.jsxs("div",{className:"ap-lan-ask",children:[l.jsxs("span",{className:"ap-lan-ask-what",children:[l.jsx("strong",{className:"ap-lan-peer-name",children:ce.name})," at ",l.jsx("code",{className:"ap-lan-code",children:ce.addr})," wants to pair"]}),l.jsxs("span",{className:"ap-lan-ask-fp",children:["fingerprint ",l.jsx("code",{className:"ap-lan-code",children:ce.fp})]}),l.jsxs("span",{className:"ap-lan-ask-acts",children:[l.jsx("button",{type:"button",className:"ap-manage-btn",...X(`accept:${ce.fp}`),onClick:()=>void F("accept",ce.fp,"accept that deck"),title:`Talk to this deck from now on. Its fingerprint is ${ce.fp} — check it matches the one on their screen before you accept.`,children:"accept"}),l.jsx("button",{type:"button",className:"ap-manage-btn",...X(`dismiss:${ce.fp}`),onClick:()=>void F("dismiss",ce.fp,"decline that request"),title:"Say no. Nothing is shared, and that deck is told rather than left waiting.",children:"decline"})]})]},ce.fp))}),(je?[...Pe,...Se]:Pe).length>0&&l.jsx("ul",{className:"ap-lan-here",children:(je?[...Pe,...Se]:Pe).map((ce,ke)=>l.jsxs("li",{className:"ap-lan-who","data-tone":ce.tone,children:[l.jsx("i",{className:ce.here?"ap-pulse":"ap-dot","aria-hidden":!0}),l.jsx("span",{className:"ap-lan-who-name","aria-hidden":!0,children:ce.name}),l.jsx("button",{type:"button",className:"ap-lan-who-open","aria-haspopup":"dialog","aria-describedby":`lan-who-state-${ke}`,onClick:()=>Z(ce.fp),children:l.jsxs("span",{className:"vis-hidden",children:[ce.name,", details"]})}),l.jsx("span",{id:`lan-who-state-${ke}`,className:ce.quiet?"vis-hidden":"ap-lan-who-when",children:ce.state}),ce.kind==="nearby"&&l.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...X(`accept:${ce.fp}`),onClick:()=>void F("accept",ce.fp,"reach that deck"),"aria-label":`Ask ${ce.name} to pair`,title:`Send ${ce.name} a request. Somebody at that machine has to accept it before anything is shared. Its fingerprint is ${ce.fp}.`,children:"ask"}),ce.kind==="paired"&&l.jsx("button",{type:"button",className:`ap-manage-btn ap-lan-do danger${N===ce.fp?" armed":""}`,...X(`unpair:${ce.fp}`),onClick:()=>{if(N!==ce.fp){_(ce.fp),S.current=Date.now(),window.setTimeout(()=>_(Ee=>Ee===ce.fp?null:Ee),4e3);return}Date.now()-S.current<qd||(_(null),F("unpair",ce.fp,"unpair that deck"))},"aria-label":N===ce.fp?`Confirm unpairing ${ce.name}`:`Unpair ${ce.name}`,title:N===ce.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:N===ce.fp?"confirm":"unpair"}),ce.kind==="dialling"&&l.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...X(`drop:${ce.fp}`),onClick:()=>void oe(ce.fp),"aria-label":`Stop dialling ${ce.name}`,title:"Stop trying this address. Nothing was ever paired here.",children:"stop"}),ce.kind==="declined"&&l.jsx("button",{type:"button",className:"ap-manage-btn ap-lan-do",...X(`allow:${ce.fp}`),onClick:()=>void F("allow",ce.fp,"let that deck ask again"),"aria-label":`Let ${ce.name} ask again`,title:"Take the no back. That deck is still trying, so the request comes round again on its own.",children:"allow"})]},`${ce.kind}:${ce.fp}`))}),(Pe.length>0&&Se.length>0||pe&&Ke>0)&&l.jsxs("div",{className:"ap-lan-tail",children:[Pe.length>0&&Se.length>0&&l.jsxs("button",{type:"button",className:"ap-lan-word ap-lan-more","aria-expanded":L,onClick:()=>H(ce=>!ce),title:L?"Show only the decks that are on":`Show the ${Se.length} deck${Se.length===1?"":"s"} that are not responding right now`,children:[l.jsx("span",{className:`ap-lan-chev${L?" open":""}`,"aria-hidden":!0,children:"›"}),L?"fewer":`${Se.length} more`,!L&&nt>0&&l.jsxs("span",{className:"ap-lan-more-bad",children:[" · ",nt," not responding"]})]}),pe&&Ke>0&&l.jsx("span",{className:"ap-lan-checked",children:r8(c==null?void 0:c.checkedAt,G,h==="check")})]}),He.length===0&&Ue.length===0&&l.jsxs(l.Fragment,{children:[l.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."}),l.jsx("button",{type:"button",className:"ap-lan-word ap-lan-how",onClick:()=>C(!0),children:"How it works"})]})]})]})}),Ye]})}const S_=15e3,f8=8e3,p8=1800,m8=3e4,pp=[70,80,85,90,95];function mp(e,t){return dA(t-Math.floor(e/1e3))}function g8(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 ec(e){return e.charAt(0).toUpperCase()+e.slice(1)}function y8(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 s=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 ${s}m. No sign-in, no switch.`}}return{text:"numbers paused",hint:n}}function w8(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 v8(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 gp(e,t){if(e.staleCopy){const n=y8(e.repair??null,t);return{text:ec(n.text),hint:n.hint,fix:null,tone:"quiet",blocksSwitch:!1}}if(e.stopped){const n=v8(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 s=e.collector==="no_credentials"||e.collector==="relogin_required";return{text:ec(n.text),hint:n.hint,fix:n.fix?ec(n.fix):null,tone:s||e.collector==="keychain_unavailable"?"warn":"quiet",blocksSwitch:s}}if(e.error){const n=w8(e.error);return{text:ec(n.text),hint:n.hint,fix:n.fixable?"Sign in again":null,tone:n.fixable?"warn":"quiet",blocksSwitch:n.fixable}}return null}function yp(){return l.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:[l.jsx("path",{d:"M7 1.9 12.9 12H1.1Z"}),l.jsx("path",{d:"M7 5.6v2.9"}),l.jsx("path",{d:"M7 10.3v.05"})]})}function x8(e){return e>=90?"hi":e>=70?"mid":void 0}function b8(e){const t=Number(e);return[...Number.isFinite(t)&&t>0&&!pp.includes(t)?[...pp,t]:pp].sort((s,a)=>s-a)}function k8({lane:e,nowSec:t,frozen:n}){const s=Math.min(100,Math.max(0,e.pct)),a=n?"var(--muted)":s>=90?"var(--err)":s>=70?"var(--warn)":"var(--accent)",i=e.resetAt&&!n?hA(e.resetAt,t):null;return l.jsxs("div",{className:"ap-lane",children:[l.jsx("span",{className:"ap-lane-label",title:e.label,children:e.label}),l.jsx("div",{className:"ap-lane-track",children:l.jsx("div",{className:"ap-lane-fill",style:{width:`${s===0?1.5:s}%`,background:a,opacity:s===0||n?.4:1}})}),l.jsxs("span",{className:"ap-lane-pct",style:{color:a},children:[s,"%"]}),l.jsx("span",{className:"ap-lane-reset",title:i?`${e.label} resets in ${i}`:void 0,children:i&&l.jsxs(l.Fragment,{children:[l.jsx("span",{className:"vis-hidden",children:"resets in "}),i]})})]})}async function j_(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(s=>window.setTimeout(()=>s(!1),500))])}catch{t=!1}if(t)return!0;try{const s=document.createElement("textarea");s.value=e,s.setAttribute("readonly",""),s.style.cssText="position:fixed;top:0;left:0;opacity:0",document.body.appendChild(s),s.select(),t=document.execCommand("copy"),s.remove()}catch{t=!1}return t}function _8({onClose:e,leaving:t}){var Yn,qt,Ft,Kn;const[n,s]=x.useState(null),[a,i]=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"),[S,b]=x.useState(!1),[j,E]=x.useState(null),C=x.useRef(j);C.current=j;const[T,R]=x.useState(()=>Math.floor(Date.now()/1e3)),I=x.useRef(null),[L,H]=x.useState(null),$=(L==null?void 0:L.num)??null,V=x.useRef(L);V.current=L;const[Q,J]=x.useState(null),[M,X]=x.useState(!1),[G,P]=x.useState(""),[B,W]=x.useState(null),Y=x.useRef(0),[O,F]=x.useState(null),[oe,z]=x.useState(!1),[Z,U]=x.useState(!1),[re,de]=x.useState(null),[pe,ge]=x.useState(null),[Te,Ue]=x.useState(null),[He,Pe]=x.useState(!1),Se=x.useRef(null),nt=x.useRef(null),[je,be]=x.useState([]),Ke=x.useRef(null),ct=x.useCallback(te=>ah(Ke.current)?(Ke.current=te,u(te),!0):!1,[]),Ye=x.useCallback(()=>{Ke.current=null,u(null)},[]),ce=(te,Ae=!1)=>{const Ie=ua(c,te);return{disabled:Ie.disabled,"aria-busy":Ie.busy||Ae}},ke=x.useCallback(te=>{window.requestAnimationFrame(()=>{var Ae;if(t_(((Ae=document.activeElement)==null?void 0:Ae.tagName)??null))for(const Ie of ED(te)){const Me=document.querySelector(Ie);if(Me){Me.focus();return}}})},[]),Ee=x.useCallback(async(te=!1)=>{te&&p(!0);const Ae=new AbortController,Ie=window.setTimeout(()=>Ae.abort(),m8);try{const[Me,De]=await Promise.all([fetch(`/api/claude-accounts${te?"?refresh=1":""}`,{signal:Ae.signal}),fetch("/api/cswap-auto",{signal:Ae.signal})]);if(Me.ok){const Tt=await Me.json();s(Tt),be(vt=>dF(vt,Tt.accounts))}De.ok&&i(await De.json());const dt=gF([await f_(Me),await f_(De)]);m(Tt=>p_(Tt,dt))}catch{m(Me=>p_(Me,Ae.signal.aborted?mF:pF))}finally{window.clearTimeout(Ie),te&&p(!1)}},[]),Ze=x.useCallback(async(te,Ae,Ie="panel")=>{if(!ct(Ae))return null;const Me=Ie==="menu"?J:m;Me(null);try{const dt=await(await fetch("/api/cswap-auto",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(te)})).json().catch(()=>null);return dt!=null&&dt.ok||Me({text:ux(dt,"command failed"),raw:gc(dt)}),dt}catch{return Me({text:"server unreachable"}),null}finally{Ye()}},[ct,Ye]),Xe=x.useCallback(async(te,Ae)=>{if(!ct(Ae))return null;m(null),J(null);try{const Me=await(await fetch("/api/claude-accounts/admin",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(te)})).json().catch(()=>null);return Me!=null&&Me.ok||J({text:Ti(Me,"command failed")}),Me}catch{return J({text:"server unreachable"}),null}finally{Ye()}},[ct,Ye]);x.useEffect(()=>(Ee(!0),I.current=window.setInterval(()=>Ee(!1),S_),()=>{I.current!=null&&window.clearInterval(I.current)}),[Ee]),x.useEffect(()=>{const te=window.setInterval(()=>R(Math.floor(Date.now()/1e3)),3e4);return()=>window.clearInterval(te)},[]);const ut=((Yn=a==null?void 0:a.settings["autoswitch.threshold"])==null?void 0:Yn.value)??"90",ee=Te??ut,Ne=iF(ee,ut),Be=(qt=n==null?void 0:n.accounts)==null?void 0:qt.find(te=>te.active),et=Be?gp(Be,T):null,pt=async(te,Ae)=>{if(ct(`switch-${te}`)){m(null),w(null);try{const Me=await(await fetch("/api/claude-accounts/switch",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({account:te})})).json().catch(()=>null);Me!=null&&Me.ok?w({num:te,name:Ae}):m({text:ux(Me,"the switch failed"),raw:gc(Me),row:te}),await Ee(!0)}catch{m({text:"server unreachable",row:te})}finally{Ye(),ke(te)}}},tt=x.useCallback(()=>{H(null),J(null),W(null),F(null),U(!1)},[]),rt=(te,Ae="first")=>{tt(),E(null),ge(null),H({num:te,view:"menu",start:Ae})},lt=(te,Ae)=>{tt(),E(Ie=>(Ie==null?void 0:Ie.anchor)===Ae?null:{num:te,anchor:Ae})},bt=x.useCallback((te=!1)=>{var Ie;const Ae=C.current;te&&Ae&&((Ie=document.getElementById(Ae.anchor))==null||Ie.focus()),E(null)},[]),st=()=>{tt(),E(null),_("lan")},mt=x.useRef(N);x.useEffect(()=>{mt.current!==N&&(mt.current=N,window.requestAnimationFrame(()=>{var te;(te=document.getElementById(N==="lan"?"ap-lan-back":"ap-lan-entry"))==null||te.focus()}))},[N]),x.useEffect(()=>{n!=null&&n.ok&&b(!0)},[n==null?void 0:n.ok]);const ze=x.useCallback(te=>{var Me,De;const Ae=V.current;if(!Ae||te!=null&&Ae.num!==te)return;const Ie=document.getElementById(`ap-menu-${Ae.num}`);(Ie!=null&&Ie.contains(document.activeElement)||t_(((Me=document.activeElement)==null?void 0:Me.tagName)??null))&&((De=document.getElementById(`ap-more-${Ae.num}`))==null||De.focus()),tt()},[tt]);x.useEffect(()=>{t&&(tt(),E(null))},[t,tt]),x.useEffect(()=>{L&&(n!=null&&n.accounts)&&!n.accounts.some(te=>te.num===L.num)&&tt(),j&&(n!=null&&n.accounts)&&!n.accounts.some(te=>te.num===j.num)&&E(null)},[n,L,j,tt]);const Dt=async te=>{var Ie;U(!1);const Ae=await Xe({action:"share",account:te},`share-${te}`);!(Ae!=null&&Ae.ok)||((Ie=V.current)==null?void 0:Ie.num)!==te||(F({num:te,blob:Ae.blob,expiresAt:Ae.expiresAt}),H({num:te,view:"share"}))},me=async(te,Ae)=>{const{commit:Ie,alias:Me}=fF(G,Ae);if(Ie){const De=await Xe({action:"alias",account:te,alias:Me},`alias-${te}`);if(await Ee(!0),!(De!=null&&De.ok))return}ze(te)},gt=async(te,Ae)=>{var De,dt;const Ie=await Xe({action:"move",account:te,slot:Ae},`move-${te}`),Me=sF({menuFor:((De=V.current)==null?void 0:De.num)??null,shareFor:(O==null?void 0:O.num)??null},te,Ie);if(await Ee(!0),Me){((dt=V.current)==null?void 0:dt.num)===te&&tt(),W(Me.confirmRemove),Me.shareFor==null&&(F(null),U(!1)),de(Me.swapNote);const Tt=Me.swapNote;Tt&&window.setTimeout(()=>de(vt=>vt===Tt?null:vt),f8),ge(null),ke(Me.menuFor)}return Ie},kt=async(te,Ae,Ie)=>{if(!Ie.sends){ze(te);return}await gt(te,Ae)},jn=async(te,Ae)=>{if(Ae.sends){const Ie=await Ze({action:"setting",key:"autoswitch.threshold",value:te},"threshold");if(await Ee(!0),!(Ie!=null&&Ie.ok))return;Ue(null)}Pe(!0),window.setTimeout(()=>{var Ie;document.activeElement===nt.current&&((Ie=Se.current)==null||Ie.focus()),Pe(!1)},p8)},En=l.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close accounts panel",title:"Close (A)",children:l.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:l.jsx("path",{d:"M3.4 3.4l7.2 7.2M10.6 3.4l-7.2 7.2"})})});return l.jsxs("aside",{className:`accounts-panel${t?" leaving":""}`,id:"accounts-panel","aria-label":"Claude accounts",children:[N==="accounts"&&l.jsxs("div",{className:"ap-header",children:[l.jsx("h2",{children:"Claude accounts"}),l.jsxs("div",{className:"ap-header-right",children:[l.jsx("button",{type:"button",className:"glyph-btn ap-add",onClick:()=>X(!0),"aria-label":"Add an account",title:"Sign in to another Claude account, or paste one shared from another deck",children:l.jsx("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round","aria-hidden":!0,children:l.jsx("path",{d:"M7 2.2v9.6M2.2 7h9.6"})})}),(((Ft=n==null?void 0:n.accounts)==null?void 0:Ft.length)??0)>0&&l.jsx("button",{type:"button",className:"glyph-btn",onClick:()=>z(!0),"aria-label":"Share accounts with another deck",title:`Copy several accounts to another ${Zt} in one paste. The text carries a live login for each one — treat it as those passwords.`,children:l.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:[l.jsx("path",{d:"M3.3 10.7L10.7 3.3"}),l.jsx("path",{d:"M5.5 3.3h5.2v5.2"})]})}),l.jsx("button",{type:"button",className:"glyph-btn ap-refresh",onClick:()=>Ee(!0),...ce("reload",f),"aria-label":"Reload accounts",title:"Reload from claude-swap",children:l.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:[l.jsx("path",{d:"M11.6 6.2A4.8 4.8 0 1 0 11 9.6"}),l.jsx("path",{d:"M11.9 2.6v3.7h-3.6"})]})}),En]})]}),N==="accounts"&&l.jsx("div",{className:"ap-scroll",id:"ap-scroll",children:n==null?h?l.jsxs("div",{className:"ap-empty",role:"alert",children:[l.jsx("span",{title:h.raw||void 0,children:h.text}),l.jsxs("span",{className:"ap-hint",children:["No accounts have arrived, so there is nothing to show yet. The panel keeps trying every ",S_/1e3," seconds."]}),l.jsx("button",{type:"button",className:"ap-fix",disabled:f,onClick:()=>Ee(!0),children:f?"trying…":"try again"})]}):l.jsx("div",{className:"ap-empty",children:"Checking…"}):n.ok?l.jsxs(l.Fragment,{children:[Be&&(et==null?void 0:et.tone)==="warn"&&l.jsxs("div",{className:"ap-notice",children:[l.jsxs("button",{type:"button",id:"ap-notice",className:"ap-issue","data-tone":"warn","aria-haspopup":"dialog","aria-expanded":(j==null?void 0:j.anchor)==="ap-notice","aria-controls":(j==null?void 0:j.anchor)==="ap-notice"?"ap-issue-pop":void 0,onClick:()=>lt(Be.num,"ap-notice"),children:[l.jsx(yp,{}),l.jsx("span",{className:"ap-issue-text",children:"Current account needs attention"})]}),et.fix&&l.jsx("button",{type:"button",className:"ap-notice-fix",onClick:()=>X(!0),title:"Open the sign-in dialog. Signing in as this account replaces its stored login in place.",children:"Sign in"})]}),l.jsx("ul",{className:"ap-list",children:(Kn=n.accounts)==null?void 0:Kn.map(te=>{const{shown:Ae,fuller:Ie}=lF(te.lanes),Me=gp(te,T),De=te.active||je.includes(Qx(te)),dt=te.alias??te.email??`account ${te.num}`,Tt=te.stale||(Me==null?void 0:Me.blocksSwitch)===!0,vt=Ie?[...Ae,Ie]:Ae,Qr=te.fetchedAt?mp(te.fetchedAt,T):null;return l.jsxs("li",{className:`ap-account${te.active?" active":""}`,"aria-current":te.active?"true":void 0,"data-open":De?"":void 0,"data-frozen":Tt?"":void 0,children:[!te.active&&l.jsx("button",{type:"button",className:"ap-row-open",id:`ap-row-${te.num}`,"aria-expanded":De,"aria-controls":De?`ap-detail-${te.num}`:void 0,"aria-describedby":!De&&!(Me!=null&&Me.blocksSwitch)?`ap-quota-${te.num}`:void 0,onClick:()=>be(_t=>uF(_t,te)),children:l.jsxs("span",{className:"vis-hidden",children:[dt,", ",De?"hide details":"details"]})}),l.jsxs("div",{className:"ap-account-head",children:[te.active?l.jsx("span",{className:"ap-live",title:`Active account · slot ${te.num}`,children:l.jsxs("span",{className:"vis-hidden",children:["Active account, slot ",te.num,":"]})}):l.jsx("span",{className:"ap-num",children:te.num}),te.alias&&l.jsx("span",{className:"ap-alias",title:te.alias,children:te.alias}),l.jsx("span",{className:"ap-email",title:te.email??void 0,children:te.email}),te.disabled&&l.jsx("span",{className:"ap-held",children:"held out"}),!te.active&&!te.disabled&&!(Me!=null&&Me.blocksSwitch)&&l.jsx("button",{type:"button",className:"ap-switch",...ce(`switch-${te.num}`),onClick:()=>pt(te.num,dt),"aria-label":`Switch to ${dt}`,title:`Switch to ${te.alias??te.email}`,children:c===`switch-${te.num}`?"…":"Switch"}),l.jsx("button",{type:"button",id:`ap-more-${te.num}`,className:"ap-more","aria-label":`More actions for ${te.email??te.alias??`account ${te.num}`}`,"aria-haspopup":"menu","aria-expanded":$===te.num,"aria-controls":$===te.num?`ap-menu-${te.num}`:void 0,title:"More actions",onClick:()=>$===te.num?ze():rt(te.num),onKeyDown:_t=>{_t.key!=="ArrowDown"&&_t.key!=="ArrowUp"||(_t.preventDefault(),rt(te.num,_t.key==="ArrowUp"?"last":"first"))},children:l.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 14 14",fill:"currentColor","aria-hidden":!0,children:[l.jsx("circle",{cx:"2.8",cy:"7",r:"1.15"}),l.jsx("circle",{cx:"7",cy:"7",r:"1.15"}),l.jsx("circle",{cx:"11.2",cy:"7",r:"1.15"})]})})]}),(h==null?void 0:h.row)===te.num&&l.jsxs("div",{className:"ap-failure ap-row-failure",role:"alert",children:[l.jsx("span",{className:"ap-failure-text",title:h.raw||void 0,children:h.text}),l.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),te.active&&(y==null?void 0:y.num)===te.num&&l.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)===te.num&&(()=>{var rn;const _t=(rn=n.accounts)==null?void 0:rn.find(Pr=>Pr.num===re.displaced),Jt=(_t==null?void 0:_t.alias)??(_t==null?void 0:_t.email)??"the account that was there";return l.jsxs("p",{className:"ap-note ap-swap-note",title:`Slot ${re.at} was taken, so the two accounts traded places: ${Jt} now holds slot ${re.displaced}.`,children:["swapped with slot ",re.displaced]})})(),Me&&l.jsxs("div",{className:"ap-issue-line",children:[l.jsxs("button",{type:"button",id:`ap-issue-${te.num}`,className:"ap-issue","data-tone":Me.tone,"aria-haspopup":"dialog","aria-expanded":(j==null?void 0:j.anchor)===`ap-issue-${te.num}`,"aria-controls":(j==null?void 0:j.anchor)===`ap-issue-${te.num}`?"ap-issue-pop":void 0,onClick:()=>lt(te.num,`ap-issue-${te.num}`),children:[Me.tone==="warn"&&l.jsx(yp,{}),l.jsx("span",{className:"ap-issue-text",children:Me.text})]}),!De&&l.jsx("span",{className:"ap-issue-age",title:"When claude-swap last read this account's usage",children:Qr??"never collected"})]}),!De&&!(Me!=null&&Me.blocksSwitch)&&l.jsxs("p",{className:"ap-quota",id:`ap-quota-${te.num}`,children:[vt.length?vt.map(_t=>l.jsxs("span",{className:"ap-q",children:[l.jsx("span",{className:"ap-q-label",children:_t.label})," ",l.jsxs("span",{className:"ap-q-pct","data-level":Tt?void 0:x8(_t.pct),children:[Math.round(_t.pct),"%"]})]},_t.id)):l.jsx("span",{className:"ap-q-label",children:"no usage recorded yet"}),te.stale&&!Me&&l.jsx("span",{className:"ap-q-age","data-never":Qr?void 0:"",title:"When claude-swap last read this account's usage",children:Qr??"never collected"})]}),De&&l.jsxs("div",{className:"ap-detail",id:`ap-detail-${te.num}`,children:[l.jsx("div",{className:"ap-lanes",children:te.lanes.length?te.lanes.map(_t=>l.jsx(k8,{lane:_t,nowSec:T,frozen:Tt},_t.id)):l.jsx("div",{className:"ap-hint",children:"No usage recorded yet."})}),l.jsx("div",{className:"ap-meta",children:te.fetchedAt?l.jsxs("span",{className:`ap-age${te.stale&&!Me?" 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 ",mp(te.fetchedAt,T),Me!=null&&Me.blocksSwitch?"":g8(te.nextAt,T)]}):l.jsx("span",{className:"ap-age ap-stale",title:"claude-swap has not read this account yet",children:"never collected"})})]})]},te.num)})}),L&&(()=>{var Me;const te=(Me=n.accounts)==null?void 0:Me.find(De=>De.num===L.num);if(!te)return null;const Ae=`ap-pop-title-${te.num}`,Ie=Q&&l.jsx("p",{className:"ap-pop-error",role:"alert",title:Q.raw||void 0,children:Q.text});return l.jsxs(d_,{anchorId:`ap-more-${te.num}`,boundaryId:"ap-scroll",id:`ap-menu-${te.num}`,className:"ap-pop",role:L.view==="menu"?"menu":"dialog",labelledBy:L.view==="menu"?`ap-more-${te.num}`:Ae,start:L.start,onClose:tt,children:[L.view==="menu"&&l.jsxs(l.Fragment,{children:[l.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{P(te.alias??""),J(null),H({num:te.num,view:"rename"})},children:"Rename"}),l.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",onClick:()=>{ge(null),J(null),H({num:te.num,view:"move"})},children:"Move to slot…"}),l.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",...ce(`share-${te.num}`),title:`Copy this account to another ${Zt}. 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:()=>Dt(te.num),children:c===`share-${te.num}`?"Sharing…":"Share"}),(((a==null?void 0:a.enabled)||(a==null?void 0:a.external))&&!te.active||te.disabled)&&l.jsx("button",{type:"button",role:"menuitem",className:"ap-menu-item",...ce(`rot-${te.num}`),title:te.disabled?"Return this account to auto-rotation":"Hold this account out of auto-rotation",onClick:()=>Ze({action:"account",account:te.num,enabled:te.disabled},`rot-${te.num}`,"menu").then(De=>{Ee(!0),De!=null&&De.ok&&ze(te.num)}),children:te.disabled?"Put back in rotation":"Hold out of rotation"}),l.jsx("div",{role:"separator",className:"ap-menu-sep"}),l.jsx("button",{type:"button",role:"menuitem",className:`ap-menu-item danger${B===te.num?" armed":""}`,...ce(`rm-${te.num}`),"aria-label":B===te.num?"Confirm remove":void 0,title:B===te.num?"This deletes the stored credentials for this account":"Remove this account from claude-swap",onClick:()=>{if(B!==te.num){W(te.num),Y.current=Date.now(),window.setTimeout(()=>W(De=>De===te.num?null:De),4e3);return}Date.now()-Y.current<qd||(W(null),Xe({action:"remove",account:te.num},`rm-${te.num}`).then(De=>{var dt;Ee(!0),De!=null&&De.ok&&(((dt=V.current)==null?void 0:dt.num)===te.num&&tt(),ke(null))}))},children:c===`rm-${te.num}`?"Removing…":B===te.num?"Confirm":"Remove"}),Ie]}),L.view==="rename"&&l.jsxs("form",{className:"ap-pop-form",onSubmit:De=>{De.preventDefault(),me(te.num,te.alias)},children:[l.jsx("label",{className:"ap-pop-title",id:Ae,htmlFor:`ap-alias-${te.num}`,children:"Rename account"}),l.jsx("input",{id:`ap-alias-${te.num}`,className:"ap-manage-input",type:"text",value:G,onChange:De=>P(De.target.value),maxLength:hF,placeholder:"e.g. work",spellCheck:!1,autoComplete:"off",autoFocus:!0,onFocus:De=>De.currentTarget.select()}),Ie,l.jsxs("div",{className:"ap-pop-actions",children:[l.jsx("button",{type:"button",className:"btn",onClick:()=>ze(),children:"Cancel"}),l.jsx("button",{type:"submit",className:"btn primary",...ce(`alias-${te.num}`),title:"A short name to show instead of the email",children:c===`alias-${te.num}`?"…":"Save"})]})]}),L.view==="move"&&(()=>{const De=rF((n.accounts??[]).map(vt=>vt.num),te.num),dt=aF(De,pe,te.num),Tt=oF(De,dt,te.num);return l.jsxs("div",{className:"ap-pop-form",children:[l.jsx("label",{className:"ap-pop-title",id:Ae,htmlFor:`ap-slot-${te.num}`,children:"Move to slot"}),l.jsx("span",{className:"ap-field",children:l.jsx("select",{id:`ap-slot-${te.num}`,value:String(dt),...ce(`move-${te.num}`),onChange:vt=>ge(Number(vt.target.value)),autoFocus:!0,children:De.map(vt=>l.jsx("option",{value:vt.slot,children:vt.label},vt.slot))})}),Ie,l.jsxs("div",{className:"ap-pop-actions",children:[l.jsx("button",{type:"button",className:"btn",onClick:()=>ze(),children:"Cancel"}),l.jsx("button",{type:"button",className:"btn primary",...ce(`move-${te.num}`),title:Tt.title,onClick:()=>kt(te.num,dt,Tt),children:c===`move-${te.num}`?"…":ec(Tt.label)})]})]})})(),L.view==="share"&&(O==null?void 0:O.num)===te.num&&(()=>{const De=IA(O.expiresAt,T),dt=De.tone==="gone";return l.jsxs("div",{className:`ap-pop-form ap-share${dt?" expired":""}`,children:[l.jsx("p",{className:"ap-pop-title",id:Ae,children:"Share account"}),l.jsx("code",{className:"ap-share-blob",children:O.blob}),l.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:[l.jsx("span",{className:"ap-share-warn",children:"This is the password"})," · ",l.jsx("span",{className:`ap-share-expiry ${De.tone}`,children:De.text})]}),Ie,l.jsxs("div",{className:"ap-pop-actions",children:[l.jsx("button",{type:"button",className:"btn",onClick:()=>ze(),children:"Done"}),l.jsx("button",{type:"button",className:"btn primary",...ce(`share-${te.num}`),autoFocus:!0,onClick:async()=>{if(dt){await Dt(te.num);return}await j_(O.blob)&&(U(!0),window.setTimeout(()=>U(!1),1800))},children:dt?"Make a new share":Z?"Copied":"Copy"})]})]})})()]})})(),j&&(()=>{var Ie;const te=(Ie=n.accounts)==null?void 0:Ie.find(Me=>Me.num===j.num),Ae=te?gp(te,T):null;return!te||!Ae?null:l.jsx(d_,{anchorId:j.anchor,boundaryId:"ap-scroll",id:"ap-issue-pop",className:"ap-pop ap-issue-pop",role:"dialog",labelledBy:"ap-issue-title",onClose:()=>bt(),children:l.jsxs("div",{className:"ap-pop-form",children:[l.jsxs("p",{className:"ap-pop-title ap-issue-title",id:"ap-issue-title","data-tone":Ae.tone,children:[Ae.tone==="warn"&&l.jsx(yp,{}),Ae.text]}),l.jsx("p",{className:"ap-pop-note ap-issue-hint",children:Ae.hint}),l.jsxs("p",{className:"ap-pop-note ap-issue-when",children:[l.jsx("span",{className:"ap-issue-who",children:te.alias??te.email??`account ${te.num}`})," · ",te.fetchedAt?`last collected ${mp(te.fetchedAt,T)}`:"never collected"]}),l.jsxs("div",{className:"ap-pop-actions",children:[l.jsx("button",{type:"button",className:"btn",onClick:()=>bt(!0),children:"Done"}),Ae.fix&&l.jsx("button",{type:"button",className:"btn primary",onClick:()=>{bt(!0),X(!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:Ae.fix})]})]})})})()]}):l.jsx("div",{className:"ap-empty",children:n.reason==="no_cswap"?l.jsxs(l.Fragment,{children:[l.jsx("span",{children:"claude-swap isn't installed."}),l.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&&l.jsx("code",{className:"ap-cmd",children:n.hint}),l.jsxs("span",{className:"ap-hint",children:["Then add an account with the ",l.jsx("strong",{children:"+"})," button above."]})]}):n.reason==="no_accounts"?l.jsxs(l.Fragment,{children:[l.jsx("span",{children:"No accounts added yet."}),l.jsxs("span",{className:"ap-hint",children:["claude-swap is installed but has nothing in its store. Use the ",l.jsx("strong",{children:"+"})," above to sign one in, or to paste one shared from another deck."]})]}):l.jsxs(l.Fragment,{children:[l.jsx("span",{children:"Couldn't read the account store."}),l.jsxs("span",{className:"ap-hint",children:["claude-swap is installed, but its store could not be read",n.reason?` (${n.reason})`:"","."]})]})})}),N==="accounts"&&n!=null&&h&&h.row==null&&l.jsxs("div",{className:"ap-failure",role:"alert",children:[l.jsx("span",{className:"ap-failure-text",title:h.raw||void 0,children:h.text}),l.jsx("button",{type:"button",className:"ap-failure-x",onClick:()=>m(null),"aria-label":"Dismiss this message",title:"Dismiss",children:"×"})]}),N==="accounts"&&(n==null?void 0:n.ok)&&(a==null?void 0:a.ok)&&l.jsxs("div",{className:"ap-foot",children:[l.jsxs("div",{className:"ap-policy",children:[l.jsx("h3",{className:"ap-auto-title",children:"Auto-switch"}),l.jsx("span",{className:"ap-field",title:"Switch once the active account passes this much of its limit",children:l.jsx("select",{ref:Se,"aria-label":"Switch threshold",value:ee,...ce("threshold"),onChange:te=>Ue(te.target.value),children:b8(ut).map(te=>l.jsxs("option",{value:te,children:[te,"%"]},te))})}),(Ne.sends||He)&&l.jsx("button",{ref:nt,type:"button",className:"ap-manage-btn",...ce("threshold"),title:Ne.title,onClick:()=>jn(ee,Ne),children:He&&!Ne.sends?Ne.done:Ne.label}),l.jsx("button",{type:"button",className:"switch ap-auto-state",role:"switch","aria-checked":a.enabled,"aria-label":"Auto-switch",...ce("enable"),onClick:()=>Ze({action:"enable",enabled:!a.enabled},"enable").then(()=>Ee(!0)),title:a.enabled?"Stop switching accounts automatically":"Switch accounts automatically when the active one nears its limit",children:l.jsx("span",{className:"switch-knob"})})]}),a.external&&l.jsxs("p",{className:"ap-auto-note",children:[l.jsx("i",{className:"ap-pulse","aria-hidden":!0})," A ",l.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.":"."]})]}),l.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:y?`Now active: ${y.name}`:""}),S&&l.jsx(h8,{accounts:((n==null?void 0:n.accounts)??[]).map(te=>({key:`${String(te.email??"").trim().toLowerCase()}@@${te.orgUuid??""}`,email:te.email??"",alive:te.alive===!0})),onChanged:()=>Ee(!0),view:N==="lan",onOpen:st,onBack:()=>_("accounts"),closeButton:En}),M&&l.jsx(Xq,{onClose:()=>X(!1),onChanged:()=>Ee(!0)}),oe&&l.jsx(nF,{accounts:((n==null?void 0:n.accounts)??[]).map(te=>({num:te.num,email:te.email,alias:te.alias,org:te.org})),onClose:()=>z(!1),copyText:j_})]})}const N8=3e4;function S8({bundle:e,running:t,lastTried:n}){return!t||e===t?!1:n!==t}function j8({bundle:e,running:t,pending:n,lastTried:s}){return t?S8({bundle:e,running:t,lastTried:s})?"reload":n==null||n&&n!==t?"wait":"confirm":"wait"}function E8(e){return!e||e.state!=="failed"?null:`${typeof e.at=="number"?e.at:0}:${e.error??""}`}function C8({asked:e,reported:t}){return t?t!==e:!1}function FA(e){const t=e.thresholdMs??N8;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 T8(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 A8(e,t){return e?t==null?"auto when idle":`auto in ${T8(t)}`:"auto-restart off"}function E_(e){let t=0;for(const n of e)n.state==="active"&&t++;return t}function R8(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 M8(e){const t=FA(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 I8(e,t){return e==="confirmation"?t.confirmOpen?"clear":"ignore":t.modalOpen||t.confirmOpen?"ignore":"confirm"}function $8(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 O8(e){return e<=0?null:e===1?"the one agent":`all ${e} agents`}function P8(e,t){const n=O8(e),s=(...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:s("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:s(),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:s(),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:s("this deck's event log — the file a restarted deck replays to rebuild what you see"),stays:[],final:a,confirm:"Clear everything"};const i=t.decks-1;return{goes:s(`the event log ${i===1?"1 other running deck shares":`${i} other running decks share`} with this one — every session recorded in it, not just the ones drawn here`),stays:[i===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 L8({agentCount:e,onConfirm:t,onCancel:n}){const s=x.useRef(null),a=dn(n,{focusRef:s,layer:o5}),[i,c]=x.useState(null);x.useEffect(()=>{let m=!1;return fetch("/api/clear").then(y=>y.ok?y.json():null).then(y=>{m||c($8(y))}).catch(()=>{}),()=>{m=!0}},[]);const{goes:u,stays:f,final:p,confirm:h}=P8(e,i);return l.jsx("div",{className:"modal-backdrop",onClick:n,role:"presentation",children:l.jsxs("div",{ref:a,className:"modal clear-confirm",onClick:m=>m.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"clear-confirm-title",children:[l.jsxs("header",{className:"modal-head",children:[l.jsxs("div",{className:"modal-title",children:[l.jsx("span",{className:"status-dot err","aria-hidden":!0}),l.jsx("span",{id:"clear-confirm-title",className:"modal-tool-name",children:"Clear the deck?"})]}),l.jsx("div",{className:"modal-actions",children:l.jsx("button",{type:"button",className:"glyph-btn",onClick:n,"aria-label":"Cancel (Esc)",title:"Cancel (Esc)",children:"×"})})]}),l.jsxs("section",{className:"modal-body",children:[l.jsxs("dl",{className:"cc-plan",children:[l.jsx("dt",{children:"Goes"}),l.jsx("dd",{children:u.map(m=>l.jsx("span",{children:m},m))}),l.jsx("dt",{children:"Stays"}),l.jsx("dd",{children:f.length>0?f.map(m=>l.jsx("span",{children:m},m)):l.jsx("span",{children:"nothing"})})]}),p&&l.jsx("p",{className:"cc-final",children:p}),l.jsxs("div",{className:"cc-actions",children:[l.jsx("button",{type:"button",ref:s,className:"btn",onClick:n,children:"Cancel"}),l.jsx("button",{type:"button",className:"btn danger",onClick:t,children:h})]})]})]})})}const D8="Press Esc first if a key does nothing.",q8=[{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:"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:"the topbar speaker opens volume and sound settings",binds:[]}]}];function F8({onClose:e,onTour:t}){const n=dn(e);return l.jsx("div",{className:"modal-backdrop",onClick:e,role:"presentation",children:l.jsxs("div",{ref:n,className:"modal key-help",onClick:s=>s.stopPropagation(),role:"dialog","aria-modal":"true","aria-labelledby":"key-help-title",children:[l.jsxs("header",{className:"modal-head",children:[l.jsx("div",{className:"modal-title",children:l.jsx("span",{id:"key-help-title",className:"modal-tool-name",children:"Keyboard shortcuts"})}),l.jsx("div",{className:"modal-actions",children:l.jsx("button",{type:"button",className:"glyph-btn",onClick:e,"aria-label":"Close (Esc)",title:"Close (Esc)",children:"×"})})]}),l.jsxs("section",{className:"modal-body",children:[t&&l.jsxs("div",{className:"guide-door",children:[l.jsx("span",{children:"Eight pictures of what the deck shows."}),l.jsx("button",{type:"button",className:"btn",onClick:t,children:"Take the tour"})]}),l.jsx("div",{className:"shortcuts",children:q8.map(s=>l.jsxs(x.Fragment,{children:[l.jsx("h3",{className:"kh-group",children:s.title}),s.rows.map(a=>l.jsxs("div",{className:"sc",children:[l.jsx("kbd",{children:a.cap}),l.jsx("span",{children:a.action})]},`${s.title}:${a.cap}:${a.action}`))]},s.title))}),l.jsx("p",{className:"kh-foot",children:D8})]})]})})}const B8=["done","needs-input"],z8=[{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}]}],U8=[{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}]}],r0={done:z8,"needs-input":U8},zi="two";function px(e,t){const n=r0[e];return n.find(s=>s.id===t)??n.find(s=>s.id===zi)??n[0]}function BA(e,t){return r0[e].some(s=>s.id===t)?t:zi}px("done",zi).notes,px("needs-input",zi).notes;const C_=.04,W8=.24,xd=0,Bd=100,mx=5,yc=50;function wc(e){if(!Number.isFinite(e))return yc;const t=Math.round(e/mx)*mx;return Math.min(Bd,Math.max(xd,t))}function H8(e){if(e==null)return yc;const t=e.trim();return/^-?\d+(\.\d+)?$/.test(t)?wc(Number(t)):yc}function G8(e){const t=wc(e),n=C_+(W8-C_)*(t/Bd);return Math.round(n*1e4)/1e4}function V8(e,t){const n=t.trim,s=typeof n=="number"&&Number.isFinite(n)&&n>0&&n<=1?n:1;return Math.round(G8(e)*s*1e4)/1e4}const Y8=160,K8="agent-dag.soundLevel.done",X8="agent-dag.soundLevel.needs-input",Z8="agent-dag.soundFigure.done",Q8="agent-dag.soundFigure.needs-input",zA={done:K8,"needs-input":X8},UA={done:Z8,"needs-input":Q8},gx={done:{level:yc,figure:zi},"needs-input":{level:yc,figure:zi}};function J8(e){const t=n=>({level:H8(e(zA[n])),figure:BA(n,e(UA[n]))});return{done:t("done"),"needs-input":t("needs-input")}}const T_={Stop:"done",Notification:"needs-input"};function eB(e,t){var s;if(t)return null;const n=(s=e==null?void 0:e.payload)==null?void 0:s.hook_event_name;return typeof n!="string"?null:Object.hasOwn(T_,n)?T_[n]:null}function tB(e={enabled:()=>!0}){const t=e.ctor??(typeof window<"u"?window.AudioContext??window.webkitAudioContext??null:null);let n=null,s=!1;const a=()=>e.enabled()?s&&(n==null?void 0:n.state)==="running"?"ready":"locked":"off",i=()=>{var f;return(f=e.onState)==null?void 0:f.call(e,a())};function c(){var f;if(!(!t||s))try{n=n??new t,(f=n.resume)==null||f.call(n).then(i,()=>{}),s=!0,i()}catch{}}function u(f,p=!1){var N;if(!p&&!e.enabled()||!n||n.state!=="running")return!1;const h=(((N=e.prefs)==null?void 0:N.call(e))??gx)[f]??gx[f],m=px(f,h.figure),y=V8(h.level,m),w=n.currentTime;for(const _ of m.notes){const S=n.createOscillator(),b=n.createGain();S.type=m.type??"sine",S.frequency.value=_.hz;const j=w+_.at,E=j+_.ms/1e3;b.gain.setValueAtTime(1e-4,j),b.gain.exponentialRampToValueAtTime(y,j+.012),b.gain.exponentialRampToValueAtTime(1e-4,E),S.connect(b).connect(n.destination),S.start(j),S.stop(E+.02)}return!0}return{unlock:c,play:u,state:a,get context(){return n}}}const nB="Notify me when a session needs my attention.",rB="Held off for this run — the deck was started with alerts disabled. Your choice is saved for the next start.",A_="Get notified when you're away from this tab.";function sB(e){switch(e){case"granted":return{status:"Enabled",ask:!1,ok:!0,note:A_};case"default":return{status:null,ask:!0,ok:!1,note:A_};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."}}}const R_={done:"Turn finished","needs-input":"Claude is asking"},aB={done:"Plays when Claude or Codex finishes a turn.","needs-input":"Available in Claude Code only."};function oB({onClose:e,soundOn:t,onToggleSound:n,prefs:s,onLevel:a,onFigure:i,onPreview:c,openerRef:u,notifyOn:f,onToggleNotify:p,notifyVetoed:h,notifyPermission:m,onAskNotify:y}){const w=sB(m),N=f&&!h,_=dn(e),S=x.useRef(e);return S.current=e,x.useEffect(()=>{const b=j=>{var C,T;const E=j.target;E&&((C=_.current)!=null&&C.contains(E)||(T=u.current)!=null&&T.contains(E)||S.current())};return window.addEventListener("pointerdown",b,!0),()=>window.removeEventListener("pointerdown",b,!0)},[_,u]),l.jsxs("div",{ref:_,id:"sound-menu",className:"sound-menu",role:"dialog","aria-label":"Sound settings",children:[l.jsxs("div",{className:"sm-switches",children:[l.jsxs("label",{className:"sm-switch",children:[l.jsx("span",{className:"sm-switch-label",id:"sm-sound-label",children:"Sounds"}),l.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:l.jsx("span",{className:"switch-knob"})})]}),l.jsxs("div",{className:"sm-setting",children:[l.jsxs("label",{className:"sm-switch",children:[l.jsx("span",{className:"sm-switch-label",id:"sm-notify-label",children:"Notifications"}),l.jsx("button",{type:"button",role:"switch","aria-checked":f,"aria-labelledby":"sm-notify-label",className:"switch",onClick:p,title:"A system notification when a session blocks on you",children:l.jsx("span",{className:"switch-knob"})})]}),l.jsx("p",{className:"sm-note",children:h?rB:nB})]})]}),N&&l.jsxs("section",{className:"sm-channel","aria-labelledby":"sm-channel-name",children:[l.jsxs("div",{className:"sm-channel-head",children:[l.jsx("h3",{className:"sm-channel-name",id:"sm-channel-name",children:"Browser notifications"}),w.ask?l.jsx("button",{type:"button",className:"btn sm-channel-action",onClick:y,children:"Enable"}):l.jsxs("span",{className:"sm-channel-state","data-ok":w.ok||void 0,children:[w.ok&&l.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:l.jsx("path",{d:"M1.5 5.2 3.9 7.6 8.5 2.4"})}),w.status]})]}),l.jsx("p",{className:"sm-note",children:w.note})]}),!t&&l.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."}),l.jsx("div",{className:"sm-tones",children:B8.map(b=>{const j=s[b],E=`sm-level-${b}`,C=`sm-figure-${b}`;return l.jsxs("section",{className:"sm-tone","aria-labelledby":`sm-name-${b}`,children:[l.jsxs("div",{className:"sm-tone-head",children:[l.jsx("h3",{className:"sm-tone-name",id:`sm-name-${b}`,children:R_[b]}),l.jsxs("button",{type:"button",className:"btn sm-hear",onClick:()=>c(b),"aria-label":`Hear the ${R_[b].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:[l.jsx("svg",{width:"11",height:"11",viewBox:"0 0 12 12",fill:"currentColor","aria-hidden":!0,children:l.jsx("path",{d:"M3 1.6v8.8l7-4.4z"})}),"Hear it"]})]}),l.jsxs("div",{className:"sm-row",children:[l.jsx("label",{htmlFor:E,children:"Volume"}),l.jsx("input",{id:E,type:"range",min:xd,max:Bd,step:mx,value:j.level,onChange:T=>a(b,Number(T.target.value)),style:{"--sm-level":`${(j.level-xd)/(Bd-xd)*100}%`}}),l.jsxs("span",{className:"sm-read",children:[j.level,"%"]})]}),l.jsxs("div",{className:"sm-row",children:[l.jsx("label",{htmlFor:C,children:"Tone"}),l.jsx("select",{id:C,className:"sm-select",value:j.figure,onChange:T=>i(b,T.target.value),children:r0[b].map(T=>l.jsx("option",{value:T.id,children:T.label},T.id))})]}),l.jsx("p",{className:"sm-note",children:aB[b]})]},b)})}),l.jsxs("p",{className:"sm-foot",children:[l.jsx("kbd",{children:"M"}),"Mute or unmute sounds anywhere."]})]})}const iB=15e3;function lB(e){return e.visibilityState==="visible"&&e.hasFocus()}function cB(e,t){return t||e===!0}function uB(){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 dB={"//":["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.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
92
|
|
|
93
93
|
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.
|
|
94
94
|
|
|
@@ -286,7 +286,7 @@ Both CLIs get the finish tone. The second tone — Claude is waiting for you —
|
|
|
286
286
|
|
|
287
287
|
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+`
|
|
288
288
|
|
|
289
|
-
Click to set the volume and the sound of each tone, and to hear either one.`}function Wd(e){const t=Math.max(0,Math.floor(e));return`${t} event${t===1?"":"s"}`}const iT=99;function o7(e){const t=Math.max(0,Math.floor(e));return t>iT?`${iT}+`:String(t)}const i7="Pause the canvas";function l7(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 — ${Wd(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)":`${Wd(e.held)} arrived while paused and will be applied in order when you resume (Space)`}function c7(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 nM="paused · full",u7=(e,t)=>t>0?nM:e>0?`paused · ${o7(e)}`:"paused";function d7(e){const t=Math.max(0,Math.floor(e.dropped??0));return e.connected?e.paused?{tone:"paused",resting:!1,label:u7(e.held,t),widest:nM,title:t>0?`Connected — the pause is full at ${Wd(e.held)}; the oldest are being dropped as new ones arrive. Resume to catch up (Space)`:e.held>0?`Connected — ${Wd(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 h7=x.lazy(()=>vT(()=>import("./UsageHistoryModal-DEZjEWrd.js"),[])),f7=x.lazy(()=>vT(()=>import("./BrowserWatchModal-plr3Bmmv.js"),[]));function lT(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()||""}const p7={agent:q5,sessionGroup:y6,recapNote:v6},m7={recapTie:x6},g7=300,cT=130,y7=160,rM="react-flow__node";function uT(e){var t,n;return!!e&&((n=(t=e.classList)==null?void 0:t.contains)==null?void 0:n.call(t,rM))===!0}const Lv=80,Dv=.86;function dT(e){if(!e)return 0;const t=e.getBoundingClientRect();let n=t.right;for(const s of document.querySelectorAll(".sysdetail:not(.leaving), .usage-panel:not(.leaving)")){const a=s.getBoundingClientRect();a.width>0&&a.left>t.left&&(n=Math.min(n,a.left))}return Math.max(0,t.right-n)}function w7(e){try{const t=document.querySelector(`.${rM}[data-id="${CSS.escape(e)}"]`);t==null||t.focus({preventScroll:!0})}catch{}}const v7=["a[href]","button:not(:disabled)","input:not(:disabled)","select:not(:disabled)","textarea:not(:disabled)","summary","[tabindex]"].join(","),x7=420;function b7(e){return e<.35?"far":e<.55?"mid":"full"}const cd=18,k7=200,_7=5*6e4,N7=6,S7=2*6e4,hT=400,_0="agent-dag.layout",N0="agent-dag.layoutFrame",S0="agent-dag.viewport",sM="agent-dag.sessionListOpen",aM="agent-dag.detailOpen",oM="agent-dag.usagePanelOpen",iM="agent-dag.systemPanelOpen",fT="agent-dag.accountsPanelOpen",qv="agent-dag.versionNoticeDismissed",pT="agent-dag.oldNameNoticeDismissed",j7=15*6e4,Fv={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:"},ud="agent-dag.autoRestart",mT="agent-dag.bundleReloadedFor";function E7(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(sM)==="1"}catch{return!1}}function C7(e){if(!(typeof window>"u"))try{window.localStorage.setItem(sM,e?"1":"0")}catch{}}function T7(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(aM)==="1"}catch{return!1}}function A7(e){if(!(typeof window>"u"))try{window.localStorage.setItem(aM,e?"1":"0")}catch{}}function R7(){const e=vo(oM);return e===null?!0:e==="1"}function M7(e){if(!(typeof window>"u"))try{window.localStorage.setItem(oM,e?"1":"0")}catch{}}function I7(){const e=vo(iM);return e===null?!0:e==="1"}function $7(e){if(!(typeof window>"u"))try{window.localStorage.setItem(iM,e?"1":"0")}catch{}}function O7(){const e={positions:[],pins:[]};if(typeof window>"u")return e;try{const t=window.localStorage.getItem(_0);if(!t)return e;const n=JSON.parse(t);if(!("v"in n)){const a=Object.entries(n).filter(([,i])=>i&&typeof i.x=="number"&&typeof i.y=="number");return{positions:a,pins:a.map(([i])=>i)}}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 dd(e,t){if(!(typeof window>"u"))try{const n={};for(const[s,a]of e)n[s]=a;for(const[s,a]of t)n[s]=a;window.localStorage.setItem(_0,JSON.stringify({v:2,positions:n,pins:Array.from(t.keys())}))}catch{}}function P7(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(N0);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 L7(e){if(!(typeof window>"u"))try{window.localStorage.setItem(N0,JSON.stringify(e))}catch{}}function D7(){if(typeof window>"u")return null;try{return UH(window.localStorage.getItem(S0))}catch{return null}}function q7(e){if(!(typeof window>"u"))try{window.localStorage.setItem(S0,JSON.stringify(e))}catch{}}function gT(){if(!(typeof window>"u")){try{window.localStorage.removeItem(_0)}catch{}try{window.localStorage.removeItem(S0)}catch{}try{window.localStorage.removeItem(N0)}catch{}}}function F7(e,t){const n=e.agents.get(t);if(!n)return;const s=[];for(const h of e.agents.values())h.sessionId===t&&s.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:s.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}))}))},i=JSON.stringify(a,null,2),c=new Blob([i],{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=`${Zt}-${p}-${t.slice(0,8)}.json`,document.body.appendChild(f),f.click(),document.body.removeChild(f),setTimeout(()=>URL.revokeObjectURL(u),1e3)}const lM={file:"📁",shell:"⚡",web:"🌐",agent:"🤖",task:"📋",plan:"🧭",mcp:"🔌",other:"✨"},B7={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 z7({cat:e}){return l.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:l.jsx("path",{d:B7[e]})})}const Hd={file:"file",shell:"shell",web:"web",agent:"agent",task:"task",plan:"plan",mcp:"mcp",other:"other"},cM=fA,yT=new WeakMap;function U7(e,t){let n=yT.get(e);(!n||n.revision!==e.revision||n.open!==t)&&(n={revision:e.revision,open:t,byId:new Map},yT.set(e,n));const{byId:s}=n;return a=>{let i=s.get(a.id);return i||(i={...a,onOpenContext:t},s.set(a.id,i)),i}}function uM(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 W7(e,t,n,s,a,i,c,u,f,p,h,m,y,w,N,_,S,b){var J,M,X,G;const j=[],E=[],C=U7(e,b);for(const P of e.agents.values()){if(!S.has(P.id))continue;const B=P.exitAt!=null,W=_!=null&&!_.has(P.id),Y=[B?"rf-exiting":"",W?"rf-spotlit-out":""].filter(Boolean).join(" ")||void 0,O=i.get(P.id);if(j.push({id:P.id,type:"agent",position:{x:0,y:0},data:C(P),className:Y,ariaLabel:z5(P,t),...O?{width:O.width,height:O.height}:null}),P.parentId&&S.has(P.parentId)){const z=Id(P.sessionId),Z=B,U=N.size>0&&(N.has(P.id)||N.has(P.parentId)),re=_!=null&&!_.has(P.id)&&!_.has(P.parentId),de=P.state==="active"?2:1.5,pe=U?de+1.5:de,ge=Z?.2:re?.12:1,Te=["sess-edge",P.state==="active"?"sess-live":"sess-idle",Z?"rf-edge-exiting":"",U?"rf-edge-selected":""].filter(Boolean).join(" ");E.push({id:`e:${P.parentId}->${P.id}`,source:P.parentId,target:P.id,animated:(P.state==="active"||U)&&!Z,type:"smoothstep",style:{"--session-hue":z,strokeWidth:pe,opacity:ge,transition:"var(--edge-transition)"},className:Te})}const F=P.kind==="root"?rh(P):null,oe=F?cA(P.sessionId,F.at):null;if(F&&oe&&!M5(oe)){const z=Hx(P.id),Z=Id(P.sessionId),U=i.get(z);j.push({id:z,type:"recapNote",position:{x:0,y:0},data:{sessionId:P.sessionId,parentId:P.id,recap:F,noteKey:oe,hue:Z},className:W?"rf-spotlit-out":void 0,selectable:!1,focusable:!1,ariaLabel:`Claude Code's recap for ${P.label}`,...U?{width:U.width,height:U.height}:null}),E.push({id:`e:recap:${P.id}`,source:z,target:P.id,type:"recapTie",className:"recap-edge",focusable:!1,style:{"--session-hue":Z}})}}const T=uM(e),R=`${y}#lanes:${jH(T)}`,I=new Set(j.filter(P=>P.type==="recapNote").map(P=>P.id));for(const P of Array.from(h.keys()))P5(P)&&!I.has(P)&&!a.has(P)&&(h.delete(P),m.delete(P));const L=j.filter(P=>qB(P.id,a,h,m));if(L.length>0||R!==w.current){if(L.length>0){const P=IH(AH(j,E,{direction:"LR",pinned:a,measured:i,availableWidth:n,availableHeight:s,lanes:T}),a,B=>bd(B,h,m)?void 0:h.get(B));for(const B of P)bd(B.id,h,m)&&O_(B.id,B.position,h,m);MH(j,h,a,i,new Set(L.filter(B=>B.type!=="recapNote").map(B=>B.id)),T,{width:n,height:s});for(const B of L){if(B.type!=="recapNote")continue;const W=(J=B.data)==null?void 0:J.parentId;if(!W)continue;const Y=a.get(W)??(bd(W,h,m)?void 0:h.get(W));if(!Y)continue;const O=((M=i.get(B.id))==null?void 0:M.width)??g7,F=((X=i.get(B.id))==null?void 0:X.height)??cT,oe=((G=i.get(W))==null?void 0:G.height)??cT;O_(B.id,{x:Y.x-y7-O,y:Y.y+(oe-F)/2},h,m)}}RH(j,h,a,i,T),w.current=R}const H=$H(j,h,a,i,c,!f||p,T);H.length>0&&u(H);const $=PB(e.agents.values());od(h,$),od(m,$),od(a,$),od(i,OB(e.agents.values()));const V=[];let Q=!1;for(const P of j){let B=a.get(P.id)??h.get(P.id);B||(B=FB(P.id,h,m),Q=!0),V.push({...P,position:B})}return Q&&(w.current=""),{nodes:V,edges:E}}function H7(){return l.jsx(Dx,{children:l.jsx(Y7,{})})}const G7=e=>e.transform[2]>=e.maxZoom,V7=e=>e.transform[2]<=e.minZoom;function Y7(){var _l,xt,Qo,Ua;const e=Sc(),t=wt(G7),n=wt(V7),s=Ht(),a=x.useState(rx)[0],i=x.useRef(a),[,c]=x.useState(0),u=x.useCallback(()=>c(D=>D+1),[]),[f,p]=x.useState(T7);x.useEffect(()=>{A7(f)},[f]);const[h,m]=x.useState(()=>new Set),[y,w]=x.useState(null),[N,_]=x.useState(null),S=x.useCallback((D,q)=>{m(ae=>{if(!q)return new Set([D]);const ie=new Set(ae);return ie.has(D)?ie.delete(D):ie.add(D),ie}),w(ae=>q&&ae===D?ae:D),q||p(!0)},[]),b=x.useCallback(()=>{m(new Set),w(null)},[]),[j,E]=x.useState(null),[C,T]=x.useState(null),R=x.useCallback(D=>T(D),[]),[I,L]=x.useState(!1),[H,$]=x.useState(!1),[V,Q]=x.useState(!1),J=x.useRef(null),[M,X]=x.useState(E7);x.useEffect(()=>{C7(M)},[M]);const[G,P]=x.useState(R7);x.useEffect(()=>{M7(G)},[G]);const[B,W]=x.useState(I7);x.useEffect(()=>{$7(B)},[B]);const Y=x.useRef(!1),[O,F]=x.useState(()=>{const D=(()=>{try{const q=window.localStorage.getItem(fT);return q===null?!0:q==="1"}catch{return!0}})();return D&&M?(Y.current=!0,!1):D});x.useEffect(()=>{if(!(!O&&Y.current))try{window.localStorage.setItem(fT,O?"1":"0")}catch{}},[O]),x.useEffect(()=>{!M&&Y.current&&(Y.current=!1,F(!0))},[M]);const oe=up(O,200),z=up(G,130),Z=up(B,130),[U,re]=x.useState(null);x.useEffect(()=>{let D=null;try{D=localStorage.getItem("agent-dag.sound")}catch{}re(D===null?!0:D==="on")},[]);const de=x.useCallback(()=>{re(D=>{var ae;const q=D!==!0;try{localStorage.setItem("agent-dag.sound",q?"on":"off")}catch{}return q&&((ae=Ye.current)==null||ae.unlock()),q})},[]),pe=x.useCallback(D=>{de()},[de]),ge=x.useRef(pe);ge.current=pe;const Te=x.useRef(U);Te.current=U;const[Ue,He]=x.useState(()=>J8(vo)),Pe=x.useRef(Ue);Pe.current=Ue;const Se=x.useRef(null),nt=x.useCallback((D,q=!1)=>{var ae,ie;if((ae=Ye.current)==null||ae.unlock(),Se.current!==null&&clearTimeout(Se.current),Se.current=null,!q){(ie=Ye.current)==null||ie.play(D,!0);return}Se.current=setTimeout(()=>{var Ce;Se.current=null,(Ce=Ye.current)==null||Ce.play(D,!0)},Y8)},[]),je=x.useCallback((D,q)=>{He(ae=>{const ie={level:wc(q.level??ae[D].level),figure:BA(D,q.figure??ae[D].figure)};try{localStorage.setItem(zA[D],String(ie.level)),localStorage.setItem(UA[D],ie.figure)}catch{}return{...ae,[D]:ie}}),nt(D,!0)},[nt]);x.useEffect(()=>()=>{Se.current!==null&&clearTimeout(Se.current)},[]);const[be,Ke]=x.useState(!1),ct=x.useRef(null),Ye=x.useRef(null),[ce,ke]=x.useState("locked");x.useEffect(()=>{const D=tB({enabled:()=>Te.current===!0,prefs:()=>Pe.current,onState:ke});Ye.current=D,ke(D.state());const q=()=>D.unlock();return window.addEventListener("pointerdown",q,{once:!0,capture:!0}),window.addEventListener("keydown",q,{once:!0,capture:!0}),()=>{window.removeEventListener("pointerdown",q,{capture:!0}),window.removeEventListener("keydown",q,{capture:!0})}},[]);const[Ee,Ze]=x.useState(!1),[Xe,ut]=x.useState(!1),[ee,Ne]=x.useState(null),[Be,et]=x.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(qv)??""}catch{return""}}),[pt,tt]=x.useState(!1),rt=x.useRef(0),[lt,bt]=x.useState(!1),st=x.useCallback((D=!1)=>(D&&(rt.current=Date.now(),bt(!0)),fetch(D?"/api/version?refresh=1":"/api/version").then(q=>q.ok?q.json():null).then(q=>{q&&Ne(q)}).catch(()=>{}).finally(()=>{D&&bt(!1)})),[]),mt=x.useCallback(()=>{st(Date.now()-rt.current>=j7)},[st]);x.useEffect(()=>{st();const D=window.setInterval(mt,5*6e4),q=()=>{document.visibilityState==="visible"&&mt()};return document.addEventListener("visibilitychange",q),()=>{window.clearInterval(D),document.removeEventListener("visibilitychange",q)}},[st,mt]),x.useEffect(()=>{Ee&&st()},[Ee,st]),x.useEffect(()=>{const D=uB();let q=null;const ae=We=>{fetch("/api/presence",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tab:D,looking:We}),keepalive:!0}).catch(()=>{})},ie=()=>{const We=lB(document);cB(q,We)&&ae(We),q=We},Ce=()=>{q&&ae(!1),q=!1};ie();const ve=window.setInterval(ie,iB);return window.addEventListener("focus",ie),window.addEventListener("blur",ie),document.addEventListener("visibilitychange",ie),window.addEventListener("pagehide",Ce),()=>{window.clearInterval(ve),window.removeEventListener("focus",ie),window.removeEventListener("blur",ie),document.removeEventListener("visibilitychange",ie),window.removeEventListener("pagehide",Ce),Ce()}},[]);const ze=(ee==null?void 0:ee.notice)??null,[Dt,me]=x.useState(null),gt=x.useRef(!1);x.useEffect(()=>{if(gt.current)return;const D=$_(),q=vB(D),ae=SB({stored:q,running:(ee==null?void 0:ee.running)??null,notes:I_,remembers:xB(D)});if(ae.reason==="no-version")return;gt.current=!0,ae.record&&bB(D,ae.record);const ie=NB({tourSeen:kB(D),decision:ae}),Ce=ae.show.length?{entries:ae.show,since:q,firstRun:!1}:null;ie.tour&&Q(!0),ie.notes==="now"?me(Ce):ie.notes==="after"&&(J.current=Ce)},[ee==null?void 0:ee.running]);const kt=(ee==null?void 0:ee.running)??"3.23.2",jn=x.useMemo(()=>WA(I_,null,kt),[kt]),En=x.useCallback(()=>{me({entries:jn,since:null,firstRun:!1})},[jn]),[Yn,qt]=x.useState(null),[Ft,Kn]=x.useState(vx);x.useEffect(()=>{let D=!1;return fetch("/api/health").then(q=>q.ok?q.json():null).then(q=>{D||(Kn(e7(q)),!(!q||typeof q.workspace!="string")&&qt(q.workspace))}).catch(()=>{}),()=>{D=!0}},[Ee]);const te=x.useRef(Ft);te.current=Ft;const Ae=ze?`${ze.kind}:${ze.to}`:"",Ie=ze!=null&&Be!==Ae,Me=x.useCallback(()=>{et("");try{window.localStorage.setItem(qv,"")}catch{}},[]),De=x.useCallback(()=>{if(ze){et(Ae);try{window.localStorage.setItem(qv,Ae)}catch{}}},[ze,Ae]),[dt,Tt]=x.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(pT)??""}catch{return""}}),vt=ee!=null&&ee.invokedAs&&ee.invokedAs!==Zt?ee.invokedAs:null,Qr=vt!=null&&dt!==vt,_t=x.useCallback(()=>{if(vt){Tt(vt);try{window.localStorage.setItem(pT,vt)}catch{}}},[vt]),Jt=((_l=ee==null?void 0:ee.upgrade)==null?void 0:_l.state)??"idle",rn=E8(ee==null?void 0:ee.upgrade),Pr=x.useRef(!1),No=x.useCallback(async()=>{if(ws(Pr.current||Jt==="running")){Pr.current=!0;try{await fetch("/api/upgrade",{method:"POST"})}catch{}await st(),Pr.current=!1}},[Jt,st]);x.useEffect(()=>{if(Jt!=="running")return;const D=window.setInterval(st,3e3);return()=>window.clearInterval(D)},[Jt,st]);const Zi=x.useCallback(async()=>{const D=ee==null?void 0:ee.command;!D||!await Vx(D)||(tt(!0),window.setTimeout(()=>tt(!1),1600))},[ee==null?void 0:ee.command]),ha=x.useCallback(()=>{X(D=>(D||F(q=>(q&&(Y.current=!0),!1)),!D))},[]),fa=x.useCallback(()=>{Y.current=!1,F(D=>(D||X(!1),!D))},[]),[pa,Ns]=x.useState(!1),[ma,ga]=x.useState(!1),[jt,Qi]=x.useState(()=>{try{return Number(localStorage.getItem(P_))||0}catch{return 0}}),[Ss,So]=x.useState([]),[Lr,ya]=x.useState(!1);x.useEffect(()=>{let D=!0;const q=()=>{fetch("/api/browser-watch?live=0").then(ie=>ie.ok?ie.json():null).then(ie=>{var Ce;!D||!(ie!=null&&ie.ok)||(So(ie.episodes??[]),ya(((Ce=ie.settings)==null?void 0:Ce.enabled)===!0))}).catch(()=>{})};q();const ae=setInterval(q,5*6e4);return()=>{D=!1,clearInterval(ae)}},[]);const[jo,dr]=x.useState([]),vn=x.useRef(new Set),[Dr,Cn]=x.useState(null);x.useEffect(()=>{let D=!0,q=0;const ae=()=>{fetch("/api/lan").then(ie=>ie.ok?ie.json():null).then(ie=>D?(ie!=null&&ie.ok&&dr(__(Array.isArray(ie.pending)?ie.pending:[],ie.aliases)),ie):null).catch(()=>null).then(ie=>{D&&(q=window.setTimeout(ae,(ie==null?void 0:ie.enabled)===!0?fx:DA))})};return ae(),()=>{D=!1,window.clearTimeout(q)}},[]);const Oc=x.useCallback(async(D,q)=>{if(!Dr){Cn(D);try{const ie=await(await fetch("/api/lan/peer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:D,fp:q})})).json().catch(()=>null);ie&&Array.isArray(ie.pending)?dr(__(ie.pending,ie.aliases)):dr(Ce=>Ce.filter(ve=>ve.fp!==q))}catch{}finally{Cn(null)}}},[Dr]),wa=x.useMemo(()=>sz(Ss,jt).length,[Ss,jt]),[Sh,va]=x.useState(0),xa=x.useRef(null),[ba,ka]=x.useState(!1),_a=x.useRef(null),[jh,Eo]=x.useState(0),Tn=x.useState(()=>HB({protect:D=>CL(i.current,D)}))[0],[js,Na]=x.useState(!1),Ji=x.useCallback(()=>{const D=Tn.paused&&Tn.dropped>0,q=Tn.setPaused(!Tn.paused);D&&TL(i.current);for(const ae of q)i.current=g1(i.current,ae);Na(Tn.paused)},[Tn]),[Bt,yt]=x.useState(Date.now()),[hr,Sa]=x.useState(()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(ud)!=="0"}catch{return!0}}),Co=x.useRef(!1),Pc=x.useCallback(()=>{const D=!hr;Co.current=!0;try{window.localStorage.removeItem(ud)}catch{}Sa(D),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:D})}).then(q=>q.ok?q.json():null).then(q=>{var ae;q!=null&&q.ok&&Sa(((ae=q.prefs)==null?void 0:ae.autoUpdate)!==!1)}).catch(()=>{})},[hr]),[fr,ja]=x.useState(!1),[el,To]=x.useState("restart"),[pr,mr]=x.useState(null),xn=x.useRef(!1),Es=x.useRef(null),Cs=x.useRef(0),Dn=x.useCallback(async D=>{if(!ws(xn.current))return;const q=(D==null?void 0:D.upgrade)===!0;xn.current=!0,Es.current=rn;const ae=++Cs.current;To(q?"npx":"restart"),ja(!0);try{window.sessionStorage.setItem("agent-dag.restartPending",(ze==null?void 0:ze.to)??"")}catch{}try{await fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({upgrade:q})})}catch{}window.setTimeout(()=>{if(Cs.current===ae&&xn.current){xn.current=!1,ja(!1);try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}}},q?18e4:3e4)},[ze==null?void 0:ze.to,rn]),tl=x.useRef(null);x.useEffect(()=>{const D=E_(i.current.agents.values())>0,q=M8({enabled:hr,kind:ze==null?void 0:ze.kind,canRestart:(ee==null?void 0:ee.canRestart)===!0,noticeOpen:Ie,visible:document.visibilityState==="visible",busy:D,idleSince:tl.current,now:Bt});tl.current=q.idleSince,q.restart&&Dn()},[hr,ze==null?void 0:ze.kind,ee==null?void 0:ee.canRestart,Ie,Bt,Dn]);const nl=E_(i.current.agents.values()),Ts=R8(nl),Lc=FA({enabled:hr,kind:ze==null?void 0:ze.kind,canRestart:(ee==null?void 0:ee.canRestart)===!0,noticeOpen:Ie,visible:document.visibilityState==="visible",busy:nl>0,idleSince:tl.current,now:Bt});x.useEffect(()=>{const D=ee==null?void 0:ee.running;let q=null,ae=null;try{q=window.sessionStorage.getItem("agent-dag.restartPending"),ae=window.sessionStorage.getItem(mT)}catch{return}const ie=j8({bundle:"3.23.2",running:D,pending:q,lastTried:ae});if(ie==="reload"){try{window.sessionStorage.setItem(mT,D??"")}catch{return}window.location.reload();return}if(ie!=="confirm")return;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}xn.current=!1,ja(!1),mr(D??null);const Ce=window.setTimeout(()=>mr(null),6e3);return()=>window.clearTimeout(Ce)},[ee==null?void 0:ee.running]),x.useEffect(()=>{if(fr&&C8({asked:Es.current,reported:rn})){try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}xn.current=!1,ja(!1)}},[fr,rn]);const rl=x.useState(()=>zH(O7()))[0],zt=x.useRef(rl.pinned),Ea=x.useRef(null),Ao=x.useState(()=>D7())[0],[Jr,Ca]=x.useState(()=>new Set),[qn,Ta]=x.useState(YB),[As,Eh]=x.useState(()=>sT(lT)),Ro=x.useMemo(()=>FH(As),[As]),Mo=x.useCallback(D=>qH(D,Ro),[Ro]),[Io,Dc]=x.useState(!1);x.useEffect(()=>{document.documentElement.dataset.theme=qn;try{window.localStorage.setItem(YA,qn)}catch{}Eh(D=>{const q=sT(lT);return BH(D,q)?D:q})},[qn]);const hn=x.useCallback((D,q)=>{if(kd({durationMs:q,documentHidden:document.hidden})){e.setViewport(D,{duration:q});return}const{d3Zoom:ae,d3Selection:ie}=s.getState(),Ce=ie==null?void 0:ie.property("__zoom");if(ae&&ie&&Ce&&Ce.k>0&&D.zoom>0){ae.transform(ie,Ce.scale(D.zoom/Ce.k).translate((D.x-Ce.x)/D.zoom,(D.y-Ce.y)/D.zoom));return}e.setViewport(D,{duration:0})},[e,s]),es=x.useRef(null);x.useEffect(()=>{if(!Ao)return;const D=window.setTimeout(()=>{try{hn(Ao,0)}catch{}Xn.current=Date.now()},60);return()=>window.clearTimeout(D)},[hn,Ao]);const Aa=x.useRef(!0),[Rs,Ra]=x.useState(null);x.useEffect(()=>{const D=new EventSource("/events"),q=UB(u,{now:()=>Date.now(),setTimeout:(ve,We)=>window.setTimeout(ve,We),clearTimeout:ve=>window.clearTimeout(ve)});let ae=!1;const ie=typeof BroadcastChannel=="function"?QB(new BroadcastChannel(XB),Math.random().toString(36).slice(2),()=>ae):null,Ce=window.setInterval(()=>{ae||!ie||ie.ask(600).then(ve=>{ae||ut(ZB(ve))})},3e3);return D.addEventListener("open",()=>{Ze(!0),Dc(!0)}),D.addEventListener("error",()=>{Ze(!1),Ra(null)}),D.addEventListener("open",()=>{ae=!0,ut(!1)}),D.addEventListener("error",()=>{ae=!1}),D.addEventListener("replay-end",()=>{Aa.current=!1,q.flush(),Ra(Date.now())}),D.addEventListener("hook",ve=>{var We;try{const at=JSON.parse(ve.data);if(!Tn.accept(at))return;i.current=g1(i.current,at);const Nt=at.replay===!0||Aa.current||Date.now()-at.receivedAt>3e4;Nt?q.replay():q.live();const Je=eB(at,Nt);Je&&((We=Ye.current)==null||We.play(Je))}catch{}}),()=>{D.close(),q.cancel(),window.clearInterval(Ce),ie==null||ie.leave()}},[u]),x.useEffect(()=>{const D=setInterval(()=>{const q=Date.now();yt(q);let ae=AL(i.current,q,m1);RL(i.current,q,m1)&&(ae=!0);const ie=[],Ce=ve=>{ie.push(ve)};jL(i.current,q,k7,_7,Ce)&&(ae=!0),EL(i.current,q,N7,S7,Ce)&&(ae=!0),ie.length>0&&fetch("/api/forget",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({ids:ie})}).catch(()=>{}),m(ve=>$B(ve,i.current.agents)),w(ve=>ve!=null&&!i.current.agents.has(ve)?null:ve),T(ve=>ve!=null&&!i.current.agents.has(ve)?null:ve),E(ve=>ve!=null&&!i.current.agents.has(ve)?null:ve),ae&&u()},250);return()=>clearInterval(D)},[u]);const Ms=x.useRef(null),Xn=x.useRef(0),bn=420,Vt=x.useCallback((D=500)=>{const q=Lv,ae=1,ie=.2,Ce=Dv;try{const ve=document.querySelector(".canvas-wrap"),We=Array.from(document.querySelectorAll(".react-flow__node")).filter(Ot=>Ot.offsetWidth>0);if(!ve||We.length===0)return;const at=ve.getBoundingClientRect(),Nt=e.getViewport();if(!Number.isFinite(Nt.zoom)||Nt.zoom<=0)return;const Je=Ot=>(Ot-at.left-Nt.x)/Nt.zoom,an=Ot=>(Ot-at.top-Nt.y)/Nt.zoom,is=We.map(Ot=>Ot.getBoundingClientRect()),Jo=Math.min(...is.map(Ot=>Je(Ot.left))),Nl=Math.max(...is.map(Ot=>Je(Ot.right))),ei=Math.min(...is.map(Ot=>an(Ot.top))),Sl=Math.max(...is.map(Ot=>an(Ot.bottom))),nu=Nl-Jo,ti=Sl-ei;if(!(nu>0&&ti>0))return;const Wa=Math.max(ie,Math.min(ae,(at.width-dT(ve)-q*2)/(nu+bn)*Ce,(at.height-q*2)/ti*Ce)),Ha={x:q-Jo*Wa,y:Math.max(q,(at.height-ti*Wa)/2)-ei*Wa,zoom:Wa};hn(Ha,D),Xn.current=Date.now(),es.current=kd({durationMs:D,documentHidden:document.hidden})?{target:Ha,until:Date.now()+D+60}:null,window.setTimeout(()=>{var Ot;try{((Ot=es.current)==null?void 0:Ot.target)===Ha&&(es.current=null);const vr=e.getViewport();(Math.abs(vr.zoom-Wa)>.01||Math.abs(vr.x-Ha.x)>2)&&hn(Ha,0)}catch{}},D+60)}catch{}},[e,hn]);x.useEffect(()=>{const D=()=>{if(!document.hidden)return;const q=es.current;if(es.current=null,!(!q||Date.now()>q.until)){try{hn(q.target,0)}catch{}Xn.current=Date.now()}};return document.addEventListener("visibilitychange",D),()=>document.removeEventListener("visibilitychange",D)},[hn]);const Ma=x.useRef(""),ts=x.useRef(null),qc=x.useRef(0),Is=x.useCallback(()=>{qc.current=Date.now()},[]),Ia=x.useRef(null),$s=x.useRef(0),Os=x.useCallback(()=>{$s.current=Date.now()},[]),sl=x.useCallback(D=>({hasSourceEvent:!!D,at:Date.now(),lastDeckFitAt:Xn.current,lastCanvasInputAt:$s.current}),[]),Ch="agent-dag.autoFitDisabled",ns=x.useRef(!1),[al,$o]=x.useState(!1);x.useEffect(()=>{try{window.localStorage.removeItem(Ch)}catch{}},[]);const ol=x.useCallback(()=>{ns.current||(ns.current=!0,$o(!0))},[]),Fc=x.useCallback(()=>{ns.current=!1,$o(!1),Vt(400)},[e,Vt]);x.useEffect(()=>{const D=setInterval(()=>{if(ns.current||Date.now()-qc.current<800)return;const q=i.current,ae=Date.now(),ie=[];for(const ve of q.agents.values())wx(ve,ae)&&ie.push({id:ve.id});if(ie.length===0)return;const Ce=[];for(const{id:ve}of ie){const We=rs.current.get(ve),at=zt.current.get(ve)??sn.current.get(ve);!We||!at||Ce.push({x:at.x,y:at.y,width:We.width,height:We.height})}YH({pane:Ia.current,viewport:e.getViewport(),boxes:Ce})&&Vt(600)},1500);return()=>clearInterval(D)},[e]);const il=x.useRef(!1),rs=x.useRef(new Map),Bc=x.useRef(0),zc=x.useCallback(D=>{const q=rs.current;let ae=!1;for(const ie of D.nodeInternals.values()){const Ce=ie.width,ve=ie.height;if(Ce==null||ve==null)continue;const We=q.get(ie.id);We?(Math.abs(We.height-ve)>4||Math.abs(We.width-Ce)>4)&&(q.set(ie.id,{width:Ce,height:ve}),ae=!0):(q.set(ie.id,{width:Ce,height:ve}),ae=!0)}return ae&&(Bc.current+=1),Bc.current},[]),Uc=wt(zc),[Wc,Th]=x.useState(0);x.useEffect(()=>{let D=0;const q=()=>{const ie=rs.current;let Ce=!1;for(const ve of document.querySelectorAll(".react-flow__node[data-id]")){const We=ve.getAttribute("data-id");if(!We)continue;const at=ve.offsetWidth,Nt=ve.offsetHeight;if(!at||!Nt)continue;const Je=ie.get(We);(!Je||Math.abs(Je.width-at)>4||Math.abs(Je.height-Nt)>4)&&(ie.set(We,{width:at,height:Nt}),Ce=!0)}Ce&&Th(ve=>ve+1)};if(il.current)return;let ae=0;return document.visibilityState==="hidden"?ae=window.setTimeout(q,32):D=requestAnimationFrame(q),()=>{cancelAnimationFrame(D),window.clearTimeout(ae)}});const sn=x.useRef(rl.positions),Oo=x.useRef(new Set),Po=x.useRef(""),Ps=x.useMemo(()=>{const D=[];for(const q of i.current.agents.values())wx(q,Bt)&&D.push(q.id+(q.parentId?`>${q.parentId}`:""));return D.sort(),`${D.join("|")}#sv${Uc}.${Wc}`},[i.current,i.current.revision,Bt,Uc,Wc]),$a=x.useRef(null);x.useEffect(()=>($a.current!=null&&window.clearTimeout($a.current),$a.current=window.setTimeout(()=>{dd(sn.current,zt.current)},1500),()=>{$a.current!=null&&window.clearTimeout($a.current)}),[Ps]),x.useEffect(()=>{if(Ma.current===Ps)return;const D=Ma.current;if(Ma.current=Ps,!D||ns.current)return;Date.now()-Xn.current>1200&&Vt(400),Ms.current&&window.clearTimeout(Ms.current),Ms.current=window.setTimeout(()=>{ns.current||Vt(500)},280)},[Ps,e,Vt]);const Lo=x.useMemo(()=>DB(i.current,h),[i.current,i.current.revision,h]),ll=x.useMemo(()=>PH(i.current,Bt),[i.current,i.current.revision,Bt]),Do=x.useRef(null),[Oa,Hc]=x.useState({w:0,h:0});x.useEffect(()=>{const D=Do.current;if(!D||typeof ResizeObserver>"u")return;const q=new ResizeObserver(ae=>{var Ce;const ie=(Ce=ae[0])==null?void 0:Ce.contentRect;ie&&(Ia.current={width:ie.width,height:ie.height},Hc(ve=>Math.abs(ve.w-ie.width)>40||Math.abs(ve.h-ie.height)>40?{w:ie.width,h:ie.height}:ve))});return q.observe(D),Ia.current={width:D.clientWidth,height:D.clientHeight},Hc({w:D.clientWidth,h:D.clientHeight}),()=>q.disconnect()},[]);const Ah=x.useCallback(D=>{var ae,ie;const q=D.target;!(q!=null&&q.closest)||q.closest(v7)!==D.currentTarget||(D.preventDefault(),(ie=(ae=document.activeElement)==null?void 0:ae.blur)==null||ie.call(ae))},[]),Rh=x.useRef(new Map),[qo,cl]=x.useState(!1);x.useEffect(()=>{const D=window.setTimeout(()=>cl(!0),2500);return()=>window.clearTimeout(D)},[]);const[Pa,ul]=x.useState(!1),gr=x.useRef(null),[Ls,dl]=x.useState(!1),[Gc,Vc]=x.useState("full"),ss=x.useRef("full"),Mh=x.useCallback(()=>{gr.current&&(window.clearTimeout(gr.current),gr.current=null),ul(!1)},[]),Ih=x.useCallback(D=>{D.length!==0&&queueMicrotask(()=>{ul(!0),gr.current&&window.clearTimeout(gr.current),gr.current=window.setTimeout(()=>ul(!1),x7+80)})},[]);x.useEffect(()=>()=>{gr.current&&window.clearTimeout(gr.current)},[]);const fn=y?i.current.agents.get(y):null,Yc=f&&fn!=null,[Kc,La]=x.useState(0);x.useEffect(()=>{const D=dT(Do.current);La(q=>Math.abs(q-D)>40?D:q)},[Z,z,G,Yc,Oa.w]);const qr=Oa.w>0?Math.max(0,(Oa.w-Kc-Lv*2)*Dv):0,Fo=Oa.h>0?Math.max(0,(Oa.h-Lv*2)*Dv):0,Bo=L5(),{nodes:yr,edges:hl}=x.useMemo(()=>W7(i.current,Bt,qr,Fo,zt.current,rs.current,Rh.current,Ih,qo,Ls,sn.current,Oo.current,Ps,Po,h,Lo,ll,R),[i.current,i.current.revision,Bt,qr,Fo,qo,Ls,Ps,h,Lo,ll,R,Sh,Bo]),fl=x.useState(P7)[0],zo=x.useRef(fl);x.useEffect(()=>{if(!qo||Ls)return;const D={width:qr,height:Fo};if(!(D.width>0&&D.height>0))return;const q=zo.current;if(zo.current=D,L7(D),!q||q.width===D.width&&q.height===D.height)return;const ae={direction:"LR",pinned:zt.current,measured:rs.current,lanes:uM(i.current)};if(TH(yr,hl,ae,q,D)){for(const ie of Array.from(sn.current.keys()))zt.current.has(ie)||sn.current.delete(ie);Oo.current.clear(),Po.current="",u(),window.setTimeout(()=>{dd(sn.current,zt.current),!ns.current&&Vt(500)},80)}},[qr,Fo,qo,Ls,u,Vt]);const pl=x.useMemo(()=>{const D=new Map;for(const ae of yr){const ie=ae.data;if(!(ie!=null&&ie.sessionId)||ie.exitAt!=null)continue;const Ce=ae.width,ve=ae.height;if(Ce==null||ve==null)continue;const We=ae.position.x,at=ae.position.y,Nt=We+Ce,Je=at+ve,an=D.get(ie.sessionId);an?(an.minX=Math.min(an.minX,We),an.minY=Math.min(an.minY,at),an.maxX=Math.max(an.maxX,Nt),an.maxY=Math.max(an.maxY,Je)):D.set(ie.sessionId,{minX:We,minY:at,maxX:Nt,maxY:Je})}const q=[];for(const[ae,ie]of D){const Ce=ie.maxX-ie.minX+cd*2,ve=ie.maxY-ie.minY+cd*2;q.push({id:`group:${ae}`,type:QR,position:{x:ie.minX-cd,y:ie.minY-cd},data:{sessionId:ae,w:Ce,h:ve},width:Ce,height:ve,style:{width:Ce,height:ve},zIndex:-1,draggable:!0,selectable:!1,focusable:!1,deletable:!1,connectable:!1})}return q},[yr]),Xc=x.useMemo(()=>{const D=[...pl,...yr],q=_a.current;return!q||q.size===0?D:D.map(ae=>{const ie=q.get(ae.id);return ie?{...ae,position:ie}:ae})},[pl,yr,jh]),Da=x.useMemo(()=>{const D=new Set;for(const q of i.current.agents.values())for(const ae of q.tools)D.add(cM(ae.name));return Object.keys(lM).filter(q=>D.has(q))},[i.current,i.current.revision]);x.useEffect(()=>{if(Da.length<=1){ka(!1);return}let D=0;const q=()=>{const ae=xa.current;if(ae&&!document.hidden){const ie=ae.getBoundingClientRect(),Ce=Array.from(document.querySelectorAll(".react-flow__node, .tool-burst")).map(We=>We.getBoundingClientRect()),ve=DH(ie,Ce,8);ka(We=>We===ve?We:ve)}D=window.setTimeout(q,300)};return q(),()=>window.clearTimeout(D)},[Da.length]);const $h=x.useCallback(D=>{Ca(q=>{const ae=new Set(q);return ae.has(D)?ae.delete(D):ae.add(D),ae})},[]),ml=N?xL(i.current.agents,N):null,Zc=x.useCallback(async()=>{try{await fetch("/api/clear",{method:"POST"})}catch{}i.current=rx(),zt.current.clear(),rs.current.clear(),sn.current.clear(),Po.current="",gT(),b(),u()},[u,b]),Qc=x.useRef(I);Qc.current=I;const Jc=x.useRef(H);Jc.current=H;const kn=x.useRef(!1);kn.current=ml!=null||pa||C!=null||V||j!=null||ma||H||Dt!=null;const Fr=x.useCallback(D=>{const q=I8(D,{confirmOpen:Qc.current,modalOpen:kn.current});q==="confirm"?L(!0):q==="clear"&&(L(!1),Zc())},[Zc]),Uo=x.useCallback(()=>{zt.current.clear(),sn.current.clear(),Po.current="",gT(),u(),window.setTimeout(()=>Vt(500),80)},[u,e,Vt]),gl=x.useCallback(()=>Vt(500),[Vt]),qa=x.useRef(yr);qa.current=yr;const Wo=x.useRef(y);Wo.current=y;const Ds=x.useCallback(D=>{const q=qa.current.filter(ve=>ve.type==="agent"),ae=TB(q.map(ve=>({id:ve.id,x:ve.position.x,y:ve.position.y})),Wo.current,D),ie=ae?q.find(ve=>ve.id===ae):void 0;if(!ie)return;const Ce=uT(document.activeElement);S(ie.id,!1),window.setTimeout(()=>{try{e.fitView({padding:.35,duration:Ov(350),nodes:[ie]})}catch{}Xn.current=Date.now(),Ce&&w7(ie.id)},30)},[S,e]),yl=x.useRef(null),qs=x.useCallback(D=>{S(D,!1),window.setTimeout(()=>{try{const q=qa.current.find(ae=>ae.id===D);q&&e.fitView({padding:.3,duration:Ov(500),nodes:[q]}),Xn.current=Date.now()}catch{}},60)},[S,e]),as=x.useRef(null);x.useEffect(()=>{let D=-1/0;const q=()=>{D=performance.now()},ae=ie=>{as.current=performance.now()-D<250?ie.target:null};return window.addEventListener("pointerdown",q,!0),window.addEventListener("focusin",ae,!0),()=>{window.removeEventListener("pointerdown",q,!0),window.removeEventListener("focusin",ae,!0)}},[]),x.useEffect(()=>{const D=q=>{var at,Nt;const ae=q.target,ie={tagName:ae==null?void 0:ae.tagName,isContentEditable:ae==null?void 0:ae.isContentEditable,role:(at=ae==null?void 0:ae.getAttribute)==null?void 0:at.call(ae,"role"),type:ae==null?void 0:ae.type,pointerFocused:ae!=null&&ae===as.current};if(q.key==="Escape"){const Je=l5({overlayOpen:Pd.depth()>0,typing:Wx(ie)});Je==="dismiss"?Pd.dismissTop():Je==="blur"?ae==null||ae.blur():(IB(ie)&&(ae==null||ae.blur()),b());return}if(th(q))return;const Ce=uT(ae)?(Nt=ae==null?void 0:ae.getAttribute)==null?void 0:Nt.call(ae,"data-id"):null,ve=Ce&&qa.current.some(Je=>Je.id===Ce)?Ce:null,We=RB(q,ve);if(We.kind==="activate"){q.preventDefault(),S(We.nodeId,We.additive);return}if(We.kind!=="node"&&!(We.nodeId==null&&y5(ie,q.key))&&!w5({key:q.key,modalOpen:kn.current,sheetOpen:Jc.current})){if(q.key===" "&&(q.preventDefault(),Ji()),(q.key==="c"||q.key==="C")&&Fr("shortcut"),(q.key==="r"||q.key==="R")&&Uo(),(q.key==="f"||q.key==="F")&&gl(),(q.key==="l"||q.key==="L")&&ha(),q.key==="d"||q.key==="D")if(Wo.current)p(Je=>!Je);else{const Je=ip(i.current.agents.values());Je.length>0?qs(Je[0].id):Ds(1)}if((q.key==="h"||q.key==="H")&&Ns(Je=>!Je),(q.key==="u"||q.key==="U")&&P(Je=>!Je),(q.key==="a"||q.key==="A")&&te.current.claude&&fa(),(q.key==="j"||q.key==="J")&&Ds(1),(q.key==="k"||q.key==="K")&&Ds(-1),q.key==="w"||q.key==="W"){const Je=QL(ip(i.current.agents.values()),yl.current);Je&&(yl.current=Je.id,qs(Je.id))}(q.key==="t"||q.key==="T")&&Ta(Je=>Je==="dark"?"light":"dark"),(q.key==="m"||q.key==="M")&&te.current.claude&&Te.current!==null&&ge.current(q.shiftKey),(q.key==="s"||q.key==="S")&&W(Je=>!Je),(q.key==="b"||q.key==="B")&&ga(Je=>!Je),(q.key==="v"||q.key==="V")&&te.current.claude&&Te.current!==null&&Ke(Je=>!Je),q.key==="?"&&$(Je=>!Je)}};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[Fr,Uo,gl,b,S,Ds,qs,Ji]);const Ho=i.current.agents.size,$t=x.useMemo(()=>ip(i.current.agents.values()),[i.current,i.current.revision]),Go=x.useMemo(()=>JL(i.current.agents.values()),[i.current,i.current.revision]),wl=x.useRef(null);x.useEffect(()=>{const D=JB({waiting:$t.length,running:Go,connected:Ee}),q=wl.current;if(wl.current=D,(q==null?void 0:q.title)!==D.title&&(document.title=D.title),(q==null?void 0:q.icon)!==D.icon){const ae=document.querySelector('link[rel="icon"]');ae&&(ae.href=ez[D.icon])}},[$t.length,Go,Ee]);const[Vo,Fs]=x.useState(""),Yo=nz($t);x.useEffect(()=>{Fs(D=>rz(D,Yo))},[Yo]);const[Fa,Ko]=x.useState(()=>typeof Notification>"u"?"denied":Notification.permission),[Br,Xo]=x.useState(null),[Ba,Zo]=x.useState(!1),[eu,vl]=x.useState(!1);x.useEffect(()=>{let D=!0;return fetch("/api/prefs").then(q=>q.ok?q.json():null).then(q=>{var ae,ie,Ce;if(!(!D||!(q!=null&&q.ok))){if(!Co.current){let ve=!1;try{ve=window.localStorage.getItem(ud)==="0",window.localStorage.removeItem(ud)}catch{}ve&&((ae=q.prefs)==null?void 0:ae.autoUpdate)!==!1?(Sa(!1),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:!1})}).catch(()=>{})):Sa(((ie=q.prefs)==null?void 0:ie.autoUpdate)!==!1)}Zo(((Ce=q.prefs)==null?void 0:Ce.notifications)===!0),vl(q.notificationsVetoed===!0)}}).catch(()=>{}),()=>{D=!1}},[]);const wr=x.useRef(()=>{}),xl=x.useCallback(()=>{const D=!Ba;Zo(D),D&&typeof Notification<"u"&&Notification.permission==="default"&&wr.current(),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({notifications:D})}).then(q=>q.ok?q.json():null).then(q=>{var ae;q!=null&&q.ok&&(Zo(((ae=q.prefs)==null?void 0:ae.notifications)===!0),vl(q.notificationsVetoed===!0))}).catch(()=>{})},[Ba]),bl=typeof Notification<"u";x.useEffect(()=>{if(!Br)return;const q=setTimeout(()=>Xo(null),Br==="blocked"?8e3:4e3);return()=>clearTimeout(q)},[Br]);const tu=x.useCallback(()=>{typeof Notification>"u"||Notification.requestPermission().then(D=>{const q=D;Ko(q),q==="granted"?Xo("on"):q==="denied"&&Xo("blocked")})},[]);wr.current=tu;const za=x.useRef(new Set),os=x.useRef(null),Oh=$t.map(D=>eh(D.id,D.waiting)).join("|");x.useEffect(()=>{r5(os.current,Fa)&&(os.current=Fa,za.current=lp($t))},[Fa]);const kl=x.useRef(!1);return x.useEffect(()=>{s5(kl.current,Rs)&&(kl.current=!0,za.current=lp($t))},[Rs]),x.useEffect(()=>{if(typeof Notification>"u"||Notification.permission!=="granted"||!a5(os.current,Rs))return;const D=typeof document>"u"||!document.hidden,q=t5($t,za.current,D,Ba);for(const ae of q)try{const ie=new Notification(ae.title,{body:ae.body,tag:ae.key});ie.onclick=()=>{window.focus(),qs(ae.sessionId),ie.close()}}catch{}za.current=D?lp($t):n5($t,q,za.current)},[Oh,Rs]),l.jsxs("div",{className:"app",children:[l.jsx("a",{className:"skip-link",href:"#canvas",children:"Skip to the canvas"}),l.jsxs("header",{className:"topbar",children:[l.jsxs("div",{className:"readout",children:[l.jsxs("div",{className:"brand",children:[l.jsx("span",{className:"logo"}),l.jsx("h1",{children:Zt}),ze?l.jsxs("button",{type:"button",className:"v stale",onClick:()=>{En(),Me()},"aria-haspopup":"dialog","aria-label":QH({...ze,open:Ie}),title:ze.kind==="restart"?`Running v${ze.from}; v${ze.to} is installed on disk. Restart to pick it up · click for what's new`:`Running v${ze.from}; v${ze.to} is on npm · click for what's new`,children:["v",ze.from,l.jsx("span",{className:"v-dot","aria-hidden":!0})]}):(()=>{const D={running:kt,latest:ee==null?void 0:ee.latest,latestPending:ee==null?void 0:ee.latestPending,checkedAgo:ee!=null&&ee.checkedAt?gd(Bt-ee.checkedAt):null,checkFailedAgo:ee!=null&&ee.checkFailedAt&&ee.checkFailedAt>(ee.checkedAt??0)?gd(Bt-ee.checkFailedAt):null,checkDisabled:ee==null?void 0:ee.checkDisabled,checking:lt};return l.jsxs("button",{type:"button",className:lt?"v checking":"v",onClick:()=>{En(),st(!0)},"aria-busy":lt||void 0,"aria-haspopup":"dialog","aria-label":ZH(D),title:XH(D),children:["v",D.running]})})()]}),l.jsx("span",{className:"status",children:(()=>{const D=d7({connected:Ee,paused:js,held:Tn.size,dropped:Tn.dropped});return D.resting?null:l.jsx("span",{className:`pill ${D.tone}`,title:D.title,children:l.jsxs("span",{className:"pill-box",children:[l.jsx("span",{className:"pill-widest","aria-hidden":!0,children:D.widest}),l.jsx("span",{className:"pill-label",children:D.label})]})})})()}),l.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:Vo}),$t.length>0&&l.jsxs("button",{type:"button",className:"waiting-stat",onClick:()=>{yl.current=$t[0].id,qs($t[0].id)},title:`Blocked waiting for you — click, or press W, to go to the one that has been stuck longest:
|
|
289
|
+
Click to set the volume and the sound of each tone, and to hear either one.`}function Wd(e){const t=Math.max(0,Math.floor(e));return`${t} event${t===1?"":"s"}`}const iT=99;function o7(e){const t=Math.max(0,Math.floor(e));return t>iT?`${iT}+`:String(t)}const i7="Pause the canvas";function l7(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 — ${Wd(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)":`${Wd(e.held)} arrived while paused and will be applied in order when you resume (Space)`}function c7(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 nM="paused · full",u7=(e,t)=>t>0?nM:e>0?`paused · ${o7(e)}`:"paused";function d7(e){const t=Math.max(0,Math.floor(e.dropped??0));return e.connected?e.paused?{tone:"paused",resting:!1,label:u7(e.held,t),widest:nM,title:t>0?`Connected — the pause is full at ${Wd(e.held)}; the oldest are being dropped as new ones arrive. Resume to catch up (Space)`:e.held>0?`Connected — ${Wd(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 h7=x.lazy(()=>vT(()=>import("./UsageHistoryModal-D1sRtUUY.js"),[])),f7=x.lazy(()=>vT(()=>import("./BrowserWatchModal-Cro433q6.js"),[]));function lT(e){return typeof window>"u"?"":getComputedStyle(document.documentElement).getPropertyValue(e).trim()||""}const p7={agent:q5,sessionGroup:y6,recapNote:v6},m7={recapTie:x6},g7=300,cT=130,y7=160,rM="react-flow__node";function uT(e){var t,n;return!!e&&((n=(t=e.classList)==null?void 0:t.contains)==null?void 0:n.call(t,rM))===!0}const Lv=80,Dv=.86;function dT(e){if(!e)return 0;const t=e.getBoundingClientRect();let n=t.right;for(const s of document.querySelectorAll(".sysdetail:not(.leaving), .usage-panel:not(.leaving)")){const a=s.getBoundingClientRect();a.width>0&&a.left>t.left&&(n=Math.min(n,a.left))}return Math.max(0,t.right-n)}function w7(e){try{const t=document.querySelector(`.${rM}[data-id="${CSS.escape(e)}"]`);t==null||t.focus({preventScroll:!0})}catch{}}const v7=["a[href]","button:not(:disabled)","input:not(:disabled)","select:not(:disabled)","textarea:not(:disabled)","summary","[tabindex]"].join(","),x7=420;function b7(e){return e<.35?"far":e<.55?"mid":"full"}const cd=18,k7=200,_7=5*6e4,N7=6,S7=2*6e4,hT=400,_0="agent-dag.layout",N0="agent-dag.layoutFrame",S0="agent-dag.viewport",sM="agent-dag.sessionListOpen",aM="agent-dag.detailOpen",oM="agent-dag.usagePanelOpen",iM="agent-dag.systemPanelOpen",fT="agent-dag.accountsPanelOpen",qv="agent-dag.versionNoticeDismissed",pT="agent-dag.oldNameNoticeDismissed",j7=15*6e4,Fv={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:"},ud="agent-dag.autoRestart",mT="agent-dag.bundleReloadedFor";function E7(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(sM)==="1"}catch{return!1}}function C7(e){if(!(typeof window>"u"))try{window.localStorage.setItem(sM,e?"1":"0")}catch{}}function T7(){if(typeof window>"u")return!1;try{return window.localStorage.getItem(aM)==="1"}catch{return!1}}function A7(e){if(!(typeof window>"u"))try{window.localStorage.setItem(aM,e?"1":"0")}catch{}}function R7(){const e=vo(oM);return e===null?!0:e==="1"}function M7(e){if(!(typeof window>"u"))try{window.localStorage.setItem(oM,e?"1":"0")}catch{}}function I7(){const e=vo(iM);return e===null?!0:e==="1"}function $7(e){if(!(typeof window>"u"))try{window.localStorage.setItem(iM,e?"1":"0")}catch{}}function O7(){const e={positions:[],pins:[]};if(typeof window>"u")return e;try{const t=window.localStorage.getItem(_0);if(!t)return e;const n=JSON.parse(t);if(!("v"in n)){const a=Object.entries(n).filter(([,i])=>i&&typeof i.x=="number"&&typeof i.y=="number");return{positions:a,pins:a.map(([i])=>i)}}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 dd(e,t){if(!(typeof window>"u"))try{const n={};for(const[s,a]of e)n[s]=a;for(const[s,a]of t)n[s]=a;window.localStorage.setItem(_0,JSON.stringify({v:2,positions:n,pins:Array.from(t.keys())}))}catch{}}function P7(){if(typeof window>"u")return null;try{const e=window.localStorage.getItem(N0);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 L7(e){if(!(typeof window>"u"))try{window.localStorage.setItem(N0,JSON.stringify(e))}catch{}}function D7(){if(typeof window>"u")return null;try{return UH(window.localStorage.getItem(S0))}catch{return null}}function q7(e){if(!(typeof window>"u"))try{window.localStorage.setItem(S0,JSON.stringify(e))}catch{}}function gT(){if(!(typeof window>"u")){try{window.localStorage.removeItem(_0)}catch{}try{window.localStorage.removeItem(S0)}catch{}try{window.localStorage.removeItem(N0)}catch{}}}function F7(e,t){const n=e.agents.get(t);if(!n)return;const s=[];for(const h of e.agents.values())h.sessionId===t&&s.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:s.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}))}))},i=JSON.stringify(a,null,2),c=new Blob([i],{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=`${Zt}-${p}-${t.slice(0,8)}.json`,document.body.appendChild(f),f.click(),document.body.removeChild(f),setTimeout(()=>URL.revokeObjectURL(u),1e3)}const lM={file:"📁",shell:"⚡",web:"🌐",agent:"🤖",task:"📋",plan:"🧭",mcp:"🔌",other:"✨"},B7={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 z7({cat:e}){return l.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:l.jsx("path",{d:B7[e]})})}const Hd={file:"file",shell:"shell",web:"web",agent:"agent",task:"task",plan:"plan",mcp:"mcp",other:"other"},cM=fA,yT=new WeakMap;function U7(e,t){let n=yT.get(e);(!n||n.revision!==e.revision||n.open!==t)&&(n={revision:e.revision,open:t,byId:new Map},yT.set(e,n));const{byId:s}=n;return a=>{let i=s.get(a.id);return i||(i={...a,onOpenContext:t},s.set(a.id,i)),i}}function uM(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 W7(e,t,n,s,a,i,c,u,f,p,h,m,y,w,N,_,S,b){var J,M,X,G;const j=[],E=[],C=U7(e,b);for(const P of e.agents.values()){if(!S.has(P.id))continue;const B=P.exitAt!=null,W=_!=null&&!_.has(P.id),Y=[B?"rf-exiting":"",W?"rf-spotlit-out":""].filter(Boolean).join(" ")||void 0,O=i.get(P.id);if(j.push({id:P.id,type:"agent",position:{x:0,y:0},data:C(P),className:Y,ariaLabel:z5(P,t),...O?{width:O.width,height:O.height}:null}),P.parentId&&S.has(P.parentId)){const z=Id(P.sessionId),Z=B,U=N.size>0&&(N.has(P.id)||N.has(P.parentId)),re=_!=null&&!_.has(P.id)&&!_.has(P.parentId),de=P.state==="active"?2:1.5,pe=U?de+1.5:de,ge=Z?.2:re?.12:1,Te=["sess-edge",P.state==="active"?"sess-live":"sess-idle",Z?"rf-edge-exiting":"",U?"rf-edge-selected":""].filter(Boolean).join(" ");E.push({id:`e:${P.parentId}->${P.id}`,source:P.parentId,target:P.id,animated:(P.state==="active"||U)&&!Z,type:"smoothstep",style:{"--session-hue":z,strokeWidth:pe,opacity:ge,transition:"var(--edge-transition)"},className:Te})}const F=P.kind==="root"?rh(P):null,oe=F?cA(P.sessionId,F.at):null;if(F&&oe&&!M5(oe)){const z=Hx(P.id),Z=Id(P.sessionId),U=i.get(z);j.push({id:z,type:"recapNote",position:{x:0,y:0},data:{sessionId:P.sessionId,parentId:P.id,recap:F,noteKey:oe,hue:Z},className:W?"rf-spotlit-out":void 0,selectable:!1,focusable:!1,ariaLabel:`Claude Code's recap for ${P.label}`,...U?{width:U.width,height:U.height}:null}),E.push({id:`e:recap:${P.id}`,source:z,target:P.id,type:"recapTie",className:"recap-edge",focusable:!1,style:{"--session-hue":Z}})}}const T=uM(e),R=`${y}#lanes:${jH(T)}`,I=new Set(j.filter(P=>P.type==="recapNote").map(P=>P.id));for(const P of Array.from(h.keys()))P5(P)&&!I.has(P)&&!a.has(P)&&(h.delete(P),m.delete(P));const L=j.filter(P=>qB(P.id,a,h,m));if(L.length>0||R!==w.current){if(L.length>0){const P=IH(AH(j,E,{direction:"LR",pinned:a,measured:i,availableWidth:n,availableHeight:s,lanes:T}),a,B=>bd(B,h,m)?void 0:h.get(B));for(const B of P)bd(B.id,h,m)&&O_(B.id,B.position,h,m);MH(j,h,a,i,new Set(L.filter(B=>B.type!=="recapNote").map(B=>B.id)),T,{width:n,height:s});for(const B of L){if(B.type!=="recapNote")continue;const W=(J=B.data)==null?void 0:J.parentId;if(!W)continue;const Y=a.get(W)??(bd(W,h,m)?void 0:h.get(W));if(!Y)continue;const O=((M=i.get(B.id))==null?void 0:M.width)??g7,F=((X=i.get(B.id))==null?void 0:X.height)??cT,oe=((G=i.get(W))==null?void 0:G.height)??cT;O_(B.id,{x:Y.x-y7-O,y:Y.y+(oe-F)/2},h,m)}}RH(j,h,a,i,T),w.current=R}const H=$H(j,h,a,i,c,!f||p,T);H.length>0&&u(H);const $=PB(e.agents.values());od(h,$),od(m,$),od(a,$),od(i,OB(e.agents.values()));const V=[];let Q=!1;for(const P of j){let B=a.get(P.id)??h.get(P.id);B||(B=FB(P.id,h,m),Q=!0),V.push({...P,position:B})}return Q&&(w.current=""),{nodes:V,edges:E}}function H7(){return l.jsx(Dx,{children:l.jsx(Y7,{})})}const G7=e=>e.transform[2]>=e.maxZoom,V7=e=>e.transform[2]<=e.minZoom;function Y7(){var _l,xt,Qo,Ua;const e=Sc(),t=wt(G7),n=wt(V7),s=Ht(),a=x.useState(rx)[0],i=x.useRef(a),[,c]=x.useState(0),u=x.useCallback(()=>c(D=>D+1),[]),[f,p]=x.useState(T7);x.useEffect(()=>{A7(f)},[f]);const[h,m]=x.useState(()=>new Set),[y,w]=x.useState(null),[N,_]=x.useState(null),S=x.useCallback((D,q)=>{m(ae=>{if(!q)return new Set([D]);const ie=new Set(ae);return ie.has(D)?ie.delete(D):ie.add(D),ie}),w(ae=>q&&ae===D?ae:D),q||p(!0)},[]),b=x.useCallback(()=>{m(new Set),w(null)},[]),[j,E]=x.useState(null),[C,T]=x.useState(null),R=x.useCallback(D=>T(D),[]),[I,L]=x.useState(!1),[H,$]=x.useState(!1),[V,Q]=x.useState(!1),J=x.useRef(null),[M,X]=x.useState(E7);x.useEffect(()=>{C7(M)},[M]);const[G,P]=x.useState(R7);x.useEffect(()=>{M7(G)},[G]);const[B,W]=x.useState(I7);x.useEffect(()=>{$7(B)},[B]);const Y=x.useRef(!1),[O,F]=x.useState(()=>{const D=(()=>{try{const q=window.localStorage.getItem(fT);return q===null?!0:q==="1"}catch{return!0}})();return D&&M?(Y.current=!0,!1):D});x.useEffect(()=>{if(!(!O&&Y.current))try{window.localStorage.setItem(fT,O?"1":"0")}catch{}},[O]),x.useEffect(()=>{!M&&Y.current&&(Y.current=!1,F(!0))},[M]);const oe=up(O,200),z=up(G,130),Z=up(B,130),[U,re]=x.useState(null);x.useEffect(()=>{let D=null;try{D=localStorage.getItem("agent-dag.sound")}catch{}re(D===null?!0:D==="on")},[]);const de=x.useCallback(()=>{re(D=>{var ae;const q=D!==!0;try{localStorage.setItem("agent-dag.sound",q?"on":"off")}catch{}return q&&((ae=Ye.current)==null||ae.unlock()),q})},[]),pe=x.useCallback(D=>{de()},[de]),ge=x.useRef(pe);ge.current=pe;const Te=x.useRef(U);Te.current=U;const[Ue,He]=x.useState(()=>J8(vo)),Pe=x.useRef(Ue);Pe.current=Ue;const Se=x.useRef(null),nt=x.useCallback((D,q=!1)=>{var ae,ie;if((ae=Ye.current)==null||ae.unlock(),Se.current!==null&&clearTimeout(Se.current),Se.current=null,!q){(ie=Ye.current)==null||ie.play(D,!0);return}Se.current=setTimeout(()=>{var Ce;Se.current=null,(Ce=Ye.current)==null||Ce.play(D,!0)},Y8)},[]),je=x.useCallback((D,q)=>{He(ae=>{const ie={level:wc(q.level??ae[D].level),figure:BA(D,q.figure??ae[D].figure)};try{localStorage.setItem(zA[D],String(ie.level)),localStorage.setItem(UA[D],ie.figure)}catch{}return{...ae,[D]:ie}}),nt(D,!0)},[nt]);x.useEffect(()=>()=>{Se.current!==null&&clearTimeout(Se.current)},[]);const[be,Ke]=x.useState(!1),ct=x.useRef(null),Ye=x.useRef(null),[ce,ke]=x.useState("locked");x.useEffect(()=>{const D=tB({enabled:()=>Te.current===!0,prefs:()=>Pe.current,onState:ke});Ye.current=D,ke(D.state());const q=()=>D.unlock();return window.addEventListener("pointerdown",q,{once:!0,capture:!0}),window.addEventListener("keydown",q,{once:!0,capture:!0}),()=>{window.removeEventListener("pointerdown",q,{capture:!0}),window.removeEventListener("keydown",q,{capture:!0})}},[]);const[Ee,Ze]=x.useState(!1),[Xe,ut]=x.useState(!1),[ee,Ne]=x.useState(null),[Be,et]=x.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(qv)??""}catch{return""}}),[pt,tt]=x.useState(!1),rt=x.useRef(0),[lt,bt]=x.useState(!1),st=x.useCallback((D=!1)=>(D&&(rt.current=Date.now(),bt(!0)),fetch(D?"/api/version?refresh=1":"/api/version").then(q=>q.ok?q.json():null).then(q=>{q&&Ne(q)}).catch(()=>{}).finally(()=>{D&&bt(!1)})),[]),mt=x.useCallback(()=>{st(Date.now()-rt.current>=j7)},[st]);x.useEffect(()=>{st();const D=window.setInterval(mt,5*6e4),q=()=>{document.visibilityState==="visible"&&mt()};return document.addEventListener("visibilitychange",q),()=>{window.clearInterval(D),document.removeEventListener("visibilitychange",q)}},[st,mt]),x.useEffect(()=>{Ee&&st()},[Ee,st]),x.useEffect(()=>{const D=uB();let q=null;const ae=We=>{fetch("/api/presence",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({tab:D,looking:We}),keepalive:!0}).catch(()=>{})},ie=()=>{const We=lB(document);cB(q,We)&&ae(We),q=We},Ce=()=>{q&&ae(!1),q=!1};ie();const ve=window.setInterval(ie,iB);return window.addEventListener("focus",ie),window.addEventListener("blur",ie),document.addEventListener("visibilitychange",ie),window.addEventListener("pagehide",Ce),()=>{window.clearInterval(ve),window.removeEventListener("focus",ie),window.removeEventListener("blur",ie),document.removeEventListener("visibilitychange",ie),window.removeEventListener("pagehide",Ce),Ce()}},[]);const ze=(ee==null?void 0:ee.notice)??null,[Dt,me]=x.useState(null),gt=x.useRef(!1);x.useEffect(()=>{if(gt.current)return;const D=$_(),q=vB(D),ae=SB({stored:q,running:(ee==null?void 0:ee.running)??null,notes:I_,remembers:xB(D)});if(ae.reason==="no-version")return;gt.current=!0,ae.record&&bB(D,ae.record);const ie=NB({tourSeen:kB(D),decision:ae}),Ce=ae.show.length?{entries:ae.show,since:q,firstRun:!1}:null;ie.tour&&Q(!0),ie.notes==="now"?me(Ce):ie.notes==="after"&&(J.current=Ce)},[ee==null?void 0:ee.running]);const kt=(ee==null?void 0:ee.running)??"3.23.3",jn=x.useMemo(()=>WA(I_,null,kt),[kt]),En=x.useCallback(()=>{me({entries:jn,since:null,firstRun:!1})},[jn]),[Yn,qt]=x.useState(null),[Ft,Kn]=x.useState(vx);x.useEffect(()=>{let D=!1;return fetch("/api/health").then(q=>q.ok?q.json():null).then(q=>{D||(Kn(e7(q)),!(!q||typeof q.workspace!="string")&&qt(q.workspace))}).catch(()=>{}),()=>{D=!0}},[Ee]);const te=x.useRef(Ft);te.current=Ft;const Ae=ze?`${ze.kind}:${ze.to}`:"",Ie=ze!=null&&Be!==Ae,Me=x.useCallback(()=>{et("");try{window.localStorage.setItem(qv,"")}catch{}},[]),De=x.useCallback(()=>{if(ze){et(Ae);try{window.localStorage.setItem(qv,Ae)}catch{}}},[ze,Ae]),[dt,Tt]=x.useState(()=>{if(typeof window>"u")return"";try{return window.localStorage.getItem(pT)??""}catch{return""}}),vt=ee!=null&&ee.invokedAs&&ee.invokedAs!==Zt?ee.invokedAs:null,Qr=vt!=null&&dt!==vt,_t=x.useCallback(()=>{if(vt){Tt(vt);try{window.localStorage.setItem(pT,vt)}catch{}}},[vt]),Jt=((_l=ee==null?void 0:ee.upgrade)==null?void 0:_l.state)??"idle",rn=E8(ee==null?void 0:ee.upgrade),Pr=x.useRef(!1),No=x.useCallback(async()=>{if(ws(Pr.current||Jt==="running")){Pr.current=!0;try{await fetch("/api/upgrade",{method:"POST"})}catch{}await st(),Pr.current=!1}},[Jt,st]);x.useEffect(()=>{if(Jt!=="running")return;const D=window.setInterval(st,3e3);return()=>window.clearInterval(D)},[Jt,st]);const Zi=x.useCallback(async()=>{const D=ee==null?void 0:ee.command;!D||!await Vx(D)||(tt(!0),window.setTimeout(()=>tt(!1),1600))},[ee==null?void 0:ee.command]),ha=x.useCallback(()=>{X(D=>(D||F(q=>(q&&(Y.current=!0),!1)),!D))},[]),fa=x.useCallback(()=>{Y.current=!1,F(D=>(D||X(!1),!D))},[]),[pa,Ns]=x.useState(!1),[ma,ga]=x.useState(!1),[jt,Qi]=x.useState(()=>{try{return Number(localStorage.getItem(P_))||0}catch{return 0}}),[Ss,So]=x.useState([]),[Lr,ya]=x.useState(!1);x.useEffect(()=>{let D=!0;const q=()=>{fetch("/api/browser-watch?live=0").then(ie=>ie.ok?ie.json():null).then(ie=>{var Ce;!D||!(ie!=null&&ie.ok)||(So(ie.episodes??[]),ya(((Ce=ie.settings)==null?void 0:Ce.enabled)===!0))}).catch(()=>{})};q();const ae=setInterval(q,5*6e4);return()=>{D=!1,clearInterval(ae)}},[]);const[jo,dr]=x.useState([]),vn=x.useRef(new Set),[Dr,Cn]=x.useState(null);x.useEffect(()=>{let D=!0,q=0;const ae=()=>{fetch("/api/lan").then(ie=>ie.ok?ie.json():null).then(ie=>D?(ie!=null&&ie.ok&&dr(__(Array.isArray(ie.pending)?ie.pending:[],ie.aliases)),ie):null).catch(()=>null).then(ie=>{D&&(q=window.setTimeout(ae,(ie==null?void 0:ie.enabled)===!0?fx:DA))})};return ae(),()=>{D=!1,window.clearTimeout(q)}},[]);const Oc=x.useCallback(async(D,q)=>{if(!Dr){Cn(D);try{const ie=await(await fetch("/api/lan/peer",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({action:D,fp:q})})).json().catch(()=>null);ie&&Array.isArray(ie.pending)?dr(__(ie.pending,ie.aliases)):dr(Ce=>Ce.filter(ve=>ve.fp!==q))}catch{}finally{Cn(null)}}},[Dr]),wa=x.useMemo(()=>sz(Ss,jt).length,[Ss,jt]),[Sh,va]=x.useState(0),xa=x.useRef(null),[ba,ka]=x.useState(!1),_a=x.useRef(null),[jh,Eo]=x.useState(0),Tn=x.useState(()=>HB({protect:D=>CL(i.current,D)}))[0],[js,Na]=x.useState(!1),Ji=x.useCallback(()=>{const D=Tn.paused&&Tn.dropped>0,q=Tn.setPaused(!Tn.paused);D&&TL(i.current);for(const ae of q)i.current=g1(i.current,ae);Na(Tn.paused)},[Tn]),[Bt,yt]=x.useState(Date.now()),[hr,Sa]=x.useState(()=>{if(typeof window>"u")return!0;try{return window.localStorage.getItem(ud)!=="0"}catch{return!0}}),Co=x.useRef(!1),Pc=x.useCallback(()=>{const D=!hr;Co.current=!0;try{window.localStorage.removeItem(ud)}catch{}Sa(D),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:D})}).then(q=>q.ok?q.json():null).then(q=>{var ae;q!=null&&q.ok&&Sa(((ae=q.prefs)==null?void 0:ae.autoUpdate)!==!1)}).catch(()=>{})},[hr]),[fr,ja]=x.useState(!1),[el,To]=x.useState("restart"),[pr,mr]=x.useState(null),xn=x.useRef(!1),Es=x.useRef(null),Cs=x.useRef(0),Dn=x.useCallback(async D=>{if(!ws(xn.current))return;const q=(D==null?void 0:D.upgrade)===!0;xn.current=!0,Es.current=rn;const ae=++Cs.current;To(q?"npx":"restart"),ja(!0);try{window.sessionStorage.setItem("agent-dag.restartPending",(ze==null?void 0:ze.to)??"")}catch{}try{await fetch("/api/restart",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({upgrade:q})})}catch{}window.setTimeout(()=>{if(Cs.current===ae&&xn.current){xn.current=!1,ja(!1);try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}}},q?18e4:3e4)},[ze==null?void 0:ze.to,rn]),tl=x.useRef(null);x.useEffect(()=>{const D=E_(i.current.agents.values())>0,q=M8({enabled:hr,kind:ze==null?void 0:ze.kind,canRestart:(ee==null?void 0:ee.canRestart)===!0,noticeOpen:Ie,visible:document.visibilityState==="visible",busy:D,idleSince:tl.current,now:Bt});tl.current=q.idleSince,q.restart&&Dn()},[hr,ze==null?void 0:ze.kind,ee==null?void 0:ee.canRestart,Ie,Bt,Dn]);const nl=E_(i.current.agents.values()),Ts=R8(nl),Lc=FA({enabled:hr,kind:ze==null?void 0:ze.kind,canRestart:(ee==null?void 0:ee.canRestart)===!0,noticeOpen:Ie,visible:document.visibilityState==="visible",busy:nl>0,idleSince:tl.current,now:Bt});x.useEffect(()=>{const D=ee==null?void 0:ee.running;let q=null,ae=null;try{q=window.sessionStorage.getItem("agent-dag.restartPending"),ae=window.sessionStorage.getItem(mT)}catch{return}const ie=j8({bundle:"3.23.3",running:D,pending:q,lastTried:ae});if(ie==="reload"){try{window.sessionStorage.setItem(mT,D??"")}catch{return}window.location.reload();return}if(ie!=="confirm")return;try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}xn.current=!1,ja(!1),mr(D??null);const Ce=window.setTimeout(()=>mr(null),6e3);return()=>window.clearTimeout(Ce)},[ee==null?void 0:ee.running]),x.useEffect(()=>{if(fr&&C8({asked:Es.current,reported:rn})){try{window.sessionStorage.removeItem("agent-dag.restartPending")}catch{}xn.current=!1,ja(!1)}},[fr,rn]);const rl=x.useState(()=>zH(O7()))[0],zt=x.useRef(rl.pinned),Ea=x.useRef(null),Ao=x.useState(()=>D7())[0],[Jr,Ca]=x.useState(()=>new Set),[qn,Ta]=x.useState(YB),[As,Eh]=x.useState(()=>sT(lT)),Ro=x.useMemo(()=>FH(As),[As]),Mo=x.useCallback(D=>qH(D,Ro),[Ro]),[Io,Dc]=x.useState(!1);x.useEffect(()=>{document.documentElement.dataset.theme=qn;try{window.localStorage.setItem(YA,qn)}catch{}Eh(D=>{const q=sT(lT);return BH(D,q)?D:q})},[qn]);const hn=x.useCallback((D,q)=>{if(kd({durationMs:q,documentHidden:document.hidden})){e.setViewport(D,{duration:q});return}const{d3Zoom:ae,d3Selection:ie}=s.getState(),Ce=ie==null?void 0:ie.property("__zoom");if(ae&&ie&&Ce&&Ce.k>0&&D.zoom>0){ae.transform(ie,Ce.scale(D.zoom/Ce.k).translate((D.x-Ce.x)/D.zoom,(D.y-Ce.y)/D.zoom));return}e.setViewport(D,{duration:0})},[e,s]),es=x.useRef(null);x.useEffect(()=>{if(!Ao)return;const D=window.setTimeout(()=>{try{hn(Ao,0)}catch{}Xn.current=Date.now()},60);return()=>window.clearTimeout(D)},[hn,Ao]);const Aa=x.useRef(!0),[Rs,Ra]=x.useState(null);x.useEffect(()=>{const D=new EventSource("/events"),q=UB(u,{now:()=>Date.now(),setTimeout:(ve,We)=>window.setTimeout(ve,We),clearTimeout:ve=>window.clearTimeout(ve)});let ae=!1;const ie=typeof BroadcastChannel=="function"?QB(new BroadcastChannel(XB),Math.random().toString(36).slice(2),()=>ae):null,Ce=window.setInterval(()=>{ae||!ie||ie.ask(600).then(ve=>{ae||ut(ZB(ve))})},3e3);return D.addEventListener("open",()=>{Ze(!0),Dc(!0)}),D.addEventListener("error",()=>{Ze(!1),Ra(null)}),D.addEventListener("open",()=>{ae=!0,ut(!1)}),D.addEventListener("error",()=>{ae=!1}),D.addEventListener("replay-end",()=>{Aa.current=!1,q.flush(),Ra(Date.now())}),D.addEventListener("hook",ve=>{var We;try{const at=JSON.parse(ve.data);if(!Tn.accept(at))return;i.current=g1(i.current,at);const Nt=at.replay===!0||Aa.current||Date.now()-at.receivedAt>3e4;Nt?q.replay():q.live();const Je=eB(at,Nt);Je&&((We=Ye.current)==null||We.play(Je))}catch{}}),()=>{D.close(),q.cancel(),window.clearInterval(Ce),ie==null||ie.leave()}},[u]),x.useEffect(()=>{const D=setInterval(()=>{const q=Date.now();yt(q);let ae=AL(i.current,q,m1);RL(i.current,q,m1)&&(ae=!0);const ie=[],Ce=ve=>{ie.push(ve)};jL(i.current,q,k7,_7,Ce)&&(ae=!0),EL(i.current,q,N7,S7,Ce)&&(ae=!0),ie.length>0&&fetch("/api/forget",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({ids:ie})}).catch(()=>{}),m(ve=>$B(ve,i.current.agents)),w(ve=>ve!=null&&!i.current.agents.has(ve)?null:ve),T(ve=>ve!=null&&!i.current.agents.has(ve)?null:ve),E(ve=>ve!=null&&!i.current.agents.has(ve)?null:ve),ae&&u()},250);return()=>clearInterval(D)},[u]);const Ms=x.useRef(null),Xn=x.useRef(0),bn=420,Vt=x.useCallback((D=500)=>{const q=Lv,ae=1,ie=.2,Ce=Dv;try{const ve=document.querySelector(".canvas-wrap"),We=Array.from(document.querySelectorAll(".react-flow__node")).filter(Ot=>Ot.offsetWidth>0);if(!ve||We.length===0)return;const at=ve.getBoundingClientRect(),Nt=e.getViewport();if(!Number.isFinite(Nt.zoom)||Nt.zoom<=0)return;const Je=Ot=>(Ot-at.left-Nt.x)/Nt.zoom,an=Ot=>(Ot-at.top-Nt.y)/Nt.zoom,is=We.map(Ot=>Ot.getBoundingClientRect()),Jo=Math.min(...is.map(Ot=>Je(Ot.left))),Nl=Math.max(...is.map(Ot=>Je(Ot.right))),ei=Math.min(...is.map(Ot=>an(Ot.top))),Sl=Math.max(...is.map(Ot=>an(Ot.bottom))),nu=Nl-Jo,ti=Sl-ei;if(!(nu>0&&ti>0))return;const Wa=Math.max(ie,Math.min(ae,(at.width-dT(ve)-q*2)/(nu+bn)*Ce,(at.height-q*2)/ti*Ce)),Ha={x:q-Jo*Wa,y:Math.max(q,(at.height-ti*Wa)/2)-ei*Wa,zoom:Wa};hn(Ha,D),Xn.current=Date.now(),es.current=kd({durationMs:D,documentHidden:document.hidden})?{target:Ha,until:Date.now()+D+60}:null,window.setTimeout(()=>{var Ot;try{((Ot=es.current)==null?void 0:Ot.target)===Ha&&(es.current=null);const vr=e.getViewport();(Math.abs(vr.zoom-Wa)>.01||Math.abs(vr.x-Ha.x)>2)&&hn(Ha,0)}catch{}},D+60)}catch{}},[e,hn]);x.useEffect(()=>{const D=()=>{if(!document.hidden)return;const q=es.current;if(es.current=null,!(!q||Date.now()>q.until)){try{hn(q.target,0)}catch{}Xn.current=Date.now()}};return document.addEventListener("visibilitychange",D),()=>document.removeEventListener("visibilitychange",D)},[hn]);const Ma=x.useRef(""),ts=x.useRef(null),qc=x.useRef(0),Is=x.useCallback(()=>{qc.current=Date.now()},[]),Ia=x.useRef(null),$s=x.useRef(0),Os=x.useCallback(()=>{$s.current=Date.now()},[]),sl=x.useCallback(D=>({hasSourceEvent:!!D,at:Date.now(),lastDeckFitAt:Xn.current,lastCanvasInputAt:$s.current}),[]),Ch="agent-dag.autoFitDisabled",ns=x.useRef(!1),[al,$o]=x.useState(!1);x.useEffect(()=>{try{window.localStorage.removeItem(Ch)}catch{}},[]);const ol=x.useCallback(()=>{ns.current||(ns.current=!0,$o(!0))},[]),Fc=x.useCallback(()=>{ns.current=!1,$o(!1),Vt(400)},[e,Vt]);x.useEffect(()=>{const D=setInterval(()=>{if(ns.current||Date.now()-qc.current<800)return;const q=i.current,ae=Date.now(),ie=[];for(const ve of q.agents.values())wx(ve,ae)&&ie.push({id:ve.id});if(ie.length===0)return;const Ce=[];for(const{id:ve}of ie){const We=rs.current.get(ve),at=zt.current.get(ve)??sn.current.get(ve);!We||!at||Ce.push({x:at.x,y:at.y,width:We.width,height:We.height})}YH({pane:Ia.current,viewport:e.getViewport(),boxes:Ce})&&Vt(600)},1500);return()=>clearInterval(D)},[e]);const il=x.useRef(!1),rs=x.useRef(new Map),Bc=x.useRef(0),zc=x.useCallback(D=>{const q=rs.current;let ae=!1;for(const ie of D.nodeInternals.values()){const Ce=ie.width,ve=ie.height;if(Ce==null||ve==null)continue;const We=q.get(ie.id);We?(Math.abs(We.height-ve)>4||Math.abs(We.width-Ce)>4)&&(q.set(ie.id,{width:Ce,height:ve}),ae=!0):(q.set(ie.id,{width:Ce,height:ve}),ae=!0)}return ae&&(Bc.current+=1),Bc.current},[]),Uc=wt(zc),[Wc,Th]=x.useState(0);x.useEffect(()=>{let D=0;const q=()=>{const ie=rs.current;let Ce=!1;for(const ve of document.querySelectorAll(".react-flow__node[data-id]")){const We=ve.getAttribute("data-id");if(!We)continue;const at=ve.offsetWidth,Nt=ve.offsetHeight;if(!at||!Nt)continue;const Je=ie.get(We);(!Je||Math.abs(Je.width-at)>4||Math.abs(Je.height-Nt)>4)&&(ie.set(We,{width:at,height:Nt}),Ce=!0)}Ce&&Th(ve=>ve+1)};if(il.current)return;let ae=0;return document.visibilityState==="hidden"?ae=window.setTimeout(q,32):D=requestAnimationFrame(q),()=>{cancelAnimationFrame(D),window.clearTimeout(ae)}});const sn=x.useRef(rl.positions),Oo=x.useRef(new Set),Po=x.useRef(""),Ps=x.useMemo(()=>{const D=[];for(const q of i.current.agents.values())wx(q,Bt)&&D.push(q.id+(q.parentId?`>${q.parentId}`:""));return D.sort(),`${D.join("|")}#sv${Uc}.${Wc}`},[i.current,i.current.revision,Bt,Uc,Wc]),$a=x.useRef(null);x.useEffect(()=>($a.current!=null&&window.clearTimeout($a.current),$a.current=window.setTimeout(()=>{dd(sn.current,zt.current)},1500),()=>{$a.current!=null&&window.clearTimeout($a.current)}),[Ps]),x.useEffect(()=>{if(Ma.current===Ps)return;const D=Ma.current;if(Ma.current=Ps,!D||ns.current)return;Date.now()-Xn.current>1200&&Vt(400),Ms.current&&window.clearTimeout(Ms.current),Ms.current=window.setTimeout(()=>{ns.current||Vt(500)},280)},[Ps,e,Vt]);const Lo=x.useMemo(()=>DB(i.current,h),[i.current,i.current.revision,h]),ll=x.useMemo(()=>PH(i.current,Bt),[i.current,i.current.revision,Bt]),Do=x.useRef(null),[Oa,Hc]=x.useState({w:0,h:0});x.useEffect(()=>{const D=Do.current;if(!D||typeof ResizeObserver>"u")return;const q=new ResizeObserver(ae=>{var Ce;const ie=(Ce=ae[0])==null?void 0:Ce.contentRect;ie&&(Ia.current={width:ie.width,height:ie.height},Hc(ve=>Math.abs(ve.w-ie.width)>40||Math.abs(ve.h-ie.height)>40?{w:ie.width,h:ie.height}:ve))});return q.observe(D),Ia.current={width:D.clientWidth,height:D.clientHeight},Hc({w:D.clientWidth,h:D.clientHeight}),()=>q.disconnect()},[]);const Ah=x.useCallback(D=>{var ae,ie;const q=D.target;!(q!=null&&q.closest)||q.closest(v7)!==D.currentTarget||(D.preventDefault(),(ie=(ae=document.activeElement)==null?void 0:ae.blur)==null||ie.call(ae))},[]),Rh=x.useRef(new Map),[qo,cl]=x.useState(!1);x.useEffect(()=>{const D=window.setTimeout(()=>cl(!0),2500);return()=>window.clearTimeout(D)},[]);const[Pa,ul]=x.useState(!1),gr=x.useRef(null),[Ls,dl]=x.useState(!1),[Gc,Vc]=x.useState("full"),ss=x.useRef("full"),Mh=x.useCallback(()=>{gr.current&&(window.clearTimeout(gr.current),gr.current=null),ul(!1)},[]),Ih=x.useCallback(D=>{D.length!==0&&queueMicrotask(()=>{ul(!0),gr.current&&window.clearTimeout(gr.current),gr.current=window.setTimeout(()=>ul(!1),x7+80)})},[]);x.useEffect(()=>()=>{gr.current&&window.clearTimeout(gr.current)},[]);const fn=y?i.current.agents.get(y):null,Yc=f&&fn!=null,[Kc,La]=x.useState(0);x.useEffect(()=>{const D=dT(Do.current);La(q=>Math.abs(q-D)>40?D:q)},[Z,z,G,Yc,Oa.w]);const qr=Oa.w>0?Math.max(0,(Oa.w-Kc-Lv*2)*Dv):0,Fo=Oa.h>0?Math.max(0,(Oa.h-Lv*2)*Dv):0,Bo=L5(),{nodes:yr,edges:hl}=x.useMemo(()=>W7(i.current,Bt,qr,Fo,zt.current,rs.current,Rh.current,Ih,qo,Ls,sn.current,Oo.current,Ps,Po,h,Lo,ll,R),[i.current,i.current.revision,Bt,qr,Fo,qo,Ls,Ps,h,Lo,ll,R,Sh,Bo]),fl=x.useState(P7)[0],zo=x.useRef(fl);x.useEffect(()=>{if(!qo||Ls)return;const D={width:qr,height:Fo};if(!(D.width>0&&D.height>0))return;const q=zo.current;if(zo.current=D,L7(D),!q||q.width===D.width&&q.height===D.height)return;const ae={direction:"LR",pinned:zt.current,measured:rs.current,lanes:uM(i.current)};if(TH(yr,hl,ae,q,D)){for(const ie of Array.from(sn.current.keys()))zt.current.has(ie)||sn.current.delete(ie);Oo.current.clear(),Po.current="",u(),window.setTimeout(()=>{dd(sn.current,zt.current),!ns.current&&Vt(500)},80)}},[qr,Fo,qo,Ls,u,Vt]);const pl=x.useMemo(()=>{const D=new Map;for(const ae of yr){const ie=ae.data;if(!(ie!=null&&ie.sessionId)||ie.exitAt!=null)continue;const Ce=ae.width,ve=ae.height;if(Ce==null||ve==null)continue;const We=ae.position.x,at=ae.position.y,Nt=We+Ce,Je=at+ve,an=D.get(ie.sessionId);an?(an.minX=Math.min(an.minX,We),an.minY=Math.min(an.minY,at),an.maxX=Math.max(an.maxX,Nt),an.maxY=Math.max(an.maxY,Je)):D.set(ie.sessionId,{minX:We,minY:at,maxX:Nt,maxY:Je})}const q=[];for(const[ae,ie]of D){const Ce=ie.maxX-ie.minX+cd*2,ve=ie.maxY-ie.minY+cd*2;q.push({id:`group:${ae}`,type:QR,position:{x:ie.minX-cd,y:ie.minY-cd},data:{sessionId:ae,w:Ce,h:ve},width:Ce,height:ve,style:{width:Ce,height:ve},zIndex:-1,draggable:!0,selectable:!1,focusable:!1,deletable:!1,connectable:!1})}return q},[yr]),Xc=x.useMemo(()=>{const D=[...pl,...yr],q=_a.current;return!q||q.size===0?D:D.map(ae=>{const ie=q.get(ae.id);return ie?{...ae,position:ie}:ae})},[pl,yr,jh]),Da=x.useMemo(()=>{const D=new Set;for(const q of i.current.agents.values())for(const ae of q.tools)D.add(cM(ae.name));return Object.keys(lM).filter(q=>D.has(q))},[i.current,i.current.revision]);x.useEffect(()=>{if(Da.length<=1){ka(!1);return}let D=0;const q=()=>{const ae=xa.current;if(ae&&!document.hidden){const ie=ae.getBoundingClientRect(),Ce=Array.from(document.querySelectorAll(".react-flow__node, .tool-burst")).map(We=>We.getBoundingClientRect()),ve=DH(ie,Ce,8);ka(We=>We===ve?We:ve)}D=window.setTimeout(q,300)};return q(),()=>window.clearTimeout(D)},[Da.length]);const $h=x.useCallback(D=>{Ca(q=>{const ae=new Set(q);return ae.has(D)?ae.delete(D):ae.add(D),ae})},[]),ml=N?xL(i.current.agents,N):null,Zc=x.useCallback(async()=>{try{await fetch("/api/clear",{method:"POST"})}catch{}i.current=rx(),zt.current.clear(),rs.current.clear(),sn.current.clear(),Po.current="",gT(),b(),u()},[u,b]),Qc=x.useRef(I);Qc.current=I;const Jc=x.useRef(H);Jc.current=H;const kn=x.useRef(!1);kn.current=ml!=null||pa||C!=null||V||j!=null||ma||H||Dt!=null;const Fr=x.useCallback(D=>{const q=I8(D,{confirmOpen:Qc.current,modalOpen:kn.current});q==="confirm"?L(!0):q==="clear"&&(L(!1),Zc())},[Zc]),Uo=x.useCallback(()=>{zt.current.clear(),sn.current.clear(),Po.current="",gT(),u(),window.setTimeout(()=>Vt(500),80)},[u,e,Vt]),gl=x.useCallback(()=>Vt(500),[Vt]),qa=x.useRef(yr);qa.current=yr;const Wo=x.useRef(y);Wo.current=y;const Ds=x.useCallback(D=>{const q=qa.current.filter(ve=>ve.type==="agent"),ae=TB(q.map(ve=>({id:ve.id,x:ve.position.x,y:ve.position.y})),Wo.current,D),ie=ae?q.find(ve=>ve.id===ae):void 0;if(!ie)return;const Ce=uT(document.activeElement);S(ie.id,!1),window.setTimeout(()=>{try{e.fitView({padding:.35,duration:Ov(350),nodes:[ie]})}catch{}Xn.current=Date.now(),Ce&&w7(ie.id)},30)},[S,e]),yl=x.useRef(null),qs=x.useCallback(D=>{S(D,!1),window.setTimeout(()=>{try{const q=qa.current.find(ae=>ae.id===D);q&&e.fitView({padding:.3,duration:Ov(500),nodes:[q]}),Xn.current=Date.now()}catch{}},60)},[S,e]),as=x.useRef(null);x.useEffect(()=>{let D=-1/0;const q=()=>{D=performance.now()},ae=ie=>{as.current=performance.now()-D<250?ie.target:null};return window.addEventListener("pointerdown",q,!0),window.addEventListener("focusin",ae,!0),()=>{window.removeEventListener("pointerdown",q,!0),window.removeEventListener("focusin",ae,!0)}},[]),x.useEffect(()=>{const D=q=>{var at,Nt;const ae=q.target,ie={tagName:ae==null?void 0:ae.tagName,isContentEditable:ae==null?void 0:ae.isContentEditable,role:(at=ae==null?void 0:ae.getAttribute)==null?void 0:at.call(ae,"role"),type:ae==null?void 0:ae.type,pointerFocused:ae!=null&&ae===as.current};if(q.key==="Escape"){const Je=l5({overlayOpen:Pd.depth()>0,typing:Wx(ie)});Je==="dismiss"?Pd.dismissTop():Je==="blur"?ae==null||ae.blur():(IB(ie)&&(ae==null||ae.blur()),b());return}if(th(q))return;const Ce=uT(ae)?(Nt=ae==null?void 0:ae.getAttribute)==null?void 0:Nt.call(ae,"data-id"):null,ve=Ce&&qa.current.some(Je=>Je.id===Ce)?Ce:null,We=RB(q,ve);if(We.kind==="activate"){q.preventDefault(),S(We.nodeId,We.additive);return}if(We.kind!=="node"&&!(We.nodeId==null&&y5(ie,q.key))&&!w5({key:q.key,modalOpen:kn.current,sheetOpen:Jc.current})){if(q.key===" "&&(q.preventDefault(),Ji()),(q.key==="c"||q.key==="C")&&Fr("shortcut"),(q.key==="r"||q.key==="R")&&Uo(),(q.key==="f"||q.key==="F")&&gl(),(q.key==="l"||q.key==="L")&&ha(),q.key==="d"||q.key==="D")if(Wo.current)p(Je=>!Je);else{const Je=ip(i.current.agents.values());Je.length>0?qs(Je[0].id):Ds(1)}if((q.key==="h"||q.key==="H")&&Ns(Je=>!Je),(q.key==="u"||q.key==="U")&&P(Je=>!Je),(q.key==="a"||q.key==="A")&&te.current.claude&&fa(),(q.key==="j"||q.key==="J")&&Ds(1),(q.key==="k"||q.key==="K")&&Ds(-1),q.key==="w"||q.key==="W"){const Je=QL(ip(i.current.agents.values()),yl.current);Je&&(yl.current=Je.id,qs(Je.id))}(q.key==="t"||q.key==="T")&&Ta(Je=>Je==="dark"?"light":"dark"),(q.key==="m"||q.key==="M")&&te.current.claude&&Te.current!==null&&ge.current(q.shiftKey),(q.key==="s"||q.key==="S")&&W(Je=>!Je),(q.key==="b"||q.key==="B")&&ga(Je=>!Je),(q.key==="v"||q.key==="V")&&te.current.claude&&Te.current!==null&&Ke(Je=>!Je),q.key==="?"&&$(Je=>!Je)}};return window.addEventListener("keydown",D),()=>window.removeEventListener("keydown",D)},[Fr,Uo,gl,b,S,Ds,qs,Ji]);const Ho=i.current.agents.size,$t=x.useMemo(()=>ip(i.current.agents.values()),[i.current,i.current.revision]),Go=x.useMemo(()=>JL(i.current.agents.values()),[i.current,i.current.revision]),wl=x.useRef(null);x.useEffect(()=>{const D=JB({waiting:$t.length,running:Go,connected:Ee}),q=wl.current;if(wl.current=D,(q==null?void 0:q.title)!==D.title&&(document.title=D.title),(q==null?void 0:q.icon)!==D.icon){const ae=document.querySelector('link[rel="icon"]');ae&&(ae.href=ez[D.icon])}},[$t.length,Go,Ee]);const[Vo,Fs]=x.useState(""),Yo=nz($t);x.useEffect(()=>{Fs(D=>rz(D,Yo))},[Yo]);const[Fa,Ko]=x.useState(()=>typeof Notification>"u"?"denied":Notification.permission),[Br,Xo]=x.useState(null),[Ba,Zo]=x.useState(!1),[eu,vl]=x.useState(!1);x.useEffect(()=>{let D=!0;return fetch("/api/prefs").then(q=>q.ok?q.json():null).then(q=>{var ae,ie,Ce;if(!(!D||!(q!=null&&q.ok))){if(!Co.current){let ve=!1;try{ve=window.localStorage.getItem(ud)==="0",window.localStorage.removeItem(ud)}catch{}ve&&((ae=q.prefs)==null?void 0:ae.autoUpdate)!==!1?(Sa(!1),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({autoUpdate:!1})}).catch(()=>{})):Sa(((ie=q.prefs)==null?void 0:ie.autoUpdate)!==!1)}Zo(((Ce=q.prefs)==null?void 0:Ce.notifications)===!0),vl(q.notificationsVetoed===!0)}}).catch(()=>{}),()=>{D=!1}},[]);const wr=x.useRef(()=>{}),xl=x.useCallback(()=>{const D=!Ba;Zo(D),D&&typeof Notification<"u"&&Notification.permission==="default"&&wr.current(),fetch("/api/prefs",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({notifications:D})}).then(q=>q.ok?q.json():null).then(q=>{var ae;q!=null&&q.ok&&(Zo(((ae=q.prefs)==null?void 0:ae.notifications)===!0),vl(q.notificationsVetoed===!0))}).catch(()=>{})},[Ba]),bl=typeof Notification<"u";x.useEffect(()=>{if(!Br)return;const q=setTimeout(()=>Xo(null),Br==="blocked"?8e3:4e3);return()=>clearTimeout(q)},[Br]);const tu=x.useCallback(()=>{typeof Notification>"u"||Notification.requestPermission().then(D=>{const q=D;Ko(q),q==="granted"?Xo("on"):q==="denied"&&Xo("blocked")})},[]);wr.current=tu;const za=x.useRef(new Set),os=x.useRef(null),Oh=$t.map(D=>eh(D.id,D.waiting)).join("|");x.useEffect(()=>{r5(os.current,Fa)&&(os.current=Fa,za.current=lp($t))},[Fa]);const kl=x.useRef(!1);return x.useEffect(()=>{s5(kl.current,Rs)&&(kl.current=!0,za.current=lp($t))},[Rs]),x.useEffect(()=>{if(typeof Notification>"u"||Notification.permission!=="granted"||!a5(os.current,Rs))return;const D=typeof document>"u"||!document.hidden,q=t5($t,za.current,D,Ba);for(const ae of q)try{const ie=new Notification(ae.title,{body:ae.body,tag:ae.key});ie.onclick=()=>{window.focus(),qs(ae.sessionId),ie.close()}}catch{}za.current=D?lp($t):n5($t,q,za.current)},[Oh,Rs]),l.jsxs("div",{className:"app",children:[l.jsx("a",{className:"skip-link",href:"#canvas",children:"Skip to the canvas"}),l.jsxs("header",{className:"topbar",children:[l.jsxs("div",{className:"readout",children:[l.jsxs("div",{className:"brand",children:[l.jsx("span",{className:"logo"}),l.jsx("h1",{children:Zt}),ze?l.jsxs("button",{type:"button",className:"v stale",onClick:()=>{En(),Me()},"aria-haspopup":"dialog","aria-label":QH({...ze,open:Ie}),title:ze.kind==="restart"?`Running v${ze.from}; v${ze.to} is installed on disk. Restart to pick it up · click for what's new`:`Running v${ze.from}; v${ze.to} is on npm · click for what's new`,children:["v",ze.from,l.jsx("span",{className:"v-dot","aria-hidden":!0})]}):(()=>{const D={running:kt,latest:ee==null?void 0:ee.latest,latestPending:ee==null?void 0:ee.latestPending,checkedAgo:ee!=null&&ee.checkedAt?gd(Bt-ee.checkedAt):null,checkFailedAgo:ee!=null&&ee.checkFailedAt&&ee.checkFailedAt>(ee.checkedAt??0)?gd(Bt-ee.checkFailedAt):null,checkDisabled:ee==null?void 0:ee.checkDisabled,checking:lt};return l.jsxs("button",{type:"button",className:lt?"v checking":"v",onClick:()=>{En(),st(!0)},"aria-busy":lt||void 0,"aria-haspopup":"dialog","aria-label":ZH(D),title:XH(D),children:["v",D.running]})})()]}),l.jsx("span",{className:"status",children:(()=>{const D=d7({connected:Ee,paused:js,held:Tn.size,dropped:Tn.dropped});return D.resting?null:l.jsx("span",{className:`pill ${D.tone}`,title:D.title,children:l.jsxs("span",{className:"pill-box",children:[l.jsx("span",{className:"pill-widest","aria-hidden":!0,children:D.widest}),l.jsx("span",{className:"pill-label",children:D.label})]})})})()}),l.jsx("div",{className:"vis-hidden",role:"status","aria-atomic":"true",children:Vo}),$t.length>0&&l.jsxs("button",{type:"button",className:"waiting-stat",onClick:()=>{yl.current=$t[0].id,qs($t[0].id)},title:`Blocked waiting for you — click, or press W, to go to the one that has been stuck longest:
|
|
290
290
|
${$t.map(D=>` ${D.label}: ${Bi(D.waiting)} (${gd(Bt-D.waiting.since)})`).join(`
|
|
291
291
|
`)}`,"aria-label":`${$t.length} session${$t.length===1?"":"s"} waiting for you`,children:[l.jsx("span",{className:"ap-pulse","aria-hidden":!0}),l.jsx("b",{children:$t.length})," ",l.jsx("span",{className:"ws-word",children:"waiting"})]}),Br&&l.jsx("span",{className:Br==="on"?"notify-said":"notify-said notify-said-blocked",role:"status",title:Br==="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:Br==="on"?"notifications on":"notifications blocked"})]}),fn&&(()=>{const D=Vn(fn),q=Math.max(0,((fn.endedAt??Bt)-fn.startedAt)/1e3),ae=fn.state==="active"?zx(D.total,q):null,ie=h.size-1;return l.jsxs("button",{type:"button",className:"selected-ribbon",title:`Fit view to ${fn.label}`,onClick:()=>{try{const Ce=yr.find(ve=>ve.id===fn.id);Ce&&e.fitView({padding:.35,duration:Ov(500),nodes:[Ce]}),Xn.current=Date.now()}catch{}},children:[l.jsx("span",{className:`state-pill state-${fn.state}`,children:fn.state==="active"?"live":fn.state}),l.jsx("span",{className:"selected-label",children:fn.label}),D.total>0&&l.jsxs("span",{className:"selected-cost",children:[St(D.total),ae?l.jsxs("span",{className:"selected-rate",children:[" · ",ae]}):null]}),ie>0&&l.jsxs("span",{className:"selected-extra",children:["+",ie]}),l.jsx("span",{"aria-hidden":!0,className:"selected-close",onClick:Ce=>{Ce.stopPropagation(),b()},children:"×"})]})})(),l.jsxs("div",{className:"actions",children:[l.jsxs("div",{className:"action-run",children:[l.jsxs("button",{className:"btn icon-btn",onClick:ha,title:`${M?"Hide":"Show"} session list (L)`,"aria-label":"Toggle session list","aria-expanded":M,"aria-controls":M?"session-list":void 0,children:[l.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:[l.jsx("path",{d:"M5.4 3.6h6.6M5.4 7h6.6M5.4 10.4h6.6"}),l.jsx("path",{d:"M2.2 3.6h.2M2.2 7h.2M2.2 10.4h.2"})]}),l.jsx("span",{className:"tb-word",children:"Session list"})]}),l.jsxs("button",{className:"btn icon-btn",onClick:()=>P(D=>!D),title:`${G?"Hide":"Show"} usage panel (U)`,"aria-label":"Toggle usage panel","aria-expanded":G,"aria-controls":G?"usage-panel":void 0,children:[l.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:[l.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"}),l.jsx("path",{d:"M7 1.6v1.5M7 10.9v1.5"})]}),l.jsx("span",{className:"tb-word",children:"Usage"})]}),l.jsxs("button",{className:"btn icon-btn",onClick:()=>Ns(D=>!D),title:"Usage history — ccusage (H)","aria-label":"Open usage history","aria-haspopup":"dialog",children:[l.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:[l.jsx("line",{x1:"3",y1:"11.5",x2:"3",y2:"7"}),l.jsx("line",{x1:"7",y1:"11.5",x2:"7",y2:"3"}),l.jsx("line",{x1:"11",y1:"11.5",x2:"11",y2:"8.5"})]}),l.jsx("span",{className:"tb-word",children:"History"})]})]}),l.jsxs("div",{className:"action-run",children:[Ft.claude&&l.jsxs("button",{className:"btn icon-btn",onClick:fa,title:`${O?"Hide":"Show"} accounts (A)`,"aria-label":"Toggle accounts panel","aria-expanded":O,"aria-controls":O?"accounts-panel":void 0,children:[l.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:[l.jsx("circle",{cx:"7",cy:"4.6",r:"2.4"}),l.jsx("path",{d:"M2.4 12c0-2.3 2.1-3.7 4.6-3.7s4.6 1.4 4.6 3.7"})]}),l.jsx("span",{className:"tb-word",children:"Accounts"})]}),l.jsxs("button",{className:"btn icon-btn",onClick:()=>W(D=>!D),title:`${B?"Hide":"Show"} this machine — cores, memory, temperature (S)`,"aria-label":"Toggle machine detail","aria-expanded":B,"aria-controls":B?"system-panel":void 0,children:[l.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:[l.jsx("rect",{x:"3.6",y:"3.6",width:"6.8",height:"6.8",rx:"1.2"}),l.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"})]}),l.jsx("span",{className:"tb-word",children:"Machine"})]}),l.jsxs("button",{className:"btn icon-btn bw-btn",onClick:()=>ga(D=>!D),title:Lr?"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, ${Lr?"watching":"not watching"}`+(wa>0?`, ${wa} unread`:""),"aria-haspopup":"dialog",children:[l.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:[l.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"}),Lr||wa>0?l.jsx("circle",{cx:"7",cy:"7",r:"1.8",fill:"currentColor",stroke:"none"}):l.jsx("line",{x1:"2.4",y1:"11.6",x2:"11.6",y2:"2.4"})]}),l.jsx("span",{className:"tb-word",children:"Browser watch"}),wa>0&&l.jsx("span",{className:"bw-badge","aria-hidden":!0,children:wa})]})]}),l.jsxs("div",{className:"action-run action-run-utility",children:[Ft.claude&&U!==null&&l.jsxs("div",{className:"sound-slot",children:[l.jsxs("button",{ref:ct,className:"btn icon-btn",onClick:()=>Ke(D=>!D),...aa(!1),title:a7(Ft,{on:U===!0,locked:ce==="locked",prefs:Ue}),"aria-label":`Sound settings, ${U?"on":"off"}`,"aria-haspopup":"dialog","aria-expanded":be,"aria-controls":be?"sound-menu":void 0,children:[l.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:[l.jsx("path",{d:"M3.2 5.2h2L7.8 3v8L5.2 8.8h-2z"}),U?l.jsxs(l.Fragment,{children:[l.jsx("path",{d:"M9.8 5.4a2.4 2.4 0 0 1 0 3.2"}),l.jsx("path",{d:"M11.3 3.9a4.6 4.6 0 0 1 0 6.2"})]}):l.jsxs(l.Fragment,{children:[l.jsx("path",{d:"M10 5.6l2.6 2.8"}),l.jsx("path",{d:"M12.6 5.6L10 8.4"})]})]}),l.jsx("span",{className:"tb-word",children:"Sound"})]}),be&&l.jsx(oB,{onClose:()=>Ke(!1),soundOn:U===!0,onToggleSound:de,prefs:Ue,onLevel:(D,q)=>je(D,{level:q}),onFigure:(D,q)=>je(D,{figure:q}),onPreview:D=>nt(D),notifyOn:Ba,onToggleNotify:xl,notifyVetoed:eu,notifyPermission:bl?Fa:"unsupported",onAskNotify:tu,openerRef:ct})]}),l.jsx("button",{className:"btn icon-btn",onClick:()=>Ta(D=>D==="dark"?"light":"dark"),title:`Switch to ${qn==="dark"?"light":"dark"} mode (T)`,"aria-label":`Switch to ${qn==="dark"?"light":"dark"} mode`,children:qn==="dark"?l.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:[l.jsx("circle",{cx:"7",cy:"7",r:"2.5"}),l.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"})]}):l.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:l.jsx("path",{d:"M11.8 8.4A5 5 0 1 1 5.6 2.2a4 4 0 0 0 6.2 6.2Z"})})})]})]})]}),pr?l.jsxs("div",{className:"ver-banner done",role:"status",children:[l.jsx("span",{className:"ver-dot"}),l.jsxs("strong",{children:["Restarted — now running v",pr,"."]}),l.jsx("span",{className:"ver-sub",children:"The canvas replayed from the event log."})]}):Io&&!Ee?l.jsxs("div",{className:"conn-banner",role:"alert",children:[l.jsx("span",{className:"conn-dot"}),fr?el==="npx"?"Fetching the new version with npx — this can take a minute…":`Restarting ${Zt}…`:(()=>{const D=c7({connected:Ee,paused:js});return l.jsxs(l.Fragment,{children:[`Lost connection to the ${Zt} server. Reconnecting…`,D&&l.jsx("span",{className:"conn-sub",children:D})]})})()]}):Ie&&ze?l.jsxs("div",{className:`ver-banner ${ze.kind}`,role:"status",children:[l.jsx("span",{className:`ver-dot${Lc==null?"":" armed"}`}),ze.kind==="restart"?l.jsxs(l.Fragment,{children:[l.jsxs("strong",{children:["v",ze.to," is installed — this deck still runs v",ze.from,"."]}),ee!=null&&ee.canRestart?l.jsxs(l.Fragment,{children:[l.jsx("button",{type:"button",className:"ver-act",onClick:()=>Dn(),...aa(fr),title:`Stop this process and bring it back on the same port. The canvas replays from the event log.
|
|
292
292
|
|