@paradow/ledge-relay 0.70.1 → 0.72.0
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/{chunk-WLFSST3N.js → chunk-MY7YYOJA.js} +1584 -1548
- package/dist/cli.js +1 -1
- package/dist/main.js +1 -1
- package/package.json +1 -1
- package/web/assets/{App-BdqHOwdo.js → App-DygKLdjP.js} +20 -20
- package/web/assets/{boot-81fb13Do.js → boot-gfEoIaJT.js} +1 -1
- package/web/assets/index-BEiOJOC0.js +52 -0
- package/web/assets/label-lFMIoau9.js +1 -0
- package/web/assets/{xterm-DYEeBZJ_.js → xterm-DbcwqIBy.js} +1 -1
- package/web/build.json +1 -1
- package/web/index.html +1 -1
- package/web/sw.js +1 -1
- package/web/assets/index-Nm5Em8Ta.js +0 -52
- package/web/assets/label-D0j0XMFY.js +0 -1
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/xterm-
|
|
2
|
-
var Qu=Object.defineProperty;var Zu=(t,n,s)=>n in t?Qu(t,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[n]=s;var Bt=(t,n,s)=>Zu(t,typeof n!="symbol"?n+"":n,s);import{r as f,l as
|
|
3
|
-
`).find(s=>s.trim()))==null?void 0:n.trim())??""};function Ia(t){switch(t.kind){case"question":return t.text;case"plan":return u.cards.plan;case"diff":return u.cards.diff(to(t.text)).trim();default:return to(t.text)}}const tc=["all","waiting","working"],Mr=t=>t.pending!==void 0||t.state==="waiting_permission"||t.state==="waiting_input";function Er(t,n){return n==="waiting"?Mr(t):n==="working"?t.state==="working"&&!Mr(t):!0}function ha(t){return Mr(t)?0:t.state==="working"?1:t.state==="exited"?3:2}function rl(t,n,s){s&&(t=Ju(t,{projectIds:s.projects.map(o=>o.id),order:s.order,projectOf:o=>o.projectId??null,keyOf:o=>o.id}));const a=new Map,r=new Map;for(const o of t){if(!Er(o,n))continue;const[c,i,x]=o.rig?[r,"rig",o.rig.name]:[a,"project",o.project];let d=c.get(x);d||c.set(x,d={id:`${i}:${x}`,kind:i,name:x,sessions:[],...i==="project"?{project:o.projectId??null}:{}}),d.sessions.push(o)}const l=o=>({...o,sessions:o.sessions.map((c,i)=>[c,i]).sort((c,i)=>ha(c[0])-ha(i[0])||c[1]-i[1]).map(([c])=>c)});return[...[...a.values()].map(o=>s?o:l(o)),...[...r.values()].map(l)]}const ll=["projects","rigs"];function cx(t,n){const s=rl(t,"all");if(n==="projects")return s;const a=t.filter(r=>!r.rig).map((r,l)=>[r,l]).sort((r,l)=>ha(r[0])-ha(l[0])||r[1]-l[1]).map(([r])=>r);return[...s.filter(r=>r.kind==="rig"),...a.length?[{id:"outside",kind:"outside",name:u.sessions.outsideRig,sessions:a}]:[]]}function dx(t){if(t.kind!=="project")return null;const n=t.sessions.map(ms);return n.includes("perm")?"perm":n.includes("ask")?"ask":null}function ux(t){return t.finishedAt!==void 0||t.state==="exited"?"done":t.state==="waiting_permission"?"perm":t.state==="waiting_input"?"ask":t.state==="working"?"work":"idle"}const nc=t=>({all:t.length,waiting:t.filter(n=>Er(n,"waiting")).length,working:t.filter(n=>Er(n,"working")).length});function ms(t){const n=kn([t])[0];return n?n.kind==="question"?"ask":"perm":t.state==="waiting_permission"?"perm":t.state==="waiting_input"?"ask":t.state==="working"?"work":t.state==="exited"?"done":"idle"}const mx=t=>ma(t).length;function xx(t,n,s=Date.now()){const a=u.sessions.line;if(n==="working")return px(t);const r=sc(t),l=r===void 0?"":` · ${r} %`,o=kn([t])[0];if(o)return(o.kind==="permission"?a.permission:u.cards.pill[o.kind])+l;switch(t.state){case"waiting_permission":return a.permission+l;case"waiting_input":return u.cards.pill.question+l;case"working":return a.working+l;case"exited":return t.exitedAt?a.ended(zi(t.exitedAt,s)):a.endedPlain;case"error":return a.error;default:return a.idle+l}}const px=t=>{var n;return((n=t.doing)==null?void 0:n.label)||u.sessions.line.thinking},sc=t=>t.context?Math.round(Math.min(1,t.context.used/t.context.window)*100):void 0;function fx(t){if(t.rig)return t.rig.role;if(t.branch)return t.branch.split("/").filter(Boolean).pop()??t.branch}function is({d:t,size:n=16,fill:s}){return e.jsxs("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.map((a,r)=>e.jsx("path",{d:a},r)),s==null?void 0:s.map((a,r)=>e.jsx("path",{d:a,fill:"currentColor",stroke:"none"},`f${r}`))]})}const ss={chevronLeft:{d:["m15 18-6-6 6-6"]},chevronRight:{d:["m9 18 6-6-6-6"]},close:{d:["M18 6 6 18","m6 6 12 12"]},check:{d:["M20 6 9 17l-5-5"]},plus:{d:["M12 5v14","M5 12h14"]}},Ye=(t,n,s)=>`M${t-s} ${n}a${s} ${s} 0 1 0 ${2*s} 0a${s} ${s} 0 1 0 ${-2*s} 0`,Yn=(t,n,s,a,r)=>`M${t+r} ${n}h${s-2*r}a${r} ${r} 0 0 1 ${r} ${r}v${a-2*r}a${r} ${r} 0 0 1 ${-r} ${r}h${-(s-2*r)}a${r} ${r} 0 0 1 ${-r} ${-r}v${-(a-2*r)}a${r} ${r} 0 0 1 ${r} ${-r}z`,hx={back:ss.chevronLeft.d,chevron:ss.chevronRight.d,close:ss.close.d,check:ss.check.d,plus:ss.plus.d,gear:["M15 12a3 3 0 1 1-6 0a3 3 0 1 1 6 0","M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1.1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1.1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1Z"],terminal:["m4 17 6-6-6-6","M12 19h8"],eye:["M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z",Ye(12,12,3)],arrowRight:["M5 12h14","m13 6 6 6-6 6"],arrowUp:["m5 12 7-7 7 7","M12 19V5"],arrowDown:["m5 12 7 7 7-7","M12 5v14"],plane:["m22 2-7 20-4-9-9-4Z","M22 2 11 13"],external:["M15 3h6v6","M10 14 21 3","M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"],stop:["M8 6h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2z"],power:["M12 3v9","M6.3 6.3a8 8 0 1 0 11.4 0"],resume:["M4 12a8 8 0 1 0 2.3-5.6","M4 4v4h4","M10 9l5 3-5 3z"],monitor:["M5 4h14a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z","M8 20h8","M12 16v4"],warning:["m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3","M12 9v4","M12 17h.01"],edit:["M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7","M18.38 2.62a2.12 2.12 0 1 1 3 3L12.36 14.64a2 2 0 0 1-.85.51l-2.87.84.84-2.87a2 2 0 0 1 .5-.85z"],spinner:["M21 12a9 9 0 1 1-6.22-8.56"],inbox:["M4 13l3-8h10l3 8v6H4z","M4 13h5l1 2h4l1-2h5"],sessions:[Yn(3,4,18,16,2),"M7 9h10M7 13h6"],pr:[Ye(6,5,2.2),Ye(6,19,2.2),Ye(18,19,2.2),"M6 7.2v9.6M18 16.8V10a3 3 0 0 0-3-3h-4","M13 5l-2 2 2 2"],rigs:[Ye(6,6,2.5),Ye(18,6,2.5),Ye(12,18,2.5),"M8 7.5l3 8M16 7.5l-3 8M8.5 6h7"],ledge:[Yn(4,8,16,12,3),"M12 8V4.5",Ye(9,14,1),Ye(15,14,1)],search:[Ye(11,11,7),"M20 20l-4-4"],more:[Ye(12,5,1.4),Ye(12,12,1.4),Ye(12,19,1.4)],send:["M12 19V5M5 12l7-7 7 7"],wifioff:["M12 20h.01M8.5 16.4a5 5 0 0 1 7 0M5 12.9a10 10 0 0 1 5.2-2.7M19 12.9a10 10 0 0 0-1.9-1.3M2 8.8a15 15 0 0 1 4.2-2.7M22 8.8A15 15 0 0 0 10.7 5M2 2l20 20"],cloud:["M2 2l20 20M5.8 5.8A7 7 0 0 0 7 20h10a5 5 0 0 0 2.6-.7M20.8 16.4A5 5 0 0 0 17 10h-1.3A7 7 0 0 0 10 5.1"],refresh:["M3 12a9 9 0 0 1 15.7-6L21 8M21 3v5h-5M21 12a9 9 0 0 1-15.7 6L3 16M3 21v-5h5"],atelier:[Yn(3,10,18,5,1),Ye(7,6,2),Ye(17,6,2),"M6 15v4M18 15v4"],plan:["M9 4h6v3H9z","M7 5H5v16h14V5h-2","m9 12 1.5 1.5L14 10","M9 17h6"],keyboard:["M3 7h18v10H3z","M7 11h.01","M11 11h.01","M15 11h.01","M8 14h8"],task:["M6.9 3.75h10.2a2.4 2.4 0 0 1 2.4 2.4v11.7a2.4 2.4 0 0 1-2.4 2.4H6.9a2.4 2.4 0 0 1-2.4-2.4V6.15a2.4 2.4 0 0 1 2.4-2.4z","M8.25 9h7.5","M8.25 13.5h5.25"],reply:["M9.75 6 3.75 12l6 6","M4.5 12h9.75a6 6 0 0 1 6 6v.75"],passkey:["M12 3a6 6 0 0 0-6 6v3h12V9a6 6 0 0 0-6-6z","M5 12h14v9H5z"],phone:["M8 2h8a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z","M11 18h2"],tablet:["M6 3h12a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z","M11 18h2"],key:[Ye(7.5,15.5,5.5),"m21 2-9.6 9.6M15.5 7.5l3 3L22 7l-3-3"],shield:["M12 3 4 6v6c0 5 8 9 8 9s8-4 8-9V6z"],laptop:[Yn(4,4,16,11,1.5),"M2 19h20"],face:["M4 8V6a2 2 0 0 1 2-2h2M16 4h2a2 2 0 0 1 2 2v2M20 16v2a2 2 0 0 1-2 2h-2M8 20H6a2 2 0 0 1-2-2v-2M9 9v1M15 9v1M12 9v4h-1M9 15.5a4 4 0 0 0 6 0"],unlink:["M18.8 13.4l1.6-1.6a4.5 4.5 0 0 0-6.4-6.4l-1.6 1.6M5.2 10.6l-1.6 1.6a4.5 4.5 0 0 0 6.4 6.4l1.6-1.6M8 2v3M2 8h3M16 22v-3M22 16h-3"],clock:[Ye(12,12,9),"M12 7v5l3 2"],alarm:[Ye(12,13,8),"M12 9v4l2.5 1.5M5 3 2 6M19 3l3 3"],play:["M7 5v14l11-7z"],lock:[Yn(3,11,18,11,2),"M7 11V7a5 5 0 0 1 10 0v4"],bell:["M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9M10.3 21a1.9 1.9 0 0 0 3.4 0"],alert:["M12 3l10 18H2z","M12 10v4M12 17.5v.01"],cpu:[Yn(6,6,12,12,2),"M9 2v4M15 2v4M9 18v4M15 18v4M2 9h4M2 15h4M18 9h4M18 15h4"],camera:["M4 8h3l2-3h6l2 3h3v11H4z",Ye(12,13,3.5)],folder:["M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"],list:["M9 6h11M9 12h11M9 18h11M4 6l1 1 2-2M4 12l1 1 2-2M4 18h2"],down:["M6 9l6 6 6-6"],branch:[Ye(6,5,2),Ye(6,19,2),Ye(18,8,2),"M6 7v10M18 10c0 4-6 3-12 7"],merge:[Ye(6,5,2.2),Ye(6,19,2.2),Ye(18,12,2.2),"M6 7.2v9.6M6 7.2c0 3 4 4.8 9.8 4.8"],file:["M14 3H6a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8z","M14 3v5h5"],commit:[Ye(12,12,3.5),"M3 12h5.5M15.5 12H21"]};function z({name:t,className:n="size-5",stroke:s=1.6}){return e.jsx("svg",{className:`flex-none ${n}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:s,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:hx[t].map((a,r)=>e.jsx("path",{d:a},r))})}const gx={work:"bg-info",perm:"bg-approval",ask:"bg-attention",idle:"bg-ok",done:"bg-muted opacity-50",off:"bg-transparent shadow-[inset_0_0_0_1.5px_var(--color-muted)]",rig:"bg-task",plain:"bg-muted"};function Pe({state:t,pulse:n=!1,label:s}){return e.jsx("span",{"data-dot":t,...s?{role:"img","aria-label":s}:{"aria-hidden":!0},className:`inline-block size-2 flex-none rounded-full ${gx[t]} ${n?"animate-[ledge-pulse_1.6s_ease-in-out_infinite]":""}`})}const bx={claude:"CC",codex:"CX",cursor:"CU",omp:"OM"};function Xn({tool:t}){return e.jsx("span",{"data-runtime":t,className:"flex-none rounded-[5px] bg-secondary px-[5px] py-px font-mono text-[11px] leading-4 font-medium",children:bx[t]})}const jx={plain:"border-input text-muted",perm:"border-approval/50 text-approval",urgent:"border-approval/50 text-approval",ask:"border-attention/50 text-attention",work:"border-info/45 text-info",ok:"border-ok/45 text-ok",rig:"border-task/50 text-task",risk:"border-transparent bg-destructive text-primary-fg font-semibold"};function Lt({tone:t="plain",children:n}){return e.jsx("span",{"data-pill":t,className:`inline-flex h-5 flex-none items-center rounded-lg border px-[7px] text-[11.5px] whitespace-nowrap ${jx[t]}`,children:n})}function cs({title:t,dot:n,count:s,sub:a,tone:r,none:l,label:o,children:c}){return e.jsxs("section",{"aria-label":t??o,className:`flex-none overflow-hidden rounded-[10px] border bg-surface dark:bg-transparent ${r==="rigs"?"border-task/45":"border-line"}`,children:[t&&e.jsxs("div",{className:"flex min-h-11 items-center gap-2 border-b border-line px-3",children:[n&&e.jsx(Pe,{state:n}),e.jsx("b",{className:"text-body font-semibold whitespace-nowrap",children:t}),s!==void 0&&e.jsx("span",{className:"text-[12.5px] text-muted",children:s}),a&&e.jsx("span",{className:"min-w-0 flex-1 truncate text-small text-muted",children:a})]}),l!==void 0?e.jsx("p",{className:"p-3 text-[13px] text-muted",children:l}):e.jsx("div",{className:"flex flex-col",children:c})]})}function ol({lead:t,title:n,sub:s,subTone:a,meta:r,metaWarn:l=!1,selected:o=!1,stale:c=!1,pressed:i=!1,href:x,press:d,children:m}){const p=`flex min-h-[52px] items-center gap-2 border-b border-line px-3 py-1.5 text-[13.5px] last:border-b-0 ${c?"opacity-60":""} ${o?"bg-secondary shadow-[inset_2px_0_0_var(--color-primary)]":""} ${i?"shadow-[inset_0_0_0_2px_var(--color-ring)]":""}`,g=e.jsxs(e.Fragment,{children:[t,e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate",children:n}),s!==void 0&&e.jsx("span",{className:`truncate text-small leading-4 ${a==="perm"?"text-approval":"text-muted"}`,children:s})]}),r!==void 0&&e.jsx("span",{className:`font-mono text-small whitespace-nowrap ${l?"text-attention":"text-muted"}`,children:r}),m]});return x?e.jsx("a",{href:x,"aria-current":o?"page":void 0,className:p,...d,children:g}):e.jsx("div",{className:p,children:g})}const yx={plain:"border-line",perm:"border-destructive/45",ask:"border-attention/45",rig:"border-destructive/40"};function Bs({tone:t="plain",selected:n=!1,label:s,children:a}){return e.jsx("article",{"aria-label":s,"data-card":t,className:`flex flex-col gap-2.5 rounded-lg border bg-surface p-3 ${yx[t]} ${n?"shadow-[0_0_0_2px_var(--color-ring)]":""}`,children:a})}function Rn({glyph:t,title:n,body:s,action:a,framed:r=!0,list:l=!1}){return e.jsxs("div",{"data-list-state":l?"":void 0,className:"flex flex-col items-center gap-1.5 px-4 pt-[26px] pb-[22px] text-center",children:[r?e.jsx("div",{"aria-hidden":"true",className:"grid size-12 place-items-center rounded-[10px] border border-line text-muted",children:t}):e.jsx("div",{"aria-hidden":"true",className:"text-muted",children:t}),e.jsx("h2",{className:"mt-1.5 text-[17px] leading-6 font-semibold",children:n}),e.jsx("p",{className:"max-w-[300px] text-[13.5px] text-muted",children:s}),a&&e.jsx("div",{className:"mt-2",children:a})]})}const Nx={outline:"border-input bg-surface dark:bg-transparent text-fg active:bg-raised",primary:"border-transparent bg-primary text-primary-fg active:bg-primary-hover",ghost:"border-transparent bg-transparent text-muted text-[13px] active:bg-raised"},kx={md:"h-11 px-3.5 text-body",sm:"h-9 px-3 text-[13px]",xs:"h-8 px-2.5 text-[12.5px]"},rt=({variant:t="outline",size:n="md",className:s}={})=>["inline-flex items-center justify-center gap-2 rounded-lg border font-medium whitespace-nowrap transition-colors duration-100 disabled:opacity-45",Nx[t],t==="ghost"?"h-9 px-3.5":kx[n],s??""].filter(Boolean).join(" ");function La({back:t,tool:n,name:s,dot:a,pulse:r=!1,sub:l,under:o=!1,more:c}){return e.jsxs("header",{className:"bleed flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-0.5",children:[t,n&&e.jsx(Xn,{tool:n}),o&&l?e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("b",{className:"min-w-0 truncate text-base leading-5 font-semibold",children:s}),a&&e.jsx(Pe,{state:a,pulse:r})]}),e.jsx("span",{className:"truncate text-[12px] leading-4 text-muted",children:l})]}):e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-base font-semibold whitespace-nowrap",children:s}),a&&e.jsx(Pe,{state:a,pulse:r}),l&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:l}),e.jsx("span",{className:"flex-1"})]}),c]})}function ac({label:t,sendLabel:n,placeholder:s,offlinePlaceholder:a,value:r,onChange:l,onSend:o,offline:c=!1}){const i=f.useId(),x=!c&&r.trim()!=="";return e.jsxs("div",{className:`flex items-end gap-2 rounded-[10px] border border-input bg-surface py-[5px] pr-[5px] pl-3 focus-within:border-ring focus-within:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)] ${c?"opacity-55":""}`,children:[e.jsx("label",{htmlFor:i,className:"sr-only",children:t}),e.jsx("textarea",{id:i,rows:1,value:c?"":r,disabled:c,placeholder:c?a:s,onChange:d=>l(d.target.value),className:"min-h-[34px] min-w-0 flex-1 resize-none bg-transparent py-[7px] text-base leading-[22px] text-fg outline-none placeholder:text-muted"}),e.jsx("button",{type:"button",disabled:!x,onClick:o,"aria-label":n,title:n,className:"grid size-9 flex-none place-items-center rounded-lg bg-primary text-primary-fg disabled:opacity-40",children:e.jsx(z,{name:"send",className:"size-[18px]"})})]})}function vx({children:t}){return e.jsx("code",{className:"block rounded-[5px] bg-raised px-[9px] py-[7px] font-mono text-small leading-[18px] break-all whitespace-pre-wrap",children:t})}const rc={permission:"approval",question:"attention",plan:"info",diff:"info"};function wx(t,n){if(n){const s=n.risk==="high"&&n.kind!=="question";return{tone:s?"danger":rc[n.kind],label:s?u.risk.badge:u.kind[n.kind]}}switch(t.state){case"waiting_permission":return{tone:"approval",label:u.kind.permission};case"waiting_input":return{tone:"attention",label:u.kind.question};case"idle":return{tone:"ok",label:u.agents.state.idle};case"exited":return{tone:"muted",label:u.agents.state.exited};case"error":return{tone:"danger",label:u.agents.state.error};default:return{tone:"info",label:u.agents.state.working}}}const Sx=t=>wx(t,kn([t])[0]);function lc({store:t,label:n,ids:s,offline:a,startOpen:r=!1,onCancel:l}){const[o,c]=f.useState(r),[i,x]=f.useState(""),[d,m]=f.useState(!1),[p,g]=f.useState(null),h=async()=>{if(s.length>xa){g({lines:[u.agents.tooMany(s.length,xa)],error:!0});return}m(!0);const N=await t.broadcast(s,i.trim());if(m(!1),N.sent){const k=N.sent;g({lines:[...k.length?[u.agents.sentTo(k)]:[u.agents.nobody],...(N.refused??[]).map(C=>u.agents.refusedLine(C.name,C.reason))],error:k.length===0}),k.length&&(c(r),x(""))}else N.status==="expired"?g({lines:[u.agents.uncertain],error:!0}):g({lines:[u.agents.notSent],error:!0})};return e.jsxs("div",{className:"pb-2",children:[!o&&e.jsx("button",{type:"button",disabled:a,onClick:()=>{g(null),c(!0)},className:"text-meta text-info disabled:opacity-60",children:u.agents.writeGroup}),o&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:`group-${s[0]}`,className:"sr-only",children:u.agents.writeGroupLabel(n)}),e.jsx("textarea",{id:`group-${s[0]}`,rows:2,value:i,disabled:d,placeholder:u.agents.writeGroupPlaceholder,onChange:N=>x(N.target.value),className:"min-h-11 w-full resize-none rounded-[14px] border border-input bg-surface px-3.5 py-[11px] text-base leading-5 text-fg placeholder:text-muted disabled:opacity-60"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ue,{variant:"ghost",className:"flex-1",disabled:d,onClick:()=>{c(!1),x(""),l==null||l()},children:u.agents.cancel}),e.jsx(Ue,{variant:"primary",className:"flex-[2]",disabled:d||!i.trim(),onClick:()=>void h(),children:u.agents.send})]})]}),p&&e.jsx("div",{role:"status",className:`mt-1 text-meta ${p.error?"text-attention":"text-muted"}`,children:p.lines.map((N,k)=>e.jsx("p",{className:"[overflow-wrap:anywhere]",children:N},k))})]})}const no=new Set(["-o","--push-option","--repo","--receive-pack","--exec"]),Cx=new Set(["-f","--force","--force-with-lease","--force-if-includes","--delete","-d","--mirror","--prune"]);function $x(t){const n=t.trim().split(/\s+/);if(n[0]!=="git")return null;const s=n.indexOf("push");if(s<1)return null;let a=!1;const r=[],l=n.slice(s+1);for(let d=0;d<l.length;d++){const m=l[d];if(m.startsWith("--")){const p=m.split("=")[0];Cx.has(p)?a=!0:no.has(p)&&!m.includes("=")&&d++}else m.startsWith("-")&&m.length>1?/[fd]/.test(m.slice(1))?a=!0:no.has(m)&&d++:r.push(m)}const[o="",...c]=r;c.some(d=>d.startsWith("+")||d.startsWith(":"))&&(a=!0);const i=c[0],x=i==null?void 0:i.replace(/^\+/,"").split(":").pop();return{remote:o,...x?{branch:x}:{},force:a}}function Mx(t){return t.risk!=="low"||t.riskReason!=="edit_inside_folder"?null:{title:u.detail.editsInProject,body:u.detail.editsInProjectBody}}function oc(t){if(t.risk==="low")return null;const n=u.consequence,s=t.riskReason;if(s==="pushes"){const a=$x(t.text),r=a!=null&&a.remote?a.branch?`${a.remote}/${a.branch}`:a.remote:n.configuredRemote;return a!=null&&a.force?{title:n.forceTitle,body:n.forceBody(a.remote?r:void 0),destination:r}:{title:n.pushTitle,body:n.pushBody,destination:r}}switch(s){case"destroys":case"deploys":case"publishes":case"pipes_to_shell":case"network":case"writes_outside_folder":case"sensitive_path":case"script":case"plan":{const[a,r]=n[s];return{title:a,body:r}}default:{const[a,r]=n.unknown;return{title:a,body:r}}}}const il=Ra,Ex=/^[1-9]$/;function ic(t){const n=t.trim();return n===""?{text:n,problem:"empty"}:Ii.test(n)?{text:n,problem:"untypable"}:n.length>il?{text:n,problem:"long"}:Ex.test(n)?{text:n,problem:"digit"}:{text:n,problem:null}}function _x(t,n,s){var a;if(t.kind==="plan"||t.kind==="diff")return{kind:"examine"};if((n==null?void 0:n.decide)===!1||t.kind==="question"&&(n==null?void 0:n.questions)===!0&&t.requestId!==void 0&&((a=t.questions)!=null&&a.length))return{kind:"examine"};if(t.kind==="question"){if(s)return{kind:"readOnly"};const r=t.options??[],l=(n==null?void 0:n.freeTextAnswer)===!0;return l||r.length>0?{kind:"question",options:r,other:l}:{kind:"answerOnPc",options:r}}return t.risk==="high"?{kind:"high"}:{kind:"permission",always:Li(t.tool,t.kind,"always")}}const _r=t=>em(t.tool,{kind:t.kind,...t.pendingTool?{tool:t.pendingTool}:{}}),ga=t=>t==="project"?u.cards.always:t==="plan"?u.cards.approveAuto:u.cards.alwaysSession,so={critical:0,urgent:1,routine:2},cc=t=>[...t].sort((n,s)=>so[n.priority]-so[s.priority]||Date.parse(n.createdAt)-Date.parse(s.createdAt)),dc=t=>t.kind==="update"?"update":t.kind==="parked"?"parked":t.questions.length>0?"decision":"question",Rx=t=>(t==null?void 0:t.replace(/\.agent$|\.lead$|\.worker$/,""))??null,uc=t=>({name:t.from.seat.split("@")[0]||t.from.seat,role:Rx(t.from.role)});function ao(t,n){var r;const s=t.questions.find(l=>l.id===n),a=s==null?void 0:s.answer;return a?a.kind==="words"?a.text:((r=s.options.find(l=>l.id===a.id))==null?void 0:r.label)??a.id:null}function Tx(t,n){var s,a;switch(n.kind){case"choice":return((a=(s=t.questions.find(r=>r.id===n.questionId))==null?void 0:s.options.find(r=>r.id===n.optionId))==null?void 0:a.label)??n.optionId;case"words":case"resolve":return n.text;case"seen":return""}}function mc(t,n){const s=Object.values(n).filter(l=>l.message.type==="openrig.answer"&&l.message.qitemId===t).sort((l,o)=>l.at.localeCompare(o.at)),a=s[s.length-1];if(!a)return{kind:"none"};const r=a.message.answer;if(a.rig){const l=a.rig;return l.rejected?{kind:"refused",answer:r,reason:l.rejected}:l.ok?l.outcome==="recorded"?{kind:"recorded",answer:r}:l.outcome==="already"?{kind:"already"}:{kind:"sent",answer:r}:l.error==="closed"||l.error==="not_found"?{kind:"already"}:l.error==="uncertain"?{kind:"uncertain",answer:r}:{kind:"failed",answer:r,error:l.error??"unreachable",...l.message?{message:l.message}:{}}}return yn(a.phase)?a.phase==="uncertain"?{kind:"uncertain",answer:r}:{kind:"sending",answer:r}:a.phase==="applied"?{kind:"sent",answer:r}:{kind:"failed",answer:r,error:a.reason??"unreachable"}}const xc=5e3;function ro(t,n){return[...t.map(s=>({name:"request",sessionId:s.sessionId,key:s.key})),...cc(n).filter(s=>s.kind!=="update").map(s=>({name:"ask",id:s.id}))]}const er=(t,n)=>t.name==="request"?n.name==="request"&&t.sessionId===n.sessionId:n.name==="ask"&&t.id===n.id;function Ax(t,n,s=t){const a=t.filter(o=>!er(o,n)),r=s.findIndex(o=>er(o,n));return(r<0?[]:s.slice(r+1)).find(o=>a.some(c=>er(c,o)))??a[0]??null}function pc(t,n,s){var c;const a=(c=n.find(i=>i.id===t.sessionId))==null?void 0:c.pending,r=(a==null?void 0:a.key)===t.key,l=Object.values(s).filter(i=>"id"in i.message&&i.message.id===t.sessionId&&Lm(i.message)===t.key).sort((i,x)=>i.at.localeCompare(x.at)),o=l.find(i=>i.phase==="applied")??l[l.length-1];if(o){const i=o.message;switch(o.phase){case"sending":return{kind:"sending"};case"uncertain":return{kind:"uncertain"};case"applied":return{kind:"applied",...i.type==="session.decide"?{decision:i.decision}:{},...i.type==="session.reply"?{answer:i.text}:{},...i.type==="session.answer"?{answer:i.answers.flatMap(x=>x.selected).join(", ")}:{}};case"rejected":return o.reason==="stale"&&!r?a!=null&&a.key?{kind:"changed"}:{kind:"handledElsewhere"}:{kind:"rejected",reason:o.reason??"invalid"};case"failed":return{kind:"failed",reason:o.reason??"invalid"}}}return r?{kind:"idle"}:{kind:"handledElsewhere"}}function xs(t=4e3){const[n,s]=f.useState(!1);return f.useEffect(()=>{if(!n)return;const a=setTimeout(()=>s(!1),t);return()=>clearTimeout(a)},[n,t]),[n,s]}function Kt(){const[t,n]=f.useState(Date.now);return f.useEffect(()=>{const s=setInterval(()=>n(Date.now()),15e3);return()=>clearInterval(s)},[]),t}const Ix={approval:"text-approval bg-approval/10",attention:"text-attention bg-attention/10",info:"text-info bg-info/10",ok:"text-ok bg-ok/10",muted:"text-muted bg-fg/[0.05]",danger:"text-danger-fg bg-danger-fg/10"};function qs({tone:t,label:n}){return e.jsx("span",{className:`inline-flex h-[22px] flex-none items-center rounded-md px-2 text-meta leading-none font-medium whitespace-nowrap ${Ix[t]}`,children:n})}function Lx({kind:t,risk:n="low"}){const s=n==="high"&&t!=="question";return e.jsx(qs,{tone:s?"danger":rc[t],label:s?u.risk.badge:u.kind[t]})}function Ox({text:t}){return e.jsx("pre",{className:"my-3.5 rounded-control border border-line bg-well p-3.5 font-mono text-small leading-[1.8] break-words whitespace-pre-wrap [overflow-wrap:anywhere]",children:t})}const ps=t=>{var n;return{fresh:t.fresh,pc:((n=t.daemon)==null?void 0:n.name)??null}};function fc({link:t}){return e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-meta whitespace-nowrap text-muted",children:[e.jsx("i",{className:`inline-block size-1.5 flex-none rounded-full ${t.fresh?"bg-ok":"bg-muted"}`}),e.jsxs("span",{className:"truncate",children:[t.pc?`${t.pc} · `:"",t.fresh?u.link.online:u.link.offline]})]})}function Zt({fallback:t,label:n}){const s=Ym(t),a=s.inApp?s.known?u.nav.backTo[s.route.name]??u.nav.back:u.nav.back:n;return e.jsx("a",{href:ce(s.route),"data-back":t.name,"aria-label":a,title:a,onClick:r=>{r.preventDefault(),Aa(t)},className:Ot({className:"-ml-2"}),children:e.jsx(z,{name:"back"})})}function Hs({title:t,fallback:n,label:s,link:a}){return e.jsx("header",{className:"flex-none border-b border-line pt-2 pb-3",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Zt,{fallback:n,label:s}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),e.jsx(fc,{link:a})]})})}const tr={},hc={grow:{ms:320,ease:"cubic-bezier(.22,1,.36,1)",delayMs:0},shrink:{ms:260,ease:"cubic-bezier(.65,0,.35,1)",delayMs:60},cardExit:{ms:300,ease:"cubic-bezier(.65,0,.35,1)",delayMs:180},pop:{ms:260,ease:"cubic-bezier(.34,1.3,.64,1)",delayMs:0},fadeIn:{ms:180,ease:"ease-out",delayMs:140},fadeOut:{ms:100,ease:"ease-in",delayMs:0},hover:{ms:150,ease:"ease-out",delayMs:0}},Dx=()=>{const t=tr==null?void 0:tr.VITE_LEDGE_MOTION;return t===void 0?1:Number(t)},St=t=>`${Math.round(t*Dx())}ms`;function Fx(t){return t.map(([n,s,a])=>{const r=hc[s];return`${n} ${St(r.ms)} ${r.ease} ${St(a??r.delayMs)}`}).join(", ")}const Px="(prefers-reduced-motion: reduce)",gc=()=>typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia(Px):null;function zx(t){const n=gc();return n==null||n.addEventListener("change",t),()=>n==null?void 0:n.removeEventListener("change",t)}const Bx=()=>{var t;return((t=gc())==null?void 0:t.matches)??!1};function qx(){return!1}function bc(){return f.useSyncExternalStore(zx,Bx,()=>!1)}const Hx=()=>({reduced:bc()||qx(),app:!1,setReduced(){}});let Ux=Hx;function Wx(){return Ux()}function Kx(t){return t==="dark"?"signal":"pebble"}function rs(t){let n=7;for(let s=0;s<t.length;s++)n=n*31+t.charCodeAt(s)>>>0;return n}function Oa(t,n){return rs(`${t}:${n}`)%3+1}const $t={blinkMs:180,gazePx:1.4,gazeYPx:.3,askDelayMs:180,transitionMs:500,hopMs:480,touchMs:360,idleMs:1700,askMs:850,nodMs:650},nr=(t,n)=>n===0?1400+t%3500:3400+(t+n*997)%3300,sr=(t,n)=>n===0?800+t%1800:2400+(t+n*557)%2100,Rr=new Set(["done","error","readonly"]),ar=(t,n)=>n===0?3500+t%4e3:5500+(t+n*557)%3500,gn=t=>!document.hidden&&!t.closest("[inert]");function ba(t,n){document.addEventListener("visibilitychange",n);const s=new MutationObserver(n);return s.observe(document.documentElement,{attributes:!0,subtree:!0,attributeFilter:["inert"]}),()=>{document.removeEventListener("visibilitychange",n),s.disconnect()}}function Vx(t){f.useEffect(()=>{const n=t.current;if(!n)return;const s=()=>n.setAttribute("data-suspended",String(!gn(n)));return s(),ba(n,s)},[t])}function Qn(t,n,s){t.style.setProperty("--bot-gx",`${n}px`),t.style.setProperty("--bot-gy",`${s}px`)}function Gx(t,n){const{seed:s,state:a,enabled:r,askKey:l,nodKey:o,gazeReach:c=0}=n,i=rs(s),x=r&&!Rr.has(a),d=f.useRef(null),m=f.useRef(a),p=f.useRef(o),g=f.useRef(void 0);f.useEffect(()=>{const h=t.current;if(!h||!x)return;let N,k,C;const j=()=>gn(h),y=()=>{N!==void 0&&clearTimeout(N),k!==void 0&&clearTimeout(k),C!==void 0&&clearTimeout(C),N=k=C=void 0,h.removeAttribute("data-idle"),Qn(h,0,0),h.removeAttribute("data-blink")},b=()=>{if(y(),!j())return;const $=Date.now();(!d.current||d.current.h!==i)&&(d.current={h:i,blinkAt:$+nr(i,0),lookAt:$+sr(i,0),idleAt:$+ar(i,0),blinks:0,looks:0,idles:0});const v=d.current;v.blinkAt<$&&(v.blinkAt=$+nr(i,++v.blinks)),v.lookAt<$&&(v.lookAt=$+sr(i,++v.looks)),v.idleAt<$&&(v.idleAt=$+ar(i,++v.idles)),N=setTimeout(M,Math.min(v.blinkAt,v.lookAt,v.idleAt)-$)},M=()=>{if(N=void 0,!j()){y();return}const $=d.current,v=Date.now();if(v>=$.blinkAt&&(h.setAttribute("data-blink","true"),k!==void 0&&clearTimeout(k),k=setTimeout(()=>{k=void 0,h.removeAttribute("data-blink")},$t.blinkMs),$.blinkAt=v+nr(i,++$.blinks)),v>=$.lookAt){$.looks++;const A=a==="working";!h.hasAttribute("data-hover")&&!h.hasAttribute("data-transition")&&Qn(h,A?$.looks%2?$t.gazePx:-1.4:0,A?$t.gazeYPx:0),$.lookAt=v+sr(i,$.looks)}if(v>=$.idleAt){$.idles++;const A=a;!h.hasAttribute("data-hover")&&!h.hasAttribute("data-transition")&&(A==="idle"||A==="question")&&(h.setAttribute("data-idle",A==="question"?"tilt":$.idles%4===0?"stretch":"look"),C=setTimeout(()=>{C=void 0,h.removeAttribute("data-idle")},$t.idleMs)),$.idleAt=v+ar(i,$.idles)}N=setTimeout(M,Math.min($.blinkAt,$.lookAt,$.idleAt)-v)};b();const S=ba(h,()=>{j()&&N===void 0?b():j()||y()});return()=>{y(),S()}},[t,x,i,a]),f.useEffect(()=>{const h=t.current,N=m.current,k=g.current,C=p.current!==o&&o!==void 0;if(p.current=o,m.current=a,g.current=l,!h)return;Qn(h,0,0),h.removeAttribute("data-idle");const j=a==="approval"&&(N!=="approval"||l!==void 0&&l!==k),y=new Set,b=(P,W)=>{const F=setTimeout(()=>{y.delete(F),gn(h)?P():M()},W);return y.add(F),F},M=()=>{y.forEach(clearTimeout),y.clear(),["data-transition","data-gesture","data-touch","data-hover","data-idle"].forEach(P=>h.removeAttribute(P)),Qn(h,0,0)};let S=!1,$=!1;r&&gn(h)&&(N!==a&&["working","question","idle","done","error"].includes(a)&&(h.setAttribute("data-transition",a),b(()=>h.removeAttribute("data-transition"),a==="working"?$t.hopMs:a==="question"?650:$t.transitionMs)),j&&!C&&b(()=>{S=!0,h.setAttribute("data-gesture","ask"),b(()=>{h.getAttribute("data-gesture")==="ask"&&h.removeAttribute("data-gesture")},$t.askMs)},$t.askDelayMs));const v=()=>r&&!Rr.has(a)&&gn(h),A=P=>{if(!v()||P.pointerType==="touch")return;const W=h.getBoundingClientRect();if(!W.width||!W.height)return;const F=P.clientX-W.left-W.width/2,re=P.clientY-W.top-W.height/2;if(c>0&&(Math.abs(F)>W.width/2+c||Math.abs(re)>W.height/2+c)){h.hasAttribute("data-hover")&&R();return}h.setAttribute("data-hover","true"),h.removeAttribute("data-idle");const Y=H=>Math.max(-2,Math.min(2,H));Qn(h,Y(F/(W.width/2+c)*2),Y(re/(W.height/2+c)*2))},R=()=>{h.removeAttribute("data-hover"),Qn(h,0,0)},_=c>0?window:h,L=c>0?document.documentElement:h;let T;const B=()=>{v()&&(T!==void 0&&(clearTimeout(T),y.delete(T)),h.removeAttribute("data-touch"),h.getBoundingClientRect(),h.setAttribute("data-touch","true"),T=b(()=>h.removeAttribute("data-touch"),$t.touchMs))};_.addEventListener("pointermove",A),L.addEventListener("pointerleave",R),h.addEventListener("click",B);const E=ba(h,()=>{gn(h)||($=!0,M())});return()=>{M(),E(),_.removeEventListener("pointermove",A),L.removeEventListener("pointerleave",R),h.removeEventListener("click",B);const P=["data-paused","data-frozen","data-reduced","data-readonly"].some(W=>h.getAttribute(W)==="true");!S&&j&&!C&&h.getAttribute("data-state")===a&&r&&!$&&gn(h)&&!P&&(g.current=k)}},[t,a,r,l,o,i,c])}function Xx(t,n,s,a,r){const l=f.useRef(n);f.useEffect(()=>{const o=t.current,c=l.current!==n;if(l.current=n,!o||!c||n===void 0||!s||!gn(o)||Rr.has(a))return;o.setAttribute("data-gesture","nod");const i=setTimeout(()=>{o.getAttribute("data-gesture")==="nod"&&o.removeAttribute("data-gesture")},$t.nodMs),x=()=>{clearTimeout(i),o.getAttribute("data-gesture")==="nod"&&o.removeAttribute("data-gesture")},d=ba(o,()=>{gn(o)||x()});return()=>{d(),x()}},[t,n,s,a,r])}const Yx={claude:"Claude Code",codex:"Codex",cursor:"Cursor Agent",omp:"omp"},Qx={starting:{eyes:"open",eye:"starting"},working:{eyes:"open",eye:"working"},approval:{eyes:"open",eye:"approval",tilt:[-4,3,-2],lift:-1},question:{eyes:"wide",eye:"question",tilt:[4,-3,6]},idle:{eyes:"happy",eye:"idle"},error:{eyes:"error",eye:"error",tilt:[-7,-6,-5],lift:2},done:{eyes:"sleep",eye:"done"},readonly:{eyes:"open",eye:"done"}},Zx="0 0 96 96",jc={claude:"10 18 76 64",codex:"5 7 87 82",cursor:"11 8 74 82",omp:"10 18 76 68"},Jx=Object.fromEntries(Object.entries(jc).map(([t,n])=>[t,Number(n.split(" ")[2])])),ep={claude:"M24 24H72Q75 24 75 27V43H82Q84 43 84 45V52Q84 54 82 54H75V62Q75 64 73 64H70V75Q70 77 68 77H66Q64 77 64 75V64H59V75Q59 77 57 77H55Q53 77 53 75V64H43V75Q43 77 41 77H39Q37 77 37 75V64H32V75Q32 77 30 77H28Q26 77 26 75V64H23Q21 64 21 62V54H14Q12 54 12 52V45Q12 43 14 43H21V27Q21 24 24 24Z",codex:"M30 25C31 13 48 10 57 20C69 14 84 23 81 37C92 46 87 62 76 65C76 80 58 86 48 77C35 85 20 78 21 66C7 61 7 45 18 38C13 28 21 20 30 25Z",cursor:"M43 13Q48 10 53 13L77 27Q82 30 82 36V64Q82 69 77 72L53 85Q48 88 43 85L19 72Q14 69 14 64V36Q14 30 19 27Z",omp:"M17 22H79Q83 22 83 26V48Q83 52 79 52H71V79Q71 83 67 83H58Q54 83 54 79V52H41V67Q41 71 37 71H28Q24 71 24 67V52H17Q13 52 13 48V26Q13 22 17 22Z"},tp={claude:"translate(0 -8)",codex:void 0,cursor:"translate(31.5 58) skewY(27) scale(.86) translate(-48.5 -49)",omp:"translate(0 -12)"},np=240;function Da({tool:t,state:n,pose:s,size:a,shownSize:r,theme:l,seed:o,readOnly:c=!1,frozen:i=!1,paused:x=!1,reducedMotion:d,askKey:m,nodKey:p,className:g}){var W;const h=f.useRef(null),N=`bot-shell-${f.useId().replace(/[^A-Za-z0-9_-]/g,"")}`,k=Wx(),j=bc()||(d??k.reduced),y=a<=20,b=Qx[n],M=!c&&n!=="done"&&n!=="readonly",S=el(),$=rs(o),v=n==="working"&&!j&&!c&&!i&&!x,A=r??a,_=Math.min(7,Math.max(2,A*.12))/A*(y?Jx[t]:96),L=3600+$%9*100,T=!y&&A>20,B=!j&&!c&&n!=="readonly"&&!i&&!x;Vx(h),Gx(h,{seed:o,state:n,askKey:m,nodKey:p,enabled:B&&T,gazeReach:np}),Xx(h,p,B&&T,n,m);const E={"--bot-size":`${a}px`,"--bot-eye":`var(--bot-eye-${b.eye})`,"--bot-tilt":`${((W=b.tilt)==null?void 0:W[s-1])??0}deg`,"--bot-lift":`${b.lift??0}px`,"--bot-breath":St(4800+$%17*100),"--bot-phase":`-${St($%43*100)}`,"--bot-hop":`${_.toFixed(2)}px`,"--bot-hop-cycle":St(L),"--bot-ease":hc.grow.ease,"--bot-material-ms":St(240),"--bot-eye-ms":St(260),"--bot-pose-ms":St(300),"--bot-gaze-ms":St(450),"--bot-blink-ms":St($t.blinkMs),"--bot-ask-ms":St($t.askMs),"--bot-nod-ms":St($t.nodMs),"--bot-question-ms":St(650),"--bot-arrival-ms":St($t.transitionMs),"--bot-entry-hop-ms":St($t.hopMs),"--bot-touch-ms":St($t.touchMs),"--bot-idle-ms":St($t.idleMs)},P=`${Yx[t]} · ${S.botLabel[n]}${c&&n!=="readonly"?` · ${S.botReadOnly}`:""}${i?` · ${S.botNotLive}`:""}`;return e.jsxs("svg",{ref:h,className:g?`bot ${g}`:"bot",role:"img","aria-label":P,width:a,height:a,viewBox:y?jc[t]:Zx,"data-tool":t,"data-state":n,"data-eyes":b.eyes,"data-pose":s,"data-material":Kx(l),"data-simplified":String(y),"data-detailed":String(T),"data-readonly":String(c||n==="readonly"),"data-halo":String(M),"data-frozen":String(i),"data-paused":String(x),"data-reduced":String(j),"data-hop":String(v),style:E,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:N,x1:".1",y1:"0",x2:".8",y2:"1",gradientUnits:"objectBoundingBox",children:[e.jsx("stop",{className:"shell-top"}),e.jsx("stop",{className:"shell-bottom",offset:"1"})]})}),e.jsx("ellipse",{className:"ground",cx:"48",cy:"90",rx:"25",ry:"3"}),e.jsx("g",{className:"hop",children:e.jsx("g",{className:"body",children:e.jsx("g",{className:"arrival",children:e.jsx("g",{className:"signature",children:e.jsx("g",{className:"touch",children:e.jsxs("g",{className:"pose",children:[e.jsx("path",{className:"shell",d:ep[t],fill:`url(#${N})`}),t==="cursor"&&e.jsxs("g",{className:"facets",children:[e.jsx("path",{className:"cube-top",d:"M43 13Q48 10 53 13L77 27Q80 29 81 32L48 49L15 32Q16 29 19 27Z"}),e.jsx("path",{className:"cube-side",d:"M48 49L81 32Q82 34 82 36V64Q82 69 77 72L53 85Q50 87 48 87Z"}),e.jsx("path",{className:"cube-edge",d:"M17 32L48 49L79 32M48 49V83"})]}),t==="claude"&&e.jsx("path",{className:"shine",d:"M27 28H69"}),e.jsx("g",{transform:tp[t],children:e.jsx("g",{className:"gaze",children:e.jsxs("g",{className:"eye-blink",children:[e.jsxs("g",{className:"eye-open",children:[e.jsx("rect",{x:"36",y:"43",width:"6",height:"12",rx:t==="claude"?.6:3}),e.jsx("rect",{x:"55",y:"43",width:"6",height:"12",rx:t==="claude"?.6:3})]}),T&&e.jsxs("g",{className:"eye-glint",children:[e.jsx("rect",{x:"37.5",y:"44.5",width:"2.4",height:"2.4",rx:t==="claude"?0:1.2}),e.jsx("rect",{x:"56.5",y:"44.5",width:"2.4",height:"2.4",rx:t==="claude"?0:1.2})]}),e.jsx("path",{className:"eye-happy",d:"M35 51Q39 43 43 51M54 51Q58 43 62 51"}),e.jsx("path",{className:"eye-error",d:"m35 45 8 3m11 0 8-3M38 54h2m16 0h2"}),e.jsx("path",{className:"eye-sleep",d:"M35 50q4 3 8 0m11 0q4 3 8 0"})]})})}),t==="claude"?e.jsx("rect",{className:"arm",x:"75",y:"56",width:"8",height:"12",rx:"2"}):e.jsx("ellipse",{className:"arm",cx:"79",cy:"63",rx:"5",ry:"8"})]})})})})})})]})}const sp={blink:180,curious:900,hello:1100,boop:700,happy:900,look:1800,stretch:1600,tap:1150,pulse:1400,nod:700,yawn:1700,sleep:3200},rr=(t,n)=>Math.max(-n,Math.min(n,t)),lo="M25 60V41C25 28 35 23 48 23C61 23 71 28 71 41V60Z";function cl({size:t,theme:n,paused:s=!1,frozen:a=!1,reducedMotion:r=!1,dnd:l=!1,pointer:o=null,center:c,gestureKey:i,gestureKind:x="hello",boopKey:d}){const m=el(),p=`resident-${f.useId().replace(/[^A-Za-z0-9_-]/g,"")}`,[g,h]=f.useState(null),[N,k]=f.useState(!1),C=f.useRef(void 0),j=s||r||l||a,y=!j&&!!o&&!!c&&Math.hypot(o.x-c.x,o.y-c.y)<140,b=y?rr((o.x-c.x)/140*5,4):0,M=y?rr((o.y-c.y)/140*3,2):0,S=y?rr((o.x-c.x)/140*7,5):0,$=R=>{j||document.hidden||(clearTimeout(C.current),h(null),h(R),C.current=setTimeout(()=>h(null),sp[R]))};f.useEffect(()=>()=>clearTimeout(C.current),[]),f.useEffect(()=>{i&&$(x)},[i]),f.useEffect(()=>{d&&$("boop")},[d]);const v=f.useRef(!1);f.useEffect(()=>{y&&!v.current&&!N&&$("curious"),v.current=y},[y]),f.useEffect(()=>{if(j){h(null),clearTimeout(C.current);return}let R,_=0;const L=()=>{!document.hidden&&!N&&(_++,$(_%17===0?"sleep":_%13===0?"yawn":_%11===0?"tap":_%7===0?"stretch":_%5===0?"look":"blink")),R=setTimeout(L,4300+_%3*900)};R=setTimeout(L,3200);const T=()=>{document.hidden&&(h(null),clearTimeout(C.current))};return document.addEventListener("visibilitychange",T),()=>{clearTimeout(R),document.removeEventListener("visibilitychange",T)}},[j,N]);const A={"--resident-gx":b?`${b.toFixed(2)}px`:"0px","--resident-gy":M?`${M.toFixed(2)}px`:"0px","--resident-tilt":S?`${S.toFixed(2)}deg`:"0deg"};return e.jsxs("svg",{className:"resident",width:t,height:t,viewBox:t<=24?"5 8 86 74":"0 0 96 96",role:"img","aria-label":"Ledge","data-theme":n,"data-large":String(t>24),"data-near":String(y),"data-dnd":String(l),"data-frozen":String(a),"data-quiet":String(j),"data-gesture":g??void 0,style:A,onMouseEnter:()=>{k(!0),$("happy")},onMouseLeave:()=>k(!1),children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:`${p}-shell`,x1:".15",y1:"0",x2:".75",y2:"1",children:[e.jsx("stop",{className:"resident-top"}),e.jsx("stop",{className:"resident-bottom",offset:"1"})]}),e.jsxs("radialGradient",{id:`${p}-sheen`,cx:".3",cy:".2",r:".75",children:[e.jsx("stop",{className:"resident-sheen"}),e.jsx("stop",{className:"resident-sheen",offset:"1",stopOpacity:"0"})]})]}),e.jsx("g",{className:"resident-body",children:e.jsxs("g",{className:"resident-pose",children:[e.jsx("path",{className:"resident-antenna",d:"M48 23v-7"}),e.jsx("circle",{className:"resident-light",cx:"48",cy:"14",r:"2.6"}),e.jsx("path",{className:"resident-shell",d:lo,fill:`url(#${p}-shell)`}),t>24&&e.jsx("path",{d:lo,fill:`url(#${p}-sheen)`}),e.jsx("g",{className:"resident-gaze",children:e.jsxs("g",{className:"resident-blink",children:[e.jsxs("g",{className:"resident-eyes",children:[e.jsx("rect",{x:"37",y:"35",width:"6",height:"12",rx:"3"}),e.jsx("rect",{x:"53",y:"35",width:"6",height:"12",rx:"3"}),t>24&&e.jsxs("g",{className:"resident-glint",children:[e.jsx("circle",{cx:"38.8",cy:"37.8",r:"1.5"}),e.jsx("circle",{cx:"54.8",cy:"37.8",r:"1.5"})]})]}),e.jsx("path",{className:"resident-smile",d:"M36 43q4-7 8 0m8 0q4-7 8 0"}),e.jsx("path",{className:"resident-sleep",d:"M36 42q4 4 8 0m8 0q4 4 8 0"})]})})]})}),e.jsx("rect",{className:"resident-wall",x:"9",y:"59",width:"78",height:"20",rx:"6"}),e.jsx("rect",{className:"resident-slab",x:"6",y:"55",width:"84",height:"7",rx:"3.5"}),e.jsx("path",{className:"resident-rim",d:"M12 56.4H84"}),e.jsx("rect",{className:"resident-shell resident-grip",x:"26",y:"50",width:"12",height:"9",rx:"4.5",fill:`url(#${p}-shell)`}),e.jsx("rect",{className:"resident-shell resident-hand",x:"58",y:"50",width:"12",height:"9",rx:"4.5",fill:`url(#${p}-shell)`}),e.jsx("title",{children:a?m.residentOffline:m.residentName})]})}const ap={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"};function Fa({tool:t,seed:n,state:s,large:a=!1,frozen:r=!1}){const l=ap[s],o=Gn();return e.jsx("span",{className:"inline-flex flex-none","aria-hidden":"true",children:e.jsx(Da,{tool:t,seed:n,state:l,pose:Oa(n,l),size:a?68:34,theme:o,frozen:r})})}function Us(t){return e.jsx(cl,{...t,theme:Gn()})}const rp={plain:"border-line bg-surface",warning:"border-attention/25 bg-attention/[0.06]",approval:"border-approval/25 bg-approval/[0.06]",danger:"border-danger-fg/25 bg-danger-bg"};function De({title:t,tone:n="plain",children:s,role:a}){return e.jsxs("div",{role:a,className:`rounded-control border p-3.5 text-small leading-[1.65] ${rp[n]}`,children:[e.jsx("strong",{className:"mb-[5px] block text-body",children:t}),s]})}var dl=tm();const ul="(min-width: 768px) and (min-height: 501px)",lp=`${ul} and (orientation: landscape)`,oo=t=>typeof globalThis.matchMedia=="function"?globalThis.matchMedia(t):null;function yc(t){return f.useSyncExternalStore(n=>{var a;const s=oo(t);return(a=s==null?void 0:s.addEventListener)==null||a.call(s,"change",n),()=>{var r;return(r=s==null?void 0:s.removeEventListener)==null?void 0:r.call(s,"change",n)}},()=>{var n;return((n=oo(t))==null?void 0:n.matches)??!1},()=>!1)}function Dt(){return yc(ul)}function Pa(){return yc(lp)}const Nc=f.createContext(void 0),kc=()=>f.useContext(Nc);function rn({list:t,detail:n,tab:s,fold:a=!1}){const[r,l]=f.useState(null);return e.jsxs("div",{className:"split","data-split":s,"data-fold":a?"":void 0,children:[e.jsx("div",{ref:l,className:"split-banner"}),e.jsxs(Nc.Provider,{value:r,children:[e.jsx("section",{className:"split-list",children:t}),e.jsx("section",{className:"split-detail",children:n})]})]})}function io({title:t,body:n}){return e.jsx("div",{"data-split-empty":"",className:"flex flex-1 items-center justify-center px-6 text-center",children:e.jsxs("div",{className:"max-w-[280px]",children:[e.jsx("h2",{className:"text-base font-semibold",children:t}),e.jsx("p",{className:"mt-1 text-body text-muted",children:n})]})})}const op=["sessions","prs","rigs"];function ml(t){switch(t.name){case"sessions":case"routines":case"thread":case"terminal":case"launch":case"request":return"sessions";case"prs":case"rigs":return t.name;case"ask":return"rigs";case"rig":case"kernel":case"max":return"rigs";case"pr":return"prs";case"atelier":return"atelier";case"connection":return null}}const vc=t=>({name:t}),ip=t=>ml(t)===t.name&&!(t.name==="atelier"&&t.sessionId),wc=new Map;function cp(t){const n=ml(t);n&&n!=="atelier"&&wc.set(n,ce(t))}const Sc=t=>wc.get(t)??ce(vc(t)),Tr=t=>t>99?"99+":String(t);function dp(t,n=0){const s=t.filter(r=>r.filter==="permission").length;if(s)return{text:Tr(s),tone:"red"};const a=t.length-s+n;return a?{text:Tr(a),tone:"amber"}:null}function up(t){const n=t.filter(s=>s.kind!=="update").length;return n?{text:Tr(n),tone:"amber"}:null}function Cc({className:t}){return e.jsx("span",{"data-settings-dot":!0,"aria-hidden":"true",className:`absolute size-2 rounded-full bg-primary ${t}`})}function mp(t,n,s){return t?"online":s==="pc_offline"||s==="relay_unreachable"?"offline":n?"reconnecting":"loading"}const $c=f.createContext({pc:null,look:"online",reach:"pc_online",since:"",retry:()=>{}}),lr=$c.Provider,zt=()=>f.useContext($c),Jt=t=>{const n=t??u.host.unknown;return n.length>14?`${n.slice(0,13)}…`:n};function Mc({size:t=24}){return e.jsxs("svg",{"data-ledge-mark":!0,width:t,height:t,viewBox:"0 0 16 16","aria-hidden":"true",className:"flex-none",children:[e.jsx("rect",{width:"16",height:"16",rx:"3.5",fill:"#0A0A0A"}),e.jsx("rect",{x:"3",y:"3",width:"3",height:"10",rx:".5",fill:"#FAFAFA"}),e.jsx("rect",{x:"7",y:"10",width:"6",height:"3",rx:".5",fill:"#FAFAFA"}),e.jsx("circle",{cx:"10",cy:"6",r:"2",fill:"#FF6467"})]})}function xl(){const{pc:t,look:n}=zt(),s=Jt(t),a=n==="offline";return e.jsxs("a",{href:ce({name:"connection",section:"link"}),"data-host":n,"aria-label":u.host.label(t??u.host.unknown,n),className:`inline-flex h-[26px] flex-none items-center gap-1.5 rounded-full border px-2.5 text-small whitespace-nowrap ${a?"border-attention/45 text-attention":"border-input text-muted"}`,children:[n==="loading"?e.jsx("span",{"aria-hidden":"true",className:"inline-block size-2.5 animate-spin rounded-full border-[1.5px] border-current border-r-transparent"}):e.jsx("span",{"aria-hidden":"true",className:`inline-block size-2 flex-none rounded-full ${n==="online"?"bg-ok":a?"bg-attention":"bg-muted"}`}),a?u.host.offline(s):s]})}function xp({title:t}={}){const{settingsDot:n}=zt();return e.jsxs("header",{className:"bleed flex h-14 flex-none items-center gap-1.5 border-b border-line pr-1.5 pl-4",children:[t?e.jsx("h1",{className:"mr-1 text-[20px] font-semibold",children:t}):e.jsxs("span",{className:"mr-1 flex items-center gap-2 text-[17px] font-semibold",children:[e.jsx(Mc,{}),u.brand]}),e.jsx(xl,{}),e.jsx("span",{className:"flex-1"}),e.jsxs("a",{href:ce({name:"connection"}),"aria-label":u.nav.settings,title:u.nav.settings,className:"relative grid size-11 flex-none place-items-center rounded-lg text-muted active:bg-raised",children:[e.jsx(z,{name:"gear"}),n&&e.jsx(Cc,{className:"top-2.5 right-2.5"})]})]})}function Ec({badge:t,className:n}){return t?e.jsx("span",{"data-badge":t.tone,className:`absolute h-4 min-w-4 rounded-full px-1 text-center text-[10px] leading-4 font-semibold ${t.tone==="red"?"bg-primary text-primary-fg":"bg-attention text-[#1c1100]"} ${n}`,children:t.text}):null}const _c={sessions:"sessions",prs:"pr",rigs:"rigs",atelier:"atelier"};function Rc(t){return(n,s)=>a=>{if(!s||t.name==="connection")return;a.preventDefault();const r=document.querySelector("[data-tab-scroll]");r&&r.scrollTop>0?r.scrollTo({top:0,behavior:"smooth"}):ip(t)||os(vc(n))}}function pp({route:t,active:n,badges:s}){const a=Rc(t);return e.jsx("nav",{"aria-label":u.nav.label,className:"tabbar bleed grid flex-none grid-cols-3 border-t border-line bg-sidebar",children:op.map(r=>e.jsxs("a",{href:Sc(r),onClick:a(r,n===r),"aria-current":n===r?"page":void 0,className:"tab group relative flex flex-col items-center justify-center gap-[3px] text-[11px] leading-[13px] text-muted aria-[current=page]:font-medium aria-[current=page]:text-fg",children:[e.jsx("span",{className:"pad grid h-7 w-[52px] place-items-center rounded-full group-aria-[current=page]:bg-raised",children:e.jsx(z,{name:_c[r]})}),u.nav[r],e.jsx(Ec,{badge:s[r]??null,className:"top-[3px] left-1/2 ml-[7px]"})]},r))})}function fp({route:t,active:n,badges:s,atelier:a}){const r=Rc(t),{settingsDot:l}=zt(),o=c=>e.jsxs("a",{href:Sc(c),onClick:r(c,n===c),"aria-current":n===c?"page":void 0,className:"rb",children:[e.jsx(z,{name:_c[c]}),u.nav[c],e.jsx(Ec,{badge:s[c]??null,className:"top-[3px] right-[7px]"})]},c);return e.jsxs("nav",{"aria-label":u.nav.label,className:"rail",children:[e.jsx("span",{className:"mb-2",children:e.jsx(Mc,{size:30})}),["sessions","prs","rigs"].map(o),a&&o("atelier"),e.jsx("span",{className:"flex-1"}),e.jsxs("a",{href:ce({name:"connection"}),"aria-current":n==="settings"?"page":void 0,className:"rb",children:[e.jsx(z,{name:"gear"}),u.nav.settings,l&&e.jsx(Cc,{className:"top-[5px] right-[15px]"})]})]})}function wn({body:t,across:n=!1}={}){const{pc:s,look:a,reach:r,since:l,retry:o}=zt(),[c,i]=xs(),x=kc();if(a!=="offline")return null;const d=r==="relay_unreachable",m=d?u.compare.relayTitle:u.offline.title(s),p=d?u.compare.relayBody:l?(t??u.offline.body)(l):u.offline.bodyUnknown,g=N=>e.jsxs("button",{type:"button",disabled:c,onClick:()=>{i(!0),o()},className:rt({size:"sm",className:N}),children:[e.jsx(z,{name:"refresh",className:"size-4"}),u.offline.retry]}),h=e.jsx(z,{name:d?"cloud":"wifioff",className:"mt-px size-4 flex-none text-attention"});return x!==void 0?!n||!x?null:dl.createPortal(e.jsxs("section",{role:"status","data-strip":d?"relay":"pc",className:"strip flex items-center gap-[9px] rounded-lg border border-attention/40 px-3 py-2.5 text-[13px] leading-[18px]",children:[h,e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("b",{className:"font-semibold",children:m})," · ",e.jsx("span",{className:"text-muted",children:p})]}),g("flex-none")]}),x):e.jsxs("section",{role:"status","data-strip":d?"relay":"pc",className:"strip flex flex-none items-start gap-[9px] rounded-lg border border-attention/40 px-3 py-2.5 text-[13px] leading-[18px]",children:[h,e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[e.jsx("b",{className:"font-semibold",children:m}),e.jsx("span",{className:"text-muted",children:p}),g("self-start")]})]})}function hp(){const t="block animate-[ledge-pulse_1.6s_ease-in-out_infinite] rounded-[5px] bg-raised";return e.jsxs("div",{"aria-hidden":"true","data-loading":"","data-list-state":"",className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-line bg-surface p-3",children:[e.jsxs("div",{className:"flex items-center gap-[7px]",children:[e.jsx("span",{className:`${t} h-4 w-[26px]`}),e.jsx("span",{className:`${t} h-3.5 w-20`}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:`${t} h-4 w-[70px]`})]}),e.jsx("span",{className:`${t} h-[34px]`}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("span",{className:`${t} h-11`}),e.jsx("span",{className:`${t} h-11`})]})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-line bg-surface p-3",children:[e.jsxs("div",{className:"flex items-center gap-[7px]",children:[e.jsx("span",{className:`${t} h-4 w-[26px]`}),e.jsx("span",{className:`${t} h-3.5 w-[110px]`})]}),e.jsx("span",{className:`${t} h-3.5 w-[85%]`})]})]})}function fs({title:t,subtitle:n,wideSubtitle:s,actions:a,wideActions:r,children:l,bodyClassName:o="flex flex-col gap-3",offlineBody:c,heading:i=!0,offlinePill:x=!0}){const d=Dt(),{pc:m,look:p,since:g}=zt(),h=p==="loading",N=h?u.link.connecting(Jt(m)):p==="offline"?g?u.link.lastKnownAt(g):u.cards.lastKnown:s;return e.jsxs(e.Fragment,{children:[d&&e.jsxs("div",{className:"pane-head flex h-[58px] flex-none items-center gap-2 border-b border-line pr-1.5 pl-4",children:[e.jsx("h1",{className:"flex-none text-lg font-semibold whitespace-nowrap",children:t}),N&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:N}),!h&&(x||p!=="offline")&&e.jsx(xl,{}),r&&e.jsx("span",{className:"ml-auto flex flex-none items-center gap-2",children:r})]}),e.jsxs("main",{"data-tab-scroll":"",className:"tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pt-3.5 pb-[18px]",children:[e.jsx(wn,{body:c,across:!0}),!d&&i&&e.jsxs("div",{className:"flex flex-none items-baseline gap-2",children:[e.jsx("h1",{className:"text-[22px] leading-7 font-semibold tracking-[-.02em]",children:t}),(h||n)&&e.jsx("span",{className:"min-w-0 truncate text-[12.5px] text-muted",children:h?u.link.connecting(Jt(m)):n}),a&&e.jsx("span",{className:"ml-auto flex flex-none items-center gap-2 self-center",children:a})]}),h?e.jsx(hp,{}):e.jsx("div",{className:`flex-none ${o}`,children:l})]})]})}function xn(){const[t,n]=f.useState(!1);return f.useEffect(()=>{let s=!0;return Om().then(a=>{s&&n(a)}),()=>{s=!1}},[]),t}function Pt(){const t=globalThis.navigator;return t?/iPhone|iPad/.test(t.userAgent)||/Macintosh/.test(t.userAgent)&&t.maxTouchPoints>1:!1}const Sn=u.confirm,or=t=>We({variant:t,block:!0});function co({store:t,item:n,enabled:s,reason:a,onConfirm:r,onDeny:l,denyLabel:o}){const[c,i]=f.useState(null),[x,d]=f.useState(null),[m,p]=f.useState(!1),[g,h]=f.useState(a!==void 0),[N,k]=f.useState(0),C=f.useRef(!0),j=f.useRef(s);j.current=s;const y=f.useRef(null);f.useEffect(()=>(C.current=!0,()=>{C.current=!1}),[]),f.useEffect(()=>{var T;if(g||!s)return;const A=(T=t.getState().sessions.get(n.sessionId))==null?void 0:T.pending;if(!(A!=null&&A.key))return;let R=!0,_;i(null);const L={key:A.key,kind:A.kind,text:A.text};return t.prepareConfirm({purpose:"decide",id:n.sessionId,expect:L}).then(B=>{R&&(y.current=L,i(B),_=setTimeout(()=>{R&&(i(null),d("expired"))},B.expiresInMs))},()=>{R&&d("prepareFailed")}),()=>{R=!1,clearTimeout(_)}},[t,n.sessionId,n.key,s,g,N]);const b=g&&a?a==="assertion_expired"?"expired":"failed":x,M=()=>{d(null),h(!1),k(A=>A+1)},S=async()=>{var _,L;if(!s||m||!c)return;if(!c.credentialId){i(null),d("failed");return}p(!0),d(null);const A=await Fs({challenge:c.challenge,rpId:c.rpId,credentialId:c.credentialId}).catch(()=>"failed");if(!C.current)return;p(!1);const R=y.current;if(!R||!j.current||((L=(_=t.getState().sessions.get(n.sessionId))==null?void 0:_.pending)==null?void 0:L.key)!==R.key){i(null),d("changed");return}if(A==="cancelled"){d("cancelled");return}if(A==="failed"){d("failed");return}i(null),r(A,R)===null&&d("failed")},$=b==="expired"||b==="failed"||b==="prepareFailed"||b==="changed",v=m?Sn.asking:c?Pt()?Sn.goApple:Sn.go:Sn.preparing;return e.jsxs("section",{"aria-labelledby":"confirm-title",className:"flex flex-col gap-3 rounded-card border border-line bg-surface p-4",children:[e.jsx("h2",{id:"confirm-title",className:"text-title leading-[1.35] font-semibold",children:Sn.heading}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:Sn.note}),b&&e.jsx(De,{title:b==="changed"?u.decide.changed:Sn[b],tone:"warning",role:"alert"}),$?e.jsx("button",{type:"button",disabled:!s,onClick:M,className:or("primary"),children:Sn.retry}):e.jsx("button",{type:"button",disabled:!s||m||!c,onClick:()=>{S()},className:or("primary"),children:v}),e.jsx("button",{type:"button",disabled:!s,onClick:l,className:or(),children:o??u.decide.deny})]})}function uo(){return e.jsxs("p",{className:"inline-flex min-h-12 flex-1 items-center justify-center gap-2 rounded-control border border-dashed border-line px-4 py-2.5 text-center text-body leading-[1.4] font-medium text-muted",children:[e.jsx(z,{name:"monitor",className:"size-4"}),u.decide.onPc]})}function gp(t){return t instanceof HTMLElement?t.isContentEditable||t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT":!1}function bp(){return document.querySelector('[role="dialog"][aria-modal="true"]')!==null}function Tc(t,n){const s=f.useRef(n);s.current=n,f.useEffect(()=>{if(!t)return;const a=r=>{r.defaultPrevented||r.repeat||r.altKey||r.ctrlKey||r.metaKey||r.isComposing||gp(r.target)||bp()||s.current(r.key)&&r.preventDefault()};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[t])}const mo=t=>We({variant:t,className:"flex-1"}),Fn=t=>We({variant:t,block:!0});function jp(t,n){const s=u.decide;switch(n){case"invalid":return t.kind==="question"?s.otherInvalid:s.failed;case"free_text":return s.otherUnsupported;case"untypable":return t.kind==="question"?u.question.untypable:s.failed;case"busy":return s.busy;case"not_taken":return s.notTaken;case"read_only":return s.readOnly;default:return s.failed}}function yp(t){const{item:n,outcome:s,fresh:a,changed:r,stillPending:l,onReread:o,onDecide:c,answerable:i=!1,choice:x=null,onAnswer:d,answerBlocked:m=!1,onCheck:p,refused:g=!1,store:h,deviceConfirm:N=!1,optionReply:k,multi:C,keys:j=!1,withThread:y=!0}=t,b=u.decide,[M,S]=xs(),$=xn(),v=n.risk==="high"||s.kind==="rejected"&&s.reason==="confirm_required",A=a&&!r&&l,R=n.kind!=="question"&&!k&&!C&&!i&&!v,_=R&&Li(n.tool,n.kind,"always"),L=_r(n),T=_&&e.jsx("p",{className:"text-small text-muted phone-side:text-[12px] phone-side:leading-4",children:u.cards.scope[L]}),B=s.kind!=="sending"&&s.kind!=="uncertain"&&!((s.kind==="rejected"||s.kind==="failed")&&(s.reason==="no_prompt"||s.reason==="nothing_to_decide"||s.reason==="stale"));Tc(j&&R&&A&&B,D=>{const Q=D.toLowerCase();return Q==="y"?(c("accept"),!0):Q==="n"?(c("deny"),!0):!1});const E=e.jsx("a",{href:t.threadHref??ce({name:"thread",sessionId:n.sessionId}),className:Fn("ghost"),children:u.result.thread(n.botName)}),P=(D,Q,q=!0)=>e.jsxs("footer",{className:"flex flex-none flex-col gap-2.5 border-t border-line bg-bg pt-3 pb-4 phone-side:pb-2",children:[D,q&&y&&e.jsx("div",{className:"phone-side:hidden",children:E}),Q&&e.jsx("p",{className:"text-center text-meta text-muted phone-side:hidden",children:Q})]});if(n.kind==="question"&&!i&&!k&&!C)return P(null,b.answerOnPc);const W=N&&$?h:void 0,F=k?k.canConfirm&&W!==void 0:v&&!i&&W!==void 0,re=s.kind==="rejected"&&(s.reason==="assertion_expired"||s.reason==="assertion_invalid"||s.reason==="confirm_required")?s.reason:void 0,Y=D=>k?F?k.picked!==null&&W?e.jsx(co,{store:W,item:n,enabled:D,reason:re,onConfirm:k.onReply,onDeny:k.onBack,denyLabel:u.answers.change}):null:e.jsx(uo,{}):C?e.jsxs("div",{className:"flex flex-col gap-2.5",children:[C.missing>0&&e.jsx("p",{className:"text-center text-small text-muted",children:u.answers.missing(C.missing)}),e.jsx("button",{type:"button",disabled:!D||C.missing>0,onClick:C.onSend,className:Fn("primary"),children:u.answers.send}),e.jsx("button",{type:"button",disabled:!D,onClick:C.onCancel,className:Fn(),children:u.answers.cancel})]}):F&&W?e.jsx(co,{store:W,item:n,enabled:D,reason:re,onConfirm:(Q,q)=>W.decide(n.sessionId,"accept",{assertion:Q,expect:q}),onDeny:()=>c("deny")}):i?e.jsx("button",{type:"button",disabled:!D||x===null||m,onClick:()=>d==null?void 0:d(),className:Fn("primary"),children:b.send}):j&&R?e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsx("button",{type:"button",disabled:!D,onClick:()=>c("accept"),className:We({variant:"primary",className:"min-w-[150px]"}),children:b.allow}),e.jsx("button",{type:"button",disabled:!D,onClick:()=>c("deny"),className:We({className:"min-w-[120px]"}),children:b.deny}),_&&e.jsx("button",{type:"button",disabled:!D,onClick:()=>c("always"),className:We({variant:"ghost"}),children:ga(L)}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono text-small text-muted",children:u.cards.keys}),T&&e.jsx("div",{className:"basis-full",children:T})]}):e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsxs("div",{className:"flex flex-col gap-2.5 phone-side:flex-row",children:[e.jsxs("div",{className:"flex gap-2.5 phone-side:flex-[2]",children:[e.jsx("button",{type:"button",disabled:!D,onClick:()=>c("deny"),className:mo(),children:b.deny}),v?e.jsx(uo,{}):e.jsx("button",{type:"button",disabled:!D,onClick:()=>c("accept"),className:mo("primary"),children:b.allow})]}),_&&e.jsx("button",{type:"button",disabled:!D,onClick:()=>c("always"),className:We({variant:"ghost",block:!0,className:"phone-side:w-auto phone-side:flex-1"}),children:ga(L)})]}),T]}),H=a?k?F?b.answerHint:b.onPcHint:C?b.answerHint:v&&!i&&!F?b.onPcHint:i?b.answerHint:b.hint:b.offlineHint,I=D=>P(e.jsxs(e.Fragment,{children:[D,Y(A)]}),H);if(r&&s.kind!=="sending"&&s.kind!=="uncertain")return P(e.jsxs(e.Fragment,{children:[e.jsx(De,{title:b.changed,tone:"warning",role:"status"}),Y(!1),e.jsx("button",{type:"button",onClick:o,className:Fn(),children:b.reread})]}));switch(s.kind){case"sending":return P(e.jsx(De,{title:b.sending,role:"status",children:e.jsx("p",{children:b.sendingBody})}));case"uncertain":return P(e.jsxs(e.Fragment,{children:[e.jsx(De,{title:b.uncertain,tone:"warning",role:"alert",children:e.jsx("p",{children:b.uncertainBody})}),p&&e.jsx("button",{type:"button",disabled:M,onClick:()=>{S(!0),p()},className:Fn("primary"),children:M?b.checking:b.check})]}));case"rejected":case"failed":{const D=s.reason;if(F&&re||D==="confirm_required")return I();if(D==="no_prompt"||D==="nothing_to_decide")return P(e.jsx(De,{title:b.noPrompt,tone:"warning",role:"alert"}));if(D==="stale")return P(e.jsxs(e.Fragment,{children:[e.jsx(De,{title:b.changed,tone:"warning",role:"alert"}),e.jsx("a",{href:ce({name:"sessions"}),className:Fn(),children:u.result.back})]}),void 0,!1);const Q=e.jsx(De,{title:jp(n,D),tone:"warning",role:"alert"});return l?I(Q):P(Q)}default:return I(g?e.jsx(De,{title:b.failed,tone:"warning",role:"alert"}):void 0)}}const Zn=(t,n)=>{var s,a;return(a=(s=t.match(new RegExp(`<${n}>([\\s\\S]*?)</${n}>`)))==null?void 0:s[1])==null?void 0:a.trim()};function Np(t){const n=t.trim();if(!n.startsWith("<task-notification>"))return null;const s=Zn(n,"status"),a=Zn(n,"summary")??"",r=a.match(/^Agent "(.+)" (?:was |has )?(?:stopped|killed|completed|finished|failed)/),l=a.match(/^Background command "(.+)" (?:completed|failed|was stopped|was killed)(?: \(exit code (\d+)\))?/);return{...Zn(n,"task-id")!==void 0&&{id:Zn(n,"task-id")},...Zn(n,"output-file")!==void 0&&{output:Zn(n,"output-file")},status:s==="killed"||s==="completed"||s==="failed"?s:"other",summary:a,about:r?{kind:"agent",name:r[1]}:l?{kind:"command",command:l[1],...l[2]!==void 0&&{code:l[2]}}:null,raw:n}}const yt=u.thread.rig,xo=t=>t?`…${t.slice(-4)}`:"…";function kp(t){const n=t.indexOf("@");return n>0?{seat:t.slice(0,n),rig:t.slice(n+1)}:{seat:t}}function oa(t,n,s){const a=n?s.get(n):void 0,{seat:r,rig:l}=kp(t??"");return a?{name:a.name,...r?{seat:r}:{},session:{id:a.id,tool:a.tool,state:a.state}}:{name:r||(t??""),...l?{seat:l}:{}}}function vp(t){const n=t.split(`
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/xterm-DbcwqIBy.js","assets/index-BEiOJOC0.js","assets/index-MFPtqCsL.css","assets/label-lFMIoau9.js","assets/xterm-DYP7pi_n.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
var Qu=Object.defineProperty;var Zu=(t,n,s)=>n in t?Qu(t,n,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[n]=s;var Bt=(t,n,s)=>Zu(t,typeof n!="symbol"?n+"":n,s);import{r as f,l as xa,c as u,s as Ju,j as e,B as Pe,a as ma,U as Ii,M as Ra,b as ex,o as Li,i as Ot,u as el,d as Gn,e as tx,f as We,g as ut,t as Ul,h as nx,k as Oi,m as Ze,I as sx,A as ax,P as rx,n as lx,p as ox,L as ix,R as cx,q as Wl,K as Ms,v as dx,C as Ta,w as os,W as la,x as ux,O as dt,y as Mt,H as Ht,F as Et,z as Nt,S as As,D as xx,E as mx,G as px,J as fx,N as hx,Q as Kl,T as Vl,V as Gl,X as Za,Y as gx,Z as Di,_ as bx,$ as jx,a0 as yx,a1 as pa,a2 as Xl,a3 as Nx,a4 as kx,a5 as Fi,a6 as tl,a7 as Pi,a8 as vx,a9 as wx,aa as Sx,ab as Yl,ac as Cx,ad as $x,ae as Ql,af as Mx,ag as Ex,ah as _x,ai as Zl,aj as Rx,ak as Tx,al as Ax,am as Ix}from"./index-BEiOJOC0.js";import{e as zi,i as yn,a as Lx,p as Ox,g as Fs,c as Dx,b as Fx,u as xe,M as Nn,d as Bi,f as Px,l as zx,h as Bx,j as nl,r as qx,k as Hx,m as sl,n as Ux,o as Wx,q as Kx,s as qi,t as Hi,v as Vx,w as Ui,R as Wi,U as Ki}from"./label-lFMIoau9.js";const Gx=["sessions","routines","prs","rigs","connection","kernel","max"],Vi="new";function Gi(t){const n=t.replace(/^#\/?/,"").split("/").filter(Boolean);try{if(n[0]==="request"&&n.length===3)return{name:"request",sessionId:decodeURIComponent(n[1]),key:decodeURIComponent(n[2])};if(n[0]==="ask"&&n.length===2)return{name:"ask",id:decodeURIComponent(n[1])};if((n[0]==="thread"||n[0]==="terminal")&&n.length===2)return{name:n[0],sessionId:decodeURIComponent(n[1])};if(n[0]==="atelier"&&n.length===4&&n[2]==="request")return{name:"atelier",sessionId:decodeURIComponent(n[1]),requestKey:decodeURIComponent(n[3])};if(n[0]==="atelier"&&n.length<=2)return n[1]?{name:"atelier",sessionId:decodeURIComponent(n[1])}:{name:"atelier"};if(n[0]==="connection"&&n.length===2&&(n[1]==="link"||n[1]==="usage"))return{name:"connection",section:n[1]};if(n[0]==="rigs"&&n.length===2)return{name:"rig",rig:decodeURIComponent(n[1])};if(n[0]==="prs"&&n.length===2)return{name:"pr",id:decodeURIComponent(n[1])};if(n[0]==="routines"&&n.length===2)return{name:"routines",routine:decodeURIComponent(n[1])};if(n[0]==="max"&&n.length===2)return{name:"max",goalId:decodeURIComponent(n[1])};if(n[0]==="sessions"&&n.length===2&&(n[1]==="working"||n[1]==="waiting"))return{name:"sessions",filter:n[1]}}catch{}if(n[0]==="agents"&&n.length===1)return{name:"sessions"};if(n[0]===Vi&&n.length===1)return{name:"launch"};const s=Gx.find(a=>a===n[0]);return s&&n.length===1?{name:s}:{name:"sessions"}}function ce(t){return t.name==="request"?`#/request/${encodeURIComponent(t.sessionId)}/${encodeURIComponent(t.key)}`:t.name==="ask"?`#/ask/${encodeURIComponent(t.id)}`:t.name==="thread"||t.name==="terminal"?`#/${t.name}/${encodeURIComponent(t.sessionId)}`:t.name==="atelier"?t.sessionId?t.requestKey?`#/atelier/${encodeURIComponent(t.sessionId)}/request/${encodeURIComponent(t.requestKey)}`:`#/atelier/${encodeURIComponent(t.sessionId)}`:"#/atelier":t.name==="connection"&&t.section?`#/connection/${t.section}`:t.name==="rig"?`#/rigs/${encodeURIComponent(t.rig)}`:t.name==="pr"?`#/prs/${encodeURIComponent(t.id)}`:t.name==="routines"&&t.routine?`#/routines/${encodeURIComponent(t.routine)}`:t.name==="max"&&t.goalId?`#/max/${encodeURIComponent(t.goalId)}`:t.name==="sessions"&&t.filter?`#/sessions/${t.filter}`:t.name==="launch"?`#/${Vi}`:`#/${t.name}`}const is=t=>{globalThis.location.hash=ce(t)},Sr=t=>typeof(t==null?void 0:t.ledge)=="number";let sn=0,Es=[],Cr=!1;const $r=t=>{try{globalThis.history.replaceState({...globalThis.history.state,ledge:t},"")}catch{}};function Xx(){const t=globalThis.location.hash,n=globalThis.history.state;Sr(n)?sn=n.ledge:(Cr||(sn+=1,Es=Es.slice(0,sn)),$r(sn)),Cr=!1,Es[sn]=t}if(typeof globalThis.addEventListener=="function"&&globalThis.history&&globalThis.location){const t=globalThis.history.state;sn=Sr(t)?t.ledge:0,Sr(t)||$r(0),Es[sn]=globalThis.location.hash,globalThis.addEventListener("hashchange",Xx)}const An=t=>{Cr=!0,globalThis.location.replace(ce(t))};function Yx(t){if(sn===0)return{route:t,known:!1,inApp:!1};const n=Es[sn-1];return n===void 0?{route:t,known:!1,inApp:!0}:{route:Gi(n),known:!0,inApp:!0}}function Aa(t){sn>0?globalThis.history.back():An(t)}const Qx=t=>(globalThis.addEventListener("hashchange",t),()=>globalThis.removeEventListener("hashchange",t));function Ps(){const t=f.useSyncExternalStore(Qx,()=>globalThis.location.hash,()=>"");return Gi(t)}const Zx=/^\/#\/[A-Za-z0-9/%._~-]*$/;function Jx(t){if(typeof t!="object"||t===null)return;const n=t;n.type!=="ledge.open"||typeof n.url!="string"||!Zx.test(n.url)||(globalThis.location.hash=n.url.slice(1))}const Xi=70,zs=6,Jl=2,al=130,En=90,Yi=t=>(Math.max(t,2)+1)*Xi,Qi=(t,n=zs,s=al)=>Yi(Math.min(t,n))+2*s;function em(t,n,s=zs,a=al){const r=t.slice(0,s),l=Yi(r.length),o=g=>r.length===1?l/2:Xi*(g+1),c=r.map((g,h)=>({session:g,x:o(h),side:r.length===1||h%2===0?"t":"b"})),i={left:[],right:[]},m=new Map,d=[];if(n){for(const[g,h]of r.entries()){const N=xa(h),k=N[0];k&&m.set(h.id,{helper:k,more:N.length-1});const C=o(g)>l/2?"right":"left",j=C==="left"?"right":"left";for(const y of N){const b=i[C].length<Jl?C:i[j].length<Jl?j:null;b?i[b].push({helper:y,parent:h}):d.push({helper:y,parent:h})}}for(const g of t.slice(s))for(const h of xa(g))d.push({helper:h,parent:g})}const x=["left","right"].flatMap(g=>i[g].map((h,N)=>({...h,end:g,slot:N,count:i[g].length}))),p=t.slice(s);return{length:l,width:Qi(t.length,s,a),seats:c,ends:x,notes:m,extra:{mains:p,helpers:d},extraCount:p.length+d.length}}const Dn=84,Ys=52;function tm(t,n,s){const a=[...n].sort((c,i)=>c-i),r=a.indexOf(t),l=(r<a.length-1?a[r+1]-Dn/2:s-6)-(t+Dn/2),o=t-Dn/2-(r>0?a[r-1]+Dn/2:6);return l>=Ys+4?t+Dn/2+2:o>=Ys+4?t-Dn/2-Ys-2:t+Dn/2-Ys+8}function nm(t){const n=new Map;for(const a of t)a.branch&&n.set(a.branch,(n.get(a.branch)??0)+1);let s=null;for(const[a,r]of n)(s===null||r>n.get(s))&&(s=a);return s}function eo(t,n){return t==="idle"?"done":t==="readonly"?"working":t}const sm={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"},Zi=t=>sm[t.state];function am(t,n,s,a,r,l){const o=n??[],c=new Set(o.map(k=>k.id)),i=k=>{const C=s(k);return C!==null&&c.has(C)?C:null},m=t.filter(k=>!k.rig),d=o.filter(k=>a==="all").map(k=>({project:k,tables:[{key:`common:${k.id}`,mains:m.filter(C=>i(C)===k.id)}]})).filter(k=>k.tables[0].mains.length>0),x=rm(t.filter(k=>k.rig),k=>{var C;return((C=o.find(j=>j.id===k))==null?void 0:C.name)??null},s,l),p=[...x.filter(k=>k.rig.kind==="kernel"),...d,...x.filter(k=>k.rig.kind==="rig")],g=a==="all"||a==="none"?m.filter(k=>i(k)===null):[],h=a==="all"||a==="none"?void 0:o.find(k=>k.id===a),N=h&&p.length===0?h:null;return{rooms:p,unassigned:g,empty:N}}const Ja="kernel";function rm(t,n,s,a){const r=new Map;for(const l of t)r.set(l.rig.name,[...r.get(l.rig.name)??[],l]);return[...r].sort(([l],[o])=>l===Ja?-1:o===Ja?1:l.localeCompare(o)).map(([l,o])=>{const c=l===Ja?"kernel":"rig",i=s(o[0]);return{project:a({id:`rig:${l}`,name:l,kind:c}),tables:[{key:`rig:${l}`,mains:o}],rig:{kind:c,name:l,folder:o[0].cwd??"",project:i?n(i):null}}})}const lm=t=>t==="kernel"?"violet":"slate",Ji=110,om=150,ec=70,im=(t,n=zs,s=al)=>t.reduce((a,r,l)=>a+Qi(r.mains.length,n,s)+(l>0?ec:0),0)+2*Ji;function kn(t){const n=[];for(const s of t){const a=s.pending;a!=null&&a.key&&n.push({sessionId:s.id,key:a.key,kind:a.kind,filter:a.kind==="question"?"question":"permission",task:s.topic??s.project,botName:s.name,tool:s.tool,repo:s.repo??s.project,...s.branch?{branch:s.branch}:{},...s.worktree?{worktree:!0}:{},since:s.lastActivityAt,text:a.text,...a.tool?{pendingTool:a.tool}:{},...a.body!==void 0?{body:a.body}:{},...a.cut?{cut:!0}:{},...a.options?{options:a.options}:{},...a.optionDetails?{optionDetails:a.optionDetails}:{},source:a.source,...a.questions?{questions:a.questions}:{},...a.requestId?{requestId:a.requestId}:{},risk:a.risk,riskReason:a.riskReason})}return n.sort((s,a)=>Date.parse(s.since)-Date.parse(a.since))}function fa(t,n){const s=Math.max(0,Math.floor((n-Date.parse(t))/1e3)),a=u.cards.age;return s<60?a.s(s):s<3600?a.min(Math.floor(s/60)):s<86400?a.h(Math.floor(s/3600)):a.d(Math.floor(s/86400))}const to=t=>{var n;return((n=t.split(`
|
|
3
|
+
`).find(s=>s.trim()))==null?void 0:n.trim())??""};function Ia(t){switch(t.kind){case"question":return t.text;case"plan":return u.cards.plan;case"diff":return u.cards.diff(to(t.text)).trim();default:return to(t.text)}}const tc=["all","waiting","working"],Mr=t=>t.pending!==void 0||t.state==="waiting_permission"||t.state==="waiting_input";function Er(t,n){return n==="waiting"?Mr(t):n==="working"?t.state==="working"&&!Mr(t):!0}function ha(t){return Mr(t)?0:t.state==="working"?1:t.state==="exited"?3:2}function rl(t,n,s){s&&(t=Ju(t,{projectIds:s.projects.map(o=>o.id),order:s.order,projectOf:o=>o.projectId??null,keyOf:o=>o.id}));const a=new Map,r=new Map;for(const o of t){if(!Er(o,n))continue;const[c,i,m]=o.rig?[r,"rig",o.rig.name]:[a,"project",o.project];let d=c.get(m);d||c.set(m,d={id:`${i}:${m}`,kind:i,name:m,sessions:[],...i==="project"?{project:o.projectId??null}:{}}),d.sessions.push(o)}const l=o=>({...o,sessions:o.sessions.map((c,i)=>[c,i]).sort((c,i)=>ha(c[0])-ha(i[0])||c[1]-i[1]).map(([c])=>c)});return[...[...a.values()].map(o=>s?o:l(o)),...[...r.values()].map(l)]}const ll=["projects","rigs"];function cm(t,n){const s=rl(t,"all");if(n==="projects")return s;const a=t.filter(r=>!r.rig).map((r,l)=>[r,l]).sort((r,l)=>ha(r[0])-ha(l[0])||r[1]-l[1]).map(([r])=>r);return[...s.filter(r=>r.kind==="rig"),...a.length?[{id:"outside",kind:"outside",name:u.sessions.outsideRig,sessions:a}]:[]]}function dm(t){if(t.kind!=="project")return null;const n=t.sessions.map(ms);return n.includes("perm")?"perm":n.includes("ask")?"ask":null}function um(t){return t.finishedAt!==void 0||t.state==="exited"?"done":t.state==="waiting_permission"?"perm":t.state==="waiting_input"?"ask":t.state==="working"?"work":"idle"}const nc=t=>({all:t.length,waiting:t.filter(n=>Er(n,"waiting")).length,working:t.filter(n=>Er(n,"working")).length});function ms(t){const n=kn([t])[0];return n?n.kind==="question"?"ask":"perm":t.state==="waiting_permission"?"perm":t.state==="waiting_input"?"ask":t.state==="working"?"work":t.state==="exited"?"done":"idle"}const xm=t=>xa(t).length;function mm(t,n,s=Date.now()){const a=u.sessions.line;if(n==="working")return pm(t);const r=sc(t),l=r===void 0?"":` · ${r} %`,o=kn([t])[0];if(o)return(o.kind==="permission"?a.permission:u.cards.pill[o.kind])+l;switch(t.state){case"waiting_permission":return a.permission+l;case"waiting_input":return u.cards.pill.question+l;case"working":return a.working+l;case"exited":return t.exitedAt?a.ended(zi(t.exitedAt,s)):a.endedPlain;case"error":return a.error;default:return a.idle+l}}const pm=t=>{var n;return((n=t.doing)==null?void 0:n.label)||u.sessions.line.thinking},sc=t=>t.context?Math.round(Math.min(1,t.context.used/t.context.window)*100):void 0;function fm(t){if(t.rig)return t.rig.role;if(t.branch)return t.branch.split("/").filter(Boolean).pop()??t.branch}function cs({d:t,size:n=16,fill:s}){return e.jsxs("svg",{width:n,height:n,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.map((a,r)=>e.jsx("path",{d:a},r)),s==null?void 0:s.map((a,r)=>e.jsx("path",{d:a,fill:"currentColor",stroke:"none"},`f${r}`))]})}const ss={chevronLeft:{d:["m15 18-6-6 6-6"]},chevronRight:{d:["m9 18 6-6-6-6"]},close:{d:["M18 6 6 18","m6 6 12 12"]},check:{d:["M20 6 9 17l-5-5"]},plus:{d:["M12 5v14","M5 12h14"]}},Ye=(t,n,s)=>`M${t-s} ${n}a${s} ${s} 0 1 0 ${2*s} 0a${s} ${s} 0 1 0 ${-2*s} 0`,Yn=(t,n,s,a,r)=>`M${t+r} ${n}h${s-2*r}a${r} ${r} 0 0 1 ${r} ${r}v${a-2*r}a${r} ${r} 0 0 1 ${-r} ${r}h${-(s-2*r)}a${r} ${r} 0 0 1 ${-r} ${-r}v${-(a-2*r)}a${r} ${r} 0 0 1 ${r} ${-r}z`,hm={back:ss.chevronLeft.d,chevron:ss.chevronRight.d,close:ss.close.d,check:ss.check.d,plus:ss.plus.d,gear:["M15 12a3 3 0 1 1-6 0a3 3 0 1 1 6 0","M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1.1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1.1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1Z"],terminal:["m4 17 6-6-6-6","M12 19h8"],eye:["M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z",Ye(12,12,3)],arrowRight:["M5 12h14","m13 6 6 6-6 6"],arrowUp:["m5 12 7-7 7 7","M12 19V5"],arrowDown:["m5 12 7 7 7-7","M12 5v14"],plane:["m22 2-7 20-4-9-9-4Z","M22 2 11 13"],external:["M15 3h6v6","M10 14 21 3","M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"],stop:["M8 6h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2z"],power:["M12 3v9","M6.3 6.3a8 8 0 1 0 11.4 0"],resume:["M4 12a8 8 0 1 0 2.3-5.6","M4 4v4h4","M10 9l5 3-5 3z"],monitor:["M5 4h14a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z","M8 20h8","M12 16v4"],warning:["m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3","M12 9v4","M12 17h.01"],edit:["M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7","M18.38 2.62a2.12 2.12 0 1 1 3 3L12.36 14.64a2 2 0 0 1-.85.51l-2.87.84.84-2.87a2 2 0 0 1 .5-.85z"],spinner:["M21 12a9 9 0 1 1-6.22-8.56"],inbox:["M4 13l3-8h10l3 8v6H4z","M4 13h5l1 2h4l1-2h5"],sessions:[Yn(3,4,18,16,2),"M7 9h10M7 13h6"],pr:[Ye(6,5,2.2),Ye(6,19,2.2),Ye(18,19,2.2),"M6 7.2v9.6M18 16.8V10a3 3 0 0 0-3-3h-4","M13 5l-2 2 2 2"],rigs:[Ye(6,6,2.5),Ye(18,6,2.5),Ye(12,18,2.5),"M8 7.5l3 8M16 7.5l-3 8M8.5 6h7"],ledge:[Yn(4,8,16,12,3),"M12 8V4.5",Ye(9,14,1),Ye(15,14,1)],search:[Ye(11,11,7),"M20 20l-4-4"],more:[Ye(12,5,1.4),Ye(12,12,1.4),Ye(12,19,1.4)],send:["M12 19V5M5 12l7-7 7 7"],wifioff:["M12 20h.01M8.5 16.4a5 5 0 0 1 7 0M5 12.9a10 10 0 0 1 5.2-2.7M19 12.9a10 10 0 0 0-1.9-1.3M2 8.8a15 15 0 0 1 4.2-2.7M22 8.8A15 15 0 0 0 10.7 5M2 2l20 20"],cloud:["M2 2l20 20M5.8 5.8A7 7 0 0 0 7 20h10a5 5 0 0 0 2.6-.7M20.8 16.4A5 5 0 0 0 17 10h-1.3A7 7 0 0 0 10 5.1"],refresh:["M3 12a9 9 0 0 1 15.7-6L21 8M21 3v5h-5M21 12a9 9 0 0 1-15.7 6L3 16M3 21v-5h5"],atelier:[Yn(3,10,18,5,1),Ye(7,6,2),Ye(17,6,2),"M6 15v4M18 15v4"],plan:["M9 4h6v3H9z","M7 5H5v16h14V5h-2","m9 12 1.5 1.5L14 10","M9 17h6"],keyboard:["M3 7h18v10H3z","M7 11h.01","M11 11h.01","M15 11h.01","M8 14h8"],task:["M6.9 3.75h10.2a2.4 2.4 0 0 1 2.4 2.4v11.7a2.4 2.4 0 0 1-2.4 2.4H6.9a2.4 2.4 0 0 1-2.4-2.4V6.15a2.4 2.4 0 0 1 2.4-2.4z","M8.25 9h7.5","M8.25 13.5h5.25"],reply:["M9.75 6 3.75 12l6 6","M4.5 12h9.75a6 6 0 0 1 6 6v.75"],passkey:["M12 3a6 6 0 0 0-6 6v3h12V9a6 6 0 0 0-6-6z","M5 12h14v9H5z"],phone:["M8 2h8a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z","M11 18h2"],tablet:["M6 3h12a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z","M11 18h2"],key:[Ye(7.5,15.5,5.5),"m21 2-9.6 9.6M15.5 7.5l3 3L22 7l-3-3"],shield:["M12 3 4 6v6c0 5 8 9 8 9s8-4 8-9V6z"],laptop:[Yn(4,4,16,11,1.5),"M2 19h20"],face:["M4 8V6a2 2 0 0 1 2-2h2M16 4h2a2 2 0 0 1 2 2v2M20 16v2a2 2 0 0 1-2 2h-2M8 20H6a2 2 0 0 1-2-2v-2M9 9v1M15 9v1M12 9v4h-1M9 15.5a4 4 0 0 0 6 0"],unlink:["M18.8 13.4l1.6-1.6a4.5 4.5 0 0 0-6.4-6.4l-1.6 1.6M5.2 10.6l-1.6 1.6a4.5 4.5 0 0 0 6.4 6.4l1.6-1.6M8 2v3M2 8h3M16 22v-3M22 16h-3"],clock:[Ye(12,12,9),"M12 7v5l3 2"],alarm:[Ye(12,13,8),"M12 9v4l2.5 1.5M5 3 2 6M19 3l3 3"],play:["M7 5v14l11-7z"],lock:[Yn(3,11,18,11,2),"M7 11V7a5 5 0 0 1 10 0v4"],bell:["M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9M10.3 21a1.9 1.9 0 0 0 3.4 0"],alert:["M12 3l10 18H2z","M12 10v4M12 17.5v.01"],cpu:[Yn(6,6,12,12,2),"M9 2v4M15 2v4M9 18v4M15 18v4M2 9h4M2 15h4M18 9h4M18 15h4"],camera:["M4 8h3l2-3h6l2 3h3v11H4z",Ye(12,13,3.5)],folder:["M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"],list:["M9 6h11M9 12h11M9 18h11M4 6l1 1 2-2M4 12l1 1 2-2M4 18h2"],down:["M6 9l6 6 6-6"],branch:[Ye(6,5,2),Ye(6,19,2),Ye(18,8,2),"M6 7v10M18 10c0 4-6 3-12 7"],merge:[Ye(6,5,2.2),Ye(6,19,2.2),Ye(18,12,2.2),"M6 7.2v9.6M6 7.2c0 3 4 4.8 9.8 4.8"],file:["M14 3H6a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8z","M14 3v5h5"],commit:[Ye(12,12,3.5),"M3 12h5.5M15.5 12H21"]};function z({name:t,className:n="size-5",stroke:s=1.6}){return e.jsx("svg",{className:`flex-none ${n}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:s,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:hm[t].map((a,r)=>e.jsx("path",{d:a},r))})}const gm={work:"bg-info",perm:"bg-approval",ask:"bg-attention",idle:"bg-ok",done:"bg-muted opacity-50",off:"bg-transparent shadow-[inset_0_0_0_1.5px_var(--color-muted)]",rig:"bg-task",plain:"bg-muted"};function ze({state:t,pulse:n=!1,label:s}){return e.jsx("span",{"data-dot":t,...s?{role:"img","aria-label":s}:{"aria-hidden":!0},className:`inline-block size-2 flex-none rounded-full ${gm[t]} ${n?"animate-[ledge-pulse_1.6s_ease-in-out_infinite]":""}`})}const bm={claude:"CC",codex:"CX",cursor:"CU",omp:"OM"};function Xn({tool:t}){return e.jsx("span",{"data-runtime":t,className:"flex-none rounded-[5px] bg-secondary px-[5px] py-px font-mono text-[11px] leading-4 font-medium",children:bm[t]})}const jm={plain:"border-input text-muted",perm:"border-approval/50 text-approval",urgent:"border-approval/50 text-approval",ask:"border-attention/50 text-attention",work:"border-info/45 text-info",ok:"border-ok/45 text-ok",rig:"border-task/50 text-task",risk:"border-transparent bg-destructive text-primary-fg font-semibold"};function Lt({tone:t="plain",children:n}){return e.jsx("span",{"data-pill":t,className:`inline-flex h-5 flex-none items-center rounded-lg border px-[7px] text-[11.5px] whitespace-nowrap ${jm[t]}`,children:n})}function ds({title:t,dot:n,count:s,sub:a,tone:r,none:l,label:o,children:c}){return e.jsxs("section",{"aria-label":t??o,className:`flex-none overflow-hidden rounded-[10px] border bg-surface dark:bg-transparent ${r==="rigs"?"border-task/45":"border-line"}`,children:[t&&e.jsxs("div",{className:"flex min-h-11 items-center gap-2 border-b border-line px-3",children:[n&&e.jsx(ze,{state:n}),e.jsx("b",{className:"text-body font-semibold whitespace-nowrap",children:t}),s!==void 0&&e.jsx("span",{className:"text-[12.5px] text-muted",children:s}),a&&e.jsx("span",{className:"min-w-0 flex-1 truncate text-small text-muted",children:a})]}),l!==void 0?e.jsx("p",{className:"p-3 text-[13px] text-muted",children:l}):e.jsx("div",{className:"flex flex-col",children:c})]})}function ol({lead:t,title:n,sub:s,subTone:a,meta:r,metaWarn:l=!1,selected:o=!1,stale:c=!1,pressed:i=!1,href:m,press:d,children:x}){const p=`flex min-h-[52px] items-center gap-2 border-b border-line px-3 py-1.5 text-[13.5px] last:border-b-0 ${c?"opacity-60":""} ${o?"bg-secondary shadow-[inset_2px_0_0_var(--color-primary)]":""} ${i?"shadow-[inset_0_0_0_2px_var(--color-ring)]":""}`,g=e.jsxs(e.Fragment,{children:[t,e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate",children:n}),s!==void 0&&e.jsx("span",{className:`truncate text-small leading-4 ${a==="perm"?"text-approval":"text-muted"}`,children:s})]}),r!==void 0&&e.jsx("span",{className:`font-mono text-small whitespace-nowrap ${l?"text-attention":"text-muted"}`,children:r}),x]});return m?e.jsx("a",{href:m,"aria-current":o?"page":void 0,className:p,...d,children:g}):e.jsx("div",{className:p,children:g})}const ym={plain:"border-line",perm:"border-destructive/45",ask:"border-attention/45",rig:"border-destructive/40"};function Bs({tone:t="plain",selected:n=!1,label:s,children:a}){return e.jsx("article",{"aria-label":s,"data-card":t,className:`flex flex-col gap-2.5 rounded-lg border bg-surface p-3 ${ym[t]} ${n?"shadow-[0_0_0_2px_var(--color-ring)]":""}`,children:a})}function Rn({glyph:t,title:n,body:s,action:a,framed:r=!0,list:l=!1}){return e.jsxs("div",{"data-list-state":l?"":void 0,className:"flex flex-col items-center gap-1.5 px-4 pt-[26px] pb-[22px] text-center",children:[r?e.jsx("div",{"aria-hidden":"true",className:"grid size-12 place-items-center rounded-[10px] border border-line text-muted",children:t}):e.jsx("div",{"aria-hidden":"true",className:"text-muted",children:t}),e.jsx("h2",{className:"mt-1.5 text-[17px] leading-6 font-semibold",children:n}),e.jsx("p",{className:"max-w-[300px] text-[13.5px] text-muted",children:s}),a&&e.jsx("div",{className:"mt-2",children:a})]})}const Nm={outline:"border-input bg-surface dark:bg-transparent text-fg active:bg-raised",primary:"border-transparent bg-primary text-primary-fg active:bg-primary-hover",ghost:"border-transparent bg-transparent text-muted text-[13px] active:bg-raised"},km={md:"h-11 px-3.5 text-body",sm:"h-9 px-3 text-[13px]",xs:"h-8 px-2.5 text-[12.5px]"},rt=({variant:t="outline",size:n="md",className:s}={})=>["inline-flex items-center justify-center gap-2 rounded-lg border font-medium whitespace-nowrap transition-colors duration-100 disabled:opacity-45",Nm[t],t==="ghost"?"h-9 px-3.5":km[n],s??""].filter(Boolean).join(" ");function La({back:t,tool:n,name:s,dot:a,pulse:r=!1,sub:l,under:o=!1,more:c}){return e.jsxs("header",{className:"bleed flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-0.5",children:[t,n&&e.jsx(Xn,{tool:n}),o&&l?e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("b",{className:"min-w-0 truncate text-base leading-5 font-semibold",children:s}),a&&e.jsx(ze,{state:a,pulse:r})]}),e.jsx("span",{className:"truncate text-[12px] leading-4 text-muted",children:l})]}):e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-base font-semibold whitespace-nowrap",children:s}),a&&e.jsx(ze,{state:a,pulse:r}),l&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:l}),e.jsx("span",{className:"flex-1"})]}),c]})}function ac({label:t,sendLabel:n,placeholder:s,offlinePlaceholder:a,value:r,onChange:l,onSend:o,offline:c=!1}){const i=f.useId(),m=!c&&r.trim()!=="";return e.jsxs("div",{className:`flex items-end gap-2 rounded-[10px] border border-input bg-surface py-[5px] pr-[5px] pl-3 focus-within:border-ring focus-within:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)] ${c?"opacity-55":""}`,children:[e.jsx("label",{htmlFor:i,className:"sr-only",children:t}),e.jsx("textarea",{id:i,rows:1,value:c?"":r,disabled:c,placeholder:c?a:s,onChange:d=>l(d.target.value),className:"min-h-[34px] min-w-0 flex-1 resize-none bg-transparent py-[7px] text-base leading-[22px] text-fg outline-none placeholder:text-muted"}),e.jsx("button",{type:"button",disabled:!m,onClick:o,"aria-label":n,title:n,className:"grid size-9 flex-none place-items-center rounded-lg bg-primary text-primary-fg disabled:opacity-40",children:e.jsx(z,{name:"send",className:"size-[18px]"})})]})}function vm({children:t}){return e.jsx("code",{className:"block rounded-[5px] bg-raised px-[9px] py-[7px] font-mono text-small leading-[18px] break-all whitespace-pre-wrap",children:t})}const rc={permission:"approval",question:"attention",plan:"info",diff:"info"};function wm(t,n){if(n){const s=n.risk==="high"&&n.kind!=="question";return{tone:s?"danger":rc[n.kind],label:s?u.risk.badge:u.kind[n.kind]}}switch(t.state){case"waiting_permission":return{tone:"approval",label:u.kind.permission};case"waiting_input":return{tone:"attention",label:u.kind.question};case"idle":return{tone:"ok",label:u.agents.state.idle};case"exited":return{tone:"muted",label:u.agents.state.exited};case"error":return{tone:"danger",label:u.agents.state.error};default:return{tone:"info",label:u.agents.state.working}}}const Sm=t=>wm(t,kn([t])[0]);function lc({store:t,label:n,ids:s,offline:a,startOpen:r=!1,onCancel:l}){const[o,c]=f.useState(r),[i,m]=f.useState(""),[d,x]=f.useState(!1),[p,g]=f.useState(null),h=async()=>{if(s.length>ma){g({lines:[u.agents.tooMany(s.length,ma)],error:!0});return}x(!0);const N=await t.broadcast(s,i.trim());if(x(!1),N.sent){const k=N.sent;g({lines:[...k.length?[u.agents.sentTo(k)]:[u.agents.nobody],...(N.refused??[]).map(C=>u.agents.refusedLine(C.name,C.reason))],error:k.length===0}),k.length&&(c(r),m(""))}else N.status==="expired"?g({lines:[u.agents.uncertain],error:!0}):g({lines:[u.agents.notSent],error:!0})};return e.jsxs("div",{className:"pb-2",children:[!o&&e.jsx("button",{type:"button",disabled:a,onClick:()=>{g(null),c(!0)},className:"text-meta text-info disabled:opacity-60",children:u.agents.writeGroup}),o&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:`group-${s[0]}`,className:"sr-only",children:u.agents.writeGroupLabel(n)}),e.jsx("textarea",{id:`group-${s[0]}`,rows:2,value:i,disabled:d,placeholder:u.agents.writeGroupPlaceholder,onChange:N=>m(N.target.value),className:"min-h-11 w-full resize-none rounded-[14px] border border-input bg-surface px-3.5 py-[11px] text-base leading-5 text-fg placeholder:text-muted disabled:opacity-60"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Pe,{variant:"ghost",className:"flex-1",disabled:d,onClick:()=>{c(!1),m(""),l==null||l()},children:u.agents.cancel}),e.jsx(Pe,{variant:"primary",className:"flex-[2]",disabled:d||!i.trim(),onClick:()=>void h(),children:u.agents.send})]})]}),p&&e.jsx("div",{role:"status",className:`mt-1 text-meta ${p.error?"text-attention":"text-muted"}`,children:p.lines.map((N,k)=>e.jsx("p",{className:"[overflow-wrap:anywhere]",children:N},k))})]})}const no=new Set(["-o","--push-option","--repo","--receive-pack","--exec"]),Cm=new Set(["-f","--force","--force-with-lease","--force-if-includes","--delete","-d","--mirror","--prune"]);function $m(t){const n=t.trim().split(/\s+/);if(n[0]!=="git")return null;const s=n.indexOf("push");if(s<1)return null;let a=!1;const r=[],l=n.slice(s+1);for(let d=0;d<l.length;d++){const x=l[d];if(x.startsWith("--")){const p=x.split("=")[0];Cm.has(p)?a=!0:no.has(p)&&!x.includes("=")&&d++}else x.startsWith("-")&&x.length>1?/[fd]/.test(x.slice(1))?a=!0:no.has(x)&&d++:r.push(x)}const[o="",...c]=r;c.some(d=>d.startsWith("+")||d.startsWith(":"))&&(a=!0);const i=c[0],m=i==null?void 0:i.replace(/^\+/,"").split(":").pop();return{remote:o,...m?{branch:m}:{},force:a}}function Mm(t){return t.risk!=="low"||t.riskReason!=="edit_inside_folder"?null:{title:u.detail.editsInProject,body:u.detail.editsInProjectBody}}function oc(t){if(t.risk==="low")return null;const n=u.consequence,s=t.riskReason;if(s==="pushes"){const a=$m(t.text),r=a!=null&&a.remote?a.branch?`${a.remote}/${a.branch}`:a.remote:n.configuredRemote;return a!=null&&a.force?{title:n.forceTitle,body:n.forceBody(a.remote?r:void 0),destination:r}:{title:n.pushTitle,body:n.pushBody,destination:r}}switch(s){case"destroys":case"deploys":case"publishes":case"pipes_to_shell":case"network":case"writes_outside_folder":case"sensitive_path":case"script":case"plan":{const[a,r]=n[s];return{title:a,body:r}}default:{const[a,r]=n.unknown;return{title:a,body:r}}}}const il=Ra,Em=/^[1-9]$/;function ic(t){const n=t.trim();return n===""?{text:n,problem:"empty"}:Ii.test(n)?{text:n,problem:"untypable"}:n.length>il?{text:n,problem:"long"}:Em.test(n)?{text:n,problem:"digit"}:{text:n,problem:null}}function _m(t,n,s){var a;if(t.kind==="plan"||t.kind==="diff")return{kind:"examine"};if((n==null?void 0:n.decide)===!1||t.kind==="question"&&(n==null?void 0:n.questions)===!0&&t.requestId!==void 0&&((a=t.questions)!=null&&a.length))return{kind:"examine"};if(t.kind==="question"){if(s)return{kind:"readOnly"};const r=t.options??[],l=(n==null?void 0:n.freeTextAnswer)===!0;return l||r.length>0?{kind:"question",options:r,other:l}:{kind:"answerOnPc",options:r}}return t.risk==="high"?{kind:"high"}:{kind:"permission",always:Li(t.tool,t.kind,"always")}}const _r=t=>ex(t.tool,{kind:t.kind,...t.pendingTool?{tool:t.pendingTool}:{}}),ga=t=>t==="project"?u.cards.always:t==="plan"?u.cards.approveAuto:u.cards.alwaysSession,so={critical:0,urgent:1,routine:2},cc=t=>[...t].sort((n,s)=>so[n.priority]-so[s.priority]||Date.parse(n.createdAt)-Date.parse(s.createdAt)),dc=t=>t.kind==="update"?"update":t.kind==="parked"?"parked":t.questions.length>0?"decision":"question",Rm=t=>(t==null?void 0:t.replace(/\.agent$|\.lead$|\.worker$/,""))??null,uc=t=>({name:t.from.seat.split("@")[0]||t.from.seat,role:Rm(t.from.role)});function ao(t,n){var r;const s=t.questions.find(l=>l.id===n),a=s==null?void 0:s.answer;return a?a.kind==="words"?a.text:((r=s.options.find(l=>l.id===a.id))==null?void 0:r.label)??a.id:null}function Tm(t,n){var s,a;switch(n.kind){case"choice":return((a=(s=t.questions.find(r=>r.id===n.questionId))==null?void 0:s.options.find(r=>r.id===n.optionId))==null?void 0:a.label)??n.optionId;case"words":case"resolve":return n.text;case"seen":return""}}function xc(t,n){const s=Object.values(n).filter(l=>l.message.type==="openrig.answer"&&l.message.qitemId===t).sort((l,o)=>l.at.localeCompare(o.at)),a=s[s.length-1];if(!a)return{kind:"none"};const r=a.message.answer;if(a.rig){const l=a.rig;return l.rejected?{kind:"refused",answer:r,reason:l.rejected}:l.ok?l.outcome==="recorded"?{kind:"recorded",answer:r}:l.outcome==="already"?{kind:"already"}:{kind:"sent",answer:r}:l.error==="closed"||l.error==="not_found"?{kind:"already"}:l.error==="uncertain"?{kind:"uncertain",answer:r}:{kind:"failed",answer:r,error:l.error??"unreachable",...l.message?{message:l.message}:{}}}return yn(a.phase)?a.phase==="uncertain"?{kind:"uncertain",answer:r}:{kind:"sending",answer:r}:a.phase==="applied"?{kind:"sent",answer:r}:{kind:"failed",answer:r,error:a.reason??"unreachable"}}const mc=5e3;function ro(t,n){return[...t.map(s=>({name:"request",sessionId:s.sessionId,key:s.key})),...cc(n).filter(s=>s.kind!=="update").map(s=>({name:"ask",id:s.id}))]}const er=(t,n)=>t.name==="request"?n.name==="request"&&t.sessionId===n.sessionId:n.name==="ask"&&t.id===n.id;function Am(t,n,s=t){const a=t.filter(o=>!er(o,n)),r=s.findIndex(o=>er(o,n));return(r<0?[]:s.slice(r+1)).find(o=>a.some(c=>er(c,o)))??a[0]??null}function pc(t,n,s){var c;const a=(c=n.find(i=>i.id===t.sessionId))==null?void 0:c.pending,r=(a==null?void 0:a.key)===t.key,l=Object.values(s).filter(i=>"id"in i.message&&i.message.id===t.sessionId&&Lx(i.message)===t.key).sort((i,m)=>i.at.localeCompare(m.at)),o=l.find(i=>i.phase==="applied")??l[l.length-1];if(o){const i=o.message;switch(o.phase){case"sending":return{kind:"sending"};case"uncertain":return{kind:"uncertain"};case"applied":return{kind:"applied",...i.type==="session.decide"?{decision:i.decision}:{},...i.type==="session.reply"?{answer:i.text}:{},...i.type==="session.answer"?{answer:i.answers.flatMap(m=>m.selected).join(", ")}:{}};case"rejected":return o.reason==="stale"&&!r?a!=null&&a.key?{kind:"changed"}:{kind:"handledElsewhere"}:{kind:"rejected",reason:o.reason??"invalid"};case"failed":return{kind:"failed",reason:o.reason??"invalid"}}}return r?{kind:"idle"}:{kind:"handledElsewhere"}}function ps(t=4e3){const[n,s]=f.useState(!1);return f.useEffect(()=>{if(!n)return;const a=setTimeout(()=>s(!1),t);return()=>clearTimeout(a)},[n,t]),[n,s]}function Kt(){const[t,n]=f.useState(Date.now);return f.useEffect(()=>{const s=setInterval(()=>n(Date.now()),15e3);return()=>clearInterval(s)},[]),t}const Im={approval:"text-approval bg-approval/10",attention:"text-attention bg-attention/10",info:"text-info bg-info/10",ok:"text-ok bg-ok/10",muted:"text-muted bg-fg/[0.05]",danger:"text-danger-fg bg-danger-fg/10"};function qs({tone:t,label:n}){return e.jsx("span",{className:`inline-flex h-[22px] flex-none items-center rounded-md px-2 text-meta leading-none font-medium whitespace-nowrap ${Im[t]}`,children:n})}function Lm({kind:t,risk:n="low"}){const s=n==="high"&&t!=="question";return e.jsx(qs,{tone:s?"danger":rc[t],label:s?u.risk.badge:u.kind[t]})}function Om({text:t}){return e.jsx("pre",{className:"my-3.5 rounded-control border border-line bg-well p-3.5 font-mono text-small leading-[1.8] break-words whitespace-pre-wrap [overflow-wrap:anywhere]",children:t})}const fs=t=>{var n;return{fresh:t.fresh,pc:((n=t.daemon)==null?void 0:n.name)??null}};function fc({link:t}){return e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-meta whitespace-nowrap text-muted",children:[e.jsx("i",{className:`inline-block size-1.5 flex-none rounded-full ${t.fresh?"bg-ok":"bg-muted"}`}),e.jsxs("span",{className:"truncate",children:[t.pc?`${t.pc} · `:"",t.fresh?u.link.online:u.link.offline]})]})}function Zt({fallback:t,label:n}){const s=Yx(t),a=s.inApp?s.known?u.nav.backTo[s.route.name]??u.nav.back:u.nav.back:n;return e.jsx("a",{href:ce(s.route),"data-back":t.name,"aria-label":a,title:a,onClick:r=>{r.preventDefault(),Aa(t)},className:Ot({className:"-ml-2"}),children:e.jsx(z,{name:"back"})})}function Hs({title:t,fallback:n,label:s,link:a}){return e.jsx("header",{className:"flex-none border-b border-line pt-2 pb-3",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(Zt,{fallback:n,label:s}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),e.jsx(fc,{link:a})]})})}const tr={},hc={grow:{ms:320,ease:"cubic-bezier(.22,1,.36,1)",delayMs:0},shrink:{ms:260,ease:"cubic-bezier(.65,0,.35,1)",delayMs:60},cardExit:{ms:300,ease:"cubic-bezier(.65,0,.35,1)",delayMs:180},pop:{ms:260,ease:"cubic-bezier(.34,1.3,.64,1)",delayMs:0},fadeIn:{ms:180,ease:"ease-out",delayMs:140},fadeOut:{ms:100,ease:"ease-in",delayMs:0},hover:{ms:150,ease:"ease-out",delayMs:0}},Dm=()=>{const t=tr==null?void 0:tr.VITE_LEDGE_MOTION;return t===void 0?1:Number(t)},St=t=>`${Math.round(t*Dm())}ms`;function Fm(t){return t.map(([n,s,a])=>{const r=hc[s];return`${n} ${St(r.ms)} ${r.ease} ${St(a??r.delayMs)}`}).join(", ")}const Pm="(prefers-reduced-motion: reduce)",gc=()=>typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia(Pm):null;function zm(t){const n=gc();return n==null||n.addEventListener("change",t),()=>n==null?void 0:n.removeEventListener("change",t)}const Bm=()=>{var t;return((t=gc())==null?void 0:t.matches)??!1};function qm(){return!1}function bc(){return f.useSyncExternalStore(zm,Bm,()=>!1)}const Hm=()=>({reduced:bc()||qm(),app:!1,setReduced(){}});let Um=Hm;function Wm(){return Um()}function Km(t){return t==="dark"?"signal":"pebble"}function ls(t){let n=7;for(let s=0;s<t.length;s++)n=n*31+t.charCodeAt(s)>>>0;return n}function Oa(t,n){return ls(`${t}:${n}`)%3+1}const $t={blinkMs:180,gazePx:1.4,gazeYPx:.3,askDelayMs:180,transitionMs:500,hopMs:480,touchMs:360,idleMs:1700,askMs:850,nodMs:650},nr=(t,n)=>n===0?1400+t%3500:3400+(t+n*997)%3300,sr=(t,n)=>n===0?800+t%1800:2400+(t+n*557)%2100,Rr=new Set(["done","error","readonly"]),ar=(t,n)=>n===0?3500+t%4e3:5500+(t+n*557)%3500,gn=t=>!document.hidden&&!t.closest("[inert]");function ba(t,n){document.addEventListener("visibilitychange",n);const s=new MutationObserver(n);return s.observe(document.documentElement,{attributes:!0,subtree:!0,attributeFilter:["inert"]}),()=>{document.removeEventListener("visibilitychange",n),s.disconnect()}}function Vm(t){f.useEffect(()=>{const n=t.current;if(!n)return;const s=()=>n.setAttribute("data-suspended",String(!gn(n)));return s(),ba(n,s)},[t])}function Qn(t,n,s){t.style.setProperty("--bot-gx",`${n}px`),t.style.setProperty("--bot-gy",`${s}px`)}function Gm(t,n){const{seed:s,state:a,enabled:r,askKey:l,nodKey:o,gazeReach:c=0}=n,i=ls(s),m=r&&!Rr.has(a),d=f.useRef(null),x=f.useRef(a),p=f.useRef(o),g=f.useRef(void 0);f.useEffect(()=>{const h=t.current;if(!h||!m)return;let N,k,C;const j=()=>gn(h),y=()=>{N!==void 0&&clearTimeout(N),k!==void 0&&clearTimeout(k),C!==void 0&&clearTimeout(C),N=k=C=void 0,h.removeAttribute("data-idle"),Qn(h,0,0),h.removeAttribute("data-blink")},b=()=>{if(y(),!j())return;const $=Date.now();(!d.current||d.current.h!==i)&&(d.current={h:i,blinkAt:$+nr(i,0),lookAt:$+sr(i,0),idleAt:$+ar(i,0),blinks:0,looks:0,idles:0});const v=d.current;v.blinkAt<$&&(v.blinkAt=$+nr(i,++v.blinks)),v.lookAt<$&&(v.lookAt=$+sr(i,++v.looks)),v.idleAt<$&&(v.idleAt=$+ar(i,++v.idles)),N=setTimeout(M,Math.min(v.blinkAt,v.lookAt,v.idleAt)-$)},M=()=>{if(N=void 0,!j()){y();return}const $=d.current,v=Date.now();if(v>=$.blinkAt&&(h.setAttribute("data-blink","true"),k!==void 0&&clearTimeout(k),k=setTimeout(()=>{k=void 0,h.removeAttribute("data-blink")},$t.blinkMs),$.blinkAt=v+nr(i,++$.blinks)),v>=$.lookAt){$.looks++;const A=a==="working";!h.hasAttribute("data-hover")&&!h.hasAttribute("data-transition")&&Qn(h,A?$.looks%2?$t.gazePx:-1.4:0,A?$t.gazeYPx:0),$.lookAt=v+sr(i,$.looks)}if(v>=$.idleAt){$.idles++;const A=a;!h.hasAttribute("data-hover")&&!h.hasAttribute("data-transition")&&(A==="idle"||A==="question")&&(h.setAttribute("data-idle",A==="question"?"tilt":$.idles%4===0?"stretch":"look"),C=setTimeout(()=>{C=void 0,h.removeAttribute("data-idle")},$t.idleMs)),$.idleAt=v+ar(i,$.idles)}N=setTimeout(M,Math.min($.blinkAt,$.lookAt,$.idleAt)-v)};b();const S=ba(h,()=>{j()&&N===void 0?b():j()||y()});return()=>{y(),S()}},[t,m,i,a]),f.useEffect(()=>{const h=t.current,N=x.current,k=g.current,C=p.current!==o&&o!==void 0;if(p.current=o,x.current=a,g.current=l,!h)return;Qn(h,0,0),h.removeAttribute("data-idle");const j=a==="approval"&&(N!=="approval"||l!==void 0&&l!==k),y=new Set,b=(P,W)=>{const F=setTimeout(()=>{y.delete(F),gn(h)?P():M()},W);return y.add(F),F},M=()=>{y.forEach(clearTimeout),y.clear(),["data-transition","data-gesture","data-touch","data-hover","data-idle"].forEach(P=>h.removeAttribute(P)),Qn(h,0,0)};let S=!1,$=!1;r&&gn(h)&&(N!==a&&["working","question","idle","done","error"].includes(a)&&(h.setAttribute("data-transition",a),b(()=>h.removeAttribute("data-transition"),a==="working"?$t.hopMs:a==="question"?650:$t.transitionMs)),j&&!C&&b(()=>{S=!0,h.setAttribute("data-gesture","ask"),b(()=>{h.getAttribute("data-gesture")==="ask"&&h.removeAttribute("data-gesture")},$t.askMs)},$t.askDelayMs));const v=()=>r&&!Rr.has(a)&&gn(h),A=P=>{if(!v()||P.pointerType==="touch")return;const W=h.getBoundingClientRect();if(!W.width||!W.height)return;const F=P.clientX-W.left-W.width/2,re=P.clientY-W.top-W.height/2;if(c>0&&(Math.abs(F)>W.width/2+c||Math.abs(re)>W.height/2+c)){h.hasAttribute("data-hover")&&R();return}h.setAttribute("data-hover","true"),h.removeAttribute("data-idle");const Y=H=>Math.max(-2,Math.min(2,H));Qn(h,Y(F/(W.width/2+c)*2),Y(re/(W.height/2+c)*2))},R=()=>{h.removeAttribute("data-hover"),Qn(h,0,0)},_=c>0?window:h,L=c>0?document.documentElement:h;let T;const B=()=>{v()&&(T!==void 0&&(clearTimeout(T),y.delete(T)),h.removeAttribute("data-touch"),h.getBoundingClientRect(),h.setAttribute("data-touch","true"),T=b(()=>h.removeAttribute("data-touch"),$t.touchMs))};_.addEventListener("pointermove",A),L.addEventListener("pointerleave",R),h.addEventListener("click",B);const E=ba(h,()=>{gn(h)||($=!0,M())});return()=>{M(),E(),_.removeEventListener("pointermove",A),L.removeEventListener("pointerleave",R),h.removeEventListener("click",B);const P=["data-paused","data-frozen","data-reduced","data-readonly"].some(W=>h.getAttribute(W)==="true");!S&&j&&!C&&h.getAttribute("data-state")===a&&r&&!$&&gn(h)&&!P&&(g.current=k)}},[t,a,r,l,o,i,c])}function Xm(t,n,s,a,r){const l=f.useRef(n);f.useEffect(()=>{const o=t.current,c=l.current!==n;if(l.current=n,!o||!c||n===void 0||!s||!gn(o)||Rr.has(a))return;o.setAttribute("data-gesture","nod");const i=setTimeout(()=>{o.getAttribute("data-gesture")==="nod"&&o.removeAttribute("data-gesture")},$t.nodMs),m=()=>{clearTimeout(i),o.getAttribute("data-gesture")==="nod"&&o.removeAttribute("data-gesture")},d=ba(o,()=>{gn(o)||m()});return()=>{d(),m()}},[t,n,s,a,r])}const Ym={claude:"Claude Code",codex:"Codex",cursor:"Cursor Agent",omp:"omp"},Qm={starting:{eyes:"open",eye:"starting"},working:{eyes:"open",eye:"working"},approval:{eyes:"open",eye:"approval",tilt:[-4,3,-2],lift:-1},question:{eyes:"wide",eye:"question",tilt:[4,-3,6]},idle:{eyes:"happy",eye:"idle"},error:{eyes:"error",eye:"error",tilt:[-7,-6,-5],lift:2},done:{eyes:"sleep",eye:"done"},readonly:{eyes:"open",eye:"done"}},Zm="0 0 96 96",jc={claude:"10 18 76 64",codex:"5 7 87 82",cursor:"11 8 74 82",omp:"10 18 76 68"},Jm=Object.fromEntries(Object.entries(jc).map(([t,n])=>[t,Number(n.split(" ")[2])])),ep={claude:"M24 24H72Q75 24 75 27V43H82Q84 43 84 45V52Q84 54 82 54H75V62Q75 64 73 64H70V75Q70 77 68 77H66Q64 77 64 75V64H59V75Q59 77 57 77H55Q53 77 53 75V64H43V75Q43 77 41 77H39Q37 77 37 75V64H32V75Q32 77 30 77H28Q26 77 26 75V64H23Q21 64 21 62V54H14Q12 54 12 52V45Q12 43 14 43H21V27Q21 24 24 24Z",codex:"M30 25C31 13 48 10 57 20C69 14 84 23 81 37C92 46 87 62 76 65C76 80 58 86 48 77C35 85 20 78 21 66C7 61 7 45 18 38C13 28 21 20 30 25Z",cursor:"M43 13Q48 10 53 13L77 27Q82 30 82 36V64Q82 69 77 72L53 85Q48 88 43 85L19 72Q14 69 14 64V36Q14 30 19 27Z",omp:"M17 22H79Q83 22 83 26V48Q83 52 79 52H71V79Q71 83 67 83H58Q54 83 54 79V52H41V67Q41 71 37 71H28Q24 71 24 67V52H17Q13 52 13 48V26Q13 22 17 22Z"},tp={claude:"translate(0 -8)",codex:void 0,cursor:"translate(31.5 58) skewY(27) scale(.86) translate(-48.5 -49)",omp:"translate(0 -12)"},np=240;function Da({tool:t,state:n,pose:s,size:a,shownSize:r,theme:l,seed:o,readOnly:c=!1,frozen:i=!1,paused:m=!1,reducedMotion:d,askKey:x,nodKey:p,className:g}){var W;const h=f.useRef(null),N=`bot-shell-${f.useId().replace(/[^A-Za-z0-9_-]/g,"")}`,k=Wm(),j=bc()||(d??k.reduced),y=a<=20,b=Qm[n],M=!c&&n!=="done"&&n!=="readonly",S=el(),$=ls(o),v=n==="working"&&!j&&!c&&!i&&!m,A=r??a,_=Math.min(7,Math.max(2,A*.12))/A*(y?Jm[t]:96),L=3600+$%9*100,T=!y&&A>20,B=!j&&!c&&n!=="readonly"&&!i&&!m;Vm(h),Gm(h,{seed:o,state:n,askKey:x,nodKey:p,enabled:B&&T,gazeReach:np}),Xm(h,p,B&&T,n,x);const E={"--bot-size":`${a}px`,"--bot-eye":`var(--bot-eye-${b.eye})`,"--bot-tilt":`${((W=b.tilt)==null?void 0:W[s-1])??0}deg`,"--bot-lift":`${b.lift??0}px`,"--bot-breath":St(4800+$%17*100),"--bot-phase":`-${St($%43*100)}`,"--bot-hop":`${_.toFixed(2)}px`,"--bot-hop-cycle":St(L),"--bot-ease":hc.grow.ease,"--bot-material-ms":St(240),"--bot-eye-ms":St(260),"--bot-pose-ms":St(300),"--bot-gaze-ms":St(450),"--bot-blink-ms":St($t.blinkMs),"--bot-ask-ms":St($t.askMs),"--bot-nod-ms":St($t.nodMs),"--bot-question-ms":St(650),"--bot-arrival-ms":St($t.transitionMs),"--bot-entry-hop-ms":St($t.hopMs),"--bot-touch-ms":St($t.touchMs),"--bot-idle-ms":St($t.idleMs)},P=`${Ym[t]} · ${S.botLabel[n]}${c&&n!=="readonly"?` · ${S.botReadOnly}`:""}${i?` · ${S.botNotLive}`:""}`;return e.jsxs("svg",{ref:h,className:g?`bot ${g}`:"bot",role:"img","aria-label":P,width:a,height:a,viewBox:y?jc[t]:Zm,"data-tool":t,"data-state":n,"data-eyes":b.eyes,"data-pose":s,"data-material":Km(l),"data-simplified":String(y),"data-detailed":String(T),"data-readonly":String(c||n==="readonly"),"data-halo":String(M),"data-frozen":String(i),"data-paused":String(m),"data-reduced":String(j),"data-hop":String(v),style:E,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:N,x1:".1",y1:"0",x2:".8",y2:"1",gradientUnits:"objectBoundingBox",children:[e.jsx("stop",{className:"shell-top"}),e.jsx("stop",{className:"shell-bottom",offset:"1"})]})}),e.jsx("ellipse",{className:"ground",cx:"48",cy:"90",rx:"25",ry:"3"}),e.jsx("g",{className:"hop",children:e.jsx("g",{className:"body",children:e.jsx("g",{className:"arrival",children:e.jsx("g",{className:"signature",children:e.jsx("g",{className:"touch",children:e.jsxs("g",{className:"pose",children:[e.jsx("path",{className:"shell",d:ep[t],fill:`url(#${N})`}),t==="cursor"&&e.jsxs("g",{className:"facets",children:[e.jsx("path",{className:"cube-top",d:"M43 13Q48 10 53 13L77 27Q80 29 81 32L48 49L15 32Q16 29 19 27Z"}),e.jsx("path",{className:"cube-side",d:"M48 49L81 32Q82 34 82 36V64Q82 69 77 72L53 85Q50 87 48 87Z"}),e.jsx("path",{className:"cube-edge",d:"M17 32L48 49L79 32M48 49V83"})]}),t==="claude"&&e.jsx("path",{className:"shine",d:"M27 28H69"}),e.jsx("g",{transform:tp[t],children:e.jsx("g",{className:"gaze",children:e.jsxs("g",{className:"eye-blink",children:[e.jsxs("g",{className:"eye-open",children:[e.jsx("rect",{x:"36",y:"43",width:"6",height:"12",rx:t==="claude"?.6:3}),e.jsx("rect",{x:"55",y:"43",width:"6",height:"12",rx:t==="claude"?.6:3})]}),T&&e.jsxs("g",{className:"eye-glint",children:[e.jsx("rect",{x:"37.5",y:"44.5",width:"2.4",height:"2.4",rx:t==="claude"?0:1.2}),e.jsx("rect",{x:"56.5",y:"44.5",width:"2.4",height:"2.4",rx:t==="claude"?0:1.2})]}),e.jsx("path",{className:"eye-happy",d:"M35 51Q39 43 43 51M54 51Q58 43 62 51"}),e.jsx("path",{className:"eye-error",d:"m35 45 8 3m11 0 8-3M38 54h2m16 0h2"}),e.jsx("path",{className:"eye-sleep",d:"M35 50q4 3 8 0m11 0q4 3 8 0"})]})})}),t==="claude"?e.jsx("rect",{className:"arm",x:"75",y:"56",width:"8",height:"12",rx:"2"}):e.jsx("ellipse",{className:"arm",cx:"79",cy:"63",rx:"5",ry:"8"})]})})})})})})]})}const sp={blink:180,curious:900,hello:1100,boop:700,happy:900,look:1800,stretch:1600,tap:1150,pulse:1400,nod:700,yawn:1700,sleep:3200},rr=(t,n)=>Math.max(-n,Math.min(n,t)),lo="M25 60V41C25 28 35 23 48 23C61 23 71 28 71 41V60Z";function cl({size:t,theme:n,paused:s=!1,frozen:a=!1,reducedMotion:r=!1,dnd:l=!1,pointer:o=null,center:c,gestureKey:i,gestureKind:m="hello",boopKey:d}){const x=el(),p=`resident-${f.useId().replace(/[^A-Za-z0-9_-]/g,"")}`,[g,h]=f.useState(null),[N,k]=f.useState(!1),C=f.useRef(void 0),j=s||r||l||a,y=!j&&!!o&&!!c&&Math.hypot(o.x-c.x,o.y-c.y)<140,b=y?rr((o.x-c.x)/140*5,4):0,M=y?rr((o.y-c.y)/140*3,2):0,S=y?rr((o.x-c.x)/140*7,5):0,$=R=>{j||document.hidden||(clearTimeout(C.current),h(null),h(R),C.current=setTimeout(()=>h(null),sp[R]))};f.useEffect(()=>()=>clearTimeout(C.current),[]),f.useEffect(()=>{i&&$(m)},[i]),f.useEffect(()=>{d&&$("boop")},[d]);const v=f.useRef(!1);f.useEffect(()=>{y&&!v.current&&!N&&$("curious"),v.current=y},[y]),f.useEffect(()=>{if(j){h(null),clearTimeout(C.current);return}let R,_=0;const L=()=>{!document.hidden&&!N&&(_++,$(_%17===0?"sleep":_%13===0?"yawn":_%11===0?"tap":_%7===0?"stretch":_%5===0?"look":"blink")),R=setTimeout(L,4300+_%3*900)};R=setTimeout(L,3200);const T=()=>{document.hidden&&(h(null),clearTimeout(C.current))};return document.addEventListener("visibilitychange",T),()=>{clearTimeout(R),document.removeEventListener("visibilitychange",T)}},[j,N]);const A={"--resident-gx":b?`${b.toFixed(2)}px`:"0px","--resident-gy":M?`${M.toFixed(2)}px`:"0px","--resident-tilt":S?`${S.toFixed(2)}deg`:"0deg"};return e.jsxs("svg",{className:"resident",width:t,height:t,viewBox:t<=24?"5 8 86 74":"0 0 96 96",role:"img","aria-label":"Ledge","data-theme":n,"data-large":String(t>24),"data-near":String(y),"data-dnd":String(l),"data-frozen":String(a),"data-quiet":String(j),"data-gesture":g??void 0,style:A,onMouseEnter:()=>{k(!0),$("happy")},onMouseLeave:()=>k(!1),children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:`${p}-shell`,x1:".15",y1:"0",x2:".75",y2:"1",children:[e.jsx("stop",{className:"resident-top"}),e.jsx("stop",{className:"resident-bottom",offset:"1"})]}),e.jsxs("radialGradient",{id:`${p}-sheen`,cx:".3",cy:".2",r:".75",children:[e.jsx("stop",{className:"resident-sheen"}),e.jsx("stop",{className:"resident-sheen",offset:"1",stopOpacity:"0"})]})]}),e.jsx("g",{className:"resident-body",children:e.jsxs("g",{className:"resident-pose",children:[e.jsx("path",{className:"resident-antenna",d:"M48 23v-7"}),e.jsx("circle",{className:"resident-light",cx:"48",cy:"14",r:"2.6"}),e.jsx("path",{className:"resident-shell",d:lo,fill:`url(#${p}-shell)`}),t>24&&e.jsx("path",{d:lo,fill:`url(#${p}-sheen)`}),e.jsx("g",{className:"resident-gaze",children:e.jsxs("g",{className:"resident-blink",children:[e.jsxs("g",{className:"resident-eyes",children:[e.jsx("rect",{x:"37",y:"35",width:"6",height:"12",rx:"3"}),e.jsx("rect",{x:"53",y:"35",width:"6",height:"12",rx:"3"}),t>24&&e.jsxs("g",{className:"resident-glint",children:[e.jsx("circle",{cx:"38.8",cy:"37.8",r:"1.5"}),e.jsx("circle",{cx:"54.8",cy:"37.8",r:"1.5"})]})]}),e.jsx("path",{className:"resident-smile",d:"M36 43q4-7 8 0m8 0q4-7 8 0"}),e.jsx("path",{className:"resident-sleep",d:"M36 42q4 4 8 0m8 0q4 4 8 0"})]})})]})}),e.jsx("rect",{className:"resident-wall",x:"9",y:"59",width:"78",height:"20",rx:"6"}),e.jsx("rect",{className:"resident-slab",x:"6",y:"55",width:"84",height:"7",rx:"3.5"}),e.jsx("path",{className:"resident-rim",d:"M12 56.4H84"}),e.jsx("rect",{className:"resident-shell resident-grip",x:"26",y:"50",width:"12",height:"9",rx:"4.5",fill:`url(#${p}-shell)`}),e.jsx("rect",{className:"resident-shell resident-hand",x:"58",y:"50",width:"12",height:"9",rx:"4.5",fill:`url(#${p}-shell)`}),e.jsx("title",{children:a?x.residentOffline:x.residentName})]})}const ap={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"};function Fa({tool:t,seed:n,state:s,large:a=!1,frozen:r=!1}){const l=ap[s],o=Gn();return e.jsx("span",{className:"inline-flex flex-none","aria-hidden":"true",children:e.jsx(Da,{tool:t,seed:n,state:l,pose:Oa(n,l),size:a?68:34,theme:o,frozen:r})})}function Us(t){return e.jsx(cl,{...t,theme:Gn()})}const rp={plain:"border-line bg-surface",warning:"border-attention/25 bg-attention/[0.06]",approval:"border-approval/25 bg-approval/[0.06]",danger:"border-danger-fg/25 bg-danger-bg"};function De({title:t,tone:n="plain",children:s,role:a}){return e.jsxs("div",{role:a,className:`rounded-control border p-3.5 text-small leading-[1.65] ${rp[n]}`,children:[e.jsx("strong",{className:"mb-[5px] block text-body",children:t}),s]})}var dl=tx();const ul="(min-width: 768px) and (min-height: 501px)",lp=`${ul} and (orientation: landscape)`,oo=t=>typeof globalThis.matchMedia=="function"?globalThis.matchMedia(t):null;function yc(t){return f.useSyncExternalStore(n=>{var a;const s=oo(t);return(a=s==null?void 0:s.addEventListener)==null||a.call(s,"change",n),()=>{var r;return(r=s==null?void 0:s.removeEventListener)==null?void 0:r.call(s,"change",n)}},()=>{var n;return((n=oo(t))==null?void 0:n.matches)??!1},()=>!1)}function Dt(){return yc(ul)}function Pa(){return yc(lp)}const Nc=f.createContext(void 0),kc=()=>f.useContext(Nc);function rn({list:t,detail:n,tab:s,fold:a=!1}){const[r,l]=f.useState(null);return e.jsxs("div",{className:"split","data-split":s,"data-fold":a?"":void 0,children:[e.jsx("div",{ref:l,className:"split-banner"}),e.jsxs(Nc.Provider,{value:r,children:[e.jsx("section",{className:"split-list",children:t}),e.jsx("section",{className:"split-detail",children:n})]})]})}function io({title:t,body:n}){return e.jsx("div",{"data-split-empty":"",className:"flex flex-1 items-center justify-center px-6 text-center",children:e.jsxs("div",{className:"max-w-[280px]",children:[e.jsx("h2",{className:"text-base font-semibold",children:t}),e.jsx("p",{className:"mt-1 text-body text-muted",children:n})]})})}const op=["sessions","prs","rigs"];function xl(t){switch(t.name){case"sessions":case"routines":case"thread":case"terminal":case"launch":case"request":return"sessions";case"prs":case"rigs":return t.name;case"ask":return"rigs";case"rig":case"kernel":case"max":return"rigs";case"pr":return"prs";case"atelier":return"atelier";case"connection":return null}}const vc=t=>({name:t}),ip=t=>xl(t)===t.name&&!(t.name==="atelier"&&t.sessionId),wc=new Map;function cp(t){const n=xl(t);n&&n!=="atelier"&&wc.set(n,ce(t))}const Sc=t=>wc.get(t)??ce(vc(t)),Tr=t=>t>99?"99+":String(t);function dp(t,n=0){const s=t.filter(r=>r.filter==="permission").length;if(s)return{text:Tr(s),tone:"red"};const a=t.length-s+n;return a?{text:Tr(a),tone:"amber"}:null}function up(t){const n=t.filter(s=>s.kind!=="update").length;return n?{text:Tr(n),tone:"amber"}:null}function Cc({className:t}){return e.jsx("span",{"data-settings-dot":!0,"aria-hidden":"true",className:`absolute size-2 rounded-full bg-primary ${t}`})}function xp(t,n,s){return t?"online":s==="pc_offline"||s==="relay_unreachable"?"offline":n?"reconnecting":"loading"}const $c=f.createContext({pc:null,look:"online",reach:"pc_online",since:"",retry:()=>{}}),lr=$c.Provider,zt=()=>f.useContext($c),Jt=t=>{const n=t??u.host.unknown;return n.length>14?`${n.slice(0,13)}…`:n};function Mc({size:t=24}){return e.jsxs("svg",{"data-ledge-mark":!0,width:t,height:t,viewBox:"0 0 16 16","aria-hidden":"true",className:"flex-none",children:[e.jsx("rect",{width:"16",height:"16",rx:"3.5",fill:"#0A0A0A"}),e.jsx("rect",{x:"3",y:"3",width:"3",height:"10",rx:".5",fill:"#FAFAFA"}),e.jsx("rect",{x:"7",y:"10",width:"6",height:"3",rx:".5",fill:"#FAFAFA"}),e.jsx("circle",{cx:"10",cy:"6",r:"2",fill:"#FF6467"})]})}function ml(){const{pc:t,look:n}=zt(),s=Jt(t),a=n==="offline";return e.jsxs("a",{href:ce({name:"connection",section:"link"}),"data-host":n,"aria-label":u.host.label(t??u.host.unknown,n),className:`inline-flex h-[26px] flex-none items-center gap-1.5 rounded-full border px-2.5 text-small whitespace-nowrap ${a?"border-attention/45 text-attention":"border-input text-muted"}`,children:[n==="loading"?e.jsx("span",{"aria-hidden":"true",className:"inline-block size-2.5 animate-spin rounded-full border-[1.5px] border-current border-r-transparent"}):e.jsx("span",{"aria-hidden":"true",className:`inline-block size-2 flex-none rounded-full ${n==="online"?"bg-ok":a?"bg-attention":"bg-muted"}`}),a?u.host.offline(s):s]})}function mp({title:t}={}){const{settingsDot:n}=zt();return e.jsxs("header",{className:"bleed flex h-14 flex-none items-center gap-1.5 border-b border-line pr-1.5 pl-4",children:[t?e.jsx("h1",{className:"mr-1 text-[20px] font-semibold",children:t}):e.jsxs("span",{className:"mr-1 flex items-center gap-2 text-[17px] font-semibold",children:[e.jsx(Mc,{}),u.brand]}),e.jsx(ml,{}),e.jsx("span",{className:"flex-1"}),e.jsxs("a",{href:ce({name:"connection"}),"aria-label":u.nav.settings,title:u.nav.settings,className:"relative grid size-11 flex-none place-items-center rounded-lg text-muted active:bg-raised",children:[e.jsx(z,{name:"gear"}),n&&e.jsx(Cc,{className:"top-2.5 right-2.5"})]})]})}function Ec({badge:t,className:n}){return t?e.jsx("span",{"data-badge":t.tone,className:`absolute h-4 min-w-4 rounded-full px-1 text-center text-[10px] leading-4 font-semibold ${t.tone==="red"?"bg-primary text-primary-fg":"bg-attention text-[#1c1100]"} ${n}`,children:t.text}):null}const _c={sessions:"sessions",prs:"pr",rigs:"rigs",atelier:"atelier"};function Rc(t){return(n,s)=>a=>{if(!s||t.name==="connection")return;a.preventDefault();const r=document.querySelector("[data-tab-scroll]");r&&r.scrollTop>0?r.scrollTo({top:0,behavior:"smooth"}):ip(t)||is(vc(n))}}function pp({route:t,active:n,badges:s}){const a=Rc(t);return e.jsx("nav",{"aria-label":u.nav.label,className:"tabbar bleed grid flex-none grid-cols-3 border-t border-line bg-sidebar",children:op.map(r=>e.jsxs("a",{href:Sc(r),onClick:a(r,n===r),"aria-current":n===r?"page":void 0,className:"tab group relative flex flex-col items-center justify-center gap-[3px] text-[11px] leading-[13px] text-muted aria-[current=page]:font-medium aria-[current=page]:text-fg",children:[e.jsx("span",{className:"pad grid h-7 w-[52px] place-items-center rounded-full group-aria-[current=page]:bg-raised",children:e.jsx(z,{name:_c[r]})}),u.nav[r],e.jsx(Ec,{badge:s[r]??null,className:"top-[3px] left-1/2 ml-[7px]"})]},r))})}function fp({route:t,active:n,badges:s,atelier:a}){const r=Rc(t),{settingsDot:l}=zt(),o=c=>e.jsxs("a",{href:Sc(c),onClick:r(c,n===c),"aria-current":n===c?"page":void 0,className:"rb",children:[e.jsx(z,{name:_c[c]}),u.nav[c],e.jsx(Ec,{badge:s[c]??null,className:"top-[3px] right-[7px]"})]},c);return e.jsxs("nav",{"aria-label":u.nav.label,className:"rail",children:[e.jsx("span",{className:"mb-2",children:e.jsx(Mc,{size:30})}),["sessions","prs","rigs"].map(o),a&&o("atelier"),e.jsx("span",{className:"flex-1"}),e.jsxs("a",{href:ce({name:"connection"}),"aria-current":n==="settings"?"page":void 0,className:"rb",children:[e.jsx(z,{name:"gear"}),u.nav.settings,l&&e.jsx(Cc,{className:"top-[5px] right-[15px]"})]})]})}function wn({body:t,across:n=!1}={}){const{pc:s,look:a,reach:r,since:l,retry:o}=zt(),[c,i]=ps(),m=kc();if(a!=="offline")return null;const d=r==="relay_unreachable",x=d?u.compare.relayTitle:u.offline.title(s),p=d?u.compare.relayBody:l?(t??u.offline.body)(l):u.offline.bodyUnknown,g=N=>e.jsxs("button",{type:"button",disabled:c,onClick:()=>{i(!0),o()},className:rt({size:"sm",className:N}),children:[e.jsx(z,{name:"refresh",className:"size-4"}),u.offline.retry]}),h=e.jsx(z,{name:d?"cloud":"wifioff",className:"mt-px size-4 flex-none text-attention"});return m!==void 0?!n||!m?null:dl.createPortal(e.jsxs("section",{role:"status","data-strip":d?"relay":"pc",className:"strip flex items-center gap-[9px] rounded-lg border border-attention/40 px-3 py-2.5 text-[13px] leading-[18px]",children:[h,e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("b",{className:"font-semibold",children:x})," · ",e.jsx("span",{className:"text-muted",children:p})]}),g("flex-none")]}),m):e.jsxs("section",{role:"status","data-strip":d?"relay":"pc",className:"strip flex flex-none items-start gap-[9px] rounded-lg border border-attention/40 px-3 py-2.5 text-[13px] leading-[18px]",children:[h,e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[e.jsx("b",{className:"font-semibold",children:x}),e.jsx("span",{className:"text-muted",children:p}),g("self-start")]})]})}function hp(){const t="block animate-[ledge-pulse_1.6s_ease-in-out_infinite] rounded-[5px] bg-raised";return e.jsxs("div",{"aria-hidden":"true","data-loading":"","data-list-state":"",className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-line bg-surface p-3",children:[e.jsxs("div",{className:"flex items-center gap-[7px]",children:[e.jsx("span",{className:`${t} h-4 w-[26px]`}),e.jsx("span",{className:`${t} h-3.5 w-20`}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:`${t} h-4 w-[70px]`})]}),e.jsx("span",{className:`${t} h-[34px]`}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("span",{className:`${t} h-11`}),e.jsx("span",{className:`${t} h-11`})]})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-line bg-surface p-3",children:[e.jsxs("div",{className:"flex items-center gap-[7px]",children:[e.jsx("span",{className:`${t} h-4 w-[26px]`}),e.jsx("span",{className:`${t} h-3.5 w-[110px]`})]}),e.jsx("span",{className:`${t} h-3.5 w-[85%]`})]})]})}function hs({title:t,subtitle:n,wideSubtitle:s,actions:a,wideActions:r,children:l,bodyClassName:o="flex flex-col gap-3",offlineBody:c,heading:i=!0,offlinePill:m=!0}){const d=Dt(),{pc:x,look:p,since:g}=zt(),h=p==="loading",N=h?u.link.connecting(Jt(x)):p==="offline"?g?u.link.lastKnownAt(g):u.cards.lastKnown:s;return e.jsxs(e.Fragment,{children:[d&&e.jsxs("div",{className:"pane-head flex h-[58px] flex-none items-center gap-2 border-b border-line pr-1.5 pl-4",children:[e.jsx("h1",{className:"flex-none text-lg font-semibold whitespace-nowrap",children:t}),N&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:N}),!h&&(m||p!=="offline")&&e.jsx(ml,{}),r&&e.jsx("span",{className:"ml-auto flex flex-none items-center gap-2",children:r})]}),e.jsxs("main",{"data-tab-scroll":"",className:"tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pt-3.5 pb-[18px]",children:[e.jsx(wn,{body:c,across:!0}),!d&&i&&e.jsxs("div",{className:"flex flex-none items-baseline gap-2",children:[e.jsx("h1",{className:"text-[22px] leading-7 font-semibold tracking-[-.02em]",children:t}),(h||n)&&e.jsx("span",{className:"min-w-0 truncate text-[12.5px] text-muted",children:h?u.link.connecting(Jt(x)):n}),a&&e.jsx("span",{className:"ml-auto flex flex-none items-center gap-2 self-center",children:a})]}),h?e.jsx(hp,{}):e.jsx("div",{className:`flex-none ${o}`,children:l})]})]})}function mn(){const[t,n]=f.useState(!1);return f.useEffect(()=>{let s=!0;return Ox().then(a=>{s&&n(a)}),()=>{s=!1}},[]),t}function Pt(){const t=globalThis.navigator;return t?/iPhone|iPad/.test(t.userAgent)||/Macintosh/.test(t.userAgent)&&t.maxTouchPoints>1:!1}const Sn=u.confirm,or=t=>We({variant:t,block:!0});function co({store:t,item:n,enabled:s,reason:a,onConfirm:r,onDeny:l,denyLabel:o}){const[c,i]=f.useState(null),[m,d]=f.useState(null),[x,p]=f.useState(!1),[g,h]=f.useState(a!==void 0),[N,k]=f.useState(0),C=f.useRef(!0),j=f.useRef(s);j.current=s;const y=f.useRef(null);f.useEffect(()=>(C.current=!0,()=>{C.current=!1}),[]),f.useEffect(()=>{var T;if(g||!s)return;const A=(T=t.getState().sessions.get(n.sessionId))==null?void 0:T.pending;if(!(A!=null&&A.key))return;let R=!0,_;i(null);const L={key:A.key,kind:A.kind,text:A.text};return t.prepareConfirm({purpose:"decide",id:n.sessionId,expect:L}).then(B=>{R&&(y.current=L,i(B),_=setTimeout(()=>{R&&(i(null),d("expired"))},B.expiresInMs))},()=>{R&&d("prepareFailed")}),()=>{R=!1,clearTimeout(_)}},[t,n.sessionId,n.key,s,g,N]);const b=g&&a?a==="assertion_expired"?"expired":"failed":m,M=()=>{d(null),h(!1),k(A=>A+1)},S=async()=>{var _,L;if(!s||x||!c)return;if(!c.credentialId){i(null),d("failed");return}p(!0),d(null);const A=await Fs({challenge:c.challenge,rpId:c.rpId,credentialId:c.credentialId}).catch(()=>"failed");if(!C.current)return;p(!1);const R=y.current;if(!R||!j.current||((L=(_=t.getState().sessions.get(n.sessionId))==null?void 0:_.pending)==null?void 0:L.key)!==R.key){i(null),d("changed");return}if(A==="cancelled"){d("cancelled");return}if(A==="failed"){d("failed");return}i(null),r(A,R)===null&&d("failed")},$=b==="expired"||b==="failed"||b==="prepareFailed"||b==="changed",v=x?Sn.asking:c?Pt()?Sn.goApple:Sn.go:Sn.preparing;return e.jsxs("section",{"aria-labelledby":"confirm-title",className:"flex flex-col gap-3 rounded-card border border-line bg-surface p-4",children:[e.jsx("h2",{id:"confirm-title",className:"text-title leading-[1.35] font-semibold",children:Sn.heading}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:Sn.note}),b&&e.jsx(De,{title:b==="changed"?u.decide.changed:Sn[b],tone:"warning",role:"alert"}),$?e.jsx("button",{type:"button",disabled:!s,onClick:M,className:or("primary"),children:Sn.retry}):e.jsx("button",{type:"button",disabled:!s||x||!c,onClick:()=>{S()},className:or("primary"),children:v}),e.jsx("button",{type:"button",disabled:!s,onClick:l,className:or(),children:o??u.decide.deny})]})}function uo(){return e.jsxs("p",{className:"inline-flex min-h-12 flex-1 items-center justify-center gap-2 rounded-control border border-dashed border-line px-4 py-2.5 text-center text-body leading-[1.4] font-medium text-muted",children:[e.jsx(z,{name:"monitor",className:"size-4"}),u.decide.onPc]})}function gp(t){return t instanceof HTMLElement?t.isContentEditable||t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT":!1}function bp(){return document.querySelector('[role="dialog"][aria-modal="true"]')!==null}function Tc(t,n){const s=f.useRef(n);s.current=n,f.useEffect(()=>{if(!t)return;const a=r=>{r.defaultPrevented||r.repeat||r.altKey||r.ctrlKey||r.metaKey||r.isComposing||gp(r.target)||bp()||s.current(r.key)&&r.preventDefault()};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[t])}const xo=t=>We({variant:t,className:"flex-1"}),Fn=t=>We({variant:t,block:!0});function jp(t,n){const s=u.decide;switch(n){case"invalid":return t.kind==="question"?s.otherInvalid:s.failed;case"free_text":return s.otherUnsupported;case"untypable":return t.kind==="question"?u.question.untypable:s.failed;case"busy":return s.busy;case"not_taken":return s.notTaken;case"read_only":return s.readOnly;default:return s.failed}}function yp(t){const{item:n,outcome:s,fresh:a,changed:r,stillPending:l,onReread:o,onDecide:c,answerable:i=!1,choice:m=null,onAnswer:d,answerBlocked:x=!1,onCheck:p,refused:g=!1,store:h,deviceConfirm:N=!1,optionReply:k,multi:C,keys:j=!1,withThread:y=!0}=t,b=u.decide,[M,S]=ps(),$=mn(),v=n.risk==="high"||s.kind==="rejected"&&s.reason==="confirm_required",A=a&&!r&&l,R=n.kind!=="question"&&!k&&!C&&!i&&!v,_=R&&Li(n.tool,n.kind,"always"),L=_r(n),T=_&&e.jsx("p",{className:"text-small text-muted phone-side:text-[12px] phone-side:leading-4",children:u.cards.scope[L]}),B=s.kind!=="sending"&&s.kind!=="uncertain"&&!((s.kind==="rejected"||s.kind==="failed")&&(s.reason==="no_prompt"||s.reason==="nothing_to_decide"||s.reason==="stale"));Tc(j&&R&&A&&B,D=>{const Q=D.toLowerCase();return Q==="y"?(c("accept"),!0):Q==="n"?(c("deny"),!0):!1});const E=e.jsx("a",{href:t.threadHref??ce({name:"thread",sessionId:n.sessionId}),className:Fn("ghost"),children:u.result.thread(n.botName)}),P=(D,Q,q=!0)=>e.jsxs("footer",{className:"flex flex-none flex-col gap-2.5 border-t border-line bg-bg pt-3 pb-4 phone-side:pb-2",children:[D,q&&y&&e.jsx("div",{className:"phone-side:hidden",children:E}),Q&&e.jsx("p",{className:"text-center text-meta text-muted phone-side:hidden",children:Q})]});if(n.kind==="question"&&!i&&!k&&!C)return P(null,b.answerOnPc);const W=N&&$?h:void 0,F=k?k.canConfirm&&W!==void 0:v&&!i&&W!==void 0,re=s.kind==="rejected"&&(s.reason==="assertion_expired"||s.reason==="assertion_invalid"||s.reason==="confirm_required")?s.reason:void 0,Y=D=>k?F?k.picked!==null&&W?e.jsx(co,{store:W,item:n,enabled:D,reason:re,onConfirm:k.onReply,onDeny:k.onBack,denyLabel:u.answers.change}):null:e.jsx(uo,{}):C?e.jsxs("div",{className:"flex flex-col gap-2.5",children:[C.missing>0&&e.jsx("p",{className:"text-center text-small text-muted",children:u.answers.missing(C.missing)}),e.jsx("button",{type:"button",disabled:!D||C.missing>0,onClick:C.onSend,className:Fn("primary"),children:u.answers.send}),e.jsx("button",{type:"button",disabled:!D,onClick:C.onCancel,className:Fn(),children:u.answers.cancel})]}):F&&W?e.jsx(co,{store:W,item:n,enabled:D,reason:re,onConfirm:(Q,q)=>W.decide(n.sessionId,"accept",{assertion:Q,expect:q}),onDeny:()=>c("deny")}):i?e.jsx("button",{type:"button",disabled:!D||m===null||x,onClick:()=>d==null?void 0:d(),className:Fn("primary"),children:b.send}):j&&R?e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsx("button",{type:"button",disabled:!D,onClick:()=>c("accept"),className:We({variant:"primary",className:"min-w-[150px]"}),children:b.allow}),e.jsx("button",{type:"button",disabled:!D,onClick:()=>c("deny"),className:We({className:"min-w-[120px]"}),children:b.deny}),_&&e.jsx("button",{type:"button",disabled:!D,onClick:()=>c("always"),className:We({variant:"ghost"}),children:ga(L)}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono text-small text-muted",children:u.cards.keys}),T&&e.jsx("div",{className:"basis-full",children:T})]}):e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsxs("div",{className:"flex flex-col gap-2.5 phone-side:flex-row",children:[e.jsxs("div",{className:"flex gap-2.5 phone-side:flex-[2]",children:[e.jsx("button",{type:"button",disabled:!D,onClick:()=>c("deny"),className:xo(),children:b.deny}),v?e.jsx(uo,{}):e.jsx("button",{type:"button",disabled:!D,onClick:()=>c("accept"),className:xo("primary"),children:b.allow})]}),_&&e.jsx("button",{type:"button",disabled:!D,onClick:()=>c("always"),className:We({variant:"ghost",block:!0,className:"phone-side:w-auto phone-side:flex-1"}),children:ga(L)})]}),T]}),H=a?k?F?b.answerHint:b.onPcHint:C?b.answerHint:v&&!i&&!F?b.onPcHint:i?b.answerHint:b.hint:b.offlineHint,I=D=>P(e.jsxs(e.Fragment,{children:[D,Y(A)]}),H);if(r&&s.kind!=="sending"&&s.kind!=="uncertain")return P(e.jsxs(e.Fragment,{children:[e.jsx(De,{title:b.changed,tone:"warning",role:"status"}),Y(!1),e.jsx("button",{type:"button",onClick:o,className:Fn(),children:b.reread})]}));switch(s.kind){case"sending":return P(e.jsx(De,{title:b.sending,role:"status",children:e.jsx("p",{children:b.sendingBody})}));case"uncertain":return P(e.jsxs(e.Fragment,{children:[e.jsx(De,{title:b.uncertain,tone:"warning",role:"alert",children:e.jsx("p",{children:b.uncertainBody})}),p&&e.jsx("button",{type:"button",disabled:M,onClick:()=>{S(!0),p()},className:Fn("primary"),children:M?b.checking:b.check})]}));case"rejected":case"failed":{const D=s.reason;if(F&&re||D==="confirm_required")return I();if(D==="no_prompt"||D==="nothing_to_decide")return P(e.jsx(De,{title:b.noPrompt,tone:"warning",role:"alert"}));if(D==="stale")return P(e.jsxs(e.Fragment,{children:[e.jsx(De,{title:b.changed,tone:"warning",role:"alert"}),e.jsx("a",{href:ce({name:"sessions"}),className:Fn(),children:u.result.back})]}),void 0,!1);const Q=e.jsx(De,{title:jp(n,D),tone:"warning",role:"alert"});return l?I(Q):P(Q)}default:return I(g?e.jsx(De,{title:b.failed,tone:"warning",role:"alert"}):void 0)}}const Zn=(t,n)=>{var s,a;return(a=(s=t.match(new RegExp(`<${n}>([\\s\\S]*?)</${n}>`)))==null?void 0:s[1])==null?void 0:a.trim()};function Np(t){const n=t.trim();if(!n.startsWith("<task-notification>"))return null;const s=Zn(n,"status"),a=Zn(n,"summary")??"",r=a.match(/^Agent "(.+)" (?:was |has )?(?:stopped|killed|completed|finished|failed)/),l=a.match(/^Background command "(.+)" (?:completed|failed|was stopped|was killed)(?: \(exit code (\d+)\))?/);return{...Zn(n,"task-id")!==void 0&&{id:Zn(n,"task-id")},...Zn(n,"output-file")!==void 0&&{output:Zn(n,"output-file")},status:s==="killed"||s==="completed"||s==="failed"?s:"other",summary:a,about:r?{kind:"agent",name:r[1]}:l?{kind:"command",command:l[1],...l[2]!==void 0&&{code:l[2]}}:null,raw:n}}const yt=u.thread.rig,mo=t=>t?`…${t.slice(-4)}`:"…";function kp(t){const n=t.indexOf("@");return n>0?{seat:t.slice(0,n),rig:t.slice(n+1)}:{seat:t}}function oa(t,n,s){const a=n?s.get(n):void 0,{seat:r,rig:l}=kp(t??"");return a?{name:a.name,...r?{seat:r}:{},session:{id:a.id,tool:a.tool,state:a.state}}:{name:r||(t??""),...l?{seat:l}:{}}}function vp(t){const n=t.split(`
|
|
4
4
|
`).map(s=>s.trim()).find(s=>s!=="")??"";return`${yt.about(Ac(n))} `}const Ac=t=>t.length>80?`${t.slice(0,79).trimEnd()}…`:t;function wp(t,n){const s=t.split(`
|
|
5
|
-
`).slice(1).map(a=>a.trim()).find(a=>a!=="");return s?yt.refusedSaid(Tn(n),Ac(s)):yt.refusedSilent(Tn(n))}const Tn=t=>new Date(t).toLocaleTimeString(ut,{hour:"2-digit",minute:"2-digit"});function Sp(t,n,s){if(t.kind!=="received"&&t.kind!=="sent"&&t.kind!=="notice"||!t.rig)return;const a=t.rig,r=a.sentAt??t.at,l=s?{cut:!0}:{},o=(i=yt.raw)=>({label:i,text:a.raw});if(a.kind==="unreadable")return{key:t.id,kind:"rig-unreadable",at:r,text:a.raw||("text"in t?t.text:""),...l};if(t.kind==="received"){const i=oa(a.from??t.from,t.peer,n);return{key:t.id,kind:"rig-message",at:r,dir:"in",who:i,text:t.text,...a.count?{count:a.count}:{},...i.session?{reply:{sessionId:i.session.id,draft:vp(t.text)}}:{},raw:o(),...l}}if(t.kind==="sent")return{key:t.id,kind:"rig-message",at:r,dir:"out",who:oa(a.to??t.to,t.peer,n),text:t.text,delivery:t.status,raw:o(yt.command),...l};if(a.kind==="handoff"){const i=!!t.outgoing,
|
|
5
|
+
`).slice(1).map(a=>a.trim()).find(a=>a!=="");return s?yt.refusedSaid(Tn(n),Ac(s)):yt.refusedSilent(Tn(n))}const Tn=t=>new Date(t).toLocaleTimeString(ut,{hour:"2-digit",minute:"2-digit"});function Sp(t,n,s){if(t.kind!=="received"&&t.kind!=="sent"&&t.kind!=="notice"||!t.rig)return;const a=t.rig,r=a.sentAt??t.at,l=s?{cut:!0}:{},o=(i=yt.raw)=>({label:i,text:a.raw});if(a.kind==="unreadable")return{key:t.id,kind:"rig-unreadable",at:r,text:a.raw||("text"in t?t.text:""),...l};if(t.kind==="received"){const i=oa(a.from??t.from,t.peer,n);return{key:t.id,kind:"rig-message",at:r,dir:"in",who:i,text:t.text,...a.count?{count:a.count}:{},...i.session?{reply:{sessionId:i.session.id,draft:vp(t.text)}}:{},raw:o(),...l}}if(t.kind==="sent")return{key:t.id,kind:"rig-message",at:r,dir:"out",who:oa(a.to??t.to,t.peer,n),text:t.text,delivery:t.status,raw:o(yt.command),...l};if(a.kind==="handoff"){const i=!!t.outgoing,m=oa(i?a.to:a.from??t.name,t.peer,n),d=i&&t.status==="refused"?{refused:{log:wp(a.raw,t.at)}}:{},x=!("refused"in d)&&a.qitem?{qitem:a.qitem}:{};return{key:t.id,kind:"rig-task",at:r,outgoing:i,who:m,title:a.summary??t.summary??t.text,raw:o(i?yt.command:yt.raw),...d,...x,...l}}if(a.kind==="unblocked")return{key:t.id,kind:"rig-notice",at:r,tone:"task",title:yt.unblocked(mo(a.qitem)),raw:o(),...l};if(a.kind==="openrig"&&a.alert==="stalled")return{key:t.id,kind:"rig-notice",at:r,tone:"warn",title:yt.stalled(mo(a.qitem),a.minutes??0),raw:o(),...l};const c=t.text.split(`
|
|
6
6
|
`).map(i=>i.trim()).find(i=>i!=="")??"";return{key:t.id,kind:"rig-notice",at:r,tone:"plain",title:c,raw:o(),...l}}const Cp=t=>{var n;return t.kind==="received"||t.kind==="sent"||t.kind==="notice"?(n=t.rig)==null?void 0:n.packet:void 0};function $p(t){const n=new Map;for(const r of t){const l=Cp(r);if(!l||!("rig"in r)||!r.rig)continue;const o=n.get(l.id)??{id:l.id,items:[],count:l.count};o.items.push({id:r.id,index:l.index,raw:r.rig.raw,at:r.at}),n.set(l.id,o)}const s=new Set,a=new Map;for(const r of n.values()){if(r.items.length<2)continue;for(const c of r.items)s.add(c.id);const l=r.items.at(-1),o=[...r.items].sort((c,i)=>c.index-i.index).map(c=>c.raw).join(`
|
|
7
|
-
`);a.set(l.id,{key:`packet-${r.id}`,kind:"rig-raw",at:l.at,raw:{label:yt.rawMany(r.count),text:o}})}return{inPacket:s,after:a}}function Mp(t){const n=[];let s=[];const a=()=>{s.length===1?n.push(s[0]):s.length>1&&n.push({key:`fold-${s[0].key}`,kind:"rig-fold",at:s[0].at,notices:s}),s=[]};for(const r of t){if(r.kind==="rig-notice"&&r.tone==="plain"){s.push(r);continue}a(),n.push(r)}return a(),n}const po={pending:"pending","in-progress":"taken","handed-off":"passed",blocked:"blocked",done:"done"};function Ep(t,n){if(!t)return{key:"unknown",text:yt.rowState.unknown};const s=po[t.state]??"unknown",a=po[t.state]?s==="passed"?yt.rowState.passed(oa(t.handedOffTo,void 0,new Map).name):yt.rowState[s]:t.state,r=[n?yt.log.passed(Tn(t.createdAt)):yt.log.handed(Tn(t.createdAt)),t.claimedAt?yt.log.taken(Tn(t.claimedAt)):s==="pending"?yt.log.notTaken:null,s==="done"?yt.log.done(Tn(t.updatedAt)):null].filter(Boolean).join(" · ");return{key:s,text:a,log:r}}const _p=t=>[...new Set(t.map(n=>n.name))],Rp=(t,n)=>t.length===n.length&&t.every((s,a)=>s===n[a]),Ic=(t,n)=>Object.values(n).filter(s=>s.message.type==="session.reply"&&s.message.expect===null&&s.message.id===t).sort((s,a)=>s.at.localeCompare(a.at));function Tp(t,n,s){return Object.values(s).some(a=>a.phase==="applied"&&a.message.type==="session.decide"&&a.message.id===n&&a.message.expect.text===t.text&&a.message.decision===t.decision)}function Lc(t,n,s,a){var l,o;const r=u.thread.event;return((l=t.by)==null?void 0:l.kind)==="device"?t.by.id===a?r.fromHere:r.fromDevice(t.by.name):((o=t.by)==null?void 0:o.kind)==="pc"?r.fromPc:Tp(t,n,s)?r.fromHere:r.fromPc}function Ap(t,n,s,a){const r=u.thread.event;if(!t.decision)return null;if(t.decision==="unknown")return r.resolved;const l=Lc(t,n,s,a);return t.decision==="deny"?r.deny(l):r.accept(l)}const Ar=2e4,Ip=(t,n,s)=>{const a=t.trim(),r=n.trim();return a===r||s&&a.length>0&&r.startsWith(a)};function Lp(t,n,s,a=Date.now(),r=[],l=new Map,o=null){var j,y,b,M,S,$;let c=[];const i=new Set(r),x=v=>i.has(v)?{cut:!0}:{},d=Ic(n.id,s),m=new Set,p=new Set;for(const v of d){if(v.phase!=="applied")continue;const A=v.message.attachments??[],R=t.find(_=>{var L;return _.kind==="prompt"&&Ip(_.text,v.message.text,i.has(_.id))&&!m.has(_.id)&&Rp(((L=_.images)==null?void 0:L.map(T=>T.id))??[],A)});R&&(m.add(R.id),p.add(v.op))}const g=$p(t);let h=null,N=null;for(const v of t){const A=Sp(v,l,i.has(v.id));if(A){const L=v.kind==="received"||v.kind==="sent"||v.kind==="notice"?((y=(j=v.rig)==null?void 0:j.packet)==null?void 0:y.id)??null:null,T=Tn(A.at);if(!(L&&L===N)&&T!==h&&c.push({key:`time-${v.id}`,kind:"time",label:T}),h=T,N=L,g.inPacket.has(v.id)){const{raw:B,...E}=A;c.push(E);const P=g.after.get(v.id);P&&c.push(P)}else c.push(A);continue}if(v.kind==="tool"&&!((b=v.images)!=null&&b.length)){const L={id:v.id,name:Ul(v.tool),label:v.label,status:v.status},T=c.at(-1);(T==null?void 0:T.kind)==="tools"?T.tools.push(L):c.push({key:`tools-${v.id}`,kind:"tools",at:v.at,tools:[L]}),h=null,N=null;continue}const R=c.length,_=v.kind==="prompt"?Np(v.text):null;if(_)c.push({key:v.id,kind:"task",task:_,at:v.at,...x(v.id)});else if(v.kind==="prompt")c.push({key:v.id,kind:"me",text:v.text,at:v.at,...(M=v.images)!=null&&M.length?{images:v.images}:{},...m.has(v.id)?{delivery:"taken"}:{},...x(v.id)});else if(v.kind==="reply")c.push({key:v.id,kind:"agent",text:v.text,at:v.at,...x(v.id)});else if(v.kind==="tool"&&((S=v.images)!=null&&S.length))c.push({key:v.id,kind:"capture",label:nm(v.tool)?u.thread.capture:Ul(v.tool),at:v.at,images:v.images});else if(v.kind==="notice"&&v.adopted)c.push({key:v.id,kind:"event",label:`${v.adopted==="pane"?u.adopt.markPane:u.adopt.markResume} · ${Tn(v.at)}`,at:v.at});else if(v.kind==="permission"){const L=Ap(v,n.id,s,o);L&&c.push({key:v.id,kind:"event",label:L,at:v.at})}c.length>R&&(h=null,N=null)}c=Mp(c);const k=Math.max(...t.map(v=>Date.parse(v.at)));for(const v of d){const A=Date.parse(v.at),R={key:v.op,kind:"me",text:v.message.text,at:v.at,...($=v.message.attachments)!=null&&$.length?{attachments:v.message.attachments}:{}};if(v.phase==="sending")c.push({...R,delivery:"sending"});else if(v.phase==="uncertain")c.push({...R,delivery:"uncertain"});else if(v.phase==="applied"&&!p.has(v.op)&&!(k-A>Ar)){const _=c.findIndex(T=>T.kind!=="awaiting"&&T.kind!=="time"&&!(T.kind==="me"&&T.delivery&&T.delivery!=="taken")&&Date.parse(T.at)>A),L=_<0?c.length:_>0&&c[_-1].kind==="time"?_-1:_;c.splice(L,0,{...R,delivery:"taken",...a-A<Ar?{fresh:!0}:{}})}}n.exitedAt&&Dm(n,s)&&c.push({key:`closed-${n.exitedAt}`,kind:"event",label:u.sessionEnd.closedHere(Fm(n.exitedAt)),at:n.exitedAt});const C=kn([n])[0];return C&&c.push({key:`awaiting-${C.key}`,kind:"awaiting",item:C}),c}const qt=u.thread.composer;function Op(t,n,s){const a=(r,l,o)=>({enabled:!1,placeholder:r,status:{tone:l,label:o}});if(n==="handshaking")return a(qt.placeholder.connecting,"muted",qt.status.connecting);if(n!=="ready")return a(qt.placeholder.offline,"muted",qt.status.offline);if(t.state==="exited"||t.state==="error")return a(qt.placeholder.ended,"muted",qt.status.ended);if(t.pending||t.state==="waiting_permission"||t.state==="waiting_input"){const r=t.pending?t.pending.kind==="question":t.state==="waiting_input";return a(qt.placeholder.awaiting,r?"attention":"approval",qt.status.awaiting)}return t.state!=="idle"?a(qt.placeholder.working,"info",qt.status.working):s?a(qt.placeholder.idle(t.name),"info",qt.status.sending):{enabled:!0,placeholder:qt.placeholder.idle(t.name),status:{tone:"ok",label:qt.status.idle}}}const Dp=["Montre le diff","Lance les tests","Explique les changements"],Ke=t=>t?new Date(t).toLocaleTimeString(ut,{hour:"2-digit",minute:"2-digit"}):"";function ia({store:t,title:n,body:s,item:a,final:r=!1,children:l}){const o=ps(me(t)),c=ce({name:"sessions"}),i={name:"sessions"};return e.jsxs(e.Fragment,{children:[e.jsx(Hs,{title:u.result.header,fallback:i,label:u.detail.back,link:o}),e.jsx("main",{className:"min-h-0 flex-1 overflow-y-auto pb-[22px]",children:e.jsxs("div",{className:"flex flex-col items-start gap-4 pt-7",children:[e.jsx("div",{className:"grid size-14 place-items-center rounded-full border border-ok/20 bg-ok/10 text-ok",children:e.jsx(z,{name:"check",className:"size-[26px]"})}),a&&e.jsxs("span",{className:"flex items-center gap-2 text-meta font-medium tracking-[0.4px] text-muted",children:[e.jsx(Fa,{tool:a.tool,seed:a.sessionId,state:"idle"}),e.jsxs("span",{className:"[overflow-wrap:anywhere]",children:[a.botName," · ",a.task]})]}),e.jsx("h1",{className:"text-display leading-[1.25] font-semibold tracking-[-1px] [overflow-wrap:anywhere]",children:n}),e.jsx("p",{className:"text-body text-muted",children:s}),a&&e.jsx("div",{className:"w-full",children:e.jsx(De,{title:Ia(a),children:e.jsxs("p",{className:"text-muted [overflow-wrap:anywhere]",children:[a.repo,a.branch&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("code",{className:"font-mono text-[.9em]",children:a.branch})]})]})})}),r&&e.jsx("p",{className:"text-body text-muted",children:u.result.final}),l,e.jsx("a",{href:c,className:We({variant:"primary",block:!0}),children:u.result.back}),a&&e.jsx("a",{href:ce({name:"thread",sessionId:a.sessionId}),className:We({block:!0}),children:u.result.thread(a.botName)})]})})]})}const Fp=We({variant:"primary",block:!0});function Pp({store:t,stale:n=!1,item:s,panel:a}){var h,N,k,C;const r=me(t),l=ps(r),o=s==null?void 0:s.sessionId,c=o!==void 0&&r.threads.has(o),i=s?(h=r.sessions.get(s.sessionId))==null?void 0:h.lastAnswer:void 0,x=!!s&&!!i&&i.key===s.key;f.useEffect(()=>{!n&&!x&&o!==void 0&&!c&&t.openThread(o)},[n,x,o,c,t]);const d=ce({name:"sessions"}),m={name:"sessions"};if(n)return e.jsxs(e.Fragment,{children:[a?a.header:e.jsx(Hs,{title:u.gone.header,fallback:m,label:u.detail.back,link:l}),e.jsxs("main",{className:"min-h-0 flex-1 overflow-y-auto pt-7",children:[e.jsx("h1",{className:"text-display leading-[1.25] font-semibold tracking-[-1px]",children:u.gone.staleTitle}),e.jsx("p",{className:"mt-2.5 text-body text-muted",children:u.gone.staleBody}),e.jsx("a",{href:(a==null?void 0:a.back.href)??d,className:`mt-6 ${Fp}`,children:(a==null?void 0:a.back.label)??u.gone.back})]})]});if(s&&i&&x){const j=i.by.kind==="pc"?u.thread.event.fromPc:i.by.id===((N=r.device)==null?void 0:N.id)?u.thread.event.fromHere:u.thread.event.fromDevice(i.by.name);return e.jsx(ia,{store:t,title:u.gone.titleOn(j),body:i.decision?u.gone.decided(i.decision,Ke(i.at)):u.gone.answered(Ke(i.at)),item:s})}const p=s&&s.kind==="permission"?[...((k=r.threads.get(s.sessionId))==null?void 0:k.items)??[]].reverse().find(j=>j.kind==="permission"&&j.text===s.text&&j.decision!==void 0&&j.decision!=="unknown"):void 0;if(!p||p.decision===void 0||p.decision==="unknown")return e.jsx(ia,{store:t,title:u.gone.titleElsewhere,body:u.gone.body,item:s});const g=Lc(p,s.sessionId,r.ops,((C=r.device)==null?void 0:C.id)??null);return e.jsx(ia,{store:t,title:u.gone.titleOn(g),body:u.gone.decided(p.decision,Ke(p.at)),item:s})}function zp({options:t,value:n,onChange:s,disabled:a=!1,botName:r,other:l,onSubmit:o}){const c=t.length,i=t.length===0,x=l!==void 0&&(i||n===c),d=x&&l.problem!==null&&l.problem!=="empty",m="flex min-h-12 cursor-pointer items-center gap-3 rounded-control border border-line bg-surface px-3 py-3 text-body has-[:checked]:border-fg/40 has-[:checked]:bg-raised has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-info";return e.jsxs("fieldset",{disabled:a,className:"my-3.5 flex min-w-0 flex-col gap-2 border-0 p-0",children:[e.jsx("legend",{className:"sr-only",children:u.question.legend}),t.map((p,g)=>e.jsxs("label",{className:m,children:[e.jsx("input",{type:"radio",name:"answer",value:g,checked:n===g,onChange:()=>s(g),className:"size-4 flex-none accent-fg"}),e.jsx("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:p})]},g)),l&&e.jsxs(e.Fragment,{children:[!i&&e.jsxs("label",{className:m,children:[e.jsx("input",{type:"radio",name:"answer",value:c,checked:x,onChange:()=>s(c),className:"size-4 flex-none accent-fg"}),e.jsx("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:u.question.other})]}),x&&e.jsxs("div",{children:[e.jsx("label",{htmlFor:"other-answer",className:"mt-3 mb-2 block text-small text-muted",children:u.question.fieldLabel(r)}),e.jsx("textarea",{id:"other-answer",rows:2,value:l.text,onChange:p=>l.onText(p.target.value),placeholder:u.question.placeholder,"aria-invalid":d,"aria-describedby":d?"other-problem":void 0,autoComplete:"off",enterKeyHint:"send",onKeyDown:p=>{p.key==="Enter"&&!p.nativeEvent.isComposing&&(p.preventDefault(),o==null||o())},className:"max-h-[120px] min-h-12 w-full min-w-0 resize-y rounded-control border border-line bg-surface p-3 text-base leading-[22px] text-fg placeholder:text-muted focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-info"}),d&&e.jsx("p",{id:"other-problem",role:"alert",className:"mt-2 text-small text-danger-fg",children:l.problem==="long"?u.question.long(il):l.problem==="digit"?u.question.digit:u.question.untypable})]})]})]})}const Bp="flex min-h-12 cursor-pointer items-center gap-3 rounded-control border border-line bg-surface px-3 py-3 text-body has-[:checked]:border-fg/40 has-[:checked]:bg-raised has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-info";function qp({questions:t,selected:n,onToggle:s,disabled:a=!1}){return e.jsx("div",{className:"my-3.5 flex flex-col gap-5",children:t.map((r,l)=>e.jsxs("fieldset",{disabled:a,className:"flex min-w-0 flex-col gap-2 border-0 p-0",children:[e.jsx("legend",{className:"mb-2 text-base leading-[1.4] font-semibold [overflow-wrap:anywhere]",children:r.header??r.question}),r.header&&e.jsx("p",{className:"mb-1 text-small text-muted [overflow-wrap:anywhere]",children:r.question}),r.options.map(o=>{var c;return e.jsxs("label",{className:Bp,children:[e.jsx("input",{type:r.multi?"checkbox":"radio",name:`question-${l}`,checked:((c=n[l])==null?void 0:c.includes(o.label))===!0,onChange:()=>s(l,o.label),className:"size-4 flex-none accent-fg"}),e.jsxs("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:[o.label,o.description&&e.jsx("small",{className:"mt-0.5 block text-meta text-muted",children:o.description})]})]},o.label)})]},r.id))})}function Hp({onReconnect:t}){const[n,s]=xs();return e.jsxs(De,{title:u.link.lostTitle,tone:"warning",role:"status",children:[e.jsx("p",{children:u.link.lostDetail}),t&&e.jsx("button",{type:"button",disabled:n,onClick:()=>{s(!0),t()},className:We({block:!0,className:"mt-3"}),children:n?u.link.reconnecting:u.link.reconnect})]})}const Up=t=>t.decision==="deny"?u.result.denied:t.answer!==void 0?u.result.answered:u.result.allowed;function Wp({title:t,panel:n}){return e.jsx("header",{className:"flex-none border-b border-line pt-2 pb-3",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("button",{type:"button",onClick:n.onBack,className:"-ml-1 flex min-h-11 items-center gap-1 pr-2 text-body text-muted active:text-fg",children:[e.jsx(z,{name:"back"}),u.nav.backTo.thread]}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),e.jsx("button",{type:"button",onClick:n.onClose,"aria-label":u.atelier.closePanel,title:u.atelier.closeTitle,className:Ot({}),children:e.jsx(z,{name:"close"})})]})})}const Kp="(orientation: landscape) and (max-height: 500px)",fo=["wheel","touchstart","keydown","pointerdown"];function Ir({store:t,sessionId:n,requestKey:s,onReconnect:a,panel:r,onSettled:l,keys:o=!1}){var Vt,tn,Gt,Xt,U,Se;const c=me(t),i=Kt(),{fresh:x,ops:d,capabilities:m}=c,p=kc(),{look:g}=zt(),h=p!==void 0&&g==="offline",[N,k]=f.useState(s),[C,j]=f.useState(!1),[y,b]=f.useState(null),[M,S]=f.useState(""),[$,v]=f.useState(null),[A,R]=f.useState({sig:"",v:[]}),_=xn(),[L,T]=f.useState(!1),B=f.useRef(N);B.current=N,f.useEffect(()=>{s!==B.current&&(k(s),j(!1),b(null),S(""),v(null),T(!1))},[s]);const E=[...c.sessions.values()],P=kn(E).find(ie=>ie.sessionId===n&&ie.key===N),W=f.useRef(void 0);P&&(W.current=P);const F=pc({sessionId:n,key:N},E,d),re=(P==null?void 0:P.cut)===!0;f.useEffect(()=>{re&&x&&t.loadPending(n)},[t,n,N,re,x]);const Y=(tn=(Vt=c.sessions.get(n))==null?void 0:Vt.pending)==null?void 0:tn.key;f.useEffect(()=>{var ie;if(!(F.kind!=="changed"||!Y)){k(Y),j(!0),b(null),S(""),v(null);try{(ie=globalThis.history)==null||ie.replaceState(globalThis.history.state,"",ce(r?{name:"atelier",sessionId:n,requestKey:Y}:{name:"request",sessionId:n,key:Y}))}catch{}}},[F.kind,Y,n]);const H=ps(c),I={name:"sessions"},D=F.kind==="applied"||P===void 0&&!(F.kind==="sending"||F.kind==="uncertain"||F.kind==="rejected"||F.kind==="failed"||F.kind==="changed")&&x,Q=r==null?void 0:r.onBack;f.useEffect(()=>{D&&Q&&Q()},[D,Q]);const q=f.useRef(l);q.current=l,f.useEffect(()=>{if(!D||!q.current)return;const ie=setTimeout(()=>{var Ie;return(Ie=q.current)==null?void 0:Ie.call(q)},xc);return()=>clearTimeout(ie)},[D]);const[K,ee]=f.useState(null),[ue,fe]=f.useState(null);f.useLayoutEffect(()=>{var js,nt;const ie=K,Ie=ue,tt=(js=globalThis.matchMedia)==null?void 0:js.call(globalThis,Kp);if(!ie||!Ie||!tt)return;let Ce=!1;const qe=()=>{if(Ce||!tt.matches)return;const Rt=Ie.firstElementChild??Ie,ys=ie.getBoundingClientRect(),Ns=Rt.getBoundingClientRect(),ql=Ns.top-ys.top+ie.scrollTop,Hl=parseFloat(getComputedStyle(ie).paddingBottom)||0;ie.scrollTop=Ns.height>ie.clientHeight-Hl?ql:Math.max(0,ql+Ns.height-(ie.clientHeight-Hl))},bt=()=>{tt.matches&&(Ce=!1,qe())},wt=()=>{Ce=!0};qe();const Yt=typeof ResizeObserver=="function"?new ResizeObserver(qe):null;Yt==null||Yt.observe(ie),Yt==null||Yt.observe(Ie),(nt=tt.addEventListener)==null||nt.call(tt,"change",bt);for(const Rt of fo)ie.addEventListener(Rt,wt,{passive:!0});return()=>{var Rt;Yt==null||Yt.disconnect(),(Rt=tt.removeEventListener)==null||Rt.call(tt,"change",bt);for(const ys of fo)ie.removeEventListener(ys,wt)}},[N,K,ue]);const he=ie=>r?e.jsx(Wp,{title:ie,panel:r}):e.jsx(Hs,{title:ie,fallback:I,label:u.detail.back,link:H});if(F.kind==="applied")return e.jsx(ia,{store:t,title:Up(F),body:u.result.body,item:W.current,final:!0});const w=F.kind==="sending"||F.kind==="uncertain"||F.kind==="rejected"||F.kind==="failed"||F.kind==="changed",O=P??(w?W.current:void 0);if(!O)return!x&&c.syncedAt===null?e.jsxs(e.Fragment,{children:[he(u.gone.header),e.jsx("main",{className:"min-h-0 flex-1 pt-7 text-body text-muted",role:"status",children:u.loading})]}):e.jsx(Pp,{store:t,stale:!x,item:W.current,...r?{panel:{header:he(u.gone.header),back:{href:ce({name:"atelier",sessionId:n}),label:u.nav.backTo.thread}}}:{}});const V=O.kind==="question",Z=O.options??[],X=m==null?void 0:m[O.tool],J=V&&(X==null?void 0:X.freeTextAnswer)===!0,pe=V&&(X==null?void 0:X.questions)===!0&&O.requestId!==void 0&&((Gt=O.questions)!=null&&Gt.length)?O.questions:void 0,Ne=!pe&&(X==null?void 0:X.decide)===!1&&Z.length>0,Xe=!pe&&!Ne&&V&&(Z.length>0||J),gt=((Xt=c.device)==null?void 0:Xt.confirm)===!0&&_,ze=O.risk!=="low",Je=JSON.stringify((pe??[]).map(ie=>[ie.id,ie.options.map(Ie=>Ie.label)])),oe=A.sig===Je?A.v:[],de=(pe??[]).filter((ie,Ie)=>{var tt;return!((tt=oe[Ie])!=null&&tt.length)}).length,ke=(ie,Ie)=>{const tt=pe==null?void 0:pe[ie];if(!tt)return;const Ce=(pe??[]).map((bt,wt)=>oe[wt]??[]),qe=Ce[ie]??[];Ce[ie]=tt.multi?qe.includes(Ie)?qe.filter(bt=>bt!==Ie):[...qe,Ie]:[Ie],R({sig:Je,v:Ce}),T(!1)},Oe={key:O.key,kind:O.kind,text:O.text},lt=ie=>{if(!pe||O.requestId===void 0)return;const Ie=ie?[]:pe.map((tt,Ce)=>({id:tt.id,selected:oe[Ce]??[]}));T(!t.answer(n,O.requestId,Ie,{expect:Oe,...ie?{cancel:!0}:{}}))},mt=x&&!C&&P!==void 0&&F.kind!=="sending"&&F.kind!=="uncertain"&&(gt||!ze),kt=ie=>{ze?(v(ie),T(!1)):T(!t.reply(n,String(ie+1),{expect:Oe}))},ct=e.jsx("ul",{"aria-label":u.answers.legend,className:"my-3.5 flex list-none flex-col gap-2 p-0",children:Z.map((ie,Ie)=>{var tt;return e.jsx("li",{children:e.jsxs("button",{type:"button",disabled:!mt,"aria-pressed":$===Ie,onClick:()=>kt(Ie),className:"flex min-h-12 w-full flex-col items-start justify-center rounded-control border border-line bg-surface px-3 py-3 text-left text-body [overflow-wrap:anywhere] disabled:opacity-45 active:bg-raised aria-pressed:border-fg/40 aria-pressed:bg-raised",children:[ie,((tt=O.optionDetails)==null?void 0:tt[Ie])&&e.jsx("small",{className:"mt-0.5 text-meta text-muted",children:O.optionDetails[Ie]})]})},`${Ie}:${ie}`)})}),xt=ic(M),G=J&&(Z.length===0||y===Z.length),Ee=V?null:oc(O),we=Mx(O),le=(c.previews.get(n)??[]).slice(-12),ge=F.kind==="sending"||F.kind==="uncertain",Be=()=>{G?xt.problem===null&&T(!t.reply(n,xt.text,{expect:Oe})):y!==null&&y<Z.length&&T(!t.reply(n,String(y+1),{expect:Oe}))},et=ce(r?{name:"atelier",sessionId:n}:{name:"thread",sessionId:n}),vt=o&&!r&&e.jsx(La,{back:e.jsx("span",{className:"w-2.5"}),tool:O.tool,name:O.botName,dot:O.kind==="permission"?"perm":O.kind==="question"?"ask":"work",sub:[O.repo,O.branch].filter(Boolean).join(" · "),more:e.jsxs(e.Fragment,{children:[O.risk==="high"?e.jsx(Lt,{tone:"risk",children:u.risk.badge}):e.jsx(Lt,{tone:O.kind==="question"?"ask":O.kind==="permission"?"perm":"plain",children:u.cards.pill[O.kind]}),e.jsxs("a",{href:et,className:rt({size:"sm",className:"ml-1"}),children:[e.jsx(z,{name:"terminal",className:"size-4"}),u.cards.openThread]})]})});return e.jsxs(e.Fragment,{children:[vt||he(u.detail.heading[O.kind]),e.jsxs("main",{ref:ee,className:"min-h-0 flex-1 overflow-y-auto overscroll-contain pb-[22px]",children:[!vt&&e.jsxs("div",{className:"mt-4 flex items-start gap-3 rounded-card border border-line bg-surface p-3.5",children:[e.jsx(Fa,{tool:O.tool,seed:O.sessionId,state:((U=c.sessions.get(n))==null?void 0:U.state)??"idle",frozen:!x}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("strong",{className:"block text-body [overflow-wrap:anywhere]",children:O.task}),e.jsxs("p",{className:"mt-0.5 text-meta text-muted",children:[O.botName," · ",u.tools[O.tool]]}),e.jsxs("p",{className:"mt-0.5 text-meta [overflow-wrap:anywhere] text-muted",children:[O.repo,O.branch&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("code",{className:`font-mono text-[.9em] ${O.worktree?"underline decoration-dotted underline-offset-2":""}`,children:O.branch})]})]})]})]}),e.jsxs("div",{className:"mt-[22px] mb-3",children:[e.jsx(Lx,{kind:O.kind,risk:O.risk}),e.jsx("h1",{className:`mt-2.5 text-display leading-[1.25] font-semibold tracking-[-1px] [overflow-wrap:anywhere] ${O.kind==="permission"?"phone-side:hidden":""}`,children:O.kind==="permission"?u.detail.commandTitle:Ia(O)})]}),V?e.jsxs(e.Fragment,{children:[pe&&e.jsx(qp,{questions:pe,selected:oe,onToggle:ke,disabled:ge}),Ne&&ct,Xe&&e.jsx(zp,{options:Z,value:y,onChange:ie=>{b(ie),T(!1)},botName:O.botName,disabled:ge,other:J?{text:M,onText:ie=>{S(ie),T(!1)},problem:xt.problem}:void 0,onSubmit:x&&!C&&!ge&&P!==void 0?Be:void 0}),!J&&!Ne&&!pe&&Z.length>0&&e.jsx("p",{className:"mb-3.5 text-small text-muted",children:u.decide.otherUnsupported})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:fe,children:e.jsx(Ox,{text:O.body??O.text})}),Ne&&ct,!Ne&&Z.length>0&&e.jsx("ul",{"aria-label":u.detail.options,className:"my-3.5 flex list-none flex-col gap-2 p-0",children:Z.map(ie=>e.jsx("li",{className:"rounded-control border border-line bg-surface px-3 py-3 text-body [overflow-wrap:anywhere]",children:ie},ie))}),Ee&&e.jsx(De,{title:Ee.title,tone:"danger",children:e.jsx("p",{children:Ee.body})}),we&&e.jsx(De,{title:we.title,children:e.jsx("p",{className:"text-muted",children:we.body})}),e.jsxs("dl",{className:"my-[18px] grid grid-cols-[74px_minmax(0,1fr)] gap-x-3 gap-y-2.5 text-small",children:[O.branch&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-muted",children:u.detail.branch}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:e.jsx("code",{className:"font-mono text-[.9em]",children:O.branch})})]}),(Ee==null?void 0:Ee.destination)&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-muted",children:u.detail.destination}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:e.jsx("code",{className:"font-mono text-[.9em]",children:Ee.destination})})]}),e.jsx("dt",{className:"text-muted",children:u.detail.asked}),e.jsx("dd",{className:"m-0",children:u.detail.ago(fa(O.since,i))})]}),le.length>0&&e.jsxs("details",{className:"group mt-[18px] border-t border-line",children:[e.jsxs("summary",{className:"flex min-h-12 cursor-pointer list-none items-center justify-between text-small [&::-webkit-details-marker]:hidden",children:[u.detail.context,e.jsx(z,{name:"terminal",className:"size-4 text-muted"})]}),e.jsx("pre",{className:"pt-2 pb-4 font-mono text-small leading-[1.7] break-words whitespace-pre-wrap text-muted [overflow-wrap:anywhere]",children:le.join(`
|
|
8
|
-
`)})]})]}),!
|
|
7
|
+
`);a.set(l.id,{key:`packet-${r.id}`,kind:"rig-raw",at:l.at,raw:{label:yt.rawMany(r.count),text:o}})}return{inPacket:s,after:a}}function Mp(t){const n=[];let s=[];const a=()=>{s.length===1?n.push(s[0]):s.length>1&&n.push({key:`fold-${s[0].key}`,kind:"rig-fold",at:s[0].at,notices:s}),s=[]};for(const r of t){if(r.kind==="rig-notice"&&r.tone==="plain"){s.push(r);continue}a(),n.push(r)}return a(),n}const po={pending:"pending","in-progress":"taken","handed-off":"passed",blocked:"blocked",done:"done"};function Ep(t,n){if(!t)return{key:"unknown",text:yt.rowState.unknown};const s=po[t.state]??"unknown",a=po[t.state]?s==="passed"?yt.rowState.passed(oa(t.handedOffTo,void 0,new Map).name):yt.rowState[s]:t.state,r=[n?yt.log.passed(Tn(t.createdAt)):yt.log.handed(Tn(t.createdAt)),t.claimedAt?yt.log.taken(Tn(t.claimedAt)):s==="pending"?yt.log.notTaken:null,s==="done"?yt.log.done(Tn(t.updatedAt)):null].filter(Boolean).join(" · ");return{key:s,text:a,log:r}}const _p=t=>[...new Set(t.map(n=>n.name))],Rp=(t,n)=>t.length===n.length&&t.every((s,a)=>s===n[a]),Ic=(t,n)=>Object.values(n).filter(s=>s.message.type==="session.reply"&&s.message.expect===null&&s.message.id===t).sort((s,a)=>s.at.localeCompare(a.at));function Tp(t,n,s){return Object.values(s).some(a=>a.phase==="applied"&&a.message.type==="session.decide"&&a.message.id===n&&a.message.expect.text===t.text&&a.message.decision===t.decision)}function Lc(t,n,s,a){var l,o;const r=u.thread.event;return((l=t.by)==null?void 0:l.kind)==="device"?t.by.id===a?r.fromHere:r.fromDevice(t.by.name):((o=t.by)==null?void 0:o.kind)==="pc"?r.fromPc:Tp(t,n,s)?r.fromHere:r.fromPc}function Ap(t,n,s,a){const r=u.thread.event;if(!t.decision)return null;if(t.decision==="unknown")return r.resolved;const l=Lc(t,n,s,a);return t.decision==="deny"?r.deny(l):r.accept(l)}const Ar=2e4,Ip=(t,n,s)=>{const a=t.trim(),r=n.trim();return a===r||s&&a.length>0&&r.startsWith(a)};function Lp(t,n,s,a=Date.now(),r=[],l=new Map,o=null){var j,y,b,M,S,$;let c=[];const i=new Set(r),m=v=>i.has(v)?{cut:!0}:{},d=Ic(n.id,s),x=new Set,p=new Set;for(const v of d){if(v.phase!=="applied")continue;const A=v.message.attachments??[],R=t.find(_=>{var L;return _.kind==="prompt"&&Ip(_.text,v.message.text,i.has(_.id))&&!x.has(_.id)&&Rp(((L=_.images)==null?void 0:L.map(T=>T.id))??[],A)});R&&(x.add(R.id),p.add(v.op))}const g=$p(t);let h=null,N=null;for(const v of t){const A=Sp(v,l,i.has(v.id));if(A){const L=v.kind==="received"||v.kind==="sent"||v.kind==="notice"?((y=(j=v.rig)==null?void 0:j.packet)==null?void 0:y.id)??null:null,T=Tn(A.at);if(!(L&&L===N)&&T!==h&&c.push({key:`time-${v.id}`,kind:"time",label:T}),h=T,N=L,g.inPacket.has(v.id)){const{raw:B,...E}=A;c.push(E);const P=g.after.get(v.id);P&&c.push(P)}else c.push(A);continue}if(v.kind==="tool"&&!((b=v.images)!=null&&b.length)){const L={id:v.id,name:Ul(v.tool),label:v.label,status:v.status},T=c.at(-1);(T==null?void 0:T.kind)==="tools"?T.tools.push(L):c.push({key:`tools-${v.id}`,kind:"tools",at:v.at,tools:[L]}),h=null,N=null;continue}const R=c.length,_=v.kind==="prompt"?Np(v.text):null;if(_)c.push({key:v.id,kind:"task",task:_,at:v.at,...m(v.id)});else if(v.kind==="prompt")c.push({key:v.id,kind:"me",text:v.text,at:v.at,...(M=v.images)!=null&&M.length?{images:v.images}:{},...x.has(v.id)?{delivery:"taken"}:{},...m(v.id)});else if(v.kind==="reply")c.push({key:v.id,kind:"agent",text:v.text,at:v.at,...m(v.id)});else if(v.kind==="tool"&&((S=v.images)!=null&&S.length))c.push({key:v.id,kind:"capture",label:nx(v.tool)?u.thread.capture:Ul(v.tool),at:v.at,images:v.images});else if(v.kind==="notice"&&v.adopted)c.push({key:v.id,kind:"event",label:`${v.adopted==="pane"?u.adopt.markPane:u.adopt.markResume} · ${Tn(v.at)}`,at:v.at});else if(v.kind==="permission"){const L=Ap(v,n.id,s,o);L&&c.push({key:v.id,kind:"event",label:L,at:v.at})}c.length>R&&(h=null,N=null)}c=Mp(c);const k=Math.max(...t.map(v=>Date.parse(v.at)));for(const v of d){const A=Date.parse(v.at),R={key:v.op,kind:"me",text:v.message.text,at:v.at,...($=v.message.attachments)!=null&&$.length?{attachments:v.message.attachments}:{}};if(v.phase==="sending")c.push({...R,delivery:"sending"});else if(v.phase==="uncertain")c.push({...R,delivery:"uncertain"});else if(v.phase==="applied"&&!p.has(v.op)&&!(k-A>Ar)){const _=c.findIndex(T=>T.kind!=="awaiting"&&T.kind!=="time"&&!(T.kind==="me"&&T.delivery&&T.delivery!=="taken")&&Date.parse(T.at)>A),L=_<0?c.length:_>0&&c[_-1].kind==="time"?_-1:_;c.splice(L,0,{...R,delivery:"taken",...a-A<Ar?{fresh:!0}:{}})}}n.exitedAt&&Dx(n,s)&&c.push({key:`closed-${n.exitedAt}`,kind:"event",label:u.sessionEnd.closedHere(Fx(n.exitedAt)),at:n.exitedAt});const C=kn([n])[0];return C&&c.push({key:`awaiting-${C.key}`,kind:"awaiting",item:C}),c}const qt=u.thread.composer;function Op(t,n,s){const a=(r,l,o)=>({enabled:!1,placeholder:r,status:{tone:l,label:o}});if(n==="handshaking")return a(qt.placeholder.connecting,"muted",qt.status.connecting);if(n!=="ready")return a(qt.placeholder.offline,"muted",qt.status.offline);if(t.state==="exited"||t.state==="error")return a(qt.placeholder.ended,"muted",qt.status.ended);if(t.pending||t.state==="waiting_permission"||t.state==="waiting_input"){const r=t.pending?t.pending.kind==="question":t.state==="waiting_input";return a(qt.placeholder.awaiting,r?"attention":"approval",qt.status.awaiting)}return t.state!=="idle"?a(qt.placeholder.working,"info",qt.status.working):s?a(qt.placeholder.idle(t.name),"info",qt.status.sending):{enabled:!0,placeholder:qt.placeholder.idle(t.name),status:{tone:"ok",label:qt.status.idle}}}const Dp=["Montre le diff","Lance les tests","Explique les changements"],Ke=t=>t?new Date(t).toLocaleTimeString(ut,{hour:"2-digit",minute:"2-digit"}):"";function ia({store:t,title:n,body:s,item:a,final:r=!1,children:l}){const o=fs(xe(t)),c=ce({name:"sessions"}),i={name:"sessions"};return e.jsxs(e.Fragment,{children:[e.jsx(Hs,{title:u.result.header,fallback:i,label:u.detail.back,link:o}),e.jsx("main",{className:"min-h-0 flex-1 overflow-y-auto pb-[22px]",children:e.jsxs("div",{className:"flex flex-col items-start gap-4 pt-7",children:[e.jsx("div",{className:"grid size-14 place-items-center rounded-full border border-ok/20 bg-ok/10 text-ok",children:e.jsx(z,{name:"check",className:"size-[26px]"})}),a&&e.jsxs("span",{className:"flex items-center gap-2 text-meta font-medium tracking-[0.4px] text-muted",children:[e.jsx(Fa,{tool:a.tool,seed:a.sessionId,state:"idle"}),e.jsxs("span",{className:"[overflow-wrap:anywhere]",children:[a.botName," · ",a.task]})]}),e.jsx("h1",{className:"text-display leading-[1.25] font-semibold tracking-[-1px] [overflow-wrap:anywhere]",children:n}),e.jsx("p",{className:"text-body text-muted",children:s}),a&&e.jsx("div",{className:"w-full",children:e.jsx(De,{title:Ia(a),children:e.jsxs("p",{className:"text-muted [overflow-wrap:anywhere]",children:[a.repo,a.branch&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("code",{className:"font-mono text-[.9em]",children:a.branch})]})]})})}),r&&e.jsx("p",{className:"text-body text-muted",children:u.result.final}),l,e.jsx("a",{href:c,className:We({variant:"primary",block:!0}),children:u.result.back}),a&&e.jsx("a",{href:ce({name:"thread",sessionId:a.sessionId}),className:We({block:!0}),children:u.result.thread(a.botName)})]})})]})}const Fp=We({variant:"primary",block:!0});function Pp({store:t,stale:n=!1,item:s,panel:a}){var h,N,k,C;const r=xe(t),l=fs(r),o=s==null?void 0:s.sessionId,c=o!==void 0&&r.threads.has(o),i=s?(h=r.sessions.get(s.sessionId))==null?void 0:h.lastAnswer:void 0,m=!!s&&!!i&&i.key===s.key;f.useEffect(()=>{!n&&!m&&o!==void 0&&!c&&t.openThread(o)},[n,m,o,c,t]);const d=ce({name:"sessions"}),x={name:"sessions"};if(n)return e.jsxs(e.Fragment,{children:[a?a.header:e.jsx(Hs,{title:u.gone.header,fallback:x,label:u.detail.back,link:l}),e.jsxs("main",{className:"min-h-0 flex-1 overflow-y-auto pt-7",children:[e.jsx("h1",{className:"text-display leading-[1.25] font-semibold tracking-[-1px]",children:u.gone.staleTitle}),e.jsx("p",{className:"mt-2.5 text-body text-muted",children:u.gone.staleBody}),e.jsx("a",{href:(a==null?void 0:a.back.href)??d,className:`mt-6 ${Fp}`,children:(a==null?void 0:a.back.label)??u.gone.back})]})]});if(s&&i&&m){const j=i.by.kind==="pc"?u.thread.event.fromPc:i.by.id===((N=r.device)==null?void 0:N.id)?u.thread.event.fromHere:u.thread.event.fromDevice(i.by.name);return e.jsx(ia,{store:t,title:u.gone.titleOn(j),body:i.decision?u.gone.decided(i.decision,Ke(i.at)):u.gone.answered(Ke(i.at)),item:s})}const p=s&&s.kind==="permission"?[...((k=r.threads.get(s.sessionId))==null?void 0:k.items)??[]].reverse().find(j=>j.kind==="permission"&&j.text===s.text&&j.decision!==void 0&&j.decision!=="unknown"):void 0;if(!p||p.decision===void 0||p.decision==="unknown")return e.jsx(ia,{store:t,title:u.gone.titleElsewhere,body:u.gone.body,item:s});const g=Lc(p,s.sessionId,r.ops,((C=r.device)==null?void 0:C.id)??null);return e.jsx(ia,{store:t,title:u.gone.titleOn(g),body:u.gone.decided(p.decision,Ke(p.at)),item:s})}function zp({options:t,value:n,onChange:s,disabled:a=!1,botName:r,other:l,onSubmit:o}){const c=t.length,i=t.length===0,m=l!==void 0&&(i||n===c),d=m&&l.problem!==null&&l.problem!=="empty",x="flex min-h-12 cursor-pointer items-center gap-3 rounded-control border border-line bg-surface px-3 py-3 text-body has-[:checked]:border-fg/40 has-[:checked]:bg-raised has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-info";return e.jsxs("fieldset",{disabled:a,className:"my-3.5 flex min-w-0 flex-col gap-2 border-0 p-0",children:[e.jsx("legend",{className:"sr-only",children:u.question.legend}),t.map((p,g)=>e.jsxs("label",{className:x,children:[e.jsx("input",{type:"radio",name:"answer",value:g,checked:n===g,onChange:()=>s(g),className:"size-4 flex-none accent-fg"}),e.jsx("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:p})]},g)),l&&e.jsxs(e.Fragment,{children:[!i&&e.jsxs("label",{className:x,children:[e.jsx("input",{type:"radio",name:"answer",value:c,checked:m,onChange:()=>s(c),className:"size-4 flex-none accent-fg"}),e.jsx("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:u.question.other})]}),m&&e.jsxs("div",{children:[e.jsx("label",{htmlFor:"other-answer",className:"mt-3 mb-2 block text-small text-muted",children:u.question.fieldLabel(r)}),e.jsx("textarea",{id:"other-answer",rows:2,value:l.text,onChange:p=>l.onText(p.target.value),placeholder:u.question.placeholder,"aria-invalid":d,"aria-describedby":d?"other-problem":void 0,autoComplete:"off",enterKeyHint:"send",onKeyDown:p=>{p.key==="Enter"&&!p.nativeEvent.isComposing&&(p.preventDefault(),o==null||o())},className:"max-h-[120px] min-h-12 w-full min-w-0 resize-y rounded-control border border-line bg-surface p-3 text-base leading-[22px] text-fg placeholder:text-muted focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-info"}),d&&e.jsx("p",{id:"other-problem",role:"alert",className:"mt-2 text-small text-danger-fg",children:l.problem==="long"?u.question.long(il):l.problem==="digit"?u.question.digit:u.question.untypable})]})]})]})}const Bp="flex min-h-12 cursor-pointer items-center gap-3 rounded-control border border-line bg-surface px-3 py-3 text-body has-[:checked]:border-fg/40 has-[:checked]:bg-raised has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-info";function qp({questions:t,selected:n,onToggle:s,disabled:a=!1}){return e.jsx("div",{className:"my-3.5 flex flex-col gap-5",children:t.map((r,l)=>e.jsxs("fieldset",{disabled:a,className:"flex min-w-0 flex-col gap-2 border-0 p-0",children:[e.jsx("legend",{className:"mb-2 text-base leading-[1.4] font-semibold [overflow-wrap:anywhere]",children:r.header??r.question}),r.header&&e.jsx("p",{className:"mb-1 text-small text-muted [overflow-wrap:anywhere]",children:r.question}),r.options.map(o=>{var c;return e.jsxs("label",{className:Bp,children:[e.jsx("input",{type:r.multi?"checkbox":"radio",name:`question-${l}`,checked:((c=n[l])==null?void 0:c.includes(o.label))===!0,onChange:()=>s(l,o.label),className:"size-4 flex-none accent-fg"}),e.jsxs("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:[o.label,o.description&&e.jsx("small",{className:"mt-0.5 block text-meta text-muted",children:o.description})]})]},o.label)})]},r.id))})}function Hp({onReconnect:t}){const[n,s]=ps();return e.jsxs(De,{title:u.link.lostTitle,tone:"warning",role:"status",children:[e.jsx("p",{children:u.link.lostDetail}),t&&e.jsx("button",{type:"button",disabled:n,onClick:()=>{s(!0),t()},className:We({block:!0,className:"mt-3"}),children:n?u.link.reconnecting:u.link.reconnect})]})}const Up=t=>t.decision==="deny"?u.result.denied:t.answer!==void 0?u.result.answered:u.result.allowed;function Wp({title:t,panel:n}){return e.jsx("header",{className:"flex-none border-b border-line pt-2 pb-3",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("button",{type:"button",onClick:n.onBack,className:"-ml-1 flex min-h-11 items-center gap-1 pr-2 text-body text-muted active:text-fg",children:[e.jsx(z,{name:"back"}),u.nav.backTo.thread]}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),e.jsx("button",{type:"button",onClick:n.onClose,"aria-label":u.atelier.closePanel,title:u.atelier.closeTitle,className:Ot({}),children:e.jsx(z,{name:"close"})})]})})}const Kp="(orientation: landscape) and (max-height: 500px)",fo=["wheel","touchstart","keydown","pointerdown"];function Ir({store:t,sessionId:n,requestKey:s,onReconnect:a,panel:r,onSettled:l,keys:o=!1}){var Vt,tn,Gt,Xt,U,Se;const c=xe(t),i=Kt(),{fresh:m,ops:d,capabilities:x}=c,p=kc(),{look:g}=zt(),h=p!==void 0&&g==="offline",[N,k]=f.useState(s),[C,j]=f.useState(!1),[y,b]=f.useState(null),[M,S]=f.useState(""),[$,v]=f.useState(null),[A,R]=f.useState({sig:"",v:[]}),_=mn(),[L,T]=f.useState(!1),B=f.useRef(N);B.current=N,f.useEffect(()=>{s!==B.current&&(k(s),j(!1),b(null),S(""),v(null),T(!1))},[s]);const E=[...c.sessions.values()],P=kn(E).find(ie=>ie.sessionId===n&&ie.key===N),W=f.useRef(void 0);P&&(W.current=P);const F=pc({sessionId:n,key:N},E,d),re=(P==null?void 0:P.cut)===!0;f.useEffect(()=>{re&&m&&t.loadPending(n)},[t,n,N,re,m]);const Y=(tn=(Vt=c.sessions.get(n))==null?void 0:Vt.pending)==null?void 0:tn.key;f.useEffect(()=>{var ie;if(!(F.kind!=="changed"||!Y)){k(Y),j(!0),b(null),S(""),v(null);try{(ie=globalThis.history)==null||ie.replaceState(globalThis.history.state,"",ce(r?{name:"atelier",sessionId:n,requestKey:Y}:{name:"request",sessionId:n,key:Y}))}catch{}}},[F.kind,Y,n]);const H=fs(c),I={name:"sessions"},D=F.kind==="applied"||P===void 0&&!(F.kind==="sending"||F.kind==="uncertain"||F.kind==="rejected"||F.kind==="failed"||F.kind==="changed")&&m,Q=r==null?void 0:r.onBack;f.useEffect(()=>{D&&Q&&Q()},[D,Q]);const q=f.useRef(l);q.current=l,f.useEffect(()=>{if(!D||!q.current)return;const ie=setTimeout(()=>{var Ie;return(Ie=q.current)==null?void 0:Ie.call(q)},mc);return()=>clearTimeout(ie)},[D]);const[K,ee]=f.useState(null),[ue,fe]=f.useState(null);f.useLayoutEffect(()=>{var ys,nt;const ie=K,Ie=ue,tt=(ys=globalThis.matchMedia)==null?void 0:ys.call(globalThis,Kp);if(!ie||!Ie||!tt)return;let Ce=!1;const He=()=>{if(Ce||!tt.matches)return;const Rt=Ie.firstElementChild??Ie,Ns=ie.getBoundingClientRect(),ks=Rt.getBoundingClientRect(),ql=ks.top-Ns.top+ie.scrollTop,Hl=parseFloat(getComputedStyle(ie).paddingBottom)||0;ie.scrollTop=ks.height>ie.clientHeight-Hl?ql:Math.max(0,ql+ks.height-(ie.clientHeight-Hl))},bt=()=>{tt.matches&&(Ce=!1,He())},wt=()=>{Ce=!0};He();const Yt=typeof ResizeObserver=="function"?new ResizeObserver(He):null;Yt==null||Yt.observe(ie),Yt==null||Yt.observe(Ie),(nt=tt.addEventListener)==null||nt.call(tt,"change",bt);for(const Rt of fo)ie.addEventListener(Rt,wt,{passive:!0});return()=>{var Rt;Yt==null||Yt.disconnect(),(Rt=tt.removeEventListener)==null||Rt.call(tt,"change",bt);for(const Ns of fo)ie.removeEventListener(Ns,wt)}},[N,K,ue]);const he=ie=>r?e.jsx(Wp,{title:ie,panel:r}):e.jsx(Hs,{title:ie,fallback:I,label:u.detail.back,link:H});if(F.kind==="applied")return e.jsx(ia,{store:t,title:Up(F),body:u.result.body,item:W.current,final:!0});const w=F.kind==="sending"||F.kind==="uncertain"||F.kind==="rejected"||F.kind==="failed"||F.kind==="changed",O=P??(w?W.current:void 0);if(!O)return!m&&c.syncedAt===null?e.jsxs(e.Fragment,{children:[he(u.gone.header),e.jsx("main",{className:"min-h-0 flex-1 pt-7 text-body text-muted",role:"status",children:u.loading})]}):e.jsx(Pp,{store:t,stale:!m,item:W.current,...r?{panel:{header:he(u.gone.header),back:{href:ce({name:"atelier",sessionId:n}),label:u.nav.backTo.thread}}}:{}});const V=O.kind==="question",Z=O.options??[],X=x==null?void 0:x[O.tool],J=V&&(X==null?void 0:X.freeTextAnswer)===!0,pe=V&&(X==null?void 0:X.questions)===!0&&O.requestId!==void 0&&((Gt=O.questions)!=null&&Gt.length)?O.questions:void 0,Ne=!pe&&(X==null?void 0:X.decide)===!1&&Z.length>0,Xe=!pe&&!Ne&&V&&(Z.length>0||J),gt=((Xt=c.device)==null?void 0:Xt.confirm)===!0&&_,Be=O.risk!=="low",Je=JSON.stringify((pe??[]).map(ie=>[ie.id,ie.options.map(Ie=>Ie.label)])),oe=A.sig===Je?A.v:[],de=(pe??[]).filter((ie,Ie)=>{var tt;return!((tt=oe[Ie])!=null&&tt.length)}).length,ke=(ie,Ie)=>{const tt=pe==null?void 0:pe[ie];if(!tt)return;const Ce=(pe??[]).map((bt,wt)=>oe[wt]??[]),He=Ce[ie]??[];Ce[ie]=tt.multi?He.includes(Ie)?He.filter(bt=>bt!==Ie):[...He,Ie]:[Ie],R({sig:Je,v:Ce}),T(!1)},Oe={key:O.key,kind:O.kind,text:O.text},lt=ie=>{if(!pe||O.requestId===void 0)return;const Ie=ie?[]:pe.map((tt,Ce)=>({id:tt.id,selected:oe[Ce]??[]}));T(!t.answer(n,O.requestId,Ie,{expect:Oe,...ie?{cancel:!0}:{}}))},xt=m&&!C&&P!==void 0&&F.kind!=="sending"&&F.kind!=="uncertain"&&(gt||!Be),kt=ie=>{Be?(v(ie),T(!1)):T(!t.reply(n,String(ie+1),{expect:Oe}))},ct=e.jsx("ul",{"aria-label":u.answers.legend,className:"my-3.5 flex list-none flex-col gap-2 p-0",children:Z.map((ie,Ie)=>{var tt;return e.jsx("li",{children:e.jsxs("button",{type:"button",disabled:!xt,"aria-pressed":$===Ie,onClick:()=>kt(Ie),className:"flex min-h-12 w-full flex-col items-start justify-center rounded-control border border-line bg-surface px-3 py-3 text-left text-body [overflow-wrap:anywhere] disabled:opacity-45 active:bg-raised aria-pressed:border-fg/40 aria-pressed:bg-raised",children:[ie,((tt=O.optionDetails)==null?void 0:tt[Ie])&&e.jsx("small",{className:"mt-0.5 text-meta text-muted",children:O.optionDetails[Ie]})]})},`${Ie}:${ie}`)})}),mt=ic(M),G=J&&(Z.length===0||y===Z.length),_e=V?null:oc(O),we=Mm(O),le=(c.previews.get(n)??[]).slice(-12),ge=F.kind==="sending"||F.kind==="uncertain",qe=()=>{G?mt.problem===null&&T(!t.reply(n,mt.text,{expect:Oe})):y!==null&&y<Z.length&&T(!t.reply(n,String(y+1),{expect:Oe}))},et=ce(r?{name:"atelier",sessionId:n}:{name:"thread",sessionId:n}),vt=o&&!r&&e.jsx(La,{back:e.jsx("span",{className:"w-2.5"}),tool:O.tool,name:O.botName,dot:O.kind==="permission"?"perm":O.kind==="question"?"ask":"work",sub:[O.repo,O.branch].filter(Boolean).join(" · "),more:e.jsxs(e.Fragment,{children:[O.risk==="high"?e.jsx(Lt,{tone:"risk",children:u.risk.badge}):e.jsx(Lt,{tone:O.kind==="question"?"ask":O.kind==="permission"?"perm":"plain",children:u.cards.pill[O.kind]}),e.jsxs("a",{href:et,className:rt({size:"sm",className:"ml-1"}),children:[e.jsx(z,{name:"terminal",className:"size-4"}),u.cards.openThread]})]})});return e.jsxs(e.Fragment,{children:[vt||he(u.detail.heading[O.kind]),e.jsxs("main",{ref:ee,className:"min-h-0 flex-1 overflow-y-auto overscroll-contain pb-[22px]",children:[!vt&&e.jsxs("div",{className:"mt-4 flex items-start gap-3 rounded-card border border-line bg-surface p-3.5",children:[e.jsx(Fa,{tool:O.tool,seed:O.sessionId,state:((U=c.sessions.get(n))==null?void 0:U.state)??"idle",frozen:!m}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("strong",{className:"block text-body [overflow-wrap:anywhere]",children:O.task}),e.jsxs("p",{className:"mt-0.5 text-meta text-muted",children:[O.botName," · ",u.tools[O.tool]]}),e.jsxs("p",{className:"mt-0.5 text-meta [overflow-wrap:anywhere] text-muted",children:[O.repo,O.branch&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("code",{className:`font-mono text-[.9em] ${O.worktree?"underline decoration-dotted underline-offset-2":""}`,children:O.branch})]})]})]})]}),e.jsxs("div",{className:"mt-[22px] mb-3",children:[e.jsx(Lm,{kind:O.kind,risk:O.risk}),e.jsx("h1",{className:`mt-2.5 text-display leading-[1.25] font-semibold tracking-[-1px] [overflow-wrap:anywhere] ${O.kind==="permission"?"phone-side:hidden":""}`,children:O.kind==="permission"?u.detail.commandTitle:Ia(O)})]}),V?e.jsxs(e.Fragment,{children:[pe&&e.jsx(qp,{questions:pe,selected:oe,onToggle:ke,disabled:ge}),Ne&&ct,Xe&&e.jsx(zp,{options:Z,value:y,onChange:ie=>{b(ie),T(!1)},botName:O.botName,disabled:ge,other:J?{text:M,onText:ie=>{S(ie),T(!1)},problem:mt.problem}:void 0,onSubmit:m&&!C&&!ge&&P!==void 0?qe:void 0}),!J&&!Ne&&!pe&&Z.length>0&&e.jsx("p",{className:"mb-3.5 text-small text-muted",children:u.decide.otherUnsupported})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:fe,children:e.jsx(Om,{text:O.body??O.text})}),Ne&&ct,!Ne&&Z.length>0&&e.jsx("ul",{"aria-label":u.detail.options,className:"my-3.5 flex list-none flex-col gap-2 p-0",children:Z.map(ie=>e.jsx("li",{className:"rounded-control border border-line bg-surface px-3 py-3 text-body [overflow-wrap:anywhere]",children:ie},ie))}),_e&&e.jsx(De,{title:_e.title,tone:"danger",children:e.jsx("p",{children:_e.body})}),we&&e.jsx(De,{title:we.title,children:e.jsx("p",{className:"text-muted",children:we.body})}),e.jsxs("dl",{className:"my-[18px] grid grid-cols-[74px_minmax(0,1fr)] gap-x-3 gap-y-2.5 text-small",children:[O.branch&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-muted",children:u.detail.branch}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:e.jsx("code",{className:"font-mono text-[.9em]",children:O.branch})})]}),(_e==null?void 0:_e.destination)&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-muted",children:u.detail.destination}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:e.jsx("code",{className:"font-mono text-[.9em]",children:_e.destination})})]}),e.jsx("dt",{className:"text-muted",children:u.detail.asked}),e.jsx("dd",{className:"m-0",children:u.detail.ago(fa(O.since,i))})]}),le.length>0&&e.jsxs("details",{className:"group mt-[18px] border-t border-line",children:[e.jsxs("summary",{className:"flex min-h-12 cursor-pointer list-none items-center justify-between text-small [&::-webkit-details-marker]:hidden",children:[u.detail.context,e.jsx(z,{name:"terminal",className:"size-4 text-muted"})]}),e.jsx("pre",{className:"pt-2 pb-4 font-mono text-small leading-[1.7] break-words whitespace-pre-wrap text-muted [overflow-wrap:anywhere]",children:le.join(`
|
|
8
|
+
`)})]})]}),!m&&!h&&F.kind!=="uncertain"&&e.jsx("div",{className:"mt-4",children:e.jsx(Hp,{onReconnect:a})})]}),e.jsx(yp,{item:O,outcome:F,fresh:m,changed:C,stillPending:P!==void 0,threadHref:et,withThread:!vt,onReread:()=>{j(!1),b(null),v(null),T(!1)},onDecide:ie=>T(!t.decide(n,ie,{expect:Oe})),answerable:Xe,choice:G?Z.length:y,onAnswer:qe,answerBlocked:G?mt.problem!==null:y===null||y>=Z.length,onCheck:a,refused:L,store:t,deviceConfirm:((Se=c.device)==null?void 0:Se.confirm)===!0,optionReply:Ne?{canConfirm:Be?gt:!0,picked:Be?$:null,onBack:()=>v(null),onReply:(ie,Ie)=>$===null?null:t.reply(n,String($+1),{assertion:ie,expect:Ie})}:void 0,multi:pe?{missing:de,onSend:()=>lt(!1),onCancel:()=>lt(!0)}:void 0,keys:o})]})}const Vp=/^#{1,6}\s+(.+?)\s*#*\s*$/,Gp=/^(?:\*\*|__)([^*_].*?)(?:\*\*|__)\s*:?\s*$/,Xp=/^(\s*)(?:[-*+]|\d+[.)])\s+(.*)$/,Yp=/^\s*\d+[.)]\s/,Qp=/^\[([ xX])\]\s+/,Zp=/^\s*([-*_])(\s*\1){2,}\s*$/,Jp=/^\s*(```|~~~)/,ef=/^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/,Lr=new RegExp("(?<!\\\\)\\|"),ir=/^\s*>\s?(.*)$/,tf=t=>t.startsWith(":")&&t.endsWith(":")?"center":t.endsWith(":")?"right":"left",Qs=t=>t.trim().replace(/^\|/,"").replace(new RegExp("(?<!\\\\)\\|$"),"").split(Lr).map(n=>n.trim().replace(/\\\|/g,"|")),nf=80,sf=t=>t.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g,""),af=[["questions",/\b(questions?|open|ouvert(e|es)?|decisions?|decider|decide|choix|choices?|a trancher|to settle|besoin de vous|need(s)? you)\b/],["next",/\b(next|suite|reste|left|remaining|todo|to do|a faire|follow[- ]?ups?|prochaines?|later|ensuite|pending)\b/],["verified",/\b(verif\w*|tests?|tested|checks?|checked|validations?|valide|results?|resultats?)\b/],["done",/\b(done|faits?|realise|termine|completed?|changes?|changements?|modifications?|what i did|ce que j'?ai fait|implemented|implemente|delivered|livre)\b/]];function rf(t){var s;const n=sf(t).replace(/[’']/g,"'");return((s=af.find(([,a])=>a.test(n)))==null?void 0:s[0])??"other"}function Oc(t){const n=t.replace(/\r\n?/g,`
|
|
9
9
|
`).split(`
|
|
10
|
-
`),s=[];let a=[],r=null;const l=()=>{a.length&&(s.push({type:"p",text:a.join(" ").trim()}),a=[])},o=()=>{r&&(s.push({type:"list",ordered:r.ordered,items:r.items}),r=null)};for(let c=0;c<n.length;c++){const i=n[c],
|
|
11
|
-
`).replace(/\s+$/,"")});continue}const d=n[c+1];if(Lr.test(i)&&d!==void 0&&ef.test(d)){const h=Qs(i);if(Qs(d).length===h.length){l(),o();const N=[];for(c+=2;c<n.length&&n[c].trim()!==""&&Lr.test(n[c]);c++)N.push(Array.from({length:h.length},(k,C)=>Qs(n[c])[C]??""));c--,s.push({type:"table",header:h,rows:N,align:Qs(d).map(tf)});continue}}const
|
|
12
|
-
`)).map(N=>N.type==="h"?{type:"p",text:N.text}:N)});continue}if(i.trim()===""){l();continue}if(Zp.test(i)){l(),o();continue}const p=i.match(Vp)??i.match(Gp);if(p){l(),o(),s.push({type:"h",text:p[1].trim().replace(/\s*:\s*$/,"")});continue}const g=i.match(Xp);if(g){l();const h=g[1].length,N=g[2];if(r&&h>r.indent&&r.items.length){r.items[r.items.length-1].sub.push(N.trim());continue}const k=Yp.test(i);(!r||h<r.indent||r.ordered!==k)&&(o(),r={ordered:k,items:[],indent:h});const C=N.match(Qp);r.items.push({text:(C?N.slice(C[0].length):N).trim(),sub:[],...C?{checked:C[1]!==" "}:{}});continue}if(r&&/^\s+\S/.test(i)&&a.length===0){const h=r.items[r.items.length-1];h.text=`${h.text} ${i.trim()}`;continue}o(),a.push(i.trim())}return l(),o(),s}const ja=t=>/[??]\s*$/.test(t);function Or(t){const n=t.replace(/\s*[??]\s*$/,"").match(/(?:^|[:;]\s*)([^:;?]*?)\s+(?:or|ou)\s+([^,:;?]{2,60})$/i);if(!n)return[];const s=[...n[1].split(/\s*,\s*/),n[2]].map(l=>l.trim()).filter(Boolean),a=l=>{var o,c,i;return(((o=l.match(/\(/g))==null?void 0:o.length)??0)===(((c=l.match(/\)/g))==null?void 0:c.length)??0)&&(((i=l.match(/`/g))==null?void 0:i.length)??0)%2===0},r=l=>l.length>=2&&l.length<=60&&l.split(/\s+/).length<=8&&!/[.!]\s/.test(l)&&a(l);return s.length>=2&&s.length<=6&&s.every(r)?s:[]}const ho=t=>t.replace(/\[([^\]]+)\]\([^)]*\)/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/(\*\*|__)(.+?)\1/g,"$2").replace(new RegExp("(?<![\\w*])\\*([^*\\n]+)\\*(?![\\w*])","g"),"$1").trim(),
|
|
13
|
-
`).length>3,Ct=()=>e.jsx("svg",{className:"size-4 flex-none motion-safe:animate-spin",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})});function gf(t){var
|
|
10
|
+
`),s=[];let a=[],r=null;const l=()=>{a.length&&(s.push({type:"p",text:a.join(" ").trim()}),a=[])},o=()=>{r&&(s.push({type:"list",ordered:r.ordered,items:r.items}),r=null)};for(let c=0;c<n.length;c++){const i=n[c],m=i.match(Jp);if(m){l(),o();const h=[];for(c++;c<n.length&&!n[c].trim().startsWith(m[1]);c++)h.push(n[c]);s.push({type:"code",text:h.join(`
|
|
11
|
+
`).replace(/\s+$/,"")});continue}const d=n[c+1];if(Lr.test(i)&&d!==void 0&&ef.test(d)){const h=Qs(i);if(Qs(d).length===h.length){l(),o();const N=[];for(c+=2;c<n.length&&n[c].trim()!==""&&Lr.test(n[c]);c++)N.push(Array.from({length:h.length},(k,C)=>Qs(n[c])[C]??""));c--,s.push({type:"table",header:h,rows:N,align:Qs(d).map(tf)});continue}}const x=i.match(ir);if(x){l(),o();const h=[x[1]];for(;c+1<n.length&&ir.test(n[c+1]);c++)h.push(n[c+1].match(ir)[1]);s.push({type:"quote",blocks:Oc(h.join(`
|
|
12
|
+
`)).map(N=>N.type==="h"?{type:"p",text:N.text}:N)});continue}if(i.trim()===""){l();continue}if(Zp.test(i)){l(),o();continue}const p=i.match(Vp)??i.match(Gp);if(p){l(),o(),s.push({type:"h",text:p[1].trim().replace(/\s*:\s*$/,"")});continue}const g=i.match(Xp);if(g){l();const h=g[1].length,N=g[2];if(r&&h>r.indent&&r.items.length){r.items[r.items.length-1].sub.push(N.trim());continue}const k=Yp.test(i);(!r||h<r.indent||r.ordered!==k)&&(o(),r={ordered:k,items:[],indent:h});const C=N.match(Qp);r.items.push({text:(C?N.slice(C[0].length):N).trim(),sub:[],...C?{checked:C[1]!==" "}:{}});continue}if(r&&/^\s+\S/.test(i)&&a.length===0){const h=r.items[r.items.length-1];h.text=`${h.text} ${i.trim()}`;continue}o(),a.push(i.trim())}return l(),o(),s}const ja=t=>/[??]\s*$/.test(t);function Or(t){const n=t.replace(/\s*[??]\s*$/,"").match(/(?:^|[:;]\s*)([^:;?]*?)\s+(?:or|ou)\s+([^,:;?]{2,60})$/i);if(!n)return[];const s=[...n[1].split(/\s*,\s*/),n[2]].map(l=>l.trim()).filter(Boolean),a=l=>{var o,c,i;return(((o=l.match(/\(/g))==null?void 0:o.length)??0)===(((c=l.match(/\)/g))==null?void 0:c.length)??0)&&(((i=l.match(/`/g))==null?void 0:i.length)??0)%2===0},r=l=>l.length>=2&&l.length<=60&&l.split(/\s+/).length<=8&&!/[.!]\s/.test(l)&&a(l);return s.length>=2&&s.length<=6&&s.every(r)?s:[]}const ho=t=>t.replace(/\[([^\]]+)\]\([^)]*\)/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/(\*\*|__)(.+?)\1/g,"$2").replace(new RegExp("(?<![\\w*])\\*([^*\\n]+)\\*(?![\\w*])","g"),"$1").trim(),Cs=/\s*[★⭐]\s*/g,Dc=/^(.+?)\s*\(([^()]*(?:\([^()]*\)[^()]*)*)\)\s*$/,In=(t,n)=>{const s=Cs.test(t)||Cs.test(n);return{label:ho(t.replace(Cs," ")),detail:ho(n.replace(Cs," ")),...s?{star:s}:{}}},Wn=/^(\*\*|__)(\S(?:.*?\S)?)\1\s*(?:[—–:-]\s*)?(.*)$/,go=/^(.+?)(\s+[—–-]\s+|:\s+)(.+)$/,pl=(t,n=!1)=>t.every(s=>s.label.length>0&&s.label.length<=nf&&!ja(s.label)&&(n||!ja(s.detail)));function bo(t){if(t.length<2||t.length>6)return null;const n=t.map(r=>{var l;return Wn.test(r)?null:((l=r.match(go))==null?void 0:l[2].trim()[0])??null}),s=n.every(r=>r!==null&&r===n[0]),a=t.map(r=>{const l=r.match(Wn);if(l)return In(l[2],l[3]);const o=s?r.match(go):null;return o?In(o[1],o[3]):In(r,"")});return pl(a)?a:null}const lf=/(^|[\s(:,;])([a-h])\)\s+/g;function jo(t){const n=[];for(const l of t.matchAll(lf))l[2].charCodeAt(0)-97===n.length&&n.push({at:l.index+l[1].length,end:l.index+l[0].length});if(n.length<2||n.length>8)return null;const s=t.slice(0,n[0].at).trim().replace(/\s*[:—–-]\s*$/,"").trim();if(!s)return null;const a=n.map((l,o)=>{var c;return t.slice(l.end,(c=n[o+1])==null?void 0:c.at)});a[a.length-1]=a[a.length-1].split(new RegExp("(?<=[.!??])\\s+(?=\\p{Lu})","u"))[0];const r=a.map(l=>{const o=l.trim().replace(/[\s,;.??]+$/,""),c=/[★⭐]/.test(o),i=o.replace(Cs," ").trim().match(Dc),m=i?In(i[1],i[2]):In(o,"");return c?{...m,star:c}:m});return pl(r,!0)?{stem:s,options:r}:null}const of=/^(\*\*|__)(.+?[??])\s*\1/,yo=t=>{var n;return ja(t)?t:((n=t.match(of))==null?void 0:n[2])??null},No=/(^|[^\p{L}])(laquelle|lequel|lesquel|quelle (option|approche|solution)|quel choix|which|pr[ée]f[ée]r|prefer|choisi|choos|pick|reten|retien)/iu,cf=/^(\d+)[.)]\s+(.+)$/,df=/^(\*\*|__)(\d+)[.)]\s+(.+?)\1\s*(.*)$/,uf=t=>t.length>160?t.split(new RegExp("(?<=[.!])\\s+(?=\\p{Lu}|\\()","u"))[0]:t;function cr(t,n,s){var l;t=t.trim().replace(/\.$/,"");const a=t.match(Dc);let r=uf(n.trim()).replace(/^\((.*)\)\.?$/,"$1").replace(/^[—–:-]\s*/,"")||(a?a[2]:"");return!r&&s&&(r=s.type==="p"?s.text:s.type==="list"?((l=s.items[0])==null?void 0:l.text)??"":""),In(a?a[1]:t,r)}const xf=/recommand|recommend/i;function Fc(t,n,s=[]){const a=t.toLowerCase(),r=d=>{const x=Math.min(...d);return x<1/0?d.indexOf(x):-1},l=d=>{const x=d.length>=2?a.search(new RegExp(`(^|[^\\p{L}])${d.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}($|[^\\p{L}])`,"u")):-1;return x<0?1/0:x},o=n.map(d=>d.label.toLowerCase().split(/\s+/)[0]),c=r(n.map((d,x)=>Math.min(l(d.label.toLowerCase()),o[x].length>=4&&o.filter(p=>p===o[x]).length===1?l(o[x]):1/0)));if(c>=0)return c;const i=a.match(/\boption\s+(\d+)/);return i&&Number(i[1])>=1&&Number(i[1])<=n.length?Number(i[1])-1:s.findIndex(d=>d&&new RegExp(`(^|[\\s:])${d}([.\\s,]|$)`).test(t))}const Pc=(t,n)=>n<0||t.some(s=>s.star)?t:t.map((s,a)=>a===n?{...s,star:!0}:s);function mf(t){if(!/^(\*\*|__)[^*_]+\1:?$/.test(t.text.trim()))return null;const n=t.sub.find(c=>xf.test(c.slice(0,40)));if(!n)return null;const s=t.sub.filter(c=>c!==n),a=s.filter(c=>Wn.test(c)),r=a.length>=2?a:s;if(r.length<2||r.length>6)return null;const l=r.map(c=>{var i;return((i=c.replace(/^(\*\*|__)/,"").match(/^([A-Z])\.\s/))==null?void 0:i[1])??""}),o=r.map(c=>{const i=c.match(Wn);return i?In(i[2].replace(/^[A-Z]\.\s+/,"").replace(/\.$/,""),i[3].replace(/^[,;]\s*/,"")):In(c.replace(/\.$/,""),"")});return pl(o)?{options:Pc(o,Fc(n,o,l)),notes:t.sub.filter(c=>!r.includes(c))}:null}const Zs=(t,n,s=t,a)=>{const r=n??Or(s).map(c=>({label:c,detail:""})),l=r.map(c=>c.detail),o=r.findIndex(c=>c.star);return{text:t,options:r.map(c=>c.label),...l.some(Boolean)?{details:l}:{},...o>=0?{recommended:o}:{},...a?{ref:a}:{}}};function pf(t,n={}){var k,C;const s=Oc(t);let a,r;const l=s[0];(l==null?void 0:l.type)==="h"&&(a=l.text,s.shift()),a&&((k=s[0])==null?void 0:k.type)==="p"&&!ja(s[0].text)&&(r=s[0].text,s.shift());const o=[];let c={kind:"other",blocks:[]};const i=()=>{(c.blocks.length||c.title)&&o.push(c)};for(const j of s)if(j.type==="h"){i();const y=rf(j.text);c={kind:n.plan&&(y==="done"||y==="verified")?"other":y,title:j.text,blocks:[]}}else c.blocks.push(j);i();const m=[];let d=null,x="";const p=(j,y)=>{j===1?d=[y]:d&&j===d.length+1&&d.push(y)},g=j=>{var y,b;return(b=(y=j.match(Wn))==null?void 0:y[2])==null?void 0:b.replace(/\s*:$/,"")},h=()=>{const j=d&&d.length>=2&&d.length<=8?d:null;return d=null,j?Pc(j,Fc(x,j)):null};for(const j of o){const y=j.kind==="done"||j.kind==="verified",b=(C=j.title)==null?void 0:C.match(cf);b&&p(Number(b[1]),cr(b[2],"",j.blocks[0]));for(let M=0;M<j.blocks.length;M++){const S=j.blocks[M];if(S.type==="p"){const $=S.text.match(df);if($){p(Number($[2]),cr($[3],$[4],j.blocks[M+1]));continue}if(/^(\*\*|__)[^*_]*(recommand|recommend)/i.test(S.text)&&(x=S.text),y)continue;const v=yo(S.text),A=jo(S.text);if(!v&&!A)continue;const R=j.blocks[M+1];let _=(R==null?void 0:R.type)==="list"&&!R.ordered?bo(R.items.map(L=>L.text)):null;_?j.blocks.splice(M+1,1):A?_=A.options:!Or(v).length&&No.test(v)&&(_=h()),S.q=m.length,m.push(Zs(S.text,_,A&&!v?A.stem:v))}else S.type==="list"&&!y&&S.items.forEach(($,v)=>{const A=Wn.test($.text)?$.text.lastIndexOf("?"):-1,R=yo($.text)??(A>0?$.text.slice(0,A+1):null),_=jo($.text),L=R||_?null:mf($);if(!R&&!_&&!L){const B=S.ordered?$.text.match(Wn):null;B&&p(v+1,cr(B[2],B[3],void 0));return}$.q=m.length;const T=bo($.sub);L?(m.push(Zs($.text,L.options,$.text,g($.text))),$.sub=L.notes):!T&&_?m.push(Zs(_.stem,_.options,_.stem,g(_.stem))):m.push(Zs($.text,T??(!Or(R).length&&No.test(R)?h():null),R??$.text)),T&&!L&&($.sub=[])})}}const N=!!a&&(l==null?void 0:l.type)==="h"||m.length>0||o.some(j=>!!j.title||j.blocks.some(y=>y.type!=="p"));return{title:a,lead:r,sections:o,questions:m,structured:N}}function zc(t){const n=f.useRef(null);return async s=>{const a=JSON.stringify(s),r=n.current;let l=r&&r.subject===a&&r.until>Date.now()?r.challenge:null;if(!l){n.current=null;try{l=await t.prepareConfirm(s)}catch{return"prepareFailed"}n.current={subject:a,challenge:l,until:Date.now()+l.expiresInMs-2e3}}if(!l.credentialId)return n.current=null,"failed";const o=await Fs({challenge:l.challenge,rpId:l.rpId,credentialId:l.credentialId}).catch(()=>"failed");return o==="cancelled"?"cancelled":(n.current=null,o)}}function at({tone:t,title:n,body:s,action:a}){const r=t==="ok"||t==="gone"?"check":t==="denied"?"close":"alert",l=t==="ok"?"text-ok":t==="fail"?"text-destructive":t==="warn"?"text-attention":"text-muted",o=t==="gone"?"border-dashed border-line text-muted":t==="fail"?"border-destructive/40":t==="warn"?"border-attention/45":"border-line";return e.jsxs("div",{role:"status","data-receipt":t,className:`flex min-h-[52px] items-center gap-2.5 rounded-lg border bg-surface px-3 py-2 ${o}`,children:[e.jsx(z,{name:r,className:`size-[18px] ${l}`}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("b",{className:`text-[13.5px] font-semibold [overflow-wrap:anywhere] ${t==="gone"?"text-fg":""}`,children:n}),s&&e.jsx("small",{className:"text-small [overflow-wrap:anywhere] text-muted",children:s})]}),a&&("href"in a?e.jsx("a",{href:a.href,className:rt({size:"xs",className:"flex-none"}),children:a.label}):e.jsx("button",{type:"button",disabled:a.disabled,onClick:a.onClick,className:rt({size:"xs",className:"flex-none"}),children:a.label}))]})}function ya({onGone:t,children:n}){const[s,a]=f.useState(!1),r=f.useRef(t);return r.current=t,f.useEffect(()=>{const l=setTimeout(()=>a(!0),mc);return()=>clearTimeout(l)},[]),f.useEffect(()=>{if(!s)return;const l=setTimeout(()=>r.current(),200);return()=>clearTimeout(l)},[s]),e.jsx("div",{"data-leaving":s||void 0,className:`grid transition-[grid-template-rows,opacity] duration-200 ${s?"grid-rows-[0fr] opacity-0":"grid-rows-[1fr]"}`,children:e.jsx("div",{className:"min-h-0 overflow-hidden",children:n})})}function ff(t){const n=f.useRef(new Map),[s,a]=f.useState(new Set),r=new Set(t.map(i=>i.id)),l=t.map(i=>({...i,ghost:!1})),o=[...n.current].filter(([i])=>!r.has(i)&&!s.has(i)).sort((i,m)=>i[1].index-m[1].index);for(const[i,m]of o)l.splice(Math.min(m.index,l.length),0,{id:i,value:m.value,ghost:!0});l.forEach((i,m)=>n.current.set(i.id,{value:i.value,index:m}));for(const i of[...n.current.keys()])!r.has(i)&&s.has(i)&&n.current.delete(i);const c=i=>a(m=>m.has(i)?m:new Set(m).add(i));return f.useEffect(()=>{[...s].some(i=>!n.current.has(i)&&!r.has(i))&&a(i=>new Set([...i].filter(m=>n.current.has(m)||r.has(m))))}),{entries:l,dismiss:c,dismissed:s}}const Bc=150,hf=t=>t.length>Bc||t.split(`
|
|
13
|
+
`).length>3,Ct=()=>e.jsx("svg",{className:"size-4 flex-none motion-safe:animate-spin",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})});function gf(t){var Be,Je;const{store:n,item:s,mode:a,outcome:r,fresh:l,ghost:o,changed:c,canConfirm:i,enroll:m,onGone:d,selected:x=!1,inThread:p=!1,keys:g=!1}=t,[h,N]=f.useState(null),[k,C]=f.useState(!1),[j,y]=f.useState(a.kind==="question"&&a.options.length===0&&a.other),[b,M]=f.useState(""),[S,$]=f.useState(!1),[v,A]=f.useState(null),R=zc(n),_=Pa(),L=p&&_,T=u.cards.receipt,B=s.botName,E=u.cards.pill[s.kind],P=ce({name:"request",sessionId:s.sessionId,key:s.key}),W=f.useRef(null),F=g&&a.kind==="permission";if(Tc(F,oe=>{var de;return((de=W.current)==null?void 0:de.call(W,oe))??!1}),W.current=null,r.kind==="applied"){const oe={label:T.thread,href:ce({name:"thread",sessionId:s.sessionId})},de=r.answer!==void 0?e.jsx(at,{tone:"ok",title:T.answered(r.answer.length>40?`${r.answer.slice(0,40)}…`:r.answer,B)}):r.decision==="deny"?e.jsx(at,{tone:"denied",title:T.denied(B),body:T.deniedBody,action:oe}):e.jsx(at,{tone:"ok",title:T.allowed(B),body:T.allowedBody,action:oe});return e.jsx(ya,{onGone:d,children:de})}if(r.kind==="uncertain")return e.jsx(at,{tone:"warn",title:u.decide.uncertain,body:T.uncertainBody,...t.onCheck?{action:{label:T.check,onClick:t.onCheck}}:{}});if(r.kind==="handledElsewhere"||o&&r.kind==="idle"){if(!l)return ko(d),null;const oe=(Be=t.session)==null?void 0:Be.lastAnswer,de=oe&&oe.key===s.key,ke=de?oe.by.kind==="pc"?u.thread.event.fromPc:oe.by.id===((Je=n.getState().device)==null?void 0:Je.id)?u.thread.event.fromHere:u.thread.event.fromDevice(oe.by.name):null,Oe=b.trim()!=="",lt=de?oe.decision?T.decidedAt(B,oe.decision,Ke(oe.at)):T.answeredAt(B,Ke(oe.at),Oe):T.gone(B,Oe);return e.jsx(ya,{onGone:d,children:e.jsx(at,{tone:"gone",title:ke?u.gone.titleOn(ke):u.gone.titleElsewhere,body:lt})})}if((k||r.kind==="failed"||r.kind==="rejected"&&!["not_taken","stale","confirm_required","assertion_expired","assertion_invalid","free_text","invalid","untypable","read_only","no_prompt","nothing_to_decide"].includes(r.reason))&&!o){const oe=h;return e.jsx(at,{tone:"fail",title:u.decide.failed,body:T.what(B,E),action:oe&&l?{label:T.retry,onClick:()=>{C(!1),D(oe)}}:{label:u.cards.examine,href:P}})}if(o)return ko(d),null;const Y=r.kind==="sending",H=l&&!c&&!Y&&!S,I={key:s.key,kind:s.kind,text:s.text},D=oe=>{N(oe),A(null);const de=oe.kind==="decide"?n.decide(s.sessionId,oe.decision,{expect:I}):n.reply(s.sessionId,oe.text,{expect:I});C(de===null)},Q=async()=>{var de,ke;if(!H)return;$(!0),A(null);const oe=await R({purpose:"decide",id:s.sessionId,expect:I});if($(!1),typeof oe=="string"){A(oe);return}((ke=(de=n.getState().sessions.get(s.sessionId))==null?void 0:de.pending)==null?void 0:ke.key)===s.key&&(N({kind:"decide",decision:"accept"}),C(n.decide(s.sessionId,"accept",{assertion:oe,expect:I})===null))};W.current=F&&H?oe=>{const de=oe.toLowerCase();return de==="y"?(D({kind:"decide",decision:"accept"}),!0):de==="n"?(D({kind:"decide",decision:"deny"}),!0):!1}:null;const q=oe=>Y&&h!==null&&JSON.stringify(h)===JSON.stringify(oe),K=ic(b),ee=()=>{H&&K.problem===null&&D({kind:"reply",text:K.text,label:K.text})},ue=r.kind==="rejected"?r.reason==="not_taken"?u.decide.notTaken:r.reason==="free_text"?u.decide.otherUnsupported:r.reason==="invalid"?s.kind==="question"?u.decide.otherInvalid:u.decide.failed:r.reason==="untypable"?u.question.untypable:r.reason==="read_only"?u.decide.readOnly:r.reason==="no_prompt"||r.reason==="nothing_to_decide"?u.decide.noPrompt:r.reason==="assertion_expired"?u.confirm.expired:r.reason==="assertion_invalid"?u.confirm.failed:null:null,fe=a.kind==="high",he=fe?oc(s):null,w=s.kind==="permission"?s.body??s.text:Ia(s),O=[s.repo,s.branch].filter(Boolean).join(" · "),V=(oe="outline",de="")=>rt({variant:oe,className:`min-w-0 ${de}`}),Z=p?e.jsxs("a",{href:P,className:"-m-1 flex min-w-0 items-center gap-[7px] rounded-md p-1 active:bg-raised",children:[e.jsx(ze,{state:s.kind==="question"?"ask":s.kind==="permission"?"perm":"work"}),e.jsx("b",{className:"min-w-0 truncate font-semibold",children:s.kind==="permission"?u.cards.line.permission:E}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono text-small whitespace-nowrap text-muted",children:F?u.cards.keys:fa(s.since,Date.now())}),fe&&e.jsx(Lt,{tone:"risk",children:u.risk.badge})]}):e.jsxs("a",{href:P,className:"-m-1 flex min-w-0 items-center gap-[7px] rounded-md p-1 active:bg-raised",children:[e.jsx(Xn,{tool:s.tool}),e.jsx("b",{className:"font-semibold whitespace-nowrap",children:B}),O&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:O}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono text-small whitespace-nowrap text-muted",children:fa(s.since,Date.now())}),fe?e.jsx(Lt,{tone:"risk",children:u.risk.badge}):e.jsx(Lt,{tone:s.kind==="question"?"ask":s.kind==="permission"?"perm":"plain",children:E})]}),X=hf(w),J=s.kind==="permission"?e.jsx("a",{href:P,className:"block",children:e.jsx(vm,{children:X?w.split(`
|
|
14
14
|
`).slice(0,3).join(`
|
|
15
|
-
`).slice(0,Bc)+"…":w})}):e.jsx("a",{href:P,className:`block text-body [overflow-wrap:anywhere] ${s.kind==="question"?"":"font-semibold"} ${X?"line-clamp-3":""}`,children:w}),pe=(oe,de=!1)=>e.jsx("p",{className:`text-small [overflow-wrap:anywhere] ${de?"text-destructive":"text-muted"}`,role:de?"alert":void 0,children:oe}),Ne=v==="cancelled"?u.confirm.cancelled:v==="prepareFailed"?u.confirm.prepareFailed:v==="failed"?u.confirm.failed:null,Xe=(()=>{switch(a.kind){case"examine":return e.jsxs("a",{href:P,className:rt({size:"sm",className:"self-start"}),children:[u.cards.examine,e.jsx(z,{name:"chevron",className:"size-4"})]});case"readOnly":return pe(u.decide.readOnly);case"answerOnPc":return pe(u.decide.answerOnPc);case"permission":return L?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D({kind:"decide",decision:"accept"}),className:V("primary","min-w-[140px]"),children:[q({kind:"decide",decision:"accept"})&&e.jsx(Ct,{}),u.cards.allow]}),e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D({kind:"decide",decision:"deny"}),className:V("outline","min-w-[120px]"),children:[q({kind:"decide",decision:"deny"})&&e.jsx(Ct,{}),u.cards.deny]}),a.always&&e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D({kind:"decide",decision:"always"}),className:rt({variant:"ghost"}),children:[q({kind:"decide",decision:"always"})&&e.jsx(Ct,{}),ga(_r(s))]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D({kind:"decide",decision:"accept"}),className:V("primary"),children:[q({kind:"decide",decision:"accept"})&&e.jsx(Ct,{}),u.cards.allow]}),e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D({kind:"decide",decision:"deny"}),className:V(),children:[q({kind:"decide",decision:"deny"})&&e.jsx(Ct,{}),u.cards.deny]})]}),a.always&&e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D({kind:"decide",decision:"always"}),className:rt({variant:"ghost",className:"-mt-1 self-stretch"}),children:[q({kind:"decide",decision:"always"})&&e.jsx(Ct,{}),ga(_r(s))]})]});case"high":return i?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{type:"button",disabled:!H,onClick:()=>{Q()},className:V("primary"),children:[S||q({kind:"decide",decision:"accept"})?e.jsx(Ct,{}):e.jsx(z,{name:"face",className:"size-[18px]"}),e.jsx("span",{className:"truncate",children:S?u.confirm.checking:Pt()?u.confirm.goApple:u.confirm.go})]}),e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D({kind:"decide",decision:"deny"}),className:V(),children:[q({kind:"decide",decision:"deny"})&&e.jsx(Ct,{}),u.cards.deny]})]}),S&&pe(u.confirm.askingNote)]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{type:"button",disabled:!0,className:V(),children:u.decide.onPc}),e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D({kind:"decide",decision:"deny"}),className:V(),children:[q({kind:"decide",decision:"deny"})&&e.jsx(Ct,{}),u.cards.deny]})]}),pe(u.decide.onPcHint),x&&e.jsx("a",{href:ce({name:"connection",section:"link"}),className:"self-start text-small font-medium underline underline-offset-2",children:u.enroll.link})]});case"question":{const oe=`free-${s.sessionId}`,de=K.problem!==null&&K.problem!=="empty";return e.jsxs(e.Fragment,{children:[a.options.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:a.options.map((ke,Oe)=>{const lt={kind:"reply",text:String(Oe+1),label:ke};return e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D(lt),className:rt({className:"h-auto min-h-11 max-w-full py-2 text-left whitespace-normal [overflow-wrap:anywhere]"}),children:[q(lt)&&e.jsx(Ct,{}),ke]},`${Oe}:${ke}`)})}),a.other&&!j&&a.options.length>0&&e.jsx("button",{type:"button",disabled:!H,onClick:()=>y(!0),className:"self-start text-[13px] font-medium text-muted underline-offset-2 hover:underline disabled:opacity-45",children:u.cards.other}),a.other&&j&&e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:`flex items-center gap-2 rounded-[10px] border bg-surface py-[5px] pr-[5px] pl-3 focus-within:border-ring ${de?"border-destructive":"border-input"}`,children:[e.jsx("label",{htmlFor:oe,className:"sr-only",children:u.question.fieldLabel(B)}),e.jsx("input",{id:oe,value:b,onChange:ke=>M(ke.target.value),placeholder:u.question.placeholder,autoComplete:"off",enterKeyHint:"send","aria-invalid":de,disabled:!l||c,onKeyDown:ke=>{ke.key==="Enter"&&!ke.nativeEvent.isComposing&&(ke.preventDefault(),ee())},className:"h-[34px] min-w-0 flex-1 bg-transparent text-base text-fg outline-none placeholder:text-muted"}),e.jsx("button",{type:"button","aria-label":u.decide.send,title:u.decide.send,disabled:!H||K.problem!==null,onClick:ee,className:"grid size-9 flex-none place-items-center rounded-lg bg-primary text-primary-fg disabled:opacity-40",children:(h==null?void 0:h.kind)==="reply"&&Y&&h.text===K.text?e.jsx(Ct,{}):e.jsx(z,{name:"send",className:"size-[18px]"})})]}),de?pe(K.problem==="long"?u.question.long(il):K.problem==="digit"?u.question.digit:u.question.untypable,!0):pe(u.cards.sendHint(B))]}),!a.other&&a.options.length>0&&pe(u.decide.otherUnsupported)]})}}})(),gt=fe?u.cards.kindName.permission:u.cards.kindName[s.kind];return e.jsxs(Bs,{tone:s.kind==="question"?"ask":s.kind==="permission"?"perm":"plain",selected:m,label:u.cards.region(gt,B,s.repo),children:[Z,ue&&pe(ue,!0),c&&e.jsxs("div",{role:"status",className:"flex items-start gap-2 rounded-md border border-attention/45 px-2.5 py-2 text-small",children:[e.jsx(z,{name:"alert",className:"mt-px size-4 text-attention"}),u.decide.changed]}),J,X&&e.jsx("a",{href:P,className:"-mt-1 self-start text-[13px] font-medium underline-offset-2 hover:underline",children:u.cards.readAll}),he&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-destructive/10 px-2.5 py-2 text-small",children:[e.jsx(z,{name:"alert",className:"mt-px size-4 text-destructive"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("b",{className:"font-semibold",children:he.title}),e.jsx("span",{className:"text-muted",children:he.body})]})]}),c&&e.jsx("button",{type:"button",onClick:t.onReread,className:rt(),children:u.decide.reread}),Ne&&pe(Ne,!0),Xe,Y&&pe(u.decide.sending)]})}function ko(t){queueMicrotask(t)}const bf={low:"Bas",medium:"Moyen",high:"Élevé",xhigh:"Très élevé",max:"Max",ultra:"Ultra"},jf={"claude:fable":"Le plus capable","claude:opus":"Très capable, plus lent","claude:sonnet":"Équilibré, au quotidien","claude:haiku":"Rapide et économique"};function yf(t,n,s){var a;if(n===void 0){const r=s.find(l=>l.isDefault);return r?`${u.model.byDefault} · ${r.label}`:u.model.byDefault}return((a=s.find(r=>r.id===n))==null?void 0:a.label)??n}const Ws=t=>bf[t]??t,qc=(t,n)=>jf[`${t}:${n.id}`]??n.description,Nf=(t,n)=>t.model===n.model&&t.effort===n.effort,kf=t=>!((t.state==="idle"||t.state==="error")&&!t.pending),fl=t=>({model:t.model??null,effort:t.effort??null});function vo(t,n,s){if(t==="cursor")return null;const a=s.model===null?n.find(r=>r.isDefault):n.find(r=>r.id===s.model);return a!=null&&a.efforts&&a.efforts.length>0?a.efforts:null}function vf(t){const n=/^(?:claude-)?(fable|opus|sonnet|haiku)(?:-(\d+)(?:-(\d+))?)?/i.exec(t);return n?[n[1].charAt(0).toUpperCase()+n[1].slice(1).toLowerCase(),n[2]?n[3]?`${n[2]}.${n[3]}`:n[2]:""].filter(Boolean).join(" "):t}const Dr=t=>String(t).padStart(2,"0");function Hc(t){const n=Math.max(0,Math.round(t/1e3));if(n<60)return`${n} s`;const s=Math.floor(n/60);if(s<60)return`${s} min`;const a=Math.floor(s/60);return a<48?`${a} h ${Dr(s%60)}`:`${Math.floor(a/24)} j`}const wf=(t,n)=>t.getFullYear()===n.getFullYear()&&t.getMonth()===n.getMonth()&&t.getDate()===n.getDate(),dr=t=>`${Dr(t.getHours())}:${Dr(t.getMinutes())}`,wo=t=>t.toLocaleDateString(ut,{weekday:"short"}),Sf=168*36e5,hl=(t,n)=>new Date(t).getTime()-n>=Sf;function Uc(t,n,s=!1){const a=new Date(t);if(hl(t,n)){const r=a.toLocaleDateString(ut,{day:"numeric",month:"short"});return s?r:`${r} ${dr(a)}`}return wf(a,new Date(n))?dr(a):s?wo(a):`${wo(a)} ${dr(a)}`}const Cf=t=>t.pct>=100;function za(t,n){return t>=100?"red":n!==null&&t>=n*100?"amber":""}const $f=60*6e4;function Ba(t,n,s=!0){return t.map(a=>{const r=a.readAt===null||n-Date.parse(a.readAt)>$f;return{...a,status:!s&&a.status==="ok"?"stale":a.status,windows:r?[]:a.windows}})}function Mf(t,n,s=Date.now()){return Ba(t,s).flatMap(a=>a.status==="expired"||a.status==="loading"?[]:a.windows.flatMap(r=>{const l=za(r.pct,n);return l?[{harness:a.harness,window:r,tone:l}]:[]}))}function Wc(t,n,s){const a=Date.parse(t.startedAt),r=t.context?Math.min(1,t.context.used/t.context.window):void 0;return{...t.model?{model:vf(t.model)}:{},...t.effort?{effort:Ws(t.effort).toLowerCase()}:{},...r!==void 0?{context:{pct:Math.round(r*100),near:r>=s}}:{},...Number.isFinite(a)&&t.state!=="exited"?{duration:Hc(n-a)}:{}}}function So(t){return t<1e3?String(Math.round(t)):t<1e6?`${Math.round(t/1e3)}k`:`${Number((t/1e6).toFixed(1))}M`}function Ef(t,n,s,a,r){const l=n&&Ba(n,a,r).find(c=>c.harness===t),o=l&&l.status!=="expired"&&l.status!=="loading"?l.windows[0]:void 0;return l&&o?{harness:l.harness,window:o,tone:za(o.pct,s)}:null}const _f='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function Kc(t,n){const s=f.useRef(n);s.current=n,f.useEffect(()=>{const a=t.current;if(!a)return;const r=document.activeElement instanceof HTMLElement?document.activeElement:null;a.focus({preventScroll:!0});const l=o=>{if(o.key==="Escape"){o.preventDefault(),s.current();return}if(o.key!=="Tab")return;const c=[...a.querySelectorAll(_f)],i=c[0],x=c.at(-1);if(!i||!x){o.preventDefault();return}o.shiftKey&&(document.activeElement===i||document.activeElement===a)?(o.preventDefault(),x.focus()):!o.shiftKey&&document.activeElement===x&&(o.preventDefault(),i.focus())};return document.addEventListener("keydown",l),()=>{document.removeEventListener("keydown",l),r!=null&&r.isConnected&&r.focus({preventScroll:!0})}},[t])}function ht({labelledBy:t,onClose:n,children:s}){const a=f.useRef(null);return Kc(a,n),dl.createPortal(e.jsxs("div",{className:"fixed inset-0 z-20",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50","aria-hidden":"true",onClick:n}),e.jsxs("section",{ref:a,role:"dialog","aria-modal":"true","aria-labelledby":t,tabIndex:-1,className:"absolute inset-x-0 bottom-0 mx-auto flex max-w-[480px] flex-col gap-4 rounded-t-[28px] border-t border-line bg-surface px-5 pt-3 pb-[calc(34px+env(safe-area-inset-bottom))] shadow-[var(--shadow-overlay)] outline-none tablet:inset-x-auto tablet:bottom-auto tablet:top-1/2 tablet:left-1/2 tablet:max-h-[calc(100dvh-48px)] tablet:w-[480px] tablet:-translate-x-1/2 tablet:-translate-y-1/2 tablet:overflow-y-auto tablet:rounded-[24px] tablet:border tablet:px-6 tablet:pt-6 tablet:pb-6",children:[e.jsx("span",{className:"h-[5px] w-9 self-center rounded-full bg-muted/40 tablet:hidden","aria-hidden":"true"}),s]})]}),document.body)}const ur="mt-px inline-flex size-4 flex-none items-center justify-center rounded-[4px] border";function Vc({checklist:t,current:n}){var d;const[s,a]=f.useState(!1),{tasks:r,done:l,total:o}=t,c=((d=r.find(m=>m.status==="in_progress"))==null?void 0:d.text)??n??(l===o?u.checklist.allDone:u.checklist.paused),i=r.some(m=>m.status==="in_progress")||!!n,x=f.useMemo(()=>{const m=new Map;return r.map(p=>{const g=m.get(p.text)??0;return m.set(p.text,g+1),g===0?p.text:`${p.text}#${g}`})},[r]);return e.jsxs("div",{className:"sticky top-0 z-10 flex-none bg-bg",children:[e.jsxs("button",{type:"button","aria-expanded":s,onClick:()=>a(m=>!m),className:`flex min-h-11 w-full flex-col gap-1.5 border border-line bg-surface px-3 py-2.5 text-left text-[12px] leading-[18px] text-muted shadow-[0_4px_14px_rgba(0,0,0,.35)] ${s?"rounded-t-card":"rounded-card"}`,children:[e.jsxs("span",{className:"flex w-full items-center gap-2",children:[e.jsx(z,{name:"plan",className:"size-3.5",stroke:1.8}),e.jsx("strong",{className:"font-medium text-fg",children:u.checklist.title}),e.jsx("span",{className:"flex-1"}),e.jsxs("span",{className:"font-mono text-[11px] text-fg",children:[l,"/",o]}),e.jsx("span",{"aria-hidden":"true",className:"h-1 w-16 overflow-hidden rounded-[2px] bg-raised",children:e.jsx("span",{className:"block h-full bg-ok",style:{width:`${o?l/o*100:0}%`}})}),e.jsx("span",{className:s?"-rotate-90":"rotate-90",children:e.jsx(z,{name:"chevron",className:"size-[13px]",stroke:2})})]}),e.jsxs("span",{className:"block w-full truncate",children:[i&&e.jsx("span",{className:"mr-1.5 inline-block size-1.5 rounded-full bg-info align-[1px]"}),c]})]}),s&&e.jsxs("ol",{className:"max-h-[50dvh] overflow-y-auto rounded-b-card border border-t-0 border-line bg-surface px-3 pt-1.5 pb-2.5 text-small",children:[r.map((m,p)=>e.jsxs("li",{className:`flex items-start gap-2.5 py-1.5 [overflow-wrap:anywhere] ${m.status==="completed"?"text-muted line-through":m.status==="in_progress"?"font-medium text-fg":"text-fg"}`,children:[m.status==="completed"&&e.jsx("span",{role:"img","aria-label":u.checklist.box.completed,className:`${ur} border-ok/50 font-mono text-[10px] font-semibold text-ok no-underline`,children:"✓"}),m.status==="in_progress"&&e.jsx("span",{role:"img","aria-label":u.checklist.box.in_progress,className:`${ur} border-info`,children:e.jsx("svg",{className:"size-2.5 text-info motion-safe:animate-spin",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})})}),m.status==="pending"&&e.jsx("span",{role:"img","aria-label":u.checklist.box.pending,className:`${ur} border-fg/25`}),m.text]},x[p])),t.cut&&e.jsx("li",{className:"py-1.5 text-meta text-muted",children:u.checklist.cut})]})]})}function Na({name:t,legend:n,options:s,value:a,onChange:r,fit:l=!1}){return e.jsxs("fieldset",{className:`m-0 min-w-0 border-0 p-0${l?" self-start":""}`,"data-fit":l||void 0,children:[e.jsx("legend",{className:"sr-only",children:n}),e.jsx("div",{className:`${l?"inline-flex":"grid auto-cols-fr grid-flow-col"} gap-1 rounded-control bg-raised p-1`,children:s.map(o=>e.jsxs("label",{lang:o.lang,className:`flex min-h-10 cursor-pointer items-center justify-center rounded-[9px] ${l?"px-3.5":"px-2"} text-body font-medium text-muted transition-colors duration-100 has-[:checked]:bg-fg has-[:checked]:text-bg has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-info`,children:[e.jsx("input",{type:"radio",name:t,value:o.value,checked:a===o.value,onChange:()=>r(o.value),className:"sr-only"}),o.label]},o.value))})]})}const gl="model-sheet-title",Rf="flex min-h-12 w-full items-center gap-3 rounded-control border border-line bg-surface px-3 py-2.5 text-left active:bg-raised aria-pressed:border-fg/40 aria-pressed:bg-raised";function Gc({tool:t,models:n,error:s,current:a,pick:r,onPick:l,note:o,actions:c,defaultHint:i=u.model.defaultHint}){var h;const x=!a||a.model===null||n.some(N=>N.id===a.model),d=vo(t,n,r),m=N=>{const k=vo(t,n,{model:N});l({model:N,effort:r.effort!==null&&(k!=null&&k.includes(r.effort))?r.effort:null})},p=(N,k,C)=>e.jsxs("button",{type:"button","aria-pressed":r.model===N,onClick:()=>m(N),className:Rf,children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-body font-medium",children:k}),C&&e.jsx("span",{className:"block text-meta text-muted",children:C})]}),(a==null?void 0:a.model)===N&&e.jsx("span",{className:"flex-none rounded-full bg-raised px-2 py-0.5 text-meta text-muted",children:u.model.current})]},N??""),g=d&&(r.effort??((h=n.find(N=>r.model===null?N.isDefault:N.id===r.model))==null?void 0:h.defaultEffort)??"");return e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("h2",{id:gl,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:u.model.title}),e.jsx("p",{className:"mt-1 text-meta text-muted",children:u.model.subtitle(u.tools[t]??t)})]}),s&&e.jsx("p",{role:"status",className:"text-meta text-attention",children:u.model.listError}),e.jsxs("div",{className:"flex max-h-[45vh] flex-col gap-1.5 overflow-y-auto",children:[p(null,u.model.byDefault,i),!x&&(a==null?void 0:a.model)!=null&&p(a.model,a.model,void 0),n.map(N=>p(N.id,N.label,qc(t,N)))]}),d&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-body font-medium",children:[u.model.effortTitle," ",e.jsx("span",{className:"text-meta font-normal text-muted",children:u.model.effortHint})]}),e.jsx("div",{className:"mt-2",children:e.jsx(Na,{name:"model-effort",legend:u.model.effortTitle,value:g??"",onChange:N=>l({model:r.model,effort:N}),options:d.map(N=>({value:N,label:Ws(N)}))})})]}),o&&e.jsx("p",{className:"text-small whitespace-pre-line text-muted",children:o}),c]})}const Xc={models:[]},Yc=t=>t.modelNext?{model:t.modelNext.model??null,effort:t.modelNext.effort??null}:fl(t),Vn=(t,n)=>!!(t!=null&&t.models)&&n.canSwitch===!0;function Tf({store:t,session:n}){const{daemon:s,models:a,fresh:r}=me(t),[l,o]=f.useState(!1),c=Vn(s,n);if(f.useEffect(()=>{c&&t.requestModels(n.tool)},[c,t,n.tool]),!c)return null;const i=a[n.tool]??Xc,x=n.modelNext?Yc(n):null,d=x??fl(n),m=[yf(n.tool,d.model??void 0,i.models),d.effort?Ws(d.effort):null].filter(Boolean).join(" · ");return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:!r,"aria-haspopup":"dialog","aria-label":u.model.chip(x?`${m}, ${u.model.nextTurn}`:m),onClick:()=>{t.requestModels(n.tool),o(!0)},className:`${Oi()} gap-2 whitespace-nowrap`,children:[e.jsx("span",{children:m}),x&&e.jsx("span",{className:"text-meta font-normal text-attention",children:u.model.nextTurn})]}),l&&e.jsx(qa,{store:t,session:n,onClose:()=>o(!1)})]})}function Af({store:t,session:n}){const{daemon:s,modelFailures:a}=me(t),r=a[n.id];return!Vn(s,n)||!r?null:e.jsx("p",{role:"status",className:"pb-2 text-meta text-attention",children:u.model.failedLine(u.model.failed[r])})}function qa({store:t,session:n,onClose:s}){const{models:a}=me(t),r=a[n.tool]??Xc,l=fl(n),[o,c]=f.useState(Yc(n)),[i,x]=f.useState(!1),[d,m]=f.useState(null),p=async h=>{x(!0),m(null);const N=await t.changeModel(n.id,h.model,h.effort);if(x(!1),N.status==="applied"){s();return}if(N.status==="expired"){m(u.model.uncertain);return}const k=N.status==="rejected"?N.reason:null;m(k&&k in u.model.failed?u.model.failed[k]:u.model.notApplied)},g=kf(n);return e.jsx(ht,{labelledBy:gl,onClose:s,children:e.jsx(Gc,{tool:n.tool,models:r.models,error:r.error,current:l,pick:o,onPick:c,note:g?u.model.noteWorking(n.name):u.model.noteIdle(n.name),actions:e.jsxs(e.Fragment,{children:[d&&e.jsx("p",{role:"alert",className:"text-meta text-attention",children:d}),n.modelNext&&e.jsx(Ue,{variant:"outline",disabled:i,onClick:()=>void p(l),children:u.model.cancelPending}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ue,{variant:"ghost",className:"flex-1",onClick:s,children:u.model.cancel}),e.jsx(Ue,{variant:"primary",className:"flex-[2]",disabled:i||Nf(o,l),onClick:()=>void p(o),children:u.model.apply})]})]})})})}const If=1e4;function Qc(t,n){const s=u.sessions.modelOff;return Vn(t,n)?null:n.state==="exited"?s.ended:t!=null&&t.models?s.outside:s.olderPc}function Lf(t,n){const s=r=>{var l;return t.rig?((l=r.rig)==null?void 0:l.name)===t.rig.name:!r.rig&&r.project===t.project},a=[...n].filter(r=>s(r)&&r.state!=="exited").map(r=>r.id);return{name:t.rig?u.sessions.rigGroup(t.rig.name):t.project,ids:a}}function cn({icon:t,label:n,why:s,right:a,onClick:r,danger:l=!1}){const o=!r;return e.jsxs("button",{type:"button",disabled:o,onClick:r,className:`flex min-h-12 w-full items-center gap-3 border-b border-line px-3.5 py-2 text-left text-[15px] last:border-b-0 disabled:opacity-60 ${l?"text-danger-fg":"text-fg"}`,children:[e.jsx(z,{name:t,className:`size-5 ${l?"text-danger-fg":"text-muted"}`}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{children:n}),s&&e.jsx("small",{className:"text-small text-muted",children:s})]}),a!=null&&e.jsx("span",{className:"ml-auto flex-none text-[12.5px] text-muted",children:a})]})}const Cs=({children:t})=>e.jsx("div",{className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:t});function bl({store:t,session:n,closable:s,closing:a,onClose:r,onModel:l,onCloseSession:o,display:c,lead:i,who:x,order:d}){var I,D,Q;const m=me(t),p=Kt(),g=f.useId(),[h,N]=f.useState("menu"),[k,C]=f.useState(!1),j=u.sessions,y=n.name,b=m.fresh,S=[Wc(n,p,1).model,n.effort?Ws(n.effort):null].filter(Boolean).join(" · "),$=Qc(m.daemon,n),v=(I=m.daemon)!=null&&I.checklist?m.checklists.get(n.id):void 0,A=!!n.pending||n.state==="waiting_permission"||n.state==="waiting_input",R=n.state==="working",_=Object.values(m.ops).filter(q=>q.message.type==="session.interrupt"&&q.message.id===n.id).sort((q,K)=>q.at.localeCompare(K.at)).at(-1),L=_!==void 0&&yn(_.phase),T=(_==null?void 0:_.phase)==="applied"&&(!R||p-Date.parse(_.at)<If),B=R&&b&&!A&&!L&&!T,E=u.terminal,P=L||T?null:b?A?E.why.waiting:R?null:E.why.idle:E.why.offline,W=(_==null?void 0:_.phase)==="sending"?E.sending:T?E.sent:E.interrupt(y),F=(_==null?void 0:_.phase)==="rejected"&&_.reason==="read_only"?E.readOnly:k||(_==null?void 0:_.phase)==="rejected"||(_==null?void 0:_.phase)==="failed"?E.fail:null,re=Lf(n,m.sessions.values()),Y=!!((D=m.daemon)!=null&&D.broadcast)&&re.ids.length>1,H=x??[n.project,n.branch].filter(Boolean).join(" · ");return e.jsxs(ht,{labelledBy:g,onClose:r,children:[e.jsxs("h2",{id:g,"aria-label":j.sheet.label(y),className:"flex min-w-0 items-center gap-2",children:[e.jsx(Xn,{tool:n.tool}),e.jsx("b",{className:"font-semibold whitespace-nowrap",children:y}),H&&e.jsx("span",{className:"min-w-0 truncate text-small font-normal text-muted",children:H})]}),h==="plan"&&v?e.jsxs(e.Fragment,{children:[e.jsx(Vc,{checklist:v,...(Q=n.checklist)!=null&&Q.current?{current:n.checklist.current}:{}}),e.jsx("button",{type:"button",onClick:()=>N("menu"),className:"h-11 rounded-lg border border-input text-body",children:u.nav.back})]}):h==="group"?e.jsx(lc,{store:t,label:re.name,ids:re.ids,offline:!b,startOpen:!0,onCancel:()=>N("menu")}):e.jsxs(e.Fragment,{children:[i&&i.length>0&&e.jsx(Cs,{children:i.map(q=>e.jsx(cn,{icon:q.icon,label:q.label,onClick:q.onClick},q.label))}),d&&d.length>0&&e.jsx(Cs,{children:d.map(q=>e.jsx(cn,{icon:q.icon,label:q.label,onClick:q.onClick},q.label))}),e.jsxs(Cs,{children:[e.jsx(cn,{icon:"cpu",label:u.model.title,why:$,right:S||null,onClick:$||!b?void 0:l}),c&&e.jsx(cn,{icon:"terminal",label:u.terminal.live2.view,right:c.value,onClick:c.onToggle}),v&&e.jsx(cn,{icon:"list",label:u.checklist.title,right:j.sheet.planCount(v.done,v.total),onClick:()=>N("plan")}),e.jsx(cn,{icon:"stop",label:W,why:F??P,onClick:B?()=>C(!t.interrupt(n.id)):void 0}),Y&&e.jsx(cn,{icon:"send",label:j.sheet.writeGroup(re.name),onClick:b?()=>N("group"):void 0})]}),s&&n.state!=="exited"&&e.jsx(Cs,{children:e.jsx(cn,{icon:"power",danger:!0,label:a?u.sessionEnd.closingNamed(y):u.sessionEnd.close(y),right:Pt()&&!a?e.jsx("span",{"aria-hidden":"true",children:j.sheet.faceId}):null,onClick:a?void 0:o})}),e.jsx("p",{className:"text-meta text-muted",children:j.sheet.interruptNote})]})]})}function Of({name:t,up:n,down:s,onClose:a}){const r=f.useId(),l=u.sessions.reorder;return e.jsxs(ht,{labelledBy:r,onClose:a,children:[e.jsx("h2",{id:r,className:"flex min-w-0 items-center gap-2",children:e.jsx("b",{className:"truncate font-semibold",children:t})}),e.jsxs(Cs,{children:[e.jsx(cn,{icon:"arrowUp",label:l.up,onClick:n?()=>{n(),a()}:void 0}),e.jsx(cn,{icon:"arrowDown",label:l.down,onClick:s?()=>{s(),a()}:void 0})]})]})}const Fr=t=>`ledge.mobile.draft.${t}`;function Zc(t,n){var s;try{return((s=Ze(n))==null?void 0:s.getItem(Fr(t)))??""}catch{return""}}function Jc(t,n,s){try{const a=Ze(s);n===""?a==null||a.removeItem(Fr(t)):a==null||a.setItem(Fr(t),n)}catch{}}const ed="ledge.mobile.draft.cleared",Df=50;function td(t){var n;try{const s=JSON.parse(((n=Ze(t))==null?void 0:n.getItem(ed))??"[]");return Array.isArray(s)?s.filter(a=>typeof a=="string"):[]}catch{return[]}}function Ff(t,n){return td(n).includes(t)}function Pf(t,n){var s;try{const a=td(n).filter(r=>r!==t);(s=Ze(n))==null||s.setItem(ed,JSON.stringify([...a,t].slice(-Df)))}catch{}}let Pr=null;const zf=t=>{Pr=t};function Bf(t){return Pr!==t?!1:(Pr=null,!0)}function qf(t,n,s){const a=Zc(t,s);Jc(t,a.startsWith(n)?a:n+a,s),zf(t)}const Hf=["image/png","image/gif","image/jpeg","image/webp"],Uf=25e6,Wf=[.85,.7,.55,.4],Co=640,Kf=.8,Vf=[.7,.5],Gf={async decode(t){const n=await createImageBitmap(t);let s=null;const a=()=>{s&&(s.width=s.height=0),s=null};return{width:n.width,height:n.height,close:()=>{a(),n.close()},async draw(r,l){a();const o=s=document.createElement("canvas");o.width=r,o.height=l;const c=o.getContext("2d");if(!c)throw new Error("no canvas");return c.imageSmoothingQuality="high",c.drawImage(n,0,0,r,l),{encode:(i,x)=>new Promise((d,m)=>o.toBlob(p=>p?d(p):m(new Error("no blob")),i,x))}}}}},nd=(t,n,s)=>{const a=Math.min(1,s/Math.max(t,n));return{w:Math.max(1,Math.round(t*a)),h:Math.max(1,Math.round(n*a))}};async function sd(t,n){let s=await t.encode("image/webp",n);return s.type==="image/webp"||s.type==="image/jpeg"?{blob:s,mime:s.type}:(s=await t.encode("image/jpeg",n),{blob:s,mime:"image/jpeg"})}const ad=t=>new Promise((n,s)=>{const a=new FileReader;a.onload=()=>n(String(a.result).slice(String(a.result).indexOf(",")+1)),a.onerror=()=>s(a.error),a.readAsDataURL(t)});async function Xf(t,n=Gf){var a;if(!Hf.includes(t.type))return{ok:!1,reason:"notImage"};if(t.size>Uf)return{ok:!1,reason:"tooLarge"};let s;try{s=await n.decode(t)}catch{return{ok:!1,reason:"unreadable"}}try{let r=Math.min(sm,Math.max(s.width,s.height));for(;;){const{w:l,h:o}=nd(s.width,s.height,r),c=await s.draw(l,o);for(const i of Wf){const{blob:x,mime:d}=await sd(c,i);if(x.size>am)continue;const m={mime:d,data:await ad(x)},p=await Yf(s);return p&&(m.preview=p),{ok:!0,value:{image:m,width:l,height:o,bytes:x.size}}}if(r<=Co)return{ok:!1,reason:"tooLarge"};r=Math.max(Co,Math.round(r*Kf))}}catch{return{ok:!1,reason:"unreadable"}}finally{(a=s.close)==null||a.call(s)}}async function Yf(t){try{return await Qf(t)}catch{return}}async function Qf(t){const{w:n,h:s}=nd(t.width,t.height,rm),a=await t.draw(n,s);for(const r of Vf){const{blob:l,mime:o}=await sd(a,r);if(l.size<=lm)return{mime:o,data:await ad(l)}}}function Zf(t,n){if(t>=1e6){const s=(Math.round(t/1e5)/10).toFixed(1);return`${n==="fr"?s.replace(".",","):s} ${n==="fr"?"Mo":"MB"}`}return`${Math.round(t/1e3)} ${n==="fr"?"Ko":"KB"}`}function Jf({items:t,onRemove:n,size:s,removeLabel:a,lang:r}){return t.length===0?null:e.jsx("div",{"data-attachment-chips":!0,style:{display:"flex",flexWrap:"wrap",gap:8},children:t.map(l=>e.jsxs("div",{"data-chip":l.state,title:l.reason,style:{position:"relative",width:s.w,height:s.h,flexShrink:0,borderRadius:"var(--radius-md)",overflow:"hidden",border:`1px solid ${l.state==="refused"?"var(--danger-text)":"var(--border)"}`,background:"var(--well)"},children:[e.jsx("img",{src:l.url,alt:"",draggable:!1,style:{width:"100%",height:"100%",objectFit:"cover",display:"block",opacity:l.state==="ready"?1:.45}}),l.state==="uploading"&&e.jsx("span",{role:"status","aria-label":"…",style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",style:{color:"var(--foreground)"},children:e.jsx("path",{d:"M12 3a9 9 0 1 1-9 9",opacity:"0.9",children:e.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.9s",repeatCount:"indefinite"})})})}),l.state==="refused"&&e.jsx("span",{style:{position:"absolute",left:0,right:0,bottom:0,padding:"2px 4px",fontSize:10,lineHeight:1.2,color:"var(--danger-text)",background:"var(--status-danger-soft)"},children:l.reason}),l.state!=="refused"&&e.jsx("span",{style:{position:"absolute",left:4,bottom:4,padding:"1px 5px",borderRadius:4,fontSize:10,lineHeight:1.3,color:"#fff",background:"rgba(0,0,0,0.6)"},children:Zf(l.bytes,r)}),e.jsx("button",{type:"button","aria-label":a,title:a,onClick:()=>n(l.key),style:{position:"absolute",top:3,right:3,width:20,height:20,padding:0,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:10,border:"none",cursor:"pointer",color:"#fff",background:"rgba(0,0,0,0.6)"},children:e.jsx(is,{...ss.close,size:12})})]},l.key))})}function eh({url:t,failed:n,width:s,height:a,maxW:r,maxH:l,alt:o,unavailable:c,onOpen:i}){const x=Math.min(1,r/s,l/a),d={width:Math.round(s*x),height:Math.round(a*x),maxWidth:"100%",borderRadius:"var(--radius-lg)",border:"1px solid var(--border)",background:"var(--well)",boxSizing:"border-box",overflow:"hidden"};return n?e.jsx("div",{"data-thumb":"failed",style:{...d,display:"flex",alignItems:"center",justifyContent:"center",padding:8,fontSize:12,color:"var(--muted-foreground)",textAlign:"center"},children:c}):t?e.jsx("button",{type:"button","data-thumb":"ready",onClick:i,style:{...d,padding:0,display:"block",cursor:"zoom-in"},children:e.jsx("img",{src:t,alt:o,draggable:!1,style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})}):e.jsx("div",{"data-thumb":"loading","aria-busy":"true",style:d})}function th({onFiles:t,disabled:n,className:s,children:a}){const r=f.useRef(null);return e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:r,type:"file",accept:"image/*",multiple:!0,hidden:!0,tabIndex:-1,"aria-hidden":"true",onChange:l=>{t([...l.target.files??[]]),l.target.value=""}}),e.jsx("button",{type:"button",disabled:n,"aria-label":a?void 0:u.images.attach,title:u.images.attach,onClick:()=>{var l;return(l=r.current)==null?void 0:l.click()},className:s??Ot({variant:"outline",round:!0}),children:a??e.jsx(z,{name:"plus"})})]})}const nh=t=>{var n;return[...((n=t.clipboardData)==null?void 0:n.files)??[]].filter(s=>s.type.startsWith("image/"))},$o=44,sh=120,rd=()=>{var t;return((t=globalThis.matchMedia)==null?void 0:t.call(globalThis,"(hover: hover) and (pointer: fine)").matches)===!0};function ah({id:t,label:n,sendLabel:s,value:a,onChange:r,onSend:l,canSend:o,oneLine:c,images:i,placeholder:x,disabled:d=!1,attachDisabled:m,maxLength:p,invalid:g=!1,describedBy:h,fieldRef:N}){const k=f.useRef(null),C=N??k;f.useLayoutEffect(()=>{const y=C.current;y&&(y.style.height=`${$o}px`,y.style.height=`${Math.min(sh,Math.max($o,y.scrollHeight+y.offsetHeight-y.clientHeight))}px`)},[a,C]);const j=m??d;return e.jsxs("div",{className:"flex flex-col gap-2",children:[i.items.length>0&&e.jsx(Jf,{items:i.items,onRemove:i.remove,size:{w:72,h:54},removeLabel:u.images.remove,lang:om}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx(th,{onFiles:i.add,disabled:j}),e.jsx("label",{htmlFor:t,className:"sr-only",children:n}),e.jsx("textarea",{id:t,ref:C,rows:1,value:a,disabled:d,placeholder:x,maxLength:p,enterKeyHint:c?"send":"enter","aria-invalid":g,"aria-describedby":h,onChange:y=>r(y.target.value),onPaste:y=>{const b=nh(y);b.length===0||j||(y.preventDefault(),i.add(b))},onKeyDown:y=>{y.key!=="Enter"||y.nativeEvent.isComposing||!c&&(y.shiftKey||!rd())||(y.preventDefault(),o&&l())},className:"max-h-[120px] min-h-11 min-w-0 flex-1 resize-none rounded-[22px] border border-input bg-surface px-3.5 py-[11px] text-base leading-5 text-fg placeholder:text-muted disabled:opacity-60"}),e.jsx("button",{type:"button",disabled:!o,onClick:l,"aria-label":s,title:s,className:Ot({variant:"primary",round:!0}),children:e.jsx(z,{name:"arrowUp"})})]})]})}const rh={anthropic:{d:"M4.709 15.955l4.72-2.647.08-.23-.08-.128H9.2l-.79-.048-2.698-.073-2.339-.097-2.266-.122-.571-.121L0 11.784l.055-.352.48-.321.686.06 1.52.103 2.278.158 1.652.097 2.449.255h.389l.055-.157-.134-.098-.103-.097-2.358-1.596-2.552-1.688-1.336-.972-.724-.491-.364-.462-.158-1.008.656-.722.881.06.225.061.893.686 1.908 1.476 2.491 1.833.365.304.145-.103.019-.073-.164-.274-1.355-2.446-1.446-2.49-.644-1.032-.17-.619a2.97 2.97 0 01-.104-.729L6.283.134 6.696 0l.996.134.42.364.62 1.414 1.002 2.229 1.555 3.03.456.898.243.832.091.255h.158V9.01l.128-1.706.237-2.095.23-2.695.08-.76.376-.91.747-.492.584.28.48.685-.067.444-.286 1.851-.559 2.903-.364 1.942h.212l.243-.242.985-1.306 1.652-2.064.73-.82.85-.904.547-.431h1.033l.76 1.129-.34 1.166-1.064 1.347-.881 1.142-1.264 1.7-.79 1.36.073.11.188-.02 2.856-.606 1.543-.28 1.841-.315.833.388.091.395-.328.807-1.969.486-2.309.462-3.439.813-.042.03.049.061 1.549.146.662.036h1.622l3.02.225.79.522.474.638-.079.485-1.215.62-1.64-.389-3.829-.91-1.312-.329h-.182v.11l1.093 1.068 2.006 1.81 2.509 2.33.127.578-.322.455-.34-.049-2.205-1.657-.851-.747-1.926-1.62h-.128v.17l.444.649 2.345 3.521.122 1.08-.17.353-.608.213-.668-.122-1.374-1.925-1.415-2.167-1.143-1.943-.14.08-.674 7.254-.316.37-.729.28-.607-.461-.322-.747.322-1.476.389-1.924.315-1.53.286-1.9.17-.632-.012-.042-.14.018-1.434 1.967-2.18 2.945-1.726 1.845-.414.164-.717-.37.067-.662.401-.589 2.388-3.036 1.44-1.882.93-1.086-.006-.158h-.055L4.132 18.56l-1.13.146-.487-.456.061-.746.231-.243 1.908-1.312-.006.006z",fill:"#D97757",rule:"nonzero"},openai:{d:"M9.205 8.658v-2.26c0-.19.072-.333.238-.428l4.543-2.616c.619-.357 1.356-.523 2.117-.523 2.854 0 4.662 2.212 4.662 4.566 0 .167 0 .357-.024.547l-4.71-2.759a.797.797 0 00-.856 0l-5.97 3.473zm10.609 8.8V12.06c0-.333-.143-.57-.429-.737l-5.97-3.473 1.95-1.118a.433.433 0 01.476 0l4.543 2.617c1.309.76 2.189 2.378 2.189 3.948 0 1.808-1.07 3.473-2.76 4.163zM7.802 12.703l-1.95-1.142c-.167-.095-.239-.238-.239-.428V5.899c0-2.545 1.95-4.472 4.591-4.472 1 0 1.927.333 2.712.928L8.23 5.067c-.285.166-.428.404-.428.737v6.898zM12 15.128l-2.795-1.57v-3.33L12 8.658l2.795 1.57v3.33L12 15.128zm1.796 7.23c-1 0-1.927-.332-2.712-.927l4.686-2.712c.285-.166.428-.404.428-.737v-6.898l1.974 1.142c.167.095.238.238.238.428v5.233c0 2.545-1.974 4.472-4.614 4.472zm-5.637-5.303l-4.544-2.617c-1.308-.761-2.188-2.378-2.188-3.948A4.482 4.482 0 014.21 6.327v5.423c0 .333.143.571.428.738l5.947 3.449-1.95 1.118a.432.432 0 01-.476 0zm-.262 3.9c-2.688 0-4.662-2.021-4.662-4.519 0-.19.024-.38.047-.57l4.686 2.71c.286.167.571.167.856 0l5.97-3.448v2.26c0 .19-.07.333-.237.428l-4.543 2.616c-.619.357-1.356.523-2.117.523zm5.899 2.83a5.947 5.947 0 005.827-4.756C22.287 18.339 24 15.84 24 13.296c0-1.665-.713-3.282-1.998-4.448.119-.5.19-.999.19-1.498 0-3.401-2.759-5.947-5.946-5.947-.642 0-1.26.095-1.88.31A5.962 5.962 0 0010.205 0a5.947 5.947 0 00-5.827 4.757C1.713 5.447 0 7.945 0 10.49c0 1.666.713 3.283 1.998 4.448-.119.5-.19 1-.19 1.499 0 3.401 2.759 5.946 5.946 5.946.642 0 1.26-.095 1.88-.309a5.96 5.96 0 004.162 1.713z",fill:"currentColor",rule:"evenodd"},cursor:{d:"M22.106 5.68L12.5.135a.998.998 0 00-.998 0L1.893 5.68a.84.84 0 00-.419.726v11.186c0 .3.16.577.42.727l9.607 5.547a.999.999 0 00.998 0l9.608-5.547a.84.84 0 00.42-.727V6.407a.84.84 0 00-.42-.726zm-.603 1.176L12.228 22.92c-.063.108-.228.064-.228-.061V12.34a.59.59 0 00-.295-.51l-9.11-5.26c-.107-.062-.063-.228.062-.228h18.55c.264 0 .428.286.296.514z",fill:"currentColor",rule:"evenodd"}},lh={claude:"anthropic",codex:"openai",cursor:"cursor"};function oh({harness:t,size:n=14}){const{d:s,fill:a,rule:r}=rh[lh[t]];return e.jsx("svg",{className:`harness-${t} inline-block flex-none`,width:n,height:n,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:s,fill:a,fillRule:r})})}function jl(t){const n=u.limits;switch(t.kind){case"five_hour":return n.five;case"seven_day":return n.week;case"month":return n.month;case"pool":return t.pool==="other"?n.poolOther:n.poolCursor;default:return n.model(t.model??"")}}const ih={"":"",amber:"bg-attention",red:"bg-approval"},ch={"":"",amber:"text-attention",red:"text-approval"};function dh({pct:t,alert:n}){const s=za(t,n);return e.jsx("span",{className:"block h-[5px] overflow-hidden rounded-[2px]",style:{background:"var(--u-track)"},children:e.jsx("span",{className:`block h-full rounded-[2px] ${ih[s]}`,style:{width:`${Math.min(100,t)}%`,...s?{}:{background:"var(--u-gauge)"}}})})}function uh({label:t,w:n,now:s,alert:a,roomy:r=!1}){const l=u.limits,o=za(n.pct,a),c=n.resetsAt?Uc(n.resetsAt,s):null;return e.jsxs("div",{className:`grid ${r?"grid-cols-[58px_minmax(0,1fr)_auto]":"grid-cols-[58px_1fr_128px]"} items-center gap-2 py-[3px] text-small`,children:[e.jsx("span",{children:t}),e.jsx(dh,{pct:n.pct,alert:a}),e.jsxs("span",{className:`${r?"whitespace-nowrap":"truncate"} font-mono text-[12px]`,children:[e.jsx("b",{className:`font-medium ${ch[o]}`,children:u.percent(n.pct)}),c&&e.jsx("small",{className:"ml-1.5 text-[11px] text-muted",children:Cf(n)?n.resetsAt&&hl(n.resetsAt,s)?l.resumesOn(c):l.resumes(c):`↺ ${c}`})]})]})}function mh({usage:t,now:n,alert:s,fresh:a=!0,heading:r=!0}){const l=u.limits,o=Ba(t,n,a);if(!o.length)return null;const c=i=>t[i].harness==="cursor"&&t[i].status==="ok"&&t[i].windows.length===0&&t[i].readAt!==null;return e.jsxs("div",{role:"group","aria-label":l.limitsLabel,className:"flex flex-col",children:[r&&e.jsx("h3",{className:"mt-1 text-meta tracking-[.4px] text-muted",children:l.limits}),o.map((i,x)=>{const d=i.readAt?Hc(n-Date.parse(i.readAt)):null,m=i.status==="stale"||i.status==="unreachable";return e.jsxs("div",{"data-harness":i.harness,className:"flex flex-col",children:[e.jsxs("div",{className:"mt-1.5 mb-0.5 flex items-baseline gap-1.5 text-small font-semibold",children:[e.jsx(oh,{harness:i.harness}),l.harness[i.harness]??i.harness]}),i.status==="loading"&&e.jsx("p",{className:"py-1 text-small text-muted",children:l.loading}),i.status==="expired"&&e.jsx("p",{className:"py-1 text-small text-attention",children:l.notOnPc(l.harness[i.harness]??i.harness)}),i.status==="ok"&&c(x)&&e.jsx("p",{className:"py-1 text-small text-muted",children:l.unread}),i.status!=="loading"&&i.status!=="expired"&&i.windows.length>0&&e.jsx("div",{className:m?"opacity-50":void 0,children:i.windows.map(p=>e.jsx(uh,{label:jl(p),w:p,now:n,alert:s,roomy:!r},`${p.kind}:${p.model??p.pool??""}`))}),i.status==="stale"&&d&&e.jsx("p",{className:"py-1 text-small text-attention",children:l.stale(d)}),i.status==="unreachable"&&e.jsx("p",{className:"py-1 text-small text-attention",children:d?l.unreach(d):l.unreachNever})]},i.harness)})]})}const ld=t=>t.state==="done"||t.state==="refused"||t.state==="dropped",xh=t=>t.owner===im;function yl(t){return[...t].filter(n=>xh(n)&&!ld(n)&&!n.routine).sort((n,s)=>n.at.localeCompare(s.at))}const mr=We({variant:"primary",size:"sm",className:"min-w-[64px] flex-none"}),Js=We({size:"sm",className:"min-w-[64px] flex-none"}),xr="w-full rounded-control border border-line bg-surface px-2.5 py-2 text-body text-fg",Jn=t=>t.replace(/\s*[\r\n]+\s*/g," ").trim();function ph({task:t,store:n,fresh:s}){const a=u.cards.note,r=t.brain,l=f.useId(),[o,c]=f.useState(!1),[i,x]=f.useState(r.fact),[d,m]=f.useState(r.title??r.note),[p,g]=f.useState(r.when??""),[h,N]=f.useState(!1),[k,C]=f.useState(null),j=async M=>{N(!0),C(null);const S=Jn(i),$=M?{yes:M,...S&&S!==r.fact?{text:S}:{},...r.create&&Jn(d)?{title:Jn(d)}:{},...r.create&&Jn(p)?{when:Jn(p)}:{}}:{yes:M},v=await n.answerNote(t.id,$);N(!1),v.status!=="applied"&&C(v.status==="rejected"&&v.reason==="confirm_required"?a.confirmRequired:v.status==="rejected"&&v.reason==="stale"?a.stale:v.status==="cancelled"?a.cancelled:v.status==="expired"?a.expired:a.failed)},y=r.kind==="flag"?a.flag(r.note):r.create?a.create(r.note):a.add(r.note),b=!s||h;return e.jsxs("div",{className:"flex flex-col gap-2 rounded-control bg-raised p-2.5","data-note-proposal":t.id,children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-1.5 text-body",children:[e.jsx(qs,{tone:"attention",label:a.tag}),e.jsx("span",{className:"font-medium",children:t.giverName??u.cards.someone}),e.jsx("span",{className:"text-muted",children:y})]}),r.create&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{htmlFor:`${l}t`,className:"flex flex-col gap-1 text-small text-muted",children:[a.titleField,e.jsx("input",{id:`${l}t`,className:xr,value:d,disabled:b,onChange:M=>m(M.target.value)})]}),e.jsxs("label",{htmlFor:`${l}w`,className:"flex flex-col gap-1 text-small text-muted",children:[a.whenField,e.jsx("input",{id:`${l}w`,className:xr,value:p,disabled:b,onChange:M=>g(M.target.value)})]})]}),o?e.jsxs("label",{htmlFor:`${l}f`,className:"flex flex-col gap-1 text-small text-muted",children:[a.field,e.jsx("textarea",{id:`${l}f`,className:xr,rows:3,value:i,disabled:b,onChange:M=>x(M.target.value)})]}):e.jsx("p",{className:"m-0 whitespace-pre-wrap break-words rounded-control bg-surface px-2.5 py-2 text-body",children:r.fact}),r.source&&!o&&e.jsx("span",{className:"break-words text-small text-muted",children:a.source(r.source)}),k&&e.jsx("p",{role:"alert",className:"m-0 text-small text-approval",children:k}),e.jsx("div",{className:"flex flex-wrap gap-2",children:r.kind==="flag"?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:mr,disabled:b,onClick:()=>{j(!0)},children:a.mark}),e.jsx("button",{type:"button",className:Js,disabled:b,onClick:()=>{j(!1)},children:a.ignore})]}):o?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:mr,disabled:b||!Jn(i),onClick:()=>{j(!0)},children:a.editYes}),e.jsx("button",{type:"button",className:Js,disabled:b,onClick:()=>{c(!1),x(r.fact)},children:a.cancel})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:mr,disabled:b,onClick:()=>{j(!0)},children:r.create?a.createYes:a.yes}),e.jsx("button",{type:"button",className:Js,disabled:b,onClick:()=>c(!0),children:a.edit}),e.jsx("button",{type:"button",className:Js,disabled:b,onClick:()=>{j(!1)},children:a.no})]})})]})}const Mo=t=>We({variant:t,block:!0}),fh=3e3,hh=(t,n)=>yl(t).filter(s=>s.giver===n);function Eo({store:t,session:n,tasks:s,sent:a,onSent:r}){var _;const l=me(t),o=xn(),c=u.decide,i=u.cards,x=f.useId(),d=r;f.useEffect(()=>{if(a===null)return;const L=setTimeout(()=>r(null),fh);return()=>clearTimeout(L)},[a,r]);const m=s[0],[p,g]=f.useState(""),[h,N]=f.useState(!1),[k,C]=f.useState(null);if(f.useEffect(()=>{g(""),C(null)},[m==null?void 0:m.id]),!(a??(m==null?void 0:m.id)))return null;const y=(m==null?void 0:m.giverName)??n.name,b=(L,T)=>e.jsxs("span",{className:"flex flex-wrap items-center gap-1.5 text-body",children:[e.jsx(qs,{tone:"attention",label:L}),e.jsx("span",{className:"font-medium",children:y}),e.jsx("span",{className:"text-muted",children:T}),s.length>1&&!a&&e.jsx("span",{className:"ml-auto text-small text-muted",children:c.ofN(1,s.length)})]}),M=L=>e.jsx("footer",{"aria-label":i.decision,className:"flex flex-none flex-col gap-2.5 border-t border-line bg-bg pt-3 pb-4",children:L}),S=!(((_=l.device)==null?void 0:_.confirm)===!0&&o),$=e.jsxs(e.Fragment,{children:[e.jsx(De,{title:i.note.confirmRequired,tone:"warning",role:"alert"}),e.jsx("a",{href:ce({name:"connection"}),className:Mo(),children:c.openSettings})]}),v=!l.fresh&&e.jsx(De,{title:c.offlineHint,tone:"warning",role:"status"});if(a!==null){const L=l.tasks.get(a);return M(e.jsxs(e.Fragment,{children:[b(i.decision,i.asks),L&&e.jsx("b",{className:"text-title font-semibold",children:L.title}),e.jsxs("p",{role:"status",className:"flex items-center gap-2 rounded-control border border-ok/40 px-3 py-2.5 text-body",children:[e.jsx(z,{name:"check",className:"size-4 text-ok"}),c.sent((L==null?void 0:L.giverName)??y)]})]}))}if(!m)return null;if(m.brain){const L=m;if(S){const T=L.brain;return M(e.jsxs(e.Fragment,{children:[b(i.note.tag,T.kind==="flag"?i.note.flag(T.note):T.create?i.note.create(T.note):i.note.add(T.note)),e.jsxs("p",{className:"text-body",children:["« ",T.fact," »"]}),T.source&&e.jsx("span",{className:"text-small text-muted",children:i.note.source(T.source)}),$]}))}return M(e.jsxs(e.Fragment,{children:[s.length>1&&e.jsx("span",{className:"self-end text-small text-muted",children:c.ofN(1,s.length)}),e.jsx(ph,{task:L,store:t,fresh:l.fresh},m.id),v||e.jsx("p",{className:"text-center text-meta text-muted",children:u.sessionEnd.check})]}))}const A=async()=>{const L=p.trim();if(!L||h)return;N(!0),C(null);const T=await t.answerTask(m.id,L);if(N(!1),T.status==="applied"){d(m.id);return}C(T.status==="rejected"&&(T.reason==="stale"||T.reason==="not_found")?"stale":T.status==="cancelled"?"cancelled":T.status==="expired"?"expired":"failed")},R=k==="stale"?e.jsx(De,{title:u.gone.titleElsewhere,tone:"warning",role:"alert"}):k?e.jsx(De,{title:k==="cancelled"?u.confirm.cancelled:k==="expired"?u.confirm.expired:i.note.failed,tone:"warning",role:"alert"}):null;return M(e.jsxs(e.Fragment,{children:[b(i.decision,i.asks),e.jsx("b",{className:"text-title font-semibold",children:m.title}),m.text&&e.jsx("p",{className:"text-body whitespace-pre-wrap text-muted",children:m.text}),S?$:k==="stale"?R:e.jsxs(e.Fragment,{children:[e.jsx("label",{htmlFor:x,className:"sr-only",children:i.answerLabel(m.title)}),e.jsx("textarea",{id:x,rows:2,value:p,disabled:h||!l.fresh,placeholder:u.cards.answerPlaceholder,onChange:L=>g(L.target.value),className:"w-full resize-none rounded-control border border-line bg-surface px-3 py-2.5 text-body text-fg"}),R,v,e.jsx("button",{type:"button",disabled:h||!l.fresh||!p.trim(),onClick:()=>{A()},className:Mo("primary"),children:c.send}),!v&&e.jsx("p",{className:"text-center text-meta text-muted",children:u.sessionEnd.check})]})]}))}const gh=new RegExp("(?<code>`[^`\\n]+`)|\\*\\*(?<b>\\S(?:.*?\\S)?)\\*\\*(?!\\*)|(?<![\\w*])\\*(?<i>[^\\s*](?:[^*\\n]*?[^\\s*])?)\\*(?![\\w*])","g"),Nl=f.createContext(void 0);function un(t,n=0,s){let a=0;const r=c=>s?[e.jsx(f.Fragment,{children:s(c)},`t${a++}`)]:[c];if(n>2)return r(t);const l=[];let o=0;for(const c of t.matchAll(gh)){const i=c.index;i>o&&l.push(...r(t.slice(o,i)));const x=c.groups;x.code?l.push(e.jsx("code",{className:"rounded-md bg-fg/[0.06] px-[5px] py-px font-mono text-[.92em] [overflow-wrap:anywhere]",children:x.code.slice(1,-1)},i)):x.b?l.push(e.jsx("strong",{className:"font-semibold",children:un(x.b,n+1,s)},i)):l.push(e.jsx("em",{children:un(x.i,n+1,s)},i)),o=i+c[0].length}return o<t.length&&l.push(...r(t.slice(o))),l}function od({b:t}){const n=f.useContext(Nl);switch(t.type){case"p":return e.jsx("p",{className:"[&+*]:mt-2.5",children:un(t.text,0,n)});case"code":return e.jsx("pre",{className:"my-2.5 overflow-x-auto rounded-lg bg-well p-2.5 font-mono text-small leading-[1.6] whitespace-pre",children:t.text});case"list":{const s=t.ordered?"ol":"ul";return e.jsx(s,{className:`my-2.5 flex flex-col gap-1 pl-[18px] text-fg/80 ${t.ordered?"list-decimal":"list-disc"}`,children:t.items.map((a,r)=>e.jsxs("li",{children:[a.checked!==void 0&&e.jsx("span",{"aria-hidden":"true",children:a.checked?"☑ ":"☐ "}),un(a.text,0,n),a.sub.length>0&&e.jsx("ul",{className:"mt-1 flex list-[circle] flex-col gap-1 pl-4",children:a.sub.map((l,o)=>e.jsx("li",{children:un(l,0,n)},o))})]},r))})}case"table":return e.jsx("div",{className:"my-2.5 overflow-x-auto",tabIndex:0,children:e.jsxs("table",{className:"w-full border-collapse text-small",children:[e.jsx("thead",{children:e.jsx("tr",{children:t.header.map((s,a)=>e.jsx("th",{className:"border-b border-line px-2 py-1.5 font-semibold",style:{textAlign:t.align[a]??"left"},children:un(s,0,n)},a))})}),e.jsx("tbody",{children:t.rows.map((s,a)=>e.jsx("tr",{children:s.map((r,l)=>e.jsx("td",{className:"border-b border-line px-2 py-1.5 align-top",style:{textAlign:t.align[l]??"left"},children:un(r,0,n)},l))},a))})]})});case"quote":return e.jsx("blockquote",{className:"my-2.5 border-l-2 border-line pl-3 text-muted",children:t.blocks.map((s,a)=>e.jsx(od,{b:s},a))})}}function bh({s:t}){const n=f.useContext(Nl),s=t.blocks.map((a,r)=>e.jsx(od,{b:a},r));return t.kind==="next"?e.jsxs("div",{className:"mt-3 rounded-[10px] border border-info/[0.13] bg-info/[0.03] p-3",children:[e.jsx("div",{className:"mb-1.5 text-meta font-medium tracking-[.5px] text-info uppercase",children:u.thread.suggestion}),s]}):e.jsxs("section",{className:"mt-2.5",children:[t.title&&e.jsx("h3",{className:"mb-1 text-body font-semibold",children:un(t.title,0,n)}),s]})}function jh({doc:t,plain:n}){return e.jsxs(Nl.Provider,{value:n,children:[t.title&&e.jsx("strong",{className:"block text-body font-semibold",children:un(t.title,0,n)}),t.lead&&e.jsx("p",{className:"mt-1.5",children:un(t.lead,0,n)}),t.sections.map((s,a)=>e.jsx(bh,{s},a))]})}const At=u.thread.rig,yh="inline-flex items-center gap-1 whitespace-nowrap text-small text-muted",Nh="inline-flex items-center gap-1 whitespace-nowrap text-small font-medium text-fg",id="mt-1.5 rounded-[6px] border border-line bg-well px-2.5 py-2 font-mono text-meta whitespace-pre-wrap text-muted [overflow-wrap:anywhere]",Ha=()=>e.jsx("div",{className:"text-meta text-muted",children:u.thread.cut});function kh({session:t}){const n=Gn(),s=t.state==="exited"?"done":t.state==="waiting_input"?"question":t.state==="waiting_permission"?"approval":t.state;return e.jsx("span",{className:"inline-flex flex-none","aria-hidden":"true",children:e.jsx(Da,{tool:t.tool,seed:t.id,state:s,pose:Oa(t.id,s),size:16,theme:n,frozen:!0})})}function vh({lead:t,who:n,children:s}){return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 text-meta leading-5 font-medium text-muted",children:[e.jsx("span",{children:t}),n.session&&e.jsx(kh,{session:n.session}),e.jsx("strong",{className:"font-semibold text-fg",children:n.name}),n.seat&&e.jsx("span",{className:"font-mono font-normal",children:n.seat}),s]})}function Ks(t){const[n,s]=f.useState(!1),a=t&&e.jsx("button",{type:"button","aria-expanded":n,onClick:()=>s(l=>!l),className:yh,children:t.label}),r=t&&n&&e.jsx("pre",{className:id,children:t.text});return{toggle:a,box:r}}function wh({e:t,storage:n}){const{toggle:s,box:a}=Ks(t.raw),r=t.dir==="out",l=t.delivery&&At.sent[t.delivery];return e.jsxs("div",{className:`flex flex-col gap-1 ${r?"items-end":"items-start"}`,children:[e.jsxs("article",{"aria-label":r?`${At.to} ${t.who.name}`:`${At.from} ${t.who.name}`,className:`flex max-w-[92%] min-w-0 flex-col gap-1 px-3.5 py-2.5 ${r?"rounded-2xl rounded-br-[4px] bg-raised":"rounded-2xl rounded-bl-[4px] border border-line bg-surface"}`,children:[e.jsxs(vh,{lead:r?At.to:At.from,who:t.who,children:[t.count&&e.jsx("span",{className:"inline-flex h-[18px] items-center rounded-full bg-attention/12 px-1.5 text-[10.5px] text-attention",children:At.twice(t.count)}),r&&l&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:t.delivery==="failed"?"text-attention":"",children:l})]})]}),e.jsx("div",{className:"text-body whitespace-pre-wrap [overflow-wrap:anywhere]",children:t.text}),(t.reply||s)&&e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-3",children:[t.reply&&e.jsxs("a",{href:ce({name:"thread",sessionId:t.reply.sessionId}),onClick:()=>qf(t.reply.sessionId,t.reply.draft,n),"aria-label":At.replyTo(t.who.name),className:Nh,children:[e.jsx(z,{name:"reply",className:"size-3.5"}),At.reply]}),s]}),a]}),t.cut&&e.jsx(Ha,{})]})}const _o="inline-flex h-5 items-center rounded-full px-2 text-meta font-medium whitespace-nowrap",Sh={pending:"bg-raised text-muted",taken:"bg-[var(--status-info-soft)] text-info",passed:"bg-task/14 text-task",blocked:"bg-[var(--status-warning-soft)] text-attention",done:"bg-[var(--status-success-soft)] text-ok",unknown:"border border-dashed border-line text-muted"};function Ch(t){const[n,s]=f.useState(typeof IntersectionObserver>"u");return f.useEffect(()=>{const a=t.current;if(!a||typeof IntersectionObserver>"u")return;const r=new IntersectionObserver(l=>s(l.some(o=>o.isIntersecting)));return r.observe(a),()=>r.disconnect()},[t]),n}function $h(t,n,s){var o,c;const a=me(t),r=((o=a.daemon)==null?void 0:o.rigRows)===!0,l=!!n&&s&&r&&a.fresh;return f.useEffect(()=>{if(!l)return;t.requestRigRow(n);const i=setInterval(()=>t.requestRigRow(n),cm);return()=>clearInterval(i)},[l,t,n]),n&&r?(c=a.rigRows[n])==null?void 0:c.row:void 0}function Mh({e:t,store:n}){const{toggle:s,box:a}=Ks(t.raw),r=f.useRef(null),l=Ch(r),o=$h(n,t.qitem,l),c=t.refused?null:Ep(o,t.outgoing),i=t.refused?t.refused.log:c==null?void 0:c.log;return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("section",{ref:r,"aria-label":t.outgoing?At.rowOut(t.who.name):At.rowIn(t.who.name),className:"flex w-full flex-col gap-1.5 rounded-[10px] border border-l-[3px] border-task/35 border-l-task bg-surface px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-small font-medium text-task",children:[e.jsx(z,{name:"task",className:"size-3.5"}),e.jsx("span",{className:"min-w-0 truncate",children:t.outgoing?At.rowOut(t.who.name):At.rowIn(t.who.name)}),e.jsx("span",{className:"flex-1"}),c?e.jsx("span",{"data-state":c.key,className:`${_o} ${Sh[c.key]}`,children:c.text}):e.jsx("span",{"data-state":"refused",className:`${_o} bg-danger-bg text-danger-fg`,children:At.rowState.refused})]}),e.jsx("h4",{className:"line-clamp-2 text-[0.90625rem] leading-[1.3125rem] font-semibold [overflow-wrap:anywhere]",children:t.title}),i&&e.jsx("p",{className:"text-small text-muted [overflow-wrap:anywhere]",children:i}),s&&e.jsxs("div",{className:"flex items-center border-t border-dashed border-line pt-1.5",children:[e.jsx("span",{className:"flex-1"}),s]}),a]}),t.cut&&e.jsx(Ha,{})]})}function cd({e:t}){const{toggle:n,box:s}=Ks(t.raw),a=t.tone==="warn"?"border-l-attention":t.tone==="task"?"border-l-task":"border-l-line";return e.jsxs("div",{role:"note",className:`min-w-0 border-l-2 ${a} py-0.5 pl-2.5 text-small leading-5 text-muted`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:`text-[10px] font-medium tracking-[.04em] uppercase ${t.tone==="task"?"text-task":""}`,children:At.openrig}),e.jsx("span",{className:`min-w-0 font-medium [overflow-wrap:anywhere] ${t.tone==="warn"?"text-attention":"text-fg"}`,children:t.title}),e.jsx("span",{className:"flex-1"}),n]}),s,t.cut&&e.jsx(Ha,{})]})}function Eh({e:t}){const[n,s]=f.useState(!1);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("button",{type:"button","aria-expanded":n,onClick:()=>s(a=>!a),className:"flex items-center gap-1.5 py-0.5 text-left text-small text-muted",children:[e.jsx("span",{className:`inline-flex transition-transform motion-reduce:transition-none ${n?"rotate-90":""}`,children:e.jsx(z,{name:"chevron",className:"size-3.5"})}),e.jsx("strong",{className:"font-medium text-fg",children:At.folded(t.notices.length)})]}),n&&t.notices.map(a=>e.jsx(cd,{e:a},a.key))]})}function _h({e:t}){return e.jsxs("div",{className:"flex flex-col gap-1 border-l-2 border-dashed border-line pl-2.5",children:[e.jsx("div",{className:"text-meta leading-5 font-medium text-muted",children:At.unreadable}),e.jsx("pre",{className:id.replace("mt-1.5 ",""),children:t.text}),t.cut&&e.jsx(Ha,{})]})}function Rh({e:t}){const{toggle:n,box:s}=Ks(t.raw);return e.jsxs("div",{className:"-mt-2 flex flex-col items-start",children:[n,s&&e.jsx("div",{className:"w-full",children:s})]})}function Th({e:t,storage:n,store:s}){switch(t.kind){case"rig-message":return e.jsx(wh,{e:t,storage:n});case"rig-task":return e.jsx(Mh,{e:t,store:s});case"rig-notice":return e.jsx(cd,{e:t});case"rig-fold":return e.jsx(Eh,{e:t});case"rig-unreadable":return e.jsx(_h,{e:t});case"rig-raw":return e.jsx(Rh,{e:t})}}const fn=u.thread.task,Ah={killed:{tone:"attention",text:"text-attention",icon:"stop"},completed:{tone:"ok",text:"text-ok",icon:"check"},failed:{tone:"danger",text:"text-danger-fg",icon:"close"},other:{tone:"muted",text:"text-muted",icon:"task"}};function Ih({task:t,cut:n}){const{toggle:s,box:a}=Ks({label:fn.raw,text:t.raw}),r=Ah[t.status],l=fn.statuses[t.status],{about:o}=t,c=(o==null?void 0:o.kind)==="command"?o.code:void 0,i=[c!==void 0?fn.code(c):null,t.output??null].filter(Boolean).join(" · ");return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("section",{"aria-label":fn.label(l),"data-status":t.status,className:"flex w-full flex-col gap-1.5 rounded-[10px] border border-line bg-surface px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(z,{name:r.icon,className:`size-3.5 ${r.text}`}),e.jsx("span",{className:"text-meta font-medium tracking-[.04em] text-muted uppercase",children:fn.kicker}),e.jsx("span",{className:"flex-1"}),e.jsx(qs,{tone:r.tone,label:l})]}),e.jsx("p",{className:"text-body [overflow-wrap:anywhere]",children:(o==null?void 0:o.kind)==="agent"?e.jsxs(e.Fragment,{children:[fn.agent," ",e.jsx("strong",{className:"font-semibold",children:o.name})," ",fn.agentDid[t.status]]}):(o==null?void 0:o.kind)==="command"?e.jsxs(e.Fragment,{children:[fn.command," ",e.jsx("code",{className:"rounded-[4px] bg-fg/[0.05] px-1 font-mono text-[.9em]",children:o.command})," ",fn.commandDid[t.status]]}):t.summary}),i&&e.jsx("p",{className:"font-mono text-meta text-muted [overflow-wrap:anywhere]",children:i}),e.jsxs("div",{className:"flex items-center border-t border-dashed border-line pt-1.5",children:[e.jsx("span",{className:"flex-1"}),s]}),a]}),n&&e.jsx("div",{className:"text-meta text-muted",children:u.thread.cut})]})}function dd(t,n,s,a=!0){const[r,l]=f.useState({key:"",url:null,failed:!1}),o=n?`${n}|${s}`:"";return f.useEffect(()=>{if(!n||!a)return;let c=!0;return t.imageUrl(n,s).then(i=>{c&&l({key:o,url:i,failed:!1})},()=>{c&&l({key:o,url:null,failed:!0})}),()=>{c=!1}},[t,n,s,a,o]),r.key===o&&o!==""?{url:r.url,failed:r.failed}:{url:null,failed:!1}}const Cn=u.images,Lh=1,Oh=4,Dh=120,Fh=t=>Math.min(Oh,Math.max(Lh,t)),Ph={"image/png":"png","image/gif":"gif","image/jpeg":"jpg","image/webp":"webp"};function zh(t,n,s){const[a,r]=f.useState(null);return f.useEffect(()=>{if(r(null),!t||typeof navigator.canShare!="function"||typeof navigator.share!="function")return;let l=!0;return fetch(t).then(o=>o.blob()).then(o=>{const c=new File([o],n,{type:s});l&&navigator.canShare({files:[c]})&&r(c)},()=>{}),()=>{l=!1}},[t,n,s]),a}function Bh({store:t,refs:n,index:s,onIndex:a,onClose:r}){const l=n[s],{url:o,failed:c}=dd(t,l.id,!1),i=`capture-${s+1}.${Ph[l.mime]??"img"}`,x=zh(o,i,l.mime),[d,m]=f.useState(1),[p,g]=f.useState(0),h=f.useRef(new Map),N=f.useRef({pinch0:0,scale0:1,y0:0});f.useEffect(()=>{m(1),g(0),h.current.clear()},[s]);const k=()=>{const[A,R]=[...h.current.values()];return A&&R?Math.hypot(A.x-R.x,A.y-R.y):0},C=A=>{var R,_;h.current.set(A.pointerId,{x:A.clientX,y:A.clientY}),(_=(R=A.currentTarget).setPointerCapture)==null||_.call(R,A.pointerId),h.current.size===2?N.current={...N.current,pinch0:k(),scale0:d}:N.current={...N.current,y0:A.clientY}},j=A=>{h.current.has(A.pointerId)&&(h.current.set(A.pointerId,{x:A.clientX,y:A.clientY}),h.current.size===2?N.current.pinch0>0&&m(Fh(N.current.scale0*k()/N.current.pinch0)):d===1&&g(A.clientY-N.current.y0))},y=A=>{if(h.current.delete(A.pointerId)&&h.current.size===0){if(d===1&&Math.abs(p)>Dh){r();return}g(0)}},b=f.useRef(null);Kc(b,r);const M=()=>{x&&navigator.share({files:[x]}).catch(()=>{})},S=A=>A.stopPropagation(),$="inline-flex min-h-11 items-center rounded-full bg-white/15 px-4 text-body font-medium text-white",v=(A,R,_,L)=>A>=0&&A<n.length&&e.jsx("button",{type:"button","aria-label":R,title:R,onPointerDown:S,onClick:()=>a(A),className:`absolute top-1/2 ${_} grid size-11 -translate-y-1/2 place-items-center rounded-full bg-white/15 text-white`,children:e.jsx("svg",{className:"size-5 fill-none stroke-current [stroke-linecap:round] [stroke-linejoin:round] [stroke-width:1.6]",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:L})})});return dl.createPortal(e.jsxs("div",{ref:b,role:"dialog","aria-modal":"true","aria-label":Cn.view,tabIndex:-1,className:"fixed inset-0 z-50 flex flex-col bg-black/90 text-white outline-none",style:{opacity:p?Math.max(.4,1-Math.abs(p)/400):1},children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsxs("span",{className:"min-w-0 flex-1 text-small text-white/70",children:[l.width,"×",l.height,n.length>1?` · ${s+1}/${n.length}`:""]}),x&&e.jsx("button",{type:"button",onPointerDown:S,onClick:M,className:$,children:Cn.share}),o&&e.jsx("a",{href:o,download:i,onPointerDown:S,className:$,children:Cn.save}),e.jsx("button",{type:"button","aria-label":Cn.close,title:Cn.close,onPointerDown:S,onClick:r,className:"grid size-11 place-items-center rounded-full bg-white/15",children:e.jsx("svg",{className:"size-5 fill-none stroke-current [stroke-linecap:round] [stroke-width:1.8]",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"M6 6l12 12M18 6 6 18"})})})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1 items-center justify-center overflow-hidden",style:{touchAction:"none"},onPointerDown:C,onPointerMove:j,onPointerUp:y,onPointerCancel:y,children:[o&&e.jsx("img",{src:o,alt:"",draggable:!1,className:"max-h-full max-w-full select-none object-contain",style:{transform:`translateY(${p}px) scale(${d})`,transition:h.current.size?"none":"transform .15s"}}),!o&&e.jsx("p",{role:"status",className:"text-body text-white/70",children:c?Cn.unavailable:"…"}),v(s-1,Cn.prev,"left-3","m15 18-6-6 6-6"),v(s+1,Cn.next,"right-3","m9 18 6-6-6-6")]})]}),document.body)}const Ro=u.images;function qh({store:t,image:n,onOpen:s}){const[a,r]=f.useState(typeof IntersectionObserver>"u"),l=f.useRef(null);f.useEffect(()=>{if(a||!l.current)return;const i=new IntersectionObserver(x=>{x.some(d=>d.isIntersecting)&&(r(!0),i.disconnect())});return i.observe(l.current),()=>i.disconnect()},[a]);const{url:o,failed:c}=dd(t,n.id,!0,a&&n.preview);return n.preview?e.jsx("div",{ref:l,className:"max-w-full",children:e.jsx(eh,{url:o,failed:c,width:n.width,height:n.height,maxW:240,maxH:240,alt:"",unavailable:Ro.unavailable,onOpen:s})}):e.jsx("p",{className:"max-w-full rounded-lg border border-line bg-surface p-2.5 text-small text-muted",children:Ro.noPreview})}function To({store:t,refs:n,align:s="start"}){const[a,r]=f.useState(null);return n.length===0?null:e.jsxs("div",{"data-thumbs":!0,className:`flex max-w-full flex-wrap gap-2 ${s==="end"?"justify-end":""}`,children:[n.map((l,o)=>e.jsx(qh,{store:t,image:l,onOpen:()=>r(o)},`${l.id}:${o}`)),a!==null&&e.jsx(Bh,{store:t,refs:n,index:a,onIndex:r,onClose:()=>r(null)})]})}const es=u.images;let Hh=0;const Uh=t=>`data:${t.mime};base64,${t.data}`;function Wh(t){const[n,s]=f.useState([]),[a,r]=f.useState(0),[l,o]=f.useState(null),c=f.useRef([]),i=f.useRef(0),x=f.useRef(!0);f.useEffect(()=>(x.current=!0,()=>{x.current=!1}),[]);const d=y=>{c.current=y,s(y)},m=(y,b)=>{x.current&&d(c.current.map(M=>M.item.key===y?{...M,...b,item:{...M.item,...b.item}}:M))},p=y=>{i.current+=y,r(i.current)},g=async y=>{const b=await Xf(y);if(p(-1),!x.current)return;if(!b.ok){o(b.reason==="tooLarge"?es.tooLarge:es.notImage);return}const{image:M,width:S,height:$,bytes:v}=b.value,A=`att-${Hh++}`;d([...c.current,{item:{key:A,url:Uh(M.preview??M),width:S,height:$,bytes:v,state:"uploading"}}]);try{const R=await t.putImage(M);m(A,{id:R.id,item:{state:"ready"}})}catch(R){const _=R instanceof Error&&R.message==="too_large"?es.tooLarge:R instanceof Error&&R.message==="not_image"?es.notImage:es.failed;m(A,{item:{state:"refused",reason:_}}),x.current&&o(_)}},h=y=>{if(y.length!==0){o(null);for(const b of y){if(c.current.length+i.current>=Wl){o(es.max);return}p(1),g(b)}}},N=y=>{const b=c.current.find(M=>M.item.key===y);d(c.current.filter(M=>M.item.key!==y)),(b==null?void 0:b.item.state)==="refused"&&o(null)},k=()=>{const y=c.current;return d([]),o(null),y},C=y=>{x.current&&d([...y,...c.current].slice(0,Wl))},j=n.map(y=>y.item);return{items:j,add:h,remove:N,clear:k,putBack:C,error:l,ready:a===0&&j.every(y=>y.state==="ready"),ids:()=>c.current.filter(y=>y.item.state==="ready"&&y.id).map(y=>y.id)}}const ud=`${Nn}launch.started`;function md(t){var n;try{const s=JSON.parse(((n=Ze(t))==null?void 0:n.getItem(ud))??"[]");return Array.isArray(s)?s.filter(a=>typeof(a==null?void 0:a.id)=="string"&&typeof(a==null?void 0:a.project)=="string"):[]}catch{return[]}}function Kh(t,n,s){var r;const a=[...md(s).filter(l=>l.id!==t),{id:t,project:n}].slice(-50);try{(r=Ze(s))==null||r.setItem(ud,JSON.stringify(a))}catch{}}const Vh=(t,n)=>{var s;return((s=md(n).find(a=>a.id===t))==null?void 0:s.project)??null};function Gh(t){const n=/^\/(\S*)$/.exec(t);return n?n[1].toLowerCase():null}function Xh(t,n){var r;const s=n.toLowerCase(),a=[];for(const l of t){const o=[l.name,...l.aliases??[]],c=o.map(h=>h.toLowerCase());let i=-1,x=l.name,d=-1;const m=c.indexOf(s),p=c.findIndex(h=>h.startsWith(s)),g=c.findIndex(h=>h.includes(s));m>=0&&s?(i=0,x=o[m],d=0):p>=0?(i=1,x=o[p],d=0):g>=0?(i=2,x=o[g],d=c[g].indexOf(s)):(r=l.description)!=null&&r.toLowerCase().includes(s)&&(i=3),!(i<0)&&(x!==l.name&&l.name.toLowerCase().startsWith(s)&&(x=l.name,d=0),a.push({command:l,shown:x,at:s?d:-1,rank:i}))}return a.sort((l,o)=>l.rank-o.rank||+!!l.command.blocked-+!!o.command.blocked||l.shown.localeCompare(o.shown)).map(({rank:l,...o})=>o)}function Yh(t,n){const s=/^\/(\S+)/.exec(t.trimStart());if(!s)return;const a=s[1].toLowerCase();return n.find(r=>{var l;return r.name.toLowerCase()===a||((l=r.aliases)==null?void 0:l.some(o=>o.toLowerCase()===a))})}const Qh=t=>`/${t.name} `,Pn=u.thread.slash;function Zh({listing:t,query:n,matches:s,tool:a,name:r,onPick:l}){const o="mb-2 overflow-hidden rounded-2xl border border-line bg-surface";return t?t.error?e.jsx("div",{className:`${o} px-3 py-3 text-meta text-muted`,role:"status",children:Pn.unavailable(r)}):s.length===0?e.jsx("div",{className:`${o} px-3 py-3 text-meta text-muted`,role:"status",children:Pn.none(`/${n}`,r)}):e.jsxs("div",{className:o,children:[e.jsx("p",{className:"px-3 pt-2 pb-1 text-meta text-muted",children:Pn.count(a,s.length)}),e.jsx("ul",{"aria-label":Pn.label(a),className:"max-h-[300px] overflow-y-auto overscroll-contain px-1 pb-1",children:s.map(c=>{const i=c.command,x=i.blocked!==void 0,d=n.length,m=Pn.source[i.source];return e.jsx("li",{className:"border-t border-line first:border-t-0",children:e.jsxs("button",{type:"button",disabled:x,onMouseDown:p=>p.preventDefault(),onClick:()=>l(i),className:"flex min-h-[52px] w-full flex-col justify-center rounded-[10px] px-2.5 py-1.5 text-left enabled:active:bg-raised",children:[e.jsxs("span",{className:`font-mono text-[14px] leading-5 ${x?"text-muted":""}`,children:["/",c.at>=0&&d>0?e.jsxs(e.Fragment,{children:[c.shown.slice(0,c.at),e.jsx("mark",{className:"bg-transparent font-semibold text-fg underline underline-offset-2",children:c.shown.slice(c.at,c.at+d)}),c.shown.slice(c.at+d)]}):c.shown,i.argumentHint&&e.jsxs("span",{className:"text-[12px] text-muted",children:[" ",i.argumentHint]}),m&&e.jsx("span",{className:`ml-1.5 font-sans text-[10.5px] ${i.source==="project"?"text-info":"text-muted"}`,children:m})]}),e.jsx("span",{className:`truncate text-[12px] leading-4 ${x?"text-attention":"text-muted"}`,children:x?Pn.blocked[i.blocked]:i.description})]})},i.name)})})]}):e.jsx("div",{className:`${o} px-3 py-3 text-meta text-muted`,role:"status",children:Pn.loading(a)})}const Jh={ok:"text-ok",info:"text-info",approval:"text-approval",attention:"text-attention",muted:"text-muted"},Tt=u.thread.composer;function xd(t){const n=t.trim();return n.length>Ra?"long":Ii.test(n)?"untypable":null}function eg(t){if(t.phase==="uncertain"||t.reason==="not_taken")return{title:Tt.uncertainTitle,body:Tt.uncertain};const n=t.reason==="busy"?Tt.busy:t.reason==="invalid"?Tt.invalid(Ra):t.reason==="untypable"?Tt.untypable:t.reason==="read_only"?Tt.readOnly:t.reason==="attachment_missing"?Tt.imageGone:t.reason==="attachments_not_accepted"?u.images.dialog:Tt.lost;return{title:Tt.failTitle,body:n}}function tg({name:t,focusAtEnd:n=!1,composer:s,draft:a,onDraft:r,onSend:l,fresh:o,taken:c,checking:i,error:x,alert:d,onReconnect:m,images:p,dialog:g,lead:h,leadNote:N,slash:k}){var E,P;const[C,j]=xs(),y=c?{tone:"ok",label:Tt.status.taken}:i?{tone:"muted",label:u.decide.checking}:s.status,b=xd(a),M=f.useRef(null),S=p.items.length>0;f.useEffect(()=>{const W=M.current;!n||!W||(W.focus(),W.setSelectionRange(W.value.length,W.value.length))},[]);const $=k&&s.enabled&&!g?Gh(a):null,v=$!==null;f.useEffect(()=>{v&&(k==null||k.ask())},[v]);const A=(E=k==null?void 0:k.listing)!=null&&E.error?[]:((P=k==null?void 0:k.listing)==null?void 0:P.commands)??[],R=f.useMemo(()=>$!==null?Xh(A,$):[],[$,A]),_=k&&!g?Yh(a,A):void 0,L=W=>{var F;r(Qh(W)),(F=M.current)==null||F.focus()},T=!_||$!==null?null:_.blocked?{warn:!0,text:u.thread.slash.blocked[_.blocked]}:_.bare&&/^\/\S+\s*$/.test(a)?{warn:!0,text:u.thread.slash.bare(_.name)}:_.argumentHint?{warn:!1,text:`/${_.name} ${_.argumentHint}`}:null,B=s.enabled&&(!!a.trim()||S)&&b===null&&p.ready&&!(S&&g);return e.jsxs("footer",{className:"flex-none border-t border-line bg-bg pt-2 pb-3 [@media(max-height:650px)]:pb-2",children:[e.jsxs("div",{className:`flex items-center gap-1.5 pb-2 text-meta ${Jh[y.tone]}`,children:[e.jsx("i",{className:"inline-block size-1.5 flex-none rounded-full bg-current"}),y.label]}),d&&e.jsx("div",{className:"mb-2.5",children:d}),!d&&x&&e.jsx("div",{className:"mb-2.5",children:e.jsxs(De,{title:x.title,tone:"warning",role:"alert",children:[e.jsx("p",{children:x.body}),!o&&m&&e.jsx("button",{type:"button",disabled:C,onClick:()=>{j(!0),m()},className:We({block:!0,className:"mt-2"}),children:C?u.link.reconnecting:Tt.reconnect})]})}),v&&e.jsx(Zh,{listing:k.listing,query:$,matches:R,tool:k.tool,name:t,onPick:L}),!v&&(s.enabled||h)&&e.jsxs("div",{role:"group","aria-label":Tt.quickLabel,className:"flex gap-1.5 overflow-x-auto pb-2 [scrollbar-width:none]",children:[h,s.enabled&&Dp.map(W=>e.jsx("button",{type:"button",onClick:()=>{var F;r(W),(F=M.current)==null||F.focus()},className:`${Oi()} whitespace-nowrap`,children:W},W))]}),N,e.jsx(ah,{id:"draft",label:Tt.label(t),sendLabel:Tt.send(t),value:a,onChange:r,onSend:l,canSend:B,oneLine:!0,images:p,placeholder:s.placeholder,disabled:!s.enabled,fieldRef:M,invalid:b!==null,describedBy:b?"draft-problem":void 0}),T&&e.jsx("p",{role:"status",className:`pt-1.5 text-meta ${T.warn?"text-attention":"font-mono text-muted"}`,children:T.text}),S&&g&&e.jsx("p",{role:"status",className:"pt-1.5 text-meta text-attention",children:u.images.dialog}),p.error&&e.jsx("p",{role:"alert",className:"pt-1.5 text-meta text-attention",children:p.error}),b&&e.jsx("p",{id:"draft-problem",role:"status",className:"pt-1.5 text-meta text-attention",children:b==="long"?Tt.tooLong(Ra):Tt.untypable})]})}const Re=u.adopt,ng=4e3;function sg(t,n,s){if(!t)return!1;const a=Bi(s,n.state);return a?a.reason!=="resume_failed"||a.exitCode!==void 0:!!n.readOnly&&(!!n.adopt||!!n.adopting)}function ag({store:t,session:n,onResume:s}){var h;const{adoptFailures:a,adoptLost:r}=me(t),l=r[n.id],[o,c]=f.useState(!1),i=n.name,x=(h=n.adopting)==null?void 0:h.step,d=Bi(a[n.id],n.state),m=()=>{c(!0),t.adopt(n.id).finally(()=>c(!1))},p=e.jsxs("p",{className:"flex items-center gap-1.5 text-meta text-muted",children:[e.jsx("i",{className:"inline-block size-1.5 flex-none rounded-full bg-current"}),u.thread.composer.status.readOnly]});let g;if(x==="attaching"||o&&n.adopt==="pane"&&!x)g=e.jsx(ln,{title:Re.action,body:Re.bodyPane,action:e.jsxs("button",{type:"button",disabled:!0,className:We({variant:"primary",block:!0}),children:[e.jsx(og,{}),Re.attaching]})});else if(x==="waiting"||x==="stopping"||x==="resuming"){const N=x==="waiting"?0:x==="stopping"?1:2;g=e.jsx(ln,{tone:"wait",title:x==="waiting"?Re.waiting(i):x==="stopping"?Re.stopping(i):Re.resuming(i),body:x==="waiting"?Re.waitingBody:x==="stopping"?Re.stoppingBody:Re.resumingBody,extra:e.jsxs(e.Fragment,{children:[e.jsx(lg,{at:N}),x==="waiting"&&(l!=null&&l.cancel)?e.jsx(Ao,{kind:l.kind}):null]}),action:x==="waiting"?e.jsx("button",{type:"button",onClick:()=>void t.adopt(n.id,!0),className:We({variant:"outline",block:!0}),children:Re.cancel}):void 0})}else if(d){const N=e.jsx("button",{type:"button",onClick:m,className:We({variant:"outline",block:!0}),children:Re.retry});switch(d.reason){case"process_gone":g=e.jsx(ln,{tone:"amber",title:Re.gone(i),body:Re.goneBody});break;case"stop_failed":g=e.jsx(ln,{tone:"amber",title:Re.stopFailed(i),body:Re.stopFailedBody,action:N});break;case"pane_not_found":g=e.jsx(ln,{tone:"amber",title:Re.paneNotFound(i),body:Re.paneNotFoundBody(i),action:N});break;case"no_conversation":g=e.jsx(ln,{title:Re.noConversation(i),body:Re.noConversationBody});break;case"resume_failed":g=e.jsx(ln,{tone:"fail",title:Re.resumeFailed(i,Re.exitedOnStart(n.tool,d.exitCode??0)),body:Re.resumeFailedBody,action:e.jsx("button",{type:"button",onClick:s,className:We({variant:"primary",block:!0}),children:Re.resumeHere})});break;default:g=e.jsx(ln,{title:Re.notLocated(i),body:Re.notLocatedBody})}}else if(n.adopt==="not_located")g=e.jsx(ln,{title:Re.notLocated(i),body:Re.notLocatedBody});else{const N=n.state==="exited";g=e.jsx(ln,{title:Re.action,body:N?Re.bodyEnded:n.adopt==="pane"?Re.bodyPane:Re.body,extra:e.jsxs(e.Fragment,{children:[!N&&n.adopt==="resume"&&n.pending?e.jsx("p",{className:"text-attention",children:Re.pendingDropped(i)}):null,l&&!l.cancel?e.jsx(Ao,{kind:l.kind}):null]}),action:e.jsx("button",{type:"button",disabled:o,onClick:m,className:We({variant:"primary",block:!0}),children:Re.action})})}return e.jsxs("footer",{role:"status",className:"flex flex-none flex-col gap-2 border-t border-line bg-bg pt-2.5 pb-3 [@media(max-height:650px)]:pb-2",children:[(d==null?void 0:d.reason)!=="resume_failed"&&p,g]})}function rg({store:t}){var c;const{adoptNotice:n,sessions:s}=me(t),[a,r]=f.useState(null);if(f.useEffect(()=>{if(!n)return;r(n.seq);const i=setTimeout(()=>r(null),ng);return()=>clearTimeout(i)},[n==null?void 0:n.seq]),!n||a!==n.seq)return null;const l=((c=s.get(n.id))==null?void 0:c.name)??n.id,o=n.kind==="done"?Re.done(l):n.kind==="cancelled"?Re.cancelled(l):n.kind==="busy"?Re.busy(l):Re.unsupported;return e.jsx("span",{role:"status",className:"fixed inset-x-3.5 top-14 z-[7] rounded-[12px] border border-line bg-raised px-3 py-2 text-[12px] leading-[17px] text-fg shadow-[0_8px_24px_#0004]",children:o})}function Ao({kind:t}){return e.jsx("p",{role:"alert",className:"text-attention",children:t==="failed"?Re.notSent:Re.uncertain})}function ln({tone:t,title:n,body:s,extra:a,action:r}){const l=t==="wait"?"border-[color-mix(in_srgb,var(--primary)_45%,var(--border))]":t==="fail"?"border-[color-mix(in_srgb,var(--destructive)_55%,var(--border))]":t==="amber"?"border-[color-mix(in_srgb,var(--warning)_55%,var(--border))]":"border-line";return e.jsxs("section",{className:`flex flex-col gap-1.5 rounded-card border ${l} bg-surface p-3 text-[12.5px] leading-[18px] text-muted`,children:[e.jsx("strong",{className:"text-body font-semibold text-fg",children:n}),e.jsx("span",{children:s}),a,r&&e.jsx("div",{className:"mt-1",children:r})]})}function lg({at:t}){return e.jsx("div",{className:"mt-1.5 flex items-center gap-1.5 text-[11px] text-muted",children:Re.steps.map((n,s)=>e.jsxs("span",{className:"contents",children:[s>0&&e.jsx("span",{"aria-hidden":"true",className:"h-px w-3.5 bg-line"}),e.jsxs("span",{className:`flex items-center gap-1 ${s===t?"text-fg":""}`,...s===t?{"aria-current":"step"}:{},children:[e.jsx("span",{"aria-hidden":"true",className:`size-2 rounded-full border-[1.5px] ${s<t?"border-ok bg-ok":s===t?"border-primary bg-[color-mix(in_srgb,var(--primary)_40%,transparent)]":"border-line"}`}),n]})]},n))})}function og(){return e.jsx("span",{"aria-hidden":"true",className:"inline-block size-3 animate-spin rounded-full border-2 border-current border-r-transparent motion-reduce:animate-none"})}const He=u.sessionEnd,ks=t=>We({variant:t,block:!0});function pd(t,n,s,a,r){const[l,o]=f.useState(null),[c,i]=f.useState(null),[x,d]=f.useState(!1),[m,p]=f.useState(0),g=f.useRef(!0);return f.useEffect(()=>(g.current=!0,()=>{g.current=!1}),[]),f.useEffect(()=>{if(!a)return;let C=!0,j;return o(null),t.prepareConfirm(n==="terminal"?{purpose:n,id:s}:{purpose:n,id:s}).then(y=>{C&&(o(y),j=setTimeout(()=>{C&&(o(null),i("expired"))},y.expiresInMs))},()=>{C&&i("prepareFailed")}),()=>{C=!1,clearTimeout(j)}},[t,n,s,a,m]),{challenge:l,problem:c,asking:x,needsNew:c==="expired"||c==="failed"||c==="prepareFailed",go:async()=>{if(!a||x||!l)return;if(!l.credentialId){o(null),i("failed");return}d(!0),i(null);const C=await Fs({challenge:l.challenge,rpId:l.rpId,credentialId:l.credentialId}).catch(()=>"failed");if(g.current){if(d(!1),C==="cancelled"){i("cancelled");return}if(C==="failed"){o(null),i("failed");return}o(null),r(C)===null&&i("failed")}},retry:()=>{i(null),p(C=>C+1)}}}function kl({store:t,session:n,mode:s,onClose:a,onSent:r,onReconnect:l}){const{fresh:o,device:c}=me(t),[i,x]=xs(),d=n.name,m=s==="close",p=!!(c!=null&&c.confirm),g=pd(t,m?"close":"act",n.id,o&&p,C=>{const j=m?t.sessionClose(n.id,C):t.sessionResume(n.id,C);return j!==null&&r(),j}),h=m?Pm(n):[],N=g.asking?u.confirm.asking:g.challenge?m?Pt()?He.goCloseApple:He.goClose:Pt()?He.goResumeApple:He.goResume:u.confirm.preparing,k=e.jsx("button",{type:"button",onClick:a,className:ks(),children:He.cancel});return e.jsxs(ht,{labelledBy:"end-title",onClose:a,children:[e.jsx("h2",{id:"end-title",className:"text-heading leading-[1.3] tracking-[-.5px]",children:m?He.closeTitle(d):He.resumeTitle(d)}),o?p?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:m?He.closeBody:He.resumeBody}),h.length>0&&e.jsx(De,{title:He.cutsTitle,tone:"warning",children:e.jsx("ul",{className:"flex list-disc flex-col gap-1 pl-5",children:h.map(C=>e.jsx("li",{children:C},C))})}),g.problem&&e.jsx(De,{title:u.confirm[g.problem],tone:"warning",role:"alert"}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:h.length>0?`${He.force} ${He.check}`:He.check}),g.needsNew?e.jsx("button",{type:"button",onClick:g.retry,className:ks("primary"),children:u.confirm.retry}):e.jsx("button",{type:"button",disabled:g.asking||!g.challenge,onClick:()=>{g.go()},className:ks("primary"),children:N}),k]}):e.jsxs(e.Fragment,{children:[e.jsx(De,{title:He.unprotectedTitle,tone:"warning",role:"status",children:e.jsx("p",{children:m?He.unprotectedClose(d):He.unprotectedResume(d)})}),e.jsx("a",{href:ce({name:"connection"}),className:ks("primary"),children:He.openConnection}),k]}):e.jsxs(e.Fragment,{children:[e.jsx(De,{title:He.offlineTitle,tone:"warning",role:"status",children:e.jsx("p",{children:m?He.offlineClose(d):He.offlineResume(d)})}),l&&e.jsx("button",{type:"button",disabled:i,onClick:()=>{x(!0),l()},className:ks("primary"),children:i?u.link.reconnecting:He.reconnect}),k]})]})}function Io({tone:t,label:n}){return e.jsxs("div",{className:`flex items-center gap-1.5 text-meta ${t==="attention"?"text-attention":"text-info"}`,children:[e.jsx(z,{name:"spinner",className:"size-3 animate-spin motion-reduce:animate-none",stroke:2}),n]})}function fd({error:t,fresh:n,onRetry:s,onReconnect:a}){const[r,l]=xs();return e.jsxs(De,{title:t.title,tone:"warning",role:"alert",children:[e.jsx("p",{children:t.body}),t.retry&&e.jsx("button",{type:"button",onClick:s,className:We({size:"sm",className:"mt-2"}),children:He.retry}),t.reconnect&&!n&&a&&e.jsx("button",{type:"button",disabled:r,onClick:()=>{l(!0),a()},className:We({size:"sm",className:"mt-2"}),children:r?u.link.reconnecting:He.reconnect})]})}function ig({ending:t,name:n,canResume:s,resumeHeld:a=!1,readOnly:r,fresh:l,focus:o,onResume:c,onReconnect:i}){const x=f.useRef(null);return f.useEffect(()=>{var d;o&&((d=x.current)==null||d.focus({preventScroll:!0}))},[o]),e.jsxs("footer",{ref:x,tabIndex:-1,role:"status",className:"flex flex-none flex-col gap-2.5 border-t border-line bg-bg pt-3 pb-3 outline-none [@media(max-height:650px)]:pb-2",children:[t.kind==="closing"&&e.jsxs(e.Fragment,{children:[e.jsx(Io,{tone:"attention",label:He.closing(n)}),e.jsx("p",{className:"text-small text-muted",children:He.closingHint})]}),t.kind==="resuming"&&e.jsx(Io,{tone:"info",label:He.resuming(n)}),t.kind==="ended"&&e.jsxs(e.Fragment,{children:[t.error&&e.jsx(fd,{error:t.error,fresh:l,onRetry:c,onReconnect:i}),e.jsxs("section",{"aria-labelledby":"ended-title",className:"flex flex-col gap-2.5 rounded-card border border-line bg-surface p-4",children:[e.jsx("h2",{id:"ended-title",className:"text-body font-semibold",children:He.ended}),t.killed?e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:He.killed}):!r&&e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:s?He.endedBody:He.endedOnPc}),s&&!r&&e.jsxs("button",{type:"button","aria-disabled":a||void 0,onClick:()=>{a||c()},className:We({variant:t.killed?"outline":"primary",block:!0,className:a?"opacity-45":""}),children:[e.jsx(z,{name:"resume"}),He.resume(n)]})]})]})]})}const hs={ok:"idle",run:"work",fail:"perm",wait:"ask",skip:"plain",none:"off"},ka=t=>t.state!=="merged"&&t.state!=="closed",cg=t=>(t.state==="open"||t.state==="review")&&t.mergeable&&(t.pipeline==="ok"||t.pipeline==="none");function dg(t){return{open:t.filter(ka),closed:t.filter(n=>!ka(n))}}const ug=t=>t.filter(n=>ka(n)&&n.pipeline==="fail").length,mg=t=>t.filter(n=>n.status!=="ok"),hd=t=>t==="github"?"gh":"glab",xg=t=>`${hd(t.forge)} auth login --hostname ${t.host}`;function gd(t){const n=new Map;for(const s of t){const a=n.get(s.column)??{column:s.column,name:s.columnName,jobs:[]};a.jobs.push(s),n.set(s.column,a)}return[...n.values()].sort((s,a)=>s.column-a.column)}const bd=t=>t.find(n=>n.status==="fail")??null;function jd(t){if(t===void 0)return null;const n=Math.round(t);return n<3600?{text:`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`,hours:!1}:{text:`${Math.floor(n/3600)}:${String(Math.floor(n%3600/60)).padStart(2,"0")}`,hours:!0}}const pg=t=>t.startsWith("…"),fg=new Set(["draft","not_open","approvals","changes_requested","pipeline","pipeline_not_started"]);function Ua(t){const{pr:n}=t,s=new Set(t.mergeBlockers),a=Math.max(1,n.approvals.required??0),r=[];s.has("draft")&&r.push({ok:!1,key:"draft"}),s.has("not_open")&&r.push({ok:!1,key:"not_open"}),s.has("approvals")&&r.push({ok:!1,key:"approvals",given:n.approvals.given,required:a}),s.has("changes_requested")&&r.push({ok:!1,key:"changes_requested",who:t.reviewers.filter(l=>l.state==="changes").map(l=>l.name).join(", ")}),s.has("pipeline_not_started")?r.push({ok:!1,key:"pipeline_not_started"}):s.has("pipeline")||n.pipeline!=="ok"&&n.pipeline!=="none"?r.push({ok:!1,key:n.pipeline==="run"?"pipeline_run":n.pipeline==="wait"?"pipeline_wait":n.pipeline==="skip"?"pipeline_skip":"pipeline_fail"}):r.push({ok:!0,key:n.pipeline==="none"?"noCi":"pipeline"});for(const l of s)fg.has(l)||r.push({ok:!1,key:"raw",code:l});return s.has("approvals")||r.push({ok:!0,key:"approved",given:n.approvals.given,required:a}),s.has("changes_requested")||r.push({ok:!0,key:"noChanges"}),r}const hg=t=>(t.pr.state==="open"||t.pr.state==="review")&&Ua(t).every(n=>n.ok),yd=t=>`${t.approvals.given}${t.approvals.required!==void 0?`/${t.approvals.required}`:""}`,zr=(t,n)=>{const s=t.replace(/\.$/,"");return n.key==="changes_requested"||n.key==="raw"?s:s.charAt(0).toLowerCase()+s.slice(1)},gg=t=>t.pipeline==="fail"&&(t.state==="open"||t.state==="review"),bg=t=>t.files.reduce((n,s)=>({added:n.added+s.added,removed:n.removed+s.removed}),{added:0,removed:0}),jg=(t,n)=>t.threads.filter(s=>s.file===n).length,vl=t=>t.slice(0,7);function yg(t,n){if(!t)return null;const s=t.prs.find(l=>ka(l)&&l.sessions.includes(n));if(s)return{pr:s};const a=t.followed.find(l=>l.session===n);if(!a)return null;const r=t.forges.find(l=>l.forge===a.forge&&l.host===a.host);return r&&r.status!=="ok"?{unknown:r,kind:a.forge}:null}const Lo=new Set(["starting","launching","booting"]);function mn(t){return Lo.has(t.status)||Lo.has(t.lifecycleState)?"starting":t.status==="partial"?"partial":t.status==="running"||t.running>0?t.nodes.some(s=>s.stopped)?"partial":"running":"stopped"}const Ng=t=>t!=="stopped",Nd=t=>t.rigs.find(n=>n.name===$s),Oo={running:0,partial:0,starting:0,stopped:1},Br=t=>t.rigs.filter(n=>n.name!==$s).map((n,s)=>({r:n,i:s})).sort((n,s)=>Oo[mn(n.r)]-Oo[mn(s.r)]||n.i-s.i).map(n=>n.r),kd=(t,n,s)=>{var a;for(const r of t)if(((a=r.rig)==null?void 0:a.name)===n&&r.rig.role===s&&r.state!=="exited")return r};function vd(t,n,s){var l;let a=0,r=0;for(const o of n)((l=o.rig)==null?void 0:l.name)!==t||!o.pending||(o.pending.kind==="question"?r+=1:a+=1);for(const o of s??[])o.from.rig===t&&o.kind!=="update"&&(r+=1);return{perm:a,ask:r}}const Vs=t=>t.activity==="running"||t.work>0;function wd(t,n){if(n.perm)return"perm";if(n.ask)return"ask";const s=mn(t);return s==="stopped"?"off":s==="starting"||t.nodes.some(Vs)?"work":"idle"}function wl(t){const{session:n,node:s,graph:a}=t;return t.rigStatus==="stopped"?"off":n?n.pending&&n.pending.kind!=="question"||n.state==="waiting_permission"||n.state==="error"?"perm":n.pending||n.state==="waiting_input"?"ask":n.state==="starting"?"starting":n.state==="working"?"work":"idle":s!=null&&s.stopped||(a==null?void 0:a.status)==="exited"||(a==null?void 0:a.status)==="stopped"?t.rigStatus==="starting"?"waiting":"off":t.rigStatus==="starting"&&!s?"waiting":s&&Vs(s)?"work":a!=null&&a.attention||s!=null&&s.attention?"ask":"idle"}const Sd={perm:"perm",ask:"ask",work:"work",idle:"idle",off:"off",starting:"work",waiting:"off"},Sl=t=>t==="claude-code"||t==="claude"?"claude":t==="codex"?"codex":t==="cursor"?"cursor":t==="omp"?"omp":null,pn=(t,n)=>(n==null?void 0:n.split("@")[0])||t.replace(".","-");function kg(t,n){const s=n.map(a=>({...a,seats:t.filter(r=>r.pod===a.id)}));for(const a of t)s.some(r=>r.id===a.pod)||s.push({id:a.pod,label:a.pod,seats:t.filter(r=>r.pod===a.pod)});return s.filter(a=>a.seats.length)}function vg(t,n){const s=n.filter(o=>/delegat/.test(o.kind)),a=new Set(s.map(o=>o.from)),r=new Set(s.map(o=>o.to)),l=t.filter(o=>a.has(o.logicalId)&&!r.has(o.logicalId));return l.length===1?l[0].logicalId:null}const wg=["auto","standard","open","yolo","locked","spec"],Cd=/^builtin:(auto|standard|open|yolo|locked)$/;function Sg(t){var n;switch(t.policySource){case"member_policy":return((n=Cd.exec(t.policy??""))==null?void 0:n[1])??null;case"rig_policy":case"team_default":case"kernel_default":case"floor":return"spec";default:return null}}function $d(t){if(t.length===0)return null;const n=t.map(Sg),s=n[0];return s&&n.every(a=>a===s)?s:"mixed"}const Cg=t=>{var n;return((n=Cd.exec(t??""))==null?void 0:n[1])??null},Md=t=>[...dm(t.nodes)].map(([n,s])=>({role:n,count:s.length,ids:s}));function $g(t,n){return n!=null&&n.some(s=>s.id===t.id)?"mine":t.state==="in-progress"?"progress":t.state==="blocked"?"blocked":"pending"}const Mg=t=>t==="done"?"done":t==="handed-off"?"handed":"stopped";function Eg(t){const n=t.trim(),s=/^handed[ _-]?off(?: to)? (.+)$/i.exec(n);if(s)return{verb:"handed",to:s[1].split("@")[0]};const a=/^blocked(?: on)? (.+)$/i.exec(n);if(a)return{verb:"blocked",on:a[1]};const r=n.toLowerCase();return r==="claimed"?{verb:"claimed"}:r==="completed"||r==="done"?{verb:"completed"}:r==="canceled"||r==="cancelled"?{verb:"canceled"}:r==="resumed"||r==="unblocked"?{verb:"resumed"}:r==="failed"?{verb:"failed"}:{verb:"other",text:n}}function va(t){const n=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(:\d{2})?$/.test(t)?`${t.replace(" ","T")}Z`:t,s=new Date(n);return Number.isNaN(s.getTime())?null:s}function Cl(t,n){const s=a=>new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime();return Math.round((s(n)-s(t))/864e5)}const Ed=t=>t.startsWith("operator."),_d=t=>Ed(t.logicalId)?"Max":pn(t.logicalId,t.session),Rd={running:"on",starting:"go",partial:"part",stopped:"plain"},_g=t=>t.daemon.state==="stopped"||t.daemon.state==="stale";function Rg(t){return t.rig?t.rig:t.seat?t.seat.split("@")[1]??null:null}function Tg(t){return t.kind==="seats"?t.rig??null:t.kind==="act"&&t.action?Rg(t.action):null}const Td=t=>[...t].sort((n,s)=>{var a,r;return(((a=va(s.createdAt))==null?void 0:a.getTime())??0)-(((r=va(n.createdAt))==null?void 0:r.getTime())??0)});function Ag(t,n){const s=[];for(const a of n){if(a.from!==t&&a.to!==t)continue;const r=a.from===t?a.to:a.from;/delegat/.test(a.kind)?s.push({kind:a.to===t?"delegatesTo":"delegates",who:r}):/collaborat/.test(a.kind)?s.some(l=>l.kind==="collaborates"&&l.who===r)||s.push({kind:"collaborates",who:r}):/escalat/.test(a.kind)&&a.from===t?s.push({kind:"escalates",who:r}):s.push({kind:"linked",who:r,label:a.kind})}return s}const Ig=t=>t.nodes.filter(n=>!n.stopped&&Vs(n)).map(n=>pn(n.logicalId,n.session));function Wa({on:t,label:n,disabled:s,onChange:a,describedBy:r}){return e.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-label":n,disabled:s,"aria-describedby":r,onClick:()=>a(!t),className:`relative h-6 w-10 flex-none rounded-full border border-line transition-colors disabled:opacity-45 ${t?"border-transparent bg-ok":"bg-raised"}`,children:e.jsx("span",{className:`absolute top-0.5 h-4.5 w-4.5 rounded-full bg-white shadow-sm transition-all ${t?"left-[18px]":"left-0.5"}`,"aria-hidden":"true"})})}const Lg={on:"border-ok/40 text-ok",go:"border-info/40 text-info",part:"border-attention/45 text-attention",bad:"border-approval/45 text-approval",plain:"border-input text-muted"};function ds({tone:t,children:n,flat:s=!1}){return e.jsxs("span",{"data-chip":t,className:`inline-flex h-[22px] flex-none items-center gap-1.5 rounded-full border px-[9px] text-[12px] font-medium whitespace-nowrap ${Lg[t]}`,children:[!s&&e.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-current"}),n]})}function Is({perm:t=!1,ok:n=!1,children:s}){const a=t?"bg-approval/12 text-approval":n?"bg-ok/12 text-ok":"bg-attention/12 text-attention";return e.jsx("span",{"data-att":t?"perm":n?"ok":"ask",className:`inline-flex h-[22px] items-center rounded-md px-2 text-[12px] whitespace-nowrap ${a}`,children:s})}function It({children:t,aside:n,id:s}){return e.jsxs("h2",{id:s,className:"flex flex-none items-center gap-2 text-[11px] font-medium tracking-[.4px] text-muted uppercase",children:[e.jsx("span",{children:t}),n!==void 0&&e.jsx("span",{className:"ml-auto text-[12px] font-normal tracking-normal normal-case",children:n})]})}function Ve({tone:t,label:n,children:s,className:a=""}){return e.jsx("section",{"aria-label":n,className:`flex-none overflow-hidden rounded-[10px] border bg-surface dark:bg-transparent ${t==="rigs"?"border-task/45":"border-line"} ${a}`,children:s})}function qr({lead:t,name:n,chip:s,sub:a,att:r,href:l,dim:o=!1,selected:c=!1,label:i}){const x=e.jsxs(e.Fragment,{children:[t,e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-[3px]",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("b",{className:`truncate text-[14.5px] font-semibold ${o?"text-muted":""}`,children:n}),s]}),a&&e.jsx("small",{className:"text-[12px] text-muted",children:a}),r&&e.jsx("span",{className:"flex flex-wrap gap-1.5",children:r})]}),l&&e.jsx(z,{name:"chevron",className:"size-4 text-muted"})]}),d=`flex min-h-[60px] items-center gap-2.5 border-b border-line px-3 py-2 last:border-b-0 ${c?"bg-secondary":""}`;return l?e.jsx("a",{href:l,"aria-label":i,"aria-current":c?"page":void 0,className:d,children:x}):e.jsx("div",{className:d,children:x})}function pr({label:t,value:n,onOpen:s}){const a=e.jsxs(e.Fragment,{children:[e.jsx("small",{className:"text-[11.5px] text-muted",children:t}),e.jsx("b",{className:"truncate text-[17px] font-semibold",children:n})]}),r="relative flex min-w-0 flex-col gap-px rounded-[10px] border border-line bg-surface px-2.5 py-2 text-left";return s?e.jsxs("button",{type:"button",onClick:s,className:r,children:[a,e.jsx("span",{"aria-hidden":"true",className:"absolute top-[7px] right-[9px] text-muted",children:"›"})]}):e.jsx("div",{className:r,children:a})}function Wt({lead:t,warn:n=!1,danger:s=!1,children:a,action:r,role:l,compact:o=!1}){return e.jsxs("div",{role:l,className:`strip flex flex-none gap-[9px] rounded-lg border text-[13px] leading-[18px] ${o?"items-center px-2.5 py-2":"items-start px-3 py-2.5"} ${s?"border-approval/45":n?"border-attention/40":"border-line"}`,children:[t,e.jsx("div",{className:`flex min-w-0 flex-1 flex-col ${o?"":"gap-2"}`,children:a}),r]})}function $e({mark:t,title:n,sub:s,children:a,onClose:r,closeLabel:l}){const o={ok:"✓",bad:"✕",warn:"!",ask:"?"}[t],c={ok:"text-ok",bad:"text-approval",warn:"text-attention",ask:"text-attention"}[t];return e.jsxs("div",{role:t==="ok"?"status":"alert","data-receipt":t,className:`flex min-h-12 items-center gap-2.5 rounded-lg border bg-surface px-3 py-2 text-[13px] leading-[18px] ${t==="bad"?"border-destructive/45":"border-line"}`,children:[e.jsx("span",{"aria-hidden":"true",className:c,children:o}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("b",{className:"font-semibold",children:n}),s!==void 0&&e.jsx("small",{className:"block text-[12px] text-muted [overflow-wrap:anywhere]",children:s}),a]}),r&&l&&e.jsx("button",{type:"button",onClick:r,"aria-label":l,title:l,className:"grid size-9 flex-none place-items-center rounded-lg text-muted active:bg-raised",children:e.jsx(z,{name:"close",className:"size-4"})})]})}function qn({commands:t}){return t.length?e.jsx("code",{className:"mt-1.5 block rounded-md bg-raised px-2 py-1.5 font-mono text-[12px] break-all whitespace-pre-wrap text-muted",children:t.join(`
|
|
16
|
-
`)}):null}function $l({title:t,body:n}){return e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-destructive/40 bg-danger-bg/70 px-2.5 py-[9px] text-[13px] leading-[18px]",children:[e.jsx(z,{name:"warning",className:"mt-px size-4 text-approval"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("b",{className:"block font-semibold",children:t}),n!==void 0&&e.jsx("span",{className:"text-muted",children:n})]})]})}const gs=({className:t="text-info"})=>e.jsx("span",{"aria-hidden":"true",className:`inline-block size-[13px] flex-none animate-spin rounded-full border-[1.6px] border-current border-r-transparent ${t}`});function Ls({children:t,bar:n=!1}){return e.jsxs("div",{role:"status",className:`flex flex-none items-center gap-2.5 px-3 py-2.5 text-[12.5px] text-muted ${n?"bleed border-t border-line bg-sidebar":"rounded-lg border border-line"}`,children:[e.jsx(gs,{}),e.jsx("span",{className:"min-w-0 flex-1",children:t})]})}function ca({label:t,options:n,value:s,onChange:a,disabled:r=!1}){return e.jsx("div",{role:"group","aria-label":t,className:"inline-flex flex-none self-start overflow-hidden rounded-lg border border-input",children:n.map(l=>e.jsx("button",{type:"button",disabled:r,"aria-pressed":l.value===s,onClick:()=>a(l.value),className:"h-9 px-3.5 text-[13px] font-medium text-muted aria-pressed:bg-raised aria-pressed:text-fg disabled:opacity-45",children:l.label},l.value))})}function Hr({pressed:t,title:n,sub:s,onClick:a,disabled:r=!1}){return e.jsxs("button",{type:"button","aria-pressed":t,disabled:r,onClick:a,className:"flex flex-col gap-0.5 rounded-lg border border-input px-[11px] py-[9px] text-left text-[13.5px] font-medium aria-pressed:border-ring aria-pressed:bg-secondary aria-pressed:shadow-[inset_0_0_0_1px_var(--color-ring)] disabled:opacity-45",children:[e.jsx("span",{children:n}),s&&e.jsx("small",{className:"text-[11.5px] font-normal text-muted",children:s})]})}function Do({on:t,label:n,onChange:s,disabled:a=!1}){return e.jsxs("label",{className:`flex min-h-12 items-center gap-3 border-b border-line px-3 py-1.5 text-[13.5px] last:border-b-0 ${a?"opacity-45":""}`,children:[e.jsx("input",{type:"checkbox",checked:t,disabled:a,onChange:r=>s(r.target.checked),className:"peer sr-only"}),e.jsx("span",{"aria-hidden":"true",className:`grid size-[18px] flex-none place-items-center rounded-[5px] border-[1.5px] text-[12px] peer-focus-visible:outline-2 peer-focus-visible:outline-info ${t?"border-primary bg-primary text-primary-fg":"border-input"}`,children:t?"✓":""}),e.jsx("span",{className:"min-w-0 flex-1",children:n})]})}function Fo({on:t,label:n,hint:s,onChange:a,disabled:r=!1}){const l=f.useId();return e.jsxs("div",{className:"flex min-h-12 items-center gap-3 border-b border-line px-3 py-1.5 text-[13.5px] last:border-b-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{children:n}),s&&e.jsx("small",{id:l,className:"text-[12px] text-muted",children:s})]}),e.jsx(Wa,{on:t,label:n,onChange:a,...r?{disabled:r}:{},...s?{describedBy:l}:{}})]})}function Og({value:t,changed:n,min:s=0,max:a=9,fewer:r,more:l,onChange:o,disabled:c=!1}){const i="h-9 w-10 text-[17px] text-fg disabled:opacity-35";return e.jsxs("span",{className:`inline-flex flex-none items-center overflow-hidden rounded-lg border ${n?"border-ring":"border-input"}`,children:[e.jsx("button",{type:"button","aria-label":r,title:r,disabled:c||t<=s,onClick:()=>o(t-1),className:i,children:"−"}),e.jsx("span",{"aria-live":"polite",className:"min-w-[30px] text-center font-mono text-[14px]",children:t}),e.jsx("button",{type:"button","aria-label":l,title:l,disabled:c||t>=a,onClick:()=>o(t+1),className:i,children:"+"})]})}function an({title:t,onClose:n,children:s,busy:a=!1}){const r=f.useId();return e.jsxs(ht,{labelledBy:r,onClose:()=>{a||n()},children:[e.jsx("h2",{id:r,className:"text-[17px] leading-6 font-semibold",children:t}),s]})}function be({tone:t="outline",size:n="md",className:s=""}={}){const a=rt({variant:t==="primary"?"primary":"outline",size:n,className:s});return t==="danger"?`${a} !border-approval/50 !text-approval`:t==="dangerfill"?`${a} !border-transparent !bg-destructive !text-primary-fg dark:!bg-primary`:a}function Ft({icon:t,children:n,size:s="size-4"}){return e.jsxs(e.Fragment,{children:[e.jsx(z,{name:t,className:s}),n]})}function Ln({children:t,retry:n,retryLabel:s}){return e.jsxs("div",{role:n?"alert":void 0,className:"flex items-center gap-2.5 px-3 py-2.5 text-[13px] text-muted",children:[n&&e.jsx(z,{name:"warning",className:"size-4 flex-none text-attention"}),e.jsx("span",{className:"min-w-0 flex-1",children:t}),n&&s&&e.jsx("button",{type:"button",onClick:n,className:be({size:"xs"}),children:s})]})}function Dg(t,n=500){const s=f.useRef(null),a=f.useRef(!1),r=()=>{s.current&&clearTimeout(s.current),s.current=null};return t?{onPointerDown:l=>{l.pointerType!=="mouse"&&(a.current=!1,r(),s.current=setTimeout(()=>{a.current=!0,t()},n))},onPointerUp:r,onPointerLeave:r,onPointerCancel:r,onContextMenu:l=>{l.preventDefault();const o=!!s.current;r(),a.current||t(),o&&(a.current=!0)},swallow:()=>{const l=a.current;return a.current=!1,l}}:{}}const Ut=u.prs,Fg={ok:"on",run:"go",fail:"bad",wait:"part",skip:"plain",none:"plain"};function Ad({pipeline:t,short:n=!1}){return e.jsx(ds,{tone:Fg[t],flat:t==="none",children:n?Ut.pipe[t]:Ut.pipeline[t]})}const Ml=t=>t.split("/").at(-1)??t,en=t=>({host:Ut.host[t.forge],cli:hd(t.forge),kind:Ut.kind[t.forge]}),Id=(t,n)=>t.sessions.map(s=>n.get(s)).filter(s=>!!s);function Pg(t,n=new Date){const s=new Date(t),a=Cl(s,n);return a<=0?Ke(t):a===1?Ut.yesterday:a<7?s.toLocaleDateString(ut,{weekday:"long"}):s.toLocaleDateString(ut,{day:"numeric",month:"short"})}function Ur(t,n=new Date){const s=new Date(t),a=Ke(t),r=Cl(s,n);return r<=0?Ut.today(a):r===1?Ut.yesterdayAt(a):`${s.toLocaleDateString(ut,r<7?{weekday:"long"}:{day:"numeric",month:"short"})} ${a}`}function Es(t,n){if(t.ok)return t.key==="approved"?Ut.ok.approved(t.given,t.required):Ut.ok[t.key];switch(t.key){case"draft":return Ut.blocker.draft(n);case"approvals":return Ut.blocker.approvals(t.given,t.required);case"changes_requested":return Ut.blocker.changes_requested(t.who);case"raw":return t.code;default:return Ut.blocker[t.key]}}function Po({pr:t,sub:n,chips:s,pills:a,href:r,dim:l=!1,selected:o=!1}){const c=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mt-1.5 self-start",children:e.jsx(Pe,{state:l?"done":hs[t.pipeline],pulse:!l&&t.pipeline==="run"})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-[3px]",children:[e.jsxs("span",{className:`truncate text-[14px] ${l?"text-muted":""}`,children:[e.jsx("b",{className:"mr-1 font-mono text-[13px] font-semibold",children:t.ref}),t.title]}),a&&e.jsx("span",{className:"flex flex-wrap gap-1",children:a}),e.jsx("small",{className:"truncate text-[12px] text-muted",children:n}),s&&e.jsx("span",{className:"flex flex-wrap gap-1.5",children:s})]}),r&&e.jsx(z,{name:"chevron",className:"size-4 text-muted"})]}),i=`flex min-h-[60px] items-center gap-2.5 border-b border-line px-3 py-2 last:border-b-0 ${o?"bg-secondary":""}`;return r?e.jsx("a",{href:r,"data-pr":t.id,"aria-current":o?"page":void 0,className:i,children:c}):e.jsx("div",{"data-pr":t.id,className:i,children:c})}const zo=u.prs,zg=()=>()=>{},Bo=()=>null;function Bg(t){return f.useSyncExternalStore(t?t.subscribe:zg,t?t.getState:Bo,t?t.getState:Bo)}function qg({forge:t,mobile:n,session:s}){var o;const a=Bg(t);if(!((o=n.daemon)!=null&&o.forge))return null;const r=yg((a==null?void 0:a.state)??null,s.id);if(!r)return null;if("pr"in r)return e.jsxs("a",{href:ce({name:"pr",id:r.pr.id}),"data-pr-chip":r.pr.id,className:"inline-flex h-8 flex-none items-center gap-[5px] font-mono text-[11px]",children:[e.jsx(Pe,{state:hs[r.pr.pipeline],pulse:r.pr.pipeline==="run"}),r.pr.ref]});const l=en({forge:r.kind});return e.jsx(Ug,{tip:zo.chipTip(l.host,n.daemon.name,l.kind),label:zo.chipUnknown(l.kind)})}const Hg=4e3;function Ug({tip:t,label:n}){const s=f.useRef(null),[a,r]=f.useState(null);f.useEffect(()=>{if(!a)return;const o=setTimeout(()=>r(null),Hg),c=i=>{var x;(x=s.current)!=null&&x.contains(i.target)||r(null)};return document.addEventListener("pointerdown",c,!0),()=>{clearTimeout(o),document.removeEventListener("pointerdown",c,!0)}},[a]);const l=()=>{var x,d;if(a){r(null);return}const o=(x=s.current)==null?void 0:x.closest("footer"),c=(d=(o==null?void 0:o.previousElementSibling)??o)==null?void 0:d.getBoundingClientRect(),i=globalThis.innerHeight??0;r({bottom:c?Math.max(i-c.top+8,8):96})};return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:s,type:"button","aria-label":t,title:t,onClick:l,"data-pr-chip":"unknown",className:"flex-none rounded-md border border-dashed border-input px-[5px] font-mono text-[11px] text-muted",children:n}),a&&e.jsx("span",{role:"status","data-chip-toast":"",style:a,className:"fixed inset-x-3.5 z-[7] flex items-center gap-2.5 rounded-[10px] border border-line bg-surface px-3 py-2.5 text-[13px] leading-[18px] whitespace-normal text-fg shadow-[0_8px_24px_#0005]",children:t})]})}function El({session:t,nameClassName:n="sn-name",nameStyle:s}){return t.label?e.jsxs(e.Fragment,{children:[t.label,e.jsxs("span",{className:n,...s?{style:s}:{},children:[" (",t.name,")"]})]}):e.jsx(e.Fragment,{children:t.name})}function Wg({text:t}){const n=f.useMemo(()=>pf(t),[t]);return e.jsx(jh,{doc:n})}const qo=({align:t})=>e.jsx("div",{className:`text-meta text-muted ${t==="end"?"text-right":""}`,children:u.thread.cut}),Ho={success:{glyph:"✓",tone:"text-ok"},running:{glyph:"●",tone:"text-info"},failed:{glyph:"✕",tone:"text-danger-fg"},unknown:{glyph:"·",tone:"text-muted"}};function Kg({tools:t}){const[n,s]=f.useState(!1),a=u.sessions;return e.jsxs("div",{className:"rounded-lg border border-line font-mono text-small leading-4 text-muted",children:[e.jsxs("button",{type:"button","aria-expanded":n,onClick:()=>s(r=>!r),className:"flex h-[34px] w-full items-center gap-1.5 px-2.5 text-left font-sans text-[12.5px]",children:[e.jsx(z,{name:"chevron",className:`size-3.5 transition-transform ${n?"rotate-90":""}`}),e.jsx("span",{className:"min-w-0 truncate",children:n?a.tools(t.length):a.toolsNamed(t.length,_p(t).join(", "))})]}),n&&e.jsx("ul",{className:"pb-2",children:t.map(r=>e.jsxs("li",{className:"flex gap-1.5 px-2.5 py-[3px]",children:[e.jsx("span",{"aria-label":a.toolStatus[r.status],role:"img",className:Ho[r.status].tone,children:Ho[r.status].glyph}),e.jsxs("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:[e.jsx("b",{className:"font-medium text-fg",children:r.name})," ",r.label]})]},r.id))})]})}function Vg({store:t,item:n,onReconnect:s,keys:a}){var c,i,x;const r=me(t),l=xn(),o=r.sessions.get(n.sessionId);return e.jsx(gf,{store:t,item:n,session:o,inThread:!0,keys:a,mode:_x(n,(c=r.capabilities)==null?void 0:c[n.tool],(o==null?void 0:o.readOnly)===!0),outcome:pc(n,[...r.sessions.values()],r.ops),fresh:r.fresh,ghost:!1,changed:!1,onReread:()=>{},canConfirm:((i=r.device)==null?void 0:i.confirm)===!0&&l,enroll:l&&((x=r.device)==null?void 0:x.confirm)!==!0,onGone:()=>{},onCheck:s})}function Gg({item:t,store:n,storage:s,inPanel:a=!1,onReconnect:r,keys:l=!1}){switch(t.kind){case"tools":return e.jsx(Kg,{tools:t.tools});case"time":return e.jsx("div",{className:"text-center font-mono text-meta text-muted",children:t.label});case"rig-message":case"rig-task":case"rig-notice":case"rig-fold":case"rig-unreadable":case"rig-raw":return e.jsx(Th,{e:t,storage:s,store:n});case"me":{const o=t.images??(t.attachments??[]).flatMap(c=>n.knownImage(c)??[]);return e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[t.text&&e.jsx("div",{className:"max-w-[94%] rounded-2xl rounded-br-[4px] bg-raised p-3.5 text-body [overflow-wrap:anywhere] whitespace-pre-wrap",children:t.text}),e.jsx(To,{store:n,refs:o,align:"end"}),t.cut&&e.jsx(qo,{align:"end"}),t.delivery&&e.jsx("div",{role:t.delivery==="sending"?"status":void 0,className:`text-meta ${t.delivery==="uncertain"?"text-attention":t.delivery==="sending"?"text-muted":"text-ok"}`,children:t.delivery==="sending"?u.thread.delivery.sending:t.delivery==="uncertain"?u.thread.delivery.uncertain:t.fresh?u.thread.delivery.takenNow:u.thread.delivery.taken})]})}case"agent":return e.jsxs("div",{className:"flex flex-col items-start gap-1",children:[e.jsx("article",{"aria-label":u.thread.agentLabel,className:"max-w-[94%] rounded-2xl rounded-bl-[4px] border border-line bg-surface p-3.5 text-body [overflow-wrap:anywhere]",children:e.jsx(Wg,{text:t.text})}),t.cut&&e.jsx(qo,{align:"start"})]});case"task":return e.jsx(Ih,{task:t.task,cut:t.cut});case"capture":{const o=t.images[0];return e.jsxs("div",{className:"flex flex-col items-start gap-1",children:[e.jsxs("div",{className:"text-meta text-muted",children:[e.jsx("span",{"aria-hidden":!0,children:"✓"})," ",e.jsx("span",{children:t.label}),o&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("span",{className:"font-mono",children:[o.width,"×",o.height]})]})]}),e.jsx(To,{store:n,refs:t.images,align:"start"})]})}case"event":return e.jsx("div",{className:"text-center text-meta text-muted",children:t.label});case"awaiting":return a?e.jsxs(De,{title:a?u.atelier.awaiting:u.thread.awaiting,tone:t.item.kind==="question"?"warning":"approval",children:[e.jsx("p",{className:"[overflow-wrap:anywhere]",children:Ia(t.item)}),e.jsxs("a",{href:ce(a?{name:"atelier",sessionId:t.item.sessionId,requestKey:t.item.key}:{name:"request",sessionId:t.item.sessionId,key:t.item.key}),className:We({block:!0,className:"mt-3"}),children:[u.thread.examine,e.jsx(z,{name:"arrowRight"})]})]}):e.jsx(Vg,{store:n,item:t.item,onReconnect:r,keys:l})}}function Xg({sessionId:t,panel:n}){return e.jsxs(e.Fragment,{children:[e.jsx("a",{href:ce({name:"thread",sessionId:t}),"aria-label":u.atelier.fullScreen,title:u.atelier.fullScreen,className:Ot({variant:"outline"}),children:e.jsx(z,{name:"external"})}),e.jsx("button",{type:"button",onClick:n.onClose,"aria-label":u.atelier.closePanel,title:u.atelier.closeTitle,className:Ot({}),children:e.jsx(z,{name:"close"})})]})}function Wr({store:t,sessionId:n,storage:s,onReconnect:a,panel:r,forge:l}){var ge,Be,et,vt,Vt,tn,Gt,Xt,U,Se,ie,Ie,tt;const o=me(t),c=Kt(),i=Dt(),x=Pa(),d=o.sessions.get(n),m=o.threads.get(n),{fresh:p,ops:g}=o,[h,N]=f.useState(()=>Zc(n,s)),[k]=f.useState(()=>Bf(n)),[C,j]=f.useState(!1),y=(ge=o.daemon)!=null&&ge.taskAnswer?hh(o.tasks.values(),n):[],[b,M]=f.useState(null),S=Wh(t),$=f.useRef(new Map);f.useEffect(()=>{var Ce;for(const[qe,bt]of $.current){const wt=(Ce=g[qe])==null?void 0:Ce.phase;wt==="applied"?$.current.delete(qe):(wt==="rejected"||wt==="failed"||wt==="uncertain")&&($.current.delete(qe),S.putBack(bt))}});const v=Ce=>{N(Ce),Jc(n,Ce,s),j(!1)},[A,R]=f.useState(null),[_,L]=f.useState(!1),[T,B]=f.useState(!1),[E,P]=f.useState(!1),[W,F]=f.useState(null),re=((Be=zm(n,g))==null?void 0:Be.op)??null,Y=f.useRef(d==null?void 0:d.state);f.useEffect(()=>{Y.current!==(d==null?void 0:d.state)&&Y.current!==void 0&&F(re),Y.current=d==null?void 0:d.state},[d==null?void 0:d.state,re]),f.useEffect(()=>(t.openThread(n),()=>t.watch(null)),[t,n]),f.useEffect(()=>{p&&t.watch(n)},[t,n,p]);const H=(m==null?void 0:m.status)==="ready"?(et=m.items.at(-1))==null?void 0:et.at:void 0;f.useEffect(()=>{H&&t.read(n,H)},[t,n,H]);const I=Ic(n,g).at(-1);f.useEffect(()=>{(I==null?void 0:I.phase)!=="applied"||Ff(I.op,s)||(Pf(I.op,s),h.trim()===I.message.text&&v(""))},[I==null?void 0:I.phase,I==null?void 0:I.op]);const[D,Q]=f.useState(""),q=d==null?void 0:d.state;f.useEffect(()=>{(I==null?void 0:I.phase)==="applied"&&q&&q!=="idle"&&Q(I.op)},[q,I==null?void 0:I.phase,I==null?void 0:I.op]);const K=f.useRef(null),ee=(m==null?void 0:m.status)==="gone",ue=d&&!ee?Lp((m==null?void 0:m.items)??[],d,g,c,(m==null?void 0:m.cut)??[],o.sessions,((vt=o.device)==null?void 0:vt.id)??null):[],fe=(Vt=ue.at(-1))==null?void 0:Vt.key,he=f.useRef(!0),[w,O]=f.useState(!1),V=()=>{const Ce=K.current;Ce&&(Ce.scrollTop=Ce.scrollHeight),he.current=!0,O(!1)},Z=f.useRef(!1);f.useLayoutEffect(()=>{var qe;const Ce=K.current;if(!(!Ce||ue.length===0)){if(!Z.current){Z.current=!0;const bt=fr.get(n);if(fr.delete(n),bt!==void 0){Ce.scrollTop=bt,he.current=Ce.scrollHeight-Ce.scrollTop-Ce.clientHeight<Uo;return}}he.current?V():((qe=ue.at(-1))==null?void 0:qe.kind)==="awaiting"&&O(!0)}},[fe,ue.length,m==null?void 0:m.items]);const X=()=>{const Ce=K.current;Ce&&(he.current=Ce.scrollHeight-Ce.scrollTop-Ce.clientHeight<Uo,he.current&&O(!1))};if(!d||ee){const Ce=!ee&&!p&&o.syncedAt===null;return e.jsxs(e.Fragment,{children:[e.jsx("header",{className:"flex-none border-b border-line pt-2 pb-3",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[!r&&e.jsx(Zt,{fallback:{name:"sessions"},label:u.thread.back}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:u.thread.title}),e.jsx(fc,{link:ps(o)}),r&&e.jsx("button",{type:"button",onClick:r.onClose,"aria-label":u.atelier.closePanel,title:u.atelier.closeTitle,className:Ot({}),children:e.jsx(z,{name:"close"})})]})}),e.jsx("main",{className:"min-h-0 flex-1 pt-7 text-body text-muted",role:"status",children:Ce?u.thread.loading:u.thread.unknown})]})}const J=I!==void 0&&yn(I.phase),pe=(I==null?void 0:I.phase)==="applied"&&D!==I.op&&d.state==="idle"&&!d.pending&&c-Date.parse(I.at)<Ar,Ne=Op(d,p?"ready":"pc_offline",J||pe),Xe=I&&(I.phase==="rejected"||I.phase==="failed"||I.phase==="uncertain")&&(I.phase==="uncertain"||h.trim()===I.message.text)?eg(I):null,gt=C&&!Xe?{title:u.thread.composer.failTitle,body:u.thread.composer.lost}:Xe,ze=!!d.pending||d.state==="waiting_input"||d.state==="waiting_permission",Je=()=>{const Ce=h.trim();if(!Ce&&S.items.length===0||!Ne.enabled||xd(h)||!S.ready||S.items.length>0&&ze)return;F(re);const qe=S.ids(),bt=S.clear(),wt=t.reply(n,Ce,qe.length?{attachments:qe}:{});!wt&&bt.length?S.putBack(bt):wt&&bt.length&&$.current.set(wt,bt),j(!wt)},oe=(m==null?void 0:m.status)==="ready",de=((tn=o.daemon)==null?void 0:tn.boot)??null,ke=Bm(d,g,c,{fresh:p,boot:de}),Oe=nl(d,g,de,c),lt=!!((Gt=o.daemon)!=null&&Gt.sessionClose)&&!d.readOnly,mt=sg(!!((Xt=o.daemon)!=null&&Xt.adopt),d,o.adoptFailures[n]),kt=ke.kind==="open"&&ke.error&&ke.error.op!==W?ke.error:null,ct=Ce=>{F(re),P(!1),R(Ce)},xt=!!r&&d.tool==="omp",G=ms(d),Ee=Vh(n,s),we=d.state==="exited"&&d.exitedAt?u.sessions.line.ended(zi(d.exitedAt,c)):void 0,le=x&&[d.project,d.branch].filter(Boolean).join(" · ")||void 0;return e.jsxs(e.Fragment,{children:[e.jsx(La,{back:r?e.jsx("span",{className:"w-2.5"}):e.jsx(Zt,{fallback:{name:"sessions"},label:u.thread.back}),tool:d.tool,name:e.jsx(El,{session:d,nameClassName:"font-normal text-muted"}),dot:G,pulse:G==="work"&&p,sub:we??le,under:!x&&!!we,more:e.jsxs(e.Fragment,{children:[r?e.jsx(Xg,{sessionId:n,panel:r}):e.jsx(Ld,{sessionId:n,current:"thread",onLeave:()=>{K.current&&fr.set(n,K.current.scrollTop)}}),e.jsx("button",{type:"button","aria-haspopup":"dialog","aria-label":u.sessions.moreOf(d.name),title:u.sessions.more,onClick:()=>L(!0),className:Ot({className:_?"bg-raised text-fg":"text-muted"}),children:e.jsx(z,{name:"more"})})]})}),xt?e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[e.jsx("h2",{className:"text-heading",children:u.atelier.ompNoThread}),e.jsx("p",{className:"max-w-[320px] text-body text-muted",children:u.atelier.ompBody}),e.jsxs("a",{href:ce({name:"terminal",sessionId:n}),className:We({variant:"primary"}),children:[e.jsx(z,{name:"terminal"}),u.atelier.ompTerminal]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("main",{ref:K,onScroll:X,"aria-label":u.thread.log(d.name),className:"flex min-h-0 flex-1 flex-col gap-3.5 overflow-y-auto overscroll-contain pt-5 pb-4 phone-side:pt-3 phone-side:pb-3",children:[((U=o.daemon)==null?void 0:U.checklist)&&o.checklists.get(n)&&e.jsx(Vc,{checklist:o.checklists.get(n),current:(Se=d==null?void 0:d.checklist)==null?void 0:Se.current}),(m==null?void 0:m.more)&&e.jsx("p",{className:"text-center text-meta text-muted",children:u.thread.more}),!(m!=null&&m.more)&&Ee!==null&&e.jsx("p",{className:"flex items-center gap-2 text-[12px] text-muted before:h-px before:flex-1 before:bg-line before:content-[''] after:h-px after:flex-1 after:bg-line after:content-['']",children:u.launch.started(d.name,Ee)}),!oe&&ue.length===0&&e.jsx("p",{className:"text-center text-meta text-muted",role:"status",children:p?u.thread.loading:u.thread.unavailable}),oe&&ue.length===0&&e.jsx("p",{className:"text-center text-meta text-muted",children:u.thread.empty}),ue.map(Ce=>e.jsx(Gg,{item:Ce,store:t,storage:s,inPanel:!!r,onReconnect:a,keys:i&&!r},Ce.key))]}),w&&e.jsx("div",{className:"relative h-0",children:e.jsxs("button",{type:"button",onClick:V,className:"absolute bottom-3 left-1/2 inline-flex h-9 -translate-x-1/2 items-center gap-1.5 rounded-full border border-line bg-surface px-3.5 text-[13px] font-medium text-fg shadow-sm",children:[e.jsx(z,{name:"down",className:"size-4"}),u.sessions.requestBelow]})}),ke.kind!=="open"&&(y.length>0||b!==null)&&e.jsx(Eo,{store:t,session:d,tasks:y,sent:b,onSent:M}),mt?e.jsx(ag,{store:t,session:d,onResume:()=>ct("resume")}):ke.kind==="open"&&(y.length>0||b!==null)?e.jsx(Eo,{store:t,session:d,tasks:y,sent:b,onSent:M}):ke.kind==="open"?e.jsx(tg,{name:d.name,focusAtEnd:k,composer:i&&rd()?{...Ne,placeholder:`${Ne.placeholder} · ${u.sessions.keysHint}`}:Ne,draft:h,onDraft:v,onSend:Je,fresh:p,taken:pe,checking:(I==null?void 0:I.phase)==="uncertain"&&p,error:gt,onReconnect:a,images:S,dialog:ze,...(ie=o.daemon)!=null&&ie.commands&&d.tool==="claude"&&!d.readOnly?{slash:{tool:u.tools[d.tool],listing:o.commands[n],ask:()=>t.requestCommands(n)}}:{},alert:kt&&e.jsx(fd,{error:kt,fresh:p,onRetry:()=>ct("close"),onReconnect:a}),...Vn(o.daemon,d)?{lead:e.jsx(Tf,{store:t,session:d}),leadNote:e.jsx(Af,{store:t,session:d})}:{}}):e.jsx(ig,{ending:ke.kind==="ended"&&((Ie=ke.error)==null?void 0:Ie.op)===W?{...ke,error:null}:ke,name:d.name,canResume:lt,resumeHeld:qm(d,g,de,c),readOnly:!!d.readOnly,fresh:p,focus:E,onResume:()=>ct("resume"),onReconnect:a},ke.kind),e.jsx(rg,{store:t}),e.jsx(Od,{store:t,forge:l,session:d,wide:x,threshold:((tt=o.device)==null?void 0:tt.contextNear)??Ta,onModel:()=>B(!0)})]}),_&&e.jsx(bl,{store:t,session:d,closable:lt&&!xt,closing:Oe,onClose:()=>L(!1),onModel:()=>{L(!1),B(!0)},onCloseSession:()=>{L(!1),ct("close")}}),T&&Vn(o.daemon,d)&&e.jsx(qa,{store:t,session:d,onClose:()=>B(!1)}),A&&e.jsx(kl,{store:t,session:d,mode:A,onClose:()=>R(null),onSent:()=>{P(!0),R(null)},onReconnect:a})]})}const fr=new Map,Uo=48;function Ld({sessionId:t,current:n,onLeave:s}){const a=u.sessions.view,r="grid h-9 place-items-center px-3 tablet:px-3.5 text-[13px] font-medium text-muted aria-[current=page]:bg-raised aria-[current=page]:text-fg";return e.jsxs("nav",{"aria-label":a.label,className:"flex flex-none overflow-hidden rounded-lg border border-input",children:[e.jsx("a",{href:ce({name:"thread",sessionId:t}),onClick:n==="thread"?void 0:s,"aria-current":n==="thread"?"page":void 0,className:r,children:a.thread}),e.jsx("a",{href:ce({name:"terminal",sessionId:t}),onClick:n==="terminal"?void 0:s,"aria-current":n==="terminal"?"page":void 0,className:r,children:a.terminal})]})}function Od({store:t,forge:n,session:s,wide:a,threshold:r,onModel:l}){const o=me(t),{daemon:c,fresh:i,usage:x,usageAlert:d}=o,m=Kt(),p=Wc(s,m,r),g=u.sessions,h=Qc(c,s)===null,N=a?Ef(s.tool,x,d,m,i):null;return e.jsxs("footer",{"aria-label":g.foot(s.name),className:"bleed flex h-10 flex-none items-center gap-2.5 border-t border-line bg-sidebar px-3 text-small whitespace-nowrap text-muted",children:[p.model&&(h?e.jsxs("button",{type:"button",disabled:!i,"aria-haspopup":"dialog","aria-label":u.model.chip(p.model),onClick:l,className:"inline-flex h-8 items-center gap-1 text-fg disabled:opacity-60",children:[p.model,e.jsx(z,{name:"down",className:"size-3.5"})]}):e.jsx("span",{className:"text-fg",children:p.model})),p.context&&e.jsxs("span",{role:"img","aria-label":g.contextLabel(p.context.pct),className:`inline-flex items-center gap-1.5 ${p.context.near?"text-attention":""}`,children:[e.jsx("span",{className:"relative block h-1 w-8 overflow-hidden rounded-sm bg-raised",children:e.jsx("span",{className:"absolute inset-y-0 left-0 bg-current",style:{width:`${p.context.pct}%`}})}),p.context.pct," %"]}),a&&s.context&&e.jsxs("span",{children:["· ",So(s.context.used)," / ",So(s.context.window)]}),(p.model||p.context)&&e.jsx("span",{className:"h-3 w-px flex-none bg-line"}),s.branch?e.jsx("span",{className:`min-w-0 truncate font-mono text-[11px] ${a?"":"flex-1"}`,children:s.branch}):e.jsxs("span",{"aria-label":g.folder(s.project),className:`inline-flex min-w-0 items-center gap-1 ${a?"":"flex-1"}`,children:[e.jsx(z,{name:"folder",className:"size-3.5"}),e.jsx("span",{className:"truncate",children:s.project})]}),s.branch&&e.jsx(qg,{forge:n,mobile:o,session:s}),a&&s.branch&&e.jsx("span",{className:"min-w-0 truncate",children:s.project}),a&&e.jsx("span",{className:"flex-1"}),N&&e.jsxs("span",{className:"flex-none",children:[u.limits.harnessShort[N.harness]??N.harness," ",jl(N.window)," ",e.jsxs("b",{className:`font-semibold ${N.tone==="red"?"text-approval":N.tone==="amber"?"text-attention":"text-fg"}`,children:[N.window.pct," %"]})]})]})}const Yg={approval:{fg:"var(--danger-text)"},question:{fg:"var(--warning)"},starting:{fg:"var(--info)"},idle:{fg:"var(--success)"},working:{fg:"var(--info)"},done:{fg:"var(--muted-foreground)"},error:{fg:"var(--danger-text)"},readonly:{fg:"var(--muted-foreground)"}};function Qg({state:t,label:n,tone:s,caps:a=!1}){const{stateLabel:r}=el(),l=Yg[s??t].fg;return e.jsx("span",{"data-badge":t,style:{display:"inline-flex",alignItems:"center",flexShrink:0,height:a?24:22,padding:a?"0 9px":"0 8px",boxSizing:"border-box",borderRadius:5,color:l,background:"color-mix(in srgb, currentColor 10%, transparent)",fontSize:a?11:12,lineHeight:1,fontWeight:500,letterSpacing:a?"0.08em":void 0,textTransform:a?"uppercase":void 0,whiteSpace:"nowrap",transition:Fx([["background-color","hover"],["color","hover"]])},children:n??r[t]})}const Wo=["monstera","fern","snake","ficus","succulent"],Zg=["tl","tr","br","ml","mr"];function Jg(t,n){const s=rs(t),a=1+s%2;return Zg.filter(r=>!n.includes(r)).sort((r,l)=>rs(t+r)-rs(t+l)).slice(0,a).map((r,l)=>({spot:r,species:Wo[(s+l*7)%Wo.length],flip:!!(s>>l&1)}))}const _n={top:56,side:12,bottom:34},Ko=11/12,Dd=t=>t.width>=t.height?"land":"port";function eb(t,n,s){if(t.length===0||n.width<=0||n.height<=0)return{zoom:1,along:s==="land"?"row":"column"};const a=Math.max(...t.map(o=>o.h)),r=Math.max(...t.map(o=>o.w));return{zoom:s==="land"?Math.min(1,Math.max(Ko,(n.height-4)/(a+_n.top+_n.bottom))):Math.min(1,Math.max(Ko,(n.width-4)/(r+2*_n.side))),along:s==="land"?"row":"column"}}const tb={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"};function wa(t){return t.state==="idle"&&(t.helpers??[]).some(n=>n.state!=="exited"&&n.state!=="idle")?"working":tb[t.state]}const Fd=t=>t.state==="waiting_permission"||t.state==="waiting_input",Pd=["M5 10.4a1.6 1.6 0 1 0 0 3.2 1.6 1.6 0 0 0 0-3.2Z","M12 10.4a1.6 1.6 0 1 0 0 3.2 1.6 1.6 0 0 0 0-3.2Z","M19 10.4a1.6 1.6 0 1 0 0 3.2 1.6 1.6 0 0 0 0-3.2Z"],nb=["M12 2.5 20.5 7.25v9.5L12 21.5l-8.5-4.75v-9.5z","M12 8.5a3.5 3.5 0 1 0 0 7a3.5 3.5 0 1 0 0-7"],sb=["M4 7h16v12H4z","M4 7l2-3h4l2 3","M9 13h6"],_s=t=>t.topic??t.title;function Kr({session:t,size:n,frozen:s}){const a=Gn(),r=wa(t);return e.jsx(Da,{tool:t.tool,state:r,pose:Oa(t.id,t.state),size:n,theme:a,seed:t.id,frozen:s,readOnly:!!t.readOnly})}function Vo({helper:t,parent:n,size:s,frozen:a}){const r=Gn(),l=`${n.id}:${t.id}`,o=Zi(t);return e.jsx(Da,{tool:n.tool,state:o,pose:Oa(l,o),size:s,theme:r,seed:l,frozen:a,readOnly:!!n.readOnly})}const zd=({state:t})=>e.jsx(Qg,{state:t}),Bd=({color:t})=>t?e.jsx("i",{className:"side-swatch",style:{background:t}}):e.jsx("i",{className:"filter-none"}),ab={monstera:()=>e.jsxs("span",{className:"p-monstera",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("b",{})]}),fern:()=>e.jsxs("span",{className:"p-fern",children:[[0,1,2,3,4,5,6].map(t=>e.jsx("i",{},t)),e.jsx("b",{})]}),snake:()=>e.jsxs("span",{className:"p-snake",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("b",{})]}),ficus:()=>e.jsxs("span",{className:"p-ficus",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("em",{}),e.jsx("b",{})]}),succulent:()=>e.jsxs("span",{className:"p-succulent",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("b",{})]})};function rb({seed:t,left:n,width:s,avoid:a}){return e.jsx("div",{className:"plants","aria-hidden":"true",style:{left:n,width:s},children:Jg(t,a).map(({spot:r,species:l,flip:o})=>{const c=ab[l];return e.jsx("span",{className:`plant-spot spot-${r}${o?" flip":""}`,children:e.jsx(c,{})},r)})})}const Go=t=>e.jsxs(e.Fragment,{children:[(t==="approval"||t==="question")&&e.jsx("b",{className:"sheet-flag"}),t==="done"&&e.jsx("i",{className:"sheet-stamp",children:"✓"})]});function lb({sheets:t,length:n}){return e.jsx("div",{className:"table-top",children:t.map(a=>e.jsxs(f.Fragment,{children:[e.jsxs("div",{style:{left:a.x-84/2},className:`task-sheet sheet-${a.slot} sheet-${a.state}`,children:[e.jsx("p",{lang:"fr",children:a.task}),Go(a.state)]}),a.note&&e.jsxs("div",{style:{left:tx(a.x,t.filter(r=>r.slot===a.slot).map(r=>r.x),n)},className:`sheet-note note-${a.slot} sheet-${a.note.state}`,children:[e.jsx("p",{children:a.note.task}),Go(a.note.state),a.note.more>0&&e.jsxs("em",{className:"note-more",children:["+",a.note.more]})]})]},a.id))})}function ob({table:t,project:n,color:s,frozen:a,act:r,helpers:l=!0}){const{length:o,width:c,seats:i,ends:x,notes:d,extra:m,extraCount:p}=ex(t.mains,l,zs,En),g=j=>`calc(50% - ${o/2}px + ${j}px)`,h=nx(t.mains),N=i.map(({session:j,x:y,side:b})=>{const M=d.get(j.id);return{id:j.id,task:_s(j),state:eo(wa(j)),slot:b,x:y,note:M&&{task:M.helper.task,state:eo(Zi(M.helper)),more:M.more}}}),k=[...m.mains.map(j=>({key:j.id,el:e.jsx(Kr,{session:j,size:18,frozen:a})})),...m.helpers.map(({helper:j,parent:y})=>({key:`${y.id}:${j.id}`,el:e.jsx(Vo,{helper:j,parent:y,size:18,frozen:a})}))].slice(0,3),C=[...p>0?["br"]:[],...x.some(j=>j.end==="left")?["ml"]:[],...x.some(j=>j.end==="right")?["mr"]:[]];return e.jsx("section",{className:"atelier-table","data-project":n.id,"data-table":t.key,"aria-label":u.atelier.table(n.name),style:{"--room":`${c}px`,"--project":s},children:e.jsxs("div",{className:"table-scene",children:[e.jsx("div",{className:"office-rug",style:{left:g(-En),right:"auto",width:o+2*En}}),e.jsxs("div",{className:"rug-labels",style:{left:g(-En),width:o+2*En},children:[e.jsxs("div",{className:"room-heading",children:[e.jsx(Bd,{color:s}),e.jsxs("span",{className:"heading-names",children:[e.jsx("button",{type:"button",className:"project-conversations",title:n.name,"aria-label":u.atelier.conversations(n.name),onClick:()=>r.room(n.id),children:n.name}),h!==null&&e.jsxs("span",{className:"heading-branch",title:h,children:["⎇ ",h]})]}),e.jsx("span",{className:"spacer"}),e.jsx("span",{className:"room-menu-wrap",children:e.jsx("button",{type:"button",className:"icon-action","aria-label":u.atelier.roomMenu(n.name),onClick:()=>r.room(n.id),children:e.jsx(is,{d:[],fill:Pd,size:14})})})]}),p>0&&e.jsxs("button",{type:"button",className:"table-more",onClick:()=>r.room(n.id),children:[e.jsx("span",{className:"more-faces","aria-hidden":"true",children:k.map(j=>e.jsx("i",{children:j.el},j.key))}),u.atelier.more(p)]})]}),e.jsx(rb,{seed:t.key,left:g(-En),width:o+2*En,avoid:C}),i.map(({session:j,x:y,side:b})=>e.jsx("div",{className:`office-chair chair-${b}`,"aria-hidden":"true",style:{left:g(y-27)}},j.id)),e.jsx("div",{className:"worktable","aria-hidden":"true",style:{left:g(0),right:"auto",width:o},children:e.jsx(lb,{length:o,sheets:N})}),i.map(({session:j,x:y,side:b})=>{var S;const M=wa(j);return e.jsxs("button",{type:"button",style:{left:g(y-56)},"data-agent":j.id,"aria-label":u.atelier.seat(j.name,_s(j)),onClick:()=>r.open(j.id),className:`agent-seat place-${b}${!a&&M==="working"?" seat-working":""}${a?" seat-offline":""}`,children:[e.jsx(Kr,{session:j,size:64,frozen:a}),e.jsx("strong",{children:e.jsx("span",{className:"seat-name",title:j.name,children:j.name})}),e.jsx("span",{className:"seat-machine",children:((S=j.rig)==null?void 0:S.role)??"local"}),e.jsx(zd,{state:M})]},j.id)}),x.map(({helper:j,parent:y,end:b,slot:M,count:S})=>e.jsxs("button",{type:"button",style:{left:g(b==="left"?-70:o+8),right:"auto",top:S>1?M?232:126:void 0},className:`agent-seat helper-seat end-${b}`,"aria-label":u.atelier.helperSeat(j.kind,y.name,j.task),title:j.task,onClick:()=>r.open(y.id),children:[e.jsx(Vo,{helper:j,parent:y,size:36,frozen:a}),e.jsx("strong",{children:j.kind}),e.jsxs("span",{className:"seat-meta",children:["↳ ",y.name]})]},`${y.id}:${j.id}`))]})})}function ib({project:t,tables:n,rig:s,width:a,act:r,children:l}){const o=n.flatMap(p=>p.mains),c=s?o.filter(p=>p.state!=="exited"):o,i=c.filter(Fd).length,x=c.filter(p=>p.state==="working").length,d=(s==null?void 0:s.kind)==="kernel"?u.atelier.kernel:t.name,m=()=>r.room(t.id);return e.jsxs("section",{className:`project-room atelier-room${s?` rig-room ${s.kind}-room`:""}`,"data-room":t.id,"aria-label":s?u.atelier.rigRoom(s.kind,t.name):u.atelier.room(t.name),style:{"--room":`${a}px`,"--project":ls[t.color],"--room-side":`${Ji}px`,"--room-back":`${ox}px`,"--table-gap":`${ec}px`},children:[e.jsxs("div",{className:"room-walls","aria-hidden":"true",children:[e.jsx("i",{className:"wall-back"}),e.jsx("i",{className:"wall-left"}),e.jsx("i",{className:"wall-right"}),e.jsx("i",{className:"wall-front"})]}),e.jsxs("div",{className:`room-plaque${s?" rig-plaque":""}`,children:[s?e.jsx("span",{className:"rig-hex","aria-hidden":"true",children:e.jsx(is,{d:nb,size:13})}):e.jsx(Bd,{color:ls[t.color]}),e.jsx("strong",{className:"plaque-name",title:d,role:"button",tabIndex:0,"aria-label":u.atelier.roomMenu(d),onClick:m,onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),m())},children:d}),s?e.jsx("span",{className:"plaque-where",children:s.kind==="kernel"?u.atelier.kernelWhere:u.atelier.rigWhere(s.folder,s.project)}):e.jsx("span",{className:"plaque-counts",children:u.atelier.plaqueCounts(o.length)}),i>0&&e.jsxs("span",{className:"plaque-waiting",children:[e.jsx("i",{className:"approval-dot"}),u.atelier.waiting(i)]}),x>0&&e.jsxs("span",{className:"plaque-working",children:[e.jsx("i",{className:"live-dot"}),u.atelier.working(x)]}),!s&&e.jsx("span",{className:"room-menu-wrap",children:e.jsx("button",{type:"button",className:"icon-action","aria-label":u.atelier.roomMenu(d),onClick:m,children:e.jsx(is,{d:[],fill:Pd,size:14})})})]}),e.jsx("div",{className:"room-tables",children:l}),e.jsx("span",{className:"room-entrance","aria-hidden":"true",children:u.atelier.entrance})]})}function cb({sessions:t,frozen:n,act:s}){return t.length===0?null:e.jsxs("section",{className:"unassigned-zone atelier","aria-labelledby":"unassigned-title",children:[e.jsxs("div",{className:"unassigned-heading",children:[e.jsx(is,{d:sb,size:15}),e.jsx("h2",{id:"unassigned-title",children:u.atelier.unassigned}),e.jsx("span",{className:"muted",children:u.atelier.unassignedHint})]}),e.jsx("div",{className:"unassigned-list",children:t.map(a=>e.jsxs("div",{className:"unassigned-card",children:[e.jsxs("button",{type:"button",className:"unassigned-open","data-agent":a.id,"aria-label":u.atelier.seat(a.name,_s(a)),onClick:()=>s.open(a.id),children:[e.jsx(Kr,{session:a,size:56,frozen:n}),e.jsxs("span",{className:"unassigned-copy",children:[e.jsx("strong",{children:a.name}),e.jsx("span",{title:_s(a),children:_s(a)}),e.jsx("code",{children:a.project})]})]}),e.jsx("div",{className:"unassigned-actions",children:e.jsx(zd,{state:wa(a)})})]},a.id))})]})}function db({count:t,requests:n=0,frozen:s,onOpen:a}){const r=Gn(),l=n>0?a:void 0;return e.jsx("div",{className:"ledge-corner",children:e.jsxs("button",{type:"button",className:"ledge-desk",onClick:l,disabled:!l,children:[e.jsx("span",{className:"ledge-bubble",children:n>0?u.atelier.ledgeRequests(n):u.atelier.watching(t)}),e.jsx("span",{className:"ledge-seat",children:e.jsx(cl,{size:80,theme:r,frozen:s})}),e.jsx("strong",{children:"Ledge"}),e.jsx("small",{children:u.atelier.assistant})]})})}function ub(){const t=u.atelier.legend;return e.jsxs("div",{className:"workspace-legend",children:[e.jsxs("span",{children:[e.jsx("i",{className:"live-dot"}),t.working]}),e.jsxs("span",{children:[e.jsx("i",{className:"approval-dot"}),t.approval]}),e.jsxs("span",{children:[e.jsx("i",{className:"question-dot"}),t.question]}),e.jsxs("span",{children:[e.jsx("i",{className:"done-dot"}),t.done]}),e.jsx("span",{className:"spacer"}),e.jsx("span",{children:t.helper})]})}const qd=.3,mb=2.5,xb=2.2,Vr=t=>Math.min(mb,Math.max(qd,t)),pb=(t,n)=>Vr(n>0?t*1.2:t/1.2);function fb(t,n,s){const a=(t.left+s.x)/t.zoom,r=(t.top+s.y)/t.zoom;return{left:a*n-s.x,top:r*n-s.y}}function hb(t,n){const s=Math.min(xb,Math.max(qd,Math.min(n.width*.92/t.w,n.height*.92/t.h)));return{zoom:s,left:(t.x+t.w/2)*s-n.width/2,top:(t.y+t.h/2)*s-n.height/2}}const gb=8,bb=320,jb=30,yb="button,a,[role=button],.unassigned-card",Nb=".atelier-room,.unassigned-zone",kb=12;let hn={zoom:null,left:0,top:0};function vb(t){const n=f.useRef(null),s=f.useRef(null),[a,r]=f.useState(1),[l,o]=f.useState(hn.zoom),c=f.useRef(hn.zoom??1),i=f.useRef(hn.zoom),x=f.useRef({w:-1,h:-1}),d=f.useCallback(()=>{const j=n.current,y=s.current;if(!j||!y)return;const b=y.style;b.zoom="1";const M={width:j.clientWidth,height:j.clientHeight};x.current={w:j.offsetWidth,h:j.offsetHeight};const S=Dd(M);b.padding=`${_n.top}px ${_n.side}px ${_n.bottom}px`,b.flexWrap="wrap",b.width="max-content",b.maxWidth="none",b.minHeight="",b.alignContent="flex-start",b.gap="0 8px";const $=y.querySelector(".ledge-corner");b.setProperty("--ledge-clear",`${$?Math.max(0,$.offsetTop+$.offsetHeight+kb-_n.top):0}px`);const v=[...y.querySelectorAll(Nb)].map(_=>({w:_.offsetWidth,h:_.offsetHeight})).filter(_=>_.w>0),{zoom:A,along:R}=eb(v,M,S);if(R==="row")b.flexWrap="nowrap",b.width="max-content",b.justifyContent="flex-start";else{const _=Math.max(0,...v.map(L=>L.w))+2*_n.side;b.flexWrap="wrap",b.width=`${_}px`,b.maxWidth=`${_}px`,b.justifyContent="center"}v.length===0&&(b.width=`${M.width}px`,b.minHeight=`${M.height}px`),r(A),c.current=i.current??A,b.zoom=String(c.current)},[]);f.useLayoutEffect(()=>{d();const j=n.current;j&&(j.scrollLeft=hn.left,j.scrollTop=hn.top)},[d,...t]);const m=f.useRef(d);m.current=d,f.useEffect(()=>{var b,M;const j=n.current;if(!j||typeof ResizeObserver>"u")return;const y=new ResizeObserver(()=>{(j.offsetWidth!==x.current.w||j.offsetHeight!==x.current.h)&&m.current()});return y.observe(j),(M=(b=globalThis.document)==null?void 0:b.fonts)==null||M.ready.then(()=>m.current()),()=>y.disconnect()},[]);const p=(j,y,b)=>{const M=n.current,S=s.current;c.current=j,i.current=j,o(j),hn.zoom=j,!(!M||!S)&&(S.style.zoom=String(j),M.scrollLeft=y,M.scrollTop=b)},g=j=>{const y=n.current,b=Vr(j);if(!y){p(b,0,0);return}const{left:M,top:S}=fb({zoom:c.current,left:y.scrollLeft,top:y.scrollTop},b,{x:y.clientWidth/2,y:y.clientHeight/2});p(b,M,S)},h=j=>g(pb(c.current,j)),N=()=>{i.current=null,o(null),hn.zoom=null,d();const j=n.current;j&&(j.scrollLeft=0,j.scrollTop=0)},k=j=>{const y=n.current;if(!y)return;const b=c.current,M=y.getBoundingClientRect(),S=j.getBoundingClientRect(),$={x:(y.scrollLeft+S.left-M.left)/b,y:(y.scrollTop+S.top-M.top)/b,w:S.width/b,h:S.height/b};if($.w<=0||$.h<=0)return;const{zoom:v,left:A,top:R}=hb($,{width:y.clientWidth,height:y.clientHeight});p(v,A,R)},C=f.useRef({setZoom:p,fit:N,frame:k});return C.current={setZoom:p,fit:N,frame:k},f.useEffect(()=>{const j=n.current;if(!j)return;const y=new Map;let b=null,M=null,S=null,$=!1;const v=(E,P)=>({x:(E.x+P.x)/2,y:(E.y+P.y)/2,d:Math.hypot(E.x-P.x,E.y-P.y)}),A=()=>{const[E,P]=[...y.values()];if(b=null,M=null,E&&P){const W=v(E,P),F=j.getBoundingClientRect(),re=c.current;b={d:Math.max(W.d,1),zoom:re,x:(j.scrollLeft+W.x-F.left)/re,y:(j.scrollTop+W.y-F.top)/re}}else E&&(M={x:E.x,y:E.y,left:j.scrollLeft,top:j.scrollTop,moved:!1})},R=E=>{E.pointerType!=="mouse"&&(y.size===0&&($=!1),y.set(E.pointerId,{x:E.clientX,y:E.clientY}),A())},_=E=>{if(!y.has(E.pointerId))return;y.set(E.pointerId,{x:E.clientX,y:E.clientY});const[P,W]=[...y.values()];if(b&&P&&W){const F=v(P,W),re=j.getBoundingClientRect(),Y=Vr(b.zoom*F.d/b.d);C.current.setZoom(Y,b.x*Y-(F.x-re.left),b.y*Y-(F.y-re.top))}else if(M){const F=E.clientX-M.x,re=E.clientY-M.y;if(!M.moved&&Math.hypot(F,re)<gb)return;M.moved=!0,j.scrollLeft=M.left-F,j.scrollTop=M.top-re}},L=E=>{if(!y.has(E.pointerId))return;(M!=null&&M.moved||b)&&($=!0);const P=y.size===1&&M!==null&&!M.moved;if(y.delete(E.pointerId),A(),!P||E.type==="pointercancel")return;const W=E.target instanceof Element?E.target:null,F=E.timeStamp;if(S&&F-S.at<bb&&Math.hypot(E.clientX-S.x,E.clientY-S.y)<jb&&!(W!=null&&W.closest(yb))){S=null;const re=W==null?void 0:W.closest(".atelier-room");re?C.current.frame(re):C.current.fit();return}S={at:F,x:E.clientX,y:E.clientY}},T=E=>{$&&($=!1,E.preventDefault(),E.stopPropagation())},B=()=>{hn.left=j.scrollLeft,hn.top=j.scrollTop};return j.addEventListener("pointerdown",R),j.addEventListener("pointermove",_),j.addEventListener("pointerup",L),j.addEventListener("pointercancel",L),j.addEventListener("click",T,!0),j.addEventListener("scroll",B,{passive:!0}),()=>{j.removeEventListener("pointerdown",R),j.removeEventListener("pointermove",_),j.removeEventListener("pointerup",L),j.removeEventListener("pointercancel",L),j.removeEventListener("click",T,!0),j.removeEventListener("scroll",B)}},[]),{scrollRef:n,shellRef:s,zoom:l??a,fitted:l===null,zoomTo:g,step:h,fit:N}}const wb=["M15 3h6v6","M9 21H3v-6","M21 3l-7 7","M3 21l7-7"],Sb=80;function Hd({label:t,onClose:n,children:s}){const a=f.useRef(null),r=f.useRef(null),[l,o]=f.useState(0),c=d=>{var p,g;const m=d.target;!m.closest(".atelier-panel-grab, .atelier-panel > header, .atelier-panel header")||m.closest("button,a,textarea,input")||(r.current={x:d.clientX,y:d.clientY,id:d.pointerId,land:Dd({width:globalThis.innerWidth,height:globalThis.innerHeight})==="land"},(g=(p=a.current)==null?void 0:p.setPointerCapture)==null||g.call(p,d.pointerId))},i=d=>{const m=r.current;!m||m.id!==d.pointerId||o(Math.max(0,m.land?d.clientX-m.x:d.clientY-m.y))},x=d=>{const m=r.current;if(!m||m.id!==d.pointerId)return;r.current=null;const p=m.land?d.clientX-m.x:d.clientY-m.y;o(0),p>Sb&&n()};return e.jsxs("aside",{ref:a,className:"atelier-panel","aria-label":t,onPointerDown:c,onPointerMove:i,onPointerUp:x,onPointerCancel:x,style:l?{"--pull":`${l}px`}:void 0,children:[e.jsx("div",{className:"atelier-panel-grab","aria-hidden":"true"}),s]})}function Cb({store:t,name:n,ids:s,onOpen:a,onClose:r}){var x;const l=me(t),o=!l.fresh,c=s.map(d=>l.sessions.get(d)).filter(d=>d!==void 0),i=c.filter(d=>d.state!=="exited").map(d=>d.id);return e.jsxs(Hd,{label:u.atelier.room(n),onClose:r,children:[e.jsxs("header",{className:"flex flex-none items-center gap-2.5 border-b border-line pt-2 pb-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h1",{className:"text-title font-semibold [overflow-wrap:anywhere]",children:n}),e.jsx("p",{className:"mt-[3px] text-meta text-muted",children:u.atelier.roomAgents(c.length)})]}),e.jsx("button",{type:"button",onClick:r,"aria-label":u.atelier.closePanel,title:u.atelier.closeTitle,className:Ot({}),children:e.jsx(z,{name:"close"})})]}),e.jsxs("main",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:[c.map(d=>{var m;return e.jsxs("button",{type:"button",onClick:()=>a(d.id),className:"flex w-full items-center gap-3 border-b border-line py-3 text-left active:bg-raised/60",children:[e.jsx(Fa,{tool:d.tool,seed:d.id,state:d.state,frozen:o}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-body font-semibold",children:d.name}),e.jsx("span",{className:"block truncate text-meta text-muted",children:((m=d.rig)==null?void 0:m.role)??d.topic??d.branch??d.title})]}),e.jsx(qs,{...Sx(d)})]},d.id)}),((x=l.daemon)==null?void 0:x.broadcast)&&i.length>0&&e.jsx("div",{className:"pt-4",children:i.length>xa?e.jsx("p",{className:"text-meta text-attention",children:u.agents.tooMany(i.length,xa)}):e.jsx(lc,{store:t,label:n,ids:i,offline:o})})]})]})}function $b(t,n){var a;const s=t.rooms.find(r=>r.project.id===n);return s?{name:((a=s.rig)==null?void 0:a.kind)==="kernel"?u.atelier.kernel:s.project.name,ids:s.tables.flatMap(r=>r.mains.map(l=>l.id))}:null}const Xo=`${Nn}sessions.helpers`,Yo=`${Nn}sessions.groupBy`;function Mb({store:t,sessionId:n,requestKey:s,storage:a,onReconnect:r}){const l=me(t),o=!l.fresh,c=f.useMemo(()=>[...l.sessions.values()],[l.sessions]),i=f.useMemo(()=>c.map(E=>({...E,cwd:E.project})),[c]),x=f.useMemo(()=>ax(i,l.projects,E=>E.projectId??null,"all",!0,({id:E,name:P,kind:W})=>({id:E,name:P,color:lx(W)})),[i,l.projects]),[d,m]=f.useState(null),[p,g]=f.useState(()=>{var E;try{return((E=Ze(a))==null?void 0:E.getItem(Xo))!=="hidden"}catch{return!0}}),[h,N]=f.useState(()=>{var E;try{return((E=Ze(a))==null?void 0:E.getItem(Yo))==="rigs"?"rigs":"projects"}catch{return"projects"}}),k=E=>{var P;N(E);try{(P=Ze(a))==null||P.setItem(Yo,E)}catch{}},C=()=>{var P;const E=!p;g(E);try{(P=Ze(a))==null||P.setItem(Xo,E?"shown":"hidden")}catch{}},j=vb([x,o]),y=E=>{m(null),n?An({name:"atelier",sessionId:E}):os({name:"atelier",sessionId:E})},b=()=>An({name:"atelier"}),M={open:y,room:E=>{n&&b(),m(E)}},S=(l.asks??[]).filter(E=>E.kind!=="update").length,$=c.filter(E=>E.state!=="exited").length,v=c.filter(Fd).length,A=`${o?`${u.agents.offline} · `:""}${u.atelier.subtitle($,v,nc(c).working)}`,R=d?$b(x,d):null,_=x.rooms.filter(E=>!E.rig),L=x.rooms.filter(E=>E.rig),T=h==="rigs"?[...L,..._]:[..._,...L],B=n?l.sessions.get(n):void 0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"atelier-col",children:[e.jsxs("header",{className:"flex flex-none items-center gap-3 pt-3 pb-3",children:[e.jsx("h1",{className:"text-title font-semibold tracking-[-.3px]",children:u.atelier.title}),e.jsx("span",{className:"min-w-0 truncate text-meta text-muted",children:A}),e.jsx("span",{className:"flex-1"}),e.jsx("div",{role:"group","aria-label":u.sessions.groupBy.label,className:"flex flex-none overflow-hidden rounded-lg border border-input",children:ll.map(E=>e.jsx("button",{type:"button","aria-pressed":E===h,onClick:()=>k(E),className:"grid h-9 place-items-center px-3.5 text-[13px] font-medium text-muted aria-pressed:bg-raised aria-pressed:text-fg",children:u.sessions.groupBy[E]},E))}),e.jsxs("button",{type:"button","aria-pressed":!p,onClick:C,className:rt({size:"sm",className:"flex-none"}),children:[e.jsx(z,{name:"eye",className:"size-4"}),p?u.sessions.helpersHide:u.sessions.helpersShow]}),e.jsx(xl,{})]}),e.jsx("div",{className:"mb-3 flex-none empty:hidden",children:e.jsx(wn,{})}),e.jsxs("div",{className:`atelier-ipad${o?" atelier-frozen":""}`,children:[e.jsxs("div",{className:"zoom-controls",role:"toolbar","aria-label":u.atelier.zoom.bar,children:[e.jsx("button",{type:"button",className:"ledge-btn","data-variant":"ghost","aria-label":u.atelier.zoom.out,onClick:()=>j.step(-1),children:"−"}),e.jsx("button",{type:"button",className:"zoom-level","aria-label":u.atelier.zoom.reset,onClick:()=>j.zoomTo(1),children:u.percent(Math.round(j.zoom*100))}),e.jsx("button",{type:"button",className:"ledge-btn","data-variant":"ghost","aria-label":u.atelier.zoom.in,onClick:()=>j.step(1),children:"+"}),e.jsx("span",{className:"zoom-sep"}),e.jsxs("button",{type:"button",className:"ledge-btn zoom-fit","data-variant":j.fitted?"secondary":"ghost","aria-pressed":j.fitted,title:u.atelier.zoom.fitTitle,onClick:j.fit,children:[e.jsx(is,{d:wb,size:13}),u.atelier.zoom.fit]})]}),e.jsxs("div",{className:"overview-scroll atelier",role:"region","aria-label":u.atelier.region,ref:j.scrollRef,children:[e.jsx("div",{className:"atelier-floor",children:e.jsxs("div",{ref:j.shellRef,className:`office-shell${o?" office-paused":""}`,children:[e.jsx(db,{count:$,requests:S,frozen:o,onOpen:()=>os({name:"rigs"})}),e.jsx("div",{className:`project-grid ${T.length===1?"focused":""}`,children:T.map(({project:E,tables:P,rig:W})=>e.jsx(ib,{project:E,tables:P,...W?{rig:W}:{},width:ix(P,zs,En),act:M,children:P.map(F=>e.jsx(ob,{table:F,project:E,color:ls[E.color],frozen:o,act:M,helpers:p},F.key))},E.id))}),e.jsx(cb,{sessions:x.unassigned,frozen:o,act:M})]})}),e.jsx(ub,{})]})]})]}),n&&e.jsx(Hd,{label:u.atelier.session((B==null?void 0:B.name)??""),onClose:b,children:s?e.jsx(Ir,{store:t,sessionId:n,requestKey:s,onReconnect:r,panel:{onBack:()=>An({name:"atelier",sessionId:n}),onClose:b}},`${n}:request`):e.jsx(Wr,{store:t,sessionId:n,storage:a,onReconnect:r,panel:{onClose:b}},n)}),!n&&R&&d&&e.jsx(Cb,{store:t,name:R.name,ids:R.ids,onOpen:y,onClose:()=>m(null)})]})}const Eb=t=>new Date(Date.UTC(2026,10,23+la.indexOf(t))),_b=t=>Eb(t).toLocaleDateString(ut,{weekday:"short",timeZone:"UTC"}),Ud=(t,n)=>t.toLocaleDateString(ut,{weekday:"short",day:"numeric",month:"short",...n?{timeZone:"UTC"}:{}});function hr(t){const n=u.routines,s=la.map((r,l)=>t.includes(r)?l:-1).filter(r=>r>=0);if(s.length===la.length)return n.daily;const a=[];for(let r=0;r<s.length;){let l=r;for(;l+1<s.length&&s[l+1]===s[l]+1;)l++;const o=s.slice(r,l+1).map(c=>n.days[la[c]]);a.push(o.length>=3?`${o[0]}–${o[o.length-1]}`:o.join(", ")),r=l+1}return a.join(", ")}function Rb(t){const[n="",s=""]=t.split("T"),[a,r,l]=n.split("-").map(Number);return`${Ud(new Date(Date.UTC(a,r-1,l)),!0)} ${s}`}function Os(t){var r;const n=u.routines;if(t.kind==="once"){const l=[...t.at].sort().map(Rb),o=l.length>3?n.more(l.slice(0,3).join(", "),l.length-3):l.join(", ");return{card:n.oneShot,ask:o,dated:!0,moments:l}}const s=[...t.times].sort().join(", ");if(((r=t.every)==null?void 0:r.weeks)===2)return{card:`${t.days.length===1?_b(t.days[0]):hr(t.days)} ${s} · ${n.everyOther}`,ask:`${s} (${hr(t.days)}, ${n.every2})`,dated:!0,moments:[]};const a=hr(t.days);return{card:`${s} · ${a}`,ask:`${s} (${a})`,dated:!1,moments:[]}}const Wd=t=>t.toLocaleTimeString(ut,{hour:"2-digit",minute:"2-digit"}),ea=t=>`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`;function Kd(t,n,s=!1){const a=new Date(t),r=Wd(a);if(!s){const l=new Date(n),o=new Date(n);if(o.setDate(o.getDate()+1),ea(a)===ea(l))return`${u.routines.today} ${r}`;if(ea(a)===ea(o))return`${u.routines.tomorrow} ${r}`}return`${Ud(a,!1)} ${r}`}function Tb(t,n){if(!t.nextRun)return null;const s=Os(t.schedule).dated,a=Kd(t.nextRun,n,s);return s?u.routines.nextDated(a):u.routines.next(a)}function Qo(t,n){var r;const s=((r=t==null?void 0:t.lastRun)==null?void 0:r.outcome)==="failed"?t.lastRun:void 0,a=u.routines.why;return t&&(s==null?void 0:s.field)==="cwd"?a.cwd(t.target.cwd):t&&(s==null?void 0:s.field)==="tool"?a.tool(t.target.tool):(s==null?void 0:s.cause)==="timeout"?a.timeout:(s==null?void 0:s.reason)??n??""}const _l=t=>t.state!=="done",Rl=t=>{var n;return((n=t.lastRun)==null?void 0:n.outcome)==="failed"},Zo=t=>t.state==="pending"?0:Rl(t)?1:t.state==="paused"?3:2,Ab=(t,n)=>Zo(t)-Zo(n)||(t.nextRun??"").localeCompare(n.nextRun??"")||t.name.localeCompare(n.name);function Ib(t){const n=t.filter(_l).sort(Ab);return{recurring:n.filter(s=>s.schedule.kind==="recurring"),once:n.filter(s=>s.schedule.kind==="once")}}function Lb(t,n){const s=t.filter(_l),a=s.filter(l=>l.state==="enabled"&&l.nextRun).map(l=>l.nextRun).sort()[0],r=a===void 0?null:new Date(a).toDateString()===new Date(n).toDateString()?Wd(new Date(a)):Kd(a,n);return{count:s.length,next:r,flagged:s.filter(l=>l.state==="pending"||Rl(l)).length}}function Ka(t,n){const s=[...n].filter(a=>a.name===t.target.name);return s.find(a=>a.state!=="exited")??s[0]}function Ob(t,n){const s=[...n],a=new Set;for(const r of t??[]){if(!_l(r))continue;const l=Ka(r,s);l&&a.add(l.id)}return a}const Vd=t=>{var n;return((n=t.proposal)==null?void 0:n.by.name)??(t.createdBy.kind==="session"?t.createdBy.name:void 0)};function Db(t){const n=s=>s.routine.kind==="approve"?0:1;return[...t].filter(s=>!!s.routine&&!ld(s)).sort((s,a)=>n(s)-n(a)||s.at.localeCompare(a.at))}const Tl=t=>t.ids??[t.id],Fb=t=>new Date(t).toLocaleTimeString(ut,{hour:"2-digit",minute:"2-digit"});function Gd({at:t}){const n=u.routines.request;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Lt,{tone:"ask",children:n.ask}),e.jsxs("span",{className:"text-[13px] text-muted",children:[n.kind," · ",e.jsx("time",{dateTime:t,children:Fb(t)})]})]})}function Xd({routine:t,session:n,frozen:s,children:a}){return e.jsxs("div",{className:"flex items-start gap-[9px]",children:[e.jsx(Yd,{routine:t,session:n,frozen:s}),e.jsx("p",{className:"min-w-0 flex-1 text-body [overflow-wrap:anywhere]",children:a})]})}const Sa=t=>{var n;return((n=t.proposal)==null?void 0:n.spec)??t};function Pb(t){return Tl(t.task.routine).length>1?e.jsx(Bb,{...t}):e.jsx(zb,{...t})}function zb({store:t,task:n,state:s,canConfirm:a}){var S,$;const r=u.routines.request,l=n.routine.id,o=(S=s.routines)==null?void 0:S.find(v=>v.id===l),c=s.routineDetails[l],i=c&&c!=="gone"?c:void 0,[x,d]=f.useState(null),[m,p]=f.useState(null);f.useEffect(()=>{s.fresh&&t.showRoutine(l)},[t,l,s.fresh,c]);const g=i?Sa(i):o&&!o.proposed?o:void 0,h=i?!!i.proposal:!!(o!=null&&o.proposed),N=i??o,k=N?Ka(N,s.sessions.values()):void 0,C=(N&&Vd(N))??n.giverName??"",[j,y]=f.useState(!1),b=async v=>{d(v),p(null),y(!1);const A=v==="approve"?await t.approveRoutine(l,i.key):await t.routineCmd(l,"refuse");v==="approve"&&A.status==="rejected"&&A.reason==="stale"?(y(!0),t.rereadRoutine(l)):p(Al(A)),d(null)},M=!s.fresh||x!==null;return e.jsxs(Bs,{tone:"ask",label:`${r.ask} · ${n.routine.name}`,children:[e.jsx(Gd,{at:n.at}),N?e.jsx(Xd,{routine:N,session:k,frozen:!s.fresh,children:g?e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:C})," ",h?r.editAsks(g.name,Os(g.schedule).ask):r.asks(g.name,Os(g.schedule).ask,g.target.cwd)]}):r.fallbackAsk(n.routine.name)}):e.jsx("p",{className:"text-body [overflow-wrap:anywhere]",children:r.fallbackAsk(n.routine.name)}),i&&e.jsx("pre",{"data-prompt":"",className:"m-0 rounded-md border border-line bg-raised px-[9px] py-1.5 font-mono text-small leading-[17px] whitespace-pre-wrap [overflow-wrap:anywhere]",children:Sa(i).prompt}),j&&e.jsx("p",{role:"status",className:"text-small text-attention [overflow-wrap:anywhere]",children:r.stale((($=g??N)==null?void 0:$.name)??n.routine.name)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button",disabled:M||!i,onClick:()=>{b("approve")},className:us(!0),children:[x==="approve"&&e.jsx(Ct,{}),r.activate]}),e.jsxs("button",{type:"button",disabled:M,onClick:()=>{b("refuse")},className:us(),children:[x==="refuse"&&e.jsx(Ct,{}),r.refuse]})]}),m?e.jsx("p",{role:"alert",className:"text-small text-destructive",children:m}):e.jsx("p",{className:"text-[12px] text-muted",children:a?r.verify:u.confirm.refused.confirm_required})]})}function Bb({store:t,task:n,state:s,canConfirm:a}){const r=u.routines.request,l=Tl(n.routine),o=l.map(_=>{var L;return(L=s.routines)==null?void 0:L.find(T=>T.id===_)}).filter(_=>!!_),c=s.routines?o.filter(_=>_.state==="pending"||_.proposed):[],i=s.routines?c.length:l.length,x=o[0],d=x?Ka(x,s.sessions.values()):void 0,[m,p]=f.useState(null),[g,h]=f.useState(null),[N,k]=f.useState(!1),C=c.map(_=>s.routineDetails[_.id]),j=C.map(_=>_&&_!=="gone"?_.key:"-").join(",");f.useEffect(()=>{if(s.fresh)for(const _ of c)t.showRoutine(_.id)},[t,s.fresh,c.map(_=>_.id).join(","),j]);const y=C.filter(_=>!!_&&_!=="gone"),b=c.length>0&&y.length===c.length,M=async _=>{p(_),h(null),k(!1);const L=c.map(E=>{const P=s.routineDetails[E.id];return{routine:E.id,routineKey:P&&P!=="gone"?P.key:E.key}}),[T,...B]=L;if(T){const E=_==="approve"?await t.approveRoutine(T.routine,T.routineKey,B):await t.routineCmd(T.routine,"refuse",B);if(_==="approve"&&E.status==="rejected"&&E.reason==="stale"){k(!0);for(const P of L)t.rereadRoutine(P.routine)}else h(Al(E))}p(null)},S=!s.fresh||m!==null||c.length===0,$=(x&&Vd(x))??n.giverName??"",v=new Set(y.map(_=>Sa(_).target.cwd)),A=v.size===1?[...v][0]:void 0,R=new Set;return e.jsxs(Bs,{tone:"ask",label:`${r.ask} · ${n.routine.name}`,children:[e.jsx(Gd,{at:n.at}),x?e.jsxs(Xd,{routine:x,session:d,frozen:!s.fresh,children:[e.jsx("b",{className:"font-semibold",children:$})," ",r.groupAsks(i),A&&e.jsxs("span",{className:"text-muted",children:[" ",r.inDir(A)]})]}):e.jsx("p",{className:"text-body [overflow-wrap:anywhere]",children:r.fallbackAsk(n.routine.name)}),c.length>0&&e.jsx("ul",{className:"m-0 flex list-none flex-col gap-2.5 p-0",children:c.map(_=>{const L=s.routineDetails[_.id],T=L&&L!=="gone"?Sa(L):void 0,B=Os((T??_).schedule),E=T&&!R.has(T.prompt)?T.prompt:void 0;return T&&R.add(T.prompt),e.jsxs("li",{className:"flex flex-col gap-1",children:[e.jsxs("span",{className:"text-[13px]",children:[e.jsx("b",{className:"font-semibold",children:(T??_).name})," ",e.jsxs("span",{className:"text-muted",children:["· ",B.moments[0]??B.card,T&&!A?` · ${r.inDir(T.target.cwd)}`:""]})]}),E&&e.jsx("pre",{"data-prompt":"",className:"m-0 rounded-md border border-line bg-raised px-[9px] py-1.5 font-mono text-[11.5px] leading-[17px] whitespace-pre-wrap [overflow-wrap:anywhere]",children:E})]},_.id)})}),N&&e.jsx("p",{role:"status",className:"text-small text-attention [overflow-wrap:anywhere]",children:r.stale(n.routine.name)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button",disabled:S||!b,onClick:()=>{M("approve")},className:us(!0),children:[m==="approve"&&e.jsx(Ct,{}),r.activateAll(i)]}),e.jsxs("button",{type:"button",disabled:S,onClick:()=>{M("refuse")},className:us(),children:[m==="refuse"&&e.jsx(Ct,{}),r.refuseAll(i)]})]}),g?e.jsx("p",{role:"alert",className:"text-small text-destructive",children:g}):e.jsx("p",{className:"text-[12px] text-muted",children:a?r.verify:u.confirm.refused.confirm_required})]})}const us=(t=!1)=>["inline-flex h-10 min-w-0 flex-auto items-center justify-center gap-1.5 rounded-[10px] border px-2.5 text-[14px] font-medium whitespace-nowrap transition-colors duration-100 disabled:opacity-45",t?"border-transparent bg-primary text-primary-fg active:bg-primary-hover":"border-input bg-surface dark:bg-transparent text-fg active:bg-raised"].join(" ");function Al(t){switch(t.status){case"applied":return null;case"cancelled":return u.confirm.cancelled;case"expired":return u.confirm.expired;case"failed":return u.cards.note.failed;case"rejected":return t.reason==="not_pending"||t.reason==="stale"||t.reason==="not_found"?u.cards.note.stale:u.confirm.refused[t.reason]??u.cards.note.failed}}function Yd({routine:t,session:n,frozen:s}){return e.jsx(Fa,{tool:(n==null?void 0:n.tool)??t.target.tool,seed:(n==null?void 0:n.id)??t.id,state:(n==null?void 0:n.state)??"exited",frozen:s})}function qb(){return e.jsx("span",{className:"inline-flex h-5 flex-none items-center rounded-lg border border-dashed border-attention/50 px-[7px] text-[11.5px] whitespace-nowrap text-attention",children:u.routines.late})}function Hb({store:t,routine:n,session:s,offline:a,now:r,focused:l}){const o=u.routines,[c,i]=f.useState(null),x=f.useRef(null),[d,m]=f.useState(l);f.useEffect(()=>{var $,v;if(!l)return;(v=($=x.current)==null?void 0:$.scrollIntoView)==null||v.call($,{block:"center"}),m(!0);const S=setTimeout(()=>m(!1),Ub);return()=>clearTimeout(S)},[l]);const[p,g]=f.useState(null),h=n.state==="pending",N=Rl(n),k=n.state==="paused",C=async(S,$)=>{i(S),g(null),g(Al(await t.routineCmd(n.id,$))),i(null)},j=h||k?null:Tb(n,r),y=n.lastRun,b=S=>c===S?e.jsx(Ct,{}):null;let M;return h?M=e.jsx(Lt,{tone:"ask",children:o.pending}):y?M=e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",className:`w-3.5 text-center text-[11px] ${y.outcome==="failed"?"text-approval":"text-ok"}`,children:y.outcome==="failed"?"!":"✓"}),e.jsx("span",{children:o.lastAt(y.slot,o.outcome[y.outcome])}),y.late&&e.jsx(qb,{})]}):M=e.jsx("span",{children:o.never}),e.jsx("div",{ref:x,"data-focused":d||void 0,className:`rounded-lg transition-shadow duration-200 ${d?"shadow-[0_0_0_2px_var(--color-task)] [&>article]:bg-[color-mix(in_srgb,var(--color-task)_10%,var(--color-surface))]":""}`,children:e.jsxs(Bs,{tone:h?"ask":N?"perm":"plain",label:n.name,children:[e.jsxs("div",{"data-routine":n.id,className:"flex min-w-0 items-center gap-[9px]",children:[e.jsx(Yd,{routine:n,session:s,frozen:a}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("b",{className:"truncate text-[15px] font-semibold",children:n.name}),e.jsxs("span",{className:"truncate text-[13px] text-muted",children:[n.target.name," · ",Os(n.schedule).card]})]})]}),k?e.jsx("div",{children:e.jsx(Lt,{children:o.paused})}):j&&e.jsx("p",{className:"text-[13px] text-muted",children:j}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 text-[13px] text-muted",children:M}),N&&Qo(n)&&e.jsx("p",{className:"text-[13px] [overflow-wrap:anywhere] text-muted",children:Qo(n)}),e.jsx("div",{className:"flex gap-2",children:h?null:e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:a||c!==null,onClick:()=>{C("run","run")},className:us(),children:[b("run")??e.jsx(z,{name:"play",className:"size-3.5"}),e.jsx("span",{className:"truncate",children:N?o.retry:o.runNow})]}),e.jsxs("button",{type:"button",disabled:a||c!==null,onClick:()=>{C("toggle",k?"resume":"pause")},className:us(),children:[b("toggle"),e.jsx("span",{className:"truncate",children:k?o.resume:o.pause})]})]})}),p&&e.jsx("p",{role:"alert",className:"text-small text-destructive",children:p})]})})}const Ub=1500;function Jo({children:t}){return e.jsx("h2",{className:"mx-1 -mb-1 text-[10.5px] font-medium tracking-[.06em] text-muted uppercase",children:t})}function ei({store:t,focus:n}){const s=me(t),a=Kt(),r=Dt(),l=u.routines,o=Ib(s.routines??[]),c=!s.fresh,i=[...s.sessions.values()],x=xn(),d=Db(s.tasks.values()).filter(N=>N.routine.kind==="approve"),m=new Set(d.flatMap(N=>Tl(N.routine))),p=d.map(N=>{var k;return e.jsx(Pb,{store:t,task:N,state:s,canConfirm:((k=s.device)==null?void 0:k.confirm)===!0&&x},N.id)}),g=N=>N.filter(k=>!m.has(k.id)),h=N=>g(N).map(k=>e.jsx(Hb,{store:t,routine:k,session:Ka(k,i),offline:c,now:a,focused:k.id===n},k.id));return e.jsxs(fs,{title:l.title,heading:!1,bodyClassName:"flex flex-col gap-2.5",children:[!r&&e.jsxs(e.Fragment,{children:[e.jsxs("a",{href:ce({name:"sessions"}),onClick:N=>{N.preventDefault(),Aa({name:"sessions"})},className:"-mb-1 flex items-center gap-1 self-start text-body text-muted",children:[e.jsx(z,{name:"back",className:"size-4"}),l.back]}),e.jsx("h1",{className:"text-[22px] leading-7 font-semibold tracking-[-.02em]",children:l.title})]}),p,g(o.recurring).length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Jo,{children:l.groups.recurring}),h(o.recurring)]}),g(o.once).length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Jo,{children:l.groups.once}),h(o.once)]}),e.jsx("p",{className:"px-2 text-center text-[12.5px] text-muted",children:l.readonly})]})}const Qd=500,Gr=10;function Zd(t){const n=f.useRef(null),s=f.useRef(null),a=f.useRef(!1),r=()=>{n.current&&clearTimeout(n.current),n.current=null},l=()=>{var o;r(),a.current=!0;try{(o=navigator.vibrate)==null||o.call(navigator,10)}catch{}t()};return{onPointerDown:o=>{o.button>0||(a.current=!1,s.current={x:o.clientX,y:o.clientY},r(),n.current=setTimeout(l,Qd))},onPointerMove:o=>{const c=s.current;c&&Math.hypot(o.clientX-c.x,o.clientY-c.y)>Gr&&r()},onPointerUp:r,onPointerCancel:r,onPointerLeave:r,onContextMenu:o=>{o.preventDefault(),a.current||l()},onClickCapture:o=>{a.current&&(o.preventDefault(),o.stopPropagation(),a.current=!1)}}}function Jd(t){const n=f.useRef(t);n.current=t;const s=f.useRef(null),a=f.useRef(null),r=f.useRef("idle"),l=f.useRef(!1),o=f.useRef(null),c=()=>{s.current&&clearTimeout(s.current),s.current=null},i=()=>{var m;c(),(m=o.current)==null||m.call(o),o.current=null,r.current="idle"};f.useEffect(()=>()=>i(),[]);const x=()=>{const m=N=>{(r.current==="lifted"||r.current==="dragging")&&N.preventDefault()},p=N=>{var C,j;const k=a.current;k&&(r.current==="lifted"&&Math.hypot(N.clientX-k.x,N.clientY-k.y)>Gr&&(r.current="dragging"),r.current==="dragging"&&((j=(C=n.current).onDrag)==null||j.call(C,N.clientY)))},g=()=>{var k,C;const N=r.current;i(),N==="dragging"?(C=(k=n.current).onDrop)==null||C.call(k):N==="lifted"&&n.current.onLong()},h=()=>{var k,C;const N=r.current;i(),(N==="dragging"||N==="lifted")&&((C=(k=n.current).onCancel)==null||C.call(k))};document.addEventListener("touchmove",m,{passive:!1}),window.addEventListener("pointermove",p),window.addEventListener("pointerup",g),window.addEventListener("pointercancel",h),o.current=()=>{document.removeEventListener("touchmove",m),window.removeEventListener("pointermove",p),window.removeEventListener("pointerup",g),window.removeEventListener("pointercancel",h)}},d=()=>{var m,p,g,h;c(),l.current=!0,r.current="lifted";try{(m=navigator.vibrate)==null||m.call(navigator,10)}catch{}(h=(g=n.current).onLift)==null||h.call(g,((p=a.current)==null?void 0:p.y)??0),x()};return{onPointerDown:m=>{m.button>0||(l.current=!1,a.current={x:m.clientX,y:m.clientY},c(),r.current="pressing",s.current=setTimeout(d,Qd))},onPointerMove:m=>{const p=a.current;r.current==="pressing"&&p&&Math.hypot(m.clientX-p.x,m.clientY-p.y)>Gr&&(c(),r.current="idle")},onPointerUp:()=>{r.current==="pressing"&&(c(),r.current="idle")},onPointerCancel:()=>{r.current==="pressing"&&(c(),r.current="idle")},onDragStart:m=>{m.preventDefault()},onContextMenu:m=>{m.preventDefault(),!l.current&&r.current!=="lifted"&&r.current!=="dragging"&&(c(),r.current="idle",l.current=!0,n.current.onLong())},onClickCapture:m=>{l.current&&(m.preventDefault(),m.stopPropagation(),l.current=!1)}}}function eu({store:t,session:n,current:s,onLeave:a,onReconnect:r,display:l,model:o,onModel:c}){var v,A;const i=me(t),x=Kt(),[d,m]=f.useState(!1),[p,g]=f.useState(!1),h=o??p,N=c??g,[k,C]=f.useState(!1),j=ms(n),y=Dt(),b=Pa(),M=s==="terminal"&&y&&!b&&[n.project,n.branch].filter(Boolean).join(" · ")||void 0,S=!!((v=i.daemon)!=null&&v.sessionClose)&&!n.readOnly,$=nl(n,i.ops,((A=i.daemon)==null?void 0:A.boot)??null,x);return e.jsxs(e.Fragment,{children:[e.jsx(La,{back:e.jsx(Zt,{fallback:{name:"sessions"},label:u.thread.back}),tool:n.tool,name:n.name,dot:j,pulse:j==="work"&&i.fresh,sub:M,more:e.jsxs(e.Fragment,{children:[e.jsx(Ld,{sessionId:n.id,current:s,...a?{onLeave:a}:{}}),e.jsx("button",{type:"button","aria-haspopup":"dialog","aria-label":u.sessions.moreOf(n.name),title:u.sessions.more,onClick:()=>m(!0),className:Ot({className:d?"bg-raised text-fg":"text-muted"}),children:e.jsx(z,{name:"more"})})]})}),d&&e.jsx(bl,{store:t,session:n,closable:S,closing:$,onClose:()=>m(!1),onModel:()=>{m(!1),N(!0)},onCloseSession:()=>{m(!1),C(!0)},display:l&&{value:l.value,onToggle:()=>{l.onToggle(),m(!1)}}}),h&&Vn(i.daemon,n)&&e.jsx(qa,{store:t,session:n,onClose:()=>N(!1)}),k&&e.jsx(kl,{store:t,session:n,mode:"close",onClose:()=>C(!1),onSent:()=>C(!1),onReconnect:r})]})}function Wb({store:t,session:n,onDone:s,order:a}){var p,g;const r=me(t),l=Kt(),[o,c]=f.useState("menu"),i=!!((p=r.daemon)!=null&&p.sessionClose)&&!n.readOnly,x=nl(n,r.ops,((g=r.daemon)==null?void 0:g.boot)??null,l),d=n.rig?u.sessions.seatOf(n.rig.role??n.name,n.rig.name):n.project,m=h=>{s(),os(h)};return o==="model"?Vn(r.daemon,n)?e.jsx(qa,{store:t,session:n,onClose:s}):null:o==="close"?e.jsx(kl,{store:t,session:n,mode:"close",onClose:s,onSent:s}):e.jsx(bl,{store:t,session:n,closable:i,closing:x,onClose:s,who:d,onModel:()=>c("model"),onCloseSession:()=>c("close"),...a?{order:[{icon:"arrowUp",label:u.sessions.reorder.up,onClick:a.up?()=>{a.up(),s()}:void 0},{icon:"arrowDown",label:u.sessions.reorder.down,onClick:a.down?()=>{a.down(),s()}:void 0}]}:{},lead:[{icon:"sessions",label:u.cards.openThread,onClick:()=>m({name:"thread",sessionId:n.id})},{icon:"terminal",label:u.thread.terminal(n.name),onClick:()=>m({name:"terminal",sessionId:n.id})}]})}function Kb({by:t,onBy:n,helpers:s,onHelpers:a}){const r=u.sessions.groupBy;return e.jsxs("div",{className:"flex flex-none items-center gap-2",children:[e.jsx("div",{role:"group","aria-label":r.label,className:"grid flex-1 grid-cols-2 gap-[3px] rounded-[10px] border border-line p-[3px]",children:ll.map(l=>e.jsx("button",{type:"button","aria-pressed":l===t,onClick:()=>n(l),className:"h-[34px] rounded-[7px] text-[13px] font-medium whitespace-nowrap text-muted aria-pressed:bg-raised aria-pressed:text-fg",children:r[l]},l))}),e.jsx("button",{type:"button",onClick:a,"aria-label":s?u.sessions.helpersHide:u.sessions.helpersShow,title:s?u.sessions.helpersHide:u.sessions.helpersShow,className:`grid size-[42px] flex-none place-items-center rounded-control border ${s?"border-input text-fg":"border-ring text-fg"}`,children:e.jsx(z,{name:"eye",className:"size-[18px]"})})]})}const ti="inline-flex items-center gap-1.5 rounded-lg border bg-bg px-2.5 select-none [-webkit-touch-callout:none]";function Vb({session:t,rig:n,helpers:s,pressed:a,onPress:r}){const l=Zd(()=>r(t)),o=ms(t),c=o==="perm"?"border-destructive/50":o==="ask"?"border-attention/50":"border-line",i=ce({name:"thread",sessionId:t.id}),x=ma(t),d=u.atelier.session(t.name);return e.jsxs(e.Fragment,{children:[e.jsxs("a",{href:i,"aria-label":d,...l,className:`${ti} h-10 text-[13px] font-medium ${c} ${t.state==="exited"?"opacity-60":""} ${a?"shadow-[0_0_0_2px_var(--color-ring)]":""}`,children:[!n&&e.jsx(Xn,{tool:t.tool}),e.jsx(El,{session:t,nameClassName:"font-normal text-muted"}),e.jsx(Pe,{state:o}),!s&&x.length>0&&e.jsx("span",{"aria-label":u.sessions.kidsLabel(x.length),className:"ml-0.5 rounded-lg border border-input px-1.5 font-mono text-[11px] leading-[18px] text-muted",children:u.sessions.kids(x.length)})]}),s&&x.map(m=>e.jsxs("a",{href:i,"aria-label":u.atelier.helperSeat(m.kind,t.name,m.task),...l,className:`${ti} h-8 border-dashed border-line text-[12px] text-muted`,children:[m.kind,e.jsx(Pe,{state:ux(m)})]},m.id))]})}function Gb({island:t,rigs:n,helpers:s,pressed:a,onPress:r}){const l=u.sessions,o=t.kind==="rig",c=dx(t),i=o?t.name==="kernel"&&n?l.kernelTag:l.rigTag:null,x=o?l.seats(t.sessions.length):u.atelier.plaqueCounts(t.sessions.length);return e.jsxs("section",{"aria-label":o?l.rigGroup(t.name):t.name,className:`flex flex-none flex-col gap-2.5 rounded-[10px] border bg-surface px-3 pt-2.5 pb-3 dark:bg-[oklch(0.18_0_0)] ${o?"border-task/45":"border-line"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 text-[13px]",children:[o&&e.jsx(Pe,{state:"rig"}),e.jsx("b",{className:"font-semibold",children:t.name}),c&&e.jsx(Pe,{state:c}),i?e.jsx("small",{className:"text-[12px] text-muted",children:i}):e.jsx("small",{className:"text-[12px] text-muted",children:x}),o&&i===l.rigTag&&(n?e.jsx("a",{href:ce({name:"rigs"}),className:"ml-auto text-[12px] text-muted underline underline-offset-2",children:x}):e.jsx("span",{className:"ml-auto text-[12px] text-muted",children:x}))]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:t.sessions.map(d=>e.jsx(Vb,{session:d,rig:o,helpers:s,pressed:a===d.id,onPress:r},d.id))})]})}function Xb({sessions:t,by:n,onBy:s,helpers:a,onHelpers:r,rigs:l,pressed:o,onPress:c,requests:i=0}){const x=Gn(),d=t.filter(g=>g.state!=="exited").length,m=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"grid size-[30px] flex-none place-items-center overflow-hidden",children:e.jsx(cl,{size:30,theme:x,frozen:!0})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("b",{className:"font-semibold",children:u.sessions.deskTitle}),e.jsx("small",{className:"text-[12px] text-muted",children:i>0?u.atelier.ledgeRequests(i):u.atelier.watching(d)})]})]}),p="flex min-h-[52px] flex-none items-center gap-2.5 rounded-[10px] border border-line bg-surface px-3 py-1.5 text-[13.5px] dark:bg-[oklch(0.18_0_0)]";return e.jsxs(e.Fragment,{children:[e.jsx(Kb,{by:n,onBy:s,helpers:a,onHelpers:r}),cx(t,n).map(g=>e.jsx(Gb,{island:g,rigs:l,helpers:a,pressed:o,onPress:c},g.id)),i>0?e.jsxs("a",{href:ce({name:"rigs"}),className:p,children:[m,e.jsx(z,{name:"chevron",className:"size-4 text-muted"})]}):e.jsx("div",{className:p,children:m})]})}const ni=`${Nn}sessions.filter`,Yb=t=>tc.includes(t);function Qb(t,n){const s=Ze(n),[a,r]=f.useState(()=>{if(t)return t;try{const o=s==null?void 0:s.getItem(ni);return Yb(o)?o:"all"}catch{return"all"}}),l=o=>{r(o);try{s==null||s.setItem(ni,o)}catch{}};return f.useEffect(()=>{t&&l(t)},[t]),[a,l]}function gr(t,n,s,a){const r=Ze(a),[l,o]=f.useState(()=>{try{const i=r==null?void 0:r.getItem(`${Nn}${t}`);return n.includes(i)?i:s}catch{return s}});return[l,i=>{o(i);try{r==null||r.setItem(`${Nn}${t}`,i)}catch{}}]}const tu=["list","atelier"];function Zb({value:t,onChange:n}){const s=u.sessions.mode;return e.jsx("div",{role:"group","aria-label":s.label,className:"flex flex-none overflow-hidden rounded-lg border border-input",children:tu.map(a=>e.jsx("button",{type:"button","aria-pressed":a===t,onClick:()=>n(a),className:"grid h-9 place-items-center px-3.5 text-[13px] font-medium text-muted aria-pressed:bg-raised aria-pressed:text-fg",children:s[a]},a))})}function Jb({value:t,counts:n,onChange:s}){const a=u.sessions.filter;return e.jsx("div",{role:"group","aria-label":a.label,className:"flex flex-none rounded-lg border border-input p-0.5",children:tc.map(r=>e.jsxs("button",{type:"button","aria-pressed":r===t,onClick:()=>s(r),className:"inline-flex h-8 min-w-0 flex-1 items-center justify-center gap-1.5 rounded-md text-[13px] font-medium whitespace-nowrap text-muted aria-pressed:bg-raised aria-pressed:text-fg",children:[a[r],e.jsx("span",{className:"font-mono text-meta",children:n[r]})]},r))})}function ej({session:t,filter:n,offline:s,threshold:a,now:r,closing:l,pressed:o,onPress:c,woken:i,decision:x=!1,drag:d}){const m=Ps(),p=Zd(()=>c(t)),g=Jd({onLong:()=>c(t),onLift:b=>d==null?void 0:d.onLift(b),onDrag:b=>d==null?void 0:d.onDrag(b),onDrop:()=>d==null?void 0:d.onDrop(),onCancel:()=>d==null?void 0:d.onCancel()}),h={...d?g:p,"data-reorder-row":t.id,...(d==null?void 0:d.lifted)!==null&&(d==null?void 0:d.lifted)!==void 0?{style:nu(d.lifted)}:{}},N=(m.name==="thread"||m.name==="terminal"||m.name==="request")&&m.sessionId===t.id,k=ms(t),C=mx(t),j=sc(t),y=n==="working"?j===void 0?void 0:`${j} %`:fx(t);return e.jsx(ol,{href:ce({name:"thread",sessionId:t.id}),selected:N,stale:s,press:h,pressed:o,lead:e.jsxs(e.Fragment,{children:[e.jsx(Pe,{state:k,pulse:k==="work"&&!s}),e.jsx(Xn,{tool:t.tool})]}),title:e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:e.jsx(El,{session:t,nameClassName:"font-normal text-muted"})}),i&&e.jsx("span",{"data-woken":"",className:"ml-1 inline-flex align-[-2px] text-muted",children:e.jsx(z,{name:"clock",className:"size-[13px]"})}),C>0&&e.jsx("span",{"aria-label":u.sessions.kidsLabel(C),className:"ml-1.5 font-mono text-small text-muted",children:u.sessions.kids(C)}),x&&e.jsx("span",{className:"ml-1.5 inline-flex align-[1px]",children:e.jsx(Lt,{tone:"ask",children:u.cards.decision})})]}),sub:l?e.jsx("span",{className:"text-attention",children:u.sessions.closing}):e.jsx("span",{className:k==="ask"?"text-attention":void 0,children:xx(t,n,r)}),...k==="perm"?{subTone:"perm"}:{},...y!==void 0?{meta:y,metaWarn:n==="working"&&j!==void 0&&j/100>=a}:{}})}const nu=t=>({transform:`translateY(${t}px) scale(1.02)`,position:"relative",zIndex:5,boxShadow:"0 10px 28px #0008",background:"var(--color-surface)",borderRadius:10,touchAction:"none"}),ta=()=>e.jsx("div",{"aria-hidden":"true","data-insert-line":"",className:"relative z-10 mx-3 my-0.5 h-[3px] rounded-full bg-task"});function tj({group:t,children:n,drag:s}){const a=t.kind==="rig",r=a?u.sessions.rigGroup(t.name):t.name,l=Jd({onLong:()=>s==null?void 0:s.onLong(),onLift:o=>s==null?void 0:s.onLift(o),onDrag:o=>s==null?void 0:s.onDrag(o),onDrop:()=>s==null?void 0:s.onDrop(),onCancel:()=>s==null?void 0:s.onCancel()});return e.jsxs("section",{"aria-label":r,"data-reorder-section":t.id,className:"flex flex-col gap-1.5",style:s&&s.lifted!==null?nu(s.lifted):void 0,children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-0.5 text-small font-semibold text-muted select-none",...s?l:{},children:[a&&e.jsx(Pe,{state:"rig"}),r,e.jsx("span",{className:"font-normal",children:t.sessions.length})]}),e.jsx(cs,{...a?{tone:"rigs"}:{},children:n})]})}function nj({routines:t,now:n,offline:s}){const a=u.routines,r=Lb(t,n);return r.count===0?null:e.jsx(cs,{label:a.entry,children:e.jsxs(ol,{href:ce({name:"routines"}),stale:s,lead:e.jsx(z,{name:"alarm",className:"size-5"}),title:e.jsx("b",{className:"font-semibold",children:a.entry}),...r.next?{sub:a.entrySub(r.count,r.next)}:{},children:[r.flagged>0&&e.jsx(Lt,{tone:"perm",children:String(r.flagged)}),e.jsx(z,{name:"chevron",className:"size-4 text-muted"})]})})}function sj({store:t,filter:n,storage:s}){var P,W,F,re;const a=me(t),r=Kt(),[l,o]=Qb(n,s),c=Dt(),[i,x]=gr("sessions.mode",tu,"list",s),[d,m]=gr("sessions.groupBy",ll,"projects",s),[p,g]=gr("sessions.helpers",["shown","hidden"],"shown",s),[h,N]=f.useState(null),k=h?a.sessions.get(h):void 0,C=!c&&i==="atelier",j=[...a.sessions.values()],y=nc(j),b=!a.fresh,M=(P=a.daemon)!=null&&P.sessionOrder&&a.daemon.atelier?{projects:a.projects,order:a.sessionOrder??{}}:null,S=rl(j,l,M),$=aj(t,j,M,b),v=Ob(a.routines,j),A=new Set((W=a.daemon)!=null&&W.taskAnswer?yl(a.tasks.values()).map(Y=>Y.giver).filter(Y=>!!Y):[]),R=((F=a.device)==null?void 0:F.contextNear)??Ta,_=b?a.syncedAt?u.link.lastKnownAt(Ke(a.syncedAt)):u.agents.offline:void 0,L=e.jsxs("a",{href:ce({name:"launch"}),className:rt({variant:"primary",size:"sm",className:"flex-none"}),children:[e.jsx(z,{name:"plus",className:"size-4"}),u.sessions.new]}),T=(Y,H)=>e.jsx("button",{type:"button",onClick:()=>o(Y),className:rt({size:"xs"}),children:H}),B=u.sessions,E=S.length===0&&j.length>0&&e.jsx(cs,{label:B.filter[l],children:l==="waiting"?e.jsx(Rn,{framed:!1,glyph:null,title:B.filterEmpty,body:B.filterEmptyBody(y.working),action:T("all",B.seeAll)}):y.waiting>0?e.jsx(Rn,{framed:!1,glyph:null,title:B.emptyWorking.title,body:B.emptyWorking.waiting(y.waiting),action:T("waiting",B.seeWaiting)}):e.jsx(Rn,{framed:!1,glyph:null,title:B.emptyWorking.title,body:B.emptyWorking.idle,action:T("all",B.seeAll)})});return e.jsxs(fs,{title:u.agents.title,subtitle:_,bodyClassName:"flex flex-col gap-2.5",actions:c?void 0:e.jsxs(e.Fragment,{children:[e.jsx(Zb,{value:i,onChange:x}),L]}),wideActions:c?L:void 0,children:[k&&e.jsx(Wb,{store:t,session:k,onDone:()=>N(null),...$.can?{order:$.stepsOf(S,k.id)}:{}}),$.sheet&&e.jsx(Of,{name:$.sheet.name,up:$.projectStep(S,$.sheet,-1),down:$.projectStep(S,$.sheet,1),onClose:()=>$.setSheet(null)}),e.jsx("div",{className:"sr-only","aria-live":"polite","aria-atomic":"true","data-reorder-said":"",children:$.said}),$.problem&&e.jsx("p",{role:"alert",className:"rounded-lg border border-destructive/40 px-3 py-2 text-small text-danger-fg",children:$.problem}),a.routines&&e.jsx(nj,{routines:a.routines,now:r,offline:b}),j.length===0?e.jsx(cs,{label:u.agents.empty,children:e.jsx(Rn,{list:!0,glyph:e.jsx(z,{name:"sessions"}),title:u.agents.empty,body:u.agents.emptyHint,action:e.jsxs("a",{href:ce({name:"launch"}),className:rt({variant:"primary",size:"sm"}),children:[e.jsx(z,{name:"plus",className:"size-4"}),u.sessions.newSession]})})}):C?e.jsx(Xb,{sessions:j,by:d,onBy:m,helpers:p==="shown",onHelpers:()=>g(p==="shown"?"hidden":"shown"),rigs:!!((re=a.daemon)!=null&&re.rigs),pressed:h,onPress:Y=>N(Y.id),requests:(a.asks??[]).filter(Y=>Y.kind!=="update").length}):e.jsxs(e.Fragment,{children:[e.jsx(Jb,{value:l,counts:y,onChange:o}),S.map((Y,H)=>{const I=$.can&&Y.kind==="project",D=$.lift,Q=D&&D.kind==="session"&&D.gid===Y.id?D:null,q=Q&&Q.to!==Q.from?Q.to<Q.from?Q.to:Q.to+1:-1,K=D&&D.kind==="project"&&D.to!==D.from&&(D.to<D.from?D.to:D.to+1)===H;return e.jsxs("div",{className:"contents",children:[K&&e.jsx(ta,{}),e.jsxs(tj,{group:Y,...I&&Y.project?{drag:$.projectDrag(S,Y)}:{},children:[Y.sessions.flatMap((ee,ue)=>[...ue===q?[e.jsx(ta,{},"line")]:[],e.jsx(ej,{session:ee,filter:l,offline:b,threshold:R,now:r,closing:Hm(ee,a.ops,r),pressed:h===ee.id,onPress:fe=>N(fe.id),woken:v.has(ee.id),decision:A.has(ee.id),...I?{drag:$.rowDrag(Y,ue)}:{}},ee.id)]),q===Y.sessions.length&&e.jsx(ta,{})]}),D&&D.kind==="project"&&D.to!==D.from&&D.to>D.from&&D.to===H&&H===S.filter(ee=>ee.kind==="project"&&ee.project).length-1&&e.jsx(ta,{})]},Y.id)}),E]})]})}const si=(t,n,s)=>t.filter((a,r)=>r!==n&&a<s).length,ai=(t,n,s)=>{const a=[...t],[r]=a.splice(n,1);return a.splice(s,0,r),a};function aj(t,n,s,a){const r=u.sessions.reorder,l=me(t),[o,c]=f.useState(null),[i,x]=f.useState(""),[d,m]=f.useState(null),[p,g]=f.useState(null),h=!!s&&!a,N=(b,M)=>b.status==="applied"?null:b.status==="rejected"&&b.reason==="unavailable"?r.outdated(M):b.status==="rejected"?r.stale(M):r.offline(M),k=(b,M,S)=>{var _;if(M===S||S<0||S>=b.sessions.length)return;const $=b.sessions[M],v=ai(b.sessions,M,S),A=((_=rl(n,"all",s).find(L=>L.id===b.id))==null?void 0:_.sessions)??b.sessions,R=um(A.map(L=>L.id),v.map(L=>L.id));m(null),t.orderSessions(b.project??null,R).then(L=>{const T=N(L,$.name);T?m(T):x(r.moved($.name,r.ordinal(S+1,!0),v.length,b.name))})},C=()=>((s==null?void 0:s.projects)??[]).map(b=>b.id),j=(b,M)=>{const S=C(),$=S.indexOf(b.project??"");$<0||$===M||M<0||M>=S.length||(m(null),t.orderProjects(ai(S,$,M)).then(v=>{const A=N(v,b.name);A?m(A):x(r.movedProject(b.name,r.ordinal(M+1,!1),S.length))}))},y=b=>[...document.querySelectorAll(b)].map(M=>{const S=M.getBoundingClientRect();return S.top+S.height/2});return{can:h,said:i,problem:d,lift:o,sheet:p,setSheet:g,rowDrag:(b,M)=>({lifted:o&&o.kind==="session"&&o.gid===b.id&&o.from===M?o.dy:null,onLift:S=>c({kind:"session",gid:b.id,from:M,to:M,y0:S,dy:0,mids:y(`[data-reorder-section="${CSS.escape(b.id)}"] [data-reorder-row]`)}),onDrag:S=>c($=>$&&{...$,dy:S-$.y0,to:si($.mids,$.from,S)}),onDrop:()=>{const S=o;c(null),S&&k(b,S.from,S.to)},onCancel:()=>c(null)}),projectDrag:(b,M)=>{const S=b.filter(v=>v.kind==="project"&&v.project),$=S.indexOf(M);return{lifted:o&&o.kind==="project"&&o.gid===M.id?o.dy:null,onLong:()=>g(M),onLift:v=>c({kind:"project",gid:M.id,from:$,to:$,y0:v,dy:0,mids:S.map(A=>y(`[data-reorder-section="${CSS.escape(A.id)}"]`)[0]??0)}),onDrag:v=>c(A=>A&&{...A,dy:v-A.y0,to:si(A.mids,A.from,v)}),onDrop:()=>{const v=o;if(c(null),!v||v.to===v.from)return;const A=S[v.to],R=A?C().indexOf(A.project):-1;R>=0&&j(M,R)},onCancel:()=>c(null)}},stepsOf:(b,M)=>{const S=b.find(v=>v.kind==="project"&&v.sessions.some(A=>A.id===M));if(!S)return{};const $=S.sessions.findIndex(v=>v.id===M);return{...$>0?{up:()=>k(S,$,$-1)}:{},...$<S.sessions.length-1?{down:()=>k(S,$,$+1)}:{}}},projectStep:(b,M,S)=>{var R;const $=C(),v=$.indexOf(M.project??""),A=v+S;return v<0||A<0||A>=$.length||!((R=l.daemon)!=null&&R.projectEdit)?void 0:()=>j(M,A)}}}const Fe=u.compare,ri=t=>{const n=t.replace(/\D/g,"");return[n.slice(0,3),n.slice(3)]},da="\0",br=t=>{const[n="",s=""]=t.split(da);return[n,s]};function bn({login:t}){return t?e.jsxs("div",{className:"flex h-8 items-center gap-2 self-center rounded-full border border-line pr-3 pl-1 text-body text-muted",children:[e.jsx("span",{"aria-hidden":"true",className:"inline-flex size-6 items-center justify-center rounded-full bg-raised text-meta font-semibold text-fg",children:t.slice(0,1).toUpperCase()}),u.account(t)]}):null}function rj({step:t,login:n,pcName:s,lost:a,stalled:r=!1,reach:l="pc_online",onRetry:o,onSame:c,onCancel:i,onRestart:x,onDone:d,actions:m}){var M,S;const[p,g]=f.useState(!1),h=s??u.yourPc,N=()=>{g(!1),x()},k=e.jsx("button",{type:"button",onClick:N,className:dt,children:Fe.retry}),C=a&&(t==null?void 0:t.step)!=="linked"?e.jsx(De,{title:Fe.lostTitle,role:"status",children:e.jsx("p",{children:Fe.lostBody})}):null;if((t==null?void 0:t.step)==="linked")return e.jsxs(Mt,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(Us,{size:88}),e.jsx("h1",{className:Ht,children:Fe.doneTitle(t.pc.name??s??u.yourPc,sl(((M=globalThis.navigator)==null?void 0:M.userAgent)??"",((S=globalThis.navigator)==null?void 0:S.maxTouchPoints)??0).replace(/ tablette$/,""))}),e.jsx("p",{className:"max-w-[300px] text-muted",children:Fe.doneBody})]}),e.jsx(Et,{}),m??e.jsx("a",{href:ce({name:"sessions"}),onClick:d,className:Nt,children:Fe.seePending})]});if((t==null?void 0:t.step)==="cancelled"&&p)return e.jsxs(Mt,{children:[e.jsx(bn,{login:n}),e.jsxs("section",{role:"alert",className:"rounded-control border border-danger-fg/15 bg-danger-bg p-4 text-danger-fg",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2.5",children:[e.jsx(z,{name:"warning",stroke:1.5}),e.jsx("strong",{children:Fe.cancelledTitle})]}),e.jsx("p",{className:"text-body leading-[1.6]",children:Fe.cancelledBody})]}),e.jsx(Et,{}),k]});const j=(t==null?void 0:t.step)==="cancelled"?[Fe.cancelledTitle,null]:!t&&r?[Fe.stalledTitle,Fe.stalledBody]:(t==null?void 0:t.step)==="expired"?[Fe.expiredTitle,Fe.expiredBody]:(t==null?void 0:t.step)==="refused"?[Fe.refusedTitle,Fe.refusedBody]:null;if(j)return e.jsxs(Mt,{children:[e.jsx(bn,{login:n}),e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:Ht,children:j[0]}),j[1]&&e.jsx("p",{className:"text-muted",children:j[1]})]}),C,e.jsx(Et,{}),k]});if((t==null?void 0:t.step)==="compare"&&t.phoneConfirmed)return e.jsxs(Mt,{top:"pt-40",children:[e.jsx(bn,{login:n}),e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(As,{}),e.jsx("h1",{className:Ht,children:Fe.waitTitle}),e.jsxs("p",{className:"max-w-[300px] text-muted",children:[br(Fe.waitBody(h,da))[0],e.jsx("span",{className:"font-mono text-fg",children:ri(t.code).join(" ")}),br(Fe.waitBody(h,da))[1]]})]}),e.jsx(Et,{}),e.jsx("button",{type:"button",onClick:i,className:dt,children:Fe.cancel})]});if((t==null?void 0:t.step)==="compare"){const[$,v]=ri(t.code),[A,R]=br(Fe.intro(da));return e.jsxs(Mt,{children:[e.jsx(bn,{login:n}),e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:Ht,children:Fe.title}),e.jsxs("p",{className:"text-muted",children:[A,e.jsx("strong",{className:"font-semibold text-fg",children:h}),R]})]}),e.jsxs("div",{className:"flex flex-col items-center gap-3 rounded-control border border-line bg-surface px-4 py-6",children:[e.jsxs("div",{"aria-label":Fe.codeLabel(`${$} ${v}`),className:"flex justify-center gap-3.5 font-mono text-[2.5rem] leading-[48px] font-semibold tracking-[.06em]",children:[e.jsx("span",{children:$}),e.jsx("span",{children:v})]}),e.jsx("span",{className:"text-small text-muted",children:Fe.basis})]}),C,e.jsx(Et,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:c,className:Nt,children:Fe.same}),e.jsx("button",{type:"button",onClick:()=>{g(!0),i()},className:dt,children:Fe.different})]})]})}const y=t&&e.jsx("button",{type:"button",onClick:i,className:dt,children:Fe.cancel}),b=l==="pc_offline"?[Fe.offlineTitle,Fe.offlineBody(h)]:l==="relay_unreachable"?[Fe.relayTitle,Fe.relayBody]:null;return b?e.jsxs(Mt,{top:"pt-40",children:[e.jsx(bn,{login:n}),e.jsxs("div",{role:"status",className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:Ht,children:b[0]}),e.jsx("p",{className:"text-muted",children:b[1]})]}),C,e.jsx(Et,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:o,className:Nt,children:Fe.retryNow}),y]})]}):e.jsxs(Mt,{top:"pt-40",children:[e.jsx(bn,{login:n}),e.jsxs("div",{role:"status",className:"flex flex-col items-center gap-3.5 text-center text-muted",children:[e.jsx(As,{}),e.jsx("p",{children:Fe.waitCode})]}),C,e.jsx(Et,{}),y]})}const pt=u.recover,Me=u.recover.no;function Kn(){var n,s;const t=sl(((n=globalThis.navigator)==null?void 0:n.userAgent)??"",((s=globalThis.navigator)==null?void 0:s.maxTouchPoints)??0);return t==="iPhone"||t==="iPad"?t:null}const lj=["key","shield","laptop"];function oj({login:t,platform:n,onPasskey:s,onCode:a}){const r=Kn();return e.jsxs(Mt,{children:[e.jsx(bn,{login:t}),e.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[e.jsx(Us,{size:72}),e.jsx("h1",{className:Ht,children:pt.title(r)}),e.jsx("p",{className:"max-w-[320px] text-muted",children:pt.lead})]}),n&&e.jsx("ul",{className:"flex flex-col gap-3 text-body leading-5 text-fg/85",children:pt.notes(Kn()).map((l,o)=>e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx(z,{name:lj[o],className:"size-5 text-muted"}),l]},o))}),e.jsx(Et,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[n&&e.jsxs("button",{type:"button",onClick:s,className:Nt,children:[e.jsx(z,{name:"face"}),pt.go]}),e.jsx("button",{type:"button",onClick:a,className:n?dt:Nt,children:pt.code})]})]})}const ij={warn:"bg-attention/12 text-attention",bad:"bg-danger-bg text-danger-fg"};function cj({icon:t,tone:n}){return e.jsx("span",{"aria-hidden":"true",className:`inline-flex size-12 flex-none items-center justify-center rounded-full ${ij[n]}`,children:e.jsx(z,{name:t,className:"size-6"})})}function on({login:t,icon:n,tone:s,title:a,body:r,centred:l=!1,children:o,actions:c}){return e.jsxs(Mt,{children:[e.jsx(bn,{login:t}),e.jsxs("div",{role:"alert",className:`flex flex-col gap-3 ${l?"items-center text-center":"items-start"}`,children:[e.jsx(cj,{icon:n,tone:s}),e.jsx("h1",{className:Ht,children:a}),e.jsx("p",{className:"text-muted",children:r})]}),o&&e.jsx("div",{className:"flex flex-col gap-2.5 text-body leading-[1.5] text-muted",children:o}),e.jsx(Et,{}),e.jsx("div",{className:"flex flex-col gap-3",children:c})]})}const ts=({lead:t,children:n})=>e.jsxs("p",{children:[t&&e.jsx("strong",{className:"font-semibold text-fg",children:t}),t&&" ",n]}),dj=t=>{if(!t)return null;const n=new Date(t);return Number.isNaN(n.getTime())?null:n.toLocaleDateString(ut,{day:"numeric",month:"short"})};function uj({state:t,login:n,reach:s,onRetry:a,onCode:r,onCancel:l,onSignOut:o,onDone:c,actions:i}){const x=Kn(),d=(g=!0)=>e.jsx("button",{type:"button",onClick:r,className:g?Nt:dt,children:pt.code},"code"),m=(g=!1)=>e.jsx("button",{type:"button",onClick:a,className:g?Nt:dt,children:pt.retry},"retry");if(t.step==="reaching"||t.step==="faceid"||t.step==="checking"){const g=(t.step==="reaching"?null:t.pcName)??u.yourPc,h=[[t.step==="reaching"?pt.checking.reaching(g):pt.checking.reached(g),t.step==="reaching"?"on":"done"],[Pt()?pt.checking.faceId:pt.checking.check,t.step==="faceid"?"on":t.step==="checking"?"done":"next"],[pt.checking.verifying(g),t.step==="checking"?"on":"next"]];return e.jsxs(Mt,{top:"pt-40",children:[e.jsx(bn,{login:n}),e.jsxs("div",{role:"status",className:"flex flex-col items-center gap-3 text-center",children:[e.jsx(As,{}),e.jsx("h1",{className:Ht,children:pt.checking.title}),e.jsx("p",{className:"max-w-[320px] text-muted",children:pt.checking.body(g)})]}),e.jsx("ol",{className:"flex flex-col gap-2.5 rounded-[10px] border border-line px-4 py-3.5 text-body",children:h.map(([N,k])=>e.jsxs("li",{className:`flex items-center gap-2.5 ${k==="on"?"font-medium text-fg":"text-muted"}`,children:[k==="done"?e.jsx(z,{name:"check",className:"size-[18px] text-ok"}):k==="on"?e.jsx(As,{size:"size-[18px]"}):e.jsx("span",{className:"size-[18px]","aria-hidden":"true"}),N]},N))}),e.jsx(Et,{}),e.jsx("button",{type:"button",onClick:l,className:dt,children:pt.cancel})]})}if(t.step==="done"){const g=t.pc.name??u.yourPc;return e.jsxs(Mt,{top:"pt-14",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[e.jsx(Us,{size:88}),e.jsx("h1",{className:Ht,children:pt.done.title(x,g)}),e.jsx("p",{className:"max-w-[320px] text-muted",children:pt.done.body(g)})]}),e.jsxs("p",{role:"status",className:"flex items-center gap-2 self-center text-small text-ok",children:[e.jsx(z,{name:"check",className:"size-4"}),pt.done.told(g)]}),e.jsx(Et,{}),i??e.jsx("a",{href:ce({name:"sessions"}),onClick:c,className:Nt,children:u.compare.seePending})]})}if(t.step==="cancelled")return null;const p=t.pcName??u.yourPc;switch(t.why){case"none":return e.jsx(on,{login:n,icon:"key",tone:"warn",title:Me.none.title,body:Me.none.body(p),actions:[m(!0),d(!1)],children:e.jsx(ts,{lead:Me.none.hintTitle,children:Me.none.hint})});case"revoked":return e.jsx(on,{login:n,icon:"unlink",tone:"bad",title:Me.revoked.title(x),body:Me.revoked.body(p,dj(t.revokedAt)),actions:[d()],children:e.jsx("p",{children:Me.revoked.hint})});case"old":return e.jsx(on,{login:n,icon:"key",tone:"warn",title:Me.old.title,body:Me.old.body,actions:[d()],children:e.jsx(ts,{lead:Me.old.hintTitle,children:Me.old.hint(x)})});case"offline":{const[g,h]=s==="relay_unreachable"?[u.compare.relayTitle,u.compare.relayBody]:[Me.offline.title(p),Me.offline.body(p)];return e.jsx(on,{login:n,icon:"wifioff",tone:"warn",centred:!0,title:g,body:h,actions:[m(!0),e.jsx("button",{type:"button",onClick:l,className:dt,children:pt.cancel},"cancel")]})}case"otherPc":{const[g,h]=t.tags??["",""];return e.jsxs(on,{login:n,icon:"shield",tone:"bad",title:Me.otherPc.title(p),body:Me.otherPc.body,actions:[d(),e.jsx("button",{type:"button",onClick:o,className:dt,children:Me.otherPc.signOut},"out")],children:[e.jsxs("dl",{className:"grid grid-cols-[auto_1fr] gap-x-4 gap-y-2.5 rounded-control border border-line bg-surface p-4 text-body text-fg",children:[e.jsx("dt",{className:"text-muted",children:Me.otherPc.inPasskey}),e.jsxs("dd",{className:"font-mono",children:[g," · ",Me.otherPc.expected]}),e.jsx("dt",{className:"text-muted",children:Me.otherPc.received}),e.jsxs("dd",{className:"font-mono text-danger-fg",children:[h," · ",Me.otherPc.unknown]})]}),e.jsx(ts,{lead:Me.otherPc.reinstalledTitle,children:Me.otherPc.reinstalledBody}),e.jsx(ts,{lead:Me.otherPc.otherwise,children:Me.otherPc.warning})]})}case"connected":return e.jsxs(on,{login:n,icon:t.device==="iPhone"?"phone":"tablet",tone:"warn",title:Me.connected.title(t.device),body:Me.connected.body(p),actions:[d(),m()],children:[e.jsx(ts,{lead:Me.connected.otherTitle(t.device),children:Me.connected.other}),e.jsx(ts,{lead:Me.connected.reinstalledTitle(t.device),children:Me.connected.reinstalled(t.device)})]});case"rate":{const g=t.retryInMs!==void 0?Math.max(1,Math.ceil(t.retryInMs/6e4)):null;return e.jsx(on,{login:n,icon:"clock",tone:"warn",title:Me.rate.title,body:Me.rate.body(p,g),actions:[d(),...g!==null?[e.jsx("button",{type:"button",disabled:!0,className:dt,children:Me.rate.retryIn(g)},"wait")]:[]]})}case"blocked":return e.jsx(on,{login:n,icon:"lock",tone:"bad",title:Me.blocked.title(p),body:Me.blocked.body(p),actions:[d()],children:e.jsxs("p",{children:[Me.blocked.hintBefore(p),e.jsx("strong",{className:"font-semibold text-fg",children:Me.blocked.unblock}),Me.blocked.hintAfter]})});case"timeout":return e.jsx(on,{login:n,icon:"clock",tone:"warn",centred:!0,title:Me.timeout.title(p),body:Me.timeout.body,actions:[m(!0),d(!1)]});case"unsaved":return e.jsx(on,{login:n,icon:x==="iPad"?"tablet":"phone",tone:"warn",centred:!0,title:Me.unsaved.title,body:Me.unsaved.body(p,x),actions:[m(!0),d(!1)]})}}const jn=u.enroll;function Gs(t,n="protect",s=!0){var v,A,R,_;const a=me(t),r=xn(),l=(v=a.device)==null?void 0:v.confirm,o=r&&(n==="protect"?l===!1:l===!0&&!((A=a.device)!=null&&A.recover)),[c,i]=f.useState(null),[x,d]=f.useState(null),[m,p]=f.useState(!1),[g,h]=f.useState(null),[N,k]=f.useState(0),C=g?(R=a.ops[g])==null?void 0:R.phase:void 0,j=(n==="protect"?l===!0:((_=a.device)==null?void 0:_.recover)===!0)||C==="applied",y=C==="sending"||C==="uncertain",b=C==="rejected"||C==="failed";f.useEffect(()=>{if(!s||!o||j)return;let L=!0;i(null);const T=t.pcKey();return Promise.all([t.prepareConfirm({purpose:"register"}),T?Um(T):Promise.reject(new Error("unpaired"))]).then(([B,E])=>{L&&i({challenge:B,userId:E})},()=>{L&&d("prepareFailed")}),()=>{L=!1}},[t,o,j,N,s]);const M=()=>{var E,P;if(!c||m||y)return;const{challenge:L,userId:T}=c;p(!0),d(null);const B=sl(((E=globalThis.navigator)==null?void 0:E.userAgent)??"",((P=globalThis.navigator)==null?void 0:P.maxTouchPoints)??0);Wm({challenge:L.challenge,rpId:L.rpId},{label:B,id:T}).then(W=>{if(p(!1),W==="cancelled"){d("cancelled");return}if(W==="unsupported"){d("unsupported");return}i(null);const F=t.registerCredential(W,Km(T));F===null?d("failed"):h(F)},()=>{p(!1),d("failed")})},S=()=>{d(null),h(null),k(L=>L+1)},$=x??(b?"failed":null);return{offered:o,registered:j,challenge:(c==null?void 0:c.challenge)??null,asking:m||y,problem:$,go:M,retry:S}}function su({e:t,className:n,label:s=jn.go}){const a=t.problem==="failed"||t.problem==="prepareFailed",r=t.problem==="cancelled"?u.confirm.cancelled:t.problem==="unsupported"?jn.unsupported:t.problem==="failed"?u.confirm.failed:t.problem==="prepareFailed"?u.confirm.prepareFailed:null;return e.jsxs(e.Fragment,{children:[r&&e.jsx(De,{title:r,tone:"warning",role:"alert"}),a?e.jsx("button",{type:"button",onClick:t.retry,className:n,children:u.confirm.retry}):t.problem==="unsupported"?null:e.jsx("button",{type:"button",disabled:!t.challenge||t.asking,onClick:t.go,className:n,children:t.challenge||t.asking?s:u.confirm.preparing})]})}function mj({store:t}){const n=Gs(t);return n.registered?e.jsx(li,{children:jn.done}):n.offered?e.jsx(li,{children:e.jsx("div",{className:"flex flex-col items-end gap-2",children:e.jsx(su,{e:n,className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 text-body font-medium disabled:opacity-45"})})}):null}function li({children:t}){return e.jsxs("div",{className:"flex items-baseline justify-between gap-4 border-b border-line px-4 py-3 last:border-b-0",children:[e.jsx("dt",{className:"flex-none text-muted",children:jn.row}),e.jsx("dd",{className:"min-w-0 text-right break-words",children:t})]})}function xj({store:t,onDone:n,update:s=!1}){const a=Gs(t),[r,l]=f.useState(!1);f.useEffect(()=>{a.offered&&l(!0)},[a.offered]);const o=ce({name:"sessions"});return r?a.registered?e.jsxs(e.Fragment,{children:[e.jsx(De,{title:jn.done,role:"status"}),e.jsx("a",{href:o,onClick:n,className:Nt,children:u.compare.seePending})]}):e.jsxs(e.Fragment,{children:[e.jsxs("section",{"aria-labelledby":"protect-title",className:"flex flex-col gap-3 rounded-control border border-line bg-surface p-4",children:[e.jsx("h2",{id:"protect-title",className:"text-title leading-[1.35] font-semibold",children:s?u.passkeyUpdate.title:jn.title}),e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:s?u.passkeyUpdate.stepBody(Kn()):jn.body}),e.jsx(su,{e:a,className:Nt,label:s?u.passkeyUpdate.go:jn.go})]}),e.jsx("a",{href:o,onClick:n,className:dt,children:jn.later})]}):e.jsx("a",{href:o,onClick:n,className:Nt,children:u.compare.seePending})}const ft=u.passkeyUpdate,pj=3e3,au="ledge.mobile.passkeyUpdateLater",ru=(t,n)=>{try{return!!n&&(t==null?void 0:t.getItem(au))===n}catch{return!1}},Xr="ledge:passkey-later";function lu(t,n=globalThis.localStorage){const s=me(t),a=xn(),r=s.device,[,l]=f.useState(0);return f.useEffect(()=>{const o=()=>l(c=>c+1);return globalThis.addEventListener(Xr,o),()=>globalThis.removeEventListener(Xr,o)},[]),a&&(r==null?void 0:r.confirm)===!0&&!r.recover&&!ru(n,r.id)}function fj({store:t,storage:n=globalThis.localStorage,enroll:s}){var g;const a=Gs(t,"update",!s),r=s??a,l=(g=me(t).device)==null?void 0:g.id,[o,c]=f.useState(()=>ru(n,l)),[i,x]=f.useState(!1);if(f.useEffect(()=>{r.offered&&!o&&x(!0)},[r.offered,o]),f.useEffect(()=>{if(!i||!r.registered)return;const h=setTimeout(()=>x(!1),pj);return()=>clearTimeout(h)},[i,r.registered]),!i)return null;if(r.registered)return e.jsxs("div",{role:"status",className:"flex items-start gap-3 rounded-card border border-line bg-surface p-4",children:[e.jsx(z,{name:"check",className:"size-5 text-ok"}),e.jsxs("span",{className:"flex flex-col gap-0.5",children:[e.jsx("strong",{className:"text-body font-semibold",children:ft.done}),e.jsx("small",{className:"text-small text-muted",children:ft.doneBody(Kn())})]})]});if(o)return null;const d=()=>{try{l&&(n==null||n.setItem(au,l))}catch{}globalThis.dispatchEvent(new Event(Xr)),c(!0),x(!1)},m=r.problem==="failed"||r.problem==="prepareFailed"||r.problem==="unsupported",p=r.problem==="cancelled"?ft.cancelled:m?ft.failed(t.pcName()??u.yourPc):null;return e.jsxs("section",{"aria-labelledby":"passkey-update-title",className:"flex flex-col gap-3 rounded-card border border-info/30 bg-info/[0.06] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{"aria-hidden":"true",className:"inline-flex size-9 items-center justify-center rounded-full bg-raised text-muted",children:e.jsx(z,{name:"key",className:"size-[18px]"})}),e.jsx("h2",{id:"passkey-update-title",className:"text-title leading-[1.35] font-semibold",children:ft.title})]}),p?e.jsx(De,{title:p,tone:r.problem==="cancelled"?"warning":"danger",role:"alert"}):e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:Pt()?ft.body(Kn()):ft.bodyOther(Kn())}),e.jsxs("div",{className:p?"grid grid-cols-2 gap-2":"flex flex-col gap-2",children:[p?e.jsx("button",{type:"button",onClick:m?r.retry:r.go,disabled:!m&&!r.challenge,className:Nt,children:ft.retry}):e.jsx("button",{type:"button",onClick:r.go,disabled:!r.challenge||r.asking,className:Nt,children:r.asking?e.jsxs(e.Fragment,{children:[e.jsx(As,{size:"size-4"}),ft.updating]}):r.challenge?ft.go:u.confirm.preparing}),e.jsx("button",{type:"button",onClick:d,disabled:r.asking,className:dt,children:ft.later})]})]})}const oi=t=>t.problem==="failed"||t.problem==="prepareFailed";function hj({store:t,enroll:n,quiet:s=!1}){const a=Gs(t,"update",!n),r=n??a,l=me(t).device;return l!=null&&l.confirm?r.registered?e.jsxs("div",{className:"flex items-baseline justify-between gap-4 border-b border-line px-4 py-3 last:border-b-0",children:[e.jsx("dt",{className:"flex-none text-muted",children:ft.row}),e.jsx("dd",{className:"text-right text-ok",children:ft.ready})]}):r.offered?e.jsxs("div",{className:"flex flex-col gap-2 border-b border-line px-4 py-3 last:border-b-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("dt",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{children:ft.row}),e.jsx("span",{className:"text-small text-muted",children:ft.rowHint})]}),e.jsx("dd",{className:"flex-none",children:e.jsx("button",{type:"button",disabled:r.asking||!oi(r)&&!r.challenge,onClick:oi(r)?r.retry:r.go,className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 text-body font-medium disabled:opacity-45",children:r.asking?ft.updating:ft.update})})]}),r.problem&&!s&&e.jsx(De,{title:r.problem==="cancelled"?ft.cancelled:ft.failed(t.pcName()??u.yourPc),tone:"warning",role:"alert"})]}):null:null}const Ds=(t,n)=>(t.slice(0,n===void 0?void 0:n*4).match(/.{1,4}/g)??[]).join(" "),ou=t=>Ds(t,6),gj=t=>Ds(t,2);function iu(t){var r;const n=me(t),s=Kt();if(!((r=n.daemon)!=null&&r.usage)||!n.usage||!n.fresh)return null;const a=Mf(Ba(n.usage,s,n.fresh),n.usageAlert,s);return a.find(l=>l.tone==="red")??a[0]??null}function bj({store:t}){const n=me(t),s=Kt(),a=u.limits,r=iu(t),l=c=>a.harness[c]??c,o=r&&(()=>{const c=jl(r.window),i=r.tone==="red"?a.reachedLabel(l(r.harness),c):a.overLabel(l(r.harness),c,r.window.pct),x=r.window.resetsAt?Uc(r.window.resetsAt,s):null;return x?`${i} · ${hl(r.window.resetsAt,s)?a.resumesOn(x):a.resumes(x)}`:i})();return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:"bleed flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-2.5",children:[e.jsx(Zt,{fallback:{name:"connection"},label:u.connection.title}),e.jsx("h1",{className:"text-base font-semibold",children:u.settings.usage})]}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto pt-5 pb-[34px]",children:[o&&e.jsx(De,{title:o,tone:r.tone==="red"?"danger":"warning",role:"status"}),n.usage===null?e.jsx("p",{role:"status",className:"text-small text-muted",children:a.loading}):e.jsx("div",{className:"rounded-[10px] border border-line bg-surface px-4 py-2",children:e.jsx(mh,{usage:n.usage,now:s,alert:n.usageAlert,fresh:n.fresh,heading:!1})})]})]})}function cu(){const t=globalThis;if(!t.Notification||!t.PushManager)return"unsupported";const n=t.navigator;return n&&"standalone"in n&&n.standalone!==!0?"unsupported":t.Notification.permission==="denied"?"denied":"ok"}const jj=t=>{const n=atob(t.replace(/-/g,"+").replace(/_/g,"/"));return Uint8Array.from(n,s=>s.charCodeAt(0))};function du(t,n){return new Promise(s=>{const a=()=>{var o;const l=(o=t.getState().ops[n])==null?void 0:o.phase;return!l||yn(l)&&l!=="uncertain"?!1:(r(),s(l==="applied"?"applied":"other"),!0)},r=t.subscribe(a);a()})}async function yj(t,n=(s,a)=>globalThis.fetch(s,a)){var a;if(cu()==="unsupported")return"unsupported";try{if(await Notification.requestPermission()!=="granted")return"denied";const r=await n("/push/key",{credentials:"same-origin",cache:"no-store"});if(r.status===404)return"unavailable";if(!r.ok)return"failed";const l=await r.json();if(typeof l.publicKey!="string")return"failed";const o=l.publicKey,c=jj(o),{pushManager:i}=await navigator.serviceWorker.ready;await((a=await i.getSubscription())==null?void 0:a.unsubscribe());const x=await i.subscribe({userVisibleOnly:!0,applicationServerKey:c}),d=mm.safeParse(x.toJSON());if(!d.success)return"failed";const m=t.pushSubscribe(d.data,o);return m===null?"failed":await du(t,m)==="applied"?"on":"failed"}catch{return"failed"}}async function Nj(t){const n=t.pushUnsubscribe(),s=n!==null&&await du(t,n)==="applied";try{await(await navigator.serviceWorker.ready).pushManager.getSubscription().then(a=>a==null?void 0:a.unsubscribe())}catch{}return s}const _t=u.notifications,kj=t=>t==="denied"?_t.denied:t==="unsupported"?_t.unsupported:t==="unavailable"?_t.noPush:t==="failed"?_t.failed:null;function uu(t,n){var x;const s=(x=me(t).device)==null?void 0:x.push,[a,r]=f.useState(!1),[l,o]=f.useState(null);return{push:s,busy:a,problem:l,enable:async()=>{if(a)return"failed";r(!0),o(null);const d=await yj(t,n);return r(!1),o(kj(d)),d},disable:async()=>{a||(r(!0),o(null),await Nj(t),r(!1))}}}function vj({store:t,fetchImpl:n}){const s=uu(t,n);if(!s.push)return null;const a=s.push==="on";return e.jsxs("div",{className:"flex flex-col gap-2 border-b border-line px-4 py-3 text-body last:border-b-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("dt",{className:"flex-none text-muted",children:_t.row}),e.jsx("dd",{className:"flex min-w-0 items-center gap-3 text-right",children:s.push==="unavailable"?e.jsx("span",{children:_t.noPush}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:a?_t.on:_t.off}),e.jsx(Wa,{on:a,label:_t.row,disabled:s.busy,onChange:r=>{r?s.enable():s.disable()}})]})})]}),s.push==="stale"&&e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[e.jsx("p",{className:"text-muted",children:_t.stale}),e.jsx("button",{type:"button",disabled:s.busy,onClick:()=>{s.enable()},className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 font-medium disabled:opacity-45",children:_t.enable})]}),s.problem&&e.jsx(De,{title:s.problem,tone:"warning",role:"alert"})]})}const ii=t=>(t==="off"||t==="stale")&&cu()!=="unsupported";function ci({store:t,onDone:n,fetchImpl:s,body:a=_t.body}){const r=uu(t,s),l=me(t).fresh,o=()=>{r.enable().then(c=>{c==="on"&&(os({name:"sessions"}),n())})};return e.jsxs(e.Fragment,{children:[e.jsxs("section",{"aria-labelledby":"notify-title",className:"flex flex-col gap-3 rounded-control border border-line bg-surface p-4",children:[e.jsx("h2",{id:"notify-title",className:"text-title leading-[1.35] font-semibold",children:_t.title}),e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:a}),r.problem&&e.jsx(De,{title:r.problem,tone:"warning",role:"alert"}),e.jsx("button",{type:"button",disabled:r.busy||!l,onClick:o,className:Nt,children:r.busy?_t.working:l?_t.enable:_t.waiting})]}),e.jsx("a",{href:ce({name:"sessions"}),onClick:n,className:dt,children:_t.later})]})}function wj(t,n){switch(t.status){case"applied":return{text:n,quiet:!1};case"cancelled":return{text:u.confirm.cancelled,quiet:!0};case"expired":return{text:u.confirm.expired,quiet:!0};case"rejected":return t.reason==="assertion_expired"?{text:u.confirm.expired,quiet:!0}:{text:u.confirm.refused[t.reason]??n,quiet:!1};default:return{text:n,quiet:!1}}}const Te=u.connection.pcUpdate,Rs="flex flex-col gap-3 rounded-card border bg-surface p-3.5";function Sj({store:t,action:n,pc:s,from:a,to:r,onClose:l}){var g;const o=f.useId(),c=!!((g=me(t).device)!=null&&g.confirm),[i,x]=f.useState(!1),[d,m]=f.useState(null),p=()=>{x(!0),m(null),t.pcAction(n,n==="update"?r:void 0).then(h=>{h.status==="applied"?l():m(wj(h,Te.notDone))},()=>m({text:Te.notDone,quiet:!1})).finally(()=>x(!1))};return e.jsxs(ht,{labelledBy:`${o}-title`,onClose:()=>{i||l()},children:[e.jsx("h2",{id:`${o}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:n==="update"?Te.confirmUpdate:Te.confirmRestart}),e.jsx("p",{className:"text-body text-muted",children:n==="update"?Te.confirmUpdateBody(s,a,r):Te.confirmRestartBody(s)}),e.jsx("p",{className:`rounded-control border border-dashed border-input px-3 py-2 text-small ${c?"text-muted":"text-attention"}`,children:c?Te.passkey:Te.noPasskey}),d&&e.jsx("p",{role:"status",className:`text-body ${d.quiet?"text-muted":"text-danger-fg"}`,children:d.text}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ue,{variant:"ghost",className:"flex-1",disabled:i,onClick:l,children:Te.cancel}),e.jsx(Ue,{variant:"primary",className:"flex-[2]",disabled:i||!c,onClick:p,children:Te.confirm})]})]})}function Cj({run:t,fresh:n}){const s=t.action==="update"?["asked","installing","restarting","back"]:["asked","restarting","back"],a=t.step==="restarting"?n?s.indexOf("restarting"):s.length-1:1;return e.jsx("ol",{className:"flex flex-col gap-1.5 text-small",children:s.map((r,l)=>e.jsxs("li",{className:`flex items-center gap-2 ${l>a?"text-muted":""}`,children:[e.jsx("span",{"aria-hidden":"true",className:"w-4 text-center",children:l<a?"✓":l===a?"…":"·"}),e.jsx("span",{children:Te.steps[r]})]},r))})}function $j({store:t,run:n,fresh:s,from:a,onRetry:r}){const l=n.action==="update";return Hi(n)?e.jsxs("div",{className:`${Rs} border-line`,role:"status",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("strong",{className:"text-body",children:l?Te.updating(n.version):Te.restarting}),e.jsx("span",{className:"text-meta text-info",children:Te.running})]}),e.jsx(Cj,{run:n,fresh:s}),e.jsx("p",{className:"text-small text-muted",children:Te.leave})]}):n.step==="done"?e.jsxs("div",{className:`${Rs} border-ok/40`,role:"status",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("strong",{className:"text-body",children:l?Te.done(n.version):Te.restarted}),e.jsx("span",{className:"text-meta text-ok",children:Te.upToDate})]}),e.jsx(Ue,{onClick:()=>t.dismissPc(),children:Te.close})]}):e.jsxs("div",{className:`${Rs} border-danger-fg/40`,role:"alert",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("strong",{className:"text-body",children:l?Te.failed:Te.notRestarted}),e.jsx("span",{className:"text-meta text-danger-fg",children:Te.refused})]}),e.jsxs("p",{className:"text-small text-muted",children:[Te.unchanged(a)," ",n.reason?Te.reasons[n.reason]:""]}),e.jsx(Ue,{onClick:r,children:Te.retry})]})}function Mj({store:t,appVersion:n}){const s=me(t),[a,r]=f.useState(null),l=s.daemon,o=s.pc;if(!l)return null;const c=n!==null&&qi(l.version,n);if(!c&&!l.restart&&!o)return null;const i=l.name,x=()=>{t.dismissPc(),((o==null?void 0:o.action)==="restart"||n)&&r((o==null?void 0:o.action)??"restart")};return e.jsxs("section",{"aria-labelledby":"pc-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"pc-title",className:"text-small font-medium text-muted",children:Te.title}),o?e.jsx($j,{store:t,run:o,fresh:s.fresh,from:l.version,onRetry:x}):c&&(l.update?e.jsxs("div",{className:`${Rs} border-input`,children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("strong",{className:"text-body",children:Te.behind}),e.jsx("span",{className:"font-mono text-small text-muted",children:Te.versions(l.version,n)})]}),e.jsx("p",{className:"text-small text-muted",children:Te.why}),e.jsx(Ue,{variant:"primary",block:!0,disabled:!s.fresh,onClick:()=>r("update"),children:Te.update}),e.jsx("p",{className:"text-meta text-muted",children:Te.keepGoing})]}):e.jsxs("div",{className:`${Rs} border-attention/40`,children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("strong",{className:"text-body",children:Te.manual}),e.jsx("span",{className:"font-mono text-small text-muted",children:Te.versions(l.version,n)})]}),e.jsx("p",{className:"text-small text-muted",children:l.restart?Te.clone:Te.byHand})]})),l.restart&&e.jsxs("div",{className:"flex items-center gap-3 rounded-control border border-line px-3.5 py-3",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"text-body",children:Te.restart}),e.jsx("span",{className:"text-small text-muted",children:Te.restartHint})]}),e.jsx(Ue,{size:"sm",disabled:!s.fresh||Hi(o),onClick:()=>r("restart"),children:Te.restartGo})]}),a&&e.jsx(Sj,{store:t,action:a,pc:i,from:l.version,to:a==="update"&&n?n:l.version,onClose:()=>r(null)})]})}const Va="min-h-12 w-full min-w-0 rounded-control border border-input bg-surface px-3 text-base text-fg focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-info",Qe=u.settings,Ga="flex flex-col rounded-[10px] border border-line bg-surface text-body",mu="flex flex-col gap-1 border-b border-line px-4 py-3 last:border-b-0",Ej=Array.from({length:Math.round((hm-Kl)*20)+1},(t,n)=>Math.round((Kl+n*.05)*100)),_j=["decision"];function Il({label:t,hint:n,children:s}){const a=f.useId();return e.jsxs("div",{className:mu,children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"min-w-0",children:t}),s(n?a:void 0)]}),n&&e.jsx("p",{id:a,className:"text-small text-muted",children:n})]})}function Rj(t,n){if(t==="hour")return new Date(n.getTime()+36e5);if(t==="four")return new Date(n.getTime()+4*36e5);const s=new Date(n);return s.setDate(s.getDate()+1),s.setHours(8,0,0,0),s}function Tj(t,n){const s=t.toLocaleTimeString(ut,{hour:"2-digit",minute:"2-digit"});if(t.toDateString()===n.toDateString())return s;const a=new Date(n);return a.setDate(a.getDate()+1),t.toDateString()===a.toDateString()?Qe.tomorrow(s):`${t.toLocaleDateString(ut,{day:"numeric",month:"short"})} ${s}`}function xu(t){var d;const n=me(t),[s,a]=f.useState(null),[r,l]=f.useState(!1),o=f.useRef(0),c=f.useRef(!0);return f.useEffect(()=>()=>{c.current=!1},[]),{prefs:s??((d=n.device)==null?void 0:d.prefs)??fm,send:m=>{const p=++o.current;a(m),l(!1),t.setDevicePrefs(m).then(g=>{!c.current||p!==o.current||(a(null),g.status!=="applied"&&l(!0))})},failed:r,fresh:n.fresh}}function Aj({store:t}){var i,x;const n=me(t),s=xu(t),a=Kt();if(!((i=n.daemon)!=null&&i.settings)||!((x=n.device)!=null&&x.prefs)||n.device.push!=="on")return null;const{prefs:r}=s,l=r.quietUntil!==null?new Date(r.quietUntil):null,o=l!==null&&l.getTime()>a,c=d=>s.send({...r,quietUntil:Rj(d,new Date(a)).toISOString()});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:Ga,children:[_j.map(d=>e.jsx(Il,{label:Qe.notify[d],hint:Qe.notify[`${d}Hint`],children:m=>e.jsx(Wa,{on:r.notify[d],label:Qe.notify[d],describedBy:m,disabled:!s.fresh,onChange:p=>s.send({...r,notify:{...r.notify,[d]:p}})})},d)),e.jsxs("div",{className:mu,children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{children:Qe.pause}),o&&e.jsx("span",{role:"status",className:"text-right text-attention",children:Qe.pausedUntil(Tj(l,new Date(a)))})]}),e.jsx("p",{className:"text-small text-muted",children:Qe.pauseHint}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-2",children:o?e.jsx("button",{type:"button",disabled:!s.fresh,onClick:()=>s.send({...r,quietUntil:null}),className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 font-medium disabled:opacity-45",children:Qe.resume}):["hour","four","morning"].map(d=>e.jsx("button",{type:"button","aria-label":Qe.pauseLabel[d],disabled:!s.fresh,onClick:()=>c(d),className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 font-medium disabled:opacity-45",children:Qe.pauseFor[d]},d))})]})]}),e.jsx("p",{className:"text-small text-muted",children:Qe.notify.always}),s.failed&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:Qe.failed})]})}function Ij({store:t}){var d,m;const n=me(t),s=xu(t),[a,r]=f.useState(null),[l,o]=f.useState(!1),c=f.useRef(!0);if(f.useEffect(()=>()=>{c.current=!1},[]),!((d=n.daemon)!=null&&d.settings)||!((m=n.device)!=null&&m.prefs))return null;const i=Math.round((a??n.device.contextNear??Ta)*100),x=p=>{r(p/100),o(!1),t.setContextNear(p/100).then(g=>{c.current&&(r(null),g.status!=="applied"&&o(!0))})};return e.jsxs("section",{"aria-labelledby":"ledge-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"ledge-title",className:"text-small font-medium text-muted",children:Qe.ledge}),e.jsx("div",{className:Ga,children:e.jsx(Il,{label:Qe.context,hint:Qe.contextHint,children:p=>e.jsx("select",{className:`${Va} w-auto`,"aria-label":Qe.context,"aria-describedby":p,disabled:!n.fresh||a!==null,value:i,onChange:g=>x(Number(g.target.value)),children:Ej.map(g=>e.jsx("option",{value:g,children:u.percent(g)},g))})})}),!n.fresh&&e.jsx("p",{className:"text-small text-muted",children:Qe.offline}),(l||s.failed)&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:Qe.failed})]})}function Lj(){const t=xm();return e.jsx("div",{className:Ga,children:e.jsx(Il,{label:Qe.motion,hint:Qe.motionHint,children:n=>e.jsx(Wa,{on:t,label:Qe.motion,describedBy:n,onChange:pm})})})}function Oj({store:t}){const n=me(t).daemon;return e.jsxs("section",{"aria-labelledby":"managed-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"managed-title",className:"text-small font-medium text-muted",children:Qe.managed}),(n==null?void 0:n.terminal)&&e.jsx("dl",{className:Ga,children:e.jsxs("div",{className:"flex items-baseline justify-between gap-4 px-4 py-3",children:[e.jsx("dt",{className:"text-muted",children:Qe.terminal}),e.jsx("dd",{children:n.terminalInput?Qe.allowed:Qe.notAllowed})]})}),e.jsx("p",{className:"text-small text-muted",children:Qe.managedBody})]})}const se=u.settings.projects,pu=Object.keys(ls),Dj=80,Xa=t=>se.errors[t.status==="rejected"?t.reason:t.status]??se.errors.failed;function Fj(t,n,s){const a=n+s;if(a<0||a>=t.length)return[...t];const r=[...t];return[r[n],r[a]]=[r[a],r[n]],r}function Pj({color:t}){return e.jsx("span",{className:"size-3 flex-none rounded-full",style:{background:ls[t]},"aria-hidden":"true"})}function zj({value:t,onChange:n,name:s}){return e.jsxs("fieldset",{className:"m-0 min-w-0 border-0 p-0",children:[e.jsx("legend",{className:"mb-1.5 text-small text-muted",children:se.color}),e.jsx("div",{className:"flex flex-wrap gap-2",children:pu.map(a=>e.jsxs("label",{className:"grid size-10 cursor-pointer place-items-center rounded-full border border-line has-[:checked]:border-fg has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-info",children:[e.jsx("input",{type:"radio",name:s,value:a,checked:t===a,onChange:()=>n(a),className:"sr-only","aria-label":se.colors[a]}),e.jsx("span",{className:"size-6 rounded-full",style:{background:ls[a]},"aria-hidden":"true"})]},a))})]})}function Bj({store:t,project:n,projects:s,onClose:a,onDelete:r,onFolders:l}){var T,B;const o=f.useId(),c=new Set(s.map(E=>E.color)),[i,x]=f.useState((n==null?void 0:n.name)??""),[d,m]=f.useState((n==null?void 0:n.color)??pu.find(E=>!c.has(E))??"blue"),[p,g]=f.useState(!1),[h,N]=f.useState(null),k=me(t),C=n===null&&!!((T=k.daemon)!=null&&T.projectFolders),j=!!((B=k.device)!=null&&B.confirm),[y,b]=f.useState(null),[M,S]=f.useState(!1);f.useEffect(()=>{C&&t.requestRecentFolders()},[t,C]);const $=i.trim(),v=$!==""&&s.some(E=>E.id!==(n==null?void 0:n.id)&&Gl(E.name)===Gl($)),A=n!==null&&$===n.name&&d===n.color,R=C&&(y===null||!j),_=()=>{if(!$||v||p||R)return;if(A){a();return}g(!0),N(null);const E=n?{...$!==n.name?{name:$}:{},...d!==n.color?{color:d}:{}}:null;(n?t.editProject(n.id,E):t.createProject($,d,C?y:void 0)).then(P=>{g(!1),P.status==="applied"?a():N(Xa(P))})};if(M)return e.jsxs(ht,{labelledBy:`${o}-title`,onClose:()=>S(!1),children:[e.jsx("h2",{id:`${o}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:se.firstFolder}),e.jsx(fu,{store:t,busy:!1,skip:()=>!1,rowLabel:se.choose,rowAria:se.chooseLabel,pickLabel:se.chooseThis,pickAria:se.chooseLabel,pickDisabled:!1,error:null,onPick:E=>{b(E),S(!1)},onBack:()=>S(!1)})]});const L=[...new Set([...y!==null?[y]:[],...k.recentFolders??[]])];return e.jsxs(ht,{labelledBy:`${o}-title`,onClose:()=>{p||a()},children:[e.jsx("h2",{id:`${o}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:n?se.editTitle:se.newTitle}),!n&&e.jsx("p",{className:"text-body text-muted",children:C?se.newBody:se.newBodyOld}),e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:E=>{E.preventDefault(),_()},children:[e.jsxs("label",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"text-small text-muted",children:se.name}),e.jsx("input",{className:Va,value:i,maxLength:Dj,autoFocus:!0,"aria-invalid":v||void 0,onChange:E=>x(E.target.value)}),v&&e.jsx("span",{role:"alert",className:"text-small text-danger-fg",children:se.errors.name_taken})]}),e.jsx(zj,{name:`${o}-color`,value:d,onChange:m}),C&&e.jsxs("section",{"aria-labelledby":`${o}-first`,className:"flex flex-col gap-1.5",children:[e.jsxs("h3",{id:`${o}-first`,className:"flex items-center gap-2 text-small text-muted",children:[se.firstFolder,e.jsx("span",{className:"rounded-full border border-task/45 px-2 text-meta text-task",children:se.required})]}),L.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{className:"text-meta tracking-[.06em] text-muted uppercase",children:se.recents}),e.jsx("ul",{className:"flex flex-col rounded-control border border-line",children:L.map(E=>e.jsxs("li",{className:Ts,children:[e.jsxs("button",{type:"button","aria-pressed":y===E,"aria-label":se.chooseLabel(E),disabled:p,onClick:()=>b(E),className:`flex min-h-10 min-w-0 flex-1 items-center gap-2 text-left ${y===E?"font-medium text-fg":""}`,children:[e.jsx(z,{name:y===E?"check":"folder",className:"size-4 flex-none"}),e.jsx("span",{className:"font-mono text-small break-all",children:E})]}),y===E&&e.jsx("span",{className:"text-meta text-ok",children:se.chosen})]},E))})]}),e.jsx(Ue,{size:"sm",className:"self-start",disabled:p,onClick:()=>S(!0),children:se.browseMore}),y===null&&e.jsx("p",{"data-pick-first":"",className:"rounded-control border border-dashed border-input px-3 py-2 text-small text-muted",children:se.pickFirst}),!j&&e.jsx("p",{className:"text-small text-attention",children:se.noPasskey})]}),h&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:h}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ue,{variant:"ghost",className:"flex-1",disabled:p,onClick:a,children:se.cancel}),e.jsx(Ue,{variant:"primary",type:"submit",className:"flex-[2]",disabled:p||!$||v||R,children:n?se.save:se.create})]}),n&&l&&e.jsx(Ue,{disabled:p,onClick:l,children:se.folders}),n&&e.jsx(Ue,{variant:"ghost",className:"text-danger-fg!",disabled:p,onClick:r,children:se.remove})]})]})}function qj({store:t,project:n,projects:s,agents:a,onClose:r}){var N;const l=f.useId(),o=!!((N=me(t).device)!=null&&N.confirm),c=s.filter(k=>k.id!==n.id),[i,x]=f.useState(null),[d,m]=f.useState(!1),[p,g]=f.useState(null),h=()=>{m(!0),g(null),t.deleteProject(n.id,i).then(k=>{m(!1),k.status==="applied"?r():g(Xa(k))})};return e.jsxs(ht,{labelledBy:`${l}-title`,onClose:()=>{d||r()},children:[e.jsx("h2",{id:`${l}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:se.deleteTitle(n.name)}),e.jsx("p",{className:"text-body text-muted",children:se.deleteAgents(a)}),e.jsxs("fieldset",{className:"m-0 flex min-w-0 flex-col gap-2 border-0 p-0",children:[e.jsx("legend",{className:"mb-1.5 text-small text-muted",children:se.deleteWhere}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:`${l}-move`,checked:i===null,onChange:()=>x(null)}),se.noProject]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:`${l}-move`,checked:i!==null,disabled:c.length===0,onChange:()=>{var k;return x(((k=c[0])==null?void 0:k.id)??null)}}),se.moveTo]}),i!==null&&e.jsx("select",{className:Va,"aria-label":se.target,value:i,onChange:k=>x(k.target.value),children:c.map(k=>e.jsx("option",{value:k.id,children:k.name},k.id))})]}),e.jsx("p",{className:`rounded-control border border-dashed border-input px-3 py-2 text-small ${o?"text-muted":"text-attention"}`,children:o?se.passkey:se.noPasskey}),p&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:p}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ue,{variant:"ghost",className:"flex-1",disabled:d,onClick:r,children:se.cancel}),e.jsx(Ue,{variant:"primary",className:"flex-[2]",disabled:d||!o,onClick:h,children:se.confirmDelete})]})]})}const Hj=t=>t.machine==="local"?se.thisPc:t.label??t.machine,Uj=t=>t.split("/").filter(Boolean).at(-1)??"/",Ts="flex items-center gap-3 border-b border-line px-3 py-2.5 last:border-b-0";function Wj({store:t,project:n,onClose:s}){var C;const a=f.useId(),r=me(t),[l,o]=f.useState(!1),[c,i]=f.useState(!1),[x,d]=f.useState(null);f.useEffect(()=>{t.requestProjectFolders(n.id)},[t,n.id]);const m=r.projectFolders[n.id],p=!!((C=r.device)!=null&&C.confirm),g=(j,y)=>{i(!1),j.status==="applied"?(t.requestProjectFolders(n.id),y()):d(Xa(j))},h=j=>{i(!0),d(null),t.removeFolder(n.id,j.machine,j.path).then(y=>g(y,()=>{}))},N=j=>{i(!0),d(null),t.addFolder(n.id,j).then(y=>g(y,()=>o(!1)))},k=()=>{c||s()};if(l){const j=Array.isArray(m)?m:[];return e.jsxs(ht,{labelledBy:`${a}-title`,onClose:k,children:[e.jsx("h2",{id:`${a}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:se.pickTitle}),e.jsx(fu,{store:t,busy:c,skip:y=>j.some(b=>b.machine==="local"&&b.path===y),rowLabel:se.addShort,rowAria:se.addThisLabel,onPick:N,note:e.jsx("p",{className:`rounded-control border border-dashed border-input px-3 py-2 text-small ${p?"text-muted":"text-attention"}`,children:p?se.folderPasskey:se.noPasskey}),error:x,pickLabel:se.addThis,pickAria:se.addThisLabel,pickDisabled:!p,onBack:()=>{o(!1),d(null)}})]})}return e.jsxs(ht,{labelledBy:`${a}-title`,onClose:k,children:[e.jsx("h2",{id:`${a}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:se.foldersTitle(n.name)}),m===void 0?e.jsx("p",{role:"status",className:"text-small text-muted",children:se.foldersLoading}):m==="gone"?e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:se.errors.stale}):m.length===0?e.jsx("p",{className:"text-body text-muted",children:se.foldersNone}):e.jsx("ul",{className:"flex max-h-[45dvh] flex-col overflow-y-auto rounded-control border border-line",children:m.map(j=>e.jsxs("li",{className:Ts,children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"font-medium",children:Uj(j.path)}),e.jsxs("span",{className:"font-mono text-meta break-all text-muted",children:[j.path," · ",Hj(j)]})]}),e.jsx(Ue,{size:"sm",variant:"ghost","aria-label":se.removeFolderLabel(j.path),disabled:c||!r.fresh||m.length===1,onClick:()=>h(j),children:se.removeFolder})]},`${j.machine}
|
|
17
|
-
${j.path}`))}),Array.isArray(m)&&m.length===1&&e.jsx("p",{"data-last-folder":"",className:"rounded-control border border-dashed border-input px-3 py-2 text-small text-muted",children:se.lastFolder}),x&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:x}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ue,{variant:"ghost",className:"flex-1",disabled:c,onClick:s,children:se.close}),e.jsxs(Ue,{variant:"primary",className:"flex-[2]",disabled:c||!r.fresh||m==="gone",onClick:()=>{d(null),o(!0)},children:[e.jsx(z,{name:"plus",className:"size-4"}),se.addFolder]})]})]})}function fu({store:t,busy:n,skip:s,rowLabel:a,rowAria:r,onPick:l,note:o,error:c,pickLabel:i,pickAria:x,pickDisabled:d,onBack:m}){const p=me(t),[g,h]=f.useState(null);f.useEffect(()=>{t.requestRecentFolders(),t.listFolder()},[t]);const N=p.folderListing,k=N&&(g===null||N.path===g)?N:null,C=y=>{h(y),t.listFolder(y)},j=(p.recentFolders??[]).filter(y=>!s(y));return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex max-h-[55dvh] flex-col gap-3 overflow-y-auto",children:[g===null&&j.length>0&&e.jsxs("section",{"aria-label":se.recents,className:"flex flex-col gap-1.5",children:[e.jsx("h3",{className:"text-small text-muted",children:se.recents}),e.jsx("ul",{className:"flex flex-col rounded-control border border-line",children:j.map(y=>e.jsxs("li",{className:Ts,children:[e.jsx("span",{className:"min-w-0 flex-1 font-mono text-small break-all",children:y}),e.jsx(Ue,{size:"sm","aria-label":r(y),disabled:n||d,onClick:()=>l(y),children:a})]},y))})]}),e.jsxs("section",{"aria-label":se.browse,className:"flex flex-col gap-1.5",children:[e.jsx("h3",{className:"text-small text-muted",children:se.browse}),k?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"font-mono text-small break-all",children:k.path}),k.error&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:se.folderErrors[k.error]}),e.jsxs("ul",{className:"flex flex-col rounded-control border border-line",children:[k.parent&&e.jsx("li",{className:Ts,children:e.jsxs("button",{type:"button",className:"flex min-h-10 flex-1 items-center gap-2 text-left",onClick:()=>C(k.parent),children:[e.jsx(z,{name:"back",className:"size-4"}),se.parent]})}),k.entries.map(y=>{const b=k.repos.find(M=>M.name===y);return e.jsx("li",{className:Ts,children:e.jsxs("button",{type:"button","aria-label":se.open(y),className:"flex min-h-10 min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>C(`${k.path==="/"?"":k.path}/${y}`),children:[e.jsx("span",{className:"truncate",children:y}),b&&e.jsxs("span",{className:"flex-none rounded-full bg-raised px-2 text-meta text-muted",children:["⎇ ",b.branch]})]})},y)}),!k.error&&k.entries.length===0&&e.jsx("li",{className:"px-3 py-2.5 text-small text-muted",children:se.empty})]}),k.cut&&e.jsx("p",{className:"text-meta text-muted",children:se.cut})]}):e.jsx("p",{role:"status",className:"text-small text-muted",children:se.loadingFolder})]})]}),e.jsx("p",{className:"text-small text-muted",children:se.onlyThisPc}),o,c&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:c}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ue,{variant:"ghost",className:"flex-1",disabled:n,onClick:m,children:se.back}),e.jsx(Ue,{variant:"primary",className:"flex-[2]",disabled:n||d||!k||!!k.error,"aria-label":k?x(k.path):i,onClick:()=>{k&&l(k.path)},children:i})]})]})}function Kj({store:t}){var k;const n=me(t),[s,a]=f.useState(null),[r,l]=f.useState(null),[o,c]=f.useState(null),[i,x]=f.useState(!1),[d,m]=f.useState(null);if(!((k=n.daemon)!=null&&k.projectEdit)||!n.daemon.atelier)return null;const p=n.projects,g=C=>[...n.sessions.values()].filter(j=>j.projectId===C&&j.state!=="exited").length,h=!n.fresh||i,N=(C,j)=>{x(!0),m(null),t.orderProjects(Fj(p.map(y=>y.id),C,j)).then(y=>{x(!1),y.status!=="applied"&&m(Xa(y))})};return e.jsxs("section",{"aria-labelledby":"projects-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"projects-title",className:"text-small font-medium text-muted",children:se.title}),e.jsxs("ul",{className:"flex flex-col rounded-[10px] border border-line bg-surface text-body",children:[p.length===0&&e.jsx("li",{className:"px-4 py-3 text-muted",children:se.none}),p.map((C,j)=>e.jsxs("li",{className:"flex items-center gap-3 border-b border-line px-4 py-2.5 last:border-b-0",children:[e.jsx(Pj,{color:C.color}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate font-medium",children:C.name}),e.jsx("span",{className:"text-small text-muted",children:se.agents(g(C.id))})]}),e.jsx(Vl,{label:se.up(C.name),disabled:h||j===0,onClick:()=>N(j,-1),children:e.jsx(z,{name:"arrowUp",className:"size-4"})}),e.jsx(Vl,{label:se.down(C.name),disabled:h||j===p.length-1,onClick:()=>N(j,1),children:e.jsx(z,{name:"arrowUp",className:"size-4 rotate-180"})}),e.jsx(Ue,{size:"sm","aria-label":se.editLabel(C.name),disabled:!n.fresh,onClick:()=>a(C),children:se.edit})]},C.id))]}),e.jsxs(Ue,{disabled:!n.fresh,onClick:()=>a("new"),children:[e.jsx(z,{name:"plus",className:"size-4"}),se.add]}),d&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:d}),e.jsx("p",{className:"text-small text-muted",children:n.daemon.projectFolders?se.folders_note:se.folders_note_old}),s!==null&&e.jsx(Bj,{store:t,project:s==="new"?null:s,projects:p,onClose:()=>a(null),onDelete:()=>{s!=="new"&&(l(s),a(null))},onFolders:n.daemon.projectFolders?()=>{s!=="new"&&(c(s),a(null))}:null}),o&&e.jsx(Wj,{store:t,project:o,onClose:()=>c(null)}),r&&e.jsx(qj,{store:t,project:r,projects:p,agents:g(r.id),onClose:()=>l(null)})]})}const nn=u.connection.device,hu=t=>{var n,s;return t??Vm(((n=globalThis.navigator)==null?void 0:n.userAgent)??"",((s=globalThis.navigator)==null?void 0:s.maxTouchPoints)??0)};function Vj({store:t,pinned:n}){const s=me(t),[a,r]=f.useState(null),[l,o]=f.useState(!1),c=s.device;if(!(c!=null&&c.id))return null;const i=hu(c.name),x=n?new Date(n.pinnedAt).toLocaleDateString(ut,{day:"numeric",month:"short",year:"numeric"}):null,d=(a==null?void 0:a.trim())??"",m=()=>{if(!(!d||d.length>Za)){if(t.renameDevice(d)===null){o(!0);return}o(!1),r(null)}};return e.jsxs("section",{"aria-labelledby":"device-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"device-title",className:"text-small font-medium text-muted",children:nn.title}),e.jsxs("div",{className:"flex items-center gap-3 rounded-[10px] border border-line bg-surface px-4 py-3",children:[e.jsx("span",{className:"grid size-9 flex-none place-items-center rounded-[10px] bg-raised","aria-hidden":"true",children:e.jsx(z,{name:c.kind==="tablet"?"tablet":"phone"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-body font-semibold [overflow-wrap:anywhere]",children:i}),x&&e.jsx("p",{className:"text-meta text-muted",children:nn.linkedOn(x)})]}),e.jsx(Ue,{size:"sm","aria-label":nn.renameLabel(i),onClick:()=>{o(!1),r(i)},children:nn.rename})]}),l&&e.jsx("p",{role:"status",className:"text-small text-danger-fg",children:nn.failed}),e.jsx("p",{className:"text-small text-muted",children:nn.others}),a!==null&&e.jsxs(ht,{labelledBy:"rename-title",onClose:()=>r(null),children:[e.jsx("h2",{id:"rename-title",className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:nn.sheetTitle}),e.jsx("p",{className:"text-body text-muted",children:nn.sheetBody}),e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:p=>{p.preventDefault(),m()},children:[e.jsxs("label",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"sr-only",children:nn.field}),e.jsx("input",{className:Va,value:a,maxLength:Za,autoFocus:!0,"aria-describedby":"rename-count",onChange:p=>r(p.target.value)}),e.jsxs("span",{id:"rename-count",className:"self-end text-meta text-muted",children:[a.length,"/",Za]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ue,{variant:"ghost",className:"flex-1",onClick:()=>r(null),children:nn.cancel}),e.jsx(Ue,{variant:"primary",type:"submit",className:"flex-[2]",disabled:!d,children:nn.save})]})]})]})]})}const st=u.connection,$n=u.settings,Gj=()=>[{value:"system",label:st.themes.system},{value:"light",label:st.themes.light},{value:"dark",label:st.themes.dark}],Xj=t=>t==="ready"?st.states.online:t==="handshaking"?st.states.connecting:st.states.offline;function Yj({store:t,login:n,relay:s,pinned:a,linkState:r,build:l,onSignOut:o,fetchImpl:c,section:i}){var j,y,b,M;const x=me(t),d=Gs(t,"update"),m=lu(t),p=iu(t),g=gm(),h=Di();f.useEffect(()=>{var S;i==="link"&&((S=document.getElementById("link-title"))==null||S.scrollIntoView({block:"start"}))},[i]);const N=(a==null?void 0:a.name)??((j=x.daemon)==null?void 0:j.name)??null,k=!!x.daemon&&!!l&&qi(x.daemon.version,l.version),C=[[st.account,n?u.account(n):st.unknown,!1],[st.relay,s,!0],[st.pc,N??st.unknown,!1],[st.pcFingerprint,a?Ds(a.fingerprint):st.unknown,!0],[st.status,Xj(r),!1],[st.version,(l==null?void 0:l.version)??st.none,!0],[st.appFingerprint,l?ou(l.fingerprint):st.none,!0],[st.pcVersion,((y=x.daemon)==null?void 0:y.version)??st.none,!0,k?"text-attention":void 0]];return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:"bleed flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-2.5",children:[e.jsx(Zt,{fallback:{name:"sessions"},label:st.back}),e.jsx("h1",{className:"text-base font-semibold",children:st.title})]}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col gap-6 overflow-y-auto pt-5 pb-[34px]",children:[e.jsx("div",{className:"flex flex-col empty:hidden",children:e.jsx(fj,{store:t,enroll:d})}),e.jsx(Vj,{store:t,pinned:a}),e.jsxs("section",{"aria-labelledby":"appearance-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"appearance-title",className:"text-small font-medium text-muted",children:$n.appearance}),e.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":"true",className:"text-small text-muted",children:$n.theme}),e.jsx(Na,{name:"theme",legend:$n.theme,options:Gj(),value:g,onChange:S=>bm(S),fit:!0})]}),e.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":"true",className:"text-small text-muted",children:$n.lang}),e.jsx(Na,{name:"lang",legend:$n.lang,options:ym.map(S=>({value:S,label:$n.langs[S],lang:S})),value:h,onChange:jm,fit:!0})]}),e.jsx(Lj,{})]}),((b=x.device)==null?void 0:b.push)&&e.jsxs("section",{"aria-labelledby":"notifications-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"notifications-title",className:"text-small font-medium text-muted",children:$n.notifications}),e.jsx("dl",{className:"flex flex-col rounded-[10px] border border-line bg-surface text-body",children:e.jsx(vj,{store:t,fetchImpl:c})}),e.jsx(Aj,{store:t})]}),((M=x.daemon)==null?void 0:M.usage)&&e.jsxs("a",{href:ce({name:"connection",section:"usage"}),className:"flex items-center justify-between gap-4 rounded-[10px] border border-line bg-surface px-4 py-3 text-body",children:[e.jsx("span",{children:$n.usage}),e.jsxs("span",{className:"flex items-center gap-2 text-muted",children:[p&&e.jsx("span",{"data-usage-dot":!0,"aria-hidden":"true",className:"size-2 rounded-full bg-attention"}),e.jsx(z,{name:"chevron",className:"size-4"})]})]}),e.jsx(Ij,{store:t}),e.jsx(Kj,{store:t}),e.jsx(Mj,{store:t,appVersion:(l==null?void 0:l.version)??null}),e.jsxs("section",{"aria-labelledby":"link-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"link-title",className:"text-small font-medium text-muted",children:st.section}),e.jsxs("dl",{className:"flex flex-col rounded-[10px] border border-line bg-surface text-body",children:[C.map(([S,$,v,A])=>e.jsxs("div",{className:"flex items-baseline justify-between gap-4 border-b border-line px-4 py-3 last:border-b-0",children:[e.jsx("dt",{className:"flex-none text-muted",children:S}),e.jsx("dd",{className:`min-w-0 text-right break-words ${v?"font-mono":""} ${A??""}`,children:$})]},S)),e.jsx(mj,{store:t}),e.jsx(hj,{store:t,enroll:d,quiet:m})]})]}),e.jsx(Oj,{store:t}),e.jsx("div",{className:"flex-grow","aria-hidden":"true"}),e.jsx("button",{type:"button",onClick:o,className:dt,children:st.signOut})]})]})}function Qj({onOther:t}){return e.jsxs(Mt,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(Us,{size:80,frozen:!0}),e.jsx("h1",{className:Ht,children:u.denied.title}),e.jsx("p",{className:"max-w-[300px] text-muted",children:u.denied.bodyNoLogin})]}),e.jsx(Et,{}),e.jsx("button",{type:"button",onClick:t,className:dt,children:u.denied.other})]})}const Qt=u.keyChanged,Zj=t=>{const n=new Date(t);return Number.isNaN(n.getTime())?u.connection.unknown:n.toLocaleDateString(ut,{day:"numeric",month:"short"})};function Jj({pcName:t,known:n,received:s,onRelink:a,onSignOut:r}){return e.jsxs(Mt,{children:[e.jsxs("div",{className:"flex flex-col gap-3.5",children:[e.jsx("span",{"aria-hidden":"true",className:"inline-flex size-12 items-center justify-center rounded-full bg-danger-bg text-danger-fg",children:e.jsxs("svg",{className:pa,viewBox:"0 0 24 24",children:[e.jsx("path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}),e.jsx("path",{d:"M12 8v4"}),e.jsx("path",{d:"M12 16h.01"})]})}),e.jsx("h1",{className:Ht,children:Qt.title(t??u.yourPc)}),e.jsx("p",{className:"text-muted",children:Qt.body})]}),e.jsxs("dl",{className:"grid grid-cols-[auto_1fr] gap-x-4 gap-y-2.5 rounded-control border border-line bg-surface p-4 text-body",children:[e.jsx("dt",{className:"text-muted",children:Qt.known}),e.jsx("dd",{className:"font-mono",children:n?Qt.knownDetail(Ds(n.fingerprint,2),Zj(n.pinnedAt)):u.connection.unknown}),e.jsx("dt",{className:"text-muted",children:Qt.received}),e.jsx("dd",{className:"font-mono",children:s?Qt.receivedDetail(Ds(s,2)):u.connection.unknown})]}),e.jsxs("div",{className:"flex flex-col gap-3 text-body leading-[1.6] text-muted",children:[e.jsxs("p",{children:[e.jsx("strong",{className:"text-fg",children:Qt.reinstalledTitle})," ",Qt.reinstalledBody]}),e.jsxs("p",{children:[e.jsx("strong",{className:"text-fg",children:Qt.otherwise})," ",Qt.warning]})]}),e.jsx(Et,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:a,className:Nt,children:Qt.relink}),e.jsx("button",{type:"button",onClick:r,className:dt,children:Qt.signOut})]})]})}const e1="/auth/github/start";function t1(t){return t==="denied"?u.login.errors.denied:t==="bad_state"||t==="error"?u.login.errors.failed:null}const n1=[e.jsxs(e.Fragment,{children:[e.jsx("circle",{cx:"7.5",cy:"15.5",r:"5.5"}),e.jsx("path",{d:"m21 2-9.6 9.6"}),e.jsx("path",{d:"m15.5 7.5 3 3L22 7l-3-3"})]}),e.jsxs(e.Fragment,{children:[e.jsx("rect",{width:"20",height:"14",x:"2",y:"3",rx:"2"}),e.jsx("line",{x1:"8",x2:"16",y1:"21",y2:"21"}),e.jsx("line",{x1:"12",x2:"12",y1:"17",y2:"21"})]}),e.jsxs(e.Fragment,{children:[e.jsx("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})];function s1({server:t,error:n}){return e.jsxs(Mt,{children:[e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(Us,{size:88}),e.jsx("h1",{className:"text-display leading-[34px] font-bold tracking-[-.025em]",children:u.login.title}),e.jsx("p",{className:"max-w-[300px] text-muted",children:u.login.subtitle})]}),e.jsxs("div",{className:"flex h-8 items-center gap-2.5 self-center rounded-full border border-line px-3 text-small text-muted",children:[e.jsxs("svg",{className:`${pa} size-3.5`,viewBox:"0 0 24 24","aria-hidden":"true",children:[e.jsx("rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2"}),e.jsx("rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2"}),e.jsx("line",{x1:"6",x2:"6.01",y1:"6",y2:"6"}),e.jsx("line",{x1:"6",x2:"6.01",y1:"18",y2:"18"})]}),e.jsx("span",{className:"font-mono",children:t})]}),n&&e.jsx("p",{role:"alert",className:"rounded-control border border-danger-fg/15 bg-danger-bg p-3.5 text-body text-danger-fg",children:n}),e.jsx(Et,{}),e.jsx("ul",{className:"flex flex-col gap-3.5 text-fg/85",children:u.login.notes.map((s,a)=>e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx("svg",{className:`${pa} text-fg`,viewBox:"0 0 24 24","aria-hidden":"true",children:n1[a]}),e.jsx("span",{children:s})]},s))}),e.jsxs("a",{href:e1,className:Nt,children:[e.jsx("svg",{className:"size-5 flex-none fill-current",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"M12 .3a12 12 0 0 0-3.8 23.38c.6.12.83-.26.83-.57L9 21.07c-3.34.72-4.04-1.61-4.04-1.61-.55-1.39-1.34-1.76-1.34-1.76-1.08-.74.09-.73.09-.73 1.2.09 1.83 1.24 1.83 1.24 1.07 1.83 2.81 1.3 3.5 1 .1-.78.42-1.31.76-1.6-2.67-.3-5.47-1.34-5.47-5.93 0-1.31.47-2.38 1.24-3.22-.14-.3-.54-1.52.1-3.18 0 0 1-.32 3.3 1.23a11.5 11.5 0 0 1 6 0c2.28-1.55 3.29-1.23 3.29-1.23.64 1.66.24 2.88.12 3.18a4.65 4.65 0 0 1 1.23 3.22c0 4.61-2.8 5.63-5.48 5.92.42.36.81 1.1.81 2.22l-.01 3.29c0 .31.2.69.82.57A12 12 0 0 0 12 .3"})}),u.login.github]})]})}function a1({onHere:t}){return e.jsxs(Mt,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:Ht,children:u.replaced.title}),e.jsx("p",{className:"text-muted",children:u.replaced.body})]}),e.jsx(Et,{}),e.jsx("button",{type:"button",onClick:t,className:dt,children:u.replaced.here})]})}const r1=t=>rt({variant:t?"primary":"outline",className:"h-auto min-h-11 w-full justify-start gap-2 px-3 py-2.5 text-left leading-[19px] whitespace-normal [overflow-wrap:anywhere]"}),di=t=>new Date(t).toLocaleTimeString(ut,{hour:"2-digit",minute:"2-digit"});function gu({store:t,ask:n,end:s,fresh:a,ghost:r,canConfirm:l,enroll:o,onGone:c,full:i=!1,selected:x=!1}){const d=u.asks,m=u.cards.receipt,p=zc(t),g=dc(n),h=uc(n),[N,k]=f.useState(!1),[C,j]=f.useState(""),[y,b]=f.useState(null),[M,S]=f.useState(null),[$,v]=f.useState(!1),[A,R]=f.useState(null),_=ce({name:"ask",id:n.id}),L=async(w,O)=>{b(w),S(null),R({key:w,answer:O});let V;if(O.kind!=="seen"){const X=await p({purpose:"rig",qitem:n.id,answer:O});if(typeof X=="string"){b(null),S(X);return}V=X}const Z=t.answerAsk(n.id,O,V?{assertion:V}:{});if(b(null),Z===null){S("notSent");return}(O.kind==="words"||O.kind==="resolve")&&k(!1)},T=m.what(h.name,d.pill[g]);if(s.kind==="sent"){const w=Tx(n,s.answer),O=s.answer.kind==="seen"?e.jsx(at,{tone:"ok",title:m.seen,body:m.what(h.name,n.summary)}):e.jsx(at,{tone:"ok",title:m.sentTo(h.name),body:[h.role,w?`« ${w.length>60?`${w.slice(0,60)}…`:w} »`:""].filter(Boolean).join(" · ")});return e.jsx(ya,{onGone:c,children:O})}if(s.kind==="already"||r&&s.kind!=="failed"&&s.kind!=="uncertain")return!a&&r&&s.kind!=="already"?(queueMicrotask(c),null):e.jsx(ya,{onGone:c,children:e.jsx(at,{tone:"gone",title:d.already,body:m.what(h.name,n.summary)})});const B=w=>{L((A==null?void 0:A.key)??"retry",w)};if(s.kind==="uncertain")return e.jsx(at,{tone:"warn",title:u.decide.uncertain,body:d.uncertain,action:{label:d.retry,onClick:()=>{t.resendAsk(n.id)||B(s.answer)},disabled:!a||y!==null}});if(s.kind==="failed"){const w=s.error==="openrig_stopped"?d.stopped:s.error==="unreachable"?d.unreachable:s.message??s.error;return e.jsx(at,{tone:"fail",title:d.notSent(w),body:T,action:{label:d.retry,onClick:()=>B(s.answer),disabled:!a||y!==null}})}const E=s.kind==="sending"||y!==null,P=a&&!E,W=g!=="update",F=P&&(l||!W),re=w=>y===w||s.kind==="sending"&&(A==null?void 0:A.key)===w?e.jsx(Ct,{}):null,Y=n.questions.length>1,H=n.questions.filter(w=>ao(n,w.id)!==null||s.kind==="recorded"&&s.answer.kind==="choice"&&s.answer.questionId===w.id).length,I=n.bodyTruncated&&n.body===n.summary?"":n.body,D=n.priority==="routine"?null:d.priority[n.priority],Q=(w,O=!1)=>e.jsx("p",{className:`text-small [overflow-wrap:anywhere] ${O?"text-destructive":"text-muted"}`,role:O?"alert":void 0,children:w}),q=Pt(),K=W?q?d.sendCheck:d.sendDevice:d.send,ee=w=>{var Z;const O=ao(n,w.id)??(s.kind==="recorded"&&s.answer.kind==="choice"&&s.answer.questionId===w.id?((Z=w.options.find(X=>X.id===s.answer.optionId))==null?void 0:Z.label)??null:null);if(O!==null)return e.jsxs("span",{className:"flex items-center gap-1.5 text-body",children:[e.jsx(z,{name:"check",className:"size-4 text-ok"}),O]});const V=[...w.options].sort((X,J)=>Number(J.recommended)-Number(X.recommended));return e.jsx("div",{className:"flex flex-col gap-2",children:V.map(X=>{const J=`${w.id}:${X.id}`;return e.jsxs("button",{type:"button",disabled:!F||N,onClick:()=>{L(J,{kind:"choice",questionId:w.id,optionId:X.id})},className:r1(X.recommended),children:[re(J),e.jsx("span",{className:"min-w-0",children:X.label}),X.recommended&&e.jsx("span",{className:"ml-auto pl-2 text-xs whitespace-nowrap opacity-85",children:d.recommended})]},X.id)})})},ue=e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"sr-only",htmlFor:`ask-${n.id}`,children:n.kind==="parked"?d.placeholderParked(h.name):d.placeholder}),e.jsx("textarea",{id:`ask-${n.id}`,rows:2,value:C,onChange:w=>j(w.target.value),disabled:E,placeholder:n.kind==="parked"?d.placeholderParked(h.name):d.placeholder,className:"max-h-[140px] min-h-11 w-full resize-y rounded-[10px] border border-input bg-surface px-3 py-2.5 text-base leading-[22px] text-fg outline-none placeholder:text-muted focus:border-ring"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{type:"button",disabled:!F||!C.trim(),onClick:()=>{L("words",n.kind==="parked"?{kind:"resolve",text:C.trim()}:{kind:"words",text:C.trim()})},className:rt({variant:"primary",className:"min-w-0"}),children:[re("words")??(W?e.jsx(z,{name:"face",className:"size-[18px]"}):null),e.jsx("span",{className:"truncate",children:K})]}),e.jsx("button",{type:"button",disabled:E,onClick:()=>k(!1),className:rt({className:"min-w-0"}),children:d.cancel})]}),Y&&H<n.questions.length&&Q(d.settlesAll)]}),fe=M==="cancelled"?u.confirm.cancelled:M==="prepareFailed"?u.confirm.prepareFailed:M==="failed"?u.confirm.failed:M==="notSent"?u.decide.failed:s.kind==="refused"?s.reason==="assertion_expired"?u.confirm.expired:s.reason==="unavailable"?d.notSent(d.unreachable):u.confirm.failed:null,he=!W||n.questions.length===0&&!N&&g!=="parked"&&g!=="question"?null:l?y!==null&&y!=="seen"?Q(u.confirm.asking):e.jsxs("p",{className:"flex items-center gap-1.5 text-small text-muted",children:[e.jsx(z,{name:"face",className:"size-4"}),q?d.confirmHint:d.confirmHintDevice]}):e.jsxs(e.Fragment,{children:[Q(d.needsDevice),o&&e.jsx("a",{href:ce({name:"connection",section:"link"}),className:"self-start text-small font-medium underline underline-offset-2",children:u.enroll.link})]});return e.jsxs(Bs,{tone:g==="update"?"plain":"rig",selected:x,label:u.cards.region(u.cards.kindName.rig,h.name,n.from.rig??""),children:[e.jsxs("a",{href:_,className:"-m-1 flex min-w-0 items-center gap-[7px] rounded-md p-1 active:bg-raised",children:[e.jsx("b",{className:"font-semibold whitespace-nowrap",children:h.name}),n.from.rig&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:n.from.rig}),e.jsx("span",{className:"flex-1"}),D&&e.jsx(Lt,{tone:"urgent",children:D}),e.jsx(Lt,{tone:g==="parked"?"rig":"plain",children:d.pill[g]}),e.jsx("time",{dateTime:n.updatedAt,className:"font-mono text-small whitespace-nowrap text-muted",children:di(n.updatedAt)})]}),e.jsx("a",{href:_,className:"block text-body font-semibold [overflow-wrap:anywhere]",children:n.summary}),I&&!N&&(i?e.jsx("p",{className:"text-body whitespace-pre-wrap [overflow-wrap:anywhere] text-muted",children:I}):e.jsx("a",{href:_,className:"line-clamp-3 text-body [overflow-wrap:anywhere] text-muted",children:I})),!i&&!N&&(n.bodyTruncated||I.length>180||I.split(`
|
|
18
|
-
`).length>3)&&e.jsx("a",{href:_,className:"-mt-1 self-start text-[13px] font-medium underline-offset-2 hover:underline",children:d.readAll}),i&&(n.evidenceRef||n.detail)&&e.jsxs("dl",{className:"grid grid-cols-[74px_minmax(0,1fr)] gap-x-3 gap-y-2 text-small",children:[e.jsx("dt",{className:"text-muted",children:u.detail.asked}),e.jsx("dd",{className:"m-0",children:di(n.createdAt)}),n.evidenceRef&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-muted",children:d.source}),e.jsx("dd",{className:"m-0 font-mono [overflow-wrap:anywhere]",children:n.evidenceRef})]})]}),i&&n.detail&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-expanded":$,onClick:()=>v(w=>!w),className:"self-start text-[13px] font-medium",children:[$?"⌄":"›"," ",d.details]}),$&&e.jsx("p",{className:"text-small whitespace-pre-wrap [overflow-wrap:anywhere] text-muted",children:n.detail})]}),g==="update"?e.jsx("div",{className:"flex",children:e.jsxs("button",{type:"button",disabled:!P,onClick:()=>{L("seen",{kind:"seen"})},className:rt({size:"sm"}),children:[re("seen"),d.seen]})}):N&&!Y?ue:n.questions.length===0?N?ue:e.jsx("button",{type:"button",disabled:!F,onClick:()=>k(!0),className:rt({className:"self-start"}),children:n.kind==="parked"?d.answerParked:d.writeAnswer}):Y?e.jsxs(e.Fragment,{children:[n.questions.map((w,O)=>e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("span",{className:"text-small text-muted [overflow-wrap:anywhere]",children:[O+1,". ",w.question]}),ee(w)]},w.id)),e.jsx("span",{className:"text-small text-muted",children:d.progress(H,n.questions.length)}),N?ue:e.jsx("button",{type:"button",disabled:!F,onClick:()=>k(!0),className:"self-start text-[13px] font-medium text-muted underline-offset-2 hover:underline disabled:opacity-45",children:d.answerOther})]}):e.jsxs(e.Fragment,{children:[ee(n.questions[0]),e.jsx("button",{type:"button",disabled:!F,onClick:()=>k(!0),className:"self-start text-[13px] font-medium text-muted underline-offset-2 hover:underline disabled:opacity-45",children:d.answerOther})]}),fe&&Q(fe,!0),!fe&&he]})}function l1(t,n){var a;if(!((a=t.daemon)!=null&&a.openrig))return n.length>0;const s=t.asksChannel;return n.length>0||s!==null&&(s.partial||s.channel.state!=="ready")}function ui({state:t,machine:n}){const s=t.asksChannel;if(!s)return null;const a=u.asks.channel,r=s.channel.state==="ready"?s.partial?{title:null,body:u.asks.partial}:null:s.channel.state==="not_installed"?{title:a.not_installed.title(n),body:a.not_installed.body}:{title:a[s.channel.state].title,body:a[s.channel.state].body};return r?e.jsxs("div",{role:"status","data-channel":s.channel.state,className:"flex items-start gap-[9px] rounded-lg border border-line px-3 py-2.5 text-[13px] leading-[18px]",children:[e.jsx("span",{className:"mt-[5px]",children:e.jsx(
|
|
19
|
-
`)}\x1B[${n.y+1};${n.x+1}H`}class f1{constructor(n,s,a,r=()=>crypto.randomUUID()){Bt(this,"view",m1);Bt(this,"listeners",new Set);Bt(this,"tid",null);Bt(this,"openOp",null);Bt(this,"holdOp",null);Bt(this,"seq",0);Bt(this,"resyncing",!1);Bt(this,"n",0);Bt(this,"pending","");Bt(this,"timer",null);Bt(this,"wasReady",!1);Bt(this,"offs",[]);Bt(this,"stopped",!1);this.wire=n,this.sessionId=s,this.screen=a,this.uuid=r}get state(){return this.view}subscribe(n){return this.listeners.add(n),()=>{this.listeners.delete(n)}}start(){this.offs.push(this.wire.onMessage(n=>this.onMessage(n))),this.offs.push(this.wire.subscribe(()=>this.onLink())),this.wasReady=this.wire.ready(),this.wasReady?this.open():this.set({phase:"offline"})}stop(){var n;if(!this.stopped){this.stopped=!0,this.flushKeys(),this.tid&&this.wire.ready()&&this.wire.send({type:"term.close",tid:this.tid});for(const s of this.offs.splice(0))s();this.timer&&clearTimeout(this.timer),(n=this.holdOp)==null||n.done("invalid"),this.holdOp=null}}hold(n){var r;if(!this.tid||this.view.phase!=="live"||this.view.readOnly||!this.wire.ready())return Promise.resolve("invalid");(r=this.holdOp)==null||r.done("invalid");const s=this.uuid(),a=this.tid;return new Promise(l=>{this.holdOp={op:s,done:o=>{this.holdOp=null,this.set({holding:!1,holdRefused:o}),l(o)}},this.set({holding:!0,holdRefused:null,released:null}),this.wire.send({type:"term.hold",op:s,tid:a,assertion:n})})}release(){!this.tid||!this.view.held||(this.flushKeys(),this.wire.send({type:"term.release",tid:this.tid}))}type(n){!this.view.held||!this.tid||u1.test(n)||(this.pending+=n,this.set({held:{...this.view.held,lastKey:Date.now()}}),this.timer===null&&(this.timer=setTimeout(()=>{this.timer=null,this.flushKeys()},d1)))}flushKeys(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),!this.tid||!this.pending||!this.wire.ready()){this.pending="";return}for(;this.pending;){const n=x1(this.pending);this.pending=this.pending.slice(n.length),this.wire.send({type:"term.input",tid:this.tid,n:this.n++,data:n})}}open(){this.openOp=this.uuid(),this.tid=null,this.n=0,this.resyncing=!1,this.set({phase:"connecting",held:null,holding:!1,exit:null,refused:null}),this.wire.send({type:"term.open",op:this.openOp,id:this.sessionId})}onLink(){var s;const n=this.wire.ready();if(!(n===this.wasReady||this.stopped)){if(this.wasReady=n,!n){this.pending="",(s=this.holdOp)==null||s.done("invalid"),this.tid=null,this.view.phase!=="ended"&&this.view.phase!=="refused"&&this.set({phase:"offline",held:null,released:this.view.held?"link":this.view.released});return}this.view.phase==="offline"&&this.open()}}onMessage(n){if(!this.stopped)switch(n.type){case"term.opened":{if(!(n.op!==void 0?n.op===this.openOp:n.tid===this.tid))return;this.tid=n.tid,this.seq=n.seq,this.resyncing=!1,this.screen.reset(n.cols,n.rows),this.screen.write(p1(n.screen,n.cursor)),this.set({phase:"live",cols:n.cols,rows:n.rows,readOnly:n.readOnly===!0});return}case"term.output":if(n.tid!==this.tid||this.resyncing)return;if(n.seq!==this.seq){this.resyncing=!0,this.wire.send({type:"term.resync",tid:n.tid});return}this.seq++,this.screen.write(n.data);return;case"term.size":if(n.tid!==this.tid)return;this.screen.resize(n.cols,n.rows),this.set({cols:n.cols,rows:n.rows});return;case"term.held":if(n.tid!==this.tid)return;this.set({held:{until:Date.parse(n.until),lastKey:Date.now()},released:null});return;case"term.released":if(n.tid!==this.tid)return;this.pending="",this.set({held:null,released:n.why==="asked"?null:n.why});return;case"term.exit":if(n.tid!==this.tid)return;this.tid=null,this.set({phase:"ended",held:null,exit:n.why});return;case"operation.result":if(n.op===this.openOp&&n.status==="rejected"){this.openOp=null,this.set({phase:"refused",refused:n.reason??"invalid"});return}if(n.op===this.openOp&&n.status==="failed"){this.openOp=null,this.set({phase:"refused",refused:"unavailable"});return}this.holdOp&&n.op===this.holdOp.op&&n.status!=="received"&&this.holdOp.done(n.status==="applied"?null:n.reason??"invalid");return;default:return}}set(n){this.view={...this.view,...n};for(const s of[...this.listeners])s()}}const h1=11,EN=6,_N=16,pi=5*6e4,g1={up:"A",down:"B",right:"C",left:"D"};function b1(t,n){switch(t){case"esc":return"\x1B";case"tab":return" ";case"enter":return"\r";case"interrupt":return"";default:return`${n?"\x1BO":"\x1B["}${g1[t]}`}}function j1(t,n){let s=t;if(n.ctrl&&[...t].length===1){const a=t.toUpperCase().charCodeAt(0);a>=64&&a<=95?s=String.fromCharCode(a-64):t===" "?s="\0":t==="?"&&(s="")}return n.alt?`\x1B${s}`:s}function y1(t){const n=t.findIndex(a=>/❯\s*1\.\s/.test(a));if(n<0)return[];const s=[];for(const a of t.slice(n,n+12)){const r=/^\s*(?:❯\s*)?(\d)\.\s+(.*)$/.exec(a);if(!r)continue;if(r[1]!==String(s.length+1))break;const l=r[2].trim(),o=/^(oui,?\s+toujours|yes,?\s+and\s+don.t\s+ask)/i.test(l)?"always":/^(oui|yes)\b/i.test(l)?"yes":/^(non|no)\b/i.test(l)?"no":null;s.push({digit:r[1],word:o})}return s}const _e=u.terminal.live2,yu="ledge.mobile.terminalView",N1=t=>{var n;try{return((n=Ze(t))==null?void 0:n.getItem(yu))==="fit"?"fit":"readable"}catch{return"readable"}},k1=(t,n)=>{var s;try{(s=Ze(n))==null||s.setItem(yu,t)}catch{}};function v1(t){return{send:n=>{t.send(n).catch(()=>{})},onMessage:n=>t.onMessage(n),ready:()=>t.state()==="ready",subscribe:n=>t.subscribe(n)}}const jr=new Map,w1=t=>{const n=Math.max(0,Math.ceil(t/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`},S1=t=>Nm(()=>import("./xterm-DYEeBZJ_.js"),__vite__mapDeps([0,1,2,3,4])).then(n=>n.createXterm(t));function C1({store:t,link:n,session:s,storage:a,makeScreen:r,forge:l}){var mt,kt,ct,xt;const o=me(t),c=Kt(),i=f.useRef(null),x=f.useRef(null),[d,m]=f.useState(null),[p,g]=f.useState(null),[h,N]=f.useState(()=>N1(a)),[k,C]=f.useState(!1),[j,y]=f.useState({ctrl:"off",alt:"off"}),[b,M]=f.useState(!1),[S,$]=f.useState(""),[v,A]=f.useState(!1),[R,_]=f.useState(null),[L,T]=f.useState([]),[B,E]=f.useState(!1),P=Dt(),W=Pa(),F=f.useRef(!0),re=f.useRef(j);re.current=j,f.useEffect(()=>{const G=i.current;if(!G)return;let Ee=!1,we=null;const le=ge=>{if(Ee){ge.dispose();return}const Be=new f1(v1(n),s.id,ge);ge.onData(et=>Be.type(Y(et))),Be.start(),we={c:Be,xt:ge},m(Be),g(ge)};return r?le(r(G)):S1(G).then(le),()=>{Ee=!0,we==null||we.c.stop(),we==null||we.xt.dispose()}},[n,s.id,r]);const Y=G=>{const Ee=re.current;if(Ee.ctrl==="off"&&Ee.alt==="off")return G;const we=j1(G,{ctrl:Ee.ctrl!=="off",alt:Ee.alt!=="off"});return y(le=>({ctrl:le.ctrl==="armed"?"off":le.ctrl,alt:le.alt==="armed"?"off":le.alt})),we},H=f.useSyncExternalStore(G=>d?d.subscribe(G):()=>{},()=>(d==null?void 0:d.state)??null),I=!!(H!=null&&H.held);f.useEffect(()=>{p==null||p.setInput(I),I&&(F.current=!0,p==null||p.focus())},[p,I]),f.useEffect(()=>{!p||!x.current||!H||p.setFont(h==="fit"?p.fitFont(x.current.clientWidth-16):h1)},[p,h,H==null?void 0:H.cols]),f.useEffect(()=>{if(!p)return;const G=x.current,Ee=()=>{if(!G)return;const we=jr.get(s.id);if(we&&G.scrollWidth>=we.left+G.clientWidth&&G.scrollHeight>=we.top+G.clientHeight&&(jr.delete(s.id),G.scrollLeft=we.left,G.scrollTop=we.top,F.current=!1),F.current&&h==="readable"){const{x:ge,cellWidth:Be}=p.cursor(),et=ge*Be;(et<G.scrollLeft||et>G.scrollLeft+G.clientWidth-Be*4)&&(G.scrollLeft=Math.max(0,et-G.clientWidth/2))}_(G.scrollWidth>G.clientWidth+1?{left:G.scrollLeft/G.scrollWidth,width:G.clientWidth/G.scrollWidth}:null);const le=y1(p.rows());T(ge=>ge.length===le.length&&ge.every((Be,et)=>Be.digit===le[et].digit&&Be.word===le[et].word)?ge:le)};p.onDrawn(Ee),Ee()},[p,h]);const D=()=>{const G=x.current;G&&jr.set(s.id,{left:G.scrollLeft,top:G.scrollTop})},Q=()=>{const G=x.current;G&&_(G.scrollWidth>G.clientWidth+1?{left:G.scrollLeft/G.scrollWidth,width:G.clientWidth/G.scrollWidth}:null)},q=f.useRef(null),K=G=>Math.hypot(G[0].clientX-G[1].clientX,G[0].clientY-G[1].clientY),ee=G=>{G.touches.length===2&&p?q.current={d:K(G.touches),px:p.font()}:F.current=!1},ue=G=>{if(G.touches.length!==2||!q.current||!p||!x.current)return;const Ee=p.fitFont(x.current.clientWidth-16);p.setFont(Math.max(Ee,q.current.px*(K(G.touches)/q.current.d)))},fe=()=>{q.current=null},he=G=>{N(G),k1(G,a),F.current=!0},w=G=>{var Ee,we;if(!(!d||!p)){if(F.current=!0,G==="ctrl"||G==="alt"){y(le=>({...le,[G]:le[G]==="off"?"armed":le[G]==="armed"?"locked":"off"}));return}if(G==="line"){M(le=>!le);return}if(G==="paste"){A(!1),(we=(Ee=navigator.clipboard)==null?void 0:Ee.readText)==null||we.call(Ee).then(le=>{le?p.paste(le):A(!0)},()=>A(!0));return}d.type(Y(b1(G,p.appCursor())))}},O=()=>{!d||!S||(d.type(`${S.replace(/\r?\n/g,"\r")}\r`),$(""))},V=!!s.pending||s.state==="waiting_permission"||s.state==="waiting_input",Z=((mt=s.pending)==null?void 0:mt.kind)==="permission"||s.state==="waiting_permission",X={name:"thread",sessionId:s.id},J=(H==null?void 0:H.phase)??"connecting",pe=J==="ended",Ne=J==="offline",Xe=!!((kt=o.daemon)!=null&&kt.terminalInput)&&!(H!=null&&H.readOnly)&&s.readOnly!==!0,gt=I?_e.status.held:_e.status[J],ze=H!=null&&H.released&&H.released!=="asked"?_e.released[H.released]:null,Je=(H==null?void 0:H.exit)==="gone"?_e.exit.gone(s.name):H!=null&&H.exit?_e.exit[H.exit]:null,oe=H!=null&&H.refused?_e.refused[H.refused]??_e.refused.unavailable:null,de=H!=null&&H.holdRefused?_e.holdRefused[H.holdRefused]??u.confirm.refused[H.holdRefused]??null:null,ke=H!=null&&H.held?Math.min(pi,Math.min(H.held.lastKey+pi,H.held.until)-c):0,Oe=I&&ke<=6e4,lt=Z?L:[];return e.jsxs(e.Fragment,{children:[e.jsx(eu,{store:t,session:s,current:"terminal",onLeave:D,model:B,onModel:E,display:J==="live"||Ne?{value:h==="readable"?_e.readable:_e.fit,onToggle:()=>he(h==="readable"?"fit":"readable")}:void 0}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col pt-2",children:[e.jsxs("div",{className:`flex h-9 flex-none items-center gap-2 rounded-t-card bg-term-bg px-3 text-[12px] text-term-fg ${I?"border-2 border-b-0 border-info":"border border-b-0 border-line"}`,children:[!Oe&&e.jsx("span",{className:"min-w-0 truncate font-mono",children:s.project}),e.jsx("span",{role:"status",className:`flex-none rounded-[6px] px-2 py-0.5 font-medium ${I?"bg-info text-white":Ne?"text-attention":J==="live"?"text-ok":"text-muted"}`,children:Oe?_e.heldLeft(w1(ke)):gt}),e.jsx("span",{className:"flex-1"}),I?e.jsx("button",{type:"button",onClick:()=>d==null?void 0:d.release(),className:"flex-none underline",children:_e.release}):H&&!pe&&J!=="refused"&&e.jsxs("span",{className:"flex-none font-mono",children:[H.cols," × ",H.rows]})]}),e.jsx("div",{ref:x,onScroll:Q,onTouchStart:ee,onTouchMove:ue,onTouchEnd:fe,"aria-label":_e.screen(s.name),className:`relative min-h-0 flex-1 overflow-auto rounded-b-card bg-term-bg p-2 ${I?"border-2 border-t-0 border-info":"border border-t-0 border-line"} ${Ne||pe?"opacity-45":""}`,children:e.jsx("div",{ref:i,"data-term":"",className:"w-max"})}),R&&!I&&h==="readable"&&e.jsx("div",{"aria-label":_e.position,role:"img",className:"relative mt-2 h-1 flex-none rounded-full bg-raised",children:e.jsx("span",{className:"absolute inset-y-0 rounded-full bg-muted",style:{left:`${R.left*100}%`,width:`${R.width*100}%`}})})]}),I?e.jsxs("footer",{className:"flex flex-none flex-col gap-1 pt-2 pb-[max(8px,var(--foot-inset))]",children:[v&&e.jsx("p",{role:"alert",className:"text-meta text-attention",children:_e.pasteFailed}),e.jsxs("div",{role:"toolbar","aria-label":_e.keys,className:"flex gap-1.5 overflow-x-auto py-1.5",children:[lt.map(G=>e.jsx("button",{type:"button",onPointerDown:Ee=>Ee.preventDefault(),onClick:()=>{F.current=!0,d==null||d.type(G.digit)},className:"inline-grid h-10 min-w-10 flex-none place-items-center rounded-control border border-attention/50 bg-attention/10 px-2.5 font-mono text-[13px] font-medium text-attention",children:G.word?`${G.digit} ${_e.contextKeys[G.word]}`:G.digit},G.digit)),(P?["interrupt","paste"]:b?["esc","tab","up","down","line"]:["esc","tab","ctrl","alt","left","up","down","right","enter","interrupt","paste","line"]).map(G=>{const Ee=G==="ctrl"||G==="alt"?j[G]!=="off":G==="line"?b:!1,we=G==="ctrl"||G==="alt"||G==="line"?Ee:void 0,le=(G==="ctrl"||G==="alt")&&j[G]!=="off"?`, ${j[G]==="locked"?_e.locked:_e.armed}`:"";return e.jsx("button",{type:"button","aria-pressed":we,"aria-label":`${_e.keyLabel[G]}${le}`,onPointerDown:ge=>ge.preventDefault(),onClick:()=>w(G),className:`inline-grid h-10 min-w-10 flex-none place-items-center rounded-control border px-2.5 font-mono text-[13px] font-medium ${Ee?"border-transparent bg-fg text-bg":"border-input bg-surface text-fg"}`,children:_e.key[G]},G)}),P&&e.jsx("span",{className:"ml-auto flex-none self-center pl-2 text-[12px] text-muted",children:_e.hardware})]}),b&&!P&&e.jsxs("form",{className:"flex items-center gap-2",onSubmit:G=>{G.preventDefault(),O()},children:[e.jsx("span",{"aria-hidden":"true",className:"font-mono text-muted",children:"$"}),e.jsx("input",{id:"term-line",value:S,onChange:G=>$(G.target.value),"aria-label":_e.lineField,placeholder:_e.lineField,autoCapitalize:"off",enterKeyHint:"send",className:"min-h-11 min-w-0 flex-1 rounded-control border border-input bg-transparent px-3 font-mono text-body"}),e.jsx("button",{type:"submit",disabled:!S,"aria-label":_e.lineSend,className:We({variant:"primary",size:"sm"}),children:_e.lineGo})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("footer",{className:"flex flex-none flex-col gap-2 pt-2.5 pb-2.5",children:[(ze||Je||oe||de)&&e.jsx("p",{role:"status",className:"text-center text-small text-muted",children:oe??Je??de??ze}),pe?e.jsx("a",{href:ce(X),className:We({block:!0}),children:_e.back}):Xe&&J!=="refused"?e.jsxs("div",{className:"flex items-center gap-3",children:[V&&e.jsx("span",{className:"min-w-0 flex-1 text-small text-muted",children:_e.alsoInThread}),e.jsxs("button",{type:"button",disabled:J!=="live"||(H==null?void 0:H.holding),onClick:()=>C(!0),className:We({size:"sm",className:V?"flex-none":"ml-auto flex-none"}),children:[e.jsx(z,{name:"keyboard"}),H!=null&&H.released?_e.holdAgain:_e.hold]})]}):!Ne&&((ct=o.daemon)==null?void 0:ct.terminal)&&!(H!=null&&H.readOnly)&&s.readOnly!==!0&&e.jsx("p",{className:"text-center text-meta text-muted",children:_e.inputOff}),Ne&&e.jsx("p",{className:"text-center text-meta text-muted",children:_e.offlineHint})]}),e.jsx(Od,{store:t,forge:l,session:s,wide:W,threshold:((xt=o.device)==null?void 0:xt.contextNear)??Ta,onModel:()=>E(!0)})]}),k&&d&&e.jsx($1,{store:t,session:s,onClose:()=>C(!1),hold:G=>(C(!1),d.hold(G),"sent")})]})}function $1({store:t,session:n,onClose:s,hold:a}){const{fresh:r,device:l}=me(t),o=!!(l!=null&&l.confirm),c=pd(t,"terminal",n.id,r&&o,a),i=d=>We({variant:d,block:!0}),x=c.asking?u.confirm.asking:c.challenge?Pt()?`${_e.go}`:_e.go:u.confirm.preparing;return e.jsxs(ht,{labelledBy:"hold-title",onClose:s,children:[e.jsx("h2",{id:"hold-title",className:"text-heading leading-[1.3] tracking-[-.5px]",children:_e.sheetTitle(n.name)}),o?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:_e.sheetBody}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:_e.sheetNote}),c.problem&&e.jsx(De,{title:u.confirm[c.problem],tone:"warning",role:"alert"}),c.needsNew?e.jsx("button",{type:"button",onClick:c.retry,className:i("primary"),children:u.confirm.retry}):e.jsxs("button",{type:"button",disabled:c.asking||!c.challenge,onClick:()=>{c.go()},className:i("primary"),children:[e.jsx(z,{name:"passkey"}),x]})]}):e.jsxs(e.Fragment,{children:[e.jsx(De,{title:_e.unprotectedTitle,tone:"warning",role:"status",children:e.jsx("p",{children:_e.unprotectedBody})}),e.jsx("a",{href:ce({name:"connection"}),className:i("primary"),children:_e.openConnection})]}),e.jsx("button",{type:"button",onClick:s,className:i(),children:_e.cancel})]})}const Nu="ledge.mobile.terminalSize",ku=11,vu=20,fi=12,M1=1e4,wu=t=>Math.max(ku,Math.min(vu,t));function E1(t){var n;try{const s=Number((n=Ze(t))==null?void 0:n.getItem(Nu));return Number.isFinite(s)&&s>0?wu(Math.round(s)):fi}catch{return fi}}function _1(t,n){var s;try{(s=Ze(n))==null||s.setItem(Nu,String(t))}catch{}}const hi=Ot({variant:"outline",className:"text-body font-medium"});function gi({store:t,link:n,sessionId:s,storage:a,forge:r}){var c;const l=me(t),o=l.sessions.get(s);return n&&o&&((c=l.daemon)!=null&&c.terminal)?e.jsx(C1,{store:t,link:n,session:o,forge:r,...a?{storage:a}:{}},s):e.jsx(R1,{store:t,sessionId:s,...a?{storage:a}:{}})}function R1({store:t,sessionId:n,storage:s}){const a=me(t),r=Kt(),{fresh:l,ops:o}=a,c=a.sessions.get(n),i=a.previews.get(n)??[],[x,d]=f.useState(()=>E1(s)),m=T=>d(B=>{const E=wu(B+T);return _1(E,s),E}),[p,g]=f.useState(!1);f.useEffect(()=>()=>t.watch(null),[t,n]),f.useEffect(()=>{l&&t.watch(n)},[t,n,l]);const h=f.useRef(null);f.useEffect(()=>{const T=h.current;T&&(T.scrollTop=T.scrollHeight)},[i.length,i[i.length-1],x]);const N={name:"thread",sessionId:n},k=ps(a);if(!c)return e.jsxs(e.Fragment,{children:[e.jsx(Hs,{title:u.thread.title,fallback:N,label:u.terminal.back,link:k}),e.jsx("main",{className:"min-h-0 flex-1 pt-7 text-body text-muted",role:"status",children:!l&&a.syncedAt===null?u.thread.loading:u.terminal.unknown})]});const C=!!c.pending||c.state==="waiting_permission"||c.state==="waiting_input",j=!l,y=j?u.terminal.offline:C?u.terminal.waiting:u.terminal.live,b=Object.values(o).filter(T=>T.message.type==="session.interrupt"&&T.message.id===n).sort((T,B)=>T.at.localeCompare(B.at)).at(-1),M=b!==void 0&&yn(b.phase),S=c.state==="working",$=(b==null?void 0:b.phase)==="applied"&&(!S||r-Date.parse(b.at)<M1),v=S&&!j&&!C&&!M&&!$,A=j?u.terminal.why.offline:C?u.terminal.why.waiting:S?null:u.terminal.why.idle,R=()=>{v&&g(!t.interrupt(n))},_=(b==null?void 0:b.phase)==="sending"?u.terminal.sending:$?u.terminal.sent:u.terminal.interrupt(c.name),L=(b==null?void 0:b.phase)==="rejected"&&b.reason==="read_only"?u.terminal.readOnly:p||(b==null?void 0:b.phase)==="rejected"||(b==null?void 0:b.phase)==="failed"?u.terminal.fail:(b==null?void 0:b.phase)==="uncertain"&&!j?u.terminal.uncertain:null;return e.jsxs(e.Fragment,{children:[e.jsx(eu,{store:t,session:c,current:"terminal"}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"mt-2 mb-4 flex items-center justify-between gap-2",children:[e.jsx("span",{role:"status",className:"text-small text-muted",children:y}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",disabled:x<=ku,onClick:()=>m(-1),"aria-label":u.terminal.smaller,className:hi,children:"A−"}),e.jsx("button",{type:"button",disabled:x>=vu,onClick:()=>m(1),"aria-label":u.terminal.larger,className:hi,children:"A+"})]})]}),e.jsx("div",{ref:h,tabIndex:0,"aria-label":u.terminal.output,className:"mb-3 min-h-0 flex-1 overflow-auto rounded-card border border-line bg-term-bg p-4",children:i.length===0?e.jsx("p",{className:"text-small text-muted",children:u.terminal.empty}):e.jsx("pre",{"data-size":x,style:{fontSize:x},className:"m-0 w-max min-w-full font-mono leading-[1.5] whitespace-pre text-term-fg",children:i.join(`
|
|
20
|
-
`)})})]}),e.jsxs("footer",{className:"flex flex-none flex-col gap-2.5 border-t border-line bg-bg pt-3 pb-[max(16px,env(safe-area-inset-bottom))] [@media(max-height:650px)]:pb-2.5",children:[e.jsx("p",{className:"text-center text-meta text-muted",children:u.terminal.scrollHint}),L&&e.jsx("p",{role:"alert",className:"text-center text-small text-attention",children:L}),e.jsxs("button",{type:"button",disabled:!v,onClick:R,className:We({block:!0}),children:[e.jsx(z,{name:"stop"}),_]}),A&&!M&&!$&&e.jsx("p",{className:"text-center text-meta text-muted",children:A}),e.jsx("p",{className:"text-center text-meta text-muted",children:u.terminal.note})]})]})}const vs=u.unrecognized;function T1({pcName:t,onRelink:n,onSignOut:s}){return e.jsxs(Mt,{children:[e.jsxs("div",{className:"flex flex-col gap-3.5",children:[e.jsx("span",{"aria-hidden":"true",className:"inline-flex size-12 items-center justify-center rounded-full bg-danger-bg text-danger-fg",children:e.jsxs("svg",{className:pa,viewBox:"0 0 24 24",children:[e.jsx("rect",{x:"5",y:"2",width:"14",height:"20",rx:"2"}),e.jsx("path",{d:"m9.5 9.5 5 5"}),e.jsx("path",{d:"m14.5 9.5-5 5"})]})}),e.jsx("h1",{className:Ht,children:vs.title(t)}),e.jsx("p",{className:"text-muted",children:vs.body})]}),e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:vs.kept}),e.jsx(Et,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:n,className:Nt,children:vs.relink}),e.jsx("button",{type:"button",onClick:s,className:dt,children:vs.signOut})]})]})}const Mn=u.update,A1=t=>`https://github.com/kl-ledge/ledge/releases/tag/v${t}`;function I1({next:t,current:n,onLater:s,onApply:a}){return e.jsxs(ht,{labelledBy:"update-title",onClose:s,children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("h2",{id:"update-title",className:"text-heading leading-[26px] font-semibold tracking-[-.02em]",children:Mn.version(t.version)}),e.jsx("p",{className:"text-muted",children:Mn.body})]}),e.jsxs("div",{className:"flex flex-col gap-2 rounded-control border border-line bg-bg p-3.5",children:[e.jsx("span",{className:"text-small leading-4 text-muted",children:Mn.fingerprint}),e.jsx("code",{className:"font-mono text-base leading-[22px] tracking-[.02em] [word-spacing:4px]",children:ou(t.fingerprint)}),e.jsxs("span",{className:"text-small leading-4 text-muted",children:[Mn.current,e.jsx("span",{className:"font-mono",children:n?Mn.currentBuild(n.version,gj(n.fingerprint)):u.connection.none})]})]}),e.jsxs("a",{href:A1(t.version),target:"_blank",rel:"noreferrer",className:"inline-flex min-h-11 items-center gap-2 font-medium",children:[e.jsx(z,{name:"external",className:"size-4",stroke:1.5}),Mn.compare(`v${t.version}`)]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2.5",children:[e.jsx(Ue,{size:"lg",onClick:s,children:Mn.later}),e.jsx(Ue,{size:"lg",variant:"primary",onClick:a,children:Mn.apply})]})]})}const Yr="ledge.mobile.rigs",L1=35e3,O1=()=>crypto.randomUUID(),bi=()=>crypto.randomUUID(),sa=t=>t!=="checking"&&t!=="sending"&&t!=="received",D1=new Set(["assertion_invalid","assertion_expired","confirm_required","conflict"]);function F1(t){var n;try{const s=(n=Ze(t))==null?void 0:n.getItem(Yr);if(!s)return null;const a=JSON.parse(s),r=km.safeParse(a.state);return r.success&&typeof a.at=="string"?{state:r.data,at:a.at}:null}catch{return null}}function P1(t,n,s){var he;const a=F1(s);let r={state:(a==null?void 0:a.state)??null,error:null,at:(a==null?void 0:a.at)??null,loading:!1,graphs:{},queues:{},permissions:{},snapshots:{},routing:null,goals:null,runs:[]};const l=new Set,o=w=>{r={...r,...w};for(const O of[...l])O()};let c=!1,i=!1,x=!1,d=!1,m=!1;const p=new Map,g=new Map,h=new Map;let N=n.getState().daemon?((he=n.getState().daemon)==null?void 0:he.boot)??null:void 0;const k=new Set,C=()=>!c&&t.state()==="ready",j=()=>{var w;return!!((w=n.getState().daemon)!=null&&w.rigs)},y=w=>{t.send(w).catch(()=>{})};function b(w,O,V){return!C()||!j()?!1:(y(O),clearTimeout(p.get(w)),p.set(w,setTimeout(()=>{p.delete(w),V()},L1)),!0)}const M=w=>{clearTimeout(p.get(w)),p.delete(w)},S=w=>({...w??{},loading:!0}),$=w=>({...w??{},loading:!1,error:"unavailable"});function v(){d||b("state",{type:"rigs.state"},()=>{d=!1,o({loading:!1,error:"unavailable"})})&&(d=!0,o({loading:!0}))}function A(){m||b("goals",{type:"rigs.goals"},()=>{m=!1,o({goals:$(r.goals??void 0)})})&&(m=!0,o({goals:S(r.goals??void 0)}))}const R=()=>{i&&v(),x&&A()};function _(w,O){const V=r.runs.findIndex(X=>X.id===w);if(V<0)return;const Z=O(r.runs[V]);if(o({runs:r.runs.map((X,J)=>J===V?Z:X)}),sa(Z.phase)){Z.op&&Z.phase!=="uncertain"&&g.delete(Z.op);const X=h.get(w);h.delete(w),X==null||X(Z)}}const L=w=>r.runs.find(O=>O.op===w),T=w=>!!w&&(!sa(w.phase)||w.phase==="uncertain"),B=(w,O)=>{const V=L(w);M(`op:${w}`),T(V)&&_(V.id,Z=>({...Z,...O,endedAt:Date.now()}))},E=w=>{clearTimeout(p.get(`op:${w}`)),p.set(`op:${w}`,setTimeout(()=>{p.delete(`op:${w}`);const O=L(w);(O==null?void 0:O.phase)==="sending"&&_(O.id,V=>({...V,phase:"uncertain",endedAt:Date.now()}))},Ki))},P=w=>w.sentAt!==void 0&&Date.now()-w.sentAt<Wi&&N!==void 0&&(w.boot??null)===N,W=w=>{M(`op:${w.op}`),g.delete(w.op),_(w.id,O=>({...O,phase:"uncertain",lost:!0,endedAt:O.endedAt??Date.now()}))};function F(w){for(const[O,V]of[...g]){if(w.has(O))continue;const Z=L(O);if(!Z){g.delete(O);continue}if(!P(Z)){W(Z);continue}_(Z.id,X=>({...X,again:!0})),y(V),Z.phase==="sending"&&E(O)}}const re=(w,O)=>!w||!w.again||!D1.has(O??"")?!1:(w.lost||W(w),!0),Y=w=>{const O=w.kind==="seats"?w.rig:w.kind==="act"&&"rig"in w.action?w.action.rig:null;O&&(r.graphs[O]||r.queues[O])&&fe.openRig(O),O&&r.snapshots[O]&&fe.readSnapshots(O)};function H(w){var O;switch(w.type){case"snapshot":{const V=N;N=w.daemon.boot??null;const Z=new Set(k);k.clear();for(const X of Z){const J=L(X);J&&_(J.id,pe=>({...pe,boot:N}))}(V===void 0||V!==N)&&F(Z),R();return}case"rigs.state":if(M("state"),d=i,w.state){const V=new Date().toISOString();o({state:w.state,error:null,at:V,loading:!1});try{(O=Ze(s))==null||O.setItem(Yr,JSON.stringify({state:w.state,at:V}))}catch{}}else o({error:w.error??"unavailable",loading:!1});return;case"rigs.graph":M(`graph:${w.rig}`),o({graphs:{...r.graphs,[w.rig]:w.graph?{data:w.graph,loading:!1,at:new Date().toISOString()}:{...r.graphs[w.rig],loading:!1,error:w.error??"unavailable"}}});return;case"rigs.queue":M(`queue:${w.rig}`),o({queues:{...r.queues,[w.rig]:w.error?{...r.queues[w.rig],loading:!1,error:w.error}:{data:{rows:w.rows,closed:w.closed,truncated:w.truncated},loading:!1,at:new Date().toISOString()}}});return;case"rigs.permissions":M(`permissions:${w.rig}`),o({permissions:{...r.permissions,[w.rig]:w.error?{...r.permissions[w.rig],loading:!1,error:w.error}:{data:{...w.policy!==void 0?{policy:w.policy}:{},seats:w.seats},loading:!1,at:new Date().toISOString()}}});return;case"rigs.snapshots":M(`snapshots:${w.rig}`),o({snapshots:{...r.snapshots,[w.rig]:w.error?{...r.snapshots[w.rig],loading:!1,error:w.error}:{data:w.snapshots,loading:!1,at:new Date().toISOString()}}});return;case"rigs.routing":M("routing"),o({routing:w.error?{...r.routing,loading:!1,error:w.error}:{data:w.entries,loading:!1,at:new Date().toISOString()}});return;case"rigs.goals":M("goals"),m=x&&!w.error,o({goals:w.error?{...r.goals,loading:!1,error:w.error}:{data:{goals:w.goals,partial:!!w.partial},loading:!1,at:new Date().toISOString()}});return;case"operation.result":{const V=L(w.op);if(!T(V))return;if(w.status==="received"){M(`op:${w.op}`),(V.phase==="sending"||V.phase==="uncertain")&&_(V.id,Z=>{const{endedAt:X,...J}=Z;return{...J,phase:"received"}});return}if(w.status==="rejected"&&re(V,w.reason))return;w.status==="rejected"&&B(w.op,{phase:"rejected",reason:w.reason??"invalid"});return}case"rigs.done":{const V=L(w.op);if(w.rejected&&re(V,w.rejected))return;V&&(B(w.op,w.rejected?{phase:"rejected",reason:w.rejected,done:w}:{phase:"done",done:w,...w.error?{reason:w.error}:{}}),Y(V.subject));return}case"rigs.reseated":{const V=L(w.op);if(w.rejected&&re(V,w.rejected))return;V&&(B(w.op,w.rejected?{phase:"rejected",reason:w.rejected,reseated:w}:{phase:"done",reseated:w,...w.error?{reason:w.error}:{}}),Y(V.subject));return}case"rigs.goal.sent":case"rigs.goal.replied":if(w.rejected&&re(L(w.op),w.rejected))return;B(w.op,w.rejected?{phase:"rejected",reason:w.rejected,sent:w}:{phase:"done",sent:w,...w.error?{reason:w.error}:{}});return}}let I=C(),D=0;const Q=t.subscribe(()=>{const w=t.state();(w==="unpaired"||w==="pairing")&&K();const O=C();if(O&&!I)I=!0,D++,d=!1,m=!1,N=void 0,k.clear();else if(!O&&I){I=!1,d=!1,m=!1;for(const[V,Z]of p)clearTimeout(Z),p.delete(V);o({loading:!1});for(const V of r.runs)V.phase==="sending"&&V.op&&_(V.id,Z=>({...Z,phase:"uncertain",endedAt:Date.now()}))}}),q=t.onMessage(H);function K(){var w;if(!(!r.state&&!r.runs.length&&!Object.keys(r.graphs).length)){try{(w=Ze(s))==null||w.removeItem(Yr)}catch{}g.clear(),o({state:null,error:null,at:null,loading:!1,graphs:{},queues:{},permissions:{},snapshots:{},routing:null,goals:null,runs:[]})}}async function ee(w){var X;if(!((X=n.getState().device)!=null&&X.confirm))return{phase:"rejected",reason:"confirm_required"};let O;try{O=await n.prepareConfirm(w)}catch(J){return{phase:J instanceof Error&&J.message==="timeout"?"expired":"unsent"}}if(!O.credentialId)return{phase:"rejected",reason:"confirm_required"};const V=Date.now(),Z=await Fs({challenge:O.challenge,rpId:O.rpId,credentialId:O.credentialId}).catch(()=>"failed");return Z==="cancelled"?{phase:"cancelled"}:Z==="failed"?{phase:"unsent"}:Date.now()-V>=O.expiresInMs?{phase:"expired"}:{assertion:Z}}function ue(w,O,V){const Z=O1(),X={op:"",id:Z,subject:w,phase:O?"checking":"sending",startedAt:Date.now()},J=new Promise(pe=>h.set(Z,pe));return!C()||!j()?(o({runs:[...r.runs,{...X,phase:"unsent",endedAt:Date.now()}]}),h.delete(Z),Promise.resolve({...X,phase:"unsent"})):(o({runs:[...r.runs,X]}),(async()=>{var oe;let pe;if(O){const de=await ee(O);if(!("assertion"in de)){_(Z,ke=>({...ke,phase:de.phase,...de.reason?{reason:de.reason}:{},endedAt:Date.now()}));return}pe=de.assertion}const Ne=Ui(),Xe=Pi.safeParse(V(Ne,pe));if(!Xe.success||!C()){_(Z,de=>({...de,phase:"unsent",endedAt:Date.now()}));return}g.set(Ne,Xe.data),N===void 0&&k.add(Ne),_(Z,de=>({...de,op:Ne,phase:"sending",sentAt:Date.now(),...N!==void 0?{boot:N}:{}})),E(Ne);const gt=D,ze=await t.send(Xe.data).catch(()=>!1),Je=(oe=L(Ne))==null?void 0:oe.phase;!ze&>===D&&(Je==="sending"||Je==="uncertain")&&(M(`op:${Ne}`),_(Z,de=>({...de,phase:"unsent",endedAt:Date.now()})))})(),J)}const fe={getState:()=>r,subscribe(w){return l.add(w),()=>{l.delete(w)}},follow(){i=!0,v()},retry(){d=!1,v()},openRig(w){const O=`graph:${w}`,V=`queue:${w}`,Z=`permissions:${w}`;b(O,{type:"rigs.graph",rig:w},()=>o({graphs:{...r.graphs,[w]:$(r.graphs[w])}}))&&o({graphs:{...r.graphs,[w]:S(r.graphs[w])}}),b(V,{type:"rigs.queue",rig:w},()=>o({queues:{...r.queues,[w]:$(r.queues[w])}}))&&o({queues:{...r.queues,[w]:S(r.queues[w])}}),b(Z,{type:"rigs.permissions",rig:w},()=>o({permissions:{...r.permissions,[w]:$(r.permissions[w])}}))&&o({permissions:{...r.permissions,[w]:S(r.permissions[w])}})},readSnapshots(w){b(`snapshots:${w}`,{type:"rigs.snapshots",rig:w},()=>o({snapshots:{...r.snapshots,[w]:$(r.snapshots[w])}}))&&o({snapshots:{...r.snapshots,[w]:S(r.snapshots[w])}})},readPermissions(w){const O=`permissions:${w}`;b(O,{type:"rigs.permissions",rig:w},()=>o({permissions:{...r.permissions,[w]:$(r.permissions[w])}}))&&o({permissions:{...r.permissions,[w]:S(r.permissions[w])}})},readRouting(){b("routing",{type:"rigs.routing"},()=>o({routing:$(r.routing??void 0)}))&&o({routing:S(r.routing??void 0)})},followGoals(){x=!0,A()},act(w){return ue({kind:"act",action:w},tl(w)?{purpose:"rigs",rigAct:w}:null,(O,V)=>({type:"rigs.act",op:O,action:w,...V?{assertion:V}:{}}))},reseat(w,O,V={}){var J,pe;const Z=((pe=(J=r.state)==null?void 0:J.rigs.find(Ne=>Ne.name===w))==null?void 0:pe.nodes)??[],X=V.check||Fi(Z,O).remove.length>0;return ue({kind:"seats",rig:w,seats:O,...V.delegation?{delegation:V.delegation}:{}},X?{purpose:"rigs",rigSeats:{rig:w,seats:O}}:null,(Ne,Xe)=>({type:"rigs.seats",op:Ne,rig:w,seats:O,...V.delegation?{delegation:V.delegation}:{},...Xe?{assertion:Xe}:{}}))},sendGoal(w,O=bi()){return ue({kind:"goal",goalId:O,text:w},null,V=>({type:"rigs.goal.send",op:V,goalId:O,text:w}))},replyGoal(w,O,V=bi()){return ue({kind:"reply",goalId:w,replyId:V,text:O},null,Z=>({type:"rigs.goal.reply",op:Z,goalId:w,replyId:V,text:O}))},dismiss(w){const O=r.runs.find(V=>V.id===w);O&&sa(O.phase)&&O.op&&(g.delete(O.op),M(`op:${O.op}`)),o({runs:r.runs.filter(V=>V.id!==w||!sa(V.phase))})},close(){c=!0,Q(),q();for(const w of p.values())clearTimeout(w);p.clear()}};return fe}function bs(t){return f.useSyncExternalStore(t.subscribe,t.getState,t.getState)}const yr={relaunch:!0,noKernel:!1},Su="ledge.mobile.daemonPrefs",Qr=new Set;function Cu(t){var n;try{const s=JSON.parse(((n=Ze(t))==null?void 0:n.getItem(Su))??"{}");return{relaunch:typeof s.relaunch=="boolean"?s.relaunch:yr.relaunch,noKernel:typeof s.noKernel=="boolean"?s.noKernel:yr.noKernel}}catch{return yr}}function z1(t,n){var s;try{(s=Ze(n))==null||s.setItem(Su,JSON.stringify({...Cu(n),...t}))}catch{}for(const a of[...Qr])a()}const B1=t=>(Qr.add(t),()=>{Qr.delete(t)});function Ll(t){const n=f.useSyncExternalStore(B1,()=>JSON.stringify(Cu(t)));return[JSON.parse(n),s=>z1(s,t)]}function $u(t,n){const s=n.relaunch?"last":"none";return t==="restart"?{kind:"daemon.restart",restore:s}:{kind:"daemon.start",restore:s,...n.noKernel&&!n.relaunch?{noKernel:!0}:{}}}const ye=u.rigs;function q1(t){var a;const n=t.subject;if(n.kind==="seats")return n.rig;if(n.kind!=="act")return"";const s=n.action;return s.rig??((a=s.seat)==null?void 0:a.split("@")[0])??""}const Ol=t=>t.subject.kind==="act"?t.subject.action.kind:t.subject.kind==="seats"?"seats":null;function ws(t){const n=Ol(t);return n?ye.notDone[n]:ye.rejected.nothingSent}function H1(t){const n=Ol(t),s=ye.rejected.againVerb;return n==="seats"?s.remove:n==="rig.stop"||n==="daemon.stop"||n==="kernel.stop"?s.stop:n==="rig.restart"||n==="daemon.restart"||n==="kernel.restart"?s.restart:n==="rig.policy"||n==="rig.permissions"?s.apply:n==="seat.set"?s.save:null}function U1(t,n){const s=Pt(),a=t.phase==="expired"?"assertion_expired":t.phase==="cancelled"?"cancelled":t.phase==="unsent"?"unsent":t.reason??"unavailable",r=H1(t),l=r?ye.rejected.again(r):ye.rejected.nothingSent;switch(a){case"busy":return{mark:"warn",title:ye.busy.title(n),sub:ye.busy.body};case"confirm_required":return t.subject.kind==="seats"?{mark:"warn",title:s?ye.reseat.wouldLeave.title:ye.reseat.wouldLeave.titleDevice,sub:ye.reseat.wouldLeave.body}:{mark:"warn",title:ye.rejected.confirm_required};case"assertion_expired":return{mark:"bad",title:ye.because(ws(t),ye.rejected.assertion_expired(s)),sub:l};case"assertion_invalid":return{mark:"bad",title:ye.because(ws(t),ye.rejected.assertion_invalid(s)),sub:l};case"cancelled":return{mark:"bad",title:ye.because(ws(t),ye.rejected.cancelled),sub:ye.rejected.nothingSent};case"unsent":return{mark:"bad",title:ye.because(ws(t),ye.rejected.unsent),sub:ye.rejected.nothingSent};default:return{mark:"bad",title:ye.because(ws(t),`${ye.notSent(n)}.`)}}}function Ca({run:t,rigs:n,pc:s,bar:a=!1}){const r=Ol(t),l=q1(t),o={onClose:()=>n.dismiss(t.id),closeLabel:ye.done.close};if(t.phase==="checking")return e.jsx(Ls,{bar:a,children:ye.running.checking});if(t.phase==="sending"||t.phase==="received"){const m=r==="seats"?ye.running.seats(l):r?ye.running[r](l):"";return e.jsx(Ls,{bar:a,children:`${m} · ${ye.running.note}`})}if(t.phase==="uncertain")return e.jsx($e,{mark:"ask",title:ye.uncertain.title,sub:ye.uncertain.body,...o});if(t.phase!=="done"){const m=U1(t,s);return e.jsx($e,{mark:m.mark,title:m.title,...m.sub?{sub:m.sub}:{},...o})}const c=Ke(t.endedAt?new Date(t.endedAt).toISOString():null);if(t.reseated){const m=t.reseated;if(m.ok){const p=m.added.length?ye.reseat.added(m.added.length,m.links):ye.reseat.removed(m.removed.length);return e.jsxs($e,{mark:"ok",title:p,...o,children:[m.linksUnsupported&&e.jsxs("small",{className:"block text-[12px] text-attention",children:[ye.reseat.noLinks.title," ",ye.reseat.noLinks.body]}),e.jsx(qn,{commands:m.commands})]})}return m.error==="busy"?e.jsx($e,{mark:"warn",title:ye.busy.title(s),sub:ye.busy.body,...o}):m.error==="rig_not_running"?e.jsx($e,{mark:"bad",title:ye.reseat.notRunning.title,sub:ye.reseat.notRunning.body,...o}):e.jsx($e,{mark:"bad",title:ye.failed(m.message??ye.errors[m.error??"failed"]??ye.errors.failed),...o,children:e.jsx(qn,{commands:m.commands})})}const i=t.done;if(!i||!r||r==="seats")return null;if(i.ok){const m=t.subject.kind==="act"&&t.subject.action.kind==="rig.stop"&&t.subject.action.snapshot;return e.jsx($e,{mark:"ok",title:ye.done[r](l),sub:[c,m?ye.done.snapshotFirst:""].filter(Boolean).join(" · "),...o,children:e.jsx(qn,{commands:i.commands})})}if(i.error==="busy")return e.jsx($e,{mark:"warn",title:ye.busy.title(s),sub:ye.busy.body,...o});const x=t.subject.kind==="act"&&"seats"in t.subject.action?t.subject.action.seats.length:0;if(i.completed!==void 0&&x)return e.jsx($e,{mark:"bad",title:ye.completed(i.completed,x),...i.message?{sub:e.jsx("span",{className:"font-mono",children:i.message})}:{},...o});const d=i.error&&i.error!=="failed"?ye.errors[i.error]:void 0;return e.jsx($e,{mark:"bad",title:d??ye.failed(ye.errors.failed),...i.message?{sub:e.jsx("span",{className:"font-mono",children:i.message})}:{},...o,children:e.jsx(qn,{commands:i.commands})})}function Dl(t,n){for(let s=t.length-1;s>=0;s--)if(n(t[s]))return t[s]}const Ya=t=>!!t&&(t.phase==="checking"||t.phase==="sending"||t.phase==="received"),je=u.rigs,W1={running:"on",stopped:"plain",stale:"bad",unknown:"plain"},Mu={ready:"on",starting:"go",stopped:"plain",skipped:"plain",absent:"plain",unknown:"plain"};function Fl({state:t,href:n}){const s=t.daemon.state==="running"&&t.daemon.startedAt?Ke(t.daemon.startedAt):null;return e.jsx(qr,{lead:e.jsx(z,{name:"cpu",className:"size-[18px] text-muted"}),name:je.daemon,chip:e.jsx(ds,{tone:W1[t.daemon.state],children:je.daemonState[t.daemon.state]}),sub:je.daemonSub(t.version,s),...n?{href:n}:{}})}function Eu({disabled:t,next:n=!1}){const[s,a]=Ll();return e.jsxs(e.Fragment,{children:[e.jsx(Fo,{on:s.relaunch,label:je.relaunch,disabled:t,onChange:r=>a({relaunch:r})}),e.jsx(Fo,{on:s.noKernel,label:je.noKernel,hint:n?je.noKernelNext:je.noKernelHint,disabled:t,onChange:r=>a({noKernel:r})})]})}function $a({glyph:t,title:n,body:s,list:a=!0,children:r}){return e.jsxs("div",{"data-list-state":a?"":void 0,className:"flex flex-col items-center gap-1.5 px-4 pt-[26px] pb-[22px] text-center",children:[t&&e.jsx("div",{"aria-hidden":"true",className:"grid size-12 place-items-center rounded-[10px] border border-line text-muted",children:t}),e.jsx("h2",{className:"mt-1.5 text-[17px] leading-6 font-semibold",children:n}),e.jsx("p",{className:"max-w-[300px] text-[13.5px] text-muted",children:s}),r]})}function ji({state:t,rigs:n,store:s,pc:a}){const r=me(s).fresh,[l]=Ll(),o=bs(n),c=Dl(o.runs,i=>i.subject.kind==="act"&&i.subject.action.kind==="daemon.start");return e.jsxs(e.Fragment,{children:[t&&e.jsxs(e.Fragment,{children:[e.jsx(It,{children:je.openrig}),e.jsx(Ve,{children:e.jsx(Fl,{state:t})})]}),e.jsxs(Ve,{children:[e.jsx($a,{glyph:e.jsx(z,{name:"power"}),title:je.stopped.title,body:je.stopped.body}),e.jsx("div",{className:"border-t border-line",children:e.jsx(Eu,{disabled:!r})}),e.jsx("div",{className:"p-3",children:e.jsx("button",{type:"button",disabled:!r||Ya(c),onClick:()=>{n.act($u("start",l))},className:be({tone:"primary",className:"w-full"}),children:e.jsx(Ft,{icon:"power",children:je.stopped.start})})})]}),c&&e.jsx(Ca,{run:c,rigs:n,pc:a}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:je.stopped.note})]})}function K1(){const t="block animate-[ledge-pulse_1.6s_ease-in-out_infinite] rounded-[5px] bg-raised";return e.jsxs("div",{role:"status","data-list-state":"",className:"flex flex-col gap-3",children:[e.jsx(Ve,{children:e.jsxs("div",{"aria-hidden":"true",className:"flex flex-col gap-2.5 p-2.5",children:[e.jsx("span",{className:`${t} h-3.5 w-[60%]`}),e.jsx("span",{className:`${t} h-3 w-[40%]`})]})}),e.jsx(Ve,{children:e.jsxs("div",{"aria-hidden":"true",className:"flex flex-col gap-2.5 p-2.5",children:[e.jsx("span",{className:`${t} h-3.5 w-1/2`}),e.jsx("span",{className:`${t} h-3 w-[70%]`}),e.jsx("span",{className:`${t} h-3.5 w-[45%]`}),e.jsx("span",{className:`${t} h-3 w-[65%]`})]})}),e.jsx("span",{className:"text-[12px] text-muted",children:je.loading})]})}function V1({state:t,at:n,store:s,offline:a}){const r=me(s),l=Ps(),o=Dt(),c=Nd(t),i=Br(t),x=i.filter(g=>Ng(mn(g))).length,d=[...r.sessions.values()],m=((c==null?void 0:c.nodes)??[]).map(_d),p=t.daemon.state==="running";return e.jsxs("div",{className:`flex flex-col gap-3 ${a?"opacity-50":""}`,children:[e.jsx(It,{aside:!a&&n?je.updatedAt(Ke(n)):void 0,children:je.openrig}),e.jsxs(Ve,{label:je.openrig,children:[e.jsx(Fl,{state:t,...a?{}:{href:ce({name:"kernel"})}}),t.kernel.state!=="absent"&&e.jsx(qr,{lead:e.jsx(Pe,{state:"rig"}),name:je.kernel,selected:l.name==="kernel"&&o,chip:e.jsx(ds,{tone:Mu[t.kernel.state],children:je.kernelState[t.kernel.state]}),sub:m.length?a||o?je.kernelSubShort(m):je.kernelSub(m):"",...a?{}:{href:ce({name:"kernel"})}})]}),p&&i.length===0?e.jsx(Ve,{children:e.jsx($a,{title:je.empty.title,body:je.empty.body,list:!1,children:e.jsx("a",{href:ce({name:"max"}),className:be({size:"sm",className:"mt-1.5"}),children:je.empty.talk})})}):i.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(It,{children:je.rigsHead(x)}),e.jsx(Ve,{tone:"rigs",label:je.title,children:i.map(g=>{const h=mn(g),N=vd(g.name,d,r.asks),k=h==="stopped",C=a?[k?je.seatCount(g.seats):je.seats(g.running,g.seats),!k&&n?je.at(Ke(n)):""].filter(Boolean).join(" · "):h==="stopped"?[je.seatCount(g.seats),g.snapshot?je.snapshot(g.snapshot):je.noSnapshot].join(" · "):h==="partial"?[je.seats(g.running,g.seats),je.stoppedCount(g.nodes.filter(y=>y.stopped).length||g.seats-g.running)].join(" · "):h==="starting"?je.seats(g.running,g.seats):[je.seats(g.running,g.seats),g.uptime?je.since(g.uptime):"",g.snapshot?je.snapshot(g.snapshot):""].filter(Boolean).join(" · "),j=!a&&(N.perm||N.ask)?e.jsxs(e.Fragment,{children:[N.perm>0&&e.jsx(Is,{perm:!0,children:je.attention.permission(N.perm)}),N.ask>0&&e.jsx(Is,{children:je.attention.question(N.ask)})]}):void 0;return e.jsx(qr,{lead:e.jsx(Pe,{state:wd(g,N),pulse:h==="starting"&&!a}),name:g.name,dim:k,chip:e.jsx(ds,{tone:Rd[h],children:je.status[h]}),sub:C,att:j,href:ce({name:"rig",rig:g.name}),selected:o&&l.name==="rig"&&l.rig===g.name},g.id)})})]}),!a&&p&&e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:je.launchNote})]})}function G1({rigs:t,store:n}){const s=bs(t),{pc:a,look:r}=zt(),l=r==="offline";f.useEffect(()=>{t.follow()},[t]);const o=Jt(a),c=s.state,i=c?c.installed?!l&&_g(c)?e.jsx(ji,{state:c,rigs:t,store:n,pc:o}):e.jsxs(e.Fragment,{children:[!l&&s.error&&e.jsxs(Wt,{warn:!0,role:"alert",lead:e.jsx(z,{name:"warning",className:"mt-px size-4 text-attention"}),children:[e.jsx("b",{className:"font-semibold",children:je.unavailable.title}),s.at&&e.jsx("span",{className:"text-muted",children:je.unavailable.body(Ke(s.at))}),e.jsx("button",{type:"button",onClick:()=>t.retry(),className:be({size:"sm",className:"self-start"}),children:e.jsx(Ft,{icon:"refresh",children:je.unavailable.retry})})]}),e.jsx(V1,{state:c,at:s.at,store:n,offline:l})]}):e.jsx(Ve,{children:e.jsx($a,{title:je.notInstalled.title,body:je.notInstalled.body(o)})}):s.error==="not_installed"?e.jsx(Ve,{children:e.jsx($a,{title:je.notInstalled.title,body:je.notInstalled.body(o)})}):s.error==="daemon_stopped"?e.jsx(ji,{state:null,rigs:t,store:n,pc:o}):s.error?e.jsx("div",{"data-list-state":"",className:"flex flex-col",children:e.jsxs(Wt,{warn:!0,role:"alert",lead:e.jsx(z,{name:"warning",className:"mt-px size-4 text-attention"}),children:[e.jsx("b",{className:"font-semibold",children:je.unavailable.title}),e.jsx("button",{type:"button",onClick:()=>t.retry(),className:be({size:"sm",className:"self-start"}),children:e.jsx(Ft,{icon:"refresh",children:je.unavailable.retry})})]})}):e.jsx(K1,{});return e.jsxs(fs,{title:je.title,offlineBody:je.offlineBody,heading:!1,children:[e.jsx(bu,{store:n}),i]})}const te=u.rigs;function Ma(t,n=new Date){const s=va(t);if(!s)return{short:t,long:t};const a=s.toLocaleTimeString(ut,{hour:"2-digit",minute:"2-digit"}),r=Cl(s,n);if(r===0)return{short:a,long:te.snapshots.today(a)};if(r===1)return{short:te.snapshots.yesterday(a),long:te.snapshots.yesterday(a)};const l=s.toLocaleDateString(ut,{weekday:"short",day:"numeric",month:"short"});return{short:l,long:`${l} ${a}`}}function On({verb:t,confirm:n,disabled:s,onClick:a}){const r=Pt();return n?e.jsx("button",{type:"button",disabled:s,onClick:a,className:be({tone:"dangerfill",className:"w-full"}),children:e.jsx(Ft,{icon:r?"face":"passkey",size:"size-[18px]",children:te.withCheck(t,r)})}):e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("p",{className:"text-[12.5px] text-muted",children:te.protectFirst}),e.jsx("a",{href:ce({name:"connection"}),className:be({className:"w-full"}),children:te.openSettings})]})}const Xs=({onClose:t})=>e.jsx("button",{type:"button",onClick:t,className:be({className:"w-full"}),children:te.confirm.cancel});function aa({title:t,conseq:n,note:s,verb:a,confirm:r,live:l,onConfirm:o,onClose:c}){return e.jsxs(an,{title:t,onClose:c,children:[n&&e.jsx($l,{title:n.title,...n.body?{body:n.body}:{}}),s&&e.jsx("p",{className:"text-[12.5px] leading-[18px] text-muted",children:s}),e.jsx(On,{verb:a,confirm:r,disabled:!l,onClick:()=>{c(),o()}}),e.jsx(Xs,{onClose:c})]})}function Hn({icon:t,label:n,aside:s,onClick:a,disabled:r=!1,danger:l=!1}){return e.jsxs("button",{type:"button",role:"menuitem",disabled:r,onClick:a,className:`flex min-h-12 items-center gap-3 border-b border-line px-3.5 text-left text-[15px] last:border-b-0 disabled:opacity-45 ${l?"text-approval":""}`,children:[e.jsx(z,{name:t,className:`size-[18px] ${l?"":"text-muted"}`}),e.jsx("span",{className:"min-w-0 flex-1",children:n}),s&&e.jsx("span",{className:"text-[13px] text-muted",children:s})]})}function X1({rig:t,live:n,running:s,snapshots:a,level:r,onSnapshot:l,onSnapshots:o,onPermissions:c,onRefresh:i,onClose:x}){return e.jsx(an,{title:t,onClose:x,children:e.jsxs("div",{role:"menu","aria-label":te.more,className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:[e.jsx(Hn,{icon:"camera",label:te.actions.snapshot,disabled:!n||s,onClick:l}),e.jsx(Hn,{icon:"list",label:te.actions.snapshots,...a!==null?{aside:String(a)}:{},onClick:o}),e.jsx(Hn,{icon:"shield",label:te.actions.permissions,...r?{aside:r}:{},onClick:c}),e.jsx(Hn,{icon:"refresh",label:te.actions.refresh,disabled:!n,onClick:i})]})})}function Y1({live:t,up:n,onRefresh:s,onRestart:a,onStop:r,onClose:l}){return e.jsx(an,{title:te.kernel,onClose:l,children:e.jsxs("div",{role:"menu","aria-label":te.more,className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:[e.jsx(Hn,{icon:"refresh",label:te.kernelView.menu.refresh,disabled:!t,onClick:s}),e.jsx(Hn,{icon:"refresh",label:te.kernelView.menu.restart,disabled:!t||!n,onClick:a}),e.jsx(Hn,{icon:"power",label:te.kernelView.menu.stop,danger:!0,disabled:!t||!n,onClick:r})]})})}function Q1({rig:t,pc:n,verb:s,confirm:a,live:r,onAct:l,onClose:o}){const[c,i]=f.useState(!0),[x,d]=f.useState(!1),m=t.nodes.filter(N=>!N.stopped&&Vs(N)).map(N=>pn(N.logicalId,N.session)),p=s==="stop",g=m.length?te.confirm.working(m.length):te.confirm.noneWorking,h=p?{kind:"rig.stop",rig:t.name,...c?{snapshot:!0}:{},...x?{force:!0}:{}}:{kind:"rig.restart",rig:t.name};return e.jsxs(an,{title:p?te.confirm.stop(t.name,n):te.confirm.restart(t.name,n),onClose:o,children:[e.jsx($l,{title:g,body:p?m.length?m.join(", "):void 0:te.confirm.restartNote}),p&&e.jsxs("div",{className:"overflow-hidden rounded-[10px] border border-line",children:[e.jsx(Do,{on:c,label:te.confirm.snapshot,onChange:i}),e.jsx(Do,{on:x,label:te.confirm.force,onChange:d})]}),e.jsx(On,{verb:p?te.actions.stop:te.actions.restart,confirm:a,disabled:!r,onClick:()=>{o(),l(h)}}),e.jsx(Xs,{onClose:o})]})}function _u({rig:t,confirm:n,live:s,onReseat:a,onDone:r,context:l}){const o=Md(t),[c,i]=f.useState({}),[x,d]=f.useState("pairs"),m=Object.fromEntries(Object.entries(c).filter(([y,b])=>{var M;return((M=o.find(S=>S.role===y))==null?void 0:M.count)!==b})),p=Fi(t.nodes,m),g=p.add.length,h=p.remove.length,N=t.nodes.filter(y=>p.remove.includes(y.logicalId)&&Vs(y)).map(y=>y.logicalId),k=g&&h?te.reseat.change(g,h):g?te.reseat.add(g):h?te.reseat.remove(h):te.reseat.noChange,C=()=>{r==null||r(),i({}),a(m,g?x:void 0)},j=l!==void 0;return e.jsxs(e.Fragment,{children:[e.jsx("table",{className:"w-full border-collapse text-[13px]",children:e.jsx("tbody",{children:o.map(y=>{const b=c[y.role]??y.count,M=p.add.filter(R=>R.role===y.role).map(R=>te.reseat.adds(`${R.pod}.${R.id}`)),S=p.remove.filter(R=>y.ids.includes(R)).map(te.reseat.removes),$=y.ids.map(R=>{var _;return pn(R,(_=t.nodes.find(L=>L.logicalId===R))==null?void 0:_.session)}).join(", "),v=j?y.ids.map(R=>l[R]).filter(R=>R!==void 0).map(R=>`${Math.round(R)} %`).join(", "):"",A=j?[...M,...S].join(" · "):[$,...M,...S].join(S.length?" → ":" · ");return e.jsxs("tr",{className:"border-b border-line last:border-b-0",children:[e.jsxs("td",{className:"px-1 py-[7px] font-mono text-[12.5px]",children:[y.role,A&&e.jsx("small",{className:"block font-sans text-[11.5px] text-muted",children:A})]}),j&&e.jsx("td",{className:"px-1 py-[7px] text-[12px] text-muted",children:v}),e.jsx("td",{className:"px-1 py-[7px] text-right",children:e.jsx(Og,{value:b,changed:b!==y.count,disabled:!s,fewer:te.reseat.fewer(y.role),more:te.reseat.more(y.role),onChange:R=>i({...c,[y.role]:R})})})]},y.role)})})}),g>0&&e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"flex-1 text-[12.5px] text-muted",children:te.reseat.delegation}),e.jsx(ca,{label:te.reseat.delegation,value:x,onChange:d,options:[{value:"pairs",label:te.reseat.pairs},{value:"all",label:te.reseat.all}]})]}),h>0&&e.jsx($l,{title:N.length?te.reseat.working(N):te.reseat.lastFirst,...N.length?{body:te.reseat.lastFirst}:{}}),(!j||g+h>0)&&(h>0?e.jsx(On,{verb:k,confirm:n,disabled:!s,onClick:C}):e.jsx("button",{type:"button",disabled:!s||g===0,onClick:C,className:be({tone:"primary",className:"w-full"}),children:k})),j&&g+h>0&&e.jsx("button",{type:"button",onClick:()=>i({}),className:be({className:"w-full"}),children:te.confirm.cancel})]})}function Z1({rig:t,pc:n,confirm:s,live:a,onReseat:r,onClose:l}){return e.jsxs(an,{title:te.reseat.title(t.name,n),onClose:l,children:[e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:te.reseat.today(Md(t).map(o=>te.reseat.part(o.count,o.role)).join(", "))}),e.jsx(_u,{rig:t,confirm:s,live:a,onReseat:r,onDone:l}),e.jsx(Xs,{onClose:l})]})}function J1({rig:t,read:n,level:s,confirm:a,live:r,onAct:l,onClose:o}){var k,C;const[c,i]=f.useState(s==="mixed"?null:s),x=Pt(),d=Cg((k=n==null?void 0:n.data)==null?void 0:k.policy),m=(((C=n==null?void 0:n.data)==null?void 0:C.seats.map(j=>j.session))??t.nodes.map(j=>j.session)).filter(j=>j.endsWith(`@${t.name}`)),p=c&&m.length?{kind:"rig.policy",rig:t.name,policy:c,seats:m}:null,g=!!p&&tl(p),h=()=>{p&&(o(),l(p))},N=!r||!p||c===s;return e.jsxs(an,{title:te.permissions.title(t.name),onClose:o,children:[e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:[te.permissions.sub,d?te.permissions.spec(te.level[d]):""].filter(Boolean).join(" ")}),(n==null?void 0:n.error)&&!n.data&&e.jsx("p",{role:"alert",className:"text-[12.5px] text-attention",children:te.permissions.unavailable}),e.jsx("div",{className:"flex flex-col gap-1.5",children:wg.map(j=>e.jsx(Hr,{pressed:c===j,disabled:!r,onClick:()=>i(j),sub:te.permissions.hint[j],title:e.jsxs(e.Fragment,{children:[te.level[j],(j==="yolo"||j==="spec")&&e.jsx("span",{className:"ml-1.5 inline-flex align-middle",children:e.jsx(Lt,{tone:"perm",children:x?te.permissions.faceId:te.permissions.check})})]})},j))}),g?e.jsx(On,{verb:te.permissions.apply,confirm:a,disabled:N,onClick:h}):e.jsx("button",{type:"button",disabled:N,onClick:h,className:be({tone:"primary",className:"w-full"}),children:te.permissions.apply})]})}const ey=(t,n)=>{const s=Ag(t,n.links).map(a=>{var l;const r=pn(a.who,(l=n.seats.find(o=>o.logicalId===a.who))==null?void 0:l.session);return a.kind==="linked"?te.seat.linked(r,a.label):te.seat[a.kind](r)});return s.length?s.join(" · "):te.seat.noLink};function ty({rig:t,seat:n,graph:s,node:a,session:r,status:l,near:o,onSettings:c,onClose:i}){const x=wl({session:r,node:a,graph:n,rigStatus:l}),d=Sl(n.runtime),m=pn(n.logicalId,n.session),p=[d?u.tools[d]:n.runtime,n.model??(a==null?void 0:a.model)??""].filter(Boolean).join(" · "),g=r!=null&&r.pending?te.seat.prompt(te.seatState[x]):te.seatState[x],h=a&&a.work>0?te.seat.tasks(a.work):te.seat.noTask,N=[[te.seat.harness,p],...n.context!==void 0?[[te.seat.context,e.jsx("span",{className:`font-mono ${n.context>=o?"text-attention":""}`,children:`${Math.round(n.context)} %`},"c")]]:[],[te.seat.now,g],[te.seat.work,h],[te.seat.links,ey(n.logicalId,s)]];return e.jsxs(an,{title:m,onClose:i,children:[e.jsxs("div",{className:"-mt-2 flex items-center gap-2",children:[e.jsx(Pe,{state:Sd[x]}),d&&e.jsx(Xn,{tool:d}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"text-[12.5px] text-muted",children:te.seat.of(n.logicalId,t)})]}),e.jsx("dl",{className:"m-0 grid grid-cols-[110px_1fr] gap-x-3 gap-y-1.5 text-[13px]",children:N.map(([k,C])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted",children:k}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:C})]},k))}),r?e.jsx("a",{href:ce({name:"thread",sessionId:r.id}),className:be({tone:"primary",className:"w-full"}),children:te.seat.openSession}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:!0,className:be({tone:"primary",className:"w-full"}),children:te.seat.openSession}),e.jsx("p",{className:"-mt-1 text-[12px] text-muted",children:te.seat.noSession})]}),e.jsx("button",{type:"button",onClick:c,className:be({className:"w-full"}),children:e.jsx(Ft,{icon:"gear",children:te.seat.settings})})]})}function ny({rig:t,seat:n,node:s,selection:a,confirm:r,live:l,onAct:o,onClose:c}){const i=te.seatSettings,x=n.runtime==="codex"?"codex":n.runtime==="claude-code"||n.runtime==="claude"?"claude-code":null,d=n.model??(s==null?void 0:s.model)??"",m=a==="inherit"||a==="auto"||a==="full_bypass"?a:null,[p,g]=f.useState(x),[h,N]=f.useState(d),[k,C]=f.useState(null),[j,y]=f.useState(m),b=pn(n.logicalId,n.session),M=n.session??(s==null?void 0:s.session)??`${b}@${t}`,S=h.trim()===""||vm.safeParse(h.trim()).success,$=p!==null&&p!==x,v={kind:"seat.set",seat:M,...$?{runtime:p}:{},...h.trim()&&h.trim()!==d?{model:h.trim()}:{},...k?{effort:k}:{},...j&&j!==m?{permissions:j}:{}},A=Object.keys(v).length>2,R=tl(v),_=Sl(n.runtime),L=[_?u.tools[_]:n.runtime,d,m?i.perm[m]:""].filter(Boolean),T=!l||!A||!S,B=()=>{c(),o(v)},E=(P,W,F)=>e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"text-[12.5px] text-muted",children:`${P} · ${W}`}),F]});return e.jsxs(an,{title:i.title(b,t),onClose:c,children:[e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:i.today(L)}),E(i.harness,i.whenNow,e.jsx(ca,{label:i.harness,value:p,disabled:!l,onChange:g,options:[{value:"claude-code",label:u.tools.claude},{value:"codex",label:u.tools.codex}]})),E(i.model,i.whenResume,e.jsx("input",{"aria-label":i.modelLabel,value:h,disabled:!l,onChange:P=>N(P.target.value),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,className:`h-11 rounded-[10px] border bg-surface px-3 text-base outline-none focus:border-ring ${S?"border-input":"border-approval/60"}`})),E(i.effort,i.whenResume,e.jsx(ca,{label:i.effort,value:k,disabled:!l,onChange:C,options:["medium","high","xhigh"].map(P=>({value:P,label:i.effortLevel[P]}))})),E(i.permissions,i.whenLaunch,e.jsx(ca,{label:i.permissions,value:j,disabled:!l,onChange:y,options:["inherit","auto","full_bypass"].map(P=>({value:P,label:i.perm[P]}))})),$&&e.jsx("p",{className:"text-[12.5px] text-attention",children:i.moveNote}),R?e.jsx(On,{verb:i.save,confirm:r,disabled:T,onClick:B}):e.jsx("button",{type:"button",disabled:T,onClick:B,className:be({tone:"primary",className:"w-full"}),children:i.save})]})}function Ru({read:t,kindOnly:n=!1,retry:s}){const a=Td((t==null?void 0:t.data)??[]),r="overflow-hidden rounded-[10px] border border-line bg-surface dark:bg-transparent";return t!=null&&t.error&&!t.data?e.jsx("div",{className:r,children:e.jsx(Ln,{retry:s,retryLabel:te.unavailable.retry,children:te.snapshots.unavailable})}):t!=null&&t.data&&a.length===0?e.jsx("div",{className:r,children:e.jsx(Ln,{children:te.snapshots.none})}):a.length?e.jsx("div",{className:"flex max-h-[45dvh] flex-col overflow-y-auto rounded-[10px] border border-line bg-surface dark:bg-transparent",children:a.map(l=>e.jsxs("div",{className:"flex min-h-[46px] items-center gap-2.5 border-b border-line px-3 py-1.5 text-[13px] last:border-b-0",children:[e.jsx(z,{name:"camera",className:"size-4 text-muted"}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{children:Ma(l.createdAt).long}),e.jsx("small",{className:"text-[11.5px] text-muted",children:n?te.snapshots.kind[l.kind]??l.kind:[te.snapshots.kind[l.kind]??l.kind,te.snapshots.status[l.status]??l.status].join(" · ")})]})]},l.id))}):e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:te.loading})}function sy({rig:t,read:n,live:s,running:a,onSnapshot:r,onRetry:l,onClose:o}){return e.jsxs(an,{title:te.snapshots.title(t),onClose:o,children:[e.jsx(Ru,{read:n,retry:l}),e.jsx("button",{type:"button",disabled:!s||a,onClick:()=>{o(),r()},className:be({className:"w-full"}),children:e.jsx(Ft,{icon:"camera",children:te.snapshots.take})}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:te.snapshots.utc})]})}const xe=u.rigs,vn=t=>{var n;return((n=va(t))==null?void 0:n.toISOString())??t},ay={mine:"border-attention/50 text-attention",progress:"border-info/45 text-info",pending:"border-input text-muted",blocked:"border-approval/45 text-approval"},ry=({tone:t})=>e.jsx("span",{"data-row":t,className:`flex-none rounded-[5px] border px-1.5 text-[11px] leading-[18px] whitespace-nowrap ${ay[t]}`,children:xe.queue.tone[t]}),Un=t=>t.split("@")[0]??t;function Tu({seat:t,state:n,pod:s,tag:a,near:r,isNew:l,pulse:o,onOpen:c,onMore:i,top:x=!1,name:d,words:m}){const{swallow:p,...g}=Dg(i),h=d??pn(t.logicalId,t.session),N=Sl(t.runtime),k=t.context!==void 0&&n!=="off"&&n!=="waiting"?Math.round(t.context):null,C=m??[x?s:void 0,xe.seatState[n]].filter(Boolean).join(" · "),j=l?"border-ok/55":n==="ask"?"border-attention/55":n==="perm"?"border-approval/55":n==="off"||n==="waiting"?"border-dashed border-input bg-transparent":"border-line",y=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx(Pe,{state:Sd[n],pulse:o}),e.jsx("b",{className:`truncate text-[13px] font-semibold ${n==="off"?"text-muted":""}`,children:h}),l?e.jsx("span",{className:"ml-auto",children:e.jsx(Lt,{tone:"ok",children:xe.reseat.new})}):a&&N&&e.jsx("span",{className:"ml-auto",children:e.jsx(Xn,{tool:N})})]}),e.jsxs("small",{className:`truncate text-[11.5px] ${n==="ask"?"text-attention":"text-muted"}`,children:[C,k!==null&&e.jsxs(e.Fragment,{children:[C?" · ":"",e.jsx("span",{className:`font-mono ${k>=r?"text-attention":""}`,children:`${k} %`})]})]})]}),b=`flex min-w-0 flex-col gap-px rounded-[9px] border bg-surface px-[9px] py-[7px] text-left ${j} ${x?"w-[190px] max-w-full":""}`;return c?e.jsx("button",{type:"button",...g,onClick:()=>{p!=null&&p()||c()},"aria-label":xe.seatLabel(h,xe.seatState[n]),"data-seat":t.logicalId,className:b,children:y}):e.jsx("div",{"data-seat":t.logicalId,className:b,children:y})}function ly({graph:t,rig:n,status:s,sessions:a,near:r,added:l,onSeat:o,wide:c=!1}){var g;const i=vg(t.seats,t.links),x=t.seats.find(h=>h.logicalId===i),d=kg(t.seats.filter(h=>h.logicalId!==i),t.pods),m=(x==null?void 0:x.runtime)??((g=t.seats[0])==null?void 0:g.runtime),p=(h,N=!1)=>{var M;const k=kd(a,n.name,h.logicalId),C=wl({session:k,node:n.nodes.find(S=>S.logicalId===h.logicalId),graph:h,rigStatus:s}),j=((M=t.pods.find(S=>S.id===h.pod))==null?void 0:M.label)??h.pod,y=o?()=>o(h.logicalId):void 0,b=c&&k?()=>os({name:"thread",sessionId:k.id}):void 0;return e.jsx(Tu,{seat:h,state:C,pod:j,top:N,near:r,isNew:l.includes(h.logicalId),tag:N||h.runtime!==m,pulse:C==="starting"||s==="starting"&&C==="work",onOpen:b??y,onMore:b?y:void 0},h.logicalId)};return e.jsxs("div",{className:"flex flex-col items-center",children:[x&&e.jsxs(e.Fragment,{children:[p(x,!0),e.jsx("span",{"aria-hidden":"true",className:"h-3 w-[1.5px] bg-input"})]}),e.jsx("div",{className:`grid w-full gap-2 ${d.length>=3?"grid-cols-3":d.length===1&&!x?"grid-cols-1":"grid-cols-2"}`,children:d.map(h=>e.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5 rounded-[10px] border border-dashed border-input p-1.5",children:[e.jsx("small",{className:"px-0.5 font-mono text-[10.5px] text-muted",children:h.label}),h.seats.map(N=>p(N))]},h.id))})]})}function oy({row:t,mine:n}){const s=[[xe.queue.from,`${Un(t.from)} → ${Un(t.to)}`],...t.blockedOn?[[xe.queue.blockedOn,t.blockedOn]]:[],[xe.queue.created,[Ke(vn(t.createdAt)),t.claimedAt?xe.queue.claimed(Ke(vn(t.claimedAt))):""].filter(Boolean).join(" · ")]];return e.jsxs("div",{className:"flex flex-col gap-2 border-b border-line bg-raised/40 px-3 py-2.5 last:border-b-0",children:[e.jsx("span",{className:"font-mono text-[12px] text-muted",children:t.id}),t.summary&&e.jsx("b",{className:"text-[14px] font-semibold",children:t.summary}),e.jsx("dl",{className:"m-0 grid grid-cols-[90px_1fr] gap-x-3 gap-y-1 text-[13px]",children:s.map(([a,r])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted",children:a}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:r})]},a))}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:xe.queue.readOnly}),n&&e.jsx("a",{href:ce({name:"ask",id:t.id}),className:be({size:"sm",className:"self-start"}),children:xe.queue.seeAsk})]})}function iy({read:t,asks:n,now:s,retry:a}){const[r,l]=f.useState(null),[o,c]=f.useState(!1),i=t==null?void 0:t.data;if(!i)return e.jsx(Ve,{children:t!=null&&t.error?e.jsx(Ln,{retry:a,retryLabel:xe.unavailable.retry,children:xe.queue.unavailable}):e.jsx("p",{role:"status",className:"p-3 text-[13px] text-muted",children:xe.loading})});const x={done:e.jsx("span",{className:"text-ok",children:"✓"}),handed:e.jsx("span",{className:"text-muted",children:"↪"}),stopped:e.jsx("span",{className:"text-approval",children:"✕"})};return e.jsxs(e.Fragment,{children:[e.jsx(It,{children:xe.queue.title(i.rows.length)}),e.jsxs(Ve,{children:[i.rows.length===0&&e.jsx("p",{className:"p-3 text-[13px] text-muted",children:xe.queue.none}),i.rows.map(d=>{const m=$g(d,n),p=r===d.id;return e.jsxs("div",{className:"contents",children:[e.jsxs("button",{type:"button","aria-expanded":p,onClick:()=>l(p?null:d.id),className:"flex min-h-[46px] w-full items-center gap-[9px] border-b border-line px-3 py-1.5 text-left text-[13px] last:border-b-0",children:[e.jsx(ry,{tone:m}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate",children:d.summary??d.id}),e.jsx("small",{className:"truncate text-[11.5px] text-muted",children:[`${Un(d.from)} → ${Un(d.to)}`,d.needsInput?xe.queue.prompt:""].filter(Boolean).join(" · ")})]}),e.jsx("span",{className:"font-mono text-[11px] whitespace-nowrap text-muted",children:fa(vn(d.updatedAt),s)})]}),p&&e.jsx(oy,{row:d,mine:m==="mine"})]},d.id)}),i.closed.length>0&&e.jsxs("button",{type:"button","aria-expanded":o,onClick:()=>c(!o),className:"flex min-h-[46px] w-full items-center gap-[9px] border-t border-line px-3 text-left text-[13px] text-muted first:border-t-0",children:[e.jsx(z,{name:"chevron",className:`size-3.5 transition-transform ${o?"rotate-90":""}`}),e.jsx("span",{children:xe.queue.closed(i.closed.length)})]}),o&&i.closed.map(d=>{const m=Mg(d.state);return e.jsxs("div",{className:"flex min-h-[46px] items-center gap-[9px] border-t border-line px-3 py-1.5 text-[13px] text-muted",children:[e.jsx("span",{"aria-hidden":"true",children:x[m]}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate text-fg",children:d.summary??d.id}),e.jsx("small",{className:"truncate text-[11.5px]",children:`${Un(d.from)} → ${Un(d.to)} · ${xe.queue.closedTone[m]}`})]}),e.jsx("span",{className:"font-mono text-[11px]",children:Ke(vn(d.updatedAt))})]},d.id)})]}),i.truncated&&e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:xe.queue.truncated})]})}function cy({rig:t,sessions:n,asks:s}){var h;const a=n.filter(N=>{var k;return((k=N.rig)==null?void 0:k.name)===t}),r=kn(a),l=r.find(N=>N.filter==="permission")??r[0],o=l?a.find(N=>N.id===l.sessionId):void 0,c=l||s==null?void 0:s.find(N=>N.from.rig===t&&N.kind!=="update");if(!l&&!c)return null;const i=o?(h=o.rig)!=null&&h.role?pn(o.rig.role):o.name:c?Un(c.from.seat):"",x=(l==null?void 0:l.filter)==="permission",[d,m,p]=x?xe.waits.permission(i):xe.waits.question(i),g=ce(l?{name:"request",sessionId:l.sessionId,key:l.key}:{name:"sessions"});return e.jsx(Wt,{warn:!x,danger:x,compact:!0,lead:e.jsx(Pe,{state:x?"perm":"ask"}),action:e.jsx("a",{href:g,className:be({size:"xs"}),children:xe.waits.see}),children:e.jsxs("span",{children:[d,e.jsx("b",{className:"font-semibold",children:m}),p]})})}function dy({rig:t,rigs:n,store:s}){var kt,ct,xt,G,Ee,we;const a=bs(n),r=me(s),{pc:l,look:o}=zt(),c=Dt(),[i,x]=f.useState(null),[d,m]=f.useState("last"),p=r.fresh,g=o==="offline",[h,N]=f.useState(()=>Date.now());f.useEffect(()=>{const le=setInterval(()=>N(Date.now()),3e4);return()=>clearInterval(le)},[]),f.useEffect(()=>{n.follow(),p&&(n.openRig(t),n.readSnapshots(t))},[n,t,p]);const k=Jt(l),C=a.state,j=C==null?void 0:C.rigs.find(le=>le.name===t),y=a.graphs[t],b=a.permissions[t],M=a.snapshots[t],S=a.queues[t],$=[...r.sessions.values()],v=((kt=r.device)==null?void 0:kt.contextNear)??70,A=!!((ct=r.device)!=null&&ct.confirm),R=Dl(a.runs,le=>Tg(le.subject)===t),_=Ya(R),L=le=>{n.act(le)},T=(le,ge)=>{n.reseat(t,le,ge?{delegation:ge}:{})},B=()=>x(null),E=()=>n.openRig(t),P=e.jsx("button",{type:"button","aria-label":xe.more,title:xe.more,"aria-haspopup":"menu",onClick:()=>x({kind:"more"}),className:Ot(),children:e.jsx(z,{name:"more"})}),W=(le,ge,Be)=>c?e.jsxs("header",{className:"pane-head flex h-[58px] flex-none items-center gap-2 border-b border-line pr-1.5",children:[e.jsx(Zt,{fallback:{name:"rigs"},label:xe.back}),e.jsx("h1",{className:"min-w-0 truncate text-[17px] font-semibold",children:t}),le,ge&&e.jsx("span",{className:"min-w-0 truncate text-[12.5px] text-muted",children:ge}),e.jsx("span",{className:"flex-1"}),Be,j&&P]}):e.jsxs("header",{className:"flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-0.5",children:[e.jsx(Zt,{fallback:{name:"rigs"},label:xe.back}),e.jsx("h1",{className:"min-w-0 truncate text-base font-semibold",children:t}),le,e.jsx("span",{className:"flex-1"}),j&&P]}),F=`tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pb-[18px] ${c?"pt-[18px]":"pt-3"}`;if(!!C&&(!j||(y==null?void 0:y.error)==="unknown_rig"||(S==null?void 0:S.error)==="unknown_rig"))return e.jsxs(e.Fragment,{children:[W(null),e.jsx("main",{"data-tab-scroll":"",className:F,children:e.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-10 text-center",children:[e.jsx("h2",{className:"text-[17px] font-semibold",children:xe.readError.unknown_rig}),e.jsx("a",{href:ce({name:"rigs"}),className:be({size:"sm",className:"mt-1.5"}),children:xe.back})]})})]});if(!j){const le=a.error?xe.readError[a.error]:null;return e.jsxs(e.Fragment,{children:[W(null),e.jsxs("main",{"data-tab-scroll":"",className:F,children:[e.jsx(wn,{body:xe.offlineBody}),le?e.jsx(Wt,{warn:!0,role:"alert",lead:e.jsx(z,{name:"warning",className:"mt-px size-4 text-attention"}),children:e.jsx("b",{className:"font-semibold",children:le})}):e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:xe.loading})]})]})}const Y=mn(j),H=Y==="stopped",I=b!=null&&b.data?$d(b.data.seats):null,D=I?xe.level[I]:null,Q=Td((M==null?void 0:M.data)??[])[0],q=Q?Ma(Q.createdAt).short:j.snapshot||"",K=(R==null?void 0:R.phase)==="done"&&((xt=R.reseated)!=null&&xt.ok)?R.reseated.added:[],ee=j.nodes.filter(le=>le.stopped).map(le=>pn(le.logicalId,le.session)),ue=le=>{var ge;return(ge=y==null?void 0:y.data)==null?void 0:ge.seats.find(Be=>Be.logicalId===le)},fe=()=>{var le;return L(d==="fresh"?{kind:"rig.start",rig:t,fresh:((le=y==null?void 0:y.data)==null?void 0:le.seats.map(ge=>ge.logicalId))??j.nodes.map(ge=>ge.logicalId)}:{kind:"rig.start",rig:t})},he=R&&!_?R:void 0,w=p&&!_,O=c?"sm":"md",V=c?"":"!h-[42px] !px-2 !text-[13.5px]",Z=e.jsx("button",{type:"button",disabled:!w,onClick:fe,className:be({tone:"primary",size:O,className:c?"":"!h-[42px]"}),children:e.jsx(Ft,{icon:"power",children:xe.actions.start})}),X=e.jsx("button",{type:"button",disabled:!w,onClick:()=>x({kind:"restart"}),className:be({size:O,className:V}),children:e.jsx(Ft,{icon:"refresh",children:xe.actions.restart})}),J=e.jsx("button",{type:"button",disabled:!w,onClick:()=>x({kind:"stop"}),className:be({tone:"danger",size:O,className:V}),children:e.jsx(Ft,{icon:"power",children:xe.actions.stop})}),pe=e.jsx("button",{type:"button",disabled:!w,onClick:()=>x({kind:"reseat"}),className:be({size:O,className:V}),children:e.jsx(Ft,{icon:"plus",children:xe.actions.seats})}),Ne=_?e.jsx(Ca,{run:R,rigs:n,pc:k,bar:!c}):Y==="starting"?e.jsx(Ls,{bar:!c,children:xe.startingSeats(t,j.running,j.seats)}):null,Xe=Ne??e.jsx("div",{className:`bleed grid flex-none gap-2 border-t border-line bg-bg px-3.5 pt-2.5 pb-3 ${H?"grid-cols-1":"grid-cols-3"}`,children:H?Z:e.jsxs(e.Fragment,{children:[pe,X,J]})}),gt=p&&e.jsx(cy,{rig:t,sessions:$,asks:r.asks}),ze=Y==="partial"&&ee.length>0&&e.jsxs(Wt,{warn:!0,lead:e.jsx(z,{name:"warning",className:"mt-px size-4 text-attention"}),children:[e.jsx("span",{children:xe.partial(ee,j.nodes.length-ee.length)}),e.jsx("button",{type:"button",disabled:!w,onClick:()=>x({kind:"restart"}),className:be({size:"sm",className:"self-start"}),children:xe.actions.restartRig})]}),Je=e.jsxs(e.Fragment,{children:[e.jsx(It,{aside:H?xe.topologyStopped:y!=null&&y.data?xe.topologyHint:void 0,children:xe.topology}),y!=null&&y.data?e.jsx(ly,{graph:y.data,rig:j,status:Y,sessions:$,near:v,added:K,onSeat:le=>x({kind:"seat",id:le}),wide:c}):e.jsx(Ve,{children:y!=null&&y.error?e.jsx(Ln,{retry:E,retryLabel:xe.unavailable.retry,children:xe.readError[y.error]}):e.jsx("p",{role:"status",className:"p-3 text-[13px] text-muted",children:xe.loading})})]}),oe=H&&j.snapshot&&e.jsxs(e.Fragment,{children:[e.jsx(It,{children:xe.resume}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(Hr,{pressed:d==="last",disabled:!p,onClick:()=>m("last"),title:xe.resumeLast(Q?Ma(Q.createdAt).long:j.snapshot),sub:xe.resumeLastBody}),e.jsx(Hr,{pressed:d==="fresh",disabled:!p,onClick:()=>m("fresh"),title:xe.fresh,sub:xe.freshBody})]})]}),de=e.jsx(iy,{read:S,asks:r.asks,now:h,retry:E}),ke=c?e.jsxs("div",{className:"grid grid-cols-[minmax(0,1.15fr)_minmax(0,1fr)] content-start gap-[18px]",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-3.5",children:[gt,ze,Je,!H&&Y!=="starting"&&e.jsxs(e.Fragment,{children:[e.jsx(It,{children:xe.seatsByRole}),e.jsx(Ve,{children:e.jsx("div",{className:"flex flex-col gap-2.5 px-3 py-1",children:e.jsx(_u,{rig:j,confirm:A,live:w,onReseat:T,context:Object.fromEntries((((G=y==null?void 0:y.data)==null?void 0:G.seats)??[]).map(le=>[le.logicalId,le.context]))},j.nodes.length)})})]}),oe]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3.5",children:[de,e.jsx(It,{children:xe.actions.snapshots}),e.jsx(Ru,{read:M,kindOnly:!0,retry:()=>n.readSnapshots(t)}),e.jsx("button",{type:"button",disabled:!w,onClick:()=>L({kind:"rig.snapshot",rig:t}),className:be({size:"sm",className:"max-w-full self-start !h-auto min-h-9 py-1.5 !whitespace-normal text-left [&>svg]:flex-none"}),children:e.jsx(Ft,{icon:"camera",children:xe.snapshots.take})})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx(pr,{label:xe.tiles.seats,value:`${j.running}/${j.seats}`}),e.jsx(pr,{label:xe.tiles.permissions,value:D??"—",onOpen:()=>x({kind:"permissions"})}),e.jsx(pr,{label:xe.tiles.snapshot,value:q||"—",onOpen:()=>x({kind:"snapshots"})})]}),gt,ze,Je,de,oe]}),Oe=(i==null?void 0:i.kind)==="seat"||(i==null?void 0:i.kind)==="settings"?ue(i.id):void 0,lt=Oe?j.nodes.find(le=>le.logicalId===Oe.logicalId):void 0,mt=[xe.seats(j.running,j.seats),D??"",q?xe.snapshot(q):""].filter(Boolean).join(" · ");return e.jsxs(e.Fragment,{children:[W(e.jsx(ds,{tone:Rd[Y],children:xe.status[Y]}),mt,!Ne&&(H?Z:e.jsxs(e.Fragment,{children:[X,J]}))),e.jsxs("main",{"data-tab-scroll":"",className:F,children:[e.jsx(wn,{body:xe.offlineBody}),c&&Ne,he&&e.jsx(Ca,{run:he,rigs:n,pc:k}),e.jsx("div",{className:`flex flex-col gap-3 ${g?"opacity-50":""}`,children:ke})]}),!c&&Xe,(i==null?void 0:i.kind)==="more"&&e.jsx(X1,{rig:t,live:p,running:_,snapshots:M!=null&&M.data?M.data.length:null,level:D,onClose:B,onSnapshot:()=>{B(),L({kind:"rig.snapshot",rig:t})},onSnapshots:()=>x({kind:"snapshots"}),onPermissions:()=>x({kind:"permissions"}),onRefresh:()=>{B(),n.retry(),n.openRig(t),n.readSnapshots(t)}}),((i==null?void 0:i.kind)==="stop"||(i==null?void 0:i.kind)==="restart")&&e.jsx(Q1,{rig:j,pc:k,verb:i.kind,confirm:A,live:w,onAct:L,onClose:B}),(i==null?void 0:i.kind)==="reseat"&&e.jsx(Z1,{rig:j,pc:k,confirm:A,live:w,onReseat:T,onClose:B}),(i==null?void 0:i.kind)==="permissions"&&e.jsx(J1,{rig:j,read:b,level:I,confirm:A,live:w,onAct:L,onClose:B}),(i==null?void 0:i.kind)==="snapshots"&&e.jsx(sy,{rig:t,read:M,live:p,running:_,onSnapshot:()=>L({kind:"rig.snapshot",rig:t}),onRetry:()=>n.readSnapshots(t),onClose:B}),(i==null?void 0:i.kind)==="seat"&&Oe&&(y==null?void 0:y.data)&&e.jsx(ty,{rig:t,seat:Oe,graph:y.data,node:lt,session:kd($,t,Oe.logicalId),status:Y,near:v,onSettings:()=>x({kind:"settings",id:Oe.logicalId}),onClose:B}),(i==null?void 0:i.kind)==="settings"&&Oe&&e.jsx(ny,{rig:t,seat:Oe,node:lt,selection:(we=(Ee=b==null?void 0:b.data)==null?void 0:Ee.seats.find(le=>le.logicalId===Oe.logicalId))==null?void 0:we.selection,confirm:A,live:w,onAct:L,onClose:B})]})}const dn=u.rigs,ve=dn.max,uy={sent:"idle",taken:"work",asking:"ask",proposed:"rig",running:"work",done:"done",closed:"done"},my={sent:"plain",taken:"work",asking:"ask",proposed:"rig",running:"work",done:"ok",closed:"plain"},xy=t=>{var n;return((n=t.trail.at(-1))==null?void 0:n.at)??t.sentAt},Au=t=>{const n=Ea(t);if(!n)return null;for(let s=t.trail.length-1;s>=0;s--)if(t.trail[s].text===n)return t.trail[s].at;return null};function py(t){var s;const n=Ma(xy(t)).short;return t.state==="asking"?`${ve.asks} · ${n}`:t.state==="running"?[ve.state.running,((s=t.current)==null?void 0:s.seat.split("@")[0])??"",ve.since(n)].filter(Boolean).join(" · "):`${ve.state[t.state]} · ${n}`}const Ea=t=>{var n,s;return((n=t.question)==null?void 0:n.text)??((s=t.proposal)==null?void 0:s.text)??null};function fy({run:t,pc:n,onAgain:s,onClose:a}){var c,i;const r={onClose:a,closeLabel:dn.done.close},l=e.jsx("button",{type:"button",onClick:s,className:be({size:"xs",className:"mt-1.5"}),children:ve.sendAgain}),o=t.phase==="uncertain"?"uncertain":t.phase==="done"?(c=t.sent)==null?void 0:c.error:void 0;return o?o==="uncertain"?e.jsx($e,{mark:"ask",title:ve.errors.uncertain.title,sub:ve.errors.uncertain.body,...r,children:l}):o==="refused"?e.jsx($e,{mark:"bad",title:ve.errors.refused.title,...(i=t.sent)!=null&&i.message?{sub:e.jsx("span",{className:"font-mono",children:t.sent.message})}:{},...r}):o==="openrig_stopped"?e.jsx($e,{mark:"bad",title:ve.errors.openrig_stopped.title(n),sub:ve.errors.openrig_stopped.body,...r,children:l}):o==="no_operator"||o==="unreachable"?e.jsx($e,{mark:"bad",title:ve.errors[o].title,sub:ve.errors[o].body,...r,children:l}):e.jsx($e,{mark:"bad",title:ve.unsent,sub:ve.keeps,...r,children:l}):e.jsx($e,{mark:"bad",title:ve.unsent,sub:ve.keeps,...r,children:l})}const hy=t=>{var n;return t.phase==="done"&&!!((n=t.sent)!=null&&n.ok)};function Iu({runs:t,rigs:n,pc:s,bubble:a}){return e.jsx(e.Fragment,{children:t.filter(r=>!hy(r)).map(r=>{const l=r.subject;if(l.kind!=="goal"&&l.kind!=="reply")return null;if(Ya(r))return e.jsxs("div",{role:"status","aria-label":ve.sending,className:"max-w-[85%] self-end rounded-[14px] rounded-br-[5px] bg-secondary px-3 py-2 text-[14px] leading-5 opacity-60",children:[l.text," ",e.jsx(gs,{className:"ml-1 align-[-1px] text-muted"})]},r.id);const o=()=>{n.dismiss(r.id),l.kind==="goal"?n.sendGoal(l.text,l.goalId):n.replyGoal(l.goalId,l.text,l.replyId)};return e.jsx(fy,{run:r,pc:s,onAgain:o,onClose:()=>n.dismiss(r.id)},r.id)})})}function gy(t){var n;switch(t.kind){case"sent":return ve.trail.sent;case"taken":return ve.trail.taken;case"note":return ve.trail.note(t.text??"");case"handed":return ve.trail.handed(((n=t.to)==null?void 0:n.split("@")[0])??"");case"closed":return ve.trail.closed}}function Lu({goal:t,runs:n,rigs:s,pc:a,compact:r=!1,asks:l=null}){const o=Ea(t),c=Au(t),i=t.question??(t.proposal&&!t.proposal.answer?t.proposal:null),x=n.filter(d=>d.subject.kind==="reply"&&d.subject.goalId===t.goalId);return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("div",{className:"max-w-[85%] self-end rounded-[14px] rounded-br-[5px] bg-secondary px-3 py-2 text-[14px] leading-5 [overflow-wrap:anywhere]",children:t.text}),!r&&t.trail.some(d=>d.kind!=="sent")&&e.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0 text-[12.5px] text-muted",children:t.trail.filter(d=>d.kind!=="sent").map((d,m)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"font-mono text-[11.5px]",children:Ke(vn(d.at))}),e.jsx("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:gy(d)})]},`${d.at}-${m}`))}),o&&e.jsxs("div",{className:"flex flex-col gap-1 text-[13.5px] leading-[19px]",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-[12px] text-muted",children:[e.jsx(Pe,{state:"idle"}),c?`${dn.kernelView.max} · ${Ke(vn(c))}`:dn.kernelView.max]}),e.jsx("span",{className:"[overflow-wrap:anywhere]",children:o})]}),i&&e.jsxs("div",{className:"flex flex-col gap-2 rounded-[10px] border border-attention/45 bg-surface px-3 py-2.5",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Pe,{state:"ask"}),e.jsx("b",{className:"text-[14px] font-semibold",children:t.question?ve.question:ve.proposal}),c&&e.jsx("span",{className:"ml-auto font-mono text-[11.5px] text-muted",children:Ke(vn(c))})]}),!r&&e.jsx("p",{className:"text-[13px] text-muted",children:t.question?ve.questionBody:ve.proposalBody}),e.jsx("a",{href:l!=null&&l.some(d=>d.id===i.askId)?ce({name:"ask",id:i.askId}):ce({name:"rigs"}),className:be({size:"sm",className:"self-start"}),children:ve.seeAsk})]}),e.jsx(Iu,{runs:x,rigs:s,pc:a,bubble:!0})]})}function Ou({goalId:t,rigs:n,live:s}){const[a,r]=f.useState("");return e.jsx(ac,{label:ve.replyPlaceholder,sendLabel:ve.send,placeholder:ve.replyPlaceholder,offlinePlaceholder:ve.offlinePlaceholder,offline:!s,value:a,onChange:r,onSend:()=>{const l=a.trim();l&&(r(""),n.replyGoal(t,l).then(o=>{o.phase==="unsent"&&r(c=>c||l)}))}})}function by({goalId:t,rigs:n,store:s}){var S,$,v,A;const a=bs(n),r=me(s),{pc:l,look:o}=zt(),c=Dt(),i=r.fresh,x=o==="offline",d=Jt(l),[m,p]=f.useState("");f.useEffect(()=>{n.follow(),n.followGoals()},[n,i]);const g=(($=(S=a.goals)==null?void 0:S.data)==null?void 0:$.goals)??[],h=t?g.find(R=>R.goalId===t):void 0,N=`tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pb-[18px] ${c?"pt-[18px]":"pt-3"}`,k=c?"pane-head flex h-[58px] flex-none items-center gap-2 border-b border-line pr-2":"flex h-14 flex-none items-center gap-2 border-b border-line pr-2 pl-0.5",C="bleed flex-none border-t border-line bg-bg px-3.5 pt-2.5 pb-3",j=(()=>{var R,_;return(R=a.goals)!=null&&R.error&&!a.goals.data?e.jsx(Ve,{children:e.jsx(Ln,{retry:()=>n.followGoals(),retryLabel:dn.unavailable.retry,children:ve.goalsUnavailable})}):(_=a.goals)!=null&&_.data?null:e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:dn.loading})})();if(t)return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:k,children:[e.jsx(Zt,{fallback:{name:"max"},label:dn.backMax}),e.jsx("h1",{className:"min-w-0 truncate text-base font-semibold",children:(h==null?void 0:h.text)??ve.title}),h&&e.jsx("span",{className:"flex-none",children:e.jsx(Lt,{tone:my[h.state],children:ve.statePill[h.state]})})]}),e.jsxs("main",{"data-tab-scroll":"",className:`${N} justify-end`,children:[e.jsx(wn,{body:dn.offlineBody}),h?e.jsx("div",{className:x?"opacity-50":"",children:e.jsx(Lu,{goal:h,runs:a.runs,rigs:n,pc:d,asks:r.asks})}):j??e.jsx("p",{role:"alert",className:"text-[13px] text-attention",children:ve.goalsUnavailable})]}),h&&e.jsx("div",{className:C,children:e.jsx(Ou,{goalId:h.goalId,rigs:n,live:i})})]});const y=a.runs.filter(R=>R.subject.kind==="goal"),b=()=>{const R=m.trim();R&&(p(""),n.sendGoal(R).then(_=>{_.phase==="unsent"&&p(L=>L||R)}))},M=()=>{var R;(R=document.querySelector("[data-goal-field] textarea"))==null||R.focus()};return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:k,children:[e.jsx(Zt,{fallback:{name:"kernel"},label:dn.backKernel}),e.jsx("h1",{className:"flex-none text-base font-semibold",children:ve.title}),e.jsx("span",{className:"min-w-0 truncate text-[12.5px] text-muted",children:ve.role}),e.jsx("span",{className:"flex-1"}),e.jsx("button",{type:"button",disabled:!i,onClick:M,className:be({tone:"primary",size:"sm"}),children:e.jsx(Ft,{icon:"plus",children:ve.newGoal})})]}),e.jsxs("main",{"data-tab-scroll":"",className:N,children:[e.jsx(wn,{body:dn.offlineBody}),e.jsxs("div",{className:`flex flex-col gap-3 ${x?"opacity-50":""}`,children:[j??(g.length===0?e.jsx(Ve,{children:e.jsx(Ln,{children:ve.none})}):e.jsx(Ve,{label:ve.goalsLabel,children:g.map(R=>e.jsxs("a",{href:ce({name:"max",goalId:R.goalId}),className:"flex items-start gap-2.5 border-b border-line px-3 py-2.5 last:border-b-0",children:[e.jsx("span",{className:"mt-1.5",children:e.jsx(Pe,{state:uy[R.state],pulse:R.state==="running"})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsx("span",{className:"line-clamp-2 text-[14px] leading-5 [overflow-wrap:anywhere]",children:R.text}),e.jsx("small",{className:`text-[12px] ${R.state==="asking"?"text-attention":"text-muted"}`,children:py(R)})]})]},R.goalId))})),((A=(v=a.goals)==null?void 0:v.data)==null?void 0:A.partial)&&e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:ve.partial}),e.jsx(Iu,{runs:y,rigs:n,pc:d,bubble:!1}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:ve.requestsNote})]})]}),e.jsx("div",{"data-goal-field":"",className:C,children:e.jsx(ac,{label:ve.goalPlaceholder,sendLabel:ve.send,placeholder:ve.goalPlaceholder,offlinePlaceholder:ve.offlinePlaceholder,offline:!i,value:m,onChange:p,onSend:b})})]})}const Ae=u.rigs,jt=Ae.kernelView,jy=t=>/^qitem-\d{14}-[0-9a-f]{8,}$/.test(t)?`…${t.slice(-8)}`:t;function yy({graph:t,status:n,near:s}){var i;const a=t.seats,r=a.find(x=>Ed(x.logicalId)),l=a.filter(x=>x!==r),o=(r==null?void 0:r.runtime)??((i=a[0])==null?void 0:i.runtime),c=(x,d=!1)=>{var h;const m=wl({graph:x,rigStatus:n}),p=((h=t.pods.find(N=>N.id===x.pod))==null?void 0:h.label)??x.pod,g=[d?p:"",m==="idle"?"":Ae.seatState[m]].filter(Boolean).join(" · ");return e.jsx(Tu,{seat:x,state:m,pod:p,top:d,near:s,isNew:!1,name:_d({logicalId:x.logicalId,session:x.session??""}),words:g,tag:d||x.runtime!==o,pulse:m==="starting"},x.logicalId)};return e.jsxs("div",{className:"flex flex-col items-center",children:[r&&e.jsxs(e.Fragment,{children:[c(r,!0),e.jsx("span",{"aria-hidden":"true",className:"h-3 w-[1.5px] bg-input"})]}),e.jsx("div",{className:"grid w-full max-w-[420px] grid-cols-2 gap-2",children:l.map(x=>c(x))})]})}function Ny({rigs:t}){const n=bs(t).routing,s=n!=null&&n.data?[...n.data].reverse():null,a=r=>{const l=Eg(r);return l.verb==="handed"?jt.change.handed(l.to):l.verb==="blocked"?jt.change.blocked(jy(l.on)):l.verb==="other"?l.text:jt.change[l.verb]};return e.jsxs(e.Fragment,{children:[e.jsx(It,{aside:jt.allRigs,children:jt.routing}),e.jsx(Ve,{children:s?s.length===0?e.jsx(Ln,{children:jt.noRouting}):s.map((r,l)=>e.jsxs("div",{className:"grid grid-cols-[44px_1fr] gap-x-2 border-b border-line px-3 py-2 text-[13px] leading-[18px] last:border-b-0",children:[e.jsx("span",{className:"font-mono text-[11.5px] text-muted",children:Ke(vn(r.at))}),e.jsxs("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:[e.jsx("b",{className:"font-semibold",children:jt.actor(r.seat.split("@")[0]??r.seat)})," ",a(r.change)]}),e.jsx("small",{className:"col-start-2 truncate text-[11.5px] text-muted",children:[r.rig,r.summary??""].filter(Boolean).join(" · ")})]},`${r.qitem}-${r.at}-${l}`)):n!=null&&n.error?e.jsx(Ln,{retry:()=>t.readRouting(),retryLabel:Ae.unavailable.retry,children:Ae.readError[n.error]}):e.jsx("p",{role:"status",className:"p-3 text-[13px] text-muted",children:Ae.loading})})]})}function ky({rigs:t,store:n}){var O,V,Z,X;const s=bs(t),a=me(n),{pc:r,look:l}=zt(),o=Dt(),[c]=Ll(),[i,x]=f.useState(null),d=a.fresh,m=l==="offline";f.useEffect(()=>{t.follow(),t.followGoals(),d&&(t.openRig($s),t.readRouting())},[t,d]);const p=s.state?Br(s.state).filter(J=>mn(J)!=="stopped").map(J=>J.name).join(" "):"";f.useEffect(()=>{if(d&&p)for(const J of p.split(" "))t.readPermissions(J)},[t,d,p]);const g=Jt(r),h=s.state,N=`tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pb-[18px] ${o?"pt-[18px]":"pt-3"}`,k=J=>e.jsxs("header",{className:o?"pane-head flex h-[58px] flex-none items-center gap-2 border-b border-line pr-1.5":"flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-0.5",children:[e.jsx(Zt,{fallback:{name:"rigs"},label:Ae.back}),e.jsx("h1",{className:`min-w-0 truncate font-semibold ${o?"text-[17px]":"text-base"}`,children:Ae.kernel}),J,e.jsx("span",{className:"flex-1"}),J&&e.jsx("button",{type:"button","aria-label":Ae.more,title:Ae.more,"aria-haspopup":"menu",onClick:()=>x("menu"),className:Ot(),children:e.jsx(z,{name:"more"})})]}),C=()=>{t.retry(),t.openRig($s),t.readRouting()};if(!h){const J=s.error?Ae.readError[s.error]:null;return e.jsxs(e.Fragment,{children:[k(null),e.jsxs("main",{"data-tab-scroll":"",className:N,children:[e.jsx(wn,{body:Ae.offlineBody}),J?e.jsx(Wt,{warn:!0,role:"alert",lead:e.jsx(z,{name:"warning",className:"mt-px size-4 text-attention"}),children:e.jsx("b",{className:"font-semibold",children:J})}):e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:Ae.loading})]})]})}const j=Nd(h),y=h.kernel.state,b=j?mn(j):"stopped",M=s.graphs[$s],S=((O=a.device)==null?void 0:O.contextNear)??70,$=!!((V=a.device)!=null&&V.confirm),v=Dl(s.runs,J=>J.subject.kind==="act"&&/^(kernel|daemon)\./.test(J.subject.action.kind)),A=Ya(v),R=d&&!A,_=J=>{t.act(J)},L=[...a.sessions.values()],T=Br(h),B=h.daemon.state==="running",E=y==="ready"||y==="starting",P=((X=(Z=s.goals)==null?void 0:Z.data)==null?void 0:X.goals)??[],W=y==="stopped"?e.jsxs(Wt,{lead:e.jsx("span",{className:"mt-[5px]",children:e.jsx(Pe,{state:"off"})}),children:[e.jsx("span",{children:e.jsx("b",{className:"font-semibold",children:jt.stoppedTitle})}),e.jsx("span",{className:"text-muted",children:jt.stoppedBody}),e.jsx("button",{type:"button",disabled:!R||!B,onClick:()=>_({kind:"kernel.start"}),className:be({tone:"primary",size:"sm",className:"self-start"}),children:e.jsx(Ft,{icon:"power",children:jt.startKernel})})]}):y==="skipped"?e.jsxs(Wt,{lead:e.jsx("span",{className:"mt-[5px]",children:e.jsx(Pe,{state:"off"})}),children:[e.jsx("span",{children:e.jsx("b",{className:"font-semibold",children:jt.skippedTitle})}),e.jsx("span",{className:"text-muted",children:jt.skippedBody})]}):null,F=P.find(J=>Ea(J)!==null),re=F?Au(F):null,Y=P.find(J=>J.state!=="done"&&J.state!=="closed"),H=e.jsx("a",{href:ce({name:"max"}),className:be({tone:"primary",className:"w-full"}),children:jt.talk}),I=o&&Y?e.jsxs(e.Fragment,{children:[e.jsx(It,{children:`${jt.max} · ${Y.text}`}),e.jsx(Ve,{children:e.jsxs("div",{className:"flex flex-col gap-2.5 p-3",children:[e.jsx(Lu,{goal:Y,runs:s.runs,rigs:t,pc:g,compact:!0,asks:a.asks}),e.jsx(Ou,{goalId:Y.goalId,rigs:t,live:d})]})})]}):e.jsx(Ve,{children:e.jsxs("div",{className:"flex flex-col gap-2 p-3",children:[F&&e.jsx("span",{className:"text-[12px] text-muted",children:jt.lastMessage(re?Ke(vn(re)):null)}),F&&e.jsx("span",{className:"text-[13.5px] leading-[19px] [overflow-wrap:anywhere]",children:Ea(F)}),H]})}),D=J=>{var Xe;const pe=(Xe=s.permissions[J])==null?void 0:Xe.data,Ne=pe?$d(pe.seats):null;return Ne?Ae.level[Ne]:""},Q=T.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(It,{children:jt.driven}),e.jsx(Ve,{children:T.map(J=>{const pe=mn(J),Ne=wd(J,vd(J.name,L,a.asks));return e.jsxs("a",{href:ce({name:"rig",rig:J.name}),className:"flex min-h-[46px] items-center gap-2.5 border-b border-line px-3 py-1.5 text-[13.5px] last:border-b-0",children:[e.jsx(Pe,{state:Ne}),e.jsx("span",{className:`min-w-0 flex-1 truncate ${pe==="stopped"?"text-muted":""}`,children:J.name}),e.jsx("span",{className:"text-[12px] text-muted",children:pe==="stopped"?Ae.seatState.off:[Ae.seatCount(J.seats),D(J.name)].filter(Boolean).join(" · ")}),e.jsx(z,{name:"chevron",className:"size-4 text-muted"})]},J.id)})})]}),q=(J,pe)=>e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{type:"button",disabled:!R,onClick:J,className:be({}),children:e.jsx(Ft,{icon:"refresh",children:Ae.actions.restart})}),e.jsx("button",{type:"button",disabled:!R,onClick:pe,className:be({tone:"danger"}),children:e.jsx(Ft,{icon:"power",children:Ae.actions.stop})})]}),K=E&&e.jsxs(e.Fragment,{children:[e.jsx(It,{children:Ae.kernel}),e.jsx(Ve,{children:e.jsxs("div",{className:"flex flex-col gap-2 p-3",children:[e.jsx("span",{className:"text-[12.5px] leading-[18px] text-muted",children:Ae.confirm.kernelNote}),q(()=>x("kernel.restart"),()=>x("kernel.stop"))]})})]}),ee=e.jsxs(e.Fragment,{children:[e.jsx(It,{children:Ae.daemon}),e.jsxs(Ve,{children:[e.jsx(Fl,{state:h}),e.jsx(Eu,{disabled:!d,next:!0}),B&&e.jsx("div",{className:"px-3 pt-2.5 pb-3",children:q(()=>x("daemon.restart"),()=>x("daemon.stop"))})]}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:jt.daemonNote})]}),ue=T.flatMap(J=>Ig(J)).length,fe=T.filter(J=>mn(J)!=="stopped").length,he=[Ae.confirm.daemonStops(fe),ue?Ae.confirm.working(ue):""].filter(Boolean).join(" "),w=()=>x(null);return e.jsxs(e.Fragment,{children:[k(e.jsx(ds,{tone:Mu[y],children:Ae.kernelState[y]})),e.jsxs("main",{"data-tab-scroll":"",className:N,children:[e.jsx(wn,{body:Ae.offlineBody}),v&&e.jsx(Ca,{run:v,rigs:t,pc:g}),e.jsxs("div",{className:`flex flex-col gap-3 ${o?"max-w-[720px]":""} ${m?"opacity-50":""}`,children:[W,e.jsx("p",{className:"text-[12.5px] leading-[18px] text-muted",children:jt.role}),E&&(M!=null&&M.data?e.jsx(yy,{graph:M.data,status:b,near:S}):e.jsx(Ve,{children:e.jsx("p",{role:M!=null&&M.error?"alert":"status",className:"p-3 text-[13px] text-muted",children:M!=null&&M.error?Ae.readError[M.error]:Ae.loading})})),E&&I,Q,e.jsx(Ny,{rigs:t}),K,ee]})]}),i==="menu"&&e.jsx(Y1,{live:d,up:E&&!A,onClose:w,onRefresh:()=>{w(),C()},onRestart:()=>x("kernel.restart"),onStop:()=>x("kernel.stop")}),i==="kernel.restart"&&e.jsx(aa,{title:Ae.confirm.restartKernel(g),conseq:{title:Ae.confirm.kernelNote},verb:Ae.actions.restart,confirm:$,live:R,onConfirm:()=>_({kind:"kernel.restart"}),onClose:w}),i==="kernel.stop"&&e.jsx(aa,{title:Ae.confirm.stopKernel(g),conseq:{title:Ae.confirm.kernelNote},verb:Ae.actions.stop,confirm:$,live:R,onConfirm:()=>_({kind:"kernel.stop"}),onClose:w}),i==="daemon.restart"&&e.jsx(aa,{title:Ae.confirm.restartDaemon(g),conseq:{title:he},verb:Ae.actions.restart,confirm:$,live:R,onConfirm:()=>_($u("restart",c)),onClose:w}),i==="daemon.stop"&&e.jsx(aa,{title:Ae.confirm.stopDaemon(g),conseq:{title:he},verb:Ae.actions.stop,confirm:$,live:R,onConfirm:()=>_({kind:"daemon.stop"}),onClose:w})]})}const ae=u.launch,vy=["claude","codex","cursor","omp"],wy=["always-ask","write","yolo"],Sy=2e4,Bn={project:`${Nn}launch.project`,prefs:`${Nn}launch.prefs`,draft:`${Nn}launch.draft`},Zr=(t,n)=>{try{return(t==null?void 0:t.getItem(n))??null}catch{return null}},ra=(t,n,s)=>{try{s===null?t==null||t.removeItem(n):t==null||t.setItem(n,s)}catch{}};function yi(t){try{const n=JSON.parse(Zr(t,Bn.prefs)??"{}");return n&&typeof n=="object"?n:{}}catch{return{}}}const Ni=t=>t.replace(/\/+$/,"").split("/").pop()||t,Du=t=>t.machine==="local",ki=t=>Du(t)&&t.exists!==!1;function vi({store:t,storage:n}){var Be,et,vt,Vt,tn,Gt,Xt;const s=me(t),a=Ze(n),r=Jt(zt().pc??((Be=s.daemon)==null?void 0:Be.name)??null),l=s.projects,[o,c]=f.useState(()=>Zr(a,Bn.project)),i=l.find(U=>U.id===o)??l[0],x=yi(a),d=i?x[i.id]:void 0,[m,p]=f.useState((d==null?void 0:d.tool)??"claude"),[g,h]=f.useState({model:(d==null?void 0:d.model)??null,effort:(d==null?void 0:d.effort)??null}),[N,k]=f.useState("always-ask"),[C,j]=f.useState(null),[y,b]=f.useState(()=>Zr(a,Bn.draft)??""),[M,S]=f.useState(null),[$,v]=f.useState(!1),[A,R]=f.useState(!1),[_,L]=f.useState(null),[T,B]=f.useState(null),E=f.useId(),[P,W]=f.useState(!1),[F,re]=f.useState(""),Y=f.useId(),H=f.useRef(null),I=f.useRef(!1);f.useEffect(()=>{var U;P&&I.current&&((U=H.current)==null||U.focus())},[P]);const D=i==null?void 0:i.id;f.useEffect(()=>{D&&s.fresh&&t.requestProjectFolders(D)},[D,s.fresh,t]),f.useEffect(()=>{var U;s.fresh&&((U=s.daemon)!=null&&U.models)&&t.requestModels(m)},[m,s.fresh,(et=s.daemon)==null?void 0:et.models,t]);const Q=D?s.projectFolders[D]:void 0,q=Array.isArray(Q)?Q:[],K=q.find(ki),ee=(C??(K?[K.path]:[])).filter(U=>q.some(Se=>Se.path===U&&ki(Se))),ue=Ql.includes(m),fe=((vt=s.models[m])==null?void 0:vt.models)??[],he=U=>{U(),L(null),R(!1)},w=U=>he(()=>{c(U.id),ra(a,Bn.project,U.id),j(null);const Se=x[U.id];p((Se==null?void 0:Se.tool)??"claude"),h({model:(Se==null?void 0:Se.model)??null,effort:(Se==null?void 0:Se.effort)??null}),S(null)}),O=U=>he(()=>{p(U),h({model:null,effort:null}),!Ql.includes(U)&&ee.length>1&&j(ee.slice(0,1))}),V=U=>he(()=>{if(!ue){j([U]),S(null);return}const ie=ee.includes(U)?ee.filter(Ie=>Ie!==U):[...ee,U];j(ie.length?ie:ee)}),Z=U=>{b(U),ra(a,Bn.draft,U),L(null),R(!1)},X=T?s.ops[T]:void 0,[J,pe]=f.useState(0);f.useEffect(()=>{if(!T)return;const U=setTimeout(()=>{const Se=t.getState().ops[T];Se&&yn(Se.phase)&&(v(!1),L({kind:"timeout",op:T}))},Sy);return()=>clearTimeout(U)},[T,J,t]),f.useEffect(()=>{if(!T||!X||yn(X.phase))return;if(v(!1),B(null),X.phase==="applied"){ra(a,Bn.draft,null),i&&ra(a,Bn.prefs,JSON.stringify({...yi(a),[i.id]:{tool:m,model:g.model,effort:g.effort}})),X.id?(Kh(X.id,(i==null?void 0:i.name)??"",n),An({name:"thread",sessionId:X.id})):An({name:"sessions"});return}if(X.phase==="failed"){L({kind:"failed"});return}const U=X.reason??"other";U==="stale"&&D&&t.requestProjectFolders(D),L({kind:"refused",reason:U})},[T,X==null?void 0:X.phase]);const Ne=async()=>{if(!i)return;const U={project:i.id,tool:m,folders:ee,prompt:y.trim(),...oe?{name:oe}:{},...g.model?{model:g.model}:{},...g.effort?{effort:g.effort}:{},...m==="omp"&&N!=="always-ask"?{approval:N}:{}};v(!0),L(null),R(!1);const Se=await t.launchSession(U);if(Se.status==="sent"){B(Se.op),pe(ie=>ie+1);return}v(!1),Se.status==="cancelled"?R(!0):Se.status==="noAnswer"?L({kind:"timeout",op:null}):Se.status==="failed"?L({kind:"refused",reason:"other"}):L({kind:"refused",reason:Se.reason})},Xe=U=>{if(U.kind==="timeout"&&U.op){if(t.launchAgain(U.op)){B(U.op),pe(ie=>ie+1),v(!0),L(null);return}const Se=t.getState().ops[U.op];if(Se&&yn(Se.phase)){L({...U});return}}Ne()},gt=U=>U.kind==="timeout"&&U.op!==null&&!!s.ops[U.op]&&yn(s.ops[U.op].phase)&&!t.canLaunchAgain(U.op),ze=[...s.sessions.values()].filter(U=>U.state!=="exited"),Je=P?F:"",oe=wm(Je),de=Sm(Yl(ze),Je)!==void 0,ke=de?Cm(ze,Je):void 0,Oe=de?ke?ke.name.toLowerCase()===oe.toLowerCase()&&ke.project?ae.nameTaken(oe,ke.project):ae.nameTakenBy(oe,ke.name):ae.nameReserved:null,lt=u.tools[m],mt=!s.fresh,kt=mt?{label:ae.missing.machine}:(Vt=s.daemon)!=null&&Vt.launch?(tn=s.device)!=null&&tn.confirm?!i||ee.length===0?{label:ae.chooseProject}:de?{label:ae.missing.name}:y.trim()===""?{label:ae.missing.prompt}:null:{label:ae.missing.setup,body:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ae.setupBody}),e.jsxs("a",{href:"#/connection/link",className:rt({size:"sm",className:"self-start"}),children:[e.jsx(z,{name:"gear",className:"size-4"}),ae.openSettings]})]})}:{label:ae.missing.pcOld(r),body:e.jsx("span",{className:"text-center text-[12px] leading-4 text-muted",children:ae.pcOldBody})},ct=_&&!(mt&&_.kind==="timeout")?_:null,xt=g.model===null?null:((Gt=fe.find(U=>U.id===g.model))==null?void 0:Gt.label)??g.model,G=g.model===null?u.model.byDefault:ae.pick(xt,g.effort?Ws(g.effort):null),Ee=g.model===null?u.model.defaultHint:(()=>{const U=fe.find(Se=>Se.id===g.model);return U?qc(m,U):void 0})(),we=q.find(U=>U.path===ee[0]),le=we?we===q[0]?we.branch?ae.onBranch(we.branch):ae.inFolder:Ni(we.path):void 0,ge=we&&we!==q[0]?we.branch??void 0:void 0;return e.jsxs(e.Fragment,{children:[e.jsx(La,{back:e.jsx("button",{type:"button","aria-label":ae.close,title:ae.close,onClick:()=>Aa({name:"sessions"}),className:Ot({className:"text-muted"}),children:e.jsx(z,{name:"close"})}),name:ae.title}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col gap-3.5 overflow-y-auto overscroll-contain pt-3.5 pb-4",children:[e.jsx(zn,{label:ae.project,aside:l.length>0?e.jsxs("button",{type:"button",role:"switch","aria-checked":P,onClick:()=>he(()=>{I.current=!0,W(U=>!U)}),className:"-my-1 inline-flex items-center gap-2 rounded-lg px-1.5 py-1 text-[13px] text-fg",children:[e.jsx("span",{"aria-hidden":"true",className:`relative inline-block h-[17px] w-[30px] flex-none rounded-full border ${P?"border-transparent bg-primary":"border-input bg-raised"}`,children:e.jsx("span",{className:`absolute top-[2px] size-[11px] rounded-full transition-all ${P?"left-[15px] bg-white":"left-[2px] bg-muted"}`})}),ae.nameToggle]}):void 0,children:l.length===0?e.jsxs("p",{className:"text-body text-muted",children:[u.launch.noProjects," ",ae.noProjectsBody]}):e.jsx(Nr,{onClick:()=>S("project"),lead:i?e.jsx(Pe,{state:mt?"off":"idle"}):null,label:ae.project,text:i?e.jsx("b",{className:"font-semibold",children:i.name}):ae.chooseProject,sub:i?[r,mt?ae.offline:d?ae.remembered:null].filter(Boolean).join(" · "):void 0,dim:mt})}),P&&l.length>0&&e.jsxs(zn,{label:ae.name,htmlFor:Y,children:[e.jsx("input",{id:Y,ref:H,type:"text",value:F,placeholder:ae.namePlaceholder($m(Yl(ze))),spellCheck:!1,autoComplete:"off",autoCapitalize:"off","aria-invalid":de||void 0,"aria-describedby":`${Y}-say`,onChange:U=>{const Se=U.target.value;he(()=>re(Se))},className:`h-12 rounded-lg border bg-surface px-3 text-[15px] outline-none placeholder:text-muted focus:border-ring focus:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)] ${de?"border-danger-fg":"border-input"}`}),Oe?e.jsx("span",{id:`${Y}-say`,role:"alert",className:"text-[12px] leading-4 text-danger-fg",children:Oe}):e.jsx("span",{id:`${Y}-say`,className:`text-[12px] leading-4 ${oe&&oe!==Je?"text-fg":"text-muted"}`,children:oe&&oe!==Je?ae.nameCleaned(oe):ae.nameHint})]}),i&&e.jsx(zn,{label:ae.where,children:e.jsx(Nr,{onClick:()=>S("where"),lead:e.jsx(z,{name:we!=null&&we.branch?"branch":"folder",className:"size-4 text-muted"}),label:ae.where,text:ee.length>1&&le?e.jsxs(e.Fragment,{children:[e.jsxs("span",{"aria-hidden":"true",children:[le,e.jsx("span",{className:"ml-1.5 font-mono text-small text-muted",children:ae.more(ee.length-1)})]}),e.jsx("span",{className:"sr-only",children:ae.moreLabel(le,ee.length-1)})]}):le??"",sub:ge})}),e.jsx(zn,{label:ae.agent,children:e.jsx("div",{role:"group","aria-label":ae.agent,className:"grid grid-cols-2 gap-2",children:vy.map(U=>e.jsxs("button",{type:"button","aria-pressed":U===m,onClick:()=>O(U),className:"flex flex-col items-start gap-0.5 rounded-lg border border-input px-[11px] py-[9px] text-left text-[13.5px] font-medium aria-pressed:border-ring aria-pressed:bg-raised aria-pressed:shadow-[inset_0_0_0_1px_var(--color-ring)]",children:[u.tools[U],e.jsx("small",{className:"text-[11.5px] font-normal text-muted",children:ae.tools[U]})]},U))})}),e.jsx(zn,{label:ae.model,children:e.jsx(Nr,{onClick:()=>S("model"),lead:e.jsx(z,{name:"cpu",className:"size-4 text-muted"}),label:ae.model,text:G,sub:Ee})}),m==="omp"&&e.jsxs(zn,{label:ae.permissions,children:[e.jsx(Na,{name:"launch-approval",legend:ae.permissions,value:N,onChange:U=>he(()=>k(U)),options:wy.map(U=>({value:U,label:ae.approvals[U][0]}))}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ae.approvals[N][1]})]}),e.jsxs(zn,{label:ae.message,htmlFor:E,children:[e.jsx("textarea",{id:E,value:y,onChange:U=>Z(U.target.value),placeholder:ae.placeholder,rows:4,className:"min-h-[92px] resize-none rounded-lg border border-input bg-surface px-3 py-2.5 text-[15px] leading-[22px] outline-none placeholder:text-muted focus:border-ring focus:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)]"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:ae.ideas.map(U=>e.jsx("button",{type:"button",onClick:()=>Z(U),className:"h-8 rounded-lg border border-dashed border-input px-2.5 text-[12.5px] text-muted",children:U},U))})]})]}),e.jsxs("div",{className:"bleed flex flex-none flex-col gap-1.5 border-t border-line bg-bg px-3.5 pt-2.5 pb-[calc(14px+var(--foot-inset))]",children:[ct&&e.jsx(Cy,{outcome:ct,agent:lt,machine:r,taken:Oe??ae.missing.name,onRetry:gt(ct)?null:()=>Xe(ct)}),kt?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:!0,className:rt({variant:"primary",className:"w-full"}),children:kt.label}),kt.body]}):e.jsx("button",{type:"button",disabled:$,onClick:()=>void Ne(),className:rt({variant:"primary",className:"w-full"}),children:$?e.jsxs(e.Fragment,{children:[e.jsx(z,{name:"spinner",className:"size-4 motion-safe:animate-spin"}),ae.launching]}):e.jsxs(e.Fragment,{children:[Pt()&&e.jsx(z,{name:"face",className:"size-[18px]"}),Pt()?ae.launchCheck:ae.launchDevice]})}),A&&e.jsx("span",{role:"status",className:"text-center text-[12px] leading-4 text-destructive",children:ae.cancelled}),!kt&&i&&e.jsx("span",{className:"text-center text-[12px] leading-4 text-muted",children:ae.summary(lt,xt,r,i.name)})]}),M==="project"&&e.jsxs(ht,{labelledBy:"launch-project",onClose:()=>S(null),children:[e.jsx("h2",{id:"launch-project",className:"text-base font-semibold",children:ae.project}),e.jsx(wi,{children:l.map(U=>e.jsx(Si,{on:U.id===(i==null?void 0:i.id),onClick:()=>w(U),lead:e.jsx(Pe,{state:mt?"off":"idle"}),text:U.name,sub:mt?`${r} · ${ae.offline}`:r},U.id))})]}),M==="where"&&i&&e.jsxs(ht,{labelledBy:"launch-where",onClose:()=>S(null),children:[e.jsxs("div",{children:[e.jsx("h2",{id:"launch-where",className:"text-base font-semibold",children:ae.where}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ae.folders(i.name)})]}),e.jsx(wi,{children:q.map((U,Se)=>{const ie=Du(U)?U.exists===!1?ae.folder.missing(r):null:ae.folder.elsewhere(U.label??U.machine,r);return e.jsx(Si,{on:ee.includes(U.path),disabled:ie!==null,onClick:()=>V(U.path),lead:e.jsx(z,{name:ie===null&&U.branch?"branch":"folder",className:"size-5 text-muted"}),text:Se===0?ae.projectFolder:Ni(U.path),sub:ie??U.branch??void 0},`${U.machine}:${U.path}`)})}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ae.folder.single})]}),M==="model"&&e.jsx(ht,{labelledBy:gl,onClose:()=>S(null),children:e.jsx(Gc,{tool:m,models:fe,error:(Xt=s.models[m])==null?void 0:Xt.error,pick:g,onPick:U=>he(()=>h(U)),actions:e.jsx("button",{type:"button",onClick:()=>S(null),className:rt({variant:"primary",className:"w-full"}),children:ae.done})})})]})}function zn({label:t,htmlFor:n,aside:s,children:a}){const r=n?"label":"span",l=e.jsx(r,{...n?{htmlFor:n}:{},className:"text-[12px] font-medium text-muted",children:t});return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[s?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l,s]}):l,a]})}function Nr({onClick:t,lead:n,text:s,sub:a,dim:r=!1}){return e.jsxs("button",{type:"button","aria-haspopup":"dialog",onClick:t,className:`flex min-h-12 w-full items-center gap-2.5 rounded-lg border border-input bg-surface px-3 py-1.5 text-left ${r?"opacity-60":""}`,children:[n,e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate text-body",children:s}),a&&e.jsx("small",{className:"truncate text-[12px] text-muted",children:a})]}),e.jsx(z,{name:"down",className:"size-4 text-muted"})]})}function wi({children:t}){return e.jsx("div",{className:"flex max-h-[50vh] flex-col overflow-y-auto rounded-[10px] border border-line",children:t})}function Si({on:t,disabled:n=!1,onClick:s,lead:a,text:r,sub:l}){return e.jsxs("button",{type:"button","aria-pressed":t,disabled:n,onClick:s,className:"flex min-h-12 items-center gap-3 border-b border-line px-3.5 py-1.5 text-left text-[15px] last:border-b-0 aria-pressed:bg-raised disabled:opacity-45",children:[a,e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate",children:r}),l&&e.jsx("small",{className:"truncate text-[12px] text-muted",children:l})]}),t&&e.jsx(z,{name:"check",className:"size-4"})]})}function Cy({outcome:t,agent:n,machine:s,taken:a,onRetry:r}){const l={label:ae.retry,onClick:r??(()=>{})};if(t.kind==="timeout")return r?e.jsx(at,{tone:"warn",title:ae.timeout,body:ae.timeoutBody,action:l}):e.jsx(at,{tone:"warn",title:ae.timeout,body:ae.lostBody,action:{label:u.cards.seeSessions,href:ce({name:"sessions"})}});if(t.kind==="failed")return e.jsx(at,{tone:"fail",title:ae.failed(n),body:ae.failedBody(n),action:l});const o=ae.refused;switch(t.reason){case"not_found":return e.jsx(at,{tone:"fail",title:o.not_found,body:ae.kept});case"invalid":return e.jsx(at,{tone:"fail",title:o.invalid,body:o.invalidBody(n)});case"stale":return e.jsx(at,{tone:"fail",title:o.stale,body:o.staleBody});case"confirm_required":return e.jsx(at,{tone:"fail",title:o.confirm_required,body:o.setupKept,action:{label:ae.settings,href:"#/connection/link"}});case"assertion_invalid":return e.jsx(at,{tone:"fail",title:o.assertion_invalid,body:ae.kept,action:l});case"assertion_expired":return e.jsx(at,{tone:"warn",title:o.assertion_expired,body:o.expiredBody,action:l});case"unavailable":return e.jsx(at,{tone:"warn",title:o.unavailable(s),body:o.unavailableBody});case"name_taken":return e.jsx(at,{tone:"fail",title:a});default:return e.jsx(at,{tone:"fail",title:o.other,body:ae.kept})}}const Jr="ledge.mobile.forge",$y=35e3,My=65e3,Pl=(t,n)=>n?`${t}
|
|
21
|
-
${n}`:t,ua=t=>t!=="checking"&&t!=="sending"&&t!=="received",kr=t=>!!t&&(!ua(t.phase)||t.phase==="uncertain"&&!t.lost),Ci=new Set(["assertion_invalid","assertion_expired","confirm_required","conflict"]);function Ey(t){var n;try{const s=(n=Ze(t))==null?void 0:n.getItem(Jr);if(!s)return null;const a=JSON.parse(s),r=Mm.safeParse(a.state);return r.success&&typeof a.at=="string"?{state:r.data,at:a.at}:null}catch{return null}}function _y(t,n,s){var H;const a=Ey(s);let r={state:(a==null?void 0:a.state)??null,at:(a==null?void 0:a.at)??null,loading:!1,details:{},runs:[],drafts:{}};const l=new Set,o=I=>{r={...r,...I};for(const D of[...l])D()};let c=!1,i=!1,x=!1;const d=new Map,m=new Map,p=new Map;let g=0,h=n.getState().daemon?((H=n.getState().daemon)==null?void 0:H.boot)??null:void 0;const N=new Set,k=()=>!c&&t.state()==="ready",C=()=>{var I;return!!((I=n.getState().daemon)!=null&&I.forge)},j=I=>{t.send(I).catch(()=>{})},y=(I,D,Q)=>{clearTimeout(d.get(I)),d.set(I,setTimeout(()=>{d.delete(I),Q()},D))},b=I=>{clearTimeout(d.get(I)),d.delete(I)};function M(){x||!i||!k()||!C()||(x=!0,j({type:"forge.state"}),o({loading:!0}),y("state",$y,()=>{x=!1,o({loading:!1})}))}const S=I=>r.runs.find(D=>D.op===I);function $(I,D){const Q=r.runs.findIndex(K=>K.id===I);if(Q<0)return;const q=D(r.runs[Q]);if(o({runs:r.runs.map((K,ee)=>ee===Q?q:K)}),ua(q.phase)){q.op&&q.phase!=="uncertain"&&m.delete(q.op);const K=p.get(I);p.delete(I),K==null||K(q)}}const v=I=>I.sentAt!==void 0&&Date.now()-I.sentAt<Wi&&h!==void 0&&(I.boot??null)===h,A=I=>{b(`op:${I.op}`),m.delete(I.op),$(I.id,D=>({...D,phase:"uncertain",lost:!0,endedAt:D.endedAt??Date.now()}))};function R(I){for(const[D,Q]of[...m]){const q=S(D);if(!q){m.delete(D);continue}if(!I.has(D)){if(!v(q)){A(q);continue}$(q.id,K=>({...K,again:!0})),j(Q),q.phase==="sending"&&L(D)}}}const _=(I,D)=>{b(`op:${I}`);const Q=S(I);Q&&kr(Q)&&$(Q.id,q=>({...q,...D,endedAt:Date.now()}))},L=I=>y(`op:${I}`,Ki,()=>{const D=S(I);(D==null?void 0:D.phase)==="sending"&&$(D.id,Q=>({...Q,phase:"uncertain",endedAt:Date.now()}))});function T(I){var D,Q,q;switch(I.type){case"snapshot":{const K=h;h=I.daemon.boot??null;const ee=new Set(N);N.clear();for(const ue of ee){const fe=S(ue);fe&&$(fe.id,he=>({...he,boot:h}))}(K===void 0||K!==h)&&R(ee),M();return}case"forge.state":{b("state");const K=new Date().toISOString(),ee={prs:I.prs,forges:I.forges,followed:I.followed,...I.mine?{mine:I.mine}:{}},ue=Object.keys(r.details).filter(fe=>{var O,V,Z;const he=(V=(O=r.details[fe])==null?void 0:O.data)==null?void 0:V.pr.headSha,w=(Z=[...ee.prs,...ee.mine??[]].find(X=>X.id===fe))==null?void 0:Z.headSha;return he&&w&&he!==w});o({state:ee,at:K,loading:!1});try{(D=Ze(s))==null||D.setItem(Jr,JSON.stringify({state:ee,at:K}))}catch{}for(const fe of ue)Y.readDetail(fe);return}case"forge.detail":{b(`detail:${I.prId}`);const K=r.details[I.prId];if(I.detail){const ee=I.detail.log??((Q=K==null?void 0:K.data)!=null&&Q.log&&I.detail.jobs.some(ue=>ue.id===K.data.log.jobId)?K.data.log:void 0);o({details:{...r.details,[I.prId]:{data:{...I.detail,...ee?{log:ee}:{}},...I.cut?{cut:!0}:{},loading:!1,at:new Date().toISOString()}}})}else o({details:{...r.details,[I.prId]:{...K,loading:!1,error:I.error??"failed"}}});return}case"operation.result":{const K=S(I.op);if(!K||!kr(K))return;if(I.status==="received"){b(`op:${I.op}`),(K.phase==="sending"||K.phase==="uncertain")&&$(K.id,ee=>{const{endedAt:ue,...fe}=ee;return{...fe,phase:"received"}});return}if(I.status==="rejected"&&K.again&&Ci.has(I.reason??"")){A(K);return}I.status==="rejected"&&_(I.op,{phase:"rejected",reason:I.reason??"invalid"});return}case"forge.done":{const K=S(I.op);if(!K)return;if(K.again&&I.rejected&&Ci.has(I.rejected)){K.lost||A(K);return}const ee=I.rejected?{phase:"rejected",reason:I.rejected,done:I}:{phase:"done",done:I,...I.error?{reason:I.error}:{}};if(K.lost)m.delete(K.op),$(K.id,ue=>{const{lost:fe,...he}=ue;return{...he,...ee,endedAt:Date.now()}});else{const ue=kr(K);_(I.op,ee),ue||$(K.id,fe=>({...fe,done:I}))}if(I.ok&&(K.action.kind==="comment"||K.action.kind==="reply")){const ue=Pl(K.prId,K.action.kind==="reply"?K.action.threadId:void 0);if(((q=r.drafts[ue])==null?void 0:q.trim())===K.action.body){const{[ue]:fe,...he}=r.drafts;o({drafts:he})}}r.details[K.prId]&&Y.readDetail(K.prId);return}}}let B=k();const E=t.subscribe(()=>{const I=t.state();(I==="unpaired"||I==="pairing")&&W();const D=k();if(D&&!B)B=!0,g++,x=!1,h=void 0,N.clear();else if(!D&&B){B=!1,x=!1;for(const[q,K]of d)clearTimeout(K),d.delete(q);const Q=Object.fromEntries(Object.entries(r.details).map(([q,K])=>[q,K.loading?{...K,loading:!1}:K]));o({loading:!1,details:Q});for(const q of r.runs)q.phase==="sending"&&q.op&&$(q.id,K=>({...K,phase:"uncertain",endedAt:Date.now()}))}}),P=t.onMessage(T);function W(){var I;if(!(!r.state&&!r.runs.length&&!Object.keys(r.details).length&&!Object.keys(r.drafts).length)){try{(I=Ze(s))==null||I.removeItem(Jr)}catch{}m.clear(),o({state:null,at:null,loading:!1,details:{},runs:[],drafts:{}})}}async function F(I){var K;if(!((K=n.getState().device)!=null&&K.confirm))return{phase:"rejected",reason:"confirm_required"};let D;try{D=await n.prepareConfirm(I)}catch(ee){return{phase:ee instanceof Error&&ee.message==="timeout"?"expired":"unsent"}}if(!D.credentialId)return{phase:"rejected",reason:"confirm_required"};const Q=Date.now(),q=await Fs({challenge:D.challenge,rpId:D.rpId,credentialId:D.credentialId}).catch(()=>"failed");return q==="cancelled"?{phase:"cancelled"}:q==="failed"?{phase:"unsent"}:Date.now()-Q>=D.expiresInMs?{phase:"expired"}:{assertion:q}}async function re(I,D,Q){var ue;L(D);const q=g,K=await t.send(Q).catch(()=>!1),ee=(ue=S(D))==null?void 0:ue.phase;!K&&q===g&&(ee==="sending"||ee==="uncertain")&&(b(`op:${D}`),$(I,fe=>({...fe,phase:"unsent",endedAt:Date.now()})))}const Y={getState:()=>r,subscribe(I){return l.add(I),()=>{l.delete(I)}},follow(){i=!0,M()},readDetail(I,D){!k()||!C()||(j({type:"forge.detail",prId:I,...D?{log:D}:{}}),o({details:{...r.details,[I]:{...r.details[I],loading:!0}}}),y(`detail:${I}`,My,()=>o({details:{...r.details,[I]:{...r.details[I],loading:!1,error:"failed"}}})))},act(I,D){const Q=crypto.randomUUID(),q={op:"",id:Q,prId:I,action:D,phase:"checking",startedAt:Date.now()};if(!k()||!C()){const ee={...q,phase:"unsent",endedAt:Date.now()};return o({runs:[...r.runs,ee]}),Promise.resolve(ee)}const K=new Promise(ee=>p.set(Q,ee));return o({runs:[...r.runs,q]}),(async()=>{const ee=await F({purpose:"forge",forge:{prId:I,action:D}});if(!("assertion"in ee)){$(Q,he=>({...he,phase:ee.phase,...ee.reason?{reason:ee.reason}:{},endedAt:Date.now()}));return}const ue=Ui(),fe=Pi.safeParse({type:"forge.act",op:ue,prId:I,action:D,assertion:ee.assertion});if(!fe.success||!k()){$(Q,he=>({...he,phase:"unsent",endedAt:Date.now()}));return}m.set(ue,fe.data),h===void 0&&N.add(ue),$(Q,he=>({...he,op:ue,phase:"sending",sentAt:Date.now(),boot:h??null})),await re(Q,ue,fe.data)})(),K},resend(I){const D=r.runs.find(q=>q.id===I),Q=D!=null&&D.op?m.get(D.op):void 0;if(!(!D||D.phase!=="uncertain"||D.lost||!Q||!k())){if(!v(D)){A(D);return}$(I,q=>{const{endedAt:K,...ee}=q;return{...ee,phase:"sending",again:!0}}),re(I,D.op,Q)}},setDraft(I,D){if(D)o({drafts:{...r.drafts,[I]:D}});else{const{[I]:Q,...q}=r.drafts;o({drafts:q})}},dismiss(I){const D=r.runs.find(Q=>Q.id===I);D&&ua(D.phase)&&D.op&&m.delete(D.op),o({runs:r.runs.filter(Q=>Q.id!==I||!ua(Q.phase))})},close(){c=!0,E(),P();for(const I of d.values())clearTimeout(I);d.clear()}};return Y}function Qa(t){return f.useSyncExternalStore(t.subscribe,t.getState,t.getState)}const Le=u.prs;function Ry({status:t,pc:n}){const[s,a]=f.useState(!1),r=en(t),l=e.jsx(z,{name:"warning",className:"mt-px size-4 text-attention"});if(t.status==="missing")return e.jsx(Wt,{warn:!0,role:"alert",lead:l,children:e.jsx("span",{"data-forge-strip":"missing",children:Le.missing(r.cli,n,t.host,r.kind)})});if(t.status==="unauthenticated"){const i=xg(t);return e.jsxs(Wt,{warn:!0,role:"alert",lead:l,children:[e.jsx("b",{"data-forge-strip":"unauthenticated",className:"font-semibold",children:Le.unauth(r.cli,t.host,n)}),e.jsx("code",{className:"block rounded-md bg-raised px-2 py-1.5 font-mono text-[12px] break-all",children:i}),e.jsx("button",{type:"button",className:be({size:"sm",className:"self-start"}),onClick:()=>{var x;(x=navigator.clipboard)==null||x.writeText(i).then(()=>a(!0),()=>{})},children:s?Le.copied:Le.copy})]})}const o=t.since??t.at,c=[t.retryAt?Le.retryAt(Ke(t.retryAt)):"",t.readAt?Le.readAt(r.kind,Ke(t.readAt)):""].filter(Boolean).join(" ");return e.jsx(Wt,{warn:!0,role:"alert",lead:l,children:e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("b",{"data-forge-strip":"error",className:"font-semibold",children:Le.error(r.host,n,Ke(o))}),c&&e.jsx("span",{className:"text-muted",children:c})]})})}function Ty(){const t="block animate-[ledge-pulse_1.6s_ease-in-out_infinite] rounded-[5px] bg-raised";return e.jsxs("div",{role:"status","data-list-state":"",className:"flex flex-col gap-3",children:[e.jsx(Ve,{children:e.jsxs("div",{"aria-hidden":"true",className:"flex flex-col gap-2.5 p-2.5",children:[e.jsx("span",{className:`${t} h-3.5 w-[70%]`}),e.jsx("span",{className:`${t} h-3 w-[45%]`}),e.jsx("span",{className:`${t} h-3.5 w-[60%]`}),e.jsx("span",{className:`${t} h-3 w-1/2`})]})}),e.jsx("span",{className:"text-[12px] text-muted",children:Le.loading})]})}function Ay(t,n,s){const a=s!=null&&s.readAt?Le.asOf(Ke(s.readAt)):Le.state[t.state];return[Le.host[t.forge],Ml(t.repo),...n?[n]:[],a].join(" · ")}let $i={role:"all",q:""};function Mi({pr:t}){const n=t.roles??[];if(!n.length&&!t.sessions.length)return null;const s="rounded-[7px] border px-1.5 text-[11px] leading-4";return e.jsxs(e.Fragment,{children:[n.map(a=>e.jsx("span",{"data-role-pill":a,className:`${s} ${a==="reviewer"?"border-attention/50 text-attention":"border-line text-muted"}`,children:Le.pill[a]},a)),t.sessions.length>0&&e.jsx("span",{"data-role-pill":"tracked",className:`${s} border-task/45 text-task`,children:Le.pill.tracked})]})}function Iy({forge:t,store:n}){const s=Qa(t),a=me(n),{pc:r,look:l}=zt(),o=Ps(),c=Dt(),[i,x]=f.useState(!0),[d,m]=f.useState(null),[p,g]=f.useState($i),h=M=>{$i=M,g(M)},N=l==="offline",k=Jt(r),C=s.state,j=M=>{var $;const S=M.sessions[0];return S?(($=a.sessions.get(S))==null?void 0:$.name)??null:null},y=M=>Le.offlineBody(s.at?Ke(s.at):M),b=(()=>{if(!C)return e.jsx(Ty,{});const M=mg(C.forges),S=F=>M.find(re=>re.forge===F.forge&&re.host===F.host),$=[...C.prs,...C.mine??[]],v={open:dg($).open.sort((F,re)=>re.updatedAt.localeCompare(F.updatedAt)),closed:Em($,Date.now())},A=_m($),R=Zl(v.open,p.role,p.q),_=Zl(v.closed,p.role,p.q),L=p.role!=="all"||p.q.trim()!=="",T=`${p.role}
|
|
22
|
-
${p.q.trim()}`,B=L&&R.length===0&&_.length>0,E=B?d!==T:!i,P=C.forges.length>0&&M.length===C.forges.length,W="flex h-[30px] shrink-0 items-center gap-1.5 rounded-full border px-[11px] text-[12.5px]";return e.jsxs(e.Fragment,{children:[!N&&M.map(F=>e.jsx(Ry,{status:F,pc:k},`${F.forge}:${F.host}`)),e.jsxs("div",{className:`flex flex-col gap-3 ${N?"opacity-50":""}`,children:[v.open.length+v.closed.length>0&&e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsxs("label",{className:"flex h-9 items-center gap-2 rounded-[9px] border border-line px-2.5 text-muted focus-within:border-muted",children:[e.jsx(z,{name:"search",className:"size-3.5 shrink-0"}),e.jsx("input",{type:"search","aria-label":Le.search,placeholder:Le.search,value:p.q,onChange:F=>h({...p,q:F.target.value}),className:"min-w-0 flex-1 bg-transparent text-[13px] text-fg outline-none placeholder:text-muted"})]}),e.jsx("div",{role:"group","aria-label":Le.rolesLabel,className:"-mx-1 flex gap-1.5 overflow-x-auto px-1 [scrollbar-width:none]",children:
|
|
23
|
-
`).map((o,c)=>e.jsx("span",{"data-line":Ei(o),className:`block overflow-hidden px-3 text-ellipsis whitespace-pre ${Oy[Ei(o)]}`,children:o||" "},c))})]})}function Fy({detail:t}){if(t.files.length===0)return e.jsx("p",{className:"p-2.5 text-center text-[12px] text-muted",children:as.noChange});const n=bg(t),s=as.host[t.pr.forge];return e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx(It,{aside:e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"font-mono text-ok",children:["+",_a(n.added)]})," ",e.jsxs("span",{className:"font-mono text-danger-fg",children:["−",_a(n.removed)]})]}),children:as.fileCount(t.files.length)}),e.jsx(Ve,{label:as.tabs.changes,children:t.files.map(a=>e.jsx(Dy,{f:a,threads:jg(t,a.path),host:s},a.path))})]})}const vr=u.prs,Py=t=>[...t].sort((n,s)=>Date.parse(s.at)-Date.parse(n.at));function zy({detail:t}){return e.jsxs("div",{className:"flex flex-col gap-2.5",children:[t.commits.length>0&&e.jsx(Ve,{label:vr.tabs.commits,children:Py(t.commits).map(n=>e.jsxs("div",{"data-commit":n.sha,className:"flex min-h-[52px] items-center gap-2.5 border-b border-line px-3 py-1.5 last:border-b-0",children:[e.jsx(z,{name:"commit",className:"size-4 text-muted"}),e.jsx("span",{className:"flex-none font-mono text-[12px] text-muted",children:vl(n.sha)}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col text-[13.5px]",children:[e.jsx("span",{className:"truncate",children:n.title}),e.jsx("small",{className:"text-[12px] text-muted",children:`${n.author} · ${Ur(n.at)}`})]})]},n.sha))}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:vr.commitsReadOnly(vr.host[t.pr.forge])})]})}const it=u.prs,Bl=t=>t.file?t.line!==void 0?it.fileLine(t.file,t.line):t.file:null,Fu=(t,n,s)=>t.filter(a=>a.prId===n&&s(a)).at(-1),Pu=["checking","sending","received"];function zu({sent:t,onClose:n}){return t==="refused"?e.jsx($e,{mark:"bad",title:u.agents.notSent,onClose:n,closeLabel:it.close}):e.jsx($e,{mark:"ok",title:it.commentSent(t.name),onClose:n,closeLabel:it.close,children:e.jsx("a",{href:ce({name:"thread",sessionId:t.id}),className:be({size:"xs",className:"mt-1.5"}),children:it.openAgent(t.name)})})}function Bu({id:t,label:n,placeholder:s,verb:a,value:r,onChange:l,confirm:o,live:c,onPost:i,host:x,autoFocus:d=!1,rows:m=2,arrow:p=!1}){const g=e.jsx("textarea",{id:t,rows:r?Math.max(m,2):m,value:r,placeholder:s,autoFocus:d,onChange:h=>l(h.target.value),className:p?"min-h-[34px] min-w-0 flex-1 resize-none bg-transparent py-[6px] text-base leading-[22px] text-fg outline-none placeholder:text-muted":"min-h-11 w-full resize-none rounded-[14px] border border-input bg-surface px-3.5 py-[11px] text-base leading-5 text-fg placeholder:text-muted"});return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:t,className:"sr-only",children:n}),p?e.jsxs("div",{className:"flex min-w-0 items-end gap-2 rounded-[10px] border border-input bg-surface py-[5px] pr-[5px] pl-3 focus-within:border-ring focus-within:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)]",children:[g,r.trim()===""&&e.jsx("button",{type:"button",disabled:!0,"aria-label":a,title:a,className:"grid size-9 flex-none place-items-center rounded-lg bg-primary text-primary-fg disabled:opacity-40",children:e.jsx(z,{name:"send",className:"size-[18px]"})})]}):g,r.trim()!==""&&e.jsxs(e.Fragment,{children:[e.jsx(On,{verb:a,confirm:o,disabled:!c,onClick:i}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:it.postedAs(x)})]})]})}const By=({who:t,at:n,body:s,reply:a})=>e.jsxs("p",{className:`m-0 text-[13.5px] leading-[19px] [overflow-wrap:anywhere] whitespace-pre-wrap ${a?"border-l-2 border-line pl-[9px]":""}`,children:[e.jsx("span",{className:"font-semibold",children:t}),e.jsx("span",{className:"ml-1 font-mono text-[11px] text-muted",children:Ke(n)}),e.jsx("br",{}),s]}),qy="flex flex-col gap-2 rounded-[10px] border border-line bg-surface p-2.5 dark:bg-transparent",wr="h-9 !px-2.5 text-[12.5px]";function qu({pr:t,t:n,agent:s,forge:a,store:r,live:l,pc:o,readOnly:c=!1}){var v,A;const i=Qa(a),x=me(r),[d,m]=f.useState(!1),[p,g]=f.useState(null),h=Pl(t.id,n.id),N=i.drafts[h]??"",k=en(t),C=Bl(n),j=n.comments[0],y=Fu(i.runs,t.id,R=>(R.action.kind==="reply"||R.action.kind==="resolve")&&R.action.threadId===n.id),b=()=>{s&&g(r.reply(s.id,it.threadText(t.ref,j.author,C,j.body))?s:"refused")},M=()=>{m(!1),a.act(t.id,{kind:"reply",threadId:n.id,body:N.trim()})},S=!!y&&Pu.includes(y.phase),$=!S&&(d||N!==""&&(y==null?void 0:y.action.kind)==="reply"&&y.phase!=="uncertain"&&!(y.phase==="done"&&((v=y.done)!=null&&v.ok)));return e.jsxs("article",{"data-thread":n.id,className:qy,children:[C&&e.jsx("span",{className:"font-mono text-[11px] text-muted",children:C}),n.code&&e.jsx("code",{className:"block truncate rounded-md bg-ok/15 px-2 py-[3px] font-mono text-[11.5px] leading-[17px] whitespace-pre",children:n.code}),n.comments.map((R,_)=>e.jsx(By,{who:R.author,at:R.at,body:R.body,reply:_>0},R.id)),!c&&e.jsxs(e.Fragment,{children:[$?e.jsx(Bu,{id:`reply-${n.id}`,label:it.reply,placeholder:it.replyPh,verb:it.reply,value:N,onChange:R=>a.setDraft(h,R),confirm:!!((A=x.device)!=null&&A.confirm),live:l,onPost:M,host:k.host,autoFocus:d}):e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsx("button",{type:"button",disabled:!l||S,onClick:()=>m(!0),className:be({className:wr}),children:it.reply}),s&&e.jsx("button",{type:"button",disabled:!x.fresh,onClick:b,className:be({className:wr}),children:it.sendTo(s.name)}),n.resolvable&&e.jsx("button",{type:"button",disabled:!l||S,onClick:()=>void a.act(t.id,{kind:"resolve",threadId:n.id}),className:`${be({className:wr})} border-transparent`,children:it.resolve})]}),p&&e.jsx(zu,{sent:p,onClose:()=>g(null)}),y&&e.jsx(zl,{run:y,pr:t,detail:void 0,forge:a,pc:o})]})]})}function Hy({pr:t,t:n,forge:s,store:a,pc:r}){const[l,o]=f.useState(!1),c=Bl(n);return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-expanded":l,onClick:()=>o(i=>!i),"data-thread":n.id,className:"flex items-center gap-2 rounded-[10px] border border-dashed border-line px-2.5 py-2 text-left text-[12.5px] text-muted",children:[e.jsx("span",{"aria-hidden":"true",className:"text-ok",children:"✓"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:it.resolvedRow([...c?[c]:[],n.comments[0].author])}),e.jsx(z,{name:l?"down":"chevron",className:"size-3.5"})]}),l&&e.jsx(qu,{pr:t,t:n,agent:null,forge:s,store:a,live:!1,pc:r,readOnly:!0})]})}function Hu(t,n){const s=me(n),[a,r]=f.useState(null),l=(t==null?void 0:t.threads)??[],o=t?Id(t.pr,s.sessions)[0]:void 0,c=o?{id:o.id,name:o.name}:null,i=l.filter(d=>!d.resolved),x=()=>{if(!c||!t)return;const d=i.map(m=>it.note(m.comments[0].author,Bl(m),m.comments[0].body));r(n.reply(c.id,it.notesText(t.pr.ref,d))?c:"refused")};return{agent:c,open:i,resolved:l.filter(d=>d.resolved),sent:a,send:x,clear:()=>r(null),fresh:s.fresh}}function Uu({all:t,className:n=""}){return!t.agent||!t.open.length?null:e.jsxs("button",{type:"button",disabled:!t.fresh,onClick:t.send,className:be({size:"sm",className:n}),children:[e.jsx(z,{name:"send",className:"size-4"}),it.sendAll(t.agent.name)]})}function Ti({detail:t,forge:n,store:s,live:a,pc:r,column:l}){const o=Hu(t,s),c=l??o,i=t.pr;return t.threads.length?e.jsxs(e.Fragment,{children:[!l&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12.5px] text-muted",children:it.discSub(c.open.length,c.resolved.length)}),e.jsx("span",{className:"flex-1"}),e.jsx(Uu,{all:c})]}),c.sent&&e.jsx(zu,{sent:c.sent,onClose:c.clear}),c.open.map(x=>e.jsx(qu,{pr:i,t:x,agent:c.agent,forge:n,store:s,live:a,pc:r},x.id)),c.resolved.map(x=>e.jsx(Hy,{pr:i,t:x,forge:n,store:s,pc:r},x.id))]}):e.jsx("p",{className:"m-0 p-2.5 text-center text-[12.5px] text-muted",children:it.noComment})}function Ai({pr:t,forge:n,store:s,live:a,pc:r}){var m;const l=Qa(n),o=me(s),c=Pl(t.id),i=l.drafts[c]??"",x=Fu(l.runs,t.id,p=>p.action.kind==="comment"),d=!!x&&Pu.includes(x.phase);return e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[x&&e.jsx(zl,{run:x,pr:t,detail:void 0,forge:n,pc:r}),e.jsx(Bu,{id:`comment-${t.id}`,label:it.addComment,placeholder:it.addComment,verb:it.post,value:i,onChange:p=>n.setDraft(c,p),confirm:!!((m=o.device)!=null&&m.confirm),live:a&&!d,onPost:()=>void n.act(t.id,{kind:"comment",body:i.trim()}),host:en(t).host,rows:1,arrow:!0})]})}const Uy=`${ul} and (orientation: landscape)`,Wu=()=>typeof globalThis.matchMedia=="function"?globalThis.matchMedia(Uy):null,Wy=t=>{var s;const n=Wu();return(s=n==null?void 0:n.addEventListener)==null||s.call(n,"change",t),()=>{var a;return(a=n==null?void 0:n.removeEventListener)==null?void 0:a.call(n,"change",t)}};function Ky(){return f.useSyncExternalStore(Wy,()=>{var t;return((t=Wu())==null?void 0:t.matches)??!1},()=>!1)}const ne=u.prs,Vy={review:"border-attention/45 text-attention"};function Gy({pr:t,landscape:n}){const s=Dt(),a=en(t);return s?e.jsxs("header",{"data-pr-head":"",className:"flex h-[58px] flex-none items-center gap-[9px] border-b border-line pr-2.5 pl-[22px]",children:[e.jsx("span",{className:"inline-flex h-5 flex-none items-center rounded-lg border border-input px-[7px] text-[11.5px] whitespace-nowrap text-muted",children:`${a.host} · ${a.kind}`}),e.jsx("h1",{className:"min-w-0 truncate text-[16px] font-semibold",children:`${t.ref} ${t.title}`}),n&&e.jsx("span",{"data-pr-state":t.state,className:`inline-flex h-[22px] flex-none items-center rounded-full border px-[9px] text-[12px] font-medium whitespace-nowrap ${Vy[t.state]??"border-input text-muted"}`,children:ne.state[t.state]}),e.jsx("span",{className:"flex-1"}),n?e.jsxs("a",{href:t.url,target:"_blank",rel:"noreferrer",className:be({size:"sm",className:"flex-none"}),children:[e.jsx(z,{name:"external",className:"size-4"}),ne.openOn(a.host)]}):e.jsx("a",{href:t.url,target:"_blank",rel:"noreferrer","aria-label":ne.openOn(a.host),title:ne.openOn(a.host),className:Ot(),children:e.jsx(z,{name:"external",className:"size-[18px]"})})]}):e.jsxs("header",{className:`flex flex-none items-center gap-2 border-b border-line pr-1.5 ${s?"pane-head h-[58px]":"h-14 pl-0.5"}`,children:[e.jsx(Zt,{fallback:{name:"prs"},label:ne.title}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("h1",{className:"truncate text-[15px] font-semibold",children:`${t.ref} ${t.title}`}),e.jsx("small",{className:"truncate text-[12px] text-muted",children:[a.host,Ml(t.repo),`${t.branch} → ${t.target}`].join(" · ")})]}),e.jsx("a",{href:t.url,target:"_blank",rel:"noreferrer","aria-label":ne.openOn(a.host),title:ne.openOn(a.host),className:Ot(),children:e.jsx(z,{name:"external",className:"size-[18px]"})})]})}const Xy=["overview","discussion","changes","commits"],Yy=["overview","changes","commits"];function Qy({pr:t,d:n,view:s,views:a,onView:r,wide:l}){const o=n?{discussion:n.threads.length,changes:n.files.length,commits:n.commits.length}:{};return e.jsx("nav",{"aria-label":ne.title,className:`flex flex-none gap-0.5 overflow-x-auto overflow-y-hidden border-b border-line [scrollbar-width:none] ${l?"px-1.5 py-2":"p-2"}`,children:a.map(c=>e.jsxs("button",{type:"button","aria-current":s===c?"page":void 0,onClick:()=>r(c),className:"group inline-flex h-9 flex-none items-center gap-[5px] rounded-lg px-[7px] text-[13px] font-medium whitespace-nowrap text-muted aria-[current=page]:bg-raised aria-[current=page]:text-fg",children:[c==="overview"&&e.jsx(Pe,{state:hs[t.pipeline],pulse:t.pipeline==="run"}),ne.tabs[c],o[c]!==void 0&&e.jsx("span",{className:"inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-raised px-1 font-mono text-[11px] group-aria-[current=page]:bg-bg",children:o[c]})]},c))})}const Ku={ok:"border-ok/40",fail:"border-approval/60",run:"border-info/50",wait:"border-line text-muted",skip:"border-line text-muted",none:"border-line text-muted"},Vu=t=>t==="fail"?"bg-danger-bg":"bg-surface dark:bg-transparent";function Gu(t){if(t.status==="run")return e.jsx("span",{className:"font-mono text-[12px] text-info",children:ne.pipe.run});const n=jd(t.durationS);return n?e.jsx("span",{className:"font-mono text-[12px] text-muted",children:n.hours?ne.hours(n.text):n.text}):t.status==="wait"||t.status==="skip"?e.jsx("span",{className:"text-[12px]",children:ne.pipe[t.status]}):null}function Zy({job:t,selected:n,onOpen:s}){const a=e.jsxs(e.Fragment,{children:[t.status==="run"?e.jsx(gs,{}):e.jsx(Pe,{state:hs[t.status]}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.name}),Gu(t)]}),r=`flex h-11 w-full items-center gap-2.5 rounded-[10px] border px-3 text-left text-[14px] ${Vu(t.status)} ${Ku[t.status]} ${n?"shadow-[0_0_0_2px_var(--color-ring)]":""}`;return s?e.jsx("button",{type:"button","data-job":t.id,onClick:s,className:r,children:a}):e.jsx("div",{"data-job":t.id,className:r,children:a})}function Jy({after:t}){const n=t.jobs.some(a=>a.status==="fail"),s=t.jobs.every(a=>a.status==="ok");return e.jsx("span",{"aria-hidden":"true",className:`mt-[5px] mb-[5px] ml-[22px] block h-3 ${n?"border-l-2 border-dashed border-approval":`w-0.5 ${s?"bg-ok":"bg-input"}`}`})}function eN({pr:t,jobs:n,selected:s,onJob:a}){const r=gd(n);return e.jsx("div",{className:"flex flex-col",children:r.map((l,o)=>e.jsxs("div",{className:"flex flex-col",children:[o>0&&e.jsx(Jy,{after:r[o-1]}),e.jsx("div",{className:"mb-[5px] text-[11px] tracking-[.5px] text-muted uppercase",children:t.forge==="gitlab"?ne.stage(o+1,l.name):l.name}),e.jsx("div",{className:"flex flex-col gap-1.5",children:l.jobs.map(c=>e.jsx(Zy,{job:c,selected:c.id===s,onOpen:c.id===s?void 0:()=>a(c)},c.id))})]},l.column))})}function tN({job:t,selected:n,onOpen:s}){const a=e.jsxs(e.Fragment,{children:[t.status==="run"?e.jsx(gs,{}):e.jsx(Pe,{state:hs[t.status]}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.name}),Gu(t)]}),r=`flex h-10 min-w-[92px] items-center gap-[7px] rounded-[10px] border px-[9px] text-left text-[13px] ${Vu(t.status)} ${Ku[t.status]} ${n?"shadow-[0_0_0_2px_var(--color-ring)]":""}`;return s?e.jsx("button",{type:"button","data-job":t.id,onClick:s,className:r,children:a}):e.jsx("div",{"data-job":t.id,className:r,children:a})}function nN({after:t}){const n=t.jobs.some(a=>a.status==="fail"),s=t.jobs.every(a=>a.status==="ok");return e.jsx("span",{"aria-hidden":"true",className:`mt-[39px] block w-5 flex-none ${n?"border-t-2 border-dashed border-approval":`h-0.5 ${s?"bg-ok":"bg-input"}`}`})}function sN({pr:t,jobs:n,selected:s,onJob:a}){const r=gd(n);return e.jsx("div",{"data-pipeline":"side",className:"flex flex-none items-start overflow-x-auto rounded-[10px] border border-line bg-surface p-3.5 dark:bg-[oklch(0.18_0_0)]",children:r.map((l,o)=>e.jsxs("div",{className:"contents",children:[o>0&&e.jsx(nN,{after:r[o-1]}),e.jsxs("div",{className:"flex min-w-0 flex-[0_1_auto] flex-col gap-2",children:[e.jsx("div",{className:"mb-[5px] text-[11px] tracking-[.5px] whitespace-nowrap text-muted uppercase",children:t.forge==="gitlab"?ne.stage(o+1,l.name):l.name}),l.jobs.map(c=>e.jsx(tN,{job:c,selected:c.id===s,onOpen:c.id===s?void 0:()=>a(c)},c.id))]})]},l.column))})}const aN=({text:t,tall:n=!1})=>e.jsx("pre",{className:`m-0 overflow-hidden rounded-[10px] border border-white/10 bg-[#0c0c0d] px-[11px] py-[9px] font-mono text-[11.5px] leading-[17px] break-all whitespace-pre-wrap text-[#e5e5e5] ${n?"max-h-[300px] overflow-y-auto":""}`,children:t});function Xu({job:t,read:n,pr:s,onRetry:a,tall:r=!1}){var c,i;const l=en(s),o=((i=(c=n==null?void 0:n.data)==null?void 0:c.log)==null?void 0:i.jobId)===t.id?n.data.log.text:null;return o!==null?e.jsx(aN,{text:o,tall:r}):n!=null&&n.loading?e.jsxs("div",{role:"status",className:"flex items-center gap-2 text-[12px] text-muted",children:[e.jsx(gs,{className:"text-muted"}),ne.log.reading(t.name)]}):e.jsx($e,{mark:"bad",title:ne.log.failed,sub:ne.log.failedBody(l.cli,l.host),children:e.jsx("button",{type:"button",onClick:a,className:be({size:"xs",className:"mt-1.5"}),children:ne.retry})})}function rN({job:t,read:n,pr:s,onRetry:a,onClose:r}){var x,d;const l=f.useId(),o=en(s),c=jd(t.durationS),i=((d=(x=n==null?void 0:n.data)==null?void 0:x.log)==null?void 0:d.jobId)===t.id?n.data.log.text:null;return e.jsxs(ht,{labelledBy:l,onClose:r,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Pe,{state:hs[t.status]}),e.jsx("h2",{id:l,className:"text-[15px] font-semibold",children:ne.log.title(t.name)}),e.jsx("span",{className:"text-[12px] text-muted",children:[ne.pipe[t.status],c?c.hours?ne.hours(c.text):c.text:""].filter(Boolean).join(" · ")})]}),e.jsx(Xu,{job:t,read:n,pr:s,onRetry:a,tall:!0}),i!==null&&e.jsx("p",{className:"m-0 text-[12px] leading-4 text-muted",children:[ne.log.note,pg(i)?ne.log.cut(o.host):""].filter(Boolean).join(" ")}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("a",{href:s.url,target:"_blank",rel:"noreferrer",className:be(),children:[e.jsx(z,{name:"external",className:"size-4"}),ne.openOn(o.host)]}),e.jsx("button",{type:"button",onClick:r,className:be(),children:ne.close})]})]})}function lN({text:t}){return e.jsx("div",{className:"text-[13.5px] leading-5",children:t.split(/\n\n+/).map((n,s)=>{const a=n.split(`
|
|
24
|
-
`);return a.every(r=>r.startsWith("- "))?e.jsx("ul",{className:"mt-1 list-disc pl-[18px]",children:a.map((r,l)=>e.jsx("li",{children:r.slice(2)},l))},s):e.jsx("p",{className:"m-0 whitespace-pre-wrap",children:n},s)})})}const oN={approved:"idle",changes:"perm",pending:"plain"};function iN({d:t}){const n="text-muted",s="m-0 flex min-w-0 flex-wrap items-center gap-1.5";return e.jsxs("dl",{className:"m-0 grid grid-cols-[auto_1fr] gap-x-3.5 gap-y-1.5 border-t border-line pt-2.5 text-[13px]",children:[e.jsx("dt",{className:n,children:ne.author}),e.jsx("dd",{className:s,children:t.author}),t.reviewers.map((a,r)=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:n,children:r===0?ne.reviewers:""}),e.jsxs("dd",{className:s,children:[e.jsx(Pe,{state:oN[a.state]}),a.name," ",e.jsx("span",{className:"text-muted",children:ne.reviewer[a.state]})]})]},a.name)),t.labels.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:n,children:ne.labels}),e.jsx("dd",{className:s,children:t.labels.map(a=>e.jsx("span",{className:"rounded-full border border-line px-2 text-[12px]",children:a},a))})]}),t.issues.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:n,children:ne.issue}),e.jsx("dd",{className:`${s} font-mono text-[12px]`,children:t.issues.join(" ")})]})]})}function cN({conds:t,host:n}){return e.jsxs("section",{"aria-label":ne.toMerge,className:"flex-none overflow-hidden rounded-[10px] border border-line bg-surface dark:bg-transparent",children:[e.jsx("div",{className:"flex min-h-11 items-center border-b border-line px-3",children:e.jsx("b",{className:"text-[14px] font-semibold",children:ne.toMerge})}),e.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-2.5 text-[13px]",children:t.map((s,a)=>e.jsxs("li",{"data-cond":s.ok?"ok":s.key,className:"flex items-baseline gap-2",children:[e.jsx("span",{"aria-hidden":"true",className:`w-3.5 flex-none text-center text-[12px] font-semibold ${s.ok?"text-ok":"text-approval"}`,children:s.ok?"✓":"✕"}),e.jsx("span",{className:s.key==="raw"?"font-mono":"",children:Es(s,n)})]},a))})]})}function dN(t,n){const s=Ua(t),a=s.find(o=>!o.ok);if(a)return e.jsxs(e.Fragment,{children:[ne.footApprovals(yd(t.pr))," · ",e.jsx("b",{className:"font-medium text-fg",children:zr(Es(a,n),a)})]});const r=s.find(o=>o.key==="pipeline"||o.key==="noCi"),l=s.find(o=>o.key==="approved");return`${Es(r,n)} · ${zr(Es(l,n),l)}`}function Yu(){const t="block animate-[ledge-pulse_1.6s_ease-in-out_infinite] rounded-[10px] bg-raised";return e.jsxs("div",{role:"status",className:"flex flex-col gap-1.5",children:[e.jsx("span",{"aria-hidden":"true",className:`${t} h-11`}),e.jsx("span",{"aria-hidden":"true",className:`${t} h-11`}),e.jsx("span",{"aria-hidden":"true",className:`${t} h-[60px]`}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ne.detailLoading})]})}function uN({pr:t,job:n,store:s}){const a=me(s),r=Id(t,a.sessions),[l,o]=f.useState(null),[c,i]=f.useState(!1),[x,d]=f.useState(null),m=f.useId();if(!r.length)return e.jsx("p",{className:"m-0 text-[12px] leading-4 text-muted",children:ne.noSession(t.branch)});const p=r.find(N=>N.id===l)??r[0],g=a.fresh,h=()=>{d(s.reply(p.id,ne.fixText(t.ref,n))?{id:p.id,name:p.name}:"refused")};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{type:"button",disabled:!g,onClick:h,className:be({tone:"dangerfill",className:"flex-1"}),children:ne.askFix(p.name)}),r.length>1&&e.jsx("button",{type:"button","aria-label":ne.otherSession,title:ne.otherSession,"aria-haspopup":"menu",disabled:!g,onClick:()=>i(!0),className:be({className:"w-12 !px-0"}),children:e.jsx(z,{name:"down",className:"size-4"})})]}),x==="refused"&&e.jsx($e,{mark:"bad",title:u.agents.notSent,onClose:()=>d(null),closeLabel:ne.close}),x&&x!=="refused"&&e.jsx($e,{mark:"ok",title:ne.sentTo(x.name),onClose:()=>d(null),closeLabel:ne.close,children:e.jsx("a",{href:ce({name:"thread",sessionId:x.id}),className:be({size:"xs",className:"mt-1.5"}),children:ne.openAgent(x.name)})}),c&&e.jsxs(ht,{labelledBy:m,onClose:()=>i(!1),children:[e.jsx("h2",{id:m,className:"sr-only",children:ne.otherSession}),e.jsx("div",{role:"menu","aria-labelledby":m,className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:r.map((N,k)=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":N.id===p.id,onClick:()=>{o(N.id),i(!1)},className:"flex min-h-12 items-center gap-3 border-b border-line px-3.5 text-left text-[15px] last:border-b-0 aria-checked:bg-secondary",children:[e.jsx(Pe,{state:ms(N)}),e.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[N.name," ",e.jsx("small",{className:"text-[12px] text-muted",children:[u.tools[N.tool],N.repo].filter(Boolean).join(" · ")})]}),k===0&&e.jsx("span",{className:"text-[12px] text-muted",children:ne.mostActive})]},N.id))})]})]})}function mN({pr:t,confirm:n,live:s,onRerun:a,onClose:r}){return e.jsxs(an,{title:ne.rerunTitle(t.ref),onClose:r,children:[e.jsx("p",{className:"m-0 text-[12.5px] leading-[18px] text-muted",children:ne.rerunBody(en(t).host)}),e.jsx(On,{verb:ne.rerun,confirm:n,disabled:!s,onClick:()=>{r(),a()}}),e.jsx(Xs,{onClose:r})]})}function xN({pr:t,read:n,store:s,live:a,onJob:r,onLog:l,onRerun:o,side:c}){const i=n==null?void 0:n.data,x=en(t),d=i?bd(i.jobs):null,m=t.state!=="merged"&&t.state!=="closed",p=t.pipeline==="none"?ne.noCi:i!=null&&i.mergeBlockers.includes("pipeline_not_started")?ne.notStarted:null;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"m-0 text-[15px] font-semibold",children:ne.pipelineTitle}),e.jsx(Ad,{pipeline:t.pipeline,short:!0}),e.jsx("span",{className:"flex-1"}),gg(t)&&e.jsxs("button",{type:"button",disabled:!a,onClick:o,className:be({size:"sm"}),children:[e.jsx(z,{name:"refresh",className:"size-4"}),ne.rerun]})]}),p&&e.jsx("p",{className:"m-0 text-[12px] text-muted",children:p}),i?e.jsxs(e.Fragment,{children:[i.jobs.length>0&&(c?e.jsx(sN,{pr:t,jobs:i.jobs,selected:(d==null?void 0:d.id)??null,onJob:r}):e.jsx(eN,{pr:t,jobs:i.jobs,selected:(d==null?void 0:d.id)??null,onJob:r})),d&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center gap-2 text-[12px] text-muted",children:e.jsx("span",{children:`${ne.log.title(d.name)} · ${ne.log.lines}`})}),e.jsx(Xu,{job:d,read:n,pr:t,onRetry:()=>l(d)}),m&&e.jsx(uN,{pr:t,job:d.name,store:s})]}),m&&e.jsx(cN,{conds:Ua(i),host:x.host}),i.description&&e.jsxs("div",{className:"flex flex-col gap-1.5 border-t border-line pt-2.5",children:[e.jsx("h2",{className:"m-0 text-[15px] font-semibold",children:ne.description}),e.jsx(lN,{text:i.description})]}),e.jsx(iN,{d:i})]}):e.jsx(Yu,{})]})}function pN({read:t,pr:n,pc:s,onRetry:a}){const r=en(n);return t.error==="unavailable"?e.jsx($e,{mark:"warn",title:ne.gone(r.kind,s),sub:ne.goneBody}):t.error==="too_large"?e.jsx($e,{mark:"bad",title:ne.tooLarge,sub:ne.tooLargeBody(r.host),children:e.jsx("a",{href:n.url,target:"_blank",rel:"noreferrer",className:be({size:"xs",className:"mt-1.5"}),children:ne.open})}):e.jsx($e,{mark:"bad",title:ne.readFailed(r.cli,r.kind),sub:ne.readFailedBody,children:e.jsx("button",{type:"button",onClick:a,className:be({size:"xs",className:"mt-1.5"}),children:ne.retry})})}function fN({d:t,pc:n,confirm:s,live:a,onMerge:r,onClose:l}){return e.jsxs(an,{title:ne.confirm(t.pr.ref,t.pr.target),onClose:l,children:[e.jsx("span",{className:"text-[12.5px] text-muted",children:ne.runsOn(n)}),e.jsx("code",{className:"block rounded-md bg-raised px-2 py-1.5 font-mono text-[12px] break-all",children:t.mergeCommand}),e.jsx("p",{className:"m-0 text-[12px] leading-4 text-muted",children:ne.headRead(vl(t.pr.headSha))}),e.jsx(On,{verb:ne.merge,confirm:s,disabled:!a,onClick:()=>{l(),r()}}),e.jsx(Xs,{onClose:l})]})}const hN=(t,n)=>t.filter(s=>s.prId===n&&(s.action.kind==="merge"||s.action.kind==="rerun")).at(-1),gN=t=>!!t&&(t.phase==="checking"||t.phase==="sending"||t.phase==="received");function bN({id:t,forge:n,store:s,pane:a=!1}){var fe,he,w,O,V,Z;const r=Qa(n),l=me(s),[o,c]=f.useState(!1),[i,x]=f.useState(!1),{pc:d,look:m}=zt(),p=Dt(),g=Ky()&&p&&!a,[h,N]=f.useState("overview"),[k,C]=f.useState(null),j=m==="offline",y=Jt(d),b=r.details[t],M=r.state&&[...r.state.prs,...r.state.mine??[]].find(X=>X.id===t),S=M??((fe=b==null?void 0:b.data)==null?void 0:fe.pr),$=Hu(b==null?void 0:b.data,s);f.useEffect(()=>{n.readDetail(t)},[n,t]);const v=b!=null&&b.data?bd(b.data.jobs):null,A=f.useRef(null);f.useEffect(()=>{var X,J;!v||((J=(X=b==null?void 0:b.data)==null?void 0:X.log)==null?void 0:J.jobId)===v.id||A.current===v.id||(A.current=v.id,n.readDetail(t,v.id))},[n,t,v==null?void 0:v.id,(w=(he=b==null?void 0:b.data)==null?void 0:he.log)==null?void 0:w.jobId]);const R=f.useRef(null);f.useEffect(()=>{var X,J;(J=(X=R.current)==null?void 0:X.scrollTo)==null||J.call(X,{top:0})},[h]);const _=`tab-main flex min-h-0 flex-1 flex-col gap-2.5 overflow-y-auto overscroll-contain pb-[18px] ${p?"px-[22px] pt-[18px]":"pt-3"}`;if(!S)return e.jsx("main",{"data-tab-scroll":"",className:_,children:r.state?e.jsx($e,{mark:"warn",title:ne.gone(ne.kind[((O=r.state.forges.find(X=>X.host===t.split("/")[0]))==null?void 0:O.forge)??"github"],y),sub:ne.goneBody}):e.jsx(Wt,{lead:e.jsx(gs,{className:"text-muted"}),children:e.jsx("span",{children:ne.loading})})});const L=en(S),T=b==null?void 0:b.data,B=S.state==="merged"||S.state==="closed",E=!!r.state&&!M,P=k&&T?T.jobs.find(X=>X.id===k):void 0,W=X=>{n.readDetail(t,X.id)},F=hN(r.runs,t),re=gN(F),Y=l.fresh&&!j,H=()=>{T&&n.act(t,{kind:"merge",headSha:T.pr.headSha})},I=g?Yy:Xy,D=I.includes(h)?h:"overview",Q=e.jsxs(e.Fragment,{children:[e.jsx(wn,{body:ne.offlineBody}),E&&!F&&e.jsx($e,{mark:"warn",title:ne.gone(L.kind,y),sub:ne.goneBody}),F&&e.jsx(zl,{run:F,pr:S,detail:T,forge:n,pc:y,onReload:()=>n.readDetail(t)}),(b==null?void 0:b.error)&&!T&&e.jsx(pN,{read:b,pr:S,pc:y,onRetry:()=>n.readDetail(t)}),(b==null?void 0:b.cut)&&e.jsx(Wt,{lead:e.jsx(z,{name:"alert",className:"mt-px size-4 text-muted"}),children:e.jsx("span",{children:ne.cut(L.host)})}),e.jsxs("div",{className:`flex flex-col ${g?"gap-4":"gap-2.5"} ${j?"opacity-50":""}`,children:[D==="overview"&&(!(b!=null&&b.error)||T)&&e.jsx(xN,{pr:S,read:b,store:s,live:Y&&!re&&!E,side:g,onJob:X=>{C(X.id),W(X)},onLog:W,onRerun:()=>x(!0)}),D!=="overview"&&!T&&!(b!=null&&b.error)&&e.jsx(Yu,{}),D==="discussion"&&T&&e.jsx(Ti,{detail:T,forge:n,store:s,live:Y&&!E,pc:y}),D==="changes"&&T&&e.jsx(Fy,{detail:T}),D==="commits"&&T&&e.jsx(zy,{detail:T})]})]}),q=e.jsxs("span",{"data-foot":"done",className:`flex min-w-0 flex-1 flex-wrap items-center gap-1.5 leading-4 text-muted ${p?"text-[12.5px]":"text-[12px]"}`,children:[e.jsx("span",{className:"inline-flex h-[22px] items-center rounded-full border border-input px-[9px] text-[12px] font-medium",children:ne.state[S.state]}),S.state==="merged"?ne.mergedInto(S.target,Ur(S.updatedAt)):Ur(S.updatedAt)]}),K=e.jsx("span",{"data-foot":"why",className:`min-w-0 flex-1 leading-4 text-muted ${p?"text-[12.5px]":"text-[12px]"}`,children:T?dN(T,L.host):ne.footApprovals(yd(S))}),ee=e.jsxs("button",{type:"button",disabled:!Y||E||re||!T||!hg(T),onClick:()=>c(!0),className:be(p?{tone:"primary",size:"sm",className:"flex-none"}:{tone:"primary",className:"h-[42px]"}),children:[e.jsx(z,{name:"merge",className:"size-4"}),ne.merge]}),ue=p?"flex flex-none items-center gap-2.5 border-t border-line bg-sidebar px-[18px] py-2.5":"flex flex-none items-center gap-2.5 border-t border-line bg-sidebar px-3.5 py-[9px]";return e.jsxs(e.Fragment,{children:[e.jsx(Gy,{pr:S,landscape:g}),e.jsx(Qy,{pr:S,d:T,view:D,views:I,onView:N,wide:p}),g?e.jsxs("div",{className:"grid min-h-0 flex-1 grid-cols-[minmax(0,1fr)_320px]",children:[e.jsx("main",{ref:R,"data-tab-scroll":"",className:"tab-main flex min-h-0 min-w-0 flex-col gap-4 overflow-y-auto overscroll-contain px-[22px] py-[18px]",children:Q}),e.jsxs("aside",{"aria-labelledby":`disc-${t}`,"data-pr-discussion":"",className:"flex min-h-0 min-w-0 flex-col border-l border-line",children:[e.jsxs("div",{className:"flex h-12 flex-none items-center gap-2 border-b border-line px-3.5",children:[e.jsx("h2",{id:`disc-${t}`,className:"m-0 text-[15px] font-semibold",children:ne.tabs.discussion}),T&&T.threads.length>0&&e.jsx("span",{className:"text-[12.5px] text-muted",children:ne.discSub($.open.length,$.resolved.length)})]}),e.jsx("div",{className:`flex min-h-0 flex-1 flex-col gap-2.5 overflow-y-auto overscroll-contain p-3 ${j?"opacity-50":""}`,children:T&&e.jsx(Ti,{detail:T,forge:n,store:s,live:Y&&!E,pc:y,column:$})}),!B&&e.jsx("div",{className:"flex flex-none border-t border-line px-3 py-2.5",children:e.jsx(Ai,{pr:S,forge:n,store:s,live:Y&&!E,pc:y})})]})]}):e.jsx("main",{ref:R,"data-tab-scroll":"",className:_,children:Q}),e.jsx("footer",{className:ue,children:g?e.jsxs(e.Fragment,{children:[B?q:K,e.jsx(Uu,{all:$,className:"flex-none"}),!B&&ee]}):D==="discussion"&&!B?e.jsx(Ai,{pr:S,forge:n,store:s,live:Y&&!E,pc:y}):B?q:e.jsxs(e.Fragment,{children:[K,ee]})}),i&&e.jsx(mN,{pr:S,confirm:!!((V=l.device)!=null&&V.confirm),live:Y,onRerun:()=>{n.act(t,{kind:"rerun"})},onClose:()=>x(!1)}),o&&T&&e.jsx(fN,{d:T,pc:y,confirm:!!((Z=l.device)!=null&&Z.confirm),live:Y,onMerge:H,onClose:()=>c(!1)}),P&&e.jsx(rN,{job:P,read:b,pr:S,onRetry:()=>W(P),onClose:()=>C(null)})]})}function jN(t){const[,n]=f.useReducer(s=>s+1,0);return f.useEffect(()=>{const s=t.subscribe(n);return n(),s},[t]),t.state()}function yN(t){const[,n]=f.useReducer(s=>s+1,0);return f.useEffect(()=>{if(!t)return;const s=t.subscribe(n);return n(),s},[t]),{build:(t==null?void 0:t.current())??null,waiting:(t==null?void 0:t.waiting())??null}}function NN(t){var s;const[,n]=f.useReducer(a=>a+1,0);return f.useEffect(()=>t==null?void 0:t.subscribe(n),[t]),((s=t==null?void 0:t.getState().state)==null?void 0:s.prs)??[]}function kN(t,n){const[s,a]=f.useState(null);return f.useEffect(()=>{if(!n){a(null);return}let r=!0;return t("/auth/me",{credentials:"same-origin",cache:"no-store"}).then(async l=>l.ok?Im.safeParse(await l.json()):null).then(l=>{r&&(l!=null&&l.success)&&a(l.data.login)}).catch(()=>{}),()=>{r=!1}},[t,n]),s}const vN=(t,n)=>globalThis.fetch(t,n),wN=t=>t.name==="request"?{name:"request",sessionId:t.sessionId,key:t.key}:t.name==="ask"?{name:"ask",id:t.id}:null;function SN({link:t,store:n,storage:s,fetchImpl:a=vN,updates:r=null,signin:l=null,lost:o=!1,relay:c=globalThis.location.host}){var ct,xt,G,Ee,we,le;const i=Di(),x=jN(t),d=me(n),m=Ps(),p=kN(a,x!=="signed_out"),{build:g,waiting:h}=yN(r),[N,k]=f.useState(null),[C,j]=f.useState(l),[y,b]=f.useState(o),[M,S]=f.useState(!1),[$,v]=f.useState(!1),[A,R]=f.useState(!1),_=f.useRef(!1),[L,T]=f.useState(!1),B=((ct=t.pairing())==null?void 0:ct.state())??null,E=((xt=t.recovery())==null?void 0:xt.state())??null,P=(E==null?void 0:E.step)==="reaching"||(E==null?void 0:E.step)==="faceid"||(E==null?void 0:E.step)==="checking",W=xn(),[F,re]=f.useState(!1),[Y,H]=f.useState(!1),I=(E==null?void 0:E.step)==="done"&&(!d.fresh||ii((G=d.device)==null?void 0:G.push));f.useEffect(()=>{I&&H(!0)},[I]),f.useEffect(()=>{E&&E.step!=="done"&&H(!1)},[E==null?void 0:E.step]);const D=t1(C),Q=C==="not_allowed"?"denied":x==="signed_out"||D||C==="another"?"login":x==="replaced"?"replaced":x==="key_changed"?"keyChanged":x==="denied"?"unrecognized":x==="storage_unavailable"?"storage":(E==null?void 0:E.step)==="done"&&!$?"recover":(B==null?void 0:B.step)==="linked"&&!$?"compare":x==="unpaired"||x==="pairing"?B!==null||L||x==="pairing"&&!P?"compare":E&&E.step!=="cancelled"?"recover":"choose":"route",q=ge=>{_.current=!0,T(!0),ge()},K=()=>{re((E==null?void 0:E.step)==="failed"&&E.why==="old"),q(()=>t.startPairing())};f.useEffect(()=>{x==="ready"&&(_.current=!1,T(!1),b(!1),S(!1)),(x==="unpaired"||x==="pairing")&&(v(!1),R(!1))},[x]),f.useEffect(()=>{var et;const ge=(et=globalThis.navigator)==null?void 0:et.serviceWorker;if(!ge)return;const Be=vt=>Jm(vt.data);return ge.addEventListener("message",Be),()=>ge.removeEventListener("message",Be)},[]);const ee=f.useRef("sessions"),ue=f.useRef([]),fe=ml(m);fe&&(ee.current=fe),f.useEffect(()=>{cp(m)},[m]);const he=Dt(),w=lu(n),[O,V]=f.useState(null);f.useEffect(()=>{const ge=P1(t,n,s);return V(ge),()=>{ge.close(),V(null)}},[t,n,s]);const[Z,X]=f.useState(null);f.useEffect(()=>{const ge=_y(t,n,s);return ge.follow(),X(ge),()=>{ge.close(),X(null)}},[t,n,s]);const J=NN(Z),pe=m.name==="atelier"&&(!he||(d.fresh||d.daemon!==null)&&!((Ee=d.daemon)!=null&&Ee.atelier));f.useEffect(()=>{pe&&An({name:"sessions"})},[pe]);const Ne=wN(m),Xe=f.useRef(!1),gt=x==="ready"&&d.fresh&&!!((we=d.device)!=null&&we.id)&&!d.device.name;f.useEffect(()=>{!gt||Xe.current||n.renameDevice(hu(void 0))!==null&&(Xe.current=!0)},[gt,n]);const ze=t.pinned(),Je=(ze==null?void 0:ze.name)??null,oe=(ze==null?void 0:ze.name)??((le=d.daemon)==null?void 0:le.name)??null,de=()=>t.retry(),ke=f.useRef(!1),Oe=ge=>{if(!ke.current){if(x!=="ready"){x!=="denied"&&S(!0),ge();return}ke.current=!0,n.forgetDevice().then(Be=>{ke.current=!1,Be||S(!0),ge()})}},lt=()=>Oe(()=>{t.signOut()}),mt=()=>Oe(()=>q(()=>{t.relink()})),kt=(()=>{var bt,wt,Yt,js;switch(Q){case"denied":return e.jsx(Qj,{onOther:()=>j("another")});case"login":return e.jsx(s1,{server:c,error:D});case"replaced":return e.jsx(a1,{onHere:()=>globalThis.location.reload()});case"keyChanged":return e.jsx(Jj,{pcName:oe,known:ze,received:t.receivedKey(),onRelink:mt,onSignOut:lt});case"unrecognized":return e.jsx(T1,{pcName:oe,onRelink:mt,onSignOut:lt});case"storage":return e.jsx(c1,{onRetry:de,onReload:()=>globalThis.location.reload()});case"choose":return e.jsx(oj,{login:p,platform:W,onPasskey:()=>t.startRecovery(),onCode:K});case"recover":return e.jsx(uj,{state:E,login:p,reach:t.reach(),onRetry:()=>{var nt;(nt=t.recovery())!=null&&nt.again()||t.startRecovery()},onCode:K,onCancel:()=>t.cancelRecovery(),onSignOut:lt,onDone:()=>v(!0),actions:Y?e.jsx(ci,{store:n,fetchImpl:a,body:u.recover.done.notify,onDone:()=>v(!0)}):void 0});case"compare":return e.jsx(rj,{step:B,login:p,pcName:Je,lost:y,stalled:x==="unpaired"&&B===null&&L,reach:t.reach(),onRetry:de,onSame:()=>{var nt;return(nt=t.pairing())==null?void 0:nt.confirmOnPhone()},onCancel:()=>{var nt;return(nt=t.pairing())==null?void 0:nt.cancel()},onRestart:()=>q(()=>t.startPairing()),onDone:()=>v(!0),actions:A?e.jsx(ci,{store:n,fetchImpl:a,onDone:()=>{R(!1),v(!0)}}):e.jsx(xj,{store:n,update:F,onDone:()=>{var nt;ii((nt=d.device)==null?void 0:nt.push)?R(!0):v(!0)}})})}const ge=ro(kn([...d.sessions.values()]),d.asks??[]);Ne&&ge.some(nt=>JSON.stringify(nt)===JSON.stringify(Ne))&&(ue.current=ge);const Be=nt=>()=>{const Rt=Ns=>Ns.name===nt.name,ys=Ax(ro(kn([...n.getState().sessions.values()]),n.getState().asks??[]).filter(Rt),nt,ue.current.filter(Rt));An(ys??(nt.name==="ask"?{name:"rigs"}:{name:"sessions"}))},et={pc:oe,look:mp(d.fresh,!!d.syncedAt,t.reach()),reach:t.reach(),since:Ke(d.syncedAt),retry:de,settingsDot:w},vt=!!((bt=d.daemon)!=null&&bt.forge)&&Z!==null,Vt=vt?ug(J):0,tn={sessions:dp(kn([...d.sessions.values()]),(wt=d.daemon)!=null&&wt.taskAnswer?yl(d.tasks.values()).length:0),rigs:up(d.asks??[]),prs:Vt?{text:Vt>99?"99+":String(Vt),tone:"red"}:null},Gt=vt?e.jsx(Iy,{forge:Z,store:n}):e.jsx(o1,{}),Xt=vt&&m.name==="pr"?e.jsx(bN,{id:m.id,forge:Z,store:n,pane:!1},m.id):null,U=e.jsx(sj,{store:n,filter:m.name==="sessions"?m.filter:void 0}),Se=!!((Yt=d.daemon)!=null&&Yt.rigs)&&O!==null,ie=Se?e.jsx(G1,{rigs:O,store:n}):e.jsx(i1,{store:n}),Ie=Se?m.name==="rig"?e.jsx(dy,{rig:m.rig,rigs:O,store:n},m.rig):m.name==="kernel"?e.jsx(ky,{rigs:O,store:n}):m.name==="max"?e.jsx(by,{goalId:m.goalId,rigs:O,store:n},m.goalId??""):null:null,Ce=(m.name==="connection"&&m.section==="usage"?e.jsx(bj,{store:n}):null)??e.jsx(Yj,{store:n,fetchImpl:a,login:p,relay:c,pinned:ze,linkState:x,build:g,onSignOut:lt,section:m.name==="connection"&&m.section==="link"?"link":void 0});if(he){const nt=(()=>{var Rt;switch(m.name){case"ask":return e.jsx(rn,{list:ie,detail:e.jsx(xi,{store:n,id:m.id,onDone:Be({name:"ask",id:m.id})},m.id)});case"request":return e.jsx(rn,{tab:"sessions",list:U,detail:e.jsx(Ir,{store:n,sessionId:m.sessionId,requestKey:m.key,onReconnect:de,onSettled:Be({name:"request",sessionId:m.sessionId,key:m.key}),keys:!0},m.sessionId)});case"sessions":return e.jsx(rn,{tab:"sessions",list:U,detail:e.jsx(io,{...u.split.agent})});case"routines":return e.jsx(rn,{tab:"sessions",list:U,detail:e.jsx(ei,{store:n,focus:m.routine})});case"thread":return e.jsx(rn,{tab:"sessions",list:U,detail:e.jsx(Wr,{store:n,sessionId:m.sessionId,storage:s,onReconnect:de,forge:Z},m.sessionId)});case"launch":return e.jsx(rn,{tab:"sessions",list:U,detail:e.jsx(vi,{store:n,storage:s})});case"terminal":return e.jsx(rn,{tab:"sessions",fold:!0,list:U,detail:e.jsx(gi,{store:n,link:t,sessionId:m.sessionId,storage:s,forge:Z},m.sessionId)});case"prs":case"pr":return e.jsx(rn,{tab:"prs",list:Gt,detail:Xt??e.jsx(mi,{icon:"pr",...u.prs.pane})});case"rigs":case"rig":case"kernel":case"max":return e.jsx(rn,{list:ie,detail:Ie??e.jsx(mi,{icon:"rigs",...u.rigs.pane})});case"atelier":return(Rt=d.daemon)!=null&&Rt.atelier?e.jsx(Mb,{store:n,...m.sessionId?{sessionId:m.sessionId}:{},...m.requestKey?{requestKey:m.requestKey}:{},storage:s,onReconnect:de}):e.jsx(rn,{list:U,detail:e.jsx(io,{...u.split.agent})});case"connection":return Ce}})();return e.jsxs(lr,{value:et,children:[nt,e.jsx(fp,{route:m,active:fe??"settings",badges:tn,atelier:!!((js=d.daemon)!=null&&js.atelier)})]})}const qe=(nt,Rt=!0)=>e.jsxs(lr,{value:et,children:[Rt&&e.jsx(xp,{...typeof Rt=="string"?{title:Rt}:{}}),nt,e.jsx(pp,{route:m,active:fe??ee.current,badges:tn})]});switch(m.name){case"sessions":case"atelier":return qe(U);case"routines":return qe(e.jsx(ei,{store:n,focus:m.routine},m.routine??""));case"prs":return qe(Gt,vt?u.prs.title:!0);case"pr":return Xt?qe(Xt,!1):qe(Gt,vt?u.prs.title:!0);case"rigs":return qe(ie,Se?u.rigs.title:!0);case"rig":case"kernel":case"max":return Ie?qe(Ie,!1):qe(ie,Se?u.rigs.title:!0);case"connection":return qe(Ce,!1);case"thread":return qe(e.jsx(Wr,{store:n,sessionId:m.sessionId,storage:s,onReconnect:de,forge:Z},m.sessionId),!1);case"terminal":return qe(e.jsx(gi,{store:n,link:t,sessionId:m.sessionId,storage:s,forge:Z},m.sessionId),!1);case"ask":return qe(e.jsx(xi,{store:n,id:m.id},m.id),!1);case"launch":return e.jsx(lr,{value:et,children:e.jsx(vi,{store:n,storage:s})});case"request":return qe(e.jsx(Ir,{store:n,sessionId:m.sessionId,requestKey:m.key,onReconnect:de},m.sessionId),!1)}})();return e.jsx(Tm,{copy:Am(i).ui,children:e.jsxs("div",{className:"app flex flex-col","data-route":m.name,children:[M&&x!=="ready"&&e.jsx("p",{role:"status",className:"mx-4 my-3 text-body text-muted",children:u.forget.pending}),kt,r&&h&&h.fingerprint!==N&&e.jsx(I1,{next:h,current:g,onLater:()=>k(h.fingerprint),onApply:()=>r.accept()})]})})}const RN=Object.freeze(Object.defineProperty({__proto__:null,App:SN},Symbol.toStringTag,{value:"Module"}));export{RN as A,EN as M,h1 as R,_N as a};
|
|
15
|
+
`).slice(0,Bc)+"…":w})}):e.jsx("a",{href:P,className:`block text-body [overflow-wrap:anywhere] ${s.kind==="question"?"":"font-semibold"} ${X?"line-clamp-3":""}`,children:w}),pe=(oe,de=!1)=>e.jsx("p",{className:`text-small [overflow-wrap:anywhere] ${de?"text-destructive":"text-muted"}`,role:de?"alert":void 0,children:oe}),Ne=v==="cancelled"?u.confirm.cancelled:v==="prepareFailed"?u.confirm.prepareFailed:v==="failed"?u.confirm.failed:null,Xe=(()=>{switch(a.kind){case"examine":return e.jsxs("a",{href:P,className:rt({size:"sm",className:"self-start"}),children:[u.cards.examine,e.jsx(z,{name:"chevron",className:"size-4"})]});case"readOnly":return pe(u.decide.readOnly);case"answerOnPc":return pe(u.decide.answerOnPc);case"permission":return L?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D({kind:"decide",decision:"accept"}),className:V("primary","min-w-[140px]"),children:[q({kind:"decide",decision:"accept"})&&e.jsx(Ct,{}),u.cards.allow]}),e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D({kind:"decide",decision:"deny"}),className:V("outline","min-w-[120px]"),children:[q({kind:"decide",decision:"deny"})&&e.jsx(Ct,{}),u.cards.deny]}),a.always&&e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D({kind:"decide",decision:"always"}),className:rt({variant:"ghost"}),children:[q({kind:"decide",decision:"always"})&&e.jsx(Ct,{}),ga(_r(s))]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D({kind:"decide",decision:"accept"}),className:V("primary"),children:[q({kind:"decide",decision:"accept"})&&e.jsx(Ct,{}),u.cards.allow]}),e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D({kind:"decide",decision:"deny"}),className:V(),children:[q({kind:"decide",decision:"deny"})&&e.jsx(Ct,{}),u.cards.deny]})]}),a.always&&e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D({kind:"decide",decision:"always"}),className:rt({variant:"ghost",className:"-mt-1 self-stretch"}),children:[q({kind:"decide",decision:"always"})&&e.jsx(Ct,{}),ga(_r(s))]})]});case"high":return i?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{type:"button",disabled:!H,onClick:()=>{Q()},className:V("primary"),children:[S||q({kind:"decide",decision:"accept"})?e.jsx(Ct,{}):e.jsx(z,{name:"face",className:"size-[18px]"}),e.jsx("span",{className:"truncate",children:S?u.confirm.checking:Pt()?u.confirm.goApple:u.confirm.go})]}),e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D({kind:"decide",decision:"deny"}),className:V(),children:[q({kind:"decide",decision:"deny"})&&e.jsx(Ct,{}),u.cards.deny]})]}),S&&pe(u.confirm.askingNote)]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{type:"button",disabled:!0,className:V(),children:u.decide.onPc}),e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D({kind:"decide",decision:"deny"}),className:V(),children:[q({kind:"decide",decision:"deny"})&&e.jsx(Ct,{}),u.cards.deny]})]}),pe(u.decide.onPcHint),m&&e.jsx("a",{href:ce({name:"connection",section:"link"}),className:"self-start text-small font-medium underline underline-offset-2",children:u.enroll.link})]});case"question":{const oe=`free-${s.sessionId}`,de=K.problem!==null&&K.problem!=="empty";return e.jsxs(e.Fragment,{children:[a.options.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:a.options.map((ke,Oe)=>{const lt={kind:"reply",text:String(Oe+1),label:ke};return e.jsxs("button",{type:"button",disabled:!H,onClick:()=>D(lt),className:rt({className:"h-auto min-h-11 max-w-full py-2 text-left whitespace-normal [overflow-wrap:anywhere]"}),children:[q(lt)&&e.jsx(Ct,{}),ke]},`${Oe}:${ke}`)})}),a.other&&!j&&a.options.length>0&&e.jsx("button",{type:"button",disabled:!H,onClick:()=>y(!0),className:"self-start text-[13px] font-medium text-muted underline-offset-2 hover:underline disabled:opacity-45",children:u.cards.other}),a.other&&j&&e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:`flex items-center gap-2 rounded-[10px] border bg-surface py-[5px] pr-[5px] pl-3 focus-within:border-ring ${de?"border-destructive":"border-input"}`,children:[e.jsx("label",{htmlFor:oe,className:"sr-only",children:u.question.fieldLabel(B)}),e.jsx("input",{id:oe,value:b,onChange:ke=>M(ke.target.value),placeholder:u.question.placeholder,autoComplete:"off",enterKeyHint:"send","aria-invalid":de,disabled:!l||c,onKeyDown:ke=>{ke.key==="Enter"&&!ke.nativeEvent.isComposing&&(ke.preventDefault(),ee())},className:"h-[34px] min-w-0 flex-1 bg-transparent text-base text-fg outline-none placeholder:text-muted"}),e.jsx("button",{type:"button","aria-label":u.decide.send,title:u.decide.send,disabled:!H||K.problem!==null,onClick:ee,className:"grid size-9 flex-none place-items-center rounded-lg bg-primary text-primary-fg disabled:opacity-40",children:(h==null?void 0:h.kind)==="reply"&&Y&&h.text===K.text?e.jsx(Ct,{}):e.jsx(z,{name:"send",className:"size-[18px]"})})]}),de?pe(K.problem==="long"?u.question.long(il):K.problem==="digit"?u.question.digit:u.question.untypable,!0):pe(u.cards.sendHint(B))]}),!a.other&&a.options.length>0&&pe(u.decide.otherUnsupported)]})}}})(),gt=fe?u.cards.kindName.permission:u.cards.kindName[s.kind];return e.jsxs(Bs,{tone:s.kind==="question"?"ask":s.kind==="permission"?"perm":"plain",selected:x,label:u.cards.region(gt,B,s.repo),children:[Z,ue&&pe(ue,!0),c&&e.jsxs("div",{role:"status",className:"flex items-start gap-2 rounded-md border border-attention/45 px-2.5 py-2 text-small",children:[e.jsx(z,{name:"alert",className:"mt-px size-4 text-attention"}),u.decide.changed]}),J,X&&e.jsx("a",{href:P,className:"-mt-1 self-start text-[13px] font-medium underline-offset-2 hover:underline",children:u.cards.readAll}),he&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-destructive/10 px-2.5 py-2 text-small",children:[e.jsx(z,{name:"alert",className:"mt-px size-4 text-destructive"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("b",{className:"font-semibold",children:he.title}),e.jsx("span",{className:"text-muted",children:he.body})]})]}),c&&e.jsx("button",{type:"button",onClick:t.onReread,className:rt(),children:u.decide.reread}),Ne&&pe(Ne,!0),Xe,Y&&pe(u.decide.sending)]})}function ko(t){queueMicrotask(t)}const bf={low:"Bas",medium:"Moyen",high:"Élevé",xhigh:"Très élevé",max:"Max",ultra:"Ultra"},jf={"claude:fable":"Le plus capable","claude:opus":"Très capable, plus lent","claude:sonnet":"Équilibré, au quotidien","claude:haiku":"Rapide et économique"};function yf(t,n,s){var a;if(n===void 0){const r=s.find(l=>l.isDefault);return r?`${u.model.byDefault} · ${r.label}`:u.model.byDefault}return((a=s.find(r=>r.id===n))==null?void 0:a.label)??n}const Ws=t=>bf[t]??t,qc=(t,n)=>jf[`${t}:${n.id}`]??n.description,Nf=(t,n)=>t.model===n.model&&t.effort===n.effort,kf=t=>!((t.state==="idle"||t.state==="error")&&!t.pending),fl=t=>({model:t.model??null,effort:t.effort??null});function vo(t,n,s){if(t==="cursor")return null;const a=s.model===null?n.find(r=>r.isDefault):n.find(r=>r.id===s.model);return a!=null&&a.efforts&&a.efforts.length>0?a.efforts:null}function vf(t){const n=/^(?:claude-)?(fable|opus|sonnet|haiku)(?:-(\d+)(?:-(\d+))?)?/i.exec(t);return n?[n[1].charAt(0).toUpperCase()+n[1].slice(1).toLowerCase(),n[2]?n[3]?`${n[2]}.${n[3]}`:n[2]:""].filter(Boolean).join(" "):t}const Dr=t=>String(t).padStart(2,"0");function Hc(t){const n=Math.max(0,Math.round(t/1e3));if(n<60)return`${n} s`;const s=Math.floor(n/60);if(s<60)return`${s} min`;const a=Math.floor(s/60);return a<48?`${a} h ${Dr(s%60)}`:`${Math.floor(a/24)} j`}const wf=(t,n)=>t.getFullYear()===n.getFullYear()&&t.getMonth()===n.getMonth()&&t.getDate()===n.getDate(),dr=t=>`${Dr(t.getHours())}:${Dr(t.getMinutes())}`,wo=t=>t.toLocaleDateString(ut,{weekday:"short"}),Sf=168*36e5,hl=(t,n)=>new Date(t).getTime()-n>=Sf;function Uc(t,n,s=!1){const a=new Date(t);if(hl(t,n)){const r=a.toLocaleDateString(ut,{day:"numeric",month:"short"});return s?r:`${r} ${dr(a)}`}return wf(a,new Date(n))?dr(a):s?wo(a):`${wo(a)} ${dr(a)}`}const Cf=t=>t.pct>=100;function za(t,n){return t>=100?"red":n!==null&&t>=n*100?"amber":""}const $f=60*6e4;function Ba(t,n,s=!0){return t.map(a=>{const r=a.readAt===null||n-Date.parse(a.readAt)>$f;return{...a,status:!s&&a.status==="ok"?"stale":a.status,windows:r?[]:a.windows}})}function Mf(t,n,s=Date.now()){return Ba(t,s).flatMap(a=>a.status==="expired"||a.status==="loading"?[]:a.windows.flatMap(r=>{const l=za(r.pct,n);return l?[{harness:a.harness,window:r,tone:l}]:[]}))}function Wc(t,n,s){const a=Date.parse(t.startedAt),r=t.context?Math.min(1,t.context.used/t.context.window):void 0;return{...t.model?{model:vf(t.model)}:{},...t.effort?{effort:Ws(t.effort).toLowerCase()}:{},...r!==void 0?{context:{pct:Math.round(r*100),near:r>=s}}:{},...Number.isFinite(a)&&t.state!=="exited"?{duration:Hc(n-a)}:{}}}function So(t){return t<1e3?String(Math.round(t)):t<1e6?`${Math.round(t/1e3)}k`:`${Number((t/1e6).toFixed(1))}M`}function Ef(t,n,s,a,r){const l=n&&Ba(n,a,r).find(c=>c.harness===t),o=l&&l.status!=="expired"&&l.status!=="loading"?l.windows[0]:void 0;return l&&o?{harness:l.harness,window:o,tone:za(o.pct,s)}:null}const _f='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function Kc(t,n){const s=f.useRef(n);s.current=n,f.useEffect(()=>{const a=t.current;if(!a)return;const r=document.activeElement instanceof HTMLElement?document.activeElement:null;a.focus({preventScroll:!0});const l=o=>{if(o.key==="Escape"){o.preventDefault(),s.current();return}if(o.key!=="Tab")return;const c=[...a.querySelectorAll(_f)],i=c[0],m=c.at(-1);if(!i||!m){o.preventDefault();return}o.shiftKey&&(document.activeElement===i||document.activeElement===a)?(o.preventDefault(),m.focus()):!o.shiftKey&&document.activeElement===m&&(o.preventDefault(),i.focus())};return document.addEventListener("keydown",l),()=>{document.removeEventListener("keydown",l),r!=null&&r.isConnected&&r.focus({preventScroll:!0})}},[t])}function ht({labelledBy:t,onClose:n,children:s}){const a=f.useRef(null);return Kc(a,n),dl.createPortal(e.jsxs("div",{className:"fixed inset-0 z-20",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50","aria-hidden":"true",onClick:n}),e.jsxs("section",{ref:a,role:"dialog","aria-modal":"true","aria-labelledby":t,tabIndex:-1,className:"absolute inset-x-0 bottom-0 mx-auto flex max-w-[480px] flex-col gap-4 rounded-t-[28px] border-t border-line bg-surface px-5 pt-3 pb-[calc(34px+env(safe-area-inset-bottom))] shadow-[var(--shadow-overlay)] outline-none tablet:inset-x-auto tablet:bottom-auto tablet:top-1/2 tablet:left-1/2 tablet:max-h-[calc(100dvh-48px)] tablet:w-[480px] tablet:-translate-x-1/2 tablet:-translate-y-1/2 tablet:overflow-y-auto tablet:rounded-[24px] tablet:border tablet:px-6 tablet:pt-6 tablet:pb-6",children:[e.jsx("span",{className:"h-[5px] w-9 self-center rounded-full bg-muted/40 tablet:hidden","aria-hidden":"true"}),s]})]}),document.body)}const ur="mt-px inline-flex size-4 flex-none items-center justify-center rounded-[4px] border";function Vc({checklist:t,current:n}){var d;const[s,a]=f.useState(!1),{tasks:r,done:l,total:o}=t,c=((d=r.find(x=>x.status==="in_progress"))==null?void 0:d.text)??n??(l===o?u.checklist.allDone:u.checklist.paused),i=r.some(x=>x.status==="in_progress")||!!n,m=f.useMemo(()=>{const x=new Map;return r.map(p=>{const g=x.get(p.text)??0;return x.set(p.text,g+1),g===0?p.text:`${p.text}#${g}`})},[r]);return e.jsxs("div",{className:"sticky top-0 z-10 flex-none bg-bg",children:[e.jsxs("button",{type:"button","aria-expanded":s,onClick:()=>a(x=>!x),className:`flex min-h-11 w-full flex-col gap-1.5 border border-line bg-surface px-3 py-2.5 text-left text-[12px] leading-[18px] text-muted shadow-[0_4px_14px_rgba(0,0,0,.35)] ${s?"rounded-t-card":"rounded-card"}`,children:[e.jsxs("span",{className:"flex w-full items-center gap-2",children:[e.jsx(z,{name:"plan",className:"size-3.5",stroke:1.8}),e.jsx("strong",{className:"font-medium text-fg",children:u.checklist.title}),e.jsx("span",{className:"flex-1"}),e.jsxs("span",{className:"font-mono text-[11px] text-fg",children:[l,"/",o]}),e.jsx("span",{"aria-hidden":"true",className:"h-1 w-16 overflow-hidden rounded-[2px] bg-raised",children:e.jsx("span",{className:"block h-full bg-ok",style:{width:`${o?l/o*100:0}%`}})}),e.jsx("span",{className:s?"-rotate-90":"rotate-90",children:e.jsx(z,{name:"chevron",className:"size-[13px]",stroke:2})})]}),e.jsxs("span",{className:"block w-full truncate",children:[i&&e.jsx("span",{className:"mr-1.5 inline-block size-1.5 rounded-full bg-info align-[1px]"}),c]})]}),s&&e.jsxs("ol",{className:"max-h-[50dvh] overflow-y-auto rounded-b-card border border-t-0 border-line bg-surface px-3 pt-1.5 pb-2.5 text-small",children:[r.map((x,p)=>e.jsxs("li",{className:`flex items-start gap-2.5 py-1.5 [overflow-wrap:anywhere] ${x.status==="completed"?"text-muted line-through":x.status==="in_progress"?"font-medium text-fg":"text-fg"}`,children:[x.status==="completed"&&e.jsx("span",{role:"img","aria-label":u.checklist.box.completed,className:`${ur} border-ok/50 font-mono text-[10px] font-semibold text-ok no-underline`,children:"✓"}),x.status==="in_progress"&&e.jsx("span",{role:"img","aria-label":u.checklist.box.in_progress,className:`${ur} border-info`,children:e.jsx("svg",{className:"size-2.5 text-info motion-safe:animate-spin",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})})}),x.status==="pending"&&e.jsx("span",{role:"img","aria-label":u.checklist.box.pending,className:`${ur} border-fg/25`}),x.text]},m[p])),t.cut&&e.jsx("li",{className:"py-1.5 text-meta text-muted",children:u.checklist.cut})]})]})}function Na({name:t,legend:n,options:s,value:a,onChange:r,fit:l=!1}){return e.jsxs("fieldset",{className:`m-0 min-w-0 border-0 p-0${l?" self-start":""}`,"data-fit":l||void 0,children:[e.jsx("legend",{className:"sr-only",children:n}),e.jsx("div",{className:`${l?"inline-flex":"grid auto-cols-fr grid-flow-col"} gap-1 rounded-control bg-raised p-1`,children:s.map(o=>e.jsxs("label",{lang:o.lang,className:`flex min-h-10 cursor-pointer items-center justify-center rounded-[9px] ${l?"px-3.5":"px-2"} text-body font-medium text-muted transition-colors duration-100 has-[:checked]:bg-fg has-[:checked]:text-bg has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-info`,children:[e.jsx("input",{type:"radio",name:t,value:o.value,checked:a===o.value,onChange:()=>r(o.value),className:"sr-only"}),o.label]},o.value))})]})}const gl="model-sheet-title",Rf="flex min-h-12 w-full items-center gap-3 rounded-control border border-line bg-surface px-3 py-2.5 text-left active:bg-raised aria-pressed:border-fg/40 aria-pressed:bg-raised";function Gc({tool:t,models:n,error:s,current:a,pick:r,onPick:l,note:o,actions:c,defaultHint:i=u.model.defaultHint}){var h;const m=!a||a.model===null||n.some(N=>N.id===a.model),d=vo(t,n,r),x=N=>{const k=vo(t,n,{model:N});l({model:N,effort:r.effort!==null&&(k!=null&&k.includes(r.effort))?r.effort:null})},p=(N,k,C)=>e.jsxs("button",{type:"button","aria-pressed":r.model===N,onClick:()=>x(N),className:Rf,children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-body font-medium",children:k}),C&&e.jsx("span",{className:"block text-meta text-muted",children:C})]}),(a==null?void 0:a.model)===N&&e.jsx("span",{className:"flex-none rounded-full bg-raised px-2 py-0.5 text-meta text-muted",children:u.model.current})]},N??""),g=d&&(r.effort??((h=n.find(N=>r.model===null?N.isDefault:N.id===r.model))==null?void 0:h.defaultEffort)??"");return e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("h2",{id:gl,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:u.model.title}),e.jsx("p",{className:"mt-1 text-meta text-muted",children:u.model.subtitle(u.tools[t]??t)})]}),s&&e.jsx("p",{role:"status",className:"text-meta text-attention",children:u.model.listError}),e.jsxs("div",{className:"flex max-h-[45vh] flex-col gap-1.5 overflow-y-auto",children:[p(null,u.model.byDefault,i),!m&&(a==null?void 0:a.model)!=null&&p(a.model,a.model,void 0),n.map(N=>p(N.id,N.label,qc(t,N)))]}),d&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-body font-medium",children:[u.model.effortTitle," ",e.jsx("span",{className:"text-meta font-normal text-muted",children:u.model.effortHint})]}),e.jsx("div",{className:"mt-2",children:e.jsx(Na,{name:"model-effort",legend:u.model.effortTitle,value:g??"",onChange:N=>l({model:r.model,effort:N}),options:d.map(N=>({value:N,label:Ws(N)}))})})]}),o&&e.jsx("p",{className:"text-small whitespace-pre-line text-muted",children:o}),c]})}const Xc={models:[]},Yc=t=>t.modelNext?{model:t.modelNext.model??null,effort:t.modelNext.effort??null}:fl(t),Vn=(t,n)=>!!(t!=null&&t.models)&&n.canSwitch===!0;function Tf({store:t,session:n}){const{daemon:s,models:a,fresh:r}=xe(t),[l,o]=f.useState(!1),c=Vn(s,n);if(f.useEffect(()=>{c&&t.requestModels(n.tool)},[c,t,n.tool]),!c)return null;const i=a[n.tool]??Xc,m=n.modelNext?Yc(n):null,d=m??fl(n),x=[yf(n.tool,d.model??void 0,i.models),d.effort?Ws(d.effort):null].filter(Boolean).join(" · ");return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:!r,"aria-haspopup":"dialog","aria-label":u.model.chip(m?`${x}, ${u.model.nextTurn}`:x),onClick:()=>{t.requestModels(n.tool),o(!0)},className:`${Oi()} gap-2 whitespace-nowrap`,children:[e.jsx("span",{children:x}),m&&e.jsx("span",{className:"text-meta font-normal text-attention",children:u.model.nextTurn})]}),l&&e.jsx(qa,{store:t,session:n,onClose:()=>o(!1)})]})}function Af({store:t,session:n}){const{daemon:s,modelFailures:a}=xe(t),r=a[n.id];return!Vn(s,n)||!r?null:e.jsx("p",{role:"status",className:"pb-2 text-meta text-attention",children:u.model.failedLine(u.model.failed[r])})}function qa({store:t,session:n,onClose:s}){const{models:a}=xe(t),r=a[n.tool]??Xc,l=fl(n),[o,c]=f.useState(Yc(n)),[i,m]=f.useState(!1),[d,x]=f.useState(null),p=async h=>{m(!0),x(null);const N=await t.changeModel(n.id,h.model,h.effort);if(m(!1),N.status==="applied"){s();return}if(N.status==="expired"){x(u.model.uncertain);return}const k=N.status==="rejected"?N.reason:null;x(k&&k in u.model.failed?u.model.failed[k]:u.model.notApplied)},g=kf(n);return e.jsx(ht,{labelledBy:gl,onClose:s,children:e.jsx(Gc,{tool:n.tool,models:r.models,error:r.error,current:l,pick:o,onPick:c,note:g?u.model.noteWorking(n.name):u.model.noteIdle(n.name),actions:e.jsxs(e.Fragment,{children:[d&&e.jsx("p",{role:"alert",className:"text-meta text-attention",children:d}),n.modelNext&&e.jsx(Pe,{variant:"outline",disabled:i,onClick:()=>void p(l),children:u.model.cancelPending}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Pe,{variant:"ghost",className:"flex-1",onClick:s,children:u.model.cancel}),e.jsx(Pe,{variant:"primary",className:"flex-[2]",disabled:i||Nf(o,l),onClick:()=>void p(o),children:u.model.apply})]})]})})})}const If=1e4;function Qc(t,n){const s=u.sessions.modelOff;return Vn(t,n)?null:n.state==="exited"?s.ended:t!=null&&t.models?s.outside:s.olderPc}function Lf(t,n){const s=r=>{var l;return t.rig?((l=r.rig)==null?void 0:l.name)===t.rig.name:!r.rig&&r.project===t.project},a=[...n].filter(r=>s(r)&&r.state!=="exited").map(r=>r.id);return{name:t.rig?u.sessions.rigGroup(t.rig.name):t.project,ids:a}}function cn({icon:t,label:n,why:s,right:a,onClick:r,danger:l=!1}){const o=!r;return e.jsxs("button",{type:"button",disabled:o,onClick:r,className:`flex min-h-12 w-full items-center gap-3 border-b border-line px-3.5 py-2 text-left text-[15px] last:border-b-0 disabled:opacity-60 ${l?"text-danger-fg":"text-fg"}`,children:[e.jsx(z,{name:t,className:`size-5 ${l?"text-danger-fg":"text-muted"}`}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{children:n}),s&&e.jsx("small",{className:"text-small text-muted",children:s})]}),a!=null&&e.jsx("span",{className:"ml-auto flex-none text-[12.5px] text-muted",children:a})]})}const $s=({children:t})=>e.jsx("div",{className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:t});function bl({store:t,session:n,closable:s,closing:a,onClose:r,onModel:l,onCloseSession:o,display:c,lead:i,who:m,order:d}){var I,D,Q;const x=xe(t),p=Kt(),g=f.useId(),[h,N]=f.useState("menu"),[k,C]=f.useState(!1),j=u.sessions,y=n.name,b=x.fresh,S=[Wc(n,p,1).model,n.effort?Ws(n.effort):null].filter(Boolean).join(" · "),$=Qc(x.daemon,n),v=(I=x.daemon)!=null&&I.checklist?x.checklists.get(n.id):void 0,A=!!n.pending||n.state==="waiting_permission"||n.state==="waiting_input",R=n.state==="working",_=Object.values(x.ops).filter(q=>q.message.type==="session.interrupt"&&q.message.id===n.id).sort((q,K)=>q.at.localeCompare(K.at)).at(-1),L=_!==void 0&&yn(_.phase),T=(_==null?void 0:_.phase)==="applied"&&(!R||p-Date.parse(_.at)<If),B=R&&b&&!A&&!L&&!T,E=u.terminal,P=L||T?null:b?A?E.why.waiting:R?null:E.why.idle:E.why.offline,W=(_==null?void 0:_.phase)==="sending"?E.sending:T?E.sent:E.interrupt(y),F=(_==null?void 0:_.phase)==="rejected"&&_.reason==="read_only"?E.readOnly:k||(_==null?void 0:_.phase)==="rejected"||(_==null?void 0:_.phase)==="failed"?E.fail:null,re=Lf(n,x.sessions.values()),Y=!!((D=x.daemon)!=null&&D.broadcast)&&re.ids.length>1,H=m??[n.project,n.branch].filter(Boolean).join(" · ");return e.jsxs(ht,{labelledBy:g,onClose:r,children:[e.jsxs("h2",{id:g,"aria-label":j.sheet.label(y),className:"flex min-w-0 items-center gap-2",children:[e.jsx(Xn,{tool:n.tool}),e.jsx("b",{className:"font-semibold whitespace-nowrap",children:y}),H&&e.jsx("span",{className:"min-w-0 truncate text-small font-normal text-muted",children:H})]}),h==="plan"&&v?e.jsxs(e.Fragment,{children:[e.jsx(Vc,{checklist:v,...(Q=n.checklist)!=null&&Q.current?{current:n.checklist.current}:{}}),e.jsx("button",{type:"button",onClick:()=>N("menu"),className:"h-11 rounded-lg border border-input text-body",children:u.nav.back})]}):h==="group"?e.jsx(lc,{store:t,label:re.name,ids:re.ids,offline:!b,startOpen:!0,onCancel:()=>N("menu")}):e.jsxs(e.Fragment,{children:[i&&i.length>0&&e.jsx($s,{children:i.map(q=>e.jsx(cn,{icon:q.icon,label:q.label,onClick:q.onClick},q.label))}),d&&d.length>0&&e.jsx($s,{children:d.map(q=>e.jsx(cn,{icon:q.icon,label:q.label,onClick:q.onClick},q.label))}),e.jsxs($s,{children:[e.jsx(cn,{icon:"cpu",label:u.model.title,why:$,right:S||null,onClick:$||!b?void 0:l}),c&&e.jsx(cn,{icon:"terminal",label:u.terminal.live2.view,right:c.value,onClick:c.onToggle}),v&&e.jsx(cn,{icon:"list",label:u.checklist.title,right:j.sheet.planCount(v.done,v.total),onClick:()=>N("plan")}),e.jsx(cn,{icon:"stop",label:W,why:F??P,onClick:B?()=>C(!t.interrupt(n.id)):void 0}),Y&&e.jsx(cn,{icon:"send",label:j.sheet.writeGroup(re.name),onClick:b?()=>N("group"):void 0})]}),s&&n.state!=="exited"&&e.jsx($s,{children:e.jsx(cn,{icon:"power",danger:!0,label:a?u.sessionEnd.closingNamed(y):u.sessionEnd.close(y),right:Pt()&&!a?e.jsx("span",{"aria-hidden":"true",children:j.sheet.faceId}):null,onClick:a?void 0:o})}),e.jsx("p",{className:"text-meta text-muted",children:j.sheet.interruptNote})]})]})}function Of({name:t,up:n,down:s,onClose:a}){const r=f.useId(),l=u.sessions.reorder;return e.jsxs(ht,{labelledBy:r,onClose:a,children:[e.jsx("h2",{id:r,className:"flex min-w-0 items-center gap-2",children:e.jsx("b",{className:"truncate font-semibold",children:t})}),e.jsxs($s,{children:[e.jsx(cn,{icon:"arrowUp",label:l.up,onClick:n?()=>{n(),a()}:void 0}),e.jsx(cn,{icon:"arrowDown",label:l.down,onClick:s?()=>{s(),a()}:void 0})]})]})}const Fr=t=>`ledge.mobile.draft.${t}`;function Zc(t,n){var s;try{return((s=Ze(n))==null?void 0:s.getItem(Fr(t)))??""}catch{return""}}function Jc(t,n,s){try{const a=Ze(s);n===""?a==null||a.removeItem(Fr(t)):a==null||a.setItem(Fr(t),n)}catch{}}const ed="ledge.mobile.draft.cleared",Df=50;function td(t){var n;try{const s=JSON.parse(((n=Ze(t))==null?void 0:n.getItem(ed))??"[]");return Array.isArray(s)?s.filter(a=>typeof a=="string"):[]}catch{return[]}}function Ff(t,n){return td(n).includes(t)}function Pf(t,n){var s;try{const a=td(n).filter(r=>r!==t);(s=Ze(n))==null||s.setItem(ed,JSON.stringify([...a,t].slice(-Df)))}catch{}}let Pr=null;const zf=t=>{Pr=t};function Bf(t){return Pr!==t?!1:(Pr=null,!0)}function qf(t,n,s){const a=Zc(t,s);Jc(t,a.startsWith(n)?a:n+a,s),zf(t)}const Hf=["image/png","image/gif","image/jpeg","image/webp"],Uf=25e6,Wf=[.85,.7,.55,.4],Co=640,Kf=.8,Vf=[.7,.5],Gf={async decode(t){const n=await createImageBitmap(t);let s=null;const a=()=>{s&&(s.width=s.height=0),s=null};return{width:n.width,height:n.height,close:()=>{a(),n.close()},async draw(r,l){a();const o=s=document.createElement("canvas");o.width=r,o.height=l;const c=o.getContext("2d");if(!c)throw new Error("no canvas");return c.imageSmoothingQuality="high",c.drawImage(n,0,0,r,l),{encode:(i,m)=>new Promise((d,x)=>o.toBlob(p=>p?d(p):x(new Error("no blob")),i,m))}}}}},nd=(t,n,s)=>{const a=Math.min(1,s/Math.max(t,n));return{w:Math.max(1,Math.round(t*a)),h:Math.max(1,Math.round(n*a))}};async function sd(t,n){let s=await t.encode("image/webp",n);return s.type==="image/webp"||s.type==="image/jpeg"?{blob:s,mime:s.type}:(s=await t.encode("image/jpeg",n),{blob:s,mime:"image/jpeg"})}const ad=t=>new Promise((n,s)=>{const a=new FileReader;a.onload=()=>n(String(a.result).slice(String(a.result).indexOf(",")+1)),a.onerror=()=>s(a.error),a.readAsDataURL(t)});async function Xf(t,n=Gf){var a;if(!Hf.includes(t.type))return{ok:!1,reason:"notImage"};if(t.size>Uf)return{ok:!1,reason:"tooLarge"};let s;try{s=await n.decode(t)}catch{return{ok:!1,reason:"unreadable"}}try{let r=Math.min(sx,Math.max(s.width,s.height));for(;;){const{w:l,h:o}=nd(s.width,s.height,r),c=await s.draw(l,o);for(const i of Wf){const{blob:m,mime:d}=await sd(c,i);if(m.size>ax)continue;const x={mime:d,data:await ad(m)},p=await Yf(s);return p&&(x.preview=p),{ok:!0,value:{image:x,width:l,height:o,bytes:m.size}}}if(r<=Co)return{ok:!1,reason:"tooLarge"};r=Math.max(Co,Math.round(r*Kf))}}catch{return{ok:!1,reason:"unreadable"}}finally{(a=s.close)==null||a.call(s)}}async function Yf(t){try{return await Qf(t)}catch{return}}async function Qf(t){const{w:n,h:s}=nd(t.width,t.height,rx),a=await t.draw(n,s);for(const r of Vf){const{blob:l,mime:o}=await sd(a,r);if(l.size<=lx)return{mime:o,data:await ad(l)}}}function Zf(t,n){if(t>=1e6){const s=(Math.round(t/1e5)/10).toFixed(1);return`${n==="fr"?s.replace(".",","):s} ${n==="fr"?"Mo":"MB"}`}return`${Math.round(t/1e3)} ${n==="fr"?"Ko":"KB"}`}function Jf({items:t,onRemove:n,size:s,removeLabel:a,lang:r}){return t.length===0?null:e.jsx("div",{"data-attachment-chips":!0,style:{display:"flex",flexWrap:"wrap",gap:8},children:t.map(l=>e.jsxs("div",{"data-chip":l.state,title:l.reason,style:{position:"relative",width:s.w,height:s.h,flexShrink:0,borderRadius:"var(--radius-md)",overflow:"hidden",border:`1px solid ${l.state==="refused"?"var(--danger-text)":"var(--border)"}`,background:"var(--well)"},children:[e.jsx("img",{src:l.url,alt:"",draggable:!1,style:{width:"100%",height:"100%",objectFit:"cover",display:"block",opacity:l.state==="ready"?1:.45}}),l.state==="uploading"&&e.jsx("span",{role:"status","aria-label":"…",style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",style:{color:"var(--foreground)"},children:e.jsx("path",{d:"M12 3a9 9 0 1 1-9 9",opacity:"0.9",children:e.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.9s",repeatCount:"indefinite"})})})}),l.state==="refused"&&e.jsx("span",{style:{position:"absolute",left:0,right:0,bottom:0,padding:"2px 4px",fontSize:10,lineHeight:1.2,color:"var(--danger-text)",background:"var(--status-danger-soft)"},children:l.reason}),l.state!=="refused"&&e.jsx("span",{style:{position:"absolute",left:4,bottom:4,padding:"1px 5px",borderRadius:4,fontSize:10,lineHeight:1.3,color:"#fff",background:"rgba(0,0,0,0.6)"},children:Zf(l.bytes,r)}),e.jsx("button",{type:"button","aria-label":a,title:a,onClick:()=>n(l.key),style:{position:"absolute",top:3,right:3,width:20,height:20,padding:0,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:10,border:"none",cursor:"pointer",color:"#fff",background:"rgba(0,0,0,0.6)"},children:e.jsx(cs,{...ss.close,size:12})})]},l.key))})}function eh({url:t,failed:n,width:s,height:a,maxW:r,maxH:l,alt:o,unavailable:c,onOpen:i}){const m=Math.min(1,r/s,l/a),d={width:Math.round(s*m),height:Math.round(a*m),maxWidth:"100%",borderRadius:"var(--radius-lg)",border:"1px solid var(--border)",background:"var(--well)",boxSizing:"border-box",overflow:"hidden"};return n?e.jsx("div",{"data-thumb":"failed",style:{...d,display:"flex",alignItems:"center",justifyContent:"center",padding:8,fontSize:12,color:"var(--muted-foreground)",textAlign:"center"},children:c}):t?e.jsx("button",{type:"button","data-thumb":"ready",onClick:i,style:{...d,padding:0,display:"block",cursor:"zoom-in"},children:e.jsx("img",{src:t,alt:o,draggable:!1,style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})}):e.jsx("div",{"data-thumb":"loading","aria-busy":"true",style:d})}function th({onFiles:t,disabled:n,className:s,children:a}){const r=f.useRef(null);return e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:r,type:"file",accept:"image/*",multiple:!0,hidden:!0,tabIndex:-1,"aria-hidden":"true",onChange:l=>{t([...l.target.files??[]]),l.target.value=""}}),e.jsx("button",{type:"button",disabled:n,"aria-label":a?void 0:u.images.attach,title:u.images.attach,onClick:()=>{var l;return(l=r.current)==null?void 0:l.click()},className:s??Ot({variant:"outline",round:!0}),children:a??e.jsx(z,{name:"plus"})})]})}const nh=t=>{var n;return[...((n=t.clipboardData)==null?void 0:n.files)??[]].filter(s=>s.type.startsWith("image/"))},$o=44,sh=120,rd=()=>{var t;return((t=globalThis.matchMedia)==null?void 0:t.call(globalThis,"(hover: hover) and (pointer: fine)").matches)===!0};function ah({id:t,label:n,sendLabel:s,value:a,onChange:r,onSend:l,canSend:o,oneLine:c,images:i,placeholder:m,disabled:d=!1,attachDisabled:x,maxLength:p,invalid:g=!1,describedBy:h,fieldRef:N}){const k=f.useRef(null),C=N??k;f.useLayoutEffect(()=>{const y=C.current;y&&(y.style.height=`${$o}px`,y.style.height=`${Math.min(sh,Math.max($o,y.scrollHeight+y.offsetHeight-y.clientHeight))}px`)},[a,C]);const j=x??d;return e.jsxs("div",{className:"flex flex-col gap-2",children:[i.items.length>0&&e.jsx(Jf,{items:i.items,onRemove:i.remove,size:{w:72,h:54},removeLabel:u.images.remove,lang:ox}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx(th,{onFiles:i.add,disabled:j}),e.jsx("label",{htmlFor:t,className:"sr-only",children:n}),e.jsx("textarea",{id:t,ref:C,rows:1,value:a,disabled:d,placeholder:m,maxLength:p,enterKeyHint:c?"send":"enter","aria-invalid":g,"aria-describedby":h,onChange:y=>r(y.target.value),onPaste:y=>{const b=nh(y);b.length===0||j||(y.preventDefault(),i.add(b))},onKeyDown:y=>{y.key!=="Enter"||y.nativeEvent.isComposing||!c&&(y.shiftKey||!rd())||(y.preventDefault(),o&&l())},className:"max-h-[120px] min-h-11 min-w-0 flex-1 resize-none rounded-[22px] border border-input bg-surface px-3.5 py-[11px] text-base leading-5 text-fg placeholder:text-muted disabled:opacity-60"}),e.jsx("button",{type:"button",disabled:!o,onClick:l,"aria-label":s,title:s,className:Ot({variant:"primary",round:!0}),children:e.jsx(z,{name:"arrowUp"})})]})]})}const rh={anthropic:{d:"M4.709 15.955l4.72-2.647.08-.23-.08-.128H9.2l-.79-.048-2.698-.073-2.339-.097-2.266-.122-.571-.121L0 11.784l.055-.352.48-.321.686.06 1.52.103 2.278.158 1.652.097 2.449.255h.389l.055-.157-.134-.098-.103-.097-2.358-1.596-2.552-1.688-1.336-.972-.724-.491-.364-.462-.158-1.008.656-.722.881.06.225.061.893.686 1.908 1.476 2.491 1.833.365.304.145-.103.019-.073-.164-.274-1.355-2.446-1.446-2.49-.644-1.032-.17-.619a2.97 2.97 0 01-.104-.729L6.283.134 6.696 0l.996.134.42.364.62 1.414 1.002 2.229 1.555 3.03.456.898.243.832.091.255h.158V9.01l.128-1.706.237-2.095.23-2.695.08-.76.376-.91.747-.492.584.28.48.685-.067.444-.286 1.851-.559 2.903-.364 1.942h.212l.243-.242.985-1.306 1.652-2.064.73-.82.85-.904.547-.431h1.033l.76 1.129-.34 1.166-1.064 1.347-.881 1.142-1.264 1.7-.79 1.36.073.11.188-.02 2.856-.606 1.543-.28 1.841-.315.833.388.091.395-.328.807-1.969.486-2.309.462-3.439.813-.042.03.049.061 1.549.146.662.036h1.622l3.02.225.79.522.474.638-.079.485-1.215.62-1.64-.389-3.829-.91-1.312-.329h-.182v.11l1.093 1.068 2.006 1.81 2.509 2.33.127.578-.322.455-.34-.049-2.205-1.657-.851-.747-1.926-1.62h-.128v.17l.444.649 2.345 3.521.122 1.08-.17.353-.608.213-.668-.122-1.374-1.925-1.415-2.167-1.143-1.943-.14.08-.674 7.254-.316.37-.729.28-.607-.461-.322-.747.322-1.476.389-1.924.315-1.53.286-1.9.17-.632-.012-.042-.14.018-1.434 1.967-2.18 2.945-1.726 1.845-.414.164-.717-.37.067-.662.401-.589 2.388-3.036 1.44-1.882.93-1.086-.006-.158h-.055L4.132 18.56l-1.13.146-.487-.456.061-.746.231-.243 1.908-1.312-.006.006z",fill:"#D97757",rule:"nonzero"},openai:{d:"M9.205 8.658v-2.26c0-.19.072-.333.238-.428l4.543-2.616c.619-.357 1.356-.523 2.117-.523 2.854 0 4.662 2.212 4.662 4.566 0 .167 0 .357-.024.547l-4.71-2.759a.797.797 0 00-.856 0l-5.97 3.473zm10.609 8.8V12.06c0-.333-.143-.57-.429-.737l-5.97-3.473 1.95-1.118a.433.433 0 01.476 0l4.543 2.617c1.309.76 2.189 2.378 2.189 3.948 0 1.808-1.07 3.473-2.76 4.163zM7.802 12.703l-1.95-1.142c-.167-.095-.239-.238-.239-.428V5.899c0-2.545 1.95-4.472 4.591-4.472 1 0 1.927.333 2.712.928L8.23 5.067c-.285.166-.428.404-.428.737v6.898zM12 15.128l-2.795-1.57v-3.33L12 8.658l2.795 1.57v3.33L12 15.128zm1.796 7.23c-1 0-1.927-.332-2.712-.927l4.686-2.712c.285-.166.428-.404.428-.737v-6.898l1.974 1.142c.167.095.238.238.238.428v5.233c0 2.545-1.974 4.472-4.614 4.472zm-5.637-5.303l-4.544-2.617c-1.308-.761-2.188-2.378-2.188-3.948A4.482 4.482 0 014.21 6.327v5.423c0 .333.143.571.428.738l5.947 3.449-1.95 1.118a.432.432 0 01-.476 0zm-.262 3.9c-2.688 0-4.662-2.021-4.662-4.519 0-.19.024-.38.047-.57l4.686 2.71c.286.167.571.167.856 0l5.97-3.448v2.26c0 .19-.07.333-.237.428l-4.543 2.616c-.619.357-1.356.523-2.117.523zm5.899 2.83a5.947 5.947 0 005.827-4.756C22.287 18.339 24 15.84 24 13.296c0-1.665-.713-3.282-1.998-4.448.119-.5.19-.999.19-1.498 0-3.401-2.759-5.947-5.946-5.947-.642 0-1.26.095-1.88.31A5.962 5.962 0 0010.205 0a5.947 5.947 0 00-5.827 4.757C1.713 5.447 0 7.945 0 10.49c0 1.666.713 3.283 1.998 4.448-.119.5-.19 1-.19 1.499 0 3.401 2.759 5.946 5.946 5.946.642 0 1.26-.095 1.88-.309a5.96 5.96 0 004.162 1.713z",fill:"currentColor",rule:"evenodd"},cursor:{d:"M22.106 5.68L12.5.135a.998.998 0 00-.998 0L1.893 5.68a.84.84 0 00-.419.726v11.186c0 .3.16.577.42.727l9.607 5.547a.999.999 0 00.998 0l9.608-5.547a.84.84 0 00.42-.727V6.407a.84.84 0 00-.42-.726zm-.603 1.176L12.228 22.92c-.063.108-.228.064-.228-.061V12.34a.59.59 0 00-.295-.51l-9.11-5.26c-.107-.062-.063-.228.062-.228h18.55c.264 0 .428.286.296.514z",fill:"currentColor",rule:"evenodd"}},lh={claude:"anthropic",codex:"openai",cursor:"cursor"};function oh({harness:t,size:n=14}){const{d:s,fill:a,rule:r}=rh[lh[t]];return e.jsx("svg",{className:`harness-${t} inline-block flex-none`,width:n,height:n,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:s,fill:a,fillRule:r})})}function jl(t){const n=u.limits;switch(t.kind){case"five_hour":return n.five;case"seven_day":return n.week;case"month":return n.month;case"pool":return t.pool==="other"?n.poolOther:n.poolCursor;default:return n.model(t.model??"")}}const ih={"":"",amber:"bg-attention",red:"bg-approval"},ch={"":"",amber:"text-attention",red:"text-approval"};function dh({pct:t,alert:n}){const s=za(t,n);return e.jsx("span",{className:"block h-[5px] overflow-hidden rounded-[2px]",style:{background:"var(--u-track)"},children:e.jsx("span",{className:`block h-full rounded-[2px] ${ih[s]}`,style:{width:`${Math.min(100,t)}%`,...s?{}:{background:"var(--u-gauge)"}}})})}function uh({label:t,w:n,now:s,alert:a,roomy:r=!1}){const l=u.limits,o=za(n.pct,a),c=n.resetsAt?Uc(n.resetsAt,s):null;return e.jsxs("div",{className:`grid ${r?"grid-cols-[58px_minmax(0,1fr)_auto]":"grid-cols-[58px_1fr_128px]"} items-center gap-2 py-[3px] text-small`,children:[e.jsx("span",{children:t}),e.jsx(dh,{pct:n.pct,alert:a}),e.jsxs("span",{className:`${r?"whitespace-nowrap":"truncate"} font-mono text-[12px]`,children:[e.jsx("b",{className:`font-medium ${ch[o]}`,children:u.percent(n.pct)}),c&&e.jsx("small",{className:"ml-1.5 text-[11px] text-muted",children:Cf(n)?n.resetsAt&&hl(n.resetsAt,s)?l.resumesOn(c):l.resumes(c):`↺ ${c}`})]})]})}function xh({usage:t,now:n,alert:s,fresh:a=!0,heading:r=!0}){const l=u.limits,o=Ba(t,n,a);if(!o.length)return null;const c=i=>t[i].harness==="cursor"&&t[i].status==="ok"&&t[i].windows.length===0&&t[i].readAt!==null;return e.jsxs("div",{role:"group","aria-label":l.limitsLabel,className:"flex flex-col",children:[r&&e.jsx("h3",{className:"mt-1 text-meta tracking-[.4px] text-muted",children:l.limits}),o.map((i,m)=>{const d=i.readAt?Hc(n-Date.parse(i.readAt)):null,x=i.status==="stale"||i.status==="unreachable";return e.jsxs("div",{"data-harness":i.harness,className:"flex flex-col",children:[e.jsxs("div",{className:"mt-1.5 mb-0.5 flex items-baseline gap-1.5 text-small font-semibold",children:[e.jsx(oh,{harness:i.harness}),l.harness[i.harness]??i.harness]}),i.status==="loading"&&e.jsx("p",{className:"py-1 text-small text-muted",children:l.loading}),i.status==="expired"&&e.jsx("p",{className:"py-1 text-small text-attention",children:l.notOnPc(l.harness[i.harness]??i.harness)}),i.status==="ok"&&c(m)&&e.jsx("p",{className:"py-1 text-small text-muted",children:l.unread}),i.status!=="loading"&&i.status!=="expired"&&i.windows.length>0&&e.jsx("div",{className:x?"opacity-50":void 0,children:i.windows.map(p=>e.jsx(uh,{label:jl(p),w:p,now:n,alert:s,roomy:!r},`${p.kind}:${p.model??p.pool??""}`))}),i.status==="stale"&&d&&e.jsx("p",{className:"py-1 text-small text-attention",children:l.stale(d)}),i.status==="unreachable"&&e.jsx("p",{className:"py-1 text-small text-attention",children:d?l.unreach(d):l.unreachNever})]},i.harness)})]})}const ld=t=>t.state==="done"||t.state==="refused"||t.state==="dropped",mh=t=>t.owner===ix;function yl(t){return[...t].filter(n=>mh(n)&&!ld(n)&&!n.routine).sort((n,s)=>n.at.localeCompare(s.at))}const xr=We({variant:"primary",size:"sm",className:"min-w-[64px] flex-none"}),Js=We({size:"sm",className:"min-w-[64px] flex-none"}),mr="w-full rounded-control border border-line bg-surface px-2.5 py-2 text-body text-fg",Jn=t=>t.replace(/\s*[\r\n]+\s*/g," ").trim();function ph({task:t,store:n,fresh:s}){const a=u.cards.note,r=t.brain,l=f.useId(),[o,c]=f.useState(!1),[i,m]=f.useState(r.fact),[d,x]=f.useState(r.title??r.note),[p,g]=f.useState(r.when??""),[h,N]=f.useState(!1),[k,C]=f.useState(null),j=async M=>{N(!0),C(null);const S=Jn(i),$=M?{yes:M,...S&&S!==r.fact?{text:S}:{},...r.create&&Jn(d)?{title:Jn(d)}:{},...r.create&&Jn(p)?{when:Jn(p)}:{}}:{yes:M},v=await n.answerNote(t.id,$);N(!1),v.status!=="applied"&&C(v.status==="rejected"&&v.reason==="confirm_required"?a.confirmRequired:v.status==="rejected"&&v.reason==="stale"?a.stale:v.status==="cancelled"?a.cancelled:v.status==="expired"?a.expired:a.failed)},y=r.kind==="flag"?a.flag(r.note):r.create?a.create(r.note):a.add(r.note),b=!s||h;return e.jsxs("div",{className:"flex flex-col gap-2 rounded-control bg-raised p-2.5","data-note-proposal":t.id,children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-1.5 text-body",children:[e.jsx(qs,{tone:"attention",label:a.tag}),e.jsx("span",{className:"font-medium",children:t.giverName??u.cards.someone}),e.jsx("span",{className:"text-muted",children:y})]}),r.create&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{htmlFor:`${l}t`,className:"flex flex-col gap-1 text-small text-muted",children:[a.titleField,e.jsx("input",{id:`${l}t`,className:mr,value:d,disabled:b,onChange:M=>x(M.target.value)})]}),e.jsxs("label",{htmlFor:`${l}w`,className:"flex flex-col gap-1 text-small text-muted",children:[a.whenField,e.jsx("input",{id:`${l}w`,className:mr,value:p,disabled:b,onChange:M=>g(M.target.value)})]})]}),o?e.jsxs("label",{htmlFor:`${l}f`,className:"flex flex-col gap-1 text-small text-muted",children:[a.field,e.jsx("textarea",{id:`${l}f`,className:mr,rows:3,value:i,disabled:b,onChange:M=>m(M.target.value)})]}):e.jsx("p",{className:"m-0 whitespace-pre-wrap break-words rounded-control bg-surface px-2.5 py-2 text-body",children:r.fact}),r.source&&!o&&e.jsx("span",{className:"break-words text-small text-muted",children:a.source(r.source)}),k&&e.jsx("p",{role:"alert",className:"m-0 text-small text-approval",children:k}),e.jsx("div",{className:"flex flex-wrap gap-2",children:r.kind==="flag"?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:xr,disabled:b,onClick:()=>{j(!0)},children:a.mark}),e.jsx("button",{type:"button",className:Js,disabled:b,onClick:()=>{j(!1)},children:a.ignore})]}):o?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:xr,disabled:b||!Jn(i),onClick:()=>{j(!0)},children:a.editYes}),e.jsx("button",{type:"button",className:Js,disabled:b,onClick:()=>{c(!1),m(r.fact)},children:a.cancel})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:xr,disabled:b,onClick:()=>{j(!0)},children:r.create?a.createYes:a.yes}),e.jsx("button",{type:"button",className:Js,disabled:b,onClick:()=>c(!0),children:a.edit}),e.jsx("button",{type:"button",className:Js,disabled:b,onClick:()=>{j(!1)},children:a.no})]})})]})}const Mo=t=>We({variant:t,block:!0}),fh=3e3,hh=(t,n)=>yl(t).filter(s=>s.giver===n);function Eo({store:t,session:n,tasks:s,sent:a,onSent:r}){var _;const l=xe(t),o=mn(),c=u.decide,i=u.cards,m=f.useId(),d=r;f.useEffect(()=>{if(a===null)return;const L=setTimeout(()=>r(null),fh);return()=>clearTimeout(L)},[a,r]);const x=s[0],[p,g]=f.useState(""),[h,N]=f.useState(!1),[k,C]=f.useState(null);if(f.useEffect(()=>{g(""),C(null)},[x==null?void 0:x.id]),!(a??(x==null?void 0:x.id)))return null;const y=(x==null?void 0:x.giverName)??n.name,b=(L,T)=>e.jsxs("span",{className:"flex flex-wrap items-center gap-1.5 text-body",children:[e.jsx(qs,{tone:"attention",label:L}),e.jsx("span",{className:"font-medium",children:y}),e.jsx("span",{className:"text-muted",children:T}),s.length>1&&!a&&e.jsx("span",{className:"ml-auto text-small text-muted",children:c.ofN(1,s.length)})]}),M=L=>e.jsx("footer",{"aria-label":i.decision,className:"flex flex-none flex-col gap-2.5 border-t border-line bg-bg pt-3 pb-4",children:L}),S=!(((_=l.device)==null?void 0:_.confirm)===!0&&o),$=e.jsxs(e.Fragment,{children:[e.jsx(De,{title:i.note.confirmRequired,tone:"warning",role:"alert"}),e.jsx("a",{href:ce({name:"connection"}),className:Mo(),children:c.openSettings})]}),v=!l.fresh&&e.jsx(De,{title:c.offlineHint,tone:"warning",role:"status"});if(a!==null){const L=l.tasks.get(a);return M(e.jsxs(e.Fragment,{children:[b(i.decision,i.asks),L&&e.jsx("b",{className:"text-title font-semibold",children:L.title}),e.jsxs("p",{role:"status",className:"flex items-center gap-2 rounded-control border border-ok/40 px-3 py-2.5 text-body",children:[e.jsx(z,{name:"check",className:"size-4 text-ok"}),c.sent((L==null?void 0:L.giverName)??y)]})]}))}if(!x)return null;if(x.brain){const L=x;if(S){const T=L.brain;return M(e.jsxs(e.Fragment,{children:[b(i.note.tag,T.kind==="flag"?i.note.flag(T.note):T.create?i.note.create(T.note):i.note.add(T.note)),e.jsxs("p",{className:"text-body",children:["« ",T.fact," »"]}),T.source&&e.jsx("span",{className:"text-small text-muted",children:i.note.source(T.source)}),$]}))}return M(e.jsxs(e.Fragment,{children:[s.length>1&&e.jsx("span",{className:"self-end text-small text-muted",children:c.ofN(1,s.length)}),e.jsx(ph,{task:L,store:t,fresh:l.fresh},x.id),v||e.jsx("p",{className:"text-center text-meta text-muted",children:u.sessionEnd.check})]}))}const A=async()=>{const L=p.trim();if(!L||h)return;N(!0),C(null);const T=await t.answerTask(x.id,L);if(N(!1),T.status==="applied"){d(x.id);return}C(T.status==="rejected"&&(T.reason==="stale"||T.reason==="not_found")?"stale":T.status==="cancelled"?"cancelled":T.status==="expired"?"expired":"failed")},R=k==="stale"?e.jsx(De,{title:u.gone.titleElsewhere,tone:"warning",role:"alert"}):k?e.jsx(De,{title:k==="cancelled"?u.confirm.cancelled:k==="expired"?u.confirm.expired:i.note.failed,tone:"warning",role:"alert"}):null;return M(e.jsxs(e.Fragment,{children:[b(i.decision,i.asks),e.jsx("b",{className:"text-title font-semibold",children:x.title}),x.text&&e.jsx("p",{className:"text-body whitespace-pre-wrap text-muted",children:x.text}),S?$:k==="stale"?R:e.jsxs(e.Fragment,{children:[e.jsx("label",{htmlFor:m,className:"sr-only",children:i.answerLabel(x.title)}),e.jsx("textarea",{id:m,rows:2,value:p,disabled:h||!l.fresh,placeholder:u.cards.answerPlaceholder,onChange:L=>g(L.target.value),className:"w-full resize-none rounded-control border border-line bg-surface px-3 py-2.5 text-body text-fg"}),R,v,e.jsx("button",{type:"button",disabled:h||!l.fresh||!p.trim(),onClick:()=>{A()},className:Mo("primary"),children:c.send}),!v&&e.jsx("p",{className:"text-center text-meta text-muted",children:u.sessionEnd.check})]})]}))}const gh=new RegExp("(?<code>`[^`\\n]+`)|\\*\\*(?<b>\\S(?:.*?\\S)?)\\*\\*(?!\\*)|(?<![\\w*])\\*(?<i>[^\\s*](?:[^*\\n]*?[^\\s*])?)\\*(?![\\w*])","g"),Nl=f.createContext(void 0);function un(t,n=0,s){let a=0;const r=c=>s?[e.jsx(f.Fragment,{children:s(c)},`t${a++}`)]:[c];if(n>2)return r(t);const l=[];let o=0;for(const c of t.matchAll(gh)){const i=c.index;i>o&&l.push(...r(t.slice(o,i)));const m=c.groups;m.code?l.push(e.jsx("code",{className:"rounded-md bg-fg/[0.06] px-[5px] py-px font-mono text-[.92em] [overflow-wrap:anywhere]",children:m.code.slice(1,-1)},i)):m.b?l.push(e.jsx("strong",{className:"font-semibold",children:un(m.b,n+1,s)},i)):l.push(e.jsx("em",{children:un(m.i,n+1,s)},i)),o=i+c[0].length}return o<t.length&&l.push(...r(t.slice(o))),l}function od({b:t}){const n=f.useContext(Nl);switch(t.type){case"p":return e.jsx("p",{className:"[&+*]:mt-2.5",children:un(t.text,0,n)});case"code":return e.jsx("pre",{className:"my-2.5 overflow-x-auto rounded-lg bg-well p-2.5 font-mono text-small leading-[1.6] whitespace-pre",children:t.text});case"list":{const s=t.ordered?"ol":"ul";return e.jsx(s,{className:`my-2.5 flex flex-col gap-1 pl-[18px] text-fg/80 ${t.ordered?"list-decimal":"list-disc"}`,children:t.items.map((a,r)=>e.jsxs("li",{children:[a.checked!==void 0&&e.jsx("span",{"aria-hidden":"true",children:a.checked?"☑ ":"☐ "}),un(a.text,0,n),a.sub.length>0&&e.jsx("ul",{className:"mt-1 flex list-[circle] flex-col gap-1 pl-4",children:a.sub.map((l,o)=>e.jsx("li",{children:un(l,0,n)},o))})]},r))})}case"table":return e.jsx("div",{className:"my-2.5 overflow-x-auto",tabIndex:0,children:e.jsxs("table",{className:"w-full border-collapse text-small",children:[e.jsx("thead",{children:e.jsx("tr",{children:t.header.map((s,a)=>e.jsx("th",{className:"border-b border-line px-2 py-1.5 font-semibold",style:{textAlign:t.align[a]??"left"},children:un(s,0,n)},a))})}),e.jsx("tbody",{children:t.rows.map((s,a)=>e.jsx("tr",{children:s.map((r,l)=>e.jsx("td",{className:"border-b border-line px-2 py-1.5 align-top",style:{textAlign:t.align[l]??"left"},children:un(r,0,n)},l))},a))})]})});case"quote":return e.jsx("blockquote",{className:"my-2.5 border-l-2 border-line pl-3 text-muted",children:t.blocks.map((s,a)=>e.jsx(od,{b:s},a))})}}function bh({s:t}){const n=f.useContext(Nl),s=t.blocks.map((a,r)=>e.jsx(od,{b:a},r));return t.kind==="next"?e.jsxs("div",{className:"mt-3 rounded-[10px] border border-info/[0.13] bg-info/[0.03] p-3",children:[e.jsx("div",{className:"mb-1.5 text-meta font-medium tracking-[.5px] text-info uppercase",children:u.thread.suggestion}),s]}):e.jsxs("section",{className:"mt-2.5",children:[t.title&&e.jsx("h3",{className:"mb-1 text-body font-semibold",children:un(t.title,0,n)}),s]})}function jh({doc:t,plain:n}){return e.jsxs(Nl.Provider,{value:n,children:[t.title&&e.jsx("strong",{className:"block text-body font-semibold",children:un(t.title,0,n)}),t.lead&&e.jsx("p",{className:"mt-1.5",children:un(t.lead,0,n)}),t.sections.map((s,a)=>e.jsx(bh,{s},a))]})}const At=u.thread.rig,yh="inline-flex items-center gap-1 whitespace-nowrap text-small text-muted",Nh="inline-flex items-center gap-1 whitespace-nowrap text-small font-medium text-fg",id="mt-1.5 rounded-[6px] border border-line bg-well px-2.5 py-2 font-mono text-meta whitespace-pre-wrap text-muted [overflow-wrap:anywhere]",Ha=()=>e.jsx("div",{className:"text-meta text-muted",children:u.thread.cut});function kh({session:t}){const n=Gn(),s=t.state==="exited"?"done":t.state==="waiting_input"?"question":t.state==="waiting_permission"?"approval":t.state;return e.jsx("span",{className:"inline-flex flex-none","aria-hidden":"true",children:e.jsx(Da,{tool:t.tool,seed:t.id,state:s,pose:Oa(t.id,s),size:16,theme:n,frozen:!0})})}function vh({lead:t,who:n,children:s}){return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 text-meta leading-5 font-medium text-muted",children:[e.jsx("span",{children:t}),n.session&&e.jsx(kh,{session:n.session}),e.jsx("strong",{className:"font-semibold text-fg",children:n.name}),n.seat&&e.jsx("span",{className:"font-mono font-normal",children:n.seat}),s]})}function Ks(t){const[n,s]=f.useState(!1),a=t&&e.jsx("button",{type:"button","aria-expanded":n,onClick:()=>s(l=>!l),className:yh,children:t.label}),r=t&&n&&e.jsx("pre",{className:id,children:t.text});return{toggle:a,box:r}}function wh({e:t,storage:n}){const{toggle:s,box:a}=Ks(t.raw),r=t.dir==="out",l=t.delivery&&At.sent[t.delivery];return e.jsxs("div",{className:`flex flex-col gap-1 ${r?"items-end":"items-start"}`,children:[e.jsxs("article",{"aria-label":r?`${At.to} ${t.who.name}`:`${At.from} ${t.who.name}`,className:`flex max-w-[92%] min-w-0 flex-col gap-1 px-3.5 py-2.5 ${r?"rounded-2xl rounded-br-[4px] bg-raised":"rounded-2xl rounded-bl-[4px] border border-line bg-surface"}`,children:[e.jsxs(vh,{lead:r?At.to:At.from,who:t.who,children:[t.count&&e.jsx("span",{className:"inline-flex h-[18px] items-center rounded-full bg-attention/12 px-1.5 text-[10.5px] text-attention",children:At.twice(t.count)}),r&&l&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:t.delivery==="failed"?"text-attention":"",children:l})]})]}),e.jsx("div",{className:"text-body whitespace-pre-wrap [overflow-wrap:anywhere]",children:t.text}),(t.reply||s)&&e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-3",children:[t.reply&&e.jsxs("a",{href:ce({name:"thread",sessionId:t.reply.sessionId}),onClick:()=>qf(t.reply.sessionId,t.reply.draft,n),"aria-label":At.replyTo(t.who.name),className:Nh,children:[e.jsx(z,{name:"reply",className:"size-3.5"}),At.reply]}),s]}),a]}),t.cut&&e.jsx(Ha,{})]})}const _o="inline-flex h-5 items-center rounded-full px-2 text-meta font-medium whitespace-nowrap",Sh={pending:"bg-raised text-muted",taken:"bg-[var(--status-info-soft)] text-info",passed:"bg-task/14 text-task",blocked:"bg-[var(--status-warning-soft)] text-attention",done:"bg-[var(--status-success-soft)] text-ok",unknown:"border border-dashed border-line text-muted"};function Ch(t){const[n,s]=f.useState(typeof IntersectionObserver>"u");return f.useEffect(()=>{const a=t.current;if(!a||typeof IntersectionObserver>"u")return;const r=new IntersectionObserver(l=>s(l.some(o=>o.isIntersecting)));return r.observe(a),()=>r.disconnect()},[t]),n}function $h(t,n,s){var o,c;const a=xe(t),r=((o=a.daemon)==null?void 0:o.rigRows)===!0,l=!!n&&s&&r&&a.fresh;return f.useEffect(()=>{if(!l)return;t.requestRigRow(n);const i=setInterval(()=>t.requestRigRow(n),cx);return()=>clearInterval(i)},[l,t,n]),n&&r?(c=a.rigRows[n])==null?void 0:c.row:void 0}function Mh({e:t,store:n}){const{toggle:s,box:a}=Ks(t.raw),r=f.useRef(null),l=Ch(r),o=$h(n,t.qitem,l),c=t.refused?null:Ep(o,t.outgoing),i=t.refused?t.refused.log:c==null?void 0:c.log;return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("section",{ref:r,"aria-label":t.outgoing?At.rowOut(t.who.name):At.rowIn(t.who.name),className:"flex w-full flex-col gap-1.5 rounded-[10px] border border-l-[3px] border-task/35 border-l-task bg-surface px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-small font-medium text-task",children:[e.jsx(z,{name:"task",className:"size-3.5"}),e.jsx("span",{className:"min-w-0 truncate",children:t.outgoing?At.rowOut(t.who.name):At.rowIn(t.who.name)}),e.jsx("span",{className:"flex-1"}),c?e.jsx("span",{"data-state":c.key,className:`${_o} ${Sh[c.key]}`,children:c.text}):e.jsx("span",{"data-state":"refused",className:`${_o} bg-danger-bg text-danger-fg`,children:At.rowState.refused})]}),e.jsx("h4",{className:"line-clamp-2 text-[0.90625rem] leading-[1.3125rem] font-semibold [overflow-wrap:anywhere]",children:t.title}),i&&e.jsx("p",{className:"text-small text-muted [overflow-wrap:anywhere]",children:i}),s&&e.jsxs("div",{className:"flex items-center border-t border-dashed border-line pt-1.5",children:[e.jsx("span",{className:"flex-1"}),s]}),a]}),t.cut&&e.jsx(Ha,{})]})}function cd({e:t}){const{toggle:n,box:s}=Ks(t.raw),a=t.tone==="warn"?"border-l-attention":t.tone==="task"?"border-l-task":"border-l-line";return e.jsxs("div",{role:"note",className:`min-w-0 border-l-2 ${a} py-0.5 pl-2.5 text-small leading-5 text-muted`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:`text-[10px] font-medium tracking-[.04em] uppercase ${t.tone==="task"?"text-task":""}`,children:At.openrig}),e.jsx("span",{className:`min-w-0 font-medium [overflow-wrap:anywhere] ${t.tone==="warn"?"text-attention":"text-fg"}`,children:t.title}),e.jsx("span",{className:"flex-1"}),n]}),s,t.cut&&e.jsx(Ha,{})]})}function Eh({e:t}){const[n,s]=f.useState(!1);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("button",{type:"button","aria-expanded":n,onClick:()=>s(a=>!a),className:"flex items-center gap-1.5 py-0.5 text-left text-small text-muted",children:[e.jsx("span",{className:`inline-flex transition-transform motion-reduce:transition-none ${n?"rotate-90":""}`,children:e.jsx(z,{name:"chevron",className:"size-3.5"})}),e.jsx("strong",{className:"font-medium text-fg",children:At.folded(t.notices.length)})]}),n&&t.notices.map(a=>e.jsx(cd,{e:a},a.key))]})}function _h({e:t}){return e.jsxs("div",{className:"flex flex-col gap-1 border-l-2 border-dashed border-line pl-2.5",children:[e.jsx("div",{className:"text-meta leading-5 font-medium text-muted",children:At.unreadable}),e.jsx("pre",{className:id.replace("mt-1.5 ",""),children:t.text}),t.cut&&e.jsx(Ha,{})]})}function Rh({e:t}){const{toggle:n,box:s}=Ks(t.raw);return e.jsxs("div",{className:"-mt-2 flex flex-col items-start",children:[n,s&&e.jsx("div",{className:"w-full",children:s})]})}function Th({e:t,storage:n,store:s}){switch(t.kind){case"rig-message":return e.jsx(wh,{e:t,storage:n});case"rig-task":return e.jsx(Mh,{e:t,store:s});case"rig-notice":return e.jsx(cd,{e:t});case"rig-fold":return e.jsx(Eh,{e:t});case"rig-unreadable":return e.jsx(_h,{e:t});case"rig-raw":return e.jsx(Rh,{e:t})}}const fn=u.thread.task,Ah={killed:{tone:"attention",text:"text-attention",icon:"stop"},completed:{tone:"ok",text:"text-ok",icon:"check"},failed:{tone:"danger",text:"text-danger-fg",icon:"close"},other:{tone:"muted",text:"text-muted",icon:"task"}};function Ih({task:t,cut:n}){const{toggle:s,box:a}=Ks({label:fn.raw,text:t.raw}),r=Ah[t.status],l=fn.statuses[t.status],{about:o}=t,c=(o==null?void 0:o.kind)==="command"?o.code:void 0,i=[c!==void 0?fn.code(c):null,t.output??null].filter(Boolean).join(" · ");return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("section",{"aria-label":fn.label(l),"data-status":t.status,className:"flex w-full flex-col gap-1.5 rounded-[10px] border border-line bg-surface px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(z,{name:r.icon,className:`size-3.5 ${r.text}`}),e.jsx("span",{className:"text-meta font-medium tracking-[.04em] text-muted uppercase",children:fn.kicker}),e.jsx("span",{className:"flex-1"}),e.jsx(qs,{tone:r.tone,label:l})]}),e.jsx("p",{className:"text-body [overflow-wrap:anywhere]",children:(o==null?void 0:o.kind)==="agent"?e.jsxs(e.Fragment,{children:[fn.agent," ",e.jsx("strong",{className:"font-semibold",children:o.name})," ",fn.agentDid[t.status]]}):(o==null?void 0:o.kind)==="command"?e.jsxs(e.Fragment,{children:[fn.command," ",e.jsx("code",{className:"rounded-[4px] bg-fg/[0.05] px-1 font-mono text-[.9em]",children:o.command})," ",fn.commandDid[t.status]]}):t.summary}),i&&e.jsx("p",{className:"font-mono text-meta text-muted [overflow-wrap:anywhere]",children:i}),e.jsxs("div",{className:"flex items-center border-t border-dashed border-line pt-1.5",children:[e.jsx("span",{className:"flex-1"}),s]}),a]}),n&&e.jsx("div",{className:"text-meta text-muted",children:u.thread.cut})]})}function dd(t,n,s,a=!0){const[r,l]=f.useState({key:"",url:null,failed:!1}),o=n?`${n}|${s}`:"";return f.useEffect(()=>{if(!n||!a)return;let c=!0;return t.imageUrl(n,s).then(i=>{c&&l({key:o,url:i,failed:!1})},()=>{c&&l({key:o,url:null,failed:!0})}),()=>{c=!1}},[t,n,s,a,o]),r.key===o&&o!==""?{url:r.url,failed:r.failed}:{url:null,failed:!1}}const Cn=u.images,Lh=1,Oh=4,Dh=120,Fh=t=>Math.min(Oh,Math.max(Lh,t)),Ph={"image/png":"png","image/gif":"gif","image/jpeg":"jpg","image/webp":"webp"};function zh(t,n,s){const[a,r]=f.useState(null);return f.useEffect(()=>{if(r(null),!t||typeof navigator.canShare!="function"||typeof navigator.share!="function")return;let l=!0;return fetch(t).then(o=>o.blob()).then(o=>{const c=new File([o],n,{type:s});l&&navigator.canShare({files:[c]})&&r(c)},()=>{}),()=>{l=!1}},[t,n,s]),a}function Bh({store:t,refs:n,index:s,onIndex:a,onClose:r}){const l=n[s],{url:o,failed:c}=dd(t,l.id,!1),i=`capture-${s+1}.${Ph[l.mime]??"img"}`,m=zh(o,i,l.mime),[d,x]=f.useState(1),[p,g]=f.useState(0),h=f.useRef(new Map),N=f.useRef({pinch0:0,scale0:1,y0:0});f.useEffect(()=>{x(1),g(0),h.current.clear()},[s]);const k=()=>{const[A,R]=[...h.current.values()];return A&&R?Math.hypot(A.x-R.x,A.y-R.y):0},C=A=>{var R,_;h.current.set(A.pointerId,{x:A.clientX,y:A.clientY}),(_=(R=A.currentTarget).setPointerCapture)==null||_.call(R,A.pointerId),h.current.size===2?N.current={...N.current,pinch0:k(),scale0:d}:N.current={...N.current,y0:A.clientY}},j=A=>{h.current.has(A.pointerId)&&(h.current.set(A.pointerId,{x:A.clientX,y:A.clientY}),h.current.size===2?N.current.pinch0>0&&x(Fh(N.current.scale0*k()/N.current.pinch0)):d===1&&g(A.clientY-N.current.y0))},y=A=>{if(h.current.delete(A.pointerId)&&h.current.size===0){if(d===1&&Math.abs(p)>Dh){r();return}g(0)}},b=f.useRef(null);Kc(b,r);const M=()=>{m&&navigator.share({files:[m]}).catch(()=>{})},S=A=>A.stopPropagation(),$="inline-flex min-h-11 items-center rounded-full bg-white/15 px-4 text-body font-medium text-white",v=(A,R,_,L)=>A>=0&&A<n.length&&e.jsx("button",{type:"button","aria-label":R,title:R,onPointerDown:S,onClick:()=>a(A),className:`absolute top-1/2 ${_} grid size-11 -translate-y-1/2 place-items-center rounded-full bg-white/15 text-white`,children:e.jsx("svg",{className:"size-5 fill-none stroke-current [stroke-linecap:round] [stroke-linejoin:round] [stroke-width:1.6]",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:L})})});return dl.createPortal(e.jsxs("div",{ref:b,role:"dialog","aria-modal":"true","aria-label":Cn.view,tabIndex:-1,className:"fixed inset-0 z-50 flex flex-col bg-black/90 text-white outline-none",style:{opacity:p?Math.max(.4,1-Math.abs(p)/400):1},children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsxs("span",{className:"min-w-0 flex-1 text-small text-white/70",children:[l.width,"×",l.height,n.length>1?` · ${s+1}/${n.length}`:""]}),m&&e.jsx("button",{type:"button",onPointerDown:S,onClick:M,className:$,children:Cn.share}),o&&e.jsx("a",{href:o,download:i,onPointerDown:S,className:$,children:Cn.save}),e.jsx("button",{type:"button","aria-label":Cn.close,title:Cn.close,onPointerDown:S,onClick:r,className:"grid size-11 place-items-center rounded-full bg-white/15",children:e.jsx("svg",{className:"size-5 fill-none stroke-current [stroke-linecap:round] [stroke-width:1.8]",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"M6 6l12 12M18 6 6 18"})})})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1 items-center justify-center overflow-hidden",style:{touchAction:"none"},onPointerDown:C,onPointerMove:j,onPointerUp:y,onPointerCancel:y,children:[o&&e.jsx("img",{src:o,alt:"",draggable:!1,className:"max-h-full max-w-full select-none object-contain",style:{transform:`translateY(${p}px) scale(${d})`,transition:h.current.size?"none":"transform .15s"}}),!o&&e.jsx("p",{role:"status",className:"text-body text-white/70",children:c?Cn.unavailable:"…"}),v(s-1,Cn.prev,"left-3","m15 18-6-6 6-6"),v(s+1,Cn.next,"right-3","m9 18 6-6-6-6")]})]}),document.body)}const Ro=u.images;function qh({store:t,image:n,onOpen:s}){const[a,r]=f.useState(typeof IntersectionObserver>"u"),l=f.useRef(null);f.useEffect(()=>{if(a||!l.current)return;const i=new IntersectionObserver(m=>{m.some(d=>d.isIntersecting)&&(r(!0),i.disconnect())});return i.observe(l.current),()=>i.disconnect()},[a]);const{url:o,failed:c}=dd(t,n.id,!0,a&&n.preview);return n.preview?e.jsx("div",{ref:l,className:"max-w-full",children:e.jsx(eh,{url:o,failed:c,width:n.width,height:n.height,maxW:240,maxH:240,alt:"",unavailable:Ro.unavailable,onOpen:s})}):e.jsx("p",{className:"max-w-full rounded-lg border border-line bg-surface p-2.5 text-small text-muted",children:Ro.noPreview})}function To({store:t,refs:n,align:s="start"}){const[a,r]=f.useState(null);return n.length===0?null:e.jsxs("div",{"data-thumbs":!0,className:`flex max-w-full flex-wrap gap-2 ${s==="end"?"justify-end":""}`,children:[n.map((l,o)=>e.jsx(qh,{store:t,image:l,onOpen:()=>r(o)},`${l.id}:${o}`)),a!==null&&e.jsx(Bh,{store:t,refs:n,index:a,onIndex:r,onClose:()=>r(null)})]})}const es=u.images;let Hh=0;const Uh=t=>`data:${t.mime};base64,${t.data}`;function Wh(t){const[n,s]=f.useState([]),[a,r]=f.useState(0),[l,o]=f.useState(null),c=f.useRef([]),i=f.useRef(0),m=f.useRef(!0);f.useEffect(()=>(m.current=!0,()=>{m.current=!1}),[]);const d=y=>{c.current=y,s(y)},x=(y,b)=>{m.current&&d(c.current.map(M=>M.item.key===y?{...M,...b,item:{...M.item,...b.item}}:M))},p=y=>{i.current+=y,r(i.current)},g=async y=>{const b=await Xf(y);if(p(-1),!m.current)return;if(!b.ok){o(b.reason==="tooLarge"?es.tooLarge:es.notImage);return}const{image:M,width:S,height:$,bytes:v}=b.value,A=`att-${Hh++}`;d([...c.current,{item:{key:A,url:Uh(M.preview??M),width:S,height:$,bytes:v,state:"uploading"}}]);try{const R=await t.putImage(M);x(A,{id:R.id,item:{state:"ready"}})}catch(R){const _=R instanceof Error&&R.message==="too_large"?es.tooLarge:R instanceof Error&&R.message==="not_image"?es.notImage:es.failed;x(A,{item:{state:"refused",reason:_}}),m.current&&o(_)}},h=y=>{if(y.length!==0){o(null);for(const b of y){if(c.current.length+i.current>=Wl){o(es.max);return}p(1),g(b)}}},N=y=>{const b=c.current.find(M=>M.item.key===y);d(c.current.filter(M=>M.item.key!==y)),(b==null?void 0:b.item.state)==="refused"&&o(null)},k=()=>{const y=c.current;return d([]),o(null),y},C=y=>{m.current&&d([...y,...c.current].slice(0,Wl))},j=n.map(y=>y.item);return{items:j,add:h,remove:N,clear:k,putBack:C,error:l,ready:a===0&&j.every(y=>y.state==="ready"),ids:()=>c.current.filter(y=>y.item.state==="ready"&&y.id).map(y=>y.id)}}const ud=`${Nn}launch.started`;function xd(t){var n;try{const s=JSON.parse(((n=Ze(t))==null?void 0:n.getItem(ud))??"[]");return Array.isArray(s)?s.filter(a=>typeof(a==null?void 0:a.id)=="string"&&typeof(a==null?void 0:a.project)=="string"):[]}catch{return[]}}function Kh(t,n,s){var r;const a=[...xd(s).filter(l=>l.id!==t),{id:t,project:n}].slice(-50);try{(r=Ze(s))==null||r.setItem(ud,JSON.stringify(a))}catch{}}const Vh=(t,n)=>{var s;return((s=xd(n).find(a=>a.id===t))==null?void 0:s.project)??null};function Gh(t){const n=/^\/(\S*)$/.exec(t);return n?n[1].toLowerCase():null}function Xh(t,n){var r;const s=n.toLowerCase(),a=[];for(const l of t){const o=[l.name,...l.aliases??[]],c=o.map(h=>h.toLowerCase());let i=-1,m=l.name,d=-1;const x=c.indexOf(s),p=c.findIndex(h=>h.startsWith(s)),g=c.findIndex(h=>h.includes(s));x>=0&&s?(i=0,m=o[x],d=0):p>=0?(i=1,m=o[p],d=0):g>=0?(i=2,m=o[g],d=c[g].indexOf(s)):(r=l.description)!=null&&r.toLowerCase().includes(s)&&(i=3),!(i<0)&&(m!==l.name&&l.name.toLowerCase().startsWith(s)&&(m=l.name,d=0),a.push({command:l,shown:m,at:s?d:-1,rank:i}))}return a.sort((l,o)=>l.rank-o.rank||+!!l.command.blocked-+!!o.command.blocked||l.shown.localeCompare(o.shown)).map(({rank:l,...o})=>o)}function Yh(t,n){const s=/^\/(\S+)/.exec(t.trimStart());if(!s)return;const a=s[1].toLowerCase();return n.find(r=>{var l;return r.name.toLowerCase()===a||((l=r.aliases)==null?void 0:l.some(o=>o.toLowerCase()===a))})}const Qh=t=>`/${t.name} `,Pn=u.thread.slash;function Zh({listing:t,query:n,matches:s,tool:a,name:r,onPick:l}){const o="mb-2 overflow-hidden rounded-2xl border border-line bg-surface";return t?t.error?e.jsx("div",{className:`${o} px-3 py-3 text-meta text-muted`,role:"status",children:Pn.unavailable(r)}):s.length===0?e.jsx("div",{className:`${o} px-3 py-3 text-meta text-muted`,role:"status",children:Pn.none(`/${n}`,r)}):e.jsxs("div",{className:o,children:[e.jsx("p",{className:"px-3 pt-2 pb-1 text-meta text-muted",children:Pn.count(a,s.length)}),e.jsx("ul",{"aria-label":Pn.label(a),className:"max-h-[300px] overflow-y-auto overscroll-contain px-1 pb-1",children:s.map(c=>{const i=c.command,m=i.blocked!==void 0,d=n.length,x=Pn.source[i.source];return e.jsx("li",{className:"border-t border-line first:border-t-0",children:e.jsxs("button",{type:"button",disabled:m,onMouseDown:p=>p.preventDefault(),onClick:()=>l(i),className:"flex min-h-[52px] w-full flex-col justify-center rounded-[10px] px-2.5 py-1.5 text-left enabled:active:bg-raised",children:[e.jsxs("span",{className:`font-mono text-[14px] leading-5 ${m?"text-muted":""}`,children:["/",c.at>=0&&d>0?e.jsxs(e.Fragment,{children:[c.shown.slice(0,c.at),e.jsx("mark",{className:"bg-transparent font-semibold text-fg underline underline-offset-2",children:c.shown.slice(c.at,c.at+d)}),c.shown.slice(c.at+d)]}):c.shown,i.argumentHint&&e.jsxs("span",{className:"text-[12px] text-muted",children:[" ",i.argumentHint]}),x&&e.jsx("span",{className:`ml-1.5 font-sans text-[10.5px] ${i.source==="project"?"text-info":"text-muted"}`,children:x})]}),e.jsx("span",{className:`truncate text-[12px] leading-4 ${m?"text-attention":"text-muted"}`,children:m?Pn.blocked[i.blocked]:i.description})]})},i.name)})})]}):e.jsx("div",{className:`${o} px-3 py-3 text-meta text-muted`,role:"status",children:Pn.loading(a)})}const Jh={ok:"text-ok",info:"text-info",approval:"text-approval",attention:"text-attention",muted:"text-muted"},Tt=u.thread.composer;function md(t){const n=t.trim();return n.length>Ra?"long":Ii.test(n)?"untypable":null}function eg(t){if(t.phase==="uncertain"||t.reason==="not_taken")return{title:Tt.uncertainTitle,body:Tt.uncertain};const n=t.reason==="busy"?Tt.busy:t.reason==="invalid"?Tt.invalid(Ra):t.reason==="untypable"?Tt.untypable:t.reason==="read_only"?Tt.readOnly:t.reason==="attachment_missing"?Tt.imageGone:t.reason==="attachments_not_accepted"?u.images.dialog:Tt.lost;return{title:Tt.failTitle,body:n}}function tg({name:t,focusAtEnd:n=!1,composer:s,draft:a,onDraft:r,onSend:l,fresh:o,taken:c,checking:i,error:m,alert:d,onReconnect:x,images:p,dialog:g,lead:h,leadNote:N,slash:k}){var E,P;const[C,j]=ps(),y=c?{tone:"ok",label:Tt.status.taken}:i?{tone:"muted",label:u.decide.checking}:s.status,b=md(a),M=f.useRef(null),S=p.items.length>0;f.useEffect(()=>{const W=M.current;!n||!W||(W.focus(),W.setSelectionRange(W.value.length,W.value.length))},[]);const $=k&&s.enabled&&!g?Gh(a):null,v=$!==null;f.useEffect(()=>{v&&(k==null||k.ask())},[v]);const A=(E=k==null?void 0:k.listing)!=null&&E.error?[]:((P=k==null?void 0:k.listing)==null?void 0:P.commands)??[],R=f.useMemo(()=>$!==null?Xh(A,$):[],[$,A]),_=k&&!g?Yh(a,A):void 0,L=W=>{var F;r(Qh(W)),(F=M.current)==null||F.focus()},T=!_||$!==null?null:_.blocked?{warn:!0,text:u.thread.slash.blocked[_.blocked]}:_.bare&&/^\/\S+\s*$/.test(a)?{warn:!0,text:u.thread.slash.bare(_.name)}:_.argumentHint?{warn:!1,text:`/${_.name} ${_.argumentHint}`}:null,B=s.enabled&&(!!a.trim()||S)&&b===null&&p.ready&&!(S&&g);return e.jsxs("footer",{className:"flex-none border-t border-line bg-bg pt-2 pb-3 [@media(max-height:650px)]:pb-2",children:[e.jsxs("div",{className:`flex items-center gap-1.5 pb-2 text-meta ${Jh[y.tone]}`,children:[e.jsx("i",{className:"inline-block size-1.5 flex-none rounded-full bg-current"}),y.label]}),d&&e.jsx("div",{className:"mb-2.5",children:d}),!d&&m&&e.jsx("div",{className:"mb-2.5",children:e.jsxs(De,{title:m.title,tone:"warning",role:"alert",children:[e.jsx("p",{children:m.body}),!o&&x&&e.jsx("button",{type:"button",disabled:C,onClick:()=>{j(!0),x()},className:We({block:!0,className:"mt-2"}),children:C?u.link.reconnecting:Tt.reconnect})]})}),v&&e.jsx(Zh,{listing:k.listing,query:$,matches:R,tool:k.tool,name:t,onPick:L}),!v&&(s.enabled||h)&&e.jsxs("div",{role:"group","aria-label":Tt.quickLabel,className:"flex gap-1.5 overflow-x-auto pb-2 [scrollbar-width:none]",children:[h,s.enabled&&Dp.map(W=>e.jsx("button",{type:"button",onClick:()=>{var F;r(W),(F=M.current)==null||F.focus()},className:`${Oi()} whitespace-nowrap`,children:W},W))]}),N,e.jsx(ah,{id:"draft",label:Tt.label(t),sendLabel:Tt.send(t),value:a,onChange:r,onSend:l,canSend:B,oneLine:!0,images:p,placeholder:s.placeholder,disabled:!s.enabled,fieldRef:M,invalid:b!==null,describedBy:b?"draft-problem":void 0}),T&&e.jsx("p",{role:"status",className:`pt-1.5 text-meta ${T.warn?"text-attention":"font-mono text-muted"}`,children:T.text}),S&&g&&e.jsx("p",{role:"status",className:"pt-1.5 text-meta text-attention",children:u.images.dialog}),p.error&&e.jsx("p",{role:"alert",className:"pt-1.5 text-meta text-attention",children:p.error}),b&&e.jsx("p",{id:"draft-problem",role:"status",className:"pt-1.5 text-meta text-attention",children:b==="long"?Tt.tooLong(Ra):Tt.untypable})]})}const Te=u.adopt,ng=4e3;function sg(t,n,s){if(!t)return!1;const a=Bi(s,n.state);return a?a.reason!=="resume_failed"||a.exitCode!==void 0:!!n.readOnly&&(!!n.adopt||!!n.adopting)}function ag({store:t,session:n,onResume:s}){var h;const{adoptFailures:a,adoptLost:r}=xe(t),l=r[n.id],[o,c]=f.useState(!1),i=n.name,m=(h=n.adopting)==null?void 0:h.step,d=Bi(a[n.id],n.state),x=()=>{c(!0),t.adopt(n.id).finally(()=>c(!1))},p=e.jsxs("p",{className:"flex items-center gap-1.5 text-meta text-muted",children:[e.jsx("i",{className:"inline-block size-1.5 flex-none rounded-full bg-current"}),u.thread.composer.status.readOnly]});let g;if(m==="attaching"||o&&n.adopt==="pane"&&!m)g=e.jsx(ln,{title:Te.action,body:Te.bodyPane,action:e.jsxs("button",{type:"button",disabled:!0,className:We({variant:"primary",block:!0}),children:[e.jsx(og,{}),Te.attaching]})});else if(m==="waiting"||m==="stopping"||m==="resuming"){const N=m==="waiting"?0:m==="stopping"?1:2;g=e.jsx(ln,{tone:"wait",title:m==="waiting"?Te.waiting(i):m==="stopping"?Te.stopping(i):Te.resuming(i),body:m==="waiting"?Te.waitingBody:m==="stopping"?Te.stoppingBody:Te.resumingBody,extra:e.jsxs(e.Fragment,{children:[e.jsx(lg,{at:N}),m==="waiting"&&(l!=null&&l.cancel)?e.jsx(Ao,{kind:l.kind}):null]}),action:m==="waiting"?e.jsx("button",{type:"button",onClick:()=>void t.adopt(n.id,!0),className:We({variant:"outline",block:!0}),children:Te.cancel}):void 0})}else if(d){const N=e.jsx("button",{type:"button",onClick:x,className:We({variant:"outline",block:!0}),children:Te.retry});switch(d.reason){case"process_gone":g=e.jsx(ln,{tone:"amber",title:Te.gone(i),body:Te.goneBody});break;case"stop_failed":g=e.jsx(ln,{tone:"amber",title:Te.stopFailed(i),body:Te.stopFailedBody,action:N});break;case"pane_not_found":g=e.jsx(ln,{tone:"amber",title:Te.paneNotFound(i),body:Te.paneNotFoundBody(i),action:N});break;case"no_conversation":g=e.jsx(ln,{title:Te.noConversation(i),body:Te.noConversationBody});break;case"resume_failed":g=e.jsx(ln,{tone:"fail",title:Te.resumeFailed(i,Te.exitedOnStart(n.tool,d.exitCode??0)),body:Te.resumeFailedBody,action:e.jsx("button",{type:"button",onClick:s,className:We({variant:"primary",block:!0}),children:Te.resumeHere})});break;default:g=e.jsx(ln,{title:Te.notLocated(i),body:Te.notLocatedBody})}}else if(n.adopt==="not_located")g=e.jsx(ln,{title:Te.notLocated(i),body:Te.notLocatedBody});else{const N=n.state==="exited";g=e.jsx(ln,{title:Te.action,body:N?Te.bodyEnded:n.adopt==="pane"?Te.bodyPane:Te.body,extra:e.jsxs(e.Fragment,{children:[!N&&n.adopt==="resume"&&n.pending?e.jsx("p",{className:"text-attention",children:Te.pendingDropped(i)}):null,l&&!l.cancel?e.jsx(Ao,{kind:l.kind}):null]}),action:e.jsx("button",{type:"button",disabled:o,onClick:x,className:We({variant:"primary",block:!0}),children:Te.action})})}return e.jsxs("footer",{role:"status",className:"flex flex-none flex-col gap-2 border-t border-line bg-bg pt-2.5 pb-3 [@media(max-height:650px)]:pb-2",children:[(d==null?void 0:d.reason)!=="resume_failed"&&p,g]})}function rg({store:t}){var c;const{adoptNotice:n,sessions:s}=xe(t),[a,r]=f.useState(null);if(f.useEffect(()=>{if(!n)return;r(n.seq);const i=setTimeout(()=>r(null),ng);return()=>clearTimeout(i)},[n==null?void 0:n.seq]),!n||a!==n.seq)return null;const l=((c=s.get(n.id))==null?void 0:c.name)??n.id,o=n.kind==="done"?Te.done(l):n.kind==="cancelled"?Te.cancelled(l):n.kind==="busy"?Te.busy(l):Te.unsupported;return e.jsx("span",{role:"status",className:"fixed inset-x-3.5 top-14 z-[7] rounded-[12px] border border-line bg-raised px-3 py-2 text-[12px] leading-[17px] text-fg shadow-[0_8px_24px_#0004]",children:o})}function Ao({kind:t}){return e.jsx("p",{role:"alert",className:"text-attention",children:t==="failed"?Te.notSent:Te.uncertain})}function ln({tone:t,title:n,body:s,extra:a,action:r}){const l=t==="wait"?"border-[color-mix(in_srgb,var(--primary)_45%,var(--border))]":t==="fail"?"border-[color-mix(in_srgb,var(--destructive)_55%,var(--border))]":t==="amber"?"border-[color-mix(in_srgb,var(--warning)_55%,var(--border))]":"border-line";return e.jsxs("section",{className:`flex flex-col gap-1.5 rounded-card border ${l} bg-surface p-3 text-[12.5px] leading-[18px] text-muted`,children:[e.jsx("strong",{className:"text-body font-semibold text-fg",children:n}),e.jsx("span",{children:s}),a,r&&e.jsx("div",{className:"mt-1",children:r})]})}function lg({at:t}){return e.jsx("div",{className:"mt-1.5 flex items-center gap-1.5 text-[11px] text-muted",children:Te.steps.map((n,s)=>e.jsxs("span",{className:"contents",children:[s>0&&e.jsx("span",{"aria-hidden":"true",className:"h-px w-3.5 bg-line"}),e.jsxs("span",{className:`flex items-center gap-1 ${s===t?"text-fg":""}`,...s===t?{"aria-current":"step"}:{},children:[e.jsx("span",{"aria-hidden":"true",className:`size-2 rounded-full border-[1.5px] ${s<t?"border-ok bg-ok":s===t?"border-primary bg-[color-mix(in_srgb,var(--primary)_40%,transparent)]":"border-line"}`}),n]})]},n))})}function og(){return e.jsx("span",{"aria-hidden":"true",className:"inline-block size-3 animate-spin rounded-full border-2 border-current border-r-transparent motion-reduce:animate-none"})}const Ue=u.sessionEnd,vs=t=>We({variant:t,block:!0});function pd(t,n,s,a,r){const[l,o]=f.useState(null),[c,i]=f.useState(null),[m,d]=f.useState(!1),[x,p]=f.useState(0),g=f.useRef(!0);return f.useEffect(()=>(g.current=!0,()=>{g.current=!1}),[]),f.useEffect(()=>{if(!a)return;let C=!0,j;return o(null),t.prepareConfirm(n==="terminal"?{purpose:n,id:s}:{purpose:n,id:s}).then(y=>{C&&(o(y),j=setTimeout(()=>{C&&(o(null),i("expired"))},y.expiresInMs))},()=>{C&&i("prepareFailed")}),()=>{C=!1,clearTimeout(j)}},[t,n,s,a,x]),{challenge:l,problem:c,asking:m,needsNew:c==="expired"||c==="failed"||c==="prepareFailed",go:async()=>{if(!a||m||!l)return;if(!l.credentialId){o(null),i("failed");return}d(!0),i(null);const C=await Fs({challenge:l.challenge,rpId:l.rpId,credentialId:l.credentialId}).catch(()=>"failed");if(g.current){if(d(!1),C==="cancelled"){i("cancelled");return}if(C==="failed"){o(null),i("failed");return}o(null),r(C)===null&&i("failed")}},retry:()=>{i(null),p(C=>C+1)}}}function kl({store:t,session:n,mode:s,onClose:a,onSent:r,onReconnect:l}){const{fresh:o,device:c}=xe(t),[i,m]=ps(),d=n.name,x=s==="close",p=!!(c!=null&&c.confirm),g=pd(t,x?"close":"act",n.id,o&&p,C=>{const j=x?t.sessionClose(n.id,C):t.sessionResume(n.id,C);return j!==null&&r(),j}),h=x?Px(n):[],N=g.asking?u.confirm.asking:g.challenge?x?Pt()?Ue.goCloseApple:Ue.goClose:Pt()?Ue.goResumeApple:Ue.goResume:u.confirm.preparing,k=e.jsx("button",{type:"button",onClick:a,className:vs(),children:Ue.cancel});return e.jsxs(ht,{labelledBy:"end-title",onClose:a,children:[e.jsx("h2",{id:"end-title",className:"text-heading leading-[1.3] tracking-[-.5px]",children:x?Ue.closeTitle(d):Ue.resumeTitle(d)}),o?p?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:x?Ue.closeBody:Ue.resumeBody}),h.length>0&&e.jsx(De,{title:Ue.cutsTitle,tone:"warning",children:e.jsx("ul",{className:"flex list-disc flex-col gap-1 pl-5",children:h.map(C=>e.jsx("li",{children:C},C))})}),g.problem&&e.jsx(De,{title:u.confirm[g.problem],tone:"warning",role:"alert"}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:h.length>0?`${Ue.force} ${Ue.check}`:Ue.check}),g.needsNew?e.jsx("button",{type:"button",onClick:g.retry,className:vs("primary"),children:u.confirm.retry}):e.jsx("button",{type:"button",disabled:g.asking||!g.challenge,onClick:()=>{g.go()},className:vs("primary"),children:N}),k]}):e.jsxs(e.Fragment,{children:[e.jsx(De,{title:Ue.unprotectedTitle,tone:"warning",role:"status",children:e.jsx("p",{children:x?Ue.unprotectedClose(d):Ue.unprotectedResume(d)})}),e.jsx("a",{href:ce({name:"connection"}),className:vs("primary"),children:Ue.openConnection}),k]}):e.jsxs(e.Fragment,{children:[e.jsx(De,{title:Ue.offlineTitle,tone:"warning",role:"status",children:e.jsx("p",{children:x?Ue.offlineClose(d):Ue.offlineResume(d)})}),l&&e.jsx("button",{type:"button",disabled:i,onClick:()=>{m(!0),l()},className:vs("primary"),children:i?u.link.reconnecting:Ue.reconnect}),k]})]})}function Io({tone:t,label:n}){return e.jsxs("div",{className:`flex items-center gap-1.5 text-meta ${t==="attention"?"text-attention":"text-info"}`,children:[e.jsx(z,{name:"spinner",className:"size-3 animate-spin motion-reduce:animate-none",stroke:2}),n]})}function fd({error:t,fresh:n,onRetry:s,onReconnect:a}){const[r,l]=ps();return e.jsxs(De,{title:t.title,tone:"warning",role:"alert",children:[e.jsx("p",{children:t.body}),t.retry&&e.jsx("button",{type:"button",onClick:s,className:We({size:"sm",className:"mt-2"}),children:Ue.retry}),t.reconnect&&!n&&a&&e.jsx("button",{type:"button",disabled:r,onClick:()=>{l(!0),a()},className:We({size:"sm",className:"mt-2"}),children:r?u.link.reconnecting:Ue.reconnect})]})}function ig({ending:t,name:n,canResume:s,resumeHeld:a=!1,readOnly:r,fresh:l,focus:o,onResume:c,onReconnect:i}){const m=f.useRef(null);return f.useEffect(()=>{var d;o&&((d=m.current)==null||d.focus({preventScroll:!0}))},[o]),e.jsxs("footer",{ref:m,tabIndex:-1,role:"status",className:"flex flex-none flex-col gap-2.5 border-t border-line bg-bg pt-3 pb-3 outline-none [@media(max-height:650px)]:pb-2",children:[t.kind==="closing"&&e.jsxs(e.Fragment,{children:[e.jsx(Io,{tone:"attention",label:Ue.closing(n)}),e.jsx("p",{className:"text-small text-muted",children:Ue.closingHint})]}),t.kind==="resuming"&&e.jsx(Io,{tone:"info",label:Ue.resuming(n)}),t.kind==="ended"&&e.jsxs(e.Fragment,{children:[t.error&&e.jsx(fd,{error:t.error,fresh:l,onRetry:c,onReconnect:i}),e.jsxs("section",{"aria-labelledby":"ended-title",className:"flex flex-col gap-2.5 rounded-card border border-line bg-surface p-4",children:[e.jsx("h2",{id:"ended-title",className:"text-body font-semibold",children:Ue.ended}),t.killed?e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:Ue.killed}):!r&&e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:s?Ue.endedBody:Ue.endedOnPc}),s&&!r&&e.jsxs("button",{type:"button","aria-disabled":a||void 0,onClick:()=>{a||c()},className:We({variant:t.killed?"outline":"primary",block:!0,className:a?"opacity-45":""}),children:[e.jsx(z,{name:"resume"}),Ue.resume(n)]})]})]})]})}const gs={ok:"idle",run:"work",fail:"perm",wait:"ask",skip:"plain",none:"off"},ka=t=>t.state!=="merged"&&t.state!=="closed",cg=t=>(t.state==="open"||t.state==="review")&&t.mergeable&&(t.pipeline==="ok"||t.pipeline==="none");function dg(t){return{open:t.filter(ka),closed:t.filter(n=>!ka(n))}}const ug=t=>t.filter(n=>ka(n)&&n.pipeline==="fail").length,xg=t=>t.filter(n=>n.status!=="ok"),hd=t=>t==="github"?"gh":"glab",mg=t=>`${hd(t.forge)} auth login --hostname ${t.host}`;function gd(t){const n=new Map;for(const s of t){const a=n.get(s.column)??{column:s.column,name:s.columnName,jobs:[]};a.jobs.push(s),n.set(s.column,a)}return[...n.values()].sort((s,a)=>s.column-a.column)}const bd=t=>t.find(n=>n.status==="fail")??null;function jd(t){if(t===void 0)return null;const n=Math.round(t);return n<3600?{text:`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`,hours:!1}:{text:`${Math.floor(n/3600)}:${String(Math.floor(n%3600/60)).padStart(2,"0")}`,hours:!0}}const pg=t=>t.startsWith("…"),fg=new Set(["draft","not_open","approvals","changes_requested","pipeline","pipeline_not_started"]);function Ua(t){const{pr:n}=t,s=new Set(t.mergeBlockers),a=Math.max(1,n.approvals.required??0),r=[];s.has("draft")&&r.push({ok:!1,key:"draft"}),s.has("not_open")&&r.push({ok:!1,key:"not_open"}),s.has("approvals")&&r.push({ok:!1,key:"approvals",given:n.approvals.given,required:a}),s.has("changes_requested")&&r.push({ok:!1,key:"changes_requested",who:t.reviewers.filter(l=>l.state==="changes").map(l=>l.name).join(", ")}),s.has("pipeline_not_started")?r.push({ok:!1,key:"pipeline_not_started"}):s.has("pipeline")||n.pipeline!=="ok"&&n.pipeline!=="none"?r.push({ok:!1,key:n.pipeline==="run"?"pipeline_run":n.pipeline==="wait"?"pipeline_wait":n.pipeline==="skip"?"pipeline_skip":"pipeline_fail"}):r.push({ok:!0,key:n.pipeline==="none"?"noCi":"pipeline"});for(const l of s)fg.has(l)||r.push({ok:!1,key:"raw",code:l});return s.has("approvals")||r.push({ok:!0,key:"approved",given:n.approvals.given,required:a}),s.has("changes_requested")||r.push({ok:!0,key:"noChanges"}),r}const hg=t=>(t.pr.state==="open"||t.pr.state==="review")&&Ua(t).every(n=>n.ok),yd=t=>`${t.approvals.given}${t.approvals.required!==void 0?`/${t.approvals.required}`:""}`,zr=(t,n)=>{const s=t.replace(/\.$/,"");return n.key==="changes_requested"||n.key==="raw"?s:s.charAt(0).toLowerCase()+s.slice(1)},gg=t=>t.pipeline==="fail"&&(t.state==="open"||t.state==="review"),bg=t=>t.files.reduce((n,s)=>({added:n.added+s.added,removed:n.removed+s.removed}),{added:0,removed:0}),jg=(t,n)=>t.threads.filter(s=>s.file===n).length,vl=t=>t.slice(0,7);function yg(t,n){if(!t)return null;const s=t.prs.find(l=>ka(l)&&l.sessions.includes(n));if(s)return{pr:s};const a=t.followed.find(l=>l.session===n);if(!a)return null;const r=t.forges.find(l=>l.forge===a.forge&&l.host===a.host);return r&&r.status!=="ok"?{unknown:r,kind:a.forge}:null}const Lo=new Set(["starting","launching","booting"]);function xn(t){return Lo.has(t.status)||Lo.has(t.lifecycleState)?"starting":t.status==="partial"?"partial":t.status==="running"||t.running>0?t.nodes.some(s=>s.stopped)?"partial":"running":"stopped"}const Ng=t=>t!=="stopped",Nd=t=>t.rigs.find(n=>n.name===Ms),Oo={running:0,partial:0,starting:0,stopped:1},Br=t=>t.rigs.filter(n=>n.name!==Ms).map((n,s)=>({r:n,i:s})).sort((n,s)=>Oo[xn(n.r)]-Oo[xn(s.r)]||n.i-s.i).map(n=>n.r),kd=(t,n,s)=>{var a;for(const r of t)if(((a=r.rig)==null?void 0:a.name)===n&&r.rig.role===s&&r.state!=="exited")return r};function vd(t,n,s){var l;let a=0,r=0;for(const o of n)((l=o.rig)==null?void 0:l.name)!==t||!o.pending||(o.pending.kind==="question"?r+=1:a+=1);for(const o of s??[])o.from.rig===t&&o.kind!=="update"&&(r+=1);return{perm:a,ask:r}}const Vs=t=>t.activity==="running"||t.work>0;function wd(t,n){if(n.perm)return"perm";if(n.ask)return"ask";const s=xn(t);return s==="stopped"?"off":s==="starting"||t.nodes.some(Vs)?"work":"idle"}function wl(t){const{session:n,node:s,graph:a}=t;return t.rigStatus==="stopped"?"off":n?n.pending&&n.pending.kind!=="question"||n.state==="waiting_permission"||n.state==="error"?"perm":n.pending||n.state==="waiting_input"?"ask":n.state==="starting"?"starting":n.state==="working"?"work":"idle":s!=null&&s.stopped||(a==null?void 0:a.status)==="exited"||(a==null?void 0:a.status)==="stopped"?t.rigStatus==="starting"?"waiting":"off":t.rigStatus==="starting"&&!s?"waiting":s&&Vs(s)?"work":a!=null&&a.attention||s!=null&&s.attention?"ask":"idle"}const Sd={perm:"perm",ask:"ask",work:"work",idle:"idle",off:"off",starting:"work",waiting:"off"},Sl=t=>t==="claude-code"||t==="claude"?"claude":t==="codex"?"codex":t==="cursor"?"cursor":t==="omp"?"omp":null,pn=(t,n)=>(n==null?void 0:n.split("@")[0])||t.replace(".","-");function kg(t,n){const s=n.map(a=>({...a,seats:t.filter(r=>r.pod===a.id)}));for(const a of t)s.some(r=>r.id===a.pod)||s.push({id:a.pod,label:a.pod,seats:t.filter(r=>r.pod===a.pod)});return s.filter(a=>a.seats.length)}function vg(t,n){const s=n.filter(o=>/delegat/.test(o.kind)),a=new Set(s.map(o=>o.from)),r=new Set(s.map(o=>o.to)),l=t.filter(o=>a.has(o.logicalId)&&!r.has(o.logicalId));return l.length===1?l[0].logicalId:null}const wg=["auto","standard","open","yolo","locked","spec"],Cd=/^builtin:(auto|standard|open|yolo|locked)$/;function Sg(t){var n;switch(t.policySource){case"member_policy":return((n=Cd.exec(t.policy??""))==null?void 0:n[1])??null;case"rig_policy":case"team_default":case"kernel_default":case"floor":return"spec";default:return null}}function $d(t){if(t.length===0)return null;const n=t.map(Sg),s=n[0];return s&&n.every(a=>a===s)?s:"mixed"}const Cg=t=>{var n;return((n=Cd.exec(t??""))==null?void 0:n[1])??null},Md=t=>[...dx(t.nodes)].map(([n,s])=>({role:n,count:s.length,ids:s}));function $g(t,n){return n!=null&&n.some(s=>s.id===t.id)?"mine":t.state==="in-progress"?"progress":t.state==="blocked"?"blocked":"pending"}const Mg=t=>t==="done"?"done":t==="handed-off"?"handed":"stopped";function Eg(t){const n=t.trim(),s=/^handed[ _-]?off(?: to)? (.+)$/i.exec(n);if(s)return{verb:"handed",to:s[1].split("@")[0]};const a=/^blocked(?: on)? (.+)$/i.exec(n);if(a)return{verb:"blocked",on:a[1]};const r=n.toLowerCase();return r==="claimed"?{verb:"claimed"}:r==="completed"||r==="done"?{verb:"completed"}:r==="canceled"||r==="cancelled"?{verb:"canceled"}:r==="resumed"||r==="unblocked"?{verb:"resumed"}:r==="failed"?{verb:"failed"}:{verb:"other",text:n}}function va(t){const n=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(:\d{2})?$/.test(t)?`${t.replace(" ","T")}Z`:t,s=new Date(n);return Number.isNaN(s.getTime())?null:s}function Cl(t,n){const s=a=>new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime();return Math.round((s(n)-s(t))/864e5)}const Ed=t=>t.startsWith("operator."),_d=t=>Ed(t.logicalId)?"Max":pn(t.logicalId,t.session),Rd={running:"on",starting:"go",partial:"part",stopped:"plain"},_g=t=>t.daemon.state==="stopped"||t.daemon.state==="stale";function Rg(t){return t.rig?t.rig:t.seat?t.seat.split("@")[1]??null:null}function Tg(t){return t.kind==="seats"?t.rig??null:t.kind==="act"&&t.action?Rg(t.action):null}const Td=t=>[...t].sort((n,s)=>{var a,r;return(((a=va(s.createdAt))==null?void 0:a.getTime())??0)-(((r=va(n.createdAt))==null?void 0:r.getTime())??0)});function Ag(t,n){const s=[];for(const a of n){if(a.from!==t&&a.to!==t)continue;const r=a.from===t?a.to:a.from;/delegat/.test(a.kind)?s.push({kind:a.to===t?"delegatesTo":"delegates",who:r}):/collaborat/.test(a.kind)?s.some(l=>l.kind==="collaborates"&&l.who===r)||s.push({kind:"collaborates",who:r}):/escalat/.test(a.kind)&&a.from===t?s.push({kind:"escalates",who:r}):s.push({kind:"linked",who:r,label:a.kind})}return s}const Ig=t=>t.nodes.filter(n=>!n.stopped&&Vs(n)).map(n=>pn(n.logicalId,n.session));function Wa({on:t,label:n,disabled:s,onChange:a,describedBy:r}){return e.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-label":n,disabled:s,"aria-describedby":r,onClick:()=>a(!t),className:`relative h-6 w-10 flex-none rounded-full border border-line transition-colors disabled:opacity-45 ${t?"border-transparent bg-ok":"bg-raised"}`,children:e.jsx("span",{className:`absolute top-0.5 h-4.5 w-4.5 rounded-full bg-white shadow-sm transition-all ${t?"left-[18px]":"left-0.5"}`,"aria-hidden":"true"})})}const Lg={on:"border-ok/40 text-ok",go:"border-info/40 text-info",part:"border-attention/45 text-attention",bad:"border-approval/45 text-approval",plain:"border-input text-muted"};function us({tone:t,children:n,flat:s=!1}){return e.jsxs("span",{"data-chip":t,className:`inline-flex h-[22px] flex-none items-center gap-1.5 rounded-full border px-[9px] text-[12px] font-medium whitespace-nowrap ${Lg[t]}`,children:[!s&&e.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-current"}),n]})}function Is({perm:t=!1,ok:n=!1,children:s}){const a=t?"bg-approval/12 text-approval":n?"bg-ok/12 text-ok":"bg-attention/12 text-attention";return e.jsx("span",{"data-att":t?"perm":n?"ok":"ask",className:`inline-flex h-[22px] items-center rounded-md px-2 text-[12px] whitespace-nowrap ${a}`,children:s})}function It({children:t,aside:n,id:s}){return e.jsxs("h2",{id:s,className:"flex flex-none items-center gap-2 text-[11px] font-medium tracking-[.4px] text-muted uppercase",children:[e.jsx("span",{children:t}),n!==void 0&&e.jsx("span",{className:"ml-auto text-[12px] font-normal tracking-normal normal-case",children:n})]})}function Ve({tone:t,label:n,children:s,className:a=""}){return e.jsx("section",{"aria-label":n,className:`flex-none overflow-hidden rounded-[10px] border bg-surface dark:bg-transparent ${t==="rigs"?"border-task/45":"border-line"} ${a}`,children:s})}function qr({lead:t,name:n,chip:s,sub:a,att:r,href:l,dim:o=!1,selected:c=!1,label:i}){const m=e.jsxs(e.Fragment,{children:[t,e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-[3px]",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("b",{className:`truncate text-[14.5px] font-semibold ${o?"text-muted":""}`,children:n}),s]}),a&&e.jsx("small",{className:"text-[12px] text-muted",children:a}),r&&e.jsx("span",{className:"flex flex-wrap gap-1.5",children:r})]}),l&&e.jsx(z,{name:"chevron",className:"size-4 text-muted"})]}),d=`flex min-h-[60px] items-center gap-2.5 border-b border-line px-3 py-2 last:border-b-0 ${c?"bg-secondary":""}`;return l?e.jsx("a",{href:l,"aria-label":i,"aria-current":c?"page":void 0,className:d,children:m}):e.jsx("div",{className:d,children:m})}function pr({label:t,value:n,onOpen:s}){const a=e.jsxs(e.Fragment,{children:[e.jsx("small",{className:"text-[11.5px] text-muted",children:t}),e.jsx("b",{className:"truncate text-[17px] font-semibold",children:n})]}),r="relative flex min-w-0 flex-col gap-px rounded-[10px] border border-line bg-surface px-2.5 py-2 text-left";return s?e.jsxs("button",{type:"button",onClick:s,className:r,children:[a,e.jsx("span",{"aria-hidden":"true",className:"absolute top-[7px] right-[9px] text-muted",children:"›"})]}):e.jsx("div",{className:r,children:a})}function Wt({lead:t,warn:n=!1,danger:s=!1,children:a,action:r,role:l,compact:o=!1}){return e.jsxs("div",{role:l,className:`strip flex flex-none gap-[9px] rounded-lg border text-[13px] leading-[18px] ${o?"items-center px-2.5 py-2":"items-start px-3 py-2.5"} ${s?"border-approval/45":n?"border-attention/40":"border-line"}`,children:[t,e.jsx("div",{className:`flex min-w-0 flex-1 flex-col ${o?"":"gap-2"}`,children:a}),r]})}function $e({mark:t,title:n,sub:s,children:a,onClose:r,closeLabel:l}){const o={ok:"✓",bad:"✕",warn:"!",ask:"?"}[t],c={ok:"text-ok",bad:"text-approval",warn:"text-attention",ask:"text-attention"}[t];return e.jsxs("div",{role:t==="ok"?"status":"alert","data-receipt":t,className:`flex min-h-12 items-center gap-2.5 rounded-lg border bg-surface px-3 py-2 text-[13px] leading-[18px] ${t==="bad"?"border-destructive/45":"border-line"}`,children:[e.jsx("span",{"aria-hidden":"true",className:c,children:o}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("b",{className:"font-semibold",children:n}),s!==void 0&&e.jsx("small",{className:"block text-[12px] text-muted [overflow-wrap:anywhere]",children:s}),a]}),r&&l&&e.jsx("button",{type:"button",onClick:r,"aria-label":l,title:l,className:"grid size-9 flex-none place-items-center rounded-lg text-muted active:bg-raised",children:e.jsx(z,{name:"close",className:"size-4"})})]})}function qn({commands:t}){return t.length?e.jsx("code",{className:"mt-1.5 block rounded-md bg-raised px-2 py-1.5 font-mono text-[12px] break-all whitespace-pre-wrap text-muted",children:t.join(`
|
|
16
|
+
`)}):null}function $l({title:t,body:n}){return e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-destructive/40 bg-danger-bg/70 px-2.5 py-[9px] text-[13px] leading-[18px]",children:[e.jsx(z,{name:"warning",className:"mt-px size-4 text-approval"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("b",{className:"block font-semibold",children:t}),n!==void 0&&e.jsx("span",{className:"text-muted",children:n})]})]})}const bs=({className:t="text-info"})=>e.jsx("span",{"aria-hidden":"true",className:`inline-block size-[13px] flex-none animate-spin rounded-full border-[1.6px] border-current border-r-transparent ${t}`});function Ls({children:t,bar:n=!1}){return e.jsxs("div",{role:"status",className:`flex flex-none items-center gap-2.5 px-3 py-2.5 text-[12.5px] text-muted ${n?"bleed border-t border-line bg-sidebar":"rounded-lg border border-line"}`,children:[e.jsx(bs,{}),e.jsx("span",{className:"min-w-0 flex-1",children:t})]})}function ca({label:t,options:n,value:s,onChange:a,disabled:r=!1}){return e.jsx("div",{role:"group","aria-label":t,className:"inline-flex flex-none self-start overflow-hidden rounded-lg border border-input",children:n.map(l=>e.jsx("button",{type:"button",disabled:r,"aria-pressed":l.value===s,onClick:()=>a(l.value),className:"h-9 px-3.5 text-[13px] font-medium text-muted aria-pressed:bg-raised aria-pressed:text-fg disabled:opacity-45",children:l.label},l.value))})}function Hr({pressed:t,title:n,sub:s,onClick:a,disabled:r=!1}){return e.jsxs("button",{type:"button","aria-pressed":t,disabled:r,onClick:a,className:"flex flex-col gap-0.5 rounded-lg border border-input px-[11px] py-[9px] text-left text-[13.5px] font-medium aria-pressed:border-ring aria-pressed:bg-secondary aria-pressed:shadow-[inset_0_0_0_1px_var(--color-ring)] disabled:opacity-45",children:[e.jsx("span",{children:n}),s&&e.jsx("small",{className:"text-[11.5px] font-normal text-muted",children:s})]})}function Do({on:t,label:n,onChange:s,disabled:a=!1}){return e.jsxs("label",{className:`flex min-h-12 items-center gap-3 border-b border-line px-3 py-1.5 text-[13.5px] last:border-b-0 ${a?"opacity-45":""}`,children:[e.jsx("input",{type:"checkbox",checked:t,disabled:a,onChange:r=>s(r.target.checked),className:"peer sr-only"}),e.jsx("span",{"aria-hidden":"true",className:`grid size-[18px] flex-none place-items-center rounded-[5px] border-[1.5px] text-[12px] peer-focus-visible:outline-2 peer-focus-visible:outline-info ${t?"border-primary bg-primary text-primary-fg":"border-input"}`,children:t?"✓":""}),e.jsx("span",{className:"min-w-0 flex-1",children:n})]})}function Fo({on:t,label:n,hint:s,onChange:a,disabled:r=!1}){const l=f.useId();return e.jsxs("div",{className:"flex min-h-12 items-center gap-3 border-b border-line px-3 py-1.5 text-[13.5px] last:border-b-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{children:n}),s&&e.jsx("small",{id:l,className:"text-[12px] text-muted",children:s})]}),e.jsx(Wa,{on:t,label:n,onChange:a,...r?{disabled:r}:{},...s?{describedBy:l}:{}})]})}function Og({value:t,changed:n,min:s=0,max:a=9,fewer:r,more:l,onChange:o,disabled:c=!1}){const i="h-9 w-10 text-[17px] text-fg disabled:opacity-35";return e.jsxs("span",{className:`inline-flex flex-none items-center overflow-hidden rounded-lg border ${n?"border-ring":"border-input"}`,children:[e.jsx("button",{type:"button","aria-label":r,title:r,disabled:c||t<=s,onClick:()=>o(t-1),className:i,children:"−"}),e.jsx("span",{"aria-live":"polite",className:"min-w-[30px] text-center font-mono text-[14px]",children:t}),e.jsx("button",{type:"button","aria-label":l,title:l,disabled:c||t>=a,onClick:()=>o(t+1),className:i,children:"+"})]})}function an({title:t,onClose:n,children:s,busy:a=!1}){const r=f.useId();return e.jsxs(ht,{labelledBy:r,onClose:()=>{a||n()},children:[e.jsx("h2",{id:r,className:"text-[17px] leading-6 font-semibold",children:t}),s]})}function be({tone:t="outline",size:n="md",className:s=""}={}){const a=rt({variant:t==="primary"?"primary":"outline",size:n,className:s});return t==="danger"?`${a} !border-approval/50 !text-approval`:t==="dangerfill"?`${a} !border-transparent !bg-destructive !text-primary-fg dark:!bg-primary`:a}function Ft({icon:t,children:n,size:s="size-4"}){return e.jsxs(e.Fragment,{children:[e.jsx(z,{name:t,className:s}),n]})}function Ln({children:t,retry:n,retryLabel:s}){return e.jsxs("div",{role:n?"alert":void 0,className:"flex items-center gap-2.5 px-3 py-2.5 text-[13px] text-muted",children:[n&&e.jsx(z,{name:"warning",className:"size-4 flex-none text-attention"}),e.jsx("span",{className:"min-w-0 flex-1",children:t}),n&&s&&e.jsx("button",{type:"button",onClick:n,className:be({size:"xs"}),children:s})]})}function Dg(t,n=500){const s=f.useRef(null),a=f.useRef(!1),r=()=>{s.current&&clearTimeout(s.current),s.current=null};return t?{onPointerDown:l=>{l.pointerType!=="mouse"&&(a.current=!1,r(),s.current=setTimeout(()=>{a.current=!0,t()},n))},onPointerUp:r,onPointerLeave:r,onPointerCancel:r,onContextMenu:l=>{l.preventDefault();const o=!!s.current;r(),a.current||t(),o&&(a.current=!0)},swallow:()=>{const l=a.current;return a.current=!1,l}}:{}}const Ut=u.prs,Fg={ok:"on",run:"go",fail:"bad",wait:"part",skip:"plain",none:"plain"};function Ad({pipeline:t,short:n=!1}){return e.jsx(us,{tone:Fg[t],flat:t==="none",children:n?Ut.pipe[t]:Ut.pipeline[t]})}const Ml=t=>t.split("/").at(-1)??t,en=t=>({host:Ut.host[t.forge],cli:hd(t.forge),kind:Ut.kind[t.forge]}),Id=(t,n)=>t.sessions.map(s=>n.get(s)).filter(s=>!!s);function Pg(t,n=new Date){const s=new Date(t),a=Cl(s,n);return a<=0?Ke(t):a===1?Ut.yesterday:a<7?s.toLocaleDateString(ut,{weekday:"long"}):s.toLocaleDateString(ut,{day:"numeric",month:"short"})}function Ur(t,n=new Date){const s=new Date(t),a=Ke(t),r=Cl(s,n);return r<=0?Ut.today(a):r===1?Ut.yesterdayAt(a):`${s.toLocaleDateString(ut,r<7?{weekday:"long"}:{day:"numeric",month:"short"})} ${a}`}function _s(t,n){if(t.ok)return t.key==="approved"?Ut.ok.approved(t.given,t.required):Ut.ok[t.key];switch(t.key){case"draft":return Ut.blocker.draft(n);case"approvals":return Ut.blocker.approvals(t.given,t.required);case"changes_requested":return Ut.blocker.changes_requested(t.who);case"raw":return t.code;default:return Ut.blocker[t.key]}}function Po({pr:t,sub:n,chips:s,pills:a,href:r,dim:l=!1,selected:o=!1}){const c=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mt-1.5 self-start",children:e.jsx(ze,{state:l?"done":gs[t.pipeline],pulse:!l&&t.pipeline==="run"})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-[3px]",children:[e.jsxs("span",{className:`truncate text-[14px] ${l?"text-muted":""}`,children:[e.jsx("b",{className:"mr-1 font-mono text-[13px] font-semibold",children:t.ref}),t.title]}),a&&e.jsx("span",{className:"flex flex-wrap gap-1",children:a}),e.jsx("small",{className:"truncate text-[12px] text-muted",children:n}),s&&e.jsx("span",{className:"flex flex-wrap gap-1.5",children:s})]}),r&&e.jsx(z,{name:"chevron",className:"size-4 text-muted"})]}),i=`flex min-h-[60px] items-center gap-2.5 border-b border-line px-3 py-2 last:border-b-0 ${o?"bg-secondary":""}`;return r?e.jsx("a",{href:r,"data-pr":t.id,"aria-current":o?"page":void 0,className:i,children:c}):e.jsx("div",{"data-pr":t.id,className:i,children:c})}const zo=u.prs,zg=()=>()=>{},Bo=()=>null;function Bg(t){return f.useSyncExternalStore(t?t.subscribe:zg,t?t.getState:Bo,t?t.getState:Bo)}function qg({forge:t,mobile:n,session:s}){var o;const a=Bg(t);if(!((o=n.daemon)!=null&&o.forge))return null;const r=yg((a==null?void 0:a.state)??null,s.id);if(!r)return null;if("pr"in r)return e.jsxs("a",{href:ce({name:"pr",id:r.pr.id}),"data-pr-chip":r.pr.id,className:"inline-flex h-8 flex-none items-center gap-[5px] font-mono text-[11px]",children:[e.jsx(ze,{state:gs[r.pr.pipeline],pulse:r.pr.pipeline==="run"}),r.pr.ref]});const l=en({forge:r.kind});return e.jsx(Ug,{tip:zo.chipTip(l.host,n.daemon.name,l.kind),label:zo.chipUnknown(l.kind)})}const Hg=4e3;function Ug({tip:t,label:n}){const s=f.useRef(null),[a,r]=f.useState(null);f.useEffect(()=>{if(!a)return;const o=setTimeout(()=>r(null),Hg),c=i=>{var m;(m=s.current)!=null&&m.contains(i.target)||r(null)};return document.addEventListener("pointerdown",c,!0),()=>{clearTimeout(o),document.removeEventListener("pointerdown",c,!0)}},[a]);const l=()=>{var m,d;if(a){r(null);return}const o=(m=s.current)==null?void 0:m.closest("footer"),c=(d=(o==null?void 0:o.previousElementSibling)??o)==null?void 0:d.getBoundingClientRect(),i=globalThis.innerHeight??0;r({bottom:c?Math.max(i-c.top+8,8):96})};return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:s,type:"button","aria-label":t,title:t,onClick:l,"data-pr-chip":"unknown",className:"flex-none rounded-md border border-dashed border-input px-[5px] font-mono text-[11px] text-muted",children:n}),a&&e.jsx("span",{role:"status","data-chip-toast":"",style:a,className:"fixed inset-x-3.5 z-[7] flex items-center gap-2.5 rounded-[10px] border border-line bg-surface px-3 py-2.5 text-[13px] leading-[18px] whitespace-normal text-fg shadow-[0_8px_24px_#0005]",children:t})]})}function El({session:t,nameClassName:n="sn-name",nameStyle:s}){return t.label?e.jsxs(e.Fragment,{children:[t.label,e.jsxs("span",{className:n,...s?{style:s}:{},children:[" (",t.name,")"]})]}):e.jsx(e.Fragment,{children:t.name})}function Wg({text:t}){const n=f.useMemo(()=>pf(t),[t]);return e.jsx(jh,{doc:n})}const qo=({align:t})=>e.jsx("div",{className:`text-meta text-muted ${t==="end"?"text-right":""}`,children:u.thread.cut}),Ho={success:{glyph:"✓",tone:"text-ok"},running:{glyph:"●",tone:"text-info"},failed:{glyph:"✕",tone:"text-danger-fg"},unknown:{glyph:"·",tone:"text-muted"}};function Kg({tools:t}){const[n,s]=f.useState(!1),a=u.sessions;return e.jsxs("div",{className:"rounded-lg border border-line font-mono text-small leading-4 text-muted",children:[e.jsxs("button",{type:"button","aria-expanded":n,onClick:()=>s(r=>!r),className:"flex h-[34px] w-full items-center gap-1.5 px-2.5 text-left font-sans text-[12.5px]",children:[e.jsx(z,{name:"chevron",className:`size-3.5 transition-transform ${n?"rotate-90":""}`}),e.jsx("span",{className:"min-w-0 truncate",children:n?a.tools(t.length):a.toolsNamed(t.length,_p(t).join(", "))})]}),n&&e.jsx("ul",{className:"pb-2",children:t.map(r=>e.jsxs("li",{className:"flex gap-1.5 px-2.5 py-[3px]",children:[e.jsx("span",{"aria-label":a.toolStatus[r.status],role:"img",className:Ho[r.status].tone,children:Ho[r.status].glyph}),e.jsxs("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:[e.jsx("b",{className:"font-medium text-fg",children:r.name})," ",r.label]})]},r.id))})]})}function Vg({store:t,item:n,onReconnect:s,keys:a}){var c,i,m;const r=xe(t),l=mn(),o=r.sessions.get(n.sessionId);return e.jsx(gf,{store:t,item:n,session:o,inThread:!0,keys:a,mode:_m(n,(c=r.capabilities)==null?void 0:c[n.tool],(o==null?void 0:o.readOnly)===!0),outcome:pc(n,[...r.sessions.values()],r.ops),fresh:r.fresh,ghost:!1,changed:!1,onReread:()=>{},canConfirm:((i=r.device)==null?void 0:i.confirm)===!0&&l,enroll:l&&((m=r.device)==null?void 0:m.confirm)!==!0,onGone:()=>{},onCheck:s})}function Gg({item:t,store:n,storage:s,inPanel:a=!1,onReconnect:r,keys:l=!1}){switch(t.kind){case"tools":return e.jsx(Kg,{tools:t.tools});case"time":return e.jsx("div",{className:"text-center font-mono text-meta text-muted",children:t.label});case"rig-message":case"rig-task":case"rig-notice":case"rig-fold":case"rig-unreadable":case"rig-raw":return e.jsx(Th,{e:t,storage:s,store:n});case"me":{const o=t.images??(t.attachments??[]).flatMap(c=>n.knownImage(c)??[]);return e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[t.text&&e.jsx("div",{className:"max-w-[94%] rounded-2xl rounded-br-[4px] bg-raised p-3.5 text-body [overflow-wrap:anywhere] whitespace-pre-wrap",children:t.text}),e.jsx(To,{store:n,refs:o,align:"end"}),t.cut&&e.jsx(qo,{align:"end"}),t.delivery&&e.jsx("div",{role:t.delivery==="sending"?"status":void 0,className:`text-meta ${t.delivery==="uncertain"?"text-attention":t.delivery==="sending"?"text-muted":"text-ok"}`,children:t.delivery==="sending"?u.thread.delivery.sending:t.delivery==="uncertain"?u.thread.delivery.uncertain:t.fresh?u.thread.delivery.takenNow:u.thread.delivery.taken})]})}case"agent":return e.jsxs("div",{className:"flex flex-col items-start gap-1",children:[e.jsx("article",{"aria-label":u.thread.agentLabel,className:"max-w-[94%] rounded-2xl rounded-bl-[4px] border border-line bg-surface p-3.5 text-body [overflow-wrap:anywhere]",children:e.jsx(Wg,{text:t.text})}),t.cut&&e.jsx(qo,{align:"start"})]});case"task":return e.jsx(Ih,{task:t.task,cut:t.cut});case"capture":{const o=t.images[0];return e.jsxs("div",{className:"flex flex-col items-start gap-1",children:[e.jsxs("div",{className:"text-meta text-muted",children:[e.jsx("span",{"aria-hidden":!0,children:"✓"})," ",e.jsx("span",{children:t.label}),o&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("span",{className:"font-mono",children:[o.width,"×",o.height]})]})]}),e.jsx(To,{store:n,refs:t.images,align:"start"})]})}case"event":return e.jsx("div",{className:"text-center text-meta text-muted",children:t.label});case"awaiting":return a?e.jsxs(De,{title:a?u.atelier.awaiting:u.thread.awaiting,tone:t.item.kind==="question"?"warning":"approval",children:[e.jsx("p",{className:"[overflow-wrap:anywhere]",children:Ia(t.item)}),e.jsxs("a",{href:ce(a?{name:"atelier",sessionId:t.item.sessionId,requestKey:t.item.key}:{name:"request",sessionId:t.item.sessionId,key:t.item.key}),className:We({block:!0,className:"mt-3"}),children:[u.thread.examine,e.jsx(z,{name:"arrowRight"})]})]}):e.jsx(Vg,{store:n,item:t.item,onReconnect:r,keys:l})}}function Xg({sessionId:t,panel:n}){return e.jsxs(e.Fragment,{children:[e.jsx("a",{href:ce({name:"thread",sessionId:t}),"aria-label":u.atelier.fullScreen,title:u.atelier.fullScreen,className:Ot({variant:"outline"}),children:e.jsx(z,{name:"external"})}),e.jsx("button",{type:"button",onClick:n.onClose,"aria-label":u.atelier.closePanel,title:u.atelier.closeTitle,className:Ot({}),children:e.jsx(z,{name:"close"})})]})}function Wr({store:t,sessionId:n,storage:s,onReconnect:a,panel:r,forge:l}){var ge,qe,et,vt,Vt,tn,Gt,Xt,U,Se,ie,Ie,tt;const o=xe(t),c=Kt(),i=Dt(),m=Pa(),d=o.sessions.get(n),x=o.threads.get(n),{fresh:p,ops:g}=o,[h,N]=f.useState(()=>Zc(n,s)),[k]=f.useState(()=>Bf(n)),[C,j]=f.useState(!1),y=(ge=o.daemon)!=null&&ge.taskAnswer?hh(o.tasks.values(),n):[],[b,M]=f.useState(null),S=Wh(t),$=f.useRef(new Map);f.useEffect(()=>{var Ce;for(const[He,bt]of $.current){const wt=(Ce=g[He])==null?void 0:Ce.phase;wt==="applied"?$.current.delete(He):(wt==="rejected"||wt==="failed"||wt==="uncertain")&&($.current.delete(He),S.putBack(bt))}});const v=Ce=>{N(Ce),Jc(n,Ce,s),j(!1)},[A,R]=f.useState(null),[_,L]=f.useState(!1),[T,B]=f.useState(!1),[E,P]=f.useState(!1),[W,F]=f.useState(null),re=((qe=zx(n,g))==null?void 0:qe.op)??null,Y=f.useRef(d==null?void 0:d.state);f.useEffect(()=>{Y.current!==(d==null?void 0:d.state)&&Y.current!==void 0&&F(re),Y.current=d==null?void 0:d.state},[d==null?void 0:d.state,re]),f.useEffect(()=>(t.openThread(n),()=>t.watch(null)),[t,n]),f.useEffect(()=>{p&&t.watch(n)},[t,n,p]);const H=(x==null?void 0:x.status)==="ready"?(et=x.items.at(-1))==null?void 0:et.at:void 0;f.useEffect(()=>{H&&t.read(n,H)},[t,n,H]);const I=Ic(n,g).at(-1);f.useEffect(()=>{(I==null?void 0:I.phase)!=="applied"||Ff(I.op,s)||(Pf(I.op,s),h.trim()===I.message.text&&v(""))},[I==null?void 0:I.phase,I==null?void 0:I.op]);const[D,Q]=f.useState(""),q=d==null?void 0:d.state;f.useEffect(()=>{(I==null?void 0:I.phase)==="applied"&&q&&q!=="idle"&&Q(I.op)},[q,I==null?void 0:I.phase,I==null?void 0:I.op]);const K=f.useRef(null),ee=(x==null?void 0:x.status)==="gone",ue=d&&!ee?Lp((x==null?void 0:x.items)??[],d,g,c,(x==null?void 0:x.cut)??[],o.sessions,((vt=o.device)==null?void 0:vt.id)??null):[],fe=(Vt=ue.at(-1))==null?void 0:Vt.key,he=f.useRef(!0),[w,O]=f.useState(!1),V=()=>{const Ce=K.current;Ce&&(Ce.scrollTop=Ce.scrollHeight),he.current=!0,O(!1)},Z=f.useRef(!1);f.useLayoutEffect(()=>{var He;const Ce=K.current;if(!(!Ce||ue.length===0)){if(!Z.current){Z.current=!0;const bt=fr.get(n);if(fr.delete(n),bt!==void 0){Ce.scrollTop=bt,he.current=Ce.scrollHeight-Ce.scrollTop-Ce.clientHeight<Uo;return}}he.current?V():((He=ue.at(-1))==null?void 0:He.kind)==="awaiting"&&O(!0)}},[fe,ue.length,x==null?void 0:x.items]);const X=()=>{const Ce=K.current;Ce&&(he.current=Ce.scrollHeight-Ce.scrollTop-Ce.clientHeight<Uo,he.current&&O(!1))};if(!d||ee){const Ce=!ee&&!p&&o.syncedAt===null;return e.jsxs(e.Fragment,{children:[e.jsx("header",{className:"flex-none border-b border-line pt-2 pb-3",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[!r&&e.jsx(Zt,{fallback:{name:"sessions"},label:u.thread.back}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:u.thread.title}),e.jsx(fc,{link:fs(o)}),r&&e.jsx("button",{type:"button",onClick:r.onClose,"aria-label":u.atelier.closePanel,title:u.atelier.closeTitle,className:Ot({}),children:e.jsx(z,{name:"close"})})]})}),e.jsx("main",{className:"min-h-0 flex-1 pt-7 text-body text-muted",role:"status",children:Ce?u.thread.loading:u.thread.unknown})]})}const J=I!==void 0&&yn(I.phase),pe=(I==null?void 0:I.phase)==="applied"&&D!==I.op&&d.state==="idle"&&!d.pending&&c-Date.parse(I.at)<Ar,Ne=Op(d,p?"ready":"pc_offline",J||pe),Xe=I&&(I.phase==="rejected"||I.phase==="failed"||I.phase==="uncertain")&&(I.phase==="uncertain"||h.trim()===I.message.text)?eg(I):null,gt=C&&!Xe?{title:u.thread.composer.failTitle,body:u.thread.composer.lost}:Xe,Be=!!d.pending||d.state==="waiting_input"||d.state==="waiting_permission",Je=()=>{const Ce=h.trim();if(!Ce&&S.items.length===0||!Ne.enabled||md(h)||!S.ready||S.items.length>0&&Be)return;F(re);const He=S.ids(),bt=S.clear(),wt=t.reply(n,Ce,He.length?{attachments:He}:{});!wt&&bt.length?S.putBack(bt):wt&&bt.length&&$.current.set(wt,bt),j(!wt)},oe=(x==null?void 0:x.status)==="ready",de=((tn=o.daemon)==null?void 0:tn.boot)??null,ke=Bx(d,g,c,{fresh:p,boot:de}),Oe=nl(d,g,de,c),lt=!!((Gt=o.daemon)!=null&&Gt.sessionClose)&&!d.readOnly,xt=sg(!!((Xt=o.daemon)!=null&&Xt.adopt),d,o.adoptFailures[n]),kt=ke.kind==="open"&&ke.error&&ke.error.op!==W?ke.error:null,ct=Ce=>{F(re),P(!1),R(Ce)},mt=!!r&&d.tool==="omp",G=ms(d),_e=Vh(n,s),we=d.state==="exited"&&d.exitedAt?u.sessions.line.ended(zi(d.exitedAt,c)):void 0,le=m&&[d.project,d.branch].filter(Boolean).join(" · ")||void 0;return e.jsxs(e.Fragment,{children:[e.jsx(La,{back:r?e.jsx("span",{className:"w-2.5"}):e.jsx(Zt,{fallback:{name:"sessions"},label:u.thread.back}),tool:d.tool,name:e.jsx(El,{session:d,nameClassName:"font-normal text-muted"}),dot:G,pulse:G==="work"&&p,sub:we??le,under:!m&&!!we,more:e.jsxs(e.Fragment,{children:[r?e.jsx(Xg,{sessionId:n,panel:r}):e.jsx(Ld,{sessionId:n,current:"thread",onLeave:()=>{K.current&&fr.set(n,K.current.scrollTop)}}),e.jsx("button",{type:"button","aria-haspopup":"dialog","aria-label":u.sessions.moreOf(d.name),title:u.sessions.more,onClick:()=>L(!0),className:Ot({className:_?"bg-raised text-fg":"text-muted"}),children:e.jsx(z,{name:"more"})})]})}),mt?e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[e.jsx("h2",{className:"text-heading",children:u.atelier.ompNoThread}),e.jsx("p",{className:"max-w-[320px] text-body text-muted",children:u.atelier.ompBody}),e.jsxs("a",{href:ce({name:"terminal",sessionId:n}),className:We({variant:"primary"}),children:[e.jsx(z,{name:"terminal"}),u.atelier.ompTerminal]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("main",{ref:K,onScroll:X,"aria-label":u.thread.log(d.name),className:"flex min-h-0 flex-1 flex-col gap-3.5 overflow-y-auto overscroll-contain pt-5 pb-4 phone-side:pt-3 phone-side:pb-3",children:[((U=o.daemon)==null?void 0:U.checklist)&&o.checklists.get(n)&&e.jsx(Vc,{checklist:o.checklists.get(n),current:(Se=d==null?void 0:d.checklist)==null?void 0:Se.current}),(x==null?void 0:x.more)&&e.jsx("p",{className:"text-center text-meta text-muted",children:u.thread.more}),!(x!=null&&x.more)&&_e!==null&&e.jsx("p",{className:"flex items-center gap-2 text-[12px] text-muted before:h-px before:flex-1 before:bg-line before:content-[''] after:h-px after:flex-1 after:bg-line after:content-['']",children:u.launch.started(d.name,_e)}),!oe&&ue.length===0&&e.jsx("p",{className:"text-center text-meta text-muted",role:"status",children:p?u.thread.loading:u.thread.unavailable}),oe&&ue.length===0&&e.jsx("p",{className:"text-center text-meta text-muted",children:u.thread.empty}),ue.map(Ce=>e.jsx(Gg,{item:Ce,store:t,storage:s,inPanel:!!r,onReconnect:a,keys:i&&!r},Ce.key))]}),w&&e.jsx("div",{className:"relative h-0",children:e.jsxs("button",{type:"button",onClick:V,className:"absolute bottom-3 left-1/2 inline-flex h-9 -translate-x-1/2 items-center gap-1.5 rounded-full border border-line bg-surface px-3.5 text-[13px] font-medium text-fg shadow-sm",children:[e.jsx(z,{name:"down",className:"size-4"}),u.sessions.requestBelow]})}),ke.kind!=="open"&&(y.length>0||b!==null)&&e.jsx(Eo,{store:t,session:d,tasks:y,sent:b,onSent:M}),xt?e.jsx(ag,{store:t,session:d,onResume:()=>ct("resume")}):ke.kind==="open"&&(y.length>0||b!==null)?e.jsx(Eo,{store:t,session:d,tasks:y,sent:b,onSent:M}):ke.kind==="open"?e.jsx(tg,{name:d.name,focusAtEnd:k,composer:i&&rd()?{...Ne,placeholder:`${Ne.placeholder} · ${u.sessions.keysHint}`}:Ne,draft:h,onDraft:v,onSend:Je,fresh:p,taken:pe,checking:(I==null?void 0:I.phase)==="uncertain"&&p,error:gt,onReconnect:a,images:S,dialog:Be,...(ie=o.daemon)!=null&&ie.commands&&d.tool==="claude"&&!d.readOnly?{slash:{tool:u.tools[d.tool],listing:o.commands[n],ask:()=>t.requestCommands(n)}}:{},alert:kt&&e.jsx(fd,{error:kt,fresh:p,onRetry:()=>ct("close"),onReconnect:a}),...Vn(o.daemon,d)?{lead:e.jsx(Tf,{store:t,session:d}),leadNote:e.jsx(Af,{store:t,session:d})}:{}}):e.jsx(ig,{ending:ke.kind==="ended"&&((Ie=ke.error)==null?void 0:Ie.op)===W?{...ke,error:null}:ke,name:d.name,canResume:lt,resumeHeld:qx(d,g,de,c),readOnly:!!d.readOnly,fresh:p,focus:E,onResume:()=>ct("resume"),onReconnect:a},ke.kind),e.jsx(rg,{store:t}),e.jsx(Od,{store:t,forge:l,session:d,wide:m,threshold:((tt=o.device)==null?void 0:tt.contextNear)??Ta,onModel:()=>B(!0)})]}),_&&e.jsx(bl,{store:t,session:d,closable:lt&&!mt,closing:Oe,onClose:()=>L(!1),onModel:()=>{L(!1),B(!0)},onCloseSession:()=>{L(!1),ct("close")}}),T&&Vn(o.daemon,d)&&e.jsx(qa,{store:t,session:d,onClose:()=>B(!1)}),A&&e.jsx(kl,{store:t,session:d,mode:A,onClose:()=>R(null),onSent:()=>{P(!0),R(null)},onReconnect:a})]})}const fr=new Map,Uo=48;function Ld({sessionId:t,current:n,onLeave:s}){const a=u.sessions.view,r="grid h-9 place-items-center px-3 tablet:px-3.5 text-[13px] font-medium text-muted aria-[current=page]:bg-raised aria-[current=page]:text-fg";return e.jsxs("nav",{"aria-label":a.label,className:"flex flex-none overflow-hidden rounded-lg border border-input",children:[e.jsx("a",{href:ce({name:"thread",sessionId:t}),onClick:n==="thread"?void 0:s,"aria-current":n==="thread"?"page":void 0,className:r,children:a.thread}),e.jsx("a",{href:ce({name:"terminal",sessionId:t}),onClick:n==="terminal"?void 0:s,"aria-current":n==="terminal"?"page":void 0,className:r,children:a.terminal})]})}function Od({store:t,forge:n,session:s,wide:a,threshold:r,onModel:l}){const o=xe(t),{daemon:c,fresh:i,usage:m,usageAlert:d}=o,x=Kt(),p=Wc(s,x,r),g=u.sessions,h=Qc(c,s)===null,N=a?Ef(s.tool,m,d,x,i):null;return e.jsxs("footer",{"aria-label":g.foot(s.name),className:"bleed flex h-10 flex-none items-center gap-2.5 border-t border-line bg-sidebar px-3 text-small whitespace-nowrap text-muted",children:[p.model&&(h?e.jsxs("button",{type:"button",disabled:!i,"aria-haspopup":"dialog","aria-label":u.model.chip(p.model),onClick:l,className:"inline-flex h-8 items-center gap-1 text-fg disabled:opacity-60",children:[p.model,e.jsx(z,{name:"down",className:"size-3.5"})]}):e.jsx("span",{className:"text-fg",children:p.model})),p.context&&e.jsxs("span",{role:"img","aria-label":g.contextLabel(p.context.pct),className:`inline-flex items-center gap-1.5 ${p.context.near?"text-attention":""}`,children:[e.jsx("span",{className:"relative block h-1 w-8 overflow-hidden rounded-sm bg-raised",children:e.jsx("span",{className:"absolute inset-y-0 left-0 bg-current",style:{width:`${p.context.pct}%`}})}),p.context.pct," %"]}),a&&s.context&&e.jsxs("span",{children:["· ",So(s.context.used)," / ",So(s.context.window)]}),(p.model||p.context)&&e.jsx("span",{className:"h-3 w-px flex-none bg-line"}),s.branch?e.jsx("span",{className:`min-w-0 truncate font-mono text-[11px] ${a?"":"flex-1"}`,children:s.branch}):e.jsxs("span",{"aria-label":g.folder(s.project),className:`inline-flex min-w-0 items-center gap-1 ${a?"":"flex-1"}`,children:[e.jsx(z,{name:"folder",className:"size-3.5"}),e.jsx("span",{className:"truncate",children:s.project})]}),s.branch&&e.jsx(qg,{forge:n,mobile:o,session:s}),a&&s.branch&&e.jsx("span",{className:"min-w-0 truncate",children:s.project}),a&&e.jsx("span",{className:"flex-1"}),N&&e.jsxs("span",{className:"flex-none",children:[u.limits.harnessShort[N.harness]??N.harness," ",jl(N.window)," ",e.jsxs("b",{className:`font-semibold ${N.tone==="red"?"text-approval":N.tone==="amber"?"text-attention":"text-fg"}`,children:[N.window.pct," %"]})]})]})}const Yg={approval:{fg:"var(--danger-text)"},question:{fg:"var(--warning)"},starting:{fg:"var(--info)"},idle:{fg:"var(--success)"},working:{fg:"var(--info)"},done:{fg:"var(--muted-foreground)"},error:{fg:"var(--danger-text)"},readonly:{fg:"var(--muted-foreground)"}};function Qg({state:t,label:n,tone:s,caps:a=!1}){const{stateLabel:r}=el(),l=Yg[s??t].fg;return e.jsx("span",{"data-badge":t,style:{display:"inline-flex",alignItems:"center",flexShrink:0,height:a?24:22,padding:a?"0 9px":"0 8px",boxSizing:"border-box",borderRadius:5,color:l,background:"color-mix(in srgb, currentColor 10%, transparent)",fontSize:a?11:12,lineHeight:1,fontWeight:500,letterSpacing:a?"0.08em":void 0,textTransform:a?"uppercase":void 0,whiteSpace:"nowrap",transition:Fm([["background-color","hover"],["color","hover"]])},children:n??r[t]})}const Wo=["monstera","fern","snake","ficus","succulent"],Zg=["tl","tr","br","ml","mr"];function Jg(t,n){const s=ls(t),a=1+s%2;return Zg.filter(r=>!n.includes(r)).sort((r,l)=>ls(t+r)-ls(t+l)).slice(0,a).map((r,l)=>({spot:r,species:Wo[(s+l*7)%Wo.length],flip:!!(s>>l&1)}))}const _n={top:56,side:12,bottom:34},Ko=11/12,Dd=t=>t.width>=t.height?"land":"port";function eb(t,n,s){if(t.length===0||n.width<=0||n.height<=0)return{zoom:1,along:s==="land"?"row":"column"};const a=Math.max(...t.map(o=>o.h)),r=Math.max(...t.map(o=>o.w));return{zoom:s==="land"?Math.min(1,Math.max(Ko,(n.height-4)/(a+_n.top+_n.bottom))):Math.min(1,Math.max(Ko,(n.width-4)/(r+2*_n.side))),along:s==="land"?"row":"column"}}const tb={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"};function wa(t){return t.state==="idle"&&(t.helpers??[]).some(n=>n.state!=="exited"&&n.state!=="idle")?"working":tb[t.state]}const Fd=t=>t.state==="waiting_permission"||t.state==="waiting_input",Pd=["M5 10.4a1.6 1.6 0 1 0 0 3.2 1.6 1.6 0 0 0 0-3.2Z","M12 10.4a1.6 1.6 0 1 0 0 3.2 1.6 1.6 0 0 0 0-3.2Z","M19 10.4a1.6 1.6 0 1 0 0 3.2 1.6 1.6 0 0 0 0-3.2Z"],nb=["M12 2.5 20.5 7.25v9.5L12 21.5l-8.5-4.75v-9.5z","M12 8.5a3.5 3.5 0 1 0 0 7a3.5 3.5 0 1 0 0-7"],sb=["M4 7h16v12H4z","M4 7l2-3h4l2 3","M9 13h6"],Rs=t=>t.topic??t.title;function Kr({session:t,size:n,frozen:s}){const a=Gn(),r=wa(t);return e.jsx(Da,{tool:t.tool,state:r,pose:Oa(t.id,t.state),size:n,theme:a,seed:t.id,frozen:s,readOnly:!!t.readOnly})}function Vo({helper:t,parent:n,size:s,frozen:a}){const r=Gn(),l=`${n.id}:${t.id}`,o=Zi(t);return e.jsx(Da,{tool:n.tool,state:o,pose:Oa(l,o),size:s,theme:r,seed:l,frozen:a,readOnly:!!n.readOnly})}const zd=({state:t})=>e.jsx(Qg,{state:t}),Bd=({color:t})=>t?e.jsx("i",{className:"side-swatch",style:{background:t}}):e.jsx("i",{className:"filter-none"}),ab={monstera:()=>e.jsxs("span",{className:"p-monstera",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("b",{})]}),fern:()=>e.jsxs("span",{className:"p-fern",children:[[0,1,2,3,4,5,6].map(t=>e.jsx("i",{},t)),e.jsx("b",{})]}),snake:()=>e.jsxs("span",{className:"p-snake",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("b",{})]}),ficus:()=>e.jsxs("span",{className:"p-ficus",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("em",{}),e.jsx("b",{})]}),succulent:()=>e.jsxs("span",{className:"p-succulent",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("b",{})]})};function rb({seed:t,left:n,width:s,avoid:a}){return e.jsx("div",{className:"plants","aria-hidden":"true",style:{left:n,width:s},children:Jg(t,a).map(({spot:r,species:l,flip:o})=>{const c=ab[l];return e.jsx("span",{className:`plant-spot spot-${r}${o?" flip":""}`,children:e.jsx(c,{})},r)})})}const Go=t=>e.jsxs(e.Fragment,{children:[(t==="approval"||t==="question")&&e.jsx("b",{className:"sheet-flag"}),t==="done"&&e.jsx("i",{className:"sheet-stamp",children:"✓"})]});function lb({sheets:t,length:n}){return e.jsx("div",{className:"table-top",children:t.map(a=>e.jsxs(f.Fragment,{children:[e.jsxs("div",{style:{left:a.x-84/2},className:`task-sheet sheet-${a.slot} sheet-${a.state}`,children:[e.jsx("p",{lang:"fr",children:a.task}),Go(a.state)]}),a.note&&e.jsxs("div",{style:{left:tm(a.x,t.filter(r=>r.slot===a.slot).map(r=>r.x),n)},className:`sheet-note note-${a.slot} sheet-${a.note.state}`,children:[e.jsx("p",{children:a.note.task}),Go(a.note.state),a.note.more>0&&e.jsxs("em",{className:"note-more",children:["+",a.note.more]})]})]},a.id))})}function ob({table:t,project:n,color:s,frozen:a,act:r,helpers:l=!0}){const{length:o,width:c,seats:i,ends:m,notes:d,extra:x,extraCount:p}=em(t.mains,l,zs,En),g=j=>`calc(50% - ${o/2}px + ${j}px)`,h=nm(t.mains),N=i.map(({session:j,x:y,side:b})=>{const M=d.get(j.id);return{id:j.id,task:Rs(j),state:eo(wa(j)),slot:b,x:y,note:M&&{task:M.helper.task,state:eo(Zi(M.helper)),more:M.more}}}),k=[...x.mains.map(j=>({key:j.id,el:e.jsx(Kr,{session:j,size:18,frozen:a})})),...x.helpers.map(({helper:j,parent:y})=>({key:`${y.id}:${j.id}`,el:e.jsx(Vo,{helper:j,parent:y,size:18,frozen:a})}))].slice(0,3),C=[...p>0?["br"]:[],...m.some(j=>j.end==="left")?["ml"]:[],...m.some(j=>j.end==="right")?["mr"]:[]];return e.jsx("section",{className:"atelier-table","data-project":n.id,"data-table":t.key,"aria-label":u.atelier.table(n.name),style:{"--room":`${c}px`,"--project":s},children:e.jsxs("div",{className:"table-scene",children:[e.jsx("div",{className:"office-rug",style:{left:g(-En),right:"auto",width:o+2*En}}),e.jsxs("div",{className:"rug-labels",style:{left:g(-En),width:o+2*En},children:[e.jsxs("div",{className:"room-heading",children:[e.jsx(Bd,{color:s}),e.jsxs("span",{className:"heading-names",children:[e.jsx("button",{type:"button",className:"project-conversations",title:n.name,"aria-label":u.atelier.conversations(n.name),onClick:()=>r.room(n.id),children:n.name}),h!==null&&e.jsxs("span",{className:"heading-branch",title:h,children:["⎇ ",h]})]}),e.jsx("span",{className:"spacer"}),e.jsx("span",{className:"room-menu-wrap",children:e.jsx("button",{type:"button",className:"icon-action","aria-label":u.atelier.roomMenu(n.name),onClick:()=>r.room(n.id),children:e.jsx(cs,{d:[],fill:Pd,size:14})})})]}),p>0&&e.jsxs("button",{type:"button",className:"table-more",onClick:()=>r.room(n.id),children:[e.jsx("span",{className:"more-faces","aria-hidden":"true",children:k.map(j=>e.jsx("i",{children:j.el},j.key))}),u.atelier.more(p)]})]}),e.jsx(rb,{seed:t.key,left:g(-En),width:o+2*En,avoid:C}),i.map(({session:j,x:y,side:b})=>e.jsx("div",{className:`office-chair chair-${b}`,"aria-hidden":"true",style:{left:g(y-27)}},j.id)),e.jsx("div",{className:"worktable","aria-hidden":"true",style:{left:g(0),right:"auto",width:o},children:e.jsx(lb,{length:o,sheets:N})}),i.map(({session:j,x:y,side:b})=>{var S;const M=wa(j);return e.jsxs("button",{type:"button",style:{left:g(y-56)},"data-agent":j.id,"aria-label":u.atelier.seat(j.name,Rs(j)),onClick:()=>r.open(j.id),className:`agent-seat place-${b}${!a&&M==="working"?" seat-working":""}${a?" seat-offline":""}`,children:[e.jsx(Kr,{session:j,size:64,frozen:a}),e.jsx("strong",{children:e.jsx("span",{className:"seat-name",title:j.name,children:j.name})}),e.jsx("span",{className:"seat-machine",children:((S=j.rig)==null?void 0:S.role)??"local"}),e.jsx(zd,{state:M})]},j.id)}),m.map(({helper:j,parent:y,end:b,slot:M,count:S})=>e.jsxs("button",{type:"button",style:{left:g(b==="left"?-70:o+8),right:"auto",top:S>1?M?232:126:void 0},className:`agent-seat helper-seat end-${b}`,"aria-label":u.atelier.helperSeat(j.kind,y.name,j.task),title:j.task,onClick:()=>r.open(y.id),children:[e.jsx(Vo,{helper:j,parent:y,size:36,frozen:a}),e.jsx("strong",{children:j.kind}),e.jsxs("span",{className:"seat-meta",children:["↳ ",y.name]})]},`${y.id}:${j.id}`))]})})}function ib({project:t,tables:n,rig:s,width:a,act:r,children:l}){const o=n.flatMap(p=>p.mains),c=s?o.filter(p=>p.state!=="exited"):o,i=c.filter(Fd).length,m=c.filter(p=>p.state==="working").length,d=(s==null?void 0:s.kind)==="kernel"?u.atelier.kernel:t.name,x=()=>r.room(t.id);return e.jsxs("section",{className:`project-room atelier-room${s?` rig-room ${s.kind}-room`:""}`,"data-room":t.id,"aria-label":s?u.atelier.rigRoom(s.kind,t.name):u.atelier.room(t.name),style:{"--room":`${a}px`,"--project":os[t.color],"--room-side":`${Ji}px`,"--room-back":`${om}px`,"--table-gap":`${ec}px`},children:[e.jsxs("div",{className:"room-walls","aria-hidden":"true",children:[e.jsx("i",{className:"wall-back"}),e.jsx("i",{className:"wall-left"}),e.jsx("i",{className:"wall-right"}),e.jsx("i",{className:"wall-front"})]}),e.jsxs("div",{className:`room-plaque${s?" rig-plaque":""}`,children:[s?e.jsx("span",{className:"rig-hex","aria-hidden":"true",children:e.jsx(cs,{d:nb,size:13})}):e.jsx(Bd,{color:os[t.color]}),e.jsx("strong",{className:"plaque-name",title:d,role:"button",tabIndex:0,"aria-label":u.atelier.roomMenu(d),onClick:x,onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),x())},children:d}),s?e.jsx("span",{className:"plaque-where",children:s.kind==="kernel"?u.atelier.kernelWhere:u.atelier.rigWhere(s.folder,s.project)}):e.jsx("span",{className:"plaque-counts",children:u.atelier.plaqueCounts(o.length)}),i>0&&e.jsxs("span",{className:"plaque-waiting",children:[e.jsx("i",{className:"approval-dot"}),u.atelier.waiting(i)]}),m>0&&e.jsxs("span",{className:"plaque-working",children:[e.jsx("i",{className:"live-dot"}),u.atelier.working(m)]}),!s&&e.jsx("span",{className:"room-menu-wrap",children:e.jsx("button",{type:"button",className:"icon-action","aria-label":u.atelier.roomMenu(d),onClick:x,children:e.jsx(cs,{d:[],fill:Pd,size:14})})})]}),e.jsx("div",{className:"room-tables",children:l}),e.jsx("span",{className:"room-entrance","aria-hidden":"true",children:u.atelier.entrance})]})}function cb({sessions:t,frozen:n,act:s}){return t.length===0?null:e.jsxs("section",{className:"unassigned-zone atelier","aria-labelledby":"unassigned-title",children:[e.jsxs("div",{className:"unassigned-heading",children:[e.jsx(cs,{d:sb,size:15}),e.jsx("h2",{id:"unassigned-title",children:u.atelier.unassigned}),e.jsx("span",{className:"muted",children:u.atelier.unassignedHint})]}),e.jsx("div",{className:"unassigned-list",children:t.map(a=>e.jsxs("div",{className:"unassigned-card",children:[e.jsxs("button",{type:"button",className:"unassigned-open","data-agent":a.id,"aria-label":u.atelier.seat(a.name,Rs(a)),onClick:()=>s.open(a.id),children:[e.jsx(Kr,{session:a,size:56,frozen:n}),e.jsxs("span",{className:"unassigned-copy",children:[e.jsx("strong",{children:a.name}),e.jsx("span",{title:Rs(a),children:Rs(a)}),e.jsx("code",{children:a.project})]})]}),e.jsx("div",{className:"unassigned-actions",children:e.jsx(zd,{state:wa(a)})})]},a.id))})]})}function db({count:t,requests:n=0,frozen:s,onOpen:a}){const r=Gn(),l=n>0?a:void 0;return e.jsx("div",{className:"ledge-corner",children:e.jsxs("button",{type:"button",className:"ledge-desk",onClick:l,disabled:!l,children:[e.jsx("span",{className:"ledge-bubble",children:n>0?u.atelier.ledgeRequests(n):u.atelier.watching(t)}),e.jsx("span",{className:"ledge-seat",children:e.jsx(cl,{size:80,theme:r,frozen:s})}),e.jsx("strong",{children:"Ledge"}),e.jsx("small",{children:u.atelier.assistant})]})})}function ub(){const t=u.atelier.legend;return e.jsxs("div",{className:"workspace-legend",children:[e.jsxs("span",{children:[e.jsx("i",{className:"live-dot"}),t.working]}),e.jsxs("span",{children:[e.jsx("i",{className:"approval-dot"}),t.approval]}),e.jsxs("span",{children:[e.jsx("i",{className:"question-dot"}),t.question]}),e.jsxs("span",{children:[e.jsx("i",{className:"done-dot"}),t.done]}),e.jsx("span",{className:"spacer"}),e.jsx("span",{children:t.helper})]})}const qd=.3,xb=2.5,mb=2.2,Vr=t=>Math.min(xb,Math.max(qd,t)),pb=(t,n)=>Vr(n>0?t*1.2:t/1.2);function fb(t,n,s){const a=(t.left+s.x)/t.zoom,r=(t.top+s.y)/t.zoom;return{left:a*n-s.x,top:r*n-s.y}}function hb(t,n){const s=Math.min(mb,Math.max(qd,Math.min(n.width*.92/t.w,n.height*.92/t.h)));return{zoom:s,left:(t.x+t.w/2)*s-n.width/2,top:(t.y+t.h/2)*s-n.height/2}}const gb=8,bb=320,jb=30,yb="button,a,[role=button],.unassigned-card",Nb=".atelier-room,.unassigned-zone",kb=12;let hn={zoom:null,left:0,top:0};function vb(t){const n=f.useRef(null),s=f.useRef(null),[a,r]=f.useState(1),[l,o]=f.useState(hn.zoom),c=f.useRef(hn.zoom??1),i=f.useRef(hn.zoom),m=f.useRef({w:-1,h:-1}),d=f.useCallback(()=>{const j=n.current,y=s.current;if(!j||!y)return;const b=y.style;b.zoom="1";const M={width:j.clientWidth,height:j.clientHeight};m.current={w:j.offsetWidth,h:j.offsetHeight};const S=Dd(M);b.padding=`${_n.top}px ${_n.side}px ${_n.bottom}px`,b.flexWrap="wrap",b.width="max-content",b.maxWidth="none",b.minHeight="",b.alignContent="flex-start",b.gap="0 8px";const $=y.querySelector(".ledge-corner");b.setProperty("--ledge-clear",`${$?Math.max(0,$.offsetTop+$.offsetHeight+kb-_n.top):0}px`);const v=[...y.querySelectorAll(Nb)].map(_=>({w:_.offsetWidth,h:_.offsetHeight})).filter(_=>_.w>0),{zoom:A,along:R}=eb(v,M,S);if(R==="row")b.flexWrap="nowrap",b.width="max-content",b.justifyContent="flex-start";else{const _=Math.max(0,...v.map(L=>L.w))+2*_n.side;b.flexWrap="wrap",b.width=`${_}px`,b.maxWidth=`${_}px`,b.justifyContent="center"}v.length===0&&(b.width=`${M.width}px`,b.minHeight=`${M.height}px`),r(A),c.current=i.current??A,b.zoom=String(c.current)},[]);f.useLayoutEffect(()=>{d();const j=n.current;j&&(j.scrollLeft=hn.left,j.scrollTop=hn.top)},[d,...t]);const x=f.useRef(d);x.current=d,f.useEffect(()=>{var b,M;const j=n.current;if(!j||typeof ResizeObserver>"u")return;const y=new ResizeObserver(()=>{(j.offsetWidth!==m.current.w||j.offsetHeight!==m.current.h)&&x.current()});return y.observe(j),(M=(b=globalThis.document)==null?void 0:b.fonts)==null||M.ready.then(()=>x.current()),()=>y.disconnect()},[]);const p=(j,y,b)=>{const M=n.current,S=s.current;c.current=j,i.current=j,o(j),hn.zoom=j,!(!M||!S)&&(S.style.zoom=String(j),M.scrollLeft=y,M.scrollTop=b)},g=j=>{const y=n.current,b=Vr(j);if(!y){p(b,0,0);return}const{left:M,top:S}=fb({zoom:c.current,left:y.scrollLeft,top:y.scrollTop},b,{x:y.clientWidth/2,y:y.clientHeight/2});p(b,M,S)},h=j=>g(pb(c.current,j)),N=()=>{i.current=null,o(null),hn.zoom=null,d();const j=n.current;j&&(j.scrollLeft=0,j.scrollTop=0)},k=j=>{const y=n.current;if(!y)return;const b=c.current,M=y.getBoundingClientRect(),S=j.getBoundingClientRect(),$={x:(y.scrollLeft+S.left-M.left)/b,y:(y.scrollTop+S.top-M.top)/b,w:S.width/b,h:S.height/b};if($.w<=0||$.h<=0)return;const{zoom:v,left:A,top:R}=hb($,{width:y.clientWidth,height:y.clientHeight});p(v,A,R)},C=f.useRef({setZoom:p,fit:N,frame:k});return C.current={setZoom:p,fit:N,frame:k},f.useEffect(()=>{const j=n.current;if(!j)return;const y=new Map;let b=null,M=null,S=null,$=!1;const v=(E,P)=>({x:(E.x+P.x)/2,y:(E.y+P.y)/2,d:Math.hypot(E.x-P.x,E.y-P.y)}),A=()=>{const[E,P]=[...y.values()];if(b=null,M=null,E&&P){const W=v(E,P),F=j.getBoundingClientRect(),re=c.current;b={d:Math.max(W.d,1),zoom:re,x:(j.scrollLeft+W.x-F.left)/re,y:(j.scrollTop+W.y-F.top)/re}}else E&&(M={x:E.x,y:E.y,left:j.scrollLeft,top:j.scrollTop,moved:!1})},R=E=>{E.pointerType!=="mouse"&&(y.size===0&&($=!1),y.set(E.pointerId,{x:E.clientX,y:E.clientY}),A())},_=E=>{if(!y.has(E.pointerId))return;y.set(E.pointerId,{x:E.clientX,y:E.clientY});const[P,W]=[...y.values()];if(b&&P&&W){const F=v(P,W),re=j.getBoundingClientRect(),Y=Vr(b.zoom*F.d/b.d);C.current.setZoom(Y,b.x*Y-(F.x-re.left),b.y*Y-(F.y-re.top))}else if(M){const F=E.clientX-M.x,re=E.clientY-M.y;if(!M.moved&&Math.hypot(F,re)<gb)return;M.moved=!0,j.scrollLeft=M.left-F,j.scrollTop=M.top-re}},L=E=>{if(!y.has(E.pointerId))return;(M!=null&&M.moved||b)&&($=!0);const P=y.size===1&&M!==null&&!M.moved;if(y.delete(E.pointerId),A(),!P||E.type==="pointercancel")return;const W=E.target instanceof Element?E.target:null,F=E.timeStamp;if(S&&F-S.at<bb&&Math.hypot(E.clientX-S.x,E.clientY-S.y)<jb&&!(W!=null&&W.closest(yb))){S=null;const re=W==null?void 0:W.closest(".atelier-room");re?C.current.frame(re):C.current.fit();return}S={at:F,x:E.clientX,y:E.clientY}},T=E=>{$&&($=!1,E.preventDefault(),E.stopPropagation())},B=()=>{hn.left=j.scrollLeft,hn.top=j.scrollTop};return j.addEventListener("pointerdown",R),j.addEventListener("pointermove",_),j.addEventListener("pointerup",L),j.addEventListener("pointercancel",L),j.addEventListener("click",T,!0),j.addEventListener("scroll",B,{passive:!0}),()=>{j.removeEventListener("pointerdown",R),j.removeEventListener("pointermove",_),j.removeEventListener("pointerup",L),j.removeEventListener("pointercancel",L),j.removeEventListener("click",T,!0),j.removeEventListener("scroll",B)}},[]),{scrollRef:n,shellRef:s,zoom:l??a,fitted:l===null,zoomTo:g,step:h,fit:N}}const wb=["M15 3h6v6","M9 21H3v-6","M21 3l-7 7","M3 21l7-7"],Sb=80;function Hd({label:t,onClose:n,children:s}){const a=f.useRef(null),r=f.useRef(null),[l,o]=f.useState(0),c=d=>{var p,g;const x=d.target;!x.closest(".atelier-panel-grab, .atelier-panel > header, .atelier-panel header")||x.closest("button,a,textarea,input")||(r.current={x:d.clientX,y:d.clientY,id:d.pointerId,land:Dd({width:globalThis.innerWidth,height:globalThis.innerHeight})==="land"},(g=(p=a.current)==null?void 0:p.setPointerCapture)==null||g.call(p,d.pointerId))},i=d=>{const x=r.current;!x||x.id!==d.pointerId||o(Math.max(0,x.land?d.clientX-x.x:d.clientY-x.y))},m=d=>{const x=r.current;if(!x||x.id!==d.pointerId)return;r.current=null;const p=x.land?d.clientX-x.x:d.clientY-x.y;o(0),p>Sb&&n()};return e.jsxs("aside",{ref:a,className:"atelier-panel","aria-label":t,onPointerDown:c,onPointerMove:i,onPointerUp:m,onPointerCancel:m,style:l?{"--pull":`${l}px`}:void 0,children:[e.jsx("div",{className:"atelier-panel-grab","aria-hidden":"true"}),s]})}function Cb({store:t,name:n,ids:s,onOpen:a,onClose:r}){var m;const l=xe(t),o=!l.fresh,c=s.map(d=>l.sessions.get(d)).filter(d=>d!==void 0),i=c.filter(d=>d.state!=="exited").map(d=>d.id);return e.jsxs(Hd,{label:u.atelier.room(n),onClose:r,children:[e.jsxs("header",{className:"flex flex-none items-center gap-2.5 border-b border-line pt-2 pb-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h1",{className:"text-title font-semibold [overflow-wrap:anywhere]",children:n}),e.jsx("p",{className:"mt-[3px] text-meta text-muted",children:u.atelier.roomAgents(c.length)})]}),e.jsx("button",{type:"button",onClick:r,"aria-label":u.atelier.closePanel,title:u.atelier.closeTitle,className:Ot({}),children:e.jsx(z,{name:"close"})})]}),e.jsxs("main",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:[c.map(d=>{var x;return e.jsxs("button",{type:"button",onClick:()=>a(d.id),className:"flex w-full items-center gap-3 border-b border-line py-3 text-left active:bg-raised/60",children:[e.jsx(Fa,{tool:d.tool,seed:d.id,state:d.state,frozen:o}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-body font-semibold",children:d.name}),e.jsx("span",{className:"block truncate text-meta text-muted",children:((x=d.rig)==null?void 0:x.role)??d.topic??d.branch??d.title})]}),e.jsx(qs,{...Sm(d)})]},d.id)}),((m=l.daemon)==null?void 0:m.broadcast)&&i.length>0&&e.jsx("div",{className:"pt-4",children:i.length>ma?e.jsx("p",{className:"text-meta text-attention",children:u.agents.tooMany(i.length,ma)}):e.jsx(lc,{store:t,label:n,ids:i,offline:o})})]})]})}function $b(t,n){var a;const s=t.rooms.find(r=>r.project.id===n);return s?{name:((a=s.rig)==null?void 0:a.kind)==="kernel"?u.atelier.kernel:s.project.name,ids:s.tables.flatMap(r=>r.mains.map(l=>l.id))}:null}const Xo=`${Nn}sessions.helpers`,Yo=`${Nn}sessions.groupBy`;function Mb({store:t,sessionId:n,requestKey:s,storage:a,onReconnect:r}){const l=xe(t),o=!l.fresh,c=f.useMemo(()=>[...l.sessions.values()],[l.sessions]),i=f.useMemo(()=>c.map(E=>({...E,cwd:E.project})),[c]),m=f.useMemo(()=>am(i,l.projects,E=>E.projectId??null,"all",!0,({id:E,name:P,kind:W})=>({id:E,name:P,color:lm(W)})),[i,l.projects]),[d,x]=f.useState(null),[p,g]=f.useState(()=>{var E;try{return((E=Ze(a))==null?void 0:E.getItem(Xo))!=="hidden"}catch{return!0}}),[h,N]=f.useState(()=>{var E;try{return((E=Ze(a))==null?void 0:E.getItem(Yo))==="rigs"?"rigs":"projects"}catch{return"projects"}}),k=E=>{var P;N(E);try{(P=Ze(a))==null||P.setItem(Yo,E)}catch{}},C=()=>{var P;const E=!p;g(E);try{(P=Ze(a))==null||P.setItem(Xo,E?"shown":"hidden")}catch{}},j=vb([m,o]),y=E=>{x(null),n?An({name:"atelier",sessionId:E}):is({name:"atelier",sessionId:E})},b=()=>An({name:"atelier"}),M={open:y,room:E=>{n&&b(),x(E)}},S=(l.asks??[]).filter(E=>E.kind!=="update").length,$=c.filter(E=>E.state!=="exited").length,v=c.filter(Fd).length,A=`${o?`${u.agents.offline} · `:""}${u.atelier.subtitle($,v,nc(c).working)}`,R=d?$b(m,d):null,_=m.rooms.filter(E=>!E.rig),L=m.rooms.filter(E=>E.rig),T=h==="rigs"?[...L,..._]:[..._,...L],B=n?l.sessions.get(n):void 0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"atelier-col",children:[e.jsxs("header",{className:"flex flex-none items-center gap-3 pt-3 pb-3",children:[e.jsx("h1",{className:"text-title font-semibold tracking-[-.3px]",children:u.atelier.title}),e.jsx("span",{className:"min-w-0 truncate text-meta text-muted",children:A}),e.jsx("span",{className:"flex-1"}),e.jsx("div",{role:"group","aria-label":u.sessions.groupBy.label,className:"flex flex-none overflow-hidden rounded-lg border border-input",children:ll.map(E=>e.jsx("button",{type:"button","aria-pressed":E===h,onClick:()=>k(E),className:"grid h-9 place-items-center px-3.5 text-[13px] font-medium text-muted aria-pressed:bg-raised aria-pressed:text-fg",children:u.sessions.groupBy[E]},E))}),e.jsxs("button",{type:"button","aria-pressed":!p,onClick:C,className:rt({size:"sm",className:"flex-none"}),children:[e.jsx(z,{name:"eye",className:"size-4"}),p?u.sessions.helpersHide:u.sessions.helpersShow]}),e.jsx(ml,{})]}),e.jsx("div",{className:"mb-3 flex-none empty:hidden",children:e.jsx(wn,{})}),e.jsxs("div",{className:`atelier-ipad${o?" atelier-frozen":""}`,children:[e.jsxs("div",{className:"zoom-controls",role:"toolbar","aria-label":u.atelier.zoom.bar,children:[e.jsx("button",{type:"button",className:"ledge-btn","data-variant":"ghost","aria-label":u.atelier.zoom.out,onClick:()=>j.step(-1),children:"−"}),e.jsx("button",{type:"button",className:"zoom-level","aria-label":u.atelier.zoom.reset,onClick:()=>j.zoomTo(1),children:u.percent(Math.round(j.zoom*100))}),e.jsx("button",{type:"button",className:"ledge-btn","data-variant":"ghost","aria-label":u.atelier.zoom.in,onClick:()=>j.step(1),children:"+"}),e.jsx("span",{className:"zoom-sep"}),e.jsxs("button",{type:"button",className:"ledge-btn zoom-fit","data-variant":j.fitted?"secondary":"ghost","aria-pressed":j.fitted,title:u.atelier.zoom.fitTitle,onClick:j.fit,children:[e.jsx(cs,{d:wb,size:13}),u.atelier.zoom.fit]})]}),e.jsxs("div",{className:"overview-scroll atelier",role:"region","aria-label":u.atelier.region,ref:j.scrollRef,children:[e.jsx("div",{className:"atelier-floor",children:e.jsxs("div",{ref:j.shellRef,className:`office-shell${o?" office-paused":""}`,children:[e.jsx(db,{count:$,requests:S,frozen:o,onOpen:()=>is({name:"rigs"})}),e.jsx("div",{className:`project-grid ${T.length===1?"focused":""}`,children:T.map(({project:E,tables:P,rig:W})=>e.jsx(ib,{project:E,tables:P,...W?{rig:W}:{},width:im(P,zs,En),act:M,children:P.map(F=>e.jsx(ob,{table:F,project:E,color:os[E.color],frozen:o,act:M,helpers:p},F.key))},E.id))}),e.jsx(cb,{sessions:m.unassigned,frozen:o,act:M})]})}),e.jsx(ub,{})]})]})]}),n&&e.jsx(Hd,{label:u.atelier.session((B==null?void 0:B.name)??""),onClose:b,children:s?e.jsx(Ir,{store:t,sessionId:n,requestKey:s,onReconnect:r,panel:{onBack:()=>An({name:"atelier",sessionId:n}),onClose:b}},`${n}:request`):e.jsx(Wr,{store:t,sessionId:n,storage:a,onReconnect:r,panel:{onClose:b}},n)}),!n&&R&&d&&e.jsx(Cb,{store:t,name:R.name,ids:R.ids,onOpen:y,onClose:()=>x(null)})]})}const Eb=t=>new Date(Date.UTC(2026,10,23+la.indexOf(t))),_b=t=>Eb(t).toLocaleDateString(ut,{weekday:"short",timeZone:"UTC"}),Ud=(t,n)=>t.toLocaleDateString(ut,{weekday:"short",day:"numeric",month:"short",...n?{timeZone:"UTC"}:{}});function hr(t){const n=u.routines,s=la.map((r,l)=>t.includes(r)?l:-1).filter(r=>r>=0);if(s.length===la.length)return n.daily;const a=[];for(let r=0;r<s.length;){let l=r;for(;l+1<s.length&&s[l+1]===s[l]+1;)l++;const o=s.slice(r,l+1).map(c=>n.days[la[c]]);a.push(o.length>=3?`${o[0]}–${o[o.length-1]}`:o.join(", ")),r=l+1}return a.join(", ")}function Rb(t){const[n="",s=""]=t.split("T"),[a,r,l]=n.split("-").map(Number);return`${Ud(new Date(Date.UTC(a,r-1,l)),!0)} ${s}`}function Os(t){var r;const n=u.routines;if(t.kind==="once"){const l=[...t.at].sort().map(Rb),o=l.length>3?n.more(l.slice(0,3).join(", "),l.length-3):l.join(", ");return{card:n.oneShot,ask:o,dated:!0,moments:l}}const s=[...t.times].sort().join(", ");if(((r=t.every)==null?void 0:r.weeks)===2)return{card:`${t.days.length===1?_b(t.days[0]):hr(t.days)} ${s} · ${n.everyOther}`,ask:`${s} (${hr(t.days)}, ${n.every2})`,dated:!0,moments:[]};const a=hr(t.days);return{card:`${s} · ${a}`,ask:`${s} (${a})`,dated:!1,moments:[]}}const Wd=t=>t.toLocaleTimeString(ut,{hour:"2-digit",minute:"2-digit"}),ea=t=>`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`;function Kd(t,n,s=!1){const a=new Date(t),r=Wd(a);if(!s){const l=new Date(n),o=new Date(n);if(o.setDate(o.getDate()+1),ea(a)===ea(l))return`${u.routines.today} ${r}`;if(ea(a)===ea(o))return`${u.routines.tomorrow} ${r}`}return`${Ud(a,!1)} ${r}`}function Tb(t,n){if(!t.nextRun)return null;const s=Os(t.schedule).dated,a=Kd(t.nextRun,n,s);return s?u.routines.nextDated(a):u.routines.next(a)}function Qo(t,n){var r;const s=((r=t==null?void 0:t.lastRun)==null?void 0:r.outcome)==="failed"?t.lastRun:void 0,a=u.routines.why;return t&&(s==null?void 0:s.field)==="cwd"?a.cwd(t.target.cwd):t&&(s==null?void 0:s.field)==="tool"?a.tool(t.target.tool):(s==null?void 0:s.cause)==="timeout"?a.timeout:(s==null?void 0:s.reason)??n??""}const _l=t=>t.state!=="done",Rl=t=>{var n;return((n=t.lastRun)==null?void 0:n.outcome)==="failed"},Zo=t=>t.state==="pending"?0:Rl(t)?1:t.state==="paused"?3:2,Ab=(t,n)=>Zo(t)-Zo(n)||(t.nextRun??"").localeCompare(n.nextRun??"")||t.name.localeCompare(n.name);function Ib(t){const n=t.filter(_l).sort(Ab);return{recurring:n.filter(s=>s.schedule.kind==="recurring"),once:n.filter(s=>s.schedule.kind==="once")}}function Lb(t,n){const s=t.filter(_l),a=s.filter(l=>l.state==="enabled"&&l.nextRun).map(l=>l.nextRun).sort()[0],r=a===void 0?null:new Date(a).toDateString()===new Date(n).toDateString()?Wd(new Date(a)):Kd(a,n);return{count:s.length,next:r,flagged:s.filter(l=>l.state==="pending"||Rl(l)).length}}function Ka(t,n){const s=[...n].filter(a=>a.name===t.target.name);return s.find(a=>a.state!=="exited")??s[0]}function Ob(t,n){const s=[...n],a=new Set;for(const r of t??[]){if(!_l(r))continue;const l=Ka(r,s);l&&a.add(l.id)}return a}const Vd=t=>{var n;return((n=t.proposal)==null?void 0:n.by.name)??(t.createdBy.kind==="session"?t.createdBy.name:void 0)};function Db(t){const n=s=>s.routine.kind==="approve"?0:1;return[...t].filter(s=>!!s.routine&&!ld(s)).sort((s,a)=>n(s)-n(a)||s.at.localeCompare(a.at))}const Tl=t=>t.ids??[t.id],Fb=t=>new Date(t).toLocaleTimeString(ut,{hour:"2-digit",minute:"2-digit"});function Gd({at:t}){const n=u.routines.request;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Lt,{tone:"ask",children:n.ask}),e.jsxs("span",{className:"text-[13px] text-muted",children:[n.kind," · ",e.jsx("time",{dateTime:t,children:Fb(t)})]})]})}function Xd({routine:t,session:n,frozen:s,children:a}){return e.jsxs("div",{className:"flex items-start gap-[9px]",children:[e.jsx(Yd,{routine:t,session:n,frozen:s}),e.jsx("p",{className:"min-w-0 flex-1 text-body [overflow-wrap:anywhere]",children:a})]})}const Sa=t=>{var n;return((n=t.proposal)==null?void 0:n.spec)??t};function Pb(t){return Tl(t.task.routine).length>1?e.jsx(Bb,{...t}):e.jsx(zb,{...t})}function zb({store:t,task:n,state:s,canConfirm:a}){var S,$;const r=u.routines.request,l=n.routine.id,o=(S=s.routines)==null?void 0:S.find(v=>v.id===l),c=s.routineDetails[l],i=c&&c!=="gone"?c:void 0,[m,d]=f.useState(null),[x,p]=f.useState(null);f.useEffect(()=>{s.fresh&&t.showRoutine(l)},[t,l,s.fresh,c]);const g=i?Sa(i):o&&!o.proposed?o:void 0,h=i?!!i.proposal:!!(o!=null&&o.proposed),N=i??o,k=N?Ka(N,s.sessions.values()):void 0,C=(N&&Vd(N))??n.giverName??"",[j,y]=f.useState(!1),b=async v=>{d(v),p(null),y(!1);const A=v==="approve"?await t.approveRoutine(l,i.key):await t.routineCmd(l,"refuse");v==="approve"&&A.status==="rejected"&&A.reason==="stale"?(y(!0),t.rereadRoutine(l)):p(Al(A)),d(null)},M=!s.fresh||m!==null;return e.jsxs(Bs,{tone:"ask",label:`${r.ask} · ${n.routine.name}`,children:[e.jsx(Gd,{at:n.at}),N?e.jsx(Xd,{routine:N,session:k,frozen:!s.fresh,children:g?e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:C})," ",h?r.editAsks(g.name,Os(g.schedule).ask):r.asks(g.name,Os(g.schedule).ask,g.target.cwd)]}):r.fallbackAsk(n.routine.name)}):e.jsx("p",{className:"text-body [overflow-wrap:anywhere]",children:r.fallbackAsk(n.routine.name)}),i&&e.jsx("pre",{"data-prompt":"",className:"m-0 rounded-md border border-line bg-raised px-[9px] py-1.5 font-mono text-small leading-[17px] whitespace-pre-wrap [overflow-wrap:anywhere]",children:Sa(i).prompt}),j&&e.jsx("p",{role:"status",className:"text-small text-attention [overflow-wrap:anywhere]",children:r.stale((($=g??N)==null?void 0:$.name)??n.routine.name)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button",disabled:M||!i,onClick:()=>{b("approve")},className:xs(!0),children:[m==="approve"&&e.jsx(Ct,{}),r.activate]}),e.jsxs("button",{type:"button",disabled:M,onClick:()=>{b("refuse")},className:xs(),children:[m==="refuse"&&e.jsx(Ct,{}),r.refuse]})]}),x?e.jsx("p",{role:"alert",className:"text-small text-destructive",children:x}):e.jsx("p",{className:"text-[12px] text-muted",children:a?r.verify:u.confirm.refused.confirm_required})]})}function Bb({store:t,task:n,state:s,canConfirm:a}){const r=u.routines.request,l=Tl(n.routine),o=l.map(_=>{var L;return(L=s.routines)==null?void 0:L.find(T=>T.id===_)}).filter(_=>!!_),c=s.routines?o.filter(_=>_.state==="pending"||_.proposed):[],i=s.routines?c.length:l.length,m=o[0],d=m?Ka(m,s.sessions.values()):void 0,[x,p]=f.useState(null),[g,h]=f.useState(null),[N,k]=f.useState(!1),C=c.map(_=>s.routineDetails[_.id]),j=C.map(_=>_&&_!=="gone"?_.key:"-").join(",");f.useEffect(()=>{if(s.fresh)for(const _ of c)t.showRoutine(_.id)},[t,s.fresh,c.map(_=>_.id).join(","),j]);const y=C.filter(_=>!!_&&_!=="gone"),b=c.length>0&&y.length===c.length,M=async _=>{p(_),h(null),k(!1);const L=c.map(E=>{const P=s.routineDetails[E.id];return{routine:E.id,routineKey:P&&P!=="gone"?P.key:E.key}}),[T,...B]=L;if(T){const E=_==="approve"?await t.approveRoutine(T.routine,T.routineKey,B):await t.routineCmd(T.routine,"refuse",B);if(_==="approve"&&E.status==="rejected"&&E.reason==="stale"){k(!0);for(const P of L)t.rereadRoutine(P.routine)}else h(Al(E))}p(null)},S=!s.fresh||x!==null||c.length===0,$=(m&&Vd(m))??n.giverName??"",v=new Set(y.map(_=>Sa(_).target.cwd)),A=v.size===1?[...v][0]:void 0,R=new Set;return e.jsxs(Bs,{tone:"ask",label:`${r.ask} · ${n.routine.name}`,children:[e.jsx(Gd,{at:n.at}),m?e.jsxs(Xd,{routine:m,session:d,frozen:!s.fresh,children:[e.jsx("b",{className:"font-semibold",children:$})," ",r.groupAsks(i),A&&e.jsxs("span",{className:"text-muted",children:[" ",r.inDir(A)]})]}):e.jsx("p",{className:"text-body [overflow-wrap:anywhere]",children:r.fallbackAsk(n.routine.name)}),c.length>0&&e.jsx("ul",{className:"m-0 flex list-none flex-col gap-2.5 p-0",children:c.map(_=>{const L=s.routineDetails[_.id],T=L&&L!=="gone"?Sa(L):void 0,B=Os((T??_).schedule),E=T&&!R.has(T.prompt)?T.prompt:void 0;return T&&R.add(T.prompt),e.jsxs("li",{className:"flex flex-col gap-1",children:[e.jsxs("span",{className:"text-[13px]",children:[e.jsx("b",{className:"font-semibold",children:(T??_).name})," ",e.jsxs("span",{className:"text-muted",children:["· ",B.moments[0]??B.card,T&&!A?` · ${r.inDir(T.target.cwd)}`:""]})]}),E&&e.jsx("pre",{"data-prompt":"",className:"m-0 rounded-md border border-line bg-raised px-[9px] py-1.5 font-mono text-[11.5px] leading-[17px] whitespace-pre-wrap [overflow-wrap:anywhere]",children:E})]},_.id)})}),N&&e.jsx("p",{role:"status",className:"text-small text-attention [overflow-wrap:anywhere]",children:r.stale(n.routine.name)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button",disabled:S||!b,onClick:()=>{M("approve")},className:xs(!0),children:[x==="approve"&&e.jsx(Ct,{}),r.activateAll(i)]}),e.jsxs("button",{type:"button",disabled:S,onClick:()=>{M("refuse")},className:xs(),children:[x==="refuse"&&e.jsx(Ct,{}),r.refuseAll(i)]})]}),g?e.jsx("p",{role:"alert",className:"text-small text-destructive",children:g}):e.jsx("p",{className:"text-[12px] text-muted",children:a?r.verify:u.confirm.refused.confirm_required})]})}const xs=(t=!1)=>["inline-flex h-10 min-w-0 flex-auto items-center justify-center gap-1.5 rounded-[10px] border px-2.5 text-[14px] font-medium whitespace-nowrap transition-colors duration-100 disabled:opacity-45",t?"border-transparent bg-primary text-primary-fg active:bg-primary-hover":"border-input bg-surface dark:bg-transparent text-fg active:bg-raised"].join(" ");function Al(t){switch(t.status){case"applied":return null;case"cancelled":return u.confirm.cancelled;case"expired":return u.confirm.expired;case"failed":return u.cards.note.failed;case"rejected":return t.reason==="not_pending"||t.reason==="stale"||t.reason==="not_found"?u.cards.note.stale:u.confirm.refused[t.reason]??u.cards.note.failed}}function Yd({routine:t,session:n,frozen:s}){return e.jsx(Fa,{tool:(n==null?void 0:n.tool)??t.target.tool,seed:(n==null?void 0:n.id)??t.id,state:(n==null?void 0:n.state)??"exited",frozen:s})}function qb(){return e.jsx("span",{className:"inline-flex h-5 flex-none items-center rounded-lg border border-dashed border-attention/50 px-[7px] text-[11.5px] whitespace-nowrap text-attention",children:u.routines.late})}function Hb({store:t,routine:n,session:s,offline:a,now:r,focused:l}){const o=u.routines,[c,i]=f.useState(null),m=f.useRef(null),[d,x]=f.useState(l);f.useEffect(()=>{var $,v;if(!l)return;(v=($=m.current)==null?void 0:$.scrollIntoView)==null||v.call($,{block:"center"}),x(!0);const S=setTimeout(()=>x(!1),Ub);return()=>clearTimeout(S)},[l]);const[p,g]=f.useState(null),h=n.state==="pending",N=Rl(n),k=n.state==="paused",C=async(S,$)=>{i(S),g(null),g(Al(await t.routineCmd(n.id,$))),i(null)},j=h||k?null:Tb(n,r),y=n.lastRun,b=S=>c===S?e.jsx(Ct,{}):null;let M;return h?M=e.jsx(Lt,{tone:"ask",children:o.pending}):y?M=e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",className:`w-3.5 text-center text-[11px] ${y.outcome==="failed"?"text-approval":"text-ok"}`,children:y.outcome==="failed"?"!":"✓"}),e.jsx("span",{children:o.lastAt(y.slot,o.outcome[y.outcome])}),y.late&&e.jsx(qb,{})]}):M=e.jsx("span",{children:o.never}),e.jsx("div",{ref:m,"data-focused":d||void 0,className:`rounded-lg transition-shadow duration-200 ${d?"shadow-[0_0_0_2px_var(--color-task)] [&>article]:bg-[color-mix(in_srgb,var(--color-task)_10%,var(--color-surface))]":""}`,children:e.jsxs(Bs,{tone:h?"ask":N?"perm":"plain",label:n.name,children:[e.jsxs("div",{"data-routine":n.id,className:"flex min-w-0 items-center gap-[9px]",children:[e.jsx(Yd,{routine:n,session:s,frozen:a}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("b",{className:"truncate text-[15px] font-semibold",children:n.name}),e.jsxs("span",{className:"truncate text-[13px] text-muted",children:[n.target.name," · ",Os(n.schedule).card]})]})]}),k?e.jsx("div",{children:e.jsx(Lt,{children:o.paused})}):j&&e.jsx("p",{className:"text-[13px] text-muted",children:j}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 text-[13px] text-muted",children:M}),N&&Qo(n)&&e.jsx("p",{className:"text-[13px] [overflow-wrap:anywhere] text-muted",children:Qo(n)}),e.jsx("div",{className:"flex gap-2",children:h?null:e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:a||c!==null,onClick:()=>{C("run","run")},className:xs(),children:[b("run")??e.jsx(z,{name:"play",className:"size-3.5"}),e.jsx("span",{className:"truncate",children:N?o.retry:o.runNow})]}),e.jsxs("button",{type:"button",disabled:a||c!==null,onClick:()=>{C("toggle",k?"resume":"pause")},className:xs(),children:[b("toggle"),e.jsx("span",{className:"truncate",children:k?o.resume:o.pause})]})]})}),p&&e.jsx("p",{role:"alert",className:"text-small text-destructive",children:p})]})})}const Ub=1500;function Jo({children:t}){return e.jsx("h2",{className:"mx-1 -mb-1 text-[10.5px] font-medium tracking-[.06em] text-muted uppercase",children:t})}function ei({store:t,focus:n}){const s=xe(t),a=Kt(),r=Dt(),l=u.routines,o=Ib(s.routines??[]),c=!s.fresh,i=[...s.sessions.values()],m=mn(),d=Db(s.tasks.values()).filter(N=>N.routine.kind==="approve"),x=new Set(d.flatMap(N=>Tl(N.routine))),p=d.map(N=>{var k;return e.jsx(Pb,{store:t,task:N,state:s,canConfirm:((k=s.device)==null?void 0:k.confirm)===!0&&m},N.id)}),g=N=>N.filter(k=>!x.has(k.id)),h=N=>g(N).map(k=>e.jsx(Hb,{store:t,routine:k,session:Ka(k,i),offline:c,now:a,focused:k.id===n},k.id));return e.jsxs(hs,{title:l.title,heading:!1,bodyClassName:"flex flex-col gap-2.5",children:[!r&&e.jsxs(e.Fragment,{children:[e.jsxs("a",{href:ce({name:"sessions"}),onClick:N=>{N.preventDefault(),Aa({name:"sessions"})},className:"-mb-1 flex items-center gap-1 self-start text-body text-muted",children:[e.jsx(z,{name:"back",className:"size-4"}),l.back]}),e.jsx("h1",{className:"text-[22px] leading-7 font-semibold tracking-[-.02em]",children:l.title})]}),p,g(o.recurring).length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Jo,{children:l.groups.recurring}),h(o.recurring)]}),g(o.once).length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Jo,{children:l.groups.once}),h(o.once)]}),e.jsx("p",{className:"px-2 text-center text-[12.5px] text-muted",children:l.readonly})]})}const Qd=500,Gr=10;function Zd(t){const n=f.useRef(null),s=f.useRef(null),a=f.useRef(!1),r=()=>{n.current&&clearTimeout(n.current),n.current=null},l=()=>{var o;r(),a.current=!0;try{(o=navigator.vibrate)==null||o.call(navigator,10)}catch{}t()};return{onPointerDown:o=>{o.button>0||(a.current=!1,s.current={x:o.clientX,y:o.clientY},r(),n.current=setTimeout(l,Qd))},onPointerMove:o=>{const c=s.current;c&&Math.hypot(o.clientX-c.x,o.clientY-c.y)>Gr&&r()},onPointerUp:r,onPointerCancel:r,onPointerLeave:r,onContextMenu:o=>{o.preventDefault(),a.current||l()},onClickCapture:o=>{a.current&&(o.preventDefault(),o.stopPropagation(),a.current=!1)}}}function Jd(t){const n=f.useRef(t);n.current=t;const s=f.useRef(null),a=f.useRef(null),r=f.useRef("idle"),l=f.useRef(!1),o=f.useRef(null),c=()=>{s.current&&clearTimeout(s.current),s.current=null},i=()=>{var x;c(),(x=o.current)==null||x.call(o),o.current=null,r.current="idle"};f.useEffect(()=>()=>i(),[]);const m=()=>{const x=N=>{(r.current==="lifted"||r.current==="dragging")&&N.preventDefault()},p=N=>{var C,j;const k=a.current;k&&(r.current==="lifted"&&Math.hypot(N.clientX-k.x,N.clientY-k.y)>Gr&&(r.current="dragging"),r.current==="dragging"&&((j=(C=n.current).onDrag)==null||j.call(C,N.clientY)))},g=()=>{var k,C;const N=r.current;i(),N==="dragging"?(C=(k=n.current).onDrop)==null||C.call(k):N==="lifted"&&n.current.onLong()},h=()=>{var k,C;const N=r.current;i(),(N==="dragging"||N==="lifted")&&((C=(k=n.current).onCancel)==null||C.call(k))};document.addEventListener("touchmove",x,{passive:!1}),window.addEventListener("pointermove",p),window.addEventListener("pointerup",g),window.addEventListener("pointercancel",h),o.current=()=>{document.removeEventListener("touchmove",x),window.removeEventListener("pointermove",p),window.removeEventListener("pointerup",g),window.removeEventListener("pointercancel",h)}},d=()=>{var x,p,g,h;c(),l.current=!0,r.current="lifted";try{(x=navigator.vibrate)==null||x.call(navigator,10)}catch{}(h=(g=n.current).onLift)==null||h.call(g,((p=a.current)==null?void 0:p.y)??0),m()};return{onPointerDown:x=>{x.button>0||(l.current=!1,a.current={x:x.clientX,y:x.clientY},c(),r.current="pressing",s.current=setTimeout(d,Qd))},onPointerMove:x=>{const p=a.current;r.current==="pressing"&&p&&Math.hypot(x.clientX-p.x,x.clientY-p.y)>Gr&&(c(),r.current="idle")},onPointerUp:()=>{r.current==="pressing"&&(c(),r.current="idle")},onPointerCancel:()=>{r.current==="pressing"&&(c(),r.current="idle")},onDragStart:x=>{x.preventDefault()},onContextMenu:x=>{x.preventDefault(),!l.current&&r.current!=="lifted"&&r.current!=="dragging"&&(c(),r.current="idle",l.current=!0,n.current.onLong())},onClickCapture:x=>{l.current&&(x.preventDefault(),x.stopPropagation(),l.current=!1)}}}function eu({store:t,session:n,current:s,onLeave:a,onReconnect:r,display:l,model:o,onModel:c}){var v,A;const i=xe(t),m=Kt(),[d,x]=f.useState(!1),[p,g]=f.useState(!1),h=o??p,N=c??g,[k,C]=f.useState(!1),j=ms(n),y=Dt(),b=Pa(),M=s==="terminal"&&y&&!b&&[n.project,n.branch].filter(Boolean).join(" · ")||void 0,S=!!((v=i.daemon)!=null&&v.sessionClose)&&!n.readOnly,$=nl(n,i.ops,((A=i.daemon)==null?void 0:A.boot)??null,m);return e.jsxs(e.Fragment,{children:[e.jsx(La,{back:e.jsx(Zt,{fallback:{name:"sessions"},label:u.thread.back}),tool:n.tool,name:n.name,dot:j,pulse:j==="work"&&i.fresh,sub:M,more:e.jsxs(e.Fragment,{children:[e.jsx(Ld,{sessionId:n.id,current:s,...a?{onLeave:a}:{}}),e.jsx("button",{type:"button","aria-haspopup":"dialog","aria-label":u.sessions.moreOf(n.name),title:u.sessions.more,onClick:()=>x(!0),className:Ot({className:d?"bg-raised text-fg":"text-muted"}),children:e.jsx(z,{name:"more"})})]})}),d&&e.jsx(bl,{store:t,session:n,closable:S,closing:$,onClose:()=>x(!1),onModel:()=>{x(!1),N(!0)},onCloseSession:()=>{x(!1),C(!0)},display:l&&{value:l.value,onToggle:()=>{l.onToggle(),x(!1)}}}),h&&Vn(i.daemon,n)&&e.jsx(qa,{store:t,session:n,onClose:()=>N(!1)}),k&&e.jsx(kl,{store:t,session:n,mode:"close",onClose:()=>C(!1),onSent:()=>C(!1),onReconnect:r})]})}function Wb({store:t,session:n,onDone:s,order:a}){var p,g;const r=xe(t),l=Kt(),[o,c]=f.useState("menu"),i=!!((p=r.daemon)!=null&&p.sessionClose)&&!n.readOnly,m=nl(n,r.ops,((g=r.daemon)==null?void 0:g.boot)??null,l),d=n.rig?u.sessions.seatOf(n.rig.role??n.name,n.rig.name):n.project,x=h=>{s(),is(h)};return o==="model"?Vn(r.daemon,n)?e.jsx(qa,{store:t,session:n,onClose:s}):null:o==="close"?e.jsx(kl,{store:t,session:n,mode:"close",onClose:s,onSent:s}):e.jsx(bl,{store:t,session:n,closable:i,closing:m,onClose:s,who:d,onModel:()=>c("model"),onCloseSession:()=>c("close"),...a?{order:[{icon:"arrowUp",label:u.sessions.reorder.up,onClick:a.up?()=>{a.up(),s()}:void 0},{icon:"arrowDown",label:u.sessions.reorder.down,onClick:a.down?()=>{a.down(),s()}:void 0}]}:{},lead:[{icon:"sessions",label:u.cards.openThread,onClick:()=>x({name:"thread",sessionId:n.id})},{icon:"terminal",label:u.thread.terminal(n.name),onClick:()=>x({name:"terminal",sessionId:n.id})}]})}function Kb({by:t,onBy:n,helpers:s,onHelpers:a}){const r=u.sessions.groupBy;return e.jsxs("div",{className:"flex flex-none items-center gap-2",children:[e.jsx("div",{role:"group","aria-label":r.label,className:"grid flex-1 grid-cols-2 gap-[3px] rounded-[10px] border border-line p-[3px]",children:ll.map(l=>e.jsx("button",{type:"button","aria-pressed":l===t,onClick:()=>n(l),className:"h-[34px] rounded-[7px] text-[13px] font-medium whitespace-nowrap text-muted aria-pressed:bg-raised aria-pressed:text-fg",children:r[l]},l))}),e.jsx("button",{type:"button",onClick:a,"aria-label":s?u.sessions.helpersHide:u.sessions.helpersShow,title:s?u.sessions.helpersHide:u.sessions.helpersShow,className:`grid size-[42px] flex-none place-items-center rounded-control border ${s?"border-input text-fg":"border-ring text-fg"}`,children:e.jsx(z,{name:"eye",className:"size-[18px]"})})]})}const ti="inline-flex items-center gap-1.5 rounded-lg border bg-bg px-2.5 select-none [-webkit-touch-callout:none]";function Vb({session:t,rig:n,helpers:s,pressed:a,onPress:r}){const l=Zd(()=>r(t)),o=ms(t),c=o==="perm"?"border-destructive/50":o==="ask"?"border-attention/50":"border-line",i=ce({name:"thread",sessionId:t.id}),m=xa(t),d=u.atelier.session(t.name);return e.jsxs(e.Fragment,{children:[e.jsxs("a",{href:i,"aria-label":d,...l,className:`${ti} h-10 text-[13px] font-medium ${c} ${t.state==="exited"?"opacity-60":""} ${a?"shadow-[0_0_0_2px_var(--color-ring)]":""}`,children:[!n&&e.jsx(Xn,{tool:t.tool}),e.jsx(El,{session:t,nameClassName:"font-normal text-muted"}),e.jsx(ze,{state:o}),!s&&m.length>0&&e.jsx("span",{"aria-label":u.sessions.kidsLabel(m.length),className:"ml-0.5 rounded-lg border border-input px-1.5 font-mono text-[11px] leading-[18px] text-muted",children:u.sessions.kids(m.length)})]}),s&&m.map(x=>e.jsxs("a",{href:i,"aria-label":u.atelier.helperSeat(x.kind,t.name,x.task),...l,className:`${ti} h-8 border-dashed border-line text-[12px] text-muted`,children:[x.kind,e.jsx(ze,{state:um(x)})]},x.id))]})}function Gb({island:t,rigs:n,helpers:s,pressed:a,onPress:r}){const l=u.sessions,o=t.kind==="rig",c=dm(t),i=o?t.name==="kernel"&&n?l.kernelTag:l.rigTag:null,m=o?l.seats(t.sessions.length):u.atelier.plaqueCounts(t.sessions.length);return e.jsxs("section",{"aria-label":o?l.rigGroup(t.name):t.name,className:`flex flex-none flex-col gap-2.5 rounded-[10px] border bg-surface px-3 pt-2.5 pb-3 dark:bg-[oklch(0.18_0_0)] ${o?"border-task/45":"border-line"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 text-[13px]",children:[o&&e.jsx(ze,{state:"rig"}),e.jsx("b",{className:"font-semibold",children:t.name}),c&&e.jsx(ze,{state:c}),i?e.jsx("small",{className:"text-[12px] text-muted",children:i}):e.jsx("small",{className:"text-[12px] text-muted",children:m}),o&&i===l.rigTag&&(n?e.jsx("a",{href:ce({name:"rigs"}),className:"ml-auto text-[12px] text-muted underline underline-offset-2",children:m}):e.jsx("span",{className:"ml-auto text-[12px] text-muted",children:m}))]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:t.sessions.map(d=>e.jsx(Vb,{session:d,rig:o,helpers:s,pressed:a===d.id,onPress:r},d.id))})]})}function Xb({sessions:t,by:n,onBy:s,helpers:a,onHelpers:r,rigs:l,pressed:o,onPress:c,requests:i=0}){const m=Gn(),d=t.filter(g=>g.state!=="exited").length,x=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"grid size-[30px] flex-none place-items-center overflow-hidden",children:e.jsx(cl,{size:30,theme:m,frozen:!0})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("b",{className:"font-semibold",children:u.sessions.deskTitle}),e.jsx("small",{className:"text-[12px] text-muted",children:i>0?u.atelier.ledgeRequests(i):u.atelier.watching(d)})]})]}),p="flex min-h-[52px] flex-none items-center gap-2.5 rounded-[10px] border border-line bg-surface px-3 py-1.5 text-[13.5px] dark:bg-[oklch(0.18_0_0)]";return e.jsxs(e.Fragment,{children:[e.jsx(Kb,{by:n,onBy:s,helpers:a,onHelpers:r}),cm(t,n).map(g=>e.jsx(Gb,{island:g,rigs:l,helpers:a,pressed:o,onPress:c},g.id)),i>0?e.jsxs("a",{href:ce({name:"rigs"}),className:p,children:[x,e.jsx(z,{name:"chevron",className:"size-4 text-muted"})]}):e.jsx("div",{className:p,children:x})]})}const ni=`${Nn}sessions.filter`,Yb=t=>tc.includes(t);function Qb(t,n){const s=Ze(n),[a,r]=f.useState(()=>{if(t)return t;try{const o=s==null?void 0:s.getItem(ni);return Yb(o)?o:"all"}catch{return"all"}}),l=o=>{r(o);try{s==null||s.setItem(ni,o)}catch{}};return f.useEffect(()=>{t&&l(t)},[t]),[a,l]}function gr(t,n,s,a){const r=Ze(a),[l,o]=f.useState(()=>{try{const i=r==null?void 0:r.getItem(`${Nn}${t}`);return n.includes(i)?i:s}catch{return s}});return[l,i=>{o(i);try{r==null||r.setItem(`${Nn}${t}`,i)}catch{}}]}const tu=["list","atelier"];function Zb({value:t,onChange:n}){const s=u.sessions.mode;return e.jsx("div",{role:"group","aria-label":s.label,className:"flex flex-none overflow-hidden rounded-lg border border-input",children:tu.map(a=>e.jsx("button",{type:"button","aria-pressed":a===t,onClick:()=>n(a),className:"grid h-9 place-items-center px-3.5 text-[13px] font-medium text-muted aria-pressed:bg-raised aria-pressed:text-fg",children:s[a]},a))})}function Jb({value:t,counts:n,onChange:s}){const a=u.sessions.filter;return e.jsx("div",{role:"group","aria-label":a.label,className:"flex flex-none rounded-lg border border-input p-0.5",children:tc.map(r=>e.jsxs("button",{type:"button","aria-pressed":r===t,onClick:()=>s(r),className:"inline-flex h-8 min-w-0 flex-1 items-center justify-center gap-1.5 rounded-md text-[13px] font-medium whitespace-nowrap text-muted aria-pressed:bg-raised aria-pressed:text-fg",children:[a[r],e.jsx("span",{className:"font-mono text-meta",children:n[r]})]},r))})}function ej({session:t,filter:n,offline:s,threshold:a,now:r,closing:l,pressed:o,onPress:c,woken:i,decision:m=!1,drag:d}){const x=Ps(),p=Zd(()=>c(t)),g=Jd({onLong:()=>c(t),onLift:b=>d==null?void 0:d.onLift(b),onDrag:b=>d==null?void 0:d.onDrag(b),onDrop:()=>d==null?void 0:d.onDrop(),onCancel:()=>d==null?void 0:d.onCancel()}),h={...d?g:p,"data-reorder-row":t.id,...(d==null?void 0:d.lifted)!==null&&(d==null?void 0:d.lifted)!==void 0?{style:nu(d.lifted)}:{}},N=(x.name==="thread"||x.name==="terminal"||x.name==="request")&&x.sessionId===t.id,k=ms(t),C=xm(t),j=sc(t),y=n==="working"?j===void 0?void 0:`${j} %`:fm(t);return e.jsx(ol,{href:ce({name:"thread",sessionId:t.id}),selected:N,stale:s,press:h,pressed:o,lead:e.jsxs(e.Fragment,{children:[e.jsx(ze,{state:k,pulse:k==="work"&&!s}),e.jsx(Xn,{tool:t.tool})]}),title:e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:e.jsx(El,{session:t,nameClassName:"font-normal text-muted"})}),i&&e.jsx("span",{"data-woken":"",className:"ml-1 inline-flex align-[-2px] text-muted",children:e.jsx(z,{name:"clock",className:"size-[13px]"})}),C>0&&e.jsx("span",{"aria-label":u.sessions.kidsLabel(C),className:"ml-1.5 font-mono text-small text-muted",children:u.sessions.kids(C)}),m&&e.jsx("span",{className:"ml-1.5 inline-flex align-[1px]",children:e.jsx(Lt,{tone:"ask",children:u.cards.decision})})]}),sub:l?e.jsx("span",{className:"text-attention",children:u.sessions.closing}):e.jsx("span",{className:k==="ask"?"text-attention":void 0,children:mm(t,n,r)}),...k==="perm"?{subTone:"perm"}:{},...y!==void 0?{meta:y,metaWarn:n==="working"&&j!==void 0&&j/100>=a}:{}})}const nu=t=>({transform:`translateY(${t}px) scale(1.02)`,position:"relative",zIndex:5,boxShadow:"0 10px 28px #0008",background:"var(--color-surface)",borderRadius:10,touchAction:"none"}),ta=()=>e.jsx("div",{"aria-hidden":"true","data-insert-line":"",className:"relative z-10 mx-3 my-0.5 h-[3px] rounded-full bg-task"});function tj({group:t,children:n,drag:s}){const a=t.kind==="rig",r=a?u.sessions.rigGroup(t.name):t.name,l=Jd({onLong:()=>s==null?void 0:s.onLong(),onLift:o=>s==null?void 0:s.onLift(o),onDrag:o=>s==null?void 0:s.onDrag(o),onDrop:()=>s==null?void 0:s.onDrop(),onCancel:()=>s==null?void 0:s.onCancel()});return e.jsxs("section",{"aria-label":r,"data-reorder-section":t.id,className:"flex flex-col gap-1.5",style:s&&s.lifted!==null?nu(s.lifted):void 0,children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-0.5 text-small font-semibold text-muted select-none",...s?l:{},children:[a&&e.jsx(ze,{state:"rig"}),r,e.jsx("span",{className:"font-normal",children:t.sessions.length})]}),e.jsx(ds,{...a?{tone:"rigs"}:{},children:n})]})}function nj({routines:t,now:n,offline:s}){const a=u.routines,r=Lb(t,n);return r.count===0?null:e.jsx(ds,{label:a.entry,children:e.jsxs(ol,{href:ce({name:"routines"}),stale:s,lead:e.jsx(z,{name:"alarm",className:"size-5"}),title:e.jsx("b",{className:"font-semibold",children:a.entry}),...r.next?{sub:a.entrySub(r.count,r.next)}:{},children:[r.flagged>0&&e.jsx(Lt,{tone:"perm",children:String(r.flagged)}),e.jsx(z,{name:"chevron",className:"size-4 text-muted"})]})})}function sj({store:t,filter:n,storage:s}){var P,W,F,re;const a=xe(t),r=Kt(),[l,o]=Qb(n,s),c=Dt(),[i,m]=gr("sessions.mode",tu,"list",s),[d,x]=gr("sessions.groupBy",ll,"projects",s),[p,g]=gr("sessions.helpers",["shown","hidden"],"shown",s),[h,N]=f.useState(null),k=h?a.sessions.get(h):void 0,C=!c&&i==="atelier",j=[...a.sessions.values()],y=nc(j),b=!a.fresh,M=(P=a.daemon)!=null&&P.sessionOrder&&a.daemon.atelier?{projects:a.projects,order:a.sessionOrder??{}}:null,S=rl(j,l,M),$=aj(t,j,M,b),v=Ob(a.routines,j),A=new Set((W=a.daemon)!=null&&W.taskAnswer?yl(a.tasks.values()).map(Y=>Y.giver).filter(Y=>!!Y):[]),R=((F=a.device)==null?void 0:F.contextNear)??Ta,_=b?a.syncedAt?u.link.lastKnownAt(Ke(a.syncedAt)):u.agents.offline:void 0,L=e.jsxs("a",{href:ce({name:"launch"}),className:rt({variant:"primary",size:"sm",className:"flex-none"}),children:[e.jsx(z,{name:"plus",className:"size-4"}),u.sessions.new]}),T=(Y,H)=>e.jsx("button",{type:"button",onClick:()=>o(Y),className:rt({size:"xs"}),children:H}),B=u.sessions,E=S.length===0&&j.length>0&&e.jsx(ds,{label:B.filter[l],children:l==="waiting"?e.jsx(Rn,{framed:!1,glyph:null,title:B.filterEmpty,body:B.filterEmptyBody(y.working),action:T("all",B.seeAll)}):y.waiting>0?e.jsx(Rn,{framed:!1,glyph:null,title:B.emptyWorking.title,body:B.emptyWorking.waiting(y.waiting),action:T("waiting",B.seeWaiting)}):e.jsx(Rn,{framed:!1,glyph:null,title:B.emptyWorking.title,body:B.emptyWorking.idle,action:T("all",B.seeAll)})});return e.jsxs(hs,{title:u.agents.title,subtitle:_,bodyClassName:"flex flex-col gap-2.5",actions:c?void 0:e.jsxs(e.Fragment,{children:[e.jsx(Zb,{value:i,onChange:m}),L]}),wideActions:c?L:void 0,children:[k&&e.jsx(Wb,{store:t,session:k,onDone:()=>N(null),...$.can?{order:$.stepsOf(S,k.id)}:{}}),$.sheet&&e.jsx(Of,{name:$.sheet.name,up:$.projectStep(S,$.sheet,-1),down:$.projectStep(S,$.sheet,1),onClose:()=>$.setSheet(null)}),e.jsx("div",{className:"sr-only","aria-live":"polite","aria-atomic":"true","data-reorder-said":"",children:$.said}),$.problem&&e.jsx("p",{role:"alert",className:"rounded-lg border border-destructive/40 px-3 py-2 text-small text-danger-fg",children:$.problem}),a.routines&&e.jsx(nj,{routines:a.routines,now:r,offline:b}),j.length===0?e.jsx(ds,{label:u.agents.empty,children:e.jsx(Rn,{list:!0,glyph:e.jsx(z,{name:"sessions"}),title:u.agents.empty,body:u.agents.emptyHint,action:e.jsxs("a",{href:ce({name:"launch"}),className:rt({variant:"primary",size:"sm"}),children:[e.jsx(z,{name:"plus",className:"size-4"}),u.sessions.newSession]})})}):C?e.jsx(Xb,{sessions:j,by:d,onBy:x,helpers:p==="shown",onHelpers:()=>g(p==="shown"?"hidden":"shown"),rigs:!!((re=a.daemon)!=null&&re.rigs),pressed:h,onPress:Y=>N(Y.id),requests:(a.asks??[]).filter(Y=>Y.kind!=="update").length}):e.jsxs(e.Fragment,{children:[e.jsx(Jb,{value:l,counts:y,onChange:o}),S.map((Y,H)=>{const I=$.can&&Y.kind==="project",D=$.lift,Q=D&&D.kind==="session"&&D.gid===Y.id?D:null,q=Q&&Q.to!==Q.from?Q.to<Q.from?Q.to:Q.to+1:-1,K=D&&D.kind==="project"&&D.to!==D.from&&(D.to<D.from?D.to:D.to+1)===H;return e.jsxs("div",{className:"contents",children:[K&&e.jsx(ta,{}),e.jsxs(tj,{group:Y,...I&&Y.project?{drag:$.projectDrag(S,Y)}:{},children:[Y.sessions.flatMap((ee,ue)=>[...ue===q?[e.jsx(ta,{},"line")]:[],e.jsx(ej,{session:ee,filter:l,offline:b,threshold:R,now:r,closing:Hx(ee,a.ops,r),pressed:h===ee.id,onPress:fe=>N(fe.id),woken:v.has(ee.id),decision:A.has(ee.id),...I?{drag:$.rowDrag(Y,ue)}:{}},ee.id)]),q===Y.sessions.length&&e.jsx(ta,{})]}),D&&D.kind==="project"&&D.to!==D.from&&D.to>D.from&&D.to===H&&H===S.filter(ee=>ee.kind==="project"&&ee.project).length-1&&e.jsx(ta,{})]},Y.id)}),E]})]})}const si=(t,n,s)=>t.filter((a,r)=>r!==n&&a<s).length,ai=(t,n,s)=>{const a=[...t],[r]=a.splice(n,1);return a.splice(s,0,r),a};function aj(t,n,s,a){const r=u.sessions.reorder,l=xe(t),[o,c]=f.useState(null),[i,m]=f.useState(""),[d,x]=f.useState(null),[p,g]=f.useState(null),h=!!s&&!a,N=(b,M)=>b.status==="applied"?null:b.status==="rejected"&&b.reason==="unavailable"?r.outdated(M):b.status==="rejected"?r.stale(M):r.offline(M),k=(b,M,S)=>{var _;if(M===S||S<0||S>=b.sessions.length)return;const $=b.sessions[M],v=ai(b.sessions,M,S),A=((_=rl(n,"all",s).find(L=>L.id===b.id))==null?void 0:_.sessions)??b.sessions,R=ux(A.map(L=>L.id),v.map(L=>L.id));x(null),t.orderSessions(b.project??null,R).then(L=>{const T=N(L,$.name);T?x(T):m(r.moved($.name,r.ordinal(S+1,!0),v.length,b.name))})},C=()=>((s==null?void 0:s.projects)??[]).map(b=>b.id),j=(b,M)=>{const S=C(),$=S.indexOf(b.project??"");$<0||$===M||M<0||M>=S.length||(x(null),t.orderProjects(ai(S,$,M)).then(v=>{const A=N(v,b.name);A?x(A):m(r.movedProject(b.name,r.ordinal(M+1,!1),S.length))}))},y=b=>[...document.querySelectorAll(b)].map(M=>{const S=M.getBoundingClientRect();return S.top+S.height/2});return{can:h,said:i,problem:d,lift:o,sheet:p,setSheet:g,rowDrag:(b,M)=>({lifted:o&&o.kind==="session"&&o.gid===b.id&&o.from===M?o.dy:null,onLift:S=>c({kind:"session",gid:b.id,from:M,to:M,y0:S,dy:0,mids:y(`[data-reorder-section="${CSS.escape(b.id)}"] [data-reorder-row]`)}),onDrag:S=>c($=>$&&{...$,dy:S-$.y0,to:si($.mids,$.from,S)}),onDrop:()=>{const S=o;c(null),S&&k(b,S.from,S.to)},onCancel:()=>c(null)}),projectDrag:(b,M)=>{const S=b.filter(v=>v.kind==="project"&&v.project),$=S.indexOf(M);return{lifted:o&&o.kind==="project"&&o.gid===M.id?o.dy:null,onLong:()=>g(M),onLift:v=>c({kind:"project",gid:M.id,from:$,to:$,y0:v,dy:0,mids:S.map(A=>y(`[data-reorder-section="${CSS.escape(A.id)}"]`)[0]??0)}),onDrag:v=>c(A=>A&&{...A,dy:v-A.y0,to:si(A.mids,A.from,v)}),onDrop:()=>{const v=o;if(c(null),!v||v.to===v.from)return;const A=S[v.to],R=A?C().indexOf(A.project):-1;R>=0&&j(M,R)},onCancel:()=>c(null)}},stepsOf:(b,M)=>{const S=b.find(v=>v.kind==="project"&&v.sessions.some(A=>A.id===M));if(!S)return{};const $=S.sessions.findIndex(v=>v.id===M);return{...$>0?{up:()=>k(S,$,$-1)}:{},...$<S.sessions.length-1?{down:()=>k(S,$,$+1)}:{}}},projectStep:(b,M,S)=>{var R;const $=C(),v=$.indexOf(M.project??""),A=v+S;return v<0||A<0||A>=$.length||!((R=l.daemon)!=null&&R.projectEdit)?void 0:()=>j(M,A)}}}const Fe=u.compare,ri=t=>{const n=t.replace(/\D/g,"");return[n.slice(0,3),n.slice(3)]},da="\0",br=t=>{const[n="",s=""]=t.split(da);return[n,s]};function bn({login:t}){return t?e.jsxs("div",{className:"flex h-8 items-center gap-2 self-center rounded-full border border-line pr-3 pl-1 text-body text-muted",children:[e.jsx("span",{"aria-hidden":"true",className:"inline-flex size-6 items-center justify-center rounded-full bg-raised text-meta font-semibold text-fg",children:t.slice(0,1).toUpperCase()}),u.account(t)]}):null}function rj({step:t,login:n,pcName:s,lost:a,stalled:r=!1,reach:l="pc_online",onRetry:o,onSame:c,onCancel:i,onRestart:m,onDone:d,actions:x}){var M,S;const[p,g]=f.useState(!1),h=s??u.yourPc,N=()=>{g(!1),m()},k=e.jsx("button",{type:"button",onClick:N,className:dt,children:Fe.retry}),C=a&&(t==null?void 0:t.step)!=="linked"?e.jsx(De,{title:Fe.lostTitle,role:"status",children:e.jsx("p",{children:Fe.lostBody})}):null;if((t==null?void 0:t.step)==="linked")return e.jsxs(Mt,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(Us,{size:88}),e.jsx("h1",{className:Ht,children:Fe.doneTitle(t.pc.name??s??u.yourPc,sl(((M=globalThis.navigator)==null?void 0:M.userAgent)??"",((S=globalThis.navigator)==null?void 0:S.maxTouchPoints)??0).replace(/ tablette$/,""))}),e.jsx("p",{className:"max-w-[300px] text-muted",children:Fe.doneBody})]}),e.jsx(Et,{}),x??e.jsx("a",{href:ce({name:"sessions"}),onClick:d,className:Nt,children:Fe.seePending})]});if((t==null?void 0:t.step)==="cancelled"&&p)return e.jsxs(Mt,{children:[e.jsx(bn,{login:n}),e.jsxs("section",{role:"alert",className:"rounded-control border border-danger-fg/15 bg-danger-bg p-4 text-danger-fg",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2.5",children:[e.jsx(z,{name:"warning",stroke:1.5}),e.jsx("strong",{children:Fe.cancelledTitle})]}),e.jsx("p",{className:"text-body leading-[1.6]",children:Fe.cancelledBody})]}),e.jsx(Et,{}),k]});const j=(t==null?void 0:t.step)==="cancelled"?[Fe.cancelledTitle,null]:!t&&r?[Fe.stalledTitle,Fe.stalledBody]:(t==null?void 0:t.step)==="expired"?[Fe.expiredTitle,Fe.expiredBody]:(t==null?void 0:t.step)==="refused"?[Fe.refusedTitle,Fe.refusedBody]:null;if(j)return e.jsxs(Mt,{children:[e.jsx(bn,{login:n}),e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:Ht,children:j[0]}),j[1]&&e.jsx("p",{className:"text-muted",children:j[1]})]}),C,e.jsx(Et,{}),k]});if((t==null?void 0:t.step)==="compare"&&t.phoneConfirmed)return e.jsxs(Mt,{top:"pt-40",children:[e.jsx(bn,{login:n}),e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(As,{}),e.jsx("h1",{className:Ht,children:Fe.waitTitle}),e.jsxs("p",{className:"max-w-[300px] text-muted",children:[br(Fe.waitBody(h,da))[0],e.jsx("span",{className:"font-mono text-fg",children:ri(t.code).join(" ")}),br(Fe.waitBody(h,da))[1]]})]}),e.jsx(Et,{}),e.jsx("button",{type:"button",onClick:i,className:dt,children:Fe.cancel})]});if((t==null?void 0:t.step)==="compare"){const[$,v]=ri(t.code),[A,R]=br(Fe.intro(da));return e.jsxs(Mt,{children:[e.jsx(bn,{login:n}),e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:Ht,children:Fe.title}),e.jsxs("p",{className:"text-muted",children:[A,e.jsx("strong",{className:"font-semibold text-fg",children:h}),R]})]}),e.jsxs("div",{className:"flex flex-col items-center gap-3 rounded-control border border-line bg-surface px-4 py-6",children:[e.jsxs("div",{"aria-label":Fe.codeLabel(`${$} ${v}`),className:"flex justify-center gap-3.5 font-mono text-[2.5rem] leading-[48px] font-semibold tracking-[.06em]",children:[e.jsx("span",{children:$}),e.jsx("span",{children:v})]}),e.jsx("span",{className:"text-small text-muted",children:Fe.basis})]}),C,e.jsx(Et,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:c,className:Nt,children:Fe.same}),e.jsx("button",{type:"button",onClick:()=>{g(!0),i()},className:dt,children:Fe.different})]})]})}const y=t&&e.jsx("button",{type:"button",onClick:i,className:dt,children:Fe.cancel}),b=l==="pc_offline"?[Fe.offlineTitle,Fe.offlineBody(h)]:l==="relay_unreachable"?[Fe.relayTitle,Fe.relayBody]:null;return b?e.jsxs(Mt,{top:"pt-40",children:[e.jsx(bn,{login:n}),e.jsxs("div",{role:"status",className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:Ht,children:b[0]}),e.jsx("p",{className:"text-muted",children:b[1]})]}),C,e.jsx(Et,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:o,className:Nt,children:Fe.retryNow}),y]})]}):e.jsxs(Mt,{top:"pt-40",children:[e.jsx(bn,{login:n}),e.jsxs("div",{role:"status",className:"flex flex-col items-center gap-3.5 text-center text-muted",children:[e.jsx(As,{}),e.jsx("p",{children:Fe.waitCode})]}),C,e.jsx(Et,{}),y]})}const pt=u.recover,Me=u.recover.no;function Kn(){var n,s;const t=sl(((n=globalThis.navigator)==null?void 0:n.userAgent)??"",((s=globalThis.navigator)==null?void 0:s.maxTouchPoints)??0);return t==="iPhone"||t==="iPad"?t:null}const lj=["key","shield","laptop"];function oj({login:t,platform:n,onPasskey:s,onCode:a}){const r=Kn();return e.jsxs(Mt,{children:[e.jsx(bn,{login:t}),e.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[e.jsx(Us,{size:72}),e.jsx("h1",{className:Ht,children:pt.title(r)}),e.jsx("p",{className:"max-w-[320px] text-muted",children:pt.lead})]}),n&&e.jsx("ul",{className:"flex flex-col gap-3 text-body leading-5 text-fg/85",children:pt.notes(Kn()).map((l,o)=>e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx(z,{name:lj[o],className:"size-5 text-muted"}),l]},o))}),e.jsx(Et,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[n&&e.jsxs("button",{type:"button",onClick:s,className:Nt,children:[e.jsx(z,{name:"face"}),pt.go]}),e.jsx("button",{type:"button",onClick:a,className:n?dt:Nt,children:pt.code})]})]})}const ij={warn:"bg-attention/12 text-attention",bad:"bg-danger-bg text-danger-fg"};function cj({icon:t,tone:n}){return e.jsx("span",{"aria-hidden":"true",className:`inline-flex size-12 flex-none items-center justify-center rounded-full ${ij[n]}`,children:e.jsx(z,{name:t,className:"size-6"})})}function on({login:t,icon:n,tone:s,title:a,body:r,centred:l=!1,children:o,actions:c}){return e.jsxs(Mt,{children:[e.jsx(bn,{login:t}),e.jsxs("div",{role:"alert",className:`flex flex-col gap-3 ${l?"items-center text-center":"items-start"}`,children:[e.jsx(cj,{icon:n,tone:s}),e.jsx("h1",{className:Ht,children:a}),e.jsx("p",{className:"text-muted",children:r})]}),o&&e.jsx("div",{className:"flex flex-col gap-2.5 text-body leading-[1.5] text-muted",children:o}),e.jsx(Et,{}),e.jsx("div",{className:"flex flex-col gap-3",children:c})]})}const ts=({lead:t,children:n})=>e.jsxs("p",{children:[t&&e.jsx("strong",{className:"font-semibold text-fg",children:t}),t&&" ",n]}),dj=t=>{if(!t)return null;const n=new Date(t);return Number.isNaN(n.getTime())?null:n.toLocaleDateString(ut,{day:"numeric",month:"short"})};function uj({state:t,login:n,reach:s,onRetry:a,onCode:r,onCancel:l,onSignOut:o,onDone:c,actions:i}){const m=Kn(),d=(g=!0)=>e.jsx("button",{type:"button",onClick:r,className:g?Nt:dt,children:pt.code},"code"),x=(g=!1)=>e.jsx("button",{type:"button",onClick:a,className:g?Nt:dt,children:pt.retry},"retry");if(t.step==="reaching"||t.step==="faceid"||t.step==="checking"){const g=(t.step==="reaching"?null:t.pcName)??u.yourPc,h=[[t.step==="reaching"?pt.checking.reaching(g):pt.checking.reached(g),t.step==="reaching"?"on":"done"],[Pt()?pt.checking.faceId:pt.checking.check,t.step==="faceid"?"on":t.step==="checking"?"done":"next"],[pt.checking.verifying(g),t.step==="checking"?"on":"next"]];return e.jsxs(Mt,{top:"pt-40",children:[e.jsx(bn,{login:n}),e.jsxs("div",{role:"status",className:"flex flex-col items-center gap-3 text-center",children:[e.jsx(As,{}),e.jsx("h1",{className:Ht,children:pt.checking.title}),e.jsx("p",{className:"max-w-[320px] text-muted",children:pt.checking.body(g)})]}),e.jsx("ol",{className:"flex flex-col gap-2.5 rounded-[10px] border border-line px-4 py-3.5 text-body",children:h.map(([N,k])=>e.jsxs("li",{className:`flex items-center gap-2.5 ${k==="on"?"font-medium text-fg":"text-muted"}`,children:[k==="done"?e.jsx(z,{name:"check",className:"size-[18px] text-ok"}):k==="on"?e.jsx(As,{size:"size-[18px]"}):e.jsx("span",{className:"size-[18px]","aria-hidden":"true"}),N]},N))}),e.jsx(Et,{}),e.jsx("button",{type:"button",onClick:l,className:dt,children:pt.cancel})]})}if(t.step==="done"){const g=t.pc.name??u.yourPc;return e.jsxs(Mt,{top:"pt-14",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[e.jsx(Us,{size:88}),e.jsx("h1",{className:Ht,children:pt.done.title(m,g)}),e.jsx("p",{className:"max-w-[320px] text-muted",children:pt.done.body(g)})]}),e.jsxs("p",{role:"status",className:"flex items-center gap-2 self-center text-small text-ok",children:[e.jsx(z,{name:"check",className:"size-4"}),pt.done.told(g)]}),e.jsx(Et,{}),i??e.jsx("a",{href:ce({name:"sessions"}),onClick:c,className:Nt,children:u.compare.seePending})]})}if(t.step==="cancelled")return null;const p=t.pcName??u.yourPc;switch(t.why){case"none":return e.jsx(on,{login:n,icon:"key",tone:"warn",title:Me.none.title,body:Me.none.body(p),actions:[x(!0),d(!1)],children:e.jsx(ts,{lead:Me.none.hintTitle,children:Me.none.hint})});case"revoked":return e.jsx(on,{login:n,icon:"unlink",tone:"bad",title:Me.revoked.title(m),body:Me.revoked.body(p,dj(t.revokedAt)),actions:[d()],children:e.jsx("p",{children:Me.revoked.hint})});case"old":return e.jsx(on,{login:n,icon:"key",tone:"warn",title:Me.old.title,body:Me.old.body,actions:[d()],children:e.jsx(ts,{lead:Me.old.hintTitle,children:Me.old.hint(m)})});case"offline":{const[g,h]=s==="relay_unreachable"?[u.compare.relayTitle,u.compare.relayBody]:[Me.offline.title(p),Me.offline.body(p)];return e.jsx(on,{login:n,icon:"wifioff",tone:"warn",centred:!0,title:g,body:h,actions:[x(!0),e.jsx("button",{type:"button",onClick:l,className:dt,children:pt.cancel},"cancel")]})}case"otherPc":{const[g,h]=t.tags??["",""];return e.jsxs(on,{login:n,icon:"shield",tone:"bad",title:Me.otherPc.title(p),body:Me.otherPc.body,actions:[d(),e.jsx("button",{type:"button",onClick:o,className:dt,children:Me.otherPc.signOut},"out")],children:[e.jsxs("dl",{className:"grid grid-cols-[auto_1fr] gap-x-4 gap-y-2.5 rounded-control border border-line bg-surface p-4 text-body text-fg",children:[e.jsx("dt",{className:"text-muted",children:Me.otherPc.inPasskey}),e.jsxs("dd",{className:"font-mono",children:[g," · ",Me.otherPc.expected]}),e.jsx("dt",{className:"text-muted",children:Me.otherPc.received}),e.jsxs("dd",{className:"font-mono text-danger-fg",children:[h," · ",Me.otherPc.unknown]})]}),e.jsx(ts,{lead:Me.otherPc.reinstalledTitle,children:Me.otherPc.reinstalledBody}),e.jsx(ts,{lead:Me.otherPc.otherwise,children:Me.otherPc.warning})]})}case"connected":return e.jsxs(on,{login:n,icon:t.device==="iPhone"?"phone":"tablet",tone:"warn",title:Me.connected.title(t.device),body:Me.connected.body(p),actions:[d(),x()],children:[e.jsx(ts,{lead:Me.connected.otherTitle(t.device),children:Me.connected.other}),e.jsx(ts,{lead:Me.connected.reinstalledTitle(t.device),children:Me.connected.reinstalled(t.device)})]});case"rate":{const g=t.retryInMs!==void 0?Math.max(1,Math.ceil(t.retryInMs/6e4)):null;return e.jsx(on,{login:n,icon:"clock",tone:"warn",title:Me.rate.title,body:Me.rate.body(p,g),actions:[d(),...g!==null?[e.jsx("button",{type:"button",disabled:!0,className:dt,children:Me.rate.retryIn(g)},"wait")]:[]]})}case"blocked":return e.jsx(on,{login:n,icon:"lock",tone:"bad",title:Me.blocked.title(p),body:Me.blocked.body(p),actions:[d()],children:e.jsxs("p",{children:[Me.blocked.hintBefore(p),e.jsx("strong",{className:"font-semibold text-fg",children:Me.blocked.unblock}),Me.blocked.hintAfter]})});case"timeout":return e.jsx(on,{login:n,icon:"clock",tone:"warn",centred:!0,title:Me.timeout.title(p),body:Me.timeout.body,actions:[x(!0),d(!1)]});case"unsaved":return e.jsx(on,{login:n,icon:m==="iPad"?"tablet":"phone",tone:"warn",centred:!0,title:Me.unsaved.title,body:Me.unsaved.body(p,m),actions:[x(!0),d(!1)]})}}const jn=u.enroll;function Gs(t,n="protect",s=!0){var v,A,R,_;const a=xe(t),r=mn(),l=(v=a.device)==null?void 0:v.confirm,o=r&&(n==="protect"?l===!1:l===!0&&!((A=a.device)!=null&&A.recover)),[c,i]=f.useState(null),[m,d]=f.useState(null),[x,p]=f.useState(!1),[g,h]=f.useState(null),[N,k]=f.useState(0),C=g?(R=a.ops[g])==null?void 0:R.phase:void 0,j=(n==="protect"?l===!0:((_=a.device)==null?void 0:_.recover)===!0)||C==="applied",y=C==="sending"||C==="uncertain",b=C==="rejected"||C==="failed";f.useEffect(()=>{if(!s||!o||j)return;let L=!0;i(null);const T=t.pcKey();return Promise.all([t.prepareConfirm({purpose:"register"}),T?Ux(T):Promise.reject(new Error("unpaired"))]).then(([B,E])=>{L&&i({challenge:B,userId:E})},()=>{L&&d("prepareFailed")}),()=>{L=!1}},[t,o,j,N,s]);const M=()=>{var E,P;if(!c||x||y)return;const{challenge:L,userId:T}=c;p(!0),d(null);const B=sl(((E=globalThis.navigator)==null?void 0:E.userAgent)??"",((P=globalThis.navigator)==null?void 0:P.maxTouchPoints)??0);Wx({challenge:L.challenge,rpId:L.rpId},{label:B,id:T}).then(W=>{if(p(!1),W==="cancelled"){d("cancelled");return}if(W==="unsupported"){d("unsupported");return}i(null);const F=t.registerCredential(W,Kx(T));F===null?d("failed"):h(F)},()=>{p(!1),d("failed")})},S=()=>{d(null),h(null),k(L=>L+1)},$=m??(b?"failed":null);return{offered:o,registered:j,challenge:(c==null?void 0:c.challenge)??null,asking:x||y,problem:$,go:M,retry:S}}function su({e:t,className:n,label:s=jn.go}){const a=t.problem==="failed"||t.problem==="prepareFailed",r=t.problem==="cancelled"?u.confirm.cancelled:t.problem==="unsupported"?jn.unsupported:t.problem==="failed"?u.confirm.failed:t.problem==="prepareFailed"?u.confirm.prepareFailed:null;return e.jsxs(e.Fragment,{children:[r&&e.jsx(De,{title:r,tone:"warning",role:"alert"}),a?e.jsx("button",{type:"button",onClick:t.retry,className:n,children:u.confirm.retry}):t.problem==="unsupported"?null:e.jsx("button",{type:"button",disabled:!t.challenge||t.asking,onClick:t.go,className:n,children:t.challenge||t.asking?s:u.confirm.preparing})]})}function xj({store:t}){const n=Gs(t);return n.registered?e.jsx(li,{children:jn.done}):n.offered?e.jsx(li,{children:e.jsx("div",{className:"flex flex-col items-end gap-2",children:e.jsx(su,{e:n,className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 text-body font-medium disabled:opacity-45"})})}):null}function li({children:t}){return e.jsxs("div",{className:"flex items-baseline justify-between gap-4 border-b border-line px-4 py-3 last:border-b-0",children:[e.jsx("dt",{className:"flex-none text-muted",children:jn.row}),e.jsx("dd",{className:"min-w-0 text-right break-words",children:t})]})}function mj({store:t,onDone:n,update:s=!1}){const a=Gs(t),[r,l]=f.useState(!1);f.useEffect(()=>{a.offered&&l(!0)},[a.offered]);const o=ce({name:"sessions"});return r?a.registered?e.jsxs(e.Fragment,{children:[e.jsx(De,{title:jn.done,role:"status"}),e.jsx("a",{href:o,onClick:n,className:Nt,children:u.compare.seePending})]}):e.jsxs(e.Fragment,{children:[e.jsxs("section",{"aria-labelledby":"protect-title",className:"flex flex-col gap-3 rounded-control border border-line bg-surface p-4",children:[e.jsx("h2",{id:"protect-title",className:"text-title leading-[1.35] font-semibold",children:s?u.passkeyUpdate.title:jn.title}),e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:s?u.passkeyUpdate.stepBody(Kn()):jn.body}),e.jsx(su,{e:a,className:Nt,label:s?u.passkeyUpdate.go:jn.go})]}),e.jsx("a",{href:o,onClick:n,className:dt,children:jn.later})]}):e.jsx("a",{href:o,onClick:n,className:Nt,children:u.compare.seePending})}const ft=u.passkeyUpdate,pj=3e3,au="ledge.mobile.passkeyUpdateLater",ru=(t,n)=>{try{return!!n&&(t==null?void 0:t.getItem(au))===n}catch{return!1}},Xr="ledge:passkey-later";function lu(t,n=globalThis.localStorage){const s=xe(t),a=mn(),r=s.device,[,l]=f.useState(0);return f.useEffect(()=>{const o=()=>l(c=>c+1);return globalThis.addEventListener(Xr,o),()=>globalThis.removeEventListener(Xr,o)},[]),a&&(r==null?void 0:r.confirm)===!0&&!r.recover&&!ru(n,r.id)}function fj({store:t,storage:n=globalThis.localStorage,enroll:s}){var g;const a=Gs(t,"update",!s),r=s??a,l=(g=xe(t).device)==null?void 0:g.id,[o,c]=f.useState(()=>ru(n,l)),[i,m]=f.useState(!1);if(f.useEffect(()=>{r.offered&&!o&&m(!0)},[r.offered,o]),f.useEffect(()=>{if(!i||!r.registered)return;const h=setTimeout(()=>m(!1),pj);return()=>clearTimeout(h)},[i,r.registered]),!i)return null;if(r.registered)return e.jsxs("div",{role:"status",className:"flex items-start gap-3 rounded-card border border-line bg-surface p-4",children:[e.jsx(z,{name:"check",className:"size-5 text-ok"}),e.jsxs("span",{className:"flex flex-col gap-0.5",children:[e.jsx("strong",{className:"text-body font-semibold",children:ft.done}),e.jsx("small",{className:"text-small text-muted",children:ft.doneBody(Kn())})]})]});if(o)return null;const d=()=>{try{l&&(n==null||n.setItem(au,l))}catch{}globalThis.dispatchEvent(new Event(Xr)),c(!0),m(!1)},x=r.problem==="failed"||r.problem==="prepareFailed"||r.problem==="unsupported",p=r.problem==="cancelled"?ft.cancelled:x?ft.failed(t.pcName()??u.yourPc):null;return e.jsxs("section",{"aria-labelledby":"passkey-update-title",className:"flex flex-col gap-3 rounded-card border border-info/30 bg-info/[0.06] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{"aria-hidden":"true",className:"inline-flex size-9 items-center justify-center rounded-full bg-raised text-muted",children:e.jsx(z,{name:"key",className:"size-[18px]"})}),e.jsx("h2",{id:"passkey-update-title",className:"text-title leading-[1.35] font-semibold",children:ft.title})]}),p?e.jsx(De,{title:p,tone:r.problem==="cancelled"?"warning":"danger",role:"alert"}):e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:Pt()?ft.body(Kn()):ft.bodyOther(Kn())}),e.jsxs("div",{className:p?"grid grid-cols-2 gap-2":"flex flex-col gap-2",children:[p?e.jsx("button",{type:"button",onClick:x?r.retry:r.go,disabled:!x&&!r.challenge,className:Nt,children:ft.retry}):e.jsx("button",{type:"button",onClick:r.go,disabled:!r.challenge||r.asking,className:Nt,children:r.asking?e.jsxs(e.Fragment,{children:[e.jsx(As,{size:"size-4"}),ft.updating]}):r.challenge?ft.go:u.confirm.preparing}),e.jsx("button",{type:"button",onClick:d,disabled:r.asking,className:dt,children:ft.later})]})]})}const oi=t=>t.problem==="failed"||t.problem==="prepareFailed";function hj({store:t,enroll:n,quiet:s=!1}){const a=Gs(t,"update",!n),r=n??a,l=xe(t).device;return l!=null&&l.confirm?r.registered?e.jsxs("div",{className:"flex items-baseline justify-between gap-4 border-b border-line px-4 py-3 last:border-b-0",children:[e.jsx("dt",{className:"flex-none text-muted",children:ft.row}),e.jsx("dd",{className:"text-right text-ok",children:ft.ready})]}):r.offered?e.jsxs("div",{className:"flex flex-col gap-2 border-b border-line px-4 py-3 last:border-b-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("dt",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{children:ft.row}),e.jsx("span",{className:"text-small text-muted",children:ft.rowHint})]}),e.jsx("dd",{className:"flex-none",children:e.jsx("button",{type:"button",disabled:r.asking||!oi(r)&&!r.challenge,onClick:oi(r)?r.retry:r.go,className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 text-body font-medium disabled:opacity-45",children:r.asking?ft.updating:ft.update})})]}),r.problem&&!s&&e.jsx(De,{title:r.problem==="cancelled"?ft.cancelled:ft.failed(t.pcName()??u.yourPc),tone:"warning",role:"alert"})]}):null:null}const Ds=(t,n)=>(t.slice(0,n===void 0?void 0:n*4).match(/.{1,4}/g)??[]).join(" "),ou=t=>Ds(t,6),gj=t=>Ds(t,2);function iu(t){var r;const n=xe(t),s=Kt();if(!((r=n.daemon)!=null&&r.usage)||!n.usage||!n.fresh)return null;const a=Mf(Ba(n.usage,s,n.fresh),n.usageAlert,s);return a.find(l=>l.tone==="red")??a[0]??null}function bj({store:t}){const n=xe(t),s=Kt(),a=u.limits,r=iu(t),l=c=>a.harness[c]??c,o=r&&(()=>{const c=jl(r.window),i=r.tone==="red"?a.reachedLabel(l(r.harness),c):a.overLabel(l(r.harness),c,r.window.pct),m=r.window.resetsAt?Uc(r.window.resetsAt,s):null;return m?`${i} · ${hl(r.window.resetsAt,s)?a.resumesOn(m):a.resumes(m)}`:i})();return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:"bleed flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-2.5",children:[e.jsx(Zt,{fallback:{name:"connection"},label:u.connection.title}),e.jsx("h1",{className:"text-base font-semibold",children:u.settings.usage})]}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto pt-5 pb-[34px]",children:[o&&e.jsx(De,{title:o,tone:r.tone==="red"?"danger":"warning",role:"status"}),n.usage===null?e.jsx("p",{role:"status",className:"text-small text-muted",children:a.loading}):e.jsx("div",{className:"rounded-[10px] border border-line bg-surface px-4 py-2",children:e.jsx(xh,{usage:n.usage,now:s,alert:n.usageAlert,fresh:n.fresh,heading:!1})})]})]})}function cu(){const t=globalThis;if(!t.Notification||!t.PushManager)return"unsupported";const n=t.navigator;return n&&"standalone"in n&&n.standalone!==!0?"unsupported":t.Notification.permission==="denied"?"denied":"ok"}const jj=t=>{const n=atob(t.replace(/-/g,"+").replace(/_/g,"/"));return Uint8Array.from(n,s=>s.charCodeAt(0))};function du(t,n){return new Promise(s=>{const a=()=>{var o;const l=(o=t.getState().ops[n])==null?void 0:o.phase;return!l||yn(l)&&l!=="uncertain"?!1:(r(),s(l==="applied"?"applied":"other"),!0)},r=t.subscribe(a);a()})}async function yj(t,n=(s,a)=>globalThis.fetch(s,a)){var a;if(cu()==="unsupported")return"unsupported";try{if(await Notification.requestPermission()!=="granted")return"denied";const r=await n("/push/key",{credentials:"same-origin",cache:"no-store"});if(r.status===404)return"unavailable";if(!r.ok)return"failed";const l=await r.json();if(typeof l.publicKey!="string")return"failed";const o=l.publicKey,c=jj(o),{pushManager:i}=await navigator.serviceWorker.ready;await((a=await i.getSubscription())==null?void 0:a.unsubscribe());const m=await i.subscribe({userVisibleOnly:!0,applicationServerKey:c}),d=xx.safeParse(m.toJSON());if(!d.success)return"failed";const x=t.pushSubscribe(d.data,o);return x===null?"failed":await du(t,x)==="applied"?"on":"failed"}catch{return"failed"}}async function Nj(t){const n=t.pushUnsubscribe(),s=n!==null&&await du(t,n)==="applied";try{await(await navigator.serviceWorker.ready).pushManager.getSubscription().then(a=>a==null?void 0:a.unsubscribe())}catch{}return s}const _t=u.notifications,kj=t=>t==="denied"?_t.denied:t==="unsupported"?_t.unsupported:t==="unavailable"?_t.noPush:t==="failed"?_t.failed:null;function uu(t,n){var m;const s=(m=xe(t).device)==null?void 0:m.push,[a,r]=f.useState(!1),[l,o]=f.useState(null);return{push:s,busy:a,problem:l,enable:async()=>{if(a)return"failed";r(!0),o(null);const d=await yj(t,n);return r(!1),o(kj(d)),d},disable:async()=>{a||(r(!0),o(null),await Nj(t),r(!1))}}}function vj({store:t,fetchImpl:n}){const s=uu(t,n);if(!s.push)return null;const a=s.push==="on";return e.jsxs("div",{className:"flex flex-col gap-2 border-b border-line px-4 py-3 text-body last:border-b-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("dt",{className:"flex-none text-muted",children:_t.row}),e.jsx("dd",{className:"flex min-w-0 items-center gap-3 text-right",children:s.push==="unavailable"?e.jsx("span",{children:_t.noPush}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:a?_t.on:_t.off}),e.jsx(Wa,{on:a,label:_t.row,disabled:s.busy,onChange:r=>{r?s.enable():s.disable()}})]})})]}),s.push==="stale"&&e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[e.jsx("p",{className:"text-muted",children:_t.stale}),e.jsx("button",{type:"button",disabled:s.busy,onClick:()=>{s.enable()},className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 font-medium disabled:opacity-45",children:_t.enable})]}),s.problem&&e.jsx(De,{title:s.problem,tone:"warning",role:"alert"})]})}const ii=t=>(t==="off"||t==="stale")&&cu()!=="unsupported";function ci({store:t,onDone:n,fetchImpl:s,body:a=_t.body}){const r=uu(t,s),l=xe(t).fresh,o=()=>{r.enable().then(c=>{c==="on"&&(is({name:"sessions"}),n())})};return e.jsxs(e.Fragment,{children:[e.jsxs("section",{"aria-labelledby":"notify-title",className:"flex flex-col gap-3 rounded-control border border-line bg-surface p-4",children:[e.jsx("h2",{id:"notify-title",className:"text-title leading-[1.35] font-semibold",children:_t.title}),e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:a}),r.problem&&e.jsx(De,{title:r.problem,tone:"warning",role:"alert"}),e.jsx("button",{type:"button",disabled:r.busy||!l,onClick:o,className:Nt,children:r.busy?_t.working:l?_t.enable:_t.waiting})]}),e.jsx("a",{href:ce({name:"sessions"}),onClick:n,className:dt,children:_t.later})]})}function wj(t,n){switch(t.status){case"applied":return{text:n,quiet:!1};case"cancelled":return{text:u.confirm.cancelled,quiet:!0};case"expired":return{text:u.confirm.expired,quiet:!0};case"rejected":return t.reason==="assertion_expired"?{text:u.confirm.expired,quiet:!0}:{text:u.confirm.refused[t.reason]??n,quiet:!1};default:return{text:n,quiet:!1}}}const Ee=u.connection.pcUpdate,as="flex flex-col gap-3 rounded-card border bg-surface p-3.5";function Sj({store:t,action:n,pc:s,from:a,to:r,onClose:l}){var g;const o=f.useId(),c=!!((g=xe(t).device)!=null&&g.confirm),[i,m]=f.useState(!1),[d,x]=f.useState(null),p=()=>{m(!0),x(null),t.pcAction(n,n==="update"?r:void 0).then(h=>{h.status==="applied"?l():x(wj(h,Ee.notDone))},()=>x({text:Ee.notDone,quiet:!1})).finally(()=>m(!1))};return e.jsxs(ht,{labelledBy:`${o}-title`,onClose:()=>{i||l()},children:[e.jsx("h2",{id:`${o}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:n==="update"?Ee.confirmUpdate:Ee.confirmRestart}),e.jsx("p",{className:"text-body text-muted",children:n==="update"?Ee.confirmUpdateBody(s,a,r):Ee.confirmRestartBody(s)}),e.jsx("p",{className:`rounded-control border border-dashed border-input px-3 py-2 text-small ${c?"text-muted":"text-attention"}`,children:c?Ee.passkey:Ee.noPasskey}),d&&e.jsx("p",{role:"status",className:`text-body ${d.quiet?"text-muted":"text-danger-fg"}`,children:d.text}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Pe,{variant:"ghost",className:"flex-1",disabled:i,onClick:l,children:Ee.cancel}),e.jsx(Pe,{variant:"primary",className:"flex-[2]",disabled:i||!c,onClick:p,children:Ee.confirm})]})]})}function Cj({run:t,fresh:n}){const s=t.action==="update"?["asked","installing","restarting","back"]:["asked","restarting","back"],a=t.step==="restarting"?n?s.indexOf("restarting"):s.length-1:1;return e.jsx("ol",{className:"flex flex-col gap-1.5 text-small",children:s.map((r,l)=>e.jsxs("li",{className:`flex items-center gap-2 ${l>a?"text-muted":""}`,children:[e.jsx("span",{"aria-hidden":"true",className:"w-4 text-center",children:l<a?"✓":l===a?"…":"·"}),e.jsx("span",{children:Ee.steps[r]})]},r))})}function $j({store:t,run:n,fresh:s,from:a,onRetry:r}){const l=n.action==="update";return Hi(n)?e.jsxs("div",{className:`${as} border-line`,role:"status",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("strong",{className:"text-body",children:l?Ee.updating(n.version):Ee.restarting}),e.jsx("span",{className:"text-meta text-info",children:Ee.running})]}),e.jsx(Cj,{run:n,fresh:s}),e.jsx("p",{className:"text-small text-muted",children:Ee.leave})]}):n.step==="done"?e.jsxs("div",{className:`${as} border-ok/40`,role:"status",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("strong",{className:"text-body",children:l?Ee.done(n.version):Ee.restarted}),e.jsx("span",{className:"text-meta text-ok",children:Ee.upToDate})]}),e.jsx(Pe,{onClick:()=>t.dismissPc(),children:Ee.close})]}):n.reason==="setup-failed"?e.jsxs("div",{className:`${as} border-attention/40`,role:"alert",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("strong",{className:"text-body",children:Ee.setupFailed}),e.jsx("span",{className:"text-meta text-attention",children:Ee.toFinish})]}),e.jsx("p",{className:"text-small text-muted",children:Ee.setupFailedBody(n.version)}),e.jsx(Pe,{onClick:()=>t.dismissPc(),children:Ee.close})]}):e.jsxs("div",{className:`${as} border-danger-fg/40`,role:"alert",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("strong",{className:"text-body",children:l?Ee.failed:Ee.notRestarted}),e.jsx("span",{className:"text-meta text-danger-fg",children:Ee.refused})]}),e.jsxs("p",{className:"text-small text-muted",children:[Ee.unchanged(a)," ",n.reason?Ee.reasons[n.reason]:""]}),e.jsx(Pe,{onClick:r,children:Ee.retry})]})}function Mj({store:t,appVersion:n}){const s=xe(t),[a,r]=f.useState(null),l=s.daemon,o=s.pc;if(!l)return null;const c=n!==null&&qi(l.version,n);if(!c&&!l.restart&&!o)return null;const i=l.name,m=()=>{t.dismissPc(),((o==null?void 0:o.action)==="restart"||n)&&r((o==null?void 0:o.action)??"restart")};return e.jsxs("section",{"aria-labelledby":"pc-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"pc-title",className:"text-small font-medium text-muted",children:Ee.title}),o?e.jsx($j,{store:t,run:o,fresh:s.fresh,from:l.version,onRetry:m}):c&&(l.update?e.jsxs("div",{className:`${as} border-input`,children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("strong",{className:"text-body",children:Ee.behind}),e.jsx("span",{className:"font-mono text-small text-muted",children:Ee.versions(l.version,n)})]}),e.jsx("p",{className:"text-small text-muted",children:Ee.why}),e.jsx(Pe,{variant:"primary",block:!0,disabled:!s.fresh,onClick:()=>r("update"),children:Ee.update}),e.jsx("p",{className:"text-meta text-muted",children:Ee.keepGoing})]}):e.jsxs("div",{className:`${as} border-attention/40`,children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("strong",{className:"text-body",children:Ee.manual}),e.jsx("span",{className:"font-mono text-small text-muted",children:Ee.versions(l.version,n)})]}),e.jsx("p",{className:"text-small text-muted",children:l.restart?Ee.clone:Ee.byHand})]})),l.restart&&e.jsxs("div",{className:"flex items-center gap-3 rounded-control border border-line px-3.5 py-3",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"text-body",children:Ee.restart}),e.jsx("span",{className:"text-small text-muted",children:Ee.restartHint})]}),e.jsx(Pe,{size:"sm",disabled:!s.fresh||Hi(o),onClick:()=>r("restart"),children:Ee.restartGo})]}),a&&e.jsx(Sj,{store:t,action:a,pc:i,from:l.version,to:a==="update"&&n?n:l.version,onClose:()=>r(null)})]})}const Va="min-h-12 w-full min-w-0 rounded-control border border-input bg-surface px-3 text-base text-fg focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-info",Qe=u.settings,Ga="flex flex-col rounded-[10px] border border-line bg-surface text-body",xu="flex flex-col gap-1 border-b border-line px-4 py-3 last:border-b-0",Ej=Array.from({length:Math.round((hx-Kl)*20)+1},(t,n)=>Math.round((Kl+n*.05)*100)),_j=["decision"];function Il({label:t,hint:n,children:s}){const a=f.useId();return e.jsxs("div",{className:xu,children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"min-w-0",children:t}),s(n?a:void 0)]}),n&&e.jsx("p",{id:a,className:"text-small text-muted",children:n})]})}function Rj(t,n){if(t==="hour")return new Date(n.getTime()+36e5);if(t==="four")return new Date(n.getTime()+4*36e5);const s=new Date(n);return s.setDate(s.getDate()+1),s.setHours(8,0,0,0),s}function Tj(t,n){const s=t.toLocaleTimeString(ut,{hour:"2-digit",minute:"2-digit"});if(t.toDateString()===n.toDateString())return s;const a=new Date(n);return a.setDate(a.getDate()+1),t.toDateString()===a.toDateString()?Qe.tomorrow(s):`${t.toLocaleDateString(ut,{day:"numeric",month:"short"})} ${s}`}function mu(t){var d;const n=xe(t),[s,a]=f.useState(null),[r,l]=f.useState(!1),o=f.useRef(0),c=f.useRef(!0);return f.useEffect(()=>()=>{c.current=!1},[]),{prefs:s??((d=n.device)==null?void 0:d.prefs)??fx,send:x=>{const p=++o.current;a(x),l(!1),t.setDevicePrefs(x).then(g=>{!c.current||p!==o.current||(a(null),g.status!=="applied"&&l(!0))})},failed:r,fresh:n.fresh}}function Aj({store:t}){var i,m;const n=xe(t),s=mu(t),a=Kt();if(!((i=n.daemon)!=null&&i.settings)||!((m=n.device)!=null&&m.prefs)||n.device.push!=="on")return null;const{prefs:r}=s,l=r.quietUntil!==null?new Date(r.quietUntil):null,o=l!==null&&l.getTime()>a,c=d=>s.send({...r,quietUntil:Rj(d,new Date(a)).toISOString()});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:Ga,children:[_j.map(d=>e.jsx(Il,{label:Qe.notify[d],hint:Qe.notify[`${d}Hint`],children:x=>e.jsx(Wa,{on:r.notify[d],label:Qe.notify[d],describedBy:x,disabled:!s.fresh,onChange:p=>s.send({...r,notify:{...r.notify,[d]:p}})})},d)),e.jsxs("div",{className:xu,children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{children:Qe.pause}),o&&e.jsx("span",{role:"status",className:"text-right text-attention",children:Qe.pausedUntil(Tj(l,new Date(a)))})]}),e.jsx("p",{className:"text-small text-muted",children:Qe.pauseHint}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-2",children:o?e.jsx("button",{type:"button",disabled:!s.fresh,onClick:()=>s.send({...r,quietUntil:null}),className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 font-medium disabled:opacity-45",children:Qe.resume}):["hour","four","morning"].map(d=>e.jsx("button",{type:"button","aria-label":Qe.pauseLabel[d],disabled:!s.fresh,onClick:()=>c(d),className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 font-medium disabled:opacity-45",children:Qe.pauseFor[d]},d))})]})]}),e.jsx("p",{className:"text-small text-muted",children:Qe.notify.always}),s.failed&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:Qe.failed})]})}function Ij({store:t}){var d,x;const n=xe(t),s=mu(t),[a,r]=f.useState(null),[l,o]=f.useState(!1),c=f.useRef(!0);if(f.useEffect(()=>()=>{c.current=!1},[]),!((d=n.daemon)!=null&&d.settings)||!((x=n.device)!=null&&x.prefs))return null;const i=Math.round((a??n.device.contextNear??Ta)*100),m=p=>{r(p/100),o(!1),t.setContextNear(p/100).then(g=>{c.current&&(r(null),g.status!=="applied"&&o(!0))})};return e.jsxs("section",{"aria-labelledby":"ledge-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"ledge-title",className:"text-small font-medium text-muted",children:Qe.ledge}),e.jsx("div",{className:Ga,children:e.jsx(Il,{label:Qe.context,hint:Qe.contextHint,children:p=>e.jsx("select",{className:`${Va} w-auto`,"aria-label":Qe.context,"aria-describedby":p,disabled:!n.fresh||a!==null,value:i,onChange:g=>m(Number(g.target.value)),children:Ej.map(g=>e.jsx("option",{value:g,children:u.percent(g)},g))})})}),!n.fresh&&e.jsx("p",{className:"text-small text-muted",children:Qe.offline}),(l||s.failed)&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:Qe.failed})]})}function Lj(){const t=mx();return e.jsx("div",{className:Ga,children:e.jsx(Il,{label:Qe.motion,hint:Qe.motionHint,children:n=>e.jsx(Wa,{on:t,label:Qe.motion,describedBy:n,onChange:px})})})}function Oj({store:t}){const n=xe(t).daemon;return e.jsxs("section",{"aria-labelledby":"managed-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"managed-title",className:"text-small font-medium text-muted",children:Qe.managed}),(n==null?void 0:n.terminal)&&e.jsx("dl",{className:Ga,children:e.jsxs("div",{className:"flex items-baseline justify-between gap-4 px-4 py-3",children:[e.jsx("dt",{className:"text-muted",children:Qe.terminal}),e.jsx("dd",{children:n.terminalInput?Qe.allowed:Qe.notAllowed})]})}),e.jsx("p",{className:"text-small text-muted",children:Qe.managedBody})]})}const se=u.settings.projects,pu=Object.keys(os),Dj=80,Xa=t=>se.errors[t.status==="rejected"?t.reason:t.status]??se.errors.failed;function Fj(t,n,s){const a=n+s;if(a<0||a>=t.length)return[...t];const r=[...t];return[r[n],r[a]]=[r[a],r[n]],r}function Pj({color:t}){return e.jsx("span",{className:"size-3 flex-none rounded-full",style:{background:os[t]},"aria-hidden":"true"})}function zj({value:t,onChange:n,name:s}){return e.jsxs("fieldset",{className:"m-0 min-w-0 border-0 p-0",children:[e.jsx("legend",{className:"mb-1.5 text-small text-muted",children:se.color}),e.jsx("div",{className:"flex flex-wrap gap-2",children:pu.map(a=>e.jsxs("label",{className:"grid size-10 cursor-pointer place-items-center rounded-full border border-line has-[:checked]:border-fg has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-info",children:[e.jsx("input",{type:"radio",name:s,value:a,checked:t===a,onChange:()=>n(a),className:"sr-only","aria-label":se.colors[a]}),e.jsx("span",{className:"size-6 rounded-full",style:{background:os[a]},"aria-hidden":"true"})]},a))})]})}function Bj({store:t,project:n,projects:s,onClose:a,onDelete:r,onFolders:l}){var T,B;const o=f.useId(),c=new Set(s.map(E=>E.color)),[i,m]=f.useState((n==null?void 0:n.name)??""),[d,x]=f.useState((n==null?void 0:n.color)??pu.find(E=>!c.has(E))??"blue"),[p,g]=f.useState(!1),[h,N]=f.useState(null),k=xe(t),C=n===null&&!!((T=k.daemon)!=null&&T.projectFolders),j=!!((B=k.device)!=null&&B.confirm),[y,b]=f.useState(null),[M,S]=f.useState(!1);f.useEffect(()=>{C&&t.requestRecentFolders()},[t,C]);const $=i.trim(),v=$!==""&&s.some(E=>E.id!==(n==null?void 0:n.id)&&Gl(E.name)===Gl($)),A=n!==null&&$===n.name&&d===n.color,R=C&&(y===null||!j),_=()=>{if(!$||v||p||R)return;if(A){a();return}g(!0),N(null);const E=n?{...$!==n.name?{name:$}:{},...d!==n.color?{color:d}:{}}:null;(n?t.editProject(n.id,E):t.createProject($,d,C?y:void 0)).then(P=>{g(!1),P.status==="applied"?a():N(Xa(P))})};if(M)return e.jsxs(ht,{labelledBy:`${o}-title`,onClose:()=>S(!1),children:[e.jsx("h2",{id:`${o}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:se.firstFolder}),e.jsx(fu,{store:t,busy:!1,skip:()=>!1,rowLabel:se.choose,rowAria:se.chooseLabel,pickLabel:se.chooseThis,pickAria:se.chooseLabel,pickDisabled:!1,error:null,onPick:E=>{b(E),S(!1)},onBack:()=>S(!1)})]});const L=[...new Set([...y!==null?[y]:[],...k.recentFolders??[]])];return e.jsxs(ht,{labelledBy:`${o}-title`,onClose:()=>{p||a()},children:[e.jsx("h2",{id:`${o}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:n?se.editTitle:se.newTitle}),!n&&e.jsx("p",{className:"text-body text-muted",children:C?se.newBody:se.newBodyOld}),e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:E=>{E.preventDefault(),_()},children:[e.jsxs("label",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"text-small text-muted",children:se.name}),e.jsx("input",{className:Va,value:i,maxLength:Dj,autoFocus:!0,"aria-invalid":v||void 0,onChange:E=>m(E.target.value)}),v&&e.jsx("span",{role:"alert",className:"text-small text-danger-fg",children:se.errors.name_taken})]}),e.jsx(zj,{name:`${o}-color`,value:d,onChange:x}),C&&e.jsxs("section",{"aria-labelledby":`${o}-first`,className:"flex flex-col gap-1.5",children:[e.jsxs("h3",{id:`${o}-first`,className:"flex items-center gap-2 text-small text-muted",children:[se.firstFolder,e.jsx("span",{className:"rounded-full border border-task/45 px-2 text-meta text-task",children:se.required})]}),L.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{className:"text-meta tracking-[.06em] text-muted uppercase",children:se.recents}),e.jsx("ul",{className:"flex flex-col rounded-control border border-line",children:L.map(E=>e.jsxs("li",{className:Ts,children:[e.jsxs("button",{type:"button","aria-pressed":y===E,"aria-label":se.chooseLabel(E),disabled:p,onClick:()=>b(E),className:`flex min-h-10 min-w-0 flex-1 items-center gap-2 text-left ${y===E?"font-medium text-fg":""}`,children:[e.jsx(z,{name:y===E?"check":"folder",className:"size-4 flex-none"}),e.jsx("span",{className:"font-mono text-small break-all",children:E})]}),y===E&&e.jsx("span",{className:"text-meta text-ok",children:se.chosen})]},E))})]}),e.jsx(Pe,{size:"sm",className:"self-start",disabled:p,onClick:()=>S(!0),children:se.browseMore}),y===null&&e.jsx("p",{"data-pick-first":"",className:"rounded-control border border-dashed border-input px-3 py-2 text-small text-muted",children:se.pickFirst}),!j&&e.jsx("p",{className:"text-small text-attention",children:se.noPasskey})]}),h&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:h}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Pe,{variant:"ghost",className:"flex-1",disabled:p,onClick:a,children:se.cancel}),e.jsx(Pe,{variant:"primary",type:"submit",className:"flex-[2]",disabled:p||!$||v||R,children:n?se.save:se.create})]}),n&&l&&e.jsx(Pe,{disabled:p,onClick:l,children:se.folders}),n&&e.jsx(Pe,{variant:"ghost",className:"text-danger-fg!",disabled:p,onClick:r,children:se.remove})]})]})}function qj({store:t,project:n,projects:s,agents:a,onClose:r}){var N;const l=f.useId(),o=!!((N=xe(t).device)!=null&&N.confirm),c=s.filter(k=>k.id!==n.id),[i,m]=f.useState(null),[d,x]=f.useState(!1),[p,g]=f.useState(null),h=()=>{x(!0),g(null),t.deleteProject(n.id,i).then(k=>{x(!1),k.status==="applied"?r():g(Xa(k))})};return e.jsxs(ht,{labelledBy:`${l}-title`,onClose:()=>{d||r()},children:[e.jsx("h2",{id:`${l}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:se.deleteTitle(n.name)}),e.jsx("p",{className:"text-body text-muted",children:se.deleteAgents(a)}),e.jsxs("fieldset",{className:"m-0 flex min-w-0 flex-col gap-2 border-0 p-0",children:[e.jsx("legend",{className:"mb-1.5 text-small text-muted",children:se.deleteWhere}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:`${l}-move`,checked:i===null,onChange:()=>m(null)}),se.noProject]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:`${l}-move`,checked:i!==null,disabled:c.length===0,onChange:()=>{var k;return m(((k=c[0])==null?void 0:k.id)??null)}}),se.moveTo]}),i!==null&&e.jsx("select",{className:Va,"aria-label":se.target,value:i,onChange:k=>m(k.target.value),children:c.map(k=>e.jsx("option",{value:k.id,children:k.name},k.id))})]}),e.jsx("p",{className:`rounded-control border border-dashed border-input px-3 py-2 text-small ${o?"text-muted":"text-attention"}`,children:o?se.passkey:se.noPasskey}),p&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:p}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Pe,{variant:"ghost",className:"flex-1",disabled:d,onClick:r,children:se.cancel}),e.jsx(Pe,{variant:"primary",className:"flex-[2]",disabled:d||!o,onClick:h,children:se.confirmDelete})]})]})}const Hj=t=>t.machine==="local"?se.thisPc:t.label??t.machine,Uj=t=>t.split("/").filter(Boolean).at(-1)??"/",Ts="flex items-center gap-3 border-b border-line px-3 py-2.5 last:border-b-0";function Wj({store:t,project:n,onClose:s}){var C;const a=f.useId(),r=xe(t),[l,o]=f.useState(!1),[c,i]=f.useState(!1),[m,d]=f.useState(null);f.useEffect(()=>{t.requestProjectFolders(n.id)},[t,n.id]);const x=r.projectFolders[n.id],p=!!((C=r.device)!=null&&C.confirm),g=(j,y)=>{i(!1),j.status==="applied"?(t.requestProjectFolders(n.id),y()):d(Xa(j))},h=j=>{i(!0),d(null),t.removeFolder(n.id,j.machine,j.path).then(y=>g(y,()=>{}))},N=j=>{i(!0),d(null),t.addFolder(n.id,j).then(y=>g(y,()=>o(!1)))},k=()=>{c||s()};if(l){const j=Array.isArray(x)?x:[];return e.jsxs(ht,{labelledBy:`${a}-title`,onClose:k,children:[e.jsx("h2",{id:`${a}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:se.pickTitle}),e.jsx(fu,{store:t,busy:c,skip:y=>j.some(b=>b.machine==="local"&&b.path===y),rowLabel:se.addShort,rowAria:se.addThisLabel,onPick:N,note:e.jsx("p",{className:`rounded-control border border-dashed border-input px-3 py-2 text-small ${p?"text-muted":"text-attention"}`,children:p?se.folderPasskey:se.noPasskey}),error:m,pickLabel:se.addThis,pickAria:se.addThisLabel,pickDisabled:!p,onBack:()=>{o(!1),d(null)}})]})}return e.jsxs(ht,{labelledBy:`${a}-title`,onClose:k,children:[e.jsx("h2",{id:`${a}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:se.foldersTitle(n.name)}),x===void 0?e.jsx("p",{role:"status",className:"text-small text-muted",children:se.foldersLoading}):x==="gone"?e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:se.errors.stale}):x.length===0?e.jsx("p",{className:"text-body text-muted",children:se.foldersNone}):e.jsx("ul",{className:"flex max-h-[45dvh] flex-col overflow-y-auto rounded-control border border-line",children:x.map(j=>e.jsxs("li",{className:Ts,children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"font-medium",children:Uj(j.path)}),e.jsxs("span",{className:"font-mono text-meta break-all text-muted",children:[j.path," · ",Hj(j)]})]}),e.jsx(Pe,{size:"sm",variant:"ghost","aria-label":se.removeFolderLabel(j.path),disabled:c||!r.fresh||x.length===1,onClick:()=>h(j),children:se.removeFolder})]},`${j.machine}
|
|
17
|
+
${j.path}`))}),Array.isArray(x)&&x.length===1&&e.jsx("p",{"data-last-folder":"",className:"rounded-control border border-dashed border-input px-3 py-2 text-small text-muted",children:se.lastFolder}),m&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:m}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Pe,{variant:"ghost",className:"flex-1",disabled:c,onClick:s,children:se.close}),e.jsxs(Pe,{variant:"primary",className:"flex-[2]",disabled:c||!r.fresh||x==="gone",onClick:()=>{d(null),o(!0)},children:[e.jsx(z,{name:"plus",className:"size-4"}),se.addFolder]})]})]})}function fu({store:t,busy:n,skip:s,rowLabel:a,rowAria:r,onPick:l,note:o,error:c,pickLabel:i,pickAria:m,pickDisabled:d,onBack:x}){const p=xe(t),[g,h]=f.useState(null);f.useEffect(()=>{t.requestRecentFolders(),t.listFolder()},[t]);const N=p.folderListing,k=N&&(g===null||N.path===g)?N:null,C=y=>{h(y),t.listFolder(y)},j=(p.recentFolders??[]).filter(y=>!s(y));return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex max-h-[55dvh] flex-col gap-3 overflow-y-auto",children:[g===null&&j.length>0&&e.jsxs("section",{"aria-label":se.recents,className:"flex flex-col gap-1.5",children:[e.jsx("h3",{className:"text-small text-muted",children:se.recents}),e.jsx("ul",{className:"flex flex-col rounded-control border border-line",children:j.map(y=>e.jsxs("li",{className:Ts,children:[e.jsx("span",{className:"min-w-0 flex-1 font-mono text-small break-all",children:y}),e.jsx(Pe,{size:"sm","aria-label":r(y),disabled:n||d,onClick:()=>l(y),children:a})]},y))})]}),e.jsxs("section",{"aria-label":se.browse,className:"flex flex-col gap-1.5",children:[e.jsx("h3",{className:"text-small text-muted",children:se.browse}),k?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"font-mono text-small break-all",children:k.path}),k.error&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:se.folderErrors[k.error]}),e.jsxs("ul",{className:"flex flex-col rounded-control border border-line",children:[k.parent&&e.jsx("li",{className:Ts,children:e.jsxs("button",{type:"button",className:"flex min-h-10 flex-1 items-center gap-2 text-left",onClick:()=>C(k.parent),children:[e.jsx(z,{name:"back",className:"size-4"}),se.parent]})}),k.entries.map(y=>{const b=k.repos.find(M=>M.name===y);return e.jsx("li",{className:Ts,children:e.jsxs("button",{type:"button","aria-label":se.open(y),className:"flex min-h-10 min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>C(`${k.path==="/"?"":k.path}/${y}`),children:[e.jsx("span",{className:"truncate",children:y}),b&&e.jsxs("span",{className:"flex-none rounded-full bg-raised px-2 text-meta text-muted",children:["⎇ ",b.branch]})]})},y)}),!k.error&&k.entries.length===0&&e.jsx("li",{className:"px-3 py-2.5 text-small text-muted",children:se.empty})]}),k.cut&&e.jsx("p",{className:"text-meta text-muted",children:se.cut})]}):e.jsx("p",{role:"status",className:"text-small text-muted",children:se.loadingFolder})]})]}),e.jsx("p",{className:"text-small text-muted",children:se.onlyThisPc}),o,c&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:c}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Pe,{variant:"ghost",className:"flex-1",disabled:n,onClick:x,children:se.back}),e.jsx(Pe,{variant:"primary",className:"flex-[2]",disabled:n||d||!k||!!k.error,"aria-label":k?m(k.path):i,onClick:()=>{k&&l(k.path)},children:i})]})]})}function Kj({store:t}){var k;const n=xe(t),[s,a]=f.useState(null),[r,l]=f.useState(null),[o,c]=f.useState(null),[i,m]=f.useState(!1),[d,x]=f.useState(null);if(!((k=n.daemon)!=null&&k.projectEdit)||!n.daemon.atelier)return null;const p=n.projects,g=C=>[...n.sessions.values()].filter(j=>j.projectId===C&&j.state!=="exited").length,h=!n.fresh||i,N=(C,j)=>{m(!0),x(null),t.orderProjects(Fj(p.map(y=>y.id),C,j)).then(y=>{m(!1),y.status!=="applied"&&x(Xa(y))})};return e.jsxs("section",{"aria-labelledby":"projects-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"projects-title",className:"text-small font-medium text-muted",children:se.title}),e.jsxs("ul",{className:"flex flex-col rounded-[10px] border border-line bg-surface text-body",children:[p.length===0&&e.jsx("li",{className:"px-4 py-3 text-muted",children:se.none}),p.map((C,j)=>e.jsxs("li",{className:"flex items-center gap-3 border-b border-line px-4 py-2.5 last:border-b-0",children:[e.jsx(Pj,{color:C.color}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate font-medium",children:C.name}),e.jsx("span",{className:"text-small text-muted",children:se.agents(g(C.id))})]}),e.jsx(Vl,{label:se.up(C.name),disabled:h||j===0,onClick:()=>N(j,-1),children:e.jsx(z,{name:"arrowUp",className:"size-4"})}),e.jsx(Vl,{label:se.down(C.name),disabled:h||j===p.length-1,onClick:()=>N(j,1),children:e.jsx(z,{name:"arrowUp",className:"size-4 rotate-180"})}),e.jsx(Pe,{size:"sm","aria-label":se.editLabel(C.name),disabled:!n.fresh,onClick:()=>a(C),children:se.edit})]},C.id))]}),e.jsxs(Pe,{disabled:!n.fresh,onClick:()=>a("new"),children:[e.jsx(z,{name:"plus",className:"size-4"}),se.add]}),d&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:d}),e.jsx("p",{className:"text-small text-muted",children:n.daemon.projectFolders?se.folders_note:se.folders_note_old}),s!==null&&e.jsx(Bj,{store:t,project:s==="new"?null:s,projects:p,onClose:()=>a(null),onDelete:()=>{s!=="new"&&(l(s),a(null))},onFolders:n.daemon.projectFolders?()=>{s!=="new"&&(c(s),a(null))}:null}),o&&e.jsx(Wj,{store:t,project:o,onClose:()=>c(null)}),r&&e.jsx(qj,{store:t,project:r,projects:p,agents:g(r.id),onClose:()=>l(null)})]})}const nn=u.connection.device,hu=t=>{var n,s;return t??Vx(((n=globalThis.navigator)==null?void 0:n.userAgent)??"",((s=globalThis.navigator)==null?void 0:s.maxTouchPoints)??0)};function Vj({store:t,pinned:n}){const s=xe(t),[a,r]=f.useState(null),[l,o]=f.useState(!1),c=s.device;if(!(c!=null&&c.id))return null;const i=hu(c.name),m=n?new Date(n.pinnedAt).toLocaleDateString(ut,{day:"numeric",month:"short",year:"numeric"}):null,d=(a==null?void 0:a.trim())??"",x=()=>{if(!(!d||d.length>Za)){if(t.renameDevice(d)===null){o(!0);return}o(!1),r(null)}};return e.jsxs("section",{"aria-labelledby":"device-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"device-title",className:"text-small font-medium text-muted",children:nn.title}),e.jsxs("div",{className:"flex items-center gap-3 rounded-[10px] border border-line bg-surface px-4 py-3",children:[e.jsx("span",{className:"grid size-9 flex-none place-items-center rounded-[10px] bg-raised","aria-hidden":"true",children:e.jsx(z,{name:c.kind==="tablet"?"tablet":"phone"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-body font-semibold [overflow-wrap:anywhere]",children:i}),m&&e.jsx("p",{className:"text-meta text-muted",children:nn.linkedOn(m)})]}),e.jsx(Pe,{size:"sm","aria-label":nn.renameLabel(i),onClick:()=>{o(!1),r(i)},children:nn.rename})]}),l&&e.jsx("p",{role:"status",className:"text-small text-danger-fg",children:nn.failed}),e.jsx("p",{className:"text-small text-muted",children:nn.others}),a!==null&&e.jsxs(ht,{labelledBy:"rename-title",onClose:()=>r(null),children:[e.jsx("h2",{id:"rename-title",className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:nn.sheetTitle}),e.jsx("p",{className:"text-body text-muted",children:nn.sheetBody}),e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:p=>{p.preventDefault(),x()},children:[e.jsxs("label",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"sr-only",children:nn.field}),e.jsx("input",{className:Va,value:a,maxLength:Za,autoFocus:!0,"aria-describedby":"rename-count",onChange:p=>r(p.target.value)}),e.jsxs("span",{id:"rename-count",className:"self-end text-meta text-muted",children:[a.length,"/",Za]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Pe,{variant:"ghost",className:"flex-1",onClick:()=>r(null),children:nn.cancel}),e.jsx(Pe,{variant:"primary",type:"submit",className:"flex-[2]",disabled:!d,children:nn.save})]})]})]})]})}const st=u.connection,$n=u.settings,Gj=()=>[{value:"system",label:st.themes.system},{value:"light",label:st.themes.light},{value:"dark",label:st.themes.dark}],Xj=t=>t==="ready"?st.states.online:t==="handshaking"?st.states.connecting:st.states.offline;function Yj({store:t,login:n,relay:s,pinned:a,linkState:r,build:l,onSignOut:o,fetchImpl:c,section:i}){var j,y,b,M;const m=xe(t),d=Gs(t,"update"),x=lu(t),p=iu(t),g=gx(),h=Di();f.useEffect(()=>{var S;i==="link"&&((S=document.getElementById("link-title"))==null||S.scrollIntoView({block:"start"}))},[i]);const N=(a==null?void 0:a.name)??((j=m.daemon)==null?void 0:j.name)??null,k=!!m.daemon&&!!l&&qi(m.daemon.version,l.version),C=[[st.account,n?u.account(n):st.unknown,!1],[st.relay,s,!0],[st.pc,N??st.unknown,!1],[st.pcFingerprint,a?Ds(a.fingerprint):st.unknown,!0],[st.status,Xj(r),!1],[st.version,(l==null?void 0:l.version)??st.none,!0],[st.appFingerprint,l?ou(l.fingerprint):st.none,!0],[st.pcVersion,((y=m.daemon)==null?void 0:y.version)??st.none,!0,k?"text-attention":void 0]];return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:"bleed flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-2.5",children:[e.jsx(Zt,{fallback:{name:"sessions"},label:st.back}),e.jsx("h1",{className:"text-base font-semibold",children:st.title})]}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col gap-6 overflow-y-auto pt-5 pb-[34px]",children:[e.jsx("div",{className:"flex flex-col empty:hidden",children:e.jsx(fj,{store:t,enroll:d})}),e.jsx(Vj,{store:t,pinned:a}),e.jsxs("section",{"aria-labelledby":"appearance-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"appearance-title",className:"text-small font-medium text-muted",children:$n.appearance}),e.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":"true",className:"text-small text-muted",children:$n.theme}),e.jsx(Na,{name:"theme",legend:$n.theme,options:Gj(),value:g,onChange:S=>bx(S),fit:!0})]}),e.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":"true",className:"text-small text-muted",children:$n.lang}),e.jsx(Na,{name:"lang",legend:$n.lang,options:yx.map(S=>({value:S,label:$n.langs[S],lang:S})),value:h,onChange:jx,fit:!0})]}),e.jsx(Lj,{})]}),((b=m.device)==null?void 0:b.push)&&e.jsxs("section",{"aria-labelledby":"notifications-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"notifications-title",className:"text-small font-medium text-muted",children:$n.notifications}),e.jsx("dl",{className:"flex flex-col rounded-[10px] border border-line bg-surface text-body",children:e.jsx(vj,{store:t,fetchImpl:c})}),e.jsx(Aj,{store:t})]}),((M=m.daemon)==null?void 0:M.usage)&&e.jsxs("a",{href:ce({name:"connection",section:"usage"}),className:"flex items-center justify-between gap-4 rounded-[10px] border border-line bg-surface px-4 py-3 text-body",children:[e.jsx("span",{children:$n.usage}),e.jsxs("span",{className:"flex items-center gap-2 text-muted",children:[p&&e.jsx("span",{"data-usage-dot":!0,"aria-hidden":"true",className:"size-2 rounded-full bg-attention"}),e.jsx(z,{name:"chevron",className:"size-4"})]})]}),e.jsx(Ij,{store:t}),e.jsx(Kj,{store:t}),e.jsx(Mj,{store:t,appVersion:(l==null?void 0:l.version)??null}),e.jsxs("section",{"aria-labelledby":"link-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"link-title",className:"text-small font-medium text-muted",children:st.section}),e.jsxs("dl",{className:"flex flex-col rounded-[10px] border border-line bg-surface text-body",children:[C.map(([S,$,v,A])=>e.jsxs("div",{className:"flex items-baseline justify-between gap-4 border-b border-line px-4 py-3 last:border-b-0",children:[e.jsx("dt",{className:"flex-none text-muted",children:S}),e.jsx("dd",{className:`min-w-0 text-right break-words ${v?"font-mono":""} ${A??""}`,children:$})]},S)),e.jsx(xj,{store:t}),e.jsx(hj,{store:t,enroll:d,quiet:x})]})]}),e.jsx(Oj,{store:t}),e.jsx("div",{className:"flex-grow","aria-hidden":"true"}),e.jsx("button",{type:"button",onClick:o,className:dt,children:st.signOut})]})]})}function Qj({onOther:t}){return e.jsxs(Mt,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(Us,{size:80,frozen:!0}),e.jsx("h1",{className:Ht,children:u.denied.title}),e.jsx("p",{className:"max-w-[300px] text-muted",children:u.denied.bodyNoLogin})]}),e.jsx(Et,{}),e.jsx("button",{type:"button",onClick:t,className:dt,children:u.denied.other})]})}const Qt=u.keyChanged,Zj=t=>{const n=new Date(t);return Number.isNaN(n.getTime())?u.connection.unknown:n.toLocaleDateString(ut,{day:"numeric",month:"short"})};function Jj({pcName:t,known:n,received:s,onRelink:a,onSignOut:r}){return e.jsxs(Mt,{children:[e.jsxs("div",{className:"flex flex-col gap-3.5",children:[e.jsx("span",{"aria-hidden":"true",className:"inline-flex size-12 items-center justify-center rounded-full bg-danger-bg text-danger-fg",children:e.jsxs("svg",{className:pa,viewBox:"0 0 24 24",children:[e.jsx("path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}),e.jsx("path",{d:"M12 8v4"}),e.jsx("path",{d:"M12 16h.01"})]})}),e.jsx("h1",{className:Ht,children:Qt.title(t??u.yourPc)}),e.jsx("p",{className:"text-muted",children:Qt.body})]}),e.jsxs("dl",{className:"grid grid-cols-[auto_1fr] gap-x-4 gap-y-2.5 rounded-control border border-line bg-surface p-4 text-body",children:[e.jsx("dt",{className:"text-muted",children:Qt.known}),e.jsx("dd",{className:"font-mono",children:n?Qt.knownDetail(Ds(n.fingerprint,2),Zj(n.pinnedAt)):u.connection.unknown}),e.jsx("dt",{className:"text-muted",children:Qt.received}),e.jsx("dd",{className:"font-mono",children:s?Qt.receivedDetail(Ds(s,2)):u.connection.unknown})]}),e.jsxs("div",{className:"flex flex-col gap-3 text-body leading-[1.6] text-muted",children:[e.jsxs("p",{children:[e.jsx("strong",{className:"text-fg",children:Qt.reinstalledTitle})," ",Qt.reinstalledBody]}),e.jsxs("p",{children:[e.jsx("strong",{className:"text-fg",children:Qt.otherwise})," ",Qt.warning]})]}),e.jsx(Et,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:a,className:Nt,children:Qt.relink}),e.jsx("button",{type:"button",onClick:r,className:dt,children:Qt.signOut})]})]})}const e1="/auth/github/start";function t1(t){return t==="denied"?u.login.errors.denied:t==="bad_state"||t==="error"?u.login.errors.failed:null}const n1=[e.jsxs(e.Fragment,{children:[e.jsx("circle",{cx:"7.5",cy:"15.5",r:"5.5"}),e.jsx("path",{d:"m21 2-9.6 9.6"}),e.jsx("path",{d:"m15.5 7.5 3 3L22 7l-3-3"})]}),e.jsxs(e.Fragment,{children:[e.jsx("rect",{width:"20",height:"14",x:"2",y:"3",rx:"2"}),e.jsx("line",{x1:"8",x2:"16",y1:"21",y2:"21"}),e.jsx("line",{x1:"12",x2:"12",y1:"17",y2:"21"})]}),e.jsxs(e.Fragment,{children:[e.jsx("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})];function s1({server:t,error:n}){return e.jsxs(Mt,{children:[e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(Us,{size:88}),e.jsx("h1",{className:"text-display leading-[34px] font-bold tracking-[-.025em]",children:u.login.title}),e.jsx("p",{className:"max-w-[300px] text-muted",children:u.login.subtitle})]}),e.jsxs("div",{className:"flex h-8 items-center gap-2.5 self-center rounded-full border border-line px-3 text-small text-muted",children:[e.jsxs("svg",{className:`${pa} size-3.5`,viewBox:"0 0 24 24","aria-hidden":"true",children:[e.jsx("rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2"}),e.jsx("rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2"}),e.jsx("line",{x1:"6",x2:"6.01",y1:"6",y2:"6"}),e.jsx("line",{x1:"6",x2:"6.01",y1:"18",y2:"18"})]}),e.jsx("span",{className:"font-mono",children:t})]}),n&&e.jsx("p",{role:"alert",className:"rounded-control border border-danger-fg/15 bg-danger-bg p-3.5 text-body text-danger-fg",children:n}),e.jsx(Et,{}),e.jsx("ul",{className:"flex flex-col gap-3.5 text-fg/85",children:u.login.notes.map((s,a)=>e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx("svg",{className:`${pa} text-fg`,viewBox:"0 0 24 24","aria-hidden":"true",children:n1[a]}),e.jsx("span",{children:s})]},s))}),e.jsxs("a",{href:e1,className:Nt,children:[e.jsx("svg",{className:"size-5 flex-none fill-current",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"M12 .3a12 12 0 0 0-3.8 23.38c.6.12.83-.26.83-.57L9 21.07c-3.34.72-4.04-1.61-4.04-1.61-.55-1.39-1.34-1.76-1.34-1.76-1.08-.74.09-.73.09-.73 1.2.09 1.83 1.24 1.83 1.24 1.07 1.83 2.81 1.3 3.5 1 .1-.78.42-1.31.76-1.6-2.67-.3-5.47-1.34-5.47-5.93 0-1.31.47-2.38 1.24-3.22-.14-.3-.54-1.52.1-3.18 0 0 1-.32 3.3 1.23a11.5 11.5 0 0 1 6 0c2.28-1.55 3.29-1.23 3.29-1.23.64 1.66.24 2.88.12 3.18a4.65 4.65 0 0 1 1.23 3.22c0 4.61-2.8 5.63-5.48 5.92.42.36.81 1.1.81 2.22l-.01 3.29c0 .31.2.69.82.57A12 12 0 0 0 12 .3"})}),u.login.github]})]})}function a1({onHere:t}){return e.jsxs(Mt,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:Ht,children:u.replaced.title}),e.jsx("p",{className:"text-muted",children:u.replaced.body})]}),e.jsx(Et,{}),e.jsx("button",{type:"button",onClick:t,className:dt,children:u.replaced.here})]})}const r1=t=>rt({variant:t?"primary":"outline",className:"h-auto min-h-11 w-full justify-start gap-2 px-3 py-2.5 text-left leading-[19px] whitespace-normal [overflow-wrap:anywhere]"}),di=t=>new Date(t).toLocaleTimeString(ut,{hour:"2-digit",minute:"2-digit"});function gu({store:t,ask:n,end:s,fresh:a,ghost:r,canConfirm:l,enroll:o,onGone:c,full:i=!1,selected:m=!1}){const d=u.asks,x=u.cards.receipt,p=zc(t),g=dc(n),h=uc(n),[N,k]=f.useState(!1),[C,j]=f.useState(""),[y,b]=f.useState(null),[M,S]=f.useState(null),[$,v]=f.useState(!1),[A,R]=f.useState(null),_=ce({name:"ask",id:n.id}),L=async(w,O)=>{b(w),S(null),R({key:w,answer:O});let V;if(O.kind!=="seen"){const X=await p({purpose:"rig",qitem:n.id,answer:O});if(typeof X=="string"){b(null),S(X);return}V=X}const Z=t.answerAsk(n.id,O,V?{assertion:V}:{});if(b(null),Z===null){S("notSent");return}(O.kind==="words"||O.kind==="resolve")&&k(!1)},T=x.what(h.name,d.pill[g]);if(s.kind==="sent"){const w=Tm(n,s.answer),O=s.answer.kind==="seen"?e.jsx(at,{tone:"ok",title:x.seen,body:x.what(h.name,n.summary)}):e.jsx(at,{tone:"ok",title:x.sentTo(h.name),body:[h.role,w?`« ${w.length>60?`${w.slice(0,60)}…`:w} »`:""].filter(Boolean).join(" · ")});return e.jsx(ya,{onGone:c,children:O})}if(s.kind==="already"||r&&s.kind!=="failed"&&s.kind!=="uncertain")return!a&&r&&s.kind!=="already"?(queueMicrotask(c),null):e.jsx(ya,{onGone:c,children:e.jsx(at,{tone:"gone",title:d.already,body:x.what(h.name,n.summary)})});const B=w=>{L((A==null?void 0:A.key)??"retry",w)};if(s.kind==="uncertain")return e.jsx(at,{tone:"warn",title:u.decide.uncertain,body:d.uncertain,action:{label:d.retry,onClick:()=>{t.resendAsk(n.id)||B(s.answer)},disabled:!a||y!==null}});if(s.kind==="failed"){const w=s.error==="openrig_stopped"?d.stopped:s.error==="unreachable"?d.unreachable:s.message??s.error;return e.jsx(at,{tone:"fail",title:d.notSent(w),body:T,action:{label:d.retry,onClick:()=>B(s.answer),disabled:!a||y!==null}})}const E=s.kind==="sending"||y!==null,P=a&&!E,W=g!=="update",F=P&&(l||!W),re=w=>y===w||s.kind==="sending"&&(A==null?void 0:A.key)===w?e.jsx(Ct,{}):null,Y=n.questions.length>1,H=n.questions.filter(w=>ao(n,w.id)!==null||s.kind==="recorded"&&s.answer.kind==="choice"&&s.answer.questionId===w.id).length,I=n.bodyTruncated&&n.body===n.summary?"":n.body,D=n.priority==="routine"?null:d.priority[n.priority],Q=(w,O=!1)=>e.jsx("p",{className:`text-small [overflow-wrap:anywhere] ${O?"text-destructive":"text-muted"}`,role:O?"alert":void 0,children:w}),q=Pt(),K=W?q?d.sendCheck:d.sendDevice:d.send,ee=w=>{var Z;const O=ao(n,w.id)??(s.kind==="recorded"&&s.answer.kind==="choice"&&s.answer.questionId===w.id?((Z=w.options.find(X=>X.id===s.answer.optionId))==null?void 0:Z.label)??null:null);if(O!==null)return e.jsxs("span",{className:"flex items-center gap-1.5 text-body",children:[e.jsx(z,{name:"check",className:"size-4 text-ok"}),O]});const V=[...w.options].sort((X,J)=>Number(J.recommended)-Number(X.recommended));return e.jsx("div",{className:"flex flex-col gap-2",children:V.map(X=>{const J=`${w.id}:${X.id}`;return e.jsxs("button",{type:"button",disabled:!F||N,onClick:()=>{L(J,{kind:"choice",questionId:w.id,optionId:X.id})},className:r1(X.recommended),children:[re(J),e.jsx("span",{className:"min-w-0",children:X.label}),X.recommended&&e.jsx("span",{className:"ml-auto pl-2 text-xs whitespace-nowrap opacity-85",children:d.recommended})]},X.id)})})},ue=e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"sr-only",htmlFor:`ask-${n.id}`,children:n.kind==="parked"?d.placeholderParked(h.name):d.placeholder}),e.jsx("textarea",{id:`ask-${n.id}`,rows:2,value:C,onChange:w=>j(w.target.value),disabled:E,placeholder:n.kind==="parked"?d.placeholderParked(h.name):d.placeholder,className:"max-h-[140px] min-h-11 w-full resize-y rounded-[10px] border border-input bg-surface px-3 py-2.5 text-base leading-[22px] text-fg outline-none placeholder:text-muted focus:border-ring"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{type:"button",disabled:!F||!C.trim(),onClick:()=>{L("words",n.kind==="parked"?{kind:"resolve",text:C.trim()}:{kind:"words",text:C.trim()})},className:rt({variant:"primary",className:"min-w-0"}),children:[re("words")??(W?e.jsx(z,{name:"face",className:"size-[18px]"}):null),e.jsx("span",{className:"truncate",children:K})]}),e.jsx("button",{type:"button",disabled:E,onClick:()=>k(!1),className:rt({className:"min-w-0"}),children:d.cancel})]}),Y&&H<n.questions.length&&Q(d.settlesAll)]}),fe=M==="cancelled"?u.confirm.cancelled:M==="prepareFailed"?u.confirm.prepareFailed:M==="failed"?u.confirm.failed:M==="notSent"?u.decide.failed:s.kind==="refused"?s.reason==="assertion_expired"?u.confirm.expired:s.reason==="unavailable"?d.notSent(d.unreachable):u.confirm.failed:null,he=!W||n.questions.length===0&&!N&&g!=="parked"&&g!=="question"?null:l?y!==null&&y!=="seen"?Q(u.confirm.asking):e.jsxs("p",{className:"flex items-center gap-1.5 text-small text-muted",children:[e.jsx(z,{name:"face",className:"size-4"}),q?d.confirmHint:d.confirmHintDevice]}):e.jsxs(e.Fragment,{children:[Q(d.needsDevice),o&&e.jsx("a",{href:ce({name:"connection",section:"link"}),className:"self-start text-small font-medium underline underline-offset-2",children:u.enroll.link})]});return e.jsxs(Bs,{tone:g==="update"?"plain":"rig",selected:m,label:u.cards.region(u.cards.kindName.rig,h.name,n.from.rig??""),children:[e.jsxs("a",{href:_,className:"-m-1 flex min-w-0 items-center gap-[7px] rounded-md p-1 active:bg-raised",children:[e.jsx("b",{className:"font-semibold whitespace-nowrap",children:h.name}),n.from.rig&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:n.from.rig}),e.jsx("span",{className:"flex-1"}),D&&e.jsx(Lt,{tone:"urgent",children:D}),e.jsx(Lt,{tone:g==="parked"?"rig":"plain",children:d.pill[g]}),e.jsx("time",{dateTime:n.updatedAt,className:"font-mono text-small whitespace-nowrap text-muted",children:di(n.updatedAt)})]}),e.jsx("a",{href:_,className:"block text-body font-semibold [overflow-wrap:anywhere]",children:n.summary}),I&&!N&&(i?e.jsx("p",{className:"text-body whitespace-pre-wrap [overflow-wrap:anywhere] text-muted",children:I}):e.jsx("a",{href:_,className:"line-clamp-3 text-body [overflow-wrap:anywhere] text-muted",children:I})),!i&&!N&&(n.bodyTruncated||I.length>180||I.split(`
|
|
18
|
+
`).length>3)&&e.jsx("a",{href:_,className:"-mt-1 self-start text-[13px] font-medium underline-offset-2 hover:underline",children:d.readAll}),i&&(n.evidenceRef||n.detail)&&e.jsxs("dl",{className:"grid grid-cols-[74px_minmax(0,1fr)] gap-x-3 gap-y-2 text-small",children:[e.jsx("dt",{className:"text-muted",children:u.detail.asked}),e.jsx("dd",{className:"m-0",children:di(n.createdAt)}),n.evidenceRef&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-muted",children:d.source}),e.jsx("dd",{className:"m-0 font-mono [overflow-wrap:anywhere]",children:n.evidenceRef})]})]}),i&&n.detail&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-expanded":$,onClick:()=>v(w=>!w),className:"self-start text-[13px] font-medium",children:[$?"⌄":"›"," ",d.details]}),$&&e.jsx("p",{className:"text-small whitespace-pre-wrap [overflow-wrap:anywhere] text-muted",children:n.detail})]}),g==="update"?e.jsx("div",{className:"flex",children:e.jsxs("button",{type:"button",disabled:!P,onClick:()=>{L("seen",{kind:"seen"})},className:rt({size:"sm"}),children:[re("seen"),d.seen]})}):N&&!Y?ue:n.questions.length===0?N?ue:e.jsx("button",{type:"button",disabled:!F,onClick:()=>k(!0),className:rt({className:"self-start"}),children:n.kind==="parked"?d.answerParked:d.writeAnswer}):Y?e.jsxs(e.Fragment,{children:[n.questions.map((w,O)=>e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("span",{className:"text-small text-muted [overflow-wrap:anywhere]",children:[O+1,". ",w.question]}),ee(w)]},w.id)),e.jsx("span",{className:"text-small text-muted",children:d.progress(H,n.questions.length)}),N?ue:e.jsx("button",{type:"button",disabled:!F,onClick:()=>k(!0),className:"self-start text-[13px] font-medium text-muted underline-offset-2 hover:underline disabled:opacity-45",children:d.answerOther})]}):e.jsxs(e.Fragment,{children:[ee(n.questions[0]),e.jsx("button",{type:"button",disabled:!F,onClick:()=>k(!0),className:"self-start text-[13px] font-medium text-muted underline-offset-2 hover:underline disabled:opacity-45",children:d.answerOther})]}),fe&&Q(fe,!0),!fe&&he]})}function l1(t,n){var a;if(!((a=t.daemon)!=null&&a.openrig))return n.length>0;const s=t.asksChannel;return n.length>0||s!==null&&(s.partial||s.channel.state!=="ready")}function ui({state:t,machine:n}){const s=t.asksChannel;if(!s)return null;const a=u.asks.channel,r=s.channel.state==="ready"?s.partial?{title:null,body:u.asks.partial}:null:s.channel.state==="not_installed"?{title:a.not_installed.title(n),body:a.not_installed.body}:{title:a[s.channel.state].title,body:a[s.channel.state].body};return r?e.jsxs("div",{role:"status","data-channel":s.channel.state,className:"flex items-start gap-[9px] rounded-lg border border-line px-3 py-2.5 text-[13px] leading-[18px]",children:[e.jsx("span",{className:"mt-[5px]",children:e.jsx(ze,{state:"off"})}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[r.title&&e.jsx("span",{className:"font-medium",children:r.title}),r.body&&e.jsx("span",{className:"text-muted",children:r.body})]})]}):null}function bu({store:t}){var C,j,y;const n=xe(t),s=Dt(),a=Ps(),r=mn(),l=cc(n.asks??[]),o=ff(l.map(b=>({id:b.id,value:b}))),[c,i]=f.useState(!1),m=f.useRef(new Set(l.map(b=>b.id)));if(f.useEffect(()=>{l.some(b=>!m.current.has(b.id))&&i(!1),m.current=new Set(l.map(b=>b.id))},[l]),!l1(n,l))return null;const d=u.rigs,x=((C=n.daemon)==null?void 0:C.name)??"",p=!n.fresh,g=e.jsx("button",{type:"button","aria-expanded":!c,onClick:()=>i(!c),className:"text-muted",children:c?d.unfold:d.fold}),h=e.jsxs(It,{aside:g,children:[d.requests," ",e.jsx("span",{className:"text-attention",children:l.length})]});if(s)return e.jsxs("section",{"aria-label":d.requests,className:"flex flex-col gap-1.5",children:[h,!c&&e.jsxs(ds,{tone:"rigs",children:[e.jsx("div",{className:"p-2 empty:hidden",children:e.jsx(ui,{state:n,machine:x})}),l.map(b=>{const M=uc(b);return e.jsx(ol,{href:ce({name:"ask",id:b.id}),stale:p,selected:a.name==="ask"&&a.id===b.id,title:e.jsxs(e.Fragment,{children:[b.priority!=="routine"&&e.jsxs(e.Fragment,{children:[e.jsx(Lt,{tone:"urgent",children:u.asks.priority[b.priority]})," "]}),e.jsx("b",{className:"font-semibold",children:M.name}),b.from.rig?` · ${b.from.rig}`:""]}),sub:b.summary,meta:Ke(b.updatedAt),children:e.jsx("span",{className:"sr-only",children:u.asks.pill[dc(b)]})},b.id)})]})]});const N=((j=n.device)==null?void 0:j.confirm)===!0&&r,k=r&&((y=n.device)==null?void 0:y.confirm)!==!0;return e.jsxs("section",{"aria-label":d.requests,className:"flex flex-col gap-2.5",children:[h,!c&&e.jsxs(e.Fragment,{children:[e.jsx(ui,{state:n,machine:x}),o.entries.map(b=>e.jsx(gu,{store:t,ask:b.value,end:xc(b.id,n.ops),fresh:n.fresh,ghost:b.ghost,canConfirm:N,enroll:k,onGone:()=>o.dismiss(b.id)},b.id))]})]})}function ju({label:t,children:n}){return Dt()?e.jsx("section",{"aria-label":t,className:"pt-[34px]",children:n}):e.jsx(ds,{label:t,children:n})}function o1(){const{pc:t}=zt();return e.jsxs(hs,{title:u.prs.title,subtitle:u.prs.subtitle,children:[e.jsx(ju,{label:u.prs.title,children:e.jsx(Rn,{glyph:e.jsx(z,{name:"pr",className:"size-[22px]"}),title:u.prs.notSent(Jt(t)),body:u.prs.notSentBody})}),e.jsx("p",{className:"text-small text-muted",children:u.prs.tracked})]})}function i1({store:t}){const{pc:n}=zt();return e.jsxs(hs,{title:u.rigs.title,subtitle:u.rigs.subtitle,children:[e.jsx(bu,{store:t}),e.jsx(ju,{label:u.rigs.title,children:e.jsx(Rn,{glyph:e.jsx(z,{name:"rigs",className:"size-[22px]"}),title:u.rigs.notSent(Jt(n)),body:u.rigs.notSentBody})})]})}function xi({icon:t,title:n,body:s}){return e.jsxs("div",{"data-split-empty":"",className:"flex flex-1 flex-col items-center justify-center gap-1 text-center text-muted",children:[e.jsx(z,{name:t,className:"size-[18px]"}),e.jsx("h2",{className:"mt-2.5 text-[17px] font-semibold text-fg",children:n}),e.jsx("p",{className:"max-w-[320px] text-small",children:s})]})}function mi({store:t,id:n,onDone:s}){var p,g,h;const a=xe(t),r=mn(),l=(p=a.asks)==null?void 0:p.find(N=>N.id===n),o=f.useRef(void 0);l&&(o.current=l);const c=l??o.current,i=s??(()=>Aa({name:"rigs"})),m=((g=a.device)==null?void 0:g.confirm)===!0&&r,d=r&&((h=a.device)==null?void 0:h.confirm)!==!0,x=c?e.jsx(gu,{store:t,ask:c,end:xc(n,a.ops),fresh:a.fresh,ghost:!l,canConfirm:m,enroll:d,onGone:i,full:!0}):a.asks===null||!a.fresh?e.jsx("p",{role:"status",className:"text-body text-muted",children:u.loading}):e.jsx(at,{tone:"gone",title:u.asks.already});return e.jsxs(e.Fragment,{children:[e.jsx(Hs,{title:u.cards.kindName.rig,fallback:{name:"rigs"},label:u.detail.back,link:fs(a)}),e.jsx("main",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain pt-4 pb-[22px]",children:x})]})}const na=u.storage;function c1({onRetry:t,onReload:n}){return e.jsxs(Mt,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:Ht,children:na.title}),e.jsx("p",{className:"text-muted",children:na.body})]}),e.jsx(Et,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:t,className:Nt,children:na.retry}),e.jsx("button",{type:"button",onClick:n,className:dt,children:na.reload})]})]})}const d1=30,u1=/^(?:\x1b\[\??\d+(?:;\d+)*[Rc]|\x1b\[[?>][\d;]*c|\x1b\][0-9]+;rgb:[0-9a-f/]+(?:\x07|\x1b\\)|\x1b\[[IO])$/i,x1={phase:"connecting",cols:80,rows:24,readOnly:!1,held:null,holding:!1,released:null,exit:null,refused:null,holdRefused:null};function m1(t){if(t.length<=Xl)return t;let n=Xl;const s=t.charCodeAt(n-1);return s>=55296&&s<=56319&&(n-=1),t.slice(0,n)}function p1(t,n){return`\x1B[H\x1B[2J\x1B[3J${t.replace(/\n/g,`\r
|
|
19
|
+
`)}\x1B[${n.y+1};${n.x+1}H`}class f1{constructor(n,s,a,r=()=>crypto.randomUUID()){Bt(this,"view",x1);Bt(this,"listeners",new Set);Bt(this,"tid",null);Bt(this,"openOp",null);Bt(this,"holdOp",null);Bt(this,"seq",0);Bt(this,"resyncing",!1);Bt(this,"n",0);Bt(this,"pending","");Bt(this,"timer",null);Bt(this,"wasReady",!1);Bt(this,"offs",[]);Bt(this,"stopped",!1);this.wire=n,this.sessionId=s,this.screen=a,this.uuid=r}get state(){return this.view}subscribe(n){return this.listeners.add(n),()=>{this.listeners.delete(n)}}start(){this.offs.push(this.wire.onMessage(n=>this.onMessage(n))),this.offs.push(this.wire.subscribe(()=>this.onLink())),this.wasReady=this.wire.ready(),this.wasReady?this.open():this.set({phase:"offline"})}stop(){var n;if(!this.stopped){this.stopped=!0,this.flushKeys(),this.tid&&this.wire.ready()&&this.wire.send({type:"term.close",tid:this.tid});for(const s of this.offs.splice(0))s();this.timer&&clearTimeout(this.timer),(n=this.holdOp)==null||n.done("invalid"),this.holdOp=null}}hold(n){var r;if(!this.tid||this.view.phase!=="live"||this.view.readOnly||!this.wire.ready())return Promise.resolve("invalid");(r=this.holdOp)==null||r.done("invalid");const s=this.uuid(),a=this.tid;return new Promise(l=>{this.holdOp={op:s,done:o=>{this.holdOp=null,this.set({holding:!1,holdRefused:o}),l(o)}},this.set({holding:!0,holdRefused:null,released:null}),this.wire.send({type:"term.hold",op:s,tid:a,assertion:n})})}release(){!this.tid||!this.view.held||(this.flushKeys(),this.wire.send({type:"term.release",tid:this.tid}))}type(n){!this.view.held||!this.tid||u1.test(n)||(this.pending+=n,this.set({held:{...this.view.held,lastKey:Date.now()}}),this.timer===null&&(this.timer=setTimeout(()=>{this.timer=null,this.flushKeys()},d1)))}flushKeys(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),!this.tid||!this.pending||!this.wire.ready()){this.pending="";return}for(;this.pending;){const n=m1(this.pending);this.pending=this.pending.slice(n.length),this.wire.send({type:"term.input",tid:this.tid,n:this.n++,data:n})}}open(){this.openOp=this.uuid(),this.tid=null,this.n=0,this.resyncing=!1,this.set({phase:"connecting",held:null,holding:!1,exit:null,refused:null}),this.wire.send({type:"term.open",op:this.openOp,id:this.sessionId})}onLink(){var s;const n=this.wire.ready();if(!(n===this.wasReady||this.stopped)){if(this.wasReady=n,!n){this.pending="",(s=this.holdOp)==null||s.done("invalid"),this.tid=null,this.view.phase!=="ended"&&this.view.phase!=="refused"&&this.set({phase:"offline",held:null,released:this.view.held?"link":this.view.released});return}this.view.phase==="offline"&&this.open()}}onMessage(n){if(!this.stopped)switch(n.type){case"term.opened":{if(!(n.op!==void 0?n.op===this.openOp:n.tid===this.tid))return;this.tid=n.tid,this.seq=n.seq,this.resyncing=!1,this.screen.reset(n.cols,n.rows),this.screen.write(p1(n.screen,n.cursor)),this.set({phase:"live",cols:n.cols,rows:n.rows,readOnly:n.readOnly===!0});return}case"term.output":if(n.tid!==this.tid||this.resyncing)return;if(n.seq!==this.seq){this.resyncing=!0,this.wire.send({type:"term.resync",tid:n.tid});return}this.seq++,this.screen.write(n.data);return;case"term.size":if(n.tid!==this.tid)return;this.screen.resize(n.cols,n.rows),this.set({cols:n.cols,rows:n.rows});return;case"term.held":if(n.tid!==this.tid)return;this.set({held:{until:Date.parse(n.until),lastKey:Date.now()},released:null});return;case"term.released":if(n.tid!==this.tid)return;this.pending="",this.set({held:null,released:n.why==="asked"?null:n.why});return;case"term.exit":if(n.tid!==this.tid)return;this.tid=null,this.set({phase:"ended",held:null,exit:n.why});return;case"operation.result":if(n.op===this.openOp&&n.status==="rejected"){this.openOp=null,this.set({phase:"refused",refused:n.reason??"invalid"});return}if(n.op===this.openOp&&n.status==="failed"){this.openOp=null,this.set({phase:"refused",refused:"unavailable"});return}this.holdOp&&n.op===this.holdOp.op&&n.status!=="received"&&this.holdOp.done(n.status==="applied"?null:n.reason??"invalid");return;default:return}}set(n){this.view={...this.view,...n};for(const s of[...this.listeners])s()}}const h1=11,EN=6,_N=16,pi=5*6e4,g1={up:"A",down:"B",right:"C",left:"D"};function b1(t,n){switch(t){case"esc":return"\x1B";case"tab":return" ";case"enter":return"\r";case"interrupt":return"";default:return`${n?"\x1BO":"\x1B["}${g1[t]}`}}function j1(t,n){let s=t;if(n.ctrl&&[...t].length===1){const a=t.toUpperCase().charCodeAt(0);a>=64&&a<=95?s=String.fromCharCode(a-64):t===" "?s="\0":t==="?"&&(s="")}return n.alt?`\x1B${s}`:s}function y1(t){const n=t.findIndex(a=>/❯\s*1\.\s/.test(a));if(n<0)return[];const s=[];for(const a of t.slice(n,n+12)){const r=/^\s*(?:❯\s*)?(\d)\.\s+(.*)$/.exec(a);if(!r)continue;if(r[1]!==String(s.length+1))break;const l=r[2].trim(),o=/^(oui,?\s+toujours|yes,?\s+and\s+don.t\s+ask)/i.test(l)?"always":/^(oui|yes)\b/i.test(l)?"yes":/^(non|no)\b/i.test(l)?"no":null;s.push({digit:r[1],word:o})}return s}const Re=u.terminal.live2,yu="ledge.mobile.terminalView",N1=t=>{var n;try{return((n=Ze(t))==null?void 0:n.getItem(yu))==="fit"?"fit":"readable"}catch{return"readable"}},k1=(t,n)=>{var s;try{(s=Ze(n))==null||s.setItem(yu,t)}catch{}};function v1(t){return{send:n=>{t.send(n).catch(()=>{})},onMessage:n=>t.onMessage(n),ready:()=>t.state()==="ready",subscribe:n=>t.subscribe(n)}}const jr=new Map,w1=t=>{const n=Math.max(0,Math.ceil(t/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,"0")}`},S1=t=>Nx(()=>import("./xterm-DbcwqIBy.js"),__vite__mapDeps([0,1,2,3,4])).then(n=>n.createXterm(t));function C1({store:t,link:n,session:s,storage:a,makeScreen:r,forge:l}){var xt,kt,ct,mt;const o=xe(t),c=Kt(),i=f.useRef(null),m=f.useRef(null),[d,x]=f.useState(null),[p,g]=f.useState(null),[h,N]=f.useState(()=>N1(a)),[k,C]=f.useState(!1),[j,y]=f.useState({ctrl:"off",alt:"off"}),[b,M]=f.useState(!1),[S,$]=f.useState(""),[v,A]=f.useState(!1),[R,_]=f.useState(null),[L,T]=f.useState([]),[B,E]=f.useState(!1),P=Dt(),W=Pa(),F=f.useRef(!0),re=f.useRef(j);re.current=j,f.useEffect(()=>{const G=i.current;if(!G)return;let _e=!1,we=null;const le=ge=>{if(_e){ge.dispose();return}const qe=new f1(v1(n),s.id,ge);ge.onData(et=>qe.type(Y(et))),qe.start(),we={c:qe,xt:ge},x(qe),g(ge)};return r?le(r(G)):S1(G).then(le),()=>{_e=!0,we==null||we.c.stop(),we==null||we.xt.dispose()}},[n,s.id,r]);const Y=G=>{const _e=re.current;if(_e.ctrl==="off"&&_e.alt==="off")return G;const we=j1(G,{ctrl:_e.ctrl!=="off",alt:_e.alt!=="off"});return y(le=>({ctrl:le.ctrl==="armed"?"off":le.ctrl,alt:le.alt==="armed"?"off":le.alt})),we},H=f.useSyncExternalStore(G=>d?d.subscribe(G):()=>{},()=>(d==null?void 0:d.state)??null),I=!!(H!=null&&H.held);f.useEffect(()=>{p==null||p.setInput(I),I&&(F.current=!0,p==null||p.focus())},[p,I]),f.useEffect(()=>{!p||!m.current||!H||p.setFont(h==="fit"?p.fitFont(m.current.clientWidth-16):h1)},[p,h,H==null?void 0:H.cols]),f.useEffect(()=>{if(!p)return;const G=m.current,_e=()=>{if(!G)return;const we=jr.get(s.id);if(we&&G.scrollWidth>=we.left+G.clientWidth&&G.scrollHeight>=we.top+G.clientHeight&&(jr.delete(s.id),G.scrollLeft=we.left,G.scrollTop=we.top,F.current=!1),F.current&&h==="readable"){const{x:ge,cellWidth:qe}=p.cursor(),et=ge*qe;(et<G.scrollLeft||et>G.scrollLeft+G.clientWidth-qe*4)&&(G.scrollLeft=Math.max(0,et-G.clientWidth/2))}_(G.scrollWidth>G.clientWidth+1?{left:G.scrollLeft/G.scrollWidth,width:G.clientWidth/G.scrollWidth}:null);const le=y1(p.rows());T(ge=>ge.length===le.length&&ge.every((qe,et)=>qe.digit===le[et].digit&&qe.word===le[et].word)?ge:le)};p.onDrawn(_e),_e()},[p,h]);const D=()=>{const G=m.current;G&&jr.set(s.id,{left:G.scrollLeft,top:G.scrollTop})},Q=()=>{const G=m.current;G&&_(G.scrollWidth>G.clientWidth+1?{left:G.scrollLeft/G.scrollWidth,width:G.clientWidth/G.scrollWidth}:null)},q=f.useRef(null),K=G=>Math.hypot(G[0].clientX-G[1].clientX,G[0].clientY-G[1].clientY),ee=G=>{G.touches.length===2&&p?q.current={d:K(G.touches),px:p.font()}:F.current=!1},ue=G=>{if(G.touches.length!==2||!q.current||!p||!m.current)return;const _e=p.fitFont(m.current.clientWidth-16);p.setFont(Math.max(_e,q.current.px*(K(G.touches)/q.current.d)))},fe=()=>{q.current=null},he=G=>{N(G),k1(G,a),F.current=!0},w=G=>{var _e,we;if(!(!d||!p)){if(F.current=!0,G==="ctrl"||G==="alt"){y(le=>({...le,[G]:le[G]==="off"?"armed":le[G]==="armed"?"locked":"off"}));return}if(G==="line"){M(le=>!le);return}if(G==="paste"){A(!1),(we=(_e=navigator.clipboard)==null?void 0:_e.readText)==null||we.call(_e).then(le=>{le?p.paste(le):A(!0)},()=>A(!0));return}d.type(Y(b1(G,p.appCursor())))}},O=()=>{!d||!S||(d.type(`${S.replace(/\r?\n/g,"\r")}\r`),$(""))},V=!!s.pending||s.state==="waiting_permission"||s.state==="waiting_input",Z=((xt=s.pending)==null?void 0:xt.kind)==="permission"||s.state==="waiting_permission",X={name:"thread",sessionId:s.id},J=(H==null?void 0:H.phase)??"connecting",pe=J==="ended",Ne=J==="offline",Xe=!!((kt=o.daemon)!=null&&kt.terminalInput)&&!(H!=null&&H.readOnly)&&s.readOnly!==!0,gt=I?Re.status.held:Re.status[J],Be=H!=null&&H.released&&H.released!=="asked"?Re.released[H.released]:null,Je=(H==null?void 0:H.exit)==="gone"?Re.exit.gone(s.name):H!=null&&H.exit?Re.exit[H.exit]:null,oe=H!=null&&H.refused?Re.refused[H.refused]??Re.refused.unavailable:null,de=H!=null&&H.holdRefused?Re.holdRefused[H.holdRefused]??u.confirm.refused[H.holdRefused]??null:null,ke=H!=null&&H.held?Math.min(pi,Math.min(H.held.lastKey+pi,H.held.until)-c):0,Oe=I&&ke<=6e4,lt=Z?L:[];return e.jsxs(e.Fragment,{children:[e.jsx(eu,{store:t,session:s,current:"terminal",onLeave:D,model:B,onModel:E,display:J==="live"||Ne?{value:h==="readable"?Re.readable:Re.fit,onToggle:()=>he(h==="readable"?"fit":"readable")}:void 0}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col pt-2",children:[e.jsxs("div",{className:`flex h-9 flex-none items-center gap-2 rounded-t-card bg-term-bg px-3 text-[12px] text-term-fg ${I?"border-2 border-b-0 border-info":"border border-b-0 border-line"}`,children:[!Oe&&e.jsx("span",{className:"min-w-0 truncate font-mono",children:s.project}),e.jsx("span",{role:"status",className:`flex-none rounded-[6px] px-2 py-0.5 font-medium ${I?"bg-info text-white":Ne?"text-attention":J==="live"?"text-ok":"text-muted"}`,children:Oe?Re.heldLeft(w1(ke)):gt}),e.jsx("span",{className:"flex-1"}),I?e.jsx("button",{type:"button",onClick:()=>d==null?void 0:d.release(),className:"flex-none underline",children:Re.release}):H&&!pe&&J!=="refused"&&e.jsxs("span",{className:"flex-none font-mono",children:[H.cols," × ",H.rows]})]}),e.jsx("div",{ref:m,onScroll:Q,onTouchStart:ee,onTouchMove:ue,onTouchEnd:fe,"aria-label":Re.screen(s.name),className:`relative min-h-0 flex-1 overflow-auto rounded-b-card bg-term-bg p-2 ${I?"border-2 border-t-0 border-info":"border border-t-0 border-line"} ${Ne||pe?"opacity-45":""}`,children:e.jsx("div",{ref:i,"data-term":"",className:"w-max"})}),R&&!I&&h==="readable"&&e.jsx("div",{"aria-label":Re.position,role:"img",className:"relative mt-2 h-1 flex-none rounded-full bg-raised",children:e.jsx("span",{className:"absolute inset-y-0 rounded-full bg-muted",style:{left:`${R.left*100}%`,width:`${R.width*100}%`}})})]}),I?e.jsxs("footer",{className:"flex flex-none flex-col gap-1 pt-2 pb-[max(8px,var(--foot-inset))]",children:[v&&e.jsx("p",{role:"alert",className:"text-meta text-attention",children:Re.pasteFailed}),e.jsxs("div",{role:"toolbar","aria-label":Re.keys,className:"flex gap-1.5 overflow-x-auto py-1.5",children:[lt.map(G=>e.jsx("button",{type:"button",onPointerDown:_e=>_e.preventDefault(),onClick:()=>{F.current=!0,d==null||d.type(G.digit)},className:"inline-grid h-10 min-w-10 flex-none place-items-center rounded-control border border-attention/50 bg-attention/10 px-2.5 font-mono text-[13px] font-medium text-attention",children:G.word?`${G.digit} ${Re.contextKeys[G.word]}`:G.digit},G.digit)),(P?["interrupt","paste"]:b?["esc","tab","up","down","line"]:["esc","tab","ctrl","alt","left","up","down","right","enter","interrupt","paste","line"]).map(G=>{const _e=G==="ctrl"||G==="alt"?j[G]!=="off":G==="line"?b:!1,we=G==="ctrl"||G==="alt"||G==="line"?_e:void 0,le=(G==="ctrl"||G==="alt")&&j[G]!=="off"?`, ${j[G]==="locked"?Re.locked:Re.armed}`:"";return e.jsx("button",{type:"button","aria-pressed":we,"aria-label":`${Re.keyLabel[G]}${le}`,onPointerDown:ge=>ge.preventDefault(),onClick:()=>w(G),className:`inline-grid h-10 min-w-10 flex-none place-items-center rounded-control border px-2.5 font-mono text-[13px] font-medium ${_e?"border-transparent bg-fg text-bg":"border-input bg-surface text-fg"}`,children:Re.key[G]},G)}),P&&e.jsx("span",{className:"ml-auto flex-none self-center pl-2 text-[12px] text-muted",children:Re.hardware})]}),b&&!P&&e.jsxs("form",{className:"flex items-center gap-2",onSubmit:G=>{G.preventDefault(),O()},children:[e.jsx("span",{"aria-hidden":"true",className:"font-mono text-muted",children:"$"}),e.jsx("input",{id:"term-line",value:S,onChange:G=>$(G.target.value),"aria-label":Re.lineField,placeholder:Re.lineField,autoCapitalize:"off",enterKeyHint:"send",className:"min-h-11 min-w-0 flex-1 rounded-control border border-input bg-transparent px-3 font-mono text-body"}),e.jsx("button",{type:"submit",disabled:!S,"aria-label":Re.lineSend,className:We({variant:"primary",size:"sm"}),children:Re.lineGo})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("footer",{className:"flex flex-none flex-col gap-2 pt-2.5 pb-2.5",children:[(Be||Je||oe||de)&&e.jsx("p",{role:"status",className:"text-center text-small text-muted",children:oe??Je??de??Be}),pe?e.jsx("a",{href:ce(X),className:We({block:!0}),children:Re.back}):Xe&&J!=="refused"?e.jsxs("div",{className:"flex items-center gap-3",children:[V&&e.jsx("span",{className:"min-w-0 flex-1 text-small text-muted",children:Re.alsoInThread}),e.jsxs("button",{type:"button",disabled:J!=="live"||(H==null?void 0:H.holding),onClick:()=>C(!0),className:We({size:"sm",className:V?"flex-none":"ml-auto flex-none"}),children:[e.jsx(z,{name:"keyboard"}),H!=null&&H.released?Re.holdAgain:Re.hold]})]}):!Ne&&((ct=o.daemon)==null?void 0:ct.terminal)&&!(H!=null&&H.readOnly)&&s.readOnly!==!0&&e.jsx("p",{className:"text-center text-meta text-muted",children:Re.inputOff}),Ne&&e.jsx("p",{className:"text-center text-meta text-muted",children:Re.offlineHint})]}),e.jsx(Od,{store:t,forge:l,session:s,wide:W,threshold:((mt=o.device)==null?void 0:mt.contextNear)??Ta,onModel:()=>E(!0)})]}),k&&d&&e.jsx($1,{store:t,session:s,onClose:()=>C(!1),hold:G=>(C(!1),d.hold(G),"sent")})]})}function $1({store:t,session:n,onClose:s,hold:a}){const{fresh:r,device:l}=xe(t),o=!!(l!=null&&l.confirm),c=pd(t,"terminal",n.id,r&&o,a),i=d=>We({variant:d,block:!0}),m=c.asking?u.confirm.asking:c.challenge?Pt()?`${Re.go}`:Re.go:u.confirm.preparing;return e.jsxs(ht,{labelledBy:"hold-title",onClose:s,children:[e.jsx("h2",{id:"hold-title",className:"text-heading leading-[1.3] tracking-[-.5px]",children:Re.sheetTitle(n.name)}),o?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:Re.sheetBody}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:Re.sheetNote}),c.problem&&e.jsx(De,{title:u.confirm[c.problem],tone:"warning",role:"alert"}),c.needsNew?e.jsx("button",{type:"button",onClick:c.retry,className:i("primary"),children:u.confirm.retry}):e.jsxs("button",{type:"button",disabled:c.asking||!c.challenge,onClick:()=>{c.go()},className:i("primary"),children:[e.jsx(z,{name:"passkey"}),m]})]}):e.jsxs(e.Fragment,{children:[e.jsx(De,{title:Re.unprotectedTitle,tone:"warning",role:"status",children:e.jsx("p",{children:Re.unprotectedBody})}),e.jsx("a",{href:ce({name:"connection"}),className:i("primary"),children:Re.openConnection})]}),e.jsx("button",{type:"button",onClick:s,className:i(),children:Re.cancel})]})}const Nu="ledge.mobile.terminalSize",ku=11,vu=20,fi=12,M1=1e4,wu=t=>Math.max(ku,Math.min(vu,t));function E1(t){var n;try{const s=Number((n=Ze(t))==null?void 0:n.getItem(Nu));return Number.isFinite(s)&&s>0?wu(Math.round(s)):fi}catch{return fi}}function _1(t,n){var s;try{(s=Ze(n))==null||s.setItem(Nu,String(t))}catch{}}const hi=Ot({variant:"outline",className:"text-body font-medium"});function gi({store:t,link:n,sessionId:s,storage:a,forge:r}){var c;const l=xe(t),o=l.sessions.get(s);return n&&o&&((c=l.daemon)!=null&&c.terminal)?e.jsx(C1,{store:t,link:n,session:o,forge:r,...a?{storage:a}:{}},s):e.jsx(R1,{store:t,sessionId:s,...a?{storage:a}:{}})}function R1({store:t,sessionId:n,storage:s}){const a=xe(t),r=Kt(),{fresh:l,ops:o}=a,c=a.sessions.get(n),i=a.previews.get(n)??[],[m,d]=f.useState(()=>E1(s)),x=T=>d(B=>{const E=wu(B+T);return _1(E,s),E}),[p,g]=f.useState(!1);f.useEffect(()=>()=>t.watch(null),[t,n]),f.useEffect(()=>{l&&t.watch(n)},[t,n,l]);const h=f.useRef(null);f.useEffect(()=>{const T=h.current;T&&(T.scrollTop=T.scrollHeight)},[i.length,i[i.length-1],m]);const N={name:"thread",sessionId:n},k=fs(a);if(!c)return e.jsxs(e.Fragment,{children:[e.jsx(Hs,{title:u.thread.title,fallback:N,label:u.terminal.back,link:k}),e.jsx("main",{className:"min-h-0 flex-1 pt-7 text-body text-muted",role:"status",children:!l&&a.syncedAt===null?u.thread.loading:u.terminal.unknown})]});const C=!!c.pending||c.state==="waiting_permission"||c.state==="waiting_input",j=!l,y=j?u.terminal.offline:C?u.terminal.waiting:u.terminal.live,b=Object.values(o).filter(T=>T.message.type==="session.interrupt"&&T.message.id===n).sort((T,B)=>T.at.localeCompare(B.at)).at(-1),M=b!==void 0&&yn(b.phase),S=c.state==="working",$=(b==null?void 0:b.phase)==="applied"&&(!S||r-Date.parse(b.at)<M1),v=S&&!j&&!C&&!M&&!$,A=j?u.terminal.why.offline:C?u.terminal.why.waiting:S?null:u.terminal.why.idle,R=()=>{v&&g(!t.interrupt(n))},_=(b==null?void 0:b.phase)==="sending"?u.terminal.sending:$?u.terminal.sent:u.terminal.interrupt(c.name),L=(b==null?void 0:b.phase)==="rejected"&&b.reason==="read_only"?u.terminal.readOnly:p||(b==null?void 0:b.phase)==="rejected"||(b==null?void 0:b.phase)==="failed"?u.terminal.fail:(b==null?void 0:b.phase)==="uncertain"&&!j?u.terminal.uncertain:null;return e.jsxs(e.Fragment,{children:[e.jsx(eu,{store:t,session:c,current:"terminal"}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"mt-2 mb-4 flex items-center justify-between gap-2",children:[e.jsx("span",{role:"status",className:"text-small text-muted",children:y}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",disabled:m<=ku,onClick:()=>x(-1),"aria-label":u.terminal.smaller,className:hi,children:"A−"}),e.jsx("button",{type:"button",disabled:m>=vu,onClick:()=>x(1),"aria-label":u.terminal.larger,className:hi,children:"A+"})]})]}),e.jsx("div",{ref:h,tabIndex:0,"aria-label":u.terminal.output,className:"mb-3 min-h-0 flex-1 overflow-auto rounded-card border border-line bg-term-bg p-4",children:i.length===0?e.jsx("p",{className:"text-small text-muted",children:u.terminal.empty}):e.jsx("pre",{"data-size":m,style:{fontSize:m},className:"m-0 w-max min-w-full font-mono leading-[1.5] whitespace-pre text-term-fg",children:i.join(`
|
|
20
|
+
`)})})]}),e.jsxs("footer",{className:"flex flex-none flex-col gap-2.5 border-t border-line bg-bg pt-3 pb-[max(16px,env(safe-area-inset-bottom))] [@media(max-height:650px)]:pb-2.5",children:[e.jsx("p",{className:"text-center text-meta text-muted",children:u.terminal.scrollHint}),L&&e.jsx("p",{role:"alert",className:"text-center text-small text-attention",children:L}),e.jsxs("button",{type:"button",disabled:!v,onClick:R,className:We({block:!0}),children:[e.jsx(z,{name:"stop"}),_]}),A&&!M&&!$&&e.jsx("p",{className:"text-center text-meta text-muted",children:A}),e.jsx("p",{className:"text-center text-meta text-muted",children:u.terminal.note})]})]})}const ws=u.unrecognized;function T1({pcName:t,onRelink:n,onSignOut:s}){return e.jsxs(Mt,{children:[e.jsxs("div",{className:"flex flex-col gap-3.5",children:[e.jsx("span",{"aria-hidden":"true",className:"inline-flex size-12 items-center justify-center rounded-full bg-danger-bg text-danger-fg",children:e.jsxs("svg",{className:pa,viewBox:"0 0 24 24",children:[e.jsx("rect",{x:"5",y:"2",width:"14",height:"20",rx:"2"}),e.jsx("path",{d:"m9.5 9.5 5 5"}),e.jsx("path",{d:"m14.5 9.5-5 5"})]})}),e.jsx("h1",{className:Ht,children:ws.title(t)}),e.jsx("p",{className:"text-muted",children:ws.body})]}),e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:ws.kept}),e.jsx(Et,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:n,className:Nt,children:ws.relink}),e.jsx("button",{type:"button",onClick:s,className:dt,children:ws.signOut})]})]})}const Mn=u.update,A1=t=>`https://github.com/kl-ledge/ledge/releases/tag/v${t}`;function I1({next:t,current:n,onLater:s,onApply:a}){return e.jsxs(ht,{labelledBy:"update-title",onClose:s,children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("h2",{id:"update-title",className:"text-heading leading-[26px] font-semibold tracking-[-.02em]",children:Mn.version(t.version)}),e.jsx("p",{className:"text-muted",children:Mn.body})]}),e.jsxs("div",{className:"flex flex-col gap-2 rounded-control border border-line bg-bg p-3.5",children:[e.jsx("span",{className:"text-small leading-4 text-muted",children:Mn.fingerprint}),e.jsx("code",{className:"font-mono text-base leading-[22px] tracking-[.02em] [word-spacing:4px]",children:ou(t.fingerprint)}),e.jsxs("span",{className:"text-small leading-4 text-muted",children:[Mn.current,e.jsx("span",{className:"font-mono",children:n?Mn.currentBuild(n.version,gj(n.fingerprint)):u.connection.none})]})]}),e.jsxs("a",{href:A1(t.version),target:"_blank",rel:"noreferrer",className:"inline-flex min-h-11 items-center gap-2 font-medium",children:[e.jsx(z,{name:"external",className:"size-4",stroke:1.5}),Mn.compare(`v${t.version}`)]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2.5",children:[e.jsx(Pe,{size:"lg",onClick:s,children:Mn.later}),e.jsx(Pe,{size:"lg",variant:"primary",onClick:a,children:Mn.apply})]})]})}const Yr="ledge.mobile.rigs",L1=35e3,O1=()=>crypto.randomUUID(),bi=()=>crypto.randomUUID(),sa=t=>t!=="checking"&&t!=="sending"&&t!=="received",D1=new Set(["assertion_invalid","assertion_expired","confirm_required","conflict"]);function F1(t){var n;try{const s=(n=Ze(t))==null?void 0:n.getItem(Yr);if(!s)return null;const a=JSON.parse(s),r=kx.safeParse(a.state);return r.success&&typeof a.at=="string"?{state:r.data,at:a.at}:null}catch{return null}}function P1(t,n,s){var he;const a=F1(s);let r={state:(a==null?void 0:a.state)??null,error:null,at:(a==null?void 0:a.at)??null,loading:!1,graphs:{},queues:{},permissions:{},snapshots:{},routing:null,goals:null,runs:[]};const l=new Set,o=w=>{r={...r,...w};for(const O of[...l])O()};let c=!1,i=!1,m=!1,d=!1,x=!1;const p=new Map,g=new Map,h=new Map;let N=n.getState().daemon?((he=n.getState().daemon)==null?void 0:he.boot)??null:void 0;const k=new Set,C=()=>!c&&t.state()==="ready",j=()=>{var w;return!!((w=n.getState().daemon)!=null&&w.rigs)},y=w=>{t.send(w).catch(()=>{})};function b(w,O,V){return!C()||!j()?!1:(y(O),clearTimeout(p.get(w)),p.set(w,setTimeout(()=>{p.delete(w),V()},L1)),!0)}const M=w=>{clearTimeout(p.get(w)),p.delete(w)},S=w=>({...w??{},loading:!0}),$=w=>({...w??{},loading:!1,error:"unavailable"});function v(){d||b("state",{type:"rigs.state"},()=>{d=!1,o({loading:!1,error:"unavailable"})})&&(d=!0,o({loading:!0}))}function A(){x||b("goals",{type:"rigs.goals"},()=>{x=!1,o({goals:$(r.goals??void 0)})})&&(x=!0,o({goals:S(r.goals??void 0)}))}const R=()=>{i&&v(),m&&A()};function _(w,O){const V=r.runs.findIndex(X=>X.id===w);if(V<0)return;const Z=O(r.runs[V]);if(o({runs:r.runs.map((X,J)=>J===V?Z:X)}),sa(Z.phase)){Z.op&&Z.phase!=="uncertain"&&g.delete(Z.op);const X=h.get(w);h.delete(w),X==null||X(Z)}}const L=w=>r.runs.find(O=>O.op===w),T=w=>!!w&&(!sa(w.phase)||w.phase==="uncertain"),B=(w,O)=>{const V=L(w);M(`op:${w}`),T(V)&&_(V.id,Z=>({...Z,...O,endedAt:Date.now()}))},E=w=>{clearTimeout(p.get(`op:${w}`)),p.set(`op:${w}`,setTimeout(()=>{p.delete(`op:${w}`);const O=L(w);(O==null?void 0:O.phase)==="sending"&&_(O.id,V=>({...V,phase:"uncertain",endedAt:Date.now()}))},Ki))},P=w=>w.sentAt!==void 0&&Date.now()-w.sentAt<Wi&&N!==void 0&&(w.boot??null)===N,W=w=>{M(`op:${w.op}`),g.delete(w.op),_(w.id,O=>({...O,phase:"uncertain",lost:!0,endedAt:O.endedAt??Date.now()}))};function F(w){for(const[O,V]of[...g]){if(w.has(O))continue;const Z=L(O);if(!Z){g.delete(O);continue}if(!P(Z)){W(Z);continue}_(Z.id,X=>({...X,again:!0})),y(V),Z.phase==="sending"&&E(O)}}const re=(w,O)=>!w||!w.again||!D1.has(O??"")?!1:(w.lost||W(w),!0),Y=w=>{const O=w.kind==="seats"?w.rig:w.kind==="act"&&"rig"in w.action?w.action.rig:null;O&&(r.graphs[O]||r.queues[O])&&fe.openRig(O),O&&r.snapshots[O]&&fe.readSnapshots(O)};function H(w){var O;switch(w.type){case"snapshot":{const V=N;N=w.daemon.boot??null;const Z=new Set(k);k.clear();for(const X of Z){const J=L(X);J&&_(J.id,pe=>({...pe,boot:N}))}(V===void 0||V!==N)&&F(Z),R();return}case"rigs.state":if(M("state"),d=i,w.state){const V=new Date().toISOString();o({state:w.state,error:null,at:V,loading:!1});try{(O=Ze(s))==null||O.setItem(Yr,JSON.stringify({state:w.state,at:V}))}catch{}}else o({error:w.error??"unavailable",loading:!1});return;case"rigs.graph":M(`graph:${w.rig}`),o({graphs:{...r.graphs,[w.rig]:w.graph?{data:w.graph,loading:!1,at:new Date().toISOString()}:{...r.graphs[w.rig],loading:!1,error:w.error??"unavailable"}}});return;case"rigs.queue":M(`queue:${w.rig}`),o({queues:{...r.queues,[w.rig]:w.error?{...r.queues[w.rig],loading:!1,error:w.error}:{data:{rows:w.rows,closed:w.closed,truncated:w.truncated},loading:!1,at:new Date().toISOString()}}});return;case"rigs.permissions":M(`permissions:${w.rig}`),o({permissions:{...r.permissions,[w.rig]:w.error?{...r.permissions[w.rig],loading:!1,error:w.error}:{data:{...w.policy!==void 0?{policy:w.policy}:{},seats:w.seats},loading:!1,at:new Date().toISOString()}}});return;case"rigs.snapshots":M(`snapshots:${w.rig}`),o({snapshots:{...r.snapshots,[w.rig]:w.error?{...r.snapshots[w.rig],loading:!1,error:w.error}:{data:w.snapshots,loading:!1,at:new Date().toISOString()}}});return;case"rigs.routing":M("routing"),o({routing:w.error?{...r.routing,loading:!1,error:w.error}:{data:w.entries,loading:!1,at:new Date().toISOString()}});return;case"rigs.goals":M("goals"),x=m&&!w.error,o({goals:w.error?{...r.goals,loading:!1,error:w.error}:{data:{goals:w.goals,partial:!!w.partial},loading:!1,at:new Date().toISOString()}});return;case"operation.result":{const V=L(w.op);if(!T(V))return;if(w.status==="received"){M(`op:${w.op}`),(V.phase==="sending"||V.phase==="uncertain")&&_(V.id,Z=>{const{endedAt:X,...J}=Z;return{...J,phase:"received"}});return}if(w.status==="rejected"&&re(V,w.reason))return;w.status==="rejected"&&B(w.op,{phase:"rejected",reason:w.reason??"invalid"});return}case"rigs.done":{const V=L(w.op);if(w.rejected&&re(V,w.rejected))return;V&&(B(w.op,w.rejected?{phase:"rejected",reason:w.rejected,done:w}:{phase:"done",done:w,...w.error?{reason:w.error}:{}}),Y(V.subject));return}case"rigs.reseated":{const V=L(w.op);if(w.rejected&&re(V,w.rejected))return;V&&(B(w.op,w.rejected?{phase:"rejected",reason:w.rejected,reseated:w}:{phase:"done",reseated:w,...w.error?{reason:w.error}:{}}),Y(V.subject));return}case"rigs.goal.sent":case"rigs.goal.replied":if(w.rejected&&re(L(w.op),w.rejected))return;B(w.op,w.rejected?{phase:"rejected",reason:w.rejected,sent:w}:{phase:"done",sent:w,...w.error?{reason:w.error}:{}});return}}let I=C(),D=0;const Q=t.subscribe(()=>{const w=t.state();(w==="unpaired"||w==="pairing")&&K();const O=C();if(O&&!I)I=!0,D++,d=!1,x=!1,N=void 0,k.clear();else if(!O&&I){I=!1,d=!1,x=!1;for(const[V,Z]of p)clearTimeout(Z),p.delete(V);o({loading:!1});for(const V of r.runs)V.phase==="sending"&&V.op&&_(V.id,Z=>({...Z,phase:"uncertain",endedAt:Date.now()}))}}),q=t.onMessage(H);function K(){var w;if(!(!r.state&&!r.runs.length&&!Object.keys(r.graphs).length)){try{(w=Ze(s))==null||w.removeItem(Yr)}catch{}g.clear(),o({state:null,error:null,at:null,loading:!1,graphs:{},queues:{},permissions:{},snapshots:{},routing:null,goals:null,runs:[]})}}async function ee(w){var X;if(!((X=n.getState().device)!=null&&X.confirm))return{phase:"rejected",reason:"confirm_required"};let O;try{O=await n.prepareConfirm(w)}catch(J){return{phase:J instanceof Error&&J.message==="timeout"?"expired":"unsent"}}if(!O.credentialId)return{phase:"rejected",reason:"confirm_required"};const V=Date.now(),Z=await Fs({challenge:O.challenge,rpId:O.rpId,credentialId:O.credentialId}).catch(()=>"failed");return Z==="cancelled"?{phase:"cancelled"}:Z==="failed"?{phase:"unsent"}:Date.now()-V>=O.expiresInMs?{phase:"expired"}:{assertion:Z}}function ue(w,O,V){const Z=O1(),X={op:"",id:Z,subject:w,phase:O?"checking":"sending",startedAt:Date.now()},J=new Promise(pe=>h.set(Z,pe));return!C()||!j()?(o({runs:[...r.runs,{...X,phase:"unsent",endedAt:Date.now()}]}),h.delete(Z),Promise.resolve({...X,phase:"unsent"})):(o({runs:[...r.runs,X]}),(async()=>{var oe;let pe;if(O){const de=await ee(O);if(!("assertion"in de)){_(Z,ke=>({...ke,phase:de.phase,...de.reason?{reason:de.reason}:{},endedAt:Date.now()}));return}pe=de.assertion}const Ne=Ui(),Xe=Pi.safeParse(V(Ne,pe));if(!Xe.success||!C()){_(Z,de=>({...de,phase:"unsent",endedAt:Date.now()}));return}g.set(Ne,Xe.data),N===void 0&&k.add(Ne),_(Z,de=>({...de,op:Ne,phase:"sending",sentAt:Date.now(),...N!==void 0?{boot:N}:{}})),E(Ne);const gt=D,Be=await t.send(Xe.data).catch(()=>!1),Je=(oe=L(Ne))==null?void 0:oe.phase;!Be&>===D&&(Je==="sending"||Je==="uncertain")&&(M(`op:${Ne}`),_(Z,de=>({...de,phase:"unsent",endedAt:Date.now()})))})(),J)}const fe={getState:()=>r,subscribe(w){return l.add(w),()=>{l.delete(w)}},follow(){i=!0,v()},retry(){d=!1,v()},openRig(w){const O=`graph:${w}`,V=`queue:${w}`,Z=`permissions:${w}`;b(O,{type:"rigs.graph",rig:w},()=>o({graphs:{...r.graphs,[w]:$(r.graphs[w])}}))&&o({graphs:{...r.graphs,[w]:S(r.graphs[w])}}),b(V,{type:"rigs.queue",rig:w},()=>o({queues:{...r.queues,[w]:$(r.queues[w])}}))&&o({queues:{...r.queues,[w]:S(r.queues[w])}}),b(Z,{type:"rigs.permissions",rig:w},()=>o({permissions:{...r.permissions,[w]:$(r.permissions[w])}}))&&o({permissions:{...r.permissions,[w]:S(r.permissions[w])}})},readSnapshots(w){b(`snapshots:${w}`,{type:"rigs.snapshots",rig:w},()=>o({snapshots:{...r.snapshots,[w]:$(r.snapshots[w])}}))&&o({snapshots:{...r.snapshots,[w]:S(r.snapshots[w])}})},readPermissions(w){const O=`permissions:${w}`;b(O,{type:"rigs.permissions",rig:w},()=>o({permissions:{...r.permissions,[w]:$(r.permissions[w])}}))&&o({permissions:{...r.permissions,[w]:S(r.permissions[w])}})},readRouting(){b("routing",{type:"rigs.routing"},()=>o({routing:$(r.routing??void 0)}))&&o({routing:S(r.routing??void 0)})},followGoals(){m=!0,A()},act(w){return ue({kind:"act",action:w},tl(w)?{purpose:"rigs",rigAct:w}:null,(O,V)=>({type:"rigs.act",op:O,action:w,...V?{assertion:V}:{}}))},reseat(w,O,V={}){var J,pe;const Z=((pe=(J=r.state)==null?void 0:J.rigs.find(Ne=>Ne.name===w))==null?void 0:pe.nodes)??[],X=V.check||Fi(Z,O).remove.length>0;return ue({kind:"seats",rig:w,seats:O,...V.delegation?{delegation:V.delegation}:{}},X?{purpose:"rigs",rigSeats:{rig:w,seats:O}}:null,(Ne,Xe)=>({type:"rigs.seats",op:Ne,rig:w,seats:O,...V.delegation?{delegation:V.delegation}:{},...Xe?{assertion:Xe}:{}}))},sendGoal(w,O=bi()){return ue({kind:"goal",goalId:O,text:w},null,V=>({type:"rigs.goal.send",op:V,goalId:O,text:w}))},replyGoal(w,O,V=bi()){return ue({kind:"reply",goalId:w,replyId:V,text:O},null,Z=>({type:"rigs.goal.reply",op:Z,goalId:w,replyId:V,text:O}))},dismiss(w){const O=r.runs.find(V=>V.id===w);O&&sa(O.phase)&&O.op&&(g.delete(O.op),M(`op:${O.op}`)),o({runs:r.runs.filter(V=>V.id!==w||!sa(V.phase))})},close(){c=!0,Q(),q();for(const w of p.values())clearTimeout(w);p.clear()}};return fe}function js(t){return f.useSyncExternalStore(t.subscribe,t.getState,t.getState)}const yr={relaunch:!0,noKernel:!1},Su="ledge.mobile.daemonPrefs",Qr=new Set;function Cu(t){var n;try{const s=JSON.parse(((n=Ze(t))==null?void 0:n.getItem(Su))??"{}");return{relaunch:typeof s.relaunch=="boolean"?s.relaunch:yr.relaunch,noKernel:typeof s.noKernel=="boolean"?s.noKernel:yr.noKernel}}catch{return yr}}function z1(t,n){var s;try{(s=Ze(n))==null||s.setItem(Su,JSON.stringify({...Cu(n),...t}))}catch{}for(const a of[...Qr])a()}const B1=t=>(Qr.add(t),()=>{Qr.delete(t)});function Ll(t){const n=f.useSyncExternalStore(B1,()=>JSON.stringify(Cu(t)));return[JSON.parse(n),s=>z1(s,t)]}function $u(t,n){const s=n.relaunch?"last":"none";return t==="restart"?{kind:"daemon.restart",restore:s}:{kind:"daemon.start",restore:s,...n.noKernel&&!n.relaunch?{noKernel:!0}:{}}}const ye=u.rigs;function q1(t){var a;const n=t.subject;if(n.kind==="seats")return n.rig;if(n.kind!=="act")return"";const s=n.action;return s.rig??((a=s.seat)==null?void 0:a.split("@")[0])??""}const Ol=t=>t.subject.kind==="act"?t.subject.action.kind:t.subject.kind==="seats"?"seats":null;function Ss(t){const n=Ol(t);return n?ye.notDone[n]:ye.rejected.nothingSent}function H1(t){const n=Ol(t),s=ye.rejected.againVerb;return n==="seats"?s.remove:n==="rig.stop"||n==="daemon.stop"||n==="kernel.stop"?s.stop:n==="rig.restart"||n==="daemon.restart"||n==="kernel.restart"?s.restart:n==="rig.policy"||n==="rig.permissions"?s.apply:n==="seat.set"?s.save:null}function U1(t,n){const s=Pt(),a=t.phase==="expired"?"assertion_expired":t.phase==="cancelled"?"cancelled":t.phase==="unsent"?"unsent":t.reason??"unavailable",r=H1(t),l=r?ye.rejected.again(r):ye.rejected.nothingSent;switch(a){case"busy":return{mark:"warn",title:ye.busy.title(n),sub:ye.busy.body};case"confirm_required":return t.subject.kind==="seats"?{mark:"warn",title:s?ye.reseat.wouldLeave.title:ye.reseat.wouldLeave.titleDevice,sub:ye.reseat.wouldLeave.body}:{mark:"warn",title:ye.rejected.confirm_required};case"assertion_expired":return{mark:"bad",title:ye.because(Ss(t),ye.rejected.assertion_expired(s)),sub:l};case"assertion_invalid":return{mark:"bad",title:ye.because(Ss(t),ye.rejected.assertion_invalid(s)),sub:l};case"cancelled":return{mark:"bad",title:ye.because(Ss(t),ye.rejected.cancelled),sub:ye.rejected.nothingSent};case"unsent":return{mark:"bad",title:ye.because(Ss(t),ye.rejected.unsent),sub:ye.rejected.nothingSent};default:return{mark:"bad",title:ye.because(Ss(t),`${ye.notSent(n)}.`)}}}function Ca({run:t,rigs:n,pc:s,bar:a=!1}){const r=Ol(t),l=q1(t),o={onClose:()=>n.dismiss(t.id),closeLabel:ye.done.close};if(t.phase==="checking")return e.jsx(Ls,{bar:a,children:ye.running.checking});if(t.phase==="sending"||t.phase==="received"){const x=r==="seats"?ye.running.seats(l):r?ye.running[r](l):"";return e.jsx(Ls,{bar:a,children:`${x} · ${ye.running.note}`})}if(t.phase==="uncertain")return e.jsx($e,{mark:"ask",title:ye.uncertain.title,sub:ye.uncertain.body,...o});if(t.phase!=="done"){const x=U1(t,s);return e.jsx($e,{mark:x.mark,title:x.title,...x.sub?{sub:x.sub}:{},...o})}const c=Ke(t.endedAt?new Date(t.endedAt).toISOString():null);if(t.reseated){const x=t.reseated;if(x.ok){const p=x.added.length?ye.reseat.added(x.added.length,x.links):ye.reseat.removed(x.removed.length);return e.jsxs($e,{mark:"ok",title:p,...o,children:[x.linksUnsupported&&e.jsxs("small",{className:"block text-[12px] text-attention",children:[ye.reseat.noLinks.title," ",ye.reseat.noLinks.body]}),e.jsx(qn,{commands:x.commands})]})}return x.error==="busy"?e.jsx($e,{mark:"warn",title:ye.busy.title(s),sub:ye.busy.body,...o}):x.error==="rig_not_running"?e.jsx($e,{mark:"bad",title:ye.reseat.notRunning.title,sub:ye.reseat.notRunning.body,...o}):e.jsx($e,{mark:"bad",title:ye.failed(x.message??ye.errors[x.error??"failed"]??ye.errors.failed),...o,children:e.jsx(qn,{commands:x.commands})})}const i=t.done;if(!i||!r||r==="seats")return null;if(i.ok){const x=t.subject.kind==="act"&&t.subject.action.kind==="rig.stop"&&t.subject.action.snapshot;return e.jsx($e,{mark:"ok",title:ye.done[r](l),sub:[c,x?ye.done.snapshotFirst:""].filter(Boolean).join(" · "),...o,children:e.jsx(qn,{commands:i.commands})})}if(i.error==="busy")return e.jsx($e,{mark:"warn",title:ye.busy.title(s),sub:ye.busy.body,...o});const m=t.subject.kind==="act"&&"seats"in t.subject.action?t.subject.action.seats.length:0;if(i.completed!==void 0&&m)return e.jsx($e,{mark:"bad",title:ye.completed(i.completed,m),...i.message?{sub:e.jsx("span",{className:"font-mono",children:i.message})}:{},...o});const d=i.error&&i.error!=="failed"?ye.errors[i.error]:void 0;return e.jsx($e,{mark:"bad",title:d??ye.failed(ye.errors.failed),...i.message?{sub:e.jsx("span",{className:"font-mono",children:i.message})}:{},...o,children:e.jsx(qn,{commands:i.commands})})}function Dl(t,n){for(let s=t.length-1;s>=0;s--)if(n(t[s]))return t[s]}const Ya=t=>!!t&&(t.phase==="checking"||t.phase==="sending"||t.phase==="received"),je=u.rigs,W1={running:"on",stopped:"plain",stale:"bad",unknown:"plain"},Mu={ready:"on",starting:"go",stopped:"plain",skipped:"plain",absent:"plain",unknown:"plain"};function Fl({state:t,href:n}){const s=t.daemon.state==="running"&&t.daemon.startedAt?Ke(t.daemon.startedAt):null;return e.jsx(qr,{lead:e.jsx(z,{name:"cpu",className:"size-[18px] text-muted"}),name:je.daemon,chip:e.jsx(us,{tone:W1[t.daemon.state],children:je.daemonState[t.daemon.state]}),sub:je.daemonSub(t.version,s),...n?{href:n}:{}})}function Eu({disabled:t,next:n=!1}){const[s,a]=Ll();return e.jsxs(e.Fragment,{children:[e.jsx(Fo,{on:s.relaunch,label:je.relaunch,disabled:t,onChange:r=>a({relaunch:r})}),e.jsx(Fo,{on:s.noKernel,label:je.noKernel,hint:n?je.noKernelNext:je.noKernelHint,disabled:t,onChange:r=>a({noKernel:r})})]})}function $a({glyph:t,title:n,body:s,list:a=!0,children:r}){return e.jsxs("div",{"data-list-state":a?"":void 0,className:"flex flex-col items-center gap-1.5 px-4 pt-[26px] pb-[22px] text-center",children:[t&&e.jsx("div",{"aria-hidden":"true",className:"grid size-12 place-items-center rounded-[10px] border border-line text-muted",children:t}),e.jsx("h2",{className:"mt-1.5 text-[17px] leading-6 font-semibold",children:n}),e.jsx("p",{className:"max-w-[300px] text-[13.5px] text-muted",children:s}),r]})}function ji({state:t,rigs:n,store:s,pc:a}){const r=xe(s).fresh,[l]=Ll(),o=js(n),c=Dl(o.runs,i=>i.subject.kind==="act"&&i.subject.action.kind==="daemon.start");return e.jsxs(e.Fragment,{children:[t&&e.jsxs(e.Fragment,{children:[e.jsx(It,{children:je.openrig}),e.jsx(Ve,{children:e.jsx(Fl,{state:t})})]}),e.jsxs(Ve,{children:[e.jsx($a,{glyph:e.jsx(z,{name:"power"}),title:je.stopped.title,body:je.stopped.body}),e.jsx("div",{className:"border-t border-line",children:e.jsx(Eu,{disabled:!r})}),e.jsx("div",{className:"p-3",children:e.jsx("button",{type:"button",disabled:!r||Ya(c),onClick:()=>{n.act($u("start",l))},className:be({tone:"primary",className:"w-full"}),children:e.jsx(Ft,{icon:"power",children:je.stopped.start})})})]}),c&&e.jsx(Ca,{run:c,rigs:n,pc:a}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:je.stopped.note})]})}function K1(){const t="block animate-[ledge-pulse_1.6s_ease-in-out_infinite] rounded-[5px] bg-raised";return e.jsxs("div",{role:"status","data-list-state":"",className:"flex flex-col gap-3",children:[e.jsx(Ve,{children:e.jsxs("div",{"aria-hidden":"true",className:"flex flex-col gap-2.5 p-2.5",children:[e.jsx("span",{className:`${t} h-3.5 w-[60%]`}),e.jsx("span",{className:`${t} h-3 w-[40%]`})]})}),e.jsx(Ve,{children:e.jsxs("div",{"aria-hidden":"true",className:"flex flex-col gap-2.5 p-2.5",children:[e.jsx("span",{className:`${t} h-3.5 w-1/2`}),e.jsx("span",{className:`${t} h-3 w-[70%]`}),e.jsx("span",{className:`${t} h-3.5 w-[45%]`}),e.jsx("span",{className:`${t} h-3 w-[65%]`})]})}),e.jsx("span",{className:"text-[12px] text-muted",children:je.loading})]})}function V1({state:t,at:n,store:s,offline:a}){const r=xe(s),l=Ps(),o=Dt(),c=Nd(t),i=Br(t),m=i.filter(g=>Ng(xn(g))).length,d=[...r.sessions.values()],x=((c==null?void 0:c.nodes)??[]).map(_d),p=t.daemon.state==="running";return e.jsxs("div",{className:`flex flex-col gap-3 ${a?"opacity-50":""}`,children:[e.jsx(It,{aside:!a&&n?je.updatedAt(Ke(n)):void 0,children:je.openrig}),e.jsxs(Ve,{label:je.openrig,children:[e.jsx(Fl,{state:t,...a?{}:{href:ce({name:"kernel"})}}),t.kernel.state!=="absent"&&e.jsx(qr,{lead:e.jsx(ze,{state:"rig"}),name:je.kernel,selected:l.name==="kernel"&&o,chip:e.jsx(us,{tone:Mu[t.kernel.state],children:je.kernelState[t.kernel.state]}),sub:x.length?a||o?je.kernelSubShort(x):je.kernelSub(x):"",...a?{}:{href:ce({name:"kernel"})}})]}),p&&i.length===0?e.jsx(Ve,{children:e.jsx($a,{title:je.empty.title,body:je.empty.body,list:!1,children:e.jsx("a",{href:ce({name:"max"}),className:be({size:"sm",className:"mt-1.5"}),children:je.empty.talk})})}):i.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(It,{children:je.rigsHead(m)}),e.jsx(Ve,{tone:"rigs",label:je.title,children:i.map(g=>{const h=xn(g),N=vd(g.name,d,r.asks),k=h==="stopped",C=a?[k?je.seatCount(g.seats):je.seats(g.running,g.seats),!k&&n?je.at(Ke(n)):""].filter(Boolean).join(" · "):h==="stopped"?[je.seatCount(g.seats),g.snapshot?je.snapshot(g.snapshot):je.noSnapshot].join(" · "):h==="partial"?[je.seats(g.running,g.seats),je.stoppedCount(g.nodes.filter(y=>y.stopped).length||g.seats-g.running)].join(" · "):h==="starting"?je.seats(g.running,g.seats):[je.seats(g.running,g.seats),g.uptime?je.since(g.uptime):"",g.snapshot?je.snapshot(g.snapshot):""].filter(Boolean).join(" · "),j=!a&&(N.perm||N.ask)?e.jsxs(e.Fragment,{children:[N.perm>0&&e.jsx(Is,{perm:!0,children:je.attention.permission(N.perm)}),N.ask>0&&e.jsx(Is,{children:je.attention.question(N.ask)})]}):void 0;return e.jsx(qr,{lead:e.jsx(ze,{state:wd(g,N),pulse:h==="starting"&&!a}),name:g.name,dim:k,chip:e.jsx(us,{tone:Rd[h],children:je.status[h]}),sub:C,att:j,href:ce({name:"rig",rig:g.name}),selected:o&&l.name==="rig"&&l.rig===g.name},g.id)})})]}),!a&&p&&e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:je.launchNote})]})}function G1({rigs:t,store:n}){const s=js(t),{pc:a,look:r}=zt(),l=r==="offline";f.useEffect(()=>{t.follow()},[t]);const o=Jt(a),c=s.state,i=c?c.installed?!l&&_g(c)?e.jsx(ji,{state:c,rigs:t,store:n,pc:o}):e.jsxs(e.Fragment,{children:[!l&&s.error&&e.jsxs(Wt,{warn:!0,role:"alert",lead:e.jsx(z,{name:"warning",className:"mt-px size-4 text-attention"}),children:[e.jsx("b",{className:"font-semibold",children:je.unavailable.title}),s.at&&e.jsx("span",{className:"text-muted",children:je.unavailable.body(Ke(s.at))}),e.jsx("button",{type:"button",onClick:()=>t.retry(),className:be({size:"sm",className:"self-start"}),children:e.jsx(Ft,{icon:"refresh",children:je.unavailable.retry})})]}),e.jsx(V1,{state:c,at:s.at,store:n,offline:l})]}):e.jsx(Ve,{children:e.jsx($a,{title:je.notInstalled.title,body:je.notInstalled.body(o)})}):s.error==="not_installed"?e.jsx(Ve,{children:e.jsx($a,{title:je.notInstalled.title,body:je.notInstalled.body(o)})}):s.error==="daemon_stopped"?e.jsx(ji,{state:null,rigs:t,store:n,pc:o}):s.error?e.jsx("div",{"data-list-state":"",className:"flex flex-col",children:e.jsxs(Wt,{warn:!0,role:"alert",lead:e.jsx(z,{name:"warning",className:"mt-px size-4 text-attention"}),children:[e.jsx("b",{className:"font-semibold",children:je.unavailable.title}),e.jsx("button",{type:"button",onClick:()=>t.retry(),className:be({size:"sm",className:"self-start"}),children:e.jsx(Ft,{icon:"refresh",children:je.unavailable.retry})})]})}):e.jsx(K1,{});return e.jsxs(hs,{title:je.title,offlineBody:je.offlineBody,heading:!1,children:[e.jsx(bu,{store:n}),i]})}const te=u.rigs;function Ma(t,n=new Date){const s=va(t);if(!s)return{short:t,long:t};const a=s.toLocaleTimeString(ut,{hour:"2-digit",minute:"2-digit"}),r=Cl(s,n);if(r===0)return{short:a,long:te.snapshots.today(a)};if(r===1)return{short:te.snapshots.yesterday(a),long:te.snapshots.yesterday(a)};const l=s.toLocaleDateString(ut,{weekday:"short",day:"numeric",month:"short"});return{short:l,long:`${l} ${a}`}}function On({verb:t,confirm:n,disabled:s,onClick:a}){const r=Pt();return n?e.jsx("button",{type:"button",disabled:s,onClick:a,className:be({tone:"dangerfill",className:"w-full"}),children:e.jsx(Ft,{icon:r?"face":"passkey",size:"size-[18px]",children:te.withCheck(t,r)})}):e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("p",{className:"text-[12.5px] text-muted",children:te.protectFirst}),e.jsx("a",{href:ce({name:"connection"}),className:be({className:"w-full"}),children:te.openSettings})]})}const Xs=({onClose:t})=>e.jsx("button",{type:"button",onClick:t,className:be({className:"w-full"}),children:te.confirm.cancel});function aa({title:t,conseq:n,note:s,verb:a,confirm:r,live:l,onConfirm:o,onClose:c}){return e.jsxs(an,{title:t,onClose:c,children:[n&&e.jsx($l,{title:n.title,...n.body?{body:n.body}:{}}),s&&e.jsx("p",{className:"text-[12.5px] leading-[18px] text-muted",children:s}),e.jsx(On,{verb:a,confirm:r,disabled:!l,onClick:()=>{c(),o()}}),e.jsx(Xs,{onClose:c})]})}function Hn({icon:t,label:n,aside:s,onClick:a,disabled:r=!1,danger:l=!1}){return e.jsxs("button",{type:"button",role:"menuitem",disabled:r,onClick:a,className:`flex min-h-12 items-center gap-3 border-b border-line px-3.5 text-left text-[15px] last:border-b-0 disabled:opacity-45 ${l?"text-approval":""}`,children:[e.jsx(z,{name:t,className:`size-[18px] ${l?"":"text-muted"}`}),e.jsx("span",{className:"min-w-0 flex-1",children:n}),s&&e.jsx("span",{className:"text-[13px] text-muted",children:s})]})}function X1({rig:t,live:n,running:s,snapshots:a,level:r,onSnapshot:l,onSnapshots:o,onPermissions:c,onRefresh:i,onClose:m}){return e.jsx(an,{title:t,onClose:m,children:e.jsxs("div",{role:"menu","aria-label":te.more,className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:[e.jsx(Hn,{icon:"camera",label:te.actions.snapshot,disabled:!n||s,onClick:l}),e.jsx(Hn,{icon:"list",label:te.actions.snapshots,...a!==null?{aside:String(a)}:{},onClick:o}),e.jsx(Hn,{icon:"shield",label:te.actions.permissions,...r?{aside:r}:{},onClick:c}),e.jsx(Hn,{icon:"refresh",label:te.actions.refresh,disabled:!n,onClick:i})]})})}function Y1({live:t,up:n,onRefresh:s,onRestart:a,onStop:r,onClose:l}){return e.jsx(an,{title:te.kernel,onClose:l,children:e.jsxs("div",{role:"menu","aria-label":te.more,className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:[e.jsx(Hn,{icon:"refresh",label:te.kernelView.menu.refresh,disabled:!t,onClick:s}),e.jsx(Hn,{icon:"refresh",label:te.kernelView.menu.restart,disabled:!t||!n,onClick:a}),e.jsx(Hn,{icon:"power",label:te.kernelView.menu.stop,danger:!0,disabled:!t||!n,onClick:r})]})})}function Q1({rig:t,pc:n,verb:s,confirm:a,live:r,onAct:l,onClose:o}){const[c,i]=f.useState(!0),[m,d]=f.useState(!1),x=t.nodes.filter(N=>!N.stopped&&Vs(N)).map(N=>pn(N.logicalId,N.session)),p=s==="stop",g=x.length?te.confirm.working(x.length):te.confirm.noneWorking,h=p?{kind:"rig.stop",rig:t.name,...c?{snapshot:!0}:{},...m?{force:!0}:{}}:{kind:"rig.restart",rig:t.name};return e.jsxs(an,{title:p?te.confirm.stop(t.name,n):te.confirm.restart(t.name,n),onClose:o,children:[e.jsx($l,{title:g,body:p?x.length?x.join(", "):void 0:te.confirm.restartNote}),p&&e.jsxs("div",{className:"overflow-hidden rounded-[10px] border border-line",children:[e.jsx(Do,{on:c,label:te.confirm.snapshot,onChange:i}),e.jsx(Do,{on:m,label:te.confirm.force,onChange:d})]}),e.jsx(On,{verb:p?te.actions.stop:te.actions.restart,confirm:a,disabled:!r,onClick:()=>{o(),l(h)}}),e.jsx(Xs,{onClose:o})]})}function _u({rig:t,confirm:n,live:s,onReseat:a,onDone:r,context:l}){const o=Md(t),[c,i]=f.useState({}),[m,d]=f.useState("pairs"),x=Object.fromEntries(Object.entries(c).filter(([y,b])=>{var M;return((M=o.find(S=>S.role===y))==null?void 0:M.count)!==b})),p=Fi(t.nodes,x),g=p.add.length,h=p.remove.length,N=t.nodes.filter(y=>p.remove.includes(y.logicalId)&&Vs(y)).map(y=>y.logicalId),k=g&&h?te.reseat.change(g,h):g?te.reseat.add(g):h?te.reseat.remove(h):te.reseat.noChange,C=()=>{r==null||r(),i({}),a(x,g?m:void 0)},j=l!==void 0;return e.jsxs(e.Fragment,{children:[e.jsx("table",{className:"w-full border-collapse text-[13px]",children:e.jsx("tbody",{children:o.map(y=>{const b=c[y.role]??y.count,M=p.add.filter(R=>R.role===y.role).map(R=>te.reseat.adds(`${R.pod}.${R.id}`)),S=p.remove.filter(R=>y.ids.includes(R)).map(te.reseat.removes),$=y.ids.map(R=>{var _;return pn(R,(_=t.nodes.find(L=>L.logicalId===R))==null?void 0:_.session)}).join(", "),v=j?y.ids.map(R=>l[R]).filter(R=>R!==void 0).map(R=>`${Math.round(R)} %`).join(", "):"",A=j?[...M,...S].join(" · "):[$,...M,...S].join(S.length?" → ":" · ");return e.jsxs("tr",{className:"border-b border-line last:border-b-0",children:[e.jsxs("td",{className:"px-1 py-[7px] font-mono text-[12.5px]",children:[y.role,A&&e.jsx("small",{className:"block font-sans text-[11.5px] text-muted",children:A})]}),j&&e.jsx("td",{className:"px-1 py-[7px] text-[12px] text-muted",children:v}),e.jsx("td",{className:"px-1 py-[7px] text-right",children:e.jsx(Og,{value:b,changed:b!==y.count,disabled:!s,fewer:te.reseat.fewer(y.role),more:te.reseat.more(y.role),onChange:R=>i({...c,[y.role]:R})})})]},y.role)})})}),g>0&&e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"flex-1 text-[12.5px] text-muted",children:te.reseat.delegation}),e.jsx(ca,{label:te.reseat.delegation,value:m,onChange:d,options:[{value:"pairs",label:te.reseat.pairs},{value:"all",label:te.reseat.all}]})]}),h>0&&e.jsx($l,{title:N.length?te.reseat.working(N):te.reseat.lastFirst,...N.length?{body:te.reseat.lastFirst}:{}}),(!j||g+h>0)&&(h>0?e.jsx(On,{verb:k,confirm:n,disabled:!s,onClick:C}):e.jsx("button",{type:"button",disabled:!s||g===0,onClick:C,className:be({tone:"primary",className:"w-full"}),children:k})),j&&g+h>0&&e.jsx("button",{type:"button",onClick:()=>i({}),className:be({className:"w-full"}),children:te.confirm.cancel})]})}function Z1({rig:t,pc:n,confirm:s,live:a,onReseat:r,onClose:l}){return e.jsxs(an,{title:te.reseat.title(t.name,n),onClose:l,children:[e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:te.reseat.today(Md(t).map(o=>te.reseat.part(o.count,o.role)).join(", "))}),e.jsx(_u,{rig:t,confirm:s,live:a,onReseat:r,onDone:l}),e.jsx(Xs,{onClose:l})]})}function J1({rig:t,read:n,level:s,confirm:a,live:r,onAct:l,onClose:o}){var k,C;const[c,i]=f.useState(s==="mixed"?null:s),m=Pt(),d=Cg((k=n==null?void 0:n.data)==null?void 0:k.policy),x=(((C=n==null?void 0:n.data)==null?void 0:C.seats.map(j=>j.session))??t.nodes.map(j=>j.session)).filter(j=>j.endsWith(`@${t.name}`)),p=c&&x.length?{kind:"rig.policy",rig:t.name,policy:c,seats:x}:null,g=!!p&&tl(p),h=()=>{p&&(o(),l(p))},N=!r||!p||c===s;return e.jsxs(an,{title:te.permissions.title(t.name),onClose:o,children:[e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:[te.permissions.sub,d?te.permissions.spec(te.level[d]):""].filter(Boolean).join(" ")}),(n==null?void 0:n.error)&&!n.data&&e.jsx("p",{role:"alert",className:"text-[12.5px] text-attention",children:te.permissions.unavailable}),e.jsx("div",{className:"flex flex-col gap-1.5",children:wg.map(j=>e.jsx(Hr,{pressed:c===j,disabled:!r,onClick:()=>i(j),sub:te.permissions.hint[j],title:e.jsxs(e.Fragment,{children:[te.level[j],(j==="yolo"||j==="spec")&&e.jsx("span",{className:"ml-1.5 inline-flex align-middle",children:e.jsx(Lt,{tone:"perm",children:m?te.permissions.faceId:te.permissions.check})})]})},j))}),g?e.jsx(On,{verb:te.permissions.apply,confirm:a,disabled:N,onClick:h}):e.jsx("button",{type:"button",disabled:N,onClick:h,className:be({tone:"primary",className:"w-full"}),children:te.permissions.apply})]})}const ey=(t,n)=>{const s=Ag(t,n.links).map(a=>{var l;const r=pn(a.who,(l=n.seats.find(o=>o.logicalId===a.who))==null?void 0:l.session);return a.kind==="linked"?te.seat.linked(r,a.label):te.seat[a.kind](r)});return s.length?s.join(" · "):te.seat.noLink};function ty({rig:t,seat:n,graph:s,node:a,session:r,status:l,near:o,onSettings:c,onClose:i}){const m=wl({session:r,node:a,graph:n,rigStatus:l}),d=Sl(n.runtime),x=pn(n.logicalId,n.session),p=[d?u.tools[d]:n.runtime,n.model??(a==null?void 0:a.model)??""].filter(Boolean).join(" · "),g=r!=null&&r.pending?te.seat.prompt(te.seatState[m]):te.seatState[m],h=a&&a.work>0?te.seat.tasks(a.work):te.seat.noTask,N=[[te.seat.harness,p],...n.context!==void 0?[[te.seat.context,e.jsx("span",{className:`font-mono ${n.context>=o?"text-attention":""}`,children:`${Math.round(n.context)} %`},"c")]]:[],[te.seat.now,g],[te.seat.work,h],[te.seat.links,ey(n.logicalId,s)]];return e.jsxs(an,{title:x,onClose:i,children:[e.jsxs("div",{className:"-mt-2 flex items-center gap-2",children:[e.jsx(ze,{state:Sd[m]}),d&&e.jsx(Xn,{tool:d}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"text-[12.5px] text-muted",children:te.seat.of(n.logicalId,t)})]}),e.jsx("dl",{className:"m-0 grid grid-cols-[110px_1fr] gap-x-3 gap-y-1.5 text-[13px]",children:N.map(([k,C])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted",children:k}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:C})]},k))}),r?e.jsx("a",{href:ce({name:"thread",sessionId:r.id}),className:be({tone:"primary",className:"w-full"}),children:te.seat.openSession}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:!0,className:be({tone:"primary",className:"w-full"}),children:te.seat.openSession}),e.jsx("p",{className:"-mt-1 text-[12px] text-muted",children:te.seat.noSession})]}),e.jsx("button",{type:"button",onClick:c,className:be({className:"w-full"}),children:e.jsx(Ft,{icon:"gear",children:te.seat.settings})})]})}function ny({rig:t,seat:n,node:s,selection:a,confirm:r,live:l,onAct:o,onClose:c}){const i=te.seatSettings,m=n.runtime==="codex"?"codex":n.runtime==="claude-code"||n.runtime==="claude"?"claude-code":null,d=n.model??(s==null?void 0:s.model)??"",x=a==="inherit"||a==="auto"||a==="full_bypass"?a:null,[p,g]=f.useState(m),[h,N]=f.useState(d),[k,C]=f.useState(null),[j,y]=f.useState(x),b=pn(n.logicalId,n.session),M=n.session??(s==null?void 0:s.session)??`${b}@${t}`,S=h.trim()===""||vx.safeParse(h.trim()).success,$=p!==null&&p!==m,v={kind:"seat.set",seat:M,...$?{runtime:p}:{},...h.trim()&&h.trim()!==d?{model:h.trim()}:{},...k?{effort:k}:{},...j&&j!==x?{permissions:j}:{}},A=Object.keys(v).length>2,R=tl(v),_=Sl(n.runtime),L=[_?u.tools[_]:n.runtime,d,x?i.perm[x]:""].filter(Boolean),T=!l||!A||!S,B=()=>{c(),o(v)},E=(P,W,F)=>e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"text-[12.5px] text-muted",children:`${P} · ${W}`}),F]});return e.jsxs(an,{title:i.title(b,t),onClose:c,children:[e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:i.today(L)}),E(i.harness,i.whenNow,e.jsx(ca,{label:i.harness,value:p,disabled:!l,onChange:g,options:[{value:"claude-code",label:u.tools.claude},{value:"codex",label:u.tools.codex}]})),E(i.model,i.whenResume,e.jsx("input",{"aria-label":i.modelLabel,value:h,disabled:!l,onChange:P=>N(P.target.value),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,className:`h-11 rounded-[10px] border bg-surface px-3 text-base outline-none focus:border-ring ${S?"border-input":"border-approval/60"}`})),E(i.effort,i.whenResume,e.jsx(ca,{label:i.effort,value:k,disabled:!l,onChange:C,options:["medium","high","xhigh"].map(P=>({value:P,label:i.effortLevel[P]}))})),E(i.permissions,i.whenLaunch,e.jsx(ca,{label:i.permissions,value:j,disabled:!l,onChange:y,options:["inherit","auto","full_bypass"].map(P=>({value:P,label:i.perm[P]}))})),$&&e.jsx("p",{className:"text-[12.5px] text-attention",children:i.moveNote}),R?e.jsx(On,{verb:i.save,confirm:r,disabled:T,onClick:B}):e.jsx("button",{type:"button",disabled:T,onClick:B,className:be({tone:"primary",className:"w-full"}),children:i.save})]})}function Ru({read:t,kindOnly:n=!1,retry:s}){const a=Td((t==null?void 0:t.data)??[]),r="overflow-hidden rounded-[10px] border border-line bg-surface dark:bg-transparent";return t!=null&&t.error&&!t.data?e.jsx("div",{className:r,children:e.jsx(Ln,{retry:s,retryLabel:te.unavailable.retry,children:te.snapshots.unavailable})}):t!=null&&t.data&&a.length===0?e.jsx("div",{className:r,children:e.jsx(Ln,{children:te.snapshots.none})}):a.length?e.jsx("div",{className:"flex max-h-[45dvh] flex-col overflow-y-auto rounded-[10px] border border-line bg-surface dark:bg-transparent",children:a.map(l=>e.jsxs("div",{className:"flex min-h-[46px] items-center gap-2.5 border-b border-line px-3 py-1.5 text-[13px] last:border-b-0",children:[e.jsx(z,{name:"camera",className:"size-4 text-muted"}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{children:Ma(l.createdAt).long}),e.jsx("small",{className:"text-[11.5px] text-muted",children:n?te.snapshots.kind[l.kind]??l.kind:[te.snapshots.kind[l.kind]??l.kind,te.snapshots.status[l.status]??l.status].join(" · ")})]})]},l.id))}):e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:te.loading})}function sy({rig:t,read:n,live:s,running:a,onSnapshot:r,onRetry:l,onClose:o}){return e.jsxs(an,{title:te.snapshots.title(t),onClose:o,children:[e.jsx(Ru,{read:n,retry:l}),e.jsx("button",{type:"button",disabled:!s||a,onClick:()=>{o(),r()},className:be({className:"w-full"}),children:e.jsx(Ft,{icon:"camera",children:te.snapshots.take})}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:te.snapshots.utc})]})}const me=u.rigs,vn=t=>{var n;return((n=va(t))==null?void 0:n.toISOString())??t},ay={mine:"border-attention/50 text-attention",progress:"border-info/45 text-info",pending:"border-input text-muted",blocked:"border-approval/45 text-approval"},ry=({tone:t})=>e.jsx("span",{"data-row":t,className:`flex-none rounded-[5px] border px-1.5 text-[11px] leading-[18px] whitespace-nowrap ${ay[t]}`,children:me.queue.tone[t]}),Un=t=>t.split("@")[0]??t;function Tu({seat:t,state:n,pod:s,tag:a,near:r,isNew:l,pulse:o,onOpen:c,onMore:i,top:m=!1,name:d,words:x}){const{swallow:p,...g}=Dg(i),h=d??pn(t.logicalId,t.session),N=Sl(t.runtime),k=t.context!==void 0&&n!=="off"&&n!=="waiting"?Math.round(t.context):null,C=x??[m?s:void 0,me.seatState[n]].filter(Boolean).join(" · "),j=l?"border-ok/55":n==="ask"?"border-attention/55":n==="perm"?"border-approval/55":n==="off"||n==="waiting"?"border-dashed border-input bg-transparent":"border-line",y=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx(ze,{state:Sd[n],pulse:o}),e.jsx("b",{className:`truncate text-[13px] font-semibold ${n==="off"?"text-muted":""}`,children:h}),l?e.jsx("span",{className:"ml-auto",children:e.jsx(Lt,{tone:"ok",children:me.reseat.new})}):a&&N&&e.jsx("span",{className:"ml-auto",children:e.jsx(Xn,{tool:N})})]}),e.jsxs("small",{className:`truncate text-[11.5px] ${n==="ask"?"text-attention":"text-muted"}`,children:[C,k!==null&&e.jsxs(e.Fragment,{children:[C?" · ":"",e.jsx("span",{className:`font-mono ${k>=r?"text-attention":""}`,children:`${k} %`})]})]})]}),b=`flex min-w-0 flex-col gap-px rounded-[9px] border bg-surface px-[9px] py-[7px] text-left ${j} ${m?"w-[190px] max-w-full":""}`;return c?e.jsx("button",{type:"button",...g,onClick:()=>{p!=null&&p()||c()},"aria-label":me.seatLabel(h,me.seatState[n]),"data-seat":t.logicalId,className:b,children:y}):e.jsx("div",{"data-seat":t.logicalId,className:b,children:y})}function ly({graph:t,rig:n,status:s,sessions:a,near:r,added:l,onSeat:o,wide:c=!1}){var g;const i=vg(t.seats,t.links),m=t.seats.find(h=>h.logicalId===i),d=kg(t.seats.filter(h=>h.logicalId!==i),t.pods),x=(m==null?void 0:m.runtime)??((g=t.seats[0])==null?void 0:g.runtime),p=(h,N=!1)=>{var M;const k=kd(a,n.name,h.logicalId),C=wl({session:k,node:n.nodes.find(S=>S.logicalId===h.logicalId),graph:h,rigStatus:s}),j=((M=t.pods.find(S=>S.id===h.pod))==null?void 0:M.label)??h.pod,y=o?()=>o(h.logicalId):void 0,b=c&&k?()=>is({name:"thread",sessionId:k.id}):void 0;return e.jsx(Tu,{seat:h,state:C,pod:j,top:N,near:r,isNew:l.includes(h.logicalId),tag:N||h.runtime!==x,pulse:C==="starting"||s==="starting"&&C==="work",onOpen:b??y,onMore:b?y:void 0},h.logicalId)};return e.jsxs("div",{className:"flex flex-col items-center",children:[m&&e.jsxs(e.Fragment,{children:[p(m,!0),e.jsx("span",{"aria-hidden":"true",className:"h-3 w-[1.5px] bg-input"})]}),e.jsx("div",{className:`grid w-full gap-2 ${d.length>=3?"grid-cols-3":d.length===1&&!m?"grid-cols-1":"grid-cols-2"}`,children:d.map(h=>e.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5 rounded-[10px] border border-dashed border-input p-1.5",children:[e.jsx("small",{className:"px-0.5 font-mono text-[10.5px] text-muted",children:h.label}),h.seats.map(N=>p(N))]},h.id))})]})}function oy({row:t,mine:n}){const s=[[me.queue.from,`${Un(t.from)} → ${Un(t.to)}`],...t.blockedOn?[[me.queue.blockedOn,t.blockedOn]]:[],[me.queue.created,[Ke(vn(t.createdAt)),t.claimedAt?me.queue.claimed(Ke(vn(t.claimedAt))):""].filter(Boolean).join(" · ")]];return e.jsxs("div",{className:"flex flex-col gap-2 border-b border-line bg-raised/40 px-3 py-2.5 last:border-b-0",children:[e.jsx("span",{className:"font-mono text-[12px] text-muted",children:t.id}),t.summary&&e.jsx("b",{className:"text-[14px] font-semibold",children:t.summary}),e.jsx("dl",{className:"m-0 grid grid-cols-[90px_1fr] gap-x-3 gap-y-1 text-[13px]",children:s.map(([a,r])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted",children:a}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:r})]},a))}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:me.queue.readOnly}),n&&e.jsx("a",{href:ce({name:"ask",id:t.id}),className:be({size:"sm",className:"self-start"}),children:me.queue.seeAsk})]})}function iy({read:t,asks:n,now:s,retry:a}){const[r,l]=f.useState(null),[o,c]=f.useState(!1),i=t==null?void 0:t.data;if(!i)return e.jsx(Ve,{children:t!=null&&t.error?e.jsx(Ln,{retry:a,retryLabel:me.unavailable.retry,children:me.queue.unavailable}):e.jsx("p",{role:"status",className:"p-3 text-[13px] text-muted",children:me.loading})});const m={done:e.jsx("span",{className:"text-ok",children:"✓"}),handed:e.jsx("span",{className:"text-muted",children:"↪"}),stopped:e.jsx("span",{className:"text-approval",children:"✕"})};return e.jsxs(e.Fragment,{children:[e.jsx(It,{children:me.queue.title(i.rows.length)}),e.jsxs(Ve,{children:[i.rows.length===0&&e.jsx("p",{className:"p-3 text-[13px] text-muted",children:me.queue.none}),i.rows.map(d=>{const x=$g(d,n),p=r===d.id;return e.jsxs("div",{className:"contents",children:[e.jsxs("button",{type:"button","aria-expanded":p,onClick:()=>l(p?null:d.id),className:"flex min-h-[46px] w-full items-center gap-[9px] border-b border-line px-3 py-1.5 text-left text-[13px] last:border-b-0",children:[e.jsx(ry,{tone:x}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate",children:d.summary??d.id}),e.jsx("small",{className:"truncate text-[11.5px] text-muted",children:[`${Un(d.from)} → ${Un(d.to)}`,d.needsInput?me.queue.prompt:""].filter(Boolean).join(" · ")})]}),e.jsx("span",{className:"font-mono text-[11px] whitespace-nowrap text-muted",children:fa(vn(d.updatedAt),s)})]}),p&&e.jsx(oy,{row:d,mine:x==="mine"})]},d.id)}),i.closed.length>0&&e.jsxs("button",{type:"button","aria-expanded":o,onClick:()=>c(!o),className:"flex min-h-[46px] w-full items-center gap-[9px] border-t border-line px-3 text-left text-[13px] text-muted first:border-t-0",children:[e.jsx(z,{name:"chevron",className:`size-3.5 transition-transform ${o?"rotate-90":""}`}),e.jsx("span",{children:me.queue.closed(i.closed.length)})]}),o&&i.closed.map(d=>{const x=Mg(d.state);return e.jsxs("div",{className:"flex min-h-[46px] items-center gap-[9px] border-t border-line px-3 py-1.5 text-[13px] text-muted",children:[e.jsx("span",{"aria-hidden":"true",children:m[x]}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate text-fg",children:d.summary??d.id}),e.jsx("small",{className:"truncate text-[11.5px]",children:`${Un(d.from)} → ${Un(d.to)} · ${me.queue.closedTone[x]}`})]}),e.jsx("span",{className:"font-mono text-[11px]",children:Ke(vn(d.updatedAt))})]},d.id)})]}),i.truncated&&e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:me.queue.truncated})]})}function cy({rig:t,sessions:n,asks:s}){var h;const a=n.filter(N=>{var k;return((k=N.rig)==null?void 0:k.name)===t}),r=kn(a),l=r.find(N=>N.filter==="permission")??r[0],o=l?a.find(N=>N.id===l.sessionId):void 0,c=l||s==null?void 0:s.find(N=>N.from.rig===t&&N.kind!=="update");if(!l&&!c)return null;const i=o?(h=o.rig)!=null&&h.role?pn(o.rig.role):o.name:c?Un(c.from.seat):"",m=(l==null?void 0:l.filter)==="permission",[d,x,p]=m?me.waits.permission(i):me.waits.question(i),g=ce(l?{name:"request",sessionId:l.sessionId,key:l.key}:{name:"sessions"});return e.jsx(Wt,{warn:!m,danger:m,compact:!0,lead:e.jsx(ze,{state:m?"perm":"ask"}),action:e.jsx("a",{href:g,className:be({size:"xs"}),children:me.waits.see}),children:e.jsxs("span",{children:[d,e.jsx("b",{className:"font-semibold",children:x}),p]})})}function dy({rig:t,rigs:n,store:s}){var kt,ct,mt,G,_e,we;const a=js(n),r=xe(s),{pc:l,look:o}=zt(),c=Dt(),[i,m]=f.useState(null),[d,x]=f.useState("last"),p=r.fresh,g=o==="offline",[h,N]=f.useState(()=>Date.now());f.useEffect(()=>{const le=setInterval(()=>N(Date.now()),3e4);return()=>clearInterval(le)},[]),f.useEffect(()=>{n.follow(),p&&(n.openRig(t),n.readSnapshots(t))},[n,t,p]);const k=Jt(l),C=a.state,j=C==null?void 0:C.rigs.find(le=>le.name===t),y=a.graphs[t],b=a.permissions[t],M=a.snapshots[t],S=a.queues[t],$=[...r.sessions.values()],v=((kt=r.device)==null?void 0:kt.contextNear)??70,A=!!((ct=r.device)!=null&&ct.confirm),R=Dl(a.runs,le=>Tg(le.subject)===t),_=Ya(R),L=le=>{n.act(le)},T=(le,ge)=>{n.reseat(t,le,ge?{delegation:ge}:{})},B=()=>m(null),E=()=>n.openRig(t),P=e.jsx("button",{type:"button","aria-label":me.more,title:me.more,"aria-haspopup":"menu",onClick:()=>m({kind:"more"}),className:Ot(),children:e.jsx(z,{name:"more"})}),W=(le,ge,qe)=>c?e.jsxs("header",{className:"pane-head flex h-[58px] flex-none items-center gap-2 border-b border-line pr-1.5",children:[e.jsx(Zt,{fallback:{name:"rigs"},label:me.back}),e.jsx("h1",{className:"min-w-0 truncate text-[17px] font-semibold",children:t}),le,ge&&e.jsx("span",{className:"min-w-0 truncate text-[12.5px] text-muted",children:ge}),e.jsx("span",{className:"flex-1"}),qe,j&&P]}):e.jsxs("header",{className:"flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-0.5",children:[e.jsx(Zt,{fallback:{name:"rigs"},label:me.back}),e.jsx("h1",{className:"min-w-0 truncate text-base font-semibold",children:t}),le,e.jsx("span",{className:"flex-1"}),j&&P]}),F=`tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pb-[18px] ${c?"pt-[18px]":"pt-3"}`;if(!!C&&(!j||(y==null?void 0:y.error)==="unknown_rig"||(S==null?void 0:S.error)==="unknown_rig"))return e.jsxs(e.Fragment,{children:[W(null),e.jsx("main",{"data-tab-scroll":"",className:F,children:e.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-10 text-center",children:[e.jsx("h2",{className:"text-[17px] font-semibold",children:me.readError.unknown_rig}),e.jsx("a",{href:ce({name:"rigs"}),className:be({size:"sm",className:"mt-1.5"}),children:me.back})]})})]});if(!j){const le=a.error?me.readError[a.error]:null;return e.jsxs(e.Fragment,{children:[W(null),e.jsxs("main",{"data-tab-scroll":"",className:F,children:[e.jsx(wn,{body:me.offlineBody}),le?e.jsx(Wt,{warn:!0,role:"alert",lead:e.jsx(z,{name:"warning",className:"mt-px size-4 text-attention"}),children:e.jsx("b",{className:"font-semibold",children:le})}):e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:me.loading})]})]})}const Y=xn(j),H=Y==="stopped",I=b!=null&&b.data?$d(b.data.seats):null,D=I?me.level[I]:null,Q=Td((M==null?void 0:M.data)??[])[0],q=Q?Ma(Q.createdAt).short:j.snapshot||"",K=(R==null?void 0:R.phase)==="done"&&((mt=R.reseated)!=null&&mt.ok)?R.reseated.added:[],ee=j.nodes.filter(le=>le.stopped).map(le=>pn(le.logicalId,le.session)),ue=le=>{var ge;return(ge=y==null?void 0:y.data)==null?void 0:ge.seats.find(qe=>qe.logicalId===le)},fe=()=>{var le;return L(d==="fresh"?{kind:"rig.start",rig:t,fresh:((le=y==null?void 0:y.data)==null?void 0:le.seats.map(ge=>ge.logicalId))??j.nodes.map(ge=>ge.logicalId)}:{kind:"rig.start",rig:t})},he=R&&!_?R:void 0,w=p&&!_,O=c?"sm":"md",V=c?"":"!h-[42px] !px-2 !text-[13.5px]",Z=e.jsx("button",{type:"button",disabled:!w,onClick:fe,className:be({tone:"primary",size:O,className:c?"":"!h-[42px]"}),children:e.jsx(Ft,{icon:"power",children:me.actions.start})}),X=e.jsx("button",{type:"button",disabled:!w,onClick:()=>m({kind:"restart"}),className:be({size:O,className:V}),children:e.jsx(Ft,{icon:"refresh",children:me.actions.restart})}),J=e.jsx("button",{type:"button",disabled:!w,onClick:()=>m({kind:"stop"}),className:be({tone:"danger",size:O,className:V}),children:e.jsx(Ft,{icon:"power",children:me.actions.stop})}),pe=e.jsx("button",{type:"button",disabled:!w,onClick:()=>m({kind:"reseat"}),className:be({size:O,className:V}),children:e.jsx(Ft,{icon:"plus",children:me.actions.seats})}),Ne=_?e.jsx(Ca,{run:R,rigs:n,pc:k,bar:!c}):Y==="starting"?e.jsx(Ls,{bar:!c,children:me.startingSeats(t,j.running,j.seats)}):null,Xe=Ne??e.jsx("div",{className:`bleed grid flex-none gap-2 border-t border-line bg-bg px-3.5 pt-2.5 pb-3 ${H?"grid-cols-1":"grid-cols-3"}`,children:H?Z:e.jsxs(e.Fragment,{children:[pe,X,J]})}),gt=p&&e.jsx(cy,{rig:t,sessions:$,asks:r.asks}),Be=Y==="partial"&&ee.length>0&&e.jsxs(Wt,{warn:!0,lead:e.jsx(z,{name:"warning",className:"mt-px size-4 text-attention"}),children:[e.jsx("span",{children:me.partial(ee,j.nodes.length-ee.length)}),e.jsx("button",{type:"button",disabled:!w,onClick:()=>m({kind:"restart"}),className:be({size:"sm",className:"self-start"}),children:me.actions.restartRig})]}),Je=e.jsxs(e.Fragment,{children:[e.jsx(It,{aside:H?me.topologyStopped:y!=null&&y.data?me.topologyHint:void 0,children:me.topology}),y!=null&&y.data?e.jsx(ly,{graph:y.data,rig:j,status:Y,sessions:$,near:v,added:K,onSeat:le=>m({kind:"seat",id:le}),wide:c}):e.jsx(Ve,{children:y!=null&&y.error?e.jsx(Ln,{retry:E,retryLabel:me.unavailable.retry,children:me.readError[y.error]}):e.jsx("p",{role:"status",className:"p-3 text-[13px] text-muted",children:me.loading})})]}),oe=H&&j.snapshot&&e.jsxs(e.Fragment,{children:[e.jsx(It,{children:me.resume}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(Hr,{pressed:d==="last",disabled:!p,onClick:()=>x("last"),title:me.resumeLast(Q?Ma(Q.createdAt).long:j.snapshot),sub:me.resumeLastBody}),e.jsx(Hr,{pressed:d==="fresh",disabled:!p,onClick:()=>x("fresh"),title:me.fresh,sub:me.freshBody})]})]}),de=e.jsx(iy,{read:S,asks:r.asks,now:h,retry:E}),ke=c?e.jsxs("div",{className:"grid grid-cols-[minmax(0,1.15fr)_minmax(0,1fr)] content-start gap-[18px]",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-3.5",children:[gt,Be,Je,!H&&Y!=="starting"&&e.jsxs(e.Fragment,{children:[e.jsx(It,{children:me.seatsByRole}),e.jsx(Ve,{children:e.jsx("div",{className:"flex flex-col gap-2.5 px-3 py-1",children:e.jsx(_u,{rig:j,confirm:A,live:w,onReseat:T,context:Object.fromEntries((((G=y==null?void 0:y.data)==null?void 0:G.seats)??[]).map(le=>[le.logicalId,le.context]))},j.nodes.length)})})]}),oe]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3.5",children:[de,e.jsx(It,{children:me.actions.snapshots}),e.jsx(Ru,{read:M,kindOnly:!0,retry:()=>n.readSnapshots(t)}),e.jsx("button",{type:"button",disabled:!w,onClick:()=>L({kind:"rig.snapshot",rig:t}),className:be({size:"sm",className:"max-w-full self-start !h-auto min-h-9 py-1.5 !whitespace-normal text-left [&>svg]:flex-none"}),children:e.jsx(Ft,{icon:"camera",children:me.snapshots.take})})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx(pr,{label:me.tiles.seats,value:`${j.running}/${j.seats}`}),e.jsx(pr,{label:me.tiles.permissions,value:D??"—",onOpen:()=>m({kind:"permissions"})}),e.jsx(pr,{label:me.tiles.snapshot,value:q||"—",onOpen:()=>m({kind:"snapshots"})})]}),gt,Be,Je,de,oe]}),Oe=(i==null?void 0:i.kind)==="seat"||(i==null?void 0:i.kind)==="settings"?ue(i.id):void 0,lt=Oe?j.nodes.find(le=>le.logicalId===Oe.logicalId):void 0,xt=[me.seats(j.running,j.seats),D??"",q?me.snapshot(q):""].filter(Boolean).join(" · ");return e.jsxs(e.Fragment,{children:[W(e.jsx(us,{tone:Rd[Y],children:me.status[Y]}),xt,!Ne&&(H?Z:e.jsxs(e.Fragment,{children:[X,J]}))),e.jsxs("main",{"data-tab-scroll":"",className:F,children:[e.jsx(wn,{body:me.offlineBody}),c&&Ne,he&&e.jsx(Ca,{run:he,rigs:n,pc:k}),e.jsx("div",{className:`flex flex-col gap-3 ${g?"opacity-50":""}`,children:ke})]}),!c&&Xe,(i==null?void 0:i.kind)==="more"&&e.jsx(X1,{rig:t,live:p,running:_,snapshots:M!=null&&M.data?M.data.length:null,level:D,onClose:B,onSnapshot:()=>{B(),L({kind:"rig.snapshot",rig:t})},onSnapshots:()=>m({kind:"snapshots"}),onPermissions:()=>m({kind:"permissions"}),onRefresh:()=>{B(),n.retry(),n.openRig(t),n.readSnapshots(t)}}),((i==null?void 0:i.kind)==="stop"||(i==null?void 0:i.kind)==="restart")&&e.jsx(Q1,{rig:j,pc:k,verb:i.kind,confirm:A,live:w,onAct:L,onClose:B}),(i==null?void 0:i.kind)==="reseat"&&e.jsx(Z1,{rig:j,pc:k,confirm:A,live:w,onReseat:T,onClose:B}),(i==null?void 0:i.kind)==="permissions"&&e.jsx(J1,{rig:j,read:b,level:I,confirm:A,live:w,onAct:L,onClose:B}),(i==null?void 0:i.kind)==="snapshots"&&e.jsx(sy,{rig:t,read:M,live:p,running:_,onSnapshot:()=>L({kind:"rig.snapshot",rig:t}),onRetry:()=>n.readSnapshots(t),onClose:B}),(i==null?void 0:i.kind)==="seat"&&Oe&&(y==null?void 0:y.data)&&e.jsx(ty,{rig:t,seat:Oe,graph:y.data,node:lt,session:kd($,t,Oe.logicalId),status:Y,near:v,onSettings:()=>m({kind:"settings",id:Oe.logicalId}),onClose:B}),(i==null?void 0:i.kind)==="settings"&&Oe&&e.jsx(ny,{rig:t,seat:Oe,node:lt,selection:(we=(_e=b==null?void 0:b.data)==null?void 0:_e.seats.find(le=>le.logicalId===Oe.logicalId))==null?void 0:we.selection,confirm:A,live:w,onAct:L,onClose:B})]})}const dn=u.rigs,ve=dn.max,uy={sent:"idle",taken:"work",asking:"ask",proposed:"rig",running:"work",done:"done",closed:"done"},xy={sent:"plain",taken:"work",asking:"ask",proposed:"rig",running:"work",done:"ok",closed:"plain"},my=t=>{var n;return((n=t.trail.at(-1))==null?void 0:n.at)??t.sentAt},Au=t=>{const n=Ea(t);if(!n)return null;for(let s=t.trail.length-1;s>=0;s--)if(t.trail[s].text===n)return t.trail[s].at;return null};function py(t){var s;const n=Ma(my(t)).short;return t.state==="asking"?`${ve.asks} · ${n}`:t.state==="running"?[ve.state.running,((s=t.current)==null?void 0:s.seat.split("@")[0])??"",ve.since(n)].filter(Boolean).join(" · "):`${ve.state[t.state]} · ${n}`}const Ea=t=>{var n,s;return((n=t.question)==null?void 0:n.text)??((s=t.proposal)==null?void 0:s.text)??null};function fy({run:t,pc:n,onAgain:s,onClose:a}){var c,i;const r={onClose:a,closeLabel:dn.done.close},l=e.jsx("button",{type:"button",onClick:s,className:be({size:"xs",className:"mt-1.5"}),children:ve.sendAgain}),o=t.phase==="uncertain"?"uncertain":t.phase==="done"?(c=t.sent)==null?void 0:c.error:void 0;return o?o==="uncertain"?e.jsx($e,{mark:"ask",title:ve.errors.uncertain.title,sub:ve.errors.uncertain.body,...r,children:l}):o==="refused"?e.jsx($e,{mark:"bad",title:ve.errors.refused.title,...(i=t.sent)!=null&&i.message?{sub:e.jsx("span",{className:"font-mono",children:t.sent.message})}:{},...r}):o==="openrig_stopped"?e.jsx($e,{mark:"bad",title:ve.errors.openrig_stopped.title(n),sub:ve.errors.openrig_stopped.body,...r,children:l}):o==="no_operator"||o==="unreachable"?e.jsx($e,{mark:"bad",title:ve.errors[o].title,sub:ve.errors[o].body,...r,children:l}):e.jsx($e,{mark:"bad",title:ve.unsent,sub:ve.keeps,...r,children:l}):e.jsx($e,{mark:"bad",title:ve.unsent,sub:ve.keeps,...r,children:l})}const hy=t=>{var n;return t.phase==="done"&&!!((n=t.sent)!=null&&n.ok)};function Iu({runs:t,rigs:n,pc:s,bubble:a}){return e.jsx(e.Fragment,{children:t.filter(r=>!hy(r)).map(r=>{const l=r.subject;if(l.kind!=="goal"&&l.kind!=="reply")return null;if(Ya(r))return e.jsxs("div",{role:"status","aria-label":ve.sending,className:"max-w-[85%] self-end rounded-[14px] rounded-br-[5px] bg-secondary px-3 py-2 text-[14px] leading-5 opacity-60",children:[l.text," ",e.jsx(bs,{className:"ml-1 align-[-1px] text-muted"})]},r.id);const o=()=>{n.dismiss(r.id),l.kind==="goal"?n.sendGoal(l.text,l.goalId):n.replyGoal(l.goalId,l.text,l.replyId)};return e.jsx(fy,{run:r,pc:s,onAgain:o,onClose:()=>n.dismiss(r.id)},r.id)})})}function gy(t){var n;switch(t.kind){case"sent":return ve.trail.sent;case"taken":return ve.trail.taken;case"note":return ve.trail.note(t.text??"");case"handed":return ve.trail.handed(((n=t.to)==null?void 0:n.split("@")[0])??"");case"closed":return ve.trail.closed}}function Lu({goal:t,runs:n,rigs:s,pc:a,compact:r=!1,asks:l=null}){const o=Ea(t),c=Au(t),i=t.question??(t.proposal&&!t.proposal.answer?t.proposal:null),m=n.filter(d=>d.subject.kind==="reply"&&d.subject.goalId===t.goalId);return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("div",{className:"max-w-[85%] self-end rounded-[14px] rounded-br-[5px] bg-secondary px-3 py-2 text-[14px] leading-5 [overflow-wrap:anywhere]",children:t.text}),!r&&t.trail.some(d=>d.kind!=="sent")&&e.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0 text-[12.5px] text-muted",children:t.trail.filter(d=>d.kind!=="sent").map((d,x)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"font-mono text-[11.5px]",children:Ke(vn(d.at))}),e.jsx("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:gy(d)})]},`${d.at}-${x}`))}),o&&e.jsxs("div",{className:"flex flex-col gap-1 text-[13.5px] leading-[19px]",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-[12px] text-muted",children:[e.jsx(ze,{state:"idle"}),c?`${dn.kernelView.max} · ${Ke(vn(c))}`:dn.kernelView.max]}),e.jsx("span",{className:"[overflow-wrap:anywhere]",children:o})]}),i&&e.jsxs("div",{className:"flex flex-col gap-2 rounded-[10px] border border-attention/45 bg-surface px-3 py-2.5",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(ze,{state:"ask"}),e.jsx("b",{className:"text-[14px] font-semibold",children:t.question?ve.question:ve.proposal}),c&&e.jsx("span",{className:"ml-auto font-mono text-[11.5px] text-muted",children:Ke(vn(c))})]}),!r&&e.jsx("p",{className:"text-[13px] text-muted",children:t.question?ve.questionBody:ve.proposalBody}),e.jsx("a",{href:l!=null&&l.some(d=>d.id===i.askId)?ce({name:"ask",id:i.askId}):ce({name:"rigs"}),className:be({size:"sm",className:"self-start"}),children:ve.seeAsk})]}),e.jsx(Iu,{runs:m,rigs:s,pc:a,bubble:!0})]})}function Ou({goalId:t,rigs:n,live:s}){const[a,r]=f.useState("");return e.jsx(ac,{label:ve.replyPlaceholder,sendLabel:ve.send,placeholder:ve.replyPlaceholder,offlinePlaceholder:ve.offlinePlaceholder,offline:!s,value:a,onChange:r,onSend:()=>{const l=a.trim();l&&(r(""),n.replyGoal(t,l).then(o=>{o.phase==="unsent"&&r(c=>c||l)}))}})}function by({goalId:t,rigs:n,store:s}){var S,$,v,A;const a=js(n),r=xe(s),{pc:l,look:o}=zt(),c=Dt(),i=r.fresh,m=o==="offline",d=Jt(l),[x,p]=f.useState("");f.useEffect(()=>{n.follow(),n.followGoals()},[n,i]);const g=(($=(S=a.goals)==null?void 0:S.data)==null?void 0:$.goals)??[],h=t?g.find(R=>R.goalId===t):void 0,N=`tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pb-[18px] ${c?"pt-[18px]":"pt-3"}`,k=c?"pane-head flex h-[58px] flex-none items-center gap-2 border-b border-line pr-2":"flex h-14 flex-none items-center gap-2 border-b border-line pr-2 pl-0.5",C="bleed flex-none border-t border-line bg-bg px-3.5 pt-2.5 pb-3",j=(()=>{var R,_;return(R=a.goals)!=null&&R.error&&!a.goals.data?e.jsx(Ve,{children:e.jsx(Ln,{retry:()=>n.followGoals(),retryLabel:dn.unavailable.retry,children:ve.goalsUnavailable})}):(_=a.goals)!=null&&_.data?null:e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:dn.loading})})();if(t)return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:k,children:[e.jsx(Zt,{fallback:{name:"max"},label:dn.backMax}),e.jsx("h1",{className:"min-w-0 truncate text-base font-semibold",children:(h==null?void 0:h.text)??ve.title}),h&&e.jsx("span",{className:"flex-none",children:e.jsx(Lt,{tone:xy[h.state],children:ve.statePill[h.state]})})]}),e.jsxs("main",{"data-tab-scroll":"",className:`${N} justify-end`,children:[e.jsx(wn,{body:dn.offlineBody}),h?e.jsx("div",{className:m?"opacity-50":"",children:e.jsx(Lu,{goal:h,runs:a.runs,rigs:n,pc:d,asks:r.asks})}):j??e.jsx("p",{role:"alert",className:"text-[13px] text-attention",children:ve.goalsUnavailable})]}),h&&e.jsx("div",{className:C,children:e.jsx(Ou,{goalId:h.goalId,rigs:n,live:i})})]});const y=a.runs.filter(R=>R.subject.kind==="goal"),b=()=>{const R=x.trim();R&&(p(""),n.sendGoal(R).then(_=>{_.phase==="unsent"&&p(L=>L||R)}))},M=()=>{var R;(R=document.querySelector("[data-goal-field] textarea"))==null||R.focus()};return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:k,children:[e.jsx(Zt,{fallback:{name:"kernel"},label:dn.backKernel}),e.jsx("h1",{className:"flex-none text-base font-semibold",children:ve.title}),e.jsx("span",{className:"min-w-0 truncate text-[12.5px] text-muted",children:ve.role}),e.jsx("span",{className:"flex-1"}),e.jsx("button",{type:"button",disabled:!i,onClick:M,className:be({tone:"primary",size:"sm"}),children:e.jsx(Ft,{icon:"plus",children:ve.newGoal})})]}),e.jsxs("main",{"data-tab-scroll":"",className:N,children:[e.jsx(wn,{body:dn.offlineBody}),e.jsxs("div",{className:`flex flex-col gap-3 ${m?"opacity-50":""}`,children:[j??(g.length===0?e.jsx(Ve,{children:e.jsx(Ln,{children:ve.none})}):e.jsx(Ve,{label:ve.goalsLabel,children:g.map(R=>e.jsxs("a",{href:ce({name:"max",goalId:R.goalId}),className:"flex items-start gap-2.5 border-b border-line px-3 py-2.5 last:border-b-0",children:[e.jsx("span",{className:"mt-1.5",children:e.jsx(ze,{state:uy[R.state],pulse:R.state==="running"})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsx("span",{className:"line-clamp-2 text-[14px] leading-5 [overflow-wrap:anywhere]",children:R.text}),e.jsx("small",{className:`text-[12px] ${R.state==="asking"?"text-attention":"text-muted"}`,children:py(R)})]})]},R.goalId))})),((A=(v=a.goals)==null?void 0:v.data)==null?void 0:A.partial)&&e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:ve.partial}),e.jsx(Iu,{runs:y,rigs:n,pc:d,bubble:!1}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:ve.requestsNote})]})]}),e.jsx("div",{"data-goal-field":"",className:C,children:e.jsx(ac,{label:ve.goalPlaceholder,sendLabel:ve.send,placeholder:ve.goalPlaceholder,offlinePlaceholder:ve.offlinePlaceholder,offline:!i,value:x,onChange:p,onSend:b})})]})}const Ae=u.rigs,jt=Ae.kernelView,jy=t=>/^qitem-\d{14}-[0-9a-f]{8,}$/.test(t)?`…${t.slice(-8)}`:t;function yy({graph:t,status:n,near:s}){var i;const a=t.seats,r=a.find(m=>Ed(m.logicalId)),l=a.filter(m=>m!==r),o=(r==null?void 0:r.runtime)??((i=a[0])==null?void 0:i.runtime),c=(m,d=!1)=>{var h;const x=wl({graph:m,rigStatus:n}),p=((h=t.pods.find(N=>N.id===m.pod))==null?void 0:h.label)??m.pod,g=[d?p:"",x==="idle"?"":Ae.seatState[x]].filter(Boolean).join(" · ");return e.jsx(Tu,{seat:m,state:x,pod:p,top:d,near:s,isNew:!1,name:_d({logicalId:m.logicalId,session:m.session??""}),words:g,tag:d||m.runtime!==o,pulse:x==="starting"},m.logicalId)};return e.jsxs("div",{className:"flex flex-col items-center",children:[r&&e.jsxs(e.Fragment,{children:[c(r,!0),e.jsx("span",{"aria-hidden":"true",className:"h-3 w-[1.5px] bg-input"})]}),e.jsx("div",{className:"grid w-full max-w-[420px] grid-cols-2 gap-2",children:l.map(m=>c(m))})]})}function Ny({rigs:t}){const n=js(t).routing,s=n!=null&&n.data?[...n.data].reverse():null,a=r=>{const l=Eg(r);return l.verb==="handed"?jt.change.handed(l.to):l.verb==="blocked"?jt.change.blocked(jy(l.on)):l.verb==="other"?l.text:jt.change[l.verb]};return e.jsxs(e.Fragment,{children:[e.jsx(It,{aside:jt.allRigs,children:jt.routing}),e.jsx(Ve,{children:s?s.length===0?e.jsx(Ln,{children:jt.noRouting}):s.map((r,l)=>e.jsxs("div",{className:"grid grid-cols-[44px_1fr] gap-x-2 border-b border-line px-3 py-2 text-[13px] leading-[18px] last:border-b-0",children:[e.jsx("span",{className:"font-mono text-[11.5px] text-muted",children:Ke(vn(r.at))}),e.jsxs("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:[e.jsx("b",{className:"font-semibold",children:jt.actor(r.seat.split("@")[0]??r.seat)})," ",a(r.change)]}),e.jsx("small",{className:"col-start-2 truncate text-[11.5px] text-muted",children:[r.rig,r.summary??""].filter(Boolean).join(" · ")})]},`${r.qitem}-${r.at}-${l}`)):n!=null&&n.error?e.jsx(Ln,{retry:()=>t.readRouting(),retryLabel:Ae.unavailable.retry,children:Ae.readError[n.error]}):e.jsx("p",{role:"status",className:"p-3 text-[13px] text-muted",children:Ae.loading})})]})}function ky({rigs:t,store:n}){var O,V,Z,X;const s=js(t),a=xe(n),{pc:r,look:l}=zt(),o=Dt(),[c]=Ll(),[i,m]=f.useState(null),d=a.fresh,x=l==="offline";f.useEffect(()=>{t.follow(),t.followGoals(),d&&(t.openRig(Ms),t.readRouting())},[t,d]);const p=s.state?Br(s.state).filter(J=>xn(J)!=="stopped").map(J=>J.name).join(" "):"";f.useEffect(()=>{if(d&&p)for(const J of p.split(" "))t.readPermissions(J)},[t,d,p]);const g=Jt(r),h=s.state,N=`tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pb-[18px] ${o?"pt-[18px]":"pt-3"}`,k=J=>e.jsxs("header",{className:o?"pane-head flex h-[58px] flex-none items-center gap-2 border-b border-line pr-1.5":"flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-0.5",children:[e.jsx(Zt,{fallback:{name:"rigs"},label:Ae.back}),e.jsx("h1",{className:`min-w-0 truncate font-semibold ${o?"text-[17px]":"text-base"}`,children:Ae.kernel}),J,e.jsx("span",{className:"flex-1"}),J&&e.jsx("button",{type:"button","aria-label":Ae.more,title:Ae.more,"aria-haspopup":"menu",onClick:()=>m("menu"),className:Ot(),children:e.jsx(z,{name:"more"})})]}),C=()=>{t.retry(),t.openRig(Ms),t.readRouting()};if(!h){const J=s.error?Ae.readError[s.error]:null;return e.jsxs(e.Fragment,{children:[k(null),e.jsxs("main",{"data-tab-scroll":"",className:N,children:[e.jsx(wn,{body:Ae.offlineBody}),J?e.jsx(Wt,{warn:!0,role:"alert",lead:e.jsx(z,{name:"warning",className:"mt-px size-4 text-attention"}),children:e.jsx("b",{className:"font-semibold",children:J})}):e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:Ae.loading})]})]})}const j=Nd(h),y=h.kernel.state,b=j?xn(j):"stopped",M=s.graphs[Ms],S=((O=a.device)==null?void 0:O.contextNear)??70,$=!!((V=a.device)!=null&&V.confirm),v=Dl(s.runs,J=>J.subject.kind==="act"&&/^(kernel|daemon)\./.test(J.subject.action.kind)),A=Ya(v),R=d&&!A,_=J=>{t.act(J)},L=[...a.sessions.values()],T=Br(h),B=h.daemon.state==="running",E=y==="ready"||y==="starting",P=((X=(Z=s.goals)==null?void 0:Z.data)==null?void 0:X.goals)??[],W=y==="stopped"?e.jsxs(Wt,{lead:e.jsx("span",{className:"mt-[5px]",children:e.jsx(ze,{state:"off"})}),children:[e.jsx("span",{children:e.jsx("b",{className:"font-semibold",children:jt.stoppedTitle})}),e.jsx("span",{className:"text-muted",children:jt.stoppedBody}),e.jsx("button",{type:"button",disabled:!R||!B,onClick:()=>_({kind:"kernel.start"}),className:be({tone:"primary",size:"sm",className:"self-start"}),children:e.jsx(Ft,{icon:"power",children:jt.startKernel})})]}):y==="skipped"?e.jsxs(Wt,{lead:e.jsx("span",{className:"mt-[5px]",children:e.jsx(ze,{state:"off"})}),children:[e.jsx("span",{children:e.jsx("b",{className:"font-semibold",children:jt.skippedTitle})}),e.jsx("span",{className:"text-muted",children:jt.skippedBody})]}):null,F=P.find(J=>Ea(J)!==null),re=F?Au(F):null,Y=P.find(J=>J.state!=="done"&&J.state!=="closed"),H=e.jsx("a",{href:ce({name:"max"}),className:be({tone:"primary",className:"w-full"}),children:jt.talk}),I=o&&Y?e.jsxs(e.Fragment,{children:[e.jsx(It,{children:`${jt.max} · ${Y.text}`}),e.jsx(Ve,{children:e.jsxs("div",{className:"flex flex-col gap-2.5 p-3",children:[e.jsx(Lu,{goal:Y,runs:s.runs,rigs:t,pc:g,compact:!0,asks:a.asks}),e.jsx(Ou,{goalId:Y.goalId,rigs:t,live:d})]})})]}):e.jsx(Ve,{children:e.jsxs("div",{className:"flex flex-col gap-2 p-3",children:[F&&e.jsx("span",{className:"text-[12px] text-muted",children:jt.lastMessage(re?Ke(vn(re)):null)}),F&&e.jsx("span",{className:"text-[13.5px] leading-[19px] [overflow-wrap:anywhere]",children:Ea(F)}),H]})}),D=J=>{var Xe;const pe=(Xe=s.permissions[J])==null?void 0:Xe.data,Ne=pe?$d(pe.seats):null;return Ne?Ae.level[Ne]:""},Q=T.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(It,{children:jt.driven}),e.jsx(Ve,{children:T.map(J=>{const pe=xn(J),Ne=wd(J,vd(J.name,L,a.asks));return e.jsxs("a",{href:ce({name:"rig",rig:J.name}),className:"flex min-h-[46px] items-center gap-2.5 border-b border-line px-3 py-1.5 text-[13.5px] last:border-b-0",children:[e.jsx(ze,{state:Ne}),e.jsx("span",{className:`min-w-0 flex-1 truncate ${pe==="stopped"?"text-muted":""}`,children:J.name}),e.jsx("span",{className:"text-[12px] text-muted",children:pe==="stopped"?Ae.seatState.off:[Ae.seatCount(J.seats),D(J.name)].filter(Boolean).join(" · ")}),e.jsx(z,{name:"chevron",className:"size-4 text-muted"})]},J.id)})})]}),q=(J,pe)=>e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{type:"button",disabled:!R,onClick:J,className:be({}),children:e.jsx(Ft,{icon:"refresh",children:Ae.actions.restart})}),e.jsx("button",{type:"button",disabled:!R,onClick:pe,className:be({tone:"danger"}),children:e.jsx(Ft,{icon:"power",children:Ae.actions.stop})})]}),K=E&&e.jsxs(e.Fragment,{children:[e.jsx(It,{children:Ae.kernel}),e.jsx(Ve,{children:e.jsxs("div",{className:"flex flex-col gap-2 p-3",children:[e.jsx("span",{className:"text-[12.5px] leading-[18px] text-muted",children:Ae.confirm.kernelNote}),q(()=>m("kernel.restart"),()=>m("kernel.stop"))]})})]}),ee=e.jsxs(e.Fragment,{children:[e.jsx(It,{children:Ae.daemon}),e.jsxs(Ve,{children:[e.jsx(Fl,{state:h}),e.jsx(Eu,{disabled:!d,next:!0}),B&&e.jsx("div",{className:"px-3 pt-2.5 pb-3",children:q(()=>m("daemon.restart"),()=>m("daemon.stop"))})]}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:jt.daemonNote})]}),ue=T.flatMap(J=>Ig(J)).length,fe=T.filter(J=>xn(J)!=="stopped").length,he=[Ae.confirm.daemonStops(fe),ue?Ae.confirm.working(ue):""].filter(Boolean).join(" "),w=()=>m(null);return e.jsxs(e.Fragment,{children:[k(e.jsx(us,{tone:Mu[y],children:Ae.kernelState[y]})),e.jsxs("main",{"data-tab-scroll":"",className:N,children:[e.jsx(wn,{body:Ae.offlineBody}),v&&e.jsx(Ca,{run:v,rigs:t,pc:g}),e.jsxs("div",{className:`flex flex-col gap-3 ${o?"max-w-[720px]":""} ${x?"opacity-50":""}`,children:[W,e.jsx("p",{className:"text-[12.5px] leading-[18px] text-muted",children:jt.role}),E&&(M!=null&&M.data?e.jsx(yy,{graph:M.data,status:b,near:S}):e.jsx(Ve,{children:e.jsx("p",{role:M!=null&&M.error?"alert":"status",className:"p-3 text-[13px] text-muted",children:M!=null&&M.error?Ae.readError[M.error]:Ae.loading})})),E&&I,Q,e.jsx(Ny,{rigs:t}),K,ee]})]}),i==="menu"&&e.jsx(Y1,{live:d,up:E&&!A,onClose:w,onRefresh:()=>{w(),C()},onRestart:()=>m("kernel.restart"),onStop:()=>m("kernel.stop")}),i==="kernel.restart"&&e.jsx(aa,{title:Ae.confirm.restartKernel(g),conseq:{title:Ae.confirm.kernelNote},verb:Ae.actions.restart,confirm:$,live:R,onConfirm:()=>_({kind:"kernel.restart"}),onClose:w}),i==="kernel.stop"&&e.jsx(aa,{title:Ae.confirm.stopKernel(g),conseq:{title:Ae.confirm.kernelNote},verb:Ae.actions.stop,confirm:$,live:R,onConfirm:()=>_({kind:"kernel.stop"}),onClose:w}),i==="daemon.restart"&&e.jsx(aa,{title:Ae.confirm.restartDaemon(g),conseq:{title:he},verb:Ae.actions.restart,confirm:$,live:R,onConfirm:()=>_($u("restart",c)),onClose:w}),i==="daemon.stop"&&e.jsx(aa,{title:Ae.confirm.stopDaemon(g),conseq:{title:he},verb:Ae.actions.stop,confirm:$,live:R,onConfirm:()=>_({kind:"daemon.stop"}),onClose:w})]})}const ae=u.launch,vy=["claude","codex","cursor","omp"],wy=["always-ask","write","yolo"],Sy=2e4,Bn={project:`${Nn}launch.project`,prefs:`${Nn}launch.prefs`,draft:`${Nn}launch.draft`},Zr=(t,n)=>{try{return(t==null?void 0:t.getItem(n))??null}catch{return null}},ra=(t,n,s)=>{try{s===null?t==null||t.removeItem(n):t==null||t.setItem(n,s)}catch{}};function yi(t){try{const n=JSON.parse(Zr(t,Bn.prefs)??"{}");return n&&typeof n=="object"?n:{}}catch{return{}}}const Ni=t=>t.replace(/\/+$/,"").split("/").pop()||t,Du=t=>t.machine==="local",ki=t=>Du(t)&&t.exists!==!1;function vi({store:t,storage:n}){var qe,et,vt,Vt,tn,Gt,Xt;const s=xe(t),a=Ze(n),r=Jt(zt().pc??((qe=s.daemon)==null?void 0:qe.name)??null),l=s.projects,[o,c]=f.useState(()=>Zr(a,Bn.project)),i=l.find(U=>U.id===o)??l[0],m=yi(a),d=i?m[i.id]:void 0,[x,p]=f.useState((d==null?void 0:d.tool)??"claude"),[g,h]=f.useState({model:(d==null?void 0:d.model)??null,effort:(d==null?void 0:d.effort)??null}),[N,k]=f.useState("always-ask"),[C,j]=f.useState(null),[y,b]=f.useState(()=>Zr(a,Bn.draft)??""),[M,S]=f.useState(null),[$,v]=f.useState(!1),[A,R]=f.useState(!1),[_,L]=f.useState(null),[T,B]=f.useState(null),E=f.useId(),[P,W]=f.useState(!1),[F,re]=f.useState(""),Y=f.useId(),H=f.useRef(null),I=f.useRef(!1);f.useEffect(()=>{var U;P&&I.current&&((U=H.current)==null||U.focus())},[P]);const D=i==null?void 0:i.id;f.useEffect(()=>{D&&s.fresh&&t.requestProjectFolders(D)},[D,s.fresh,t]),f.useEffect(()=>{var U;s.fresh&&((U=s.daemon)!=null&&U.models)&&t.requestModels(x)},[x,s.fresh,(et=s.daemon)==null?void 0:et.models,t]);const Q=D?s.projectFolders[D]:void 0,q=Array.isArray(Q)?Q:[],K=q.find(ki),ee=(C??(K?[K.path]:[])).filter(U=>q.some(Se=>Se.path===U&&ki(Se))),ue=Ql.includes(x),fe=((vt=s.models[x])==null?void 0:vt.models)??[],he=U=>{U(),L(null),R(!1)},w=U=>he(()=>{c(U.id),ra(a,Bn.project,U.id),j(null);const Se=m[U.id];p((Se==null?void 0:Se.tool)??"claude"),h({model:(Se==null?void 0:Se.model)??null,effort:(Se==null?void 0:Se.effort)??null}),S(null)}),O=U=>he(()=>{p(U),h({model:null,effort:null}),!Ql.includes(U)&&ee.length>1&&j(ee.slice(0,1))}),V=U=>he(()=>{if(!ue){j([U]),S(null);return}const ie=ee.includes(U)?ee.filter(Ie=>Ie!==U):[...ee,U];j(ie.length?ie:ee)}),Z=U=>{b(U),ra(a,Bn.draft,U),L(null),R(!1)},X=T?s.ops[T]:void 0,[J,pe]=f.useState(0);f.useEffect(()=>{if(!T)return;const U=setTimeout(()=>{const Se=t.getState().ops[T];Se&&yn(Se.phase)&&(v(!1),L({kind:"timeout",op:T}))},Sy);return()=>clearTimeout(U)},[T,J,t]),f.useEffect(()=>{if(!T||!X||yn(X.phase))return;if(v(!1),B(null),X.phase==="applied"){ra(a,Bn.draft,null),i&&ra(a,Bn.prefs,JSON.stringify({...yi(a),[i.id]:{tool:x,model:g.model,effort:g.effort}})),X.id?(Kh(X.id,(i==null?void 0:i.name)??"",n),An({name:"thread",sessionId:X.id})):An({name:"sessions"});return}if(X.phase==="failed"){L({kind:"failed"});return}const U=X.reason??"other";U==="stale"&&D&&t.requestProjectFolders(D),L({kind:"refused",reason:U})},[T,X==null?void 0:X.phase]);const Ne=async()=>{if(!i)return;const U={project:i.id,tool:x,folders:ee,prompt:y.trim(),...oe?{name:oe}:{},...g.model?{model:g.model}:{},...g.effort?{effort:g.effort}:{},...x==="omp"&&N!=="always-ask"?{approval:N}:{}};v(!0),L(null),R(!1);const Se=await t.launchSession(U);if(Se.status==="sent"){B(Se.op),pe(ie=>ie+1);return}v(!1),Se.status==="cancelled"?R(!0):Se.status==="noAnswer"?L({kind:"timeout",op:null}):Se.status==="failed"?L({kind:"refused",reason:"other"}):L({kind:"refused",reason:Se.reason})},Xe=U=>{if(U.kind==="timeout"&&U.op){if(t.launchAgain(U.op)){B(U.op),pe(ie=>ie+1),v(!0),L(null);return}const Se=t.getState().ops[U.op];if(Se&&yn(Se.phase)){L({...U});return}}Ne()},gt=U=>U.kind==="timeout"&&U.op!==null&&!!s.ops[U.op]&&yn(s.ops[U.op].phase)&&!t.canLaunchAgain(U.op),Be=[...s.sessions.values()].filter(U=>U.state!=="exited"),Je=P?F:"",oe=wx(Je),de=Sx(Yl(Be),Je)!==void 0,ke=de?Cx(Be,Je):void 0,Oe=de?ke?ke.name.toLowerCase()===oe.toLowerCase()&&ke.project?ae.nameTaken(oe,ke.project):ae.nameTakenBy(oe,ke.name):ae.nameReserved:null,lt=u.tools[x],xt=!s.fresh,kt=xt?{label:ae.missing.machine}:(Vt=s.daemon)!=null&&Vt.launch?(tn=s.device)!=null&&tn.confirm?!i||ee.length===0?{label:ae.chooseProject}:de?{label:ae.missing.name}:y.trim()===""?{label:ae.missing.prompt}:null:{label:ae.missing.setup,body:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ae.setupBody}),e.jsxs("a",{href:"#/connection/link",className:rt({size:"sm",className:"self-start"}),children:[e.jsx(z,{name:"gear",className:"size-4"}),ae.openSettings]})]})}:{label:ae.missing.pcOld(r),body:e.jsx("span",{className:"text-center text-[12px] leading-4 text-muted",children:ae.pcOldBody})},ct=_&&!(xt&&_.kind==="timeout")?_:null,mt=g.model===null?null:((Gt=fe.find(U=>U.id===g.model))==null?void 0:Gt.label)??g.model,G=g.model===null?u.model.byDefault:ae.pick(mt,g.effort?Ws(g.effort):null),_e=g.model===null?u.model.defaultHint:(()=>{const U=fe.find(Se=>Se.id===g.model);return U?qc(x,U):void 0})(),we=q.find(U=>U.path===ee[0]),le=we?we===q[0]?we.branch?ae.onBranch(we.branch):ae.inFolder:Ni(we.path):void 0,ge=we&&we!==q[0]?we.branch??void 0:void 0;return e.jsxs(e.Fragment,{children:[e.jsx(La,{back:e.jsx("button",{type:"button","aria-label":ae.close,title:ae.close,onClick:()=>Aa({name:"sessions"}),className:Ot({className:"text-muted"}),children:e.jsx(z,{name:"close"})}),name:ae.title}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col gap-3.5 overflow-y-auto overscroll-contain pt-3.5 pb-4",children:[e.jsx(zn,{label:ae.project,aside:l.length>0?e.jsxs("button",{type:"button",role:"switch","aria-checked":P,onClick:()=>he(()=>{I.current=!0,W(U=>!U)}),className:"-my-1 inline-flex items-center gap-2 rounded-lg px-1.5 py-1 text-[13px] text-fg",children:[e.jsx("span",{"aria-hidden":"true",className:`relative inline-block h-[17px] w-[30px] flex-none rounded-full border ${P?"border-transparent bg-primary":"border-input bg-raised"}`,children:e.jsx("span",{className:`absolute top-[2px] size-[11px] rounded-full transition-all ${P?"left-[15px] bg-white":"left-[2px] bg-muted"}`})}),ae.nameToggle]}):void 0,children:l.length===0?e.jsxs("p",{className:"text-body text-muted",children:[u.launch.noProjects," ",ae.noProjectsBody]}):e.jsx(Nr,{onClick:()=>S("project"),lead:i?e.jsx(ze,{state:xt?"off":"idle"}):null,label:ae.project,text:i?e.jsx("b",{className:"font-semibold",children:i.name}):ae.chooseProject,sub:i?[r,xt?ae.offline:d?ae.remembered:null].filter(Boolean).join(" · "):void 0,dim:xt})}),P&&l.length>0&&e.jsxs(zn,{label:ae.name,htmlFor:Y,children:[e.jsx("input",{id:Y,ref:H,type:"text",value:F,placeholder:ae.namePlaceholder($x(Yl(Be))),spellCheck:!1,autoComplete:"off",autoCapitalize:"off","aria-invalid":de||void 0,"aria-describedby":`${Y}-say`,onChange:U=>{const Se=U.target.value;he(()=>re(Se))},className:`h-12 rounded-lg border bg-surface px-3 text-[15px] outline-none placeholder:text-muted focus:border-ring focus:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)] ${de?"border-danger-fg":"border-input"}`}),Oe?e.jsx("span",{id:`${Y}-say`,role:"alert",className:"text-[12px] leading-4 text-danger-fg",children:Oe}):e.jsx("span",{id:`${Y}-say`,className:`text-[12px] leading-4 ${oe&&oe!==Je?"text-fg":"text-muted"}`,children:oe&&oe!==Je?ae.nameCleaned(oe):ae.nameHint})]}),i&&e.jsx(zn,{label:ae.where,children:e.jsx(Nr,{onClick:()=>S("where"),lead:e.jsx(z,{name:we!=null&&we.branch?"branch":"folder",className:"size-4 text-muted"}),label:ae.where,text:ee.length>1&&le?e.jsxs(e.Fragment,{children:[e.jsxs("span",{"aria-hidden":"true",children:[le,e.jsx("span",{className:"ml-1.5 font-mono text-small text-muted",children:ae.more(ee.length-1)})]}),e.jsx("span",{className:"sr-only",children:ae.moreLabel(le,ee.length-1)})]}):le??"",sub:ge})}),e.jsx(zn,{label:ae.agent,children:e.jsx("div",{role:"group","aria-label":ae.agent,className:"grid grid-cols-2 gap-2",children:vy.map(U=>e.jsxs("button",{type:"button","aria-pressed":U===x,onClick:()=>O(U),className:"flex flex-col items-start gap-0.5 rounded-lg border border-input px-[11px] py-[9px] text-left text-[13.5px] font-medium aria-pressed:border-ring aria-pressed:bg-raised aria-pressed:shadow-[inset_0_0_0_1px_var(--color-ring)]",children:[u.tools[U],e.jsx("small",{className:"text-[11.5px] font-normal text-muted",children:ae.tools[U]})]},U))})}),e.jsx(zn,{label:ae.model,children:e.jsx(Nr,{onClick:()=>S("model"),lead:e.jsx(z,{name:"cpu",className:"size-4 text-muted"}),label:ae.model,text:G,sub:_e})}),x==="omp"&&e.jsxs(zn,{label:ae.permissions,children:[e.jsx(Na,{name:"launch-approval",legend:ae.permissions,value:N,onChange:U=>he(()=>k(U)),options:wy.map(U=>({value:U,label:ae.approvals[U][0]}))}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ae.approvals[N][1]})]}),e.jsxs(zn,{label:ae.message,htmlFor:E,children:[e.jsx("textarea",{id:E,value:y,onChange:U=>Z(U.target.value),placeholder:ae.placeholder,rows:4,className:"min-h-[92px] resize-none rounded-lg border border-input bg-surface px-3 py-2.5 text-[15px] leading-[22px] outline-none placeholder:text-muted focus:border-ring focus:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)]"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:ae.ideas.map(U=>e.jsx("button",{type:"button",onClick:()=>Z(U),className:"h-8 rounded-lg border border-dashed border-input px-2.5 text-[12.5px] text-muted",children:U},U))})]})]}),e.jsxs("div",{className:"bleed flex flex-none flex-col gap-1.5 border-t border-line bg-bg px-3.5 pt-2.5 pb-[calc(14px+var(--foot-inset))]",children:[ct&&e.jsx(Cy,{outcome:ct,agent:lt,machine:r,taken:Oe??ae.missing.name,onRetry:gt(ct)?null:()=>Xe(ct)}),kt?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:!0,className:rt({variant:"primary",className:"w-full"}),children:kt.label}),kt.body]}):e.jsx("button",{type:"button",disabled:$,onClick:()=>void Ne(),className:rt({variant:"primary",className:"w-full"}),children:$?e.jsxs(e.Fragment,{children:[e.jsx(z,{name:"spinner",className:"size-4 motion-safe:animate-spin"}),ae.launching]}):e.jsxs(e.Fragment,{children:[Pt()&&e.jsx(z,{name:"face",className:"size-[18px]"}),Pt()?ae.launchCheck:ae.launchDevice]})}),A&&e.jsx("span",{role:"status",className:"text-center text-[12px] leading-4 text-destructive",children:ae.cancelled}),!kt&&i&&e.jsx("span",{className:"text-center text-[12px] leading-4 text-muted",children:ae.summary(lt,mt,r,i.name)})]}),M==="project"&&e.jsxs(ht,{labelledBy:"launch-project",onClose:()=>S(null),children:[e.jsx("h2",{id:"launch-project",className:"text-base font-semibold",children:ae.project}),e.jsx(wi,{children:l.map(U=>e.jsx(Si,{on:U.id===(i==null?void 0:i.id),onClick:()=>w(U),lead:e.jsx(ze,{state:xt?"off":"idle"}),text:U.name,sub:xt?`${r} · ${ae.offline}`:r},U.id))})]}),M==="where"&&i&&e.jsxs(ht,{labelledBy:"launch-where",onClose:()=>S(null),children:[e.jsxs("div",{children:[e.jsx("h2",{id:"launch-where",className:"text-base font-semibold",children:ae.where}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ae.folders(i.name)})]}),e.jsx(wi,{children:q.map((U,Se)=>{const ie=Du(U)?U.exists===!1?ae.folder.missing(r):null:ae.folder.elsewhere(U.label??U.machine,r);return e.jsx(Si,{on:ee.includes(U.path),disabled:ie!==null,onClick:()=>V(U.path),lead:e.jsx(z,{name:ie===null&&U.branch?"branch":"folder",className:"size-5 text-muted"}),text:Se===0?ae.projectFolder:Ni(U.path),sub:ie??U.branch??void 0},`${U.machine}:${U.path}`)})}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ae.folder.single})]}),M==="model"&&e.jsx(ht,{labelledBy:gl,onClose:()=>S(null),children:e.jsx(Gc,{tool:x,models:fe,error:(Xt=s.models[x])==null?void 0:Xt.error,pick:g,onPick:U=>he(()=>h(U)),actions:e.jsx("button",{type:"button",onClick:()=>S(null),className:rt({variant:"primary",className:"w-full"}),children:ae.done})})})]})}function zn({label:t,htmlFor:n,aside:s,children:a}){const r=n?"label":"span",l=e.jsx(r,{...n?{htmlFor:n}:{},className:"text-[12px] font-medium text-muted",children:t});return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[s?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[l,s]}):l,a]})}function Nr({onClick:t,lead:n,text:s,sub:a,dim:r=!1}){return e.jsxs("button",{type:"button","aria-haspopup":"dialog",onClick:t,className:`flex min-h-12 w-full items-center gap-2.5 rounded-lg border border-input bg-surface px-3 py-1.5 text-left ${r?"opacity-60":""}`,children:[n,e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate text-body",children:s}),a&&e.jsx("small",{className:"truncate text-[12px] text-muted",children:a})]}),e.jsx(z,{name:"down",className:"size-4 text-muted"})]})}function wi({children:t}){return e.jsx("div",{className:"flex max-h-[50vh] flex-col overflow-y-auto rounded-[10px] border border-line",children:t})}function Si({on:t,disabled:n=!1,onClick:s,lead:a,text:r,sub:l}){return e.jsxs("button",{type:"button","aria-pressed":t,disabled:n,onClick:s,className:"flex min-h-12 items-center gap-3 border-b border-line px-3.5 py-1.5 text-left text-[15px] last:border-b-0 aria-pressed:bg-raised disabled:opacity-45",children:[a,e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate",children:r}),l&&e.jsx("small",{className:"truncate text-[12px] text-muted",children:l})]}),t&&e.jsx(z,{name:"check",className:"size-4"})]})}function Cy({outcome:t,agent:n,machine:s,taken:a,onRetry:r}){const l={label:ae.retry,onClick:r??(()=>{})};if(t.kind==="timeout")return r?e.jsx(at,{tone:"warn",title:ae.timeout,body:ae.timeoutBody,action:l}):e.jsx(at,{tone:"warn",title:ae.timeout,body:ae.lostBody,action:{label:u.cards.seeSessions,href:ce({name:"sessions"})}});if(t.kind==="failed")return e.jsx(at,{tone:"fail",title:ae.failed(n),body:ae.failedBody(n),action:l});const o=ae.refused;switch(t.reason){case"not_found":return e.jsx(at,{tone:"fail",title:o.not_found,body:ae.kept});case"invalid":return e.jsx(at,{tone:"fail",title:o.invalid,body:o.invalidBody(n)});case"stale":return e.jsx(at,{tone:"fail",title:o.stale,body:o.staleBody});case"confirm_required":return e.jsx(at,{tone:"fail",title:o.confirm_required,body:o.setupKept,action:{label:ae.settings,href:"#/connection/link"}});case"assertion_invalid":return e.jsx(at,{tone:"fail",title:o.assertion_invalid,body:ae.kept,action:l});case"assertion_expired":return e.jsx(at,{tone:"warn",title:o.assertion_expired,body:o.expiredBody,action:l});case"unavailable":return e.jsx(at,{tone:"warn",title:o.unavailable(s),body:o.unavailableBody});case"name_taken":return e.jsx(at,{tone:"fail",title:a});default:return e.jsx(at,{tone:"fail",title:o.other,body:ae.kept})}}const Jr="ledge.mobile.forge",$y=35e3,My=65e3,Pl=(t,n)=>n?`${t}
|
|
21
|
+
${n}`:t,ua=t=>t!=="checking"&&t!=="sending"&&t!=="received",kr=t=>!!t&&(!ua(t.phase)||t.phase==="uncertain"&&!t.lost),Ci=new Set(["assertion_invalid","assertion_expired","confirm_required","conflict"]);function Ey(t){var n;try{const s=(n=Ze(t))==null?void 0:n.getItem(Jr);if(!s)return null;const a=JSON.parse(s),r=Mx.safeParse(a.state);return r.success&&typeof a.at=="string"?{state:r.data,at:a.at}:null}catch{return null}}function _y(t,n,s){var H;const a=Ey(s);let r={state:(a==null?void 0:a.state)??null,at:(a==null?void 0:a.at)??null,loading:!1,details:{},runs:[],drafts:{}};const l=new Set,o=I=>{r={...r,...I};for(const D of[...l])D()};let c=!1,i=!1,m=!1;const d=new Map,x=new Map,p=new Map;let g=0,h=n.getState().daemon?((H=n.getState().daemon)==null?void 0:H.boot)??null:void 0;const N=new Set,k=()=>!c&&t.state()==="ready",C=()=>{var I;return!!((I=n.getState().daemon)!=null&&I.forge)},j=I=>{t.send(I).catch(()=>{})},y=(I,D,Q)=>{clearTimeout(d.get(I)),d.set(I,setTimeout(()=>{d.delete(I),Q()},D))},b=I=>{clearTimeout(d.get(I)),d.delete(I)};function M(){m||!i||!k()||!C()||(m=!0,j({type:"forge.state"}),o({loading:!0}),y("state",$y,()=>{m=!1,o({loading:!1})}))}const S=I=>r.runs.find(D=>D.op===I);function $(I,D){const Q=r.runs.findIndex(K=>K.id===I);if(Q<0)return;const q=D(r.runs[Q]);if(o({runs:r.runs.map((K,ee)=>ee===Q?q:K)}),ua(q.phase)){q.op&&q.phase!=="uncertain"&&x.delete(q.op);const K=p.get(I);p.delete(I),K==null||K(q)}}const v=I=>I.sentAt!==void 0&&Date.now()-I.sentAt<Wi&&h!==void 0&&(I.boot??null)===h,A=I=>{b(`op:${I.op}`),x.delete(I.op),$(I.id,D=>({...D,phase:"uncertain",lost:!0,endedAt:D.endedAt??Date.now()}))};function R(I){for(const[D,Q]of[...x]){const q=S(D);if(!q){x.delete(D);continue}if(!I.has(D)){if(!v(q)){A(q);continue}$(q.id,K=>({...K,again:!0})),j(Q),q.phase==="sending"&&L(D)}}}const _=(I,D)=>{b(`op:${I}`);const Q=S(I);Q&&kr(Q)&&$(Q.id,q=>({...q,...D,endedAt:Date.now()}))},L=I=>y(`op:${I}`,Ki,()=>{const D=S(I);(D==null?void 0:D.phase)==="sending"&&$(D.id,Q=>({...Q,phase:"uncertain",endedAt:Date.now()}))});function T(I){var D,Q,q;switch(I.type){case"snapshot":{const K=h;h=I.daemon.boot??null;const ee=new Set(N);N.clear();for(const ue of ee){const fe=S(ue);fe&&$(fe.id,he=>({...he,boot:h}))}(K===void 0||K!==h)&&R(ee),M();return}case"forge.state":{b("state");const K=new Date().toISOString(),ee={prs:I.prs,forges:I.forges,followed:I.followed,...I.mine?{mine:I.mine}:{}},ue=Object.keys(r.details).filter(fe=>{var O,V,Z;const he=(V=(O=r.details[fe])==null?void 0:O.data)==null?void 0:V.pr.headSha,w=(Z=[...ee.prs,...ee.mine??[]].find(X=>X.id===fe))==null?void 0:Z.headSha;return he&&w&&he!==w});o({state:ee,at:K,loading:!1});try{(D=Ze(s))==null||D.setItem(Jr,JSON.stringify({state:ee,at:K}))}catch{}for(const fe of ue)Y.readDetail(fe);return}case"forge.detail":{b(`detail:${I.prId}`);const K=r.details[I.prId];if(I.detail){const ee=I.detail.log??((Q=K==null?void 0:K.data)!=null&&Q.log&&I.detail.jobs.some(ue=>ue.id===K.data.log.jobId)?K.data.log:void 0);o({details:{...r.details,[I.prId]:{data:{...I.detail,...ee?{log:ee}:{}},...I.cut?{cut:!0}:{},loading:!1,at:new Date().toISOString()}}})}else o({details:{...r.details,[I.prId]:{...K,loading:!1,error:I.error??"failed"}}});return}case"operation.result":{const K=S(I.op);if(!K||!kr(K))return;if(I.status==="received"){b(`op:${I.op}`),(K.phase==="sending"||K.phase==="uncertain")&&$(K.id,ee=>{const{endedAt:ue,...fe}=ee;return{...fe,phase:"received"}});return}if(I.status==="rejected"&&K.again&&Ci.has(I.reason??"")){A(K);return}I.status==="rejected"&&_(I.op,{phase:"rejected",reason:I.reason??"invalid"});return}case"forge.done":{const K=S(I.op);if(!K)return;if(K.again&&I.rejected&&Ci.has(I.rejected)){K.lost||A(K);return}const ee=I.rejected?{phase:"rejected",reason:I.rejected,done:I}:{phase:"done",done:I,...I.error?{reason:I.error}:{}};if(K.lost)x.delete(K.op),$(K.id,ue=>{const{lost:fe,...he}=ue;return{...he,...ee,endedAt:Date.now()}});else{const ue=kr(K);_(I.op,ee),ue||$(K.id,fe=>({...fe,done:I}))}if(I.ok&&(K.action.kind==="comment"||K.action.kind==="reply")){const ue=Pl(K.prId,K.action.kind==="reply"?K.action.threadId:void 0);if(((q=r.drafts[ue])==null?void 0:q.trim())===K.action.body){const{[ue]:fe,...he}=r.drafts;o({drafts:he})}}r.details[K.prId]&&Y.readDetail(K.prId);return}}}let B=k();const E=t.subscribe(()=>{const I=t.state();(I==="unpaired"||I==="pairing")&&W();const D=k();if(D&&!B)B=!0,g++,m=!1,h=void 0,N.clear();else if(!D&&B){B=!1,m=!1;for(const[q,K]of d)clearTimeout(K),d.delete(q);const Q=Object.fromEntries(Object.entries(r.details).map(([q,K])=>[q,K.loading?{...K,loading:!1}:K]));o({loading:!1,details:Q});for(const q of r.runs)q.phase==="sending"&&q.op&&$(q.id,K=>({...K,phase:"uncertain",endedAt:Date.now()}))}}),P=t.onMessage(T);function W(){var I;if(!(!r.state&&!r.runs.length&&!Object.keys(r.details).length&&!Object.keys(r.drafts).length)){try{(I=Ze(s))==null||I.removeItem(Jr)}catch{}x.clear(),o({state:null,at:null,loading:!1,details:{},runs:[],drafts:{}})}}async function F(I){var K;if(!((K=n.getState().device)!=null&&K.confirm))return{phase:"rejected",reason:"confirm_required"};let D;try{D=await n.prepareConfirm(I)}catch(ee){return{phase:ee instanceof Error&&ee.message==="timeout"?"expired":"unsent"}}if(!D.credentialId)return{phase:"rejected",reason:"confirm_required"};const Q=Date.now(),q=await Fs({challenge:D.challenge,rpId:D.rpId,credentialId:D.credentialId}).catch(()=>"failed");return q==="cancelled"?{phase:"cancelled"}:q==="failed"?{phase:"unsent"}:Date.now()-Q>=D.expiresInMs?{phase:"expired"}:{assertion:q}}async function re(I,D,Q){var ue;L(D);const q=g,K=await t.send(Q).catch(()=>!1),ee=(ue=S(D))==null?void 0:ue.phase;!K&&q===g&&(ee==="sending"||ee==="uncertain")&&(b(`op:${D}`),$(I,fe=>({...fe,phase:"unsent",endedAt:Date.now()})))}const Y={getState:()=>r,subscribe(I){return l.add(I),()=>{l.delete(I)}},follow(){i=!0,M()},readDetail(I,D){!k()||!C()||(j({type:"forge.detail",prId:I,...D?{log:D}:{}}),o({details:{...r.details,[I]:{...r.details[I],loading:!0}}}),y(`detail:${I}`,My,()=>o({details:{...r.details,[I]:{...r.details[I],loading:!1,error:"failed"}}})))},act(I,D){const Q=crypto.randomUUID(),q={op:"",id:Q,prId:I,action:D,phase:"checking",startedAt:Date.now()};if(!k()||!C()){const ee={...q,phase:"unsent",endedAt:Date.now()};return o({runs:[...r.runs,ee]}),Promise.resolve(ee)}const K=new Promise(ee=>p.set(Q,ee));return o({runs:[...r.runs,q]}),(async()=>{const ee=await F({purpose:"forge",forge:{prId:I,action:D}});if(!("assertion"in ee)){$(Q,he=>({...he,phase:ee.phase,...ee.reason?{reason:ee.reason}:{},endedAt:Date.now()}));return}const ue=Ui(),fe=Pi.safeParse({type:"forge.act",op:ue,prId:I,action:D,assertion:ee.assertion});if(!fe.success||!k()){$(Q,he=>({...he,phase:"unsent",endedAt:Date.now()}));return}x.set(ue,fe.data),h===void 0&&N.add(ue),$(Q,he=>({...he,op:ue,phase:"sending",sentAt:Date.now(),boot:h??null})),await re(Q,ue,fe.data)})(),K},resend(I){const D=r.runs.find(q=>q.id===I),Q=D!=null&&D.op?x.get(D.op):void 0;if(!(!D||D.phase!=="uncertain"||D.lost||!Q||!k())){if(!v(D)){A(D);return}$(I,q=>{const{endedAt:K,...ee}=q;return{...ee,phase:"sending",again:!0}}),re(I,D.op,Q)}},setDraft(I,D){if(D)o({drafts:{...r.drafts,[I]:D}});else{const{[I]:Q,...q}=r.drafts;o({drafts:q})}},dismiss(I){const D=r.runs.find(Q=>Q.id===I);D&&ua(D.phase)&&D.op&&x.delete(D.op),o({runs:r.runs.filter(Q=>Q.id!==I||!ua(Q.phase))})},close(){c=!0,E(),P();for(const I of d.values())clearTimeout(I);d.clear()}};return Y}function Qa(t){return f.useSyncExternalStore(t.subscribe,t.getState,t.getState)}const Le=u.prs;function Ry({status:t,pc:n}){const[s,a]=f.useState(!1),r=en(t),l=e.jsx(z,{name:"warning",className:"mt-px size-4 text-attention"});if(t.status==="missing")return e.jsx(Wt,{warn:!0,role:"alert",lead:l,children:e.jsx("span",{"data-forge-strip":"missing",children:Le.missing(r.cli,n,t.host,r.kind)})});if(t.status==="unauthenticated"){const i=mg(t);return e.jsxs(Wt,{warn:!0,role:"alert",lead:l,children:[e.jsx("b",{"data-forge-strip":"unauthenticated",className:"font-semibold",children:Le.unauth(r.cli,t.host,n)}),e.jsx("code",{className:"block rounded-md bg-raised px-2 py-1.5 font-mono text-[12px] break-all",children:i}),e.jsx("button",{type:"button",className:be({size:"sm",className:"self-start"}),onClick:()=>{var m;(m=navigator.clipboard)==null||m.writeText(i).then(()=>a(!0),()=>{})},children:s?Le.copied:Le.copy})]})}const o=t.since??t.at,c=[t.retryAt?Le.retryAt(Ke(t.retryAt)):"",t.readAt?Le.readAt(r.kind,Ke(t.readAt)):""].filter(Boolean).join(" ");return e.jsx(Wt,{warn:!0,role:"alert",lead:l,children:e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("b",{"data-forge-strip":"error",className:"font-semibold",children:Le.error(r.host,n,Ke(o))}),c&&e.jsx("span",{className:"text-muted",children:c})]})})}function Ty(){const t="block animate-[ledge-pulse_1.6s_ease-in-out_infinite] rounded-[5px] bg-raised";return e.jsxs("div",{role:"status","data-list-state":"",className:"flex flex-col gap-3",children:[e.jsx(Ve,{children:e.jsxs("div",{"aria-hidden":"true",className:"flex flex-col gap-2.5 p-2.5",children:[e.jsx("span",{className:`${t} h-3.5 w-[70%]`}),e.jsx("span",{className:`${t} h-3 w-[45%]`}),e.jsx("span",{className:`${t} h-3.5 w-[60%]`}),e.jsx("span",{className:`${t} h-3 w-1/2`})]})}),e.jsx("span",{className:"text-[12px] text-muted",children:Le.loading})]})}function Ay(t,n,s){const a=s!=null&&s.readAt?Le.asOf(Ke(s.readAt)):Le.state[t.state];return[Le.host[t.forge],Ml(t.repo),...n?[n]:[],a].join(" · ")}let $i={role:"all",q:""};function Mi({pr:t}){const n=t.roles??[];if(!n.length&&!t.sessions.length)return null;const s="rounded-[7px] border px-1.5 text-[11px] leading-4";return e.jsxs(e.Fragment,{children:[n.map(a=>e.jsx("span",{"data-role-pill":a,className:`${s} ${a==="reviewer"?"border-attention/50 text-attention":"border-line text-muted"}`,children:Le.pill[a]},a)),t.sessions.length>0&&e.jsx("span",{"data-role-pill":"tracked",className:`${s} border-task/45 text-task`,children:Le.pill.tracked})]})}function Iy({forge:t,store:n}){const s=Qa(t),a=xe(n),{pc:r,look:l}=zt(),o=Ps(),c=Dt(),[i,m]=f.useState(!0),[d,x]=f.useState(null),[p,g]=f.useState($i),h=M=>{$i=M,g(M)},N=l==="offline",k=Jt(r),C=s.state,j=M=>{var $;const S=M.sessions[0];return S?(($=a.sessions.get(S))==null?void 0:$.name)??null:null},y=M=>Le.offlineBody(s.at?Ke(s.at):M),b=(()=>{if(!C)return e.jsx(Ty,{});const M=xg(C.forges),S=F=>M.find(re=>re.forge===F.forge&&re.host===F.host),$=[...C.prs,...C.mine??[]],v={open:dg($).open.sort((F,re)=>re.updatedAt.localeCompare(F.updatedAt)),closed:Ex($,Date.now())},A=_x($),R=Zl(v.open,p.role,p.q),_=Zl(v.closed,p.role,p.q),L=p.role!=="all"||p.q.trim()!=="",T=`${p.role}
|
|
22
|
+
${p.q.trim()}`,B=L&&R.length===0&&_.length>0,E=B?d!==T:!i,P=C.forges.length>0&&M.length===C.forges.length,W="flex h-[30px] shrink-0 items-center gap-1.5 rounded-full border px-[11px] text-[12.5px]";return e.jsxs(e.Fragment,{children:[!N&&M.map(F=>e.jsx(Ry,{status:F,pc:k},`${F.forge}:${F.host}`)),e.jsxs("div",{className:`flex flex-col gap-3 ${N?"opacity-50":""}`,children:[v.open.length+v.closed.length>0&&e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsxs("label",{className:"flex h-9 items-center gap-2 rounded-[9px] border border-line px-2.5 text-muted focus-within:border-muted",children:[e.jsx(z,{name:"search",className:"size-3.5 shrink-0"}),e.jsx("input",{type:"search","aria-label":Le.search,placeholder:Le.search,value:p.q,onChange:F=>h({...p,q:F.target.value}),className:"min-w-0 flex-1 bg-transparent text-[13px] text-fg outline-none placeholder:text-muted"})]}),e.jsx("div",{role:"group","aria-label":Le.rolesLabel,className:"-mx-1 flex gap-1.5 overflow-x-auto px-1 [scrollbar-width:none]",children:Rx.map(F=>e.jsxs("button",{type:"button","aria-pressed":p.role===F,onClick:()=>h({...p,role:F}),className:`${W} ${p.role===F?"border-transparent bg-secondary text-fg":"border-line text-muted"}`,children:[Le.roles[F],e.jsx("span",{className:`font-mono text-[11px] ${F==="reviewer"?"text-attention":""}`,children:A[F]})]},F))})]}),B?null:R.length===0&&L?e.jsx(Ve,{children:e.jsxs("div",{"data-list-state":"none",className:"flex flex-col items-center gap-2.5 px-4 py-6 text-center text-[13px] text-muted",children:[e.jsx("b",{className:"font-medium text-fg",children:Le.none}),e.jsx("button",{type:"button",className:be({size:"sm"}),onClick:()=>h({role:"all",q:""}),children:Le.clear})]})}):R.length===0?e.jsx(Ve,{children:P?e.jsx(Rn,{framed:!1,glyph:null,title:Le.emptyTitle,body:Le.emptyUnread,list:_.length===0}):e.jsx(Rn,{glyph:e.jsx(z,{name:"pr",className:"size-[22px]"}),title:Le.emptyTitle,body:Le.emptyBody,list:_.length===0})}):e.jsxs(e.Fragment,{children:[e.jsx(It,{aside:!N&&s.at?Le.asOf(Ke(s.at)):void 0,children:Le.openHead(R.length)}),e.jsx(Ve,{label:Le.title,children:R.map(F=>{const re=S(F),Y=cg(F),H=e.jsxs(e.Fragment,{children:[e.jsx(Ad,{pipeline:F.pipeline}),!N&&!re&&F.openThreads>0&&e.jsx(Is,{children:Le.threads(F.openThreads)}),!N&&!re&&Y&&e.jsx(Is,{ok:!0,children:Le.ready})]});return e.jsx(Po,{pr:F,sub:Ay(F,j(F),re),chips:H,pills:e.jsx(Mi,{pr:F}),...N?{}:{href:ce({name:"pr",id:F.id})},selected:c&&o.name==="pr"&&o.id===F.id},F.id)})})]}),_.length>0&&e.jsxs(Ve,{children:[e.jsxs("button",{type:"button","aria-expanded":E,onClick:()=>B?x(F=>F===T?null:T):m(F=>!F),className:"flex min-h-11 w-full items-center gap-[9px] px-3 py-1.5 text-left text-[13px] text-muted",children:[e.jsx(z,{name:E?"down":"chevron",className:"size-3.5"}),Le.closedGroup(_.length)]}),E&&e.jsx("div",{className:"border-t border-line",children:_.map(F=>e.jsx(Po,{pr:F,dim:!0,pills:e.jsx(Mi,{pr:F}),sub:[Le.host[F.forge],Ml(F.repo),Le.state[F.state],Pg(F.updatedAt)].join(" · "),...N?{}:{href:ce({name:"pr",id:F.id})},selected:c&&o.name==="pr"&&o.id===F.id},F.id))})]})]}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:Le.tracked})]})})();return e.jsx(hs,{title:Le.title,offlineBody:y,heading:!1,children:b})}const Ge=u.prs,ot=u.rigs,ns=t=>Ge.notDone[t.action.kind],Ly=t=>{var n;return t.phase==="expired"?"assertion_expired":t.phase==="cancelled"?"cancelled":t.phase==="unsent"?"unsent":t.reason??((n=t.done)==null?void 0:n.error)};function zl({run:t,pr:n,detail:s,forge:a,pc:r,onReload:l}){const o=en(n),c=Pt(),i={onClose:()=>a.dismiss(t.id),closeLabel:Ge.close};if(t.phase==="checking")return e.jsx(Ls,{children:ot.running.checking});if(t.phase==="sending"||t.phase==="received")return e.jsx(Ls,{children:t.action.kind==="merge"?`${Ge.merging} · ${Ge.answers(o.cli)}`:Ge.answers(o.cli)});if(t.phase==="uncertain")return e.jsx($e,{mark:"ask",title:ot.uncertain.title,sub:ot.uncertain.body,...i,children:!t.lost&&e.jsx("button",{type:"button",onClick:()=>a.resend(t.id),className:be({size:"xs",className:"mt-1.5"}),children:Ge.retry})});const m=Ly(t),d=t.done;if(t.phase==="done"&&(d!=null&&d.ok)){const g=Ke(t.endedAt?new Date(t.endedAt).toISOString():null);return t.action.kind==="merge"?e.jsx($e,{mark:"ok",title:Ge.merged(n.ref),sub:Ge.mergedSub(g,n.target),...i,children:d.command&&e.jsx(qn,{commands:[d.command]})}):t.action.kind==="rerun"?e.jsx($e,{mark:"ok",title:Ge.rerunDone(n.ref),sub:Ge.rerunDoneSub(g),...i,children:d.command&&e.jsx(qn,{commands:[d.command]})}):t.action.kind==="reply"?e.jsx($e,{mark:"ok",title:Ge.replyPosted(o.host),sub:g,...i}):t.action.kind==="comment"?e.jsx($e,{mark:"ok",title:Ge.commentPosted(o.host),sub:g,...i}):null}if((t.action.kind==="comment"||t.action.kind==="reply")&&m!=="unavailable"&&m!=="confirm_required"){const g=t.action,h=m==="assertion_expired"?ot.rejected.assertion_expired(c):m==="assertion_invalid"?ot.rejected.assertion_invalid(c):m==="cancelled"?ot.rejected.cancelled:m==="unsent"?ot.rejected.unsent:Ge.lastLine(o.cli),N=!["assertion_expired","assertion_invalid","cancelled","unsent"].includes(m??"");return e.jsx($e,{mark:"bad",title:`${ot.because(ns(t),h)} ${Ge.keptText}`,...N&&(d!=null&&d.message)?{sub:e.jsx("span",{className:"font-mono",children:d.message})}:{},...i,children:e.jsx("button",{type:"button",onClick:()=>{a.dismiss(t.id),a.act(t.prId,g)},className:be({size:"xs",className:"mt-1.5"}),children:Ge.retry})})}const p=t.action.kind==="merge"?ot.rejected.again(Ge.mergeAgain):ot.rejected.nothingSent;switch(m){case"stale":return e.jsx($e,{mark:"warn",title:Ge.stale(vl(n.headSha)),sub:Ge.staleBody,...i,children:e.jsx("button",{type:"button",onClick:l??(()=>a.readDetail(t.prId)),className:be({size:"xs",className:"mt-1.5"}),children:Ge.reload})});case"not_offered":{if(t.action.kind==="rerun")return e.jsx($e,{mark:"warn",title:Ge.nothingToRerun,...i});const g=s?Ua(s).find(N=>!N.ok):void 0,h=g?zr(_s(g,o.host),g):(d==null?void 0:d.message)??"";return e.jsx($e,{mark:"bad",title:Ge.refused(o.host,h),...i})}case"busy":return e.jsx($e,{mark:"warn",title:Ge.rerunRefused(Ge.rerunBusy),...i});case"confirm_required":return e.jsx($e,{mark:"warn",title:ot.rejected.confirm_required,...i});case"assertion_expired":return e.jsx($e,{mark:"bad",title:ot.because(ns(t),ot.rejected.assertion_expired(c)),sub:p,...i});case"assertion_invalid":return e.jsx($e,{mark:"bad",title:ot.because(ns(t),ot.rejected.assertion_invalid(c)),sub:p,...i});case"cancelled":return e.jsx($e,{mark:"bad",title:ot.because(ns(t),ot.rejected.cancelled),sub:ot.rejected.nothingSent,...i});case"unsent":return e.jsx($e,{mark:"bad",title:ot.because(ns(t),ot.rejected.unsent),sub:ot.rejected.nothingSent,...i});case"unavailable":return e.jsx($e,{mark:"warn",title:Ge.gone(o.kind,r),sub:Ge.goneBody,...i});default:return e.jsx($e,{mark:"bad",title:t.action.kind==="resolve"?ot.because(ns(t),Ge.lastLine(o.cli)):Ge.failed(o.cli),...d!=null&&d.message?{sub:e.jsx("span",{className:"font-mono",children:d.message})}:{},...i,children:(d==null?void 0:d.command)&&e.jsx(qn,{commands:[d.command]})})}}const rs=u.prs,_a=t=>t.toLocaleString(ut);function Ei(t){return t.startsWith("@@")?"hunk":t.startsWith("+")?"add":t.startsWith("-")?"del":"ctx"}const Oy={hunk:"bg-info/8 text-info",add:"bg-ok/15",del:"bg-danger-fg/15",ctx:"text-muted"};function _i({path:t}){return e.jsx("span",{className:"min-w-0 flex-1 overflow-hidden text-left font-mono text-[12px] text-ellipsis whitespace-nowrap [direction:rtl]",children:e.jsx("span",{dir:"ltr",children:t})})}function Ri({f:t}){return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"font-mono text-[12px] text-ok",children:["+",_a(t.added)]}),e.jsxs("span",{className:"font-mono text-[12px] text-danger-fg",children:["−",_a(t.removed)]})]})}function Dy({f:t,threads:n,host:s}){const[a,r]=f.useState(!1),l=n>0&&e.jsx(Is,{children:rs.fileThreads(n)});return t.patch===void 0?e.jsxs("div",{"data-file":t.path,className:"flex min-h-[46px] flex-wrap items-center gap-2 border-b border-line px-3 py-1.5 text-[13px] last:border-b-0",children:[e.jsx(z,{name:"file",className:"size-3.5 text-muted"}),e.jsx(_i,{path:t.path}),l,e.jsx(Ri,{f:t}),e.jsx("span",{className:"basis-full pl-[22px] text-[12px] text-muted",children:rs.noPatch(s)})]}):e.jsxs("div",{"data-file":t.path,className:"border-b border-line last:border-b-0",children:[e.jsxs("button",{type:"button","aria-expanded":a,onClick:()=>r(o=>!o),className:"flex min-h-[46px] w-full items-center gap-2 px-3 py-1.5 text-left text-[13px]",children:[e.jsx(z,{name:a?"down":"chevron",className:"size-3.5 text-muted"}),e.jsx(_i,{path:t.path}),l,e.jsx(Ri,{f:t})]}),a&&e.jsx("pre",{className:"m-0 overflow-hidden border-t border-line bg-well font-mono text-[11px] leading-[17px]",children:t.patch.split(`
|
|
23
|
+
`).map((o,c)=>e.jsx("span",{"data-line":Ei(o),className:`block overflow-hidden px-3 text-ellipsis whitespace-pre ${Oy[Ei(o)]}`,children:o||" "},c))})]})}function Fy({detail:t}){if(t.files.length===0)return e.jsx("p",{className:"p-2.5 text-center text-[12px] text-muted",children:rs.noChange});const n=bg(t),s=rs.host[t.pr.forge];return e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx(It,{aside:e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"font-mono text-ok",children:["+",_a(n.added)]})," ",e.jsxs("span",{className:"font-mono text-danger-fg",children:["−",_a(n.removed)]})]}),children:rs.fileCount(t.files.length)}),e.jsx(Ve,{label:rs.tabs.changes,children:t.files.map(a=>e.jsx(Dy,{f:a,threads:jg(t,a.path),host:s},a.path))})]})}const vr=u.prs,Py=t=>[...t].sort((n,s)=>Date.parse(s.at)-Date.parse(n.at));function zy({detail:t}){return e.jsxs("div",{className:"flex flex-col gap-2.5",children:[t.commits.length>0&&e.jsx(Ve,{label:vr.tabs.commits,children:Py(t.commits).map(n=>e.jsxs("div",{"data-commit":n.sha,className:"flex min-h-[52px] items-center gap-2.5 border-b border-line px-3 py-1.5 last:border-b-0",children:[e.jsx(z,{name:"commit",className:"size-4 text-muted"}),e.jsx("span",{className:"flex-none font-mono text-[12px] text-muted",children:vl(n.sha)}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col text-[13.5px]",children:[e.jsx("span",{className:"truncate",children:n.title}),e.jsx("small",{className:"text-[12px] text-muted",children:`${n.author} · ${Ur(n.at)}`})]})]},n.sha))}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:vr.commitsReadOnly(vr.host[t.pr.forge])})]})}const it=u.prs,Bl=t=>t.file?t.line!==void 0?it.fileLine(t.file,t.line):t.file:null,Fu=(t,n,s)=>t.filter(a=>a.prId===n&&s(a)).at(-1),Pu=["checking","sending","received"];function zu({sent:t,onClose:n}){return t==="refused"?e.jsx($e,{mark:"bad",title:u.agents.notSent,onClose:n,closeLabel:it.close}):e.jsx($e,{mark:"ok",title:it.commentSent(t.name),onClose:n,closeLabel:it.close,children:e.jsx("a",{href:ce({name:"thread",sessionId:t.id}),className:be({size:"xs",className:"mt-1.5"}),children:it.openAgent(t.name)})})}function Bu({id:t,label:n,placeholder:s,verb:a,value:r,onChange:l,confirm:o,live:c,onPost:i,host:m,autoFocus:d=!1,rows:x=2,arrow:p=!1}){const g=e.jsx("textarea",{id:t,rows:r?Math.max(x,2):x,value:r,placeholder:s,autoFocus:d,onChange:h=>l(h.target.value),className:p?"min-h-[34px] min-w-0 flex-1 resize-none bg-transparent py-[6px] text-base leading-[22px] text-fg outline-none placeholder:text-muted":"min-h-11 w-full resize-none rounded-[14px] border border-input bg-surface px-3.5 py-[11px] text-base leading-5 text-fg placeholder:text-muted"});return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:t,className:"sr-only",children:n}),p?e.jsxs("div",{className:"flex min-w-0 items-end gap-2 rounded-[10px] border border-input bg-surface py-[5px] pr-[5px] pl-3 focus-within:border-ring focus-within:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)]",children:[g,r.trim()===""&&e.jsx("button",{type:"button",disabled:!0,"aria-label":a,title:a,className:"grid size-9 flex-none place-items-center rounded-lg bg-primary text-primary-fg disabled:opacity-40",children:e.jsx(z,{name:"send",className:"size-[18px]"})})]}):g,r.trim()!==""&&e.jsxs(e.Fragment,{children:[e.jsx(On,{verb:a,confirm:o,disabled:!c,onClick:i}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:it.postedAs(m)})]})]})}const By=({who:t,at:n,body:s,reply:a})=>e.jsxs("p",{className:`m-0 text-[13.5px] leading-[19px] [overflow-wrap:anywhere] whitespace-pre-wrap ${a?"border-l-2 border-line pl-[9px]":""}`,children:[e.jsx("span",{className:"font-semibold",children:t}),e.jsx("span",{className:"ml-1 font-mono text-[11px] text-muted",children:Ke(n)}),e.jsx("br",{}),s]}),qy="flex flex-col gap-2 rounded-[10px] border border-line bg-surface p-2.5 dark:bg-transparent",wr="h-9 !px-2.5 text-[12.5px]";function qu({pr:t,t:n,agent:s,forge:a,store:r,live:l,pc:o,readOnly:c=!1}){var v,A;const i=Qa(a),m=xe(r),[d,x]=f.useState(!1),[p,g]=f.useState(null),h=Pl(t.id,n.id),N=i.drafts[h]??"",k=en(t),C=Bl(n),j=n.comments[0],y=Fu(i.runs,t.id,R=>(R.action.kind==="reply"||R.action.kind==="resolve")&&R.action.threadId===n.id),b=()=>{s&&g(r.reply(s.id,it.threadText(t.ref,j.author,C,j.body))?s:"refused")},M=()=>{x(!1),a.act(t.id,{kind:"reply",threadId:n.id,body:N.trim()})},S=!!y&&Pu.includes(y.phase),$=!S&&(d||N!==""&&(y==null?void 0:y.action.kind)==="reply"&&y.phase!=="uncertain"&&!(y.phase==="done"&&((v=y.done)!=null&&v.ok)));return e.jsxs("article",{"data-thread":n.id,className:qy,children:[C&&e.jsx("span",{className:"font-mono text-[11px] text-muted",children:C}),n.code&&e.jsx("code",{className:"block truncate rounded-md bg-ok/15 px-2 py-[3px] font-mono text-[11.5px] leading-[17px] whitespace-pre",children:n.code}),n.comments.map((R,_)=>e.jsx(By,{who:R.author,at:R.at,body:R.body,reply:_>0},R.id)),!c&&e.jsxs(e.Fragment,{children:[$?e.jsx(Bu,{id:`reply-${n.id}`,label:it.reply,placeholder:it.replyPh,verb:it.reply,value:N,onChange:R=>a.setDraft(h,R),confirm:!!((A=m.device)!=null&&A.confirm),live:l,onPost:M,host:k.host,autoFocus:d}):e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsx("button",{type:"button",disabled:!l||S,onClick:()=>x(!0),className:be({className:wr}),children:it.reply}),s&&e.jsx("button",{type:"button",disabled:!m.fresh,onClick:b,className:be({className:wr}),children:it.sendTo(s.name)}),n.resolvable&&e.jsx("button",{type:"button",disabled:!l||S,onClick:()=>void a.act(t.id,{kind:"resolve",threadId:n.id}),className:`${be({className:wr})} border-transparent`,children:it.resolve})]}),p&&e.jsx(zu,{sent:p,onClose:()=>g(null)}),y&&e.jsx(zl,{run:y,pr:t,detail:void 0,forge:a,pc:o})]})]})}function Hy({pr:t,t:n,forge:s,store:a,pc:r}){const[l,o]=f.useState(!1),c=Bl(n);return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-expanded":l,onClick:()=>o(i=>!i),"data-thread":n.id,className:"flex items-center gap-2 rounded-[10px] border border-dashed border-line px-2.5 py-2 text-left text-[12.5px] text-muted",children:[e.jsx("span",{"aria-hidden":"true",className:"text-ok",children:"✓"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:it.resolvedRow([...c?[c]:[],n.comments[0].author])}),e.jsx(z,{name:l?"down":"chevron",className:"size-3.5"})]}),l&&e.jsx(qu,{pr:t,t:n,agent:null,forge:s,store:a,live:!1,pc:r,readOnly:!0})]})}function Hu(t,n){const s=xe(n),[a,r]=f.useState(null),l=(t==null?void 0:t.threads)??[],o=t?Id(t.pr,s.sessions)[0]:void 0,c=o?{id:o.id,name:o.name}:null,i=l.filter(d=>!d.resolved),m=()=>{if(!c||!t)return;const d=i.map(x=>it.note(x.comments[0].author,Bl(x),x.comments[0].body));r(n.reply(c.id,it.notesText(t.pr.ref,d))?c:"refused")};return{agent:c,open:i,resolved:l.filter(d=>d.resolved),sent:a,send:m,clear:()=>r(null),fresh:s.fresh}}function Uu({all:t,className:n=""}){return!t.agent||!t.open.length?null:e.jsxs("button",{type:"button",disabled:!t.fresh,onClick:t.send,className:be({size:"sm",className:n}),children:[e.jsx(z,{name:"send",className:"size-4"}),it.sendAll(t.agent.name)]})}function Ti({detail:t,forge:n,store:s,live:a,pc:r,column:l}){const o=Hu(t,s),c=l??o,i=t.pr;return t.threads.length?e.jsxs(e.Fragment,{children:[!l&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12.5px] text-muted",children:it.discSub(c.open.length,c.resolved.length)}),e.jsx("span",{className:"flex-1"}),e.jsx(Uu,{all:c})]}),c.sent&&e.jsx(zu,{sent:c.sent,onClose:c.clear}),c.open.map(m=>e.jsx(qu,{pr:i,t:m,agent:c.agent,forge:n,store:s,live:a,pc:r},m.id)),c.resolved.map(m=>e.jsx(Hy,{pr:i,t:m,forge:n,store:s,pc:r},m.id))]}):e.jsx("p",{className:"m-0 p-2.5 text-center text-[12.5px] text-muted",children:it.noComment})}function Ai({pr:t,forge:n,store:s,live:a,pc:r}){var x;const l=Qa(n),o=xe(s),c=Pl(t.id),i=l.drafts[c]??"",m=Fu(l.runs,t.id,p=>p.action.kind==="comment"),d=!!m&&Pu.includes(m.phase);return e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[m&&e.jsx(zl,{run:m,pr:t,detail:void 0,forge:n,pc:r}),e.jsx(Bu,{id:`comment-${t.id}`,label:it.addComment,placeholder:it.addComment,verb:it.post,value:i,onChange:p=>n.setDraft(c,p),confirm:!!((x=o.device)!=null&&x.confirm),live:a&&!d,onPost:()=>void n.act(t.id,{kind:"comment",body:i.trim()}),host:en(t).host,rows:1,arrow:!0})]})}const Uy=`${ul} and (orientation: landscape)`,Wu=()=>typeof globalThis.matchMedia=="function"?globalThis.matchMedia(Uy):null,Wy=t=>{var s;const n=Wu();return(s=n==null?void 0:n.addEventListener)==null||s.call(n,"change",t),()=>{var a;return(a=n==null?void 0:n.removeEventListener)==null?void 0:a.call(n,"change",t)}};function Ky(){return f.useSyncExternalStore(Wy,()=>{var t;return((t=Wu())==null?void 0:t.matches)??!1},()=>!1)}const ne=u.prs,Vy={review:"border-attention/45 text-attention"};function Gy({pr:t,landscape:n}){const s=Dt(),a=en(t);return s?e.jsxs("header",{"data-pr-head":"",className:"flex h-[58px] flex-none items-center gap-[9px] border-b border-line pr-2.5 pl-[22px]",children:[e.jsx("span",{className:"inline-flex h-5 flex-none items-center rounded-lg border border-input px-[7px] text-[11.5px] whitespace-nowrap text-muted",children:`${a.host} · ${a.kind}`}),e.jsx("h1",{className:"min-w-0 truncate text-[16px] font-semibold",children:`${t.ref} ${t.title}`}),n&&e.jsx("span",{"data-pr-state":t.state,className:`inline-flex h-[22px] flex-none items-center rounded-full border px-[9px] text-[12px] font-medium whitespace-nowrap ${Vy[t.state]??"border-input text-muted"}`,children:ne.state[t.state]}),e.jsx("span",{className:"flex-1"}),n?e.jsxs("a",{href:t.url,target:"_blank",rel:"noreferrer",className:be({size:"sm",className:"flex-none"}),children:[e.jsx(z,{name:"external",className:"size-4"}),ne.openOn(a.host)]}):e.jsx("a",{href:t.url,target:"_blank",rel:"noreferrer","aria-label":ne.openOn(a.host),title:ne.openOn(a.host),className:Ot(),children:e.jsx(z,{name:"external",className:"size-[18px]"})})]}):e.jsxs("header",{className:`flex flex-none items-center gap-2 border-b border-line pr-1.5 ${s?"pane-head h-[58px]":"h-14 pl-0.5"}`,children:[e.jsx(Zt,{fallback:{name:"prs"},label:ne.title}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("h1",{className:"truncate text-[15px] font-semibold",children:`${t.ref} ${t.title}`}),e.jsx("small",{className:"truncate text-[12px] text-muted",children:[a.host,Ml(t.repo),`${t.branch} → ${t.target}`].join(" · ")})]}),e.jsx("a",{href:t.url,target:"_blank",rel:"noreferrer","aria-label":ne.openOn(a.host),title:ne.openOn(a.host),className:Ot(),children:e.jsx(z,{name:"external",className:"size-[18px]"})})]})}const Xy=["overview","discussion","changes","commits"],Yy=["overview","changes","commits"];function Qy({pr:t,d:n,view:s,views:a,onView:r,wide:l}){const o=n?{discussion:n.threads.length,changes:n.files.length,commits:n.commits.length}:{};return e.jsx("nav",{"aria-label":ne.title,className:`flex flex-none gap-0.5 overflow-x-auto overflow-y-hidden border-b border-line [scrollbar-width:none] ${l?"px-1.5 py-2":"p-2"}`,children:a.map(c=>e.jsxs("button",{type:"button","aria-current":s===c?"page":void 0,onClick:()=>r(c),className:"group inline-flex h-9 flex-none items-center gap-[5px] rounded-lg px-[7px] text-[13px] font-medium whitespace-nowrap text-muted aria-[current=page]:bg-raised aria-[current=page]:text-fg",children:[c==="overview"&&e.jsx(ze,{state:gs[t.pipeline],pulse:t.pipeline==="run"}),ne.tabs[c],o[c]!==void 0&&e.jsx("span",{className:"inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-raised px-1 font-mono text-[11px] group-aria-[current=page]:bg-bg",children:o[c]})]},c))})}const Ku={ok:"border-ok/40",fail:"border-approval/60",run:"border-info/50",wait:"border-line text-muted",skip:"border-line text-muted",none:"border-line text-muted"},Vu=t=>t==="fail"?"bg-danger-bg":"bg-surface dark:bg-transparent";function Gu(t){if(t.status==="run")return e.jsx("span",{className:"font-mono text-[12px] text-info",children:ne.pipe.run});const n=jd(t.durationS);return n?e.jsx("span",{className:"font-mono text-[12px] text-muted",children:n.hours?ne.hours(n.text):n.text}):t.status==="wait"||t.status==="skip"?e.jsx("span",{className:"text-[12px]",children:ne.pipe[t.status]}):null}function Zy({job:t,selected:n,onOpen:s}){const a=e.jsxs(e.Fragment,{children:[t.status==="run"?e.jsx(bs,{}):e.jsx(ze,{state:gs[t.status]}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.name}),Gu(t)]}),r=`flex h-11 w-full items-center gap-2.5 rounded-[10px] border px-3 text-left text-[14px] ${Vu(t.status)} ${Ku[t.status]} ${n?"shadow-[0_0_0_2px_var(--color-ring)]":""}`;return s?e.jsx("button",{type:"button","data-job":t.id,onClick:s,className:r,children:a}):e.jsx("div",{"data-job":t.id,className:r,children:a})}function Jy({after:t}){const n=t.jobs.some(a=>a.status==="fail"),s=t.jobs.every(a=>a.status==="ok");return e.jsx("span",{"aria-hidden":"true",className:`mt-[5px] mb-[5px] ml-[22px] block h-3 ${n?"border-l-2 border-dashed border-approval":`w-0.5 ${s?"bg-ok":"bg-input"}`}`})}function eN({pr:t,jobs:n,selected:s,onJob:a}){const r=gd(n);return e.jsx("div",{className:"flex flex-col",children:r.map((l,o)=>e.jsxs("div",{className:"flex flex-col",children:[o>0&&e.jsx(Jy,{after:r[o-1]}),e.jsx("div",{className:"mb-[5px] text-[11px] tracking-[.5px] text-muted uppercase",children:t.forge==="gitlab"?ne.stage(o+1,l.name):l.name}),e.jsx("div",{className:"flex flex-col gap-1.5",children:l.jobs.map(c=>e.jsx(Zy,{job:c,selected:c.id===s,onOpen:c.id===s?void 0:()=>a(c)},c.id))})]},l.column))})}function tN({job:t,selected:n,onOpen:s}){const a=e.jsxs(e.Fragment,{children:[t.status==="run"?e.jsx(bs,{}):e.jsx(ze,{state:gs[t.status]}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.name}),Gu(t)]}),r=`flex h-10 min-w-[92px] items-center gap-[7px] rounded-[10px] border px-[9px] text-left text-[13px] ${Vu(t.status)} ${Ku[t.status]} ${n?"shadow-[0_0_0_2px_var(--color-ring)]":""}`;return s?e.jsx("button",{type:"button","data-job":t.id,onClick:s,className:r,children:a}):e.jsx("div",{"data-job":t.id,className:r,children:a})}function nN({after:t}){const n=t.jobs.some(a=>a.status==="fail"),s=t.jobs.every(a=>a.status==="ok");return e.jsx("span",{"aria-hidden":"true",className:`mt-[39px] block w-5 flex-none ${n?"border-t-2 border-dashed border-approval":`h-0.5 ${s?"bg-ok":"bg-input"}`}`})}function sN({pr:t,jobs:n,selected:s,onJob:a}){const r=gd(n);return e.jsx("div",{"data-pipeline":"side",className:"flex flex-none items-start overflow-x-auto rounded-[10px] border border-line bg-surface p-3.5 dark:bg-[oklch(0.18_0_0)]",children:r.map((l,o)=>e.jsxs("div",{className:"contents",children:[o>0&&e.jsx(nN,{after:r[o-1]}),e.jsxs("div",{className:"flex min-w-0 flex-[0_1_auto] flex-col gap-2",children:[e.jsx("div",{className:"mb-[5px] text-[11px] tracking-[.5px] whitespace-nowrap text-muted uppercase",children:t.forge==="gitlab"?ne.stage(o+1,l.name):l.name}),l.jobs.map(c=>e.jsx(tN,{job:c,selected:c.id===s,onOpen:c.id===s?void 0:()=>a(c)},c.id))]})]},l.column))})}const aN=({text:t,tall:n=!1})=>e.jsx("pre",{className:`m-0 overflow-hidden rounded-[10px] border border-white/10 bg-[#0c0c0d] px-[11px] py-[9px] font-mono text-[11.5px] leading-[17px] break-all whitespace-pre-wrap text-[#e5e5e5] ${n?"max-h-[300px] overflow-y-auto":""}`,children:t});function Xu({job:t,read:n,pr:s,onRetry:a,tall:r=!1}){var c,i;const l=en(s),o=((i=(c=n==null?void 0:n.data)==null?void 0:c.log)==null?void 0:i.jobId)===t.id?n.data.log.text:null;return o!==null?e.jsx(aN,{text:o,tall:r}):n!=null&&n.loading?e.jsxs("div",{role:"status",className:"flex items-center gap-2 text-[12px] text-muted",children:[e.jsx(bs,{className:"text-muted"}),ne.log.reading(t.name)]}):e.jsx($e,{mark:"bad",title:ne.log.failed,sub:ne.log.failedBody(l.cli,l.host),children:e.jsx("button",{type:"button",onClick:a,className:be({size:"xs",className:"mt-1.5"}),children:ne.retry})})}function rN({job:t,read:n,pr:s,onRetry:a,onClose:r}){var m,d;const l=f.useId(),o=en(s),c=jd(t.durationS),i=((d=(m=n==null?void 0:n.data)==null?void 0:m.log)==null?void 0:d.jobId)===t.id?n.data.log.text:null;return e.jsxs(ht,{labelledBy:l,onClose:r,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ze,{state:gs[t.status]}),e.jsx("h2",{id:l,className:"text-[15px] font-semibold",children:ne.log.title(t.name)}),e.jsx("span",{className:"text-[12px] text-muted",children:[ne.pipe[t.status],c?c.hours?ne.hours(c.text):c.text:""].filter(Boolean).join(" · ")})]}),e.jsx(Xu,{job:t,read:n,pr:s,onRetry:a,tall:!0}),i!==null&&e.jsx("p",{className:"m-0 text-[12px] leading-4 text-muted",children:[ne.log.note,pg(i)?ne.log.cut(o.host):""].filter(Boolean).join(" ")}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("a",{href:s.url,target:"_blank",rel:"noreferrer",className:be(),children:[e.jsx(z,{name:"external",className:"size-4"}),ne.openOn(o.host)]}),e.jsx("button",{type:"button",onClick:r,className:be(),children:ne.close})]})]})}function lN({text:t}){return e.jsx("div",{className:"text-[13.5px] leading-5",children:t.split(/\n\n+/).map((n,s)=>{const a=n.split(`
|
|
24
|
+
`);return a.every(r=>r.startsWith("- "))?e.jsx("ul",{className:"mt-1 list-disc pl-[18px]",children:a.map((r,l)=>e.jsx("li",{children:r.slice(2)},l))},s):e.jsx("p",{className:"m-0 whitespace-pre-wrap",children:n},s)})})}const oN={approved:"idle",changes:"perm",pending:"plain"};function iN({d:t}){const n="text-muted",s="m-0 flex min-w-0 flex-wrap items-center gap-1.5";return e.jsxs("dl",{className:"m-0 grid grid-cols-[auto_1fr] gap-x-3.5 gap-y-1.5 border-t border-line pt-2.5 text-[13px]",children:[e.jsx("dt",{className:n,children:ne.author}),e.jsx("dd",{className:s,children:t.author}),t.reviewers.map((a,r)=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:n,children:r===0?ne.reviewers:""}),e.jsxs("dd",{className:s,children:[e.jsx(ze,{state:oN[a.state]}),a.name," ",e.jsx("span",{className:"text-muted",children:ne.reviewer[a.state]})]})]},a.name)),t.labels.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:n,children:ne.labels}),e.jsx("dd",{className:s,children:t.labels.map(a=>e.jsx("span",{className:"rounded-full border border-line px-2 text-[12px]",children:a},a))})]}),t.issues.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:n,children:ne.issue}),e.jsx("dd",{className:`${s} font-mono text-[12px]`,children:t.issues.join(" ")})]})]})}function cN({conds:t,host:n}){return e.jsxs("section",{"aria-label":ne.toMerge,className:"flex-none overflow-hidden rounded-[10px] border border-line bg-surface dark:bg-transparent",children:[e.jsx("div",{className:"flex min-h-11 items-center border-b border-line px-3",children:e.jsx("b",{className:"text-[14px] font-semibold",children:ne.toMerge})}),e.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-2.5 text-[13px]",children:t.map((s,a)=>e.jsxs("li",{"data-cond":s.ok?"ok":s.key,className:"flex items-baseline gap-2",children:[e.jsx("span",{"aria-hidden":"true",className:`w-3.5 flex-none text-center text-[12px] font-semibold ${s.ok?"text-ok":"text-approval"}`,children:s.ok?"✓":"✕"}),e.jsx("span",{className:s.key==="raw"?"font-mono":"",children:_s(s,n)})]},a))})]})}function dN(t,n){const s=Ua(t),a=s.find(o=>!o.ok);if(a)return e.jsxs(e.Fragment,{children:[ne.footApprovals(yd(t.pr))," · ",e.jsx("b",{className:"font-medium text-fg",children:zr(_s(a,n),a)})]});const r=s.find(o=>o.key==="pipeline"||o.key==="noCi"),l=s.find(o=>o.key==="approved");return`${_s(r,n)} · ${zr(_s(l,n),l)}`}function Yu(){const t="block animate-[ledge-pulse_1.6s_ease-in-out_infinite] rounded-[10px] bg-raised";return e.jsxs("div",{role:"status",className:"flex flex-col gap-1.5",children:[e.jsx("span",{"aria-hidden":"true",className:`${t} h-11`}),e.jsx("span",{"aria-hidden":"true",className:`${t} h-11`}),e.jsx("span",{"aria-hidden":"true",className:`${t} h-[60px]`}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ne.detailLoading})]})}function uN({pr:t,job:n,store:s}){const a=xe(s),r=Id(t,a.sessions),[l,o]=f.useState(null),[c,i]=f.useState(!1),[m,d]=f.useState(null),x=f.useId();if(!r.length)return e.jsx("p",{className:"m-0 text-[12px] leading-4 text-muted",children:ne.noSession(t.branch)});const p=r.find(N=>N.id===l)??r[0],g=a.fresh,h=()=>{d(s.reply(p.id,ne.fixText(t.ref,n))?{id:p.id,name:p.name}:"refused")};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{type:"button",disabled:!g,onClick:h,className:be({tone:"dangerfill",className:"flex-1"}),children:ne.askFix(p.name)}),r.length>1&&e.jsx("button",{type:"button","aria-label":ne.otherSession,title:ne.otherSession,"aria-haspopup":"menu",disabled:!g,onClick:()=>i(!0),className:be({className:"w-12 !px-0"}),children:e.jsx(z,{name:"down",className:"size-4"})})]}),m==="refused"&&e.jsx($e,{mark:"bad",title:u.agents.notSent,onClose:()=>d(null),closeLabel:ne.close}),m&&m!=="refused"&&e.jsx($e,{mark:"ok",title:ne.sentTo(m.name),onClose:()=>d(null),closeLabel:ne.close,children:e.jsx("a",{href:ce({name:"thread",sessionId:m.id}),className:be({size:"xs",className:"mt-1.5"}),children:ne.openAgent(m.name)})}),c&&e.jsxs(ht,{labelledBy:x,onClose:()=>i(!1),children:[e.jsx("h2",{id:x,className:"sr-only",children:ne.otherSession}),e.jsx("div",{role:"menu","aria-labelledby":x,className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:r.map((N,k)=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":N.id===p.id,onClick:()=>{o(N.id),i(!1)},className:"flex min-h-12 items-center gap-3 border-b border-line px-3.5 text-left text-[15px] last:border-b-0 aria-checked:bg-secondary",children:[e.jsx(ze,{state:ms(N)}),e.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[N.name," ",e.jsx("small",{className:"text-[12px] text-muted",children:[u.tools[N.tool],N.repo].filter(Boolean).join(" · ")})]}),k===0&&e.jsx("span",{className:"text-[12px] text-muted",children:ne.mostActive})]},N.id))})]})]})}function xN({pr:t,confirm:n,live:s,onRerun:a,onClose:r}){return e.jsxs(an,{title:ne.rerunTitle(t.ref),onClose:r,children:[e.jsx("p",{className:"m-0 text-[12.5px] leading-[18px] text-muted",children:ne.rerunBody(en(t).host)}),e.jsx(On,{verb:ne.rerun,confirm:n,disabled:!s,onClick:()=>{r(),a()}}),e.jsx(Xs,{onClose:r})]})}function mN({pr:t,read:n,store:s,live:a,onJob:r,onLog:l,onRerun:o,side:c}){const i=n==null?void 0:n.data,m=en(t),d=i?bd(i.jobs):null,x=t.state!=="merged"&&t.state!=="closed",p=t.pipeline==="none"?ne.noCi:i!=null&&i.mergeBlockers.includes("pipeline_not_started")?ne.notStarted:null;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"m-0 text-[15px] font-semibold",children:ne.pipelineTitle}),e.jsx(Ad,{pipeline:t.pipeline,short:!0}),e.jsx("span",{className:"flex-1"}),gg(t)&&e.jsxs("button",{type:"button",disabled:!a,onClick:o,className:be({size:"sm"}),children:[e.jsx(z,{name:"refresh",className:"size-4"}),ne.rerun]})]}),p&&e.jsx("p",{className:"m-0 text-[12px] text-muted",children:p}),i?e.jsxs(e.Fragment,{children:[i.jobs.length>0&&(c?e.jsx(sN,{pr:t,jobs:i.jobs,selected:(d==null?void 0:d.id)??null,onJob:r}):e.jsx(eN,{pr:t,jobs:i.jobs,selected:(d==null?void 0:d.id)??null,onJob:r})),d&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center gap-2 text-[12px] text-muted",children:e.jsx("span",{children:`${ne.log.title(d.name)} · ${ne.log.lines}`})}),e.jsx(Xu,{job:d,read:n,pr:t,onRetry:()=>l(d)}),x&&e.jsx(uN,{pr:t,job:d.name,store:s})]}),x&&e.jsx(cN,{conds:Ua(i),host:m.host}),i.description&&e.jsxs("div",{className:"flex flex-col gap-1.5 border-t border-line pt-2.5",children:[e.jsx("h2",{className:"m-0 text-[15px] font-semibold",children:ne.description}),e.jsx(lN,{text:i.description})]}),e.jsx(iN,{d:i})]}):e.jsx(Yu,{})]})}function pN({read:t,pr:n,pc:s,onRetry:a}){const r=en(n);return t.error==="unavailable"?e.jsx($e,{mark:"warn",title:ne.gone(r.kind,s),sub:ne.goneBody}):t.error==="too_large"?e.jsx($e,{mark:"bad",title:ne.tooLarge,sub:ne.tooLargeBody(r.host),children:e.jsx("a",{href:n.url,target:"_blank",rel:"noreferrer",className:be({size:"xs",className:"mt-1.5"}),children:ne.open})}):e.jsx($e,{mark:"bad",title:ne.readFailed(r.cli,r.kind),sub:ne.readFailedBody,children:e.jsx("button",{type:"button",onClick:a,className:be({size:"xs",className:"mt-1.5"}),children:ne.retry})})}function fN({d:t,pc:n,confirm:s,live:a,onMerge:r,onClose:l}){return e.jsxs(an,{title:ne.confirm(t.pr.ref,t.pr.target),onClose:l,children:[e.jsx("span",{className:"text-[12.5px] text-muted",children:ne.runsOn(n)}),e.jsx("code",{className:"block rounded-md bg-raised px-2 py-1.5 font-mono text-[12px] break-all",children:t.mergeCommand}),e.jsx("p",{className:"m-0 text-[12px] leading-4 text-muted",children:ne.headRead(vl(t.pr.headSha))}),e.jsx(On,{verb:ne.merge,confirm:s,disabled:!a,onClick:()=>{l(),r()}}),e.jsx(Xs,{onClose:l})]})}const hN=(t,n)=>t.filter(s=>s.prId===n&&(s.action.kind==="merge"||s.action.kind==="rerun")).at(-1),gN=t=>!!t&&(t.phase==="checking"||t.phase==="sending"||t.phase==="received");function bN({id:t,forge:n,store:s,pane:a=!1}){var fe,he,w,O,V,Z;const r=Qa(n),l=xe(s),[o,c]=f.useState(!1),[i,m]=f.useState(!1),{pc:d,look:x}=zt(),p=Dt(),g=Ky()&&p&&!a,[h,N]=f.useState("overview"),[k,C]=f.useState(null),j=x==="offline",y=Jt(d),b=r.details[t],M=r.state&&[...r.state.prs,...r.state.mine??[]].find(X=>X.id===t),S=M??((fe=b==null?void 0:b.data)==null?void 0:fe.pr),$=Hu(b==null?void 0:b.data,s);f.useEffect(()=>{n.readDetail(t)},[n,t]);const v=b!=null&&b.data?bd(b.data.jobs):null,A=f.useRef(null);f.useEffect(()=>{var X,J;!v||((J=(X=b==null?void 0:b.data)==null?void 0:X.log)==null?void 0:J.jobId)===v.id||A.current===v.id||(A.current=v.id,n.readDetail(t,v.id))},[n,t,v==null?void 0:v.id,(w=(he=b==null?void 0:b.data)==null?void 0:he.log)==null?void 0:w.jobId]);const R=f.useRef(null);f.useEffect(()=>{var X,J;(J=(X=R.current)==null?void 0:X.scrollTo)==null||J.call(X,{top:0})},[h]);const _=`tab-main flex min-h-0 flex-1 flex-col gap-2.5 overflow-y-auto overscroll-contain pb-[18px] ${p?"px-[22px] pt-[18px]":"pt-3"}`;if(!S)return e.jsx("main",{"data-tab-scroll":"",className:_,children:r.state?e.jsx($e,{mark:"warn",title:ne.gone(ne.kind[((O=r.state.forges.find(X=>X.host===t.split("/")[0]))==null?void 0:O.forge)??"github"],y),sub:ne.goneBody}):e.jsx(Wt,{lead:e.jsx(bs,{className:"text-muted"}),children:e.jsx("span",{children:ne.loading})})});const L=en(S),T=b==null?void 0:b.data,B=S.state==="merged"||S.state==="closed",E=!!r.state&&!M,P=k&&T?T.jobs.find(X=>X.id===k):void 0,W=X=>{n.readDetail(t,X.id)},F=hN(r.runs,t),re=gN(F),Y=l.fresh&&!j,H=()=>{T&&n.act(t,{kind:"merge",headSha:T.pr.headSha})},I=g?Yy:Xy,D=I.includes(h)?h:"overview",Q=e.jsxs(e.Fragment,{children:[e.jsx(wn,{body:ne.offlineBody}),E&&!F&&e.jsx($e,{mark:"warn",title:ne.gone(L.kind,y),sub:ne.goneBody}),F&&e.jsx(zl,{run:F,pr:S,detail:T,forge:n,pc:y,onReload:()=>n.readDetail(t)}),(b==null?void 0:b.error)&&!T&&e.jsx(pN,{read:b,pr:S,pc:y,onRetry:()=>n.readDetail(t)}),(b==null?void 0:b.cut)&&e.jsx(Wt,{lead:e.jsx(z,{name:"alert",className:"mt-px size-4 text-muted"}),children:e.jsx("span",{children:ne.cut(L.host)})}),e.jsxs("div",{className:`flex flex-col ${g?"gap-4":"gap-2.5"} ${j?"opacity-50":""}`,children:[D==="overview"&&(!(b!=null&&b.error)||T)&&e.jsx(mN,{pr:S,read:b,store:s,live:Y&&!re&&!E,side:g,onJob:X=>{C(X.id),W(X)},onLog:W,onRerun:()=>m(!0)}),D!=="overview"&&!T&&!(b!=null&&b.error)&&e.jsx(Yu,{}),D==="discussion"&&T&&e.jsx(Ti,{detail:T,forge:n,store:s,live:Y&&!E,pc:y}),D==="changes"&&T&&e.jsx(Fy,{detail:T}),D==="commits"&&T&&e.jsx(zy,{detail:T})]})]}),q=e.jsxs("span",{"data-foot":"done",className:`flex min-w-0 flex-1 flex-wrap items-center gap-1.5 leading-4 text-muted ${p?"text-[12.5px]":"text-[12px]"}`,children:[e.jsx("span",{className:"inline-flex h-[22px] items-center rounded-full border border-input px-[9px] text-[12px] font-medium",children:ne.state[S.state]}),S.state==="merged"?ne.mergedInto(S.target,Ur(S.updatedAt)):Ur(S.updatedAt)]}),K=e.jsx("span",{"data-foot":"why",className:`min-w-0 flex-1 leading-4 text-muted ${p?"text-[12.5px]":"text-[12px]"}`,children:T?dN(T,L.host):ne.footApprovals(yd(S))}),ee=e.jsxs("button",{type:"button",disabled:!Y||E||re||!T||!hg(T),onClick:()=>c(!0),className:be(p?{tone:"primary",size:"sm",className:"flex-none"}:{tone:"primary",className:"h-[42px]"}),children:[e.jsx(z,{name:"merge",className:"size-4"}),ne.merge]}),ue=p?"flex flex-none items-center gap-2.5 border-t border-line bg-sidebar px-[18px] py-2.5":"flex flex-none items-center gap-2.5 border-t border-line bg-sidebar px-3.5 py-[9px]";return e.jsxs(e.Fragment,{children:[e.jsx(Gy,{pr:S,landscape:g}),e.jsx(Qy,{pr:S,d:T,view:D,views:I,onView:N,wide:p}),g?e.jsxs("div",{className:"grid min-h-0 flex-1 grid-cols-[minmax(0,1fr)_320px]",children:[e.jsx("main",{ref:R,"data-tab-scroll":"",className:"tab-main flex min-h-0 min-w-0 flex-col gap-4 overflow-y-auto overscroll-contain px-[22px] py-[18px]",children:Q}),e.jsxs("aside",{"aria-labelledby":`disc-${t}`,"data-pr-discussion":"",className:"flex min-h-0 min-w-0 flex-col border-l border-line",children:[e.jsxs("div",{className:"flex h-12 flex-none items-center gap-2 border-b border-line px-3.5",children:[e.jsx("h2",{id:`disc-${t}`,className:"m-0 text-[15px] font-semibold",children:ne.tabs.discussion}),T&&T.threads.length>0&&e.jsx("span",{className:"text-[12.5px] text-muted",children:ne.discSub($.open.length,$.resolved.length)})]}),e.jsx("div",{className:`flex min-h-0 flex-1 flex-col gap-2.5 overflow-y-auto overscroll-contain p-3 ${j?"opacity-50":""}`,children:T&&e.jsx(Ti,{detail:T,forge:n,store:s,live:Y&&!E,pc:y,column:$})}),!B&&e.jsx("div",{className:"flex flex-none border-t border-line px-3 py-2.5",children:e.jsx(Ai,{pr:S,forge:n,store:s,live:Y&&!E,pc:y})})]})]}):e.jsx("main",{ref:R,"data-tab-scroll":"",className:_,children:Q}),e.jsx("footer",{className:ue,children:g?e.jsxs(e.Fragment,{children:[B?q:K,e.jsx(Uu,{all:$,className:"flex-none"}),!B&&ee]}):D==="discussion"&&!B?e.jsx(Ai,{pr:S,forge:n,store:s,live:Y&&!E,pc:y}):B?q:e.jsxs(e.Fragment,{children:[K,ee]})}),i&&e.jsx(xN,{pr:S,confirm:!!((V=l.device)!=null&&V.confirm),live:Y,onRerun:()=>{n.act(t,{kind:"rerun"})},onClose:()=>m(!1)}),o&&T&&e.jsx(fN,{d:T,pc:y,confirm:!!((Z=l.device)!=null&&Z.confirm),live:Y,onMerge:H,onClose:()=>c(!1)}),P&&e.jsx(rN,{job:P,read:b,pr:S,onRetry:()=>W(P),onClose:()=>C(null)})]})}function jN(t){const[,n]=f.useReducer(s=>s+1,0);return f.useEffect(()=>{const s=t.subscribe(n);return n(),s},[t]),t.state()}function yN(t){const[,n]=f.useReducer(s=>s+1,0);return f.useEffect(()=>{if(!t)return;const s=t.subscribe(n);return n(),s},[t]),{build:(t==null?void 0:t.current())??null,waiting:(t==null?void 0:t.waiting())??null}}function NN(t){var s;const[,n]=f.useReducer(a=>a+1,0);return f.useEffect(()=>t==null?void 0:t.subscribe(n),[t]),((s=t==null?void 0:t.getState().state)==null?void 0:s.prs)??[]}function kN(t,n){const[s,a]=f.useState(null);return f.useEffect(()=>{if(!n){a(null);return}let r=!0;return t("/auth/me",{credentials:"same-origin",cache:"no-store"}).then(async l=>l.ok?Ix.safeParse(await l.json()):null).then(l=>{r&&(l!=null&&l.success)&&a(l.data.login)}).catch(()=>{}),()=>{r=!1}},[t,n]),s}const vN=(t,n)=>globalThis.fetch(t,n),wN=t=>t.name==="request"?{name:"request",sessionId:t.sessionId,key:t.key}:t.name==="ask"?{name:"ask",id:t.id}:null;function SN({link:t,store:n,storage:s,fetchImpl:a=vN,updates:r=null,signin:l=null,lost:o=!1,relay:c=globalThis.location.host}){var ct,mt,G,_e,we,le;const i=Di(),m=jN(t),d=xe(n),x=Ps(),p=kN(a,m!=="signed_out"),{build:g,waiting:h}=yN(r),[N,k]=f.useState(null),[C,j]=f.useState(l),[y,b]=f.useState(o),[M,S]=f.useState(!1),[$,v]=f.useState(!1),[A,R]=f.useState(!1),_=f.useRef(!1),[L,T]=f.useState(!1),B=((ct=t.pairing())==null?void 0:ct.state())??null,E=((mt=t.recovery())==null?void 0:mt.state())??null,P=(E==null?void 0:E.step)==="reaching"||(E==null?void 0:E.step)==="faceid"||(E==null?void 0:E.step)==="checking",W=mn(),[F,re]=f.useState(!1),[Y,H]=f.useState(!1),I=(E==null?void 0:E.step)==="done"&&(!d.fresh||ii((G=d.device)==null?void 0:G.push));f.useEffect(()=>{I&&H(!0)},[I]),f.useEffect(()=>{E&&E.step!=="done"&&H(!1)},[E==null?void 0:E.step]);const D=t1(C),Q=C==="not_allowed"?"denied":m==="signed_out"||D||C==="another"?"login":m==="replaced"?"replaced":m==="key_changed"?"keyChanged":m==="denied"?"unrecognized":m==="storage_unavailable"?"storage":(E==null?void 0:E.step)==="done"&&!$?"recover":(B==null?void 0:B.step)==="linked"&&!$?"compare":m==="unpaired"||m==="pairing"?B!==null||L||m==="pairing"&&!P?"compare":E&&E.step!=="cancelled"?"recover":"choose":"route",q=ge=>{_.current=!0,T(!0),ge()},K=()=>{re((E==null?void 0:E.step)==="failed"&&E.why==="old"),q(()=>t.startPairing())};f.useEffect(()=>{m==="ready"&&(_.current=!1,T(!1),b(!1),S(!1)),(m==="unpaired"||m==="pairing")&&(v(!1),R(!1))},[m]),f.useEffect(()=>{var et;const ge=(et=globalThis.navigator)==null?void 0:et.serviceWorker;if(!ge)return;const qe=vt=>Jx(vt.data);return ge.addEventListener("message",qe),()=>ge.removeEventListener("message",qe)},[]);const ee=f.useRef("sessions"),ue=f.useRef([]),fe=xl(x);fe&&(ee.current=fe),f.useEffect(()=>{cp(x)},[x]);const he=Dt(),w=lu(n),[O,V]=f.useState(null);f.useEffect(()=>{const ge=P1(t,n,s);return V(ge),()=>{ge.close(),V(null)}},[t,n,s]);const[Z,X]=f.useState(null);f.useEffect(()=>{const ge=_y(t,n,s);return ge.follow(),X(ge),()=>{ge.close(),X(null)}},[t,n,s]);const J=NN(Z),pe=x.name==="atelier"&&(!he||(d.fresh||d.daemon!==null)&&!((_e=d.daemon)!=null&&_e.atelier));f.useEffect(()=>{pe&&An({name:"sessions"})},[pe]);const Ne=wN(x),Xe=f.useRef(!1),gt=m==="ready"&&d.fresh&&!!((we=d.device)!=null&&we.id)&&!d.device.name;f.useEffect(()=>{!gt||Xe.current||n.renameDevice(hu(void 0))!==null&&(Xe.current=!0)},[gt,n]);const Be=t.pinned(),Je=(Be==null?void 0:Be.name)??null,oe=(Be==null?void 0:Be.name)??((le=d.daemon)==null?void 0:le.name)??null,de=()=>t.retry(),ke=f.useRef(!1),Oe=ge=>{if(!ke.current){if(m!=="ready"){m!=="denied"&&S(!0),ge();return}ke.current=!0,n.forgetDevice().then(qe=>{ke.current=!1,qe||S(!0),ge()})}},lt=()=>Oe(()=>{t.signOut()}),xt=()=>Oe(()=>q(()=>{t.relink()})),kt=(()=>{var bt,wt,Yt,ys;switch(Q){case"denied":return e.jsx(Qj,{onOther:()=>j("another")});case"login":return e.jsx(s1,{server:c,error:D});case"replaced":return e.jsx(a1,{onHere:()=>globalThis.location.reload()});case"keyChanged":return e.jsx(Jj,{pcName:oe,known:Be,received:t.receivedKey(),onRelink:xt,onSignOut:lt});case"unrecognized":return e.jsx(T1,{pcName:oe,onRelink:xt,onSignOut:lt});case"storage":return e.jsx(c1,{onRetry:de,onReload:()=>globalThis.location.reload()});case"choose":return e.jsx(oj,{login:p,platform:W,onPasskey:()=>t.startRecovery(),onCode:K});case"recover":return e.jsx(uj,{state:E,login:p,reach:t.reach(),onRetry:()=>{var nt;(nt=t.recovery())!=null&&nt.again()||t.startRecovery()},onCode:K,onCancel:()=>t.cancelRecovery(),onSignOut:lt,onDone:()=>v(!0),actions:Y?e.jsx(ci,{store:n,fetchImpl:a,body:u.recover.done.notify,onDone:()=>v(!0)}):void 0});case"compare":return e.jsx(rj,{step:B,login:p,pcName:Je,lost:y,stalled:m==="unpaired"&&B===null&&L,reach:t.reach(),onRetry:de,onSame:()=>{var nt;return(nt=t.pairing())==null?void 0:nt.confirmOnPhone()},onCancel:()=>{var nt;return(nt=t.pairing())==null?void 0:nt.cancel()},onRestart:()=>q(()=>t.startPairing()),onDone:()=>v(!0),actions:A?e.jsx(ci,{store:n,fetchImpl:a,onDone:()=>{R(!1),v(!0)}}):e.jsx(mj,{store:n,update:F,onDone:()=>{var nt;ii((nt=d.device)==null?void 0:nt.push)?R(!0):v(!0)}})})}const ge=ro(kn([...d.sessions.values()]),d.asks??[]);Ne&&ge.some(nt=>JSON.stringify(nt)===JSON.stringify(Ne))&&(ue.current=ge);const qe=nt=>()=>{const Rt=ks=>ks.name===nt.name,Ns=Am(ro(kn([...n.getState().sessions.values()]),n.getState().asks??[]).filter(Rt),nt,ue.current.filter(Rt));An(Ns??(nt.name==="ask"?{name:"rigs"}:{name:"sessions"}))},et={pc:oe,look:xp(d.fresh,!!d.syncedAt,t.reach()),reach:t.reach(),since:Ke(d.syncedAt),retry:de,settingsDot:w},vt=!!((bt=d.daemon)!=null&&bt.forge)&&Z!==null,Vt=vt?ug(J):0,tn={sessions:dp(kn([...d.sessions.values()]),(wt=d.daemon)!=null&&wt.taskAnswer?yl(d.tasks.values()).length:0),rigs:up(d.asks??[]),prs:Vt?{text:Vt>99?"99+":String(Vt),tone:"red"}:null},Gt=vt?e.jsx(Iy,{forge:Z,store:n}):e.jsx(o1,{}),Xt=vt&&x.name==="pr"?e.jsx(bN,{id:x.id,forge:Z,store:n,pane:!1},x.id):null,U=e.jsx(sj,{store:n,filter:x.name==="sessions"?x.filter:void 0}),Se=!!((Yt=d.daemon)!=null&&Yt.rigs)&&O!==null,ie=Se?e.jsx(G1,{rigs:O,store:n}):e.jsx(i1,{store:n}),Ie=Se?x.name==="rig"?e.jsx(dy,{rig:x.rig,rigs:O,store:n},x.rig):x.name==="kernel"?e.jsx(ky,{rigs:O,store:n}):x.name==="max"?e.jsx(by,{goalId:x.goalId,rigs:O,store:n},x.goalId??""):null:null,Ce=(x.name==="connection"&&x.section==="usage"?e.jsx(bj,{store:n}):null)??e.jsx(Yj,{store:n,fetchImpl:a,login:p,relay:c,pinned:Be,linkState:m,build:g,onSignOut:lt,section:x.name==="connection"&&x.section==="link"?"link":void 0});if(he){const nt=(()=>{var Rt;switch(x.name){case"ask":return e.jsx(rn,{list:ie,detail:e.jsx(mi,{store:n,id:x.id,onDone:qe({name:"ask",id:x.id})},x.id)});case"request":return e.jsx(rn,{tab:"sessions",list:U,detail:e.jsx(Ir,{store:n,sessionId:x.sessionId,requestKey:x.key,onReconnect:de,onSettled:qe({name:"request",sessionId:x.sessionId,key:x.key}),keys:!0},x.sessionId)});case"sessions":return e.jsx(rn,{tab:"sessions",list:U,detail:e.jsx(io,{...u.split.agent})});case"routines":return e.jsx(rn,{tab:"sessions",list:U,detail:e.jsx(ei,{store:n,focus:x.routine})});case"thread":return e.jsx(rn,{tab:"sessions",list:U,detail:e.jsx(Wr,{store:n,sessionId:x.sessionId,storage:s,onReconnect:de,forge:Z},x.sessionId)});case"launch":return e.jsx(rn,{tab:"sessions",list:U,detail:e.jsx(vi,{store:n,storage:s})});case"terminal":return e.jsx(rn,{tab:"sessions",fold:!0,list:U,detail:e.jsx(gi,{store:n,link:t,sessionId:x.sessionId,storage:s,forge:Z},x.sessionId)});case"prs":case"pr":return e.jsx(rn,{tab:"prs",list:Gt,detail:Xt??e.jsx(xi,{icon:"pr",...u.prs.pane})});case"rigs":case"rig":case"kernel":case"max":return e.jsx(rn,{list:ie,detail:Ie??e.jsx(xi,{icon:"rigs",...u.rigs.pane})});case"atelier":return(Rt=d.daemon)!=null&&Rt.atelier?e.jsx(Mb,{store:n,...x.sessionId?{sessionId:x.sessionId}:{},...x.requestKey?{requestKey:x.requestKey}:{},storage:s,onReconnect:de}):e.jsx(rn,{list:U,detail:e.jsx(io,{...u.split.agent})});case"connection":return Ce}})();return e.jsxs(lr,{value:et,children:[nt,e.jsx(fp,{route:x,active:fe??"settings",badges:tn,atelier:!!((ys=d.daemon)!=null&&ys.atelier)})]})}const He=(nt,Rt=!0)=>e.jsxs(lr,{value:et,children:[Rt&&e.jsx(mp,{...typeof Rt=="string"?{title:Rt}:{}}),nt,e.jsx(pp,{route:x,active:fe??ee.current,badges:tn})]});switch(x.name){case"sessions":case"atelier":return He(U);case"routines":return He(e.jsx(ei,{store:n,focus:x.routine},x.routine??""));case"prs":return He(Gt,vt?u.prs.title:!0);case"pr":return Xt?He(Xt,!1):He(Gt,vt?u.prs.title:!0);case"rigs":return He(ie,Se?u.rigs.title:!0);case"rig":case"kernel":case"max":return Ie?He(Ie,!1):He(ie,Se?u.rigs.title:!0);case"connection":return He(Ce,!1);case"thread":return He(e.jsx(Wr,{store:n,sessionId:x.sessionId,storage:s,onReconnect:de,forge:Z},x.sessionId),!1);case"terminal":return He(e.jsx(gi,{store:n,link:t,sessionId:x.sessionId,storage:s,forge:Z},x.sessionId),!1);case"ask":return He(e.jsx(mi,{store:n,id:x.id},x.id),!1);case"launch":return e.jsx(lr,{value:et,children:e.jsx(vi,{store:n,storage:s})});case"request":return He(e.jsx(Ir,{store:n,sessionId:x.sessionId,requestKey:x.key,onReconnect:de},x.sessionId),!1)}})();return e.jsx(Tx,{copy:Ax(i).ui,children:e.jsxs("div",{className:"app flex flex-col","data-route":x.name,children:[M&&m!=="ready"&&e.jsx("p",{role:"status",className:"mx-4 my-3 text-body text-muted",children:u.forget.pending}),kt,r&&h&&h.fingerprint!==N&&e.jsx(I1,{next:h,current:g,onLater:()=>k(h.fingerprint),onApply:()=>r.accept()})]})})}const RN=Object.freeze(Object.defineProperty({__proto__:null,App:SN},Symbol.toStringTag,{value:"Module"}));export{RN as A,EN as M,h1 as R,_N as a};
|