@paradow/ledge-relay 0.71.0 → 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.
@@ -1,5 +1,5 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/xterm-Mp6tf_7v.js","assets/index-CuDI3tOb.js","assets/index-MFPtqCsL.css","assets/label-yxk5e8gK.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-CuDI3tOb.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-yxk5e8gK.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(`
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
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
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(`
@@ -16,7 +16,7 @@ var Qu=Object.defineProperty;var Zu=(t,n,s)=>n in t?Qu(t,n,{enumerable:!0,config
16
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
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
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-Mp6tf_7v.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(`
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
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&&gt===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
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
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(`