@paradow/ledge-relay 0.65.0 → 0.66.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-CDPb9wXW.js","assets/index-CJFu9LP7.js","assets/index-DlM6pK9t.css","assets/label-CbD8UGH0.js","assets/xterm-DYP7pi_n.css"])))=>i.map(i=>d[i]);
2
- var sm=Object.defineProperty;var nm=(t,s,n)=>s in t?sm(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var Pt=(t,s,n)=>nm(t,typeof s!="symbol"?s+"":s,n);import{r as f,c as d,s as am,j as e,B as Ke,a as Pa,U as Tc,M as ta,o as _c,b as lm,i as Tt,u as qr,d as nn,e as rm,f as Pe,l as lt,t as Do,g as om,L as sr,W as Ra,O as mt,h as Et,H as qt,F as Rt,P as St,S as Vn,K as Pn,k as im,C as kn,m as Ic,n as Qe,I as cm,A as dm,p as um,q as xm,v as Lc,R as mm,w as Fo,x as jn,y as pm,z as fm,D as hm,E as gm,G as bm,J as jm,N as zo,Q as Po,T as Bo,V as Sl,X as ym,Y as Oc,Z as Nm,_ as vm,$ as km,a0 as Ba,a1 as qo,a2 as wm,a3 as Sm,a4 as Dc,a5 as Hr,a6 as Fc,a7 as $m,a8 as Cm,a9 as Mm,aa as Ho,ab as Em,ac as Rm,ad as Uo,ae as Am,af as Tm,ag as _m,ah as Wo,ai as Im,aj as Lm,ak as Om,al as Dm}from"./index-CJFu9LP7.js";import{e as zc,i as ps,a as Fm,p as zm,g as sa,c as Pm,b as Bm,u as me,d as Ur,r as qm,f as Hm,h as Um,j as Pc,k as Wm,l as Ko,m as Vo,n as Km,M as Cs,o as Vm,q as Gm,s as Xm,t as Wr,v as Ym,w as Qm,x as Zm,y as Bc,z as qc,A as Jm,B as Hc,R as Uc,U as Wc}from"./label-CbD8UGH0.js";const ep=["sessions","routines","prs","rigs","chat","connection","kernel","max"],Kc="new";function qa(t){const s=t.replace(/^#\/?/,"").split("/").filter(Boolean);try{if(s[0]==="request"&&s.length===3)return{name:"request",sessionId:decodeURIComponent(s[1]),key:decodeURIComponent(s[2])};if(s[0]==="ask"&&s.length===2)return{name:"ask",id:decodeURIComponent(s[1])};if((s[0]==="thread"||s[0]==="terminal")&&s.length===2)return{name:s[0],sessionId:decodeURIComponent(s[1])};if(s[0]==="atelier"&&s.length===4&&s[2]==="request")return{name:"atelier",sessionId:decodeURIComponent(s[1]),requestKey:decodeURIComponent(s[3])};if(s[0]==="atelier"&&s.length<=2)return s[1]?{name:"atelier",sessionId:decodeURIComponent(s[1])}:{name:"atelier"};if(s[0]==="connection"&&s.length===2&&s[1]==="link")return{name:"connection",section:"link"};if(s[0]==="rigs"&&s.length===2)return{name:"rig",rig:decodeURIComponent(s[1])};if(s[0]==="prs"&&s.length===2)return{name:"pr",id:decodeURIComponent(s[1])};if(s[0]==="routines"&&s.length===2)return{name:"routines",routine:decodeURIComponent(s[1])};if(s[0]==="max"&&s.length===2)return{name:"max",goalId:decodeURIComponent(s[1])};if(s[0]==="sessions"&&s.length===2&&(s[1]==="working"||s[1]==="waiting"))return{name:"sessions",filter:s[1]}}catch{}if(s[0]==="agents"&&s.length===1)return{name:"sessions"};if(s[0]===Kc&&s.length===1)return{name:"launch"};const n=ep.find(a=>a===s[0]);return n&&s.length===1?{name:n}:{name:"atoi"}}function ne(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"?`#/${Kc}`:t.name==="atoi"?"#/":`#/${t.name}`}const tn=t=>{globalThis.location.hash=ne(t)},nr=t=>typeof(t==null?void 0:t.ledge)=="number";let as=0,Bn=[],ar=!1;const lr=t=>{try{globalThis.history.replaceState({...globalThis.history.state,ledge:t},"")}catch{}};function tp(){const t=globalThis.location.hash,s=globalThis.history.state;nr(s)?as=s.ledge:(ar||(as+=1,Bn=Bn.slice(0,as)),lr(as)),ar=!1,Bn[as]=t}if(typeof globalThis.addEventListener=="function"&&globalThis.history&&globalThis.location){const t=globalThis.history.state;as=nr(t)?t.ledge:0,nr(t)||lr(0),Bn[as]=globalThis.location.hash,globalThis.addEventListener("hashchange",tp)}const fs=t=>{ar=!0,globalThis.location.replace(ne(t))};function sp(t){if(as===0)return{route:t,known:!1,inApp:!1};const s=Bn[as-1];return s===void 0?{route:t,known:!1,inApp:!0}:{route:qa(s),known:!0,inApp:!0}}function al(t){as>0?globalThis.history.back():fs(t)}const np=t=>(globalThis.addEventListener("hashchange",t),()=>globalThis.removeEventListener("hashchange",t));function na(){const t=f.useSyncExternalStore(np,()=>globalThis.location.hash,()=>"");return qa(t)}const ap=/^\/#\/[A-Za-z0-9/%._~-]*$/;function lp(t){if(typeof t!="object"||t===null)return;const s=t;s.type!=="ledge.open"||typeof s.url!="string"||!ap.test(s.url)||(globalThis.location.hash=s.url.slice(1))}const Vc=70,aa=6,Go=2,Kr=130,Is=90,Gc=t=>(Math.max(t,2)+1)*Vc,Xc=(t,s=aa,n=Kr)=>Gc(Math.min(t,s))+2*n;function rp(t,s,n=aa,a=Kr){const l=t.slice(0,n),r=Gc(l.length),o=h=>l.length===1?r/2:Vc*(h+1),i=l.map((h,g)=>({session:h,x:o(g),side:l.length===1||g%2===0?"t":"b"})),c={left:[],right:[]},x=new Map,u=[];if(s){for(const[h,g]of l.entries()){const y=g.helpers??[],k=y[0];k&&x.set(g.id,{helper:k,more:y.length-1});const S=o(h)>r/2?"right":"left",b=S==="left"?"right":"left";for(const j of y){const N=c[S].length<Go?S:c[b].length<Go?b:null;N?c[N].push({helper:j,parent:g}):u.push({helper:j,parent:g})}}for(const h of t.slice(n))for(const g of h.helpers??[])u.push({helper:g,parent:h})}const m=["left","right"].flatMap(h=>c[h].map((g,y)=>({...g,end:h,slot:y,count:c[h].length}))),p=t.slice(n);return{length:r,width:Xc(t.length,n,a),seats:i,ends:m,notes:x,extra:{mains:p,helpers:u},extraCount:p.length+u.length}}const qs=84,ga=52;function op(t,s,n){const a=[...s].sort((i,c)=>i-c),l=a.indexOf(t),r=(l<a.length-1?a[l+1]-qs/2:n-6)-(t+qs/2),o=t-qs/2-(l>0?a[l-1]+qs/2:6);return r>=ga+4?t+qs/2+2:o>=ga+4?t-qs/2-ga-2:t+qs/2-ga+8}function ip(t){const s=new Map;for(const a of t)a.branch&&s.set(a.branch,(s.get(a.branch)??0)+1);let n=null;for(const[a,l]of s)(n===null||l>s.get(n))&&(n=a);return n}function Xo(t,s){return t==="idle"?"done":t==="readonly"?"working":t}const cp={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"},Yc=t=>cp[t.state];function dp(t,s,n,a,l,r){const o=s??[],i=new Set(o.map(k=>k.id)),c=k=>{const S=n(k);return S!==null&&i.has(S)?S:null},x=t.filter(k=>!k.rig),u=o.filter(k=>a==="all").map(k=>({project:k,tables:[{key:`common:${k.id}`,mains:x.filter(S=>c(S)===k.id)}]})).filter(k=>k.tables[0].mains.length>0),m=up(t.filter(k=>k.rig),k=>{var S;return((S=o.find(b=>b.id===k))==null?void 0:S.name)??null},n,r),p=[...m.filter(k=>k.rig.kind==="kernel"),...u,...m.filter(k=>k.rig.kind==="rig")],h=a==="all"||a==="none"?x.filter(k=>c(k)===null):[],g=a==="all"||a==="none"?void 0:o.find(k=>k.id===a),y=g&&p.length===0?g:null;return{rooms:p,unassigned:h,empty:y}}const $l="kernel";function up(t,s,n,a){const l=new Map;for(const r of t)l.set(r.rig.name,[...l.get(r.rig.name)??[],r]);return[...l].sort(([r],[o])=>r===$l?-1:o===$l?1:r.localeCompare(o)).map(([r,o])=>{const i=r===$l?"kernel":"rig",c=n(o[0]);return{project:a({id:`rig:${r}`,name:r,kind:i}),tables:[{key:`rig:${r}`,mains:o}],rig:{kind:i,name:r,folder:o[0].cwd??"",project:c?s(c):null}}})}const xp=t=>t==="kernel"?"violet":"slate",Qc=110,mp=150,Zc=70,pp=(t,s=aa,n=Kr)=>t.reduce((a,l,r)=>a+Xc(l.mains.length,s,n)+(r>0?Zc:0),0)+2*Qc;function Vt(t){const s=[];for(const n of t){const a=n.pending;a!=null&&a.key&&s.push({sessionId:n.id,key:a.key,kind:a.kind,filter:a.kind==="question"?"question":"permission",task:n.topic??n.project,botName:n.name,tool:n.tool,repo:n.repo??n.project,...n.branch?{branch:n.branch}:{},...n.worktree?{worktree:!0}:{},since:n.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 s.sort((n,a)=>Date.parse(n.since)-Date.parse(a.since))}const Cl=(t,s)=>s==="all"?t:t.filter(n=>n.filter===s);function yn(t,s){const n=Math.max(0,Math.floor((s-Date.parse(t))/1e3)),a=d.inbox.age;return n<60?a.s(n):n<3600?a.min(Math.floor(n/60)):n<86400?a.h(Math.floor(n/3600)):a.d(Math.floor(n/86400))}const rr=t=>{var s;return((s=t.split(`
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/xterm-DmfYKkwX.js","assets/index-C5B85TXh.js","assets/index-DlM6pK9t.css","assets/label-C-VicMT7.js","assets/xterm-DYP7pi_n.css"])))=>i.map(i=>d[i]);
2
+ var sm=Object.defineProperty;var nm=(t,s,n)=>s in t?sm(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var Pt=(t,s,n)=>nm(t,typeof s!="symbol"?s+"":s,n);import{r as f,c as d,s as am,j as e,B as Ke,a as Pa,U as Tc,M as ta,o as _c,b as lm,i as Tt,u as qr,d as nn,e as rm,f as Pe,l as lt,t as Do,g as om,L as sr,W as Ra,O as mt,h as Et,H as qt,F as Rt,P as St,S as Vn,K as Pn,k as im,C as kn,m as Ic,n as Qe,I as cm,A as dm,p as um,q as xm,v as Lc,R as mm,w as Fo,x as jn,y as pm,z as fm,D as hm,E as gm,G as bm,J as jm,N as zo,Q as Po,T as Bo,V as Sl,X as ym,Y as Oc,Z as Nm,_ as vm,$ as km,a0 as Ba,a1 as qo,a2 as wm,a3 as Sm,a4 as Dc,a5 as Hr,a6 as Fc,a7 as $m,a8 as Cm,a9 as Mm,aa as Ho,ab as Em,ac as Rm,ad as Uo,ae as Am,af as Tm,ag as _m,ah as Wo,ai as Im,aj as Lm,ak as Om,al as Dm}from"./index-C5B85TXh.js";import{e as zc,i as ps,a as Fm,p as zm,g as sa,c as Pm,b as Bm,u as me,d as Ur,r as qm,f as Hm,h as Um,j as Pc,k as Wm,l as Ko,m as Vo,n as Km,M as Cs,o as Vm,q as Gm,s as Xm,t as Wr,v as Ym,w as Qm,x as Zm,y as Bc,z as qc,A as Jm,B as Hc,R as Uc,U as Wc}from"./label-C-VicMT7.js";const ep=["sessions","routines","prs","rigs","chat","connection","kernel","max"],Kc="new";function qa(t){const s=t.replace(/^#\/?/,"").split("/").filter(Boolean);try{if(s[0]==="request"&&s.length===3)return{name:"request",sessionId:decodeURIComponent(s[1]),key:decodeURIComponent(s[2])};if(s[0]==="ask"&&s.length===2)return{name:"ask",id:decodeURIComponent(s[1])};if((s[0]==="thread"||s[0]==="terminal")&&s.length===2)return{name:s[0],sessionId:decodeURIComponent(s[1])};if(s[0]==="atelier"&&s.length===4&&s[2]==="request")return{name:"atelier",sessionId:decodeURIComponent(s[1]),requestKey:decodeURIComponent(s[3])};if(s[0]==="atelier"&&s.length<=2)return s[1]?{name:"atelier",sessionId:decodeURIComponent(s[1])}:{name:"atelier"};if(s[0]==="connection"&&s.length===2&&s[1]==="link")return{name:"connection",section:"link"};if(s[0]==="rigs"&&s.length===2)return{name:"rig",rig:decodeURIComponent(s[1])};if(s[0]==="prs"&&s.length===2)return{name:"pr",id:decodeURIComponent(s[1])};if(s[0]==="routines"&&s.length===2)return{name:"routines",routine:decodeURIComponent(s[1])};if(s[0]==="max"&&s.length===2)return{name:"max",goalId:decodeURIComponent(s[1])};if(s[0]==="sessions"&&s.length===2&&(s[1]==="working"||s[1]==="waiting"))return{name:"sessions",filter:s[1]}}catch{}if(s[0]==="agents"&&s.length===1)return{name:"sessions"};if(s[0]===Kc&&s.length===1)return{name:"launch"};const n=ep.find(a=>a===s[0]);return n&&s.length===1?{name:n}:{name:"atoi"}}function ne(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"?`#/${Kc}`:t.name==="atoi"?"#/":`#/${t.name}`}const tn=t=>{globalThis.location.hash=ne(t)},nr=t=>typeof(t==null?void 0:t.ledge)=="number";let as=0,Bn=[],ar=!1;const lr=t=>{try{globalThis.history.replaceState({...globalThis.history.state,ledge:t},"")}catch{}};function tp(){const t=globalThis.location.hash,s=globalThis.history.state;nr(s)?as=s.ledge:(ar||(as+=1,Bn=Bn.slice(0,as)),lr(as)),ar=!1,Bn[as]=t}if(typeof globalThis.addEventListener=="function"&&globalThis.history&&globalThis.location){const t=globalThis.history.state;as=nr(t)?t.ledge:0,nr(t)||lr(0),Bn[as]=globalThis.location.hash,globalThis.addEventListener("hashchange",tp)}const fs=t=>{ar=!0,globalThis.location.replace(ne(t))};function sp(t){if(as===0)return{route:t,known:!1,inApp:!1};const s=Bn[as-1];return s===void 0?{route:t,known:!1,inApp:!0}:{route:qa(s),known:!0,inApp:!0}}function al(t){as>0?globalThis.history.back():fs(t)}const np=t=>(globalThis.addEventListener("hashchange",t),()=>globalThis.removeEventListener("hashchange",t));function na(){const t=f.useSyncExternalStore(np,()=>globalThis.location.hash,()=>"");return qa(t)}const ap=/^\/#\/[A-Za-z0-9/%._~-]*$/;function lp(t){if(typeof t!="object"||t===null)return;const s=t;s.type!=="ledge.open"||typeof s.url!="string"||!ap.test(s.url)||(globalThis.location.hash=s.url.slice(1))}const Vc=70,aa=6,Go=2,Kr=130,Is=90,Gc=t=>(Math.max(t,2)+1)*Vc,Xc=(t,s=aa,n=Kr)=>Gc(Math.min(t,s))+2*n;function rp(t,s,n=aa,a=Kr){const l=t.slice(0,n),r=Gc(l.length),o=h=>l.length===1?r/2:Vc*(h+1),i=l.map((h,g)=>({session:h,x:o(g),side:l.length===1||g%2===0?"t":"b"})),c={left:[],right:[]},x=new Map,u=[];if(s){for(const[h,g]of l.entries()){const y=g.helpers??[],k=y[0];k&&x.set(g.id,{helper:k,more:y.length-1});const S=o(h)>r/2?"right":"left",b=S==="left"?"right":"left";for(const j of y){const N=c[S].length<Go?S:c[b].length<Go?b:null;N?c[N].push({helper:j,parent:g}):u.push({helper:j,parent:g})}}for(const h of t.slice(n))for(const g of h.helpers??[])u.push({helper:g,parent:h})}const m=["left","right"].flatMap(h=>c[h].map((g,y)=>({...g,end:h,slot:y,count:c[h].length}))),p=t.slice(n);return{length:r,width:Xc(t.length,n,a),seats:i,ends:m,notes:x,extra:{mains:p,helpers:u},extraCount:p.length+u.length}}const qs=84,ga=52;function op(t,s,n){const a=[...s].sort((i,c)=>i-c),l=a.indexOf(t),r=(l<a.length-1?a[l+1]-qs/2:n-6)-(t+qs/2),o=t-qs/2-(l>0?a[l-1]+qs/2:6);return r>=ga+4?t+qs/2+2:o>=ga+4?t-qs/2-ga-2:t+qs/2-ga+8}function ip(t){const s=new Map;for(const a of t)a.branch&&s.set(a.branch,(s.get(a.branch)??0)+1);let n=null;for(const[a,l]of s)(n===null||l>s.get(n))&&(n=a);return n}function Xo(t,s){return t==="idle"?"done":t==="readonly"?"working":t}const cp={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"},Yc=t=>cp[t.state];function dp(t,s,n,a,l,r){const o=s??[],i=new Set(o.map(k=>k.id)),c=k=>{const S=n(k);return S!==null&&i.has(S)?S:null},x=t.filter(k=>!k.rig),u=o.filter(k=>a==="all").map(k=>({project:k,tables:[{key:`common:${k.id}`,mains:x.filter(S=>c(S)===k.id)}]})).filter(k=>k.tables[0].mains.length>0),m=up(t.filter(k=>k.rig),k=>{var S;return((S=o.find(b=>b.id===k))==null?void 0:S.name)??null},n,r),p=[...m.filter(k=>k.rig.kind==="kernel"),...u,...m.filter(k=>k.rig.kind==="rig")],h=a==="all"||a==="none"?x.filter(k=>c(k)===null):[],g=a==="all"||a==="none"?void 0:o.find(k=>k.id===a),y=g&&p.length===0?g:null;return{rooms:p,unassigned:h,empty:y}}const $l="kernel";function up(t,s,n,a){const l=new Map;for(const r of t)l.set(r.rig.name,[...l.get(r.rig.name)??[],r]);return[...l].sort(([r],[o])=>r===$l?-1:o===$l?1:r.localeCompare(o)).map(([r,o])=>{const i=r===$l?"kernel":"rig",c=n(o[0]);return{project:a({id:`rig:${r}`,name:r,kind:i}),tables:[{key:`rig:${r}`,mains:o}],rig:{kind:i,name:r,folder:o[0].cwd??"",project:c?s(c):null}}})}const xp=t=>t==="kernel"?"violet":"slate",Qc=110,mp=150,Zc=70,pp=(t,s=aa,n=Kr)=>t.reduce((a,l,r)=>a+Xc(l.mains.length,s,n)+(r>0?Zc:0),0)+2*Qc;function Vt(t){const s=[];for(const n of t){const a=n.pending;a!=null&&a.key&&s.push({sessionId:n.id,key:a.key,kind:a.kind,filter:a.kind==="question"?"question":"permission",task:n.topic??n.project,botName:n.name,tool:n.tool,repo:n.repo??n.project,...n.branch?{branch:n.branch}:{},...n.worktree?{worktree:!0}:{},since:n.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 s.sort((n,a)=>Date.parse(n.since)-Date.parse(a.since))}const Cl=(t,s)=>s==="all"?t:t.filter(n=>n.filter===s);function yn(t,s){const n=Math.max(0,Math.floor((s-Date.parse(t))/1e3)),a=d.inbox.age;return n<60?a.s(n):n<3600?a.min(Math.floor(n/60)):n<86400?a.h(Math.floor(n/3600)):a.d(Math.floor(n/86400))}const rr=t=>{var s;return((s=t.split(`
3
3
  `).find(n=>n.trim()))==null?void 0:s.trim())??""};function wn(t){switch(t.kind){case"question":return t.text;case"plan":return d.inbox.plan;case"diff":return d.inbox.diff(rr(t.text)).trim();default:return rr(t.text)}}const Jc=["all","waiting","working"],or=t=>t.pending!==void 0||t.state==="waiting_permission"||t.state==="waiting_input";function ir(t,s){return s==="waiting"?or(t):s==="working"?t.state==="working"&&!or(t):!0}function Ha(t){return or(t)?0:t.state==="working"?1:t.state==="exited"?3:2}function Vr(t,s,n){n&&(t=am(t,{projectIds:n.projects.map(o=>o.id),order:n.order,projectOf:o=>o.projectId??null,keyOf:o=>o.id}));const a=new Map,l=new Map;for(const o of t){if(!ir(o,s))continue;const[i,c,x]=o.rig?[l,"rig",o.rig.name]:[a,"project",o.project];let u=i.get(x);u||i.set(x,u={id:`${c}:${x}`,kind:c,name:x,sessions:[],...c==="project"?{project:o.projectId??null}:{}}),u.sessions.push(o)}const r=o=>({...o,sessions:o.sessions.map((i,c)=>[i,c]).sort((i,c)=>Ha(i[0])-Ha(c[0])||i[1]-c[1]).map(([i])=>i)});return[...[...a.values()].map(o=>n?o:r(o)),...[...l.values()].map(r)]}const Gr=["projects","rigs"];function fp(t,s){const n=Vr(t,"all");if(s==="projects")return n;const a=t.filter(l=>!l.rig).map((l,r)=>[l,r]).sort((l,r)=>Ha(l[0])-Ha(r[0])||l[1]-r[1]).map(([l])=>l);return[...n.filter(l=>l.kind==="rig"),...a.length?[{id:"outside",kind:"outside",name:d.sessions.outsideRig,sessions:a}]:[]]}function hp(t){if(t.kind!=="project")return null;const s=t.sessions.map(Sn);return s.includes("perm")?"perm":s.includes("ask")?"ask":null}function gp(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 ed=t=>({all:t.length,waiting:t.filter(s=>ir(s,"waiting")).length,working:t.filter(s=>ir(s,"working")).length});function Sn(t){const s=Vt([t])[0];return s?s.kind==="question"?"ask":"perm":t.state==="waiting_permission"?"perm":t.state==="waiting_input"?"ask":t.state==="working"?"work":t.state==="exited"?"done":"idle"}const bp=t=>t.helpers.filter(s=>s.state!=="exited"&&s.finishedAt===void 0).length;function jp(t,s,n=Date.now()){const a=d.sessions.line;if(s==="working")return Xr(t);const l=td(t),r=l===void 0?"":` · ${l} %`,o=Vt([t])[0];if(o)return(o.kind==="permission"?a.permission:d.atoi.pill[o.kind])+r;switch(t.state){case"waiting_permission":return a.permission+r;case"waiting_input":return d.atoi.pill.question+r;case"working":return a.working+r;case"exited":return t.exitedAt?a.ended(zc(t.exitedAt,n)):a.endedPlain;case"error":return a.error;default:return a.idle+r}}const Xr=t=>{var s;return((s=t.doing)==null?void 0:s.label)||d.sessions.line.thinking},td=t=>t.context?Math.round(Math.min(1,t.context.used/t.context.window)*100):void 0;function yp(t){if(t.rig)return t.rig.role;if(t.branch)return t.branch.split("/").filter(Boolean).pop()??t.branch}function Nn({d:t,size:s=16,fill:n}){return e.jsxs("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.map((a,l)=>e.jsx("path",{d:a},l)),n==null?void 0:n.map((a,l)=>e.jsx("path",{d:a,fill:"currentColor",stroke:"none"},`f${l}`))]})}const hn={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"]}},et=(t,s,n)=>`M${t-n} ${s}a${n} ${n} 0 1 0 ${2*n} 0a${n} ${n} 0 1 0 ${-2*n} 0`,cn=(t,s,n,a,l)=>`M${t+l} ${s}h${n-2*l}a${l} ${l} 0 0 1 ${l} ${l}v${a-2*l}a${l} ${l} 0 0 1 ${-l} ${l}h${-(n-2*l)}a${l} ${l} 0 0 1 ${-l} ${-l}v${-(a-2*l)}a${l} ${l} 0 0 1 ${l} ${-l}z`,Np={back:hn.chevronLeft.d,chevron:hn.chevronRight.d,close:hn.close.d,check:hn.check.d,plus:hn.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",et(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:[cn(3,4,18,16,2),"M7 9h10M7 13h6"],pr:[et(6,5,2.2),et(6,19,2.2),et(18,19,2.2),"M6 7.2v9.6M18 16.8V10a3 3 0 0 0-3-3h-4","M13 5l-2 2 2 2"],rigs:[et(6,6,2.5),et(18,6,2.5),et(12,18,2.5),"M8 7.5l3 8M16 7.5l-3 8M8.5 6h7"],ledge:[cn(4,8,16,12,3),"M12 8V4.5",et(9,14,1),et(15,14,1)],search:[et(11,11,7),"M20 20l-4-4"],more:[et(12,5,1.4),et(12,12,1.4),et(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:[cn(3,10,18,5,1),et(7,6,2),et(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:[et(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:[cn(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:[et(12,12,9),"M12 7v5l3 2"],alarm:[et(12,13,8),"M12 9v4l2.5 1.5M5 3 2 6M19 3l3 3"],play:["M7 5v14l11-7z"],lock:[cn(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:[cn(6,6,12,12,2),"M9 2v4M15 2v4M9 18v4M15 18v4M2 9h4M2 15h4M18 9h4M18 15h4"],camera:["M4 8h3l2-3h6l2 3h3v11H4z",et(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:[et(6,5,2),et(6,19,2),et(18,8,2),"M6 7v10M18 10c0 4-6 3-12 7"],merge:[et(6,5,2.2),et(6,19,2.2),et(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:[et(12,12,3.5),"M3 12h5.5M15.5 12H21"]};function q({name:t,className:s="size-5",stroke:n=1.6}){return e.jsx("svg",{className:`flex-none ${s}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:n,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:Np[t].map((a,l)=>e.jsx("path",{d:a},l))})}const vp={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 Ie({state:t,pulse:s=!1,label:n}){return e.jsx("span",{"data-dot":t,...n?{role:"img","aria-label":n}:{"aria-hidden":!0},className:`inline-block size-2 flex-none rounded-full ${vp[t]} ${s?"animate-[ledge-pulse_1.6s_ease-in-out_infinite]":""}`})}const kp={claude:"CC",codex:"CX",cursor:"CU",omp:"OM"};function gs({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:kp[t]})}const wp={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 zt({tone:t="plain",children:s}){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 ${wp[t]}`,children:s})}function os({title:t,dot:s,count:n,sub:a,tone:l,none:r,label:o,children:i}){return e.jsxs("section",{"aria-label":t??o,className:`flex-none overflow-hidden rounded-[10px] border bg-surface dark:bg-transparent ${l==="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:[s&&e.jsx(Ie,{state:s}),e.jsx("b",{className:"text-body font-semibold whitespace-nowrap",children:t}),n!==void 0&&e.jsx("span",{className:"text-[12.5px] text-muted",children:n}),a&&e.jsx("span",{className:"min-w-0 flex-1 truncate text-small text-muted",children:a})]}),r!==void 0?e.jsx("p",{className:"p-3 text-[13px] text-muted",children:r}):e.jsx("div",{className:"flex flex-col",children:i})]})}function Zs({lead:t,title:s,sub:n,subTone:a,meta:l,metaWarn:r=!1,selected:o=!1,stale:i=!1,pressed:c=!1,href:x,press:u,children:m}){const p=`flex min-h-[52px] items-center gap-2 border-b border-line px-3 py-1.5 text-[13.5px] last:border-b-0 ${i?"opacity-60":""} ${o?"bg-secondary shadow-[inset_2px_0_0_var(--color-primary)]":""} ${c?"shadow-[inset_0_0_0_2px_var(--color-ring)]":""}`,h=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:s}),n!==void 0&&e.jsx("span",{className:`truncate text-small leading-4 ${a==="perm"?"text-approval":"text-muted"}`,children:n})]}),l!==void 0&&e.jsx("span",{className:`font-mono text-small whitespace-nowrap ${r?"text-attention":"text-muted"}`,children:l}),m]});return x?e.jsx("a",{href:x,"aria-current":o?"page":void 0,className:p,...u,children:h}):e.jsx("div",{className:p,children:h})}const Sp={plain:"border-line",perm:"border-destructive/45",ask:"border-attention/45",rig:"border-destructive/40"};function $n({tone:t="plain",selected:s=!1,label:n,children:a}){return e.jsx("article",{"aria-label":n,"data-card":t,className:`flex flex-col gap-2.5 rounded-lg border bg-surface p-3 ${Sp[t]} ${s?"shadow-[0_0_0_2px_var(--color-ring)]":""}`,children:a})}function Jt({glyph:t,title:s,body:n,action:a,framed:l=!0,list:r=!1}){return e.jsxs("div",{"data-list-state":r?"":void 0,className:"flex flex-col items-center gap-1.5 px-4 pt-[26px] pb-[22px] text-center",children:[l?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:s}),e.jsx("p",{className:"max-w-[300px] text-[13.5px] text-muted",children:n}),a&&e.jsx("div",{className:"mt-2",children:a})]})}const $p={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"},Cp={md:"h-11 px-3.5 text-body",sm:"h-9 px-3 text-[13px]",xs:"h-8 px-2.5 text-[12.5px]"},Fe=({variant:t="outline",size:s="md",className:n}={})=>["inline-flex items-center justify-center gap-2 rounded-lg border font-medium whitespace-nowrap transition-colors duration-100 disabled:opacity-45",$p[t],t==="ghost"?"h-9 px-3.5":Cp[s],n??""].filter(Boolean).join(" ");function Mp({label:t,options:s,value:n,onChange:a}){return e.jsx("div",{role:"group","aria-label":t,className:"flex flex-none gap-1.5 overflow-x-auto",children:s.map(l=>e.jsxs("button",{type:"button","aria-pressed":l.value===n,onClick:()=>a(l.value),className:"inline-flex h-8 flex-none items-center gap-1.5 rounded-lg border border-input px-3 text-[13px] font-medium whitespace-nowrap text-muted aria-pressed:border-ring aria-pressed:bg-raised aria-pressed:text-fg",children:[l.label,l.count!==void 0&&e.jsx("span",{className:"font-mono text-meta",children:l.count})]},l.value))})}function la({back:t,tool:s,name:n,dot:a,pulse:l=!1,sub:r,under:o=!1,more:i}){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,s&&e.jsx(gs,{tool:s}),o&&r?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:n}),a&&e.jsx(Ie,{state:a,pulse:l})]}),e.jsx("span",{className:"truncate text-[12px] leading-4 text-muted",children:r})]}):e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-base font-semibold whitespace-nowrap",children:n}),a&&e.jsx(Ie,{state:a,pulse:l}),r&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:r}),e.jsx("span",{className:"flex-1"})]}),i]})}function sd({label:t,sendLabel:s,placeholder:n,offlinePlaceholder:a,value:l,onChange:r,onSend:o,offline:i=!1}){const c=f.useId(),x=!i&&l.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)] ${i?"opacity-55":""}`,children:[e.jsx("label",{htmlFor:c,className:"sr-only",children:t}),e.jsx("textarea",{id:c,rows:1,value:i?"":l,disabled:i,placeholder:i?a:n,onChange:u=>r(u.target.value),className:"min-h-[34px] min-w-0 flex-1 resize-none bg-transparent py-[7px] text-base leading-[22px] text-fg outline-none placeholder:text-muted"}),e.jsx("button",{type:"button",disabled:!x,onClick:o,"aria-label":s,title:s,className:"grid size-9 flex-none place-items-center rounded-lg bg-primary text-primary-fg disabled:opacity-40",children:e.jsx(q,{name:"send",className:"size-[18px]"})})]})}function Ep({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 nd={permission:"approval",question:"attention",plan:"info",diff:"info"};function Rp(t,s){if(s){const n=s.risk==="high"&&s.kind!=="question";return{tone:n?"danger":nd[s.kind],label:n?d.risk.badge:d.kind[s.kind]}}switch(t.state){case"waiting_permission":return{tone:"approval",label:d.kind.permission};case"waiting_input":return{tone:"attention",label:d.kind.question};case"idle":return{tone:"ok",label:d.agents.state.idle};case"exited":return{tone:"muted",label:d.agents.state.exited};case"error":return{tone:"danger",label:d.agents.state.error};default:return{tone:"info",label:d.agents.state.working}}}const Ap=t=>Rp(t,Vt([t])[0]);function ad({store:t,label:s,ids:n,offline:a,startOpen:l=!1,onCancel:r}){const[o,i]=f.useState(l),[c,x]=f.useState(""),[u,m]=f.useState(!1),[p,h]=f.useState(null),g=async()=>{if(n.length>Pa){h({lines:[d.agents.tooMany(n.length,Pa)],error:!0});return}m(!0);const y=await t.broadcast(n,c.trim());if(m(!1),y.sent){const k=y.sent;h({lines:[...k.length?[d.agents.sentTo(k)]:[d.agents.nobody],...(y.refused??[]).map(S=>d.agents.refusedLine(S.name,S.reason))],error:k.length===0}),k.length&&(i(l),x(""))}else y.status==="expired"?h({lines:[d.agents.uncertain],error:!0}):h({lines:[d.agents.notSent],error:!0})};return e.jsxs("div",{className:"pb-2",children:[!o&&e.jsx("button",{type:"button",disabled:a,onClick:()=>{h(null),i(!0)},className:"text-meta text-info disabled:opacity-60",children:d.agents.writeGroup}),o&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:`group-${n[0]}`,className:"sr-only",children:d.agents.writeGroupLabel(s)}),e.jsx("textarea",{id:`group-${n[0]}`,rows:2,value:c,disabled:u,placeholder:d.agents.writeGroupPlaceholder,onChange:y=>x(y.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(Ke,{variant:"ghost",className:"flex-1",disabled:u,onClick:()=>{i(!1),x(""),r==null||r()},children:d.agents.cancel}),e.jsx(Ke,{variant:"primary",className:"flex-[2]",disabled:u||!c.trim(),onClick:()=>void g(),children:d.agents.send})]})]}),p&&e.jsx("div",{role:"status",className:`mt-1 text-meta ${p.error?"text-attention":"text-muted"}`,children:p.lines.map((y,k)=>e.jsx("p",{className:"[overflow-wrap:anywhere]",children:y},k))})]})}const Yo=new Set(["-o","--push-option","--repo","--receive-pack","--exec"]),Tp=new Set(["-f","--force","--force-with-lease","--force-if-includes","--delete","-d","--mirror","--prune"]);function _p(t){const s=t.trim().split(/\s+/);if(s[0]!=="git")return null;const n=s.indexOf("push");if(n<1)return null;let a=!1;const l=[],r=s.slice(n+1);for(let u=0;u<r.length;u++){const m=r[u];if(m.startsWith("--")){const p=m.split("=")[0];Tp.has(p)?a=!0:Yo.has(p)&&!m.includes("=")&&u++}else m.startsWith("-")&&m.length>1?/[fd]/.test(m.slice(1))?a=!0:Yo.has(m)&&u++:l.push(m)}const[o="",...i]=l;i.some(u=>u.startsWith("+")||u.startsWith(":"))&&(a=!0);const c=i[0],x=c==null?void 0:c.replace(/^\+/,"").split(":").pop();return{remote:o,...x?{branch:x}:{},force:a}}function Ip(t){return t.risk!=="low"||t.riskReason!=="edit_inside_folder"?null:{title:d.detail.editsInProject,body:d.detail.editsInProjectBody}}function ld(t){if(t.risk==="low")return null;const s=d.consequence,n=t.riskReason;if(n==="pushes"){const a=_p(t.text),l=a!=null&&a.remote?a.branch?`${a.remote}/${a.branch}`:a.remote:s.configuredRemote;return a!=null&&a.force?{title:s.forceTitle,body:s.forceBody(a.remote?l:void 0),destination:l}:{title:s.pushTitle,body:s.pushBody,destination:l}}switch(n){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,l]=s[n];return{title:a,body:l}}default:{const[a,l]=s.unknown;return{title:a,body:l}}}}const Yr=ta,Lp=/^[1-9]$/;function rd(t){const s=t.trim();return s===""?{text:s,problem:"empty"}:Tc.test(s)?{text:s,problem:"untypable"}:s.length>Yr?{text:s,problem:"long"}:Lp.test(s)?{text:s,problem:"digit"}:{text:s,problem:null}}function Qr(t,s,n){var a;if(t.kind==="plan"||t.kind==="diff")return{kind:"examine"};if((s==null?void 0:s.decide)===!1||t.kind==="question"&&(s==null?void 0:s.questions)===!0&&t.requestId!==void 0&&((a=t.questions)!=null&&a.length))return{kind:"examine"};if(t.kind==="question"){if(n)return{kind:"readOnly"};const l=t.options??[],r=(s==null?void 0:s.freeTextAnswer)===!0;return r||l.length>0?{kind:"question",options:l,other:r}:{kind:"answerOnPc",options:l}}return t.risk==="high"?{kind:"high"}:{kind:"permission",always:_c(t.tool,t.kind,"always")}}const cr=t=>lm(t.tool,{kind:t.kind,...t.pendingTool?{tool:t.pendingTool}:{}}),Ua=t=>t==="project"?d.atoi.always:t==="plan"?d.atoi.approveAuto:d.atoi.alwaysSession,Qo={critical:0,urgent:1,routine:2},od=t=>[...t].sort((s,n)=>Qo[s.priority]-Qo[n.priority]||Date.parse(s.createdAt)-Date.parse(n.createdAt)),id=t=>t.kind==="update"?"update":t.kind==="parked"?"parked":t.questions.length>0?"decision":"question",Op=t=>(t==null?void 0:t.replace(/\.agent$|\.lead$|\.worker$/,""))??null,cd=t=>({name:t.from.seat.split("@")[0]||t.from.seat,role:Op(t.from.role)});function Zo(t,s){var l;const n=t.questions.find(r=>r.id===s),a=n==null?void 0:n.answer;return a?a.kind==="words"?a.text:((l=n.options.find(r=>r.id===a.id))==null?void 0:l.label)??a.id:null}function Dp(t,s){var n,a;switch(s.kind){case"choice":return((a=(n=t.questions.find(l=>l.id===s.questionId))==null?void 0:n.options.find(l=>l.id===s.optionId))==null?void 0:a.label)??s.optionId;case"words":case"resolve":return s.text;case"seen":return""}}function dd(t,s){const n=Object.values(s).filter(r=>r.message.type==="openrig.answer"&&r.message.qitemId===t).sort((r,o)=>r.at.localeCompare(o.at)),a=n[n.length-1];if(!a)return{kind:"none"};const l=a.message.answer;if(a.rig){const r=a.rig;return r.rejected?{kind:"refused",answer:l,reason:r.rejected}:r.ok?r.outcome==="recorded"?{kind:"recorded",answer:l}:r.outcome==="already"?{kind:"already"}:{kind:"sent",answer:l}:r.error==="closed"||r.error==="not_found"?{kind:"already"}:r.error==="uncertain"?{kind:"uncertain",answer:l}:{kind:"failed",answer:l,error:r.error??"unreachable",...r.message?{message:r.message}:{}}}return ps(a.phase)?a.phase==="uncertain"?{kind:"uncertain",answer:l}:{kind:"sending",answer:l}:a.phase==="applied"?{kind:"sent",answer:l}:{kind:"failed",answer:l,error:a.reason??"unreachable"}}const Aa=5;function Fp(t,s){return t.filter(n=>n.state==="working"&&!s.has(n.id)).sort((n,a)=>Date.parse(a.lastActivityAt)-Date.parse(n.lastActivityAt))}const zp=6,ud=5e3;function Ml(t,s){return[...t.map(n=>({name:"request",sessionId:n.sessionId,key:n.key})),...od(s).filter(n=>n.kind!=="update").map(n=>({name:"ask",id:n.id}))]}const Ta=(t,s)=>t.name==="request"?s.name==="request"&&t.sessionId===s.sessionId:s.name==="ask"&&t.id===s.id;function Pp(t,s,n=t){const a=t.filter(o=>!Ta(o,s)),l=n.findIndex(o=>Ta(o,s));return(l<0?[]:n.slice(l+1)).find(o=>a.some(i=>Ta(i,o)))??a[0]??null}function Bp(t,s,n){if(!t.length)return null;const a=s?t.findIndex(l=>Ta(l,s)):-1;return a<0?t[0]:t[Math.min(t.length-1,Math.max(0,a+n))]}function Gn(t,s,n){var i;const a=(i=s.find(c=>c.id===t.sessionId))==null?void 0:i.pending,l=(a==null?void 0:a.key)===t.key,r=Object.values(n).filter(c=>"id"in c.message&&c.message.id===t.sessionId&&Fm(c.message)===t.key).sort((c,x)=>c.at.localeCompare(x.at)),o=r.find(c=>c.phase==="applied")??r[r.length-1];if(o){const c=o.message;switch(o.phase){case"sending":return{kind:"sending"};case"uncertain":return{kind:"uncertain"};case"applied":return{kind:"applied",...c.type==="session.decide"?{decision:c.decision}:{},...c.type==="session.reply"?{answer:c.text}:{},...c.type==="session.answer"?{answer:c.answers.flatMap(x=>x.selected).join(", ")}:{}};case"rejected":return o.reason==="stale"&&!l?a!=null&&a.key?{kind:"changed"}:{kind:"handledElsewhere"}:{kind:"rejected",reason:o.reason??"invalid"};case"failed":return{kind:"failed",reason:o.reason??"invalid"}}}return l?{kind:"idle"}:{kind:"handledElsewhere"}}function Cn(t=4e3){const[s,n]=f.useState(!1);return f.useEffect(()=>{if(!s)return;const a=setTimeout(()=>n(!1),t);return()=>clearTimeout(a)},[s,t]),[s,n]}function Xt(){const[t,s]=f.useState(Date.now);return f.useEffect(()=>{const n=setInterval(()=>s(Date.now()),15e3);return()=>clearInterval(n)},[]),t}const qp={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 ra({tone:t,label:s}){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 ${qp[t]}`,children:s})}function Hp({kind:t,risk:s="low"}){const n=s==="high"&&t!=="question";return e.jsx(ra,{tone:n?"danger":nd[t],label:n?d.risk.badge:d.kind[t]})}function Up({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 Mn=t=>{var s;return{fresh:t.fresh,pc:((s=t.daemon)==null?void 0:s.name)??null}};function xd({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?d.link.online:d.link.offline]})]})}function is({fallback:t,label:s}){const n=sp(t),a=n.inApp?n.known?d.nav.backTo[n.route.name]??d.nav.back:d.nav.back:s;return e.jsx("a",{href:ne(n.route),"data-back":t.name,"aria-label":a,title:a,onClick:l=>{l.preventDefault(),al(t)},className:Tt({className:"-ml-2"}),children:e.jsx(q,{name:"back"})})}function oa({title:t,fallback:s,label:n,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(is,{fallback:s,label:n}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),e.jsx(xd,{link:a})]})})}const El={},md={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}},Wp=()=>{const t=El==null?void 0:El.VITE_LEDGE_MOTION;return t===void 0?1:Number(t)},Ct=t=>`${Math.round(t*Wp())}ms`;function Kp(t){return t.map(([s,n,a])=>{const l=md[n];return`${s} ${Ct(l.ms)} ${l.ease} ${Ct(a??l.delayMs)}`}).join(", ")}const Vp="(prefers-reduced-motion: reduce)",pd=()=>typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia(Vp):null;function Gp(t){const s=pd();return s==null||s.addEventListener("change",t),()=>s==null?void 0:s.removeEventListener("change",t)}const Xp=()=>{var t;return((t=pd())==null?void 0:t.matches)??!1};function Yp(){return!1}function fd(){return f.useSyncExternalStore(Gp,Xp,()=>!1)}const Qp=()=>({reduced:fd()||Yp(),app:!1,setReduced(){}});let Zp=Qp;function Jp(){return Zp()}function ef(t){return t==="dark"?"signal":"pebble"}function bn(t){let s=7;for(let n=0;n<t.length;n++)s=s*31+t.charCodeAt(n)>>>0;return s}function ll(t,s){return bn(`${t}:${s}`)%3+1}const Mt={blinkMs:180,gazePx:1.4,gazeYPx:.3,askDelayMs:180,transitionMs:500,hopMs:480,touchMs:360,idleMs:1700,askMs:850,nodMs:650},Rl=(t,s)=>s===0?1400+t%3500:3400+(t+s*997)%3300,Al=(t,s)=>s===0?800+t%1800:2400+(t+s*557)%2100,dr=new Set(["done","error","readonly"]),Tl=(t,s)=>s===0?3500+t%4e3:5500+(t+s*557)%3500,ws=t=>!document.hidden&&!t.closest("[inert]");function Wa(t,s){document.addEventListener("visibilitychange",s);const n=new MutationObserver(s);return n.observe(document.documentElement,{attributes:!0,subtree:!0,attributeFilter:["inert"]}),()=>{document.removeEventListener("visibilitychange",s),n.disconnect()}}function tf(t){f.useEffect(()=>{const s=t.current;if(!s)return;const n=()=>s.setAttribute("data-suspended",String(!ws(s)));return n(),Wa(s,n)},[t])}function dn(t,s,n){t.style.setProperty("--bot-gx",`${s}px`),t.style.setProperty("--bot-gy",`${n}px`)}function sf(t,s){const{seed:n,state:a,enabled:l,askKey:r,nodKey:o,gazeReach:i=0}=s,c=bn(n),x=l&&!dr.has(a),u=f.useRef(null),m=f.useRef(a),p=f.useRef(o),h=f.useRef(void 0);f.useEffect(()=>{const g=t.current;if(!g||!x)return;let y,k,S;const b=()=>ws(g),j=()=>{y!==void 0&&clearTimeout(y),k!==void 0&&clearTimeout(k),S!==void 0&&clearTimeout(S),y=k=S=void 0,g.removeAttribute("data-idle"),dn(g,0,0),g.removeAttribute("data-blink")},N=()=>{if(j(),!b())return;const M=Date.now();(!u.current||u.current.h!==c)&&(u.current={h:c,blinkAt:M+Rl(c,0),lookAt:M+Al(c,0),idleAt:M+Tl(c,0),blinks:0,looks:0,idles:0});const v=u.current;v.blinkAt<M&&(v.blinkAt=M+Rl(c,++v.blinks)),v.lookAt<M&&(v.lookAt=M+Al(c,++v.looks)),v.idleAt<M&&(v.idleAt=M+Tl(c,++v.idles)),y=setTimeout($,Math.min(v.blinkAt,v.lookAt,v.idleAt)-M)},$=()=>{if(y=void 0,!b()){j();return}const M=u.current,v=Date.now();if(v>=M.blinkAt&&(g.setAttribute("data-blink","true"),k!==void 0&&clearTimeout(k),k=setTimeout(()=>{k=void 0,g.removeAttribute("data-blink")},Mt.blinkMs),M.blinkAt=v+Rl(c,++M.blinks)),v>=M.lookAt){M.looks++;const A=a==="working";!g.hasAttribute("data-hover")&&!g.hasAttribute("data-transition")&&dn(g,A?M.looks%2?Mt.gazePx:-1.4:0,A?Mt.gazeYPx:0),M.lookAt=v+Al(c,M.looks)}if(v>=M.idleAt){M.idles++;const A=a;!g.hasAttribute("data-hover")&&!g.hasAttribute("data-transition")&&(A==="idle"||A==="question")&&(g.setAttribute("data-idle",A==="question"?"tilt":M.idles%4===0?"stretch":"look"),S=setTimeout(()=>{S=void 0,g.removeAttribute("data-idle")},Mt.idleMs)),M.idleAt=v+Tl(c,M.idles)}y=setTimeout($,Math.min(M.blinkAt,M.lookAt,M.idleAt)-v)};N();const C=Wa(g,()=>{b()&&y===void 0?N():b()||j()});return()=>{j(),C()}},[t,x,c,a]),f.useEffect(()=>{const g=t.current,y=m.current,k=h.current,S=p.current!==o&&o!==void 0;if(p.current=o,m.current=a,h.current=r,!g)return;dn(g,0,0),g.removeAttribute("data-idle");const b=a==="approval"&&(y!=="approval"||r!==void 0&&r!==k),j=new Set,N=(z,K)=>{const L=setTimeout(()=>{j.delete(L),ws(g)?z():$()},K);return j.add(L),L},$=()=>{j.forEach(clearTimeout),j.clear(),["data-transition","data-gesture","data-touch","data-hover","data-idle"].forEach(z=>g.removeAttribute(z)),dn(g,0,0)};let C=!1,M=!1;l&&ws(g)&&(y!==a&&["working","question","idle","done","error"].includes(a)&&(g.setAttribute("data-transition",a),N(()=>g.removeAttribute("data-transition"),a==="working"?Mt.hopMs:a==="question"?650:Mt.transitionMs)),b&&!S&&N(()=>{C=!0,g.setAttribute("data-gesture","ask"),N(()=>{g.getAttribute("data-gesture")==="ask"&&g.removeAttribute("data-gesture")},Mt.askMs)},Mt.askDelayMs));const v=()=>l&&!dr.has(a)&&ws(g),A=z=>{if(!v()||z.pointerType==="touch")return;const K=g.getBoundingClientRect();if(!K.width||!K.height)return;const L=z.clientX-K.left-K.width/2,W=z.clientY-K.top-K.height/2;if(i>0&&(Math.abs(L)>K.width/2+i||Math.abs(W)>K.height/2+i)){g.hasAttribute("data-hover")&&T();return}g.setAttribute("data-hover","true"),g.removeAttribute("data-idle");const ae=U=>Math.max(-2,Math.min(2,U));dn(g,ae(L/(K.width/2+i)*2),ae(W/(K.height/2+i)*2))},T=()=>{g.removeAttribute("data-hover"),dn(g,0,0)},R=i>0?window:g,P=i>0?document.documentElement:g;let _;const D=()=>{v()&&(_!==void 0&&(clearTimeout(_),j.delete(_)),g.removeAttribute("data-touch"),g.getBoundingClientRect(),g.setAttribute("data-touch","true"),_=N(()=>g.removeAttribute("data-touch"),Mt.touchMs))};R.addEventListener("pointermove",A),P.addEventListener("pointerleave",T),g.addEventListener("click",D);const E=Wa(g,()=>{ws(g)||(M=!0,$())});return()=>{$(),E(),R.removeEventListener("pointermove",A),P.removeEventListener("pointerleave",T),g.removeEventListener("click",D);const z=["data-paused","data-frozen","data-reduced","data-readonly"].some(K=>g.getAttribute(K)==="true");!C&&b&&!S&&g.getAttribute("data-state")===a&&l&&!M&&ws(g)&&!z&&(h.current=k)}},[t,a,l,r,o,c,i])}function nf(t,s,n,a,l){const r=f.useRef(s);f.useEffect(()=>{const o=t.current,i=r.current!==s;if(r.current=s,!o||!i||s===void 0||!n||!ws(o)||dr.has(a))return;o.setAttribute("data-gesture","nod");const c=setTimeout(()=>{o.getAttribute("data-gesture")==="nod"&&o.removeAttribute("data-gesture")},Mt.nodMs),x=()=>{clearTimeout(c),o.getAttribute("data-gesture")==="nod"&&o.removeAttribute("data-gesture")},u=Wa(o,()=>{ws(o)||x()});return()=>{u(),x()}},[t,s,n,a,l])}const af={claude:"Claude Code",codex:"Codex",cursor:"Cursor Agent",omp:"omp"},lf={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"}},rf="0 0 96 96",hd={claude:"10 18 76 64",codex:"5 7 87 82",cursor:"11 8 74 82",omp:"10 18 76 68"},of=Object.fromEntries(Object.entries(hd).map(([t,s])=>[t,Number(s.split(" ")[2])])),cf={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"},df={claude:"translate(0 -8)",codex:void 0,cursor:"translate(31.5 58) skewY(27) scale(.86) translate(-48.5 -49)",omp:"translate(0 -12)"},uf=240;function rl({tool:t,state:s,pose:n,size:a,shownSize:l,theme:r,seed:o,readOnly:i=!1,frozen:c=!1,paused:x=!1,reducedMotion:u,askKey:m,nodKey:p,className:h}){var K;const g=f.useRef(null),y=`bot-shell-${f.useId().replace(/[^A-Za-z0-9_-]/g,"")}`,k=Jp(),b=fd()||(u??k.reduced),j=a<=20,N=lf[s],$=!i&&s!=="done"&&s!=="readonly",C=qr(),M=bn(o),v=s==="working"&&!b&&!i&&!c&&!x,A=l??a,R=Math.min(7,Math.max(2,A*.12))/A*(j?of[t]:96),P=3600+M%9*100,_=!j&&A>20,D=!b&&!i&&s!=="readonly"&&!c&&!x;tf(g),sf(g,{seed:o,state:s,askKey:m,nodKey:p,enabled:D&&_,gazeReach:uf}),nf(g,p,D&&_,s,m);const E={"--bot-size":`${a}px`,"--bot-eye":`var(--bot-eye-${N.eye})`,"--bot-tilt":`${((K=N.tilt)==null?void 0:K[n-1])??0}deg`,"--bot-lift":`${N.lift??0}px`,"--bot-breath":Ct(4800+M%17*100),"--bot-phase":`-${Ct(M%43*100)}`,"--bot-hop":`${R.toFixed(2)}px`,"--bot-hop-cycle":Ct(P),"--bot-ease":md.grow.ease,"--bot-material-ms":Ct(240),"--bot-eye-ms":Ct(260),"--bot-pose-ms":Ct(300),"--bot-gaze-ms":Ct(450),"--bot-blink-ms":Ct(Mt.blinkMs),"--bot-ask-ms":Ct(Mt.askMs),"--bot-nod-ms":Ct(Mt.nodMs),"--bot-question-ms":Ct(650),"--bot-arrival-ms":Ct(Mt.transitionMs),"--bot-entry-hop-ms":Ct(Mt.hopMs),"--bot-touch-ms":Ct(Mt.touchMs),"--bot-idle-ms":Ct(Mt.idleMs)},z=`${af[t]} · ${C.botLabel[s]}${i&&s!=="readonly"?` · ${C.botReadOnly}`:""}${c?` · ${C.botNotLive}`:""}`;return e.jsxs("svg",{ref:g,className:h?`bot ${h}`:"bot",role:"img","aria-label":z,width:a,height:a,viewBox:j?hd[t]:rf,"data-tool":t,"data-state":s,"data-eyes":N.eyes,"data-pose":n,"data-material":ef(r),"data-simplified":String(j),"data-detailed":String(_),"data-readonly":String(i||s==="readonly"),"data-halo":String($),"data-frozen":String(c),"data-paused":String(x),"data-reduced":String(b),"data-hop":String(v),style:E,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:y,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:cf[t],fill:`url(#${y})`}),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:df[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})]}),_&&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 xf={blink:180,curious:900,hello:1100,boop:700,happy:900,look:1800,stretch:1600,tap:1150,pulse:1400,nod:700,yawn:1700,sleep:3200},_l=(t,s)=>Math.max(-s,Math.min(s,t)),Jo="M25 60V41C25 28 35 23 48 23C61 23 71 28 71 41V60Z";function Zr({size:t,theme:s,paused:n=!1,frozen:a=!1,reducedMotion:l=!1,dnd:r=!1,pointer:o=null,center:i,gestureKey:c,gestureKind:x="hello",boopKey:u}){const m=qr(),p=`resident-${f.useId().replace(/[^A-Za-z0-9_-]/g,"")}`,[h,g]=f.useState(null),[y,k]=f.useState(!1),S=f.useRef(void 0),b=n||l||r||a,j=!b&&!!o&&!!i&&Math.hypot(o.x-i.x,o.y-i.y)<140,N=j?_l((o.x-i.x)/140*5,4):0,$=j?_l((o.y-i.y)/140*3,2):0,C=j?_l((o.x-i.x)/140*7,5):0,M=T=>{b||document.hidden||(clearTimeout(S.current),g(null),g(T),S.current=setTimeout(()=>g(null),xf[T]))};f.useEffect(()=>()=>clearTimeout(S.current),[]),f.useEffect(()=>{c&&M(x)},[c]),f.useEffect(()=>{u&&M("boop")},[u]);const v=f.useRef(!1);f.useEffect(()=>{j&&!v.current&&!y&&M("curious"),v.current=j},[j]),f.useEffect(()=>{if(b){g(null),clearTimeout(S.current);return}let T,R=0;const P=()=>{!document.hidden&&!y&&(R++,M(R%17===0?"sleep":R%13===0?"yawn":R%11===0?"tap":R%7===0?"stretch":R%5===0?"look":"blink")),T=setTimeout(P,4300+R%3*900)};T=setTimeout(P,3200);const _=()=>{document.hidden&&(g(null),clearTimeout(S.current))};return document.addEventListener("visibilitychange",_),()=>{clearTimeout(T),document.removeEventListener("visibilitychange",_)}},[b,y]);const A={"--resident-gx":N?`${N.toFixed(2)}px`:"0px","--resident-gy":$?`${$.toFixed(2)}px`:"0px","--resident-tilt":C?`${C.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":s,"data-large":String(t>24),"data-near":String(j),"data-dnd":String(r),"data-frozen":String(a),"data-quiet":String(b),"data-gesture":h??void 0,style:A,onMouseEnter:()=>{k(!0),M("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:Jo,fill:`url(#${p}-shell)`}),t>24&&e.jsx("path",{d:Jo,fill:`url(#${p}-sheen)`}),e.jsx("g",{className:"resident-gaze",children:e.jsxs("g",{className:"resident-blink",children:[e.jsxs("g",{className:"resident-eyes",children:[e.jsx("rect",{x:"37",y:"35",width:"6",height:"12",rx:"3"}),e.jsx("rect",{x:"53",y:"35",width:"6",height:"12",rx:"3"}),t>24&&e.jsxs("g",{className:"resident-glint",children:[e.jsx("circle",{cx:"38.8",cy:"37.8",r:"1.5"}),e.jsx("circle",{cx:"54.8",cy:"37.8",r:"1.5"})]})]}),e.jsx("path",{className:"resident-smile",d:"M36 43q4-7 8 0m8 0q4-7 8 0"}),e.jsx("path",{className:"resident-sleep",d:"M36 42q4 4 8 0m8 0q4 4 8 0"})]})})]})}),e.jsx("rect",{className:"resident-wall",x:"9",y:"59",width:"78",height:"20",rx:"6"}),e.jsx("rect",{className:"resident-slab",x:"6",y:"55",width:"84",height:"7",rx:"3.5"}),e.jsx("path",{className:"resident-rim",d:"M12 56.4H84"}),e.jsx("rect",{className:"resident-shell resident-grip",x:"26",y:"50",width:"12",height:"9",rx:"4.5",fill:`url(#${p}-shell)`}),e.jsx("rect",{className:"resident-shell resident-hand",x:"58",y:"50",width:"12",height:"9",rx:"4.5",fill:`url(#${p}-shell)`}),e.jsx("title",{children:a?m.residentOffline:m.residentName})]})}const mf={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"};function ol({tool:t,seed:s,state:n,large:a=!1,frozen:l=!1}){const r=mf[n],o=nn();return e.jsx("span",{className:"inline-flex flex-none","aria-hidden":"true",children:e.jsx(rl,{tool:t,seed:s,state:r,pose:ll(s,r),size:a?68:34,theme:o,frozen:l})})}function bs(t){return e.jsx(Zr,{...t,theme:nn()})}const pf={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 Xe({title:t,tone:s="plain",children:n,role:a}){return e.jsxs("div",{role:a,className:`rounded-control border p-3.5 text-small leading-[1.65] ${pf[s]}`,children:[e.jsx("strong",{className:"mb-[5px] block text-body",children:t}),n]})}var Jr=rm();const eo="(min-width: 768px) and (min-height: 501px)",ff=`${eo} and (orientation: landscape)`,ei=t=>typeof globalThis.matchMedia=="function"?globalThis.matchMedia(t):null;function gd(t){return f.useSyncExternalStore(s=>{var a;const n=ei(t);return(a=n==null?void 0:n.addEventListener)==null||a.call(n,"change",s),()=>{var l;return(l=n==null?void 0:n.removeEventListener)==null?void 0:l.call(n,"change",s)}},()=>{var s;return((s=ei(t))==null?void 0:s.matches)??!1},()=>!1)}function It(){return gd(eo)}function il(){return gd(ff)}const bd=f.createContext(void 0),jd=()=>f.useContext(bd);function ss({list:t,detail:s,tab:n,fold:a=!1}){const[l,r]=f.useState(null);return e.jsxs("div",{className:"split","data-split":n,"data-fold":a?"":void 0,children:[e.jsx("div",{ref:r,className:"split-banner"}),e.jsxs(bd.Provider,{value:l,children:[e.jsx("section",{className:"split-list",children:t}),e.jsx("section",{className:"split-detail",children:s})]})]})}function Il({title:t,body:s}){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:s})]})})}const hf=["atoi","sessions","prs","rigs","chat"];function to(t){switch(t.name){case"atoi":case"request":case"ask":return"atoi";case"sessions":case"routines":case"thread":case"terminal":case"launch":return"sessions";case"prs":case"rigs":case"chat":return t.name;case"rig":case"kernel":case"max":return"rigs";case"pr":return"prs";case"atelier":return"atelier";case"connection":return null}}const yd=t=>({name:t}),gf=t=>to(t)===t.name&&!(t.name==="atelier"&&t.sessionId),Nd=new Map;function bf(t){const s=to(t);s&&s!=="atelier"&&Nd.set(s,ne(t))}const so=t=>Nd.get(t)??ne(yd(t));function jf(t,s=[],n=[]){const a=t.filter(o=>o.filter==="permission").length+n.filter(o=>o.routine.kind==="failed").length,l=t.filter(o=>o.filter!=="permission").length+s.filter(o=>o.kind!=="update").length+n.filter(o=>o.routine.kind==="approve").length,r=a||l;return r?{text:r>99?"99+":String(r),tone:a?"red":"amber"}:null}function yf(t,s,n){return t?"online":n==="pc_offline"||n==="relay_unreachable"?"offline":s?"reconnecting":"loading"}const vd=f.createContext({pc:null,look:"online",reach:"pc_online",since:"",retry:()=>{}}),Ll=vd.Provider,Ut=()=>f.useContext(vd),Ht=t=>{const s=t??d.host.unknown;return s.length>14?`${s.slice(0,13)}…`:s};function kd({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 cl(){const{pc:t,look:s}=Ut(),n=Ht(t),a=s==="offline";return e.jsxs("a",{href:ne({name:"connection",section:"link"}),"data-host":s,"aria-label":d.host.label(t??d.host.unknown,s),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:[s==="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 ${s==="online"?"bg-ok":a?"bg-attention":"bg-muted"}`}),a?d.host.offline(n):n]})}function Nf({title:t}={}){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(kd,{}),d.brand]}),e.jsx(cl,{}),e.jsx("span",{className:"flex-1"}),e.jsx("a",{href:ne({name:"connection"}),"aria-label":d.nav.settings,title:d.nav.settings,className:"grid size-11 flex-none place-items-center rounded-lg text-muted active:bg-raised",children:e.jsx(q,{name:"gear"})})]})}function wd({badge:t,className:s}){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]"} ${s}`,children:t.text}):null}const ur={atoi:"inbox",sessions:"sessions",prs:"pr",rigs:"rigs",chat:"ledge",atelier:"atelier"};function Sd(t){return(s,n)=>a=>{if(!n||t.name==="connection")return;a.preventDefault();const l=document.querySelector("[data-tab-scroll]");l&&l.scrollTop>0?l.scrollTo({top:0,behavior:"smooth"}):gf(t)||tn(yd(s))}}function vf({route:t,active:s,badges:n}){const a=Sd(t);return e.jsx("nav",{"aria-label":d.nav.label,className:"tabbar bleed grid flex-none grid-cols-5 border-t border-line bg-sidebar",children:hf.map(l=>e.jsxs("a",{href:so(l),onClick:a(l,s===l),"aria-current":s===l?"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(q,{name:ur[l]})}),d.nav[l],e.jsx(wd,{badge:n[l]??null,className:"top-[3px] left-1/2 ml-[7px]"})]},l))})}function kf({route:t,active:s,badges:n,atelier:a,ledge:l}){const r=Sd(t),o=i=>e.jsxs("a",{href:so(i),onClick:r(i,s===i),"aria-current":s===i?"page":void 0,className:"rb",children:[e.jsx(q,{name:ur[i]}),d.nav[i],e.jsx(wd,{badge:n[i]??null,className:"top-[3px] right-[7px]"})]},i);return e.jsxs("nav",{"aria-label":d.nav.label,className:"rail",children:[e.jsx("span",{className:"mb-2",children:e.jsx(kd,{size:30})}),["atoi","sessions","prs","rigs"].map(o),a&&o("atelier"),e.jsx("span",{className:"flex-1"}),e.jsxs("button",{type:"button","aria-pressed":l.open,onClick:l.onToggle,className:"rb",children:[e.jsx(q,{name:ur.chat}),d.nav.chat]}),e.jsx("span",{"aria-hidden":"true",className:"my-1.5 h-px w-[34px] bg-line"}),e.jsxs("a",{href:ne({name:"connection"}),"aria-current":s==="settings"?"page":void 0,className:"rb",children:[e.jsx(q,{name:"gear"}),d.nav.settings]})]})}function js({body:t,across:s=!1}={}){const{pc:n,look:a,reach:l,since:r,retry:o}=Ut(),[i,c]=Cn(),x=jd();if(a!=="offline")return null;const u=l==="relay_unreachable",m=u?d.compare.relayTitle:d.offline.title(n),p=u?d.compare.relayBody:r?(t??d.offline.body)(r):d.offline.bodyUnknown,h=y=>e.jsxs("button",{type:"button",disabled:i,onClick:()=>{c(!0),o()},className:Fe({size:"sm",className:y}),children:[e.jsx(q,{name:"refresh",className:"size-4"}),d.offline.retry]}),g=e.jsx(q,{name:u?"cloud":"wifioff",className:"mt-px size-4 flex-none text-attention"});return x!==void 0?!s||!x?null:Jr.createPortal(e.jsxs("section",{role:"status","data-strip":u?"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:[g,e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("b",{className:"font-semibold",children:m})," · ",e.jsx("span",{className:"text-muted",children:p})]}),h("flex-none")]}),x):e.jsxs("section",{role:"status","data-strip":u?"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:[g,e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[e.jsx("b",{className:"font-semibold",children:m}),e.jsx("span",{className:"text-muted",children:p}),h("self-start")]})]})}function wf(){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 Rs({title:t,subtitle:s,wideSubtitle:n,actions:a,wideActions:l,children:r,bodyClassName:o="flex flex-col gap-3",offlineBody:i,heading:c=!0,offlinePill:x=!0}){const u=It(),{pc:m,look:p,since:h}=Ut(),g=p==="loading",y=g?d.link.connecting(Ht(m)):p==="offline"?h?d.link.lastKnownAt(h):d.inbox.lastKnown:n;return e.jsxs(e.Fragment,{children:[u&&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}),y&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:y}),!g&&(x||p!=="offline")&&e.jsx(cl,{}),l&&e.jsx("span",{className:"ml-auto flex flex-none items-center gap-2",children:l})]}),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(js,{body:i,across:!0}),!u&&c&&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}),(g||s)&&e.jsx("span",{className:"min-w-0 truncate text-[12.5px] text-muted",children:g?d.link.connecting(Ht(m)):s}),a&&e.jsx("span",{className:"ml-auto flex flex-none items-center gap-2 self-center",children:a})]}),g?e.jsx(wf,{}):e.jsx("div",{className:`flex-none ${o}`,children:r})]})]})}function Fs(){const[t,s]=f.useState(!1);return f.useEffect(()=>{let n=!0;return zm().then(a=>{n&&s(a)}),()=>{n=!1}},[]),t}function _t(){const t=globalThis.navigator;return t?/iPhone|iPad/.test(t.userAgent)||/Macintosh/.test(t.userAgent)&&t.maxTouchPoints>1:!1}const As=d.confirm,Ol=t=>Pe({variant:t,block:!0});function ti({store:t,item:s,enabled:n,reason:a,onConfirm:l,onDeny:r,denyLabel:o}){const[i,c]=f.useState(null),[x,u]=f.useState(null),[m,p]=f.useState(!1),[h,g]=f.useState(a!==void 0),[y,k]=f.useState(0),S=f.useRef(!0),b=f.useRef(n);b.current=n;const j=f.useRef(null);f.useEffect(()=>(S.current=!0,()=>{S.current=!1}),[]),f.useEffect(()=>{var _;if(h||!n)return;const A=(_=t.getState().sessions.get(s.sessionId))==null?void 0:_.pending;if(!(A!=null&&A.key))return;let T=!0,R;c(null);const P={key:A.key,kind:A.kind,text:A.text};return t.prepareConfirm({purpose:"decide",id:s.sessionId,expect:P}).then(D=>{T&&(j.current=P,c(D),R=setTimeout(()=>{T&&(c(null),u("expired"))},D.expiresInMs))},()=>{T&&u("prepareFailed")}),()=>{T=!1,clearTimeout(R)}},[t,s.sessionId,s.key,n,h,y]);const N=h&&a?a==="assertion_expired"?"expired":"failed":x,$=()=>{u(null),g(!1),k(A=>A+1)},C=async()=>{var R,P;if(!n||m||!i)return;if(!i.credentialId){c(null),u("failed");return}p(!0),u(null);const A=await sa({challenge:i.challenge,rpId:i.rpId,credentialId:i.credentialId}).catch(()=>"failed");if(!S.current)return;p(!1);const T=j.current;if(!T||!b.current||((P=(R=t.getState().sessions.get(s.sessionId))==null?void 0:R.pending)==null?void 0:P.key)!==T.key){c(null),u("changed");return}if(A==="cancelled"){u("cancelled");return}if(A==="failed"){u("failed");return}c(null),l(A,T)===null&&u("failed")},M=N==="expired"||N==="failed"||N==="prepareFailed"||N==="changed",v=m?As.asking:i?_t()?As.goApple:As.go:As.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:As.heading}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:As.note}),N&&e.jsx(Xe,{title:N==="changed"?d.decide.changed:As[N],tone:"warning",role:"alert"}),M?e.jsx("button",{type:"button",disabled:!n,onClick:$,className:Ol("primary"),children:As.retry}):e.jsx("button",{type:"button",disabled:!n||m||!i,onClick:()=>{C()},className:Ol("primary"),children:v}),e.jsx("button",{type:"button",disabled:!n,onClick:r,className:Ol(),children:o??d.decide.deny})]})}function xr(){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(q,{name:"monitor",className:"size-4"}),d.decide.onPc]})}function Sf(t){return t instanceof HTMLElement?t.isContentEditable||t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT":!1}function $d(){return document.querySelector('[role="dialog"][aria-modal="true"]')!==null}function no(t,s){const n=f.useRef(s);n.current=s,f.useEffect(()=>{if(!t)return;const a=l=>{l.defaultPrevented||l.repeat||l.altKey||l.ctrlKey||l.metaKey||l.isComposing||Sf(l.target)||$d()||n.current(l.key)&&l.preventDefault()};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[t])}const si=t=>Pe({variant:t,className:"flex-1"}),Hs=t=>Pe({variant:t,block:!0});function $f(t,s){const n=d.decide;switch(s){case"invalid":return t.kind==="question"?n.otherInvalid:n.failed;case"free_text":return n.otherUnsupported;case"untypable":return t.kind==="question"?d.question.untypable:n.failed;case"busy":return n.busy;case"not_taken":return n.notTaken;case"read_only":return n.readOnly;default:return n.failed}}function Cf(t){const{item:s,outcome:n,fresh:a,changed:l,stillPending:r,onReread:o,onDecide:i,answerable:c=!1,choice:x=null,onAnswer:u,answerBlocked:m=!1,onCheck:p,refused:h=!1,store:g,deviceConfirm:y=!1,optionReply:k,multi:S,keys:b=!1,withThread:j=!0}=t,N=d.decide,[$,C]=Cn(),M=Fs(),v=s.risk==="high"||n.kind==="rejected"&&n.reason==="confirm_required",A=a&&!l&&r,T=s.kind!=="question"&&!k&&!S&&!c&&!v,R=T&&_c(s.tool,s.kind,"always"),P=cr(s),_=R&&e.jsx("p",{className:"text-small text-muted phone-side:text-[12px] phone-side:leading-4",children:d.atoi.scope[P]}),D=n.kind!=="sending"&&n.kind!=="uncertain"&&!((n.kind==="rejected"||n.kind==="failed")&&(n.reason==="no_prompt"||n.reason==="nothing_to_decide"||n.reason==="stale"));no(b&&T&&A&&D,B=>{const Z=B.toLowerCase();return Z==="y"?(i("accept"),!0):Z==="n"?(i("deny"),!0):!1});const E=e.jsx("a",{href:t.threadHref??ne({name:"thread",sessionId:s.sessionId}),className:Hs("ghost"),children:d.result.thread(s.botName)}),z=(B,Z,H=!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:[B,H&&j&&e.jsx("div",{className:"phone-side:hidden",children:E}),Z&&e.jsx("p",{className:"text-center text-meta text-muted phone-side:hidden",children:Z})]});if(s.kind==="question"&&!c&&!k&&!S)return z(null,N.answerOnPc);const K=y&&M?g:void 0,L=k?k.canConfirm&&K!==void 0:v&&!c&&K!==void 0,W=n.kind==="rejected"&&(n.reason==="assertion_expired"||n.reason==="assertion_invalid"||n.reason==="confirm_required")?n.reason:void 0,ae=B=>k?L?k.picked!==null&&K?e.jsx(ti,{store:K,item:s,enabled:B,reason:W,onConfirm:k.onReply,onDeny:k.onBack,denyLabel:d.answers.change}):null:e.jsx(xr,{}):S?e.jsxs("div",{className:"flex flex-col gap-2.5",children:[S.missing>0&&e.jsx("p",{className:"text-center text-small text-muted",children:d.answers.missing(S.missing)}),e.jsx("button",{type:"button",disabled:!B||S.missing>0,onClick:S.onSend,className:Hs("primary"),children:d.answers.send}),e.jsx("button",{type:"button",disabled:!B,onClick:S.onCancel,className:Hs(),children:d.answers.cancel})]}):L&&K?e.jsx(ti,{store:K,item:s,enabled:B,reason:W,onConfirm:(Z,H)=>K.decide(s.sessionId,"accept",{assertion:Z,expect:H}),onDeny:()=>i("deny")}):c?e.jsx("button",{type:"button",disabled:!B||x===null||m,onClick:()=>u==null?void 0:u(),className:Hs("primary"),children:N.send}):b&&T?e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsx("button",{type:"button",disabled:!B,onClick:()=>i("accept"),className:Pe({variant:"primary",className:"min-w-[150px]"}),children:N.allow}),e.jsx("button",{type:"button",disabled:!B,onClick:()=>i("deny"),className:Pe({className:"min-w-[120px]"}),children:N.deny}),R&&e.jsx("button",{type:"button",disabled:!B,onClick:()=>i("always"),className:Pe({variant:"ghost"}),children:Ua(P)}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono text-small text-muted",children:d.atoi.keys}),_&&e.jsx("div",{className:"basis-full",children:_})]}):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:!B,onClick:()=>i("deny"),className:si(),children:N.deny}),v?e.jsx(xr,{}):e.jsx("button",{type:"button",disabled:!B,onClick:()=>i("accept"),className:si("primary"),children:N.allow})]}),R&&e.jsx("button",{type:"button",disabled:!B,onClick:()=>i("always"),className:Pe({variant:"ghost",block:!0,className:"phone-side:w-auto phone-side:flex-1"}),children:Ua(P)})]}),_]}),U=a?k?L?N.answerHint:N.onPcHint:S?N.answerHint:v&&!c&&!L?N.onPcHint:c?N.answerHint:N.hint:N.offlineHint,O=B=>z(e.jsxs(e.Fragment,{children:[B,ae(A)]}),U);if(l&&n.kind!=="sending"&&n.kind!=="uncertain")return z(e.jsxs(e.Fragment,{children:[e.jsx(Xe,{title:N.changed,tone:"warning",role:"status"}),ae(!1),e.jsx("button",{type:"button",onClick:o,className:Hs(),children:N.reread})]}));switch(n.kind){case"sending":return z(e.jsx(Xe,{title:N.sending,role:"status",children:e.jsx("p",{children:N.sendingBody})}));case"uncertain":return z(e.jsxs(e.Fragment,{children:[e.jsx(Xe,{title:N.uncertain,tone:"warning",role:"alert",children:e.jsx("p",{children:N.uncertainBody})}),p&&e.jsx("button",{type:"button",disabled:$,onClick:()=>{C(!0),p()},className:Hs("primary"),children:$?N.checking:N.check})]}));case"rejected":case"failed":{const B=n.reason;if(L&&W||B==="confirm_required")return O();if(B==="no_prompt"||B==="nothing_to_decide")return z(e.jsx(Xe,{title:N.noPrompt,tone:"warning",role:"alert"}));if(B==="stale")return z(e.jsxs(e.Fragment,{children:[e.jsx(Xe,{title:N.changed,tone:"warning",role:"alert"}),e.jsx("a",{href:ne({name:"atoi"}),className:Hs(),children:d.result.back})]}),void 0,!1);const Z=e.jsx(Xe,{title:$f(s,B),tone:"warning",role:"alert"});return r?O(Z):z(Z)}default:return O(h?e.jsx(Xe,{title:N.failed,tone:"warning",role:"alert"}):void 0)}}const un=(t,s)=>{var n,a;return(a=(n=t.match(new RegExp(`<${s}>([\\s\\S]*?)</${s}>`)))==null?void 0:n[1])==null?void 0:a.trim()};function Mf(t){const s=t.trim();if(!s.startsWith("<task-notification>"))return null;const n=un(s,"status"),a=un(s,"summary")??"",l=a.match(/^Agent "(.+)" (?:was |has )?(?:stopped|killed|completed|finished|failed)/),r=a.match(/^Background command "(.+)" (?:completed|failed|was stopped|was killed)(?: \(exit code (\d+)\))?/);return{...un(s,"task-id")!==void 0&&{id:un(s,"task-id")},...un(s,"output-file")!==void 0&&{output:un(s,"output-file")},status:n==="killed"||n==="completed"||n==="failed"?n:"other",summary:a,about:l?{kind:"agent",name:l[1]}:r?{kind:"command",command:r[1],...r[2]!==void 0&&{code:r[2]}}:null,raw:s}}const wt=d.thread.rig,ni=t=>t?`…${t.slice(-4)}`:"…";function Ef(t){const s=t.indexOf("@");return s>0?{seat:t.slice(0,s),rig:t.slice(s+1)}:{seat:t}}function _a(t,s,n){const a=s?n.get(s):void 0,{seat:l,rig:r}=Ef(t??"");return a?{name:a.name,...l?{seat:l}:{},session:{id:a.id,tool:a.tool,state:a.state}}:{name:l||(t??""),...r?{seat:r}:{}}}function Rf(t){const s=t.split(`
4
4
  `).map(n=>n.trim()).find(n=>n!=="")??"";return`${wt.about(Cd(s))} `}const Cd=t=>t.length>80?`${t.slice(0,79).trimEnd()}…`:t;function Af(t,s){const n=t.split(`
5
5
  `).slice(1).map(a=>a.trim()).find(a=>a!=="");return n?wt.refusedSaid(Gs(s),Cd(n)):wt.refusedSilent(Gs(s))}const Gs=t=>new Date(t).toLocaleTimeString(lt,{hour:"2-digit",minute:"2-digit"});function Tf(t,s,n){if(t.kind!=="received"&&t.kind!=="sent"&&t.kind!=="notice"||!t.rig)return;const a=t.rig,l=a.sentAt??t.at,r=n?{cut:!0}:{},o=(c=wt.raw)=>({label:c,text:a.raw});if(a.kind==="unreadable")return{key:t.id,kind:"rig-unreadable",at:l,text:a.raw||("text"in t?t.text:""),...r};if(t.kind==="received"){const c=_a(a.from??t.from,t.peer,s);return{key:t.id,kind:"rig-message",at:l,dir:"in",who:c,text:t.text,...a.count?{count:a.count}:{},...c.session?{reply:{sessionId:c.session.id,draft:Rf(t.text)}}:{},raw:o(),...r}}if(t.kind==="sent")return{key:t.id,kind:"rig-message",at:l,dir:"out",who:_a(a.to??t.to,t.peer,s),text:t.text,delivery:t.status,raw:o(wt.command),...r};if(a.kind==="handoff"){const c=!!t.outgoing,x=_a(c?a.to:a.from??t.name,t.peer,s),u=c&&t.status==="refused"?{refused:{log:Af(a.raw,t.at)}}:{},m=!("refused"in u)&&a.qitem?{qitem:a.qitem}:{};return{key:t.id,kind:"rig-task",at:l,outgoing:c,who:x,title:a.summary??t.summary??t.text,raw:o(c?wt.command:wt.raw),...u,...m,...r}}if(a.kind==="unblocked")return{key:t.id,kind:"rig-notice",at:l,tone:"task",title:wt.unblocked(ni(a.qitem)),raw:o(),...r};if(a.kind==="openrig"&&a.alert==="stalled")return{key:t.id,kind:"rig-notice",at:l,tone:"warn",title:wt.stalled(ni(a.qitem),a.minutes??0),raw:o(),...r};const i=t.text.split(`
@@ -16,7 +16,7 @@ var sm=Object.defineProperty;var nm=(t,s,n)=>s in t?sm(t,s,{enumerable:!0,config
16
16
  `).replace(/\s+$/,"")});continue}const u=s[i+1];if(kr.test(c)&&u!==void 0&&Gg.test(u)){const g=ja(c);if(ja(u).length===g.length){r(),o();const y=[];for(i+=2;i<s.length&&s[i].trim()!==""&&kr.test(s[i]);i++)y.push(Array.from({length:g.length},(k,S)=>ja(s[i])[S]??""));i--,n.push({type:"table",header:g,rows:y,align:ja(u).map(Xg)});continue}}const m=c.match(Bl);if(m){r(),o();const g=[m[1]];for(;i+1<s.length&&Bl.test(s[i+1]);i++)g.push(s[i+1].match(Bl)[1]);n.push({type:"quote",blocks:ju(g.join(`
17
17
  `)).map(y=>y.type==="h"?{type:"p",text:y.text}:y)});continue}if(c.trim()===""){r();continue}if(Kg.test(c)){r(),o();continue}const p=c.match(Bg)??c.match(qg);if(p){r(),o(),n.push({type:"h",text:p[1].trim().replace(/\s*:\s*$/,"")});continue}const h=c.match(Hg);if(h){r();const g=h[1].length,y=h[2];if(l&&g>l.indent&&l.items.length){l.items[l.items.length-1].sub.push(y.trim());continue}const k=Ug.test(c);(!l||g<l.indent||l.ordered!==k)&&(o(),l={ordered:k,items:[],indent:g});const S=y.match(Wg);l.items.push({text:(S?y.slice(S[0].length):y).trim(),sub:[],...S?{checked:S[1]!==" "}:{}});continue}if(l&&/^\s+\S/.test(c)&&a.length===0){const g=l.items[l.items.length-1];g.text=`${g.text} ${c.trim()}`;continue}o(),a.push(c.trim())}return r(),o(),n}const Ya=t=>/[??]\s*$/.test(t);function wr(t){const s=t.replace(/\s*[??]\s*$/,"").match(/(?:^|[:;]\s*)([^:;?]*?)\s+(?:or|ou)\s+([^,:;?]{2,60})$/i);if(!s)return[];const n=[...s[1].split(/\s*,\s*/),s[2]].map(r=>r.trim()).filter(Boolean),a=r=>{var o,i,c;return(((o=r.match(/\(/g))==null?void 0:o.length)??0)===(((i=r.match(/\)/g))==null?void 0:i.length)??0)&&(((c=r.match(/`/g))==null?void 0:c.length)??0)%2===0},l=r=>r.length>=2&&r.length<=60&&r.split(/\s+/).length<=8&&!/[.!]\s/.test(r)&&a(r);return n.length>=2&&n.length<=6&&n.every(l)?n:[]}const Si=t=>t.replace(/\[([^\]]+)\]\([^)]*\)/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/(\*\*|__)(.+?)\1/g,"$2").replace(new RegExp("(?<![\\w*])\\*([^*\\n]+)\\*(?![\\w*])","g"),"$1").trim(),Fn=/\s*[★⭐]\s*/g,yu=/^(.+?)\s*\(([^()]*(?:\([^()]*\)[^()]*)*)\)\s*$/,Os=(t,s)=>{const n=Fn.test(t)||Fn.test(s);return{label:Si(t.replace(Fn," ")),detail:Si(s.replace(Fn," ")),...n?{star:n}:{}}},en=/^(\*\*|__)(\S(?:.*?\S)?)\1\s*(?:[—–:-]\s*)?(.*)$/,$i=/^(.+?)(\s+[—–-]\s+|:\s+)(.+)$/,go=(t,s=!1)=>t.every(n=>n.label.length>0&&n.label.length<=Yg&&!Ya(n.label)&&(s||!Ya(n.detail)));function Ci(t){if(t.length<2||t.length>6)return null;const s=t.map(l=>{var r;return en.test(l)?null:((r=l.match($i))==null?void 0:r[2].trim()[0])??null}),n=s.every(l=>l!==null&&l===s[0]),a=t.map(l=>{const r=l.match(en);if(r)return Os(r[2],r[3]);const o=n?l.match($i):null;return o?Os(o[1],o[3]):Os(l,"")});return go(a)?a:null}const eb=/(^|[\s(:,;])([a-h])\)\s+/g;function Mi(t){const s=[];for(const r of t.matchAll(eb))r[2].charCodeAt(0)-97===s.length&&s.push({at:r.index+r[1].length,end:r.index+r[0].length});if(s.length<2||s.length>8)return null;const n=t.slice(0,s[0].at).trim().replace(/\s*[:—–-]\s*$/,"").trim();if(!n)return null;const a=s.map((r,o)=>{var i;return t.slice(r.end,(i=s[o+1])==null?void 0:i.at)});a[a.length-1]=a[a.length-1].split(new RegExp("(?<=[.!??])\\s+(?=\\p{Lu})","u"))[0];const l=a.map(r=>{const o=r.trim().replace(/[\s,;.??]+$/,""),i=/[★⭐]/.test(o),c=o.replace(Fn," ").trim().match(yu),x=c?Os(c[1],c[2]):Os(o,"");return i?{...x,star:i}:x});return go(l,!0)?{stem:n,options:l}:null}const tb=/^(\*\*|__)(.+?[??])\s*\1/,Ei=t=>{var s;return Ya(t)?t:((s=t.match(tb))==null?void 0:s[2])??null},Ri=/(^|[^\p{L}])(laquelle|lequel|lesquel|quelle (option|approche|solution)|quel choix|which|pr[ée]f[ée]r|prefer|choisi|choos|pick|reten|retien)/iu,sb=/^(\d+)[.)]\s+(.+)$/,nb=/^(\*\*|__)(\d+)[.)]\s+(.+?)\1\s*(.*)$/,ab=t=>t.length>160?t.split(new RegExp("(?<=[.!])\\s+(?=\\p{Lu}|\\()","u"))[0]:t;function ql(t,s,n){var r;t=t.trim().replace(/\.$/,"");const a=t.match(yu);let l=ab(s.trim()).replace(/^\((.*)\)\.?$/,"$1").replace(/^[—–:-]\s*/,"")||(a?a[2]:"");return!l&&n&&(l=n.type==="p"?n.text:n.type==="list"?((r=n.items[0])==null?void 0:r.text)??"":""),Os(a?a[1]:t,l)}const lb=/recommand|recommend/i;function Nu(t,s,n=[]){const a=t.toLowerCase(),l=u=>{const m=Math.min(...u);return m<1/0?u.indexOf(m):-1},r=u=>{const m=u.length>=2?a.search(new RegExp(`(^|[^\\p{L}])${u.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}($|[^\\p{L}])`,"u")):-1;return m<0?1/0:m},o=s.map(u=>u.label.toLowerCase().split(/\s+/)[0]),i=l(s.map((u,m)=>Math.min(r(u.label.toLowerCase()),o[m].length>=4&&o.filter(p=>p===o[m]).length===1?r(o[m]):1/0)));if(i>=0)return i;const c=a.match(/\boption\s+(\d+)/);return c&&Number(c[1])>=1&&Number(c[1])<=s.length?Number(c[1])-1:n.findIndex(u=>u&&new RegExp(`(^|[\\s:])${u}([.\\s,]|$)`).test(t))}const vu=(t,s)=>s<0||t.some(n=>n.star)?t:t.map((n,a)=>a===s?{...n,star:!0}:n);function rb(t){if(!/^(\*\*|__)[^*_]+\1:?$/.test(t.text.trim()))return null;const s=t.sub.find(i=>lb.test(i.slice(0,40)));if(!s)return null;const n=t.sub.filter(i=>i!==s),a=n.filter(i=>en.test(i)),l=a.length>=2?a:n;if(l.length<2||l.length>6)return null;const r=l.map(i=>{var c;return((c=i.replace(/^(\*\*|__)/,"").match(/^([A-Z])\.\s/))==null?void 0:c[1])??""}),o=l.map(i=>{const c=i.match(en);return c?Os(c[2].replace(/^[A-Z]\.\s+/,"").replace(/\.$/,""),c[3].replace(/^[,;]\s*/,"")):Os(i.replace(/\.$/,""),"")});return go(o)?{options:vu(o,Nu(s,o,r)),notes:t.sub.filter(i=>!l.includes(i))}:null}const ya=(t,s,n=t,a)=>{const l=s??wr(n).map(i=>({label:i,detail:""})),r=l.map(i=>i.detail),o=l.findIndex(i=>i.star);return{text:t,options:l.map(i=>i.label),...r.some(Boolean)?{details:r}:{},...o>=0?{recommended:o}:{},...a?{ref:a}:{}}};function ku(t,s={}){var k,S;const n=ju(t);let a,l;const r=n[0];(r==null?void 0:r.type)==="h"&&(a=r.text,n.shift()),a&&((k=n[0])==null?void 0:k.type)==="p"&&!Ya(n[0].text)&&(l=n[0].text,n.shift());const o=[];let i={kind:"other",blocks:[]};const c=()=>{(i.blocks.length||i.title)&&o.push(i)};for(const b of n)if(b.type==="h"){c();const j=Jg(b.text);i={kind:s.plan&&(j==="done"||j==="verified")?"other":j,title:b.text,blocks:[]}}else i.blocks.push(b);c();const x=[];let u=null,m="";const p=(b,j)=>{b===1?u=[j]:u&&b===u.length+1&&u.push(j)},h=b=>{var j,N;return(N=(j=b.match(en))==null?void 0:j[2])==null?void 0:N.replace(/\s*:$/,"")},g=()=>{const b=u&&u.length>=2&&u.length<=8?u:null;return u=null,b?vu(b,Nu(m,b)):null};for(const b of o){const j=b.kind==="done"||b.kind==="verified",N=(S=b.title)==null?void 0:S.match(sb);N&&p(Number(N[1]),ql(N[2],"",b.blocks[0]));for(let $=0;$<b.blocks.length;$++){const C=b.blocks[$];if(C.type==="p"){const M=C.text.match(nb);if(M){p(Number(M[2]),ql(M[3],M[4],b.blocks[$+1]));continue}if(/^(\*\*|__)[^*_]*(recommand|recommend)/i.test(C.text)&&(m=C.text),j)continue;const v=Ei(C.text),A=Mi(C.text);if(!v&&!A)continue;const T=b.blocks[$+1];let R=(T==null?void 0:T.type)==="list"&&!T.ordered?Ci(T.items.map(P=>P.text)):null;R?b.blocks.splice($+1,1):A?R=A.options:!wr(v).length&&Ri.test(v)&&(R=g()),C.q=x.length,x.push(ya(C.text,R,A&&!v?A.stem:v))}else C.type==="list"&&!j&&C.items.forEach((M,v)=>{const A=en.test(M.text)?M.text.lastIndexOf("?"):-1,T=Ei(M.text)??(A>0?M.text.slice(0,A+1):null),R=Mi(M.text),P=T||R?null:rb(M);if(!T&&!R&&!P){const D=C.ordered?M.text.match(en):null;D&&p(v+1,ql(D[2],D[3],void 0));return}M.q=x.length;const _=Ci(M.sub);P?(x.push(ya(M.text,P.options,M.text,h(M.text))),M.sub=P.notes):!_&&R?x.push(ya(R.stem,R.options,R.stem,h(R.stem))):x.push(ya(M.text,_??(!wr(T).length&&Ri.test(T)?g():null),T??M.text)),_&&!P&&(M.sub=[])})}}const y=!!a&&(r==null?void 0:r.type)==="h"||x.length>0||o.some(b=>!!b.title||b.blocks.some(j=>j.type!=="p"));return{title:a,lead:l,sections:o,questions:x,structured:y}}const Hl="mt-px inline-flex size-4 flex-none items-center justify-center rounded-[4px] border";function wu({checklist:t,current:s}){var u;const[n,a]=f.useState(!1),{tasks:l,done:r,total:o}=t,i=((u=l.find(m=>m.status==="in_progress"))==null?void 0:u.text)??s??(r===o?d.checklist.allDone:d.checklist.paused),c=l.some(m=>m.status==="in_progress")||!!s,x=f.useMemo(()=>{const m=new Map;return l.map(p=>{const h=m.get(p.text)??0;return m.set(p.text,h+1),h===0?p.text:`${p.text}#${h}`})},[l]);return e.jsxs("div",{className:"sticky top-0 z-10 flex-none bg-bg",children:[e.jsxs("button",{type:"button","aria-expanded":n,onClick:()=>a(m=>!m),className:`flex min-h-11 w-full flex-col gap-1.5 border border-line bg-surface px-3 py-2.5 text-left text-[12px] leading-[18px] text-muted shadow-[0_4px_14px_rgba(0,0,0,.35)] ${n?"rounded-t-card":"rounded-card"}`,children:[e.jsxs("span",{className:"flex w-full items-center gap-2",children:[e.jsx(q,{name:"plan",className:"size-3.5",stroke:1.8}),e.jsx("strong",{className:"font-medium text-fg",children:d.checklist.title}),e.jsx("span",{className:"flex-1"}),e.jsxs("span",{className:"font-mono text-[11px] text-fg",children:[r,"/",o]}),e.jsx("span",{"aria-hidden":"true",className:"h-1 w-16 overflow-hidden rounded-[2px] bg-raised",children:e.jsx("span",{className:"block h-full bg-ok",style:{width:`${o?r/o*100:0}%`}})}),e.jsx("span",{className:n?"-rotate-90":"rotate-90",children:e.jsx(q,{name:"chevron",className:"size-[13px]",stroke:2})})]}),e.jsxs("span",{className:"block w-full truncate",children:[c&&e.jsx("span",{className:"mr-1.5 inline-block size-1.5 rounded-full bg-info align-[1px]"}),i]})]}),n&&e.jsxs("ol",{className:"max-h-[50dvh] overflow-y-auto rounded-b-card border border-t-0 border-line bg-surface px-3 pt-1.5 pb-2.5 text-small",children:[l.map((m,p)=>e.jsxs("li",{className:`flex items-start gap-2.5 py-1.5 [overflow-wrap:anywhere] ${m.status==="completed"?"text-muted line-through":m.status==="in_progress"?"font-medium text-fg":"text-fg"}`,children:[m.status==="completed"&&e.jsx("span",{role:"img","aria-label":d.checklist.box.completed,className:`${Hl} border-ok/50 font-mono text-[10px] font-semibold text-ok no-underline`,children:"✓"}),m.status==="in_progress"&&e.jsx("span",{role:"img","aria-label":d.checklist.box.in_progress,className:`${Hl} border-info`,children:e.jsx("svg",{className:"size-2.5 text-info motion-safe:animate-spin",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})})}),m.status==="pending"&&e.jsx("span",{role:"img","aria-label":d.checklist.box.pending,className:`${Hl} border-fg/25`}),m.text]},x[p])),t.cut&&e.jsx("li",{className:"py-1.5 text-meta text-muted",children:d.checklist.cut})]})]})}function Jn({name:t,legend:s,options:n,value:a,onChange:l,fit:r=!1}){return e.jsxs("fieldset",{className:`m-0 min-w-0 border-0 p-0${r?" self-start":""}`,"data-fit":r||void 0,children:[e.jsx("legend",{className:"sr-only",children:s}),e.jsx("div",{className:`${r?"inline-flex":"grid auto-cols-fr grid-flow-col"} gap-1 rounded-control bg-raised p-1`,children:n.map(o=>e.jsxs("label",{lang:o.lang,className:`flex min-h-10 cursor-pointer items-center justify-center rounded-[9px] ${r?"px-3.5":"px-2"} text-body font-medium text-muted transition-colors duration-100 has-[:checked]:bg-fg has-[:checked]:text-bg has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-info`,children:[e.jsx("input",{type:"radio",name:t,value:o.value,checked:a===o.value,onChange:()=>l(o.value),className:"sr-only"}),o.label]},o.value))})]})}const bo="model-sheet-title",ob="flex min-h-12 w-full items-center gap-3 rounded-control border border-line bg-surface px-3 py-2.5 text-left active:bg-raised aria-pressed:border-fg/40 aria-pressed:bg-raised";function Su({tool:t,models:s,error:n,current:a,pick:l,onPick:r,note:o,actions:i,defaultHint:c=d.model.defaultHint}){var g;const x=!a||a.model===null||s.some(y=>y.id===a.model),u=ri(t,s,l),m=y=>{const k=ri(t,s,{model:y});r({model:y,effort:l.effort!==null&&(k!=null&&k.includes(l.effort))?l.effort:null})},p=(y,k,S)=>e.jsxs("button",{type:"button","aria-pressed":l.model===y,onClick:()=>m(y),className:ob,children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-body font-medium",children:k}),S&&e.jsx("span",{className:"block text-meta text-muted",children:S})]}),(a==null?void 0:a.model)===y&&e.jsx("span",{className:"flex-none rounded-full bg-raised px-2 py-0.5 text-meta text-muted",children:d.model.current})]},y??""),h=u&&(l.effort??((g=s.find(y=>l.model===null?y.isDefault:y.id===l.model))==null?void 0:g.defaultEffort)??"");return e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("h2",{id:bo,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:d.model.title}),e.jsx("p",{className:"mt-1 text-meta text-muted",children:d.model.subtitle(d.tools[t]??t)})]}),n&&e.jsx("p",{role:"status",className:"text-meta text-attention",children:d.model.listError}),e.jsxs("div",{className:"flex max-h-[45vh] flex-col gap-1.5 overflow-y-auto",children:[p(null,d.model.byDefault,c),!x&&(a==null?void 0:a.model)!=null&&p(a.model,a.model,void 0),s.map(y=>p(y.id,y.label,Fd(t,y)))]}),u&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-body font-medium",children:[d.model.effortTitle," ",e.jsx("span",{className:"text-meta font-normal text-muted",children:d.model.effortHint})]}),e.jsx("div",{className:"mt-2",children:e.jsx(Jn,{name:"model-effort",legend:d.model.effortTitle,value:h??"",onChange:y=>r({model:l.model,effort:y}),options:u.map(y=>({value:y,label:ca(y)}))})})]}),o&&e.jsx("p",{className:"text-small whitespace-pre-line text-muted",children:o}),i]})}const $u={models:[]},Cu=t=>t.modelNext?{model:t.modelNext.model??null,effort:t.modelNext.effort??null}:ro(t),sn=(t,s)=>!!(t!=null&&t.models)&&s.canSwitch===!0;function ib({store:t,session:s}){const{daemon:n,models:a,fresh:l}=me(t),[r,o]=f.useState(!1),i=sn(n,s);if(f.useEffect(()=>{i&&t.requestModels(s.tool)},[i,t,s.tool]),!i)return null;const c=a[s.tool]??$u,x=s.modelNext?Cu(s):null,u=x??ro(s),m=[ah(s.tool,u.model??void 0,c.models),u.effort?ca(u.effort):null].filter(Boolean).join(" · ");return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:!l,"aria-haspopup":"dialog","aria-label":d.model.chip(x?`${m}, ${d.model.nextTurn}`:m),onClick:()=>{t.requestModels(s.tool),o(!0)},className:`${Ic()} gap-2 whitespace-nowrap`,children:[e.jsx("span",{children:m}),x&&e.jsx("span",{className:"text-meta font-normal text-attention",children:d.model.nextTurn})]}),r&&e.jsx(gl,{store:t,session:s,onClose:()=>o(!1)})]})}function cb({store:t,session:s}){const{daemon:n,modelFailures:a}=me(t),l=a[s.id];return!sn(n,s)||!l?null:e.jsx("p",{role:"status",className:"pb-2 text-meta text-attention",children:d.model.failedLine(d.model.failed[l])})}function gl({store:t,session:s,onClose:n}){const{models:a}=me(t),l=a[s.tool]??$u,r=ro(s),[o,i]=f.useState(Cu(s)),[c,x]=f.useState(!1),[u,m]=f.useState(null),p=async g=>{x(!0),m(null);const y=await t.changeModel(s.id,g.model,g.effort);if(x(!1),y.status==="applied"){n();return}if(y.status==="expired"){m(d.model.uncertain);return}const k=y.status==="rejected"?y.reason:null;m(k&&k in d.model.failed?d.model.failed[k]:d.model.notApplied)},h=rh(s);return e.jsx(dt,{labelledBy:bo,onClose:n,children:e.jsx(Su,{tool:s.tool,models:l.models,error:l.error,current:r,pick:o,onPick:i,note:h?d.model.noteWorking(s.name):d.model.noteIdle(s.name),actions:e.jsxs(e.Fragment,{children:[u&&e.jsx("p",{role:"alert",className:"text-meta text-attention",children:u}),s.modelNext&&e.jsx(Ke,{variant:"outline",disabled:c,onClick:()=>void p(r),children:d.model.cancelPending}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ke,{variant:"ghost",className:"flex-1",onClick:n,children:d.model.cancel}),e.jsx(Ke,{variant:"primary",className:"flex-[2]",disabled:c||lh(o,r),onClick:()=>void p(o),children:d.model.apply})]})]})})})}const db=1e4;function Mu(t,s){const n=d.sessions.modelOff;return sn(t,s)?null:s.state==="exited"?n.ended:t!=null&&t.models?n.outside:n.olderPc}function ub(t,s){const n=l=>{var r;return t.rig?((r=l.rig)==null?void 0:r.name)===t.rig.name:!l.rig&&l.project===t.project},a=[...s].filter(l=>n(l)&&l.state!=="exited").map(l=>l.id);return{name:t.rig?d.sessions.rigGroup(t.rig.name):t.project,ids:a}}function us({icon:t,label:s,why:n,right:a,onClick:l,danger:r=!1}){const o=!l;return e.jsxs("button",{type:"button",disabled:o,onClick:l,className:`flex min-h-12 w-full items-center gap-3 border-b border-line px-3.5 py-2 text-left text-[15px] last:border-b-0 disabled:opacity-60 ${r?"text-danger-fg":"text-fg"}`,children:[e.jsx(q,{name:t,className:`size-5 ${r?"text-danger-fg":"text-muted"}`}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{children:s}),n&&e.jsx("small",{className:"text-small text-muted",children:n})]}),a!=null&&e.jsx("span",{className:"ml-auto flex-none text-[12.5px] text-muted",children:a})]})}const zn=({children:t})=>e.jsx("div",{className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:t});function jo({store:t,session:s,closable:n,closing:a,onClose:l,onModel:r,onCloseSession:o,display:i,lead:c,who:x,order:u}){var O,B,Z;const m=me(t),p=Xt(),h=f.useId(),[g,y]=f.useState("menu"),[k,S]=f.useState(!1),b=d.sessions,j=s.name,N=m.fresh,C=[ul(s,p,1).model,s.effort?ca(s.effort):null].filter(Boolean).join(" · "),M=Mu(m.daemon,s),v=(O=m.daemon)!=null&&O.checklist?m.checklists.get(s.id):void 0,A=!!s.pending||s.state==="waiting_permission"||s.state==="waiting_input",T=s.state==="working",R=Object.values(m.ops).filter(H=>H.message.type==="session.interrupt"&&H.message.id===s.id).sort((H,X)=>H.at.localeCompare(X.at)).at(-1),P=R!==void 0&&ps(R.phase),_=(R==null?void 0:R.phase)==="applied"&&(!T||p-Date.parse(R.at)<db),D=T&&N&&!A&&!P&&!_,E=d.terminal,z=P||_?null:N?A?E.why.waiting:T?null:E.why.idle:E.why.offline,K=(R==null?void 0:R.phase)==="sending"?E.sending:_?E.sent:E.interrupt(j),L=(R==null?void 0:R.phase)==="rejected"&&R.reason==="read_only"?E.readOnly:k||(R==null?void 0:R.phase)==="rejected"||(R==null?void 0:R.phase)==="failed"?E.fail:null,W=ub(s,m.sessions.values()),ae=!!((B=m.daemon)!=null&&B.broadcast)&&W.ids.length>1,U=x??[s.project,s.branch].filter(Boolean).join(" · ");return e.jsxs(dt,{labelledBy:h,onClose:l,children:[e.jsxs("h2",{id:h,"aria-label":b.sheet.label(j),className:"flex min-w-0 items-center gap-2",children:[e.jsx(gs,{tool:s.tool}),e.jsx("b",{className:"font-semibold whitespace-nowrap",children:j}),U&&e.jsx("span",{className:"min-w-0 truncate text-small font-normal text-muted",children:U})]}),g==="plan"&&v?e.jsxs(e.Fragment,{children:[e.jsx(wu,{checklist:v,...(Z=s.checklist)!=null&&Z.current?{current:s.checklist.current}:{}}),e.jsx("button",{type:"button",onClick:()=>y("menu"),className:"h-11 rounded-lg border border-input text-body",children:d.nav.back})]}):g==="group"?e.jsx(ad,{store:t,label:W.name,ids:W.ids,offline:!N,startOpen:!0,onCancel:()=>y("menu")}):e.jsxs(e.Fragment,{children:[c&&c.length>0&&e.jsx(zn,{children:c.map(H=>e.jsx(us,{icon:H.icon,label:H.label,onClick:H.onClick},H.label))}),u&&u.length>0&&e.jsx(zn,{children:u.map(H=>e.jsx(us,{icon:H.icon,label:H.label,onClick:H.onClick},H.label))}),e.jsxs(zn,{children:[e.jsx(us,{icon:"cpu",label:d.model.title,why:M,right:C||null,onClick:M||!N?void 0:r}),i&&e.jsx(us,{icon:"terminal",label:d.terminal.live2.view,right:i.value,onClick:i.onToggle}),v&&e.jsx(us,{icon:"list",label:d.checklist.title,right:b.sheet.planCount(v.done,v.total),onClick:()=>y("plan")}),e.jsx(us,{icon:"stop",label:K,why:L??z,onClick:D?()=>S(!t.interrupt(s.id)):void 0}),ae&&e.jsx(us,{icon:"send",label:b.sheet.writeGroup(W.name),onClick:N?()=>y("group"):void 0})]}),n&&s.state!=="exited"&&e.jsx(zn,{children:e.jsx(us,{icon:"power",danger:!0,label:a?d.sessionEnd.closingNamed(j):d.sessionEnd.close(j),right:_t()&&!a?e.jsx("span",{"aria-hidden":"true",children:b.sheet.faceId}):null,onClick:a?void 0:o})}),e.jsx("p",{className:"text-meta text-muted",children:b.sheet.interruptNote})]})]})}function xb({name:t,up:s,down:n,onClose:a}){const l=f.useId(),r=d.sessions.reorder;return e.jsxs(dt,{labelledBy:l,onClose:a,children:[e.jsx("h2",{id:l,className:"flex min-w-0 items-center gap-2",children:e.jsx("b",{className:"truncate font-semibold",children:t})}),e.jsxs(zn,{children:[e.jsx(us,{icon:"arrowUp",label:r.up,onClick:s?()=>{s(),a()}:void 0}),e.jsx(us,{icon:"arrowDown",label:r.down,onClick:n?()=>{n(),a()}:void 0})]})]})}const Sr=t=>`ledge.mobile.draft.${t}`;function Eu(t,s){var n;try{return((n=Qe(s))==null?void 0:n.getItem(Sr(t)))??""}catch{return""}}function Ru(t,s,n){try{const a=Qe(n);s===""?a==null||a.removeItem(Sr(t)):a==null||a.setItem(Sr(t),s)}catch{}}const Au="ledge.mobile.draft.cleared",mb=50;function Tu(t){var s;try{const n=JSON.parse(((s=Qe(t))==null?void 0:s.getItem(Au))??"[]");return Array.isArray(n)?n.filter(a=>typeof a=="string"):[]}catch{return[]}}function pb(t,s){return Tu(s).includes(t)}function fb(t,s){var n;try{const a=Tu(s).filter(l=>l!==t);(n=Qe(s))==null||n.setItem(Au,JSON.stringify([...a,t].slice(-mb)))}catch{}}let $r=null;const hb=t=>{$r=t};function gb(t){return $r!==t?!1:($r=null,!0)}function bb(t,s,n){const a=Eu(t,n);Ru(t,a.startsWith(s)?a:s+a,n),hb(t)}const jb=["image/png","image/gif","image/jpeg","image/webp"],yb=25e6,Nb=[.85,.7,.55,.4],Ai=640,vb=.8,kb=[.7,.5],wb={async decode(t){const s=await createImageBitmap(t);let n=null;const a=()=>{n&&(n.width=n.height=0),n=null};return{width:s.width,height:s.height,close:()=>{a(),s.close()},async draw(l,r){a();const o=n=document.createElement("canvas");o.width=l,o.height=r;const i=o.getContext("2d");if(!i)throw new Error("no canvas");return i.imageSmoothingQuality="high",i.drawImage(s,0,0,l,r),{encode:(c,x)=>new Promise((u,m)=>o.toBlob(p=>p?u(p):m(new Error("no blob")),c,x))}}}}},_u=(t,s,n)=>{const a=Math.min(1,n/Math.max(t,s));return{w:Math.max(1,Math.round(t*a)),h:Math.max(1,Math.round(s*a))}};async function Iu(t,s){let n=await t.encode("image/webp",s);return n.type==="image/webp"||n.type==="image/jpeg"?{blob:n,mime:n.type}:(n=await t.encode("image/jpeg",s),{blob:n,mime:"image/jpeg"})}const Lu=t=>new Promise((s,n)=>{const a=new FileReader;a.onload=()=>s(String(a.result).slice(String(a.result).indexOf(",")+1)),a.onerror=()=>n(a.error),a.readAsDataURL(t)});async function Sb(t,s=wb){var a;if(!jb.includes(t.type))return{ok:!1,reason:"notImage"};if(t.size>yb)return{ok:!1,reason:"tooLarge"};let n;try{n=await s.decode(t)}catch{return{ok:!1,reason:"unreadable"}}try{let l=Math.min(cm,Math.max(n.width,n.height));for(;;){const{w:r,h:o}=_u(n.width,n.height,l),i=await n.draw(r,o);for(const c of Nb){const{blob:x,mime:u}=await Iu(i,c);if(x.size>dm)continue;const m={mime:u,data:await Lu(x)},p=await $b(n);return p&&(m.preview=p),{ok:!0,value:{image:m,width:r,height:o,bytes:x.size}}}if(l<=Ai)return{ok:!1,reason:"tooLarge"};l=Math.max(Ai,Math.round(l*vb))}}catch{return{ok:!1,reason:"unreadable"}}finally{(a=n.close)==null||a.call(n)}}async function $b(t){try{return await Cb(t)}catch{return}}async function Cb(t){const{w:s,h:n}=_u(t.width,t.height,um),a=await t.draw(s,n);for(const l of kb){const{blob:r,mime:o}=await Iu(a,l);if(r.size<=xm)return{mime:o,data:await Lu(r)}}}function Mb(t,s){if(t>=1e6){const n=(Math.round(t/1e5)/10).toFixed(1);return`${s==="fr"?n.replace(".",","):n} ${s==="fr"?"Mo":"MB"}`}return`${Math.round(t/1e3)} ${s==="fr"?"Ko":"KB"}`}function Ou({items:t,onRemove:s,size:n,removeLabel:a,lang:l}){return t.length===0?null:e.jsx("div",{"data-attachment-chips":!0,style:{display:"flex",flexWrap:"wrap",gap:8},children:t.map(r=>e.jsxs("div",{"data-chip":r.state,title:r.reason,style:{position:"relative",width:n.w,height:n.h,flexShrink:0,borderRadius:"var(--radius-md)",overflow:"hidden",border:`1px solid ${r.state==="refused"?"var(--danger-text)":"var(--border)"}`,background:"var(--well)"},children:[e.jsx("img",{src:r.url,alt:"",draggable:!1,style:{width:"100%",height:"100%",objectFit:"cover",display:"block",opacity:r.state==="ready"?1:.45}}),r.state==="uploading"&&e.jsx("span",{role:"status","aria-label":"…",style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",style:{color:"var(--foreground)"},children:e.jsx("path",{d:"M12 3a9 9 0 1 1-9 9",opacity:"0.9",children:e.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.9s",repeatCount:"indefinite"})})})}),r.state==="refused"&&e.jsx("span",{style:{position:"absolute",left:0,right:0,bottom:0,padding:"2px 4px",fontSize:10,lineHeight:1.2,color:"var(--danger-text)",background:"var(--status-danger-soft)"},children:r.reason}),r.state!=="refused"&&e.jsx("span",{style:{position:"absolute",left:4,bottom:4,padding:"1px 5px",borderRadius:4,fontSize:10,lineHeight:1.3,color:"#fff",background:"rgba(0,0,0,0.6)"},children:Mb(r.bytes,l)}),e.jsx("button",{type:"button","aria-label":a,title:a,onClick:()=>s(r.key),style:{position:"absolute",top:3,right:3,width:20,height:20,padding:0,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:10,border:"none",cursor:"pointer",color:"#fff",background:"rgba(0,0,0,0.6)"},children:e.jsx(Nn,{...hn.close,size:12})})]},r.key))})}function Eb({url:t,failed:s,width:n,height:a,maxW:l,maxH:r,alt:o,unavailable:i,onOpen:c}){const x=Math.min(1,l/n,r/a),u={width:Math.round(n*x),height:Math.round(a*x),maxWidth:"100%",borderRadius:"var(--radius-lg)",border:"1px solid var(--border)",background:"var(--well)",boxSizing:"border-box",overflow:"hidden"};return s?e.jsx("div",{"data-thumb":"failed",style:{...u,display:"flex",alignItems:"center",justifyContent:"center",padding:8,fontSize:12,color:"var(--muted-foreground)",textAlign:"center"},children:i}):t?e.jsx("button",{type:"button","data-thumb":"ready",onClick:c,style:{...u,padding:0,display:"block",cursor:"zoom-in"},children:e.jsx("img",{src:t,alt:o,draggable:!1,style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})}):e.jsx("div",{"data-thumb":"loading","aria-busy":"true",style:u})}function Du({onFiles:t,disabled:s,className:n,children:a}){const l=f.useRef(null);return e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:l,type:"file",accept:"image/*",multiple:!0,hidden:!0,tabIndex:-1,"aria-hidden":"true",onChange:r=>{t([...r.target.files??[]]),r.target.value=""}}),e.jsx("button",{type:"button",disabled:s,"aria-label":a?void 0:d.images.attach,title:d.images.attach,onClick:()=>{var r;return(r=l.current)==null?void 0:r.click()},className:n??Tt({variant:"outline",round:!0}),children:a??e.jsx(q,{name:"plus"})})]})}const Fu=t=>{var s;return[...((s=t.clipboardData)==null?void 0:s.files)??[]].filter(n=>n.type.startsWith("image/"))},Ti=44,Rb=120,Qa=()=>{var t;return((t=globalThis.matchMedia)==null?void 0:t.call(globalThis,"(hover: hover) and (pointer: fine)").matches)===!0};function Ab({id:t,label:s,sendLabel:n,value:a,onChange:l,onSend:r,canSend:o,oneLine:i,images:c,placeholder:x,disabled:u=!1,attachDisabled:m,maxLength:p,invalid:h=!1,describedBy:g,fieldRef:y}){const k=f.useRef(null),S=y??k;f.useLayoutEffect(()=>{const j=S.current;j&&(j.style.height=`${Ti}px`,j.style.height=`${Math.min(Rb,Math.max(Ti,j.scrollHeight+j.offsetHeight-j.clientHeight))}px`)},[a,S]);const b=m??u;return e.jsxs("div",{className:"flex flex-col gap-2",children:[c.items.length>0&&e.jsx(Ou,{items:c.items,onRemove:c.remove,size:{w:72,h:54},removeLabel:d.images.remove,lang:Lc}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx(Du,{onFiles:c.add,disabled:b}),e.jsx("label",{htmlFor:t,className:"sr-only",children:s}),e.jsx("textarea",{id:t,ref:S,rows:1,value:a,disabled:u,placeholder:x,maxLength:p,enterKeyHint:i?"send":"enter","aria-invalid":h,"aria-describedby":g,onChange:j=>l(j.target.value),onPaste:j=>{const N=Fu(j);N.length===0||b||(j.preventDefault(),c.add(N))},onKeyDown:j=>{j.key!=="Enter"||j.nativeEvent.isComposing||!i&&(j.shiftKey||!Qa())||(j.preventDefault(),o&&r())},className:"max-h-[120px] min-h-11 min-w-0 flex-1 resize-none rounded-[22px] border border-input bg-surface px-3.5 py-[11px] text-base leading-5 text-fg placeholder:text-muted disabled:opacity-60"}),e.jsx("button",{type:"button",disabled:!o,onClick:r,"aria-label":n,title:n,className:Tt({variant:"primary",round:!0}),children:e.jsx(q,{name:"arrowUp"})})]})]})}const Tb={anthropic:{d:"M4.709 15.955l4.72-2.647.08-.23-.08-.128H9.2l-.79-.048-2.698-.073-2.339-.097-2.266-.122-.571-.121L0 11.784l.055-.352.48-.321.686.06 1.52.103 2.278.158 1.652.097 2.449.255h.389l.055-.157-.134-.098-.103-.097-2.358-1.596-2.552-1.688-1.336-.972-.724-.491-.364-.462-.158-1.008.656-.722.881.06.225.061.893.686 1.908 1.476 2.491 1.833.365.304.145-.103.019-.073-.164-.274-1.355-2.446-1.446-2.49-.644-1.032-.17-.619a2.97 2.97 0 01-.104-.729L6.283.134 6.696 0l.996.134.42.364.62 1.414 1.002 2.229 1.555 3.03.456.898.243.832.091.255h.158V9.01l.128-1.706.237-2.095.23-2.695.08-.76.376-.91.747-.492.584.28.48.685-.067.444-.286 1.851-.559 2.903-.364 1.942h.212l.243-.242.985-1.306 1.652-2.064.73-.82.85-.904.547-.431h1.033l.76 1.129-.34 1.166-1.064 1.347-.881 1.142-1.264 1.7-.79 1.36.073.11.188-.02 2.856-.606 1.543-.28 1.841-.315.833.388.091.395-.328.807-1.969.486-2.309.462-3.439.813-.042.03.049.061 1.549.146.662.036h1.622l3.02.225.79.522.474.638-.079.485-1.215.62-1.64-.389-3.829-.91-1.312-.329h-.182v.11l1.093 1.068 2.006 1.81 2.509 2.33.127.578-.322.455-.34-.049-2.205-1.657-.851-.747-1.926-1.62h-.128v.17l.444.649 2.345 3.521.122 1.08-.17.353-.608.213-.668-.122-1.374-1.925-1.415-2.167-1.143-1.943-.14.08-.674 7.254-.316.37-.729.28-.607-.461-.322-.747.322-1.476.389-1.924.315-1.53.286-1.9.17-.632-.012-.042-.14.018-1.434 1.967-2.18 2.945-1.726 1.845-.414.164-.717-.37.067-.662.401-.589 2.388-3.036 1.44-1.882.93-1.086-.006-.158h-.055L4.132 18.56l-1.13.146-.487-.456.061-.746.231-.243 1.908-1.312-.006.006z",fill:"#D97757",rule:"nonzero"},openai:{d:"M9.205 8.658v-2.26c0-.19.072-.333.238-.428l4.543-2.616c.619-.357 1.356-.523 2.117-.523 2.854 0 4.662 2.212 4.662 4.566 0 .167 0 .357-.024.547l-4.71-2.759a.797.797 0 00-.856 0l-5.97 3.473zm10.609 8.8V12.06c0-.333-.143-.57-.429-.737l-5.97-3.473 1.95-1.118a.433.433 0 01.476 0l4.543 2.617c1.309.76 2.189 2.378 2.189 3.948 0 1.808-1.07 3.473-2.76 4.163zM7.802 12.703l-1.95-1.142c-.167-.095-.239-.238-.239-.428V5.899c0-2.545 1.95-4.472 4.591-4.472 1 0 1.927.333 2.712.928L8.23 5.067c-.285.166-.428.404-.428.737v6.898zM12 15.128l-2.795-1.57v-3.33L12 8.658l2.795 1.57v3.33L12 15.128zm1.796 7.23c-1 0-1.927-.332-2.712-.927l4.686-2.712c.285-.166.428-.404.428-.737v-6.898l1.974 1.142c.167.095.238.238.238.428v5.233c0 2.545-1.974 4.472-4.614 4.472zm-5.637-5.303l-4.544-2.617c-1.308-.761-2.188-2.378-2.188-3.948A4.482 4.482 0 014.21 6.327v5.423c0 .333.143.571.428.738l5.947 3.449-1.95 1.118a.432.432 0 01-.476 0zm-.262 3.9c-2.688 0-4.662-2.021-4.662-4.519 0-.19.024-.38.047-.57l4.686 2.71c.286.167.571.167.856 0l5.97-3.448v2.26c0 .19-.07.333-.237.428l-4.543 2.616c-.619.357-1.356.523-2.117.523zm5.899 2.83a5.947 5.947 0 005.827-4.756C22.287 18.339 24 15.84 24 13.296c0-1.665-.713-3.282-1.998-4.448.119-.5.19-.999.19-1.498 0-3.401-2.759-5.947-5.946-5.947-.642 0-1.26.095-1.88.31A5.962 5.962 0 0010.205 0a5.947 5.947 0 00-5.827 4.757C1.713 5.447 0 7.945 0 10.49c0 1.666.713 3.283 1.998 4.448-.119.5-.19 1-.19 1.499 0 3.401 2.759 5.946 5.946 5.946.642 0 1.26-.095 1.88-.309a5.96 5.96 0 004.162 1.713z",fill:"currentColor",rule:"evenodd"},cursor:{d:"M22.106 5.68L12.5.135a.998.998 0 00-.998 0L1.893 5.68a.84.84 0 00-.419.726v11.186c0 .3.16.577.42.727l9.607 5.547a.999.999 0 00.998 0l9.608-5.547a.84.84 0 00.42-.727V6.407a.84.84 0 00-.42-.726zm-.603 1.176L12.228 22.92c-.063.108-.228.064-.228-.061V12.34a.59.59 0 00-.295-.51l-9.11-5.26c-.107-.062-.063-.228.062-.228h18.55c.264 0 .428.286.296.514z",fill:"currentColor",rule:"evenodd"}},_b={claude:"anthropic",codex:"openai",cursor:"cursor"};function zu(t,s,n,a=!0){const[l,r]=f.useState({key:"",url:null,failed:!1}),o=s?`${s}|${n}`:"";return f.useEffect(()=>{if(!s||!a)return;let i=!0;return t.imageUrl(s,n).then(c=>{i&&r({key:o,url:c,failed:!1})},()=>{i&&r({key:o,url:null,failed:!0})}),()=>{i=!1}},[t,s,n,a,o]),l.key===o&&o!==""?{url:l.url,failed:l.failed}:{url:null,failed:!1}}const Ts=d.images,Ib=1,Lb=4,Ob=120,Db=t=>Math.min(Lb,Math.max(Ib,t)),Fb={"image/png":"png","image/gif":"gif","image/jpeg":"jpg","image/webp":"webp"};function zb(t,s,n){const[a,l]=f.useState(null);return f.useEffect(()=>{if(l(null),!t||typeof navigator.canShare!="function"||typeof navigator.share!="function")return;let r=!0;return fetch(t).then(o=>o.blob()).then(o=>{const i=new File([o],s,{type:n});r&&navigator.canShare({files:[i]})&&l(i)},()=>{}),()=>{r=!1}},[t,s,n]),a}function Pb({store:t,refs:s,index:n,onIndex:a,onClose:l}){const r=s[n],{url:o,failed:i}=zu(t,r.id,!1),c=`capture-${n+1}.${Fb[r.mime]??"img"}`,x=zb(o,c,r.mime),[u,m]=f.useState(1),[p,h]=f.useState(0),g=f.useRef(new Map),y=f.useRef({pinch0:0,scale0:1,y0:0});f.useEffect(()=>{m(1),h(0),g.current.clear()},[n]);const k=()=>{const[A,T]=[...g.current.values()];return A&&T?Math.hypot(A.x-T.x,A.y-T.y):0},S=A=>{var T,R;g.current.set(A.pointerId,{x:A.clientX,y:A.clientY}),(R=(T=A.currentTarget).setPointerCapture)==null||R.call(T,A.pointerId),g.current.size===2?y.current={...y.current,pinch0:k(),scale0:u}:y.current={...y.current,y0:A.clientY}},b=A=>{g.current.has(A.pointerId)&&(g.current.set(A.pointerId,{x:A.clientX,y:A.clientY}),g.current.size===2?y.current.pinch0>0&&m(Db(y.current.scale0*k()/y.current.pinch0)):u===1&&h(A.clientY-y.current.y0))},j=A=>{if(g.current.delete(A.pointerId)&&g.current.size===0){if(u===1&&Math.abs(p)>Ob){l();return}h(0)}},N=f.useRef(null);du(N,l);const $=()=>{x&&navigator.share({files:[x]}).catch(()=>{})},C=A=>A.stopPropagation(),M="inline-flex min-h-11 items-center rounded-full bg-white/15 px-4 text-body font-medium text-white",v=(A,T,R,P)=>A>=0&&A<s.length&&e.jsx("button",{type:"button","aria-label":T,title:T,onPointerDown:C,onClick:()=>a(A),className:`absolute top-1/2 ${R} grid size-11 -translate-y-1/2 place-items-center rounded-full bg-white/15 text-white`,children:e.jsx("svg",{className:"size-5 fill-none stroke-current [stroke-linecap:round] [stroke-linejoin:round] [stroke-width:1.6]",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:P})})});return Jr.createPortal(e.jsxs("div",{ref:N,role:"dialog","aria-modal":"true","aria-label":Ts.view,tabIndex:-1,className:"fixed inset-0 z-50 flex flex-col bg-black/90 text-white outline-none",style:{opacity:p?Math.max(.4,1-Math.abs(p)/400):1},children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsxs("span",{className:"min-w-0 flex-1 text-small text-white/70",children:[r.width,"×",r.height,s.length>1?` · ${n+1}/${s.length}`:""]}),x&&e.jsx("button",{type:"button",onPointerDown:C,onClick:$,className:M,children:Ts.share}),o&&e.jsx("a",{href:o,download:c,onPointerDown:C,className:M,children:Ts.save}),e.jsx("button",{type:"button","aria-label":Ts.close,title:Ts.close,onPointerDown:C,onClick:l,className:"grid size-11 place-items-center rounded-full bg-white/15",children:e.jsx("svg",{className:"size-5 fill-none stroke-current [stroke-linecap:round] [stroke-width:1.8]",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"M6 6l12 12M18 6 6 18"})})})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1 items-center justify-center overflow-hidden",style:{touchAction:"none"},onPointerDown:S,onPointerMove:b,onPointerUp:j,onPointerCancel:j,children:[o&&e.jsx("img",{src:o,alt:"",draggable:!1,className:"max-h-full max-w-full select-none object-contain",style:{transform:`translateY(${p}px) scale(${u})`,transition:g.current.size?"none":"transform .15s"}}),!o&&e.jsx("p",{role:"status",className:"text-body text-white/70",children:i?Ts.unavailable:"…"}),v(n-1,Ts.prev,"left-3","m15 18-6-6 6-6"),v(n+1,Ts.next,"right-3","m9 18 6-6-6-6")]})]}),document.body)}const _i=d.images;function Bb({store:t,image:s,onOpen:n}){const[a,l]=f.useState(typeof IntersectionObserver>"u"),r=f.useRef(null);f.useEffect(()=>{if(a||!r.current)return;const c=new IntersectionObserver(x=>{x.some(u=>u.isIntersecting)&&(l(!0),c.disconnect())});return c.observe(r.current),()=>c.disconnect()},[a]);const{url:o,failed:i}=zu(t,s.id,!0,a&&s.preview);return s.preview?e.jsx("div",{ref:r,className:"max-w-full",children:e.jsx(Eb,{url:o,failed:i,width:s.width,height:s.height,maxW:240,maxH:240,alt:"",unavailable:_i.unavailable,onOpen:n})}):e.jsx("p",{className:"max-w-full rounded-lg border border-line bg-surface p-2.5 text-small text-muted",children:_i.noPreview})}function Cr({store:t,refs:s,align:n="start"}){const[a,l]=f.useState(null);return s.length===0?null:e.jsxs("div",{"data-thumbs":!0,className:`flex max-w-full flex-wrap gap-2 ${n==="end"?"justify-end":""}`,children:[s.map((r,o)=>e.jsx(Bb,{store:t,image:r,onOpen:()=>l(o)},`${r.id}:${o}`)),a!==null&&e.jsx(Pb,{store:t,refs:s,index:a,onIndex:l,onClose:()=>l(null)})]})}function qb(t){return!t||t.state==="exited"||t.state==="error"?"stopped":t.state==="waiting_input"||t.state==="waiting_permission"?"waiting":t.state==="idle"&&!t.helpers.some(s=>s.state!=="exited"&&s.state!=="idle")?"yours":"working"}const Hb=new RegExp("(?<code>`[^`\\n]+`)|\\*\\*(?<b>\\S(?:.*?\\S)?)\\*\\*(?!\\*)|(?<![\\w*])\\*(?<i>[^\\s*](?:[^*\\n]*?[^\\s*])?)\\*(?![\\w*])","g"),yo=f.createContext(void 0);function ms(t,s=0,n){let a=0;const l=i=>n?[e.jsx(f.Fragment,{children:n(i)},`t${a++}`)]:[i];if(s>2)return l(t);const r=[];let o=0;for(const i of t.matchAll(Hb)){const c=i.index;c>o&&r.push(...l(t.slice(o,c)));const x=i.groups;x.code?r.push(e.jsx("code",{className:"rounded-md bg-fg/[0.06] px-[5px] py-px font-mono text-[.92em] [overflow-wrap:anywhere]",children:x.code.slice(1,-1)},c)):x.b?r.push(e.jsx("strong",{className:"font-semibold",children:ms(x.b,s+1,n)},c)):r.push(e.jsx("em",{children:ms(x.i,s+1,n)},c)),o=c+i[0].length}return o<t.length&&r.push(...l(t.slice(o))),r}function Pu({b:t}){const s=f.useContext(yo);switch(t.type){case"p":return e.jsx("p",{className:"[&+*]:mt-2.5",children:ms(t.text,0,s)});case"code":return e.jsx("pre",{className:"my-2.5 overflow-x-auto rounded-lg bg-well p-2.5 font-mono text-small leading-[1.6] whitespace-pre",children:t.text});case"list":{const n=t.ordered?"ol":"ul";return e.jsx(n,{className:`my-2.5 flex flex-col gap-1 pl-[18px] text-fg/80 ${t.ordered?"list-decimal":"list-disc"}`,children:t.items.map((a,l)=>e.jsxs("li",{children:[a.checked!==void 0&&e.jsx("span",{"aria-hidden":"true",children:a.checked?"☑ ":"☐ "}),ms(a.text,0,s),a.sub.length>0&&e.jsx("ul",{className:"mt-1 flex list-[circle] flex-col gap-1 pl-4",children:a.sub.map((r,o)=>e.jsx("li",{children:ms(r,0,s)},o))})]},l))})}case"table":return e.jsx("div",{className:"my-2.5 overflow-x-auto",tabIndex:0,children:e.jsxs("table",{className:"w-full border-collapse text-small",children:[e.jsx("thead",{children:e.jsx("tr",{children:t.header.map((n,a)=>e.jsx("th",{className:"border-b border-line px-2 py-1.5 font-semibold",style:{textAlign:t.align[a]??"left"},children:ms(n,0,s)},a))})}),e.jsx("tbody",{children:t.rows.map((n,a)=>e.jsx("tr",{children:n.map((l,r)=>e.jsx("td",{className:"border-b border-line px-2 py-1.5 align-top",style:{textAlign:t.align[r]??"left"},children:ms(l,0,s)},r))},a))})]})});case"quote":return e.jsx("blockquote",{className:"my-2.5 border-l-2 border-line pl-3 text-muted",children:t.blocks.map((n,a)=>e.jsx(Pu,{b:n},a))})}}function Ub({s:t}){const s=f.useContext(yo),n=t.blocks.map((a,l)=>e.jsx(Pu,{b:a},l));return t.kind==="next"?e.jsxs("div",{className:"mt-3 rounded-[10px] border border-info/[0.13] bg-info/[0.03] p-3",children:[e.jsx("div",{className:"mb-1.5 text-meta font-medium tracking-[.5px] text-info uppercase",children:d.thread.suggestion}),n]}):e.jsxs("section",{className:"mt-2.5",children:[t.title&&e.jsx("h3",{className:"mb-1 text-body font-semibold",children:ms(t.title,0,s)}),n]})}function Bu({doc:t,plain:s}){return e.jsxs(yo.Provider,{value:s,children:[t.title&&e.jsx("strong",{className:"block text-body font-semibold",children:ms(t.title,0,s)}),t.lead&&e.jsx("p",{className:"mt-1.5",children:ms(t.lead,0,s)}),t.sections.map((n,a)=>e.jsx(Ub,{s:n},a))]})}const Wb="text-info underline underline-offset-2",bl=(t,s)=>e.jsx("a",{href:ne({name:"thread",sessionId:t}),className:Wb,children:s});function Kb(t){const s=[...t.keys()].filter(Boolean).sort((a,l)=>l.length-a.length);if(s.length===0)return a=>a;const n=new RegExp(`(?<![\\p{L}\\p{N}_])(${s.map(a=>a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")})(?![\\p{L}\\p{N}_])`,"gu");return a=>{const l=[];let r=0;for(const o of a.matchAll(n))o.index>r&&l.push(a.slice(r,o.index)),l.push(e.jsx("span",{children:bl(t.get(o[1]),o[1])},o.index)),r=o.index+o[0].length;return r===0?a:(r<a.length&&l.push(a.slice(r)),l)}}function Vb({text:t,names:s}){const n=f.useMemo(()=>ku(t),[t]),a=f.useMemo(()=>Kb(s),[s]);return e.jsx("div",{className:"px-1 break-words [overflow-wrap:anywhere]",children:e.jsx(Bu,{doc:n,plain:a})})}function Gb({names:t,ids:s}){return t.length===0?null:e.jsxs("span",{className:"px-1 text-small text-muted",children:[d.chat.sources,t.map((n,a)=>e.jsxs("span",{children:[a>0&&", ",s.has(n)?bl(s.get(n),n):n]},n))]})}const Ii=t=>new Date(t).toLocaleTimeString(lt,{hour:"2-digit",minute:"2-digit"});function qu({store:t,qid:s,at:n,rest:a}){return e.jsxs("p",{className:"flex flex-wrap items-center gap-x-2 px-1 text-small text-muted",children:[a?d.chat.ignoredRest(Ii(n)):d.chat.action.ignored(1,Ii(n),{done:0,denied:0,failed:0}),e.jsx("button",{type:"button",className:rs,onClick:()=>{t.ignoreTurn(s,!0)},children:d.chat.review})]})}const ma="flex flex-col gap-2.5 rounded-xl border border-line bg-surface p-3.5",rs=Pe({size:"sm"}),pa=Pe({variant:"primary",size:"sm"});function Xb({store:t,qid:s,relay:n,target:a,known:l,ignoredAt:r}){const o=a==null?void 0:a.repo,[i,c]=f.useState(null),[x,u]=f.useState(!1),[m,p]=f.useState(null),h=n.status==="sent",g=qb(a!=null&&a.state?{state:a.state,helpers:a.helpers??[]}:void 0),y=n.status==="queued";if((m==="send"&&(h||y)||m==="cancel"&&!y)&&p(null),r!==void 0&&!h&&!y)return e.jsx(qu,{store:t,qid:s,at:r});const k=j=>{u(!0),c(null),(j==="send"?t.relay(s):t.cancelRelay(s)).then($=>{$.status==="applied"?p(j):j==="send"&&c($.status==="rejected"?$.reason??"":"")},()=>{j==="send"&&c("")}).finally(()=>u(!1))},S=i||(n.failed?n.code??"":i),b=h?e.jsxs("p",{role:"status",className:"text-body text-ok",children:[d.chat.sentTo(n.name),l?bl(n.id,d.chat.seeThread):d.chat.seeThread]}):y?e.jsx("p",{role:"status",className:"text-body text-attention",children:d.chat.queued(n.name)}):S!==null?e.jsx("p",{role:"alert",className:"text-body text-danger-fg",children:d.chat.relayFailed(S||void 0)}):null;return e.jsxs("section",{"aria-label":d.chat.relayLabel,className:ma,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("h3",{className:"text-body font-semibold",children:[d.chat.relayHead(n.name),o?` · ${o}`:""]}),!h&&e.jsx("span",{"data-pill":g,className:"shrink-0 rounded-full border border-line px-2 text-small text-muted",children:d.chat.relayPill[g]})]}),e.jsx("p",{className:"whitespace-pre-wrap break-words text-body text-fg/80",children:n.text}),b,y&&e.jsx("div",{className:"flex gap-2",children:e.jsx("button",{type:"button",className:rs,disabled:x||m!==null,onClick:()=>k("cancel"),children:d.chat.relayCancel})}),!h&&!y&&e.jsxs("div",{className:"flex gap-2",children:[m===null&&e.jsx("button",{type:"button",className:rs,disabled:x,onClick:()=>{t.ignoreTurn(s)},children:d.chat.ignore}),e.jsx("button",{type:"button",className:pa,disabled:x||m!==null,onClick:()=>k("send"),children:S!==null?d.chat.relayRetry:d.chat.relayGo})]})]})}const Ee=d.chat.action,Yb=Pe({size:"sm",className:"border-danger-fg/50 text-danger-fg"}),Qb=Pe({block:!0,className:"!border-transparent !bg-destructive !text-primary-fg active:opacity-75"});function Mr(t){return t.split(/\*\*(.+?)\*\*/g).map((s,n)=>n%2?e.jsx("strong",{className:"font-semibold",children:s},n):e.jsx(f.Fragment,{children:s},n))}const Zb=t=>t.replace(/\*\*/g,""),Na=t=>t?new Date(t).toLocaleTimeString(lt,{hour:"2-digit",minute:"2-digit"}):"",No=t=>(t.vars&&t.action!==void 0?Ee.line(t.action,t.vars):void 0)??t.summary,Jb=t=>(t.vars&&t.action==="session.decide"?Ee.line("session.decide",{...t.vars,decision:"deny"}):void 0)??No(t),Li=t=>Ee.why(t.code??(t.state==="failed"?"failed":void 0),t.action,t.vars??{});function Oi(t){var l,r;const s=t.vars;if(!(s!=null&&s.seats))return;const n=t.action==="rig.seats"?"removed":t.action!=="rig.act"?void 0:(l=s.kind)!=null&&l.endsWith(".restart")?"restart":(r=s.kind)!=null&&r.endsWith(".stop")?"stop":void 0;if(!n)return;const a=Number(s.seatCount)||s.seats.split(", ").length;return Ee.stops(n,a,s.seats,Number(s.seatsMore??0)||0)}const ej=t=>Ee.verb(t.action,t.vars??{})??(t.action!==void 0?Ee.verbs[t.action]:void 0)??Ee.apply;function tj({r:t}){const s=t.risk==="destructive";return e.jsxs("span",{className:`inline-flex items-center gap-1 text-small ${s?"font-medium text-danger-fg":"text-muted"}`,children:[s&&e.jsx(q,{name:"warning",className:"size-3.5"}),Ee.risk[t.risk]]})}function Di({s:t,k:s,r:n,last:a}){const l=t==="done"||t==="failed"||t==="refused"||t==="running"?Ee.stepState[t](s):Ee.step(s),r=t==="done"?"border-ok bg-ok text-bg":t==="failed"||t==="refused"?"border-transparent bg-destructive text-primary-fg":n.risk==="destructive"?`border-danger-fg/60 bg-surface text-danger-fg ${t==="held"?"border-dashed":""}`:`border-input bg-surface text-muted ${t==="held"?"border-dashed":""}`;return e.jsxs("div",{className:"relative flex justify-center self-stretch",children:[!a&&e.jsx("span",{"aria-hidden":"true",className:"absolute top-5 -bottom-3 left-1/2 w-px -translate-x-1/2 bg-muted/45"}),e.jsx("span",{role:"img","aria-label":l,className:`relative grid size-5 place-items-center rounded-full border-[1.5px] font-mono text-[11px] ${r}`,children:t==="done"?e.jsx(q,{name:"check",className:"size-3"}):t==="failed"||t==="refused"?e.jsx(q,{name:"close",className:"size-3"}):t==="running"?e.jsx(q,{name:"spinner",className:"size-3 motion-safe:animate-spin"}):s})]})}function Fi({r:t,s,whole:n}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"break-words text-body",children:Mr(s==="denied"?Jb(t):No(t))}),s!=="denied"&&e.jsx(tj,{r:t}),n&&Oi(t)&&e.jsx("p",{className:"mt-1 break-words text-small text-muted",children:Oi(t)}),t.detail&&e.jsx("p",{className:`mt-1 break-words text-small text-muted ${n||s==="done"?"":"line-clamp-2"}`,children:t.detail}),t.request&&e.jsxs("pre",{className:`mt-1.5 max-h-40 overflow-auto rounded-md border border-line border-l-2 border-l-muted bg-bg px-2.5 py-2 font-mono text-small whitespace-pre-wrap break-words ${s==="stale"?"line-through opacity-60":s==="denied"?"opacity-60":""}`,children:[e.jsx("span",{className:"mb-0.5 block font-sans text-muted",children:Ee.kind[t.request.kind]??t.request.kind}),t.request.text,s==="cut"&&e.jsx("span",{className:"mt-1 block border-t border-dashed border-line pt-1 font-sans text-muted",children:Ee.cutMark})]})]})}function sj({store:t,qid:s,actions:n,ignoredAt:a,canConfirm:l,readOnly:r=!1}){const[o,i]=f.useState(null),[c,x]=f.useState(new Set),[u,m]=f.useState(null),p=f.useId(),h=n.map(Wm),g=h.length>1,{shown:y,stopAt:k}=Ko(h),S=y.map((D,E)=>c.has(E)&&(D==="proposed"||D==="held"||D==="failed")?"running":D),b=c.size>0,j=D=>D.some(E=>Vo(n[E])),N=(D,E)=>{x(new Set),E.status==="cancelled"||E.status==="expired"?m({rows:D,text:d.confirm[E.status]}):E.status==="rejected"&&E.reason==="confirm_required"?m({rows:D,text:d.chat.closeSetup}):E.status!=="applied"&&m({rows:D,text:Ee.notSent})},$=(D,E)=>{i(null),m(null),x(new Set(D)),t.act(s,D,E).then(z=>N(D,z),()=>N(D,{status:"failed"}))},C=D=>j(D)?i(D):$(D),M=D=>{t.ignoreTurn(s,D)};if(a!==void 0){const D=E=>S.filter(z=>z===E).length;return e.jsxs("p",{className:"flex flex-wrap items-center gap-x-2 px-1 text-small text-muted",children:[Ee.ignored(h.length,Na(a),{done:D("done"),denied:D("denied"),failed:D("failed")}),!r&&e.jsx("button",{type:"button",className:rs,onClick:()=>M(!0),children:Ee.review})]})}const v=e.jsx("button",{type:"button",className:rs,disabled:b,onClick:()=>M(),children:Ee.ignore}),A=(D,E,z)=>{const K=z.risk==="destructive",L=e.jsxs("button",{type:"button",className:K?Yb:rs,disabled:b||j([E])&&!l,onClick:()=>C([E]),children:[ej(z),j([E])?"…":""]}),W=z.deny&&e.jsx("button",{type:"button",className:rs,disabled:b,onClick:()=>$([E],{deny:!0}),children:Ee.deny}),ae=n[E].session;if(r&&(D==="proposed"||D==="held"||D==="failed"||D==="cut"||D==="stale"||D==="running"))return e.jsx("span",{className:"text-small text-muted",children:d.chat.history.notApplied});switch(D){case"proposed":case"held":return e.jsxs(e.Fragment,{children:[!g&&D==="proposed"&&v,W,L]});case"running":return e.jsx("span",{className:"text-body text-attention",children:Ee.running});case"done":return e.jsxs("span",{className:"inline-flex items-center gap-1 text-body text-ok",children:[e.jsx(q,{name:"check",className:"size-3.5"}),Ee.done(Na(z.doneAt))]});case"failed":return e.jsxs(e.Fragment,{children:[!g&&v,e.jsx("button",{type:"button",className:rs,disabled:b||j([E])&&!l,onClick:()=>C([E]),children:Ee.retry})]});case"refused":return e.jsx("span",{className:"text-body text-muted",children:Ee.refusedState});case"denied":return e.jsxs("span",{className:"inline-flex items-center gap-1 text-body text-muted",children:[e.jsx(q,{name:"check",className:"size-3.5"}),Ee.denied(Na(z.doneAt))]});case"stale":return ae?e.jsx("a",{className:rs,href:ne({name:"thread",sessionId:ae}),children:Ee.open(z.target??"")}):null;case"cut":return e.jsxs(e.Fragment,{children:[!g&&v,W,e.jsx(xr,{})]})}},T=(D,E)=>{const z=S[E];return e.jsxs("li",{className:`grid gap-x-2.5 gap-y-1 ${g?"grid-cols-[22px_minmax(0,1fr)]":"grid-cols-1"} ${E>0?"border-t border-line pt-2.5":""}`,children:[g&&e.jsx(Di,{s:z,k:E+1,r:D,last:E===h.length-1}),e.jsxs("div",{className:"min-w-0",children:[e.jsx(Fi,{r:D,s:z,whole:!1}),z==="failed"&&e.jsx("p",{role:"alert",className:"mt-1 text-small text-danger-fg",children:Mr(Ee.failed(Li(D)))}),z==="refused"&&e.jsx("p",{role:"alert",className:"mt-1 text-small text-danger-fg",children:Mr(Ee.refused(Li(D)))}),z==="held"&&e.jsx("p",{className:"mt-1 text-small text-muted",children:Ee.held(k+1)}),z==="stale"&&e.jsx("p",{className:"mt-1 text-small text-attention",children:Ee.stale}),z==="cut"&&e.jsx("p",{className:"mt-1 text-small text-muted",children:Ee.cutNote}),z==="denied"&&e.jsx("p",{className:"mt-1 text-small text-muted",children:Ee.deniedNote(D.target??"")}),e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:A(z,E,D)})]})]},E)},R=()=>{if(!g||r&&!S.every(K=>K==="done"))return null;if(S.every(K=>K==="done")){const K=h.map(L=>L.doneAt).filter(L=>!!L).sort().at(-1);return e.jsxs("p",{className:"inline-flex items-center gap-1.5 text-body text-ok",children:[e.jsx(q,{name:"check",className:"size-3.5"}),Ee.planDone(Na(K))]})}const D=S.indexOf("running");if(D>=0)return e.jsx("button",{type:"button",className:Pe({variant:"primary",size:"sm",block:!0}),disabled:!0,children:Ee.progress(D+1,h.length)});const E=Km(h);if(!E.rows.length)return null;const z=E.from==="start"?Ee.all(E.rows.length):E.from==="resume"?Ee.resume(k+1,E.rows.length):Ee.skip(k+1,E.rows.length);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[v,e.jsxs("button",{type:"button",className:`${pa} flex-1`,disabled:b||j(E.rows)&&!l,onClick:()=>C(E.rows),children:[z,j(E.rows)?"…":""]})]}),e.jsx("span",{className:"text-small text-muted",children:k>=0?Ee.notReplayed:Ee.inOrder})]})},P=!r&&!l&&Ko(h).open.some(D=>Vo(n[D])),_=u&&u.rows.every(D=>(h[D].state??"proposed")==="proposed"||h[D].state==="failed")?u.text:null;return e.jsxs("section",{"aria-label":Ee.label(h.length),"aria-live":"polite",className:ma,children:[e.jsx("ol",{className:"flex flex-col gap-2.5",children:h.map(T)}),R(),_&&e.jsx("p",{role:"status",className:"text-body text-muted",children:_}),P&&e.jsxs("p",{className:"text-body text-attention",children:[d.chat.closeSetup," ",e.jsx("a",{href:ne({name:"connection"}),className:"text-info underline underline-offset-2",children:d.connection.title})]}),o&&e.jsxs(dt,{labelledBy:p,onClose:()=>i(null),children:[e.jsx("h2",{id:p,className:"text-heading leading-[1.3] tracking-[-.5px]",children:o.length>1?Ee.sheet.many(o.length):Ee.sheet.one(Zb(No(h[o[0]])))}),e.jsx("ol",{className:"flex flex-col gap-2.5",children:o.map((D,E)=>e.jsxs("li",{className:`grid gap-x-2.5 ${g?"grid-cols-[22px_minmax(0,1fr)]":"grid-cols-1"}`,children:[g&&e.jsx(Di,{s:"proposed",k:D+1,r:h[D],last:E===o.length-1}),e.jsx(Fi,{r:h[D],s:"proposed",whole:!0})]},D))}),e.jsxs("p",{className:"text-small leading-[1.6] text-muted",children:[o.length>1?`${Ee.sheet.stops} `:"",d.confirm.note]}),e.jsx("button",{type:"button",className:Qb,onClick:()=>$(o),children:_t()?d.confirm.goApple:d.confirm.go}),e.jsx("button",{type:"button",className:Pe({block:!0}),onClick:()=>i(null),children:Ee.sheet.cancel})]})]})}function nj(t,s,n,a,l){return t.closedAt!==void 0?t.how==="killed"?"killed":"closed":n?"ended":a==="all"||a!=null&&a.has(s)?"closing":t.failed||l?"failed":"open"}function aj({store:t,qid:s,closes:n,canConfirm:a,sessions:l}){const{ops:r}=me(t),[o,i]=f.useState(new Set),[c,x]=f.useState(!1),[u,m]=f.useState(null),p=Object.values(r).filter(j=>ps(j.phase)).map(j=>j.message).filter(j=>j.type==="chat.relay"||j.type==="chat.launch"||j.type==="chat.close").filter(j=>j.qid===s),h=(()=>{const j=p.filter(N=>N.type==="chat.close");return j.length===0?null:j.some(N=>!N.rows)?"all":new Set(j.flatMap(N=>N.rows??[]))})(),g=c||p.length>0,y=n.map((j,N)=>{const $=l.find(C=>C.id===j.id);return{row:j,i:N,name:($==null?void 0:$.name)??j.name,state:nj(j,N,!$||!!$.exited,h,o.has(N))}}),k=y.filter(j=>j.state==="open"||j.state==="failed"),S=j=>{x(!0),m(null),i(N=>new Set([...N].filter($=>!j.includes($)))),t.closeSessions(s,j).then(N=>{N.status==="cancelled"||N.status==="expired"?m(N.status):(N.status==="failed"||N.status==="rejected")&&i($=>new Set([...$,...j]))},()=>i(N=>new Set([...N,...j]))).finally(()=>x(!1))},b={closed:d.chat.closed,killed:d.chat.killed,ended:d.chat.ended,closing:d.chat.closing,failed:d.chat.closeFailed,open:""};return e.jsxs("section",{"aria-label":d.chat.closeLabel,"aria-live":"polite",className:ma,children:[e.jsx("ul",{className:"flex flex-col gap-2",children:y.map(({row:j,i:N,name:$,state:C})=>e.jsxs("li",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"min-w-0 flex-1 truncate text-body font-semibold",children:[$," ",e.jsxs("span",{className:"font-normal text-muted",children:["· ",d.tools[j.tool]]})]}),C!=="open"&&e.jsx("span",{className:`text-body ${C==="failed"?"text-danger-fg":C==="closing"?"text-attention":"text-ok"}`,children:b[C]}),(C==="open"||C==="failed")&&e.jsx("button",{type:"button",className:rs,disabled:g||!a,onClick:()=>S([N]),children:d.chat.closeRow})]},N))}),u&&e.jsx("p",{className:"text-body text-muted",children:d.confirm[u]}),k.length>0&&!a&&e.jsxs("p",{className:"text-body text-attention",children:[d.chat.closeSetup," ",e.jsx("a",{href:ne({name:"connection"}),className:"text-info underline underline-offset-2",children:d.connection.title})]}),k.length>=2&&e.jsx("div",{className:"flex gap-2",children:e.jsx("button",{type:"button",className:pa,disabled:g||!a,onClick:()=>S(k.map(j=>j.i)),children:d.chat.closeAll(k.length)})})]})}function lj({store:t,qid:s,row:n,proposal:a,canConfirm:l,known:r,ignored:o}){const[i,c]=f.useState(null),[x,u]=f.useState(!1),[m,p]=f.useState(!1),h=a.launchedId!==void 0;if(o&&!h)return null;const g=()=>{u(!0),c(null),t.launch(s,[n]).then(k=>{k.status==="applied"?p(!0):k.status==="cancelled"||k.status==="expired"?c(k.status):(k.status==="failed"||k.status==="rejected")&&c("failed")},()=>c("failed")).finally(()=>u(!1))},y=a.failed?"failed":i;return e.jsxs("section",{"aria-label":d.chat.launchLabel,className:ma,children:[e.jsx("h3",{className:"text-body font-semibold",children:d.chat.launchHead(d.tools[a.tool],a.project)}),a.prompt&&e.jsx("p",{className:"whitespace-pre-wrap break-words text-body text-fg/80",children:a.prompt}),h&&e.jsxs("p",{role:"status",className:"text-body text-ok",children:[d.chat.launchedTo,r?bl(a.launchedId,d.chat.seeThread):d.chat.seeThread]}),!h&&y&&e.jsx("p",{role:"status",className:`text-body ${y==="failed"?"text-danger-fg":"text-muted"}`,children:y==="failed"?d.chat.notLaunched:d.confirm[y]}),!h&&!l&&e.jsxs("p",{className:"text-body text-attention",children:[d.chat.launchSetup," ",e.jsx("a",{href:ne({name:"connection"}),className:"text-info underline underline-offset-2",children:d.connection.title})]}),!h&&e.jsxs("div",{className:"flex gap-2",children:[!m&&e.jsx("button",{type:"button",className:rs,disabled:x,onClick:()=>{t.ignoreTurn(s)},children:d.chat.ignore}),e.jsx("button",{type:"button",className:pa,disabled:x||m||!l,onClick:g,children:_t()?d.confirm.goApple:d.confirm.go})]})]})}function rj({store:t,qid:s,proposals:n,canConfirm:a,sessionIds:l,ignoredAt:r}){const o=r!==void 0;return e.jsxs(e.Fragment,{children:[n.map((i,c)=>e.jsx(lj,{store:t,qid:s,row:c,proposal:i,canConfirm:a,known:l.has(i.launchedId??""),ignored:o},c)),o&&n.some(i=>i.launchedId===void 0)&&e.jsx(qu,{store:t,qid:s,at:r,rest:n.some(i=>i.launchedId!==void 0)})]})}function oj({store:t,qid:s,row:n,task:a}){const[l,r]=f.useState(!1),[o,i]=f.useState(!1),[c,x]=f.useState(!1),u=a.taskId!==void 0,m=()=>{r(!0),i(!1),t.giveTask(s,n).then(p=>{p.status==="applied"?x(!0):i(!0)},()=>i(!0)).finally(()=>r(!1))};return e.jsxs("section",{"aria-label":d.chat.task.label,className:ma,children:[e.jsxs("p",{className:"text-body",children:[e.jsx("span",{className:"font-mono text-agent",children:a.toName??a.to})," · ",e.jsx("span",{className:"font-semibold",children:a.title})]}),a.text&&e.jsx("p",{className:"whitespace-pre-wrap break-words text-body text-fg/80",children:a.text}),u&&e.jsx("p",{role:"status",className:"text-body text-ok",children:d.chat.task.given(a.ownerName??a.toName??a.to,a.taskId,d.chat.point.state[a.state??"open"])}),!u&&(o||a.failed)&&e.jsx("p",{role:"status",className:"text-body text-danger-fg",children:d.chat.task.notGiven}),!u&&e.jsx("div",{className:"flex items-center gap-3",children:e.jsx("button",{type:"button",className:pa,disabled:l||c,onClick:m,children:d.chat.task.give})})]})}function ij({store:t,qid:s,tasks:n}){return e.jsx(e.Fragment,{children:n.map((a,l)=>e.jsx(oj,{store:t,qid:s,row:l,task:a},l))})}const vo="flex flex-col gap-1.5 border-l-2 border-line pl-2.5",zi="size-3.5 flex-none fill-none stroke-current [stroke-linecap:round] [stroke-linejoin:round] [stroke-width:1.6]";function cj(t,s){const n=t.name??t.id??"";switch(t.kind){case"sessions":return d.chat.steps.sessions(s);case"pane":return d.chat.steps.pane(n);case"reply":return d.chat.steps.reply(n);case"git":case"repo":return d.chat.steps.look(n)}}function dj(t){const s=t.filter(n=>n.kind==="pane"||n.kind==="reply").map(n=>n.name??n.id).filter(n=>!!n);return[...new Set(s)]}function uj({steps:t,sessions:s,running:n}){return t.length===0?null:e.jsx("ul",{className:"flex flex-col gap-2 px-1 py-0.5","aria-label":d.chat.stepsLabel,children:t.map((a,l)=>{const r=n&&l===t.length-1;return e.jsxs("li",{className:`flex items-center gap-2 text-small text-muted ${r?"motion-safe:animate-pulse":""}`,children:[r?e.jsx("svg",{className:`${zi} motion-safe:animate-spin`,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})}):e.jsx("svg",{className:`${zi} text-ok`,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"M20 6 9 17l-5-5"})}),cj(a,s)]},`${l}:${a.kind}:${a.id??""}`)})})}const xj=t=>({busy:d.chat.busy,timeout:d.chat.timeout,failed:d.chat.failed,cancelled:d.chat.cancelled})[t];function Pi({store:t,turn:s,live:n,sessions:a,list:l,canConfirm:r,onAskAgain:o,readOnly:i=!1,limits:c,inAnswer:x}){if(s.point)return e.jsx(Cg,{store:t,turn:{...s,point:s.point},readOnly:i});const u=(n==null?void 0:n.steps)??s.steps,m=n?n.text:s.answer,p=new Map,h=new Set;for(const y of l)y.name&&(p.has(y.name)?h.add(y.name):p.set(y.name,y.id));for(const y of h)p.delete(y);const g=s.relay;return e.jsxs("div",{className:"flex flex-col gap-3",children:[s.question&&e.jsx("div",{className:"max-w-[85%] self-end whitespace-pre-wrap break-words rounded-[12px_12px_4px_12px] bg-raised px-3 py-2",children:s.question}),s.attachments&&e.jsx("div",{className:"self-end max-w-full",children:e.jsx(Cr,{store:t,refs:s.attachments,align:"end"})}),e.jsx(uj,{steps:u,sessions:a,running:!!n&&!n.text}),n&&m&&e.jsx("p",{"aria-live":"polite",className:"px-1 whitespace-pre-wrap break-words",children:m}),!n&&m&&e.jsx(Vb,{text:m,names:p}),!n&&s.answer&&e.jsx(Gb,{names:dj(u),ids:p}),!n&&s.answer&&x,!n&&s.answer&&c&&e.jsx(gj,{usage:c.usage,now:Date.now(),alert:c.alert,fresh:c.fresh,at:c.at}),!n&&s.cut&&e.jsx("span",{className:"px-1 text-small text-muted",children:d.chat.cut}),!n&&s.error&&e.jsxs("div",{className:"flex flex-col items-start gap-1.5 px-1",children:[e.jsx("p",{role:"status",className:`text-[13.5px] ${s.error==="cancelled"?"text-muted":s.error==="busy"?"text-attention":"text-danger-fg"}`,children:xj(s.error)}),(s.error==="timeout"||s.error==="failed")&&s.question&&o&&e.jsx("button",{type:"button",onClick:()=>o(s.question),className:Fe({size:"xs"}),children:d.chat.askAgain})]}),!n&&e.jsxs("fieldset",{disabled:i,className:"contents",children:[!n&&s.closes&&e.jsx(aj,{store:t,qid:s.qid,closes:s.closes,canConfirm:r,sessions:l}),!n&&!s.closes&&g&&e.jsx(Xb,{store:t,qid:s.qid,relay:g,target:l.find(y=>y.id===g.id),known:l.some(y=>y.id===g.id),ignoredAt:s.ignoredAt}),!n&&!s.closes&&s.proposals&&s.proposals.length>0&&e.jsx(rj,{store:t,qid:s.qid,proposals:s.proposals,canConfirm:r,sessionIds:new Set(l.map(y=>y.id)),ignoredAt:s.ignoredAt}),!n&&s.actions&&e.jsx(sj,{store:t,qid:s.qid,actions:s.actions,ignoredAt:s.ignoredAt,canConfirm:r,readOnly:i}),!n&&s.tasks&&s.tasks.length>0&&e.jsx(ij,{store:t,qid:s.qid,tasks:s.tasks})]})]})}function mj({harness:t,size:s=14}){const{d:n,fill:a,rule:l}=Tb[_b[t]];return e.jsx("svg",{className:`harness-${t} inline-block flex-none`,width:s,height:s,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:n,fill:a,fillRule:l})})}function ko(t){const s=d.chat.point;switch(t.kind){case"five_hour":return s.five;case"seven_day":return s.week;case"month":return s.month;case"pool":return t.pool==="other"?s.poolOther:s.poolCursor;default:return s.model(t.model??"")}}const pj={"":"",amber:"bg-attention",red:"bg-approval"},wo={"":"",amber:"text-attention",red:"text-approval"};function Hu({pct:t,alert:s}){const n=da(t,s);return e.jsx("span",{className:"block h-[5px] overflow-hidden rounded-[2px]",style:{background:"var(--u-track)"},children:e.jsx("span",{className:`block h-full rounded-[2px] ${pj[n]}`,style:{width:`${Math.min(100,t)}%`,...n?{}:{background:"var(--u-gauge)"}}})})}function fj({label:t,w:s,now:n,alert:a}){const l=d.chat.point,r=da(s.pct,a),o=s.resetsAt?oo(s.resetsAt,n):null;return e.jsxs("div",{className:"grid grid-cols-[58px_1fr_128px] items-center gap-2 py-[3px] text-small",children:[e.jsx("span",{children:t}),e.jsx(Hu,{pct:s.pct,alert:a}),e.jsxs("span",{className:"truncate font-mono text-[12px]",children:[e.jsx("b",{className:`font-medium ${wo[r]}`,children:d.percent(s.pct)}),o&&e.jsx("small",{className:"ml-1.5 text-[11px] text-muted",children:dh(s)?s.resetsAt&&zd(s.resetsAt,n)?l.resumesOn(o):l.resumes(o):`↺ ${o}`})]})]})}function hj(t,s){const n=d.chat.point,a=n.harnessShort[t]??t;switch(s.kind){case"five_hour":return`${a} ${n.five}`;case"seven_day":return`${a} ${n.weekShort}`;case"month":return`${a} ${n.monthShort}`;case"model":return`${n.model(s.model??a)} ${n.weekShort}`;default:return null}}function gj({usage:t,now:s,alert:n,fresh:a=!0,at:l}){const r=d.chat.point,o=[],i=[];if(ua(t,s,a).forEach((x,u)=>{const m=r.harnessShort[x.harness]??x.harness,p=(k,S)=>o.push({key:x.harness,label:m,sentence:k,amber:S});if(x.status==="loading")return p(r.loading,!1);if(x.status==="expired")return p(r.notOnPc(r.harness[x.harness]??m),!0);const h=t[u];if(h.harness==="cursor"&&h.status==="ok"&&h.windows.length===0&&h.readAt!==null)return p(r.unread,!1);const g=x.status==="stale"||x.status==="unreachable",y=x.windows.flatMap(k=>{const S=hj(x.harness,k);return S?[{key:`${x.harness}:${k.kind}:${k.model??""}`,label:S,w:k,dim:g}]:[]});if(y.length){o.push(...y),g&&x.readAt&&i.push(Date.parse(x.readAt));return}x.status==="unreachable"&&p(x.readAt?r.unreach(Ka(Math.max(0,s-Date.parse(x.readAt)))):r.unreachNever,!0)}),!o.length)return null;const c=Math.min(Date.parse(l),...i);return e.jsxs("div",{role:"group","aria-label":r.limitsLabel,className:vo,children:[e.jsx("div",{className:"flex flex-col",children:o.map(x=>{if("sentence"in x)return e.jsxs("div",{className:"grid grid-cols-[66px_1fr] items-center gap-2 py-0.5 text-[12px]",children:[e.jsx("span",{className:"whitespace-nowrap",children:x.label}),e.jsx("span",{className:x.amber?"text-attention":"text-muted",children:x.sentence})]},x.key);const u=da(x.w.pct,n);return e.jsxs("div",{className:`grid grid-cols-[66px_1fr_118px] items-center gap-2 py-0.5 text-[12px] ${x.dim?"opacity-50":""}`,children:[e.jsx("span",{className:"whitespace-nowrap",children:x.label}),e.jsx(Hu,{pct:x.w.pct,alert:n}),e.jsxs("span",{className:"whitespace-nowrap font-mono text-[12px]",children:[e.jsx("b",{className:u?`font-medium ${wo[u]}`:"font-normal",children:d.percent(x.w.pct)}),x.w.resetsAt&&e.jsxs("small",{className:"ml-[5px] text-[11px] text-muted",children:["↺ ",oo(x.w.resetsAt,s,!0)]})]})]},x.key)})}),o.some(x=>"w"in x)&&e.jsx("span",{className:"text-[11.5px] text-muted",children:r.stale(Ka(Math.max(0,s-c)))})]})}function bj({usage:t,now:s,alert:n,fresh:a=!0}){const l=d.chat.point,r=ua(t,s,a);if(!r.length)return null;const o=i=>t[i].harness==="cursor"&&t[i].status==="ok"&&t[i].windows.length===0&&t[i].readAt!==null;return e.jsxs("div",{role:"group","aria-label":l.limitsLabel,className:"flex flex-col",children:[e.jsx("h3",{className:"mt-1 text-meta tracking-[.4px] text-muted",children:l.limits}),r.map((i,c)=>{const x=i.readAt?Ka(s-Date.parse(i.readAt)):null,u=i.status==="stale"||i.status==="unreachable";return e.jsxs("div",{"data-harness":i.harness,className:"flex flex-col",children:[e.jsxs("div",{className:"mt-1.5 mb-0.5 flex items-baseline gap-1.5 text-small font-semibold",children:[e.jsx(mj,{harness:i.harness}),l.harness[i.harness]??i.harness]}),i.status==="loading"&&e.jsx("p",{className:"py-1 text-small text-muted",children:l.loading}),i.status==="expired"&&e.jsx("p",{className:"py-1 text-small text-attention",children:l.notOnPc(l.harness[i.harness]??i.harness)}),i.status==="ok"&&o(c)&&e.jsx("p",{className:"py-1 text-small text-muted",children:l.unread}),i.status!=="loading"&&i.status!=="expired"&&i.windows.length>0&&e.jsx("div",{className:u?"opacity-50":void 0,children:i.windows.map(m=>e.jsx(fj,{label:ko(m),w:m,now:s,alert:n},`${m.kind}:${m.model??m.pool??""}`))}),i.status==="stale"&&x&&e.jsx("p",{className:"py-1 text-small text-attention",children:l.stale(x)}),i.status==="unreachable"&&e.jsx("p",{className:"py-1 text-small text-attention",children:x?l.unreach(x):l.unreachNever})]},i.harness)})]})}const Ot=d.thread.rig,jj="inline-flex items-center gap-1 whitespace-nowrap text-small text-muted",yj="inline-flex items-center gap-1 whitespace-nowrap text-small font-medium text-fg",Uu="mt-1.5 rounded-[6px] border border-line bg-well px-2.5 py-2 font-mono text-meta whitespace-pre-wrap text-muted [overflow-wrap:anywhere]",jl=()=>e.jsx("div",{className:"text-meta text-muted",children:d.thread.cut});function Nj({session:t}){const s=nn(),n=t.state==="exited"?"done":t.state==="waiting_input"?"question":t.state==="waiting_permission"?"approval":t.state;return e.jsx("span",{className:"inline-flex flex-none","aria-hidden":"true",children:e.jsx(rl,{tool:t.tool,seed:t.id,state:n,pose:ll(t.id,n),size:16,theme:s,frozen:!0})})}function vj({lead:t,who:s,children:n}){return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 text-meta leading-5 font-medium text-muted",children:[e.jsx("span",{children:t}),s.session&&e.jsx(Nj,{session:s.session}),e.jsx("strong",{className:"font-semibold text-fg",children:s.name}),s.seat&&e.jsx("span",{className:"font-mono font-normal",children:s.seat}),n]})}function fa(t){const[s,n]=f.useState(!1),a=t&&e.jsx("button",{type:"button","aria-expanded":s,onClick:()=>n(r=>!r),className:jj,children:t.label}),l=t&&s&&e.jsx("pre",{className:Uu,children:t.text});return{toggle:a,box:l}}function kj({e:t,storage:s}){const{toggle:n,box:a}=fa(t.raw),l=t.dir==="out",r=t.delivery&&Ot.sent[t.delivery];return e.jsxs("div",{className:`flex flex-col gap-1 ${l?"items-end":"items-start"}`,children:[e.jsxs("article",{"aria-label":l?`${Ot.to} ${t.who.name}`:`${Ot.from} ${t.who.name}`,className:`flex max-w-[92%] min-w-0 flex-col gap-1 px-3.5 py-2.5 ${l?"rounded-2xl rounded-br-[4px] bg-raised":"rounded-2xl rounded-bl-[4px] border border-line bg-surface"}`,children:[e.jsxs(vj,{lead:l?Ot.to:Ot.from,who:t.who,children:[t.count&&e.jsx("span",{className:"inline-flex h-[18px] items-center rounded-full bg-attention/12 px-1.5 text-[10.5px] text-attention",children:Ot.twice(t.count)}),l&&r&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:t.delivery==="failed"?"text-attention":"",children:r})]})]}),e.jsx("div",{className:"text-body whitespace-pre-wrap [overflow-wrap:anywhere]",children:t.text}),(t.reply||n)&&e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-3",children:[t.reply&&e.jsxs("a",{href:ne({name:"thread",sessionId:t.reply.sessionId}),onClick:()=>bb(t.reply.sessionId,t.reply.draft,s),"aria-label":Ot.replyTo(t.who.name),className:yj,children:[e.jsx(q,{name:"reply",className:"size-3.5"}),Ot.reply]}),n]}),a]}),t.cut&&e.jsx(jl,{})]})}const Bi="inline-flex h-5 items-center rounded-full px-2 text-meta font-medium whitespace-nowrap",wj={pending:"bg-raised text-muted",taken:"bg-[var(--status-info-soft)] text-info",passed:"bg-task/14 text-task",blocked:"bg-[var(--status-warning-soft)] text-attention",done:"bg-[var(--status-success-soft)] text-ok",unknown:"border border-dashed border-line text-muted"};function Sj(t){const[s,n]=f.useState(typeof IntersectionObserver>"u");return f.useEffect(()=>{const a=t.current;if(!a||typeof IntersectionObserver>"u")return;const l=new IntersectionObserver(r=>n(r.some(o=>o.isIntersecting)));return l.observe(a),()=>l.disconnect()},[t]),s}function $j(t,s,n){var o,i;const a=me(t),l=((o=a.daemon)==null?void 0:o.rigRows)===!0,r=!!s&&n&&l&&a.fresh;return f.useEffect(()=>{if(!r)return;t.requestRigRow(s);const c=setInterval(()=>t.requestRigRow(s),mm);return()=>clearInterval(c)},[r,t,s]),s&&l?(i=a.rigRows[s])==null?void 0:i.row:void 0}function Cj({e:t,store:s}){const{toggle:n,box:a}=fa(t.raw),l=f.useRef(null),r=Sj(l),o=$j(s,t.qitem,r),i=t.refused?null:Of(o,t.outgoing),c=t.refused?t.refused.log:i==null?void 0:i.log;return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("section",{ref:l,"aria-label":t.outgoing?Ot.rowOut(t.who.name):Ot.rowIn(t.who.name),className:"flex w-full flex-col gap-1.5 rounded-[10px] border border-l-[3px] border-task/35 border-l-task bg-surface px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-small font-medium text-task",children:[e.jsx(q,{name:"task",className:"size-3.5"}),e.jsx("span",{className:"min-w-0 truncate",children:t.outgoing?Ot.rowOut(t.who.name):Ot.rowIn(t.who.name)}),e.jsx("span",{className:"flex-1"}),i?e.jsx("span",{"data-state":i.key,className:`${Bi} ${wj[i.key]}`,children:i.text}):e.jsx("span",{"data-state":"refused",className:`${Bi} bg-danger-bg text-danger-fg`,children:Ot.rowState.refused})]}),e.jsx("h4",{className:"line-clamp-2 text-[0.90625rem] leading-[1.3125rem] font-semibold [overflow-wrap:anywhere]",children:t.title}),c&&e.jsx("p",{className:"text-small text-muted [overflow-wrap:anywhere]",children:c}),n&&e.jsxs("div",{className:"flex items-center border-t border-dashed border-line pt-1.5",children:[e.jsx("span",{className:"flex-1"}),n]}),a]}),t.cut&&e.jsx(jl,{})]})}function Wu({e:t}){const{toggle:s,box:n}=fa(t.raw),a=t.tone==="warn"?"border-l-attention":t.tone==="task"?"border-l-task":"border-l-line";return e.jsxs("div",{role:"note",className:`min-w-0 border-l-2 ${a} py-0.5 pl-2.5 text-small leading-5 text-muted`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:`text-[10px] font-medium tracking-[.04em] uppercase ${t.tone==="task"?"text-task":""}`,children:Ot.openrig}),e.jsx("span",{className:`min-w-0 font-medium [overflow-wrap:anywhere] ${t.tone==="warn"?"text-attention":"text-fg"}`,children:t.title}),e.jsx("span",{className:"flex-1"}),s]}),n,t.cut&&e.jsx(jl,{})]})}function Mj({e:t}){const[s,n]=f.useState(!1);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("button",{type:"button","aria-expanded":s,onClick:()=>n(a=>!a),className:"flex items-center gap-1.5 py-0.5 text-left text-small text-muted",children:[e.jsx("span",{className:`inline-flex transition-transform motion-reduce:transition-none ${s?"rotate-90":""}`,children:e.jsx(q,{name:"chevron",className:"size-3.5"})}),e.jsx("strong",{className:"font-medium text-fg",children:Ot.folded(t.notices.length)})]}),s&&t.notices.map(a=>e.jsx(Wu,{e:a},a.key))]})}function Ej({e:t}){return e.jsxs("div",{className:"flex flex-col gap-1 border-l-2 border-dashed border-line pl-2.5",children:[e.jsx("div",{className:"text-meta leading-5 font-medium text-muted",children:Ot.unreadable}),e.jsx("pre",{className:Uu.replace("mt-1.5 ",""),children:t.text}),t.cut&&e.jsx(jl,{})]})}function Rj({e:t}){const{toggle:s,box:n}=fa(t.raw);return e.jsxs("div",{className:"-mt-2 flex flex-col items-start",children:[s,n&&e.jsx("div",{className:"w-full",children:n})]})}function Aj({e:t,storage:s,store:n}){switch(t.kind){case"rig-message":return e.jsx(kj,{e:t,storage:s});case"rig-task":return e.jsx(Cj,{e:t,store:n});case"rig-notice":return e.jsx(Wu,{e:t});case"rig-fold":return e.jsx(Mj,{e:t});case"rig-unreadable":return e.jsx(Ej,{e:t});case"rig-raw":return e.jsx(Rj,{e:t})}}const vs=d.thread.task,Tj={killed:{tone:"attention",text:"text-attention",icon:"stop"},completed:{tone:"ok",text:"text-ok",icon:"check"},failed:{tone:"danger",text:"text-danger-fg",icon:"close"},other:{tone:"muted",text:"text-muted",icon:"task"}};function _j({task:t,cut:s}){const{toggle:n,box:a}=fa({label:vs.raw,text:t.raw}),l=Tj[t.status],r=vs.statuses[t.status],{about:o}=t,i=(o==null?void 0:o.kind)==="command"?o.code:void 0,c=[i!==void 0?vs.code(i):null,t.output??null].filter(Boolean).join(" · ");return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("section",{"aria-label":vs.label(r),"data-status":t.status,className:"flex w-full flex-col gap-1.5 rounded-[10px] border border-line bg-surface px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(q,{name:l.icon,className:`size-3.5 ${l.text}`}),e.jsx("span",{className:"text-meta font-medium tracking-[.04em] text-muted uppercase",children:vs.kicker}),e.jsx("span",{className:"flex-1"}),e.jsx(ra,{tone:l.tone,label:r})]}),e.jsx("p",{className:"text-body [overflow-wrap:anywhere]",children:(o==null?void 0:o.kind)==="agent"?e.jsxs(e.Fragment,{children:[vs.agent," ",e.jsx("strong",{className:"font-semibold",children:o.name})," ",vs.agentDid[t.status]]}):(o==null?void 0:o.kind)==="command"?e.jsxs(e.Fragment,{children:[vs.command," ",e.jsx("code",{className:"rounded-[4px] bg-fg/[0.05] px-1 font-mono text-[.9em]",children:o.command})," ",vs.commandDid[t.status]]}):t.summary}),c&&e.jsx("p",{className:"font-mono text-meta text-muted [overflow-wrap:anywhere]",children:c}),e.jsxs("div",{className:"flex items-center border-t border-dashed border-line pt-1.5",children:[e.jsx("span",{className:"flex-1"}),n]}),a]}),s&&e.jsx("div",{className:"text-meta text-muted",children:d.thread.cut})]})}const mn=d.images;let Ij=0;const Lj=t=>`data:${t.mime};base64,${t.data}`;function Ku(t){const[s,n]=f.useState([]),[a,l]=f.useState(0),[r,o]=f.useState(null),i=f.useRef([]),c=f.useRef(0),x=f.useRef(!0);f.useEffect(()=>(x.current=!0,()=>{x.current=!1}),[]);const u=j=>{i.current=j,n(j)},m=(j,N)=>{x.current&&u(i.current.map($=>$.item.key===j?{...$,...N,item:{...$.item,...N.item}}:$))},p=j=>{c.current+=j,l(c.current)},h=async j=>{const N=await Sb(j);if(p(-1),!x.current)return;if(!N.ok){o(N.reason==="tooLarge"?mn.tooLarge:mn.notImage);return}const{image:$,width:C,height:M,bytes:v}=N.value,A=`att-${Ij++}`;u([...i.current,{item:{key:A,url:Lj($.preview??$),width:C,height:M,bytes:v,state:"uploading"}}]);try{const T=await t.putImage($);m(A,{id:T.id,item:{state:"ready"}})}catch(T){const R=T instanceof Error&&T.message==="too_large"?mn.tooLarge:T instanceof Error&&T.message==="not_image"?mn.notImage:mn.failed;m(A,{item:{state:"refused",reason:R}}),x.current&&o(R)}},g=j=>{if(j.length!==0){o(null);for(const N of j){if(i.current.length+c.current>=Fo){o(mn.max);return}p(1),h(N)}}},y=j=>{const N=i.current.find($=>$.item.key===j);u(i.current.filter($=>$.item.key!==j)),(N==null?void 0:N.item.state)==="refused"&&o(null)},k=()=>{const j=i.current;return u([]),o(null),j},S=j=>{x.current&&u([...j,...i.current].slice(0,Fo))},b=s.map(j=>j.item);return{items:b,add:g,remove:y,clear:k,putBack:S,error:r,ready:a===0&&b.every(j=>j.state==="ready"),ids:()=>i.current.filter(j=>j.item.state==="ready"&&j.id).map(j=>j.id)}}const Vu=`${Cs}launch.started`;function Gu(t){var s;try{const n=JSON.parse(((s=Qe(t))==null?void 0:s.getItem(Vu))??"[]");return Array.isArray(n)?n.filter(a=>typeof(a==null?void 0:a.id)=="string"&&typeof(a==null?void 0:a.project)=="string"):[]}catch{return[]}}function Oj(t,s,n){var l;const a=[...Gu(n).filter(r=>r.id!==t),{id:t,project:s}].slice(-50);try{(l=Qe(n))==null||l.setItem(Vu,JSON.stringify(a))}catch{}}const Dj=(t,s)=>{var n;return((n=Gu(s).find(a=>a.id===t))==null?void 0:n.project)??null};function Fj(t){const s=/^\/(\S*)$/.exec(t);return s?s[1].toLowerCase():null}function zj(t,s){var l;const n=s.toLowerCase(),a=[];for(const r of t){const o=[r.name,...r.aliases??[]],i=o.map(g=>g.toLowerCase());let c=-1,x=r.name,u=-1;const m=i.indexOf(n),p=i.findIndex(g=>g.startsWith(n)),h=i.findIndex(g=>g.includes(n));m>=0&&n?(c=0,x=o[m],u=0):p>=0?(c=1,x=o[p],u=0):h>=0?(c=2,x=o[h],u=i[h].indexOf(n)):(l=r.description)!=null&&l.toLowerCase().includes(n)&&(c=3),!(c<0)&&(x!==r.name&&r.name.toLowerCase().startsWith(n)&&(x=r.name,u=0),a.push({command:r,shown:x,at:n?u:-1,rank:c}))}return a.sort((r,o)=>r.rank-o.rank||+!!r.command.blocked-+!!o.command.blocked||r.shown.localeCompare(o.shown)).map(({rank:r,...o})=>o)}function Pj(t,s){const n=/^\/(\S+)/.exec(t.trimStart());if(!n)return;const a=n[1].toLowerCase();return s.find(l=>{var r;return l.name.toLowerCase()===a||((r=l.aliases)==null?void 0:r.some(o=>o.toLowerCase()===a))})}const Bj=t=>`/${t.name} `,Us=d.thread.slash;function qj({listing:t,query:s,matches:n,tool:a,name:l,onPick:r}){const o="mb-2 overflow-hidden rounded-2xl border border-line bg-surface";return t?t.error?e.jsx("div",{className:`${o} px-3 py-3 text-meta text-muted`,role:"status",children:Us.unavailable(l)}):n.length===0?e.jsx("div",{className:`${o} px-3 py-3 text-meta text-muted`,role:"status",children:Us.none(`/${s}`,l)}):e.jsxs("div",{className:o,children:[e.jsx("p",{className:"px-3 pt-2 pb-1 text-meta text-muted",children:Us.count(a,n.length)}),e.jsx("ul",{"aria-label":Us.label(a),className:"max-h-[300px] overflow-y-auto overscroll-contain px-1 pb-1",children:n.map(i=>{const c=i.command,x=c.blocked!==void 0,u=s.length,m=Us.source[c.source];return e.jsx("li",{className:"border-t border-line first:border-t-0",children:e.jsxs("button",{type:"button",disabled:x,onMouseDown:p=>p.preventDefault(),onClick:()=>r(c),className:"flex min-h-[52px] w-full flex-col justify-center rounded-[10px] px-2.5 py-1.5 text-left enabled:active:bg-raised",children:[e.jsxs("span",{className:`font-mono text-[14px] leading-5 ${x?"text-muted":""}`,children:["/",i.at>=0&&u>0?e.jsxs(e.Fragment,{children:[i.shown.slice(0,i.at),e.jsx("mark",{className:"bg-transparent font-semibold text-fg underline underline-offset-2",children:i.shown.slice(i.at,i.at+u)}),i.shown.slice(i.at+u)]}):i.shown,c.argumentHint&&e.jsxs("span",{className:"text-[12px] text-muted",children:[" ",c.argumentHint]}),m&&e.jsx("span",{className:`ml-1.5 font-sans text-[10.5px] ${c.source==="project"?"text-info":"text-muted"}`,children:m})]}),e.jsx("span",{className:`truncate text-[12px] leading-4 ${x?"text-attention":"text-muted"}`,children:x?Us.blocked[c.blocked]:c.description})]})},c.name)})})]}):e.jsx("div",{className:`${o} px-3 py-3 text-meta text-muted`,role:"status",children:Us.loading(a)})}const Hj={ok:"text-ok",info:"text-info",approval:"text-approval",attention:"text-attention",muted:"text-muted"},Lt=d.thread.composer;function Xu(t){const s=t.trim();return s.length>ta?"long":Tc.test(s)?"untypable":null}function Uj(t){if(t.phase==="uncertain"||t.reason==="not_taken")return{title:Lt.uncertainTitle,body:Lt.uncertain};const s=t.reason==="busy"?Lt.busy:t.reason==="invalid"?Lt.invalid(ta):t.reason==="untypable"?Lt.untypable:t.reason==="read_only"?Lt.readOnly:t.reason==="attachment_missing"?Lt.imageGone:t.reason==="attachments_not_accepted"?d.images.dialog:Lt.lost;return{title:Lt.failTitle,body:s}}function Wj({name:t,focusAtEnd:s=!1,composer:n,draft:a,onDraft:l,onSend:r,fresh:o,taken:i,checking:c,error:x,alert:u,onReconnect:m,images:p,dialog:h,lead:g,leadNote:y,slash:k}){var E,z;const[S,b]=Cn(),j=i?{tone:"ok",label:Lt.status.taken}:c?{tone:"muted",label:d.decide.checking}:n.status,N=Xu(a),$=f.useRef(null),C=p.items.length>0;f.useEffect(()=>{const K=$.current;!s||!K||(K.focus(),K.setSelectionRange(K.value.length,K.value.length))},[]);const M=k&&n.enabled&&!h?Fj(a):null,v=M!==null;f.useEffect(()=>{v&&(k==null||k.ask())},[v]);const A=(E=k==null?void 0:k.listing)!=null&&E.error?[]:((z=k==null?void 0:k.listing)==null?void 0:z.commands)??[],T=f.useMemo(()=>M!==null?zj(A,M):[],[M,A]),R=k&&!h?Pj(a,A):void 0,P=K=>{var L;l(Bj(K)),(L=$.current)==null||L.focus()},_=!R||M!==null?null:R.blocked?{warn:!0,text:d.thread.slash.blocked[R.blocked]}:R.bare&&/^\/\S+\s*$/.test(a)?{warn:!0,text:d.thread.slash.bare(R.name)}:R.argumentHint?{warn:!1,text:`/${R.name} ${R.argumentHint}`}:null,D=n.enabled&&(!!a.trim()||C)&&N===null&&p.ready&&!(C&&h);return e.jsxs("footer",{className:"flex-none border-t border-line bg-bg pt-2 pb-3 [@media(max-height:650px)]:pb-2",children:[e.jsxs("div",{className:`flex items-center gap-1.5 pb-2 text-meta ${Hj[j.tone]}`,children:[e.jsx("i",{className:"inline-block size-1.5 flex-none rounded-full bg-current"}),j.label]}),u&&e.jsx("div",{className:"mb-2.5",children:u}),!u&&x&&e.jsx("div",{className:"mb-2.5",children:e.jsxs(Xe,{title:x.title,tone:"warning",role:"alert",children:[e.jsx("p",{children:x.body}),!o&&m&&e.jsx("button",{type:"button",disabled:S,onClick:()=>{b(!0),m()},className:Pe({block:!0,className:"mt-2"}),children:S?d.link.reconnecting:Lt.reconnect})]})}),v&&e.jsx(qj,{listing:k.listing,query:M,matches:T,tool:k.tool,name:t,onPick:P}),!v&&(n.enabled||g)&&e.jsxs("div",{role:"group","aria-label":Lt.quickLabel,className:"flex gap-1.5 overflow-x-auto pb-2 [scrollbar-width:none]",children:[g,n.enabled&&Uf.map(K=>e.jsx("button",{type:"button",onClick:()=>{var L;l(K),(L=$.current)==null||L.focus()},className:`${Ic()} whitespace-nowrap`,children:K},K))]}),y,e.jsx(Ab,{id:"draft",label:Lt.label(t),sendLabel:Lt.send(t),value:a,onChange:l,onSend:r,canSend:D,oneLine:!0,images:p,placeholder:n.placeholder,disabled:!n.enabled,fieldRef:$,invalid:N!==null,describedBy:N?"draft-problem":void 0}),_&&e.jsx("p",{role:"status",className:`pt-1.5 text-meta ${_.warn?"text-attention":"font-mono text-muted"}`,children:_.text}),C&&h&&e.jsx("p",{role:"status",className:"pt-1.5 text-meta text-attention",children:d.images.dialog}),p.error&&e.jsx("p",{role:"alert",className:"pt-1.5 text-meta text-attention",children:p.error}),N&&e.jsx("p",{id:"draft-problem",role:"status",className:"pt-1.5 text-meta text-attention",children:N==="long"?Lt.tooLong(ta):Lt.untypable})]})}const Ue=d.sessionEnd,In=t=>Pe({variant:t,block:!0});function Yu(t,s,n,a,l){const[r,o]=f.useState(null),[i,c]=f.useState(null),[x,u]=f.useState(!1),[m,p]=f.useState(0),h=f.useRef(!0);return f.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]),f.useEffect(()=>{if(!a)return;let S=!0,b;return o(null),t.prepareConfirm(s==="terminal"?{purpose:s,id:n}:{purpose:s,id:n}).then(j=>{S&&(o(j),b=setTimeout(()=>{S&&(o(null),c("expired"))},j.expiresInMs))},()=>{S&&c("prepareFailed")}),()=>{S=!1,clearTimeout(b)}},[t,s,n,a,m]),{challenge:r,problem:i,asking:x,needsNew:i==="expired"||i==="failed"||i==="prepareFailed",go:async()=>{if(!a||x||!r)return;if(!r.credentialId){o(null),c("failed");return}u(!0),c(null);const S=await sa({challenge:r.challenge,rpId:r.rpId,credentialId:r.credentialId}).catch(()=>"failed");if(h.current){if(u(!1),S==="cancelled"){c("cancelled");return}if(S==="failed"){o(null),c("failed");return}o(null),l(S)===null&&c("failed")}},retry:()=>{c(null),p(S=>S+1)}}}function So({store:t,session:s,mode:n,onClose:a,onSent:l,onReconnect:r}){const{fresh:o,device:i}=me(t),[c,x]=Cn(),u=s.name,m=n==="close",p=!!(i!=null&&i.confirm),h=Yu(t,m?"close":"act",s.id,o&&p,S=>{const b=m?t.sessionClose(s.id,S):t.sessionResume(s.id,S);return b!==null&&l(),b}),g=m?Vm(s):[],y=h.asking?d.confirm.asking:h.challenge?m?_t()?Ue.goCloseApple:Ue.goClose:_t()?Ue.goResumeApple:Ue.goResume:d.confirm.preparing,k=e.jsx("button",{type:"button",onClick:a,className:In(),children:Ue.cancel});return e.jsxs(dt,{labelledBy:"end-title",onClose:a,children:[e.jsx("h2",{id:"end-title",className:"text-heading leading-[1.3] tracking-[-.5px]",children:m?Ue.closeTitle(u):Ue.resumeTitle(u)}),o?p?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:m?Ue.closeBody:Ue.resumeBody}),g.length>0&&e.jsx(Xe,{title:Ue.cutsTitle,tone:"warning",children:e.jsx("ul",{className:"flex list-disc flex-col gap-1 pl-5",children:g.map(S=>e.jsx("li",{children:S},S))})}),h.problem&&e.jsx(Xe,{title:d.confirm[h.problem],tone:"warning",role:"alert"}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:g.length>0?`${Ue.force} ${Ue.check}`:Ue.check}),h.needsNew?e.jsx("button",{type:"button",onClick:h.retry,className:In("primary"),children:d.confirm.retry}):e.jsx("button",{type:"button",disabled:h.asking||!h.challenge,onClick:()=>{h.go()},className:In("primary"),children:y}),k]}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{title:Ue.unprotectedTitle,tone:"warning",role:"status",children:e.jsx("p",{children:m?Ue.unprotectedClose(u):Ue.unprotectedResume(u)})}),e.jsx("a",{href:ne({name:"connection"}),className:In("primary"),children:Ue.openConnection}),k]}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{title:Ue.offlineTitle,tone:"warning",role:"status",children:e.jsx("p",{children:m?Ue.offlineClose(u):Ue.offlineResume(u)})}),r&&e.jsx("button",{type:"button",disabled:c,onClick:()=>{x(!0),r()},className:In("primary"),children:c?d.link.reconnecting:Ue.reconnect}),k]})]})}function qi({tone:t,label:s}){return e.jsxs("div",{className:`flex items-center gap-1.5 text-meta ${t==="attention"?"text-attention":"text-info"}`,children:[e.jsx(q,{name:"spinner",className:"size-3 animate-spin motion-reduce:animate-none",stroke:2}),s]})}function Qu({error:t,fresh:s,onRetry:n,onReconnect:a}){const[l,r]=Cn();return e.jsxs(Xe,{title:t.title,tone:"warning",role:"alert",children:[e.jsx("p",{children:t.body}),t.retry&&e.jsx("button",{type:"button",onClick:n,className:Pe({size:"sm",className:"mt-2"}),children:Ue.retry}),t.reconnect&&!s&&a&&e.jsx("button",{type:"button",disabled:l,onClick:()=>{r(!0),a()},className:Pe({size:"sm",className:"mt-2"}),children:l?d.link.reconnecting:Ue.reconnect})]})}function Kj({ending:t,name:s,canResume:n,resumeHeld:a=!1,readOnly:l,fresh:r,focus:o,onResume:i,onReconnect:c}){const x=f.useRef(null);return f.useEffect(()=>{var u;o&&((u=x.current)==null||u.focus({preventScroll:!0}))},[o]),e.jsxs("footer",{ref:x,tabIndex:-1,role:"status",className:"flex flex-none flex-col gap-2.5 border-t border-line bg-bg pt-3 pb-3 outline-none [@media(max-height:650px)]:pb-2",children:[t.kind==="closing"&&e.jsxs(e.Fragment,{children:[e.jsx(qi,{tone:"attention",label:Ue.closing(s)}),e.jsx("p",{className:"text-small text-muted",children:Ue.closingHint})]}),t.kind==="resuming"&&e.jsx(qi,{tone:"info",label:Ue.resuming(s)}),t.kind==="ended"&&e.jsxs(e.Fragment,{children:[t.error&&e.jsx(Qu,{error:t.error,fresh:r,onRetry:i,onReconnect:c}),e.jsxs("section",{"aria-labelledby":"ended-title",className:"flex flex-col gap-2.5 rounded-card border border-line bg-surface p-4",children:[e.jsx("h2",{id:"ended-title",className:"text-body font-semibold",children:Ue.ended}),t.killed?e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:Ue.killed}):!l&&e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:n?Ue.endedBody:Ue.endedOnPc}),n&&!l&&e.jsxs("button",{type:"button","aria-disabled":a||void 0,onClick:()=>{a||i()},className:Pe({variant:t.killed?"outline":"primary",block:!0,className:a?"opacity-45":""}),children:[e.jsx(q,{name:"resume"}),Ue.resume(s)]})]})]})]})}function Vj({text:t}){const s=f.useMemo(()=>ku(t),[t]);return e.jsx(Bu,{doc:s})}const Hi=({align:t})=>e.jsx("div",{className:`text-meta text-muted ${t==="end"?"text-right":""}`,children:d.thread.cut}),Ui={success:{glyph:"✓",tone:"text-ok"},running:{glyph:"●",tone:"text-info"},failed:{glyph:"✕",tone:"text-danger-fg"},unknown:{glyph:"·",tone:"text-muted"}};function Gj({tools:t}){const[s,n]=f.useState(!1),a=d.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":s,onClick:()=>n(l=>!l),className:"flex h-[34px] w-full items-center gap-1.5 px-2.5 text-left font-sans text-[12.5px]",children:[e.jsx(q,{name:"chevron",className:`size-3.5 transition-transform ${s?"rotate-90":""}`}),e.jsx("span",{className:"min-w-0 truncate",children:s?a.tools(t.length):a.toolsNamed(t.length,Df(t).join(", "))})]}),s&&e.jsx("ul",{className:"pb-2",children:t.map(l=>e.jsxs("li",{className:"flex gap-1.5 px-2.5 py-[3px]",children:[e.jsx("span",{"aria-label":a.toolStatus[l.status],role:"img",className:Ui[l.status].tone,children:Ui[l.status].glyph}),e.jsxs("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:[e.jsx("b",{className:"font-medium text-fg",children:l.name})," ",l.label]})]},l.id))})]})}function Xj({store:t,item:s,onReconnect:n,keys:a}){var i,c,x;const l=me(t),r=Fs(),o=l.sessions.get(s.sessionId);return e.jsx(io,{store:t,item:s,session:o,inThread:!0,keys:a,mode:Qr(s,(i=l.capabilities)==null?void 0:i[s.tool],(o==null?void 0:o.readOnly)===!0),outcome:Gn(s,[...l.sessions.values()],l.ops),fresh:l.fresh,ghost:!1,changed:!1,onReread:()=>{},canConfirm:((c=l.device)==null?void 0:c.confirm)===!0&&r,enroll:r&&((x=l.device)==null?void 0:x.confirm)!==!0,onGone:()=>{},onCheck:n})}function Yj({item:t,store:s,storage:n,inPanel:a=!1,onReconnect:l,keys:r=!1}){switch(t.kind){case"tools":return e.jsx(Gj,{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(Aj,{e:t,storage:n,store:s});case"me":{const o=t.images??(t.attachments??[]).flatMap(i=>s.knownImage(i)??[]);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(Cr,{store:s,refs:o,align:"end"}),t.cut&&e.jsx(Hi,{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"?d.thread.delivery.sending:t.delivery==="uncertain"?d.thread.delivery.uncertain:t.fresh?d.thread.delivery.takenNow:d.thread.delivery.taken})]})}case"agent":return e.jsxs("div",{className:"flex flex-col items-start gap-1",children:[e.jsx("article",{"aria-label":d.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(Vj,{text:t.text})}),t.cut&&e.jsx(Hi,{align:"start"})]});case"task":return e.jsx(_j,{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(Cr,{store:s,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(Xe,{title:a?d.atelier.awaiting:d.thread.awaiting,tone:t.item.kind==="question"?"warning":"approval",children:[e.jsx("p",{className:"[overflow-wrap:anywhere]",children:wn(t.item)}),e.jsxs("a",{href:ne(a?{name:"atelier",sessionId:t.item.sessionId,requestKey:t.item.key}:{name:"request",sessionId:t.item.sessionId,key:t.item.key}),className:Pe({block:!0,className:"mt-3"}),children:[d.thread.examine,e.jsx(q,{name:"arrowRight"})]})]}):e.jsx(Xj,{store:s,item:t.item,onReconnect:l,keys:r})}}function Qj({sessionId:t,panel:s}){return e.jsxs(e.Fragment,{children:[e.jsx("a",{href:ne({name:"thread",sessionId:t}),"aria-label":d.atelier.fullScreen,title:d.atelier.fullScreen,className:Tt({variant:"outline"}),children:e.jsx(q,{name:"external"})}),e.jsx("button",{type:"button",onClick:s.onClose,"aria-label":d.atelier.closePanel,title:d.atelier.closeTitle,className:Tt({}),children:e.jsx(q,{name:"close"})})]})}function Er({store:t,sessionId:s,storage:n,onReconnect:a,panel:l,forge:r}){var Y,Re,ke,ie,Ae,Je,xt,Yt,ze,ht,Nt;const o=me(t),i=Xt(),c=It(),x=il(),u=o.sessions.get(s),m=o.threads.get(s),{fresh:p,ops:h}=o,[g,y]=f.useState(()=>Eu(s,n)),[k]=f.useState(()=>gb(s)),[S,b]=f.useState(!1),j=Ku(t),N=f.useRef(new Map);f.useEffect(()=>{var we;for(const[G,Ne]of N.current){const oe=(we=h[G])==null?void 0:we.phase;oe==="applied"?N.current.delete(G):(oe==="rejected"||oe==="failed"||oe==="uncertain")&&(N.current.delete(G),j.putBack(Ne))}});const $=we=>{y(we),Ru(s,we,n),b(!1)},[C,M]=f.useState(null),[v,A]=f.useState(!1),[T,R]=f.useState(!1),[P,_]=f.useState(!1),[D,E]=f.useState(null),z=((Y=Gm(s,h))==null?void 0:Y.op)??null,K=f.useRef(u==null?void 0:u.state);f.useEffect(()=>{K.current!==(u==null?void 0:u.state)&&K.current!==void 0&&E(z),K.current=u==null?void 0:u.state},[u==null?void 0:u.state,z]),f.useEffect(()=>(t.openThread(s),()=>t.watch(null)),[t,s]),f.useEffect(()=>{p&&t.watch(s)},[t,s,p]);const L=(m==null?void 0:m.status)==="ready"?(Re=m.items.at(-1))==null?void 0:Re.at:void 0;f.useEffect(()=>{L&&t.read(s,L)},[t,s,L]);const W=Md(s,h).at(-1);f.useEffect(()=>{(W==null?void 0:W.phase)!=="applied"||pb(W.op,n)||(fb(W.op,n),g.trim()===W.message.text&&$(""))},[W==null?void 0:W.phase,W==null?void 0:W.op]);const[ae,U]=f.useState(""),O=u==null?void 0:u.state;f.useEffect(()=>{(W==null?void 0:W.phase)==="applied"&&O&&O!=="idle"&&U(W.op)},[O,W==null?void 0:W.phase,W==null?void 0:W.op]);const B=f.useRef(null),Z=(m==null?void 0:m.status)==="gone",H=u&&!Z?qf((m==null?void 0:m.items)??[],u,h,i,(m==null?void 0:m.cut)??[],o.sessions,((ke=o.device)==null?void 0:ke.id)??null):[],X=(ie=H.at(-1))==null?void 0:ie.key,te=f.useRef(!0),[pe,ue]=f.useState(!1),F=()=>{const we=B.current;we&&(we.scrollTop=we.scrollHeight),te.current=!0,ue(!1)},w=f.useRef(!1);f.useLayoutEffect(()=>{var G;const we=B.current;if(!(!we||H.length===0)){if(!w.current){w.current=!0;const Ne=Ul.get(s);if(Ul.delete(s),Ne!==void 0){we.scrollTop=Ne,te.current=we.scrollHeight-we.scrollTop-we.clientHeight<Wi;return}}te.current?F():((G=H.at(-1))==null?void 0:G.kind)==="awaiting"&&ue(!0)}},[X,H.length,m==null?void 0:m.items]);const I=()=>{const we=B.current;we&&(te.current=we.scrollHeight-we.scrollTop-we.clientHeight<Wi,te.current&&ue(!1))};if(!u||Z){const we=!Z&&!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:[!l&&e.jsx(is,{fallback:{name:"sessions"},label:d.thread.back}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:d.thread.title}),e.jsx(xd,{link:Mn(o)}),l&&e.jsx("button",{type:"button",onClick:l.onClose,"aria-label":d.atelier.closePanel,title:d.atelier.closeTitle,className:Tt({}),children:e.jsx(q,{name:"close"})})]})}),e.jsx("main",{className:"min-h-0 flex-1 pt-7 text-body text-muted",role:"status",children:we?d.thread.loading:d.thread.unknown})]})}const V=W!==void 0&&ps(W.phase),ee=(W==null?void 0:W.phase)==="applied"&&ae!==W.op&&u.state==="idle"&&!u.pending&&i-Date.parse(W.at)<mr,Q=Hf(u,p?"ready":"pc_offline",V||ee),J=W&&(W.phase==="rejected"||W.phase==="failed"||W.phase==="uncertain")&&(W.phase==="uncertain"||g.trim()===W.message.text)?Uj(W):null,fe=S&&!J?{title:d.thread.composer.failTitle,body:d.thread.composer.lost}:J,be=!!u.pending||u.state==="waiting_input"||u.state==="waiting_permission",tt=()=>{const we=g.trim();if(!we&&j.items.length===0||!Q.enabled||Xu(g)||!j.ready||j.items.length>0&&be)return;E(z);const G=j.ids(),Ne=j.clear(),oe=t.reply(s,we,G.length?{attachments:G}:{});!oe&&Ne.length?j.putBack(Ne):oe&&Ne.length&&N.current.set(oe,Ne),b(!oe)},yt=(m==null?void 0:m.status)==="ready",Ze=((Ae=o.daemon)==null?void 0:Ae.boot)??null,Le=Xm(u,h,i,{fresh:p,boot:Ze}),de=Wr(u,h,Ze,i),he=!!((Je=o.daemon)!=null&&Je.sessionClose)&&!u.readOnly,$e=Le.kind==="open"&&Le.error&&Le.error.op!==D?Le.error:null,Oe=we=>{E(z),_(!1),M(we)},rt=!!l&&u.tool==="omp",Ge=Sn(u),pt=Dj(s,n),ft=u.state==="exited"&&u.exitedAt?d.sessions.line.ended(zc(u.exitedAt,i)):void 0,ut=x&&[u.project,u.branch].filter(Boolean).join(" · ")||void 0;return e.jsxs(e.Fragment,{children:[e.jsx(la,{back:l?e.jsx("span",{className:"w-2.5"}):e.jsx(is,{fallback:{name:"sessions"},label:d.thread.back}),tool:u.tool,name:u.name,dot:Ge,pulse:Ge==="work"&&p,sub:ft??ut,under:!x&&!!ft,more:e.jsxs(e.Fragment,{children:[l?e.jsx(Qj,{sessionId:s,panel:l}):e.jsx(Zu,{sessionId:s,current:"thread",onLeave:()=>{B.current&&Ul.set(s,B.current.scrollTop)}}),e.jsx("button",{type:"button","aria-haspopup":"dialog","aria-label":d.sessions.moreOf(u.name),title:d.sessions.more,onClick:()=>A(!0),className:Tt({className:v?"bg-raised text-fg":"text-muted"}),children:e.jsx(q,{name:"more"})})]})}),rt?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:d.atelier.ompNoThread}),e.jsx("p",{className:"max-w-[320px] text-body text-muted",children:d.atelier.ompBody}),e.jsxs("a",{href:ne({name:"terminal",sessionId:s}),className:Pe({variant:"primary"}),children:[e.jsx(q,{name:"terminal"}),d.atelier.ompTerminal]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("main",{ref:B,onScroll:I,"aria-label":d.thread.log(u.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:[((xt=o.daemon)==null?void 0:xt.checklist)&&o.checklists.get(s)&&e.jsx(wu,{checklist:o.checklists.get(s),current:(Yt=u==null?void 0:u.checklist)==null?void 0:Yt.current}),(m==null?void 0:m.more)&&e.jsx("p",{className:"text-center text-meta text-muted",children:d.thread.more}),!(m!=null&&m.more)&&pt!==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:d.launch.started(u.name,pt)}),!yt&&H.length===0&&e.jsx("p",{className:"text-center text-meta text-muted",role:"status",children:p?d.thread.loading:d.thread.unavailable}),yt&&H.length===0&&e.jsx("p",{className:"text-center text-meta text-muted",children:d.thread.empty}),H.map(we=>e.jsx(Yj,{item:we,store:t,storage:n,inPanel:!!l,onReconnect:a,keys:c&&!l},we.key))]}),pe&&e.jsx("div",{className:"relative h-0",children:e.jsxs("button",{type:"button",onClick:F,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(q,{name:"down",className:"size-4"}),d.sessions.requestBelow]})}),Le.kind==="open"?e.jsx(Wj,{name:u.name,focusAtEnd:k,composer:c&&Qa()?{...Q,placeholder:`${Q.placeholder} · ${d.sessions.keysHint}`}:Q,draft:g,onDraft:$,onSend:tt,fresh:p,taken:ee,checking:(W==null?void 0:W.phase)==="uncertain"&&p,error:fe,onReconnect:a,images:j,dialog:be,...(ze=o.daemon)!=null&&ze.commands&&u.tool==="claude"&&!u.readOnly?{slash:{tool:d.tools[u.tool],listing:o.commands[s],ask:()=>t.requestCommands(s)}}:{},alert:$e&&e.jsx(Qu,{error:$e,fresh:p,onRetry:()=>Oe("close"),onReconnect:a}),...sn(o.daemon,u)?{lead:e.jsx(ib,{store:t,session:u}),leadNote:e.jsx(cb,{store:t,session:u})}:{}}):e.jsx(Kj,{ending:Le.kind==="ended"&&((ht=Le.error)==null?void 0:ht.op)===D?{...Le,error:null}:Le,name:u.name,canResume:he,resumeHeld:Ym(u,h,Ze,i),readOnly:!!u.readOnly,fresh:p,focus:P,onResume:()=>Oe("resume"),onReconnect:a},Le.kind),e.jsx(Ju,{store:t,forge:r,session:u,wide:x,threshold:((Nt=o.device)==null?void 0:Nt.contextNear)??kn,onModel:()=>R(!0)})]}),v&&e.jsx(jo,{store:t,session:u,closable:he&&!rt,closing:de,onClose:()=>A(!1),onModel:()=>{A(!1),R(!0)},onCloseSession:()=>{A(!1),Oe("close")}}),T&&sn(o.daemon,u)&&e.jsx(gl,{store:t,session:u,onClose:()=>R(!1)}),C&&e.jsx(So,{store:t,session:u,mode:C,onClose:()=>M(null),onSent:()=>{_(!0),M(null)},onReconnect:a})]})}const Ul=new Map,Wi=48;function Zu({sessionId:t,current:s,onLeave:n}){const a=d.sessions.view,l="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:ne({name:"thread",sessionId:t}),onClick:s==="thread"?void 0:n,"aria-current":s==="thread"?"page":void 0,className:l,children:a.thread}),e.jsx("a",{href:ne({name:"terminal",sessionId:t}),onClick:s==="terminal"?void 0:n,"aria-current":s==="terminal"?"page":void 0,className:l,children:a.terminal})]})}function Ju({store:t,forge:s,session:n,wide:a,threshold:l,onModel:r}){const o=me(t),{daemon:i,fresh:c,usage:x,usageAlert:u}=o,m=Xt(),p=ul(n,m,l),h=d.sessions,g=Mu(i,n)===null,y=a?mh(n.tool,x,u,m,c):null;return e.jsxs("footer",{"aria-label":h.foot(n.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&&(g?e.jsxs("button",{type:"button",disabled:!c,"aria-haspopup":"dialog","aria-label":d.model.chip(p.model),onClick:r,className:"inline-flex h-8 items-center gap-1 text-fg disabled:opacity-60",children:[p.model,e.jsx(q,{name:"down",className:"size-3.5"})]}):e.jsx("span",{className:"text-fg",children:p.model})),p.context&&e.jsxs("span",{role:"img","aria-label":h.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&&n.context&&e.jsxs("span",{children:["· ",ii(n.context.used)," / ",ii(n.context.window)]}),(p.model||p.context)&&e.jsx("span",{className:"h-3 w-px flex-none bg-line"}),n.branch?e.jsx("span",{className:`min-w-0 truncate font-mono text-[11px] ${a?"":"flex-1"}`,children:n.branch}):e.jsxs("span",{"aria-label":h.folder(n.project),className:`inline-flex min-w-0 items-center gap-1 ${a?"":"flex-1"}`,children:[e.jsx(q,{name:"folder",className:"size-3.5"}),e.jsx("span",{className:"truncate",children:n.project})]}),n.branch&&e.jsx(gg,{forge:s,mobile:o,session:n}),a&&n.branch&&e.jsx("span",{className:"min-w-0 truncate",children:n.project}),a&&e.jsx("span",{className:"flex-1"}),y&&e.jsxs("span",{className:"flex-none",children:[d.chat.point.harnessShort[y.harness]??y.harness," ",ko(y.window)," ",e.jsxs("b",{className:`font-semibold ${y.tone==="red"?"text-approval":y.tone==="amber"?"text-attention":"text-fg"}`,children:[y.window.pct," %"]})]})]})}const Zj={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 Jj({state:t,label:s,tone:n,caps:a=!1}){const{stateLabel:l}=qr(),r=Zj[n??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:r,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:Kp([["background-color","hover"],["color","hover"]])},children:s??l[t]})}const Ki=["monstera","fern","snake","ficus","succulent"],e1=["tl","tr","br","ml","mr"];function t1(t,s){const n=bn(t),a=1+n%2;return e1.filter(l=>!s.includes(l)).sort((l,r)=>bn(t+l)-bn(t+r)).slice(0,a).map((l,r)=>({spot:l,species:Ki[(n+r*7)%Ki.length],flip:!!(n>>r&1)}))}const Ls={top:56,side:12,bottom:34},Vi=11/12,ex=t=>t.width>=t.height?"land":"port";function s1(t,s,n){if(t.length===0||s.width<=0||s.height<=0)return{zoom:1,along:n==="land"?"row":"column"};const a=Math.max(...t.map(o=>o.h)),l=Math.max(...t.map(o=>o.w));return{zoom:n==="land"?Math.min(1,Math.max(Vi,(s.height-4)/(a+Ls.top+Ls.bottom))):Math.min(1,Math.max(Vi,(s.width-4)/(l+2*Ls.side))),along:n==="land"?"row":"column"}}const n1={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"};function Za(t){return t.state==="idle"&&(t.helpers??[]).some(s=>s.state!=="exited"&&s.state!=="idle")?"working":n1[t.state]}const tx=t=>t.state==="waiting_permission"||t.state==="waiting_input",sx=["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"],a1=["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"],l1=["M4 7h16v12H4z","M4 7l2-3h4l2 3","M9 13h6"],Un=t=>t.topic??t.title;function Rr({session:t,size:s,frozen:n}){const a=nn(),l=Za(t);return e.jsx(rl,{tool:t.tool,state:l,pose:ll(t.id,t.state),size:s,theme:a,seed:t.id,frozen:n,readOnly:!!t.readOnly})}function Gi({helper:t,parent:s,size:n,frozen:a}){const l=nn(),r=`${s.id}:${t.id}`,o=Yc(t);return e.jsx(rl,{tool:s.tool,state:o,pose:ll(r,o),size:n,theme:l,seed:r,frozen:a,readOnly:!!s.readOnly})}const nx=({state:t})=>e.jsx(Jj,{state:t}),ax=({color:t})=>t?e.jsx("i",{className:"side-swatch",style:{background:t}}):e.jsx("i",{className:"filter-none"}),r1={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 o1({seed:t,left:s,width:n,avoid:a}){return e.jsx("div",{className:"plants","aria-hidden":"true",style:{left:s,width:n},children:t1(t,a).map(({spot:l,species:r,flip:o})=>{const i=r1[r];return e.jsx("span",{className:`plant-spot spot-${l}${o?" flip":""}`,children:e.jsx(i,{})},l)})})}const Xi=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 i1({sheets:t,length:s}){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}),Xi(a.state)]}),a.note&&e.jsxs("div",{style:{left:op(a.x,t.filter(l=>l.slot===a.slot).map(l=>l.x),s)},className:`sheet-note note-${a.slot} sheet-${a.note.state}`,children:[e.jsx("p",{children:a.note.task}),Xi(a.note.state),a.note.more>0&&e.jsxs("em",{className:"note-more",children:["+",a.note.more]})]})]},a.id))})}function c1({table:t,project:s,color:n,frozen:a,act:l,helpers:r=!0}){const{length:o,width:i,seats:c,ends:x,notes:u,extra:m,extraCount:p}=rp(t.mains,r,aa,Is),h=b=>`calc(50% - ${o/2}px + ${b}px)`,g=ip(t.mains),y=c.map(({session:b,x:j,side:N})=>{const $=u.get(b.id);return{id:b.id,task:Un(b),state:Xo(Za(b)),slot:N,x:j,note:$&&{task:$.helper.task,state:Xo(Yc($.helper)),more:$.more}}}),k=[...m.mains.map(b=>({key:b.id,el:e.jsx(Rr,{session:b,size:18,frozen:a})})),...m.helpers.map(({helper:b,parent:j})=>({key:`${j.id}:${b.id}`,el:e.jsx(Gi,{helper:b,parent:j,size:18,frozen:a})}))].slice(0,3),S=[...p>0?["br"]:[],...x.some(b=>b.end==="left")?["ml"]:[],...x.some(b=>b.end==="right")?["mr"]:[]];return e.jsx("section",{className:"atelier-table","data-project":s.id,"data-table":t.key,"aria-label":d.atelier.table(s.name),style:{"--room":`${i}px`,"--project":n},children:e.jsxs("div",{className:"table-scene",children:[e.jsx("div",{className:"office-rug",style:{left:h(-Is),right:"auto",width:o+2*Is}}),e.jsxs("div",{className:"rug-labels",style:{left:h(-Is),width:o+2*Is},children:[e.jsxs("div",{className:"room-heading",children:[e.jsx(ax,{color:n}),e.jsxs("span",{className:"heading-names",children:[e.jsx("button",{type:"button",className:"project-conversations",title:s.name,"aria-label":d.atelier.conversations(s.name),onClick:()=>l.room(s.id),children:s.name}),g!==null&&e.jsxs("span",{className:"heading-branch",title:g,children:["⎇ ",g]})]}),e.jsx("span",{className:"spacer"}),e.jsx("span",{className:"room-menu-wrap",children:e.jsx("button",{type:"button",className:"icon-action","aria-label":d.atelier.roomMenu(s.name),onClick:()=>l.room(s.id),children:e.jsx(Nn,{d:[],fill:sx,size:14})})})]}),p>0&&e.jsxs("button",{type:"button",className:"table-more",onClick:()=>l.room(s.id),children:[e.jsx("span",{className:"more-faces","aria-hidden":"true",children:k.map(b=>e.jsx("i",{children:b.el},b.key))}),d.atelier.more(p)]})]}),e.jsx(o1,{seed:t.key,left:h(-Is),width:o+2*Is,avoid:S}),c.map(({session:b,x:j,side:N})=>e.jsx("div",{className:`office-chair chair-${N}`,"aria-hidden":"true",style:{left:h(j-27)}},b.id)),e.jsx("div",{className:"worktable","aria-hidden":"true",style:{left:h(0),right:"auto",width:o},children:e.jsx(i1,{length:o,sheets:y})}),c.map(({session:b,x:j,side:N})=>{var C;const $=Za(b);return e.jsxs("button",{type:"button",style:{left:h(j-56)},"data-agent":b.id,"aria-label":d.atelier.seat(b.name,Un(b)),onClick:()=>l.open(b.id),className:`agent-seat place-${N}${!a&&$==="working"?" seat-working":""}${a?" seat-offline":""}`,children:[e.jsx(Rr,{session:b,size:64,frozen:a}),e.jsx("strong",{children:e.jsx("span",{className:"seat-name",title:b.name,children:b.name})}),e.jsx("span",{className:"seat-machine",children:((C=b.rig)==null?void 0:C.role)??"local"}),e.jsx(nx,{state:$})]},b.id)}),x.map(({helper:b,parent:j,end:N,slot:$,count:C})=>e.jsxs("button",{type:"button",style:{left:h(N==="left"?-70:o+8),right:"auto",top:C>1?$?232:126:void 0},className:`agent-seat helper-seat end-${N}`,"aria-label":d.atelier.helperSeat(b.kind,j.name,b.task),title:b.task,onClick:()=>l.open(j.id),children:[e.jsx(Gi,{helper:b,parent:j,size:36,frozen:a}),e.jsx("strong",{children:b.kind}),e.jsxs("span",{className:"seat-meta",children:["↳ ",j.name]})]},`${j.id}:${b.id}`))]})})}function d1({project:t,tables:s,rig:n,width:a,act:l,children:r}){const o=s.flatMap(p=>p.mains),i=n?o.filter(p=>p.state!=="exited"):o,c=i.filter(tx).length,x=i.filter(p=>p.state==="working").length,u=(n==null?void 0:n.kind)==="kernel"?d.atelier.kernel:t.name,m=()=>l.room(t.id);return e.jsxs("section",{className:`project-room atelier-room${n?` rig-room ${n.kind}-room`:""}`,"data-room":t.id,"aria-label":n?d.atelier.rigRoom(n.kind,t.name):d.atelier.room(t.name),style:{"--room":`${a}px`,"--project":jn[t.color],"--room-side":`${Qc}px`,"--room-back":`${mp}px`,"--table-gap":`${Zc}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${n?" rig-plaque":""}`,children:[n?e.jsx("span",{className:"rig-hex","aria-hidden":"true",children:e.jsx(Nn,{d:a1,size:13})}):e.jsx(ax,{color:jn[t.color]}),e.jsx("strong",{className:"plaque-name",title:u,role:"button",tabIndex:0,"aria-label":d.atelier.roomMenu(u),onClick:m,onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),m())},children:u}),n?e.jsx("span",{className:"plaque-where",children:n.kind==="kernel"?d.atelier.kernelWhere:d.atelier.rigWhere(n.folder,n.project)}):e.jsx("span",{className:"plaque-counts",children:d.atelier.plaqueCounts(o.length)}),c>0&&e.jsxs("span",{className:"plaque-waiting",children:[e.jsx("i",{className:"approval-dot"}),d.atelier.waiting(c)]}),x>0&&e.jsxs("span",{className:"plaque-working",children:[e.jsx("i",{className:"live-dot"}),d.atelier.working(x)]}),!n&&e.jsx("span",{className:"room-menu-wrap",children:e.jsx("button",{type:"button",className:"icon-action","aria-label":d.atelier.roomMenu(u),onClick:m,children:e.jsx(Nn,{d:[],fill:sx,size:14})})})]}),e.jsx("div",{className:"room-tables",children:r}),e.jsx("span",{className:"room-entrance","aria-hidden":"true",children:d.atelier.entrance})]})}function u1({sessions:t,frozen:s,act:n}){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(Nn,{d:l1,size:15}),e.jsx("h2",{id:"unassigned-title",children:d.atelier.unassigned}),e.jsx("span",{className:"muted",children:d.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":d.atelier.seat(a.name,Un(a)),onClick:()=>n.open(a.id),children:[e.jsx(Rr,{session:a,size:56,frozen:s}),e.jsxs("span",{className:"unassigned-copy",children:[e.jsx("strong",{children:a.name}),e.jsx("span",{title:Un(a),children:Un(a)}),e.jsx("code",{children:a.project})]})]}),e.jsx("div",{className:"unassigned-actions",children:e.jsx(nx,{state:Za(a)})})]},a.id))})]})}function x1({count:t,frozen:s,onOpen:n}){const a=nn();return e.jsx("div",{className:"ledge-corner",children:e.jsxs("button",{type:"button",className:"ledge-desk",onClick:n,disabled:!n,"aria-label":d.atelier.desk,children:[e.jsx("span",{className:"ledge-bubble",children:d.atelier.watching(t)}),e.jsx("span",{className:"ledge-seat",children:e.jsx(Zr,{size:80,theme:a,frozen:s})}),e.jsx("strong",{children:"Ledge"}),e.jsx("small",{children:d.atelier.assistant})]})})}function m1(){const t=d.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 lx=.3,p1=2.5,f1=2.2,Ar=t=>Math.min(p1,Math.max(lx,t)),h1=(t,s)=>Ar(s>0?t*1.2:t/1.2);function g1(t,s,n){const a=(t.left+n.x)/t.zoom,l=(t.top+n.y)/t.zoom;return{left:a*s-n.x,top:l*s-n.y}}function b1(t,s){const n=Math.min(f1,Math.max(lx,Math.min(s.width*.92/t.w,s.height*.92/t.h)));return{zoom:n,left:(t.x+t.w/2)*n-s.width/2,top:(t.y+t.h/2)*n-s.height/2}}const j1=8,y1=320,N1=30,v1="button,a,[role=button],.unassigned-card",k1=".atelier-room,.unassigned-zone",w1=12;let ks={zoom:null,left:0,top:0};function S1(t){const s=f.useRef(null),n=f.useRef(null),[a,l]=f.useState(1),[r,o]=f.useState(ks.zoom),i=f.useRef(ks.zoom??1),c=f.useRef(ks.zoom),x=f.useRef({w:-1,h:-1}),u=f.useCallback(()=>{const b=s.current,j=n.current;if(!b||!j)return;const N=j.style;N.zoom="1";const $={width:b.clientWidth,height:b.clientHeight};x.current={w:b.offsetWidth,h:b.offsetHeight};const C=ex($);N.padding=`${Ls.top}px ${Ls.side}px ${Ls.bottom}px`,N.flexWrap="wrap",N.width="max-content",N.maxWidth="none",N.minHeight="",N.alignContent="flex-start",N.gap="0 8px";const M=j.querySelector(".ledge-corner");N.setProperty("--ledge-clear",`${M?Math.max(0,M.offsetTop+M.offsetHeight+w1-Ls.top):0}px`);const v=[...j.querySelectorAll(k1)].map(R=>({w:R.offsetWidth,h:R.offsetHeight})).filter(R=>R.w>0),{zoom:A,along:T}=s1(v,$,C);if(T==="row")N.flexWrap="nowrap",N.width="max-content",N.justifyContent="flex-start";else{const R=Math.max(0,...v.map(P=>P.w))+2*Ls.side;N.flexWrap="wrap",N.width=`${R}px`,N.maxWidth=`${R}px`,N.justifyContent="center"}v.length===0&&(N.width=`${$.width}px`,N.minHeight=`${$.height}px`),l(A),i.current=c.current??A,N.zoom=String(i.current)},[]);f.useLayoutEffect(()=>{u();const b=s.current;b&&(b.scrollLeft=ks.left,b.scrollTop=ks.top)},[u,...t]);const m=f.useRef(u);m.current=u,f.useEffect(()=>{var N,$;const b=s.current;if(!b||typeof ResizeObserver>"u")return;const j=new ResizeObserver(()=>{(b.offsetWidth!==x.current.w||b.offsetHeight!==x.current.h)&&m.current()});return j.observe(b),($=(N=globalThis.document)==null?void 0:N.fonts)==null||$.ready.then(()=>m.current()),()=>j.disconnect()},[]);const p=(b,j,N)=>{const $=s.current,C=n.current;i.current=b,c.current=b,o(b),ks.zoom=b,!(!$||!C)&&(C.style.zoom=String(b),$.scrollLeft=j,$.scrollTop=N)},h=b=>{const j=s.current,N=Ar(b);if(!j){p(N,0,0);return}const{left:$,top:C}=g1({zoom:i.current,left:j.scrollLeft,top:j.scrollTop},N,{x:j.clientWidth/2,y:j.clientHeight/2});p(N,$,C)},g=b=>h(h1(i.current,b)),y=()=>{c.current=null,o(null),ks.zoom=null,u();const b=s.current;b&&(b.scrollLeft=0,b.scrollTop=0)},k=b=>{const j=s.current;if(!j)return;const N=i.current,$=j.getBoundingClientRect(),C=b.getBoundingClientRect(),M={x:(j.scrollLeft+C.left-$.left)/N,y:(j.scrollTop+C.top-$.top)/N,w:C.width/N,h:C.height/N};if(M.w<=0||M.h<=0)return;const{zoom:v,left:A,top:T}=b1(M,{width:j.clientWidth,height:j.clientHeight});p(v,A,T)},S=f.useRef({setZoom:p,fit:y,frame:k});return S.current={setZoom:p,fit:y,frame:k},f.useEffect(()=>{const b=s.current;if(!b)return;const j=new Map;let N=null,$=null,C=null,M=!1;const v=(E,z)=>({x:(E.x+z.x)/2,y:(E.y+z.y)/2,d:Math.hypot(E.x-z.x,E.y-z.y)}),A=()=>{const[E,z]=[...j.values()];if(N=null,$=null,E&&z){const K=v(E,z),L=b.getBoundingClientRect(),W=i.current;N={d:Math.max(K.d,1),zoom:W,x:(b.scrollLeft+K.x-L.left)/W,y:(b.scrollTop+K.y-L.top)/W}}else E&&($={x:E.x,y:E.y,left:b.scrollLeft,top:b.scrollTop,moved:!1})},T=E=>{E.pointerType!=="mouse"&&(j.size===0&&(M=!1),j.set(E.pointerId,{x:E.clientX,y:E.clientY}),A())},R=E=>{if(!j.has(E.pointerId))return;j.set(E.pointerId,{x:E.clientX,y:E.clientY});const[z,K]=[...j.values()];if(N&&z&&K){const L=v(z,K),W=b.getBoundingClientRect(),ae=Ar(N.zoom*L.d/N.d);S.current.setZoom(ae,N.x*ae-(L.x-W.left),N.y*ae-(L.y-W.top))}else if($){const L=E.clientX-$.x,W=E.clientY-$.y;if(!$.moved&&Math.hypot(L,W)<j1)return;$.moved=!0,b.scrollLeft=$.left-L,b.scrollTop=$.top-W}},P=E=>{if(!j.has(E.pointerId))return;($!=null&&$.moved||N)&&(M=!0);const z=j.size===1&&$!==null&&!$.moved;if(j.delete(E.pointerId),A(),!z||E.type==="pointercancel")return;const K=E.target instanceof Element?E.target:null,L=E.timeStamp;if(C&&L-C.at<y1&&Math.hypot(E.clientX-C.x,E.clientY-C.y)<N1&&!(K!=null&&K.closest(v1))){C=null;const W=K==null?void 0:K.closest(".atelier-room");W?S.current.frame(W):S.current.fit();return}C={at:L,x:E.clientX,y:E.clientY}},_=E=>{M&&(M=!1,E.preventDefault(),E.stopPropagation())},D=()=>{ks.left=b.scrollLeft,ks.top=b.scrollTop};return b.addEventListener("pointerdown",T),b.addEventListener("pointermove",R),b.addEventListener("pointerup",P),b.addEventListener("pointercancel",P),b.addEventListener("click",_,!0),b.addEventListener("scroll",D,{passive:!0}),()=>{b.removeEventListener("pointerdown",T),b.removeEventListener("pointermove",R),b.removeEventListener("pointerup",P),b.removeEventListener("pointercancel",P),b.removeEventListener("click",_,!0),b.removeEventListener("scroll",D)}},[]),{scrollRef:s,shellRef:n,zoom:r??a,fitted:r===null,zoomTo:h,step:g,fit:y}}const $1=["M15 3h6v6","M9 21H3v-6","M21 3l-7 7","M3 21l7-7"],C1=80;function rx({label:t,onClose:s,children:n}){const a=f.useRef(null),l=f.useRef(null),[r,o]=f.useState(0),i=u=>{var p,h;const m=u.target;!m.closest(".atelier-panel-grab, .atelier-panel > header, .atelier-panel header")||m.closest("button,a,textarea,input")||(l.current={x:u.clientX,y:u.clientY,id:u.pointerId,land:ex({width:globalThis.innerWidth,height:globalThis.innerHeight})==="land"},(h=(p=a.current)==null?void 0:p.setPointerCapture)==null||h.call(p,u.pointerId))},c=u=>{const m=l.current;!m||m.id!==u.pointerId||o(Math.max(0,m.land?u.clientX-m.x:u.clientY-m.y))},x=u=>{const m=l.current;if(!m||m.id!==u.pointerId)return;l.current=null;const p=m.land?u.clientX-m.x:u.clientY-m.y;o(0),p>C1&&s()};return e.jsxs("aside",{ref:a,className:"atelier-panel","aria-label":t,onPointerDown:i,onPointerMove:c,onPointerUp:x,onPointerCancel:x,style:r?{"--pull":`${r}px`}:void 0,children:[e.jsx("div",{className:"atelier-panel-grab","aria-hidden":"true"}),n]})}function M1({store:t,name:s,ids:n,onOpen:a,onClose:l}){var x;const r=me(t),o=!r.fresh,i=n.map(u=>r.sessions.get(u)).filter(u=>u!==void 0),c=i.filter(u=>u.state!=="exited").map(u=>u.id);return e.jsxs(rx,{label:d.atelier.room(s),onClose:l,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:s}),e.jsx("p",{className:"mt-[3px] text-meta text-muted",children:d.atelier.roomAgents(i.length)})]}),e.jsx("button",{type:"button",onClick:l,"aria-label":d.atelier.closePanel,title:d.atelier.closeTitle,className:Tt({}),children:e.jsx(q,{name:"close"})})]}),e.jsxs("main",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:[i.map(u=>{var m;return e.jsxs("button",{type:"button",onClick:()=>a(u.id),className:"flex w-full items-center gap-3 border-b border-line py-3 text-left active:bg-raised/60",children:[e.jsx(ol,{tool:u.tool,seed:u.id,state:u.state,frozen:o}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-body font-semibold",children:u.name}),e.jsx("span",{className:"block truncate text-meta text-muted",children:((m=u.rig)==null?void 0:m.role)??u.topic??u.branch??u.title})]}),e.jsx(ra,{...Ap(u)})]},u.id)}),((x=r.daemon)==null?void 0:x.broadcast)&&c.length>0&&e.jsx("div",{className:"pt-4",children:c.length>Pa?e.jsx("p",{className:"text-meta text-attention",children:d.agents.tooMany(c.length,Pa)}):e.jsx(ad,{store:t,label:s,ids:c,offline:o})})]})]})}function E1(t,s){var a;const n=t.rooms.find(l=>l.project.id===s);return n?{name:((a=n.rig)==null?void 0:a.kind)==="kernel"?d.atelier.kernel:n.project.name,ids:n.tables.flatMap(l=>l.mains.map(r=>r.id))}:null}const Yi=`${Cs}sessions.helpers`,Qi=`${Cs}sessions.groupBy`;function R1({store:t,sessionId:s,requestKey:n,storage:a,onReconnect:l}){var D;const r=me(t),o=!r.fresh,i=f.useMemo(()=>[...r.sessions.values()],[r.sessions]),c=f.useMemo(()=>i.map(E=>({...E,cwd:E.project})),[i]),x=f.useMemo(()=>dp(c,r.projects,E=>E.projectId??null,"all",!0,({id:E,name:z,kind:K})=>({id:E,name:z,color:xp(K)})),[c,r.projects]),[u,m]=f.useState(null),[p,h]=f.useState(()=>{var E;try{return((E=Qe(a))==null?void 0:E.getItem(Yi))!=="hidden"}catch{return!0}}),[g,y]=f.useState(()=>{var E;try{return((E=Qe(a))==null?void 0:E.getItem(Qi))==="rigs"?"rigs":"projects"}catch{return"projects"}}),k=E=>{var z;y(E);try{(z=Qe(a))==null||z.setItem(Qi,E)}catch{}},S=()=>{var z;const E=!p;h(E);try{(z=Qe(a))==null||z.setItem(Yi,E?"shown":"hidden")}catch{}},b=S1([x,o]),j=E=>{m(null),s?fs({name:"atelier",sessionId:E}):tn({name:"atelier",sessionId:E})},N=()=>fs({name:"atelier"}),$={open:j,room:E=>{s&&N(),m(E)},chat:()=>tn({name:"chat"})},C=i.filter(E=>E.state!=="exited").length,M=i.filter(tx).length,v=`${o?`${d.agents.offline} · `:""}${d.atelier.subtitle(C,M,ed(i).working)}`,A=u?E1(x,u):null,T=x.rooms.filter(E=>!E.rig),R=x.rooms.filter(E=>E.rig),P=g==="rigs"?[...R,...T]:[...T,...R],_=s?r.sessions.get(s):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:d.atelier.title}),e.jsx("span",{className:"min-w-0 truncate text-meta text-muted",children:v}),e.jsx("span",{className:"flex-1"}),e.jsx("div",{role:"group","aria-label":d.sessions.groupBy.label,className:"flex flex-none overflow-hidden rounded-lg border border-input",children:Gr.map(E=>e.jsx("button",{type:"button","aria-pressed":E===g,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:d.sessions.groupBy[E]},E))}),e.jsxs("button",{type:"button","aria-pressed":!p,onClick:S,className:Fe({size:"sm",className:"flex-none"}),children:[e.jsx(q,{name:"eye",className:"size-4"}),p?d.sessions.helpersHide:d.sessions.helpersShow]}),e.jsx(cl,{})]}),e.jsx("div",{className:"mb-3 flex-none empty:hidden",children:e.jsx(js,{})}),e.jsxs("div",{className:`atelier-ipad${o?" atelier-frozen":""}`,children:[e.jsxs("div",{className:"zoom-controls",role:"toolbar","aria-label":d.atelier.zoom.bar,children:[e.jsx("button",{type:"button",className:"ledge-btn","data-variant":"ghost","aria-label":d.atelier.zoom.out,onClick:()=>b.step(-1),children:"−"}),e.jsx("button",{type:"button",className:"zoom-level","aria-label":d.atelier.zoom.reset,onClick:()=>b.zoomTo(1),children:d.percent(Math.round(b.zoom*100))}),e.jsx("button",{type:"button",className:"ledge-btn","data-variant":"ghost","aria-label":d.atelier.zoom.in,onClick:()=>b.step(1),children:"+"}),e.jsx("span",{className:"zoom-sep"}),e.jsxs("button",{type:"button",className:"ledge-btn zoom-fit","data-variant":b.fitted?"secondary":"ghost","aria-pressed":b.fitted,title:d.atelier.zoom.fitTitle,onClick:b.fit,children:[e.jsx(Nn,{d:$1,size:13}),d.atelier.zoom.fit]})]}),e.jsxs("div",{className:"overview-scroll atelier",role:"region","aria-label":d.atelier.region,ref:b.scrollRef,children:[e.jsx("div",{className:"atelier-floor",children:e.jsxs("div",{ref:b.shellRef,className:`office-shell${o?" office-paused":""}`,children:[e.jsx(x1,{count:C,frozen:o,...(D=r.device)!=null&&D.chat?{onOpen:$.chat}:{}}),e.jsx("div",{className:`project-grid ${P.length===1?"focused":""}`,children:P.map(({project:E,tables:z,rig:K})=>e.jsx(d1,{project:E,tables:z,...K?{rig:K}:{},width:pp(z,aa,Is),act:$,children:z.map(L=>e.jsx(c1,{table:L,project:E,color:jn[E.color],frozen:o,act:$,helpers:p},L.key))},E.id))}),e.jsx(u1,{sessions:x.unassigned,frozen:o,act:$})]})}),e.jsx(m1,{})]})]})]}),s&&e.jsx(rx,{label:d.atelier.session((_==null?void 0:_.name)??""),onClose:N,children:n?e.jsx(vr,{store:t,sessionId:s,requestKey:n,onReconnect:l,panel:{onBack:()=>fs({name:"atelier",sessionId:s}),onClose:N}},`${s}:request`):e.jsx(Er,{store:t,sessionId:s,storage:a,onReconnect:l,panel:{onClose:N}},s)}),!s&&A&&u&&e.jsx(M1,{store:t,name:A.name,ids:A.ids,onOpen:j,onClose:()=>m(null)})]})}const ox=500,Tr=10;function ix(t){const s=f.useRef(null),n=f.useRef(null),a=f.useRef(!1),l=()=>{s.current&&clearTimeout(s.current),s.current=null},r=()=>{var o;l(),a.current=!0;try{(o=navigator.vibrate)==null||o.call(navigator,10)}catch{}t()};return{onPointerDown:o=>{o.button>0||(a.current=!1,n.current={x:o.clientX,y:o.clientY},l(),s.current=setTimeout(r,ox))},onPointerMove:o=>{const i=n.current;i&&Math.hypot(o.clientX-i.x,o.clientY-i.y)>Tr&&l()},onPointerUp:l,onPointerCancel:l,onPointerLeave:l,onContextMenu:o=>{o.preventDefault(),a.current||r()},onClickCapture:o=>{a.current&&(o.preventDefault(),o.stopPropagation(),a.current=!1)}}}function cx(t){const s=f.useRef(t);s.current=t;const n=f.useRef(null),a=f.useRef(null),l=f.useRef("idle"),r=f.useRef(!1),o=f.useRef(null),i=()=>{n.current&&clearTimeout(n.current),n.current=null},c=()=>{var m;i(),(m=o.current)==null||m.call(o),o.current=null,l.current="idle"};f.useEffect(()=>()=>c(),[]);const x=()=>{const m=y=>{(l.current==="lifted"||l.current==="dragging")&&y.preventDefault()},p=y=>{var S,b;const k=a.current;k&&(l.current==="lifted"&&Math.hypot(y.clientX-k.x,y.clientY-k.y)>Tr&&(l.current="dragging"),l.current==="dragging"&&((b=(S=s.current).onDrag)==null||b.call(S,y.clientY)))},h=()=>{var k,S;const y=l.current;c(),y==="dragging"?(S=(k=s.current).onDrop)==null||S.call(k):y==="lifted"&&s.current.onLong()},g=()=>{var k,S;const y=l.current;c(),(y==="dragging"||y==="lifted")&&((S=(k=s.current).onCancel)==null||S.call(k))};document.addEventListener("touchmove",m,{passive:!1}),window.addEventListener("pointermove",p),window.addEventListener("pointerup",h),window.addEventListener("pointercancel",g),o.current=()=>{document.removeEventListener("touchmove",m),window.removeEventListener("pointermove",p),window.removeEventListener("pointerup",h),window.removeEventListener("pointercancel",g)}},u=()=>{var m,p,h,g;i(),r.current=!0,l.current="lifted";try{(m=navigator.vibrate)==null||m.call(navigator,10)}catch{}(g=(h=s.current).onLift)==null||g.call(h,((p=a.current)==null?void 0:p.y)??0),x()};return{onPointerDown:m=>{m.button>0||(r.current=!1,a.current={x:m.clientX,y:m.clientY},i(),l.current="pressing",n.current=setTimeout(u,ox))},onPointerMove:m=>{const p=a.current;l.current==="pressing"&&p&&Math.hypot(m.clientX-p.x,m.clientY-p.y)>Tr&&(i(),l.current="idle")},onPointerUp:()=>{l.current==="pressing"&&(i(),l.current="idle")},onPointerCancel:()=>{l.current==="pressing"&&(i(),l.current="idle")},onDragStart:m=>{m.preventDefault()},onContextMenu:m=>{m.preventDefault(),!r.current&&l.current!=="lifted"&&l.current!=="dragging"&&(i(),l.current="idle",r.current=!0,s.current.onLong())},onClickCapture:m=>{r.current&&(m.preventDefault(),m.stopPropagation(),r.current=!1)}}}function dx({store:t,session:s,current:n,onLeave:a,onReconnect:l,display:r,model:o,onModel:i}){var v,A;const c=me(t),x=Xt(),[u,m]=f.useState(!1),[p,h]=f.useState(!1),g=o??p,y=i??h,[k,S]=f.useState(!1),b=Sn(s),j=It(),N=il(),$=n==="terminal"&&j&&!N&&[s.project,s.branch].filter(Boolean).join(" · ")||void 0,C=!!((v=c.daemon)!=null&&v.sessionClose)&&!s.readOnly,M=Wr(s,c.ops,((A=c.daemon)==null?void 0:A.boot)??null,x);return e.jsxs(e.Fragment,{children:[e.jsx(la,{back:e.jsx(is,{fallback:{name:"sessions"},label:d.thread.back}),tool:s.tool,name:s.name,dot:b,pulse:b==="work"&&c.fresh,sub:$,more:e.jsxs(e.Fragment,{children:[e.jsx(Zu,{sessionId:s.id,current:n,...a?{onLeave:a}:{}}),e.jsx("button",{type:"button","aria-haspopup":"dialog","aria-label":d.sessions.moreOf(s.name),title:d.sessions.more,onClick:()=>m(!0),className:Tt({className:u?"bg-raised text-fg":"text-muted"}),children:e.jsx(q,{name:"more"})})]})}),u&&e.jsx(jo,{store:t,session:s,closable:C,closing:M,onClose:()=>m(!1),onModel:()=>{m(!1),y(!0)},onCloseSession:()=>{m(!1),S(!0)},display:r&&{value:r.value,onToggle:()=>{r.onToggle(),m(!1)}}}),g&&sn(c.daemon,s)&&e.jsx(gl,{store:t,session:s,onClose:()=>y(!1)}),k&&e.jsx(So,{store:t,session:s,mode:"close",onClose:()=>S(!1),onSent:()=>S(!1),onReconnect:l})]})}function A1({store:t,session:s,onDone:n,order:a}){var p,h;const l=me(t),r=Xt(),[o,i]=f.useState("menu"),c=!!((p=l.daemon)!=null&&p.sessionClose)&&!s.readOnly,x=Wr(s,l.ops,((h=l.daemon)==null?void 0:h.boot)??null,r),u=s.rig?d.sessions.seatOf(s.rig.role??s.name,s.rig.name):s.project,m=g=>{n(),tn(g)};return o==="model"?sn(l.daemon,s)?e.jsx(gl,{store:t,session:s,onClose:n}):null:o==="close"?e.jsx(So,{store:t,session:s,mode:"close",onClose:n,onSent:n}):e.jsx(jo,{store:t,session:s,closable:c,closing:x,onClose:n,who:u,onModel:()=>i("model"),onCloseSession:()=>i("close"),...a?{order:[{icon:"arrowUp",label:d.sessions.reorder.up,onClick:a.up?()=>{a.up(),n()}:void 0},{icon:"arrowDown",label:d.sessions.reorder.down,onClick:a.down?()=>{a.down(),n()}:void 0}]}:{},lead:[{icon:"sessions",label:d.atoi.openThread,onClick:()=>m({name:"thread",sessionId:s.id})},{icon:"terminal",label:d.thread.terminal(s.name),onClick:()=>m({name:"terminal",sessionId:s.id})}]})}function T1({by:t,onBy:s,helpers:n,onHelpers:a}){const l=d.sessions.groupBy;return e.jsxs("div",{className:"flex flex-none items-center gap-2",children:[e.jsx("div",{role:"group","aria-label":l.label,className:"grid flex-1 grid-cols-2 gap-[3px] rounded-[10px] border border-line p-[3px]",children:Gr.map(r=>e.jsx("button",{type:"button","aria-pressed":r===t,onClick:()=>s(r),className:"h-[34px] rounded-[7px] text-[13px] font-medium whitespace-nowrap text-muted aria-pressed:bg-raised aria-pressed:text-fg",children:l[r]},r))}),e.jsx("button",{type:"button",onClick:a,"aria-label":n?d.sessions.helpersHide:d.sessions.helpersShow,title:n?d.sessions.helpersHide:d.sessions.helpersShow,className:`grid size-[42px] flex-none place-items-center rounded-control border ${n?"border-input text-fg":"border-ring text-fg"}`,children:e.jsx(q,{name:"eye",className:"size-[18px]"})})]})}const Zi="inline-flex items-center gap-1.5 rounded-lg border bg-bg px-2.5 select-none [-webkit-touch-callout:none]";function _1({session:t,rig:s,helpers:n,pressed:a,onPress:l}){const r=ix(()=>l(t)),o=Sn(t),i=o==="perm"?"border-destructive/50":o==="ask"?"border-attention/50":"border-line",c=ne({name:"thread",sessionId:t.id}),x=d.atelier.session(t.name);return e.jsxs(e.Fragment,{children:[e.jsxs("a",{href:c,"aria-label":x,...r,className:`${Zi} h-10 text-[13px] font-medium ${i} ${t.state==="exited"?"opacity-60":""} ${a?"shadow-[0_0_0_2px_var(--color-ring)]":""}`,children:[!s&&e.jsx(gs,{tool:t.tool}),t.name,e.jsx(Ie,{state:o}),!n&&t.helpers.length>0&&e.jsx("span",{"aria-label":d.sessions.kidsLabel(t.helpers.length),className:"ml-0.5 rounded-lg border border-input px-1.5 font-mono text-[11px] leading-[18px] text-muted",children:d.sessions.kids(t.helpers.length)})]}),n&&t.helpers.map(u=>e.jsxs("a",{href:c,"aria-label":d.atelier.helperSeat(u.kind,t.name,u.task),...r,className:`${Zi} h-8 border-dashed border-line text-[12px] text-muted`,children:[u.kind,e.jsx(Ie,{state:gp(u)})]},u.id))]})}function I1({island:t,rigs:s,helpers:n,pressed:a,onPress:l}){const r=d.sessions,o=t.kind==="rig",i=hp(t),c=o?t.name==="kernel"&&s?r.kernelTag:r.rigTag:null,x=o?r.seats(t.sessions.length):d.atelier.plaqueCounts(t.sessions.length);return e.jsxs("section",{"aria-label":o?r.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(Ie,{state:"rig"}),e.jsx("b",{className:"font-semibold",children:t.name}),i&&e.jsx(Ie,{state:i}),c?e.jsx("small",{className:"text-[12px] text-muted",children:c}):e.jsx("small",{className:"text-[12px] text-muted",children:x}),o&&c===r.rigTag&&(s?e.jsx("a",{href:ne({name:"rigs"}),className:"ml-auto text-[12px] text-muted underline underline-offset-2",children:x}):e.jsx("span",{className:"ml-auto text-[12px] text-muted",children:x}))]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:t.sessions.map(u=>e.jsx(_1,{session:u,rig:o,helpers:n,pressed:a===u.id,onPress:l},u.id))})]})}function L1({sessions:t,by:s,onBy:n,helpers:a,onHelpers:l,rigs:r,pressed:o,onPress:i}){const c=nn(),x=t.filter(p=>p.state!=="exited").length,u=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"grid size-[30px] flex-none place-items-center overflow-hidden",children:e.jsx(Zr,{size:30,theme:c,frozen:!0})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("b",{className:"font-semibold",children:d.sessions.deskTitle}),e.jsxs("small",{className:"text-[12px] text-muted",children:[d.atelier.desk," · ",d.atelier.watching(x)]})]})]});return e.jsxs(e.Fragment,{children:[e.jsx(T1,{by:s,onBy:n,helpers:a,onHelpers:l}),fp(t,s).map(p=>e.jsx(I1,{island:p,rigs:r,helpers:a,pressed:o,onPress:i},p.id)),e.jsxs("a",{href:ne({name:"chat"}),className:"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)]",children:[u,e.jsx(q,{name:"chevron",className:"size-4 text-muted"})]})]})}const Ji=`${Cs}sessions.filter`,O1=t=>Jc.includes(t);function D1(t,s){const n=Qe(s),[a,l]=f.useState(()=>{if(t)return t;try{const o=n==null?void 0:n.getItem(Ji);return O1(o)?o:"all"}catch{return"all"}}),r=o=>{l(o);try{n==null||n.setItem(Ji,o)}catch{}};return f.useEffect(()=>{t&&r(t)},[t]),[a,r]}function Wl(t,s,n,a){const l=Qe(a),[r,o]=f.useState(()=>{try{const c=l==null?void 0:l.getItem(`${Cs}${t}`);return s.includes(c)?c:n}catch{return n}});return[r,c=>{o(c);try{l==null||l.setItem(`${Cs}${t}`,c)}catch{}}]}const ux=["list","atelier"];function F1({value:t,onChange:s}){const n=d.sessions.mode;return e.jsx("div",{role:"group","aria-label":n.label,className:"flex flex-none overflow-hidden rounded-lg border border-input",children:ux.map(a=>e.jsx("button",{type:"button","aria-pressed":a===t,onClick:()=>s(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:n[a]},a))})}function z1({value:t,counts:s,onChange:n}){const a=d.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:Jc.map(l=>e.jsxs("button",{type:"button","aria-pressed":l===t,onClick:()=>n(l),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[l],e.jsx("span",{className:"font-mono text-meta",children:s[l]})]},l))})}function P1({session:t,filter:s,offline:n,threshold:a,now:l,closing:r,pressed:o,onPress:i,woken:c,drag:x}){const u=na(),m=ix(()=>i(t)),p=cx({onLong:()=>i(t),onLift:j=>x==null?void 0:x.onLift(j),onDrag:j=>x==null?void 0:x.onDrag(j),onDrop:()=>x==null?void 0:x.onDrop(),onCancel:()=>x==null?void 0:x.onCancel()}),h={...x?p:m,"data-reorder-row":t.id,...(x==null?void 0:x.lifted)!==null&&(x==null?void 0:x.lifted)!==void 0?{style:xx(x.lifted)}:{}},g=(u.name==="thread"||u.name==="terminal")&&u.sessionId===t.id,y=Sn(t),k=bp(t),S=td(t),b=s==="working"?S===void 0?void 0:`${S} %`:yp(t);return e.jsx(Zs,{href:ne({name:"thread",sessionId:t.id}),selected:g,stale:n,press:h,pressed:o,lead:e.jsxs(e.Fragment,{children:[e.jsx(Ie,{state:y,pulse:y==="work"&&!n}),e.jsx(gs,{tool:t.tool})]}),title:e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:t.name}),c&&e.jsx("span",{"data-woken":"",className:"ml-1 inline-flex align-[-2px] text-muted",children:e.jsx(q,{name:"clock",className:"size-[13px]"})}),k>0&&e.jsx("span",{"aria-label":d.sessions.kidsLabel(k),className:"ml-1.5 font-mono text-small text-muted",children:d.sessions.kids(k)})]}),sub:r?e.jsx("span",{className:"text-attention",children:d.chat.closing}):e.jsx("span",{className:y==="ask"?"text-attention":void 0,children:jp(t,s,l)}),...y==="perm"?{subTone:"perm"}:{},...b!==void 0?{meta:b,metaWarn:s==="working"&&S!==void 0&&S/100>=a}:{}})}const xx=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"}),va=()=>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 B1({group:t,children:s,drag:n}){const a=t.kind==="rig",l=a?d.sessions.rigGroup(t.name):t.name,r=cx({onLong:()=>n==null?void 0:n.onLong(),onLift:o=>n==null?void 0:n.onLift(o),onDrag:o=>n==null?void 0:n.onDrag(o),onDrop:()=>n==null?void 0:n.onDrop(),onCancel:()=>n==null?void 0:n.onCancel()});return e.jsxs("section",{"aria-label":l,"data-reorder-section":t.id,className:"flex flex-col gap-1.5",style:n&&n.lifted!==null?xx(n.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",...n?r:{},children:[a&&e.jsx(Ie,{state:"rig"}),l,e.jsx("span",{className:"font-normal",children:t.sessions.length})]}),e.jsx(os,{...a?{tone:"rigs"}:{},children:s})]})}function q1({routines:t,now:s,offline:n}){const a=d.routines,l=eh(t,s);return l.count===0?null:e.jsx(os,{label:a.entry,children:e.jsxs(Zs,{href:ne({name:"routines"}),stale:n,lead:e.jsx(q,{name:"alarm",className:"size-5"}),title:e.jsx("b",{className:"font-semibold",children:a.entry}),...l.next?{sub:a.entrySub(l.count,l.next)}:{},children:[l.flagged>0&&e.jsx(zt,{tone:"perm",children:String(l.flagged)}),e.jsx(q,{name:"chevron",className:"size-4 text-muted"})]})})}function H1({store:t,filter:s,storage:n}){var E,z,K;const a=me(t),l=Xt(),[r,o]=D1(s,n),i=It(),[c,x]=Wl("sessions.mode",ux,"list",n),[u,m]=Wl("sessions.groupBy",Gr,"projects",n),[p,h]=Wl("sessions.helpers",["shown","hidden"],"shown",n),[g,y]=f.useState(null),k=g?a.sessions.get(g):void 0,S=!i&&c==="atelier",b=[...a.sessions.values()],j=ed(b),N=!a.fresh,$=(E=a.daemon)!=null&&E.sessionOrder&&a.daemon.atelier?{projects:a.projects,order:a.sessionOrder??{}}:null,C=Vr(b,r,$),M=U1(t,b,$,N),v=th(a.routines,b),A=((z=a.device)==null?void 0:z.contextNear)??kn,T=N?a.syncedAt?d.link.lastKnownAt(Be(a.syncedAt)):d.agents.offline:void 0,R=e.jsxs("a",{href:ne({name:"launch"}),className:Fe({variant:"primary",size:"sm",className:"flex-none"}),children:[e.jsx(q,{name:"plus",className:"size-4"}),d.sessions.new]}),P=(L,W)=>e.jsx("button",{type:"button",onClick:()=>o(L),className:Fe({size:"xs"}),children:W}),_=d.sessions,D=C.length===0&&b.length>0&&e.jsx(os,{label:_.filter[r],children:r==="waiting"?e.jsx(Jt,{framed:!1,glyph:null,title:_.filterEmpty,body:_.filterEmptyBody(j.working),action:P("all",_.seeAll)}):j.waiting>0?e.jsx(Jt,{framed:!1,glyph:null,title:_.emptyWorking.title,body:_.emptyWorking.waiting(j.waiting),action:P("waiting",_.seeWaiting)}):e.jsx(Jt,{framed:!1,glyph:null,title:_.emptyWorking.title,body:_.emptyWorking.idle,action:P("all",_.seeAll)})});return e.jsxs(Rs,{title:d.agents.title,subtitle:T,bodyClassName:"flex flex-col gap-2.5",actions:i?void 0:e.jsxs(e.Fragment,{children:[e.jsx(F1,{value:c,onChange:x}),R]}),wideActions:i?R:void 0,children:[k&&e.jsx(A1,{store:t,session:k,onDone:()=>y(null),...M.can?{order:M.stepsOf(C,k.id)}:{}}),M.sheet&&e.jsx(xb,{name:M.sheet.name,up:M.projectStep(C,M.sheet,-1),down:M.projectStep(C,M.sheet,1),onClose:()=>M.setSheet(null)}),e.jsx("div",{className:"sr-only","aria-live":"polite","aria-atomic":"true","data-reorder-said":"",children:M.said}),M.problem&&e.jsx("p",{role:"alert",className:"rounded-lg border border-destructive/40 px-3 py-2 text-small text-danger-fg",children:M.problem}),a.routines&&e.jsx(q1,{routines:a.routines,now:l,offline:N}),b.length===0?e.jsx(os,{label:d.agents.empty,children:e.jsx(Jt,{list:!0,glyph:e.jsx(q,{name:"sessions"}),title:d.agents.empty,body:d.agents.emptyHint,action:e.jsxs("a",{href:ne({name:"launch"}),className:Fe({variant:"primary",size:"sm"}),children:[e.jsx(q,{name:"plus",className:"size-4"}),d.sessions.newSession]})})}):S?e.jsx(L1,{sessions:b,by:u,onBy:m,helpers:p==="shown",onHelpers:()=>h(p==="shown"?"hidden":"shown"),rigs:!!((K=a.daemon)!=null&&K.rigs),pressed:g,onPress:L=>y(L.id)}):e.jsxs(e.Fragment,{children:[e.jsx(z1,{value:r,counts:j,onChange:o}),C.map((L,W)=>{const ae=M.can&&L.kind==="project",U=M.lift,O=U&&U.kind==="session"&&U.gid===L.id?U:null,B=O&&O.to!==O.from?O.to<O.from?O.to:O.to+1:-1,Z=U&&U.kind==="project"&&U.to!==U.from&&(U.to<U.from?U.to:U.to+1)===W;return e.jsxs("div",{className:"contents",children:[Z&&e.jsx(va,{}),e.jsxs(B1,{group:L,...ae&&L.project?{drag:M.projectDrag(C,L)}:{},children:[L.sessions.flatMap((H,X)=>[...X===B?[e.jsx(va,{},"line")]:[],e.jsx(P1,{session:H,filter:r,offline:N,threshold:A,now:l,closing:Qm(H,a.ops,l),pressed:g===H.id,onPress:te=>y(te.id),woken:v.has(H.id),...ae?{drag:M.rowDrag(L,X)}:{}},H.id)]),B===L.sessions.length&&e.jsx(va,{})]}),U&&U.kind==="project"&&U.to!==U.from&&U.to>U.from&&U.to===W&&W===C.filter(H=>H.kind==="project"&&H.project).length-1&&e.jsx(va,{})]},L.id)}),D]})]})}const ec=(t,s,n)=>t.filter((a,l)=>l!==s&&a<n).length,tc=(t,s,n)=>{const a=[...t],[l]=a.splice(s,1);return a.splice(n,0,l),a};function U1(t,s,n,a){const l=d.sessions.reorder,r=me(t),[o,i]=f.useState(null),[c,x]=f.useState(""),[u,m]=f.useState(null),[p,h]=f.useState(null),g=!!n&&!a,y=(N,$)=>N.status==="applied"?null:N.status==="rejected"&&N.reason==="unavailable"?l.outdated($):N.status==="rejected"?l.stale($):l.offline($),k=(N,$,C)=>{var R;if($===C||C<0||C>=N.sessions.length)return;const M=N.sessions[$],v=tc(N.sessions,$,C),A=((R=Vr(s,"all",n).find(P=>P.id===N.id))==null?void 0:R.sessions)??N.sessions,T=pm(A.map(P=>P.id),v.map(P=>P.id));m(null),t.orderSessions(N.project??null,T).then(P=>{const _=y(P,M.name);_?m(_):x(l.moved(M.name,l.ordinal(C+1,!0),v.length,N.name))})},S=()=>((n==null?void 0:n.projects)??[]).map(N=>N.id),b=(N,$)=>{const C=S(),M=C.indexOf(N.project??"");M<0||M===$||$<0||$>=C.length||(m(null),t.orderProjects(tc(C,M,$)).then(v=>{const A=y(v,N.name);A?m(A):x(l.movedProject(N.name,l.ordinal($+1,!1),C.length))}))},j=N=>[...document.querySelectorAll(N)].map($=>{const C=$.getBoundingClientRect();return C.top+C.height/2});return{can:g,said:c,problem:u,lift:o,sheet:p,setSheet:h,rowDrag:(N,$)=>({lifted:o&&o.kind==="session"&&o.gid===N.id&&o.from===$?o.dy:null,onLift:C=>i({kind:"session",gid:N.id,from:$,to:$,y0:C,dy:0,mids:j(`[data-reorder-section="${CSS.escape(N.id)}"] [data-reorder-row]`)}),onDrag:C=>i(M=>M&&{...M,dy:C-M.y0,to:ec(M.mids,M.from,C)}),onDrop:()=>{const C=o;i(null),C&&k(N,C.from,C.to)},onCancel:()=>i(null)}),projectDrag:(N,$)=>{const C=N.filter(v=>v.kind==="project"&&v.project),M=C.indexOf($);return{lifted:o&&o.kind==="project"&&o.gid===$.id?o.dy:null,onLong:()=>h($),onLift:v=>i({kind:"project",gid:$.id,from:M,to:M,y0:v,dy:0,mids:C.map(A=>j(`[data-reorder-section="${CSS.escape(A.id)}"]`)[0]??0)}),onDrag:v=>i(A=>A&&{...A,dy:v-A.y0,to:ec(A.mids,A.from,v)}),onDrop:()=>{const v=o;if(i(null),!v||v.to===v.from)return;const A=C[v.to],T=A?S().indexOf(A.project):-1;T>=0&&b($,T)},onCancel:()=>i(null)}},stepsOf:(N,$)=>{const C=N.find(v=>v.kind==="project"&&v.sessions.some(A=>A.id===$));if(!C)return{};const M=C.sessions.findIndex(v=>v.id===$);return{...M>0?{up:()=>k(C,M,M-1)}:{},...M<C.sessions.length-1?{down:()=>k(C,M,M+1)}:{}}},projectStep:(N,$,C)=>{var T;const M=S(),v=M.indexOf($.project??""),A=v+C;return v<0||A<0||A>=M.length||!((T=r.daemon)!=null&&T.projectEdit)?void 0:()=>b($,A)}}}const sc=34,W1=120;function K1({value:t,onChange:s,onSend:n,canSend:a,images:l,running:r,offline:o,onStop:i,fieldRef:c}){const x=f.useRef(null),u=c??x;f.useLayoutEffect(()=>{const p=u.current;p&&(p.style.height=`${sc}px`,p.style.height=`${Math.min(W1,Math.max(sc,p.scrollHeight))}px`)},[t,u]);const m=r||o;return e.jsxs("div",{className:"group flex flex-none flex-col gap-1.5 pt-1.5 pb-2",children:[l.items.length>0&&e.jsx(Ou,{items:l.items,onRemove:l.remove,size:{w:72,h:54},removeLabel:d.images.remove,lang:Lc}),e.jsxs("div",{className:`flex min-w-0 items-end gap-2 rounded-[10px] border border-input bg-surface py-[5px] pr-[5px] pl-3 focus-within:border-ring focus-within:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)] ${o?"opacity-55":""}`,children:[e.jsx("label",{htmlFor:"chat-ask",className:"sr-only",children:d.chat.field}),e.jsx("textarea",{id:"chat-ask",ref:u,rows:1,value:o?"":t,disabled:o,maxLength:ta,enterKeyHint:"enter",placeholder:r?d.chat.answering:d.chat.placeholder,onChange:p=>s(p.target.value),onPaste:p=>{const h=Fu(p);h.length===0||m||(p.preventDefault(),l.add(h))},onKeyDown:p=>{p.key!=="Enter"||p.nativeEvent.isComposing||p.shiftKey||!Qa()||(p.preventDefault(),a&&n())},className:"max-h-[120px] min-h-[34px] min-w-0 flex-1 resize-none bg-transparent py-[6px] text-base leading-[22px] text-fg outline-none placeholder:text-muted"}),r?e.jsx("button",{type:"button",onClick:i,"aria-label":d.chat.stop,title:d.chat.stop,className:"grid size-9 flex-none place-items-center rounded-lg bg-raised text-fg",children:e.jsx(q,{name:"stop",className:"size-4"})}):e.jsx("button",{type:"button",disabled:!a,onClick:n,"aria-label":d.chat.send,title:d.chat.send,className:"grid size-9 flex-none place-items-center rounded-lg bg-primary text-primary-fg disabled:opacity-40",children:e.jsx(q,{name:"send",className:"size-[18px]"})})]}),e.jsxs("p",{className:"hidden items-center gap-1 text-[12px] leading-4 text-muted group-focus-within:flex",children:[e.jsx(Du,{onFiles:l.add,disabled:m,className:"text-[12px] leading-4 text-muted disabled:opacity-50",children:d.chat.plusImage}),Qa()&&e.jsxs("span",{children:["· ",d.chat.enterSends]})]}),l.error&&e.jsx("p",{role:"alert",className:"text-body text-attention",children:l.error})]})}const Kl=Pe({variant:"primary",size:"sm",className:"min-w-[64px] flex-none"}),ka=Pe({size:"sm",className:"min-w-[64px] flex-none"}),Vl="w-full rounded-control border border-line bg-surface px-2.5 py-2 text-body text-fg",pn=t=>t.replace(/\s*[\r\n]+\s*/g," ").trim();function V1({task:t,store:s,fresh:n}){const a=d.chat.point.note,l=t.brain,r=f.useId(),[o,i]=f.useState(!1),[c,x]=f.useState(l.fact),[u,m]=f.useState(l.title??l.note),[p,h]=f.useState(l.when??""),[g,y]=f.useState(!1),[k,S]=f.useState(null),b=async $=>{y(!0),S(null);const C=pn(c),M=$?{yes:$,...C&&C!==l.fact?{text:C}:{},...l.create&&pn(u)?{title:pn(u)}:{},...l.create&&pn(p)?{when:pn(p)}:{}}:{yes:$},v=await s.answerNote(t.id,M);y(!1),v.status!=="applied"&&S(v.status==="rejected"&&v.reason==="confirm_required"?a.confirmRequired:v.status==="rejected"&&v.reason==="stale"?a.stale:v.status==="cancelled"?a.cancelled:v.status==="expired"?a.expired:a.failed)},j=l.kind==="flag"?a.flag(l.note):l.create?a.create(l.note):a.add(l.note),N=!n||g;return e.jsxs("div",{className:"flex flex-col gap-2 rounded-control bg-raised p-2.5","data-note-proposal":t.id,children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-1.5 text-body",children:[e.jsx(ra,{tone:"attention",label:a.tag}),e.jsx("span",{className:"font-medium",children:t.giverName??d.chat.point.someone}),e.jsx("span",{className:"text-muted",children:j})]}),l.create&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{htmlFor:`${r}t`,className:"flex flex-col gap-1 text-small text-muted",children:[a.titleField,e.jsx("input",{id:`${r}t`,className:Vl,value:u,disabled:N,onChange:$=>m($.target.value)})]}),e.jsxs("label",{htmlFor:`${r}w`,className:"flex flex-col gap-1 text-small text-muted",children:[a.whenField,e.jsx("input",{id:`${r}w`,className:Vl,value:p,disabled:N,onChange:$=>h($.target.value)})]})]}),o?e.jsxs("label",{htmlFor:`${r}f`,className:"flex flex-col gap-1 text-small text-muted",children:[a.field,e.jsx("textarea",{id:`${r}f`,className:Vl,rows:3,value:c,disabled:N,onChange:$=>x($.target.value)})]}):e.jsx("p",{className:"m-0 whitespace-pre-wrap break-words rounded-control bg-surface px-2.5 py-2 text-body",children:l.fact}),l.source&&!o&&e.jsx("span",{className:"break-words text-small text-muted",children:a.source(l.source)}),k&&e.jsx("p",{role:"alert",className:"m-0 text-small text-approval",children:k}),e.jsx("div",{className:"flex flex-wrap gap-2",children:l.kind==="flag"?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Kl,disabled:N,onClick:()=>{b(!0)},children:a.mark}),e.jsx("button",{type:"button",className:ka,disabled:N,onClick:()=>{b(!1)},children:a.ignore})]}):o?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Kl,disabled:N||!pn(c),onClick:()=>{b(!0)},children:a.editYes}),e.jsx("button",{type:"button",className:ka,disabled:N,onClick:()=>{i(!1),x(l.fact)},children:a.cancel})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Kl,disabled:N,onClick:()=>{b(!0)},children:l.create?a.createYes:a.yes}),e.jsx("button",{type:"button",className:ka,disabled:N,onClick:()=>i(!0),children:a.edit}),e.jsx("button",{type:"button",className:ka,disabled:N,onClick:()=>{b(!1)},children:a.no})]})})]})}const Ln=Pe({size:"sm",className:"min-w-[64px] flex-none"}),G1=Pe({variant:"primary",size:"sm",className:"min-w-[64px] flex-none"}),nc="mt-1 text-meta tracking-[.4px] text-muted";function wa({tone:t}){return e.jsx("span",{"aria-hidden":"true",className:`size-2 flex-none rounded-full ${t==="ok"?"bg-ok":t==="danger"?"bg-approval":"bg-attention"}`})}function X1(t){return t.state==="done"?d.chat.point.finished:t.state==="refused"?d.chat.point.refused:d.chat.point.dropped}function Y1({store:t,sessions:s,tasks:n,syncedAt:a,fresh:l,threshold:r=kn,onAnswer:o,usage:i=[],usageAlert:c=null}){const x=Xt(),[u,m]=f.useState(null),p=new Map(s.map(v=>[v.id,v])),h=Vt(s),g=Wf(n.values()),y=Kf(n.values()),k=s.filter(v=>v.state!=="exited"&&!v.handover&&v.context&&v.context.used/v.context.window>=r),S=Vf(n.values()).slice(0,5),b=d.chat.point,j=ua(i,x,l),N=l?xh(j,c,x):[],$=h.length+N.length+g.length+y.length+k.length,C=(v,A,T)=>{const R=h.find(P=>P.sessionId===v&&P.key===A);R&&(m(`${v}/${A}`),t.decide(v,T,{expect:{key:R.key,kind:R.kind,text:R.text}}))},M=v=>{t.seeTask(v.id),tn({name:"thread",sessionId:v.owner})};return e.jsxs("section",{"aria-label":b.label,className:"flex flex-col gap-2.5 rounded-card border border-line bg-surface p-4",children:[e.jsxs("h2",{className:"flex items-baseline gap-2 text-base font-bold",children:[b.title,a&&e.jsx("span",{className:"text-small font-normal text-muted",children:b.ago(yn(a,x))})]}),$===0&&e.jsx("p",{className:"text-body text-muted",children:b.calm}),$>0&&e.jsxs("div",{role:"group","aria-label":b.yoursLabel,className:"flex flex-col gap-2",children:[e.jsxs("h3",{className:nc,children:[b.yours," · ",$]}),h.map(v=>{p.get(v.sessionId);const A=v.kind==="permission"&&v.risk!=="high"&&v.source!=="rpc",T=`${v.sessionId}/${v.key}`;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wa,{tone:"danger"}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5 text-body",children:[e.jsx("span",{className:"font-medium",children:v.botName}),e.jsx("span",{className:"min-w-0 truncate font-mono",children:wn(v)})]}),A?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:G1,disabled:!l||u===T,onClick:()=>C(v.sessionId,v.key,"accept"),children:b.yes}),e.jsx("button",{type:"button",className:Ln,disabled:!l||u===T,onClick:()=>C(v.sessionId,v.key,"deny"),children:b.no})]}):e.jsx("a",{href:ne({name:"request",sessionId:v.sessionId,key:v.key}),className:Ln,children:b.see})]},T)}),N.map(({harness:v,window:A,tone:T})=>{const R=ko(A);return e.jsxs("div",{"data-usage-over":T,className:"flex items-center gap-2","aria-label":T==="red"?b.reachedLabel(b.harnessShort[v]??v,R):b.overLabel(b.harnessShort[v]??v,R,A.pct),children:[e.jsx("span",{"aria-hidden":"true",className:`flex size-5 flex-none items-center justify-center rounded-md ${T==="red"?"bg-danger-bg text-approval":"text-attention"}`,style:T==="red"?void 0:{background:"var(--status-warning-soft)"},children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("path",{d:"M12 14l4-4"}),e.jsx("path",{d:"M3.3 19a10 10 0 1 1 17.4 0"})]})}),e.jsxs("span",{className:"min-w-0 flex-1 text-body",children:[b.harnessShort[v]??v," · ",R," ",e.jsx("b",{className:`font-medium ${wo[T]}`,children:d.percent(A.pct)})]}),A.resetsAt&&e.jsxs("span",{className:"flex-none whitespace-nowrap text-small text-muted",children:["↺ ",oo(A.resetsAt,x,!0)]})]},`usage:${v}:${A.kind}:${A.model??A.pool??""}`)}),g.map(v=>v.brain?e.jsx(V1,{task:{...v,brain:v.brain},store:t,fresh:l},`decision:${v.id}`):e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"mt-2 flex",children:e.jsx(wa,{tone:"attention"})}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5 text-body",children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx(ra,{tone:"attention",label:b.decision}),e.jsx("span",{className:"font-medium",children:v.giverName??b.someone}),e.jsx("span",{className:"text-muted",children:b.asks})]}),e.jsx("span",{className:"break-words",children:v.title}),v.text&&e.jsx("span",{className:"whitespace-pre-wrap break-words text-small text-muted",children:v.text})]}),o&&e.jsx("button",{type:"button",className:Ln,"aria-label":b.answerLabel(v.title),onClick:()=>o(v),children:b.answer})]},`decision:${v.id}`)),y.map(v=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wa,{tone:v.state==="done"?"ok":"attention"}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5 text-body",children:[e.jsx("span",{className:"font-medium",children:v.ownerName}),e.jsx("span",{children:X1(v)})]}),e.jsx("button",{type:"button",className:Ln,onClick:()=>M(v),children:b.see})]},v.id)),k.map(v=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wa,{tone:"attention"}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5 text-body",title:b.nearHint,children:[e.jsx("span",{className:"font-medium",children:v.name}),e.jsxs("span",{className:"text-attention",children:["· ",b.near(Math.round(v.context.used/v.context.window*100))]})]}),e.jsx("a",{href:ne({name:"thread",sessionId:v.id}),className:Ln,children:b.see})]},`near:${v.id}`))]}),e.jsx(bj,{usage:j,now:x,alert:c}),S.length>0&&e.jsxs("div",{role:"group","aria-label":b.givenLabel,className:"flex flex-col gap-2",children:[e.jsx("h3",{className:nc,children:b.given}),S.map(v=>e.jsxs("a",{href:ne({name:"thread",sessionId:v.owner}),className:"flex items-center gap-2 text-body",children:[e.jsx("code",{className:"flex-none font-mono text-small text-muted",children:v.id}),e.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[v.title," ",e.jsxs("span",{className:"text-muted",children:["→ ",v.ownerName]})]}),e.jsx("span",{className:v.state==="taken"?"text-info":"text-muted",children:b.state[v.state]})]},v.id))]})]})}const Zt=()=>d.chat.history,Da=t=>{const s=new Date(t);return`${s.getHours()}:${String(s.getMinutes()).padStart(2,"0")}`},Sa=t=>`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`;function mx(t,s){const n=new Date(t);if(Sa(n)===Sa(s))return Zt().today;const a=new Date(s);return a.setDate(s.getDate()-1),Sa(n)===Sa(a)?Zt().yesterday:n.toLocaleDateString(lt,{weekday:"short",day:"numeric",month:"short"})}const Q1=(t,s)=>`${mx(t.startedAt,s)}, ${Da(t.startedAt)}`,Z1="flex min-h-12 w-full items-center gap-3 border-b border-line px-3.5 py-2 text-left last:border-b-0",J1="px-1 pt-1.5 text-[12px] font-medium text-muted";function Gl({first:t,sub:s,current:n=!1,onClick:a}){return e.jsxs("button",{type:"button",onClick:a,"aria-current":n||void 0,className:`${Z1} ${n?"bg-raised":""}`,children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("b",{className:"truncate text-[14.5px] font-medium",children:Zt().quote(t)}),e.jsx("small",{className:"truncate text-[12px] text-muted",children:s})]}),!n&&e.jsx(q,{name:"chevron",className:"size-4 text-muted"})]})}function Xl({children:t}){return e.jsx("div",{className:"flex max-h-[55vh] flex-col overflow-y-auto rounded-[10px] border border-line",children:t})}function ey({conversations:t,kept:s,turns:n,running:a,now:l,onClose:r,onReset:o,onOpen:i,onScrollTo:c}){const x=f.useId();if(!s){const p=n.filter(h=>h.question);return e.jsxs(dt,{labelledBy:x,onClose:r,children:[e.jsx("h2",{id:x,className:"text-base font-semibold",children:Zt().today}),p.length===0?e.jsx("p",{className:"text-body text-muted",children:Zt().none}):e.jsx(Xl,{children:p.map(h=>e.jsx(Gl,{first:h.question,sub:Da(h.askedAt),onClick:()=>c(h.qid)},h.qid))})]})}const u=t.list,m=[];for(const p of(u==null?void 0:u.past)??[]){const h=mx(p.startedAt,l),g=m.at(-1);(g==null?void 0:g.day)===h?g.items.push(p):m.push({day:h,items:[p]})}return e.jsxs(dt,{labelledBy:x,onClose:r,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{id:x,className:"flex-1 text-base font-semibold",children:Zt().title}),e.jsxs("button",{type:"button",disabled:a,onClick:o,className:Fe({size:"sm"}),children:[e.jsx(q,{name:"edit",className:"size-4"}),d.chat.reset]})]}),u&&(u.current||m.length>0)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[u.current&&e.jsx(Xl,{children:e.jsx(Gl,{current:!0,first:u.current.first,onClick:r,sub:[Zt().current,Zt().count(u.current.count),Zt().since(Da(u.current.startedAt))].join(" · ")})}),m.map(p=>e.jsxs("section",{"aria-label":p.day,className:"flex flex-col gap-1",children:[e.jsx("h3",{className:J1,children:p.day}),e.jsx(Xl,{children:p.items.map(h=>e.jsx(Gl,{first:h.first,sub:`${Zt().count(h.count)} · ${Da(h.startedAt)}`,onClick:()=>i(h)},h.id))})]},p.day))]}),e.jsx("p",{className:"text-small text-muted",children:Zt().kept})]}),u&&!u.current&&m.length===0&&e.jsx("p",{className:"text-body text-muted",children:Zt().empty})]})}const _r=3,Ir=t=>`${t.sessionId}/${t.key}`;function ty(t,s){return new Set(t.filter(n=>n.kind==="pane"||n.kind==="reply").flatMap(n=>{const a=n.id??(n.name?s.get(n.name):void 0);return a?[a]:[]}))}function sy({store:t,items:s,onGo:n}){const a=hr(s.slice(0,_r).map(r=>({id:Ir(r),value:r}))),l=s.length-_r;return a.entries.length===0?null:e.jsxs("div",{className:vo,children:[a.entries.map(r=>e.jsx(ny,{store:t,item:r.value,ghost:r.ghost,onGone:()=>a.dismiss(r.id),onGo:n},r.id)),l>0&&e.jsx("a",{href:ne({name:"atoi"}),className:"text-small text-info underline underline-offset-2",children:d.chat.inAnswer.more(l)})]})}function ny({store:t,item:s,ghost:n,onGone:a,onGo:l}){var c,x,u;const r=me(t),o=Fs(),i=r.sessions.get(s.sessionId);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[!n&&e.jsx("span",{className:"text-[11.5px] text-muted",children:d.chat.inAnswer.request(s.botName)}),e.jsx(io,{store:t,item:s,session:i,mode:Qr(s,(c=r.capabilities)==null?void 0:c[s.tool],(i==null?void 0:i.readOnly)===!0),outcome:Gn(s,[...r.sessions.values()],r.ops),fresh:r.fresh,ghost:n,changed:!1,onReread:()=>{},canConfirm:((x=r.device)==null?void 0:x.confirm)===!0&&o,enroll:o&&((u=r.device)==null?void 0:u.confirm)!==!0,onGone:a,onCheck:l})]})}function ay({names:t}){return t.length===0?null:e.jsx("div",{className:vo,children:t.map(s=>e.jsxs("span",{className:"text-[11.5px] text-muted",children:[d.chat.inAnswer.settled," · ",s]},s))})}const ly="kernel";function ry(t,s){var l,r,o;const n=(r=(l=t.find(i=>i.rig&&i.rig.name!==ly))==null?void 0:l.rig)==null?void 0:r.name,a=(o=t.find(i=>i.name&&!i.rig))==null?void 0:o.name;return[d.chat.suggestions.waiting,...s.getHours()<12?[d.chat.suggestions.summarize]:[],...n?[d.chat.suggestions.rig(n)]:a?[d.chat.suggestions.session(a)]:[]]}const Fa="grid size-11 flex-none place-items-center rounded-lg text-muted active:bg-raised disabled:opacity-40";function px({frozen:t,onClose:s,children:n}){return e.jsxs("header",{className:"bleed flex h-[58px] flex-none items-center gap-1.5 border-b border-line pr-1.5 pl-3.5",children:[e.jsx("span",{"aria-hidden":"true",className:"flex size-[22px] flex-none",children:e.jsx(bs,{size:22,frozen:t})}),e.jsx("h2",{className:"text-base font-semibold",children:d.chat.title}),e.jsx("span",{className:"flex-1"}),n,e.jsx(fx,{onClose:s})]})}function fx({onClose:t}){return e.jsx("button",{type:"button",onClick:t,"aria-label":d.chat.pane.close,title:d.chat.pane.close,className:Fa,children:e.jsx(q,{name:"close"})})}function ac({store:t,onClose:s}){var H,X,te,pe,ue;const n=me(t),a=It(),l=Pc(t),r=[...n.sessions.values()],[o,i]=f.useState(""),c=Ku(t),[x,u]=f.useState(null),m=f.useRef(null),p=l.live!==null,h=!n.fresh,g=Zm(t),y=!!((H=n.daemon)!=null&&H.conversations),[k,S]=f.useState(!1),[b,j]=f.useState(null),N=f.useRef(new Map);hu(t);const $=f.useRef(null),[C,M]=f.useState(0);f.useEffect(()=>{const F=$.current;!C||!F||(F.focus(),F.setSelectionRange(F.value.length,F.value.length))},[C]);const v=F=>{u(null),i(d.chat.point.answerDraft(F.title,F.id,F.giverName??d.chat.point.someone)),M(w=>w+1)},A=f.useRef([]);f.useEffect(()=>{const F=l.error;(F==null?void 0:F.text)!==void 0&&(i(w=>w||F.text),A.current.length&&(c.putBack(A.current),A.current=[]),u(F.code==="offline"?null:{question:F.text,note:F.code==="busy"?d.chat.busy:d.chat.failed}),t.clearChatError())},[l.error,t]),f.useEffect(()=>{var F,w;(w=(F=m.current)==null?void 0:F.scrollIntoView)==null||w.call(F,{block:"end"})},[l.turns.length,(X=l.live)==null?void 0:X.text,(te=l.live)==null?void 0:te.steps.length,x]);const T=(F,w=[])=>{u(null),t.ask(F,w)},R=()=>{const F=o.trim();if(!F&&c.items.length===0||p||h||!c.ready)return;const w=c.ids();A.current=c.clear(),T(F,w),i("")},P=r.map(F=>({id:F.id,name:F.name,repo:F.repo,exited:F.state==="exited",state:F.state,helpers:F.helpers})),_=()=>{u(null),t.resetChat()},D=new Map,E=new Set;for(const F of r)F.name&&(D.has(F.name)?E.add(F.name):D.set(F.name,F.id));for(const F of E)D.delete(F);const z=Vt(r),K=new Set(z.map(Ir)),L=l.turns.at(-1),W=!p&&(L==null?void 0:L.answer)!==void 0?L:void 0,ae=W?(()=>{const F=ty(W.steps,D);return z.filter(w=>F.has(w.sessionId))})():[];if(W){const F=N.current.get(W.qid)??new Map;for(const w of ae.slice(0,_r))F.set(Ir(w),w.botName);N.current.set(W.qid,F)}const U=F=>F===(W==null?void 0:W.qid)?e.jsx(sy,{store:t,items:ae}):e.jsx(ay,{names:[...new Set([...N.current.get(F)??[]].filter(([w])=>!K.has(w)).map(([,w])=>w))]}),O=F=>({at:F,usage:n.usage??[],alert:n.usageAlert,fresh:n.fresh}),B=()=>{t.askConversations(),S(!0)},Z=e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:B,"aria-haspopup":"dialog","aria-label":y?d.chat.history.title:d.chat.history.today,title:y?d.chat.history.title:d.chat.history.today,className:Fa,children:e.jsx(q,{name:"clock"})}),e.jsx("button",{type:"button",disabled:p,onClick:_,"aria-label":d.chat.reset,title:d.chat.reset,className:Fa,children:e.jsx(q,{name:"edit"})})]});if(b){const F=g.open[b.id];return e.jsxs(e.Fragment,{children:[e.jsx(la,{name:Q1(b,new Date),back:e.jsx("button",{type:"button","aria-label":d.nav.backTo.chat,title:d.nav.backTo.chat,onClick:()=>j(null),className:Tt({className:"text-muted"}),children:e.jsx(q,{name:"back"})}),...s?{more:e.jsx(fx,{onClose:s})}:{}}),e.jsxs("p",{className:"bleed flex flex-none items-center gap-2 border-b border-line bg-raised px-3.5 py-2 text-small text-muted",children:[e.jsx(q,{name:"clock",className:"size-4 flex-none"}),d.chat.history.pastBanner]}),e.jsxs("main",{"data-tab-scroll":s?void 0:"",className:"flex min-h-0 flex-1 flex-col gap-2.5 overflow-y-auto overscroll-contain py-3 text-[14px]",children:[F&&"gone"in F&&e.jsx("p",{className:"px-1 text-body text-muted",children:d.chat.history.gone}),F&&"turns"in F&&F.turns.map(w=>{const I=F.limits.find(V=>V.qid===w.qid);return e.jsx(Pi,{store:t,turn:w,list:P,canConfirm:!1,live:null,sessions:r.length,readOnly:!0,limits:I&&O(I.at)},w.qid)})]}),e.jsx("div",{className:"flex-none pt-1.5 pb-3",children:e.jsx("button",{type:"button",onClick:()=>j(null),className:Fe({variant:"primary",className:"w-full"}),children:d.chat.history.backToday})})]})}return e.jsxs(e.Fragment,{children:[s?e.jsx(px,{frozen:h,onClose:s,children:Z}):e.jsxs("header",{className:"bleed flex h-14 flex-none items-center gap-1 border-b border-line pr-1 pl-3.5",children:[e.jsxs("span",{className:"mr-1 flex items-center gap-2 text-[17px] font-semibold",children:[e.jsx("span",{"aria-hidden":"true",className:"flex size-7 flex-none",children:e.jsx(bs,{size:28,frozen:h})}),e.jsx("h1",{children:d.chat.title})]}),e.jsx(cl,{}),e.jsx("span",{className:"flex-1"}),Z,!a&&e.jsx("a",{href:ne({name:"connection"}),"aria-label":d.nav.settings,title:d.nav.settings,className:Fa,children:e.jsx(q,{name:"gear"})})]}),e.jsxs("main",{"data-tab-scroll":s?void 0:"",className:"flex min-h-0 flex-1 flex-col gap-2.5 overflow-y-auto overscroll-contain py-3 text-[14px]",children:[e.jsx(js,{}),l.turns.length===0&&!x&&e.jsxs("div",{className:"flex flex-1 flex-col justify-end gap-2.5",children:[e.jsx(Y1,{store:t,sessions:r,tasks:n.tasks,syncedAt:n.syncedAt,fresh:n.fresh,onAnswer:v,...((pe=n.device)==null?void 0:pe.contextNear)!==void 0?{threshold:n.device.contextNear}:{},usage:n.usage??[],usageAlert:n.usageAlert}),!h&&e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[ry(r,new Date).map(F=>e.jsx("button",{type:"button",onClick:()=>T(F),className:"inline-flex h-[34px] items-center gap-1.5 rounded-full border border-input bg-surface px-3 text-[13px] text-fg",children:F},F)),((ue=n.daemon)==null?void 0:ue.launch)&&e.jsxs("a",{href:ne({name:"launch"}),className:"inline-flex h-[34px] items-center gap-1.5 rounded-full border border-dashed border-input px-3 text-[13px] text-muted",children:[e.jsx(q,{name:"plus",className:"size-3.5"}),d.chat.suggestions.newSession]})]})]}),l.turns.map(F=>{var w,I;return e.jsx("div",{id:`turn-${F.qid}`,className:"contents",children:e.jsx(Pi,{store:t,turn:F,list:P,canConfirm:!!((w=n.device)!=null&&w.confirm),live:((I=l.live)==null?void 0:I.qid)===F.qid?l.live:null,sessions:r.length,...!p&&!h?{onAskAgain:V=>T(V)}:{},limits:l.limits[F.qid]!==void 0?O(l.limits[F.qid]):void 0,inAnswer:U(F.qid)})},F.qid)}),x&&e.jsxs("div",{className:"flex flex-col gap-1.5",children:[x.question&&e.jsx("div",{className:"max-w-[85%] self-end whitespace-pre-wrap break-words rounded-[12px_12px_4px_12px] bg-raised px-3 py-2",children:x.question}),e.jsx("p",{role:"status",className:"text-[13.5px] text-attention",children:x.note})]}),e.jsx("div",{ref:m})]}),e.jsx(K1,{value:o,onChange:i,onSend:R,canSend:(o.trim()!==""||c.items.length>0)&&c.ready&&!p&&!h,images:c,running:p,offline:h,onStop:()=>t.cancelAsk(),fieldRef:$}),h&&e.jsx("p",{role:"status",className:"flex-none pb-2 text-[13px] text-attention",children:d.chat.offline}),k&&e.jsx(ey,{conversations:g,kept:y,turns:l.turns,running:p,now:new Date,onClose:()=>S(!1),onReset:()=>{S(!1),_()},onOpen:F=>{S(!1),t.openConversation(F.id),j(F)},onScrollTo:F=>{var w,I,V;S(!1),(V=(I=(w=document.getElementById(`turn-${F}`))==null?void 0:w.firstElementChild)==null?void 0:I.scrollIntoView)==null||V.call(I,{block:"start"})}})]})}const ea=(t,s)=>(t.slice(0,s===void 0?void 0:s*4).match(/.{1,4}/g)??[]).join(" "),hx=t=>ea(t,6),oy=t=>ea(t,2);function gx(){const t=globalThis;if(!t.Notification||!t.PushManager)return"unsupported";const s=t.navigator;return s&&"standalone"in s&&s.standalone!==!0?"unsupported":t.Notification.permission==="denied"?"denied":"ok"}const iy=t=>{const s=atob(t.replace(/-/g,"+").replace(/_/g,"/"));return Uint8Array.from(s,n=>n.charCodeAt(0))};function bx(t,s){return new Promise(n=>{const a=()=>{var o;const r=(o=t.getState().ops[s])==null?void 0:o.phase;return!r||ps(r)&&r!=="uncertain"?!1:(l(),n(r==="applied"?"applied":"other"),!0)},l=t.subscribe(a);a()})}async function cy(t,s=(n,a)=>globalThis.fetch(n,a)){var a;if(gx()==="unsupported")return"unsupported";try{if(await Notification.requestPermission()!=="granted")return"denied";const l=await s("/push/key",{credentials:"same-origin",cache:"no-store"});if(l.status===404)return"unavailable";if(!l.ok)return"failed";const r=await l.json();if(typeof r.publicKey!="string")return"failed";const o=r.publicKey,i=iy(o),{pushManager:c}=await navigator.serviceWorker.ready;await((a=await c.getSubscription())==null?void 0:a.unsubscribe());const x=await c.subscribe({userVisibleOnly:!0,applicationServerKey:i}),u=fm.safeParse(x.toJSON());if(!u.success)return"failed";const m=t.pushSubscribe(u.data,o);return m===null?"failed":await bx(t,m)==="applied"?"on":"failed"}catch{return"failed"}}async function dy(t){const s=t.pushUnsubscribe(),n=s!==null&&await bx(t,s)==="applied";try{await(await navigator.serviceWorker.ready).pushManager.getSubscription().then(a=>a==null?void 0:a.unsubscribe())}catch{}return n}const At=d.notifications,uy=t=>t==="denied"?At.denied:t==="unsupported"?At.unsupported:t==="unavailable"?At.noPush:t==="failed"?At.failed:null;function jx(t,s){var x;const n=(x=me(t).device)==null?void 0:x.push,[a,l]=f.useState(!1),[r,o]=f.useState(null);return{push:n,busy:a,problem:r,enable:async()=>{if(a)return"failed";l(!0),o(null);const u=await cy(t,s);return l(!1),o(uy(u)),u},disable:async()=>{a||(l(!0),o(null),await dy(t),l(!1))}}}function xy({store:t,fetchImpl:s}){const n=jx(t,s);if(!n.push)return null;const a=n.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:At.row}),e.jsx("dd",{className:"flex min-w-0 items-center gap-3 text-right",children:n.push==="unavailable"?e.jsx("span",{children:At.noPush}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:a?At.on:At.off}),e.jsx(fl,{on:a,label:At.row,disabled:n.busy,onChange:l=>{l?n.enable():n.disable()}})]})})]}),n.push==="stale"&&e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[e.jsx("p",{className:"text-muted",children:At.stale}),e.jsx("button",{type:"button",disabled:n.busy,onClick:()=>{n.enable()},className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 font-medium disabled:opacity-45",children:At.enable})]}),n.problem&&e.jsx(Xe,{title:n.problem,tone:"warning",role:"alert"})]})}const lc=t=>(t==="off"||t==="stale")&&gx()!=="unsupported";function rc({store:t,onDone:s,fetchImpl:n,body:a=At.body}){const l=jx(t,n),r=me(t).fresh,o=()=>{l.enable().then(i=>{i==="on"&&(tn({name:"atoi"}),s())})};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:At.title}),e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:a}),l.problem&&e.jsx(Xe,{title:l.problem,tone:"warning",role:"alert"}),e.jsx("button",{type:"button",disabled:l.busy||!r,onClick:o,className:St,children:l.busy?At.working:r?At.enable:At.waiting})]}),e.jsx("a",{href:ne({name:"atoi"}),onClick:s,className:mt,children:At.later})]})}function my(t,s){switch(t.status){case"applied":return{text:s,quiet:!1};case"cancelled":return{text:d.confirm.cancelled,quiet:!0};case"expired":return{text:d.confirm.expired,quiet:!0};case"rejected":return t.reason==="assertion_expired"?{text:d.confirm.expired,quiet:!0}:{text:d.confirm.refused[t.reason]??s,quiet:!1};default:return{text:s,quiet:!1}}}const Te=d.connection.pcUpdate,Wn="flex flex-col gap-3 rounded-card border bg-surface p-3.5";function py({store:t,action:s,pc:n,from:a,to:l,onClose:r}){var h;const o=f.useId(),i=!!((h=me(t).device)!=null&&h.confirm),[c,x]=f.useState(!1),[u,m]=f.useState(null),p=()=>{x(!0),m(null),t.pcAction(s,s==="update"?l:void 0).then(g=>{g.status==="applied"?r():m(my(g,Te.notDone))},()=>m({text:Te.notDone,quiet:!1})).finally(()=>x(!1))};return e.jsxs(dt,{labelledBy:`${o}-title`,onClose:()=>{c||r()},children:[e.jsx("h2",{id:`${o}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:s==="update"?Te.confirmUpdate:Te.confirmRestart}),e.jsx("p",{className:"text-body text-muted",children:s==="update"?Te.confirmUpdateBody(n,a,l):Te.confirmRestartBody(n)}),e.jsx("p",{className:`rounded-control border border-dashed border-input px-3 py-2 text-small ${i?"text-muted":"text-attention"}`,children:i?Te.passkey:Te.noPasskey}),u&&e.jsx("p",{role:"status",className:`text-body ${u.quiet?"text-muted":"text-danger-fg"}`,children:u.text}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ke,{variant:"ghost",className:"flex-1",disabled:c,onClick:r,children:Te.cancel}),e.jsx(Ke,{variant:"primary",className:"flex-[2]",disabled:c||!i,onClick:p,children:Te.confirm})]})]})}function fy({run:t,fresh:s}){const n=t.action==="update"?["asked","installing","restarting","back"]:["asked","restarting","back"],a=t.step==="restarting"?s?n.indexOf("restarting"):n.length-1:1;return e.jsx("ol",{className:"flex flex-col gap-1.5 text-small",children:n.map((l,r)=>e.jsxs("li",{className:`flex items-center gap-2 ${r>a?"text-muted":""}`,children:[e.jsx("span",{"aria-hidden":"true",className:"w-4 text-center",children:r<a?"✓":r===a?"…":"·"}),e.jsx("span",{children:Te.steps[l]})]},l))})}function hy({store:t,run:s,fresh:n,from:a,onRetry:l}){const r=s.action==="update";return qc(s)?e.jsxs("div",{className:`${Wn} border-line`,role:"status",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("strong",{className:"text-body",children:r?Te.updating(s.version):Te.restarting}),e.jsx("span",{className:"text-meta text-info",children:Te.running})]}),e.jsx(fy,{run:s,fresh:n}),e.jsx("p",{className:"text-small text-muted",children:Te.leave})]}):s.step==="done"?e.jsxs("div",{className:`${Wn} 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:r?Te.done(s.version):Te.restarted}),e.jsx("span",{className:"text-meta text-ok",children:Te.upToDate})]}),e.jsx(Ke,{onClick:()=>t.dismissPc(),children:Te.close})]}):e.jsxs("div",{className:`${Wn} 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:r?Te.failed:Te.notRestarted}),e.jsx("span",{className:"text-meta text-danger-fg",children:Te.refused})]}),e.jsxs("p",{className:"text-small text-muted",children:[Te.unchanged(a)," ",s.reason?Te.reasons[s.reason]:""]}),e.jsx(Ke,{onClick:l,children:Te.retry})]})}function gy({store:t,appVersion:s}){const n=me(t),[a,l]=f.useState(null),r=n.daemon,o=n.pc;if(!r)return null;const i=s!==null&&Bc(r.version,s);if(!i&&!r.restart&&!o)return null;const c=r.name,x=()=>{t.dismissPc(),((o==null?void 0:o.action)==="restart"||s)&&l((o==null?void 0:o.action)??"restart")};return e.jsxs("section",{"aria-labelledby":"pc-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"pc-title",className:"text-small font-medium text-muted",children:Te.title}),o?e.jsx(hy,{store:t,run:o,fresh:n.fresh,from:r.version,onRetry:x}):i&&(r.update?e.jsxs("div",{className:`${Wn} border-input`,children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("strong",{className:"text-body",children:Te.behind}),e.jsx("span",{className:"font-mono text-small text-muted",children:Te.versions(r.version,s)})]}),e.jsx("p",{className:"text-small text-muted",children:Te.why}),e.jsx(Ke,{variant:"primary",block:!0,disabled:!n.fresh,onClick:()=>l("update"),children:Te.update}),e.jsx("p",{className:"text-meta text-muted",children:Te.keepGoing})]}):e.jsxs("div",{className:`${Wn} border-attention/40`,children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("strong",{className:"text-body",children:Te.manual}),e.jsx("span",{className:"font-mono text-small text-muted",children:Te.versions(r.version,s)})]}),e.jsx("p",{className:"text-small text-muted",children:r.restart?Te.clone:Te.byHand})]})),r.restart&&e.jsxs("div",{className:"flex items-center gap-3 rounded-control border border-line px-3.5 py-3",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"text-body",children:Te.restart}),e.jsx("span",{className:"text-small text-muted",children:Te.restartHint})]}),e.jsx(Ke,{size:"sm",disabled:!n.fresh||qc(o),onClick:()=>l("restart"),children:Te.restartGo})]}),a&&e.jsx(py,{store:t,action:a,pc:c,from:r.version,to:a==="update"&&s?s:r.version,onClose:()=>l(null)})]})}const yl="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",We=d.settings,Nl="flex flex-col rounded-[10px] border border-line bg-surface text-body",$o="flex flex-col gap-1 border-b border-line px-4 py-3 last:border-b-0",by=Array.from({length:Math.round((jm-zo)*20)+1},(t,s)=>Math.round((zo+s*.05)*100)),jy=["finished","chat","decision"],yy=["pc","claude","codex","cursor","omp"];function Co({label:t,hint:s,children:n}){const a=f.useId();return e.jsxs("div",{className:$o,children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"min-w-0",children:t}),n(s?a:void 0)]}),s&&e.jsx("p",{id:a,className:"text-small text-muted",children:s})]})}function Ny(t,s){if(t==="hour")return new Date(s.getTime()+36e5);if(t==="four")return new Date(s.getTime()+4*36e5);const n=new Date(s);return n.setDate(n.getDate()+1),n.setHours(8,0,0,0),n}function vy(t,s){const n=t.toLocaleTimeString(lt,{hour:"2-digit",minute:"2-digit"});if(t.toDateString()===s.toDateString())return n;const a=new Date(s);return a.setDate(a.getDate()+1),t.toDateString()===a.toDateString()?We.tomorrow(n):`${t.toLocaleDateString(lt,{day:"numeric",month:"short"})} ${n}`}function yx(t){var u;const s=me(t),[n,a]=f.useState(null),[l,r]=f.useState(!1),o=f.useRef(0),i=f.useRef(!0);return f.useEffect(()=>()=>{i.current=!1},[]),{prefs:n??((u=s.device)==null?void 0:u.prefs)??bm,send:m=>{const p=++o.current;a(m),r(!1),t.setDevicePrefs(m).then(h=>{!i.current||p!==o.current||(a(null),h.status!=="applied"&&r(!0))})},failed:l,fresh:s.fresh}}function ky({store:t}){var c,x;const s=me(t),n=yx(t),a=Xt();if(!((c=s.daemon)!=null&&c.settings)||!((x=s.device)!=null&&x.prefs)||s.device.push!=="on")return null;const{prefs:l}=n,r=l.quietUntil!==null?new Date(l.quietUntil):null,o=r!==null&&r.getTime()>a,i=u=>n.send({...l,quietUntil:Ny(u,new Date(a)).toISOString()});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:Nl,children:[jy.map(u=>e.jsx(Co,{label:We.notify[u],hint:We.notify[`${u}Hint`],children:m=>e.jsx(fl,{on:l.notify[u],label:We.notify[u],describedBy:m,disabled:!n.fresh,onChange:p=>n.send({...l,notify:{...l.notify,[u]:p}})})},u)),e.jsxs("div",{className:$o,children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{children:We.pause}),o&&e.jsx("span",{role:"status",className:"text-right text-attention",children:We.pausedUntil(vy(r,new Date(a)))})]}),e.jsx("p",{className:"text-small text-muted",children:We.pauseHint}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-2",children:o?e.jsx("button",{type:"button",disabled:!n.fresh,onClick:()=>n.send({...l,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:We.resume}):["hour","four","morning"].map(u=>e.jsx("button",{type:"button","aria-label":We.pauseLabel[u],disabled:!n.fresh,onClick:()=>i(u),className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 font-medium disabled:opacity-45",children:We.pauseFor[u]},u))})]})]}),e.jsx("p",{className:"text-small text-muted",children:We.notify.always}),n.failed&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:We.failed})]})}function wy({store:t}){var m,p;const s=me(t),n=yx(t),[a,l]=f.useState(null),[r,o]=f.useState(!1),i=f.useRef(!0);if(f.useEffect(()=>()=>{i.current=!1},[]),!((m=s.daemon)!=null&&m.settings)||!((p=s.device)!=null&&p.prefs))return null;const c=Math.round((a??s.device.contextNear??kn)*100),x=h=>{l(h/100),o(!1),t.setContextNear(h/100).then(g=>{i.current&&(l(null),g.status!=="applied"&&o(!0))})},u=n.prefs.chatTool??"pc";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:We.ledge}),e.jsxs("div",{className:Nl,children:[e.jsx(Co,{label:We.context,hint:We.contextHint,children:h=>e.jsx("select",{className:`${yl} w-auto`,"aria-label":We.context,"aria-describedby":h,disabled:!s.fresh||a!==null,value:c,onChange:g=>x(Number(g.target.value)),children:by.map(g=>e.jsx("option",{value:g,children:d.percent(g)},g))})}),s.device.chat&&e.jsxs("div",{className:$o,children:[e.jsx("span",{children:We.chatTool}),e.jsx("p",{className:"text-small text-muted",children:We.chatToolHint}),e.jsx("div",{className:"mt-1",children:e.jsx(Jn,{name:"chat-tool",legend:We.chatTool,value:u,options:yy.map(h=>({value:h,label:We.tools[h]})),onChange:h=>{s.fresh&&n.send({...n.prefs,chatTool:h==="pc"?null:h})}})}),e.jsx("p",{className:"text-meta text-muted",children:We.toolPcHint})]})]}),!s.fresh&&e.jsx("p",{className:"text-small text-muted",children:We.offline}),(r||n.failed)&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:We.failed})]})}function Sy(){const t=hm();return e.jsx("div",{className:Nl,children:e.jsx(Co,{label:We.motion,hint:We.motionHint,children:s=>e.jsx(fl,{on:t,label:We.motion,describedBy:s,onChange:gm})})})}function $y({store:t}){const s=me(t).daemon;return e.jsxs("section",{"aria-labelledby":"managed-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"managed-title",className:"text-small font-medium text-muted",children:We.managed}),(s==null?void 0:s.terminal)&&e.jsx("dl",{className:Nl,children:e.jsxs("div",{className:"flex items-baseline justify-between gap-4 px-4 py-3",children:[e.jsx("dt",{className:"text-muted",children:We.terminal}),e.jsx("dd",{children:s.terminalInput?We.allowed:We.notAllowed})]})}),e.jsx("p",{className:"text-small text-muted",children:We.managedBody})]})}const re=d.settings.projects,Nx=Object.keys(jn),Cy=80,vl=t=>re.errors[t.status==="rejected"?t.reason:t.status]??re.errors.failed;function My(t,s,n){const a=s+n;if(a<0||a>=t.length)return[...t];const l=[...t];return[l[s],l[a]]=[l[a],l[s]],l}function Ey({color:t}){return e.jsx("span",{className:"size-3 flex-none rounded-full",style:{background:jn[t]},"aria-hidden":"true"})}function Ry({value:t,onChange:s,name:n}){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:re.color}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Nx.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:n,value:a,checked:t===a,onChange:()=>s(a),className:"sr-only","aria-label":re.colors[a]}),e.jsx("span",{className:"size-6 rounded-full",style:{background:jn[a]},"aria-hidden":"true"})]},a))})]})}function Ay({store:t,project:s,projects:n,onClose:a,onDelete:l,onFolders:r}){var _,D;const o=f.useId(),i=new Set(n.map(E=>E.color)),[c,x]=f.useState((s==null?void 0:s.name)??""),[u,m]=f.useState((s==null?void 0:s.color)??Nx.find(E=>!i.has(E))??"blue"),[p,h]=f.useState(!1),[g,y]=f.useState(null),k=me(t),S=s===null&&!!((_=k.daemon)!=null&&_.projectFolders),b=!!((D=k.device)!=null&&D.confirm),[j,N]=f.useState(null),[$,C]=f.useState(!1);f.useEffect(()=>{S&&t.requestRecentFolders()},[t,S]);const M=c.trim(),v=M!==""&&n.some(E=>E.id!==(s==null?void 0:s.id)&&Bo(E.name)===Bo(M)),A=s!==null&&M===s.name&&u===s.color,T=S&&(j===null||!b),R=()=>{if(!M||v||p||T)return;if(A){a();return}h(!0),y(null);const E=s?{...M!==s.name?{name:M}:{},...u!==s.color?{color:u}:{}}:null;(s?t.editProject(s.id,E):t.createProject(M,u,S?j:void 0)).then(z=>{h(!1),z.status==="applied"?a():y(vl(z))})};if($)return e.jsxs(dt,{labelledBy:`${o}-title`,onClose:()=>C(!1),children:[e.jsx("h2",{id:`${o}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:re.firstFolder}),e.jsx(vx,{store:t,busy:!1,skip:()=>!1,rowLabel:re.choose,rowAria:re.chooseLabel,pickLabel:re.chooseThis,pickAria:re.chooseLabel,pickDisabled:!1,error:null,onPick:E=>{N(E),C(!1)},onBack:()=>C(!1)})]});const P=[...new Set([...j!==null?[j]:[],...k.recentFolders??[]])];return e.jsxs(dt,{labelledBy:`${o}-title`,onClose:()=>{p||a()},children:[e.jsx("h2",{id:`${o}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:s?re.editTitle:re.newTitle}),!s&&e.jsx("p",{className:"text-body text-muted",children:S?re.newBody:re.newBodyOld}),e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:E=>{E.preventDefault(),R()},children:[e.jsxs("label",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"text-small text-muted",children:re.name}),e.jsx("input",{className:yl,value:c,maxLength:Cy,autoFocus:!0,"aria-invalid":v||void 0,onChange:E=>x(E.target.value)}),v&&e.jsx("span",{role:"alert",className:"text-small text-danger-fg",children:re.errors.name_taken})]}),e.jsx(Ry,{name:`${o}-color`,value:u,onChange:m}),S&&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:[re.firstFolder,e.jsx("span",{className:"rounded-full border border-task/45 px-2 text-meta text-task",children:re.required})]}),P.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{className:"text-meta tracking-[.06em] text-muted uppercase",children:re.recents}),e.jsx("ul",{className:"flex flex-col rounded-control border border-line",children:P.map(E=>e.jsxs("li",{className:Kn,children:[e.jsxs("button",{type:"button","aria-pressed":j===E,"aria-label":re.chooseLabel(E),disabled:p,onClick:()=>N(E),className:`flex min-h-10 min-w-0 flex-1 items-center gap-2 text-left ${j===E?"font-medium text-fg":""}`,children:[e.jsx(q,{name:j===E?"check":"folder",className:"size-4 flex-none"}),e.jsx("span",{className:"font-mono text-small break-all",children:E})]}),j===E&&e.jsx("span",{className:"text-meta text-ok",children:re.chosen})]},E))})]}),e.jsx(Ke,{size:"sm",className:"self-start",disabled:p,onClick:()=>C(!0),children:re.browseMore}),j===null&&e.jsx("p",{"data-pick-first":"",className:"rounded-control border border-dashed border-input px-3 py-2 text-small text-muted",children:re.pickFirst}),!b&&e.jsx("p",{className:"text-small text-attention",children:re.noPasskey})]}),g&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:g}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ke,{variant:"ghost",className:"flex-1",disabled:p,onClick:a,children:re.cancel}),e.jsx(Ke,{variant:"primary",type:"submit",className:"flex-[2]",disabled:p||!M||v||T,children:s?re.save:re.create})]}),s&&r&&e.jsx(Ke,{disabled:p,onClick:r,children:re.folders}),s&&e.jsx(Ke,{variant:"ghost",className:"text-danger-fg!",disabled:p,onClick:l,children:re.remove})]})]})}function Ty({store:t,project:s,projects:n,agents:a,onClose:l}){var y;const r=f.useId(),o=!!((y=me(t).device)!=null&&y.confirm),i=n.filter(k=>k.id!==s.id),[c,x]=f.useState(null),[u,m]=f.useState(!1),[p,h]=f.useState(null),g=()=>{m(!0),h(null),t.deleteProject(s.id,c).then(k=>{m(!1),k.status==="applied"?l():h(vl(k))})};return e.jsxs(dt,{labelledBy:`${r}-title`,onClose:()=>{u||l()},children:[e.jsx("h2",{id:`${r}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:re.deleteTitle(s.name)}),e.jsx("p",{className:"text-body text-muted",children:re.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:re.deleteWhere}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:`${r}-move`,checked:c===null,onChange:()=>x(null)}),re.noProject]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:`${r}-move`,checked:c!==null,disabled:i.length===0,onChange:()=>{var k;return x(((k=i[0])==null?void 0:k.id)??null)}}),re.moveTo]}),c!==null&&e.jsx("select",{className:yl,"aria-label":re.target,value:c,onChange:k=>x(k.target.value),children:i.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?re.passkey:re.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(Ke,{variant:"ghost",className:"flex-1",disabled:u,onClick:l,children:re.cancel}),e.jsx(Ke,{variant:"primary",className:"flex-[2]",disabled:u||!o,onClick:g,children:re.confirmDelete})]})]})}const _y=t=>t.machine==="local"?re.thisPc:t.label??t.machine,Iy=t=>t.split("/").filter(Boolean).at(-1)??"/",Kn="flex items-center gap-3 border-b border-line px-3 py-2.5 last:border-b-0";function Ly({store:t,project:s,onClose:n}){var S;const a=f.useId(),l=me(t),[r,o]=f.useState(!1),[i,c]=f.useState(!1),[x,u]=f.useState(null);f.useEffect(()=>{t.requestProjectFolders(s.id)},[t,s.id]);const m=l.projectFolders[s.id],p=!!((S=l.device)!=null&&S.confirm),h=(b,j)=>{c(!1),b.status==="applied"?(t.requestProjectFolders(s.id),j()):u(vl(b))},g=b=>{c(!0),u(null),t.removeFolder(s.id,b.machine,b.path).then(j=>h(j,()=>{}))},y=b=>{c(!0),u(null),t.addFolder(s.id,b).then(j=>h(j,()=>o(!1)))},k=()=>{i||n()};if(r){const b=Array.isArray(m)?m:[];return e.jsxs(dt,{labelledBy:`${a}-title`,onClose:k,children:[e.jsx("h2",{id:`${a}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:re.pickTitle}),e.jsx(vx,{store:t,busy:i,skip:j=>b.some(N=>N.machine==="local"&&N.path===j),rowLabel:re.addShort,rowAria:re.addThisLabel,onPick:y,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?re.folderPasskey:re.noPasskey}),error:x,pickLabel:re.addThis,pickAria:re.addThisLabel,pickDisabled:!p,onBack:()=>{o(!1),u(null)}})]})}return e.jsxs(dt,{labelledBy:`${a}-title`,onClose:k,children:[e.jsx("h2",{id:`${a}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:re.foldersTitle(s.name)}),m===void 0?e.jsx("p",{role:"status",className:"text-small text-muted",children:re.foldersLoading}):m==="gone"?e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:re.errors.stale}):m.length===0?e.jsx("p",{className:"text-body text-muted",children:re.foldersNone}):e.jsx("ul",{className:"flex max-h-[45dvh] flex-col overflow-y-auto rounded-control border border-line",children:m.map(b=>e.jsxs("li",{className:Kn,children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"font-medium",children:Iy(b.path)}),e.jsxs("span",{className:"font-mono text-meta break-all text-muted",children:[b.path," · ",_y(b)]})]}),e.jsx(Ke,{size:"sm",variant:"ghost","aria-label":re.removeFolderLabel(b.path),disabled:i||!l.fresh||m.length===1,onClick:()=>g(b),children:re.removeFolder})]},`${b.machine}
18
18
  ${b.path}`))}),Array.isArray(m)&&m.length===1&&e.jsx("p",{"data-last-folder":"",className:"rounded-control border border-dashed border-input px-3 py-2 text-small text-muted",children:re.lastFolder}),x&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:x}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ke,{variant:"ghost",className:"flex-1",disabled:i,onClick:n,children:re.close}),e.jsxs(Ke,{variant:"primary",className:"flex-[2]",disabled:i||!l.fresh||m==="gone",onClick:()=>{u(null),o(!0)},children:[e.jsx(q,{name:"plus",className:"size-4"}),re.addFolder]})]})]})}function vx({store:t,busy:s,skip:n,rowLabel:a,rowAria:l,onPick:r,note:o,error:i,pickLabel:c,pickAria:x,pickDisabled:u,onBack:m}){const p=me(t),[h,g]=f.useState(null);f.useEffect(()=>{t.requestRecentFolders(),t.listFolder()},[t]);const y=p.folderListing,k=y&&(h===null||y.path===h)?y:null,S=j=>{g(j),t.listFolder(j)},b=(p.recentFolders??[]).filter(j=>!n(j));return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex max-h-[55dvh] flex-col gap-3 overflow-y-auto",children:[h===null&&b.length>0&&e.jsxs("section",{"aria-label":re.recents,className:"flex flex-col gap-1.5",children:[e.jsx("h3",{className:"text-small text-muted",children:re.recents}),e.jsx("ul",{className:"flex flex-col rounded-control border border-line",children:b.map(j=>e.jsxs("li",{className:Kn,children:[e.jsx("span",{className:"min-w-0 flex-1 font-mono text-small break-all",children:j}),e.jsx(Ke,{size:"sm","aria-label":l(j),disabled:s||u,onClick:()=>r(j),children:a})]},j))})]}),e.jsxs("section",{"aria-label":re.browse,className:"flex flex-col gap-1.5",children:[e.jsx("h3",{className:"text-small text-muted",children:re.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:re.folderErrors[k.error]}),e.jsxs("ul",{className:"flex flex-col rounded-control border border-line",children:[k.parent&&e.jsx("li",{className:Kn,children:e.jsxs("button",{type:"button",className:"flex min-h-10 flex-1 items-center gap-2 text-left",onClick:()=>S(k.parent),children:[e.jsx(q,{name:"back",className:"size-4"}),re.parent]})}),k.entries.map(j=>{const N=k.repos.find($=>$.name===j);return e.jsx("li",{className:Kn,children:e.jsxs("button",{type:"button","aria-label":re.open(j),className:"flex min-h-10 min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>S(`${k.path==="/"?"":k.path}/${j}`),children:[e.jsx("span",{className:"truncate",children:j}),N&&e.jsxs("span",{className:"flex-none rounded-full bg-raised px-2 text-meta text-muted",children:["⎇ ",N.branch]})]})},j)}),!k.error&&k.entries.length===0&&e.jsx("li",{className:"px-3 py-2.5 text-small text-muted",children:re.empty})]}),k.cut&&e.jsx("p",{className:"text-meta text-muted",children:re.cut})]}):e.jsx("p",{role:"status",className:"text-small text-muted",children:re.loadingFolder})]})]}),e.jsx("p",{className:"text-small text-muted",children:re.onlyThisPc}),o,i&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:i}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ke,{variant:"ghost",className:"flex-1",disabled:s,onClick:m,children:re.back}),e.jsx(Ke,{variant:"primary",className:"flex-[2]",disabled:s||u||!k||!!k.error,"aria-label":k?x(k.path):c,onClick:()=>{k&&r(k.path)},children:c})]})]})}function Oy({store:t}){var k;const s=me(t),[n,a]=f.useState(null),[l,r]=f.useState(null),[o,i]=f.useState(null),[c,x]=f.useState(!1),[u,m]=f.useState(null);if(!((k=s.daemon)!=null&&k.projectEdit)||!s.daemon.atelier)return null;const p=s.projects,h=S=>[...s.sessions.values()].filter(b=>b.projectId===S&&b.state!=="exited").length,g=!s.fresh||c,y=(S,b)=>{x(!0),m(null),t.orderProjects(My(p.map(j=>j.id),S,b)).then(j=>{x(!1),j.status!=="applied"&&m(vl(j))})};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:re.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:re.none}),p.map((S,b)=>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(Ey,{color:S.color}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate font-medium",children:S.name}),e.jsx("span",{className:"text-small text-muted",children:re.agents(h(S.id))})]}),e.jsx(Po,{label:re.up(S.name),disabled:g||b===0,onClick:()=>y(b,-1),children:e.jsx(q,{name:"arrowUp",className:"size-4"})}),e.jsx(Po,{label:re.down(S.name),disabled:g||b===p.length-1,onClick:()=>y(b,1),children:e.jsx(q,{name:"arrowUp",className:"size-4 rotate-180"})}),e.jsx(Ke,{size:"sm","aria-label":re.editLabel(S.name),disabled:!s.fresh,onClick:()=>a(S),children:re.edit})]},S.id))]}),e.jsxs(Ke,{disabled:!s.fresh,onClick:()=>a("new"),children:[e.jsx(q,{name:"plus",className:"size-4"}),re.add]}),u&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:u}),e.jsx("p",{className:"text-small text-muted",children:s.daemon.projectFolders?re.folders_note:re.folders_note_old}),n!==null&&e.jsx(Ay,{store:t,project:n==="new"?null:n,projects:p,onClose:()=>a(null),onDelete:()=>{n!=="new"&&(r(n),a(null))},onFolders:s.daemon.projectFolders?()=>{n!=="new"&&(i(n),a(null))}:null}),o&&e.jsx(Ly,{store:t,project:o,onClose:()=>i(null)}),l&&e.jsx(Ty,{store:t,project:l,projects:p,agents:h(l.id),onClose:()=>r(null)})]})}const ns=d.connection.device,kx=t=>{var s,n;return t??Jm(((s=globalThis.navigator)==null?void 0:s.userAgent)??"",((n=globalThis.navigator)==null?void 0:n.maxTouchPoints)??0)};function Dy({store:t,pinned:s}){const n=me(t),[a,l]=f.useState(null),[r,o]=f.useState(!1),i=n.device;if(!(i!=null&&i.id))return null;const c=kx(i.name),x=s?new Date(s.pinnedAt).toLocaleDateString(lt,{day:"numeric",month:"short",year:"numeric"}):null,u=(a==null?void 0:a.trim())??"",m=()=>{if(!(!u||u.length>Sl)){if(t.renameDevice(u)===null){o(!0);return}o(!1),l(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:ns.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(q,{name:i.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:c}),x&&e.jsx("p",{className:"text-meta text-muted",children:ns.linkedOn(x)})]}),e.jsx(Ke,{size:"sm","aria-label":ns.renameLabel(c),onClick:()=>{o(!1),l(c)},children:ns.rename})]}),r&&e.jsx("p",{role:"status",className:"text-small text-danger-fg",children:ns.failed}),e.jsx("p",{className:"text-small text-muted",children:ns.others}),a!==null&&e.jsxs(dt,{labelledBy:"rename-title",onClose:()=>l(null),children:[e.jsx("h2",{id:"rename-title",className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:ns.sheetTitle}),e.jsx("p",{className:"text-body text-muted",children:ns.sheetBody}),e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:p=>{p.preventDefault(),m()},children:[e.jsxs("label",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"sr-only",children:ns.field}),e.jsx("input",{className:yl,value:a,maxLength:Sl,autoFocus:!0,"aria-describedby":"rename-count",onChange:p=>l(p.target.value)}),e.jsxs("span",{id:"rename-count",className:"self-end text-meta text-muted",children:[a.length,"/",Sl]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ke,{variant:"ghost",className:"flex-1",onClick:()=>l(null),children:ns.cancel}),e.jsx(Ke,{variant:"primary",type:"submit",className:"flex-[2]",disabled:!u,children:ns.save})]})]})]})]})}const nt=d.connection,Ws=d.settings,Fy=()=>[{value:"system",label:nt.themes.system},{value:"light",label:nt.themes.light},{value:"dark",label:nt.themes.dark}],zy=t=>t==="ready"?nt.states.online:t==="handshaking"?nt.states.connecting:nt.states.offline;function Py({store:t,login:s,relay:n,pinned:a,linkState:l,build:r,onSignOut:o,fetchImpl:i,section:c}){var y,k,S;const x=me(t),u=ym(),m=Oc();f.useEffect(()=>{var b;c==="link"&&((b=document.getElementById("link-title"))==null||b.scrollIntoView({block:"start"}))},[c]);const p=(a==null?void 0:a.name)??((y=x.daemon)==null?void 0:y.name)??null,h=!!x.daemon&&!!r&&Bc(x.daemon.version,r.version),g=[[nt.account,s?d.account(s):nt.unknown,!1],[nt.relay,n,!0],[nt.pc,p??nt.unknown,!1],[nt.pcFingerprint,a?ea(a.fingerprint):nt.unknown,!0],[nt.status,zy(l),!1],[nt.version,(r==null?void 0:r.version)??nt.none,!0],[nt.appFingerprint,r?hx(r.fingerprint):nt.none,!0],[nt.pcVersion,((k=x.daemon)==null?void 0:k.version)??nt.none,!0,h?"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(is,{fallback:{name:"atoi"},label:nt.back}),e.jsx("h1",{className:"text-base font-semibold",children:nt.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(Dy,{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:Ws.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:Ws.theme}),e.jsx(Jn,{name:"theme",legend:Ws.theme,options:Fy(),value:u,onChange:b=>Nm(b),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:Ws.lang}),e.jsx(Jn,{name:"lang",legend:Ws.lang,options:km.map(b=>({value:b,label:Ws.langs[b],lang:b})),value:m,onChange:vm,fit:!0})]}),e.jsx(Sy,{})]}),((S=x.device)==null?void 0:S.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:Ws.notifications}),e.jsx("dl",{className:"flex flex-col rounded-[10px] border border-line bg-surface text-body",children:e.jsx(xy,{store:t,fetchImpl:i})}),e.jsx(ky,{store:t})]}),e.jsx(wy,{store:t}),e.jsx(Oy,{store:t}),e.jsx(gy,{store:t,appVersion:(r==null?void 0:r.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:nt.section}),e.jsxs("dl",{className:"flex flex-col rounded-[10px] border border-line bg-surface text-body",children:[g.map(([b,j,N,$])=>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:b}),e.jsx("dd",{className:`min-w-0 text-right break-words ${N?"font-mono":""} ${$??""}`,children:j})]},b)),e.jsx(Ah,{store:t}),e.jsx(Lh,{store:t})]})]}),e.jsx($y,{store:t}),e.jsx("div",{className:"flex-grow","aria-hidden":"true"}),e.jsx("button",{type:"button",onClick:o,className:mt,children:nt.signOut})]})]})}function By({onOther:t}){return e.jsxs(Et,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(bs,{size:80,frozen:!0}),e.jsx("h1",{className:qt,children:d.denied.title}),e.jsx("p",{className:"max-w-[300px] text-muted",children:d.denied.bodyNoLogin})]}),e.jsx(Rt,{}),e.jsx("button",{type:"button",onClick:t,className:mt,children:d.denied.other})]})}const Qt=d.keyChanged,qy=t=>{const s=new Date(t);return Number.isNaN(s.getTime())?d.connection.unknown:s.toLocaleDateString(lt,{day:"numeric",month:"short"})};function Hy({pcName:t,known:s,received:n,onRelink:a,onSignOut:l}){return e.jsxs(Et,{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:Ba,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:qt,children:Qt.title(t??d.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:s?Qt.knownDetail(ea(s.fingerprint,2),qy(s.pinnedAt)):d.connection.unknown}),e.jsx("dt",{className:"text-muted",children:Qt.received}),e.jsx("dd",{className:"font-mono",children:n?Qt.receivedDetail(ea(n,2)):d.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(Rt,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:a,className:St,children:Qt.relink}),e.jsx("button",{type:"button",onClick:l,className:mt,children:Qt.signOut})]})]})}const Uy="/auth/github/start";function Wy(t){return t==="denied"?d.login.errors.denied:t==="bad_state"||t==="error"?d.login.errors.failed:null}const Ky=[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 Vy({server:t,error:s}){return e.jsxs(Et,{children:[e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(bs,{size:88}),e.jsx("h1",{className:"text-display leading-[34px] font-bold tracking-[-.025em]",children:d.login.title}),e.jsx("p",{className:"max-w-[300px] text-muted",children:d.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:`${Ba} 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})]}),s&&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:s}),e.jsx(Rt,{}),e.jsx("ul",{className:"flex flex-col gap-3.5 text-fg/85",children:d.login.notes.map((n,a)=>e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx("svg",{className:`${Ba} text-fg`,viewBox:"0 0 24 24","aria-hidden":"true",children:Ky[a]}),e.jsx("span",{children:n})]},n))}),e.jsxs("a",{href:Uy,className:St,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"})}),d.login.github]})]})}function Gy({onHere:t}){return e.jsxs(Et,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:qt,children:d.replaced.title}),e.jsx("p",{className:"text-muted",children:d.replaced.body})]}),e.jsx(Rt,{}),e.jsx("button",{type:"button",onClick:t,className:mt,children:d.replaced.here})]})}const Lr=t=>e.jsx("a",{href:ne({name:"atoi"}),className:Fe({size:"sm"}),children:t});function Mo({label:t,children:s}){return It()?e.jsx("section",{"aria-label":t,className:"pt-[34px]",children:s}):e.jsx(os,{label:t,children:s})}function Xy(){const{pc:t}=Ut();return e.jsxs(Rs,{title:d.prs.title,subtitle:d.prs.subtitle,children:[e.jsx(Mo,{label:d.prs.title,children:e.jsx(Jt,{glyph:e.jsx(q,{name:"pr",className:"size-[22px]"}),title:d.prs.notSent(Ht(t)),body:d.prs.notSentBody})}),e.jsx("p",{className:"text-small text-muted",children:d.prs.tracked})]})}function Yy(){const{pc:t}=Ut();return e.jsx(Rs,{title:d.rigs.title,subtitle:d.rigs.subtitle,children:e.jsx(Mo,{label:d.rigs.title,children:e.jsx(Jt,{glyph:e.jsx(q,{name:"rigs",className:"size-[22px]"}),title:d.rigs.notSent(Ht(t)),body:d.rigs.notSentBody,action:Lr(d.rigs.seeAtoi)})})})}function oc({onClose:t}={}){const{pc:s}=Ut();return t?e.jsxs(e.Fragment,{children:[e.jsx(px,{frozen:!0,onClose:t}),e.jsx("section",{"aria-label":d.chat.title,className:"pt-[34px]",children:e.jsx(Jt,{framed:!1,glyph:e.jsx(bs,{size:64,frozen:!0}),title:d.chat.unavailable.title(Ht(s)),body:d.chat.unavailable.body,action:Lr(d.chat.unavailable.seeAtoi)})})]}):e.jsx(Rs,{title:d.chat.title,children:e.jsx(Mo,{label:d.chat.title,children:e.jsx(Jt,{framed:!1,glyph:e.jsx(bs,{size:64,frozen:!0}),title:d.chat.unavailable.title(Ht(s)),body:d.chat.unavailable.body,action:Lr(d.chat.unavailable.seeAtoi)})})})}function ic({icon:t,title:s,body:n}){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(q,{name:t,className:"size-[18px]"}),e.jsx("h2",{className:"mt-2.5 text-[17px] font-semibold text-fg",children:s}),e.jsx("p",{className:"max-w-[320px] text-small",children:n})]})}function Qy({open:t,onClose:s,children:n}){const a=f.useRef(null),l=f.useRef(s);l.current=s;const r=f.useRef(null);return f.useEffect(()=>{const o=a.current;if(!o)return;const i=c=>{t&&c.target instanceof HTMLElement&&c.target.tagName==="MAIN"&&(r.current=c.target.scrollTop)};return o.addEventListener("scroll",i,!0),()=>o.removeEventListener("scroll",i,!0)},[t]),f.useEffect(()=>{var c;if(!t)return;const o=(c=a.current)==null?void 0:c.querySelector("main");o&&r.current!==null&&(o.scrollTop=r.current);const i=x=>{x.key!=="Escape"||x.defaultPrevented||x.isComposing||$d()||(x.preventDefault(),l.current())};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[t]),e.jsx("aside",{ref:a,hidden:!t,"aria-label":d.chat.title,"data-ledge-pane":"",className:"lpane",children:n})}const wx="ledge.mobile.ledgePane",Or=new Set;let Dr=null;function Zy(t){var s;if(Dr!==null)return Dr;try{return((s=Qe(t))==null?void 0:s.getItem(wx))==="open"}catch{return!1}}function cc(t,s){var n;Dr=t;try{(n=Qe(s))==null||n.setItem(wx,t?"open":"closed")}catch{}for(const a of Or)a()}const Jy=t=>(Or.add(t),()=>{Or.delete(t)});function eN(t){return f.useSyncExternalStore(Jy,()=>Zy(t),()=>!1)}function dc({store:t,id:s,onDone:n}){var p,h,g;const a=me(t),l=Fs(),r=(p=a.asks)==null?void 0:p.find(y=>y.id===s),o=f.useRef(void 0);r&&(o.current=r);const i=r??o.current,c=n??(()=>al({name:"atoi"})),x=((h=a.device)==null?void 0:h.confirm)===!0&&l,u=l&&((g=a.device)==null?void 0:g.confirm)!==!0,m=i?e.jsx(qd,{store:t,ask:i,end:dd(s,a.ops),fresh:a.fresh,ghost:!r,canConfirm:x,enroll:u,onGone:c,full:!0}):a.asks===null||!a.fresh?e.jsx("p",{role:"status",className:"text-body text-muted",children:d.loading}):e.jsx(at,{tone:"gone",title:d.asks.already});return e.jsxs(e.Fragment,{children:[e.jsx(oa,{title:d.atoi.kindName.rig,fallback:{name:"atoi"},label:d.detail.back,link:Mn(a)}),e.jsx("main",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain pt-4 pb-[22px]",children:m})]})}const $a=d.storage;function tN({onRetry:t,onReload:s}){return e.jsxs(Et,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:qt,children:$a.title}),e.jsx("p",{className:"text-muted",children:$a.body})]}),e.jsx(Rt,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:t,className:St,children:$a.retry}),e.jsx("button",{type:"button",onClick:s,className:mt,children:$a.reload})]})]})}const sN=30,nN=/^(?:\x1b\[\??\d+(?:;\d+)*[Rc]|\x1b\[[?>][\d;]*c|\x1b\][0-9]+;rgb:[0-9a-f/]+(?:\x07|\x1b\\)|\x1b\[[IO])$/i,aN={phase:"connecting",cols:80,rows:24,readOnly:!1,held:null,holding:!1,released:null,exit:null,refused:null,holdRefused:null};function lN(t){if(t.length<=qo)return t;let s=qo;const n=t.charCodeAt(s-1);return n>=55296&&n<=56319&&(s-=1),t.slice(0,s)}function rN(t,s){return`\x1B[H\x1B[2J\x1B[3J${t.replace(/\n/g,`\r
19
- `)}\x1B[${s.y+1};${s.x+1}H`}class oN{constructor(s,n,a,l=()=>crypto.randomUUID()){Pt(this,"view",aN);Pt(this,"listeners",new Set);Pt(this,"tid",null);Pt(this,"openOp",null);Pt(this,"holdOp",null);Pt(this,"seq",0);Pt(this,"resyncing",!1);Pt(this,"n",0);Pt(this,"pending","");Pt(this,"timer",null);Pt(this,"wasReady",!1);Pt(this,"offs",[]);Pt(this,"stopped",!1);this.wire=s,this.sessionId=n,this.screen=a,this.uuid=l}get state(){return this.view}subscribe(s){return this.listeners.add(s),()=>{this.listeners.delete(s)}}start(){this.offs.push(this.wire.onMessage(s=>this.onMessage(s))),this.offs.push(this.wire.subscribe(()=>this.onLink())),this.wasReady=this.wire.ready(),this.wasReady?this.open():this.set({phase:"offline"})}stop(){var s;if(!this.stopped){this.stopped=!0,this.flushKeys(),this.tid&&this.wire.ready()&&this.wire.send({type:"term.close",tid:this.tid});for(const n of this.offs.splice(0))n();this.timer&&clearTimeout(this.timer),(s=this.holdOp)==null||s.done("invalid"),this.holdOp=null}}hold(s){var l;if(!this.tid||this.view.phase!=="live"||this.view.readOnly||!this.wire.ready())return Promise.resolve("invalid");(l=this.holdOp)==null||l.done("invalid");const n=this.uuid(),a=this.tid;return new Promise(r=>{this.holdOp={op:n,done:o=>{this.holdOp=null,this.set({holding:!1,holdRefused:o}),r(o)}},this.set({holding:!0,holdRefused:null,released:null}),this.wire.send({type:"term.hold",op:n,tid:a,assertion:s})})}release(){!this.tid||!this.view.held||(this.flushKeys(),this.wire.send({type:"term.release",tid:this.tid}))}type(s){!this.view.held||!this.tid||nN.test(s)||(this.pending+=s,this.set({held:{...this.view.held,lastKey:Date.now()}}),this.timer===null&&(this.timer=setTimeout(()=>{this.timer=null,this.flushKeys()},sN)))}flushKeys(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),!this.tid||!this.pending||!this.wire.ready()){this.pending="";return}for(;this.pending;){const s=lN(this.pending);this.pending=this.pending.slice(s.length),this.wire.send({type:"term.input",tid:this.tid,n:this.n++,data:s})}}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 n;const s=this.wire.ready();if(!(s===this.wasReady||this.stopped)){if(this.wasReady=s,!s){this.pending="",(n=this.holdOp)==null||n.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(s){if(!this.stopped)switch(s.type){case"term.opened":{if(!(s.op!==void 0?s.op===this.openOp:s.tid===this.tid))return;this.tid=s.tid,this.seq=s.seq,this.resyncing=!1,this.screen.reset(s.cols,s.rows),this.screen.write(rN(s.screen,s.cursor)),this.set({phase:"live",cols:s.cols,rows:s.rows,readOnly:s.readOnly===!0});return}case"term.output":if(s.tid!==this.tid||this.resyncing)return;if(s.seq!==this.seq){this.resyncing=!0,this.wire.send({type:"term.resync",tid:s.tid});return}this.seq++,this.screen.write(s.data);return;case"term.size":if(s.tid!==this.tid)return;this.screen.resize(s.cols,s.rows),this.set({cols:s.cols,rows:s.rows});return;case"term.held":if(s.tid!==this.tid)return;this.set({held:{until:Date.parse(s.until),lastKey:Date.now()},released:null});return;case"term.released":if(s.tid!==this.tid)return;this.pending="",this.set({held:null,released:s.why==="asked"?null:s.why});return;case"term.exit":if(s.tid!==this.tid)return;this.tid=null,this.set({phase:"ended",held:null,exit:s.why});return;case"operation.result":if(s.op===this.openOp&&s.status==="rejected"){this.openOp=null,this.set({phase:"refused",refused:s.reason??"invalid"});return}if(s.op===this.openOp&&s.status==="failed"){this.openOp=null,this.set({phase:"refused",refused:"unavailable"});return}this.holdOp&&s.op===this.holdOp.op&&s.status!=="received"&&this.holdOp.done(s.status==="applied"?null:s.reason??"invalid");return;default:return}}set(s){this.view={...this.view,...s};for(const n of[...this.listeners])n()}}const iN=11,yv=6,Nv=16,uc=5*6e4,cN={up:"A",down:"B",right:"C",left:"D"};function dN(t,s){switch(t){case"esc":return"\x1B";case"tab":return" ";case"enter":return"\r";case"interrupt":return"";default:return`${s?"\x1BO":"\x1B["}${cN[t]}`}}function uN(t,s){let n=t;if(s.ctrl&&[...t].length===1){const a=t.toUpperCase().charCodeAt(0);a>=64&&a<=95?n=String.fromCharCode(a-64):t===" "?n="\0":t==="?"&&(n="")}return s.alt?`\x1B${n}`:n}function xN(t){const s=t.findIndex(a=>/❯\s*1\.\s/.test(a));if(s<0)return[];const n=[];for(const a of t.slice(s,s+12)){const l=/^\s*(?:❯\s*)?(\d)\.\s+(.*)$/.exec(a);if(!l)continue;if(l[1]!==String(n.length+1))break;const r=l[2].trim(),o=/^(oui,?\s+toujours|yes,?\s+and\s+don.t\s+ask)/i.test(r)?"always":/^(oui|yes)\b/i.test(r)?"yes":/^(non|no)\b/i.test(r)?"no":null;n.push({digit:l[1],word:o})}return n}const Me=d.terminal.live2,Sx="ledge.mobile.terminalView",mN=t=>{var s;try{return((s=Qe(t))==null?void 0:s.getItem(Sx))==="fit"?"fit":"readable"}catch{return"readable"}},pN=(t,s)=>{var n;try{(n=Qe(s))==null||n.setItem(Sx,t)}catch{}};function fN(t){return{send:s=>{t.send(s).catch(()=>{})},onMessage:s=>t.onMessage(s),ready:()=>t.state()==="ready",subscribe:s=>t.subscribe(s)}}const Yl=new Map,hN=t=>{const s=Math.max(0,Math.ceil(t/1e3));return`${Math.floor(s/60)}:${String(s%60).padStart(2,"0")}`},gN=t=>wm(()=>import("./xterm-CDPb9wXW.js"),__vite__mapDeps([0,1,2,3,4])).then(s=>s.createXterm(t));function bN({store:t,link:s,session:n,storage:a,makeScreen:l,forge:r}){var Ge,pt,ft,ut;const o=me(t),i=Xt(),c=f.useRef(null),x=f.useRef(null),[u,m]=f.useState(null),[p,h]=f.useState(null),[g,y]=f.useState(()=>mN(a)),[k,S]=f.useState(!1),[b,j]=f.useState({ctrl:"off",alt:"off"}),[N,$]=f.useState(!1),[C,M]=f.useState(""),[v,A]=f.useState(!1),[T,R]=f.useState(null),[P,_]=f.useState([]),[D,E]=f.useState(!1),z=It(),K=il(),L=f.useRef(!0),W=f.useRef(b);W.current=b,f.useEffect(()=>{const Y=c.current;if(!Y)return;let Re=!1,ke=null;const ie=Ae=>{if(Re){Ae.dispose();return}const Je=new oN(fN(s),n.id,Ae);Ae.onData(xt=>Je.type(ae(xt))),Je.start(),ke={c:Je,xt:Ae},m(Je),h(Ae)};return l?ie(l(Y)):gN(Y).then(ie),()=>{Re=!0,ke==null||ke.c.stop(),ke==null||ke.xt.dispose()}},[s,n.id,l]);const ae=Y=>{const Re=W.current;if(Re.ctrl==="off"&&Re.alt==="off")return Y;const ke=uN(Y,{ctrl:Re.ctrl!=="off",alt:Re.alt!=="off"});return j(ie=>({ctrl:ie.ctrl==="armed"?"off":ie.ctrl,alt:ie.alt==="armed"?"off":ie.alt})),ke},U=f.useSyncExternalStore(Y=>u?u.subscribe(Y):()=>{},()=>(u==null?void 0:u.state)??null),O=!!(U!=null&&U.held);f.useEffect(()=>{p==null||p.setInput(O),O&&(L.current=!0,p==null||p.focus())},[p,O]),f.useEffect(()=>{!p||!x.current||!U||p.setFont(g==="fit"?p.fitFont(x.current.clientWidth-16):iN)},[p,g,U==null?void 0:U.cols]),f.useEffect(()=>{if(!p)return;const Y=x.current,Re=()=>{if(!Y)return;const ke=Yl.get(n.id);if(ke&&Y.scrollWidth>=ke.left+Y.clientWidth&&Y.scrollHeight>=ke.top+Y.clientHeight&&(Yl.delete(n.id),Y.scrollLeft=ke.left,Y.scrollTop=ke.top,L.current=!1),L.current&&g==="readable"){const{x:Ae,cellWidth:Je}=p.cursor(),xt=Ae*Je;(xt<Y.scrollLeft||xt>Y.scrollLeft+Y.clientWidth-Je*4)&&(Y.scrollLeft=Math.max(0,xt-Y.clientWidth/2))}R(Y.scrollWidth>Y.clientWidth+1?{left:Y.scrollLeft/Y.scrollWidth,width:Y.clientWidth/Y.scrollWidth}:null);const ie=xN(p.rows());_(Ae=>Ae.length===ie.length&&Ae.every((Je,xt)=>Je.digit===ie[xt].digit&&Je.word===ie[xt].word)?Ae:ie)};p.onDrawn(Re),Re()},[p,g]);const B=()=>{const Y=x.current;Y&&Yl.set(n.id,{left:Y.scrollLeft,top:Y.scrollTop})},Z=()=>{const Y=x.current;Y&&R(Y.scrollWidth>Y.clientWidth+1?{left:Y.scrollLeft/Y.scrollWidth,width:Y.clientWidth/Y.scrollWidth}:null)},H=f.useRef(null),X=Y=>Math.hypot(Y[0].clientX-Y[1].clientX,Y[0].clientY-Y[1].clientY),te=Y=>{Y.touches.length===2&&p?H.current={d:X(Y.touches),px:p.font()}:L.current=!1},pe=Y=>{if(Y.touches.length!==2||!H.current||!p||!x.current)return;const Re=p.fitFont(x.current.clientWidth-16);p.setFont(Math.max(Re,H.current.px*(X(Y.touches)/H.current.d)))},ue=()=>{H.current=null},F=Y=>{y(Y),pN(Y,a),L.current=!0},w=Y=>{var Re,ke;if(!(!u||!p)){if(L.current=!0,Y==="ctrl"||Y==="alt"){j(ie=>({...ie,[Y]:ie[Y]==="off"?"armed":ie[Y]==="armed"?"locked":"off"}));return}if(Y==="line"){$(ie=>!ie);return}if(Y==="paste"){A(!1),(ke=(Re=navigator.clipboard)==null?void 0:Re.readText)==null||ke.call(Re).then(ie=>{ie?p.paste(ie):A(!0)},()=>A(!0));return}u.type(ae(dN(Y,p.appCursor())))}},I=()=>{!u||!C||(u.type(`${C.replace(/\r?\n/g,"\r")}\r`),M(""))},V=!!n.pending||n.state==="waiting_permission"||n.state==="waiting_input",ee=((Ge=n.pending)==null?void 0:Ge.kind)==="permission"||n.state==="waiting_permission",Q={name:"thread",sessionId:n.id},J=(U==null?void 0:U.phase)??"connecting",fe=J==="ended",be=J==="offline",tt=!!((pt=o.daemon)!=null&&pt.terminalInput)&&!(U!=null&&U.readOnly)&&n.readOnly!==!0,yt=O?Me.status.held:Me.status[J],Ze=U!=null&&U.released&&U.released!=="asked"?Me.released[U.released]:null,Le=(U==null?void 0:U.exit)==="gone"?Me.exit.gone(n.name):U!=null&&U.exit?Me.exit[U.exit]:null,de=U!=null&&U.refused?Me.refused[U.refused]??Me.refused.unavailable:null,he=U!=null&&U.holdRefused?Me.holdRefused[U.holdRefused]??d.confirm.refused[U.holdRefused]??null:null,$e=U!=null&&U.held?Math.min(uc,Math.min(U.held.lastKey+uc,U.held.until)-i):0,Oe=O&&$e<=6e4,rt=ee?P:[];return e.jsxs(e.Fragment,{children:[e.jsx(dx,{store:t,session:n,current:"terminal",onLeave:B,model:D,onModel:E,display:J==="live"||be?{value:g==="readable"?Me.readable:Me.fit,onToggle:()=>F(g==="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 ${O?"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:n.project}),e.jsx("span",{role:"status",className:`flex-none rounded-[6px] px-2 py-0.5 font-medium ${O?"bg-info text-white":be?"text-attention":J==="live"?"text-ok":"text-muted"}`,children:Oe?Me.heldLeft(hN($e)):yt}),e.jsx("span",{className:"flex-1"}),O?e.jsx("button",{type:"button",onClick:()=>u==null?void 0:u.release(),className:"flex-none underline",children:Me.release}):U&&!fe&&J!=="refused"&&e.jsxs("span",{className:"flex-none font-mono",children:[U.cols," × ",U.rows]})]}),e.jsx("div",{ref:x,onScroll:Z,onTouchStart:te,onTouchMove:pe,onTouchEnd:ue,"aria-label":Me.screen(n.name),className:`relative min-h-0 flex-1 overflow-auto rounded-b-card bg-term-bg p-2 ${O?"border-2 border-t-0 border-info":"border border-t-0 border-line"} ${be||fe?"opacity-45":""}`,children:e.jsx("div",{ref:c,"data-term":"",className:"w-max"})}),T&&!O&&g==="readable"&&e.jsx("div",{"aria-label":Me.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:`${T.left*100}%`,width:`${T.width*100}%`}})})]}),O?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:Me.pasteFailed}),e.jsxs("div",{role:"toolbar","aria-label":Me.keys,className:"flex gap-1.5 overflow-x-auto py-1.5",children:[rt.map(Y=>e.jsx("button",{type:"button",onPointerDown:Re=>Re.preventDefault(),onClick:()=>{L.current=!0,u==null||u.type(Y.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:Y.word?`${Y.digit} ${Me.contextKeys[Y.word]}`:Y.digit},Y.digit)),(z?["interrupt","paste"]:N?["esc","tab","up","down","line"]:["esc","tab","ctrl","alt","left","up","down","right","enter","interrupt","paste","line"]).map(Y=>{const Re=Y==="ctrl"||Y==="alt"?b[Y]!=="off":Y==="line"?N:!1,ke=Y==="ctrl"||Y==="alt"||Y==="line"?Re:void 0,ie=(Y==="ctrl"||Y==="alt")&&b[Y]!=="off"?`, ${b[Y]==="locked"?Me.locked:Me.armed}`:"";return e.jsx("button",{type:"button","aria-pressed":ke,"aria-label":`${Me.keyLabel[Y]}${ie}`,onPointerDown:Ae=>Ae.preventDefault(),onClick:()=>w(Y),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 ${Re?"border-transparent bg-fg text-bg":"border-input bg-surface text-fg"}`,children:Me.key[Y]},Y)}),z&&e.jsx("span",{className:"ml-auto flex-none self-center pl-2 text-[12px] text-muted",children:Me.hardware})]}),N&&!z&&e.jsxs("form",{className:"flex items-center gap-2",onSubmit:Y=>{Y.preventDefault(),I()},children:[e.jsx("span",{"aria-hidden":"true",className:"font-mono text-muted",children:"$"}),e.jsx("input",{id:"term-line",value:C,onChange:Y=>M(Y.target.value),"aria-label":Me.lineField,placeholder:Me.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:!C,"aria-label":Me.lineSend,className:Pe({variant:"primary",size:"sm"}),children:Me.lineGo})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("footer",{className:"flex flex-none flex-col gap-2 pt-2.5 pb-2.5",children:[(Ze||Le||de||he)&&e.jsx("p",{role:"status",className:"text-center text-small text-muted",children:de??Le??he??Ze}),fe?e.jsx("a",{href:ne(Q),className:Pe({block:!0}),children:Me.back}):tt&&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:Me.alsoInThread}),e.jsxs("button",{type:"button",disabled:J!=="live"||(U==null?void 0:U.holding),onClick:()=>S(!0),className:Pe({size:"sm",className:V?"flex-none":"ml-auto flex-none"}),children:[e.jsx(q,{name:"keyboard"}),U!=null&&U.released?Me.holdAgain:Me.hold]})]}):!be&&((ft=o.daemon)==null?void 0:ft.terminal)&&!(U!=null&&U.readOnly)&&n.readOnly!==!0&&e.jsx("p",{className:"text-center text-meta text-muted",children:Me.inputOff}),be&&e.jsx("p",{className:"text-center text-meta text-muted",children:Me.offlineHint})]}),e.jsx(Ju,{store:t,forge:r,session:n,wide:K,threshold:((ut=o.device)==null?void 0:ut.contextNear)??kn,onModel:()=>E(!0)})]}),k&&u&&e.jsx(jN,{store:t,session:n,onClose:()=>S(!1),hold:Y=>(S(!1),u.hold(Y),"sent")})]})}function jN({store:t,session:s,onClose:n,hold:a}){const{fresh:l,device:r}=me(t),o=!!(r!=null&&r.confirm),i=Yu(t,"terminal",s.id,l&&o,a),c=u=>Pe({variant:u,block:!0}),x=i.asking?d.confirm.asking:i.challenge?_t()?`${Me.go}`:Me.go:d.confirm.preparing;return e.jsxs(dt,{labelledBy:"hold-title",onClose:n,children:[e.jsx("h2",{id:"hold-title",className:"text-heading leading-[1.3] tracking-[-.5px]",children:Me.sheetTitle(s.name)}),o?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:Me.sheetBody}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:Me.sheetNote}),i.problem&&e.jsx(Xe,{title:d.confirm[i.problem],tone:"warning",role:"alert"}),i.needsNew?e.jsx("button",{type:"button",onClick:i.retry,className:c("primary"),children:d.confirm.retry}):e.jsxs("button",{type:"button",disabled:i.asking||!i.challenge,onClick:()=>{i.go()},className:c("primary"),children:[e.jsx(q,{name:"passkey"}),x]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{title:Me.unprotectedTitle,tone:"warning",role:"status",children:e.jsx("p",{children:Me.unprotectedBody})}),e.jsx("a",{href:ne({name:"connection"}),className:c("primary"),children:Me.openConnection})]}),e.jsx("button",{type:"button",onClick:n,className:c(),children:Me.cancel})]})}const $x="ledge.mobile.terminalSize",Cx=11,Mx=20,xc=12,yN=1e4,Ex=t=>Math.max(Cx,Math.min(Mx,t));function NN(t){var s;try{const n=Number((s=Qe(t))==null?void 0:s.getItem($x));return Number.isFinite(n)&&n>0?Ex(Math.round(n)):xc}catch{return xc}}function vN(t,s){var n;try{(n=Qe(s))==null||n.setItem($x,String(t))}catch{}}const mc=Tt({variant:"outline",className:"text-body font-medium"});function pc({store:t,link:s,sessionId:n,storage:a,forge:l}){var i;const r=me(t),o=r.sessions.get(n);return s&&o&&((i=r.daemon)!=null&&i.terminal)?e.jsx(bN,{store:t,link:s,session:o,forge:l,...a?{storage:a}:{}},n):e.jsx(kN,{store:t,sessionId:n,...a?{storage:a}:{}})}function kN({store:t,sessionId:s,storage:n}){const a=me(t),l=Xt(),{fresh:r,ops:o}=a,i=a.sessions.get(s),c=a.previews.get(s)??[],[x,u]=f.useState(()=>NN(n)),m=_=>u(D=>{const E=Ex(D+_);return vN(E,n),E}),[p,h]=f.useState(!1);f.useEffect(()=>()=>t.watch(null),[t,s]),f.useEffect(()=>{r&&t.watch(s)},[t,s,r]);const g=f.useRef(null);f.useEffect(()=>{const _=g.current;_&&(_.scrollTop=_.scrollHeight)},[c.length,c[c.length-1],x]);const y={name:"thread",sessionId:s},k=Mn(a);if(!i)return e.jsxs(e.Fragment,{children:[e.jsx(oa,{title:d.thread.title,fallback:y,label:d.terminal.back,link:k}),e.jsx("main",{className:"min-h-0 flex-1 pt-7 text-body text-muted",role:"status",children:!r&&a.syncedAt===null?d.thread.loading:d.terminal.unknown})]});const S=!!i.pending||i.state==="waiting_permission"||i.state==="waiting_input",b=!r,j=b?d.terminal.offline:S?d.terminal.waiting:d.terminal.live,N=Object.values(o).filter(_=>_.message.type==="session.interrupt"&&_.message.id===s).sort((_,D)=>_.at.localeCompare(D.at)).at(-1),$=N!==void 0&&ps(N.phase),C=i.state==="working",M=(N==null?void 0:N.phase)==="applied"&&(!C||l-Date.parse(N.at)<yN),v=C&&!b&&!S&&!$&&!M,A=b?d.terminal.why.offline:S?d.terminal.why.waiting:C?null:d.terminal.why.idle,T=()=>{v&&h(!t.interrupt(s))},R=(N==null?void 0:N.phase)==="sending"?d.terminal.sending:M?d.terminal.sent:d.terminal.interrupt(i.name),P=(N==null?void 0:N.phase)==="rejected"&&N.reason==="read_only"?d.terminal.readOnly:p||(N==null?void 0:N.phase)==="rejected"||(N==null?void 0:N.phase)==="failed"?d.terminal.fail:(N==null?void 0:N.phase)==="uncertain"&&!b?d.terminal.uncertain:null;return e.jsxs(e.Fragment,{children:[e.jsx(dx,{store:t,session:i,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:j}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",disabled:x<=Cx,onClick:()=>m(-1),"aria-label":d.terminal.smaller,className:mc,children:"A−"}),e.jsx("button",{type:"button",disabled:x>=Mx,onClick:()=>m(1),"aria-label":d.terminal.larger,className:mc,children:"A+"})]})]}),e.jsx("div",{ref:g,tabIndex:0,"aria-label":d.terminal.output,className:"mb-3 min-h-0 flex-1 overflow-auto rounded-card border border-line bg-term-bg p-4",children:c.length===0?e.jsx("p",{className:"text-small text-muted",children:d.terminal.empty}):e.jsx("pre",{"data-size":x,style:{fontSize:x},className:"m-0 w-max min-w-full font-mono leading-[1.5] whitespace-pre text-term-fg",children:c.join(`
19
+ `)}\x1B[${s.y+1};${s.x+1}H`}class oN{constructor(s,n,a,l=()=>crypto.randomUUID()){Pt(this,"view",aN);Pt(this,"listeners",new Set);Pt(this,"tid",null);Pt(this,"openOp",null);Pt(this,"holdOp",null);Pt(this,"seq",0);Pt(this,"resyncing",!1);Pt(this,"n",0);Pt(this,"pending","");Pt(this,"timer",null);Pt(this,"wasReady",!1);Pt(this,"offs",[]);Pt(this,"stopped",!1);this.wire=s,this.sessionId=n,this.screen=a,this.uuid=l}get state(){return this.view}subscribe(s){return this.listeners.add(s),()=>{this.listeners.delete(s)}}start(){this.offs.push(this.wire.onMessage(s=>this.onMessage(s))),this.offs.push(this.wire.subscribe(()=>this.onLink())),this.wasReady=this.wire.ready(),this.wasReady?this.open():this.set({phase:"offline"})}stop(){var s;if(!this.stopped){this.stopped=!0,this.flushKeys(),this.tid&&this.wire.ready()&&this.wire.send({type:"term.close",tid:this.tid});for(const n of this.offs.splice(0))n();this.timer&&clearTimeout(this.timer),(s=this.holdOp)==null||s.done("invalid"),this.holdOp=null}}hold(s){var l;if(!this.tid||this.view.phase!=="live"||this.view.readOnly||!this.wire.ready())return Promise.resolve("invalid");(l=this.holdOp)==null||l.done("invalid");const n=this.uuid(),a=this.tid;return new Promise(r=>{this.holdOp={op:n,done:o=>{this.holdOp=null,this.set({holding:!1,holdRefused:o}),r(o)}},this.set({holding:!0,holdRefused:null,released:null}),this.wire.send({type:"term.hold",op:n,tid:a,assertion:s})})}release(){!this.tid||!this.view.held||(this.flushKeys(),this.wire.send({type:"term.release",tid:this.tid}))}type(s){!this.view.held||!this.tid||nN.test(s)||(this.pending+=s,this.set({held:{...this.view.held,lastKey:Date.now()}}),this.timer===null&&(this.timer=setTimeout(()=>{this.timer=null,this.flushKeys()},sN)))}flushKeys(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),!this.tid||!this.pending||!this.wire.ready()){this.pending="";return}for(;this.pending;){const s=lN(this.pending);this.pending=this.pending.slice(s.length),this.wire.send({type:"term.input",tid:this.tid,n:this.n++,data:s})}}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 n;const s=this.wire.ready();if(!(s===this.wasReady||this.stopped)){if(this.wasReady=s,!s){this.pending="",(n=this.holdOp)==null||n.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(s){if(!this.stopped)switch(s.type){case"term.opened":{if(!(s.op!==void 0?s.op===this.openOp:s.tid===this.tid))return;this.tid=s.tid,this.seq=s.seq,this.resyncing=!1,this.screen.reset(s.cols,s.rows),this.screen.write(rN(s.screen,s.cursor)),this.set({phase:"live",cols:s.cols,rows:s.rows,readOnly:s.readOnly===!0});return}case"term.output":if(s.tid!==this.tid||this.resyncing)return;if(s.seq!==this.seq){this.resyncing=!0,this.wire.send({type:"term.resync",tid:s.tid});return}this.seq++,this.screen.write(s.data);return;case"term.size":if(s.tid!==this.tid)return;this.screen.resize(s.cols,s.rows),this.set({cols:s.cols,rows:s.rows});return;case"term.held":if(s.tid!==this.tid)return;this.set({held:{until:Date.parse(s.until),lastKey:Date.now()},released:null});return;case"term.released":if(s.tid!==this.tid)return;this.pending="",this.set({held:null,released:s.why==="asked"?null:s.why});return;case"term.exit":if(s.tid!==this.tid)return;this.tid=null,this.set({phase:"ended",held:null,exit:s.why});return;case"operation.result":if(s.op===this.openOp&&s.status==="rejected"){this.openOp=null,this.set({phase:"refused",refused:s.reason??"invalid"});return}if(s.op===this.openOp&&s.status==="failed"){this.openOp=null,this.set({phase:"refused",refused:"unavailable"});return}this.holdOp&&s.op===this.holdOp.op&&s.status!=="received"&&this.holdOp.done(s.status==="applied"?null:s.reason??"invalid");return;default:return}}set(s){this.view={...this.view,...s};for(const n of[...this.listeners])n()}}const iN=11,yv=6,Nv=16,uc=5*6e4,cN={up:"A",down:"B",right:"C",left:"D"};function dN(t,s){switch(t){case"esc":return"\x1B";case"tab":return" ";case"enter":return"\r";case"interrupt":return"";default:return`${s?"\x1BO":"\x1B["}${cN[t]}`}}function uN(t,s){let n=t;if(s.ctrl&&[...t].length===1){const a=t.toUpperCase().charCodeAt(0);a>=64&&a<=95?n=String.fromCharCode(a-64):t===" "?n="\0":t==="?"&&(n="")}return s.alt?`\x1B${n}`:n}function xN(t){const s=t.findIndex(a=>/❯\s*1\.\s/.test(a));if(s<0)return[];const n=[];for(const a of t.slice(s,s+12)){const l=/^\s*(?:❯\s*)?(\d)\.\s+(.*)$/.exec(a);if(!l)continue;if(l[1]!==String(n.length+1))break;const r=l[2].trim(),o=/^(oui,?\s+toujours|yes,?\s+and\s+don.t\s+ask)/i.test(r)?"always":/^(oui|yes)\b/i.test(r)?"yes":/^(non|no)\b/i.test(r)?"no":null;n.push({digit:l[1],word:o})}return n}const Me=d.terminal.live2,Sx="ledge.mobile.terminalView",mN=t=>{var s;try{return((s=Qe(t))==null?void 0:s.getItem(Sx))==="fit"?"fit":"readable"}catch{return"readable"}},pN=(t,s)=>{var n;try{(n=Qe(s))==null||n.setItem(Sx,t)}catch{}};function fN(t){return{send:s=>{t.send(s).catch(()=>{})},onMessage:s=>t.onMessage(s),ready:()=>t.state()==="ready",subscribe:s=>t.subscribe(s)}}const Yl=new Map,hN=t=>{const s=Math.max(0,Math.ceil(t/1e3));return`${Math.floor(s/60)}:${String(s%60).padStart(2,"0")}`},gN=t=>wm(()=>import("./xterm-DmfYKkwX.js"),__vite__mapDeps([0,1,2,3,4])).then(s=>s.createXterm(t));function bN({store:t,link:s,session:n,storage:a,makeScreen:l,forge:r}){var Ge,pt,ft,ut;const o=me(t),i=Xt(),c=f.useRef(null),x=f.useRef(null),[u,m]=f.useState(null),[p,h]=f.useState(null),[g,y]=f.useState(()=>mN(a)),[k,S]=f.useState(!1),[b,j]=f.useState({ctrl:"off",alt:"off"}),[N,$]=f.useState(!1),[C,M]=f.useState(""),[v,A]=f.useState(!1),[T,R]=f.useState(null),[P,_]=f.useState([]),[D,E]=f.useState(!1),z=It(),K=il(),L=f.useRef(!0),W=f.useRef(b);W.current=b,f.useEffect(()=>{const Y=c.current;if(!Y)return;let Re=!1,ke=null;const ie=Ae=>{if(Re){Ae.dispose();return}const Je=new oN(fN(s),n.id,Ae);Ae.onData(xt=>Je.type(ae(xt))),Je.start(),ke={c:Je,xt:Ae},m(Je),h(Ae)};return l?ie(l(Y)):gN(Y).then(ie),()=>{Re=!0,ke==null||ke.c.stop(),ke==null||ke.xt.dispose()}},[s,n.id,l]);const ae=Y=>{const Re=W.current;if(Re.ctrl==="off"&&Re.alt==="off")return Y;const ke=uN(Y,{ctrl:Re.ctrl!=="off",alt:Re.alt!=="off"});return j(ie=>({ctrl:ie.ctrl==="armed"?"off":ie.ctrl,alt:ie.alt==="armed"?"off":ie.alt})),ke},U=f.useSyncExternalStore(Y=>u?u.subscribe(Y):()=>{},()=>(u==null?void 0:u.state)??null),O=!!(U!=null&&U.held);f.useEffect(()=>{p==null||p.setInput(O),O&&(L.current=!0,p==null||p.focus())},[p,O]),f.useEffect(()=>{!p||!x.current||!U||p.setFont(g==="fit"?p.fitFont(x.current.clientWidth-16):iN)},[p,g,U==null?void 0:U.cols]),f.useEffect(()=>{if(!p)return;const Y=x.current,Re=()=>{if(!Y)return;const ke=Yl.get(n.id);if(ke&&Y.scrollWidth>=ke.left+Y.clientWidth&&Y.scrollHeight>=ke.top+Y.clientHeight&&(Yl.delete(n.id),Y.scrollLeft=ke.left,Y.scrollTop=ke.top,L.current=!1),L.current&&g==="readable"){const{x:Ae,cellWidth:Je}=p.cursor(),xt=Ae*Je;(xt<Y.scrollLeft||xt>Y.scrollLeft+Y.clientWidth-Je*4)&&(Y.scrollLeft=Math.max(0,xt-Y.clientWidth/2))}R(Y.scrollWidth>Y.clientWidth+1?{left:Y.scrollLeft/Y.scrollWidth,width:Y.clientWidth/Y.scrollWidth}:null);const ie=xN(p.rows());_(Ae=>Ae.length===ie.length&&Ae.every((Je,xt)=>Je.digit===ie[xt].digit&&Je.word===ie[xt].word)?Ae:ie)};p.onDrawn(Re),Re()},[p,g]);const B=()=>{const Y=x.current;Y&&Yl.set(n.id,{left:Y.scrollLeft,top:Y.scrollTop})},Z=()=>{const Y=x.current;Y&&R(Y.scrollWidth>Y.clientWidth+1?{left:Y.scrollLeft/Y.scrollWidth,width:Y.clientWidth/Y.scrollWidth}:null)},H=f.useRef(null),X=Y=>Math.hypot(Y[0].clientX-Y[1].clientX,Y[0].clientY-Y[1].clientY),te=Y=>{Y.touches.length===2&&p?H.current={d:X(Y.touches),px:p.font()}:L.current=!1},pe=Y=>{if(Y.touches.length!==2||!H.current||!p||!x.current)return;const Re=p.fitFont(x.current.clientWidth-16);p.setFont(Math.max(Re,H.current.px*(X(Y.touches)/H.current.d)))},ue=()=>{H.current=null},F=Y=>{y(Y),pN(Y,a),L.current=!0},w=Y=>{var Re,ke;if(!(!u||!p)){if(L.current=!0,Y==="ctrl"||Y==="alt"){j(ie=>({...ie,[Y]:ie[Y]==="off"?"armed":ie[Y]==="armed"?"locked":"off"}));return}if(Y==="line"){$(ie=>!ie);return}if(Y==="paste"){A(!1),(ke=(Re=navigator.clipboard)==null?void 0:Re.readText)==null||ke.call(Re).then(ie=>{ie?p.paste(ie):A(!0)},()=>A(!0));return}u.type(ae(dN(Y,p.appCursor())))}},I=()=>{!u||!C||(u.type(`${C.replace(/\r?\n/g,"\r")}\r`),M(""))},V=!!n.pending||n.state==="waiting_permission"||n.state==="waiting_input",ee=((Ge=n.pending)==null?void 0:Ge.kind)==="permission"||n.state==="waiting_permission",Q={name:"thread",sessionId:n.id},J=(U==null?void 0:U.phase)??"connecting",fe=J==="ended",be=J==="offline",tt=!!((pt=o.daemon)!=null&&pt.terminalInput)&&!(U!=null&&U.readOnly)&&n.readOnly!==!0,yt=O?Me.status.held:Me.status[J],Ze=U!=null&&U.released&&U.released!=="asked"?Me.released[U.released]:null,Le=(U==null?void 0:U.exit)==="gone"?Me.exit.gone(n.name):U!=null&&U.exit?Me.exit[U.exit]:null,de=U!=null&&U.refused?Me.refused[U.refused]??Me.refused.unavailable:null,he=U!=null&&U.holdRefused?Me.holdRefused[U.holdRefused]??d.confirm.refused[U.holdRefused]??null:null,$e=U!=null&&U.held?Math.min(uc,Math.min(U.held.lastKey+uc,U.held.until)-i):0,Oe=O&&$e<=6e4,rt=ee?P:[];return e.jsxs(e.Fragment,{children:[e.jsx(dx,{store:t,session:n,current:"terminal",onLeave:B,model:D,onModel:E,display:J==="live"||be?{value:g==="readable"?Me.readable:Me.fit,onToggle:()=>F(g==="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 ${O?"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:n.project}),e.jsx("span",{role:"status",className:`flex-none rounded-[6px] px-2 py-0.5 font-medium ${O?"bg-info text-white":be?"text-attention":J==="live"?"text-ok":"text-muted"}`,children:Oe?Me.heldLeft(hN($e)):yt}),e.jsx("span",{className:"flex-1"}),O?e.jsx("button",{type:"button",onClick:()=>u==null?void 0:u.release(),className:"flex-none underline",children:Me.release}):U&&!fe&&J!=="refused"&&e.jsxs("span",{className:"flex-none font-mono",children:[U.cols," × ",U.rows]})]}),e.jsx("div",{ref:x,onScroll:Z,onTouchStart:te,onTouchMove:pe,onTouchEnd:ue,"aria-label":Me.screen(n.name),className:`relative min-h-0 flex-1 overflow-auto rounded-b-card bg-term-bg p-2 ${O?"border-2 border-t-0 border-info":"border border-t-0 border-line"} ${be||fe?"opacity-45":""}`,children:e.jsx("div",{ref:c,"data-term":"",className:"w-max"})}),T&&!O&&g==="readable"&&e.jsx("div",{"aria-label":Me.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:`${T.left*100}%`,width:`${T.width*100}%`}})})]}),O?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:Me.pasteFailed}),e.jsxs("div",{role:"toolbar","aria-label":Me.keys,className:"flex gap-1.5 overflow-x-auto py-1.5",children:[rt.map(Y=>e.jsx("button",{type:"button",onPointerDown:Re=>Re.preventDefault(),onClick:()=>{L.current=!0,u==null||u.type(Y.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:Y.word?`${Y.digit} ${Me.contextKeys[Y.word]}`:Y.digit},Y.digit)),(z?["interrupt","paste"]:N?["esc","tab","up","down","line"]:["esc","tab","ctrl","alt","left","up","down","right","enter","interrupt","paste","line"]).map(Y=>{const Re=Y==="ctrl"||Y==="alt"?b[Y]!=="off":Y==="line"?N:!1,ke=Y==="ctrl"||Y==="alt"||Y==="line"?Re:void 0,ie=(Y==="ctrl"||Y==="alt")&&b[Y]!=="off"?`, ${b[Y]==="locked"?Me.locked:Me.armed}`:"";return e.jsx("button",{type:"button","aria-pressed":ke,"aria-label":`${Me.keyLabel[Y]}${ie}`,onPointerDown:Ae=>Ae.preventDefault(),onClick:()=>w(Y),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 ${Re?"border-transparent bg-fg text-bg":"border-input bg-surface text-fg"}`,children:Me.key[Y]},Y)}),z&&e.jsx("span",{className:"ml-auto flex-none self-center pl-2 text-[12px] text-muted",children:Me.hardware})]}),N&&!z&&e.jsxs("form",{className:"flex items-center gap-2",onSubmit:Y=>{Y.preventDefault(),I()},children:[e.jsx("span",{"aria-hidden":"true",className:"font-mono text-muted",children:"$"}),e.jsx("input",{id:"term-line",value:C,onChange:Y=>M(Y.target.value),"aria-label":Me.lineField,placeholder:Me.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:!C,"aria-label":Me.lineSend,className:Pe({variant:"primary",size:"sm"}),children:Me.lineGo})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("footer",{className:"flex flex-none flex-col gap-2 pt-2.5 pb-2.5",children:[(Ze||Le||de||he)&&e.jsx("p",{role:"status",className:"text-center text-small text-muted",children:de??Le??he??Ze}),fe?e.jsx("a",{href:ne(Q),className:Pe({block:!0}),children:Me.back}):tt&&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:Me.alsoInThread}),e.jsxs("button",{type:"button",disabled:J!=="live"||(U==null?void 0:U.holding),onClick:()=>S(!0),className:Pe({size:"sm",className:V?"flex-none":"ml-auto flex-none"}),children:[e.jsx(q,{name:"keyboard"}),U!=null&&U.released?Me.holdAgain:Me.hold]})]}):!be&&((ft=o.daemon)==null?void 0:ft.terminal)&&!(U!=null&&U.readOnly)&&n.readOnly!==!0&&e.jsx("p",{className:"text-center text-meta text-muted",children:Me.inputOff}),be&&e.jsx("p",{className:"text-center text-meta text-muted",children:Me.offlineHint})]}),e.jsx(Ju,{store:t,forge:r,session:n,wide:K,threshold:((ut=o.device)==null?void 0:ut.contextNear)??kn,onModel:()=>E(!0)})]}),k&&u&&e.jsx(jN,{store:t,session:n,onClose:()=>S(!1),hold:Y=>(S(!1),u.hold(Y),"sent")})]})}function jN({store:t,session:s,onClose:n,hold:a}){const{fresh:l,device:r}=me(t),o=!!(r!=null&&r.confirm),i=Yu(t,"terminal",s.id,l&&o,a),c=u=>Pe({variant:u,block:!0}),x=i.asking?d.confirm.asking:i.challenge?_t()?`${Me.go}`:Me.go:d.confirm.preparing;return e.jsxs(dt,{labelledBy:"hold-title",onClose:n,children:[e.jsx("h2",{id:"hold-title",className:"text-heading leading-[1.3] tracking-[-.5px]",children:Me.sheetTitle(s.name)}),o?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:Me.sheetBody}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:Me.sheetNote}),i.problem&&e.jsx(Xe,{title:d.confirm[i.problem],tone:"warning",role:"alert"}),i.needsNew?e.jsx("button",{type:"button",onClick:i.retry,className:c("primary"),children:d.confirm.retry}):e.jsxs("button",{type:"button",disabled:i.asking||!i.challenge,onClick:()=>{i.go()},className:c("primary"),children:[e.jsx(q,{name:"passkey"}),x]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{title:Me.unprotectedTitle,tone:"warning",role:"status",children:e.jsx("p",{children:Me.unprotectedBody})}),e.jsx("a",{href:ne({name:"connection"}),className:c("primary"),children:Me.openConnection})]}),e.jsx("button",{type:"button",onClick:n,className:c(),children:Me.cancel})]})}const $x="ledge.mobile.terminalSize",Cx=11,Mx=20,xc=12,yN=1e4,Ex=t=>Math.max(Cx,Math.min(Mx,t));function NN(t){var s;try{const n=Number((s=Qe(t))==null?void 0:s.getItem($x));return Number.isFinite(n)&&n>0?Ex(Math.round(n)):xc}catch{return xc}}function vN(t,s){var n;try{(n=Qe(s))==null||n.setItem($x,String(t))}catch{}}const mc=Tt({variant:"outline",className:"text-body font-medium"});function pc({store:t,link:s,sessionId:n,storage:a,forge:l}){var i;const r=me(t),o=r.sessions.get(n);return s&&o&&((i=r.daemon)!=null&&i.terminal)?e.jsx(bN,{store:t,link:s,session:o,forge:l,...a?{storage:a}:{}},n):e.jsx(kN,{store:t,sessionId:n,...a?{storage:a}:{}})}function kN({store:t,sessionId:s,storage:n}){const a=me(t),l=Xt(),{fresh:r,ops:o}=a,i=a.sessions.get(s),c=a.previews.get(s)??[],[x,u]=f.useState(()=>NN(n)),m=_=>u(D=>{const E=Ex(D+_);return vN(E,n),E}),[p,h]=f.useState(!1);f.useEffect(()=>()=>t.watch(null),[t,s]),f.useEffect(()=>{r&&t.watch(s)},[t,s,r]);const g=f.useRef(null);f.useEffect(()=>{const _=g.current;_&&(_.scrollTop=_.scrollHeight)},[c.length,c[c.length-1],x]);const y={name:"thread",sessionId:s},k=Mn(a);if(!i)return e.jsxs(e.Fragment,{children:[e.jsx(oa,{title:d.thread.title,fallback:y,label:d.terminal.back,link:k}),e.jsx("main",{className:"min-h-0 flex-1 pt-7 text-body text-muted",role:"status",children:!r&&a.syncedAt===null?d.thread.loading:d.terminal.unknown})]});const S=!!i.pending||i.state==="waiting_permission"||i.state==="waiting_input",b=!r,j=b?d.terminal.offline:S?d.terminal.waiting:d.terminal.live,N=Object.values(o).filter(_=>_.message.type==="session.interrupt"&&_.message.id===s).sort((_,D)=>_.at.localeCompare(D.at)).at(-1),$=N!==void 0&&ps(N.phase),C=i.state==="working",M=(N==null?void 0:N.phase)==="applied"&&(!C||l-Date.parse(N.at)<yN),v=C&&!b&&!S&&!$&&!M,A=b?d.terminal.why.offline:S?d.terminal.why.waiting:C?null:d.terminal.why.idle,T=()=>{v&&h(!t.interrupt(s))},R=(N==null?void 0:N.phase)==="sending"?d.terminal.sending:M?d.terminal.sent:d.terminal.interrupt(i.name),P=(N==null?void 0:N.phase)==="rejected"&&N.reason==="read_only"?d.terminal.readOnly:p||(N==null?void 0:N.phase)==="rejected"||(N==null?void 0:N.phase)==="failed"?d.terminal.fail:(N==null?void 0:N.phase)==="uncertain"&&!b?d.terminal.uncertain:null;return e.jsxs(e.Fragment,{children:[e.jsx(dx,{store:t,session:i,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:j}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",disabled:x<=Cx,onClick:()=>m(-1),"aria-label":d.terminal.smaller,className:mc,children:"A−"}),e.jsx("button",{type:"button",disabled:x>=Mx,onClick:()=>m(1),"aria-label":d.terminal.larger,className:mc,children:"A+"})]})]}),e.jsx("div",{ref:g,tabIndex:0,"aria-label":d.terminal.output,className:"mb-3 min-h-0 flex-1 overflow-auto rounded-card border border-line bg-term-bg p-4",children:c.length===0?e.jsx("p",{className:"text-small text-muted",children:d.terminal.empty}):e.jsx("pre",{"data-size":x,style:{fontSize:x},className:"m-0 w-max min-w-full font-mono leading-[1.5] whitespace-pre text-term-fg",children:c.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:d.terminal.scrollHint}),P&&e.jsx("p",{role:"alert",className:"text-center text-small text-attention",children:P}),e.jsxs("button",{type:"button",disabled:!v,onClick:T,className:Pe({block:!0}),children:[e.jsx(q,{name:"stop"}),R]}),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:d.terminal.note})]})]})}const On=d.unrecognized;function wN({pcName:t,onRelink:s,onSignOut:n}){return e.jsxs(Et,{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:Ba,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:qt,children:On.title(t)}),e.jsx("p",{className:"text-muted",children:On.body})]}),e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:On.kept}),e.jsx(Rt,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:s,className:St,children:On.relink}),e.jsx("button",{type:"button",onClick:n,className:mt,children:On.signOut})]})]})}const _s=d.update,SN=t=>`https://github.com/kl-ledge/ledge/releases/tag/v${t}`;function $N({next:t,current:s,onLater:n,onApply:a}){return e.jsxs(dt,{labelledBy:"update-title",onClose:n,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:_s.version(t.version)}),e.jsx("p",{className:"text-muted",children:_s.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:_s.fingerprint}),e.jsx("code",{className:"font-mono text-base leading-[22px] tracking-[.02em] [word-spacing:4px]",children:hx(t.fingerprint)}),e.jsxs("span",{className:"text-small leading-4 text-muted",children:[_s.current,e.jsx("span",{className:"font-mono",children:s?_s.currentBuild(s.version,oy(s.fingerprint)):d.connection.none})]})]}),e.jsxs("a",{href:SN(t.version),target:"_blank",rel:"noreferrer",className:"inline-flex min-h-11 items-center gap-2 font-medium",children:[e.jsx(q,{name:"external",className:"size-4",stroke:1.5}),_s.compare(`v${t.version}`)]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2.5",children:[e.jsx(Ke,{size:"lg",onClick:n,children:_s.later}),e.jsx(Ke,{size:"lg",variant:"primary",onClick:a,children:_s.apply})]})]})}const Fr="ledge.mobile.rigs",CN=35e3,MN=()=>crypto.randomUUID(),fc=()=>crypto.randomUUID(),Ca=t=>t!=="checking"&&t!=="sending"&&t!=="received",EN=new Set(["assertion_invalid","assertion_expired","confirm_required","conflict"]);function RN(t){var s;try{const n=(s=Qe(t))==null?void 0:s.getItem(Fr);if(!n)return null;const a=JSON.parse(n),l=Sm.safeParse(a.state);return l.success&&typeof a.at=="string"?{state:l.data,at:a.at}:null}catch{return null}}function AN(t,s,n){var F;const a=RN(n);let l={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 r=new Set,o=w=>{l={...l,...w};for(const I of[...r])I()};let i=!1,c=!1,x=!1,u=!1,m=!1;const p=new Map,h=new Map,g=new Map;let y=s.getState().daemon?((F=s.getState().daemon)==null?void 0:F.boot)??null:void 0;const k=new Set,S=()=>!i&&t.state()==="ready",b=()=>{var w;return!!((w=s.getState().daemon)!=null&&w.rigs)},j=w=>{t.send(w).catch(()=>{})};function N(w,I,V){return!S()||!b()?!1:(j(I),clearTimeout(p.get(w)),p.set(w,setTimeout(()=>{p.delete(w),V()},CN)),!0)}const $=w=>{clearTimeout(p.get(w)),p.delete(w)},C=w=>({...w??{},loading:!0}),M=w=>({...w??{},loading:!1,error:"unavailable"});function v(){u||N("state",{type:"rigs.state"},()=>{u=!1,o({loading:!1,error:"unavailable"})})&&(u=!0,o({loading:!0}))}function A(){m||N("goals",{type:"rigs.goals"},()=>{m=!1,o({goals:M(l.goals??void 0)})})&&(m=!0,o({goals:C(l.goals??void 0)}))}const T=()=>{c&&v(),x&&A()};function R(w,I){const V=l.runs.findIndex(Q=>Q.id===w);if(V<0)return;const ee=I(l.runs[V]);if(o({runs:l.runs.map((Q,J)=>J===V?ee:Q)}),Ca(ee.phase)){ee.op&&ee.phase!=="uncertain"&&h.delete(ee.op);const Q=g.get(w);g.delete(w),Q==null||Q(ee)}}const P=w=>l.runs.find(I=>I.op===w),_=w=>!!w&&(!Ca(w.phase)||w.phase==="uncertain"),D=(w,I)=>{const V=P(w);$(`op:${w}`),_(V)&&R(V.id,ee=>({...ee,...I,endedAt:Date.now()}))},E=w=>{clearTimeout(p.get(`op:${w}`)),p.set(`op:${w}`,setTimeout(()=>{p.delete(`op:${w}`);const I=P(w);(I==null?void 0:I.phase)==="sending"&&R(I.id,V=>({...V,phase:"uncertain",endedAt:Date.now()}))},Wc))},z=w=>w.sentAt!==void 0&&Date.now()-w.sentAt<Uc&&y!==void 0&&(w.boot??null)===y,K=w=>{$(`op:${w.op}`),h.delete(w.op),R(w.id,I=>({...I,phase:"uncertain",lost:!0,endedAt:I.endedAt??Date.now()}))};function L(w){for(const[I,V]of[...h]){if(w.has(I))continue;const ee=P(I);if(!ee){h.delete(I);continue}if(!z(ee)){K(ee);continue}R(ee.id,Q=>({...Q,again:!0})),j(V),ee.phase==="sending"&&E(I)}}const W=(w,I)=>!w||!w.again||!EN.has(I??"")?!1:(w.lost||K(w),!0),ae=w=>{const I=w.kind==="seats"?w.rig:w.kind==="act"&&"rig"in w.action?w.action.rig:null;I&&(l.graphs[I]||l.queues[I])&&ue.openRig(I),I&&l.snapshots[I]&&ue.readSnapshots(I)};function U(w){var I;switch(w.type){case"snapshot":{const V=y;y=w.daemon.boot??null;const ee=new Set(k);k.clear();for(const Q of ee){const J=P(Q);J&&R(J.id,fe=>({...fe,boot:y}))}(V===void 0||V!==y)&&L(ee),T();return}case"rigs.state":if($("state"),u=c,w.state){const V=new Date().toISOString();o({state:w.state,error:null,at:V,loading:!1});try{(I=Qe(n))==null||I.setItem(Fr,JSON.stringify({state:w.state,at:V}))}catch{}}else o({error:w.error??"unavailable",loading:!1});return;case"rigs.graph":$(`graph:${w.rig}`),o({graphs:{...l.graphs,[w.rig]:w.graph?{data:w.graph,loading:!1,at:new Date().toISOString()}:{...l.graphs[w.rig],loading:!1,error:w.error??"unavailable"}}});return;case"rigs.queue":$(`queue:${w.rig}`),o({queues:{...l.queues,[w.rig]:w.error?{...l.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":$(`permissions:${w.rig}`),o({permissions:{...l.permissions,[w.rig]:w.error?{...l.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":$(`snapshots:${w.rig}`),o({snapshots:{...l.snapshots,[w.rig]:w.error?{...l.snapshots[w.rig],loading:!1,error:w.error}:{data:w.snapshots,loading:!1,at:new Date().toISOString()}}});return;case"rigs.routing":$("routing"),o({routing:w.error?{...l.routing,loading:!1,error:w.error}:{data:w.entries,loading:!1,at:new Date().toISOString()}});return;case"rigs.goals":$("goals"),m=x&&!w.error,o({goals:w.error?{...l.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=P(w.op);if(!_(V))return;if(w.status==="received"){$(`op:${w.op}`),(V.phase==="sending"||V.phase==="uncertain")&&R(V.id,ee=>{const{endedAt:Q,...J}=ee;return{...J,phase:"received"}});return}if(w.status==="rejected"&&W(V,w.reason))return;w.status==="rejected"&&D(w.op,{phase:"rejected",reason:w.reason??"invalid"});return}case"rigs.done":{const V=P(w.op);if(w.rejected&&W(V,w.rejected))return;V&&(D(w.op,w.rejected?{phase:"rejected",reason:w.rejected,done:w}:{phase:"done",done:w,...w.error?{reason:w.error}:{}}),ae(V.subject));return}case"rigs.reseated":{const V=P(w.op);if(w.rejected&&W(V,w.rejected))return;V&&(D(w.op,w.rejected?{phase:"rejected",reason:w.rejected,reseated:w}:{phase:"done",reseated:w,...w.error?{reason:w.error}:{}}),ae(V.subject));return}case"rigs.goal.sent":case"rigs.goal.replied":if(w.rejected&&W(P(w.op),w.rejected))return;D(w.op,w.rejected?{phase:"rejected",reason:w.rejected,sent:w}:{phase:"done",sent:w,...w.error?{reason:w.error}:{}});return}}let O=S(),B=0;const Z=t.subscribe(()=>{const w=t.state();(w==="unpaired"||w==="pairing")&&X();const I=S();if(I&&!O)O=!0,B++,u=!1,m=!1,y=void 0,k.clear();else if(!I&&O){O=!1,u=!1,m=!1;for(const[V,ee]of p)clearTimeout(ee),p.delete(V);o({loading:!1});for(const V of l.runs)V.phase==="sending"&&V.op&&R(V.id,ee=>({...ee,phase:"uncertain",endedAt:Date.now()}))}}),H=t.onMessage(U);function X(){var w;if(!(!l.state&&!l.runs.length&&!Object.keys(l.graphs).length)){try{(w=Qe(n))==null||w.removeItem(Fr)}catch{}h.clear(),o({state:null,error:null,at:null,loading:!1,graphs:{},queues:{},permissions:{},snapshots:{},routing:null,goals:null,runs:[]})}}async function te(w){var Q;if(!((Q=s.getState().device)!=null&&Q.confirm))return{phase:"rejected",reason:"confirm_required"};let I;try{I=await s.prepareConfirm(w)}catch(J){return{phase:J instanceof Error&&J.message==="timeout"?"expired":"unsent"}}if(!I.credentialId)return{phase:"rejected",reason:"confirm_required"};const V=Date.now(),ee=await sa({challenge:I.challenge,rpId:I.rpId,credentialId:I.credentialId}).catch(()=>"failed");return ee==="cancelled"?{phase:"cancelled"}:ee==="failed"?{phase:"unsent"}:Date.now()-V>=I.expiresInMs?{phase:"expired"}:{assertion:ee}}function pe(w,I,V){const ee=MN(),Q={op:"",id:ee,subject:w,phase:I?"checking":"sending",startedAt:Date.now()},J=new Promise(fe=>g.set(ee,fe));return!S()||!b()?(o({runs:[...l.runs,{...Q,phase:"unsent",endedAt:Date.now()}]}),g.delete(ee),Promise.resolve({...Q,phase:"unsent"})):(o({runs:[...l.runs,Q]}),(async()=>{var de;let fe;if(I){const he=await te(I);if(!("assertion"in he)){R(ee,$e=>({...$e,phase:he.phase,...he.reason?{reason:he.reason}:{},endedAt:Date.now()}));return}fe=he.assertion}const be=Hc(),tt=Fc.safeParse(V(be,fe));if(!tt.success||!S()){R(ee,he=>({...he,phase:"unsent",endedAt:Date.now()}));return}h.set(be,tt.data),y===void 0&&k.add(be),R(ee,he=>({...he,op:be,phase:"sending",sentAt:Date.now(),...y!==void 0?{boot:y}:{}})),E(be);const yt=B,Ze=await t.send(tt.data).catch(()=>!1),Le=(de=P(be))==null?void 0:de.phase;!Ze&&yt===B&&(Le==="sending"||Le==="uncertain")&&($(`op:${be}`),R(ee,he=>({...he,phase:"unsent",endedAt:Date.now()})))})(),J)}const ue={getState:()=>l,subscribe(w){return r.add(w),()=>{r.delete(w)}},follow(){c=!0,v()},retry(){u=!1,v()},openRig(w){const I=`graph:${w}`,V=`queue:${w}`,ee=`permissions:${w}`;N(I,{type:"rigs.graph",rig:w},()=>o({graphs:{...l.graphs,[w]:M(l.graphs[w])}}))&&o({graphs:{...l.graphs,[w]:C(l.graphs[w])}}),N(V,{type:"rigs.queue",rig:w},()=>o({queues:{...l.queues,[w]:M(l.queues[w])}}))&&o({queues:{...l.queues,[w]:C(l.queues[w])}}),N(ee,{type:"rigs.permissions",rig:w},()=>o({permissions:{...l.permissions,[w]:M(l.permissions[w])}}))&&o({permissions:{...l.permissions,[w]:C(l.permissions[w])}})},readSnapshots(w){N(`snapshots:${w}`,{type:"rigs.snapshots",rig:w},()=>o({snapshots:{...l.snapshots,[w]:M(l.snapshots[w])}}))&&o({snapshots:{...l.snapshots,[w]:C(l.snapshots[w])}})},readPermissions(w){const I=`permissions:${w}`;N(I,{type:"rigs.permissions",rig:w},()=>o({permissions:{...l.permissions,[w]:M(l.permissions[w])}}))&&o({permissions:{...l.permissions,[w]:C(l.permissions[w])}})},readRouting(){N("routing",{type:"rigs.routing"},()=>o({routing:M(l.routing??void 0)}))&&o({routing:C(l.routing??void 0)})},followGoals(){x=!0,A()},act(w){return pe({kind:"act",action:w},Hr(w)?{purpose:"rigs",rigAct:w}:null,(I,V)=>({type:"rigs.act",op:I,action:w,...V?{assertion:V}:{}}))},reseat(w,I,V={}){var J,fe;const ee=((fe=(J=l.state)==null?void 0:J.rigs.find(be=>be.name===w))==null?void 0:fe.nodes)??[],Q=V.check||Dc(ee,I).remove.length>0;return pe({kind:"seats",rig:w,seats:I,...V.delegation?{delegation:V.delegation}:{}},Q?{purpose:"rigs",rigSeats:{rig:w,seats:I}}:null,(be,tt)=>({type:"rigs.seats",op:be,rig:w,seats:I,...V.delegation?{delegation:V.delegation}:{},...tt?{assertion:tt}:{}}))},sendGoal(w,I=fc()){return pe({kind:"goal",goalId:I,text:w},null,V=>({type:"rigs.goal.send",op:V,goalId:I,text:w}))},replyGoal(w,I,V=fc()){return pe({kind:"reply",goalId:w,replyId:V,text:I},null,ee=>({type:"rigs.goal.reply",op:ee,goalId:w,replyId:V,text:I}))},dismiss(w){const I=l.runs.find(V=>V.id===w);I&&Ca(I.phase)&&I.op&&(h.delete(I.op),$(`op:${I.op}`)),o({runs:l.runs.filter(V=>V.id!==w||!Ca(V.phase))})},close(){i=!0,Z(),H();for(const w of p.values())clearTimeout(w);p.clear()}};return ue}function Rn(t){return f.useSyncExternalStore(t.subscribe,t.getState,t.getState)}const Ql={relaunch:!0,noKernel:!1},Rx="ledge.mobile.daemonPrefs",zr=new Set;function Ax(t){var s;try{const n=JSON.parse(((s=Qe(t))==null?void 0:s.getItem(Rx))??"{}");return{relaunch:typeof n.relaunch=="boolean"?n.relaunch:Ql.relaunch,noKernel:typeof n.noKernel=="boolean"?n.noKernel:Ql.noKernel}}catch{return Ql}}function TN(t,s){var n;try{(n=Qe(s))==null||n.setItem(Rx,JSON.stringify({...Ax(s),...t}))}catch{}for(const a of[...zr])a()}const _N=t=>(zr.add(t),()=>{zr.delete(t)});function Eo(t){const s=f.useSyncExternalStore(_N,()=>JSON.stringify(Ax(t)));return[JSON.parse(s),n=>TN(n,t)]}function Tx(t,s){const n=s.relaunch?"last":"none";return t==="restart"?{kind:"daemon.restart",restore:n}:{kind:"daemon.start",restore:n,...s.noKernel&&!s.relaunch?{noKernel:!0}:{}}}const ye=d.rigs;function IN(t){var a;const s=t.subject;if(s.kind==="seats")return s.rig;if(s.kind!=="act")return"";const n=s.action;return n.rig??((a=n.seat)==null?void 0:a.split("@")[0])??""}const Ro=t=>t.subject.kind==="act"?t.subject.action.kind:t.subject.kind==="seats"?"seats":null;function Dn(t){const s=Ro(t);return s?ye.notDone[s]:ye.rejected.nothingSent}function LN(t){const s=Ro(t),n=ye.rejected.againVerb;return s==="seats"?n.remove:s==="rig.stop"||s==="daemon.stop"||s==="kernel.stop"?n.stop:s==="rig.restart"||s==="daemon.restart"||s==="kernel.restart"?n.restart:s==="rig.policy"||s==="rig.permissions"?n.apply:s==="seat.set"?n.save:null}function ON(t,s){const n=_t(),a=t.phase==="expired"?"assertion_expired":t.phase==="cancelled"?"cancelled":t.phase==="unsent"?"unsent":t.reason??"unavailable",l=LN(t),r=l?ye.rejected.again(l):ye.rejected.nothingSent;switch(a){case"busy":return{mark:"warn",title:ye.busy.title(s),sub:ye.busy.body};case"confirm_required":return t.subject.kind==="seats"?{mark:"warn",title:n?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(Dn(t),ye.rejected.assertion_expired(n)),sub:r};case"assertion_invalid":return{mark:"bad",title:ye.because(Dn(t),ye.rejected.assertion_invalid(n)),sub:r};case"cancelled":return{mark:"bad",title:ye.because(Dn(t),ye.rejected.cancelled),sub:ye.rejected.nothingSent};case"unsent":return{mark:"bad",title:ye.because(Dn(t),ye.rejected.unsent),sub:ye.rejected.nothingSent};default:return{mark:"bad",title:ye.because(Dn(t),`${ye.notSent(s)}.`)}}}function Ja({run:t,rigs:s,pc:n,bar:a=!1}){const l=Ro(t),r=IN(t),o={onClose:()=>s.dismiss(t.id),closeLabel:ye.done.close};if(t.phase==="checking")return e.jsx(Zn,{bar:a,children:ye.running.checking});if(t.phase==="sending"||t.phase==="received"){const m=l==="seats"?ye.running.seats(r):l?ye.running[l](r):"";return e.jsx(Zn,{bar:a,children:`${m} · ${ye.running.note}`})}if(t.phase==="uncertain")return e.jsx(Se,{mark:"ask",title:ye.uncertain.title,sub:ye.uncertain.body,...o});if(t.phase!=="done"){const m=ON(t,n);return e.jsx(Se,{mark:m.mark,title:m.title,...m.sub?{sub:m.sub}:{},...o})}const i=Be(t.endedAt?new Date(t.endedAt).toISOString():null);if(t.reseated){const m=t.reseated;if(m.ok){const p=m.added.length?ye.reseat.added(m.added.length,m.links):ye.reseat.removed(m.removed.length);return e.jsxs(Se,{mark:"ok",title:p,...o,children:[m.linksUnsupported&&e.jsxs("small",{className:"block text-[12px] text-attention",children:[ye.reseat.noLinks.title," ",ye.reseat.noLinks.body]}),e.jsx(Xs,{commands:m.commands})]})}return m.error==="busy"?e.jsx(Se,{mark:"warn",title:ye.busy.title(n),sub:ye.busy.body,...o}):m.error==="rig_not_running"?e.jsx(Se,{mark:"bad",title:ye.reseat.notRunning.title,sub:ye.reseat.notRunning.body,...o}):e.jsx(Se,{mark:"bad",title:ye.failed(m.message??ye.errors[m.error??"failed"]??ye.errors.failed),...o,children:e.jsx(Xs,{commands:m.commands})})}const c=t.done;if(!c||!l||l==="seats")return null;if(c.ok){const m=t.subject.kind==="act"&&t.subject.action.kind==="rig.stop"&&t.subject.action.snapshot;return e.jsx(Se,{mark:"ok",title:ye.done[l](r),sub:[i,m?ye.done.snapshotFirst:""].filter(Boolean).join(" · "),...o,children:e.jsx(Xs,{commands:c.commands})})}if(c.error==="busy")return e.jsx(Se,{mark:"warn",title:ye.busy.title(n),sub:ye.busy.body,...o});const x=t.subject.kind==="act"&&"seats"in t.subject.action?t.subject.action.seats.length:0;if(c.completed!==void 0&&x)return e.jsx(Se,{mark:"bad",title:ye.completed(c.completed,x),...c.message?{sub:e.jsx("span",{className:"font-mono",children:c.message})}:{},...o});const u=c.error&&c.error!=="failed"?ye.errors[c.error]:void 0;return e.jsx(Se,{mark:"bad",title:u??ye.failed(ye.errors.failed),...c.message?{sub:e.jsx("span",{className:"font-mono",children:c.message})}:{},...o,children:e.jsx(Xs,{commands:c.commands})})}function Ao(t,s){for(let n=t.length-1;n>=0;n--)if(s(t[n]))return t[n]}const kl=t=>!!t&&(t.phase==="checking"||t.phase==="sending"||t.phase==="received"),je=d.rigs,DN={running:"on",stopped:"plain",stale:"bad",unknown:"plain"},_x={ready:"on",starting:"go",stopped:"plain",skipped:"plain",absent:"plain",unknown:"plain"};function To({state:t,href:s}){const n=t.daemon.state==="running"&&t.daemon.startedAt?Be(t.daemon.startedAt):null;return e.jsx(jr,{lead:e.jsx(q,{name:"cpu",className:"size-[18px] text-muted"}),name:je.daemon,chip:e.jsx(vn,{tone:DN[t.daemon.state],children:je.daemonState[t.daemon.state]}),sub:je.daemonSub(t.version,n),...s?{href:s}:{}})}function Ix({disabled:t,next:s=!1}){const[n,a]=Eo();return e.jsxs(e.Fragment,{children:[e.jsx(ji,{on:n.relaunch,label:je.relaunch,disabled:t,onChange:l=>a({relaunch:l})}),e.jsx(ji,{on:n.noKernel,label:je.noKernel,hint:s?je.noKernelNext:je.noKernelHint,disabled:t,onChange:l=>a({noKernel:l})})]})}function el({glyph:t,title:s,body:n,list:a=!0,children:l}){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:s}),e.jsx("p",{className:"max-w-[300px] text-[13.5px] text-muted",children:n}),l]})}function hc({state:t,rigs:s,store:n,pc:a}){const l=me(n).fresh,[r]=Eo(),o=Rn(s),i=Ao(o.runs,c=>c.subject.kind==="act"&&c.subject.action.kind==="daemon.start");return e.jsxs(e.Fragment,{children:[t&&e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:je.openrig}),e.jsx(Ve,{children:e.jsx(To,{state:t})})]}),e.jsxs(Ve,{children:[e.jsx(el,{glyph:e.jsx(q,{name:"power"}),title:je.stopped.title,body:je.stopped.body}),e.jsx("div",{className:"border-t border-line",children:e.jsx(Ix,{disabled:!l})}),e.jsx("div",{className:"p-3",children:e.jsx("button",{type:"button",disabled:!l||kl(i),onClick:()=>{s.act(Tx("start",r))},className:ge({tone:"primary",className:"w-full"}),children:e.jsx(Dt,{icon:"power",children:je.stopped.start})})})]}),i&&e.jsx(Ja,{run:i,rigs:s,pc:a}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:je.stopped.note})]})}function FN(){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 zN({state:t,at:s,store:n,offline:a}){const l=me(n),r=na(),o=It(),i=Zd(t),c=br(t),x=c.filter(h=>Gh(hs(h))).length,u=[...l.sessions.values()],m=((i==null?void 0:i.nodes)??[]).map(ou),p=t.daemon.state==="running";return e.jsxs("div",{className:`flex flex-col gap-3 ${a?"opacity-50":""}`,children:[e.jsx(Ft,{aside:!a&&s?je.updatedAt(Be(s)):void 0,children:je.openrig}),e.jsxs(Ve,{label:je.openrig,children:[e.jsx(To,{state:t,...a?{}:{href:ne({name:"kernel"})}}),t.kernel.state!=="absent"&&e.jsx(jr,{lead:e.jsx(Ie,{state:"rig"}),name:je.kernel,selected:r.name==="kernel"&&o,chip:e.jsx(vn,{tone:_x[t.kernel.state],children:je.kernelState[t.kernel.state]}),sub:m.length?a||o?je.kernelSubShort(m):je.kernelSub(m):"",...a?{}:{href:ne({name:"kernel"})}})]}),p&&c.length===0?e.jsx(Ve,{children:e.jsx(el,{title:je.empty.title,body:je.empty.body,list:!1,children:e.jsx("a",{href:ne({name:"max"}),className:ge({size:"sm",className:"mt-1.5"}),children:je.empty.talk})})}):c.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:je.rigsHead(x)}),e.jsx(Ve,{tone:"rigs",label:je.title,children:c.map(h=>{const g=hs(h),y=eu(h.name,u,l.asks),k=g==="stopped",S=a?[k?je.seatCount(h.seats):je.seats(h.running,h.seats),!k&&s?je.at(Be(s)):""].filter(Boolean).join(" · "):g==="stopped"?[je.seatCount(h.seats),h.snapshot?je.snapshot(h.snapshot):je.noSnapshot].join(" · "):g==="partial"?[je.seats(h.running,h.seats),je.stoppedCount(h.nodes.filter(j=>j.stopped).length||h.seats-h.running)].join(" · "):g==="starting"?je.seats(h.running,h.seats):[je.seats(h.running,h.seats),h.uptime?je.since(h.uptime):"",h.snapshot?je.snapshot(h.snapshot):""].filter(Boolean).join(" · "),b=!a&&(y.perm||y.ask)?e.jsxs(e.Fragment,{children:[y.perm>0&&e.jsx(Qn,{perm:!0,children:je.attention.permission(y.perm)}),y.ask>0&&e.jsx(Qn,{children:je.attention.question(y.ask)})]}):void 0;return e.jsx(jr,{lead:e.jsx(Ie,{state:tu(h,y),pulse:g==="starting"&&!a}),name:h.name,dim:k,chip:e.jsx(vn,{tone:iu[g],children:je.status[g]}),sub:S,att:b,href:ne({name:"rig",rig:h.name}),selected:o&&r.name==="rig"&&r.rig===h.name},h.id)})})]}),!a&&p&&e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:je.launchNote})]})}function PN({rigs:t,store:s}){const n=Rn(t),{pc:a,look:l}=Ut(),r=l==="offline";f.useEffect(()=>{t.follow()},[t]);const o=Ht(a),i=n.state,c=i?i.installed?!r&&ng(i)?e.jsx(hc,{state:i,rigs:t,store:s,pc:o}):e.jsxs(e.Fragment,{children:[!r&&n.error&&e.jsxs(Gt,{warn:!0,role:"alert",lead:e.jsx(q,{name:"warning",className:"mt-px size-4 text-attention"}),children:[e.jsx("b",{className:"font-semibold",children:je.unavailable.title}),n.at&&e.jsx("span",{className:"text-muted",children:je.unavailable.body(Be(n.at))}),e.jsx("button",{type:"button",onClick:()=>t.retry(),className:ge({size:"sm",className:"self-start"}),children:e.jsx(Dt,{icon:"refresh",children:je.unavailable.retry})})]}),e.jsx(zN,{state:i,at:n.at,store:s,offline:r})]}):e.jsx(Ve,{children:e.jsx(el,{title:je.notInstalled.title,body:je.notInstalled.body(o)})}):n.error==="not_installed"?e.jsx(Ve,{children:e.jsx(el,{title:je.notInstalled.title,body:je.notInstalled.body(o)})}):n.error==="daemon_stopped"?e.jsx(hc,{state:null,rigs:t,store:s,pc:o}):n.error?e.jsx("div",{"data-list-state":"",className:"flex flex-col",children:e.jsxs(Gt,{warn:!0,role:"alert",lead:e.jsx(q,{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:ge({size:"sm",className:"self-start"}),children:e.jsx(Dt,{icon:"refresh",children:je.unavailable.retry})})]})}):e.jsx(FN,{});return e.jsx(Rs,{title:je.title,offlineBody:je.offlineBody,heading:!1,children:c})}const se=d.rigs;function tl(t,s=new Date){const n=Xa(t);if(!n)return{short:t,long:t};const a=n.toLocaleTimeString(lt,{hour:"2-digit",minute:"2-digit"}),l=fo(n,s);if(l===0)return{short:a,long:se.snapshots.today(a)};if(l===1)return{short:se.snapshots.yesterday(a),long:se.snapshots.yesterday(a)};const r=n.toLocaleDateString(lt,{weekday:"short",day:"numeric",month:"short"});return{short:r,long:`${r} ${a}`}}function zs({verb:t,confirm:s,disabled:n,onClick:a}){const l=_t();return s?e.jsx("button",{type:"button",disabled:n,onClick:a,className:ge({tone:"dangerfill",className:"w-full"}),children:e.jsx(Dt,{icon:l?"face":"passkey",size:"size-[18px]",children:se.withCheck(t,l)})}):e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("p",{className:"text-[12.5px] text-muted",children:se.protectFirst}),e.jsx("a",{href:ne({name:"connection"}),className:ge({className:"w-full"}),children:se.openSettings})]})}const ha=({onClose:t})=>e.jsx("button",{type:"button",onClick:t,className:ge({className:"w-full"}),children:se.confirm.cancel});function Ma({title:t,conseq:s,note:n,verb:a,confirm:l,live:r,onConfirm:o,onClose:i}){return e.jsxs(cs,{title:t,onClose:i,children:[s&&e.jsx(ho,{title:s.title,...s.body?{body:s.body}:{}}),n&&e.jsx("p",{className:"text-[12.5px] leading-[18px] text-muted",children:n}),e.jsx(zs,{verb:a,confirm:l,disabled:!r,onClick:()=>{i(),o()}}),e.jsx(ha,{onClose:i})]})}function Ys({icon:t,label:s,aside:n,onClick:a,disabled:l=!1,danger:r=!1}){return e.jsxs("button",{type:"button",role:"menuitem",disabled:l,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 ${r?"text-approval":""}`,children:[e.jsx(q,{name:t,className:`size-[18px] ${r?"":"text-muted"}`}),e.jsx("span",{className:"min-w-0 flex-1",children:s}),n&&e.jsx("span",{className:"text-[13px] text-muted",children:n})]})}function BN({rig:t,live:s,running:n,snapshots:a,level:l,onSnapshot:r,onSnapshots:o,onPermissions:i,onRefresh:c,onClose:x}){return e.jsx(cs,{title:t,onClose:x,children:e.jsxs("div",{role:"menu","aria-label":se.more,className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:[e.jsx(Ys,{icon:"camera",label:se.actions.snapshot,disabled:!s||n,onClick:r}),e.jsx(Ys,{icon:"list",label:se.actions.snapshots,...a!==null?{aside:String(a)}:{},onClick:o}),e.jsx(Ys,{icon:"shield",label:se.actions.permissions,...l?{aside:l}:{},onClick:i}),e.jsx(Ys,{icon:"refresh",label:se.actions.refresh,disabled:!s,onClick:c})]})})}function qN({live:t,up:s,onRefresh:n,onRestart:a,onStop:l,onClose:r}){return e.jsx(cs,{title:se.kernel,onClose:r,children:e.jsxs("div",{role:"menu","aria-label":se.more,className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:[e.jsx(Ys,{icon:"refresh",label:se.kernelView.menu.refresh,disabled:!t,onClick:n}),e.jsx(Ys,{icon:"refresh",label:se.kernelView.menu.restart,disabled:!t||!s,onClick:a}),e.jsx(Ys,{icon:"power",label:se.kernelView.menu.stop,danger:!0,disabled:!t||!s,onClick:l})]})})}function HN({rig:t,pc:s,verb:n,confirm:a,live:l,onAct:r,onClose:o}){const[i,c]=f.useState(!0),[x,u]=f.useState(!1),m=t.nodes.filter(y=>!y.stopped&&xa(y)).map(y=>ys(y.logicalId,y.session)),p=n==="stop",h=m.length?se.confirm.working(m.length):se.confirm.noneWorking,g=p?{kind:"rig.stop",rig:t.name,...i?{snapshot:!0}:{},...x?{force:!0}:{}}:{kind:"rig.restart",rig:t.name};return e.jsxs(cs,{title:p?se.confirm.stop(t.name,s):se.confirm.restart(t.name,s),onClose:o,children:[e.jsx(ho,{title:h,body:p?m.length?m.join(", "):void 0:se.confirm.restartNote}),p&&e.jsxs("div",{className:"overflow-hidden rounded-[10px] border border-line",children:[e.jsx(bi,{on:i,label:se.confirm.snapshot,onChange:c}),e.jsx(bi,{on:x,label:se.confirm.force,onChange:u})]}),e.jsx(zs,{verb:p?se.actions.stop:se.actions.restart,confirm:a,disabled:!l,onClick:()=>{o(),r(g)}}),e.jsx(ha,{onClose:o})]})}function Lx({rig:t,confirm:s,live:n,onReseat:a,onDone:l,context:r}){const o=lu(t),[i,c]=f.useState({}),[x,u]=f.useState("pairs"),m=Object.fromEntries(Object.entries(i).filter(([j,N])=>{var $;return(($=o.find(C=>C.role===j))==null?void 0:$.count)!==N})),p=Dc(t.nodes,m),h=p.add.length,g=p.remove.length,y=t.nodes.filter(j=>p.remove.includes(j.logicalId)&&xa(j)).map(j=>j.logicalId),k=h&&g?se.reseat.change(h,g):h?se.reseat.add(h):g?se.reseat.remove(g):se.reseat.noChange,S=()=>{l==null||l(),c({}),a(m,h?x:void 0)},b=r!==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(j=>{const N=i[j.role]??j.count,$=p.add.filter(T=>T.role===j.role).map(T=>se.reseat.adds(`${T.pod}.${T.id}`)),C=p.remove.filter(T=>j.ids.includes(T)).map(se.reseat.removes),M=j.ids.map(T=>{var R;return ys(T,(R=t.nodes.find(P=>P.logicalId===T))==null?void 0:R.session)}).join(", "),v=b?j.ids.map(T=>r[T]).filter(T=>T!==void 0).map(T=>`${Math.round(T)} %`).join(", "):"",A=b?[...$,...C].join(" · "):[M,...$,...C].join(C.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:[j.role,A&&e.jsx("small",{className:"block font-sans text-[11.5px] text-muted",children:A})]}),b&&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(dg,{value:N,changed:N!==j.count,disabled:!n,fewer:se.reseat.fewer(j.role),more:se.reseat.more(j.role),onChange:T=>c({...i,[j.role]:T})})})]},j.role)})})}),h>0&&e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"flex-1 text-[12.5px] text-muted",children:se.reseat.delegation}),e.jsx(La,{label:se.reseat.delegation,value:x,onChange:u,options:[{value:"pairs",label:se.reseat.pairs},{value:"all",label:se.reseat.all}]})]}),g>0&&e.jsx(ho,{title:y.length?se.reseat.working(y):se.reseat.lastFirst,...y.length?{body:se.reseat.lastFirst}:{}}),(!b||h+g>0)&&(g>0?e.jsx(zs,{verb:k,confirm:s,disabled:!n,onClick:S}):e.jsx("button",{type:"button",disabled:!n||h===0,onClick:S,className:ge({tone:"primary",className:"w-full"}),children:k})),b&&h+g>0&&e.jsx("button",{type:"button",onClick:()=>c({}),className:ge({className:"w-full"}),children:se.confirm.cancel})]})}function UN({rig:t,pc:s,confirm:n,live:a,onReseat:l,onClose:r}){return e.jsxs(cs,{title:se.reseat.title(t.name,s),onClose:r,children:[e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:se.reseat.today(lu(t).map(o=>se.reseat.part(o.count,o.role)).join(", "))}),e.jsx(Lx,{rig:t,confirm:n,live:a,onReseat:l,onDone:r}),e.jsx(ha,{onClose:r})]})}function WN({rig:t,read:s,level:n,confirm:a,live:l,onAct:r,onClose:o}){var k,S;const[i,c]=f.useState(n==="mixed"?null:n),x=_t(),u=Jh((k=s==null?void 0:s.data)==null?void 0:k.policy),m=(((S=s==null?void 0:s.data)==null?void 0:S.seats.map(b=>b.session))??t.nodes.map(b=>b.session)).filter(b=>b.endsWith(`@${t.name}`)),p=i&&m.length?{kind:"rig.policy",rig:t.name,policy:i,seats:m}:null,h=!!p&&Hr(p),g=()=>{p&&(o(),r(p))},y=!l||!p||i===n;return e.jsxs(cs,{title:se.permissions.title(t.name),onClose:o,children:[e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:[se.permissions.sub,u?se.permissions.spec(se.level[u]):""].filter(Boolean).join(" ")}),(s==null?void 0:s.error)&&!s.data&&e.jsx("p",{role:"alert",className:"text-[12.5px] text-attention",children:se.permissions.unavailable}),e.jsx("div",{className:"flex flex-col gap-1.5",children:Qh.map(b=>e.jsx(yr,{pressed:i===b,disabled:!l,onClick:()=>c(b),sub:se.permissions.hint[b],title:e.jsxs(e.Fragment,{children:[se.level[b],(b==="yolo"||b==="spec")&&e.jsx("span",{className:"ml-1.5 inline-flex align-middle",children:e.jsx(zt,{tone:"perm",children:x?se.permissions.faceId:se.permissions.check})})]})},b))}),h?e.jsx(zs,{verb:se.permissions.apply,confirm:a,disabled:y,onClick:g}):e.jsx("button",{type:"button",disabled:y,onClick:g,className:ge({tone:"primary",className:"w-full"}),children:se.permissions.apply})]})}const KN=(t,s)=>{const n=rg(t,s.links).map(a=>{var r;const l=ys(a.who,(r=s.seats.find(o=>o.logicalId===a.who))==null?void 0:r.session);return a.kind==="linked"?se.seat.linked(l,a.label):se.seat[a.kind](l)});return n.length?n.join(" · "):se.seat.noLink};function VN({rig:t,seat:s,graph:n,node:a,session:l,status:r,near:o,onSettings:i,onClose:c}){const x=mo({session:l,node:a,graph:s,rigStatus:r}),u=po(s.runtime),m=ys(s.logicalId,s.session),p=[u?d.tools[u]:s.runtime,s.model??(a==null?void 0:a.model)??""].filter(Boolean).join(" · "),h=l!=null&&l.pending?se.seat.prompt(se.seatState[x]):se.seatState[x],g=a&&a.work>0?se.seat.tasks(a.work):se.seat.noTask,y=[[se.seat.harness,p],...s.context!==void 0?[[se.seat.context,e.jsx("span",{className:`font-mono ${s.context>=o?"text-attention":""}`,children:`${Math.round(s.context)} %`},"c")]]:[],[se.seat.now,h],[se.seat.work,g],[se.seat.links,KN(s.logicalId,n)]];return e.jsxs(cs,{title:m,onClose:c,children:[e.jsxs("div",{className:"-mt-2 flex items-center gap-2",children:[e.jsx(Ie,{state:su[x]}),u&&e.jsx(gs,{tool:u}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"text-[12.5px] text-muted",children:se.seat.of(s.logicalId,t)})]}),e.jsx("dl",{className:"m-0 grid grid-cols-[110px_1fr] gap-x-3 gap-y-1.5 text-[13px]",children:y.map(([k,S])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted",children:k}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:S})]},k))}),l?e.jsx("a",{href:ne({name:"thread",sessionId:l.id}),className:ge({tone:"primary",className:"w-full"}),children:se.seat.openSession}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:!0,className:ge({tone:"primary",className:"w-full"}),children:se.seat.openSession}),e.jsx("p",{className:"-mt-1 text-[12px] text-muted",children:se.seat.noSession})]}),e.jsx("button",{type:"button",onClick:i,className:ge({className:"w-full"}),children:e.jsx(Dt,{icon:"gear",children:se.seat.settings})})]})}function GN({rig:t,seat:s,node:n,selection:a,confirm:l,live:r,onAct:o,onClose:i}){const c=se.seatSettings,x=s.runtime==="codex"?"codex":s.runtime==="claude-code"||s.runtime==="claude"?"claude-code":null,u=s.model??(n==null?void 0:n.model)??"",m=a==="inherit"||a==="auto"||a==="full_bypass"?a:null,[p,h]=f.useState(x),[g,y]=f.useState(u),[k,S]=f.useState(null),[b,j]=f.useState(m),N=ys(s.logicalId,s.session),$=s.session??(n==null?void 0:n.session)??`${N}@${t}`,C=g.trim()===""||$m.safeParse(g.trim()).success,M=p!==null&&p!==x,v={kind:"seat.set",seat:$,...M?{runtime:p}:{},...g.trim()&&g.trim()!==u?{model:g.trim()}:{},...k?{effort:k}:{},...b&&b!==m?{permissions:b}:{}},A=Object.keys(v).length>2,T=Hr(v),R=po(s.runtime),P=[R?d.tools[R]:s.runtime,u,m?c.perm[m]:""].filter(Boolean),_=!r||!A||!C,D=()=>{i(),o(v)},E=(z,K,L)=>e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"text-[12.5px] text-muted",children:`${z} · ${K}`}),L]});return e.jsxs(cs,{title:c.title(N,t),onClose:i,children:[e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:c.today(P)}),E(c.harness,c.whenNow,e.jsx(La,{label:c.harness,value:p,disabled:!r,onChange:h,options:[{value:"claude-code",label:d.tools.claude},{value:"codex",label:d.tools.codex}]})),E(c.model,c.whenResume,e.jsx("input",{"aria-label":c.modelLabel,value:g,disabled:!r,onChange:z=>y(z.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 ${C?"border-input":"border-approval/60"}`})),E(c.effort,c.whenResume,e.jsx(La,{label:c.effort,value:k,disabled:!r,onChange:S,options:["medium","high","xhigh"].map(z=>({value:z,label:c.effortLevel[z]}))})),E(c.permissions,c.whenLaunch,e.jsx(La,{label:c.permissions,value:b,disabled:!r,onChange:j,options:["inherit","auto","full_bypass"].map(z=>({value:z,label:c.perm[z]}))})),M&&e.jsx("p",{className:"text-[12.5px] text-attention",children:c.moveNote}),T?e.jsx(zs,{verb:c.save,confirm:l,disabled:_,onClick:D}):e.jsx("button",{type:"button",disabled:_,onClick:D,className:ge({tone:"primary",className:"w-full"}),children:c.save})]})}function Ox({read:t,kindOnly:s=!1,retry:n}){const a=cu((t==null?void 0:t.data)??[]),l="overflow-hidden rounded-[10px] border border-line bg-surface dark:bg-transparent";return t!=null&&t.error&&!t.data?e.jsx("div",{className:l,children:e.jsx(Ds,{retry:n,retryLabel:se.unavailable.retry,children:se.snapshots.unavailable})}):t!=null&&t.data&&a.length===0?e.jsx("div",{className:l,children:e.jsx(Ds,{children:se.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(r=>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(q,{name:"camera",className:"size-4 text-muted"}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{children:tl(r.createdAt).long}),e.jsx("small",{className:"text-[11.5px] text-muted",children:s?se.snapshots.kind[r.kind]??r.kind:[se.snapshots.kind[r.kind]??r.kind,se.snapshots.status[r.status]??r.status].join(" · ")})]})]},r.id))}):e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:se.loading})}function XN({rig:t,read:s,live:n,running:a,onSnapshot:l,onRetry:r,onClose:o}){return e.jsxs(cs,{title:se.snapshots.title(t),onClose:o,children:[e.jsx(Ox,{read:s,retry:r}),e.jsx("button",{type:"button",disabled:!n||a,onClick:()=>{o(),l()},className:ge({className:"w-full"}),children:e.jsx(Dt,{icon:"camera",children:se.snapshots.take})}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:se.snapshots.utc})]})}const xe=d.rigs,Es=t=>{var s;return((s=Xa(t))==null?void 0:s.toISOString())??t},YN={mine:"border-attention/50 text-attention",progress:"border-info/45 text-info",pending:"border-input text-muted",blocked:"border-approval/45 text-approval"},QN=({tone:t})=>e.jsx("span",{"data-row":t,className:`flex-none rounded-[5px] border px-1.5 text-[11px] leading-[18px] whitespace-nowrap ${YN[t]}`,children:xe.queue.tone[t]}),Qs=t=>t.split("@")[0]??t;function Dx({seat:t,state:s,pod:n,tag:a,near:l,isNew:r,pulse:o,onOpen:i,onMore:c,top:x=!1,name:u,words:m}){const{swallow:p,...h}=ug(c),g=u??ys(t.logicalId,t.session),y=po(t.runtime),k=t.context!==void 0&&s!=="off"&&s!=="waiting"?Math.round(t.context):null,S=m??[x?n:void 0,xe.seatState[s]].filter(Boolean).join(" · "),b=r?"border-ok/55":s==="ask"?"border-attention/55":s==="perm"?"border-approval/55":s==="off"||s==="waiting"?"border-dashed border-input bg-transparent":"border-line",j=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx(Ie,{state:su[s],pulse:o}),e.jsx("b",{className:`truncate text-[13px] font-semibold ${s==="off"?"text-muted":""}`,children:g}),r?e.jsx("span",{className:"ml-auto",children:e.jsx(zt,{tone:"ok",children:xe.reseat.new})}):a&&y&&e.jsx("span",{className:"ml-auto",children:e.jsx(gs,{tool:y})})]}),e.jsxs("small",{className:`truncate text-[11.5px] ${s==="ask"?"text-attention":"text-muted"}`,children:[S,k!==null&&e.jsxs(e.Fragment,{children:[S?" · ":"",e.jsx("span",{className:`font-mono ${k>=l?"text-attention":""}`,children:`${k} %`})]})]})]}),N=`flex min-w-0 flex-col gap-px rounded-[9px] border bg-surface px-[9px] py-[7px] text-left ${b} ${x?"w-[190px] max-w-full":""}`;return i?e.jsx("button",{type:"button",...h,onClick:()=>{p!=null&&p()||i()},"aria-label":xe.seatLabel(g,xe.seatState[s]),"data-seat":t.logicalId,className:N,children:j}):e.jsx("div",{"data-seat":t.logicalId,className:N,children:j})}function ZN({graph:t,rig:s,status:n,sessions:a,near:l,added:r,onSeat:o,wide:i=!1}){var h;const c=Yh(t.seats,t.links),x=t.seats.find(g=>g.logicalId===c),u=Xh(t.seats.filter(g=>g.logicalId!==c),t.pods),m=(x==null?void 0:x.runtime)??((h=t.seats[0])==null?void 0:h.runtime),p=(g,y=!1)=>{var $;const k=Jd(a,s.name,g.logicalId),S=mo({session:k,node:s.nodes.find(C=>C.logicalId===g.logicalId),graph:g,rigStatus:n}),b=(($=t.pods.find(C=>C.id===g.pod))==null?void 0:$.label)??g.pod,j=o?()=>o(g.logicalId):void 0,N=i&&k?()=>tn({name:"thread",sessionId:k.id}):void 0;return e.jsx(Dx,{seat:g,state:S,pod:b,top:y,near:l,isNew:r.includes(g.logicalId),tag:y||g.runtime!==m,pulse:S==="starting"||n==="starting"&&S==="work",onOpen:N??j,onMore:N?j:void 0},g.logicalId)};return e.jsxs("div",{className:"flex flex-col items-center",children:[x&&e.jsxs(e.Fragment,{children:[p(x,!0),e.jsx("span",{"aria-hidden":"true",className:"h-3 w-[1.5px] bg-input"})]}),e.jsx("div",{className:`grid w-full gap-2 ${u.length>=3?"grid-cols-3":u.length===1&&!x?"grid-cols-1":"grid-cols-2"}`,children:u.map(g=>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:g.label}),g.seats.map(y=>p(y))]},g.id))})]})}function JN({row:t,mine:s}){const n=[[xe.queue.from,`${Qs(t.from)} → ${Qs(t.to)}`],...t.blockedOn?[[xe.queue.blockedOn,t.blockedOn]]:[],[xe.queue.created,[Be(Es(t.createdAt)),t.claimedAt?xe.queue.claimed(Be(Es(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:n.map(([a,l])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted",children:a}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:l})]},a))}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:xe.queue.readOnly}),s&&e.jsx("a",{href:ne({name:"atoi"}),className:ge({size:"sm",className:"self-start"}),children:xe.queue.seeAtoi})]})}function e0({read:t,asks:s,now:n,retry:a}){const[l,r]=f.useState(null),[o,i]=f.useState(!1),c=t==null?void 0:t.data;if(!c)return e.jsx(Ve,{children:t!=null&&t.error?e.jsx(Ds,{retry:a,retryLabel:xe.unavailable.retry,children:xe.queue.unavailable}):e.jsx("p",{role:"status",className:"p-3 text-[13px] text-muted",children:xe.loading})});const x={done:e.jsx("span",{className:"text-ok",children:"✓"}),handed:e.jsx("span",{className:"text-muted",children:"↪"}),stopped:e.jsx("span",{className:"text-approval",children:"✕"})};return e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:xe.queue.title(c.rows.length)}),e.jsxs(Ve,{children:[c.rows.length===0&&e.jsx("p",{className:"p-3 text-[13px] text-muted",children:xe.queue.none}),c.rows.map(u=>{const m=eg(u,s),p=l===u.id;return e.jsxs("div",{className:"contents",children:[e.jsxs("button",{type:"button","aria-expanded":p,onClick:()=>r(p?null:u.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(QN,{tone:m}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate",children:u.summary??u.id}),e.jsx("small",{className:"truncate text-[11.5px] text-muted",children:[`${Qs(u.from)} → ${Qs(u.to)}`,u.needsInput?xe.queue.prompt:""].filter(Boolean).join(" · ")})]}),e.jsx("span",{className:"font-mono text-[11px] whitespace-nowrap text-muted",children:yn(Es(u.updatedAt),n)})]}),p&&e.jsx(JN,{row:u,mine:m==="mine"})]},u.id)}),c.closed.length>0&&e.jsxs("button",{type:"button","aria-expanded":o,onClick:()=>i(!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(q,{name:"chevron",className:`size-3.5 transition-transform ${o?"rotate-90":""}`}),e.jsx("span",{children:xe.queue.closed(c.closed.length)})]}),o&&c.closed.map(u=>{const m=tg(u.state);return e.jsxs("div",{className:"flex min-h-[46px] items-center gap-[9px] border-t border-line px-3 py-1.5 text-[13px] text-muted",children:[e.jsx("span",{"aria-hidden":"true",children:x[m]}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate text-fg",children:u.summary??u.id}),e.jsx("small",{className:"truncate text-[11.5px]",children:`${Qs(u.from)} → ${Qs(u.to)} · ${xe.queue.closedTone[m]}`})]}),e.jsx("span",{className:"font-mono text-[11px]",children:Be(Es(u.updatedAt))})]},u.id)})]}),c.truncated&&e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:xe.queue.truncated})]})}function t0({rig:t,sessions:s,asks:n}){var g;const a=s.filter(y=>{var k;return((k=y.rig)==null?void 0:k.name)===t}),l=Vt(a),r=l.find(y=>y.filter==="permission")??l[0],o=r?a.find(y=>y.id===r.sessionId):void 0,i=r||n==null?void 0:n.find(y=>y.from.rig===t&&y.kind!=="update");if(!r&&!i)return null;const c=o?(g=o.rig)!=null&&g.role?ys(o.rig.role):o.name:i?Qs(i.from.seat):"",x=(r==null?void 0:r.filter)==="permission",[u,m,p]=x?xe.waits.permission(c):xe.waits.question(c),h=ne(r?{name:"request",sessionId:r.sessionId,key:r.key}:{name:"atoi"});return e.jsx(Gt,{warn:!x,danger:x,compact:!0,lead:e.jsx(Ie,{state:x?"perm":"ask"}),action:e.jsx("a",{href:h,className:ge({size:"xs"}),children:xe.waits.see}),children:e.jsxs("span",{children:[u,e.jsx("b",{className:"font-semibold",children:m}),p]})})}function s0({rig:t,rigs:s,store:n}){var pt,ft,ut,Y,Re,ke;const a=Rn(s),l=me(n),{pc:r,look:o}=Ut(),i=It(),[c,x]=f.useState(null),[u,m]=f.useState("last"),p=l.fresh,h=o==="offline",[g,y]=f.useState(()=>Date.now());f.useEffect(()=>{const ie=setInterval(()=>y(Date.now()),3e4);return()=>clearInterval(ie)},[]),f.useEffect(()=>{s.follow(),p&&(s.openRig(t),s.readSnapshots(t))},[s,t,p]);const k=Ht(r),S=a.state,b=S==null?void 0:S.rigs.find(ie=>ie.name===t),j=a.graphs[t],N=a.permissions[t],$=a.snapshots[t],C=a.queues[t],M=[...l.sessions.values()],v=((pt=l.device)==null?void 0:pt.contextNear)??70,A=!!((ft=l.device)!=null&&ft.confirm),T=Ao(a.runs,ie=>lg(ie.subject)===t),R=kl(T),P=ie=>{s.act(ie)},_=(ie,Ae)=>{s.reseat(t,ie,Ae?{delegation:Ae}:{})},D=()=>x(null),E=()=>s.openRig(t),z=e.jsx("button",{type:"button","aria-label":xe.more,title:xe.more,"aria-haspopup":"menu",onClick:()=>x({kind:"more"}),className:Tt(),children:e.jsx(q,{name:"more"})}),K=(ie,Ae,Je)=>i?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(is,{fallback:{name:"rigs"},label:xe.back}),e.jsx("h1",{className:"min-w-0 truncate text-[17px] font-semibold",children:t}),ie,Ae&&e.jsx("span",{className:"min-w-0 truncate text-[12.5px] text-muted",children:Ae}),e.jsx("span",{className:"flex-1"}),Je,b&&z]}):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(is,{fallback:{name:"rigs"},label:xe.back}),e.jsx("h1",{className:"min-w-0 truncate text-base font-semibold",children:t}),ie,e.jsx("span",{className:"flex-1"}),b&&z]}),L=`tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pb-[18px] ${i?"pt-[18px]":"pt-3"}`;if(!!S&&(!b||(j==null?void 0:j.error)==="unknown_rig"||(C==null?void 0:C.error)==="unknown_rig"))return e.jsxs(e.Fragment,{children:[K(null),e.jsx("main",{"data-tab-scroll":"",className:L,children:e.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-10 text-center",children:[e.jsx("h2",{className:"text-[17px] font-semibold",children:xe.readError.unknown_rig}),e.jsx("a",{href:ne({name:"rigs"}),className:ge({size:"sm",className:"mt-1.5"}),children:xe.back})]})})]});if(!b){const ie=a.error?xe.readError[a.error]:null;return e.jsxs(e.Fragment,{children:[K(null),e.jsxs("main",{"data-tab-scroll":"",className:L,children:[e.jsx(js,{body:xe.offlineBody}),ie?e.jsx(Gt,{warn:!0,role:"alert",lead:e.jsx(q,{name:"warning",className:"mt-px size-4 text-attention"}),children:e.jsx("b",{className:"font-semibold",children:ie})}):e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:xe.loading})]})]})}const ae=hs(b),U=ae==="stopped",O=N!=null&&N.data?au(N.data.seats):null,B=O?xe.level[O]:null,Z=cu(($==null?void 0:$.data)??[])[0],H=Z?tl(Z.createdAt).short:b.snapshot||"",X=(T==null?void 0:T.phase)==="done"&&((ut=T.reseated)!=null&&ut.ok)?T.reseated.added:[],te=b.nodes.filter(ie=>ie.stopped).map(ie=>ys(ie.logicalId,ie.session)),pe=ie=>{var Ae;return(Ae=j==null?void 0:j.data)==null?void 0:Ae.seats.find(Je=>Je.logicalId===ie)},ue=()=>{var ie;return P(u==="fresh"?{kind:"rig.start",rig:t,fresh:((ie=j==null?void 0:j.data)==null?void 0:ie.seats.map(Ae=>Ae.logicalId))??b.nodes.map(Ae=>Ae.logicalId)}:{kind:"rig.start",rig:t})},F=T&&!R?T:void 0,w=p&&!R,I=i?"sm":"md",V=i?"":"!h-[42px] !px-2 !text-[13.5px]",ee=e.jsx("button",{type:"button",disabled:!w,onClick:ue,className:ge({tone:"primary",size:I,className:i?"":"!h-[42px]"}),children:e.jsx(Dt,{icon:"power",children:xe.actions.start})}),Q=e.jsx("button",{type:"button",disabled:!w,onClick:()=>x({kind:"restart"}),className:ge({size:I,className:V}),children:e.jsx(Dt,{icon:"refresh",children:xe.actions.restart})}),J=e.jsx("button",{type:"button",disabled:!w,onClick:()=>x({kind:"stop"}),className:ge({tone:"danger",size:I,className:V}),children:e.jsx(Dt,{icon:"power",children:xe.actions.stop})}),fe=e.jsx("button",{type:"button",disabled:!w,onClick:()=>x({kind:"reseat"}),className:ge({size:I,className:V}),children:e.jsx(Dt,{icon:"plus",children:xe.actions.seats})}),be=R?e.jsx(Ja,{run:T,rigs:s,pc:k,bar:!i}):ae==="starting"?e.jsx(Zn,{bar:!i,children:xe.startingSeats(t,b.running,b.seats)}):null,tt=be??e.jsx("div",{className:`bleed grid flex-none gap-2 border-t border-line bg-bg px-3.5 pt-2.5 pb-3 ${U?"grid-cols-1":"grid-cols-3"}`,children:U?ee:e.jsxs(e.Fragment,{children:[fe,Q,J]})}),yt=p&&e.jsx(t0,{rig:t,sessions:M,asks:l.asks}),Ze=ae==="partial"&&te.length>0&&e.jsxs(Gt,{warn:!0,lead:e.jsx(q,{name:"warning",className:"mt-px size-4 text-attention"}),children:[e.jsx("span",{children:xe.partial(te,b.nodes.length-te.length)}),e.jsx("button",{type:"button",disabled:!w,onClick:()=>x({kind:"restart"}),className:ge({size:"sm",className:"self-start"}),children:xe.actions.restartRig})]}),Le=e.jsxs(e.Fragment,{children:[e.jsx(Ft,{aside:U?xe.topologyStopped:j!=null&&j.data?xe.topologyHint:void 0,children:xe.topology}),j!=null&&j.data?e.jsx(ZN,{graph:j.data,rig:b,status:ae,sessions:M,near:v,added:X,onSeat:ie=>x({kind:"seat",id:ie}),wide:i}):e.jsx(Ve,{children:j!=null&&j.error?e.jsx(Ds,{retry:E,retryLabel:xe.unavailable.retry,children:xe.readError[j.error]}):e.jsx("p",{role:"status",className:"p-3 text-[13px] text-muted",children:xe.loading})})]}),de=U&&b.snapshot&&e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:xe.resume}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(yr,{pressed:u==="last",disabled:!p,onClick:()=>m("last"),title:xe.resumeLast(Z?tl(Z.createdAt).long:b.snapshot),sub:xe.resumeLastBody}),e.jsx(yr,{pressed:u==="fresh",disabled:!p,onClick:()=>m("fresh"),title:xe.fresh,sub:xe.freshBody})]})]}),he=e.jsx(e0,{read:C,asks:l.asks,now:g,retry:E}),$e=i?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:[yt,Ze,Le,!U&&ae!=="starting"&&e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:xe.seatsByRole}),e.jsx(Ve,{children:e.jsx("div",{className:"flex flex-col gap-2.5 px-3 py-1",children:e.jsx(Lx,{rig:b,confirm:A,live:w,onReseat:_,context:Object.fromEntries((((Y=j==null?void 0:j.data)==null?void 0:Y.seats)??[]).map(ie=>[ie.logicalId,ie.context]))},b.nodes.length)})})]}),de]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3.5",children:[he,e.jsx(Ft,{children:xe.actions.snapshots}),e.jsx(Ox,{read:$,kindOnly:!0,retry:()=>s.readSnapshots(t)}),e.jsx("button",{type:"button",disabled:!w,onClick:()=>P({kind:"rig.snapshot",rig:t}),className:ge({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(Dt,{icon:"camera",children:xe.snapshots.take})})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx(Pl,{label:xe.tiles.seats,value:`${b.running}/${b.seats}`}),e.jsx(Pl,{label:xe.tiles.permissions,value:B??"—",onOpen:()=>x({kind:"permissions"})}),e.jsx(Pl,{label:xe.tiles.snapshot,value:H||"—",onOpen:()=>x({kind:"snapshots"})})]}),yt,Ze,Le,he,de]}),Oe=(c==null?void 0:c.kind)==="seat"||(c==null?void 0:c.kind)==="settings"?pe(c.id):void 0,rt=Oe?b.nodes.find(ie=>ie.logicalId===Oe.logicalId):void 0,Ge=[xe.seats(b.running,b.seats),B??"",H?xe.snapshot(H):""].filter(Boolean).join(" · ");return e.jsxs(e.Fragment,{children:[K(e.jsx(vn,{tone:iu[ae],children:xe.status[ae]}),Ge,!be&&(U?ee:e.jsxs(e.Fragment,{children:[Q,J]}))),e.jsxs("main",{"data-tab-scroll":"",className:L,children:[e.jsx(js,{body:xe.offlineBody}),i&&be,F&&e.jsx(Ja,{run:F,rigs:s,pc:k}),e.jsx("div",{className:`flex flex-col gap-3 ${h?"opacity-50":""}`,children:$e})]}),!i&&tt,(c==null?void 0:c.kind)==="more"&&e.jsx(BN,{rig:t,live:p,running:R,snapshots:$!=null&&$.data?$.data.length:null,level:B,onClose:D,onSnapshot:()=>{D(),P({kind:"rig.snapshot",rig:t})},onSnapshots:()=>x({kind:"snapshots"}),onPermissions:()=>x({kind:"permissions"}),onRefresh:()=>{D(),s.retry(),s.openRig(t),s.readSnapshots(t)}}),((c==null?void 0:c.kind)==="stop"||(c==null?void 0:c.kind)==="restart")&&e.jsx(HN,{rig:b,pc:k,verb:c.kind,confirm:A,live:w,onAct:P,onClose:D}),(c==null?void 0:c.kind)==="reseat"&&e.jsx(UN,{rig:b,pc:k,confirm:A,live:w,onReseat:_,onClose:D}),(c==null?void 0:c.kind)==="permissions"&&e.jsx(WN,{rig:b,read:N,level:O,confirm:A,live:w,onAct:P,onClose:D}),(c==null?void 0:c.kind)==="snapshots"&&e.jsx(XN,{rig:t,read:$,live:p,running:R,onSnapshot:()=>P({kind:"rig.snapshot",rig:t}),onRetry:()=>s.readSnapshots(t),onClose:D}),(c==null?void 0:c.kind)==="seat"&&Oe&&(j==null?void 0:j.data)&&e.jsx(VN,{rig:t,seat:Oe,graph:j.data,node:rt,session:Jd(M,t,Oe.logicalId),status:ae,near:v,onSettings:()=>x({kind:"settings",id:Oe.logicalId}),onClose:D}),(c==null?void 0:c.kind)==="settings"&&Oe&&e.jsx(GN,{rig:t,seat:Oe,node:rt,selection:(ke=(Re=N==null?void 0:N.data)==null?void 0:Re.seats.find(ie=>ie.logicalId===Oe.logicalId))==null?void 0:ke.selection,confirm:A,live:w,onAct:P,onClose:D})]})}const xs=d.rigs,ve=xs.max,n0={sent:"idle",taken:"work",asking:"ask",proposed:"rig",running:"work",done:"done",closed:"done"},a0={sent:"plain",taken:"work",asking:"ask",proposed:"rig",running:"work",done:"ok",closed:"plain"},l0=t=>{var s;return((s=t.trail.at(-1))==null?void 0:s.at)??t.sentAt},Fx=t=>{const s=sl(t);if(!s)return null;for(let n=t.trail.length-1;n>=0;n--)if(t.trail[n].text===s)return t.trail[n].at;return null};function r0(t){var n;const s=tl(l0(t)).short;return t.state==="asking"?`${ve.asks} · ${s}`:t.state==="running"?[ve.state.running,((n=t.current)==null?void 0:n.seat.split("@")[0])??"",ve.since(s)].filter(Boolean).join(" · "):`${ve.state[t.state]} · ${s}`}const sl=t=>{var s,n;return((s=t.question)==null?void 0:s.text)??((n=t.proposal)==null?void 0:n.text)??null};function o0({run:t,pc:s,onAgain:n,onClose:a}){var i,c;const l={onClose:a,closeLabel:xs.done.close},r=e.jsx("button",{type:"button",onClick:n,className:ge({size:"xs",className:"mt-1.5"}),children:ve.sendAgain}),o=t.phase==="uncertain"?"uncertain":t.phase==="done"?(i=t.sent)==null?void 0:i.error:void 0;return o?o==="uncertain"?e.jsx(Se,{mark:"ask",title:ve.errors.uncertain.title,sub:ve.errors.uncertain.body,...l,children:r}):o==="refused"?e.jsx(Se,{mark:"bad",title:ve.errors.refused.title,...(c=t.sent)!=null&&c.message?{sub:e.jsx("span",{className:"font-mono",children:t.sent.message})}:{},...l}):o==="openrig_stopped"?e.jsx(Se,{mark:"bad",title:ve.errors.openrig_stopped.title(s),sub:ve.errors.openrig_stopped.body,...l,children:r}):o==="no_operator"||o==="unreachable"?e.jsx(Se,{mark:"bad",title:ve.errors[o].title,sub:ve.errors[o].body,...l,children:r}):e.jsx(Se,{mark:"bad",title:ve.unsent,sub:ve.keeps,...l,children:r}):e.jsx(Se,{mark:"bad",title:ve.unsent,sub:ve.keeps,...l,children:r})}const i0=t=>{var s;return t.phase==="done"&&!!((s=t.sent)!=null&&s.ok)};function zx({runs:t,rigs:s,pc:n,bubble:a}){return e.jsx(e.Fragment,{children:t.filter(l=>!i0(l)).map(l=>{const r=l.subject;if(r.kind!=="goal"&&r.kind!=="reply")return null;if(kl(l))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:[r.text," ",e.jsx(En,{className:"ml-1 align-[-1px] text-muted"})]},l.id);const o=()=>{s.dismiss(l.id),r.kind==="goal"?s.sendGoal(r.text,r.goalId):s.replyGoal(r.goalId,r.text,r.replyId)};return e.jsx(o0,{run:l,pc:n,onAgain:o,onClose:()=>s.dismiss(l.id)},l.id)})})}function c0(t){var s;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(((s=t.to)==null?void 0:s.split("@")[0])??"");case"closed":return ve.trail.closed}}function Px({goal:t,runs:s,rigs:n,pc:a,compact:l=!1}){const r=sl(t),o=Fx(t),i=t.question??(t.proposal&&!t.proposal.answer?t.proposal:null),c=s.filter(x=>x.subject.kind==="reply"&&x.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}),!l&&t.trail.some(x=>x.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(x=>x.kind!=="sent").map((x,u)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"font-mono text-[11.5px]",children:Be(Es(x.at))}),e.jsx("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:c0(x)})]},`${x.at}-${u}`))}),r&&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(Ie,{state:"idle"}),o?`${xs.kernelView.max} · ${Be(Es(o))}`:xs.kernelView.max]}),e.jsx("span",{className:"[overflow-wrap:anywhere]",children:r})]}),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(Ie,{state:"ask"}),e.jsx("b",{className:"text-[14px] font-semibold",children:t.question?ve.question:ve.proposal}),o&&e.jsx("span",{className:"ml-auto font-mono text-[11.5px] text-muted",children:Be(Es(o))})]}),!l&&e.jsx("p",{className:"text-[13px] text-muted",children:t.question?ve.questionBody:ve.proposalBody}),e.jsx("a",{href:ne({name:"atoi"}),className:ge({size:"sm",className:"self-start"}),children:ve.seeAtoi})]}),e.jsx(zx,{runs:c,rigs:n,pc:a,bubble:!0})]})}function Bx({goalId:t,rigs:s,live:n}){const[a,l]=f.useState("");return e.jsx(sd,{label:ve.replyPlaceholder,sendLabel:ve.send,placeholder:ve.replyPlaceholder,offlinePlaceholder:ve.offlinePlaceholder,offline:!n,value:a,onChange:l,onSend:()=>{const r=a.trim();r&&(l(""),s.replyGoal(t,r).then(o=>{o.phase==="unsent"&&l(i=>i||r)}))}})}function d0({goalId:t,rigs:s,store:n}){var C,M,v,A;const a=Rn(s),l=me(n),{pc:r,look:o}=Ut(),i=It(),c=l.fresh,x=o==="offline",u=Ht(r),[m,p]=f.useState("");f.useEffect(()=>{s.follow(),s.followGoals()},[s,c]);const h=((M=(C=a.goals)==null?void 0:C.data)==null?void 0:M.goals)??[],g=t?h.find(T=>T.goalId===t):void 0,y=`tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pb-[18px] ${i?"pt-[18px]":"pt-3"}`,k=i?"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",S="bleed flex-none border-t border-line bg-bg px-3.5 pt-2.5 pb-3",b=(()=>{var T,R;return(T=a.goals)!=null&&T.error&&!a.goals.data?e.jsx(Ve,{children:e.jsx(Ds,{retry:()=>s.followGoals(),retryLabel:xs.unavailable.retry,children:ve.goalsUnavailable})}):(R=a.goals)!=null&&R.data?null:e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:xs.loading})})();if(t)return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:k,children:[e.jsx(is,{fallback:{name:"max"},label:xs.backMax}),e.jsx("h1",{className:"min-w-0 truncate text-base font-semibold",children:(g==null?void 0:g.text)??ve.title}),g&&e.jsx("span",{className:"flex-none",children:e.jsx(zt,{tone:a0[g.state],children:ve.statePill[g.state]})})]}),e.jsxs("main",{"data-tab-scroll":"",className:`${y} justify-end`,children:[e.jsx(js,{body:xs.offlineBody}),g?e.jsx("div",{className:x?"opacity-50":"",children:e.jsx(Px,{goal:g,runs:a.runs,rigs:s,pc:u})}):b??e.jsx("p",{role:"alert",className:"text-[13px] text-attention",children:ve.goalsUnavailable})]}),g&&e.jsx("div",{className:S,children:e.jsx(Bx,{goalId:g.goalId,rigs:s,live:c})})]});const j=a.runs.filter(T=>T.subject.kind==="goal"),N=()=>{const T=m.trim();T&&(p(""),s.sendGoal(T).then(R=>{R.phase==="unsent"&&p(P=>P||T)}))},$=()=>{var T;(T=document.querySelector("[data-goal-field] textarea"))==null||T.focus()};return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:k,children:[e.jsx(is,{fallback:{name:"kernel"},label:xs.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:!c,onClick:$,className:ge({tone:"primary",size:"sm"}),children:e.jsx(Dt,{icon:"plus",children:ve.newGoal})})]}),e.jsxs("main",{"data-tab-scroll":"",className:y,children:[e.jsx(js,{body:xs.offlineBody}),e.jsxs("div",{className:`flex flex-col gap-3 ${x?"opacity-50":""}`,children:[b??(h.length===0?e.jsx(Ve,{children:e.jsx(Ds,{children:ve.none})}):e.jsx(Ve,{label:ve.goalsLabel,children:h.map(T=>e.jsxs("a",{href:ne({name:"max",goalId:T.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(Ie,{state:n0[T.state],pulse:T.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:T.text}),e.jsx("small",{className:`text-[12px] ${T.state==="asking"?"text-attention":"text-muted"}`,children:r0(T)})]})]},T.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(zx,{runs:j,rigs:s,pc:u,bubble:!1}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:ve.atoiNote})]})]}),e.jsx("div",{"data-goal-field":"",className:S,children:e.jsx(sd,{label:ve.goalPlaceholder,sendLabel:ve.send,placeholder:ve.goalPlaceholder,offlinePlaceholder:ve.offlinePlaceholder,offline:!c,value:m,onChange:p,onSend:N})})]})}const _e=d.rigs,kt=_e.kernelView,u0=t=>/^qitem-\d{14}-[0-9a-f]{8,}$/.test(t)?`…${t.slice(-8)}`:t;function x0({graph:t,status:s,near:n}){var c;const a=t.seats,l=a.find(x=>ru(x.logicalId)),r=a.filter(x=>x!==l),o=(l==null?void 0:l.runtime)??((c=a[0])==null?void 0:c.runtime),i=(x,u=!1)=>{var g;const m=mo({graph:x,rigStatus:s}),p=((g=t.pods.find(y=>y.id===x.pod))==null?void 0:g.label)??x.pod,h=[u?p:"",m==="idle"?"":_e.seatState[m]].filter(Boolean).join(" · ");return e.jsx(Dx,{seat:x,state:m,pod:p,top:u,near:n,isNew:!1,name:ou({logicalId:x.logicalId,session:x.session??""}),words:h,tag:u||x.runtime!==o,pulse:m==="starting"},x.logicalId)};return e.jsxs("div",{className:"flex flex-col items-center",children:[l&&e.jsxs(e.Fragment,{children:[i(l,!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:r.map(x=>i(x))})]})}function m0({rigs:t}){const s=Rn(t).routing,n=s!=null&&s.data?[...s.data].reverse():null,a=l=>{const r=sg(l);return r.verb==="handed"?kt.change.handed(r.to):r.verb==="blocked"?kt.change.blocked(u0(r.on)):r.verb==="other"?r.text:kt.change[r.verb]};return e.jsxs(e.Fragment,{children:[e.jsx(Ft,{aside:kt.allRigs,children:kt.routing}),e.jsx(Ve,{children:n?n.length===0?e.jsx(Ds,{children:kt.noRouting}):n.map((l,r)=>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:Be(Es(l.at))}),e.jsxs("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:[e.jsx("b",{className:"font-semibold",children:kt.actor(l.seat.split("@")[0]??l.seat)})," ",a(l.change)]}),e.jsx("small",{className:"col-start-2 truncate text-[11.5px] text-muted",children:[l.rig,l.summary??""].filter(Boolean).join(" · ")})]},`${l.qitem}-${l.at}-${r}`)):s!=null&&s.error?e.jsx(Ds,{retry:()=>t.readRouting(),retryLabel:_e.unavailable.retry,children:_e.readError[s.error]}):e.jsx("p",{role:"status",className:"p-3 text-[13px] text-muted",children:_e.loading})})]})}function p0({rigs:t,store:s}){var I,V,ee,Q;const n=Rn(t),a=me(s),{pc:l,look:r}=Ut(),o=It(),[i]=Eo(),[c,x]=f.useState(null),u=a.fresh,m=r==="offline";f.useEffect(()=>{t.follow(),t.followGoals(),u&&(t.openRig(Pn),t.readRouting())},[t,u]);const p=n.state?br(n.state).filter(J=>hs(J)!=="stopped").map(J=>J.name).join(" "):"";f.useEffect(()=>{if(u&&p)for(const J of p.split(" "))t.readPermissions(J)},[t,u,p]);const h=Ht(l),g=n.state,y=`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(is,{fallback:{name:"rigs"},label:_e.back}),e.jsx("h1",{className:`min-w-0 truncate font-semibold ${o?"text-[17px]":"text-base"}`,children:_e.kernel}),J,e.jsx("span",{className:"flex-1"}),J&&e.jsx("button",{type:"button","aria-label":_e.more,title:_e.more,"aria-haspopup":"menu",onClick:()=>x("menu"),className:Tt(),children:e.jsx(q,{name:"more"})})]}),S=()=>{t.retry(),t.openRig(Pn),t.readRouting()};if(!g){const J=n.error?_e.readError[n.error]:null;return e.jsxs(e.Fragment,{children:[k(null),e.jsxs("main",{"data-tab-scroll":"",className:y,children:[e.jsx(js,{body:_e.offlineBody}),J?e.jsx(Gt,{warn:!0,role:"alert",lead:e.jsx(q,{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:_e.loading})]})]})}const b=Zd(g),j=g.kernel.state,N=b?hs(b):"stopped",$=n.graphs[Pn],C=((I=a.device)==null?void 0:I.contextNear)??70,M=!!((V=a.device)!=null&&V.confirm),v=Ao(n.runs,J=>J.subject.kind==="act"&&/^(kernel|daemon)\./.test(J.subject.action.kind)),A=kl(v),T=u&&!A,R=J=>{t.act(J)},P=[...a.sessions.values()],_=br(g),D=g.daemon.state==="running",E=j==="ready"||j==="starting",z=((Q=(ee=n.goals)==null?void 0:ee.data)==null?void 0:Q.goals)??[],K=j==="stopped"?e.jsxs(Gt,{lead:e.jsx("span",{className:"mt-[5px]",children:e.jsx(Ie,{state:"off"})}),children:[e.jsx("span",{children:e.jsx("b",{className:"font-semibold",children:kt.stoppedTitle})}),e.jsx("span",{className:"text-muted",children:kt.stoppedBody}),e.jsx("button",{type:"button",disabled:!T||!D,onClick:()=>R({kind:"kernel.start"}),className:ge({tone:"primary",size:"sm",className:"self-start"}),children:e.jsx(Dt,{icon:"power",children:kt.startKernel})})]}):j==="skipped"?e.jsxs(Gt,{lead:e.jsx("span",{className:"mt-[5px]",children:e.jsx(Ie,{state:"off"})}),children:[e.jsx("span",{children:e.jsx("b",{className:"font-semibold",children:kt.skippedTitle})}),e.jsx("span",{className:"text-muted",children:kt.skippedBody})]}):null,L=z.find(J=>sl(J)!==null),W=L?Fx(L):null,ae=z.find(J=>J.state!=="done"&&J.state!=="closed"),U=e.jsx("a",{href:ne({name:"max"}),className:ge({tone:"primary",className:"w-full"}),children:kt.talk}),O=o&&ae?e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:`${kt.max} · ${ae.text}`}),e.jsx(Ve,{children:e.jsxs("div",{className:"flex flex-col gap-2.5 p-3",children:[e.jsx(Px,{goal:ae,runs:n.runs,rigs:t,pc:h,compact:!0}),e.jsx(Bx,{goalId:ae.goalId,rigs:t,live:u})]})})]}):e.jsx(Ve,{children:e.jsxs("div",{className:"flex flex-col gap-2 p-3",children:[L&&e.jsx("span",{className:"text-[12px] text-muted",children:kt.lastMessage(W?Be(Es(W)):null)}),L&&e.jsx("span",{className:"text-[13.5px] leading-[19px] [overflow-wrap:anywhere]",children:sl(L)}),U]})}),B=J=>{var tt;const fe=(tt=n.permissions[J])==null?void 0:tt.data,be=fe?au(fe.seats):null;return be?_e.level[be]:""},Z=_.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:kt.driven}),e.jsx(Ve,{children:_.map(J=>{const fe=hs(J),be=tu(J,eu(J.name,P,a.asks));return e.jsxs("a",{href:ne({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(Ie,{state:be}),e.jsx("span",{className:`min-w-0 flex-1 truncate ${fe==="stopped"?"text-muted":""}`,children:J.name}),e.jsx("span",{className:"text-[12px] text-muted",children:fe==="stopped"?_e.seatState.off:[_e.seatCount(J.seats),B(J.name)].filter(Boolean).join(" · ")}),e.jsx(q,{name:"chevron",className:"size-4 text-muted"})]},J.id)})})]}),H=(J,fe)=>e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{type:"button",disabled:!T,onClick:J,className:ge({}),children:e.jsx(Dt,{icon:"refresh",children:_e.actions.restart})}),e.jsx("button",{type:"button",disabled:!T,onClick:fe,className:ge({tone:"danger"}),children:e.jsx(Dt,{icon:"power",children:_e.actions.stop})})]}),X=E&&e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:_e.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:_e.confirm.kernelNote}),H(()=>x("kernel.restart"),()=>x("kernel.stop"))]})})]}),te=e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:_e.daemon}),e.jsxs(Ve,{children:[e.jsx(To,{state:g}),e.jsx(Ix,{disabled:!u,next:!0}),D&&e.jsx("div",{className:"px-3 pt-2.5 pb-3",children:H(()=>x("daemon.restart"),()=>x("daemon.stop"))})]}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:kt.daemonNote})]}),pe=_.flatMap(J=>og(J)).length,ue=_.filter(J=>hs(J)!=="stopped").length,F=[_e.confirm.daemonStops(ue),pe?_e.confirm.working(pe):""].filter(Boolean).join(" "),w=()=>x(null);return e.jsxs(e.Fragment,{children:[k(e.jsx(vn,{tone:_x[j],children:_e.kernelState[j]})),e.jsxs("main",{"data-tab-scroll":"",className:y,children:[e.jsx(js,{body:_e.offlineBody}),v&&e.jsx(Ja,{run:v,rigs:t,pc:h}),e.jsxs("div",{className:`flex flex-col gap-3 ${o?"max-w-[720px]":""} ${m?"opacity-50":""}`,children:[K,e.jsx("p",{className:"text-[12.5px] leading-[18px] text-muted",children:kt.role}),E&&($!=null&&$.data?e.jsx(x0,{graph:$.data,status:N,near:C}):e.jsx(Ve,{children:e.jsx("p",{role:$!=null&&$.error?"alert":"status",className:"p-3 text-[13px] text-muted",children:$!=null&&$.error?_e.readError[$.error]:_e.loading})})),E&&O,Z,e.jsx(m0,{rigs:t}),X,te]})]}),c==="menu"&&e.jsx(qN,{live:u,up:E&&!A,onClose:w,onRefresh:()=>{w(),S()},onRestart:()=>x("kernel.restart"),onStop:()=>x("kernel.stop")}),c==="kernel.restart"&&e.jsx(Ma,{title:_e.confirm.restartKernel(h),conseq:{title:_e.confirm.kernelNote},verb:_e.actions.restart,confirm:M,live:T,onConfirm:()=>R({kind:"kernel.restart"}),onClose:w}),c==="kernel.stop"&&e.jsx(Ma,{title:_e.confirm.stopKernel(h),conseq:{title:_e.confirm.kernelNote},verb:_e.actions.stop,confirm:M,live:T,onConfirm:()=>R({kind:"kernel.stop"}),onClose:w}),c==="daemon.restart"&&e.jsx(Ma,{title:_e.confirm.restartDaemon(h),conseq:{title:F},verb:_e.actions.restart,confirm:M,live:T,onConfirm:()=>R(Tx("restart",i)),onClose:w}),c==="daemon.stop"&&e.jsx(Ma,{title:_e.confirm.stopDaemon(h),conseq:{title:F},verb:_e.actions.stop,confirm:M,live:T,onConfirm:()=>R({kind:"daemon.stop"}),onClose:w})]})}const ce=d.launch,f0=["claude","codex","cursor","omp"],h0=["always-ask","write","yolo"],g0=2e4,Vs={project:`${Cs}launch.project`,prefs:`${Cs}launch.prefs`,draft:`${Cs}launch.draft`},Pr=(t,s)=>{try{return(t==null?void 0:t.getItem(s))??null}catch{return null}},Ea=(t,s,n)=>{try{n===null?t==null||t.removeItem(s):t==null||t.setItem(s,n)}catch{}};function gc(t){try{const s=JSON.parse(Pr(t,Vs.prefs)??"{}");return s&&typeof s=="object"?s:{}}catch{return{}}}const bc=t=>t.replace(/\/+$/,"").split("/").pop()||t,qx=t=>t.machine==="local",jc=t=>qx(t)&&t.exists!==!1;function yc({store:t,storage:s}){var Je,xt,Yt,ze,ht,Nt,we;const n=me(t),a=Qe(s),l=Ht(Ut().pc??((Je=n.daemon)==null?void 0:Je.name)??null),r=n.projects,[o,i]=f.useState(()=>Pr(a,Vs.project)),c=r.find(G=>G.id===o)??r[0],x=gc(a),u=c?x[c.id]:void 0,[m,p]=f.useState((u==null?void 0:u.tool)??"claude"),[h,g]=f.useState({model:(u==null?void 0:u.model)??null,effort:(u==null?void 0:u.effort)??null}),[y,k]=f.useState("always-ask"),[S,b]=f.useState(null),[j,N]=f.useState(()=>Pr(a,Vs.draft)??""),[$,C]=f.useState(null),[M,v]=f.useState(!1),[A,T]=f.useState(!1),[R,P]=f.useState(null),[_,D]=f.useState(null),E=f.useId(),[z,K]=f.useState(!1),[L,W]=f.useState(""),ae=f.useId(),U=f.useRef(null),O=f.useRef(!1);f.useEffect(()=>{var G;z&&O.current&&((G=U.current)==null||G.focus())},[z]);const B=c==null?void 0:c.id;f.useEffect(()=>{B&&n.fresh&&t.requestProjectFolders(B)},[B,n.fresh,t]),f.useEffect(()=>{var G;n.fresh&&((G=n.daemon)!=null&&G.models)&&t.requestModels(m)},[m,n.fresh,(xt=n.daemon)==null?void 0:xt.models,t]);const Z=B?n.projectFolders[B]:void 0,H=Array.isArray(Z)?Z:[],X=H.find(jc),te=(S??(X?[X.path]:[])).filter(G=>H.some(Ne=>Ne.path===G&&jc(Ne))),pe=Uo.includes(m),ue=((Yt=n.models[m])==null?void 0:Yt.models)??[],F=G=>{G(),P(null),T(!1)},w=G=>F(()=>{i(G.id),Ea(a,Vs.project,G.id),b(null);const Ne=x[G.id];p((Ne==null?void 0:Ne.tool)??"claude"),g({model:(Ne==null?void 0:Ne.model)??null,effort:(Ne==null?void 0:Ne.effort)??null}),C(null)}),I=G=>F(()=>{p(G),g({model:null,effort:null}),!Uo.includes(G)&&te.length>1&&b(te.slice(0,1))}),V=G=>F(()=>{if(!pe){b([G]),C(null);return}const oe=te.includes(G)?te.filter(qe=>qe!==G):[...te,G];b(oe.length?oe:te)}),ee=G=>{N(G),Ea(a,Vs.draft,G),P(null),T(!1)},Q=_?n.ops[_]:void 0,[J,fe]=f.useState(0);f.useEffect(()=>{if(!_)return;const G=setTimeout(()=>{const Ne=t.getState().ops[_];Ne&&ps(Ne.phase)&&(v(!1),P({kind:"timeout",op:_}))},g0);return()=>clearTimeout(G)},[_,J,t]),f.useEffect(()=>{if(!_||!Q||ps(Q.phase))return;if(v(!1),D(null),Q.phase==="applied"){Ea(a,Vs.draft,null),c&&Ea(a,Vs.prefs,JSON.stringify({...gc(a),[c.id]:{tool:m,model:h.model,effort:h.effort}})),Q.id?(Oj(Q.id,(c==null?void 0:c.name)??"",s),fs({name:"thread",sessionId:Q.id})):fs({name:"sessions"});return}if(Q.phase==="failed"){P({kind:"failed"});return}const G=Q.reason??"other";G==="stale"&&B&&t.requestProjectFolders(B),P({kind:"refused",reason:G})},[_,Q==null?void 0:Q.phase]);const be=async()=>{if(!c)return;const G={project:c.id,tool:m,folders:te,prompt:j.trim(),...de?{name:de}:{},...h.model?{model:h.model}:{},...h.effort?{effort:h.effort}:{},...m==="omp"&&y!=="always-ask"?{approval:y}:{}};v(!0),P(null),T(!1);const Ne=await t.launchSession(G);if(Ne.status==="sent"){D(Ne.op),fe(oe=>oe+1);return}v(!1),Ne.status==="cancelled"?T(!0):Ne.status==="noAnswer"?P({kind:"timeout",op:null}):Ne.status==="failed"?P({kind:"refused",reason:"other"}):P({kind:"refused",reason:Ne.reason})},tt=G=>{if(G.kind==="timeout"&&G.op){if(t.launchAgain(G.op)){D(G.op),fe(oe=>oe+1),v(!0),P(null);return}const Ne=t.getState().ops[G.op];if(Ne&&ps(Ne.phase)){P({...G});return}}be()},yt=G=>G.kind==="timeout"&&G.op!==null&&!!n.ops[G.op]&&ps(n.ops[G.op].phase)&&!t.canLaunchAgain(G.op),Ze=[...n.sessions.values()].filter(G=>G.state!=="exited"),Le=z?L:"",de=Cm(Le),he=Mm(Ho(Ze),Le)!==void 0,$e=he?Em(Ze,Le):void 0,Oe=he?$e?$e.name.toLowerCase()===de.toLowerCase()&&$e.project?ce.nameTaken(de,$e.project):ce.nameTakenBy(de,$e.name):ce.nameReserved:null,rt=d.tools[m],Ge=!n.fresh,pt=Ge?{label:ce.missing.machine}:(ze=n.daemon)!=null&&ze.launch?(ht=n.device)!=null&&ht.confirm?!c||te.length===0?{label:ce.chooseProject}:he?{label:ce.missing.name}:j.trim()===""?{label:ce.missing.prompt}:null:{label:ce.missing.setup,body:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ce.setupBody}),e.jsxs("a",{href:"#/connection/link",className:Fe({size:"sm",className:"self-start"}),children:[e.jsx(q,{name:"gear",className:"size-4"}),ce.openSettings]})]})}:{label:ce.missing.pcOld(l),body:e.jsx("span",{className:"text-center text-[12px] leading-4 text-muted",children:ce.pcOldBody})},ft=R&&!(Ge&&R.kind==="timeout")?R:null,ut=h.model===null?null:((Nt=ue.find(G=>G.id===h.model))==null?void 0:Nt.label)??h.model,Y=h.model===null?d.model.byDefault:ce.pick(ut,h.effort?ca(h.effort):null),Re=h.model===null?d.model.defaultHint:(()=>{const G=ue.find(Ne=>Ne.id===h.model);return G?Fd(m,G):void 0})(),ke=H.find(G=>G.path===te[0]),ie=ke?ke===H[0]?ke.branch?ce.onBranch(ke.branch):ce.inFolder:bc(ke.path):void 0,Ae=ke&&ke!==H[0]?ke.branch??void 0:void 0;return e.jsxs(e.Fragment,{children:[e.jsx(la,{back:e.jsx("button",{type:"button","aria-label":ce.close,title:ce.close,onClick:()=>al({name:"sessions"}),className:Tt({className:"text-muted"}),children:e.jsx(q,{name:"close"})}),name:ce.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(Ks,{label:ce.project,aside:r.length>0?e.jsxs("button",{type:"button",role:"switch","aria-checked":z,onClick:()=>F(()=>{O.current=!0,K(G=>!G)}),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 ${z?"border-transparent bg-primary":"border-input bg-raised"}`,children:e.jsx("span",{className:`absolute top-[2px] size-[11px] rounded-full transition-all ${z?"left-[15px] bg-white":"left-[2px] bg-muted"}`})}),ce.nameToggle]}):void 0,children:r.length===0?e.jsxs("p",{className:"text-body text-muted",children:[d.launch.noProjects," ",ce.noProjectsBody]}):e.jsx(Zl,{onClick:()=>C("project"),lead:c?e.jsx(Ie,{state:Ge?"off":"idle"}):null,label:ce.project,text:c?e.jsx("b",{className:"font-semibold",children:c.name}):ce.chooseProject,sub:c?[l,Ge?ce.offline:u?ce.remembered:null].filter(Boolean).join(" · "):void 0,dim:Ge})}),z&&r.length>0&&e.jsxs(Ks,{label:ce.name,htmlFor:ae,children:[e.jsx("input",{id:ae,ref:U,type:"text",value:L,placeholder:ce.namePlaceholder(Rm(Ho(Ze))),spellCheck:!1,autoComplete:"off",autoCapitalize:"off","aria-invalid":he||void 0,"aria-describedby":`${ae}-say`,onChange:G=>{const Ne=G.target.value;F(()=>W(Ne))},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)] ${he?"border-danger-fg":"border-input"}`}),Oe?e.jsx("span",{id:`${ae}-say`,role:"alert",className:"text-[12px] leading-4 text-danger-fg",children:Oe}):e.jsx("span",{id:`${ae}-say`,className:`text-[12px] leading-4 ${de&&de!==Le?"text-fg":"text-muted"}`,children:de&&de!==Le?ce.nameCleaned(de):ce.nameHint})]}),c&&e.jsx(Ks,{label:ce.where,children:e.jsx(Zl,{onClick:()=>C("where"),lead:e.jsx(q,{name:ke!=null&&ke.branch?"branch":"folder",className:"size-4 text-muted"}),label:ce.where,text:te.length>1&&ie?e.jsxs(e.Fragment,{children:[e.jsxs("span",{"aria-hidden":"true",children:[ie,e.jsx("span",{className:"ml-1.5 font-mono text-small text-muted",children:ce.more(te.length-1)})]}),e.jsx("span",{className:"sr-only",children:ce.moreLabel(ie,te.length-1)})]}):ie??"",sub:Ae})}),e.jsx(Ks,{label:ce.agent,children:e.jsx("div",{role:"group","aria-label":ce.agent,className:"grid grid-cols-2 gap-2",children:f0.map(G=>e.jsxs("button",{type:"button","aria-pressed":G===m,onClick:()=>I(G),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:[d.tools[G],e.jsx("small",{className:"text-[11.5px] font-normal text-muted",children:ce.tools[G]})]},G))})}),e.jsx(Ks,{label:ce.model,children:e.jsx(Zl,{onClick:()=>C("model"),lead:e.jsx(q,{name:"cpu",className:"size-4 text-muted"}),label:ce.model,text:Y,sub:Re})}),m==="omp"&&e.jsxs(Ks,{label:ce.permissions,children:[e.jsx(Jn,{name:"launch-approval",legend:ce.permissions,value:y,onChange:G=>F(()=>k(G)),options:h0.map(G=>({value:G,label:ce.approvals[G][0]}))}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ce.approvals[y][1]})]}),e.jsxs(Ks,{label:ce.message,htmlFor:E,children:[e.jsx("textarea",{id:E,value:j,onChange:G=>ee(G.target.value),placeholder:ce.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:ce.ideas.map(G=>e.jsx("button",{type:"button",onClick:()=>ee(G),className:"h-8 rounded-lg border border-dashed border-input px-2.5 text-[12.5px] text-muted",children:G},G))})]})]}),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:[ft&&e.jsx(b0,{outcome:ft,agent:rt,machine:l,taken:Oe??ce.missing.name,onRetry:yt(ft)?null:()=>tt(ft)}),pt?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:!0,className:Fe({variant:"primary",className:"w-full"}),children:pt.label}),pt.body]}):e.jsx("button",{type:"button",disabled:M,onClick:()=>void be(),className:Fe({variant:"primary",className:"w-full"}),children:M?e.jsxs(e.Fragment,{children:[e.jsx(q,{name:"spinner",className:"size-4 motion-safe:animate-spin"}),ce.launching]}):e.jsxs(e.Fragment,{children:[_t()&&e.jsx(q,{name:"face",className:"size-[18px]"}),_t()?ce.launchCheck:ce.launchDevice]})}),A&&e.jsx("span",{role:"status",className:"text-center text-[12px] leading-4 text-destructive",children:ce.cancelled}),!pt&&c&&e.jsx("span",{className:"text-center text-[12px] leading-4 text-muted",children:ce.summary(rt,ut,l,c.name)})]}),$==="project"&&e.jsxs(dt,{labelledBy:"launch-project",onClose:()=>C(null),children:[e.jsx("h2",{id:"launch-project",className:"text-base font-semibold",children:ce.project}),e.jsx(Nc,{children:r.map(G=>e.jsx(vc,{on:G.id===(c==null?void 0:c.id),onClick:()=>w(G),lead:e.jsx(Ie,{state:Ge?"off":"idle"}),text:G.name,sub:Ge?`${l} · ${ce.offline}`:l},G.id))})]}),$==="where"&&c&&e.jsxs(dt,{labelledBy:"launch-where",onClose:()=>C(null),children:[e.jsxs("div",{children:[e.jsx("h2",{id:"launch-where",className:"text-base font-semibold",children:ce.where}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ce.folders(c.name)})]}),e.jsx(Nc,{children:H.map((G,Ne)=>{const oe=qx(G)?G.exists===!1?ce.folder.missing(l):null:ce.folder.elsewhere(G.label??G.machine,l);return e.jsx(vc,{on:te.includes(G.path),disabled:oe!==null,onClick:()=>V(G.path),lead:e.jsx(q,{name:oe===null&&G.branch?"branch":"folder",className:"size-5 text-muted"}),text:Ne===0?ce.projectFolder:bc(G.path),sub:oe??G.branch??void 0},`${G.machine}:${G.path}`)})}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ce.folder.single})]}),$==="model"&&e.jsx(dt,{labelledBy:bo,onClose:()=>C(null),children:e.jsx(Su,{tool:m,models:ue,error:(we=n.models[m])==null?void 0:we.error,pick:h,onPick:G=>F(()=>g(G)),actions:e.jsx("button",{type:"button",onClick:()=>C(null),className:Fe({variant:"primary",className:"w-full"}),children:ce.done})})})]})}function Ks({label:t,htmlFor:s,aside:n,children:a}){const l=s?"label":"span",r=e.jsx(l,{...s?{htmlFor:s}:{},className:"text-[12px] font-medium text-muted",children:t});return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[n?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r,n]}):r,a]})}function Zl({onClick:t,lead:s,text:n,sub:a,dim:l=!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 ${l?"opacity-60":""}`,children:[s,e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate text-body",children:n}),a&&e.jsx("small",{className:"truncate text-[12px] text-muted",children:a})]}),e.jsx(q,{name:"down",className:"size-4 text-muted"})]})}function Nc({children:t}){return e.jsx("div",{className:"flex max-h-[50vh] flex-col overflow-y-auto rounded-[10px] border border-line",children:t})}function vc({on:t,disabled:s=!1,onClick:n,lead:a,text:l,sub:r}){return e.jsxs("button",{type:"button","aria-pressed":t,disabled:s,onClick:n,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:l}),r&&e.jsx("small",{className:"truncate text-[12px] text-muted",children:r})]}),t&&e.jsx(q,{name:"check",className:"size-4"})]})}function b0({outcome:t,agent:s,machine:n,taken:a,onRetry:l}){const r={label:ce.retry,onClick:l??(()=>{})};if(t.kind==="timeout")return l?e.jsx(at,{tone:"warn",title:ce.timeout,body:ce.timeoutBody,action:r}):e.jsx(at,{tone:"warn",title:ce.timeout,body:ce.lostBody,action:{label:d.atoi.seeSessions,href:ne({name:"sessions"})}});if(t.kind==="failed")return e.jsx(at,{tone:"fail",title:ce.failed(s),body:ce.failedBody(s),action:r});const o=ce.refused;switch(t.reason){case"not_found":return e.jsx(at,{tone:"fail",title:o.not_found,body:ce.kept});case"invalid":return e.jsx(at,{tone:"fail",title:o.invalid,body:o.invalidBody(s)});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:ce.settings,href:"#/connection/link"}});case"assertion_invalid":return e.jsx(at,{tone:"fail",title:o.assertion_invalid,body:ce.kept,action:r});case"assertion_expired":return e.jsx(at,{tone:"warn",title:o.assertion_expired,body:o.expiredBody,action:r});case"unavailable":return e.jsx(at,{tone:"warn",title:o.unavailable(n),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:ce.kept})}}const Br="ledge.mobile.forge",j0=35e3,y0=65e3,_o=(t,s)=>s?`${t}
21
21
  ${s}`:t,za=t=>t!=="checking"&&t!=="sending"&&t!=="received",Jl=t=>!!t&&(!za(t.phase)||t.phase==="uncertain"&&!t.lost),kc=new Set(["assertion_invalid","assertion_expired","confirm_required","conflict"]);function N0(t){var s;try{const n=(s=Qe(t))==null?void 0:s.getItem(Br);if(!n)return null;const a=JSON.parse(n),l=Am.safeParse(a.state);return l.success&&typeof a.at=="string"?{state:l.data,at:a.at}:null}catch{return null}}function v0(t,s,n){var U;const a=N0(n);let l={state:(a==null?void 0:a.state)??null,at:(a==null?void 0:a.at)??null,loading:!1,details:{},runs:[],drafts:{}};const r=new Set,o=O=>{l={...l,...O};for(const B of[...r])B()};let i=!1,c=!1,x=!1;const u=new Map,m=new Map,p=new Map;let h=0,g=s.getState().daemon?((U=s.getState().daemon)==null?void 0:U.boot)??null:void 0;const y=new Set,k=()=>!i&&t.state()==="ready",S=()=>{var O;return!!((O=s.getState().daemon)!=null&&O.forge)},b=O=>{t.send(O).catch(()=>{})},j=(O,B,Z)=>{clearTimeout(u.get(O)),u.set(O,setTimeout(()=>{u.delete(O),Z()},B))},N=O=>{clearTimeout(u.get(O)),u.delete(O)};function $(){x||!c||!k()||!S()||(x=!0,b({type:"forge.state"}),o({loading:!0}),j("state",j0,()=>{x=!1,o({loading:!1})}))}const C=O=>l.runs.find(B=>B.op===O);function M(O,B){const Z=l.runs.findIndex(X=>X.id===O);if(Z<0)return;const H=B(l.runs[Z]);if(o({runs:l.runs.map((X,te)=>te===Z?H:X)}),za(H.phase)){H.op&&H.phase!=="uncertain"&&m.delete(H.op);const X=p.get(O);p.delete(O),X==null||X(H)}}const v=O=>O.sentAt!==void 0&&Date.now()-O.sentAt<Uc&&g!==void 0&&(O.boot??null)===g,A=O=>{N(`op:${O.op}`),m.delete(O.op),M(O.id,B=>({...B,phase:"uncertain",lost:!0,endedAt:B.endedAt??Date.now()}))};function T(O){for(const[B,Z]of[...m]){const H=C(B);if(!H){m.delete(B);continue}if(!O.has(B)){if(!v(H)){A(H);continue}M(H.id,X=>({...X,again:!0})),b(Z),H.phase==="sending"&&P(B)}}}const R=(O,B)=>{N(`op:${O}`);const Z=C(O);Z&&Jl(Z)&&M(Z.id,H=>({...H,...B,endedAt:Date.now()}))},P=O=>j(`op:${O}`,Wc,()=>{const B=C(O);(B==null?void 0:B.phase)==="sending"&&M(B.id,Z=>({...Z,phase:"uncertain",endedAt:Date.now()}))});function _(O){var B,Z,H;switch(O.type){case"snapshot":{const X=g;g=O.daemon.boot??null;const te=new Set(y);y.clear();for(const pe of te){const ue=C(pe);ue&&M(ue.id,F=>({...F,boot:g}))}(X===void 0||X!==g)&&T(te),$();return}case"forge.state":{N("state");const X=new Date().toISOString(),te={prs:O.prs,forges:O.forges,followed:O.followed,...O.mine?{mine:O.mine}:{}},pe=Object.keys(l.details).filter(ue=>{var I,V,ee;const F=(V=(I=l.details[ue])==null?void 0:I.data)==null?void 0:V.pr.headSha,w=(ee=[...te.prs,...te.mine??[]].find(Q=>Q.id===ue))==null?void 0:ee.headSha;return F&&w&&F!==w});o({state:te,at:X,loading:!1});try{(B=Qe(n))==null||B.setItem(Br,JSON.stringify({state:te,at:X}))}catch{}for(const ue of pe)ae.readDetail(ue);return}case"forge.detail":{N(`detail:${O.prId}`);const X=l.details[O.prId];if(O.detail){const te=O.detail.log??((Z=X==null?void 0:X.data)!=null&&Z.log&&O.detail.jobs.some(pe=>pe.id===X.data.log.jobId)?X.data.log:void 0);o({details:{...l.details,[O.prId]:{data:{...O.detail,...te?{log:te}:{}},...O.cut?{cut:!0}:{},loading:!1,at:new Date().toISOString()}}})}else o({details:{...l.details,[O.prId]:{...X,loading:!1,error:O.error??"failed"}}});return}case"operation.result":{const X=C(O.op);if(!X||!Jl(X))return;if(O.status==="received"){N(`op:${O.op}`),(X.phase==="sending"||X.phase==="uncertain")&&M(X.id,te=>{const{endedAt:pe,...ue}=te;return{...ue,phase:"received"}});return}if(O.status==="rejected"&&X.again&&kc.has(O.reason??"")){A(X);return}O.status==="rejected"&&R(O.op,{phase:"rejected",reason:O.reason??"invalid"});return}case"forge.done":{const X=C(O.op);if(!X)return;if(X.again&&O.rejected&&kc.has(O.rejected)){X.lost||A(X);return}const te=O.rejected?{phase:"rejected",reason:O.rejected,done:O}:{phase:"done",done:O,...O.error?{reason:O.error}:{}};if(X.lost)m.delete(X.op),M(X.id,pe=>{const{lost:ue,...F}=pe;return{...F,...te,endedAt:Date.now()}});else{const pe=Jl(X);R(O.op,te),pe||M(X.id,ue=>({...ue,done:O}))}if(O.ok&&(X.action.kind==="comment"||X.action.kind==="reply")){const pe=_o(X.prId,X.action.kind==="reply"?X.action.threadId:void 0);if(((H=l.drafts[pe])==null?void 0:H.trim())===X.action.body){const{[pe]:ue,...F}=l.drafts;o({drafts:F})}}l.details[X.prId]&&ae.readDetail(X.prId);return}}}let D=k();const E=t.subscribe(()=>{const O=t.state();(O==="unpaired"||O==="pairing")&&K();const B=k();if(B&&!D)D=!0,h++,x=!1,g=void 0,y.clear();else if(!B&&D){D=!1,x=!1;for(const[H,X]of u)clearTimeout(X),u.delete(H);const Z=Object.fromEntries(Object.entries(l.details).map(([H,X])=>[H,X.loading?{...X,loading:!1}:X]));o({loading:!1,details:Z});for(const H of l.runs)H.phase==="sending"&&H.op&&M(H.id,X=>({...X,phase:"uncertain",endedAt:Date.now()}))}}),z=t.onMessage(_);function K(){var O;if(!(!l.state&&!l.runs.length&&!Object.keys(l.details).length&&!Object.keys(l.drafts).length)){try{(O=Qe(n))==null||O.removeItem(Br)}catch{}m.clear(),o({state:null,at:null,loading:!1,details:{},runs:[],drafts:{}})}}async function L(O){var X;if(!((X=s.getState().device)!=null&&X.confirm))return{phase:"rejected",reason:"confirm_required"};let B;try{B=await s.prepareConfirm(O)}catch(te){return{phase:te instanceof Error&&te.message==="timeout"?"expired":"unsent"}}if(!B.credentialId)return{phase:"rejected",reason:"confirm_required"};const Z=Date.now(),H=await sa({challenge:B.challenge,rpId:B.rpId,credentialId:B.credentialId}).catch(()=>"failed");return H==="cancelled"?{phase:"cancelled"}:H==="failed"?{phase:"unsent"}:Date.now()-Z>=B.expiresInMs?{phase:"expired"}:{assertion:H}}async function W(O,B,Z){var pe;P(B);const H=h,X=await t.send(Z).catch(()=>!1),te=(pe=C(B))==null?void 0:pe.phase;!X&&H===h&&(te==="sending"||te==="uncertain")&&(N(`op:${B}`),M(O,ue=>({...ue,phase:"unsent",endedAt:Date.now()})))}const ae={getState:()=>l,subscribe(O){return r.add(O),()=>{r.delete(O)}},follow(){c=!0,$()},readDetail(O,B){!k()||!S()||(b({type:"forge.detail",prId:O,...B?{log:B}:{}}),o({details:{...l.details,[O]:{...l.details[O],loading:!0}}}),j(`detail:${O}`,y0,()=>o({details:{...l.details,[O]:{...l.details[O],loading:!1,error:"failed"}}})))},act(O,B){const Z=crypto.randomUUID(),H={op:"",id:Z,prId:O,action:B,phase:"checking",startedAt:Date.now()};if(!k()||!S()){const te={...H,phase:"unsent",endedAt:Date.now()};return o({runs:[...l.runs,te]}),Promise.resolve(te)}const X=new Promise(te=>p.set(Z,te));return o({runs:[...l.runs,H]}),(async()=>{const te=await L({purpose:"forge",forge:{prId:O,action:B}});if(!("assertion"in te)){M(Z,F=>({...F,phase:te.phase,...te.reason?{reason:te.reason}:{},endedAt:Date.now()}));return}const pe=Hc(),ue=Fc.safeParse({type:"forge.act",op:pe,prId:O,action:B,assertion:te.assertion});if(!ue.success||!k()){M(Z,F=>({...F,phase:"unsent",endedAt:Date.now()}));return}m.set(pe,ue.data),g===void 0&&y.add(pe),M(Z,F=>({...F,op:pe,phase:"sending",sentAt:Date.now(),boot:g??null})),await W(Z,pe,ue.data)})(),X},resend(O){const B=l.runs.find(H=>H.id===O),Z=B!=null&&B.op?m.get(B.op):void 0;if(!(!B||B.phase!=="uncertain"||B.lost||!Z||!k())){if(!v(B)){A(B);return}M(O,H=>{const{endedAt:X,...te}=H;return{...te,phase:"sending",again:!0}}),W(O,B.op,Z)}},setDraft(O,B){if(B)o({drafts:{...l.drafts,[O]:B}});else{const{[O]:Z,...H}=l.drafts;o({drafts:H})}},dismiss(O){const B=l.runs.find(Z=>Z.id===O);B&&za(B.phase)&&B.op&&m.delete(B.op),o({runs:l.runs.filter(Z=>Z.id!==O||!za(Z.phase))})},close(){i=!0,E(),z();for(const O of u.values())clearTimeout(O);u.clear()}};return ae}function wl(t){return f.useSyncExternalStore(t.subscribe,t.getState,t.getState)}const De=d.prs;function k0({status:t,pc:s}){const[n,a]=f.useState(!1),l=es(t),r=e.jsx(q,{name:"warning",className:"mt-px size-4 text-attention"});if(t.status==="missing")return e.jsx(Gt,{warn:!0,role:"alert",lead:r,children:e.jsx("span",{"data-forge-strip":"missing",children:De.missing(l.cli,s,t.host,l.kind)})});if(t.status==="unauthenticated"){const c=Ph(t);return e.jsxs(Gt,{warn:!0,role:"alert",lead:r,children:[e.jsx("b",{"data-forge-strip":"unauthenticated",className:"font-semibold",children:De.unauth(l.cli,t.host,s)}),e.jsx("code",{className:"block rounded-md bg-raised px-2 py-1.5 font-mono text-[12px] break-all",children:c}),e.jsx("button",{type:"button",className:ge({size:"sm",className:"self-start"}),onClick:()=>{var x;(x=navigator.clipboard)==null||x.writeText(c).then(()=>a(!0),()=>{})},children:n?De.copied:De.copy})]})}const o=t.since??t.at,i=[t.retryAt?De.retryAt(Be(t.retryAt)):"",t.readAt?De.readAt(l.kind,Be(t.readAt)):""].filter(Boolean).join(" ");return e.jsx(Gt,{warn:!0,role:"alert",lead:r,children:e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("b",{"data-forge-strip":"error",className:"font-semibold",children:De.error(l.host,s,Be(o))}),i&&e.jsx("span",{className:"text-muted",children:i})]})})}function w0(){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:De.loading})]})}function S0(t,s,n){const a=n!=null&&n.readAt?De.asOf(Be(n.readAt)):De.state[t.state];return[De.host[t.forge],hl(t.repo),...s?[s]:[],a].join(" · ")}let wc={role:"all",q:""};function Sc({pr:t}){const s=t.roles??[];if(!s.length&&!t.sessions.length)return null;const n="rounded-[7px] border px-1.5 text-[11px] leading-4";return e.jsxs(e.Fragment,{children:[s.map(a=>e.jsx("span",{"data-role-pill":a,className:`${n} ${a==="reviewer"?"border-attention/50 text-attention":"border-line text-muted"}`,children:De.pill[a]},a)),t.sessions.length>0&&e.jsx("span",{"data-role-pill":"tracked",className:`${n} border-task/45 text-task`,children:De.pill.tracked})]})}function $0({forge:t,store:s}){const n=wl(t),a=me(s),{pc:l,look:r}=Ut(),o=na(),i=It(),[c,x]=f.useState(!0),[u,m]=f.useState(null),[p,h]=f.useState(wc),g=$=>{wc=$,h($)},y=r==="offline",k=Ht(l),S=n.state,b=$=>{var M;const C=$.sessions[0];return C?((M=a.sessions.get(C))==null?void 0:M.name)??null:null},j=$=>De.offlineBody(n.at?Be(n.at):$),N=(()=>{if(!S)return e.jsx(w0,{});const $=zh(S.forges),C=L=>$.find(W=>W.forge===L.forge&&W.host===L.host),M=[...S.prs,...S.mine??[]],v={open:Oh(M).open.sort((L,W)=>W.updatedAt.localeCompare(L.updatedAt)),closed:Tm(M,Date.now())},A=_m(M),T=Wo(v.open,p.role,p.q),R=Wo(v.closed,p.role,p.q),P=p.role!=="all"||p.q.trim()!=="",_=`${p.role}
22
22
  ${p.q.trim()}`,D=P&&T.length===0&&R.length>0,E=D?u!==_:!c,z=S.forges.length>0&&$.length===S.forges.length,K="flex h-[30px] shrink-0 items-center gap-1.5 rounded-full border px-[11px] text-[12.5px]";return e.jsxs(e.Fragment,{children:[!y&&$.map(L=>e.jsx(k0,{status:L,pc:k},`${L.forge}:${L.host}`)),e.jsxs("div",{className:`flex flex-col gap-3 ${y?"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(q,{name:"search",className:"size-3.5 shrink-0"}),e.jsx("input",{type:"search","aria-label":De.search,placeholder:De.search,value:p.q,onChange:L=>g({...p,q:L.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":De.rolesLabel,className:"-mx-1 flex gap-1.5 overflow-x-auto px-1 [scrollbar-width:none]",children:Im.map(L=>e.jsxs("button",{type:"button","aria-pressed":p.role===L,onClick:()=>g({...p,role:L}),className:`${K} ${p.role===L?"border-transparent bg-secondary text-fg":"border-line text-muted"}`,children:[De.roles[L],e.jsx("span",{className:`font-mono text-[11px] ${L==="reviewer"?"text-attention":""}`,children:A[L]})]},L))})]}),D?null:T.length===0&&P?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:De.none}),e.jsx("button",{type:"button",className:ge({size:"sm"}),onClick:()=>g({role:"all",q:""}),children:De.clear})]})}):T.length===0?e.jsx(Ve,{children:z?e.jsx(Jt,{framed:!1,glyph:null,title:De.emptyTitle,body:De.emptyUnread,list:R.length===0}):e.jsx(Jt,{glyph:e.jsx(q,{name:"pr",className:"size-[22px]"}),title:De.emptyTitle,body:De.emptyBody,list:R.length===0})}):e.jsxs(e.Fragment,{children:[e.jsx(Ft,{aside:!y&&n.at?De.asOf(Be(n.at)):void 0,children:De.openHead(T.length)}),e.jsx(Ve,{label:De.title,children:T.map(L=>{const W=C(L),ae=Kd(L),U=e.jsxs(e.Fragment,{children:[e.jsx(uu,{pipeline:L.pipeline}),!y&&!W&&L.openThreads>0&&e.jsx(Qn,{children:De.threads(L.openThreads)}),!y&&!W&&ae&&e.jsx(Qn,{ok:!0,children:De.ready})]});return e.jsx(yi,{pr:L,sub:S0(L,b(L),W),chips:U,pills:e.jsx(Sc,{pr:L}),...y?{}:{href:ne({name:"pr",id:L.id})},selected:i&&o.name==="pr"&&o.id===L.id},L.id)})})]}),R.length>0&&e.jsxs(Ve,{children:[e.jsxs("button",{type:"button","aria-expanded":E,onClick:()=>D?m(L=>L===_?null:_):x(L=>!L),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(q,{name:E?"down":"chevron",className:"size-3.5"}),De.closedGroup(R.length)]}),E&&e.jsx("div",{className:"border-t border-line",children:R.map(L=>e.jsx(yi,{pr:L,dim:!0,pills:e.jsx(Sc,{pr:L}),sub:[De.host[L.forge],hl(L.repo),De.state[L.state],mg(L.updatedAt)].join(" · "),...y?{}:{href:ne({name:"pr",id:L.id})},selected:i&&o.name==="pr"&&o.id===L.id},L.id))})]})]}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:De.tracked})]})})();return e.jsx(Rs,{title:De.title,offlineBody:j,heading:!1,children:N})}const Ye=d.prs,it=d.rigs,fn=t=>Ye.notDone[t.action.kind],C0=t=>{var s;return t.phase==="expired"?"assertion_expired":t.phase==="cancelled"?"cancelled":t.phase==="unsent"?"unsent":t.reason??((s=t.done)==null?void 0:s.error)};function Io({run:t,pr:s,detail:n,forge:a,pc:l,onReload:r}){const o=es(s),i=_t(),c={onClose:()=>a.dismiss(t.id),closeLabel:Ye.close};if(t.phase==="checking")return e.jsx(Zn,{children:it.running.checking});if(t.phase==="sending"||t.phase==="received")return e.jsx(Zn,{children:t.action.kind==="merge"?`${Ye.merging} · ${Ye.answers(o.cli)}`:Ye.answers(o.cli)});if(t.phase==="uncertain")return e.jsx(Se,{mark:"ask",title:it.uncertain.title,sub:it.uncertain.body,...c,children:!t.lost&&e.jsx("button",{type:"button",onClick:()=>a.resend(t.id),className:ge({size:"xs",className:"mt-1.5"}),children:Ye.retry})});const x=C0(t),u=t.done;if(t.phase==="done"&&(u!=null&&u.ok)){const h=Be(t.endedAt?new Date(t.endedAt).toISOString():null);return t.action.kind==="merge"?e.jsx(Se,{mark:"ok",title:Ye.merged(s.ref),sub:Ye.mergedSub(h,s.target),...c,children:u.command&&e.jsx(Xs,{commands:[u.command]})}):t.action.kind==="rerun"?e.jsx(Se,{mark:"ok",title:Ye.rerunDone(s.ref),sub:Ye.rerunDoneSub(h),...c,children:u.command&&e.jsx(Xs,{commands:[u.command]})}):t.action.kind==="reply"?e.jsx(Se,{mark:"ok",title:Ye.replyPosted(o.host),sub:h,...c}):t.action.kind==="comment"?e.jsx(Se,{mark:"ok",title:Ye.commentPosted(o.host),sub:h,...c}):null}if((t.action.kind==="comment"||t.action.kind==="reply")&&x!=="unavailable"&&x!=="confirm_required"){const h=t.action,g=x==="assertion_expired"?it.rejected.assertion_expired(i):x==="assertion_invalid"?it.rejected.assertion_invalid(i):x==="cancelled"?it.rejected.cancelled:x==="unsent"?it.rejected.unsent:Ye.lastLine(o.cli),y=!["assertion_expired","assertion_invalid","cancelled","unsent"].includes(x??"");return e.jsx(Se,{mark:"bad",title:`${it.because(fn(t),g)} ${Ye.keptText}`,...y&&(u!=null&&u.message)?{sub:e.jsx("span",{className:"font-mono",children:u.message})}:{},...c,children:e.jsx("button",{type:"button",onClick:()=>{a.dismiss(t.id),a.act(t.prId,h)},className:ge({size:"xs",className:"mt-1.5"}),children:Ye.retry})})}const p=t.action.kind==="merge"?it.rejected.again(Ye.mergeAgain):it.rejected.nothingSent;switch(x){case"stale":return e.jsx(Se,{mark:"warn",title:Ye.stale(xo(s.headSha)),sub:Ye.staleBody,...c,children:e.jsx("button",{type:"button",onClick:r??(()=>a.readDetail(t.prId)),className:ge({size:"xs",className:"mt-1.5"}),children:Ye.reload})});case"not_offered":{if(t.action.kind==="rerun")return e.jsx(Se,{mark:"warn",title:Ye.nothingToRerun,...c});const h=n?pl(n).find(y=>!y.ok):void 0,g=h?gr(qn(h,o.host),h):(u==null?void 0:u.message)??"";return e.jsx(Se,{mark:"bad",title:Ye.refused(o.host,g),...c})}case"busy":return e.jsx(Se,{mark:"warn",title:Ye.rerunRefused(Ye.rerunBusy),...c});case"confirm_required":return e.jsx(Se,{mark:"warn",title:it.rejected.confirm_required,...c});case"assertion_expired":return e.jsx(Se,{mark:"bad",title:it.because(fn(t),it.rejected.assertion_expired(i)),sub:p,...c});case"assertion_invalid":return e.jsx(Se,{mark:"bad",title:it.because(fn(t),it.rejected.assertion_invalid(i)),sub:p,...c});case"cancelled":return e.jsx(Se,{mark:"bad",title:it.because(fn(t),it.rejected.cancelled),sub:it.rejected.nothingSent,...c});case"unsent":return e.jsx(Se,{mark:"bad",title:it.because(fn(t),it.rejected.unsent),sub:it.rejected.nothingSent,...c});case"unavailable":return e.jsx(Se,{mark:"warn",title:Ye.gone(o.kind,l),sub:Ye.goneBody,...c});default:return e.jsx(Se,{mark:"bad",title:t.action.kind==="resolve"?it.because(fn(t),Ye.lastLine(o.cli)):Ye.failed(o.cli),...u!=null&&u.message?{sub:e.jsx("span",{className:"font-mono",children:u.message})}:{},...c,children:(u==null?void 0:u.command)&&e.jsx(Xs,{commands:[u.command]})})}}const gn=d.prs,nl=t=>t.toLocaleString(lt);function $c(t){return t.startsWith("@@")?"hunk":t.startsWith("+")?"add":t.startsWith("-")?"del":"ctx"}const M0={hunk:"bg-info/8 text-info",add:"bg-ok/15",del:"bg-danger-fg/15",ctx:"text-muted"};function Cc({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 Mc({f:t}){return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"font-mono text-[12px] text-ok",children:["+",nl(t.added)]}),e.jsxs("span",{className:"font-mono text-[12px] text-danger-fg",children:["−",nl(t.removed)]})]})}function E0({f:t,threads:s,host:n}){const[a,l]=f.useState(!1),r=s>0&&e.jsx(Qn,{children:gn.fileThreads(s)});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(q,{name:"file",className:"size-3.5 text-muted"}),e.jsx(Cc,{path:t.path}),r,e.jsx(Mc,{f:t}),e.jsx("span",{className:"basis-full pl-[22px] text-[12px] text-muted",children:gn.noPatch(n)})]}):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:()=>l(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(q,{name:a?"down":"chevron",className:"size-3.5 text-muted"}),e.jsx(Cc,{path:t.path}),r,e.jsx(Mc,{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(`