@paradow/ledge-relay 0.62.0 → 0.64.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.
@@ -0,0 +1,24 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/xterm-DbCZs1Jk.js","assets/index-Cm_-9uqI.js","assets/index-B7Qk80Pv.css","assets/label-BjpUvtdY.js","assets/xterm-DYP7pi_n.css"])))=>i.map(i=>d[i]);
2
+ var Gx=Object.defineProperty;var Xx=(t,s,n)=>s in t?Gx(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var Pt=(t,s,n)=>Xx(t,typeof s!="symbol"?s+"":s,n);import{r as f,c as d,j as e,B as Ue,a as Fa,U as $c,M as ea,o as Cc,b as Qx,i as Mt,u as Pr,d as sn,e as Yx,f as ze,l as st,t as _i,g as Zx,L as tr,W as Ma,O as dt,h as St,H as qt,F as $t,P as bt,S as Kn,K as zn,s as Jx,C as vn,k as Mc,m as Qe,I as em,A as tm,n as sm,p as nm,q as Ac,R as am,v as Ii,w as jn,x as lm,y as rm,z as im,D as om,E as cm,G as Li,J as Oi,N as Di,Q as vl,T as dm,V as Ec,X as um,Y as xm,Z as mm,_ as za,$ as Fi,a0 as pm,a1 as fm,a2 as Rc,a3 as Br,a4 as Tc,a5 as hm,a6 as zi,a7 as gm,a8 as bm,a9 as jm,aa as Pi,ab as ym,ac as Nm,ad as km,ae as vm}from"./index-Cm_-9uqI.js";import{e as _c,i as xs,a as wm,p as Sm,g as ta,c as $m,b as Cm,u as me,d as qr,r as Mm,f as Am,h as Em,j as Ic,k as Rm,l as Bi,m as qi,n as Tm,M as $s,o as _m,q as Im,s as Lm,t as Hr,v as Om,w as Dm,x as Fm,y as Lc,z as Oc,A as zm,B as Dc,R as Fc,U as zc}from"./label-BjpUvtdY.js";const Pm=["sessions","routines","prs","rigs","chat","connection","kernel","max"],Pc="new";function Pa(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]===Pc&&s.length===1)return{name:"launch"};const n=Pm.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"?`#/${Pc}`:t.name==="atoi"?"#/":`#/${t.name}`}const en=t=>{globalThis.location.hash=ne(t)},sr=t=>typeof(t==null?void 0:t.ledge)=="number";let ns=0,Pn=[],nr=!1;const ar=t=>{try{globalThis.history.replaceState({...globalThis.history.state,ledge:t},"")}catch{}};function Bm(){const t=globalThis.location.hash,s=globalThis.history.state;sr(s)?ns=s.ledge:(nr||(ns+=1,Pn=Pn.slice(0,ns)),ar(ns)),nr=!1,Pn[ns]=t}if(typeof globalThis.addEventListener=="function"&&globalThis.history&&globalThis.location){const t=globalThis.history.state;ns=sr(t)?t.ledge:0,sr(t)||ar(0),Pn[ns]=globalThis.location.hash,globalThis.addEventListener("hashchange",Bm)}const ms=t=>{nr=!0,globalThis.location.replace(ne(t))};function qm(t){if(ns===0)return{route:t,known:!1,inApp:!1};const s=Pn[ns-1];return s===void 0?{route:t,known:!1,inApp:!0}:{route:Pa(s),known:!0,inApp:!0}}function sl(t){ns>0?globalThis.history.back():ms(t)}const Hm=t=>(globalThis.addEventListener("hashchange",t),()=>globalThis.removeEventListener("hashchange",t));function sa(){const t=f.useSyncExternalStore(Hm,()=>globalThis.location.hash,()=>"");return Pa(t)}const Um=/^\/#\/[A-Za-z0-9/%._~-]*$/;function Wm(t){if(typeof t!="object"||t===null)return;const s=t;s.type!=="ledge.open"||typeof s.url!="string"||!Um.test(s.url)||(globalThis.location.hash=s.url.slice(1))}const Bc=70,na=6,Hi=2,Ur=130,_s=90,qc=t=>(Math.max(t,2)+1)*Bc,Hc=(t,s=na,n=Ur)=>qc(Math.min(t,s))+2*n;function Km(t,s,n=na,a=Ur){const l=t.slice(0,n),r=qc(l.length),i=h=>l.length===1?r/2:Bc*(h+1),o=l.map((h,g)=>({session:h,x:i(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??[],w=y[0];w&&x.set(g.id,{helper:w,more:y.length-1});const S=i(h)>r/2?"right":"left",b=S==="left"?"right":"left";for(const j of y){const N=c[S].length<Hi?S:c[b].length<Hi?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:Hc(t.length,n,a),seats:o,ends:m,notes:x,extra:{mains:p,helpers:u},extraCount:p.length+u.length}}const Bs=84,ha=52;function Vm(t,s,n){const a=[...s].sort((o,c)=>o-c),l=a.indexOf(t),r=(l<a.length-1?a[l+1]-Bs/2:n-6)-(t+Bs/2),i=t-Bs/2-(l>0?a[l-1]+Bs/2:6);return r>=ha+4?t+Bs/2+2:i>=ha+4?t-Bs/2-ha-2:t+Bs/2-ha+8}function Gm(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 Ui(t,s){return t==="idle"?"done":t==="readonly"?"working":t}const Xm={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"},Uc=t=>Xm[t.state];function Qm(t,s,n,a,l,r){const i=s??[],o=new Set(i.map(w=>w.id)),c=w=>{const S=n(w);return S!==null&&o.has(S)?S:null},x=t.filter(w=>!w.rig),u=i.filter(w=>a==="all").map(w=>({project:w,tables:[{key:`common:${w.id}`,mains:x.filter(S=>c(S)===w.id)}]})).filter(w=>w.tables[0].mains.length>0),m=Ym(t.filter(w=>w.rig),w=>{var S;return((S=i.find(b=>b.id===w))==null?void 0:S.name)??null},n,r),p=[...m.filter(w=>w.rig.kind==="kernel"),...u,...m.filter(w=>w.rig.kind==="rig")],h=a==="all"||a==="none"?x.filter(w=>c(w)===null):[],g=a==="all"||a==="none"?void 0:i.find(w=>w.id===a),y=g&&p.length===0?g:null;return{rooms:p,unassigned:h,empty:y}}const wl="kernel";function Ym(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],[i])=>r===wl?-1:i===wl?1:r.localeCompare(i)).map(([r,i])=>{const o=r===wl?"kernel":"rig",c=n(i[0]);return{project:a({id:`rig:${r}`,name:r,kind:o}),tables:[{key:`rig:${r}`,mains:i}],rig:{kind:o,name:r,folder:i[0].cwd??"",project:c?s(c):null}}})}const Zm=t=>t==="kernel"?"violet":"slate",Wc=110,Jm=150,Kc=70,ep=(t,s=na,n=Ur)=>t.reduce((a,l,r)=>a+Hc(l.mains.length,s,n)+(r>0?Kc:0),0)+2*Wc;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 Sl=(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 lr=t=>{var s;return((s=t.split(`
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(lr(t.text)).trim();default:return lr(t.text)}}const Vc=["all","waiting","working"],rr=t=>t.pending!==void 0||t.state==="waiting_permission"||t.state==="waiting_input";function ir(t,s){return s==="waiting"?rr(t):s==="working"?t.state==="working"&&!rr(t):!0}function Ba(t){return rr(t)?0:t.state==="working"?1:t.state==="exited"?3:2}function Gc(t,s){const n=new Map,a=new Map;for(const r of t){if(!ir(r,s))continue;const[i,o,c]=r.rig?[a,"rig",r.rig.name]:[n,"project",r.project];let x=i.get(c);x||i.set(c,x={id:`${o}:${c}`,kind:o,name:c,sessions:[]}),x.sessions.push(r)}const l=r=>({...r,sessions:r.sessions.map((i,o)=>[i,o]).sort((i,o)=>Ba(i[0])-Ba(o[0])||i[1]-o[1]).map(([i])=>i)});return[...n.values(),...a.values()].map(l)}const Wr=["projects","rigs"];function tp(t,s){const n=Gc(t,"all");if(s==="projects")return n;const a=t.filter(l=>!l.rig).map((l,r)=>[l,r]).sort((l,r)=>Ba(l[0])-Ba(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 sp(t){if(t.kind!=="project")return null;const s=t.sessions.map(Sn);return s.includes("perm")?"perm":s.includes("ask")?"ask":null}function np(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 Xc=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 ap=t=>t.helpers.filter(s=>s.state!=="exited"&&s.finishedAt===void 0).length;function lp(t,s,n=Date.now()){const a=d.sessions.line;if(s==="working")return Kr(t);const l=Qc(t),r=l===void 0?"":` · ${l} %`,i=Vt([t])[0];if(i)return(i.kind==="permission"?a.permission:d.atoi.pill[i.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(_c(t.exitedAt,n)):a.endedPlain;case"error":return a.error;default:return a.idle+r}}const Kr=t=>{var s;return((s=t.doing)==null?void 0:s.label)||d.sessions.line.thinking},Qc=t=>t.context?Math.round(Math.min(1,t.context.used/t.context.window)*100):void 0;function rp(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"]}},Ye=(t,s,n)=>`M${t-n} ${s}a${n} ${n} 0 1 0 ${2*n} 0a${n} ${n} 0 1 0 ${-2*n} 0`,on=(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`,ip={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",Ye(12,12,3)],arrowRight:["M5 12h14","m13 6 6 6-6 6"],arrowUp:["m5 12 7-7 7 7","M12 19V5"],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:[on(3,4,18,16,2),"M7 9h10M7 13h6"],pr:[Ye(6,5,2.2),Ye(6,19,2.2),Ye(18,19,2.2),"M6 7.2v9.6M18 16.8V10a3 3 0 0 0-3-3h-4","M13 5l-2 2 2 2"],rigs:[Ye(6,6,2.5),Ye(18,6,2.5),Ye(12,18,2.5),"M8 7.5l3 8M16 7.5l-3 8M8.5 6h7"],ledge:[on(4,8,16,12,3),"M12 8V4.5",Ye(9,14,1),Ye(15,14,1)],search:[Ye(11,11,7),"M20 20l-4-4"],more:[Ye(12,5,1.4),Ye(12,12,1.4),Ye(12,19,1.4)],send:["M12 19V5M5 12l7-7 7 7"],wifioff:["M12 20h.01M8.5 16.4a5 5 0 0 1 7 0M5 12.9a10 10 0 0 1 5.2-2.7M19 12.9a10 10 0 0 0-1.9-1.3M2 8.8a15 15 0 0 1 4.2-2.7M22 8.8A15 15 0 0 0 10.7 5M2 2l20 20"],cloud:["M2 2l20 20M5.8 5.8A7 7 0 0 0 7 20h10a5 5 0 0 0 2.6-.7M20.8 16.4A5 5 0 0 0 17 10h-1.3A7 7 0 0 0 10 5.1"],refresh:["M3 12a9 9 0 0 1 15.7-6L21 8M21 3v5h-5M21 12a9 9 0 0 1-15.7 6L3 16M3 21v-5h5"],atelier:[on(3,10,18,5,1),Ye(7,6,2),Ye(17,6,2),"M6 15v4M18 15v4"],plan:["M9 4h6v3H9z","M7 5H5v16h14V5h-2","m9 12 1.5 1.5L14 10","M9 17h6"],keyboard:["M3 7h18v10H3z","M7 11h.01","M11 11h.01","M15 11h.01","M8 14h8"],task:["M6.9 3.75h10.2a2.4 2.4 0 0 1 2.4 2.4v11.7a2.4 2.4 0 0 1-2.4 2.4H6.9a2.4 2.4 0 0 1-2.4-2.4V6.15a2.4 2.4 0 0 1 2.4-2.4z","M8.25 9h7.5","M8.25 13.5h5.25"],reply:["M9.75 6 3.75 12l6 6","M4.5 12h9.75a6 6 0 0 1 6 6v.75"],passkey:["M12 3a6 6 0 0 0-6 6v3h12V9a6 6 0 0 0-6-6z","M5 12h14v9H5z"],phone:["M8 2h8a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z","M11 18h2"],tablet:["M6 3h12a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z","M11 18h2"],key:[Ye(7.5,15.5,5.5),"m21 2-9.6 9.6M15.5 7.5l3 3L22 7l-3-3"],shield:["M12 3 4 6v6c0 5 8 9 8 9s8-4 8-9V6z"],laptop:[on(4,4,16,11,1.5),"M2 19h20"],face:["M4 8V6a2 2 0 0 1 2-2h2M16 4h2a2 2 0 0 1 2 2v2M20 16v2a2 2 0 0 1-2 2h-2M8 20H6a2 2 0 0 1-2-2v-2M9 9v1M15 9v1M12 9v4h-1M9 15.5a4 4 0 0 0 6 0"],unlink:["M18.8 13.4l1.6-1.6a4.5 4.5 0 0 0-6.4-6.4l-1.6 1.6M5.2 10.6l-1.6 1.6a4.5 4.5 0 0 0 6.4 6.4l1.6-1.6M8 2v3M2 8h3M16 22v-3M22 16h-3"],clock:[Ye(12,12,9),"M12 7v5l3 2"],alarm:[Ye(12,13,8),"M12 9v4l2.5 1.5M5 3 2 6M19 3l3 3"],play:["M7 5v14l11-7z"],lock:[on(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:[on(6,6,12,12,2),"M9 2v4M15 2v4M9 18v4M15 18v4M2 9h4M2 15h4M18 9h4M18 15h4"],camera:["M4 8h3l2-3h6l2 3h3v11H4z",Ye(12,13,3.5)],folder:["M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"],list:["M9 6h11M9 12h11M9 18h11M4 6l1 1 2-2M4 12l1 1 2-2M4 18h2"],down:["M6 9l6 6 6-6"],branch:[Ye(6,5,2),Ye(6,19,2),Ye(18,8,2),"M6 7v10M18 10c0 4-6 3-12 7"],merge:[Ye(6,5,2.2),Ye(6,19,2.2),Ye(18,12,2.2),"M6 7.2v9.6M6 7.2c0 3 4 4.8 9.8 4.8"],file:["M14 3H6a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8z","M14 3v5h5"],commit:[Ye(12,12,3.5),"M3 12h5.5M15.5 12H21"]};function 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:ip[t].map((a,l)=>e.jsx("path",{d:a},l))})}const op={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 _e({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 ${op[t]} ${s?"animate-[ledge-pulse_1.6s_ease-in-out_infinite]":""}`})}const cp={claude:"CC",codex:"CX",cursor:"CU",omp:"OM"};function fs({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:cp[t]})}const dp={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 ${dp[t]}`,children:s})}function rs({title:t,dot:s,count:n,sub:a,tone:l,none:r,label:i,children:o}){return e.jsxs("section",{"aria-label":t??i,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(_e,{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:o})]})}function Ys({lead:t,title:s,sub:n,subTone:a,meta:l,metaWarn:r=!1,selected:i=!1,stale:o=!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 ${o?"opacity-60":""} ${i?"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":i?"page":void 0,className:p,...u,children:h}):e.jsx("div",{className:p,children:h})}const up={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 ${up[t]} ${s?"shadow-[0_0_0_2px_var(--color-ring)]":""}`,children:a})}function Zt({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 xp={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"},mp={md:"h-11 px-3.5 text-body",sm:"h-9 px-3 text-[13px]",xs:"h-8 px-2.5 text-[12.5px]"},Oe=({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",xp[t],t==="ghost"?"h-9 px-3.5":mp[s],n??""].filter(Boolean).join(" ");function pp({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 aa({back:t,tool:s,name:n,dot:a,pulse:l=!1,sub:r,under:i=!1,more:o}){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(fs,{tool:s}),i&&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(_e,{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(_e,{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"})]}),o]})}function Yc({label:t,sendLabel:s,placeholder:n,offlinePlaceholder:a,value:l,onChange:r,onSend:i,offline:o=!1}){const c=f.useId(),x=!o&&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)] ${o?"opacity-55":""}`,children:[e.jsx("label",{htmlFor:c,className:"sr-only",children:t}),e.jsx("textarea",{id:c,rows:1,value:o?"":l,disabled:o,placeholder:o?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:i,"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 fp({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 Zc={permission:"approval",question:"attention",plan:"info",diff:"info"};function hp(t,s){if(s){const n=s.risk==="high"&&s.kind!=="question";return{tone:n?"danger":Zc[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 gp=t=>hp(t,Vt([t])[0]);function Jc({store:t,label:s,ids:n,offline:a,startOpen:l=!1,onCancel:r}){const[i,o]=f.useState(l),[c,x]=f.useState(""),[u,m]=f.useState(!1),[p,h]=f.useState(null),g=async()=>{if(n.length>Fa){h({lines:[d.agents.tooMany(n.length,Fa)],error:!0});return}m(!0);const y=await t.broadcast(n,c.trim());if(m(!1),y.sent){const w=y.sent;h({lines:[...w.length?[d.agents.sentTo(w)]:[d.agents.nobody],...(y.refused??[]).map(S=>d.agents.refusedLine(S.name,S.reason))],error:w.length===0}),w.length&&(o(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:[!i&&e.jsx("button",{type:"button",disabled:a,onClick:()=>{h(null),o(!0)},className:"text-meta text-info disabled:opacity-60",children:d.agents.writeGroup}),i&&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(Ue,{variant:"ghost",className:"flex-1",disabled:u,onClick:()=>{o(!1),x(""),r==null||r()},children:d.agents.cancel}),e.jsx(Ue,{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,w)=>e.jsx("p",{className:"[overflow-wrap:anywhere]",children:y},w))})]})}const Wi=new Set(["-o","--push-option","--repo","--receive-pack","--exec"]),bp=new Set(["-f","--force","--force-with-lease","--force-if-includes","--delete","-d","--mirror","--prune"]);function jp(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];bp.has(p)?a=!0:Wi.has(p)&&!m.includes("=")&&u++}else m.startsWith("-")&&m.length>1?/[fd]/.test(m.slice(1))?a=!0:Wi.has(m)&&u++:l.push(m)}const[i="",...o]=l;o.some(u=>u.startsWith("+")||u.startsWith(":"))&&(a=!0);const c=o[0],x=c==null?void 0:c.replace(/^\+/,"").split(":").pop();return{remote:i,...x?{branch:x}:{},force:a}}function yp(t){return t.risk!=="low"||t.riskReason!=="edit_inside_folder"?null:{title:d.detail.editsInProject,body:d.detail.editsInProjectBody}}function ed(t){if(t.risk==="low")return null;const s=d.consequence,n=t.riskReason;if(n==="pushes"){const a=jp(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 Vr=ea,Np=/^[1-9]$/;function td(t){const s=t.trim();return s===""?{text:s,problem:"empty"}:$c.test(s)?{text:s,problem:"untypable"}:s.length>Vr?{text:s,problem:"long"}:Np.test(s)?{text:s,problem:"digit"}:{text:s,problem:null}}function Gr(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:Cc(t.tool,t.kind,"always")}}const or=t=>Qx(t.tool,{kind:t.kind,...t.pendingTool?{tool:t.pendingTool}:{}}),qa=t=>t==="project"?d.atoi.always:t==="plan"?d.atoi.approveAuto:d.atoi.alwaysSession,Ki={critical:0,urgent:1,routine:2},sd=t=>[...t].sort((s,n)=>Ki[s.priority]-Ki[n.priority]||Date.parse(s.createdAt)-Date.parse(n.createdAt)),nd=t=>t.kind==="update"?"update":t.kind==="parked"?"parked":t.questions.length>0?"decision":"question",kp=t=>(t==null?void 0:t.replace(/\.agent$|\.lead$|\.worker$/,""))??null,ad=t=>({name:t.from.seat.split("@")[0]||t.from.seat,role:kp(t.from.role)});function Vi(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 vp(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 ld(t,s){const n=Object.values(s).filter(r=>r.message.type==="openrig.answer"&&r.message.qitemId===t).sort((r,i)=>r.at.localeCompare(i.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 xs(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 wp(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 Sp=6,rd=5e3;function $l(t,s){return[...t.map(n=>({name:"request",sessionId:n.sessionId,key:n.key})),...sd(s).filter(n=>n.kind!=="update").map(n=>({name:"ask",id:n.id}))]}const Ea=(t,s)=>t.name==="request"?s.name==="request"&&t.sessionId===s.sessionId:s.name==="ask"&&t.id===s.id;function $p(t,s,n=t){const a=t.filter(i=>!Ea(i,s)),l=n.findIndex(i=>Ea(i,s));return(l<0?[]:n.slice(l+1)).find(i=>a.some(o=>Ea(o,i)))??a[0]??null}function Cp(t,s,n){if(!t.length)return null;const a=s?t.findIndex(l=>Ea(l,s)):-1;return a<0?t[0]:t[Math.min(t.length-1,Math.max(0,a+n))]}function Vn(t,s,n){var o;const a=(o=s.find(c=>c.id===t.sessionId))==null?void 0:o.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&&wm(c.message)===t.key).sort((c,x)=>c.at.localeCompare(x.at)),i=r.find(c=>c.phase==="applied")??r[r.length-1];if(i){const c=i.message;switch(i.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 i.reason==="stale"&&!l?a!=null&&a.key?{kind:"changed"}:{kind:"handledElsewhere"}:{kind:"rejected",reason:i.reason??"invalid"};case"failed":return{kind:"failed",reason:i.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 Mp={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 la({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 ${Mp[t]}`,children:s})}function Ap({kind:t,risk:s="low"}){const n=s==="high"&&t!=="question";return e.jsx(la,{tone:n?"danger":Zc[t],label:n?d.risk.badge:d.kind[t]})}function Ep({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 id({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=qm(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(),sl(t)},className:Mt({className:"-ml-2"}),children:e.jsx(q,{name:"back"})})}function ra({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(id,{link:a})]})})}const Cl={},od={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}},Rp=()=>{const t=Cl==null?void 0:Cl.VITE_LEDGE_MOTION;return t===void 0?1:Number(t)},vt=t=>`${Math.round(t*Rp())}ms`;function Tp(t){return t.map(([s,n,a])=>{const l=od[n];return`${s} ${vt(l.ms)} ${l.ease} ${vt(a??l.delayMs)}`}).join(", ")}const _p="(prefers-reduced-motion: reduce)",cd=()=>typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia(_p):null;function Ip(t){const s=cd();return s==null||s.addEventListener("change",t),()=>s==null?void 0:s.removeEventListener("change",t)}const Lp=()=>{var t;return((t=cd())==null?void 0:t.matches)??!1};function Op(){return!1}function dd(){return f.useSyncExternalStore(Ip,Lp,()=>!1)}const Dp=()=>({reduced:dd()||Op(),app:!1,setReduced(){}});let Fp=Dp;function zp(){return Fp()}function Pp(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 nl(t,s){return bn(`${t}:${s}`)%3+1}const wt={blinkMs:180,gazePx:1.4,gazeYPx:.3,askDelayMs:180,transitionMs:500,hopMs:480,touchMs:360,idleMs:1700,askMs:850,nodMs:650},Ml=(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,cr=new Set(["done","error","readonly"]),El=(t,s)=>s===0?3500+t%4e3:5500+(t+s*557)%3500,vs=t=>!document.hidden&&!t.closest("[inert]");function Ha(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 Bp(t){f.useEffect(()=>{const s=t.current;if(!s)return;const n=()=>s.setAttribute("data-suspended",String(!vs(s)));return n(),Ha(s,n)},[t])}function cn(t,s,n){t.style.setProperty("--bot-gx",`${s}px`),t.style.setProperty("--bot-gy",`${n}px`)}function qp(t,s){const{seed:n,state:a,enabled:l,askKey:r,nodKey:i,gazeReach:o=0}=s,c=bn(n),x=l&&!cr.has(a),u=f.useRef(null),m=f.useRef(a),p=f.useRef(i),h=f.useRef(void 0);f.useEffect(()=>{const g=t.current;if(!g||!x)return;let y,w,S;const b=()=>vs(g),j=()=>{y!==void 0&&clearTimeout(y),w!==void 0&&clearTimeout(w),S!==void 0&&clearTimeout(S),y=w=S=void 0,g.removeAttribute("data-idle"),cn(g,0,0),g.removeAttribute("data-blink")},N=()=>{if(j(),!b())return;const R=Date.now();(!u.current||u.current.h!==c)&&(u.current={h:c,blinkAt:R+Ml(c,0),lookAt:R+Al(c,0),idleAt:R+El(c,0),blinks:0,looks:0,idles:0});const v=u.current;v.blinkAt<R&&(v.blinkAt=R+Ml(c,++v.blinks)),v.lookAt<R&&(v.lookAt=R+Al(c,++v.looks)),v.idleAt<R&&(v.idleAt=R+El(c,++v.idles)),y=setTimeout(C,Math.min(v.blinkAt,v.lookAt,v.idleAt)-R)},C=()=>{if(y=void 0,!b()){j();return}const R=u.current,v=Date.now();if(v>=R.blinkAt&&(g.setAttribute("data-blink","true"),w!==void 0&&clearTimeout(w),w=setTimeout(()=>{w=void 0,g.removeAttribute("data-blink")},wt.blinkMs),R.blinkAt=v+Ml(c,++R.blinks)),v>=R.lookAt){R.looks++;const T=a==="working";!g.hasAttribute("data-hover")&&!g.hasAttribute("data-transition")&&cn(g,T?R.looks%2?wt.gazePx:-1.4:0,T?wt.gazeYPx:0),R.lookAt=v+Al(c,R.looks)}if(v>=R.idleAt){R.idles++;const T=a;!g.hasAttribute("data-hover")&&!g.hasAttribute("data-transition")&&(T==="idle"||T==="question")&&(g.setAttribute("data-idle",T==="question"?"tilt":R.idles%4===0?"stretch":"look"),S=setTimeout(()=>{S=void 0,g.removeAttribute("data-idle")},wt.idleMs)),R.idleAt=v+El(c,R.idles)}y=setTimeout(C,Math.min(R.blinkAt,R.lookAt,R.idleAt)-v)};N();const M=Ha(g,()=>{b()&&y===void 0?N():b()||j()});return()=>{j(),M()}},[t,x,c,a]),f.useEffect(()=>{const g=t.current,y=m.current,w=h.current,S=p.current!==i&&i!==void 0;if(p.current=i,m.current=a,h.current=r,!g)return;cn(g,0,0),g.removeAttribute("data-idle");const b=a==="approval"&&(y!=="approval"||r!==void 0&&r!==w),j=new Set,N=(O,U)=>{const D=setTimeout(()=>{j.delete(D),vs(g)?O():C()},U);return j.add(D),D},C=()=>{j.forEach(clearTimeout),j.clear(),["data-transition","data-gesture","data-touch","data-hover","data-idle"].forEach(O=>g.removeAttribute(O)),cn(g,0,0)};let M=!1,R=!1;l&&vs(g)&&(y!==a&&["working","question","idle","done","error"].includes(a)&&(g.setAttribute("data-transition",a),N(()=>g.removeAttribute("data-transition"),a==="working"?wt.hopMs:a==="question"?650:wt.transitionMs)),b&&!S&&N(()=>{M=!0,g.setAttribute("data-gesture","ask"),N(()=>{g.getAttribute("data-gesture")==="ask"&&g.removeAttribute("data-gesture")},wt.askMs)},wt.askDelayMs));const v=()=>l&&!cr.has(a)&&vs(g),T=O=>{if(!v()||O.pointerType==="touch")return;const U=g.getBoundingClientRect();if(!U.width||!U.height)return;const D=O.clientX-U.left-U.width/2,K=O.clientY-U.top-U.height/2;if(o>0&&(Math.abs(D)>U.width/2+o||Math.abs(K)>U.height/2+o)){g.hasAttribute("data-hover")&&A();return}g.setAttribute("data-hover","true"),g.removeAttribute("data-idle");const te=V=>Math.max(-2,Math.min(2,V));cn(g,te(D/(U.width/2+o)*2),te(K/(U.height/2+o)*2))},A=()=>{g.removeAttribute("data-hover"),cn(g,0,0)},E=o>0?window:g,P=o>0?document.documentElement:g;let I;const L=()=>{v()&&(I!==void 0&&(clearTimeout(I),j.delete(I)),g.removeAttribute("data-touch"),g.getBoundingClientRect(),g.setAttribute("data-touch","true"),I=N(()=>g.removeAttribute("data-touch"),wt.touchMs))};E.addEventListener("pointermove",T),P.addEventListener("pointerleave",A),g.addEventListener("click",L);const $=Ha(g,()=>{vs(g)||(R=!0,C())});return()=>{C(),$(),E.removeEventListener("pointermove",T),P.removeEventListener("pointerleave",A),g.removeEventListener("click",L);const O=["data-paused","data-frozen","data-reduced","data-readonly"].some(U=>g.getAttribute(U)==="true");!M&&b&&!S&&g.getAttribute("data-state")===a&&l&&!R&&vs(g)&&!O&&(h.current=w)}},[t,a,l,r,i,c,o])}function Hp(t,s,n,a,l){const r=f.useRef(s);f.useEffect(()=>{const i=t.current,o=r.current!==s;if(r.current=s,!i||!o||s===void 0||!n||!vs(i)||cr.has(a))return;i.setAttribute("data-gesture","nod");const c=setTimeout(()=>{i.getAttribute("data-gesture")==="nod"&&i.removeAttribute("data-gesture")},wt.nodMs),x=()=>{clearTimeout(c),i.getAttribute("data-gesture")==="nod"&&i.removeAttribute("data-gesture")},u=Ha(i,()=>{vs(i)||x()});return()=>{u(),x()}},[t,s,n,a,l])}const Up={claude:"Claude Code",codex:"Codex",cursor:"Cursor Agent",omp:"omp"},Wp={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"}},Kp="0 0 96 96",ud={claude:"10 18 76 64",codex:"5 7 87 82",cursor:"11 8 74 82",omp:"10 18 76 68"},Vp=Object.fromEntries(Object.entries(ud).map(([t,s])=>[t,Number(s.split(" ")[2])])),Gp={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"},Xp={claude:"translate(0 -8)",codex:void 0,cursor:"translate(31.5 58) skewY(27) scale(.86) translate(-48.5 -49)",omp:"translate(0 -12)"},Qp=240;function al({tool:t,state:s,pose:n,size:a,shownSize:l,theme:r,seed:i,readOnly:o=!1,frozen:c=!1,paused:x=!1,reducedMotion:u,askKey:m,nodKey:p,className:h}){var U;const g=f.useRef(null),y=`bot-shell-${f.useId().replace(/[^A-Za-z0-9_-]/g,"")}`,w=zp(),b=dd()||(u??w.reduced),j=a<=20,N=Wp[s],C=!o&&s!=="done"&&s!=="readonly",M=Pr(),R=bn(i),v=s==="working"&&!b&&!o&&!c&&!x,T=l??a,E=Math.min(7,Math.max(2,T*.12))/T*(j?Vp[t]:96),P=3600+R%9*100,I=!j&&T>20,L=!b&&!o&&s!=="readonly"&&!c&&!x;Bp(g),qp(g,{seed:i,state:s,askKey:m,nodKey:p,enabled:L&&I,gazeReach:Qp}),Hp(g,p,L&&I,s,m);const $={"--bot-size":`${a}px`,"--bot-eye":`var(--bot-eye-${N.eye})`,"--bot-tilt":`${((U=N.tilt)==null?void 0:U[n-1])??0}deg`,"--bot-lift":`${N.lift??0}px`,"--bot-breath":vt(4800+R%17*100),"--bot-phase":`-${vt(R%43*100)}`,"--bot-hop":`${E.toFixed(2)}px`,"--bot-hop-cycle":vt(P),"--bot-ease":od.grow.ease,"--bot-material-ms":vt(240),"--bot-eye-ms":vt(260),"--bot-pose-ms":vt(300),"--bot-gaze-ms":vt(450),"--bot-blink-ms":vt(wt.blinkMs),"--bot-ask-ms":vt(wt.askMs),"--bot-nod-ms":vt(wt.nodMs),"--bot-question-ms":vt(650),"--bot-arrival-ms":vt(wt.transitionMs),"--bot-entry-hop-ms":vt(wt.hopMs),"--bot-touch-ms":vt(wt.touchMs),"--bot-idle-ms":vt(wt.idleMs)},O=`${Up[t]} · ${M.botLabel[s]}${o&&s!=="readonly"?` · ${M.botReadOnly}`:""}${c?` · ${M.botNotLive}`:""}`;return e.jsxs("svg",{ref:g,className:h?`bot ${h}`:"bot",role:"img","aria-label":O,width:a,height:a,viewBox:j?ud[t]:Kp,"data-tool":t,"data-state":s,"data-eyes":N.eyes,"data-pose":n,"data-material":Pp(r),"data-simplified":String(j),"data-detailed":String(I),"data-readonly":String(o||s==="readonly"),"data-halo":String(C),"data-frozen":String(c),"data-paused":String(x),"data-reduced":String(b),"data-hop":String(v),style:$,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:Gp[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:Xp[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})]}),I&&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 Yp={blink:180,curious:900,hello:1100,boop:700,happy:900,look:1800,stretch:1600,tap:1150,pulse:1400,nod:700,yawn:1700,sleep:3200},Rl=(t,s)=>Math.max(-s,Math.min(s,t)),Gi="M25 60V41C25 28 35 23 48 23C61 23 71 28 71 41V60Z";function Xr({size:t,theme:s,paused:n=!1,frozen:a=!1,reducedMotion:l=!1,dnd:r=!1,pointer:i=null,center:o,gestureKey:c,gestureKind:x="hello",boopKey:u}){const m=Pr(),p=`resident-${f.useId().replace(/[^A-Za-z0-9_-]/g,"")}`,[h,g]=f.useState(null),[y,w]=f.useState(!1),S=f.useRef(void 0),b=n||l||r||a,j=!b&&!!i&&!!o&&Math.hypot(i.x-o.x,i.y-o.y)<140,N=j?Rl((i.x-o.x)/140*5,4):0,C=j?Rl((i.y-o.y)/140*3,2):0,M=j?Rl((i.x-o.x)/140*7,5):0,R=A=>{b||document.hidden||(clearTimeout(S.current),g(null),g(A),S.current=setTimeout(()=>g(null),Yp[A]))};f.useEffect(()=>()=>clearTimeout(S.current),[]),f.useEffect(()=>{c&&R(x)},[c]),f.useEffect(()=>{u&&R("boop")},[u]);const v=f.useRef(!1);f.useEffect(()=>{j&&!v.current&&!y&&R("curious"),v.current=j},[j]),f.useEffect(()=>{if(b){g(null),clearTimeout(S.current);return}let A,E=0;const P=()=>{!document.hidden&&!y&&(E++,R(E%17===0?"sleep":E%13===0?"yawn":E%11===0?"tap":E%7===0?"stretch":E%5===0?"look":"blink")),A=setTimeout(P,4300+E%3*900)};A=setTimeout(P,3200);const I=()=>{document.hidden&&(g(null),clearTimeout(S.current))};return document.addEventListener("visibilitychange",I),()=>{clearTimeout(A),document.removeEventListener("visibilitychange",I)}},[b,y]);const T={"--resident-gx":N?`${N.toFixed(2)}px`:"0px","--resident-gy":C?`${C.toFixed(2)}px`:"0px","--resident-tilt":M?`${M.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:T,onMouseEnter:()=>{w(!0),R("happy")},onMouseLeave:()=>w(!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:Gi,fill:`url(#${p}-shell)`}),t>24&&e.jsx("path",{d:Gi,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 Zp={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"};function ll({tool:t,seed:s,state:n,large:a=!1,frozen:l=!1}){const r=Zp[n],i=sn();return e.jsx("span",{className:"inline-flex flex-none","aria-hidden":"true",children:e.jsx(al,{tool:t,seed:s,state:r,pose:nl(s,r),size:a?68:34,theme:i,frozen:l})})}function hs(t){return e.jsx(Xr,{...t,theme:sn()})}const Jp={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 Ge({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] ${Jp[s]}`,children:[e.jsx("strong",{className:"mb-[5px] block text-body",children:t}),n]})}var Qr=Yx();const Yr="(min-width: 768px) and (min-height: 501px)",ef=`${Yr} and (orientation: landscape)`,Xi=t=>typeof globalThis.matchMedia=="function"?globalThis.matchMedia(t):null;function xd(t){return f.useSyncExternalStore(s=>{var a;const n=Xi(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=Xi(t))==null?void 0:s.matches)??!1},()=>!1)}function Et(){return xd(Yr)}function rl(){return xd(ef)}const md=f.createContext(void 0),pd=()=>f.useContext(md);function ts({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(md.Provider,{value:l,children:[e.jsx("section",{className:"split-list",children:t}),e.jsx("section",{className:"split-detail",children:s})]})]})}function Tl({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 tf=["atoi","sessions","prs","rigs","chat"];function Zr(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 fd=t=>({name:t}),sf=t=>Zr(t)===t.name&&!(t.name==="atelier"&&t.sessionId),hd=new Map;function nf(t){const s=Zr(t);s&&s!=="atelier"&&hd.set(s,ne(t))}const Jr=t=>hd.get(t)??ne(fd(t));function af(t,s=[],n=[]){const a=t.filter(i=>i.filter==="permission").length+n.filter(i=>i.routine.kind==="failed").length,l=t.filter(i=>i.filter!=="permission").length+s.filter(i=>i.kind!=="update").length+n.filter(i=>i.routine.kind==="approve").length,r=a||l;return r?{text:r>99?"99+":String(r),tone:a?"red":"amber"}:null}function lf(t,s,n){return t?"online":n==="pc_offline"||n==="relay_unreachable"?"offline":s?"reconnecting":"loading"}const gd=f.createContext({pc:null,look:"online",reach:"pc_online",since:"",retry:()=>{}}),_l=gd.Provider,Ut=()=>f.useContext(gd),Ht=t=>{const s=t??d.host.unknown;return s.length>14?`${s.slice(0,13)}…`:s};function bd({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 il(){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 rf({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(bd,{}),d.brand]}),e.jsx(il,{}),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 jd({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 dr={atoi:"inbox",sessions:"sessions",prs:"pr",rigs:"rigs",chat:"ledge",atelier:"atelier"};function yd(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"}):sf(t)||en(fd(s))}}function of({route:t,active:s,badges:n}){const a=yd(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:tf.map(l=>e.jsxs("a",{href:Jr(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:dr[l]})}),d.nav[l],e.jsx(jd,{badge:n[l]??null,className:"top-[3px] left-1/2 ml-[7px]"})]},l))})}function cf({route:t,active:s,badges:n,atelier:a,ledge:l}){const r=yd(t),i=o=>e.jsxs("a",{href:Jr(o),onClick:r(o,s===o),"aria-current":s===o?"page":void 0,className:"rb",children:[e.jsx(q,{name:dr[o]}),d.nav[o],e.jsx(jd,{badge:n[o]??null,className:"top-[3px] right-[7px]"})]},o);return e.jsxs("nav",{"aria-label":d.nav.label,className:"rail",children:[e.jsx("span",{className:"mb-2",children:e.jsx(bd,{size:30})}),["atoi","sessions","prs","rigs"].map(i),a&&i("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:dr.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 gs({body:t,across:s=!1}={}){const{pc:n,look:a,reach:l,since:r,retry:i}=Ut(),[o,c]=Cn(),x=pd();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:o,onClick:()=>{c(!0),i()},className:Oe({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:Qr.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 df(){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 As({title:t,subtitle:s,wideSubtitle:n,actions:a,wideActions:l,children:r,bodyClassName:i="flex flex-col gap-3",offlineBody:o,heading:c=!0,offlinePill:x=!0}){const u=Et(),{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(il,{}),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(gs,{body:o,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(df,{}):e.jsx("div",{className:`flex-none ${i}`,children:r})]})]})}function Ds(){const[t,s]=f.useState(!1);return f.useEffect(()=>{let n=!0;return Sm().then(a=>{n&&s(a)}),()=>{n=!1}},[]),t}function At(){const t=globalThis.navigator;return t?/iPhone|iPad/.test(t.userAgent)||/Macintosh/.test(t.userAgent)&&t.maxTouchPoints>1:!1}const Es=d.confirm,Il=t=>ze({variant:t,block:!0});function Qi({store:t,item:s,enabled:n,reason:a,onConfirm:l,onDeny:r,denyLabel:i}){const[o,c]=f.useState(null),[x,u]=f.useState(null),[m,p]=f.useState(!1),[h,g]=f.useState(a!==void 0),[y,w]=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 I;if(h||!n)return;const T=(I=t.getState().sessions.get(s.sessionId))==null?void 0:I.pending;if(!(T!=null&&T.key))return;let A=!0,E;c(null);const P={key:T.key,kind:T.kind,text:T.text};return t.prepareConfirm({purpose:"decide",id:s.sessionId,expect:P}).then(L=>{A&&(j.current=P,c(L),E=setTimeout(()=>{A&&(c(null),u("expired"))},L.expiresInMs))},()=>{A&&u("prepareFailed")}),()=>{A=!1,clearTimeout(E)}},[t,s.sessionId,s.key,n,h,y]);const N=h&&a?a==="assertion_expired"?"expired":"failed":x,C=()=>{u(null),g(!1),w(T=>T+1)},M=async()=>{var E,P;if(!n||m||!o)return;if(!o.credentialId){c(null),u("failed");return}p(!0),u(null);const T=await ta({challenge:o.challenge,rpId:o.rpId,credentialId:o.credentialId}).catch(()=>"failed");if(!S.current)return;p(!1);const A=j.current;if(!A||!b.current||((P=(E=t.getState().sessions.get(s.sessionId))==null?void 0:E.pending)==null?void 0:P.key)!==A.key){c(null),u("changed");return}if(T==="cancelled"){u("cancelled");return}if(T==="failed"){u("failed");return}c(null),l(T,A)===null&&u("failed")},R=N==="expired"||N==="failed"||N==="prepareFailed"||N==="changed",v=m?Es.asking:o?At()?Es.goApple:Es.go:Es.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:Es.heading}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:Es.note}),N&&e.jsx(Ge,{title:N==="changed"?d.decide.changed:Es[N],tone:"warning",role:"alert"}),R?e.jsx("button",{type:"button",disabled:!n,onClick:C,className:Il("primary"),children:Es.retry}):e.jsx("button",{type:"button",disabled:!n||m||!o,onClick:()=>{M()},className:Il("primary"),children:v}),e.jsx("button",{type:"button",disabled:!n,onClick:r,className:Il(),children:i??d.decide.deny})]})}function ur(){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 uf(t){return t instanceof HTMLElement?t.isContentEditable||t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT":!1}function Nd(){return document.querySelector('[role="dialog"][aria-modal="true"]')!==null}function ei(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||uf(l.target)||Nd()||n.current(l.key)&&l.preventDefault()};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[t])}const Yi=t=>ze({variant:t,className:"flex-1"}),qs=t=>ze({variant:t,block:!0});function xf(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 mf(t){const{item:s,outcome:n,fresh:a,changed:l,stillPending:r,onReread:i,onDecide:o,answerable:c=!1,choice:x=null,onAnswer:u,answerBlocked:m=!1,onCheck:p,refused:h=!1,store:g,deviceConfirm:y=!1,optionReply:w,multi:S,keys:b=!1,withThread:j=!0}=t,N=d.decide,[C,M]=Cn(),R=Ds(),v=s.risk==="high"||n.kind==="rejected"&&n.reason==="confirm_required",T=a&&!l&&r,A=s.kind!=="question"&&!w&&!S&&!c&&!v,E=A&&Cc(s.tool,s.kind,"always"),P=or(s),I=E&&e.jsx("p",{className:"text-small text-muted phone-side:text-[12px] phone-side:leading-4",children:d.atoi.scope[P]}),L=n.kind!=="sending"&&n.kind!=="uncertain"&&!((n.kind==="rejected"||n.kind==="failed")&&(n.reason==="no_prompt"||n.reason==="nothing_to_decide"||n.reason==="stale"));ei(b&&A&&T&&L,B=>{const Y=B.toLowerCase();return Y==="y"?(o("accept"),!0):Y==="n"?(o("deny"),!0):!1});const $=e.jsx("a",{href:t.threadHref??ne({name:"thread",sessionId:s.sessionId}),className:qs("ghost"),children:d.result.thread(s.botName)}),O=(B,Y,G=!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,G&&j&&e.jsx("div",{className:"phone-side:hidden",children:$}),Y&&e.jsx("p",{className:"text-center text-meta text-muted phone-side:hidden",children:Y})]});if(s.kind==="question"&&!c&&!w&&!S)return O(null,N.answerOnPc);const U=y&&R?g:void 0,D=w?w.canConfirm&&U!==void 0:v&&!c&&U!==void 0,K=n.kind==="rejected"&&(n.reason==="assertion_expired"||n.reason==="assertion_invalid"||n.reason==="confirm_required")?n.reason:void 0,te=B=>w?D?w.picked!==null&&U?e.jsx(Qi,{store:U,item:s,enabled:B,reason:K,onConfirm:w.onReply,onDeny:w.onBack,denyLabel:d.answers.change}):null:e.jsx(ur,{}):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:qs("primary"),children:d.answers.send}),e.jsx("button",{type:"button",disabled:!B,onClick:S.onCancel,className:qs(),children:d.answers.cancel})]}):D&&U?e.jsx(Qi,{store:U,item:s,enabled:B,reason:K,onConfirm:(Y,G)=>U.decide(s.sessionId,"accept",{assertion:Y,expect:G}),onDeny:()=>o("deny")}):c?e.jsx("button",{type:"button",disabled:!B||x===null||m,onClick:()=>u==null?void 0:u(),className:qs("primary"),children:N.send}):b&&A?e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsx("button",{type:"button",disabled:!B,onClick:()=>o("accept"),className:ze({variant:"primary",className:"min-w-[150px]"}),children:N.allow}),e.jsx("button",{type:"button",disabled:!B,onClick:()=>o("deny"),className:ze({className:"min-w-[120px]"}),children:N.deny}),E&&e.jsx("button",{type:"button",disabled:!B,onClick:()=>o("always"),className:ze({variant:"ghost"}),children:qa(P)}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono text-small text-muted",children:d.atoi.keys}),I&&e.jsx("div",{className:"basis-full",children:I})]}):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:()=>o("deny"),className:Yi(),children:N.deny}),v?e.jsx(ur,{}):e.jsx("button",{type:"button",disabled:!B,onClick:()=>o("accept"),className:Yi("primary"),children:N.allow})]}),E&&e.jsx("button",{type:"button",disabled:!B,onClick:()=>o("always"),className:ze({variant:"ghost",block:!0,className:"phone-side:w-auto phone-side:flex-1"}),children:qa(P)})]}),I]}),V=a?w?D?N.answerHint:N.onPcHint:S?N.answerHint:v&&!c&&!D?N.onPcHint:c?N.answerHint:N.hint:N.offlineHint,F=B=>O(e.jsxs(e.Fragment,{children:[B,te(T)]}),V);if(l&&n.kind!=="sending"&&n.kind!=="uncertain")return O(e.jsxs(e.Fragment,{children:[e.jsx(Ge,{title:N.changed,tone:"warning",role:"status"}),te(!1),e.jsx("button",{type:"button",onClick:i,className:qs(),children:N.reread})]}));switch(n.kind){case"sending":return O(e.jsx(Ge,{title:N.sending,role:"status",children:e.jsx("p",{children:N.sendingBody})}));case"uncertain":return O(e.jsxs(e.Fragment,{children:[e.jsx(Ge,{title:N.uncertain,tone:"warning",role:"alert",children:e.jsx("p",{children:N.uncertainBody})}),p&&e.jsx("button",{type:"button",disabled:C,onClick:()=>{M(!0),p()},className:qs("primary"),children:C?N.checking:N.check})]}));case"rejected":case"failed":{const B=n.reason;if(D&&K||B==="confirm_required")return F();if(B==="no_prompt"||B==="nothing_to_decide")return O(e.jsx(Ge,{title:N.noPrompt,tone:"warning",role:"alert"}));if(B==="stale")return O(e.jsxs(e.Fragment,{children:[e.jsx(Ge,{title:N.changed,tone:"warning",role:"alert"}),e.jsx("a",{href:ne({name:"atoi"}),className:qs(),children:d.result.back})]}),void 0,!1);const Y=e.jsx(Ge,{title:xf(s,B),tone:"warning",role:"alert"});return r?F(Y):O(Y)}default:return F(h?e.jsx(Ge,{title:N.failed,tone:"warning",role:"alert"}):void 0)}}const dn=(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 pf(t){const s=t.trim();if(!s.startsWith("<task-notification>"))return null;const n=dn(s,"status"),a=dn(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{...dn(s,"task-id")!==void 0&&{id:dn(s,"task-id")},...dn(s,"output-file")!==void 0&&{output:dn(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 gt=d.thread.rig,Zi=t=>t?`…${t.slice(-4)}`:"…";function ff(t){const s=t.indexOf("@");return s>0?{seat:t.slice(0,s),rig:t.slice(s+1)}:{seat:t}}function Ra(t,s,n){const a=s?n.get(s):void 0,{seat:l,rig:r}=ff(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 hf(t){const s=t.split(`
4
+ `).map(n=>n.trim()).find(n=>n!=="")??"";return`${gt.about(kd(s))} `}const kd=t=>t.length>80?`${t.slice(0,79).trimEnd()}…`:t;function gf(t,s){const n=t.split(`
5
+ `).slice(1).map(a=>a.trim()).find(a=>a!=="");return n?gt.refusedSaid(Vs(s),kd(n)):gt.refusedSilent(Vs(s))}const Vs=t=>new Date(t).toLocaleTimeString(st,{hour:"2-digit",minute:"2-digit"});function bf(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}:{},i=(c=gt.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=Ra(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:hf(t.text)}}:{},raw:i(),...r}}if(t.kind==="sent")return{key:t.id,kind:"rig-message",at:l,dir:"out",who:Ra(a.to??t.to,t.peer,s),text:t.text,delivery:t.status,raw:i(gt.command),...r};if(a.kind==="handoff"){const c=!!t.outgoing,x=Ra(c?a.to:a.from??t.name,t.peer,s),u=c&&t.status==="refused"?{refused:{log:gf(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:i(c?gt.command:gt.raw),...u,...m,...r}}if(a.kind==="unblocked")return{key:t.id,kind:"rig-notice",at:l,tone:"task",title:gt.unblocked(Zi(a.qitem)),raw:i(),...r};if(a.kind==="openrig"&&a.alert==="stalled")return{key:t.id,kind:"rig-notice",at:l,tone:"warn",title:gt.stalled(Zi(a.qitem),a.minutes??0),raw:i(),...r};const o=t.text.split(`
6
+ `).map(c=>c.trim()).find(c=>c!=="")??"";return{key:t.id,kind:"rig-notice",at:l,tone:"plain",title:o,raw:i(),...r}}const jf=t=>{var s;return t.kind==="received"||t.kind==="sent"||t.kind==="notice"?(s=t.rig)==null?void 0:s.packet:void 0};function yf(t){const s=new Map;for(const l of t){const r=jf(l);if(!r||!("rig"in l)||!l.rig)continue;const i=s.get(r.id)??{id:r.id,items:[],count:r.count};i.items.push({id:l.id,index:r.index,raw:l.rig.raw,at:l.at}),s.set(r.id,i)}const n=new Set,a=new Map;for(const l of s.values()){if(l.items.length<2)continue;for(const o of l.items)n.add(o.id);const r=l.items.at(-1),i=[...l.items].sort((o,c)=>o.index-c.index).map(o=>o.raw).join(`
7
+ `);a.set(r.id,{key:`packet-${l.id}`,kind:"rig-raw",at:r.at,raw:{label:gt.rawMany(l.count),text:i}})}return{inPacket:n,after:a}}function Nf(t){const s=[];let n=[];const a=()=>{n.length===1?s.push(n[0]):n.length>1&&s.push({key:`fold-${n[0].key}`,kind:"rig-fold",at:n[0].at,notices:n}),n=[]};for(const l of t){if(l.kind==="rig-notice"&&l.tone==="plain"){n.push(l);continue}a(),s.push(l)}return a(),s}const Ji={pending:"pending","in-progress":"taken","handed-off":"passed",blocked:"blocked",done:"done"};function kf(t,s){if(!t)return{key:"unknown",text:gt.rowState.unknown};const n=Ji[t.state]??"unknown",a=Ji[t.state]?n==="passed"?gt.rowState.passed(Ra(t.handedOffTo,void 0,new Map).name):gt.rowState[n]:t.state,l=[s?gt.log.passed(Vs(t.createdAt)):gt.log.handed(Vs(t.createdAt)),t.claimedAt?gt.log.taken(Vs(t.claimedAt)):n==="pending"?gt.log.notTaken:null,n==="done"?gt.log.done(Vs(t.updatedAt)):null].filter(Boolean).join(" · ");return{key:n,text:a,log:l}}const vf=t=>[...new Set(t.map(s=>s.name))],wf=(t,s)=>t.length===s.length&&t.every((n,a)=>n===s[a]),vd=(t,s)=>Object.values(s).filter(n=>n.message.type==="session.reply"&&n.message.expect===null&&n.message.id===t).sort((n,a)=>n.at.localeCompare(a.at));function Sf(t,s,n){return Object.values(n).some(a=>a.phase==="applied"&&a.message.type==="session.decide"&&a.message.id===s&&a.message.expect.text===t.text&&a.message.decision===t.decision)}function wd(t,s,n,a){var r,i;const l=d.thread.event;return((r=t.by)==null?void 0:r.kind)==="device"?t.by.id===a?l.fromHere:l.fromDevice(t.by.name):((i=t.by)==null?void 0:i.kind)==="pc"?l.fromPc:Sf(t,s,n)?l.fromHere:l.fromPc}function $f(t,s,n,a){const l=d.thread.event;if(!t.decision)return null;if(t.decision==="unknown")return l.resolved;const r=wd(t,s,n,a);return t.decision==="deny"?l.deny(r):l.accept(r)}const xr=2e4,Cf=(t,s,n)=>{const a=t.trim(),l=s.trim();return a===l||n&&a.length>0&&l.startsWith(a)};function Mf(t,s,n,a=Date.now(),l=[],r=new Map,i=null){var b,j,N,C,M,R;let o=[];const c=new Set(l),x=v=>c.has(v)?{cut:!0}:{},u=vd(s.id,n),m=new Set,p=new Set;for(const v of u){if(v.phase!=="applied")continue;const T=v.message.attachments??[],A=t.find(E=>{var P;return E.kind==="prompt"&&Cf(E.text,v.message.text,c.has(E.id))&&!m.has(E.id)&&wf(((P=E.images)==null?void 0:P.map(I=>I.id))??[],T)});A&&(m.add(A.id),p.add(v.op))}const h=yf(t);let g=null,y=null;for(const v of t){const T=bf(v,r,c.has(v.id));if(T){const P=v.kind==="received"||v.kind==="sent"||v.kind==="notice"?((j=(b=v.rig)==null?void 0:b.packet)==null?void 0:j.id)??null:null,I=Vs(T.at);if(!(P&&P===y)&&I!==g&&o.push({key:`time-${v.id}`,kind:"time",label:I}),g=I,y=P,h.inPacket.has(v.id)){const{raw:L,...$}=T;o.push($);const O=h.after.get(v.id);O&&o.push(O)}else o.push(T);continue}if(v.kind==="tool"&&!((N=v.images)!=null&&N.length)){const P={id:v.id,name:_i(v.tool),label:v.label,status:v.status},I=o.at(-1);(I==null?void 0:I.kind)==="tools"?I.tools.push(P):o.push({key:`tools-${v.id}`,kind:"tools",at:v.at,tools:[P]}),g=null,y=null;continue}const A=o.length,E=v.kind==="prompt"?pf(v.text):null;if(E)o.push({key:v.id,kind:"task",task:E,at:v.at,...x(v.id)});else if(v.kind==="prompt")o.push({key:v.id,kind:"me",text:v.text,at:v.at,...(C=v.images)!=null&&C.length?{images:v.images}:{},...m.has(v.id)?{delivery:"taken"}:{},...x(v.id)});else if(v.kind==="reply")o.push({key:v.id,kind:"agent",text:v.text,at:v.at,...x(v.id)});else if(v.kind==="tool"&&((M=v.images)!=null&&M.length))o.push({key:v.id,kind:"capture",label:Zx(v.tool)?d.thread.capture:_i(v.tool),at:v.at,images:v.images});else if(v.kind==="permission"){const P=$f(v,s.id,n,i);P&&o.push({key:v.id,kind:"event",label:P,at:v.at})}o.length>A&&(g=null,y=null)}o=Nf(o);const w=Math.max(...t.map(v=>Date.parse(v.at)));for(const v of u){const T=Date.parse(v.at),A={key:v.op,kind:"me",text:v.message.text,at:v.at,...(R=v.message.attachments)!=null&&R.length?{attachments:v.message.attachments}:{}};if(v.phase==="sending")o.push({...A,delivery:"sending"});else if(v.phase==="uncertain")o.push({...A,delivery:"uncertain"});else if(v.phase==="applied"&&!p.has(v.op)&&!(w-T>xr)){const E=o.findIndex(I=>I.kind!=="awaiting"&&I.kind!=="time"&&!(I.kind==="me"&&I.delivery&&I.delivery!=="taken")&&Date.parse(I.at)>T),P=E<0?o.length:E>0&&o[E-1].kind==="time"?E-1:E;o.splice(P,0,{...A,delivery:"taken",...a-T<xr?{fresh:!0}:{}})}}s.exitedAt&&$m(s,n)&&o.push({key:`closed-${s.exitedAt}`,kind:"event",label:d.sessionEnd.closedHere(Cm(s.exitedAt)),at:s.exitedAt});const S=Vt([s])[0];return S&&o.push({key:`awaiting-${S.key}`,kind:"awaiting",item:S}),o}const Bt=d.thread.composer;function Af(t,s,n){const a=(l,r,i)=>({enabled:!1,placeholder:l,status:{tone:r,label:i}});if(s==="handshaking")return a(Bt.placeholder.connecting,"muted",Bt.status.connecting);if(s!=="ready")return a(Bt.placeholder.offline,"muted",Bt.status.offline);if(t.state==="exited"||t.state==="error")return a(Bt.placeholder.ended,"muted",Bt.status.ended);if(t.pending||t.state==="waiting_permission"||t.state==="waiting_input"){const l=t.pending?t.pending.kind==="question":t.state==="waiting_input";return a(Bt.placeholder.awaiting,l?"attention":"approval",Bt.status.awaiting)}return t.state!=="idle"?a(Bt.placeholder.working,"info",Bt.status.working):n?a(Bt.placeholder.idle(t.name),"info",Bt.status.sending):{enabled:!0,placeholder:Bt.placeholder.idle(t.name),status:{tone:"ok",label:Bt.status.idle}}}const Ef=["Montre le diff","Lance les tests","Explique les changements"],ol=t=>t.state==="done"||t.state==="refused"||t.state==="dropped",Sd=t=>t.owner===tr,$d=t=>(t.giver??tr)===tr&&!Sd(t);function Rf(t){return[...t].filter(s=>Sd(s)&&!ol(s)&&!s.routine).sort((s,n)=>s.at.localeCompare(n.at))}function Tf(t){return[...t].filter(s=>$d(s)&&ol(s)&&!s.seen).sort((s,n)=>s.updatedAt.localeCompare(n.updatedAt))}function _f(t){return[...t].filter(s=>$d(s)&&!ol(s)).sort((s,n)=>n.updatedAt.localeCompare(s.updatedAt))}const If=t=>new Date(Date.UTC(2026,10,23+Ma.indexOf(t))),Lf=t=>If(t).toLocaleDateString(st,{weekday:"short",timeZone:"UTC"}),Cd=(t,s)=>t.toLocaleDateString(st,{weekday:"short",day:"numeric",month:"short",...s?{timeZone:"UTC"}:{}});function Ll(t){const s=d.routines,n=Ma.map((l,r)=>t.includes(l)?r:-1).filter(l=>l>=0);if(n.length===Ma.length)return s.daily;const a=[];for(let l=0;l<n.length;){let r=l;for(;r+1<n.length&&n[r+1]===n[r]+1;)r++;const i=n.slice(l,r+1).map(o=>s.days[Ma[o]]);a.push(i.length>=3?`${i[0]}–${i[i.length-1]}`:i.join(", ")),l=r+1}return a.join(", ")}function Of(t){const[s="",n=""]=t.split("T"),[a,l,r]=s.split("-").map(Number);return`${Cd(new Date(Date.UTC(a,l-1,r)),!0)} ${n}`}function Gn(t){var l;const s=d.routines;if(t.kind==="once"){const r=[...t.at].sort().map(Of),i=r.length>3?s.more(r.slice(0,3).join(", "),r.length-3):r.join(", ");return{card:s.oneShot,ask:i,dated:!0,moments:r}}const n=[...t.times].sort().join(", ");if(((l=t.every)==null?void 0:l.weeks)===2)return{card:`${t.days.length===1?Lf(t.days[0]):Ll(t.days)} ${n} · ${s.everyOther}`,ask:`${n} (${Ll(t.days)}, ${s.every2})`,dated:!0,moments:[]};const a=Ll(t.days);return{card:`${n} · ${a}`,ask:`${n} (${a})`,dated:!1,moments:[]}}const Md=t=>t.toLocaleTimeString(st,{hour:"2-digit",minute:"2-digit"}),ga=t=>`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`;function Ad(t,s,n=!1){const a=new Date(t),l=Md(a);if(!n){const r=new Date(s),i=new Date(s);if(i.setDate(i.getDate()+1),ga(a)===ga(r))return`${d.routines.today} ${l}`;if(ga(a)===ga(i))return`${d.routines.tomorrow} ${l}`}return`${Cd(a,!1)} ${l}`}function Df(t,s){if(!t.nextRun)return null;const n=Gn(t.schedule).dated,a=Ad(t.nextRun,s,n);return n?d.routines.nextDated(a):d.routines.next(a)}function mr(t,s){var l;const n=((l=t==null?void 0:t.lastRun)==null?void 0:l.outcome)==="failed"?t.lastRun:void 0,a=d.routines.why;return t&&(n==null?void 0:n.field)==="cwd"?a.cwd(t.target.cwd):t&&(n==null?void 0:n.field)==="tool"?a.tool(t.target.tool):(n==null?void 0:n.cause)==="timeout"?a.timeout:(n==null?void 0:n.reason)??s??""}const ti=t=>t.state!=="done",si=t=>{var s;return((s=t.lastRun)==null?void 0:s.outcome)==="failed"},eo=t=>t.state==="pending"?0:si(t)?1:t.state==="paused"?3:2,Ff=(t,s)=>eo(t)-eo(s)||(t.nextRun??"￿").localeCompare(s.nextRun??"￿")||t.name.localeCompare(s.name);function zf(t){const s=t.filter(ti).sort(Ff);return{recurring:s.filter(n=>n.schedule.kind==="recurring"),once:s.filter(n=>n.schedule.kind==="once")}}function Pf(t,s){const n=t.filter(ti),a=n.filter(r=>r.state==="enabled"&&r.nextRun).map(r=>r.nextRun).sort()[0],l=a===void 0?null:new Date(a).toDateString()===new Date(s).toDateString()?Md(new Date(a)):Ad(a,s);return{count:n.length,next:l,flagged:n.filter(r=>r.state==="pending"||si(r)).length}}function ia(t,s){const n=[...s].filter(a=>a.name===t.target.name);return n.find(a=>a.state!=="exited")??n[0]}function Bf(t,s){const n=[...s],a=new Set;for(const l of t??[]){if(!ti(l))continue;const r=ia(l,n);r&&a.add(r.id)}return a}const Ed=t=>{var s;return((s=t.proposal)==null?void 0:s.by.name)??(t.createdBy.kind==="session"?t.createdBy.name:void 0)};function Rd(t){const s=n=>n.routine.kind==="approve"?0:1;return[...t].filter(n=>!!n.routine&&!ol(n)).sort((n,a)=>s(n)-s(a)||n.at.localeCompare(a.at))}const Td=t=>t.ids??[t.id],qf={low:"Bas",medium:"Moyen",high:"Élevé",xhigh:"Très élevé",max:"Max",ultra:"Ultra"},Hf={"claude:fable":"Le plus capable","claude:opus":"Très capable, plus lent","claude:sonnet":"Équilibré, au quotidien","claude:haiku":"Rapide et économique"};function Uf(t,s,n){var a;if(s===void 0){const l=n.find(r=>r.isDefault);return l?`${d.model.byDefault} · ${l.label}`:d.model.byDefault}return((a=n.find(l=>l.id===s))==null?void 0:a.label)??s}const oa=t=>qf[t]??t,_d=(t,s)=>Hf[`${t}:${s.id}`]??s.description,Wf=(t,s)=>t.model===s.model&&t.effort===s.effort,Kf=t=>!((t.state==="idle"||t.state==="error")&&!t.pending),ni=t=>({model:t.model??null,effort:t.effort??null});function to(t,s,n){if(t==="cursor")return null;const a=n.model===null?s.find(l=>l.isDefault):s.find(l=>l.id===n.model);return a!=null&&a.efforts&&a.efforts.length>0?a.efforts:null}function Vf(t){const s=/^(?:claude-)?(fable|opus|sonnet|haiku)(?:-(\d+)(?:-(\d+))?)?/i.exec(t);return s?[s[1].charAt(0).toUpperCase()+s[1].slice(1).toLowerCase(),s[2]?s[3]?`${s[2]}.${s[3]}`:s[2]:""].filter(Boolean).join(" "):t}const pr=t=>String(t).padStart(2,"0");function Ua(t){const s=Math.max(0,Math.round(t/1e3));if(s<60)return`${s} s`;const n=Math.floor(s/60);if(n<60)return`${n} min`;const a=Math.floor(n/60);return a<48?`${a} h ${pr(n%60)}`:`${Math.floor(a/24)} j`}const Gf=(t,s)=>t.getFullYear()===s.getFullYear()&&t.getMonth()===s.getMonth()&&t.getDate()===s.getDate(),Ol=t=>`${pr(t.getHours())}:${pr(t.getMinutes())}`,so=t=>t.toLocaleDateString(st,{weekday:"short"}),Xf=168*36e5,Id=(t,s)=>new Date(t).getTime()-s>=Xf;function ai(t,s,n=!1){const a=new Date(t);if(Id(t,s)){const l=a.toLocaleDateString(st,{day:"numeric",month:"short"});return n?l:`${l} ${Ol(a)}`}return Gf(a,new Date(s))?Ol(a):n?so(a):`${so(a)} ${Ol(a)}`}const Qf=t=>t.pct>=100;function ca(t,s){return t>=100?"red":s!==null&&t>=s*100?"amber":""}const Yf=60*6e4;function da(t,s,n=!0){return t.map(a=>{const l=a.readAt===null||s-Date.parse(a.readAt)>Yf;return{...a,status:!n&&a.status==="ok"?"stale":a.status,windows:l?[]:a.windows}})}function Zf(t,s,n=Date.now()){return da(t,n).flatMap(a=>a.status==="expired"||a.status==="loading"?[]:a.windows.flatMap(l=>{const r=ca(l.pct,s);return r?[{harness:a.harness,window:l,tone:r}]:[]}))}function cl(t,s,n){const a=Date.parse(t.startedAt),l=t.context?Math.min(1,t.context.used/t.context.window):void 0;return{...t.model?{model:Vf(t.model)}:{},...t.effort?{effort:oa(t.effort).toLowerCase()}:{},...l!==void 0?{context:{pct:Math.round(l*100),near:l>=n}}:{},...Number.isFinite(a)&&t.state!=="exited"?{duration:Ua(s-a)}:{}}}function no(t){return t<1e3?String(Math.round(t)):t<1e6?`${Math.round(t/1e3)}k`:`${Number((t/1e6).toFixed(1))}M`}function Jf(t,s,n,a,l){const r=s&&da(s,a,l).find(o=>o.harness===t),i=r&&r.status!=="expired"&&r.status!=="loading"?r.windows[0]:void 0;return r&&i?{harness:r.harness,window:i,tone:ca(i.pct,n)}:null}function Ld(t){const s=f.useRef(null);return async n=>{const a=JSON.stringify(n),l=s.current;let r=l&&l.subject===a&&l.until>Date.now()?l.challenge:null;if(!r){s.current=null;try{r=await t.prepareConfirm(n)}catch{return"prepareFailed"}s.current={subject:a,challenge:r,until:Date.now()+r.expiresInMs-2e3}}if(!r.credentialId)return s.current=null,"failed";const i=await ta({challenge:r.challenge,rpId:r.rpId,credentialId:r.credentialId}).catch(()=>"failed");return i==="cancelled"?"cancelled":(s.current=null,i)}}function at({tone:t,title:s,body:n,action:a}){const l=t==="ok"||t==="gone"?"check":t==="denied"?"close":"alert",r=t==="ok"?"text-ok":t==="fail"?"text-destructive":t==="warn"?"text-attention":"text-muted",i=t==="gone"?"border-dashed border-line text-muted":t==="fail"?"border-destructive/40":t==="warn"?"border-attention/45":"border-line";return e.jsxs("div",{role:"status","data-receipt":t,className:`flex min-h-[52px] items-center gap-2.5 rounded-lg border bg-surface px-3 py-2 ${i}`,children:[e.jsx(q,{name:l,className:`size-[18px] ${r}`}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("b",{className:`text-[13.5px] font-semibold [overflow-wrap:anywhere] ${t==="gone"?"text-fg":""}`,children:s}),n&&e.jsx("small",{className:"text-small [overflow-wrap:anywhere] text-muted",children:n})]}),a&&("href"in a?e.jsx("a",{href:a.href,className:Oe({size:"xs",className:"flex-none"}),children:a.label}):e.jsx("button",{type:"button",disabled:a.disabled,onClick:a.onClick,className:Oe({size:"xs",className:"flex-none"}),children:a.label}))]})}function Wa({onGone:t,children:s}){const[n,a]=f.useState(!1),l=f.useRef(t);return l.current=t,f.useEffect(()=>{const r=setTimeout(()=>a(!0),rd);return()=>clearTimeout(r)},[]),f.useEffect(()=>{if(!n)return;const r=setTimeout(()=>l.current(),200);return()=>clearTimeout(r)},[n]),e.jsx("div",{"data-leaving":n||void 0,className:`grid transition-[grid-template-rows,opacity] duration-200 ${n?"grid-rows-[0fr] opacity-0":"grid-rows-[1fr]"}`,children:e.jsx("div",{className:"min-h-0 overflow-hidden",children:s})})}function fr(t){const s=f.useRef(new Map),[n,a]=f.useState(new Set),l=new Set(t.map(c=>c.id)),r=t.map(c=>({...c,ghost:!1})),i=[...s.current].filter(([c])=>!l.has(c)&&!n.has(c)).sort((c,x)=>c[1].index-x[1].index);for(const[c,x]of i)r.splice(Math.min(x.index,r.length),0,{id:c,value:x.value,ghost:!0});r.forEach((c,x)=>s.current.set(c.id,{value:c.value,index:x}));for(const c of[...s.current.keys()])!l.has(c)&&n.has(c)&&s.current.delete(c);const o=c=>a(x=>x.has(c)?x:new Set(x).add(c));return f.useEffect(()=>{[...n].some(c=>!s.current.has(c)&&!l.has(c))&&a(c=>new Set([...c].filter(x=>s.current.has(x)||l.has(x))))}),{entries:r,dismiss:o,dismissed:n}}const Od=150,eh=t=>t.length>Od||t.split(`
8
+ `).length>3,ft=()=>e.jsx("svg",{className:"size-4 flex-none motion-safe:animate-spin",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})});function li(t){var Ie,De;const{store:s,item:n,mode:a,outcome:l,fresh:r,ghost:i,changed:o,canConfirm:c,enroll:x,onGone:u,selected:m=!1,inThread:p=!1,keys:h=!1}=t,[g,y]=f.useState(null),[w,S]=f.useState(!1),[b,j]=f.useState(a.kind==="question"&&a.options.length===0&&a.other),[N,C]=f.useState(""),[M,R]=f.useState(!1),[v,T]=f.useState(null),A=Ld(s),E=rl(),P=p&&E,I=d.atoi.receipt,L=n.botName,$=d.atoi.pill[n.kind],O=ne({name:"request",sessionId:n.sessionId,key:n.key}),U=f.useRef(null),D=h&&a.kind==="permission";if(ei(D,fe=>{var he;return((he=U.current)==null?void 0:he.call(U,fe))??!1}),U.current=null,l.kind==="applied"){const fe={label:I.thread,href:ne({name:"thread",sessionId:n.sessionId})},he=l.answer!==void 0?e.jsx(at,{tone:"ok",title:I.answered(l.answer.length>40?`${l.answer.slice(0,40)}…`:l.answer,L)}):l.decision==="deny"?e.jsx(at,{tone:"denied",title:I.denied(L),body:I.deniedBody,action:fe}):e.jsx(at,{tone:"ok",title:I.allowed(L),body:I.allowedBody,action:fe});return e.jsx(Wa,{onGone:u,children:he})}if(l.kind==="uncertain")return e.jsx(at,{tone:"warn",title:d.decide.uncertain,body:I.uncertainBody,...t.onCheck?{action:{label:I.check,onClick:t.onCheck}}:{}});if(l.kind==="handledElsewhere"||i&&l.kind==="idle"){if(!r)return ao(u),null;const fe=(Ie=t.session)==null?void 0:Ie.lastAnswer,he=fe&&fe.key===n.key,Me=he?fe.by.kind==="pc"?d.thread.event.fromPc:fe.by.id===((De=s.getState().device)==null?void 0:De.id)?d.thread.event.fromHere:d.thread.event.fromDevice(fe.by.name):null,Fe=N.trim()!=="",lt=he?fe.decision?I.decidedAt(L,fe.decision,Pe(fe.at)):I.answeredAt(L,Pe(fe.at),Fe):I.gone(L,Fe);return e.jsx(Wa,{onGone:u,children:e.jsx(at,{tone:"gone",title:Me?d.gone.titleOn(Me):d.gone.titleElsewhere,body:lt})})}if((w||l.kind==="failed"||l.kind==="rejected"&&!["not_taken","stale","confirm_required","assertion_expired","assertion_invalid","free_text","invalid","untypable","read_only","no_prompt","nothing_to_decide"].includes(l.reason))&&!i){const fe=g;return e.jsx(at,{tone:"fail",title:d.decide.failed,body:I.what(L,$),action:fe&&r?{label:I.retry,onClick:()=>{S(!1),B(fe)}}:{label:d.inbox.examine,href:O}})}if(i)return ao(u),null;const te=l.kind==="sending",V=r&&!o&&!te&&!M,F={key:n.key,kind:n.kind,text:n.text},B=fe=>{y(fe),T(null);const he=fe.kind==="decide"?s.decide(n.sessionId,fe.decision,{expect:F}):s.reply(n.sessionId,fe.text,{expect:F});S(he===null)},Y=async()=>{var he,Me;if(!V)return;R(!0),T(null);const fe=await A({purpose:"decide",id:n.sessionId,expect:F});if(R(!1),typeof fe=="string"){T(fe);return}((Me=(he=s.getState().sessions.get(n.sessionId))==null?void 0:he.pending)==null?void 0:Me.key)===n.key&&(y({kind:"decide",decision:"accept"}),S(s.decide(n.sessionId,"accept",{assertion:fe,expect:F})===null))};U.current=D&&V?fe=>{const he=fe.toLowerCase();return he==="y"?(B({kind:"decide",decision:"accept"}),!0):he==="n"?(B({kind:"decide",decision:"deny"}),!0):!1}:null;const G=fe=>te&&g!==null&&JSON.stringify(g)===JSON.stringify(fe),X=td(N),re=()=>{V&&X.problem===null&&B({kind:"reply",text:X.text,label:X.text})},ie=l.kind==="rejected"?l.reason==="not_taken"?d.decide.notTaken:l.reason==="free_text"?d.decide.otherUnsupported:l.reason==="invalid"?n.kind==="question"?d.decide.otherInvalid:d.decide.failed:l.reason==="untypable"?d.question.untypable:l.reason==="read_only"?d.decide.readOnly:l.reason==="no_prompt"||l.reason==="nothing_to_decide"?d.decide.noPrompt:l.reason==="assertion_expired"?d.confirm.expired:l.reason==="assertion_invalid"?d.confirm.failed:null:null,ce=a.kind==="high",z=ce?ed(n):null,k=n.kind==="permission"?n.body??n.text:wn(n),_=[n.repo,n.branch].filter(Boolean).join(" · "),W=(fe="outline",he="")=>Oe({variant:fe,className:`min-w-0 ${he}`}),ee=p?e.jsxs("a",{href:O,className:"-m-1 flex min-w-0 items-center gap-[7px] rounded-md p-1 active:bg-raised",children:[e.jsx(_e,{state:n.kind==="question"?"ask":n.kind==="permission"?"perm":"work"}),e.jsx("b",{className:"min-w-0 truncate font-semibold",children:n.kind==="permission"?d.atoi.line.permission:$}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono text-small whitespace-nowrap text-muted",children:D?d.atoi.keys:yn(n.since,Date.now())}),ce&&e.jsx(zt,{tone:"risk",children:d.risk.badge})]}):e.jsxs("a",{href:O,className:"-m-1 flex min-w-0 items-center gap-[7px] rounded-md p-1 active:bg-raised",children:[e.jsx(fs,{tool:n.tool}),e.jsx("b",{className:"font-semibold whitespace-nowrap",children:L}),_&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:_}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono text-small whitespace-nowrap text-muted",children:yn(n.since,Date.now())}),ce?e.jsx(zt,{tone:"risk",children:d.risk.badge}):e.jsx(zt,{tone:n.kind==="question"?"ask":n.kind==="permission"?"perm":"plain",children:$})]}),Z=eh(k),J=n.kind==="permission"?e.jsx("a",{href:O,className:"block",children:e.jsx(fp,{children:Z?k.split(`
9
+ `).slice(0,3).join(`
10
+ `).slice(0,Od)+"…":k})}):e.jsx("a",{href:O,className:`block text-body [overflow-wrap:anywhere] ${n.kind==="question"?"":"font-semibold"} ${Z?"line-clamp-3":""}`,children:k}),pe=(fe,he=!1)=>e.jsx("p",{className:`text-small [overflow-wrap:anywhere] ${he?"text-destructive":"text-muted"}`,role:he?"alert":void 0,children:fe}),be=v==="cancelled"?d.confirm.cancelled:v==="prepareFailed"?d.confirm.prepareFailed:v==="failed"?d.confirm.failed:null,Ze=(()=>{switch(a.kind){case"examine":return e.jsxs("a",{href:O,className:Oe({size:"sm",className:"self-start"}),children:[d.inbox.examine,e.jsx(q,{name:"chevron",className:"size-4"})]});case"readOnly":return pe(d.decide.readOnly);case"answerOnPc":return pe(d.decide.answerOnPc);case"permission":return P?e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("button",{type:"button",disabled:!V,onClick:()=>B({kind:"decide",decision:"accept"}),className:W("primary","min-w-[140px]"),children:[G({kind:"decide",decision:"accept"})&&e.jsx(ft,{}),d.atoi.allow]}),e.jsxs("button",{type:"button",disabled:!V,onClick:()=>B({kind:"decide",decision:"deny"}),className:W("outline","min-w-[120px]"),children:[G({kind:"decide",decision:"deny"})&&e.jsx(ft,{}),d.atoi.deny]}),a.always&&e.jsxs("button",{type:"button",disabled:!V,onClick:()=>B({kind:"decide",decision:"always"}),className:Oe({variant:"ghost"}),children:[G({kind:"decide",decision:"always"})&&e.jsx(ft,{}),qa(or(n))]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{type:"button",disabled:!V,onClick:()=>B({kind:"decide",decision:"accept"}),className:W("primary"),children:[G({kind:"decide",decision:"accept"})&&e.jsx(ft,{}),d.atoi.allow]}),e.jsxs("button",{type:"button",disabled:!V,onClick:()=>B({kind:"decide",decision:"deny"}),className:W(),children:[G({kind:"decide",decision:"deny"})&&e.jsx(ft,{}),d.atoi.deny]})]}),a.always&&e.jsxs("button",{type:"button",disabled:!V,onClick:()=>B({kind:"decide",decision:"always"}),className:Oe({variant:"ghost",className:"-mt-1 self-stretch"}),children:[G({kind:"decide",decision:"always"})&&e.jsx(ft,{}),qa(or(n))]})]});case"high":return c?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{type:"button",disabled:!V,onClick:()=>{Y()},className:W("primary"),children:[M||G({kind:"decide",decision:"accept"})?e.jsx(ft,{}):e.jsx(q,{name:"face",className:"size-[18px]"}),e.jsx("span",{className:"truncate",children:M?d.confirm.checking:At()?d.confirm.goApple:d.confirm.go})]}),e.jsxs("button",{type:"button",disabled:!V,onClick:()=>B({kind:"decide",decision:"deny"}),className:W(),children:[G({kind:"decide",decision:"deny"})&&e.jsx(ft,{}),d.atoi.deny]})]}),M&&pe(d.confirm.askingNote)]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{type:"button",disabled:!0,className:W(),children:d.decide.onPc}),e.jsxs("button",{type:"button",disabled:!V,onClick:()=>B({kind:"decide",decision:"deny"}),className:W(),children:[G({kind:"decide",decision:"deny"})&&e.jsx(ft,{}),d.atoi.deny]})]}),pe(d.decide.onPcHint),x&&e.jsx("a",{href:ne({name:"connection",section:"link"}),className:"self-start text-small font-medium underline underline-offset-2",children:d.enroll.link})]});case"question":{const fe=`free-${n.sessionId}`,he=X.problem!==null&&X.problem!=="empty";return e.jsxs(e.Fragment,{children:[a.options.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:a.options.map((Me,Fe)=>{const lt={kind:"reply",text:String(Fe+1),label:Me};return e.jsxs("button",{type:"button",disabled:!V,onClick:()=>B(lt),className:Oe({className:"h-auto min-h-11 max-w-full py-2 text-left whitespace-normal [overflow-wrap:anywhere]"}),children:[G(lt)&&e.jsx(ft,{}),Me]},`${Fe}:${Me}`)})}),a.other&&!b&&a.options.length>0&&e.jsx("button",{type:"button",disabled:!V,onClick:()=>j(!0),className:"self-start text-[13px] font-medium text-muted underline-offset-2 hover:underline disabled:opacity-45",children:d.atoi.other}),a.other&&b&&e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:`flex items-center gap-2 rounded-[10px] border bg-surface py-[5px] pr-[5px] pl-3 focus-within:border-ring ${he?"border-destructive":"border-input"}`,children:[e.jsx("label",{htmlFor:fe,className:"sr-only",children:d.question.fieldLabel(L)}),e.jsx("input",{id:fe,value:N,onChange:Me=>C(Me.target.value),placeholder:d.question.placeholder,autoComplete:"off",enterKeyHint:"send","aria-invalid":he,disabled:!r||o,onKeyDown:Me=>{Me.key==="Enter"&&!Me.nativeEvent.isComposing&&(Me.preventDefault(),re())},className:"h-[34px] min-w-0 flex-1 bg-transparent text-base text-fg outline-none placeholder:text-muted"}),e.jsx("button",{type:"button","aria-label":d.decide.send,title:d.decide.send,disabled:!V||X.problem!==null,onClick:re,className:"grid size-9 flex-none place-items-center rounded-lg bg-primary text-primary-fg disabled:opacity-40",children:(g==null?void 0:g.kind)==="reply"&&te&&g.text===X.text?e.jsx(ft,{}):e.jsx(q,{name:"send",className:"size-[18px]"})})]}),he?pe(X.problem==="long"?d.question.long(Vr):X.problem==="digit"?d.question.digit:d.question.untypable,!0):pe(d.atoi.sendHint(L))]}),!a.other&&a.options.length>0&&pe(d.decide.otherUnsupported)]})}}})(),pt=ce?d.atoi.kindName.permission:d.atoi.kindName[n.kind];return e.jsxs($n,{tone:n.kind==="question"?"ask":n.kind==="permission"?"perm":"plain",selected:m,label:d.atoi.region(pt,L,n.repo),children:[ee,ie&&pe(ie,!0),o&&e.jsxs("div",{role:"status",className:"flex items-start gap-2 rounded-md border border-attention/45 px-2.5 py-2 text-small",children:[e.jsx(q,{name:"alert",className:"mt-px size-4 text-attention"}),d.decide.changed]}),J,Z&&e.jsx("a",{href:O,className:"-mt-1 self-start text-[13px] font-medium underline-offset-2 hover:underline",children:d.atoi.readAll}),z&&e.jsxs("div",{className:"flex items-start gap-2 rounded-md bg-destructive/10 px-2.5 py-2 text-small",children:[e.jsx(q,{name:"alert",className:"mt-px size-4 text-destructive"}),e.jsxs("div",{className:"flex flex-col",children:[e.jsx("b",{className:"font-semibold",children:z.title}),e.jsx("span",{className:"text-muted",children:z.body})]})]}),o&&e.jsx("button",{type:"button",onClick:t.onReread,className:Oe(),children:d.decide.reread}),be&&pe(be,!0),Ze,te&&pe(d.decide.sending)]})}function ao(t){queueMicrotask(t)}const th=t=>Oe({variant:t?"primary":"outline",className:"h-auto min-h-11 w-full justify-start gap-2 px-3 py-2.5 text-left leading-[19px] whitespace-normal [overflow-wrap:anywhere]"}),lo=t=>new Date(t).toLocaleTimeString(st,{hour:"2-digit",minute:"2-digit"});function Dd({store:t,ask:s,end:n,fresh:a,ghost:l,canConfirm:r,enroll:i,onGone:o,full:c=!1,selected:x=!1}){const u=d.asks,m=d.atoi.receipt,p=Ld(t),h=nd(s),g=ad(s),[y,w]=f.useState(!1),[S,b]=f.useState(""),[j,N]=f.useState(null),[C,M]=f.useState(null),[R,v]=f.useState(!1),[T,A]=f.useState(null),E=ne({name:"ask",id:s.id}),P=async(k,_)=>{N(k),M(null),A({key:k,answer:_});let W;if(_.kind!=="seen"){const Z=await p({purpose:"rig",qitem:s.id,answer:_});if(typeof Z=="string"){N(null),M(Z);return}W=Z}const ee=t.answerAsk(s.id,_,W?{assertion:W}:{});if(N(null),ee===null){M("notSent");return}(_.kind==="words"||_.kind==="resolve")&&w(!1)},I=m.what(g.name,u.pill[h]);if(n.kind==="sent"){const k=vp(s,n.answer),_=n.answer.kind==="seen"?e.jsx(at,{tone:"ok",title:m.seen,body:m.what(g.name,s.summary)}):e.jsx(at,{tone:"ok",title:m.sentTo(g.name),body:[g.role,k?`« ${k.length>60?`${k.slice(0,60)}…`:k} »`:""].filter(Boolean).join(" · ")});return e.jsx(Wa,{onGone:o,children:_})}if(n.kind==="already"||l&&n.kind!=="failed"&&n.kind!=="uncertain")return!a&&l&&n.kind!=="already"?(queueMicrotask(o),null):e.jsx(Wa,{onGone:o,children:e.jsx(at,{tone:"gone",title:u.already,body:m.what(g.name,s.summary)})});const L=k=>{P((T==null?void 0:T.key)??"retry",k)};if(n.kind==="uncertain")return e.jsx(at,{tone:"warn",title:d.decide.uncertain,body:u.uncertain,action:{label:u.retry,onClick:()=>{t.resendAsk(s.id)||L(n.answer)},disabled:!a||j!==null}});if(n.kind==="failed"){const k=n.error==="openrig_stopped"?u.stopped:n.error==="unreachable"?u.unreachable:n.message??n.error;return e.jsx(at,{tone:"fail",title:u.notSent(k),body:I,action:{label:u.retry,onClick:()=>L(n.answer),disabled:!a||j!==null}})}const $=n.kind==="sending"||j!==null,O=a&&!$,U=h!=="update",D=O&&(r||!U),K=k=>j===k||n.kind==="sending"&&(T==null?void 0:T.key)===k?e.jsx(ft,{}):null,te=s.questions.length>1,V=s.questions.filter(k=>Vi(s,k.id)!==null||n.kind==="recorded"&&n.answer.kind==="choice"&&n.answer.questionId===k.id).length,F=s.bodyTruncated&&s.body===s.summary?"":s.body,B=s.priority==="routine"?null:u.priority[s.priority],Y=(k,_=!1)=>e.jsx("p",{className:`text-small [overflow-wrap:anywhere] ${_?"text-destructive":"text-muted"}`,role:_?"alert":void 0,children:k}),G=At(),X=U?G?u.sendCheck:u.sendDevice:u.send,re=k=>{var ee;const _=Vi(s,k.id)??(n.kind==="recorded"&&n.answer.kind==="choice"&&n.answer.questionId===k.id?((ee=k.options.find(Z=>Z.id===n.answer.optionId))==null?void 0:ee.label)??null:null);if(_!==null)return e.jsxs("span",{className:"flex items-center gap-1.5 text-body",children:[e.jsx(q,{name:"check",className:"size-4 text-ok"}),_]});const W=[...k.options].sort((Z,J)=>Number(J.recommended)-Number(Z.recommended));return e.jsx("div",{className:"flex flex-col gap-2",children:W.map(Z=>{const J=`${k.id}:${Z.id}`;return e.jsxs("button",{type:"button",disabled:!D||y,onClick:()=>{P(J,{kind:"choice",questionId:k.id,optionId:Z.id})},className:th(Z.recommended),children:[K(J),e.jsx("span",{className:"min-w-0",children:Z.label}),Z.recommended&&e.jsx("span",{className:"ml-auto pl-2 text-xs whitespace-nowrap opacity-85",children:u.recommended})]},Z.id)})})},ie=e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{className:"sr-only",htmlFor:`ask-${s.id}`,children:s.kind==="parked"?u.placeholderParked(g.name):u.placeholder}),e.jsx("textarea",{id:`ask-${s.id}`,rows:2,value:S,onChange:k=>b(k.target.value),disabled:$,placeholder:s.kind==="parked"?u.placeholderParked(g.name):u.placeholder,className:"max-h-[140px] min-h-11 w-full resize-y rounded-[10px] border border-input bg-surface px-3 py-2.5 text-base leading-[22px] text-fg outline-none placeholder:text-muted focus:border-ring"}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{type:"button",disabled:!D||!S.trim(),onClick:()=>{P("words",s.kind==="parked"?{kind:"resolve",text:S.trim()}:{kind:"words",text:S.trim()})},className:Oe({variant:"primary",className:"min-w-0"}),children:[K("words")??(U?e.jsx(q,{name:"face",className:"size-[18px]"}):null),e.jsx("span",{className:"truncate",children:X})]}),e.jsx("button",{type:"button",disabled:$,onClick:()=>w(!1),className:Oe({className:"min-w-0"}),children:u.cancel})]}),te&&V<s.questions.length&&Y(u.settlesAll)]}),ce=C==="cancelled"?d.confirm.cancelled:C==="prepareFailed"?d.confirm.prepareFailed:C==="failed"?d.confirm.failed:C==="notSent"?d.decide.failed:n.kind==="refused"?n.reason==="assertion_expired"?d.confirm.expired:n.reason==="unavailable"?u.notSent(u.unreachable):d.confirm.failed:null,z=!U||s.questions.length===0&&!y&&h!=="parked"&&h!=="question"?null:r?j!==null&&j!=="seen"?Y(d.confirm.asking):e.jsxs("p",{className:"flex items-center gap-1.5 text-small text-muted",children:[e.jsx(q,{name:"face",className:"size-4"}),G?u.confirmHint:u.confirmHintDevice]}):e.jsxs(e.Fragment,{children:[Y(u.needsDevice),i&&e.jsx("a",{href:ne({name:"connection",section:"link"}),className:"self-start text-small font-medium underline underline-offset-2",children:d.enroll.link})]});return e.jsxs($n,{tone:h==="update"?"plain":"rig",selected:x,label:d.atoi.region(d.atoi.kindName.rig,g.name,s.from.rig??""),children:[e.jsxs("a",{href:E,className:"-m-1 flex min-w-0 items-center gap-[7px] rounded-md p-1 active:bg-raised",children:[e.jsx("b",{className:"font-semibold whitespace-nowrap",children:g.name}),s.from.rig&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:s.from.rig}),e.jsx("span",{className:"flex-1"}),B&&e.jsx(zt,{tone:"urgent",children:B}),e.jsx(zt,{tone:h==="parked"?"rig":"plain",children:u.pill[h]}),e.jsx("time",{dateTime:s.updatedAt,className:"font-mono text-small whitespace-nowrap text-muted",children:lo(s.updatedAt)})]}),e.jsx("a",{href:E,className:"block text-body font-semibold [overflow-wrap:anywhere]",children:s.summary}),F&&!y&&(c?e.jsx("p",{className:"text-body whitespace-pre-wrap [overflow-wrap:anywhere] text-muted",children:F}):e.jsx("a",{href:E,className:"line-clamp-3 text-body [overflow-wrap:anywhere] text-muted",children:F})),!c&&!y&&(s.bodyTruncated||F.length>180||F.split(`
11
+ `).length>3)&&e.jsx("a",{href:E,className:"-mt-1 self-start text-[13px] font-medium underline-offset-2 hover:underline",children:u.readAll}),c&&(s.evidenceRef||s.detail)&&e.jsxs("dl",{className:"grid grid-cols-[74px_minmax(0,1fr)] gap-x-3 gap-y-2 text-small",children:[e.jsx("dt",{className:"text-muted",children:d.detail.asked}),e.jsx("dd",{className:"m-0",children:lo(s.createdAt)}),s.evidenceRef&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-muted",children:u.source}),e.jsx("dd",{className:"m-0 font-mono [overflow-wrap:anywhere]",children:s.evidenceRef})]})]}),c&&s.detail&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-expanded":R,onClick:()=>v(k=>!k),className:"self-start text-[13px] font-medium",children:[R?"⌄":"›"," ",u.details]}),R&&e.jsx("p",{className:"text-small whitespace-pre-wrap [overflow-wrap:anywhere] text-muted",children:s.detail})]}),h==="update"?e.jsx("div",{className:"flex",children:e.jsxs("button",{type:"button",disabled:!O,onClick:()=>{P("seen",{kind:"seen"})},className:Oe({size:"sm"}),children:[K("seen"),u.seen]})}):y&&!te?ie:s.questions.length===0?y?ie:e.jsx("button",{type:"button",disabled:!D,onClick:()=>w(!0),className:Oe({className:"self-start"}),children:s.kind==="parked"?u.answerParked:u.writeAnswer}):te?e.jsxs(e.Fragment,{children:[s.questions.map((k,_)=>e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("span",{className:"text-small text-muted [overflow-wrap:anywhere]",children:[_+1,". ",k.question]}),re(k)]},k.id)),e.jsx("span",{className:"text-small text-muted",children:u.progress(V,s.questions.length)}),y?ie:e.jsx("button",{type:"button",disabled:!D,onClick:()=>w(!0),className:"self-start text-[13px] font-medium text-muted underline-offset-2 hover:underline disabled:opacity-45",children:u.answerOther})]}):e.jsxs(e.Fragment,{children:[re(s.questions[0]),e.jsx("button",{type:"button",disabled:!D,onClick:()=>w(!0),className:"self-start text-[13px] font-medium text-muted underline-offset-2 hover:underline disabled:opacity-45",children:u.answerOther})]}),ce&&Y(ce,!0),!ce&&z]})}const Cs=(t=!1)=>["inline-flex h-10 min-w-0 flex-auto items-center justify-center gap-1.5 rounded-[10px] border px-2.5 text-[14px] font-medium whitespace-nowrap transition-colors duration-100 disabled:opacity-45",t?"border-transparent bg-primary text-primary-fg active:bg-primary-hover":"border-input bg-surface dark:bg-transparent text-fg active:bg-raised"].join(" ");function dl(t){switch(t.status){case"applied":return null;case"cancelled":return d.confirm.cancelled;case"expired":return d.confirm.expired;case"failed":return d.chat.point.note.failed;case"rejected":return t.reason==="not_pending"||t.reason==="stale"||t.reason==="not_found"?d.chat.point.note.stale:d.confirm.refused[t.reason]??d.chat.point.note.failed}}function Fd({routine:t,session:s,frozen:n}){return e.jsx(ll,{tool:(s==null?void 0:s.tool)??t.target.tool,seed:(s==null?void 0:s.id)??t.id,state:(s==null?void 0:s.state)??"exited",frozen:n})}function sh(){return e.jsx("span",{className:"inline-flex h-5 flex-none items-center rounded-lg border border-dashed border-attention/50 px-[7px] text-[11.5px] whitespace-nowrap text-attention",children:d.routines.late})}function nh({store:t,routine:s,session:n,offline:a,now:l,focused:r}){const i=d.routines,[o,c]=f.useState(null),x=f.useRef(null),[u,m]=f.useState(r);f.useEffect(()=>{var R,v;if(!r)return;(v=(R=x.current)==null?void 0:R.scrollIntoView)==null||v.call(R,{block:"center"}),m(!0);const M=setTimeout(()=>m(!1),ah);return()=>clearTimeout(M)},[r]);const[p,h]=f.useState(null),g=s.state==="pending",y=si(s),w=s.state==="paused",S=async(M,R)=>{c(M),h(null),h(dl(await t.routineCmd(s.id,R))),c(null)},b=g||w?null:Df(s,l),j=s.lastRun,N=M=>o===M?e.jsx(ft,{}):null;let C;return g?C=e.jsx(zt,{tone:"ask",children:i.pending}):j?C=e.jsxs(e.Fragment,{children:[e.jsx("span",{"aria-hidden":"true",className:`w-3.5 text-center text-[11px] ${j.outcome==="failed"?"text-approval":"text-ok"}`,children:j.outcome==="failed"?"!":"✓"}),e.jsx("span",{children:i.lastAt(j.slot,i.outcome[j.outcome])}),j.late&&e.jsx(sh,{})]}):C=e.jsx("span",{children:i.never}),e.jsx("div",{ref:x,"data-focused":u||void 0,className:`rounded-lg transition-shadow duration-200 ${u?"shadow-[0_0_0_2px_var(--color-task)] [&>article]:bg-[color-mix(in_srgb,var(--color-task)_10%,var(--color-surface))]":""}`,children:e.jsxs($n,{tone:g?"ask":y?"perm":"plain",label:s.name,children:[e.jsxs("div",{"data-routine":s.id,className:"flex min-w-0 items-center gap-[9px]",children:[e.jsx(Fd,{routine:s,session:n,frozen:a}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("b",{className:"truncate text-[15px] font-semibold",children:s.name}),e.jsxs("span",{className:"truncate text-[13px] text-muted",children:[s.target.name," · ",Gn(s.schedule).card]})]})]}),w?e.jsx("div",{children:e.jsx(zt,{children:i.paused})}):b&&e.jsx("p",{className:"text-[13px] text-muted",children:b}),e.jsx("div",{className:"flex flex-wrap items-center gap-1.5 text-[13px] text-muted",children:C}),y&&mr(s)&&e.jsx("p",{className:"text-[13px] [overflow-wrap:anywhere] text-muted",children:mr(s)}),e.jsx("div",{className:"flex gap-2",children:g?e.jsx("a",{href:ne({name:"atoi"}),className:Cs(),children:i.seeInAtoi}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:a||o!==null,onClick:()=>{S("run","run")},className:Cs(),children:[N("run")??e.jsx(q,{name:"play",className:"size-3.5"}),e.jsx("span",{className:"truncate",children:y?i.retry:i.runNow})]}),e.jsxs("button",{type:"button",disabled:a||o!==null,onClick:()=>{S("toggle",w?"resume":"pause")},className:Cs(),children:[N("toggle"),e.jsx("span",{className:"truncate",children:w?i.resume:i.pause})]})]})}),p&&e.jsx("p",{role:"alert",className:"text-small text-destructive",children:p})]})})}const ah=1500;function ro({children:t}){return e.jsx("h2",{className:"mx-1 -mb-1 text-[10.5px] font-medium tracking-[.06em] text-muted uppercase",children:t})}function io({store:t,focus:s}){const n=me(t),a=Xt(),l=Et(),r=d.routines,i=zf(n.routines??[]),o=!n.fresh,c=[...n.sessions.values()],x=u=>u.map(m=>e.jsx(nh,{store:t,routine:m,session:ia(m,c),offline:o,now:a,focused:m.id===s},m.id));return e.jsxs(As,{title:r.title,heading:!1,bodyClassName:"flex flex-col gap-2.5",children:[!l&&e.jsxs(e.Fragment,{children:[e.jsxs("a",{href:ne({name:"sessions"}),onClick:u=>{u.preventDefault(),sl({name:"sessions"})},className:"-mb-1 flex items-center gap-1 self-start text-body text-muted",children:[e.jsx(q,{name:"back",className:"size-4"}),r.back]}),e.jsx("h1",{className:"text-[22px] leading-7 font-semibold tracking-[-.02em]",children:r.title})]}),i.recurring.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ro,{children:r.groups.recurring}),x(i.recurring)]}),i.once.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ro,{children:r.groups.once}),x(i.once)]}),e.jsx("p",{className:"px-2 text-center text-[12.5px] text-muted",children:r.readonly})]})}const lh=t=>new Date(t).toLocaleTimeString(st,{hour:"2-digit",minute:"2-digit"});function ri({failed:t,at:s}){const n=d.routines.atoi;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(zt,{tone:t?"perm":"ask",children:t?n.failed:n.ask}),e.jsxs("span",{className:"text-[13px] text-muted",children:[n.kind," · ",e.jsx("time",{dateTime:s,children:lh(s)})]})]})}function ii({routine:t,session:s,frozen:n,children:a}){return e.jsxs("div",{className:"flex items-start gap-[9px]",children:[e.jsx(Fd,{routine:t,session:s,frozen:n}),e.jsx("p",{className:"min-w-0 flex-1 text-body [overflow-wrap:anywhere]",children:a})]})}const Ka=t=>{var s;return((s=t.proposal)==null?void 0:s.spec)??t};function rh(t){return t.task.routine.kind==="failed"?e.jsx(ch,{...t}):Td(t.task.routine).length>1?e.jsx(oh,{...t}):e.jsx(ih,{...t})}function ih({store:t,task:s,state:n,canConfirm:a}){var M,R;const l=d.routines.atoi,r=s.routine.id,i=(M=n.routines)==null?void 0:M.find(v=>v.id===r),o=n.routineDetails[r],c=o&&o!=="gone"?o:void 0,[x,u]=f.useState(null),[m,p]=f.useState(null);f.useEffect(()=>{n.fresh&&t.showRoutine(r)},[t,r,n.fresh,o]);const h=c?Ka(c):i&&!i.proposed?i:void 0,g=c?!!c.proposal:!!(i!=null&&i.proposed),y=c??i,w=y?ia(y,n.sessions.values()):void 0,S=(y&&Ed(y))??s.giverName??"",[b,j]=f.useState(!1),N=async v=>{u(v),p(null),j(!1);const T=v==="approve"?await t.approveRoutine(r,c.key):await t.routineCmd(r,"refuse");v==="approve"&&T.status==="rejected"&&T.reason==="stale"?(j(!0),t.rereadRoutine(r)):p(dl(T)),u(null)},C=!n.fresh||x!==null;return e.jsxs($n,{tone:"ask",label:`${l.ask} · ${s.routine.name}`,children:[e.jsx(ri,{failed:!1,at:s.at}),y?e.jsx(ii,{routine:y,session:w,frozen:!n.fresh,children:h?e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:S})," ",g?l.editAsks(h.name,Gn(h.schedule).ask):l.asks(h.name,Gn(h.schedule).ask,h.target.cwd)]}):l.fallbackAsk(s.routine.name)}):e.jsx("p",{className:"text-body [overflow-wrap:anywhere]",children:l.fallbackAsk(s.routine.name)}),c&&e.jsx("pre",{"data-prompt":"",className:"m-0 rounded-md border border-line bg-raised px-[9px] py-1.5 font-mono text-small leading-[17px] whitespace-pre-wrap [overflow-wrap:anywhere]",children:Ka(c).prompt}),b&&e.jsx("p",{role:"status",className:"text-small text-attention [overflow-wrap:anywhere]",children:l.stale(((R=h??y)==null?void 0:R.name)??s.routine.name)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button",disabled:C||!c,onClick:()=>{N("approve")},className:Cs(!0),children:[x==="approve"&&e.jsx(ft,{}),l.activate]}),e.jsxs("button",{type:"button",disabled:C,onClick:()=>{N("refuse")},className:Cs(),children:[x==="refuse"&&e.jsx(ft,{}),l.refuse]})]}),m?e.jsx("p",{role:"alert",className:"text-small text-destructive",children:m}):e.jsx("p",{className:"text-[12px] text-muted",children:a?l.verify:d.confirm.refused.confirm_required})]})}function oh({store:t,task:s,state:n,canConfirm:a}){const l=d.routines.atoi,r=Td(s.routine),i=r.map(E=>{var P;return(P=n.routines)==null?void 0:P.find(I=>I.id===E)}).filter(E=>!!E),o=n.routines?i.filter(E=>E.state==="pending"||E.proposed):[],c=n.routines?o.length:r.length,x=i[0],u=x?ia(x,n.sessions.values()):void 0,[m,p]=f.useState(null),[h,g]=f.useState(null),[y,w]=f.useState(!1),S=o.map(E=>n.routineDetails[E.id]),b=S.map(E=>E&&E!=="gone"?E.key:"-").join(",");f.useEffect(()=>{if(n.fresh)for(const E of o)t.showRoutine(E.id)},[t,n.fresh,o.map(E=>E.id).join(","),b]);const j=S.filter(E=>!!E&&E!=="gone"),N=o.length>0&&j.length===o.length,C=async E=>{p(E),g(null),w(!1);const P=o.map($=>{const O=n.routineDetails[$.id];return{routine:$.id,routineKey:O&&O!=="gone"?O.key:$.key}}),[I,...L]=P;if(I){const $=E==="approve"?await t.approveRoutine(I.routine,I.routineKey,L):await t.routineCmd(I.routine,"refuse",L);if(E==="approve"&&$.status==="rejected"&&$.reason==="stale"){w(!0);for(const O of P)t.rereadRoutine(O.routine)}else g(dl($))}p(null)},M=!n.fresh||m!==null||o.length===0,R=(x&&Ed(x))??s.giverName??"",v=new Set(j.map(E=>Ka(E).target.cwd)),T=v.size===1?[...v][0]:void 0,A=new Set;return e.jsxs($n,{tone:"ask",label:`${l.ask} · ${s.routine.name}`,children:[e.jsx(ri,{failed:!1,at:s.at}),x?e.jsxs(ii,{routine:x,session:u,frozen:!n.fresh,children:[e.jsx("b",{className:"font-semibold",children:R})," ",l.groupAsks(c),T&&e.jsxs("span",{className:"text-muted",children:[" ",l.inDir(T)]})]}):e.jsx("p",{className:"text-body [overflow-wrap:anywhere]",children:l.fallbackAsk(s.routine.name)}),o.length>0&&e.jsx("ul",{className:"m-0 flex list-none flex-col gap-2.5 p-0",children:o.map(E=>{const P=n.routineDetails[E.id],I=P&&P!=="gone"?Ka(P):void 0,L=Gn((I??E).schedule),$=I&&!A.has(I.prompt)?I.prompt:void 0;return I&&A.add(I.prompt),e.jsxs("li",{className:"flex flex-col gap-1",children:[e.jsxs("span",{className:"text-[13px]",children:[e.jsx("b",{className:"font-semibold",children:(I??E).name})," ",e.jsxs("span",{className:"text-muted",children:["· ",L.moments[0]??L.card,I&&!T?` · ${l.inDir(I.target.cwd)}`:""]})]}),$&&e.jsx("pre",{"data-prompt":"",className:"m-0 rounded-md border border-line bg-raised px-[9px] py-1.5 font-mono text-[11.5px] leading-[17px] whitespace-pre-wrap [overflow-wrap:anywhere]",children:$})]},E.id)})}),y&&e.jsx("p",{role:"status",className:"text-small text-attention [overflow-wrap:anywhere]",children:l.stale(s.routine.name)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button",disabled:M||!N,onClick:()=>{C("approve")},className:Cs(!0),children:[m==="approve"&&e.jsx(ft,{}),l.activateAll(c)]}),e.jsxs("button",{type:"button",disabled:M,onClick:()=>{C("refuse")},className:Cs(),children:[m==="refuse"&&e.jsx(ft,{}),l.refuseAll(c)]})]}),h?e.jsx("p",{role:"alert",className:"text-small text-destructive",children:h}):e.jsx("p",{className:"text-[12px] text-muted",children:a?l.verify:d.confirm.refused.confirm_required})]})}function ch({store:t,task:s,state:n}){var g;const a=d.routines.atoi,l=s.routine.id,r=(g=n.routines)==null?void 0:g.find(y=>y.id===l),i=r?ia(r,n.sessions.values()):void 0,[o,c]=f.useState(!1),[x,u]=f.useState(null),m=mr(r,s.routine.reason),p=r?a.failedLine(r.name,r.target.name,m):a.fallbackFailed(s.routine.name,m),h=async()=>{c(!0),u(null),u(dl(await t.routineCmd(l,"run"))),c(!1)};return e.jsxs($n,{tone:"perm",label:`${a.failed} · ${s.routine.name}`,children:[e.jsx(ri,{failed:!0,at:s.at}),r?e.jsx(ii,{routine:r,session:i,frozen:!n.fresh,children:p}):e.jsx("p",{className:"text-body [overflow-wrap:anywhere]",children:p}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button",disabled:!n.fresh||o,onClick:()=>{h()},className:Cs(!0),children:[o&&e.jsx(ft,{}),a.retry]}),e.jsx("a",{href:ne({name:"routines",routine:l}),className:Cs(),children:a.see})]}),x&&e.jsx("p",{role:"alert",className:"text-small text-destructive",children:x})]})}const Be=d.compare,oo=t=>{const s=t.replace(/\D/g,"");return[s.slice(0,3),s.slice(3)]},Ta="\0",Dl=t=>{const[s="",n=""]=t.split(Ta);return[s,n]};function ws({login:t}){return t?e.jsxs("div",{className:"flex h-8 items-center gap-2 self-center rounded-full border border-line pr-3 pl-1 text-body text-muted",children:[e.jsx("span",{"aria-hidden":"true",className:"inline-flex size-6 items-center justify-center rounded-full bg-raised text-meta font-semibold text-fg",children:t.slice(0,1).toUpperCase()}),d.account(t)]}):null}function dh({step:t,login:s,pcName:n,lost:a,stalled:l=!1,reach:r="pc_online",onRetry:i,onSame:o,onCancel:c,onRestart:x,onDone:u,actions:m}){var C,M;const[p,h]=f.useState(!1),g=n??d.yourPc,y=()=>{h(!1),x()},w=e.jsx("button",{type:"button",onClick:y,className:dt,children:Be.retry}),S=a&&(t==null?void 0:t.step)!=="linked"?e.jsx(Ge,{title:Be.lostTitle,role:"status",children:e.jsx("p",{children:Be.lostBody})}):null;if((t==null?void 0:t.step)==="linked")return e.jsxs(St,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(hs,{size:88}),e.jsx("h1",{className:qt,children:Be.doneTitle(t.pc.name??n??d.yourPc,qr(((C=globalThis.navigator)==null?void 0:C.userAgent)??"",((M=globalThis.navigator)==null?void 0:M.maxTouchPoints)??0).replace(/ tablette$/,""))}),e.jsx("p",{className:"max-w-[300px] text-muted",children:Be.doneBody})]}),e.jsx($t,{}),m??e.jsx("a",{href:ne({name:"atoi"}),onClick:u,className:bt,children:Be.seePending})]});if((t==null?void 0:t.step)==="cancelled"&&p)return e.jsxs(St,{children:[e.jsx(ws,{login:s}),e.jsxs("section",{role:"alert",className:"rounded-control border border-danger-fg/15 bg-danger-bg p-4 text-danger-fg",children:[e.jsxs("div",{className:"mb-2 flex items-center gap-2.5",children:[e.jsx(q,{name:"warning",stroke:1.5}),e.jsx("strong",{children:Be.cancelledTitle})]}),e.jsx("p",{className:"text-body leading-[1.6]",children:Be.cancelledBody})]}),e.jsx($t,{}),w]});const b=(t==null?void 0:t.step)==="cancelled"?[Be.cancelledTitle,null]:!t&&l?[Be.stalledTitle,Be.stalledBody]:(t==null?void 0:t.step)==="expired"?[Be.expiredTitle,Be.expiredBody]:(t==null?void 0:t.step)==="refused"?[Be.refusedTitle,Be.refusedBody]:null;if(b)return e.jsxs(St,{children:[e.jsx(ws,{login:s}),e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:qt,children:b[0]}),b[1]&&e.jsx("p",{className:"text-muted",children:b[1]})]}),S,e.jsx($t,{}),w]});if((t==null?void 0:t.step)==="compare"&&t.phoneConfirmed)return e.jsxs(St,{top:"pt-40",children:[e.jsx(ws,{login:s}),e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(Kn,{}),e.jsx("h1",{className:qt,children:Be.waitTitle}),e.jsxs("p",{className:"max-w-[300px] text-muted",children:[Dl(Be.waitBody(g,Ta))[0],e.jsx("span",{className:"font-mono text-fg",children:oo(t.code).join(" ")}),Dl(Be.waitBody(g,Ta))[1]]})]}),e.jsx($t,{}),e.jsx("button",{type:"button",onClick:c,className:dt,children:Be.cancel})]});if((t==null?void 0:t.step)==="compare"){const[R,v]=oo(t.code),[T,A]=Dl(Be.intro(Ta));return e.jsxs(St,{children:[e.jsx(ws,{login:s}),e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:qt,children:Be.title}),e.jsxs("p",{className:"text-muted",children:[T,e.jsx("strong",{className:"font-semibold text-fg",children:g}),A]})]}),e.jsxs("div",{className:"flex flex-col items-center gap-3 rounded-control border border-line bg-surface px-4 py-6",children:[e.jsxs("div",{"aria-label":Be.codeLabel(`${R} ${v}`),className:"flex justify-center gap-3.5 font-mono text-[2.5rem] leading-[48px] font-semibold tracking-[.06em]",children:[e.jsx("span",{children:R}),e.jsx("span",{children:v})]}),e.jsx("span",{className:"text-small text-muted",children:Be.basis})]}),S,e.jsx($t,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:o,className:bt,children:Be.same}),e.jsx("button",{type:"button",onClick:()=>{h(!0),c()},className:dt,children:Be.different})]})]})}const j=t&&e.jsx("button",{type:"button",onClick:c,className:dt,children:Be.cancel}),N=r==="pc_offline"?[Be.offlineTitle,Be.offlineBody(g)]:r==="relay_unreachable"?[Be.relayTitle,Be.relayBody]:null;return N?e.jsxs(St,{top:"pt-40",children:[e.jsx(ws,{login:s}),e.jsxs("div",{role:"status",className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:qt,children:N[0]}),e.jsx("p",{className:"text-muted",children:N[1]})]}),S,e.jsx($t,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:i,className:bt,children:Be.retryNow}),j]})]}):e.jsxs(St,{top:"pt-40",children:[e.jsx(ws,{login:s}),e.jsxs("div",{role:"status",className:"flex flex-col items-center gap-3.5 text-center text-muted",children:[e.jsx(Kn,{}),e.jsx("p",{children:Be.waitCode})]}),S,e.jsx($t,{}),j]})}const xt=d.recover,we=d.recover.no;function Zs(){var s,n;const t=qr(((s=globalThis.navigator)==null?void 0:s.userAgent)??"",((n=globalThis.navigator)==null?void 0:n.maxTouchPoints)??0);return t==="iPhone"||t==="iPad"?t:null}const uh=["key","shield","laptop"];function xh({login:t,platform:s,onPasskey:n,onCode:a}){const l=Zs();return e.jsxs(St,{children:[e.jsx(ws,{login:t}),e.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[e.jsx(hs,{size:72}),e.jsx("h1",{className:qt,children:xt.title(l)}),e.jsx("p",{className:"max-w-[320px] text-muted",children:xt.lead})]}),s&&e.jsx("ul",{className:"flex flex-col gap-3 text-body leading-5 text-fg/85",children:xt.notes(Zs()).map((r,i)=>e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx(q,{name:uh[i],className:"size-5 text-muted"}),r]},i))}),e.jsx($t,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[s&&e.jsxs("button",{type:"button",onClick:n,className:bt,children:[e.jsx(q,{name:"face"}),xt.go]}),e.jsx("button",{type:"button",onClick:a,className:s?dt:bt,children:xt.code})]})]})}const mh={warn:"bg-attention/12 text-attention",bad:"bg-danger-bg text-danger-fg"};function ph({icon:t,tone:s}){return e.jsx("span",{"aria-hidden":"true",className:`inline-flex size-12 flex-none items-center justify-center rounded-full ${mh[s]}`,children:e.jsx(q,{name:t,className:"size-6"})})}function cs({login:t,icon:s,tone:n,title:a,body:l,centred:r=!1,children:i,actions:o}){return e.jsxs(St,{children:[e.jsx(ws,{login:t}),e.jsxs("div",{role:"alert",className:`flex flex-col gap-3 ${r?"items-center text-center":"items-start"}`,children:[e.jsx(ph,{icon:s,tone:n}),e.jsx("h1",{className:qt,children:a}),e.jsx("p",{className:"text-muted",children:l})]}),i&&e.jsx("div",{className:"flex flex-col gap-2.5 text-body leading-[1.5] text-muted",children:i}),e.jsx($t,{}),e.jsx("div",{className:"flex flex-col gap-3",children:o})]})}const un=({lead:t,children:s})=>e.jsxs("p",{children:[t&&e.jsx("strong",{className:"font-semibold text-fg",children:t}),t&&" ",s]}),fh=t=>{if(!t)return null;const s=new Date(t);return Number.isNaN(s.getTime())?null:s.toLocaleDateString(st,{day:"numeric",month:"short"})};function hh({state:t,login:s,reach:n,onRetry:a,onCode:l,onCancel:r,onSignOut:i,onDone:o,actions:c}){const x=Zs(),u=(h=!0)=>e.jsx("button",{type:"button",onClick:l,className:h?bt:dt,children:xt.code},"code"),m=(h=!1)=>e.jsx("button",{type:"button",onClick:a,className:h?bt:dt,children:xt.retry},"retry");if(t.step==="reaching"||t.step==="faceid"||t.step==="checking"){const h=(t.step==="reaching"?null:t.pcName)??d.yourPc,g=[[t.step==="reaching"?xt.checking.reaching(h):xt.checking.reached(h),t.step==="reaching"?"on":"done"],[At()?xt.checking.faceId:xt.checking.check,t.step==="faceid"?"on":t.step==="checking"?"done":"next"],[xt.checking.verifying(h),t.step==="checking"?"on":"next"]];return e.jsxs(St,{top:"pt-40",children:[e.jsx(ws,{login:s}),e.jsxs("div",{role:"status",className:"flex flex-col items-center gap-3 text-center",children:[e.jsx(Kn,{}),e.jsx("h1",{className:qt,children:xt.checking.title}),e.jsx("p",{className:"max-w-[320px] text-muted",children:xt.checking.body(h)})]}),e.jsx("ol",{className:"flex flex-col gap-2.5 rounded-[10px] border border-line px-4 py-3.5 text-body",children:g.map(([y,w])=>e.jsxs("li",{className:`flex items-center gap-2.5 ${w==="on"?"font-medium text-fg":"text-muted"}`,children:[w==="done"?e.jsx(q,{name:"check",className:"size-[18px] text-ok"}):w==="on"?e.jsx(Kn,{size:"size-[18px]"}):e.jsx("span",{className:"size-[18px]","aria-hidden":"true"}),y]},y))}),e.jsx($t,{}),e.jsx("button",{type:"button",onClick:r,className:dt,children:xt.cancel})]})}if(t.step==="done"){const h=t.pc.name??d.yourPc;return e.jsxs(St,{top:"pt-14",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[e.jsx(hs,{size:88}),e.jsx("h1",{className:qt,children:xt.done.title(x,h)}),e.jsx("p",{className:"max-w-[320px] text-muted",children:xt.done.body(h)})]}),e.jsxs("p",{role:"status",className:"flex items-center gap-2 self-center text-small text-ok",children:[e.jsx(q,{name:"check",className:"size-4"}),xt.done.told(h)]}),e.jsx($t,{}),c??e.jsx("a",{href:ne({name:"atoi"}),onClick:o,className:bt,children:d.compare.seePending})]})}if(t.step==="cancelled")return null;const p=t.pcName??d.yourPc;switch(t.why){case"none":return e.jsx(cs,{login:s,icon:"key",tone:"warn",title:we.none.title,body:we.none.body(p),actions:[m(!0),u(!1)],children:e.jsx(un,{lead:we.none.hintTitle,children:we.none.hint})});case"revoked":return e.jsx(cs,{login:s,icon:"unlink",tone:"bad",title:we.revoked.title(x),body:we.revoked.body(p,fh(t.revokedAt)),actions:[u()],children:e.jsx("p",{children:we.revoked.hint})});case"old":return e.jsx(cs,{login:s,icon:"key",tone:"warn",title:we.old.title,body:we.old.body,actions:[u()],children:e.jsx(un,{lead:we.old.hintTitle,children:we.old.hint(x)})});case"offline":{const[h,g]=n==="relay_unreachable"?[d.compare.relayTitle,d.compare.relayBody]:[we.offline.title(p),we.offline.body(p)];return e.jsx(cs,{login:s,icon:"wifioff",tone:"warn",centred:!0,title:h,body:g,actions:[m(!0),e.jsx("button",{type:"button",onClick:r,className:dt,children:xt.cancel},"cancel")]})}case"otherPc":{const[h,g]=t.tags??["",""];return e.jsxs(cs,{login:s,icon:"shield",tone:"bad",title:we.otherPc.title(p),body:we.otherPc.body,actions:[u(),e.jsx("button",{type:"button",onClick:i,className:dt,children:we.otherPc.signOut},"out")],children:[e.jsxs("dl",{className:"grid grid-cols-[auto_1fr] gap-x-4 gap-y-2.5 rounded-control border border-line bg-surface p-4 text-body text-fg",children:[e.jsx("dt",{className:"text-muted",children:we.otherPc.inPasskey}),e.jsxs("dd",{className:"font-mono",children:[h," · ",we.otherPc.expected]}),e.jsx("dt",{className:"text-muted",children:we.otherPc.received}),e.jsxs("dd",{className:"font-mono text-danger-fg",children:[g," · ",we.otherPc.unknown]})]}),e.jsx(un,{lead:we.otherPc.reinstalledTitle,children:we.otherPc.reinstalledBody}),e.jsx(un,{lead:we.otherPc.otherwise,children:we.otherPc.warning})]})}case"connected":return e.jsxs(cs,{login:s,icon:t.device==="iPhone"?"phone":"tablet",tone:"warn",title:we.connected.title(t.device),body:we.connected.body(p),actions:[u(),m()],children:[e.jsx(un,{lead:we.connected.otherTitle(t.device),children:we.connected.other}),e.jsx(un,{lead:we.connected.reinstalledTitle(t.device),children:we.connected.reinstalled(t.device)})]});case"rate":{const h=t.retryInMs!==void 0?Math.max(1,Math.ceil(t.retryInMs/6e4)):null;return e.jsx(cs,{login:s,icon:"clock",tone:"warn",title:we.rate.title,body:we.rate.body(p,h),actions:[u(),...h!==null?[e.jsx("button",{type:"button",disabled:!0,className:dt,children:we.rate.retryIn(h)},"wait")]:[]]})}case"blocked":return e.jsx(cs,{login:s,icon:"lock",tone:"bad",title:we.blocked.title(p),body:we.blocked.body(p),actions:[u()],children:e.jsxs("p",{children:[we.blocked.hintBefore(p),e.jsx("strong",{className:"font-semibold text-fg",children:we.blocked.unblock}),we.blocked.hintAfter]})});case"timeout":return e.jsx(cs,{login:s,icon:"clock",tone:"warn",centred:!0,title:we.timeout.title(p),body:we.timeout.body,actions:[m(!0),u(!1)]});case"unsaved":return e.jsx(cs,{login:s,icon:x==="iPad"?"tablet":"phone",tone:"warn",centred:!0,title:we.unsaved.title,body:we.unsaved.body(p,x),actions:[m(!0),u(!1)]})}}const Ss=d.enroll;function ul(t,s="protect"){var R,v,T,A;const n=me(t),a=Ds(),l=(R=n.device)==null?void 0:R.confirm,r=a&&(s==="protect"?l===!1:l===!0&&!((v=n.device)!=null&&v.recover)),[i,o]=f.useState(null),[c,x]=f.useState(null),[u,m]=f.useState(!1),[p,h]=f.useState(null),[g,y]=f.useState(0),w=p?(T=n.ops[p])==null?void 0:T.phase:void 0,S=(s==="protect"?l===!0:((A=n.device)==null?void 0:A.recover)===!0)||w==="applied",b=w==="sending"||w==="uncertain",j=w==="rejected"||w==="failed";f.useEffect(()=>{if(!r||S)return;let E=!0;o(null);const P=t.pcKey();return Promise.all([t.prepareConfirm({purpose:"register"}),P?Mm(P):Promise.reject(new Error("unpaired"))]).then(([I,L])=>{E&&o({challenge:I,userId:L})},()=>{E&&x("prepareFailed")}),()=>{E=!1}},[t,r,S,g]);const N=()=>{var L,$;if(!i||u||b)return;const{challenge:E,userId:P}=i;m(!0),x(null);const I=qr(((L=globalThis.navigator)==null?void 0:L.userAgent)??"",(($=globalThis.navigator)==null?void 0:$.maxTouchPoints)??0);Am({challenge:E.challenge,rpId:E.rpId},{label:I,id:P}).then(O=>{if(m(!1),O==="cancelled"){x("cancelled");return}if(O==="unsupported"){x("unsupported");return}o(null);const U=t.registerCredential(O,Em(P));U===null?x("failed"):h(U)},()=>{m(!1),x("failed")})},C=()=>{x(null),h(null),y(E=>E+1)},M=c??(j?"failed":null);return{offered:r,registered:S,challenge:(i==null?void 0:i.challenge)??null,asking:u||b,problem:M,go:N,retry:C}}function zd({e:t,className:s,label:n=Ss.go}){const a=t.problem==="failed"||t.problem==="prepareFailed",l=t.problem==="cancelled"?d.confirm.cancelled:t.problem==="unsupported"?Ss.unsupported:t.problem==="failed"?d.confirm.failed:t.problem==="prepareFailed"?d.confirm.prepareFailed:null;return e.jsxs(e.Fragment,{children:[l&&e.jsx(Ge,{title:l,tone:"warning",role:"alert"}),a?e.jsx("button",{type:"button",onClick:t.retry,className:s,children:d.confirm.retry}):t.problem==="unsupported"?null:e.jsx("button",{type:"button",disabled:!t.challenge||t.asking,onClick:t.go,className:s,children:t.challenge||t.asking?n:d.confirm.preparing})]})}function gh({store:t}){const s=ul(t);return s.registered?e.jsx(co,{children:Ss.done}):s.offered?e.jsx(co,{children:e.jsx("div",{className:"flex flex-col items-end gap-2",children:e.jsx(zd,{e:s,className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 text-body font-medium disabled:opacity-45"})})}):null}function co({children:t}){return e.jsxs("div",{className:"flex items-baseline justify-between gap-4 border-b border-line px-4 py-3 last:border-b-0",children:[e.jsx("dt",{className:"flex-none text-muted",children:Ss.row}),e.jsx("dd",{className:"min-w-0 text-right break-words",children:t})]})}function bh({store:t,onDone:s,update:n=!1}){const a=ul(t),[l,r]=f.useState(!1);f.useEffect(()=>{a.offered&&r(!0)},[a.offered]);const i=ne({name:"atoi"});return l?a.registered?e.jsxs(e.Fragment,{children:[e.jsx(Ge,{title:Ss.done,role:"status"}),e.jsx("a",{href:i,onClick:s,className:bt,children:d.compare.seePending})]}):e.jsxs(e.Fragment,{children:[e.jsxs("section",{"aria-labelledby":"protect-title",className:"flex flex-col gap-3 rounded-control border border-line bg-surface p-4",children:[e.jsx("h2",{id:"protect-title",className:"text-title leading-[1.35] font-semibold",children:n?d.passkeyUpdate.title:Ss.title}),e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:n?d.passkeyUpdate.stepBody(Zs()):Ss.body}),e.jsx(zd,{e:a,className:bt,label:n?d.passkeyUpdate.go:Ss.go})]}),e.jsx("a",{href:i,onClick:s,className:dt,children:Ss.later})]}):e.jsx("a",{href:i,onClick:s,className:bt,children:d.compare.seePending})}const mt=d.passkeyUpdate,Pd="ledge.mobile.passkeyUpdateLater",jh=(t,s)=>{try{return!!s&&(t==null?void 0:t.getItem(Pd))===s}catch{return!1}};function yh({store:t,storage:s=globalThis.localStorage}){var m;const n=ul(t,"update"),a=(m=me(t).device)==null?void 0:m.id,[l,r]=f.useState(()=>jh(s,a)),[i,o]=f.useState(!1);if(f.useEffect(()=>{n.offered&&!l&&o(!0)},[n.offered,l]),!i)return null;if(n.registered)return e.jsxs("div",{role:"status",className:"flex items-start gap-3 rounded-card border border-line bg-surface p-4",children:[e.jsx(q,{name:"check",className:"size-5 text-ok"}),e.jsxs("span",{className:"flex flex-col gap-0.5",children:[e.jsx("strong",{className:"text-body font-semibold",children:mt.done}),e.jsx("small",{className:"text-small text-muted",children:mt.doneBody(Zs())})]})]});if(l)return null;const c=()=>{try{a&&(s==null||s.setItem(Pd,a))}catch{}r(!0),o(!1)},x=n.problem==="failed"||n.problem==="prepareFailed"||n.problem==="unsupported",u=n.problem==="cancelled"?mt.cancelled:x?mt.failed(t.pcName()??d.yourPc):null;return e.jsxs("section",{"aria-labelledby":"passkey-update-title",className:"flex flex-col gap-3 rounded-card border border-info/30 bg-info/[0.06] p-4",children:[e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{"aria-hidden":"true",className:"inline-flex size-9 items-center justify-center rounded-full bg-raised text-muted",children:e.jsx(q,{name:"key",className:"size-[18px]"})}),e.jsx("h2",{id:"passkey-update-title",className:"text-title leading-[1.35] font-semibold",children:mt.title})]}),u?e.jsx(Ge,{title:u,tone:n.problem==="cancelled"?"warning":"danger",role:"alert"}):e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:At()?mt.body(Zs()):mt.bodyOther(Zs())}),e.jsxs("div",{className:u?"grid grid-cols-2 gap-2":"flex flex-col gap-2",children:[u?e.jsx("button",{type:"button",onClick:x?n.retry:n.go,disabled:!x&&!n.challenge,className:bt,children:mt.retry}):e.jsx("button",{type:"button",onClick:n.go,disabled:!n.challenge||n.asking,className:bt,children:n.asking?e.jsxs(e.Fragment,{children:[e.jsx(Kn,{size:"size-4"}),mt.updating]}):n.challenge?mt.go:d.confirm.preparing}),e.jsx("button",{type:"button",onClick:c,disabled:n.asking,className:dt,children:mt.later})]})]})}const uo=t=>t.problem==="failed"||t.problem==="prepareFailed";function Nh({store:t}){const s=ul(t,"update"),n=me(t).device;return n!=null&&n.confirm?s.registered?e.jsxs("div",{className:"flex items-baseline justify-between gap-4 border-b border-line px-4 py-3 last:border-b-0",children:[e.jsx("dt",{className:"flex-none text-muted",children:mt.row}),e.jsx("dd",{className:"text-right text-ok",children:mt.ready})]}):s.offered?e.jsxs("div",{className:"flex flex-col gap-2 border-b border-line px-4 py-3 last:border-b-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("dt",{className:"flex min-w-0 flex-col",children:[e.jsx("span",{children:mt.row}),e.jsx("span",{className:"text-small text-muted",children:mt.rowHint})]}),e.jsx("dd",{className:"flex-none",children:e.jsx("button",{type:"button",disabled:s.asking||!uo(s)&&!s.challenge,onClick:uo(s)?s.retry:s.go,className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 text-body font-medium disabled:opacity-45",children:s.asking?mt.updating:mt.update})})]}),s.problem&&e.jsx(Ge,{title:s.problem==="cancelled"?mt.cancelled:mt.failed(t.pcName()??d.yourPc),tone:"warning",role:"alert"})]}):null:null}const nn={ok:"idle",run:"work",fail:"perm",wait:"ask",skip:"plain",none:"off"},Xn=t=>t.state!=="merged"&&t.state!=="closed",Bd=t=>(t.state==="open"||t.state==="review")&&t.mergeable&&(t.pipeline==="ok"||t.pipeline==="none");function kh(t){return{open:t.filter(Xn),closed:t.filter(s=>!Xn(s))}}const vh=t=>t.filter(s=>Xn(s)&&s.pipeline==="fail").length;function wh(t){const s=t.filter(Xn);return[...s.filter(n=>n.pipeline==="fail").map(n=>({pr:n,why:"fail"})),...s.filter(n=>n.pipeline!=="fail"&&Bd(n)).map(n=>({pr:n,why:"ready"}))]}const Sh=t=>t.filter(s=>s.status!=="ok"),qd=t=>t==="github"?"gh":"glab",$h=t=>`${qd(t.forge)} auth login --hostname ${t.host}`;function Hd(t){const s=new Map;for(const n of t){const a=s.get(n.column)??{column:n.column,name:n.columnName,jobs:[]};a.jobs.push(n),s.set(n.column,a)}return[...s.values()].sort((n,a)=>n.column-a.column)}const Ud=t=>t.find(s=>s.status==="fail")??null;function Wd(t){if(t===void 0)return null;const s=Math.round(t);return s<3600?{text:`${Math.floor(s/60)}:${String(s%60).padStart(2,"0")}`,hours:!1}:{text:`${Math.floor(s/3600)}:${String(Math.floor(s%3600/60)).padStart(2,"0")}`,hours:!0}}const Ch=t=>t.startsWith("…"),Mh=new Set(["draft","not_open","approvals","changes_requested","pipeline","pipeline_not_started"]);function xl(t){const{pr:s}=t,n=new Set(t.mergeBlockers),a=Math.max(1,s.approvals.required??0),l=[];n.has("draft")&&l.push({ok:!1,key:"draft"}),n.has("not_open")&&l.push({ok:!1,key:"not_open"}),n.has("approvals")&&l.push({ok:!1,key:"approvals",given:s.approvals.given,required:a}),n.has("changes_requested")&&l.push({ok:!1,key:"changes_requested",who:t.reviewers.filter(r=>r.state==="changes").map(r=>r.name).join(", ")}),n.has("pipeline_not_started")?l.push({ok:!1,key:"pipeline_not_started"}):n.has("pipeline")||s.pipeline!=="ok"&&s.pipeline!=="none"?l.push({ok:!1,key:s.pipeline==="run"?"pipeline_run":s.pipeline==="wait"?"pipeline_wait":s.pipeline==="skip"?"pipeline_skip":"pipeline_fail"}):l.push({ok:!0,key:s.pipeline==="none"?"noCi":"pipeline"});for(const r of n)Mh.has(r)||l.push({ok:!1,key:"raw",code:r});return n.has("approvals")||l.push({ok:!0,key:"approved",given:s.approvals.given,required:a}),n.has("changes_requested")||l.push({ok:!0,key:"noChanges"}),l}const Ah=t=>(t.pr.state==="open"||t.pr.state==="review")&&xl(t).every(s=>s.ok),Kd=t=>`${t.approvals.given}${t.approvals.required!==void 0?`/${t.approvals.required}`:""}`,hr=(t,s)=>{const n=t.replace(/\.$/,"");return s.key==="changes_requested"||s.key==="raw"?n:n.charAt(0).toLowerCase()+n.slice(1)},Eh=t=>t.pipeline==="fail"&&(t.state==="open"||t.state==="review"),Rh=t=>t.files.reduce((s,n)=>({added:s.added+n.added,removed:s.removed+n.removed}),{added:0,removed:0}),Th=(t,s)=>t.threads.filter(n=>n.file===s).length,oi=t=>t.slice(0,7);function _h(t,s){if(!t)return null;const n=t.prs.find(r=>Xn(r)&&r.sessions.includes(s));if(n)return{pr:n};const a=t.followed.find(r=>r.session===s);if(!a)return null;const l=t.forges.find(r=>r.forge===a.forge&&r.host===a.host);return l&&l.status!=="ok"?{unknown:l,kind:a.forge}:null}const xo=new Set(["starting","launching","booting"]);function ps(t){return xo.has(t.status)||xo.has(t.lifecycleState)?"starting":t.status==="partial"?"partial":t.status==="running"||t.running>0?t.nodes.some(n=>n.stopped)?"partial":"running":"stopped"}const Ih=t=>t!=="stopped",Vd=t=>t.rigs.find(s=>s.name===zn),mo={running:0,partial:0,starting:0,stopped:1},gr=t=>t.rigs.filter(s=>s.name!==zn).map((s,n)=>({r:s,i:n})).sort((s,n)=>mo[ps(s.r)]-mo[ps(n.r)]||s.i-n.i).map(s=>s.r),Gd=(t,s,n)=>{var a;for(const l of t)if(((a=l.rig)==null?void 0:a.name)===s&&l.rig.role===n&&l.state!=="exited")return l};function Xd(t,s,n){var r;let a=0,l=0;for(const i of s)((r=i.rig)==null?void 0:r.name)!==t||!i.pending||(i.pending.kind==="question"?l+=1:a+=1);for(const i of n??[])i.from.rig===t&&i.kind!=="update"&&(l+=1);return{perm:a,ask:l}}const ua=t=>t.activity==="running"||t.work>0;function Qd(t,s){if(s.perm)return"perm";if(s.ask)return"ask";const n=ps(t);return n==="stopped"?"off":n==="starting"||t.nodes.some(ua)?"work":"idle"}function ci(t){const{session:s,node:n,graph:a}=t;return t.rigStatus==="stopped"?"off":s?s.pending&&s.pending.kind!=="question"||s.state==="waiting_permission"||s.state==="error"?"perm":s.pending||s.state==="waiting_input"?"ask":s.state==="starting"?"starting":s.state==="working"?"work":"idle":n!=null&&n.stopped||(a==null?void 0:a.status)==="exited"||(a==null?void 0:a.status)==="stopped"?t.rigStatus==="starting"?"waiting":"off":t.rigStatus==="starting"&&!n?"waiting":n&&ua(n)?"work":a!=null&&a.attention||n!=null&&n.attention?"ask":"idle"}const Yd={perm:"perm",ask:"ask",work:"work",idle:"idle",off:"off",starting:"work",waiting:"off"},di=t=>t==="claude-code"||t==="claude"?"claude":t==="codex"?"codex":t==="cursor"?"cursor":t==="omp"?"omp":null,bs=(t,s)=>(s==null?void 0:s.split("@")[0])||t.replace(".","-");function Lh(t,s){const n=s.map(a=>({...a,seats:t.filter(l=>l.pod===a.id)}));for(const a of t)n.some(l=>l.id===a.pod)||n.push({id:a.pod,label:a.pod,seats:t.filter(l=>l.pod===a.pod)});return n.filter(a=>a.seats.length)}function Oh(t,s){const n=s.filter(i=>/delegat/.test(i.kind)),a=new Set(n.map(i=>i.from)),l=new Set(n.map(i=>i.to)),r=t.filter(i=>a.has(i.logicalId)&&!l.has(i.logicalId));return r.length===1?r[0].logicalId:null}const Dh=["auto","standard","open","yolo","locked","spec"],Zd=/^builtin:(auto|standard|open|yolo|locked)$/;function Fh(t){var s;switch(t.policySource){case"member_policy":return((s=Zd.exec(t.policy??""))==null?void 0:s[1])??null;case"rig_policy":case"team_default":case"kernel_default":case"floor":return"spec";default:return null}}function Jd(t){if(t.length===0)return null;const s=t.map(Fh),n=s[0];return n&&s.every(a=>a===n)?n:"mixed"}const zh=t=>{var s;return((s=Zd.exec(t??""))==null?void 0:s[1])??null},eu=t=>[...Jx(t.nodes)].map(([s,n])=>({role:s,count:n.length,ids:n}));function Ph(t,s){return s!=null&&s.some(n=>n.id===t.id)?"mine":t.state==="in-progress"?"progress":t.state==="blocked"?"blocked":"pending"}const Bh=t=>t==="done"?"done":t==="handed-off"?"handed":"stopped";function qh(t){const s=t.trim(),n=/^handed[ _-]?off(?: to)? (.+)$/i.exec(s);if(n)return{verb:"handed",to:n[1].split("@")[0]};const a=/^blocked(?: on)? (.+)$/i.exec(s);if(a)return{verb:"blocked",on:a[1]};const l=s.toLowerCase();return l==="claimed"?{verb:"claimed"}:l==="completed"||l==="done"?{verb:"completed"}:l==="canceled"||l==="cancelled"?{verb:"canceled"}:l==="resumed"||l==="unblocked"?{verb:"resumed"}:l==="failed"?{verb:"failed"}:{verb:"other",text:s}}function Va(t){const s=/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}(:\d{2})?$/.test(t)?`${t.replace(" ","T")}Z`:t,n=new Date(s);return Number.isNaN(n.getTime())?null:n}function ui(t,s){const n=a=>new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime();return Math.round((n(s)-n(t))/864e5)}const tu=t=>t.startsWith("operator."),su=t=>tu(t.logicalId)?"Max":bs(t.logicalId,t.session),nu={running:"on",starting:"go",partial:"part",stopped:"plain"},Hh=t=>t.daemon.state==="stopped"||t.daemon.state==="stale";function Uh(t){return t.rig?t.rig:t.seat?t.seat.split("@")[1]??null:null}function Wh(t){return t.kind==="seats"?t.rig??null:t.kind==="act"&&t.action?Uh(t.action):null}const au=t=>[...t].sort((s,n)=>{var a,l;return(((a=Va(n.createdAt))==null?void 0:a.getTime())??0)-(((l=Va(s.createdAt))==null?void 0:l.getTime())??0)});function Kh(t,s){const n=[];for(const a of s){if(a.from!==t&&a.to!==t)continue;const l=a.from===t?a.to:a.from;/delegat/.test(a.kind)?n.push({kind:a.to===t?"delegatesTo":"delegates",who:l}):/collaborat/.test(a.kind)?n.some(r=>r.kind==="collaborates"&&r.who===l)||n.push({kind:"collaborates",who:l}):/escalat/.test(a.kind)&&a.from===t?n.push({kind:"escalates",who:l}):n.push({kind:"linked",who:l,label:a.kind})}return n}const Vh=t=>t.nodes.filter(s=>!s.stopped&&ua(s)).map(s=>bs(s.logicalId,s.session)),Gh='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function lu(t,s){const n=f.useRef(s);n.current=s,f.useEffect(()=>{const a=t.current;if(!a)return;const l=document.activeElement instanceof HTMLElement?document.activeElement:null;a.focus({preventScroll:!0});const r=i=>{if(i.key==="Escape"){i.preventDefault(),n.current();return}if(i.key!=="Tab")return;const o=[...a.querySelectorAll(Gh)],c=o[0],x=o.at(-1);if(!c||!x){i.preventDefault();return}i.shiftKey&&(document.activeElement===c||document.activeElement===a)?(i.preventDefault(),x.focus()):!i.shiftKey&&document.activeElement===x&&(i.preventDefault(),c.focus())};return document.addEventListener("keydown",r),()=>{document.removeEventListener("keydown",r),l!=null&&l.isConnected&&l.focus({preventScroll:!0})}},[t])}function ct({labelledBy:t,onClose:s,children:n}){const a=f.useRef(null);return lu(a,s),Qr.createPortal(e.jsxs("div",{className:"fixed inset-0 z-20",children:[e.jsx("div",{className:"absolute inset-0 bg-black/50","aria-hidden":"true",onClick:s}),e.jsxs("section",{ref:a,role:"dialog","aria-modal":"true","aria-labelledby":t,tabIndex:-1,className:"absolute inset-x-0 bottom-0 mx-auto flex max-w-[480px] flex-col gap-4 rounded-t-[28px] border-t border-line bg-surface px-5 pt-3 pb-[calc(34px+env(safe-area-inset-bottom))] shadow-[var(--shadow-overlay)] outline-none tablet:inset-x-auto tablet:bottom-auto tablet:top-1/2 tablet:left-1/2 tablet:max-h-[calc(100dvh-48px)] tablet:w-[480px] tablet:-translate-x-1/2 tablet:-translate-y-1/2 tablet:overflow-y-auto tablet:rounded-[24px] tablet:border tablet:px-6 tablet:pt-6 tablet:pb-6",children:[e.jsx("span",{className:"h-[5px] w-9 self-center rounded-full bg-muted/40 tablet:hidden","aria-hidden":"true"}),n]})]}),document.body)}function ml({on:t,label:s,disabled:n,onChange:a,describedBy:l}){return e.jsx("button",{type:"button",role:"switch","aria-checked":t,"aria-label":s,disabled:n,"aria-describedby":l,onClick:()=>a(!t),className:`relative h-6 w-10 flex-none rounded-full border border-line transition-colors disabled:opacity-45 ${t?"border-transparent bg-ok":"bg-raised"}`,children:e.jsx("span",{className:`absolute top-0.5 h-4.5 w-4.5 rounded-full bg-white shadow-sm transition-all ${t?"left-[18px]":"left-0.5"}`,"aria-hidden":"true"})})}const Xh={on:"border-ok/40 text-ok",go:"border-info/40 text-info",part:"border-attention/45 text-attention",bad:"border-approval/45 text-approval",plain:"border-input text-muted"};function kn({tone:t,children:s,flat:n=!1}){return e.jsxs("span",{"data-chip":t,className:`inline-flex h-[22px] flex-none items-center gap-1.5 rounded-full border px-[9px] text-[12px] font-medium whitespace-nowrap ${Xh[t]}`,children:[!n&&e.jsx("span",{"aria-hidden":"true",className:"size-1.5 rounded-full bg-current"}),s]})}function Qn({perm:t=!1,ok:s=!1,children:n}){const a=t?"bg-approval/12 text-approval":s?"bg-ok/12 text-ok":"bg-attention/12 text-attention";return e.jsx("span",{"data-att":t?"perm":s?"ok":"ask",className:`inline-flex h-[22px] items-center rounded-md px-2 text-[12px] whitespace-nowrap ${a}`,children:n})}function Ft({children:t,aside:s,id:n}){return e.jsxs("h2",{id:n,className:"flex flex-none items-center gap-2 text-[11px] font-medium tracking-[.4px] text-muted uppercase",children:[e.jsx("span",{children:t}),s!==void 0&&e.jsx("span",{className:"ml-auto text-[12px] font-normal tracking-normal normal-case",children:s})]})}function Ve({tone:t,label:s,children:n,className:a=""}){return e.jsx("section",{"aria-label":s,className:`flex-none overflow-hidden rounded-[10px] border bg-surface dark:bg-transparent ${t==="rigs"?"border-task/45":"border-line"} ${a}`,children:n})}function br({lead:t,name:s,chip:n,sub:a,att:l,href:r,dim:i=!1,selected:o=!1,label:c}){const x=e.jsxs(e.Fragment,{children:[t,e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-[3px]",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("b",{className:`truncate text-[14.5px] font-semibold ${i?"text-muted":""}`,children:s}),n]}),a&&e.jsx("small",{className:"text-[12px] text-muted",children:a}),l&&e.jsx("span",{className:"flex flex-wrap gap-1.5",children:l})]}),r&&e.jsx(q,{name:"chevron",className:"size-4 text-muted"})]}),u=`flex min-h-[60px] items-center gap-2.5 border-b border-line px-3 py-2 last:border-b-0 ${o?"bg-secondary":""}`;return r?e.jsx("a",{href:r,"aria-label":c,"aria-current":o?"page":void 0,className:u,children:x}):e.jsx("div",{className:u,children:x})}function Fl({label:t,value:s,onOpen:n}){const a=e.jsxs(e.Fragment,{children:[e.jsx("small",{className:"text-[11.5px] text-muted",children:t}),e.jsx("b",{className:"truncate text-[17px] font-semibold",children:s})]}),l="relative flex min-w-0 flex-col gap-px rounded-[10px] border border-line bg-surface px-2.5 py-2 text-left";return n?e.jsxs("button",{type:"button",onClick:n,className:l,children:[a,e.jsx("span",{"aria-hidden":"true",className:"absolute top-[7px] right-[9px] text-muted",children:"›"})]}):e.jsx("div",{className:l,children:a})}function Gt({lead:t,warn:s=!1,danger:n=!1,children:a,action:l,role:r,compact:i=!1}){return e.jsxs("div",{role:r,className:`strip flex flex-none gap-[9px] rounded-lg border text-[13px] leading-[18px] ${i?"items-center px-2.5 py-2":"items-start px-3 py-2.5"} ${n?"border-approval/45":s?"border-attention/40":"border-line"}`,children:[t,e.jsx("div",{className:`flex min-w-0 flex-1 flex-col ${i?"":"gap-2"}`,children:a}),l]})}function ve({mark:t,title:s,sub:n,children:a,onClose:l,closeLabel:r}){const i={ok:"✓",bad:"✕",warn:"!",ask:"?"}[t],o={ok:"text-ok",bad:"text-approval",warn:"text-attention",ask:"text-attention"}[t];return e.jsxs("div",{role:t==="ok"?"status":"alert","data-receipt":t,className:`flex min-h-12 items-center gap-2.5 rounded-lg border bg-surface px-3 py-2 text-[13px] leading-[18px] ${t==="bad"?"border-destructive/45":"border-line"}`,children:[e.jsx("span",{"aria-hidden":"true",className:o,children:i}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("b",{className:"font-semibold",children:s}),n!==void 0&&e.jsx("small",{className:"block text-[12px] text-muted [overflow-wrap:anywhere]",children:n}),a]}),l&&r&&e.jsx("button",{type:"button",onClick:l,"aria-label":r,title:r,className:"grid size-9 flex-none place-items-center rounded-lg text-muted active:bg-raised",children:e.jsx(q,{name:"close",className:"size-4"})})]})}function Gs({commands:t}){return t.length?e.jsx("code",{className:"mt-1.5 block rounded-md bg-raised px-2 py-1.5 font-mono text-[12px] break-all whitespace-pre-wrap text-muted",children:t.join(`
12
+ `)}):null}function xi({title:t,body:s}){return e.jsxs("div",{className:"flex items-start gap-2 rounded-lg border border-destructive/40 bg-danger-bg/70 px-2.5 py-[9px] text-[13px] leading-[18px]",children:[e.jsx(q,{name:"warning",className:"mt-px size-4 text-approval"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("b",{className:"block font-semibold",children:t}),s!==void 0&&e.jsx("span",{className:"text-muted",children:s})]})]})}const An=({className:t="text-info"})=>e.jsx("span",{"aria-hidden":"true",className:`inline-block size-[13px] flex-none animate-spin rounded-full border-[1.6px] border-current border-r-transparent ${t}`});function Yn({children:t,bar:s=!1}){return e.jsxs("div",{role:"status",className:`flex flex-none items-center gap-2.5 px-3 py-2.5 text-[12.5px] text-muted ${s?"bleed border-t border-line bg-sidebar":"rounded-lg border border-line"}`,children:[e.jsx(An,{}),e.jsx("span",{className:"min-w-0 flex-1",children:t})]})}function _a({label:t,options:s,value:n,onChange:a,disabled:l=!1}){return e.jsx("div",{role:"group","aria-label":t,className:"inline-flex flex-none self-start overflow-hidden rounded-lg border border-input",children:s.map(r=>e.jsx("button",{type:"button",disabled:l,"aria-pressed":r.value===n,onClick:()=>a(r.value),className:"h-9 px-3.5 text-[13px] font-medium text-muted aria-pressed:bg-raised aria-pressed:text-fg disabled:opacity-45",children:r.label},r.value))})}function jr({pressed:t,title:s,sub:n,onClick:a,disabled:l=!1}){return e.jsxs("button",{type:"button","aria-pressed":t,disabled:l,onClick:a,className:"flex flex-col gap-0.5 rounded-lg border border-input px-[11px] py-[9px] text-left text-[13.5px] font-medium aria-pressed:border-ring aria-pressed:bg-secondary aria-pressed:shadow-[inset_0_0_0_1px_var(--color-ring)] disabled:opacity-45",children:[e.jsx("span",{children:s}),n&&e.jsx("small",{className:"text-[11.5px] font-normal text-muted",children:n})]})}function po({on:t,label:s,onChange:n,disabled:a=!1}){return e.jsxs("label",{className:`flex min-h-12 items-center gap-3 border-b border-line px-3 py-1.5 text-[13.5px] last:border-b-0 ${a?"opacity-45":""}`,children:[e.jsx("input",{type:"checkbox",checked:t,disabled:a,onChange:l=>n(l.target.checked),className:"peer sr-only"}),e.jsx("span",{"aria-hidden":"true",className:`grid size-[18px] flex-none place-items-center rounded-[5px] border-[1.5px] text-[12px] peer-focus-visible:outline-2 peer-focus-visible:outline-info ${t?"border-primary bg-primary text-primary-fg":"border-input"}`,children:t?"✓":""}),e.jsx("span",{className:"min-w-0 flex-1",children:s})]})}function fo({on:t,label:s,hint:n,onChange:a,disabled:l=!1}){const r=f.useId();return e.jsxs("div",{className:"flex min-h-12 items-center gap-3 border-b border-line px-3 py-1.5 text-[13.5px] last:border-b-0",children:[e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{children:s}),n&&e.jsx("small",{id:r,className:"text-[12px] text-muted",children:n})]}),e.jsx(ml,{on:t,label:s,onChange:a,...l?{disabled:l}:{},...n?{describedBy:r}:{}})]})}function Qh({value:t,changed:s,min:n=0,max:a=9,fewer:l,more:r,onChange:i,disabled:o=!1}){const c="h-9 w-10 text-[17px] text-fg disabled:opacity-35";return e.jsxs("span",{className:`inline-flex flex-none items-center overflow-hidden rounded-lg border ${s?"border-ring":"border-input"}`,children:[e.jsx("button",{type:"button","aria-label":l,title:l,disabled:o||t<=n,onClick:()=>i(t-1),className:c,children:"−"}),e.jsx("span",{"aria-live":"polite",className:"min-w-[30px] text-center font-mono text-[14px]",children:t}),e.jsx("button",{type:"button","aria-label":r,title:r,disabled:o||t>=a,onClick:()=>i(t+1),className:c,children:"+"})]})}function os({title:t,onClose:s,children:n,busy:a=!1}){const l=f.useId();return e.jsxs(ct,{labelledBy:l,onClose:()=>{a||s()},children:[e.jsx("h2",{id:l,className:"text-[17px] leading-6 font-semibold",children:t}),n]})}function ge({tone:t="outline",size:s="md",className:n=""}={}){const a=Oe({variant:t==="primary"?"primary":"outline",size:s,className:n});return t==="danger"?`${a} !border-approval/50 !text-approval`:t==="dangerfill"?`${a} !border-transparent !bg-destructive !text-primary-fg dark:!bg-primary`:a}function Dt({icon:t,children:s,size:n="size-4"}){return e.jsxs(e.Fragment,{children:[e.jsx(q,{name:t,className:n}),s]})}function Os({children:t,retry:s,retryLabel:n}){return e.jsxs("div",{role:s?"alert":void 0,className:"flex items-center gap-2.5 px-3 py-2.5 text-[13px] text-muted",children:[s&&e.jsx(q,{name:"warning",className:"size-4 flex-none text-attention"}),e.jsx("span",{className:"min-w-0 flex-1",children:t}),s&&n&&e.jsx("button",{type:"button",onClick:s,className:ge({size:"xs"}),children:n})]})}function Yh(t,s=500){const n=f.useRef(null),a=f.useRef(!1),l=()=>{n.current&&clearTimeout(n.current),n.current=null};return t?{onPointerDown:r=>{r.pointerType!=="mouse"&&(a.current=!1,l(),n.current=setTimeout(()=>{a.current=!0,t()},s))},onPointerUp:l,onPointerLeave:l,onPointerCancel:l,onContextMenu:r=>{r.preventDefault();const i=!!n.current;l(),a.current||t(),i&&(a.current=!0)},swallow:()=>{const r=a.current;return a.current=!1,r}}:{}}const Kt=d.prs,Zh={ok:"on",run:"go",fail:"bad",wait:"part",skip:"plain",none:"plain"};function ru({pipeline:t,short:s=!1}){return e.jsx(kn,{tone:Zh[t],flat:t==="none",children:s?Kt.pipe[t]:Kt.pipeline[t]})}const pl=t=>t.split("/").at(-1)??t,Jt=t=>({host:Kt.host[t.forge],cli:qd(t.forge),kind:Kt.kind[t.forge]}),iu=(t,s)=>t.sessions.map(n=>s.get(n)).filter(n=>!!n);function Jh(t,s=new Date){const n=new Date(t),a=ui(n,s);return a<=0?Pe(t):a===1?Kt.yesterday:a<7?n.toLocaleDateString(st,{weekday:"long"}):n.toLocaleDateString(st,{day:"numeric",month:"short"})}function yr(t,s=new Date){const n=new Date(t),a=Pe(t),l=ui(n,s);return l<=0?Kt.today(a):l===1?Kt.yesterdayAt(a):`${n.toLocaleDateString(st,l<7?{weekday:"long"}:{day:"numeric",month:"short"})} ${a}`}function Bn(t,s){if(t.ok)return t.key==="approved"?Kt.ok.approved(t.given,t.required):Kt.ok[t.key];switch(t.key){case"draft":return Kt.blocker.draft(s);case"approvals":return Kt.blocker.approvals(t.given,t.required);case"changes_requested":return Kt.blocker.changes_requested(t.who);case"raw":return t.code;default:return Kt.blocker[t.key]}}function ho({pr:t,sub:s,chips:n,pills:a,href:l,dim:r=!1,selected:i=!1}){const o=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mt-1.5 self-start",children:e.jsx(_e,{state:r?"done":nn[t.pipeline],pulse:!r&&t.pipeline==="run"})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-[3px]",children:[e.jsxs("span",{className:`truncate text-[14px] ${r?"text-muted":""}`,children:[e.jsx("b",{className:"mr-1 font-mono text-[13px] font-semibold",children:t.ref}),t.title]}),a&&e.jsx("span",{className:"flex flex-wrap gap-1",children:a}),e.jsx("small",{className:"truncate text-[12px] text-muted",children:s}),n&&e.jsx("span",{className:"flex flex-wrap gap-1.5",children:n})]}),l&&e.jsx(q,{name:"chevron",className:"size-4 text-muted"})]}),c=`flex min-h-[60px] items-center gap-2.5 border-b border-line px-3 py-2 last:border-b-0 ${i?"bg-secondary":""}`;return l?e.jsx("a",{href:l,"data-pr":t.id,"aria-current":i?"page":void 0,className:c,children:o}):e.jsx("div",{"data-pr":t.id,className:c,children:o})}const as=d.prs,eg=()=>()=>{},go=()=>null;function ou(t){return f.useSyncExternalStore(t?t.subscribe:eg,t?t.getState:go,t?t.getState:go)}function tg(t,s,n,a){const l=s==="fail"?as.pipeline.fail:t.pipeline==="none"?as.atoi.readyNoCi:as.atoi.ready;return a!==null?[as.host[t.forge],l,as.asOf(Pe(a))].join(" · "):[as.host[t.forge],pl(t.repo),l,...s==="fail"&&n?[n]:[]].join(" · ")}function sg({forge:t,mobile:s}){var i;const n=ou(t);if(!((i=s.daemon)!=null&&i.forge)||!(n!=null&&n.state))return null;const a=wh(n.state.prs);if(a.length===0)return null;const l=!s.fresh,r=o=>{var x;const c=o.sessions[0];return c?((x=s.sessions.get(c))==null?void 0:x.name)??null:null};return e.jsxs(e.Fragment,{children:[e.jsxs("h2",{className:"mt-1 flex items-center gap-2 text-[13px] font-semibold",children:[e.jsx(q,{name:"pr",className:"size-3.5"}),as.atoi.title,e.jsx("span",{className:"min-w-0 truncate font-normal text-muted",children:as.atoi.sub})]}),e.jsx(rs,{label:as.atoi.title,children:a.map(({pr:o,why:c})=>e.jsx(Ys,{href:ne({name:"pr",id:o.id}),stale:l,lead:e.jsx(_e,{state:nn[o.pipeline]}),title:e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:o.ref})," ",o.title]}),sub:tg(o,c,r(o),l?n.at:null),children:e.jsx(q,{name:"chevron",className:"size-4 text-muted"})},o.id))})]})}function ng({forge:t,mobile:s,session:n}){var i;const a=ou(t);if(!((i=s.daemon)!=null&&i.forge))return null;const l=_h((a==null?void 0:a.state)??null,n.id);if(!l)return null;if("pr"in l)return e.jsxs("a",{href:ne({name:"pr",id:l.pr.id}),"data-pr-chip":l.pr.id,className:"inline-flex h-8 flex-none items-center gap-[5px] font-mono text-[11px]",children:[e.jsx(_e,{state:nn[l.pr.pipeline],pulse:l.pr.pipeline==="run"}),l.pr.ref]});const r=Jt({forge:l.kind});return e.jsx(lg,{tip:as.chipTip(r.host,s.daemon.name,r.kind),label:as.chipUnknown(r.kind)})}const ag=4e3;function lg({tip:t,label:s}){const n=f.useRef(null),[a,l]=f.useState(null);f.useEffect(()=>{if(!a)return;const i=setTimeout(()=>l(null),ag),o=c=>{var x;(x=n.current)!=null&&x.contains(c.target)||l(null)};return document.addEventListener("pointerdown",o,!0),()=>{clearTimeout(i),document.removeEventListener("pointerdown",o,!0)}},[a]);const r=()=>{var x,u;if(a){l(null);return}const i=(x=n.current)==null?void 0:x.closest("footer"),o=(u=(i==null?void 0:i.previousElementSibling)??i)==null?void 0:u.getBoundingClientRect(),c=globalThis.innerHeight??0;l({bottom:o?Math.max(c-o.top+8,8):96})};return e.jsxs(e.Fragment,{children:[e.jsx("button",{ref:n,type:"button","aria-label":t,title:t,onClick:r,"data-pr-chip":"unknown",className:"flex-none rounded-md border border-dashed border-input px-[5px] font-mono text-[11px] text-muted",children:s}),a&&e.jsx("span",{role:"status","data-chip-toast":"",style:a,className:"fixed inset-x-3.5 z-[7] flex items-center gap-2.5 rounded-[10px] border border-line bg-surface px-3 py-2.5 text-[13px] leading-[18px] whitespace-normal text-fg shadow-[0_8px_24px_#0005]",children:t})]})}function rg(t){const s=[...t].reverse().find(n=>n.point);return s!=null&&s.point?{qid:s.qid,eventId:s.point.items.reduce((n,a)=>Math.max(n,a.event),0)}:null}const ig=["atoi","done","ongoing","rigs"],og={perm:"bg-approval",ask:"bg-attention",work:"bg-info",idle:"bg-ok",off:"bg-muted/70"},cu="grid grid-cols-[12px_minmax(0,1fr)] gap-x-2 gap-y-0.5 border-t border-dashed border-line py-1.5 first:border-t-0",bo="border-approval/45 text-approval",cg=t=>t.replace(/\*\*/g,""),qn=t=>new Date(t).toLocaleTimeString(st,{hour:"2-digit",minute:"2-digit",hourCycle:"h23"});function jo(t){var a,l;const s=t.vars??{},n=d.chat.action;return((l=(a=d.chat.operator.suggest)[t.action])==null?void 0:l.call(a,s))??n.verb(t.action,s)??n.verbs[t.action]??n.apply}function du({tone:t,faded:s}){return e.jsx("span",{"aria-hidden":"true",className:`mt-[7px] size-2 rounded-full ${og[t]} ${s?"opacity-50":""}`})}function dg(t){const s=d.chat.operator,n=t.turn.point,a="rounded-card border border-[color-mix(in_srgb,var(--sidebar-primary)_40%,var(--border))] bg-surface px-3 py-2.5 text-body";if(n.foldedAt){const l=s.folded(qn(n.foldedAt));return e.jsx("article",{"data-point":!0,"data-point-folded":!0,"aria-label":l,className:`${a} text-muted`,children:l})}return e.jsxs("article",{"data-point":!0,"aria-label":`${s.title} · ${qn(t.turn.askedAt)}`,className:a,children:[e.jsxs("div",{className:"mb-1 flex items-center gap-1.5 text-small text-muted",children:[e.jsx("b",{className:"font-semibold text-fg",children:s.title}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono",children:qn(t.turn.askedAt)})]}),e.jsx("div",{children:ig.map(l=>{const r=n.items.filter(i=>i.group===l);return r.length?l==="ongoing"?e.jsxs("div",{"data-point-group":l,className:cu,children:[e.jsx(du,{tone:"work"}),e.jsx("span",{className:"min-w-0",children:s.ongoing(r.length)})]},l):r.map(i=>e.jsx(ug,{item:i,...t},i.id)):null})})]})}function ug(t){var y,w;const s=d.chat.operator,n=d.chat.action,{item:a}=t,[l,r]=f.useState(!1),[i,o]=f.useState(""),c=!!t.disabled||t.busy!==null&&t.busy!==void 0,x=t.busy===a.id,u=a.group==="atoi",m=((y=a.ref)==null?void 0:y.kind)==="session.request"&&a.tone==="perm",p=a.suggestion,h=()=>{const S=i.trim();S&&(t.onAnswer(a.id,{text:S}),r(!1),o(""))},g=()=>{if(a.settled)return null;const S=[];for(const b of a.answers??[])S.push(e.jsx("button",{type:"button",disabled:c,onClick:()=>t.onAnswer(a.id,{id:b.id}),className:Oe({variant:b.style==="primary"?"primary":"outline",size:"xs",className:b.style==="danger"?bo:""}),children:b.label},`a-${b.id}`));if(a.freeText&&S.push(e.jsx("button",{type:"button",disabled:c,"aria-expanded":l,onClick:()=>r(b=>!b),className:Oe({variant:"ghost",className:"h-8 px-2.5"}),children:s.reply},"reply")),p&&p.state!=="done"){const b=p.state==="running"||x;S.push(e.jsx("button",{type:"button",disabled:c||b,onClick:()=>t.onSuggestion(a.id),className:Oe({size:"xs",className:p.risk==="destructive"?bo:""}),children:b?n.running:jo(p)},"suggest"))}return S.length?e.jsx("div",{"data-point-acts":!0,className:"col-start-2 mt-1 flex flex-wrap gap-1.5",children:S}):null};return e.jsxs("div",{"data-point-item":a.id,"data-settled":a.settled?!0:void 0,className:cu,children:[e.jsx(du,{tone:a.tone,faded:!!a.settled}),e.jsxs("div",{className:`min-w-0 [overflow-wrap:anywhere] ${a.settled?"text-muted":""}`,children:[e.jsx("b",{className:"font-semibold",children:a.who}),u?" : ":" ",m?e.jsx("code",{className:"font-mono text-[13px]",children:a.text}):cg(a.text),!u&&a.sub&&e.jsxs("span",{className:"text-muted",children:[" · ",a.sub]}),a.settled&&e.jsxs("span",{"data-point-receipt":!0,className:"block text-small text-ok",children:["✓ ",[a.settled.answer,s.settled[a.settled.where],qn(a.settled.at)].filter(Boolean).join(" · ")]}),!a.settled&&(p==null?void 0:p.state)==="done"&&e.jsxs("span",{"data-point-receipt":!0,className:"block text-small text-ok",children:["✓ ",jo(p)," · ",n.done(p.doneAt?qn(p.doneAt):"")]}),!a.settled&&a.error&&e.jsx("span",{role:"alert",className:"block text-small text-danger-fg",children:s.error(a.error)}),!a.settled&&((w=t.note)==null?void 0:w.item)===a.id&&e.jsx("span",{role:"status",className:"block text-small text-muted",children:t.note.text})]}),g(),l&&!a.settled&&e.jsxs("div",{"data-point-answer":!0,className:"col-start-2 mt-1 flex gap-1.5",children:[e.jsx("input",{"aria-label":s.answer.label,placeholder:s.answer.placeholder,value:i,disabled:c,onChange:S=>o(S.target.value),onKeyDown:S=>{S.key==="Enter"&&!S.nativeEvent.isComposing&&(S.preventDefault(),h())},className:"h-8 min-w-0 flex-1 rounded-lg border border-input bg-well px-2.5 text-[13px]"}),e.jsx("button",{type:"button",onClick:()=>{r(!1),o("")},className:Oe({variant:"ghost",className:"h-8 px-2.5"}),children:s.answer.cancel}),e.jsx("button",{type:"button",disabled:c||!i.trim(),onClick:h,className:Oe({variant:"primary",size:"xs"}),children:s.answer.send})]})]})}function xg(t){return t.status==="applied"?null:t.status==="cancelled"||t.status==="expired"?d.confirm[t.status]:t.status==="rejected"&&t.reason==="confirm_required"?d.chat.operator.setup:t.status==="rejected"&&t.reason==="stale"?d.chat.operator.stale:d.chat.operator.notSent}function mg({store:t,turn:s,readOnly:n}){const a=me(t).fresh,[l,r]=f.useState(null),[i,o]=f.useState(null),c=(x,u)=>{r(x),o(null);const m=p=>{r(null);const h=xg(p);o(h?{item:x,text:h}:null)};t.pointAct(s.qid,x,u).then(m,()=>m({status:"failed"}))};return e.jsx(dg,{turn:s,busy:l,note:i,disabled:n||!a,onAnswer:c,onSuggestion:x=>c(x,"suggest")})}function uu(t){const s=Ic(t),n=me(t).fresh,a=rg(s.turns),l=a==null?void 0:a.eventId;f.useEffect(()=>{l!==void 0&&n&&t.operatorRead(l)},[l,n,t])}const Pe=t=>t?new Date(t).toLocaleTimeString(st,{hour:"2-digit",minute:"2-digit"}):"",xu=t=>`${t.sessionId}/${t.key}`;function pg(t,s){var a;if(!((a=t.daemon)!=null&&a.openrig))return s.length>0;const n=t.asksChannel;return s.length>0||n!==null&&(n.partial||n.channel.state!=="ready")}function mu({state:t,machine:s}){const n=t.asksChannel;if(!n)return null;const a=d.asks.channel,l=n.channel.state==="ready"?n.partial?{title:null,body:d.asks.partial}:null:n.channel.state==="not_installed"?{title:a.not_installed.title(s),body:a.not_installed.body}:{title:a[n.channel.state].title,body:a[n.channel.state].body};return l?e.jsxs("div",{role:"status","data-channel":n.channel.state,className:"flex items-start gap-[9px] rounded-lg border border-line px-3 py-2.5 text-[13px] leading-[18px]",children:[e.jsx("span",{className:"mt-[5px]",children:e.jsx(_e,{state:"off"})}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[l.title&&e.jsx("span",{className:"font-medium",children:l.title}),l.body&&e.jsx("span",{className:"text-muted",children:l.body})]})]}):null}function fg({sessions:t,threshold:s,now:n,stale:a}){const l=t.slice(0,Aa),r=t.length-l.length;return e.jsxs(rs,{label:d.atoi.working,children:[l.map(i=>{const o=cl(i,n,s).context;return e.jsx(Ys,{href:ne({name:"thread",sessionId:i.id}),stale:a,lead:e.jsxs(e.Fragment,{children:[e.jsx(_e,{state:"work",pulse:!a}),e.jsx(fs,{tool:i.tool})]}),title:e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:i.name}),i.rig&&e.jsxs("span",{className:"text-small text-muted",children:[" ",i.rig.name]})]}),sub:Kr(i),...o?{meta:`${o.pct} %`,metaWarn:o.near}:{}},i.id)}),r>0&&e.jsxs("a",{href:ne({name:"sessions",filter:"working"}),className:"flex min-h-11 items-center gap-1 px-3 text-[13px] font-medium text-muted",children:[d.atoi.more(r),e.jsx(q,{name:"chevron",className:"size-4"})]})]})}function hg({store:t,onReconnect:s,forge:n}){var X,re,ie,ce;const a=me(t),l=Et(),r=Ds(),i=Xt();uu(t);const[o,c]=f.useState("all"),[x,u]=f.useState(new Set),m=[...a.sessions.values()],p=Vt(m),h=sd(a.asks??[]),g=Rd(a.tasks.values()),y=a.fresh,w=((X=a.device)==null?void 0:X.confirm)===!0&&r,S=r&&((re=a.device)==null?void 0:re.confirm)!==!0,b=((ie=a.daemon)==null?void 0:ie.name)??"",j=((ce=a.device)==null?void 0:ce.contextNear)??vn,N=p.length+h.length+g.length,C=N>=Sp,M=C?o:"all",R=M==="rigs"?[]:Sl(p,M),v=M==="all"||M==="rigs"?h:[],T=fr(R.map(z=>({id:xu(z),value:z}))),A=fr(v.map(z=>({id:z.id,value:z}))),E=T.entries.filter(z=>{var W,ee;if(!z.ghost||!y)return!1;const k=a.sessions.get(z.value.sessionId),_=(W=k==null?void 0:k.pending)==null?void 0:W.key;return!_||_===z.value.key||((ee=k==null?void 0:k.lastAnswer)==null?void 0:ee.key)===z.value.key?!1:Vn(z.value,m,a.ops).kind==="handledElsewhere"}),P=E.map(z=>z.id).join("|");f.useEffect(()=>{if(E.length){u(z=>{var _,W;const k=new Set(z);for(const ee of E){const Z=(W=(_=a.sessions.get(ee.value.sessionId))==null?void 0:_.pending)==null?void 0:W.key;Z&&k.add(`${ee.value.sessionId}/${Z}`)}return k});for(const z of E)T.dismiss(z.id)}},[P]);const I=new Set(E.map(z=>z.id)),L=z=>u(k=>{const _=new Set(k);return _.delete(z),_}),$=new Set(p.map(z=>z.sessionId)),O=wp(m,$),U=M!=="permission"&&M!=="question"&&pg(a,h),D=N===0,K=!y,te=K?a.syncedAt?d.link.lastKnownAt(Pe(a.syncedAt)):d.inbox.lastKnown:N?d.atoi.count(N):void 0,V=C&&e.jsx(pp,{label:d.inbox.filtersLabel,value:M,onChange:c,options:[{value:"all",label:d.inbox.filters.all,count:N},{value:"permission",label:d.inbox.filters.permission,count:Sl(p,"permission").length},{value:"question",label:d.inbox.filters.question,count:Sl(p,"question").length},{value:"rigs",label:d.atoi.rigs,count:h.length}]}),F=D&&e.jsx(rs,{label:d.atoi.noRequest,children:e.jsx(Zt,{framed:!1,glyph:e.jsx(hs,{size:96,frozen:K}),title:d.atoi.noRequest,list:O.length===0,body:O.length?d.atoi.calmHint:d.atoi.nothingRunning,...O.length?{}:{action:e.jsxs("a",{href:ne({name:"sessions"}),className:Oe({size:"sm"}),children:[d.atoi.seeSessions,e.jsx(q,{name:"chevron",className:"size-4"})]})}})}),B=!D&&R.length===0&&v.length===0&&!(M==="all"&&g.length>0)&&e.jsx(Zt,{glyph:e.jsx(q,{name:"inbox"}),title:d.inbox.emptyFilter,body:d.inbox.emptyFilterHint}),Y=e.jsx("div",{className:"flex flex-col gap-3 empty:hidden",children:e.jsx(yh,{store:t})}),G=M==="all"&&g.map(z=>e.jsx(rh,{store:t,task:z,state:a,canConfirm:w},z.id));return l?e.jsx(gg,{update:Y,state:a,items:R,asks:U?v:[],working:O,showRigs:U,chipBar:V,empty:F||B,subtitle:te,threshold:j,now:i,machine:b,routines:G}):e.jsxs(As,{title:d.inbox.title,subtitle:te,offlinePill:!1,children:[Y,V,F,B,T.entries.filter(z=>!I.has(z.id)).map(z=>{var W;const k=z.value,_=a.sessions.get(k.sessionId);return e.jsx(li,{store:t,item:k,session:_,mode:Gr(k,(W=a.capabilities)==null?void 0:W[k.tool],(_==null?void 0:_.readOnly)===!0),outcome:Vn(k,m,a.ops),fresh:y,ghost:z.ghost,changed:x.has(z.id),onReread:()=>L(z.id),canConfirm:w,enroll:S,onGone:()=>T.dismiss(z.id),onCheck:s},z.id)}),G,U&&e.jsxs(e.Fragment,{children:[e.jsxs("h2",{className:"mt-1 flex items-center gap-2 text-[13px] font-semibold",children:[e.jsx(_e,{state:"rig"}),d.atoi.rigs,e.jsx("span",{className:"font-normal text-muted",children:h.length})]}),e.jsx(mu,{state:a,machine:b}),A.entries.map(z=>e.jsx(Dd,{store:t,ask:z.value,end:ld(z.id,a.ops),fresh:y,ghost:z.ghost,canConfirm:w,enroll:S,onGone:()=>A.dismiss(z.id)},z.id))]}),O.length>0&&M==="all"&&e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"mt-1 text-[13px] font-semibold",children:d.atoi.working}),e.jsx(fg,{sessions:O,threshold:j,now:i,stale:K})]}),M==="all"&&e.jsx(sg,{forge:n,mobile:a}),K&&e.jsx("p",{className:"text-small text-muted",children:d.inbox.offlineNote})]})}function gg({update:t,state:s,items:n,asks:a,working:l,showRigs:r,chipBar:i,empty:o,subtitle:c,threshold:x,now:u,machine:m,routines:p}){const h=sa(),g=!s.fresh;return e.jsxs(As,{title:d.inbox.title,subtitle:c,wideSubtitle:c,offlinePill:!1,children:[t,i,o,n.length>0&&e.jsx(rs,{title:d.atoi.requests,dot:"perm",count:n.length,children:n.map(y=>e.jsx(Ys,{href:ne({name:"request",sessionId:y.sessionId,key:y.key}),stale:g,selected:h.name==="request"&&h.sessionId===y.sessionId,lead:e.jsx(fs,{tool:y.tool}),title:e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:y.botName})," ",y.risk==="high"?d.risk.badge:y.kind==="permission"?d.atoi.line.permission:d.atoi.pill[y.kind]]}),sub:lr(y.kind==="permission"?y.body??y.text:wn(y)),meta:yn(y.since,u)},xu(y)))}),p,r&&e.jsxs(rs,{title:d.atoi.rigs,dot:"rig",count:a.length,tone:"rigs",children:[e.jsx("div",{className:"p-2 empty:hidden",children:e.jsx(mu,{state:s,machine:m})}),a.map(y=>{const w=ad(y);return e.jsx(Ys,{href:ne({name:"ask",id:y.id}),stale:g,selected:h.name==="ask"&&h.id===y.id,title:e.jsxs(e.Fragment,{children:[y.priority!=="routine"&&e.jsxs(e.Fragment,{children:[e.jsx(zt,{tone:"urgent",children:d.asks.priority[y.priority]})," "]}),e.jsx("b",{className:"font-semibold",children:w.name}),y.from.rig?` · ${y.from.rig}`:""]}),sub:y.summary,meta:Pe(y.updatedAt),children:e.jsx("span",{className:"sr-only",children:d.asks.pill[nd(y)]})},y.id)})]}),l.length>0&&e.jsxs(rs,{title:d.atoi.working,dot:"work",count:l.length,children:[l.slice(0,Aa).map(y=>{const w=cl(y,u,x).context;return e.jsx(Ys,{href:ne({name:"thread",sessionId:y.id}),stale:g,lead:e.jsx(fs,{tool:y.tool}),title:e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:y.name}),y.rig&&e.jsxs("span",{className:"text-small text-muted",children:[" ",y.rig.name]})]}),sub:Kr(y),...w?{meta:`${w.pct} %`,metaWarn:w.near}:{}},y.id)}),l.length>Aa&&e.jsxs("a",{href:ne({name:"sessions"}),className:"flex min-h-11 items-center gap-1 px-3 text-[13px] font-medium text-muted",children:[d.atoi.more(l.length-Aa),e.jsx(q,{name:"chevron",className:"size-4"})]})]}),g&&e.jsx("p",{className:"text-small text-muted",children:d.inbox.offlineNote})]})}function Ia({store:t,title:s,body:n,item:a,final:l=!1,children:r}){const i=Mn(me(t)),o=ne({name:"atoi"}),c={name:"atoi"};return e.jsxs(e.Fragment,{children:[e.jsx(ra,{title:d.result.header,fallback:c,label:d.detail.back,link:i}),e.jsx("main",{className:"min-h-0 flex-1 overflow-y-auto pb-[22px]",children:e.jsxs("div",{className:"flex flex-col items-start gap-4 pt-7",children:[e.jsx("div",{className:"grid size-14 place-items-center rounded-full border border-ok/20 bg-ok/10 text-ok",children:e.jsx(q,{name:"check",className:"size-[26px]"})}),a&&e.jsxs("span",{className:"flex items-center gap-2 text-meta font-medium tracking-[0.4px] text-muted",children:[e.jsx(ll,{tool:a.tool,seed:a.sessionId,state:"idle"}),e.jsxs("span",{className:"[overflow-wrap:anywhere]",children:[a.botName," · ",a.task]})]}),e.jsx("h1",{className:"text-display leading-[1.25] font-semibold tracking-[-1px] [overflow-wrap:anywhere]",children:s}),e.jsx("p",{className:"text-body text-muted",children:n}),a&&e.jsx("div",{className:"w-full",children:e.jsx(Ge,{title:wn(a),children:e.jsxs("p",{className:"text-muted [overflow-wrap:anywhere]",children:[a.repo,a.branch&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("code",{className:"font-mono text-[.9em]",children:a.branch})]})]})})}),l&&e.jsx("p",{className:"text-body text-muted",children:d.result.final}),r,e.jsx("a",{href:o,className:ze({variant:"primary",block:!0}),children:d.result.back}),a&&e.jsx("a",{href:ne({name:"thread",sessionId:a.sessionId}),className:ze({block:!0}),children:d.result.thread(a.botName)})]})})]})}const bg=ze({variant:"primary",block:!0});function jg({store:t,stale:s=!1,item:n,panel:a}){var g,y,w,S;const l=me(t),r=Mn(l),i=n==null?void 0:n.sessionId,o=i!==void 0&&l.threads.has(i),c=n?(g=l.sessions.get(n.sessionId))==null?void 0:g.lastAnswer:void 0,x=!!n&&!!c&&c.key===n.key;f.useEffect(()=>{!s&&!x&&i!==void 0&&!o&&t.openThread(i)},[s,x,i,o,t]);const u=ne({name:"atoi"}),m={name:"atoi"};if(s)return e.jsxs(e.Fragment,{children:[a?a.header:e.jsx(ra,{title:d.gone.header,fallback:m,label:d.detail.back,link:r}),e.jsxs("main",{className:"min-h-0 flex-1 overflow-y-auto pt-7",children:[e.jsx("h1",{className:"text-display leading-[1.25] font-semibold tracking-[-1px]",children:d.gone.staleTitle}),e.jsx("p",{className:"mt-2.5 text-body text-muted",children:d.gone.staleBody}),e.jsx("a",{href:(a==null?void 0:a.back.href)??u,className:`mt-6 ${bg}`,children:(a==null?void 0:a.back.label)??d.gone.back})]})]});if(n&&c&&x){const b=c.by.kind==="pc"?d.thread.event.fromPc:c.by.id===((y=l.device)==null?void 0:y.id)?d.thread.event.fromHere:d.thread.event.fromDevice(c.by.name);return e.jsx(Ia,{store:t,title:d.gone.titleOn(b),body:c.decision?d.gone.decided(c.decision,Pe(c.at)):d.gone.answered(Pe(c.at)),item:n})}const p=n&&n.kind==="permission"?[...((w=l.threads.get(n.sessionId))==null?void 0:w.items)??[]].reverse().find(b=>b.kind==="permission"&&b.text===n.text&&b.decision!==void 0&&b.decision!=="unknown"):void 0;if(!p||p.decision===void 0||p.decision==="unknown")return e.jsx(Ia,{store:t,title:d.gone.titleElsewhere,body:d.gone.body,item:n});const h=wd(p,n.sessionId,l.ops,((S=l.device)==null?void 0:S.id)??null);return e.jsx(Ia,{store:t,title:d.gone.titleOn(h),body:d.gone.decided(p.decision,Pe(p.at)),item:n})}function yg({options:t,value:s,onChange:n,disabled:a=!1,botName:l,other:r,onSubmit:i}){const o=t.length,c=t.length===0,x=r!==void 0&&(c||s===o),u=x&&r.problem!==null&&r.problem!=="empty",m="flex min-h-12 cursor-pointer items-center gap-3 rounded-control border border-line bg-surface px-3 py-3 text-body has-[:checked]:border-fg/40 has-[:checked]:bg-raised has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-info";return e.jsxs("fieldset",{disabled:a,className:"my-3.5 flex min-w-0 flex-col gap-2 border-0 p-0",children:[e.jsx("legend",{className:"sr-only",children:d.question.legend}),t.map((p,h)=>e.jsxs("label",{className:m,children:[e.jsx("input",{type:"radio",name:"answer",value:h,checked:s===h,onChange:()=>n(h),className:"size-4 flex-none accent-fg"}),e.jsx("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:p})]},h)),r&&e.jsxs(e.Fragment,{children:[!c&&e.jsxs("label",{className:m,children:[e.jsx("input",{type:"radio",name:"answer",value:o,checked:x,onChange:()=>n(o),className:"size-4 flex-none accent-fg"}),e.jsx("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:d.question.other})]}),x&&e.jsxs("div",{children:[e.jsx("label",{htmlFor:"other-answer",className:"mt-3 mb-2 block text-small text-muted",children:d.question.fieldLabel(l)}),e.jsx("textarea",{id:"other-answer",rows:2,value:r.text,onChange:p=>r.onText(p.target.value),placeholder:d.question.placeholder,"aria-invalid":u,"aria-describedby":u?"other-problem":void 0,autoComplete:"off",enterKeyHint:"send",onKeyDown:p=>{p.key==="Enter"&&!p.nativeEvent.isComposing&&(p.preventDefault(),i==null||i())},className:"max-h-[120px] min-h-12 w-full min-w-0 resize-y rounded-control border border-line bg-surface p-3 text-base leading-[22px] text-fg placeholder:text-muted focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-info"}),u&&e.jsx("p",{id:"other-problem",role:"alert",className:"mt-2 text-small text-danger-fg",children:r.problem==="long"?d.question.long(Vr):r.problem==="digit"?d.question.digit:d.question.untypable})]})]})]})}const Ng="flex min-h-12 cursor-pointer items-center gap-3 rounded-control border border-line bg-surface px-3 py-3 text-body has-[:checked]:border-fg/40 has-[:checked]:bg-raised has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-info";function kg({questions:t,selected:s,onToggle:n,disabled:a=!1}){return e.jsx("div",{className:"my-3.5 flex flex-col gap-5",children:t.map((l,r)=>e.jsxs("fieldset",{disabled:a,className:"flex min-w-0 flex-col gap-2 border-0 p-0",children:[e.jsx("legend",{className:"mb-2 text-base leading-[1.4] font-semibold [overflow-wrap:anywhere]",children:l.header??l.question}),l.header&&e.jsx("p",{className:"mb-1 text-small text-muted [overflow-wrap:anywhere]",children:l.question}),l.options.map(i=>{var o;return e.jsxs("label",{className:Ng,children:[e.jsx("input",{type:l.multi?"checkbox":"radio",name:`question-${r}`,checked:((o=s[r])==null?void 0:o.includes(i.label))===!0,onChange:()=>n(r,i.label),className:"size-4 flex-none accent-fg"}),e.jsxs("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:[i.label,i.description&&e.jsx("small",{className:"mt-0.5 block text-meta text-muted",children:i.description})]})]},i.label)})]},l.id))})}function vg({onReconnect:t}){const[s,n]=Cn();return e.jsxs(Ge,{title:d.link.lostTitle,tone:"warning",role:"status",children:[e.jsx("p",{children:d.link.lostDetail}),t&&e.jsx("button",{type:"button",disabled:s,onClick:()=>{n(!0),t()},className:ze({block:!0,className:"mt-3"}),children:s?d.link.reconnecting:d.link.reconnect})]})}const wg=t=>t.decision==="deny"?d.result.denied:t.answer!==void 0?d.result.answered:d.result.allowed;function Sg({title:t,panel:s}){return e.jsx("header",{className:"flex-none border-b border-line pt-2 pb-3",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsxs("button",{type:"button",onClick:s.onBack,className:"-ml-1 flex min-h-11 items-center gap-1 pr-2 text-body text-muted active:text-fg",children:[e.jsx(q,{name:"back"}),d.nav.backTo.thread]}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),e.jsx("button",{type:"button",onClick:s.onClose,"aria-label":d.atelier.closePanel,title:d.atelier.closeTitle,className:Mt({}),children:e.jsx(q,{name:"close"})})]})})}const $g="(orientation: landscape) and (max-height: 500px)",yo=["wheel","touchstart","keydown","pointerdown"];function Nr({store:t,sessionId:s,requestKey:n,onReconnect:a,panel:l,onSettled:r,keys:i=!1}){var We,Rt,Lt,Se,Tt,Ot;const o=me(t),c=Xt(),{fresh:x,ops:u,capabilities:m}=o,p=pd(),{look:h}=Ut(),g=p!==void 0&&h==="offline",[y,w]=f.useState(n),[S,b]=f.useState(!1),[j,N]=f.useState(null),[C,M]=f.useState(""),[R,v]=f.useState(null),[T,A]=f.useState({sig:"",v:[]}),E=Ds(),[P,I]=f.useState(!1),L=f.useRef(y);L.current=y,f.useEffect(()=>{n!==L.current&&(w(n),b(!1),N(null),M(""),v(null),I(!1))},[n]);const $=[...o.sessions.values()],O=Vt($).find(de=>de.sessionId===s&&de.key===y),U=f.useRef(void 0);O&&(U.current=O);const D=Vn({sessionId:s,key:y},$,u),K=(O==null?void 0:O.cut)===!0;f.useEffect(()=>{K&&x&&t.loadPending(s)},[t,s,y,K,x]);const te=(Rt=(We=o.sessions.get(s))==null?void 0:We.pending)==null?void 0:Rt.key;f.useEffect(()=>{var de;if(!(D.kind!=="changed"||!te)){w(te),b(!0),N(null),M(""),v(null);try{(de=globalThis.history)==null||de.replaceState(globalThis.history.state,"",ne(l?{name:"atelier",sessionId:s,requestKey:te}:{name:"request",sessionId:s,key:te}))}catch{}}},[D.kind,te,s]);const V=Mn(o),F={name:"atoi"},B=D.kind==="applied"||O===void 0&&!(D.kind==="sending"||D.kind==="uncertain"||D.kind==="rejected"||D.kind==="failed"||D.kind==="changed")&&x,Y=l==null?void 0:l.onBack;f.useEffect(()=>{B&&Y&&Y()},[B,Y]);const G=f.useRef(r);G.current=r,f.useEffect(()=>{if(!B||!G.current)return;const de=setTimeout(()=>{var Ke;return(Ke=G.current)==null?void 0:Ke.call(G)},rd);return()=>clearTimeout(de)},[B]);const[X,re]=f.useState(null),[ie,ce]=f.useState(null);f.useLayoutEffect(()=>{var an,Rn;const de=X,Ke=ie,Je=(an=globalThis.matchMedia)==null?void 0:an.call(globalThis,$g);if(!de||!Ke||!Je)return;let kt=!1;const es=()=>{if(kt||!Je.matches)return;const rt=Ke.firstElementChild??Ke,ln=de.getBoundingClientRect(),rn=rt.getBoundingClientRect(),Tn=rn.top-ln.top+de.scrollTop,_n=parseFloat(getComputedStyle(de).paddingBottom)||0;de.scrollTop=rn.height>de.clientHeight-_n?Tn:Math.max(0,Tn+rn.height-(de.clientHeight-_n))},zs=()=>{Je.matches&&(kt=!1,es())},ys=()=>{kt=!0};es();const Wt=typeof ResizeObserver=="function"?new ResizeObserver(es):null;Wt==null||Wt.observe(de),Wt==null||Wt.observe(Ke),(Rn=Je.addEventListener)==null||Rn.call(Je,"change",zs);for(const rt of yo)de.addEventListener(rt,ys,{passive:!0});return()=>{var rt;Wt==null||Wt.disconnect(),(rt=Je.removeEventListener)==null||rt.call(Je,"change",zs);for(const ln of yo)de.removeEventListener(ln,ys)}},[y,X,ie]);const z=de=>l?e.jsx(Sg,{title:de,panel:l}):e.jsx(ra,{title:de,fallback:F,label:d.detail.back,link:V});if(D.kind==="applied")return e.jsx(Ia,{store:t,title:wg(D),body:d.result.body,item:U.current,final:!0});const k=D.kind==="sending"||D.kind==="uncertain"||D.kind==="rejected"||D.kind==="failed"||D.kind==="changed",_=O??(k?U.current:void 0);if(!_)return!x&&o.syncedAt===null?e.jsxs(e.Fragment,{children:[z(d.gone.header),e.jsx("main",{className:"min-h-0 flex-1 pt-7 text-body text-muted",role:"status",children:d.loading})]}):e.jsx(jg,{store:t,stale:!x,item:U.current,...l?{panel:{header:z(d.gone.header),back:{href:ne({name:"atelier",sessionId:s}),label:d.nav.backTo.thread}}}:{}});const W=_.kind==="question",ee=_.options??[],Z=m==null?void 0:m[_.tool],J=W&&(Z==null?void 0:Z.freeTextAnswer)===!0,pe=W&&(Z==null?void 0:Z.questions)===!0&&_.requestId!==void 0&&((Lt=_.questions)!=null&&Lt.length)?_.questions:void 0,be=!pe&&(Z==null?void 0:Z.decide)===!1&&ee.length>0,Ze=!pe&&!be&&W&&(ee.length>0||J),pt=((Se=o.device)==null?void 0:Se.confirm)===!0&&E,Ie=_.risk!=="low",De=JSON.stringify((pe??[]).map(de=>[de.id,de.options.map(Ke=>Ke.label)])),fe=T.sig===De?T.v:[],he=(pe??[]).filter((de,Ke)=>{var Je;return!((Je=fe[Ke])!=null&&Je.length)}).length,Me=(de,Ke)=>{const Je=pe==null?void 0:pe[de];if(!Je)return;const kt=(pe??[]).map((zs,ys)=>fe[ys]??[]),es=kt[de]??[];kt[de]=Je.multi?es.includes(Ke)?es.filter(zs=>zs!==Ke):[...es,Ke]:[Ke],A({sig:De,v:kt}),I(!1)},Fe={key:_.key,kind:_.kind,text:_.text},lt=de=>{if(!pe||_.requestId===void 0)return;const Ke=de?[]:pe.map((Je,kt)=>({id:Je.id,selected:fe[kt]??[]}));I(!t.answer(s,_.requestId,Ke,{expect:Fe,...de?{cancel:!0}:{}}))},et=x&&!S&&O!==void 0&&D.kind!=="sending"&&D.kind!=="uncertain"&&(pt||!Ie),jt=de=>{Ie?(v(de),I(!1)):I(!t.reply(s,String(de+1),{expect:Fe}))},yt=e.jsx("ul",{"aria-label":d.answers.legend,className:"my-3.5 flex list-none flex-col gap-2 p-0",children:ee.map((de,Ke)=>{var Je;return e.jsx("li",{children:e.jsxs("button",{type:"button",disabled:!et,"aria-pressed":R===Ke,onClick:()=>jt(Ke),className:"flex min-h-12 w-full flex-col items-start justify-center rounded-control border border-line bg-surface px-3 py-3 text-left text-body [overflow-wrap:anywhere] disabled:opacity-45 active:bg-raised aria-pressed:border-fg/40 aria-pressed:bg-raised",children:[de,((Je=_.optionDetails)==null?void 0:Je[Ke])&&e.jsx("small",{className:"mt-0.5 text-meta text-muted",children:_.optionDetails[Ke]})]})},`${Ke}:${de}`)})}),Q=td(C),H=J&&(ee.length===0||j===ee.length),ye=W?null:ed(_),Te=yp(_),oe=(o.previews.get(s)??[]).slice(-12),Ee=D.kind==="sending"||D.kind==="uncertain",nt=()=>{H?Q.problem===null&&I(!t.reply(s,Q.text,{expect:Fe})):j!==null&&j<ee.length&&I(!t.reply(s,String(j+1),{expect:Fe}))},Nt=ne(l?{name:"atelier",sessionId:s}:{name:"thread",sessionId:s}),js=i&&!l&&e.jsx(aa,{back:e.jsx("span",{className:"w-2.5"}),tool:_.tool,name:_.botName,dot:_.kind==="permission"?"perm":_.kind==="question"?"ask":"work",sub:[_.repo,_.branch].filter(Boolean).join(" · "),more:e.jsxs(e.Fragment,{children:[_.risk==="high"?e.jsx(zt,{tone:"risk",children:d.risk.badge}):e.jsx(zt,{tone:_.kind==="question"?"ask":_.kind==="permission"?"perm":"plain",children:d.atoi.pill[_.kind]}),e.jsxs("a",{href:Nt,className:Oe({size:"sm",className:"ml-1"}),children:[e.jsx(q,{name:"terminal",className:"size-4"}),d.atoi.openThread]})]})});return e.jsxs(e.Fragment,{children:[js||z(d.detail.heading[_.kind]),e.jsxs("main",{ref:re,className:"min-h-0 flex-1 overflow-y-auto overscroll-contain pb-[22px]",children:[!js&&e.jsxs("div",{className:"mt-4 flex items-start gap-3 rounded-card border border-line bg-surface p-3.5",children:[e.jsx(ll,{tool:_.tool,seed:_.sessionId,state:((Tt=o.sessions.get(s))==null?void 0:Tt.state)??"idle",frozen:!x}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("strong",{className:"block text-body [overflow-wrap:anywhere]",children:_.task}),e.jsxs("p",{className:"mt-0.5 text-meta text-muted",children:[_.botName," · ",d.tools[_.tool]]}),e.jsxs("p",{className:"mt-0.5 text-meta [overflow-wrap:anywhere] text-muted",children:[_.repo,_.branch&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("code",{className:`font-mono text-[.9em] ${_.worktree?"underline decoration-dotted underline-offset-2":""}`,children:_.branch})]})]})]})]}),e.jsxs("div",{className:"mt-[22px] mb-3",children:[e.jsx(Ap,{kind:_.kind,risk:_.risk}),e.jsx("h1",{className:`mt-2.5 text-display leading-[1.25] font-semibold tracking-[-1px] [overflow-wrap:anywhere] ${_.kind==="permission"?"phone-side:hidden":""}`,children:_.kind==="permission"?d.detail.commandTitle:wn(_)})]}),W?e.jsxs(e.Fragment,{children:[pe&&e.jsx(kg,{questions:pe,selected:fe,onToggle:Me,disabled:Ee}),be&&yt,Ze&&e.jsx(yg,{options:ee,value:j,onChange:de=>{N(de),I(!1)},botName:_.botName,disabled:Ee,other:J?{text:C,onText:de=>{M(de),I(!1)},problem:Q.problem}:void 0,onSubmit:x&&!S&&!Ee&&O!==void 0?nt:void 0}),!J&&!be&&!pe&&ee.length>0&&e.jsx("p",{className:"mb-3.5 text-small text-muted",children:d.decide.otherUnsupported})]}):e.jsxs(e.Fragment,{children:[e.jsx("div",{ref:ce,children:e.jsx(Ep,{text:_.body??_.text})}),be&&yt,!be&&ee.length>0&&e.jsx("ul",{"aria-label":d.detail.options,className:"my-3.5 flex list-none flex-col gap-2 p-0",children:ee.map(de=>e.jsx("li",{className:"rounded-control border border-line bg-surface px-3 py-3 text-body [overflow-wrap:anywhere]",children:de},de))}),ye&&e.jsx(Ge,{title:ye.title,tone:"danger",children:e.jsx("p",{children:ye.body})}),Te&&e.jsx(Ge,{title:Te.title,children:e.jsx("p",{className:"text-muted",children:Te.body})}),e.jsxs("dl",{className:"my-[18px] grid grid-cols-[74px_minmax(0,1fr)] gap-x-3 gap-y-2.5 text-small",children:[_.branch&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-muted",children:d.detail.branch}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:e.jsx("code",{className:"font-mono text-[.9em]",children:_.branch})})]}),(ye==null?void 0:ye.destination)&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:"text-muted",children:d.detail.destination}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:e.jsx("code",{className:"font-mono text-[.9em]",children:ye.destination})})]}),e.jsx("dt",{className:"text-muted",children:d.detail.asked}),e.jsx("dd",{className:"m-0",children:d.detail.ago(yn(_.since,c))})]}),oe.length>0&&e.jsxs("details",{className:"group mt-[18px] border-t border-line",children:[e.jsxs("summary",{className:"flex min-h-12 cursor-pointer list-none items-center justify-between text-small [&::-webkit-details-marker]:hidden",children:[d.detail.context,e.jsx(q,{name:"terminal",className:"size-4 text-muted"})]}),e.jsx("pre",{className:"pt-2 pb-4 font-mono text-small leading-[1.7] break-words whitespace-pre-wrap text-muted [overflow-wrap:anywhere]",children:oe.join(`
13
+ `)})]})]}),!x&&!g&&D.kind!=="uncertain"&&e.jsx("div",{className:"mt-4",children:e.jsx(vg,{onReconnect:a})})]}),e.jsx(mf,{item:_,outcome:D,fresh:x,changed:S,stillPending:O!==void 0,threadHref:Nt,withThread:!js,onReread:()=>{b(!1),N(null),v(null),I(!1)},onDecide:de=>I(!t.decide(s,de,{expect:Fe})),answerable:Ze,choice:H?ee.length:j,onAnswer:nt,answerBlocked:H?Q.problem!==null:j===null||j>=ee.length,onCheck:a,refused:P,store:t,deviceConfirm:((Ot=o.device)==null?void 0:Ot.confirm)===!0,optionReply:be?{canConfirm:Ie?pt:!0,picked:Ie?R:null,onBack:()=>v(null),onReply:(de,Ke)=>R===null?null:t.reply(s,String(R+1),{assertion:de,expect:Ke})}:void 0,multi:pe?{missing:he,onSend:()=>lt(!1),onCancel:()=>lt(!0)}:void 0,keys:i})]})}const Cg=/^#{1,6}\s+(.+?)\s*#*\s*$/,Mg=/^(?:\*\*|__)([^*_].*?)(?:\*\*|__)\s*:?\s*$/,Ag=/^(\s*)(?:[-*+]|\d+[.)])\s+(.*)$/,Eg=/^\s*\d+[.)]\s/,Rg=/^\[([ xX])\]\s+/,Tg=/^\s*([-*_])(\s*\1){2,}\s*$/,_g=/^\s*(```|~~~)/,Ig=/^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/,kr=new RegExp("(?<!\\\\)\\|"),zl=/^\s*>\s?(.*)$/,Lg=t=>t.startsWith(":")&&t.endsWith(":")?"center":t.endsWith(":")?"right":"left",ba=t=>t.trim().replace(/^\|/,"").replace(new RegExp("(?<!\\\\)\\|$"),"").split(kr).map(s=>s.trim().replace(/\\\|/g,"|")),Og=80,Dg=t=>t.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g,""),Fg=[["questions",/\b(questions?|open|ouvert(e|es)?|decisions?|decider|decide|choix|choices?|a trancher|to settle|besoin de vous|need(s)? you)\b/],["next",/\b(next|suite|reste|left|remaining|todo|to do|a faire|follow[- ]?ups?|prochaines?|later|ensuite|pending)\b/],["verified",/\b(verif\w*|tests?|tested|checks?|checked|validations?|valide|results?|resultats?)\b/],["done",/\b(done|faits?|realise|termine|completed?|changes?|changements?|modifications?|what i did|ce que j'?ai fait|implemented|implemente|delivered|livre)\b/]];function zg(t){var n;const s=Dg(t).replace(/[’']/g,"'");return((n=Fg.find(([,a])=>a.test(s)))==null?void 0:n[0])??"other"}function pu(t){const s=t.replace(/\r\n?/g,`
14
+ `).split(`
15
+ `),n=[];let a=[],l=null;const r=()=>{a.length&&(n.push({type:"p",text:a.join(" ").trim()}),a=[])},i=()=>{l&&(n.push({type:"list",ordered:l.ordered,items:l.items}),l=null)};for(let o=0;o<s.length;o++){const c=s[o],x=c.match(_g);if(x){r(),i();const g=[];for(o++;o<s.length&&!s[o].trim().startsWith(x[1]);o++)g.push(s[o]);n.push({type:"code",text:g.join(`
16
+ `).replace(/\s+$/,"")});continue}const u=s[o+1];if(kr.test(c)&&u!==void 0&&Ig.test(u)){const g=ba(c);if(ba(u).length===g.length){r(),i();const y=[];for(o+=2;o<s.length&&s[o].trim()!==""&&kr.test(s[o]);o++)y.push(Array.from({length:g.length},(w,S)=>ba(s[o])[S]??""));o--,n.push({type:"table",header:g,rows:y,align:ba(u).map(Lg)});continue}}const m=c.match(zl);if(m){r(),i();const g=[m[1]];for(;o+1<s.length&&zl.test(s[o+1]);o++)g.push(s[o+1].match(zl)[1]);n.push({type:"quote",blocks:pu(g.join(`
17
+ `)).map(y=>y.type==="h"?{type:"p",text:y.text}:y)});continue}if(c.trim()===""){r();continue}if(Tg.test(c)){r(),i();continue}const p=c.match(Cg)??c.match(Mg);if(p){r(),i(),n.push({type:"h",text:p[1].trim().replace(/\s*:\s*$/,"")});continue}const h=c.match(Ag);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 w=Eg.test(c);(!l||g<l.indent||l.ordered!==w)&&(i(),l={ordered:w,items:[],indent:g});const S=y.match(Rg);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}i(),a.push(c.trim())}return r(),i(),n}const Ga=t=>/[??]\s*$/.test(t);function vr(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 i,o,c;return(((i=r.match(/\(/g))==null?void 0:i.length)??0)===(((o=r.match(/\)/g))==null?void 0:o.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 No=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,fu=/^(.+?)\s*\(([^()]*(?:\([^()]*\)[^()]*)*)\)\s*$/,Ls=(t,s)=>{const n=Fn.test(t)||Fn.test(s);return{label:No(t.replace(Fn," ")),detail:No(s.replace(Fn," ")),...n?{star:n}:{}}},Js=/^(\*\*|__)(\S(?:.*?\S)?)\1\s*(?:[—–:-]\s*)?(.*)$/,ko=/^(.+?)(\s+[—–-]\s+|:\s+)(.+)$/,mi=(t,s=!1)=>t.every(n=>n.label.length>0&&n.label.length<=Og&&!Ga(n.label)&&(s||!Ga(n.detail)));function vo(t){if(t.length<2||t.length>6)return null;const s=t.map(l=>{var r;return Js.test(l)?null:((r=l.match(ko))==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(Js);if(r)return Ls(r[2],r[3]);const i=n?l.match(ko):null;return i?Ls(i[1],i[3]):Ls(l,"")});return mi(a)?a:null}const Pg=/(^|[\s(:,;])([a-h])\)\s+/g;function wo(t){const s=[];for(const r of t.matchAll(Pg))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,i)=>{var o;return t.slice(r.end,(o=s[i+1])==null?void 0:o.at)});a[a.length-1]=a[a.length-1].split(new RegExp("(?<=[.!??])\\s+(?=\\p{Lu})","u"))[0];const l=a.map(r=>{const i=r.trim().replace(/[\s,;.??]+$/,""),o=/[★⭐]/.test(i),c=i.replace(Fn," ").trim().match(fu),x=c?Ls(c[1],c[2]):Ls(i,"");return o?{...x,star:o}:x});return mi(l,!0)?{stem:n,options:l}:null}const Bg=/^(\*\*|__)(.+?[??])\s*\1/,So=t=>{var s;return Ga(t)?t:((s=t.match(Bg))==null?void 0:s[2])??null},$o=/(^|[^\p{L}])(laquelle|lequel|lesquel|quelle (option|approche|solution)|quel choix|which|pr[ée]f[ée]r|prefer|choisi|choos|pick|reten|retien)/iu,qg=/^(\d+)[.)]\s+(.+)$/,Hg=/^(\*\*|__)(\d+)[.)]\s+(.+?)\1\s*(.*)$/,Ug=t=>t.length>160?t.split(new RegExp("(?<=[.!])\\s+(?=\\p{Lu}|\\()","u"))[0]:t;function Pl(t,s,n){var r;t=t.trim().replace(/\.$/,"");const a=t.match(fu);let l=Ug(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)??"":""),Ls(a?a[1]:t,l)}const Wg=/recommand|recommend/i;function hu(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},i=s.map(u=>u.label.toLowerCase().split(/\s+/)[0]),o=l(s.map((u,m)=>Math.min(r(u.label.toLowerCase()),i[m].length>=4&&i.filter(p=>p===i[m]).length===1?r(i[m]):1/0)));if(o>=0)return o;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 gu=(t,s)=>s<0||t.some(n=>n.star)?t:t.map((n,a)=>a===s?{...n,star:!0}:n);function Kg(t){if(!/^(\*\*|__)[^*_]+\1:?$/.test(t.text.trim()))return null;const s=t.sub.find(o=>Wg.test(o.slice(0,40)));if(!s)return null;const n=t.sub.filter(o=>o!==s),a=n.filter(o=>Js.test(o)),l=a.length>=2?a:n;if(l.length<2||l.length>6)return null;const r=l.map(o=>{var c;return((c=o.replace(/^(\*\*|__)/,"").match(/^([A-Z])\.\s/))==null?void 0:c[1])??""}),i=l.map(o=>{const c=o.match(Js);return c?Ls(c[2].replace(/^[A-Z]\.\s+/,"").replace(/\.$/,""),c[3].replace(/^[,;]\s*/,"")):Ls(o.replace(/\.$/,""),"")});return mi(i)?{options:gu(i,hu(s,i,r)),notes:t.sub.filter(o=>!l.includes(o))}:null}const ja=(t,s,n=t,a)=>{const l=s??vr(n).map(o=>({label:o,detail:""})),r=l.map(o=>o.detail),i=l.findIndex(o=>o.star);return{text:t,options:l.map(o=>o.label),...r.some(Boolean)?{details:r}:{},...i>=0?{recommended:i}:{},...a?{ref:a}:{}}};function bu(t,s={}){var w,S;const n=pu(t);let a,l;const r=n[0];(r==null?void 0:r.type)==="h"&&(a=r.text,n.shift()),a&&((w=n[0])==null?void 0:w.type)==="p"&&!Ga(n[0].text)&&(l=n[0].text,n.shift());const i=[];let o={kind:"other",blocks:[]};const c=()=>{(o.blocks.length||o.title)&&i.push(o)};for(const b of n)if(b.type==="h"){c();const j=zg(b.text);o={kind:s.plan&&(j==="done"||j==="verified")?"other":j,title:b.text,blocks:[]}}else o.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(Js))==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?gu(b,hu(m,b)):null};for(const b of i){const j=b.kind==="done"||b.kind==="verified",N=(S=b.title)==null?void 0:S.match(qg);N&&p(Number(N[1]),Pl(N[2],"",b.blocks[0]));for(let C=0;C<b.blocks.length;C++){const M=b.blocks[C];if(M.type==="p"){const R=M.text.match(Hg);if(R){p(Number(R[2]),Pl(R[3],R[4],b.blocks[C+1]));continue}if(/^(\*\*|__)[^*_]*(recommand|recommend)/i.test(M.text)&&(m=M.text),j)continue;const v=So(M.text),T=wo(M.text);if(!v&&!T)continue;const A=b.blocks[C+1];let E=(A==null?void 0:A.type)==="list"&&!A.ordered?vo(A.items.map(P=>P.text)):null;E?b.blocks.splice(C+1,1):T?E=T.options:!vr(v).length&&$o.test(v)&&(E=g()),M.q=x.length,x.push(ja(M.text,E,T&&!v?T.stem:v))}else M.type==="list"&&!j&&M.items.forEach((R,v)=>{const T=Js.test(R.text)?R.text.lastIndexOf("?"):-1,A=So(R.text)??(T>0?R.text.slice(0,T+1):null),E=wo(R.text),P=A||E?null:Kg(R);if(!A&&!E&&!P){const L=M.ordered?R.text.match(Js):null;L&&p(v+1,Pl(L[2],L[3],void 0));return}R.q=x.length;const I=vo(R.sub);P?(x.push(ja(R.text,P.options,R.text,h(R.text))),R.sub=P.notes):!I&&E?x.push(ja(E.stem,E.options,E.stem,h(E.stem))):x.push(ja(R.text,I??(!vr(A).length&&$o.test(A)?g():null),A??R.text)),I&&!P&&(R.sub=[])})}}const y=!!a&&(r==null?void 0:r.type)==="h"||x.length>0||i.some(b=>!!b.title||b.blocks.some(j=>j.type!=="p"));return{title:a,lead:l,sections:i,questions:x,structured:y}}const Bl="mt-px inline-flex size-4 flex-none items-center justify-center rounded-[4px] border";function ju({checklist:t,current:s}){var u;const[n,a]=f.useState(!1),{tasks:l,done:r,total:i}=t,o=((u=l.find(m=>m.status==="in_progress"))==null?void 0:u.text)??s??(r===i?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,"/",i]}),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:`${i?r/i*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]"}),o]})]}),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:`${Bl} 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:`${Bl} 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:`${Bl} 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 Zn({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(i=>e.jsxs("label",{lang:i.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:i.value,checked:a===i.value,onChange:()=>l(i.value),className:"sr-only"}),i.label]},i.value))})]})}const pi="model-sheet-title",Vg="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 yu({tool:t,models:s,error:n,current:a,pick:l,onPick:r,note:i,actions:o,defaultHint:c=d.model.defaultHint}){var g;const x=!a||a.model===null||s.some(y=>y.id===a.model),u=to(t,s,l),m=y=>{const w=to(t,s,{model:y});r({model:y,effort:l.effort!==null&&(w!=null&&w.includes(l.effort))?l.effort:null})},p=(y,w,S)=>e.jsxs("button",{type:"button","aria-pressed":l.model===y,onClick:()=>m(y),className:Vg,children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-body font-medium",children:w}),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:pi,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,_d(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(Zn,{name:"model-effort",legend:d.model.effortTitle,value:h??"",onChange:y=>r({model:l.model,effort:y}),options:u.map(y=>({value:y,label:oa(y)}))})})]}),i&&e.jsx("p",{className:"text-small whitespace-pre-line text-muted",children:i}),o]})}const Nu={models:[]},ku=t=>t.modelNext?{model:t.modelNext.model??null,effort:t.modelNext.effort??null}:ni(t),tn=(t,s)=>!!(t!=null&&t.models)&&s.canSwitch===!0;function Gg({store:t,session:s}){const{daemon:n,models:a,fresh:l}=me(t),[r,i]=f.useState(!1),o=tn(n,s);if(f.useEffect(()=>{o&&t.requestModels(s.tool)},[o,t,s.tool]),!o)return null;const c=a[s.tool]??Nu,x=s.modelNext?ku(s):null,u=x??ni(s),m=[Uf(s.tool,u.model??void 0,c.models),u.effort?oa(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),i(!0)},className:`${Mc()} 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(fl,{store:t,session:s,onClose:()=>i(!1)})]})}function Xg({store:t,session:s}){const{daemon:n,modelFailures:a}=me(t),l=a[s.id];return!tn(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 fl({store:t,session:s,onClose:n}){const{models:a}=me(t),l=a[s.tool]??Nu,r=ni(s),[i,o]=f.useState(ku(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 w=y.status==="rejected"?y.reason:null;m(w&&w in d.model.failed?d.model.failed[w]:d.model.notApplied)},h=Kf(s);return e.jsx(ct,{labelledBy:pi,onClose:n,children:e.jsx(yu,{tool:s.tool,models:l.models,error:l.error,current:r,pick:i,onPick:o,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(Ue,{variant:"outline",disabled:c,onClick:()=>void p(r),children:d.model.cancelPending}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ue,{variant:"ghost",className:"flex-1",onClick:n,children:d.model.cancel}),e.jsx(Ue,{variant:"primary",className:"flex-[2]",disabled:c||Wf(i,r),onClick:()=>void p(i),children:d.model.apply})]})]})})})}const Qg=1e4;function vu(t,s){const n=d.sessions.modelOff;return tn(t,s)?null:s.state==="exited"?n.ended:t!=null&&t.models?n.outside:n.olderPc}function Yg(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 Hs({icon:t,label:s,why:n,right:a,onClick:l,danger:r=!1}){const i=!l;return e.jsxs("button",{type:"button",disabled:i,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 ql=({children:t})=>e.jsx("div",{className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:t});function fi({store:t,session:s,closable:n,closing:a,onClose:l,onModel:r,onCloseSession:i,display:o,lead:c,who:x}){var V,F,B;const u=me(t),m=Xt(),p=f.useId(),[h,g]=f.useState("menu"),[y,w]=f.useState(!1),S=d.sessions,b=s.name,j=u.fresh,C=[cl(s,m,1).model,s.effort?oa(s.effort):null].filter(Boolean).join(" · "),M=vu(u.daemon,s),R=(V=u.daemon)!=null&&V.checklist?u.checklists.get(s.id):void 0,v=!!s.pending||s.state==="waiting_permission"||s.state==="waiting_input",T=s.state==="working",A=Object.values(u.ops).filter(Y=>Y.message.type==="session.interrupt"&&Y.message.id===s.id).sort((Y,G)=>Y.at.localeCompare(G.at)).at(-1),E=A!==void 0&&xs(A.phase),P=(A==null?void 0:A.phase)==="applied"&&(!T||m-Date.parse(A.at)<Qg),I=T&&j&&!v&&!E&&!P,L=d.terminal,$=E||P?null:j?v?L.why.waiting:T?null:L.why.idle:L.why.offline,O=(A==null?void 0:A.phase)==="sending"?L.sending:P?L.sent:L.interrupt(b),U=(A==null?void 0:A.phase)==="rejected"&&A.reason==="read_only"?L.readOnly:y||(A==null?void 0:A.phase)==="rejected"||(A==null?void 0:A.phase)==="failed"?L.fail:null,D=Yg(s,u.sessions.values()),K=!!((F=u.daemon)!=null&&F.broadcast)&&D.ids.length>1,te=x??[s.project,s.branch].filter(Boolean).join(" · ");return e.jsxs(ct,{labelledBy:p,onClose:l,children:[e.jsxs("h2",{id:p,"aria-label":S.sheet.label(b),className:"flex min-w-0 items-center gap-2",children:[e.jsx(fs,{tool:s.tool}),e.jsx("b",{className:"font-semibold whitespace-nowrap",children:b}),te&&e.jsx("span",{className:"min-w-0 truncate text-small font-normal text-muted",children:te})]}),h==="plan"&&R?e.jsxs(e.Fragment,{children:[e.jsx(ju,{checklist:R,...(B=s.checklist)!=null&&B.current?{current:s.checklist.current}:{}}),e.jsx("button",{type:"button",onClick:()=>g("menu"),className:"h-11 rounded-lg border border-input text-body",children:d.nav.back})]}):h==="group"?e.jsx(Jc,{store:t,label:D.name,ids:D.ids,offline:!j,startOpen:!0,onCancel:()=>g("menu")}):e.jsxs(e.Fragment,{children:[c&&c.length>0&&e.jsx(ql,{children:c.map(Y=>e.jsx(Hs,{icon:Y.icon,label:Y.label,onClick:Y.onClick},Y.label))}),e.jsxs(ql,{children:[e.jsx(Hs,{icon:"cpu",label:d.model.title,why:M,right:C||null,onClick:M||!j?void 0:r}),o&&e.jsx(Hs,{icon:"terminal",label:d.terminal.live2.view,right:o.value,onClick:o.onToggle}),R&&e.jsx(Hs,{icon:"list",label:d.checklist.title,right:S.sheet.planCount(R.done,R.total),onClick:()=>g("plan")}),e.jsx(Hs,{icon:"stop",label:O,why:U??$,onClick:I?()=>w(!t.interrupt(s.id)):void 0}),K&&e.jsx(Hs,{icon:"send",label:S.sheet.writeGroup(D.name),onClick:j?()=>g("group"):void 0})]}),n&&s.state!=="exited"&&e.jsx(ql,{children:e.jsx(Hs,{icon:"power",danger:!0,label:a?d.sessionEnd.closingNamed(b):d.sessionEnd.close(b),right:At()&&!a?e.jsx("span",{"aria-hidden":"true",children:S.sheet.faceId}):null,onClick:a?void 0:i})}),e.jsx("p",{className:"text-meta text-muted",children:S.sheet.interruptNote})]})]})}const wr=t=>`ledge.mobile.draft.${t}`;function wu(t,s){var n;try{return((n=Qe(s))==null?void 0:n.getItem(wr(t)))??""}catch{return""}}function Su(t,s,n){try{const a=Qe(n);s===""?a==null||a.removeItem(wr(t)):a==null||a.setItem(wr(t),s)}catch{}}const $u="ledge.mobile.draft.cleared",Zg=50;function Cu(t){var s;try{const n=JSON.parse(((s=Qe(t))==null?void 0:s.getItem($u))??"[]");return Array.isArray(n)?n.filter(a=>typeof a=="string"):[]}catch{return[]}}function Jg(t,s){return Cu(s).includes(t)}function eb(t,s){var n;try{const a=Cu(s).filter(l=>l!==t);(n=Qe(s))==null||n.setItem($u,JSON.stringify([...a,t].slice(-Zg)))}catch{}}let Sr=null;const tb=t=>{Sr=t};function sb(t){return Sr!==t?!1:(Sr=null,!0)}function nb(t,s,n){const a=wu(t,n);Su(t,a.startsWith(s)?a:s+a,n),tb(t)}const ab=["image/png","image/gif","image/jpeg","image/webp"],lb=25e6,rb=[.85,.7,.55,.4],Co=640,ib=.8,ob=[.7,.5],cb={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 i=n=document.createElement("canvas");i.width=l,i.height=r;const o=i.getContext("2d");if(!o)throw new Error("no canvas");return o.imageSmoothingQuality="high",o.drawImage(s,0,0,l,r),{encode:(c,x)=>new Promise((u,m)=>i.toBlob(p=>p?u(p):m(new Error("no blob")),c,x))}}}}},Mu=(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 Au(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 Eu=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 db(t,s=cb){var a;if(!ab.includes(t.type))return{ok:!1,reason:"notImage"};if(t.size>lb)return{ok:!1,reason:"tooLarge"};let n;try{n=await s.decode(t)}catch{return{ok:!1,reason:"unreadable"}}try{let l=Math.min(em,Math.max(n.width,n.height));for(;;){const{w:r,h:i}=Mu(n.width,n.height,l),o=await n.draw(r,i);for(const c of rb){const{blob:x,mime:u}=await Au(o,c);if(x.size>tm)continue;const m={mime:u,data:await Eu(x)},p=await ub(n);return p&&(m.preview=p),{ok:!0,value:{image:m,width:r,height:i,bytes:x.size}}}if(l<=Co)return{ok:!1,reason:"tooLarge"};l=Math.max(Co,Math.round(l*ib))}}catch{return{ok:!1,reason:"unreadable"}}finally{(a=n.close)==null||a.call(n)}}async function ub(t){try{return await xb(t)}catch{return}}async function xb(t){const{w:s,h:n}=Mu(t.width,t.height,sm),a=await t.draw(s,n);for(const l of ob){const{blob:r,mime:i}=await Au(a,l);if(r.size<=nm)return{mime:i,data:await Eu(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 Ru({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 pb({url:t,failed:s,width:n,height:a,maxW:l,maxH:r,alt:i,unavailable:o,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:o}):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:i,draggable:!1,style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})}):e.jsx("div",{"data-thumb":"loading","aria-busy":"true",style:u})}function Tu({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??Mt({variant:"outline",round:!0}),children:a??e.jsx(q,{name:"plus"})})]})}const _u=t=>{var s;return[...((s=t.clipboardData)==null?void 0:s.files)??[]].filter(n=>n.type.startsWith("image/"))},Mo=44,fb=120,Xa=()=>{var t;return((t=globalThis.matchMedia)==null?void 0:t.call(globalThis,"(hover: hover) and (pointer: fine)").matches)===!0};function hb({id:t,label:s,sendLabel:n,value:a,onChange:l,onSend:r,canSend:i,oneLine:o,images:c,placeholder:x,disabled:u=!1,attachDisabled:m,maxLength:p,invalid:h=!1,describedBy:g,fieldRef:y}){const w=f.useRef(null),S=y??w;f.useLayoutEffect(()=>{const j=S.current;j&&(j.style.height=`${Mo}px`,j.style.height=`${Math.min(fb,Math.max(Mo,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(Ru,{items:c.items,onRemove:c.remove,size:{w:72,h:54},removeLabel:d.images.remove,lang:Ac}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx(Tu,{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:o?"send":"enter","aria-invalid":h,"aria-describedby":g,onChange:j=>l(j.target.value),onPaste:j=>{const N=_u(j);N.length===0||b||(j.preventDefault(),c.add(N))},onKeyDown:j=>{j.key!=="Enter"||j.nativeEvent.isComposing||!o&&(j.shiftKey||!Xa())||(j.preventDefault(),i&&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:!i,onClick:r,"aria-label":n,title:n,className:Mt({variant:"primary",round:!0}),children:e.jsx(q,{name:"arrowUp"})})]})]})}const gb={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"}},bb={claude:"anthropic",codex:"openai",cursor:"cursor"};function Iu(t,s,n,a=!0){const[l,r]=f.useState({key:"",url:null,failed:!1}),i=s?`${s}|${n}`:"";return f.useEffect(()=>{if(!s||!a)return;let o=!0;return t.imageUrl(s,n).then(c=>{o&&r({key:i,url:c,failed:!1})},()=>{o&&r({key:i,url:null,failed:!0})}),()=>{o=!1}},[t,s,n,a,i]),l.key===i&&i!==""?{url:l.url,failed:l.failed}:{url:null,failed:!1}}const Rs=d.images,jb=1,yb=4,Nb=120,kb=t=>Math.min(yb,Math.max(jb,t)),vb={"image/png":"png","image/gif":"gif","image/jpeg":"jpg","image/webp":"webp"};function wb(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(i=>i.blob()).then(i=>{const o=new File([i],s,{type:n});r&&navigator.canShare({files:[o]})&&l(o)},()=>{}),()=>{r=!1}},[t,s,n]),a}function Sb({store:t,refs:s,index:n,onIndex:a,onClose:l}){const r=s[n],{url:i,failed:o}=Iu(t,r.id,!1),c=`capture-${n+1}.${vb[r.mime]??"img"}`,x=wb(i,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 w=()=>{const[T,A]=[...g.current.values()];return T&&A?Math.hypot(T.x-A.x,T.y-A.y):0},S=T=>{var A,E;g.current.set(T.pointerId,{x:T.clientX,y:T.clientY}),(E=(A=T.currentTarget).setPointerCapture)==null||E.call(A,T.pointerId),g.current.size===2?y.current={...y.current,pinch0:w(),scale0:u}:y.current={...y.current,y0:T.clientY}},b=T=>{g.current.has(T.pointerId)&&(g.current.set(T.pointerId,{x:T.clientX,y:T.clientY}),g.current.size===2?y.current.pinch0>0&&m(kb(y.current.scale0*w()/y.current.pinch0)):u===1&&h(T.clientY-y.current.y0))},j=T=>{if(g.current.delete(T.pointerId)&&g.current.size===0){if(u===1&&Math.abs(p)>Nb){l();return}h(0)}},N=f.useRef(null);lu(N,l);const C=()=>{x&&navigator.share({files:[x]}).catch(()=>{})},M=T=>T.stopPropagation(),R="inline-flex min-h-11 items-center rounded-full bg-white/15 px-4 text-body font-medium text-white",v=(T,A,E,P)=>T>=0&&T<s.length&&e.jsx("button",{type:"button","aria-label":A,title:A,onPointerDown:M,onClick:()=>a(T),className:`absolute top-1/2 ${E} 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 Qr.createPortal(e.jsxs("div",{ref:N,role:"dialog","aria-modal":"true","aria-label":Rs.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:M,onClick:C,className:R,children:Rs.share}),i&&e.jsx("a",{href:i,download:c,onPointerDown:M,className:R,children:Rs.save}),e.jsx("button",{type:"button","aria-label":Rs.close,title:Rs.close,onPointerDown:M,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:[i&&e.jsx("img",{src:i,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"}}),!i&&e.jsx("p",{role:"status",className:"text-body text-white/70",children:o?Rs.unavailable:"…"}),v(n-1,Rs.prev,"left-3","m15 18-6-6 6-6"),v(n+1,Rs.next,"right-3","m9 18 6-6-6-6")]})]}),document.body)}const Ao=d.images;function $b({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:i,failed:o}=Iu(t,s.id,!0,a&&s.preview);return s.preview?e.jsx("div",{ref:r,className:"max-w-full",children:e.jsx(pb,{url:i,failed:o,width:s.width,height:s.height,maxW:240,maxH:240,alt:"",unavailable:Ao.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:Ao.noPreview})}function $r({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,i)=>e.jsx($b,{store:t,image:r,onOpen:()=>l(i)},`${r.id}:${i}`)),a!==null&&e.jsx(Sb,{store:t,refs:s,index:a,onIndex:l,onClose:()=>l(null)})]})}function Cb(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 Mb=new RegExp("(?<code>`[^`\\n]+`)|\\*\\*(?<b>\\S(?:.*?\\S)?)\\*\\*(?!\\*)|(?<![\\w*])\\*(?<i>[^\\s*](?:[^*\\n]*?[^\\s*])?)\\*(?![\\w*])","g"),hi=f.createContext(void 0);function us(t,s=0,n){let a=0;const l=o=>n?[e.jsx(f.Fragment,{children:n(o)},`t${a++}`)]:[o];if(s>2)return l(t);const r=[];let i=0;for(const o of t.matchAll(Mb)){const c=o.index;c>i&&r.push(...l(t.slice(i,c)));const x=o.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:us(x.b,s+1,n)},c)):r.push(e.jsx("em",{children:us(x.i,s+1,n)},c)),i=c+o[0].length}return i<t.length&&r.push(...l(t.slice(i))),r}function Lu({b:t}){const s=f.useContext(hi);switch(t.type){case"p":return e.jsx("p",{className:"[&+*]:mt-2.5",children:us(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?"☑ ":"☐ "}),us(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,i)=>e.jsx("li",{children:us(r,0,s)},i))})]},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:us(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:us(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(Lu,{b:n},a))})}}function Ab({s:t}){const s=f.useContext(hi),n=t.blocks.map((a,l)=>e.jsx(Lu,{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:us(t.title,0,s)}),n]})}function Ou({doc:t,plain:s}){return e.jsxs(hi.Provider,{value:s,children:[t.title&&e.jsx("strong",{className:"block text-body font-semibold",children:us(t.title,0,s)}),t.lead&&e.jsx("p",{className:"mt-1.5",children:us(t.lead,0,s)}),t.sections.map((n,a)=>e.jsx(Ab,{s:n},a))]})}const Eb="text-info underline underline-offset-2",hl=(t,s)=>e.jsx("a",{href:ne({name:"thread",sessionId:t}),className:Eb,children:s});function Rb(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 i of a.matchAll(n))i.index>r&&l.push(a.slice(r,i.index)),l.push(e.jsx("span",{children:hl(t.get(i[1]),i[1])},i.index)),r=i.index+i[0].length;return r===0?a:(r<a.length&&l.push(a.slice(r)),l)}}function Tb({text:t,names:s}){const n=f.useMemo(()=>bu(t),[t]),a=f.useMemo(()=>Rb(s),[s]);return e.jsx("div",{className:"px-1 break-words [overflow-wrap:anywhere]",children:e.jsx(Ou,{doc:n,plain:a})})}function _b({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)?hl(s.get(n),n):n]},n))]})}const Eo=t=>new Date(t).toLocaleTimeString(st,{hour:"2-digit",minute:"2-digit"});function Du({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(Eo(n)):d.chat.action.ignored(1,Eo(n),{done:0,denied:0,failed:0}),e.jsx("button",{type:"button",className:ls,onClick:()=>{t.ignoreTurn(s,!0)},children:d.chat.review})]})}const xa="flex flex-col gap-2.5 rounded-xl border border-line bg-surface p-3.5",ls=ze({size:"sm"}),ma=ze({variant:"primary",size:"sm"});function Ib({store:t,qid:s,relay:n,target:a,known:l,ignoredAt:r}){const i=a==null?void 0:a.repo,[o,c]=f.useState(null),[x,u]=f.useState(!1),[m,p]=f.useState(null),h=n.status==="sent",g=Cb(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(Du,{store:t,qid:s,at:r});const w=j=>{u(!0),c(null),(j==="send"?t.relay(s):t.cancelRelay(s)).then(C=>{C.status==="applied"?p(j):j==="send"&&c(C.status==="rejected"?C.reason??"":"")},()=>{j==="send"&&c("")}).finally(()=>u(!1))},S=o||(n.failed?n.code??"":o),b=h?e.jsxs("p",{role:"status",className:"text-body text-ok",children:[d.chat.sentTo(n.name),l?hl(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:xa,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),i?` · ${i}`:""]}),!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:ls,disabled:x||m!==null,onClick:()=>w("cancel"),children:d.chat.relayCancel})}),!h&&!y&&e.jsxs("div",{className:"flex gap-2",children:[m===null&&e.jsx("button",{type:"button",className:ls,disabled:x,onClick:()=>{t.ignoreTurn(s)},children:d.chat.ignore}),e.jsx("button",{type:"button",className:ma,disabled:x||m!==null,onClick:()=>w("send"),children:S!==null?d.chat.relayRetry:d.chat.relayGo})]})]})}const Ce=d.chat.action,Lb=ze({size:"sm",className:"border-danger-fg/50 text-danger-fg"}),Ob=ze({block:!0,className:"!border-transparent !bg-destructive !text-primary-fg active:opacity-75"});function Cr(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 Db=t=>t.replace(/\*\*/g,""),ya=t=>t?new Date(t).toLocaleTimeString(st,{hour:"2-digit",minute:"2-digit"}):"",gi=t=>(t.vars&&t.action!==void 0?Ce.line(t.action,t.vars):void 0)??t.summary,Fb=t=>(t.vars&&t.action==="session.decide"?Ce.line("session.decide",{...t.vars,decision:"deny"}):void 0)??gi(t),Ro=t=>Ce.why(t.code??(t.state==="failed"?"failed":void 0),t.action,t.vars??{});function To(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 Ce.stops(n,a,s.seats,Number(s.seatsMore??0)||0)}const zb=t=>Ce.verb(t.action,t.vars??{})??(t.action!==void 0?Ce.verbs[t.action]:void 0)??Ce.apply;function Pb({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"}),Ce.risk[t.risk]]})}function _o({s:t,k:s,r:n,last:a}){const l=t==="done"||t==="failed"||t==="refused"||t==="running"?Ce.stepState[t](s):Ce.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 Io({r:t,s,whole:n}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"break-words text-body",children:Cr(s==="denied"?Fb(t):gi(t))}),s!=="denied"&&e.jsx(Pb,{r:t}),n&&To(t)&&e.jsx("p",{className:"mt-1 break-words text-small text-muted",children:To(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:Ce.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:Ce.cutMark})]})]})}function Bb({store:t,qid:s,actions:n,ignoredAt:a,canConfirm:l,readOnly:r=!1}){const[i,o]=f.useState(null),[c,x]=f.useState(new Set),[u,m]=f.useState(null),p=f.useId(),h=n.map(Rm),g=h.length>1,{shown:y,stopAt:w}=Bi(h),S=y.map((L,$)=>c.has($)&&(L==="proposed"||L==="held"||L==="failed")?"running":L),b=c.size>0,j=L=>L.some($=>qi(n[$])),N=(L,$)=>{x(new Set),$.status==="cancelled"||$.status==="expired"?m({rows:L,text:d.confirm[$.status]}):$.status==="rejected"&&$.reason==="confirm_required"?m({rows:L,text:d.chat.closeSetup}):$.status!=="applied"&&m({rows:L,text:Ce.notSent})},C=(L,$)=>{o(null),m(null),x(new Set(L)),t.act(s,L,$).then(O=>N(L,O),()=>N(L,{status:"failed"}))},M=L=>j(L)?o(L):C(L),R=L=>{t.ignoreTurn(s,L)};if(a!==void 0){const L=$=>S.filter(O=>O===$).length;return e.jsxs("p",{className:"flex flex-wrap items-center gap-x-2 px-1 text-small text-muted",children:[Ce.ignored(h.length,ya(a),{done:L("done"),denied:L("denied"),failed:L("failed")}),!r&&e.jsx("button",{type:"button",className:ls,onClick:()=>R(!0),children:Ce.review})]})}const v=e.jsx("button",{type:"button",className:ls,disabled:b,onClick:()=>R(),children:Ce.ignore}),T=(L,$,O)=>{const U=O.risk==="destructive",D=e.jsxs("button",{type:"button",className:U?Lb:ls,disabled:b||j([$])&&!l,onClick:()=>M([$]),children:[zb(O),j([$])?"…":""]}),K=O.deny&&e.jsx("button",{type:"button",className:ls,disabled:b,onClick:()=>C([$],{deny:!0}),children:Ce.deny}),te=n[$].session;if(r&&(L==="proposed"||L==="held"||L==="failed"||L==="cut"||L==="stale"||L==="running"))return e.jsx("span",{className:"text-small text-muted",children:d.chat.history.notApplied});switch(L){case"proposed":case"held":return e.jsxs(e.Fragment,{children:[!g&&L==="proposed"&&v,K,D]});case"running":return e.jsx("span",{className:"text-body text-attention",children:Ce.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"}),Ce.done(ya(O.doneAt))]});case"failed":return e.jsxs(e.Fragment,{children:[!g&&v,e.jsx("button",{type:"button",className:ls,disabled:b||j([$])&&!l,onClick:()=>M([$]),children:Ce.retry})]});case"refused":return e.jsx("span",{className:"text-body text-muted",children:Ce.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"}),Ce.denied(ya(O.doneAt))]});case"stale":return te?e.jsx("a",{className:ls,href:ne({name:"thread",sessionId:te}),children:Ce.open(O.target??"")}):null;case"cut":return e.jsxs(e.Fragment,{children:[!g&&v,K,e.jsx(ur,{})]})}},A=(L,$)=>{const O=S[$];return e.jsxs("li",{className:`grid gap-x-2.5 gap-y-1 ${g?"grid-cols-[22px_minmax(0,1fr)]":"grid-cols-1"} ${$>0?"border-t border-line pt-2.5":""}`,children:[g&&e.jsx(_o,{s:O,k:$+1,r:L,last:$===h.length-1}),e.jsxs("div",{className:"min-w-0",children:[e.jsx(Io,{r:L,s:O,whole:!1}),O==="failed"&&e.jsx("p",{role:"alert",className:"mt-1 text-small text-danger-fg",children:Cr(Ce.failed(Ro(L)))}),O==="refused"&&e.jsx("p",{role:"alert",className:"mt-1 text-small text-danger-fg",children:Cr(Ce.refused(Ro(L)))}),O==="held"&&e.jsx("p",{className:"mt-1 text-small text-muted",children:Ce.held(w+1)}),O==="stale"&&e.jsx("p",{className:"mt-1 text-small text-attention",children:Ce.stale}),O==="cut"&&e.jsx("p",{className:"mt-1 text-small text-muted",children:Ce.cutNote}),O==="denied"&&e.jsx("p",{className:"mt-1 text-small text-muted",children:Ce.deniedNote(L.target??"")}),e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:T(O,$,L)})]})]},$)},E=()=>{if(!g||r&&!S.every(U=>U==="done"))return null;if(S.every(U=>U==="done")){const U=h.map(D=>D.doneAt).filter(D=>!!D).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"}),Ce.planDone(ya(U))]})}const L=S.indexOf("running");if(L>=0)return e.jsx("button",{type:"button",className:ze({variant:"primary",size:"sm",block:!0}),disabled:!0,children:Ce.progress(L+1,h.length)});const $=Tm(h);if(!$.rows.length)return null;const O=$.from==="start"?Ce.all($.rows.length):$.from==="resume"?Ce.resume(w+1,$.rows.length):Ce.skip(w+1,$.rows.length);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[v,e.jsxs("button",{type:"button",className:`${ma} flex-1`,disabled:b||j($.rows)&&!l,onClick:()=>M($.rows),children:[O,j($.rows)?"…":""]})]}),e.jsx("span",{className:"text-small text-muted",children:w>=0?Ce.notReplayed:Ce.inOrder})]})},P=!r&&!l&&Bi(h).open.some(L=>qi(n[L])),I=u&&u.rows.every(L=>(h[L].state??"proposed")==="proposed"||h[L].state==="failed")?u.text:null;return e.jsxs("section",{"aria-label":Ce.label(h.length),"aria-live":"polite",className:xa,children:[e.jsx("ol",{className:"flex flex-col gap-2.5",children:h.map(A)}),E(),I&&e.jsx("p",{role:"status",className:"text-body text-muted",children:I}),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})]}),i&&e.jsxs(ct,{labelledBy:p,onClose:()=>o(null),children:[e.jsx("h2",{id:p,className:"text-heading leading-[1.3] tracking-[-.5px]",children:i.length>1?Ce.sheet.many(i.length):Ce.sheet.one(Db(gi(h[i[0]])))}),e.jsx("ol",{className:"flex flex-col gap-2.5",children:i.map((L,$)=>e.jsxs("li",{className:`grid gap-x-2.5 ${g?"grid-cols-[22px_minmax(0,1fr)]":"grid-cols-1"}`,children:[g&&e.jsx(_o,{s:"proposed",k:L+1,r:h[L],last:$===i.length-1}),e.jsx(Io,{r:h[L],s:"proposed",whole:!0})]},L))}),e.jsxs("p",{className:"text-small leading-[1.6] text-muted",children:[i.length>1?`${Ce.sheet.stops} `:"",d.confirm.note]}),e.jsx("button",{type:"button",className:Ob,onClick:()=>C(i),children:At()?d.confirm.goApple:d.confirm.go}),e.jsx("button",{type:"button",className:ze({block:!0}),onClick:()=>o(null),children:Ce.sheet.cancel})]})]})}function qb(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 Hb({store:t,qid:s,closes:n,canConfirm:a,sessions:l}){const{ops:r}=me(t),[i,o]=f.useState(new Set),[c,x]=f.useState(!1),[u,m]=f.useState(null),p=Object.values(r).filter(j=>xs(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 C=l.find(M=>M.id===j.id);return{row:j,i:N,name:(C==null?void 0:C.name)??j.name,state:qb(j,N,!C||!!C.exited,h,i.has(N))}}),w=y.filter(j=>j.state==="open"||j.state==="failed"),S=j=>{x(!0),m(null),o(N=>new Set([...N].filter(C=>!j.includes(C)))),t.closeSessions(s,j).then(N=>{N.status==="cancelled"||N.status==="expired"?m(N.status):(N.status==="failed"||N.status==="rejected")&&o(C=>new Set([...C,...j]))},()=>o(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:xa,children:[e.jsx("ul",{className:"flex flex-col gap-2",children:y.map(({row:j,i:N,name:C,state:M})=>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:[C," ",e.jsxs("span",{className:"font-normal text-muted",children:["· ",d.tools[j.tool]]})]}),M!=="open"&&e.jsx("span",{className:`text-body ${M==="failed"?"text-danger-fg":M==="closing"?"text-attention":"text-ok"}`,children:b[M]}),(M==="open"||M==="failed")&&e.jsx("button",{type:"button",className:ls,disabled:g||!a,onClick:()=>S([N]),children:d.chat.closeRow})]},N))}),u&&e.jsx("p",{className:"text-body text-muted",children:d.confirm[u]}),w.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})]}),w.length>=2&&e.jsx("div",{className:"flex gap-2",children:e.jsx("button",{type:"button",className:ma,disabled:g||!a,onClick:()=>S(w.map(j=>j.i)),children:d.chat.closeAll(w.length)})})]})}function Ub({store:t,qid:s,row:n,proposal:a,canConfirm:l,known:r,ignored:i}){const[o,c]=f.useState(null),[x,u]=f.useState(!1),[m,p]=f.useState(!1),h=a.launchedId!==void 0;if(i&&!h)return null;const g=()=>{u(!0),c(null),t.launch(s,[n]).then(w=>{w.status==="applied"?p(!0):w.status==="cancelled"||w.status==="expired"?c(w.status):(w.status==="failed"||w.status==="rejected")&&c("failed")},()=>c("failed")).finally(()=>u(!1))},y=a.failed?"failed":o;return e.jsxs("section",{"aria-label":d.chat.launchLabel,className:xa,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?hl(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:ls,disabled:x,onClick:()=>{t.ignoreTurn(s)},children:d.chat.ignore}),e.jsx("button",{type:"button",className:ma,disabled:x||m||!l,onClick:g,children:At()?d.confirm.goApple:d.confirm.go})]})]})}function Wb({store:t,qid:s,proposals:n,canConfirm:a,sessionIds:l,ignoredAt:r}){const i=r!==void 0;return e.jsxs(e.Fragment,{children:[n.map((o,c)=>e.jsx(Ub,{store:t,qid:s,row:c,proposal:o,canConfirm:a,known:l.has(o.launchedId??""),ignored:i},c)),i&&n.some(o=>o.launchedId===void 0)&&e.jsx(Du,{store:t,qid:s,at:r,rest:n.some(o=>o.launchedId!==void 0)})]})}function Kb({store:t,qid:s,row:n,task:a}){const[l,r]=f.useState(!1),[i,o]=f.useState(!1),[c,x]=f.useState(!1),u=a.taskId!==void 0,m=()=>{r(!0),o(!1),t.giveTask(s,n).then(p=>{p.status==="applied"?x(!0):o(!0)},()=>o(!0)).finally(()=>r(!1))};return e.jsxs("section",{"aria-label":d.chat.task.label,className:xa,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&&(i||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:ma,disabled:l||c,onClick:m,children:d.chat.task.give})})]})}function Vb({store:t,qid:s,tasks:n}){return e.jsx(e.Fragment,{children:n.map((a,l)=>e.jsx(Kb,{store:t,qid:s,row:l,task:a},l))})}const bi="flex flex-col gap-1.5 border-l-2 border-line pl-2.5",Lo="size-3.5 flex-none fill-none stroke-current [stroke-linecap:round] [stroke-linejoin:round] [stroke-width:1.6]";function Gb(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 Xb(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 Qb({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:`${Lo} 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:`${Lo} text-ok`,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"M20 6 9 17l-5-5"})}),Gb(a,s)]},`${l}:${a.kind}:${a.id??""}`)})})}const Yb=t=>({busy:d.chat.busy,timeout:d.chat.timeout,failed:d.chat.failed,cancelled:d.chat.cancelled})[t];function Oo({store:t,turn:s,live:n,sessions:a,list:l,canConfirm:r,onAskAgain:i,readOnly:o=!1,limits:c,inAnswer:x}){if(s.point)return e.jsx(mg,{store:t,turn:{...s,point:s.point},readOnly:o});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($r,{store:t,refs:s.attachments,align:"end"})}),e.jsx(Qb,{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(Tb,{text:m,names:p}),!n&&s.answer&&e.jsx(_b,{names:Xb(u),ids:p}),!n&&s.answer&&x,!n&&s.answer&&c&&e.jsx(sj,{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:Yb(s.error)}),(s.error==="timeout"||s.error==="failed")&&s.question&&i&&e.jsx("button",{type:"button",onClick:()=>i(s.question),className:Oe({size:"xs"}),children:d.chat.askAgain})]}),!n&&e.jsxs("fieldset",{disabled:o,className:"contents",children:[!n&&s.closes&&e.jsx(Hb,{store:t,qid:s.qid,closes:s.closes,canConfirm:r,sessions:l}),!n&&!s.closes&&g&&e.jsx(Ib,{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(Wb,{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(Bb,{store:t,qid:s.qid,actions:s.actions,ignoredAt:s.ignoredAt,canConfirm:r,readOnly:o}),!n&&s.tasks&&s.tasks.length>0&&e.jsx(Vb,{store:t,qid:s.qid,tasks:s.tasks})]})]})}function Zb({harness:t,size:s=14}){const{d:n,fill:a,rule:l}=gb[bb[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 ji(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 Jb={"":"",amber:"bg-attention",red:"bg-approval"},yi={"":"",amber:"text-attention",red:"text-approval"};function Fu({pct:t,alert:s}){const n=ca(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] ${Jb[n]}`,style:{width:`${Math.min(100,t)}%`,...n?{}:{background:"var(--u-gauge)"}}})})}function ej({label:t,w:s,now:n,alert:a}){const l=d.chat.point,r=ca(s.pct,a),i=s.resetsAt?ai(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(Fu,{pct:s.pct,alert:a}),e.jsxs("span",{className:"truncate font-mono text-[12px]",children:[e.jsx("b",{className:`font-medium ${yi[r]}`,children:d.percent(s.pct)}),i&&e.jsx("small",{className:"ml-1.5 text-[11px] text-muted",children:Qf(s)?s.resetsAt&&Id(s.resetsAt,n)?l.resumesOn(i):l.resumes(i):`↺ ${i}`})]})]})}function tj(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 sj({usage:t,now:s,alert:n,fresh:a=!0,at:l}){const r=d.chat.point,i=[],o=[];if(da(t,s,a).forEach((x,u)=>{const m=r.harnessShort[x.harness]??x.harness,p=(w,S)=>i.push({key:x.harness,label:m,sentence:w,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(w=>{const S=tj(x.harness,w);return S?[{key:`${x.harness}:${w.kind}:${w.model??""}`,label:S,w,dim:g}]:[]});if(y.length){i.push(...y),g&&x.readAt&&o.push(Date.parse(x.readAt));return}x.status==="unreachable"&&p(x.readAt?r.unreach(Ua(Math.max(0,s-Date.parse(x.readAt)))):r.unreachNever,!0)}),!i.length)return null;const c=Math.min(Date.parse(l),...o);return e.jsxs("div",{role:"group","aria-label":r.limitsLabel,className:bi,children:[e.jsx("div",{className:"flex flex-col",children:i.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=ca(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(Fu,{pct:x.w.pct,alert:n}),e.jsxs("span",{className:"whitespace-nowrap font-mono text-[12px]",children:[e.jsx("b",{className:u?`font-medium ${yi[u]}`:"font-normal",children:d.percent(x.w.pct)}),x.w.resetsAt&&e.jsxs("small",{className:"ml-[5px] text-[11px] text-muted",children:["↺ ",ai(x.w.resetsAt,s,!0)]})]})]},x.key)})}),i.some(x=>"w"in x)&&e.jsx("span",{className:"text-[11.5px] text-muted",children:r.stale(Ua(Math.max(0,s-c)))})]})}function nj({usage:t,now:s,alert:n,fresh:a=!0}){const l=d.chat.point,r=da(t,s,a);if(!r.length)return null;const i=o=>t[o].harness==="cursor"&&t[o].status==="ok"&&t[o].windows.length===0&&t[o].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((o,c)=>{const x=o.readAt?Ua(s-Date.parse(o.readAt)):null,u=o.status==="stale"||o.status==="unreachable";return e.jsxs("div",{"data-harness":o.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(Zb,{harness:o.harness}),l.harness[o.harness]??o.harness]}),o.status==="loading"&&e.jsx("p",{className:"py-1 text-small text-muted",children:l.loading}),o.status==="expired"&&e.jsx("p",{className:"py-1 text-small text-attention",children:l.notOnPc(l.harness[o.harness]??o.harness)}),o.status==="ok"&&i(c)&&e.jsx("p",{className:"py-1 text-small text-muted",children:l.unread}),o.status!=="loading"&&o.status!=="expired"&&o.windows.length>0&&e.jsx("div",{className:u?"opacity-50":void 0,children:o.windows.map(m=>e.jsx(ej,{label:ji(m),w:m,now:s,alert:n},`${m.kind}:${m.model??m.pool??""}`))}),o.status==="stale"&&x&&e.jsx("p",{className:"py-1 text-small text-attention",children:l.stale(x)}),o.status==="unreachable"&&e.jsx("p",{className:"py-1 text-small text-attention",children:x?l.unreach(x):l.unreachNever})]},o.harness)})]})}const It=d.thread.rig,aj="inline-flex items-center gap-1 whitespace-nowrap text-small text-muted",lj="inline-flex items-center gap-1 whitespace-nowrap text-small font-medium text-fg",zu="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]",gl=()=>e.jsx("div",{className:"text-meta text-muted",children:d.thread.cut});function rj({session:t}){const s=sn(),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(al,{tool:t.tool,seed:t.id,state:n,pose:nl(t.id,n),size:16,theme:s,frozen:!0})})}function ij({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(rj,{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 pa(t){const[s,n]=f.useState(!1),a=t&&e.jsx("button",{type:"button","aria-expanded":s,onClick:()=>n(r=>!r),className:aj,children:t.label}),l=t&&s&&e.jsx("pre",{className:zu,children:t.text});return{toggle:a,box:l}}function oj({e:t,storage:s}){const{toggle:n,box:a}=pa(t.raw),l=t.dir==="out",r=t.delivery&&It.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?`${It.to} ${t.who.name}`:`${It.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(ij,{lead:l?It.to:It.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:It.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:()=>nb(t.reply.sessionId,t.reply.draft,s),"aria-label":It.replyTo(t.who.name),className:lj,children:[e.jsx(q,{name:"reply",className:"size-3.5"}),It.reply]}),n]}),a]}),t.cut&&e.jsx(gl,{})]})}const Do="inline-flex h-5 items-center rounded-full px-2 text-meta font-medium whitespace-nowrap",cj={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 dj(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(i=>i.isIntersecting)));return l.observe(a),()=>l.disconnect()},[t]),s}function uj(t,s,n){var i,o;const a=me(t),l=((i=a.daemon)==null?void 0:i.rigRows)===!0,r=!!s&&n&&l&&a.fresh;return f.useEffect(()=>{if(!r)return;t.requestRigRow(s);const c=setInterval(()=>t.requestRigRow(s),am);return()=>clearInterval(c)},[r,t,s]),s&&l?(o=a.rigRows[s])==null?void 0:o.row:void 0}function xj({e:t,store:s}){const{toggle:n,box:a}=pa(t.raw),l=f.useRef(null),r=dj(l),i=uj(s,t.qitem,r),o=t.refused?null:kf(i,t.outgoing),c=t.refused?t.refused.log:o==null?void 0:o.log;return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("section",{ref:l,"aria-label":t.outgoing?It.rowOut(t.who.name):It.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?It.rowOut(t.who.name):It.rowIn(t.who.name)}),e.jsx("span",{className:"flex-1"}),o?e.jsx("span",{"data-state":o.key,className:`${Do} ${cj[o.key]}`,children:o.text}):e.jsx("span",{"data-state":"refused",className:`${Do} bg-danger-bg text-danger-fg`,children:It.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(gl,{})]})}function Pu({e:t}){const{toggle:s,box:n}=pa(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:It.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(gl,{})]})}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:It.folded(t.notices.length)})]}),s&&t.notices.map(a=>e.jsx(Pu,{e:a},a.key))]})}function pj({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:It.unreadable}),e.jsx("pre",{className:zu.replace("mt-1.5 ",""),children:t.text}),t.cut&&e.jsx(gl,{})]})}function fj({e:t}){const{toggle:s,box:n}=pa(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 hj({e:t,storage:s,store:n}){switch(t.kind){case"rig-message":return e.jsx(oj,{e:t,storage:s});case"rig-task":return e.jsx(xj,{e:t,store:n});case"rig-notice":return e.jsx(Pu,{e:t});case"rig-fold":return e.jsx(mj,{e:t});case"rig-unreadable":return e.jsx(pj,{e:t});case"rig-raw":return e.jsx(fj,{e:t})}}const Ns=d.thread.task,gj={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 bj({task:t,cut:s}){const{toggle:n,box:a}=pa({label:Ns.raw,text:t.raw}),l=gj[t.status],r=Ns.statuses[t.status],{about:i}=t,o=(i==null?void 0:i.kind)==="command"?i.code:void 0,c=[o!==void 0?Ns.code(o):null,t.output??null].filter(Boolean).join(" · ");return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("section",{"aria-label":Ns.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:Ns.kicker}),e.jsx("span",{className:"flex-1"}),e.jsx(la,{tone:l.tone,label:r})]}),e.jsx("p",{className:"text-body [overflow-wrap:anywhere]",children:(i==null?void 0:i.kind)==="agent"?e.jsxs(e.Fragment,{children:[Ns.agent," ",e.jsx("strong",{className:"font-semibold",children:i.name})," ",Ns.agentDid[t.status]]}):(i==null?void 0:i.kind)==="command"?e.jsxs(e.Fragment,{children:[Ns.command," ",e.jsx("code",{className:"rounded-[4px] bg-fg/[0.05] px-1 font-mono text-[.9em]",children:i.command})," ",Ns.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 xn=d.images;let jj=0;const yj=t=>`data:${t.mime};base64,${t.data}`;function Bu(t){const[s,n]=f.useState([]),[a,l]=f.useState(0),[r,i]=f.useState(null),o=f.useRef([]),c=f.useRef(0),x=f.useRef(!0);f.useEffect(()=>(x.current=!0,()=>{x.current=!1}),[]);const u=j=>{o.current=j,n(j)},m=(j,N)=>{x.current&&u(o.current.map(C=>C.item.key===j?{...C,...N,item:{...C.item,...N.item}}:C))},p=j=>{c.current+=j,l(c.current)},h=async j=>{const N=await db(j);if(p(-1),!x.current)return;if(!N.ok){i(N.reason==="tooLarge"?xn.tooLarge:xn.notImage);return}const{image:C,width:M,height:R,bytes:v}=N.value,T=`att-${jj++}`;u([...o.current,{item:{key:T,url:yj(C.preview??C),width:M,height:R,bytes:v,state:"uploading"}}]);try{const A=await t.putImage(C);m(T,{id:A.id,item:{state:"ready"}})}catch(A){const E=A instanceof Error&&A.message==="too_large"?xn.tooLarge:A instanceof Error&&A.message==="not_image"?xn.notImage:xn.failed;m(T,{item:{state:"refused",reason:E}}),x.current&&i(E)}},g=j=>{if(j.length!==0){i(null);for(const N of j){if(o.current.length+c.current>=Ii){i(xn.max);return}p(1),h(N)}}},y=j=>{const N=o.current.find(C=>C.item.key===j);u(o.current.filter(C=>C.item.key!==j)),(N==null?void 0:N.item.state)==="refused"&&i(null)},w=()=>{const j=o.current;return u([]),i(null),j},S=j=>{x.current&&u([...j,...o.current].slice(0,Ii))},b=s.map(j=>j.item);return{items:b,add:g,remove:y,clear:w,putBack:S,error:r,ready:a===0&&b.every(j=>j.state==="ready"),ids:()=>o.current.filter(j=>j.item.state==="ready"&&j.id).map(j=>j.id)}}const qu=`${$s}launch.started`;function Hu(t){var s;try{const n=JSON.parse(((s=Qe(t))==null?void 0:s.getItem(qu))??"[]");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 Nj(t,s,n){var l;const a=[...Hu(n).filter(r=>r.id!==t),{id:t,project:s}].slice(-50);try{(l=Qe(n))==null||l.setItem(qu,JSON.stringify(a))}catch{}}const kj=(t,s)=>{var n;return((n=Hu(s).find(a=>a.id===t))==null?void 0:n.project)??null};function vj(t){const s=/^\/(\S*)$/.exec(t);return s?s[1].toLowerCase():null}function wj(t,s){var l;const n=s.toLowerCase(),a=[];for(const r of t){const i=[r.name,...r.aliases??[]],o=i.map(g=>g.toLowerCase());let c=-1,x=r.name,u=-1;const m=o.indexOf(n),p=o.findIndex(g=>g.startsWith(n)),h=o.findIndex(g=>g.includes(n));m>=0&&n?(c=0,x=i[m],u=0):p>=0?(c=1,x=i[p],u=0):h>=0?(c=2,x=i[h],u=o[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,i)=>r.rank-i.rank||+!!r.command.blocked-+!!i.command.blocked||r.shown.localeCompare(i.shown)).map(({rank:r,...i})=>i)}function Sj(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(i=>i.toLowerCase()===a))})}const $j=t=>`/${t.name} `,Us=d.thread.slash;function Cj({listing:t,query:s,matches:n,tool:a,name:l,onPick:r}){const i="mb-2 overflow-hidden rounded-2xl border border-line bg-surface";return t?t.error?e.jsx("div",{className:`${i} px-3 py-3 text-meta text-muted`,role:"status",children:Us.unavailable(l)}):n.length===0?e.jsx("div",{className:`${i} px-3 py-3 text-meta text-muted`,role:"status",children:Us.none(`/${s}`,l)}):e.jsxs("div",{className:i,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(o=>{const c=o.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:["/",o.at>=0&&u>0?e.jsxs(e.Fragment,{children:[o.shown.slice(0,o.at),e.jsx("mark",{className:"bg-transparent font-semibold text-fg underline underline-offset-2",children:o.shown.slice(o.at,o.at+u)}),o.shown.slice(o.at+u)]}):o.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:`${i} px-3 py-3 text-meta text-muted`,role:"status",children:Us.loading(a)})}const Mj={ok:"text-ok",info:"text-info",approval:"text-approval",attention:"text-attention",muted:"text-muted"},_t=d.thread.composer;function Uu(t){const s=t.trim();return s.length>ea?"long":$c.test(s)?"untypable":null}function Aj(t){if(t.phase==="uncertain"||t.reason==="not_taken")return{title:_t.uncertainTitle,body:_t.uncertain};const s=t.reason==="busy"?_t.busy:t.reason==="invalid"?_t.invalid(ea):t.reason==="untypable"?_t.untypable:t.reason==="read_only"?_t.readOnly:t.reason==="attachment_missing"?_t.imageGone:t.reason==="attachments_not_accepted"?d.images.dialog:_t.lost;return{title:_t.failTitle,body:s}}function Ej({name:t,focusAtEnd:s=!1,composer:n,draft:a,onDraft:l,onSend:r,fresh:i,taken:o,checking:c,error:x,alert:u,onReconnect:m,images:p,dialog:h,lead:g,leadNote:y,slash:w}){var $,O;const[S,b]=Cn(),j=o?{tone:"ok",label:_t.status.taken}:c?{tone:"muted",label:d.decide.checking}:n.status,N=Uu(a),C=f.useRef(null),M=p.items.length>0;f.useEffect(()=>{const U=C.current;!s||!U||(U.focus(),U.setSelectionRange(U.value.length,U.value.length))},[]);const R=w&&n.enabled&&!h?vj(a):null,v=R!==null;f.useEffect(()=>{v&&(w==null||w.ask())},[v]);const T=($=w==null?void 0:w.listing)!=null&&$.error?[]:((O=w==null?void 0:w.listing)==null?void 0:O.commands)??[],A=f.useMemo(()=>R!==null?wj(T,R):[],[R,T]),E=w&&!h?Sj(a,T):void 0,P=U=>{var D;l($j(U)),(D=C.current)==null||D.focus()},I=!E||R!==null?null:E.blocked?{warn:!0,text:d.thread.slash.blocked[E.blocked]}:E.bare&&/^\/\S+\s*$/.test(a)?{warn:!0,text:d.thread.slash.bare(E.name)}:E.argumentHint?{warn:!1,text:`/${E.name} ${E.argumentHint}`}:null,L=n.enabled&&(!!a.trim()||M)&&N===null&&p.ready&&!(M&&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 ${Mj[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(Ge,{title:x.title,tone:"warning",role:"alert",children:[e.jsx("p",{children:x.body}),!i&&m&&e.jsx("button",{type:"button",disabled:S,onClick:()=>{b(!0),m()},className:ze({block:!0,className:"mt-2"}),children:S?d.link.reconnecting:_t.reconnect})]})}),v&&e.jsx(Cj,{listing:w.listing,query:R,matches:A,tool:w.tool,name:t,onPick:P}),!v&&(n.enabled||g)&&e.jsxs("div",{role:"group","aria-label":_t.quickLabel,className:"flex gap-1.5 overflow-x-auto pb-2 [scrollbar-width:none]",children:[g,n.enabled&&Ef.map(U=>e.jsx("button",{type:"button",onClick:()=>{var D;l(U),(D=C.current)==null||D.focus()},className:`${Mc()} whitespace-nowrap`,children:U},U))]}),y,e.jsx(hb,{id:"draft",label:_t.label(t),sendLabel:_t.send(t),value:a,onChange:l,onSend:r,canSend:L,oneLine:!0,images:p,placeholder:n.placeholder,disabled:!n.enabled,fieldRef:C,invalid:N!==null,describedBy:N?"draft-problem":void 0}),I&&e.jsx("p",{role:"status",className:`pt-1.5 text-meta ${I.warn?"text-attention":"font-mono text-muted"}`,children:I.text}),M&&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"?_t.tooLong(ea):_t.untypable})]})}const qe=d.sessionEnd,In=t=>ze({variant:t,block:!0});function Wu(t,s,n,a,l){const[r,i]=f.useState(null),[o,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 i(null),t.prepareConfirm(s==="terminal"?{purpose:s,id:n}:{purpose:s,id:n}).then(j=>{S&&(i(j),b=setTimeout(()=>{S&&(i(null),c("expired"))},j.expiresInMs))},()=>{S&&c("prepareFailed")}),()=>{S=!1,clearTimeout(b)}},[t,s,n,a,m]),{challenge:r,problem:o,asking:x,needsNew:o==="expired"||o==="failed"||o==="prepareFailed",go:async()=>{if(!a||x||!r)return;if(!r.credentialId){i(null),c("failed");return}u(!0),c(null);const S=await ta({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"){i(null),c("failed");return}i(null),l(S)===null&&c("failed")}},retry:()=>{c(null),p(S=>S+1)}}}function Ni({store:t,session:s,mode:n,onClose:a,onSent:l,onReconnect:r}){const{fresh:i,device:o}=me(t),[c,x]=Cn(),u=s.name,m=n==="close",p=!!(o!=null&&o.confirm),h=Wu(t,m?"close":"act",s.id,i&&p,S=>{const b=m?t.sessionClose(s.id,S):t.sessionResume(s.id,S);return b!==null&&l(),b}),g=m?_m(s):[],y=h.asking?d.confirm.asking:h.challenge?m?At()?qe.goCloseApple:qe.goClose:At()?qe.goResumeApple:qe.goResume:d.confirm.preparing,w=e.jsx("button",{type:"button",onClick:a,className:In(),children:qe.cancel});return e.jsxs(ct,{labelledBy:"end-title",onClose:a,children:[e.jsx("h2",{id:"end-title",className:"text-heading leading-[1.3] tracking-[-.5px]",children:m?qe.closeTitle(u):qe.resumeTitle(u)}),i?p?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:m?qe.closeBody:qe.resumeBody}),g.length>0&&e.jsx(Ge,{title:qe.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(Ge,{title:d.confirm[h.problem],tone:"warning",role:"alert"}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:g.length>0?`${qe.force} ${qe.check}`:qe.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}),w]}):e.jsxs(e.Fragment,{children:[e.jsx(Ge,{title:qe.unprotectedTitle,tone:"warning",role:"status",children:e.jsx("p",{children:m?qe.unprotectedClose(u):qe.unprotectedResume(u)})}),e.jsx("a",{href:ne({name:"connection"}),className:In("primary"),children:qe.openConnection}),w]}):e.jsxs(e.Fragment,{children:[e.jsx(Ge,{title:qe.offlineTitle,tone:"warning",role:"status",children:e.jsx("p",{children:m?qe.offlineClose(u):qe.offlineResume(u)})}),r&&e.jsx("button",{type:"button",disabled:c,onClick:()=>{x(!0),r()},className:In("primary"),children:c?d.link.reconnecting:qe.reconnect}),w]})]})}function Fo({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 Ku({error:t,fresh:s,onRetry:n,onReconnect:a}){const[l,r]=Cn();return e.jsxs(Ge,{title:t.title,tone:"warning",role:"alert",children:[e.jsx("p",{children:t.body}),t.retry&&e.jsx("button",{type:"button",onClick:n,className:ze({size:"sm",className:"mt-2"}),children:qe.retry}),t.reconnect&&!s&&a&&e.jsx("button",{type:"button",disabled:l,onClick:()=>{r(!0),a()},className:ze({size:"sm",className:"mt-2"}),children:l?d.link.reconnecting:qe.reconnect})]})}function Rj({ending:t,name:s,canResume:n,resumeHeld:a=!1,readOnly:l,fresh:r,focus:i,onResume:o,onReconnect:c}){const x=f.useRef(null);return f.useEffect(()=>{var u;i&&((u=x.current)==null||u.focus({preventScroll:!0}))},[i]),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(Fo,{tone:"attention",label:qe.closing(s)}),e.jsx("p",{className:"text-small text-muted",children:qe.closingHint})]}),t.kind==="resuming"&&e.jsx(Fo,{tone:"info",label:qe.resuming(s)}),t.kind==="ended"&&e.jsxs(e.Fragment,{children:[t.error&&e.jsx(Ku,{error:t.error,fresh:r,onRetry:o,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:qe.ended}),t.killed?e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:qe.killed}):!l&&e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:n?qe.endedBody:qe.endedOnPc}),n&&!l&&e.jsxs("button",{type:"button","aria-disabled":a||void 0,onClick:()=>{a||o()},className:ze({variant:t.killed?"outline":"primary",block:!0,className:a?"opacity-45":""}),children:[e.jsx(q,{name:"resume"}),qe.resume(s)]})]})]})]})}function Tj({text:t}){const s=f.useMemo(()=>bu(t),[t]);return e.jsx(Ou,{doc:s})}const zo=({align:t})=>e.jsx("div",{className:`text-meta text-muted ${t==="end"?"text-right":""}`,children:d.thread.cut}),Po={success:{glyph:"✓",tone:"text-ok"},running:{glyph:"●",tone:"text-info"},failed:{glyph:"✕",tone:"text-danger-fg"},unknown:{glyph:"·",tone:"text-muted"}};function _j({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,vf(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:Po[l.status].tone,children:Po[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 Ij({store:t,item:s,onReconnect:n,keys:a}){var o,c,x;const l=me(t),r=Ds(),i=l.sessions.get(s.sessionId);return e.jsx(li,{store:t,item:s,session:i,inThread:!0,keys:a,mode:Gr(s,(o=l.capabilities)==null?void 0:o[s.tool],(i==null?void 0:i.readOnly)===!0),outcome:Vn(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 Lj({item:t,store:s,storage:n,inPanel:a=!1,onReconnect:l,keys:r=!1}){switch(t.kind){case"tools":return e.jsx(_j,{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(hj,{e:t,storage:n,store:s});case"me":{const i=t.images??(t.attachments??[]).flatMap(o=>s.knownImage(o)??[]);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($r,{store:s,refs:i,align:"end"}),t.cut&&e.jsx(zo,{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(Tj,{text:t.text})}),t.cut&&e.jsx(zo,{align:"start"})]});case"task":return e.jsx(bj,{task:t.task,cut:t.cut});case"capture":{const i=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}),i&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("span",{className:"font-mono",children:[i.width,"×",i.height]})]})]}),e.jsx($r,{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(Ge,{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:ze({block:!0,className:"mt-3"}),children:[d.thread.examine,e.jsx(q,{name:"arrowRight"})]})]}):e.jsx(Ij,{store:s,item:t.item,onReconnect:l,keys:r})}}function Oj({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:Mt({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:Mt({}),children:e.jsx(q,{name:"close"})})]})}function Mr({store:t,sessionId:s,storage:n,onReconnect:a,panel:l,forge:r}){var H,ye,Te,oe,Ee,nt,Nt,js,We,Rt,Lt;const i=me(t),o=Xt(),c=Et(),x=rl(),u=i.sessions.get(s),m=i.threads.get(s),{fresh:p,ops:h}=i,[g,y]=f.useState(()=>wu(s,n)),[w]=f.useState(()=>sb(s)),[S,b]=f.useState(!1),j=Bu(t),N=f.useRef(new Map);f.useEffect(()=>{var Se;for(const[Tt,Ot]of N.current){const de=(Se=h[Tt])==null?void 0:Se.phase;de==="applied"?N.current.delete(Tt):(de==="rejected"||de==="failed"||de==="uncertain")&&(N.current.delete(Tt),j.putBack(Ot))}});const C=Se=>{y(Se),Su(s,Se,n),b(!1)},[M,R]=f.useState(null),[v,T]=f.useState(!1),[A,E]=f.useState(!1),[P,I]=f.useState(!1),[L,$]=f.useState(null),O=((H=Im(s,h))==null?void 0:H.op)??null,U=f.useRef(u==null?void 0:u.state);f.useEffect(()=>{U.current!==(u==null?void 0:u.state)&&U.current!==void 0&&$(O),U.current=u==null?void 0:u.state},[u==null?void 0:u.state,O]),f.useEffect(()=>(t.openThread(s),()=>t.watch(null)),[t,s]),f.useEffect(()=>{p&&t.watch(s)},[t,s,p]);const D=(m==null?void 0:m.status)==="ready"?(ye=m.items.at(-1))==null?void 0:ye.at:void 0;f.useEffect(()=>{D&&t.read(s,D)},[t,s,D]);const K=vd(s,h).at(-1);f.useEffect(()=>{(K==null?void 0:K.phase)!=="applied"||Jg(K.op,n)||(eb(K.op,n),g.trim()===K.message.text&&C(""))},[K==null?void 0:K.phase,K==null?void 0:K.op]);const[te,V]=f.useState(""),F=u==null?void 0:u.state;f.useEffect(()=>{(K==null?void 0:K.phase)==="applied"&&F&&F!=="idle"&&V(K.op)},[F,K==null?void 0:K.phase,K==null?void 0:K.op]);const B=f.useRef(null),Y=(m==null?void 0:m.status)==="gone",G=u&&!Y?Mf((m==null?void 0:m.items)??[],u,h,o,(m==null?void 0:m.cut)??[],i.sessions,((Te=i.device)==null?void 0:Te.id)??null):[],X=(oe=G.at(-1))==null?void 0:oe.key,re=f.useRef(!0),[ie,ce]=f.useState(!1),z=()=>{const Se=B.current;Se&&(Se.scrollTop=Se.scrollHeight),re.current=!0,ce(!1)},k=f.useRef(!1);f.useLayoutEffect(()=>{var Tt;const Se=B.current;if(!(!Se||G.length===0)){if(!k.current){k.current=!0;const Ot=Hl.get(s);if(Hl.delete(s),Ot!==void 0){Se.scrollTop=Ot,re.current=Se.scrollHeight-Se.scrollTop-Se.clientHeight<Bo;return}}re.current?z():((Tt=G.at(-1))==null?void 0:Tt.kind)==="awaiting"&&ce(!0)}},[X,G.length,m==null?void 0:m.items]);const _=()=>{const Se=B.current;Se&&(re.current=Se.scrollHeight-Se.scrollTop-Se.clientHeight<Bo,re.current&&ce(!1))};if(!u||Y){const Se=!Y&&!p&&i.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(id,{link:Mn(i)}),l&&e.jsx("button",{type:"button",onClick:l.onClose,"aria-label":d.atelier.closePanel,title:d.atelier.closeTitle,className:Mt({}),children:e.jsx(q,{name:"close"})})]})}),e.jsx("main",{className:"min-h-0 flex-1 pt-7 text-body text-muted",role:"status",children:Se?d.thread.loading:d.thread.unknown})]})}const W=K!==void 0&&xs(K.phase),ee=(K==null?void 0:K.phase)==="applied"&&te!==K.op&&u.state==="idle"&&!u.pending&&o-Date.parse(K.at)<xr,Z=Af(u,p?"ready":"pc_offline",W||ee),J=K&&(K.phase==="rejected"||K.phase==="failed"||K.phase==="uncertain")&&(K.phase==="uncertain"||g.trim()===K.message.text)?Aj(K):null,pe=S&&!J?{title:d.thread.composer.failTitle,body:d.thread.composer.lost}:J,be=!!u.pending||u.state==="waiting_input"||u.state==="waiting_permission",Ze=()=>{const Se=g.trim();if(!Se&&j.items.length===0||!Z.enabled||Uu(g)||!j.ready||j.items.length>0&&be)return;$(O);const Tt=j.ids(),Ot=j.clear(),de=t.reply(s,Se,Tt.length?{attachments:Tt}:{});!de&&Ot.length?j.putBack(Ot):de&&Ot.length&&N.current.set(de,Ot),b(!de)},pt=(m==null?void 0:m.status)==="ready",Ie=((Ee=i.daemon)==null?void 0:Ee.boot)??null,De=Lm(u,h,o,{fresh:p,boot:Ie}),fe=Hr(u,h,Ie,o),he=!!((nt=i.daemon)!=null&&nt.sessionClose)&&!u.readOnly,Me=De.kind==="open"&&De.error&&De.error.op!==L?De.error:null,Fe=Se=>{$(O),I(!1),R(Se)},lt=!!l&&u.tool==="omp",et=Sn(u),jt=kj(s,n),yt=u.state==="exited"&&u.exitedAt?d.sessions.line.ended(_c(u.exitedAt,o)):void 0,Q=x&&[u.project,u.branch].filter(Boolean).join(" · ")||void 0;return e.jsxs(e.Fragment,{children:[e.jsx(aa,{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:et,pulse:et==="work"&&p,sub:yt??Q,under:!x&&!!yt,more:e.jsxs(e.Fragment,{children:[l?e.jsx(Oj,{sessionId:s,panel:l}):e.jsx(Vu,{sessionId:s,current:"thread",onLeave:()=>{B.current&&Hl.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:()=>T(!0),className:Mt({className:v?"bg-raised text-fg":"text-muted"}),children:e.jsx(q,{name:"more"})})]})}),lt?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:ze({variant:"primary"}),children:[e.jsx(q,{name:"terminal"}),d.atelier.ompTerminal]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("main",{ref:B,onScroll:_,"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:[((Nt=i.daemon)==null?void 0:Nt.checklist)&&i.checklists.get(s)&&e.jsx(ju,{checklist:i.checklists.get(s),current:(js=u==null?void 0:u.checklist)==null?void 0:js.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)&&jt!==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,jt)}),!pt&&G.length===0&&e.jsx("p",{className:"text-center text-meta text-muted",role:"status",children:p?d.thread.loading:d.thread.unavailable}),pt&&G.length===0&&e.jsx("p",{className:"text-center text-meta text-muted",children:d.thread.empty}),G.map(Se=>e.jsx(Lj,{item:Se,store:t,storage:n,inPanel:!!l,onReconnect:a,keys:c&&!l},Se.key))]}),ie&&e.jsx("div",{className:"relative h-0",children:e.jsxs("button",{type:"button",onClick:z,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]})}),De.kind==="open"?e.jsx(Ej,{name:u.name,focusAtEnd:w,composer:c&&Xa()?{...Z,placeholder:`${Z.placeholder} · ${d.sessions.keysHint}`}:Z,draft:g,onDraft:C,onSend:Ze,fresh:p,taken:ee,checking:(K==null?void 0:K.phase)==="uncertain"&&p,error:pe,onReconnect:a,images:j,dialog:be,...(We=i.daemon)!=null&&We.commands&&u.tool==="claude"&&!u.readOnly?{slash:{tool:d.tools[u.tool],listing:i.commands[s],ask:()=>t.requestCommands(s)}}:{},alert:Me&&e.jsx(Ku,{error:Me,fresh:p,onRetry:()=>Fe("close"),onReconnect:a}),...tn(i.daemon,u)?{lead:e.jsx(Gg,{store:t,session:u}),leadNote:e.jsx(Xg,{store:t,session:u})}:{}}):e.jsx(Rj,{ending:De.kind==="ended"&&((Rt=De.error)==null?void 0:Rt.op)===L?{...De,error:null}:De,name:u.name,canResume:he,resumeHeld:Om(u,h,Ie,o),readOnly:!!u.readOnly,fresh:p,focus:P,onResume:()=>Fe("resume"),onReconnect:a},De.kind),e.jsx(Gu,{store:t,forge:r,session:u,wide:x,threshold:((Lt=i.device)==null?void 0:Lt.contextNear)??vn,onModel:()=>E(!0)})]}),v&&e.jsx(fi,{store:t,session:u,closable:he&&!lt,closing:fe,onClose:()=>T(!1),onModel:()=>{T(!1),E(!0)},onCloseSession:()=>{T(!1),Fe("close")}}),A&&tn(i.daemon,u)&&e.jsx(fl,{store:t,session:u,onClose:()=>E(!1)}),M&&e.jsx(Ni,{store:t,session:u,mode:M,onClose:()=>R(null),onSent:()=>{I(!0),R(null)},onReconnect:a})]})}const Hl=new Map,Bo=48;function Vu({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 Gu({store:t,forge:s,session:n,wide:a,threshold:l,onModel:r}){const i=me(t),{daemon:o,fresh:c,usage:x,usageAlert:u}=i,m=Xt(),p=cl(n,m,l),h=d.sessions,g=vu(o,n)===null,y=a?Jf(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:["· ",no(n.context.used)," / ",no(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(ng,{forge:s,mobile:i,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," ",ji(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 Dj={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 Fj({state:t,label:s,tone:n,caps:a=!1}){const{stateLabel:l}=Pr(),r=Dj[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:Tp([["background-color","hover"],["color","hover"]])},children:s??l[t]})}const qo=["monstera","fern","snake","ficus","succulent"],zj=["tl","tr","br","ml","mr"];function Pj(t,s){const n=bn(t),a=1+n%2;return zj.filter(l=>!s.includes(l)).sort((l,r)=>bn(t+l)-bn(t+r)).slice(0,a).map((l,r)=>({spot:l,species:qo[(n+r*7)%qo.length],flip:!!(n>>r&1)}))}const Is={top:56,side:12,bottom:34},Ho=11/12,Xu=t=>t.width>=t.height?"land":"port";function Bj(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(i=>i.h)),l=Math.max(...t.map(i=>i.w));return{zoom:n==="land"?Math.min(1,Math.max(Ho,(s.height-4)/(a+Is.top+Is.bottom))):Math.min(1,Math.max(Ho,(s.width-4)/(l+2*Is.side))),along:n==="land"?"row":"column"}}const qj={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"};function Qa(t){return t.state==="idle"&&(t.helpers??[]).some(s=>s.state!=="exited"&&s.state!=="idle")?"working":qj[t.state]}const Qu=t=>t.state==="waiting_permission"||t.state==="waiting_input",Yu=["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"],Hj=["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"],Uj=["M4 7h16v12H4z","M4 7l2-3h4l2 3","M9 13h6"],Hn=t=>t.topic??t.title;function Ar({session:t,size:s,frozen:n}){const a=sn(),l=Qa(t);return e.jsx(al,{tool:t.tool,state:l,pose:nl(t.id,t.state),size:s,theme:a,seed:t.id,frozen:n,readOnly:!!t.readOnly})}function Uo({helper:t,parent:s,size:n,frozen:a}){const l=sn(),r=`${s.id}:${t.id}`,i=Uc(t);return e.jsx(al,{tool:s.tool,state:i,pose:nl(r,i),size:n,theme:l,seed:r,frozen:a,readOnly:!!s.readOnly})}const Zu=({state:t})=>e.jsx(Fj,{state:t}),Ju=({color:t})=>t?e.jsx("i",{className:"side-swatch",style:{background:t}}):e.jsx("i",{className:"filter-none"}),Wj={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 Kj({seed:t,left:s,width:n,avoid:a}){return e.jsx("div",{className:"plants","aria-hidden":"true",style:{left:s,width:n},children:Pj(t,a).map(({spot:l,species:r,flip:i})=>{const o=Wj[r];return e.jsx("span",{className:`plant-spot spot-${l}${i?" flip":""}`,children:e.jsx(o,{})},l)})})}const Wo=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 Vj({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}),Wo(a.state)]}),a.note&&e.jsxs("div",{style:{left:Vm(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}),Wo(a.note.state),a.note.more>0&&e.jsxs("em",{className:"note-more",children:["+",a.note.more]})]})]},a.id))})}function Gj({table:t,project:s,color:n,frozen:a,act:l,helpers:r=!0}){const{length:i,width:o,seats:c,ends:x,notes:u,extra:m,extraCount:p}=Km(t.mains,r,na,_s),h=b=>`calc(50% - ${i/2}px + ${b}px)`,g=Gm(t.mains),y=c.map(({session:b,x:j,side:N})=>{const C=u.get(b.id);return{id:b.id,task:Hn(b),state:Ui(Qa(b)),slot:N,x:j,note:C&&{task:C.helper.task,state:Ui(Uc(C.helper)),more:C.more}}}),w=[...m.mains.map(b=>({key:b.id,el:e.jsx(Ar,{session:b,size:18,frozen:a})})),...m.helpers.map(({helper:b,parent:j})=>({key:`${j.id}:${b.id}`,el:e.jsx(Uo,{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":`${o}px`,"--project":n},children:e.jsxs("div",{className:"table-scene",children:[e.jsx("div",{className:"office-rug",style:{left:h(-_s),right:"auto",width:i+2*_s}}),e.jsxs("div",{className:"rug-labels",style:{left:h(-_s),width:i+2*_s},children:[e.jsxs("div",{className:"room-heading",children:[e.jsx(Ju,{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:Yu,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:w.map(b=>e.jsx("i",{children:b.el},b.key))}),d.atelier.more(p)]})]}),e.jsx(Kj,{seed:t.key,left:h(-_s),width:i+2*_s,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:i},children:e.jsx(Vj,{length:i,sheets:y})}),c.map(({session:b,x:j,side:N})=>{var M;const C=Qa(b);return e.jsxs("button",{type:"button",style:{left:h(j-56)},"data-agent":b.id,"aria-label":d.atelier.seat(b.name,Hn(b)),onClick:()=>l.open(b.id),className:`agent-seat place-${N}${!a&&C==="working"?" seat-working":""}${a?" seat-offline":""}`,children:[e.jsx(Ar,{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:((M=b.rig)==null?void 0:M.role)??"local"}),e.jsx(Zu,{state:C})]},b.id)}),x.map(({helper:b,parent:j,end:N,slot:C,count:M})=>e.jsxs("button",{type:"button",style:{left:h(N==="left"?-70:i+8),right:"auto",top:M>1?C?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(Uo,{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 Xj({project:t,tables:s,rig:n,width:a,act:l,children:r}){const i=s.flatMap(p=>p.mains),o=n?i.filter(p=>p.state!=="exited"):i,c=o.filter(Qu).length,x=o.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":`${Wc}px`,"--room-back":`${Jm}px`,"--table-gap":`${Kc}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:Hj,size:13})}):e.jsx(Ju,{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(i.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:Yu,size:14})})})]}),e.jsx("div",{className:"room-tables",children:r}),e.jsx("span",{className:"room-entrance","aria-hidden":"true",children:d.atelier.entrance})]})}function Qj({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:Uj,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,Hn(a)),onClick:()=>n.open(a.id),children:[e.jsx(Ar,{session:a,size:56,frozen:s}),e.jsxs("span",{className:"unassigned-copy",children:[e.jsx("strong",{children:a.name}),e.jsx("span",{title:Hn(a),children:Hn(a)}),e.jsx("code",{children:a.project})]})]}),e.jsx("div",{className:"unassigned-actions",children:e.jsx(Zu,{state:Qa(a)})})]},a.id))})]})}function Yj({count:t,frozen:s,onOpen:n}){const a=sn();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(Xr,{size:80,theme:a,frozen:s})}),e.jsx("strong",{children:"Ledge"}),e.jsx("small",{children:d.atelier.assistant})]})})}function Zj(){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 ex=.3,Jj=2.5,e1=2.2,Er=t=>Math.min(Jj,Math.max(ex,t)),t1=(t,s)=>Er(s>0?t*1.2:t/1.2);function s1(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 n1(t,s){const n=Math.min(e1,Math.max(ex,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 a1=8,l1=320,r1=30,i1="button,a,[role=button],.unassigned-card",o1=".atelier-room,.unassigned-zone",c1=12;let ks={zoom:null,left:0,top:0};function d1(t){const s=f.useRef(null),n=f.useRef(null),[a,l]=f.useState(1),[r,i]=f.useState(ks.zoom),o=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 C={width:b.clientWidth,height:b.clientHeight};x.current={w:b.offsetWidth,h:b.offsetHeight};const M=Xu(C);N.padding=`${Is.top}px ${Is.side}px ${Is.bottom}px`,N.flexWrap="wrap",N.width="max-content",N.maxWidth="none",N.minHeight="",N.alignContent="flex-start",N.gap="0 8px";const R=j.querySelector(".ledge-corner");N.setProperty("--ledge-clear",`${R?Math.max(0,R.offsetTop+R.offsetHeight+c1-Is.top):0}px`);const v=[...j.querySelectorAll(o1)].map(E=>({w:E.offsetWidth,h:E.offsetHeight})).filter(E=>E.w>0),{zoom:T,along:A}=Bj(v,C,M);if(A==="row")N.flexWrap="nowrap",N.width="max-content",N.justifyContent="flex-start";else{const E=Math.max(0,...v.map(P=>P.w))+2*Is.side;N.flexWrap="wrap",N.width=`${E}px`,N.maxWidth=`${E}px`,N.justifyContent="center"}v.length===0&&(N.width=`${C.width}px`,N.minHeight=`${C.height}px`),l(T),o.current=c.current??T,N.zoom=String(o.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,C;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),(C=(N=globalThis.document)==null?void 0:N.fonts)==null||C.ready.then(()=>m.current()),()=>j.disconnect()},[]);const p=(b,j,N)=>{const C=s.current,M=n.current;o.current=b,c.current=b,i(b),ks.zoom=b,!(!C||!M)&&(M.style.zoom=String(b),C.scrollLeft=j,C.scrollTop=N)},h=b=>{const j=s.current,N=Er(b);if(!j){p(N,0,0);return}const{left:C,top:M}=s1({zoom:o.current,left:j.scrollLeft,top:j.scrollTop},N,{x:j.clientWidth/2,y:j.clientHeight/2});p(N,C,M)},g=b=>h(t1(o.current,b)),y=()=>{c.current=null,i(null),ks.zoom=null,u();const b=s.current;b&&(b.scrollLeft=0,b.scrollTop=0)},w=b=>{const j=s.current;if(!j)return;const N=o.current,C=j.getBoundingClientRect(),M=b.getBoundingClientRect(),R={x:(j.scrollLeft+M.left-C.left)/N,y:(j.scrollTop+M.top-C.top)/N,w:M.width/N,h:M.height/N};if(R.w<=0||R.h<=0)return;const{zoom:v,left:T,top:A}=n1(R,{width:j.clientWidth,height:j.clientHeight});p(v,T,A)},S=f.useRef({setZoom:p,fit:y,frame:w});return S.current={setZoom:p,fit:y,frame:w},f.useEffect(()=>{const b=s.current;if(!b)return;const j=new Map;let N=null,C=null,M=null,R=!1;const v=($,O)=>({x:($.x+O.x)/2,y:($.y+O.y)/2,d:Math.hypot($.x-O.x,$.y-O.y)}),T=()=>{const[$,O]=[...j.values()];if(N=null,C=null,$&&O){const U=v($,O),D=b.getBoundingClientRect(),K=o.current;N={d:Math.max(U.d,1),zoom:K,x:(b.scrollLeft+U.x-D.left)/K,y:(b.scrollTop+U.y-D.top)/K}}else $&&(C={x:$.x,y:$.y,left:b.scrollLeft,top:b.scrollTop,moved:!1})},A=$=>{$.pointerType!=="mouse"&&(j.size===0&&(R=!1),j.set($.pointerId,{x:$.clientX,y:$.clientY}),T())},E=$=>{if(!j.has($.pointerId))return;j.set($.pointerId,{x:$.clientX,y:$.clientY});const[O,U]=[...j.values()];if(N&&O&&U){const D=v(O,U),K=b.getBoundingClientRect(),te=Er(N.zoom*D.d/N.d);S.current.setZoom(te,N.x*te-(D.x-K.left),N.y*te-(D.y-K.top))}else if(C){const D=$.clientX-C.x,K=$.clientY-C.y;if(!C.moved&&Math.hypot(D,K)<a1)return;C.moved=!0,b.scrollLeft=C.left-D,b.scrollTop=C.top-K}},P=$=>{if(!j.has($.pointerId))return;(C!=null&&C.moved||N)&&(R=!0);const O=j.size===1&&C!==null&&!C.moved;if(j.delete($.pointerId),T(),!O||$.type==="pointercancel")return;const U=$.target instanceof Element?$.target:null,D=$.timeStamp;if(M&&D-M.at<l1&&Math.hypot($.clientX-M.x,$.clientY-M.y)<r1&&!(U!=null&&U.closest(i1))){M=null;const K=U==null?void 0:U.closest(".atelier-room");K?S.current.frame(K):S.current.fit();return}M={at:D,x:$.clientX,y:$.clientY}},I=$=>{R&&(R=!1,$.preventDefault(),$.stopPropagation())},L=()=>{ks.left=b.scrollLeft,ks.top=b.scrollTop};return b.addEventListener("pointerdown",A),b.addEventListener("pointermove",E),b.addEventListener("pointerup",P),b.addEventListener("pointercancel",P),b.addEventListener("click",I,!0),b.addEventListener("scroll",L,{passive:!0}),()=>{b.removeEventListener("pointerdown",A),b.removeEventListener("pointermove",E),b.removeEventListener("pointerup",P),b.removeEventListener("pointercancel",P),b.removeEventListener("click",I,!0),b.removeEventListener("scroll",L)}},[]),{scrollRef:s,shellRef:n,zoom:r??a,fitted:r===null,zoomTo:h,step:g,fit:y}}const u1=["M15 3h6v6","M9 21H3v-6","M21 3l-7 7","M3 21l7-7"],x1=80;function tx({label:t,onClose:s,children:n}){const a=f.useRef(null),l=f.useRef(null),[r,i]=f.useState(0),o=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:Xu({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||i(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;i(0),p>x1&&s()};return e.jsxs("aside",{ref:a,className:"atelier-panel","aria-label":t,onPointerDown:o,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),i=!r.fresh,o=n.map(u=>r.sessions.get(u)).filter(u=>u!==void 0),c=o.filter(u=>u.state!=="exited").map(u=>u.id);return e.jsxs(tx,{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(o.length)})]}),e.jsx("button",{type:"button",onClick:l,"aria-label":d.atelier.closePanel,title:d.atelier.closeTitle,className:Mt({}),children:e.jsx(q,{name:"close"})})]}),e.jsxs("main",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:[o.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(ll,{tool:u.tool,seed:u.id,state:u.state,frozen:i}),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(la,{...gp(u)})]},u.id)}),((x=r.daemon)==null?void 0:x.broadcast)&&c.length>0&&e.jsx("div",{className:"pt-4",children:c.length>Fa?e.jsx("p",{className:"text-meta text-attention",children:d.agents.tooMany(c.length,Fa)}):e.jsx(Jc,{store:t,label:s,ids:c,offline:i})})]})]})}function p1(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 Ko=`${$s}sessions.helpers`,Vo=`${$s}sessions.groupBy`;function f1({store:t,sessionId:s,requestKey:n,storage:a,onReconnect:l}){var L;const r=me(t),i=!r.fresh,o=f.useMemo(()=>[...r.sessions.values()],[r.sessions]),c=f.useMemo(()=>o.map($=>({...$,cwd:$.project})),[o]),x=f.useMemo(()=>Qm(c,r.projects,$=>$.projectId??null,"all",!0,({id:$,name:O,kind:U})=>({id:$,name:O,color:Zm(U)})),[c,r.projects]),[u,m]=f.useState(null),[p,h]=f.useState(()=>{var $;try{return(($=Qe(a))==null?void 0:$.getItem(Ko))!=="hidden"}catch{return!0}}),[g,y]=f.useState(()=>{var $;try{return(($=Qe(a))==null?void 0:$.getItem(Vo))==="rigs"?"rigs":"projects"}catch{return"projects"}}),w=$=>{var O;y($);try{(O=Qe(a))==null||O.setItem(Vo,$)}catch{}},S=()=>{var O;const $=!p;h($);try{(O=Qe(a))==null||O.setItem(Ko,$?"shown":"hidden")}catch{}},b=d1([x,i]),j=$=>{m(null),s?ms({name:"atelier",sessionId:$}):en({name:"atelier",sessionId:$})},N=()=>ms({name:"atelier"}),C={open:j,room:$=>{s&&N(),m($)},chat:()=>en({name:"chat"})},M=o.filter($=>$.state!=="exited").length,R=o.filter(Qu).length,v=`${i?`${d.agents.offline} · `:""}${d.atelier.subtitle(M,R,Xc(o).working)}`,T=u?p1(x,u):null,A=x.rooms.filter($=>!$.rig),E=x.rooms.filter($=>$.rig),P=g==="rigs"?[...E,...A]:[...A,...E],I=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:Wr.map($=>e.jsx("button",{type:"button","aria-pressed":$===g,onClick:()=>w($),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.jsxs("button",{type:"button","aria-pressed":!p,onClick:S,className:Oe({size:"sm",className:"flex-none"}),children:[e.jsx(q,{name:"eye",className:"size-4"}),p?d.sessions.helpersHide:d.sessions.helpersShow]}),e.jsx(il,{})]}),e.jsx("div",{className:"mb-3 flex-none empty:hidden",children:e.jsx(gs,{})}),e.jsxs("div",{className:`atelier-ipad${i?" 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:u1,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${i?" office-paused":""}`,children:[e.jsx(Yj,{count:M,frozen:i,...(L=r.device)!=null&&L.chat?{onOpen:C.chat}:{}}),e.jsx("div",{className:`project-grid ${P.length===1?"focused":""}`,children:P.map(({project:$,tables:O,rig:U})=>e.jsx(Xj,{project:$,tables:O,...U?{rig:U}:{},width:ep(O,na,_s),act:C,children:O.map(D=>e.jsx(Gj,{table:D,project:$,color:jn[$.color],frozen:i,act:C,helpers:p},D.key))},$.id))}),e.jsx(Qj,{sessions:x.unassigned,frozen:i,act:C})]})}),e.jsx(Zj,{})]})]})]}),s&&e.jsx(tx,{label:d.atelier.session((I==null?void 0:I.name)??""),onClose:N,children:n?e.jsx(Nr,{store:t,sessionId:s,requestKey:n,onReconnect:l,panel:{onBack:()=>ms({name:"atelier",sessionId:s}),onClose:N}},`${s}:request`):e.jsx(Mr,{store:t,sessionId:s,storage:a,onReconnect:l,panel:{onClose:N}},s)}),!s&&T&&u&&e.jsx(m1,{store:t,name:T.name,ids:T.ids,onOpen:j,onClose:()=>m(null)})]})}const h1=500,g1=10;function sx(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 i;l(),a.current=!0;try{(i=navigator.vibrate)==null||i.call(navigator,10)}catch{}t()};return{onPointerDown:i=>{i.button>0||(a.current=!1,n.current={x:i.clientX,y:i.clientY},l(),s.current=setTimeout(r,h1))},onPointerMove:i=>{const o=n.current;o&&Math.hypot(i.clientX-o.x,i.clientY-o.y)>g1&&l()},onPointerUp:l,onPointerCancel:l,onPointerLeave:l,onContextMenu:i=>{i.preventDefault(),a.current||r()},onClickCapture:i=>{a.current&&(i.preventDefault(),i.stopPropagation(),a.current=!1)}}}function nx({store:t,session:s,current:n,onLeave:a,onReconnect:l,display:r,model:i,onModel:o}){var v,T;const c=me(t),x=Xt(),[u,m]=f.useState(!1),[p,h]=f.useState(!1),g=i??p,y=o??h,[w,S]=f.useState(!1),b=Sn(s),j=Et(),N=rl(),C=n==="terminal"&&j&&!N&&[s.project,s.branch].filter(Boolean).join(" · ")||void 0,M=!!((v=c.daemon)!=null&&v.sessionClose)&&!s.readOnly,R=Hr(s,c.ops,((T=c.daemon)==null?void 0:T.boot)??null,x);return e.jsxs(e.Fragment,{children:[e.jsx(aa,{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:C,more:e.jsxs(e.Fragment,{children:[e.jsx(Vu,{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:Mt({className:u?"bg-raised text-fg":"text-muted"}),children:e.jsx(q,{name:"more"})})]})}),u&&e.jsx(fi,{store:t,session:s,closable:M,closing:R,onClose:()=>m(!1),onModel:()=>{m(!1),y(!0)},onCloseSession:()=>{m(!1),S(!0)},display:r&&{value:r.value,onToggle:()=>{r.onToggle(),m(!1)}}}),g&&tn(c.daemon,s)&&e.jsx(fl,{store:t,session:s,onClose:()=>y(!1)}),w&&e.jsx(Ni,{store:t,session:s,mode:"close",onClose:()=>S(!1),onSent:()=>S(!1),onReconnect:l})]})}function b1({store:t,session:s,onDone:n}){var m,p;const a=me(t),l=Xt(),[r,i]=f.useState("menu"),o=!!((m=a.daemon)!=null&&m.sessionClose)&&!s.readOnly,c=Hr(s,a.ops,((p=a.daemon)==null?void 0:p.boot)??null,l),x=s.rig?d.sessions.seatOf(s.rig.role??s.name,s.rig.name):s.project,u=h=>{n(),en(h)};return r==="model"?tn(a.daemon,s)?e.jsx(fl,{store:t,session:s,onClose:n}):null:r==="close"?e.jsx(Ni,{store:t,session:s,mode:"close",onClose:n,onSent:n}):e.jsx(fi,{store:t,session:s,closable:o,closing:c,onClose:n,who:x,onModel:()=>i("model"),onCloseSession:()=>i("close"),lead:[{icon:"sessions",label:d.atoi.openThread,onClick:()=>u({name:"thread",sessionId:s.id})},{icon:"terminal",label:d.thread.terminal(s.name),onClick:()=>u({name:"terminal",sessionId:s.id})}]})}function j1({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:Wr.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 Go="inline-flex items-center gap-1.5 rounded-lg border bg-bg px-2.5 select-none [-webkit-touch-callout:none]";function y1({session:t,rig:s,helpers:n,pressed:a,onPress:l}){const r=sx(()=>l(t)),i=Sn(t),o=i==="perm"?"border-destructive/50":i==="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:`${Go} h-10 text-[13px] font-medium ${o} ${t.state==="exited"?"opacity-60":""} ${a?"shadow-[0_0_0_2px_var(--color-ring)]":""}`,children:[!s&&e.jsx(fs,{tool:t.tool}),t.name,e.jsx(_e,{state:i}),!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:`${Go} h-8 border-dashed border-line text-[12px] text-muted`,children:[u.kind,e.jsx(_e,{state:np(u)})]},u.id))]})}function N1({island:t,rigs:s,helpers:n,pressed:a,onPress:l}){const r=d.sessions,i=t.kind==="rig",o=sp(t),c=i?t.name==="kernel"&&s?r.kernelTag:r.rigTag:null,x=i?r.seats(t.sessions.length):d.atelier.plaqueCounts(t.sessions.length);return e.jsxs("section",{"aria-label":i?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)] ${i?"border-task/45":"border-line"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 text-[13px]",children:[i&&e.jsx(_e,{state:"rig"}),e.jsx("b",{className:"font-semibold",children:t.name}),o&&e.jsx(_e,{state:o}),c?e.jsx("small",{className:"text-[12px] text-muted",children:c}):e.jsx("small",{className:"text-[12px] text-muted",children:x}),i&&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(y1,{session:u,rig:i,helpers:n,pressed:a===u.id,onPress:l},u.id))})]})}function k1({sessions:t,by:s,onBy:n,helpers:a,onHelpers:l,rigs:r,pressed:i,onPress:o}){const c=sn(),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(Xr,{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(j1,{by:s,onBy:n,helpers:a,onHelpers:l}),tp(t,s).map(p=>e.jsx(N1,{island:p,rigs:r,helpers:a,pressed:i,onPress:o},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 Xo=`${$s}sessions.filter`,v1=t=>Vc.includes(t);function w1(t,s){const n=Qe(s),[a,l]=f.useState(()=>{if(t)return t;try{const i=n==null?void 0:n.getItem(Xo);return v1(i)?i:"all"}catch{return"all"}}),r=i=>{l(i);try{n==null||n.setItem(Xo,i)}catch{}};return f.useEffect(()=>{t&&r(t)},[t]),[a,r]}function Ul(t,s,n,a){const l=Qe(a),[r,i]=f.useState(()=>{try{const c=l==null?void 0:l.getItem(`${$s}${t}`);return s.includes(c)?c:n}catch{return n}});return[r,c=>{i(c);try{l==null||l.setItem(`${$s}${t}`,c)}catch{}}]}const ax=["list","atelier"];function S1({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:ax.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 $1({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:Vc.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 C1({session:t,filter:s,offline:n,threshold:a,now:l,closing:r,pressed:i,onPress:o,woken:c}){const x=sa(),u=sx(()=>o(t)),m=(x.name==="thread"||x.name==="terminal")&&x.sessionId===t.id,p=Sn(t),h=ap(t),g=Qc(t),y=s==="working"?g===void 0?void 0:`${g} %`:rp(t);return e.jsx(Ys,{href:ne({name:"thread",sessionId:t.id}),selected:m,stale:n,press:u,pressed:i,lead:e.jsxs(e.Fragment,{children:[e.jsx(_e,{state:p,pulse:p==="work"&&!n}),e.jsx(fs,{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]"})}),h>0&&e.jsx("span",{"aria-label":d.sessions.kidsLabel(h),className:"ml-1.5 font-mono text-small text-muted",children:d.sessions.kids(h)})]}),sub:r?e.jsx("span",{className:"text-attention",children:d.chat.closing}):e.jsx("span",{className:p==="ask"?"text-attention":void 0,children:lp(t,s,l)}),...p==="perm"?{subTone:"perm"}:{},...y!==void 0?{meta:y,metaWarn:s==="working"&&g!==void 0&&g/100>=a}:{}})}function M1({group:t,children:s}){const n=t.kind==="rig",a=n?d.sessions.rigGroup(t.name):t.name;return e.jsxs("section",{"aria-label":a,className:"flex flex-col gap-1.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-0.5 text-small font-semibold text-muted",children:[n&&e.jsx(_e,{state:"rig"}),a,e.jsx("span",{className:"font-normal",children:t.sessions.length})]}),e.jsx(rs,{...n?{tone:"rigs"}:{},children:s})]})}function A1({routines:t,now:s,offline:n}){const a=d.routines,l=Pf(t,s);return l.count===0?null:e.jsx(rs,{label:a.entry,children:e.jsxs(Ys,{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 E1({store:t,filter:s,storage:n}){var I,L;const a=me(t),l=Xt(),[r,i]=w1(s,n),o=Et(),[c,x]=Ul("sessions.mode",ax,"list",n),[u,m]=Ul("sessions.groupBy",Wr,"projects",n),[p,h]=Ul("sessions.helpers",["shown","hidden"],"shown",n),[g,y]=f.useState(null),w=g?a.sessions.get(g):void 0,S=!o&&c==="atelier",b=[...a.sessions.values()],j=Xc(b),N=Gc(b,r),C=!a.fresh,M=Bf(a.routines,b),R=((I=a.device)==null?void 0:I.contextNear)??vn,v=C?a.syncedAt?d.link.lastKnownAt(Pe(a.syncedAt)):d.agents.offline:void 0,T=e.jsxs("a",{href:ne({name:"launch"}),className:Oe({variant:"primary",size:"sm",className:"flex-none"}),children:[e.jsx(q,{name:"plus",className:"size-4"}),d.sessions.new]}),A=($,O)=>e.jsx("button",{type:"button",onClick:()=>i($),className:Oe({size:"xs"}),children:O}),E=d.sessions,P=N.length===0&&b.length>0&&e.jsx(rs,{label:E.filter[r],children:r==="waiting"?e.jsx(Zt,{framed:!1,glyph:null,title:E.filterEmpty,body:E.filterEmptyBody(j.working),action:A("all",E.seeAll)}):j.waiting>0?e.jsx(Zt,{framed:!1,glyph:null,title:E.emptyWorking.title,body:E.emptyWorking.waiting(j.waiting),action:A("waiting",E.seeWaiting)}):e.jsx(Zt,{framed:!1,glyph:null,title:E.emptyWorking.title,body:E.emptyWorking.idle,action:A("all",E.seeAll)})});return e.jsxs(As,{title:d.agents.title,subtitle:v,bodyClassName:"flex flex-col gap-2.5",actions:o?void 0:e.jsxs(e.Fragment,{children:[e.jsx(S1,{value:c,onChange:x}),T]}),wideActions:o?T:void 0,children:[w&&e.jsx(b1,{store:t,session:w,onDone:()=>y(null)}),a.routines&&e.jsx(A1,{routines:a.routines,now:l,offline:C}),b.length===0?e.jsx(rs,{label:d.agents.empty,children:e.jsx(Zt,{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:Oe({variant:"primary",size:"sm"}),children:[e.jsx(q,{name:"plus",className:"size-4"}),d.sessions.newSession]})})}):S?e.jsx(k1,{sessions:b,by:u,onBy:m,helpers:p==="shown",onHelpers:()=>h(p==="shown"?"hidden":"shown"),rigs:!!((L=a.daemon)!=null&&L.rigs),pressed:g,onPress:$=>y($.id)}):e.jsxs(e.Fragment,{children:[e.jsx($1,{value:r,counts:j,onChange:i}),N.map($=>e.jsx(M1,{group:$,children:$.sessions.map(O=>e.jsx(C1,{session:O,filter:r,offline:C,threshold:R,now:l,closing:Dm(O,a.ops,l),pressed:g===O.id,onPress:U=>y(U.id),woken:M.has(O.id)},O.id))},$.id)),P]})]})}const Qo=34,R1=120;function T1({value:t,onChange:s,onSend:n,canSend:a,images:l,running:r,offline:i,onStop:o,fieldRef:c}){const x=f.useRef(null),u=c??x;f.useLayoutEffect(()=>{const p=u.current;p&&(p.style.height=`${Qo}px`,p.style.height=`${Math.min(R1,Math.max(Qo,p.scrollHeight))}px`)},[t,u]);const m=r||i;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(Ru,{items:l.items,onRemove:l.remove,size:{w:72,h:54},removeLabel:d.images.remove,lang:Ac}),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)] ${i?"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:i?"":t,disabled:i,maxLength:ea,enterKeyHint:"enter",placeholder:r?d.chat.answering:d.chat.placeholder,onChange:p=>s(p.target.value),onPaste:p=>{const h=_u(p);h.length===0||m||(p.preventDefault(),l.add(h))},onKeyDown:p=>{p.key!=="Enter"||p.nativeEvent.isComposing||p.shiftKey||!Xa()||(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:o,"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(Tu,{onFiles:l.add,disabled:m,className:"text-[12px] leading-4 text-muted disabled:opacity-50",children:d.chat.plusImage}),Xa()&&e.jsxs("span",{children:["· ",d.chat.enterSends]})]}),l.error&&e.jsx("p",{role:"alert",className:"text-body text-attention",children:l.error})]})}const Wl=ze({variant:"primary",size:"sm",className:"min-w-[64px] flex-none"}),Na=ze({size:"sm",className:"min-w-[64px] flex-none"}),Kl="w-full rounded-control border border-line bg-surface px-2.5 py-2 text-body text-fg",mn=t=>t.replace(/\s*[\r\n]+\s*/g," ").trim();function _1({task:t,store:s,fresh:n}){const a=d.chat.point.note,l=t.brain,r=f.useId(),[i,o]=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),[w,S]=f.useState(null),b=async C=>{y(!0),S(null);const M=mn(c),R=C?{yes:C,...M&&M!==l.fact?{text:M}:{},...l.create&&mn(u)?{title:mn(u)}:{},...l.create&&mn(p)?{when:mn(p)}:{}}:{yes:C},v=await s.answerNote(t.id,R);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(la,{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:Kl,value:u,disabled:N,onChange:C=>m(C.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:Kl,value:p,disabled:N,onChange:C=>h(C.target.value)})]})]}),i?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:Kl,rows:3,value:c,disabled:N,onChange:C=>x(C.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&&!i&&e.jsx("span",{className:"break-words text-small text-muted",children:a.source(l.source)}),w&&e.jsx("p",{role:"alert",className:"m-0 text-small text-approval",children:w}),e.jsx("div",{className:"flex flex-wrap gap-2",children:l.kind==="flag"?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Wl,disabled:N,onClick:()=>{b(!0)},children:a.mark}),e.jsx("button",{type:"button",className:Na,disabled:N,onClick:()=>{b(!1)},children:a.ignore})]}):i?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Wl,disabled:N||!mn(c),onClick:()=>{b(!0)},children:a.editYes}),e.jsx("button",{type:"button",className:Na,disabled:N,onClick:()=>{o(!1),x(l.fact)},children:a.cancel})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Wl,disabled:N,onClick:()=>{b(!0)},children:l.create?a.createYes:a.yes}),e.jsx("button",{type:"button",className:Na,disabled:N,onClick:()=>o(!0),children:a.edit}),e.jsx("button",{type:"button",className:Na,disabled:N,onClick:()=>{b(!1)},children:a.no})]})})]})}const Ln=ze({size:"sm",className:"min-w-[64px] flex-none"}),I1=ze({variant:"primary",size:"sm",className:"min-w-[64px] flex-none"}),Yo="mt-1 text-meta tracking-[.4px] text-muted";function ka({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 L1(t){return t.state==="done"?d.chat.point.finished:t.state==="refused"?d.chat.point.refused:d.chat.point.dropped}function O1({store:t,sessions:s,tasks:n,syncedAt:a,fresh:l,threshold:r=vn,onAnswer:i,usage:o=[],usageAlert:c=null}){const x=Xt(),[u,m]=f.useState(null),p=new Map(s.map(v=>[v.id,v])),h=Vt(s),g=Rf(n.values()),y=Tf(n.values()),w=s.filter(v=>v.state!=="exited"&&!v.handover&&v.context&&v.context.used/v.context.window>=r),S=_f(n.values()).slice(0,5),b=d.chat.point,j=da(o,x,l),N=l?Zf(j,c,x):[],C=h.length+N.length+g.length+y.length+w.length,M=(v,T,A)=>{const E=h.find(P=>P.sessionId===v&&P.key===T);E&&(m(`${v}/${T}`),t.decide(v,A,{expect:{key:E.key,kind:E.kind,text:E.text}}))},R=v=>{t.seeTask(v.id),en({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))})]}),C===0&&e.jsx("p",{className:"text-body text-muted",children:b.calm}),C>0&&e.jsxs("div",{role:"group","aria-label":b.yoursLabel,className:"flex flex-col gap-2",children:[e.jsxs("h3",{className:Yo,children:[b.yours," · ",C]}),h.map(v=>{p.get(v.sessionId);const T=v.kind==="permission"&&v.risk!=="high"&&v.source!=="rpc",A=`${v.sessionId}/${v.key}`;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ka,{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)})]}),T?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:I1,disabled:!l||u===A,onClick:()=>M(v.sessionId,v.key,"accept"),children:b.yes}),e.jsx("button",{type:"button",className:Ln,disabled:!l||u===A,onClick:()=>M(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})]},A)}),N.map(({harness:v,window:T,tone:A})=>{const E=ji(T);return e.jsxs("div",{"data-usage-over":A,className:"flex items-center gap-2","aria-label":A==="red"?b.reachedLabel(b.harnessShort[v]??v,E):b.overLabel(b.harnessShort[v]??v,E,T.pct),children:[e.jsx("span",{"aria-hidden":"true",className:`flex size-5 flex-none items-center justify-center rounded-md ${A==="red"?"bg-danger-bg text-approval":"text-attention"}`,style:A==="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," · ",E," ",e.jsx("b",{className:`font-medium ${yi[A]}`,children:d.percent(T.pct)})]}),T.resetsAt&&e.jsxs("span",{className:"flex-none whitespace-nowrap text-small text-muted",children:["↺ ",ai(T.resetsAt,x,!0)]})]},`usage:${v}:${T.kind}:${T.model??T.pool??""}`)}),g.map(v=>v.brain?e.jsx(_1,{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(ka,{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(la,{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})]}),i&&e.jsx("button",{type:"button",className:Ln,"aria-label":b.answerLabel(v.title),onClick:()=>i(v),children:b.answer})]},`decision:${v.id}`)),y.map(v=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ka,{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:L1(v)})]}),e.jsx("button",{type:"button",className:Ln,onClick:()=>R(v),children:b.see})]},v.id)),w.map(v=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(ka,{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(nj,{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:Yo,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 Yt=()=>d.chat.history,La=t=>{const s=new Date(t);return`${s.getHours()}:${String(s.getMinutes()).padStart(2,"0")}`},va=t=>`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`;function lx(t,s){const n=new Date(t);if(va(n)===va(s))return Yt().today;const a=new Date(s);return a.setDate(s.getDate()-1),va(n)===va(a)?Yt().yesterday:n.toLocaleDateString(st,{weekday:"short",day:"numeric",month:"short"})}const D1=(t,s)=>`${lx(t.startedAt,s)}, ${La(t.startedAt)}`,F1="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",z1="px-1 pt-1.5 text-[12px] font-medium text-muted";function Vl({first:t,sub:s,current:n=!1,onClick:a}){return e.jsxs("button",{type:"button",onClick:a,"aria-current":n||void 0,className:`${F1} ${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:Yt().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 Gl({children:t}){return e.jsx("div",{className:"flex max-h-[55vh] flex-col overflow-y-auto rounded-[10px] border border-line",children:t})}function P1({conversations:t,kept:s,turns:n,running:a,now:l,onClose:r,onReset:i,onOpen:o,onScrollTo:c}){const x=f.useId();if(!s){const p=n.filter(h=>h.question);return e.jsxs(ct,{labelledBy:x,onClose:r,children:[e.jsx("h2",{id:x,className:"text-base font-semibold",children:Yt().today}),p.length===0?e.jsx("p",{className:"text-body text-muted",children:Yt().none}):e.jsx(Gl,{children:p.map(h=>e.jsx(Vl,{first:h.question,sub:La(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=lx(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(ct,{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:Yt().title}),e.jsxs("button",{type:"button",disabled:a,onClick:i,className:Oe({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(Gl,{children:e.jsx(Vl,{current:!0,first:u.current.first,onClick:r,sub:[Yt().current,Yt().count(u.current.count),Yt().since(La(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:z1,children:p.day}),e.jsx(Gl,{children:p.items.map(h=>e.jsx(Vl,{first:h.first,sub:`${Yt().count(h.count)} · ${La(h.startedAt)}`,onClick:()=>o(h)},h.id))})]},p.day))]}),e.jsx("p",{className:"text-small text-muted",children:Yt().kept})]}),u&&!u.current&&m.length===0&&e.jsx("p",{className:"text-body text-muted",children:Yt().empty})]})}const Rr=3,Tr=t=>`${t.sessionId}/${t.key}`;function B1(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 q1({store:t,items:s,onGo:n}){const a=fr(s.slice(0,Rr).map(r=>({id:Tr(r),value:r}))),l=s.length-Rr;return a.entries.length===0?null:e.jsxs("div",{className:bi,children:[a.entries.map(r=>e.jsx(H1,{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 H1({store:t,item:s,ghost:n,onGone:a,onGo:l}){var c,x,u;const r=me(t),i=Ds(),o=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(li,{store:t,item:s,session:o,mode:Gr(s,(c=r.capabilities)==null?void 0:c[s.tool],(o==null?void 0:o.readOnly)===!0),outcome:Vn(s,[...r.sessions.values()],r.ops),fresh:r.fresh,ghost:n,changed:!1,onReread:()=>{},canConfirm:((x=r.device)==null?void 0:x.confirm)===!0&&i,enroll:i&&((u=r.device)==null?void 0:u.confirm)!==!0,onGone:a,onCheck:l})]})}function U1({names:t}){return t.length===0?null:e.jsx("div",{className:bi,children:t.map(s=>e.jsxs("span",{className:"text-[11.5px] text-muted",children:[d.chat.inAnswer.settled," · ",s]},s))})}const W1="kernel";function K1(t,s){var l,r,i;const n=(r=(l=t.find(o=>o.rig&&o.rig.name!==W1))==null?void 0:l.rig)==null?void 0:r.name,a=(i=t.find(o=>o.name&&!o.rig))==null?void 0:i.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 Oa="grid size-11 flex-none place-items-center rounded-lg text-muted active:bg-raised disabled:opacity-40";function rx({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(hs,{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(ix,{onClose:s})]})}function ix({onClose:t}){return e.jsx("button",{type:"button",onClick:t,"aria-label":d.chat.pane.close,title:d.chat.pane.close,className:Oa,children:e.jsx(q,{name:"close"})})}function Zo({store:t,onClose:s}){var G,X,re,ie,ce;const n=me(t),a=Et(),l=Ic(t),r=[...n.sessions.values()],[i,o]=f.useState(""),c=Bu(t),[x,u]=f.useState(null),m=f.useRef(null),p=l.live!==null,h=!n.fresh,g=Fm(t),y=!!((G=n.daemon)!=null&&G.conversations),[w,S]=f.useState(!1),[b,j]=f.useState(null),N=f.useRef(new Map);uu(t);const C=f.useRef(null),[M,R]=f.useState(0);f.useEffect(()=>{const z=C.current;!M||!z||(z.focus(),z.setSelectionRange(z.value.length,z.value.length))},[M]);const v=z=>{u(null),o(d.chat.point.answerDraft(z.title,z.id,z.giverName??d.chat.point.someone)),R(k=>k+1)},T=f.useRef([]);f.useEffect(()=>{const z=l.error;(z==null?void 0:z.text)!==void 0&&(o(k=>k||z.text),T.current.length&&(c.putBack(T.current),T.current=[]),u(z.code==="offline"?null:{question:z.text,note:z.code==="busy"?d.chat.busy:d.chat.failed}),t.clearChatError())},[l.error,t]),f.useEffect(()=>{var z,k;(k=(z=m.current)==null?void 0:z.scrollIntoView)==null||k.call(z,{block:"end"})},[l.turns.length,(X=l.live)==null?void 0:X.text,(re=l.live)==null?void 0:re.steps.length,x]);const A=(z,k=[])=>{u(null),t.ask(z,k)},E=()=>{const z=i.trim();if(!z&&c.items.length===0||p||h||!c.ready)return;const k=c.ids();T.current=c.clear(),A(z,k),o("")},P=r.map(z=>({id:z.id,name:z.name,repo:z.repo,exited:z.state==="exited",state:z.state,helpers:z.helpers})),I=()=>{u(null),t.resetChat()},L=new Map,$=new Set;for(const z of r)z.name&&(L.has(z.name)?$.add(z.name):L.set(z.name,z.id));for(const z of $)L.delete(z);const O=Vt(r),U=new Set(O.map(Tr)),D=l.turns.at(-1),K=!p&&(D==null?void 0:D.answer)!==void 0?D:void 0,te=K?(()=>{const z=B1(K.steps,L);return O.filter(k=>z.has(k.sessionId))})():[];if(K){const z=N.current.get(K.qid)??new Map;for(const k of te.slice(0,Rr))z.set(Tr(k),k.botName);N.current.set(K.qid,z)}const V=z=>z===(K==null?void 0:K.qid)?e.jsx(q1,{store:t,items:te}):e.jsx(U1,{names:[...new Set([...N.current.get(z)??[]].filter(([k])=>!U.has(k)).map(([,k])=>k))]}),F=z=>({at:z,usage:n.usage??[],alert:n.usageAlert,fresh:n.fresh}),B=()=>{t.askConversations(),S(!0)},Y=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:Oa,children:e.jsx(q,{name:"clock"})}),e.jsx("button",{type:"button",disabled:p,onClick:I,"aria-label":d.chat.reset,title:d.chat.reset,className:Oa,children:e.jsx(q,{name:"edit"})})]});if(b){const z=g.open[b.id];return e.jsxs(e.Fragment,{children:[e.jsx(aa,{name:D1(b,new Date),back:e.jsx("button",{type:"button","aria-label":d.nav.backTo.chat,title:d.nav.backTo.chat,onClick:()=>j(null),className:Mt({className:"text-muted"}),children:e.jsx(q,{name:"back"})}),...s?{more:e.jsx(ix,{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:[z&&"gone"in z&&e.jsx("p",{className:"px-1 text-body text-muted",children:d.chat.history.gone}),z&&"turns"in z&&z.turns.map(k=>{const _=z.limits.find(W=>W.qid===k.qid);return e.jsx(Oo,{store:t,turn:k,list:P,canConfirm:!1,live:null,sessions:r.length,readOnly:!0,limits:_&&F(_.at)},k.qid)})]}),e.jsx("div",{className:"flex-none pt-1.5 pb-3",children:e.jsx("button",{type:"button",onClick:()=>j(null),className:Oe({variant:"primary",className:"w-full"}),children:d.chat.history.backToday})})]})}return e.jsxs(e.Fragment,{children:[s?e.jsx(rx,{frozen:h,onClose:s,children:Y}):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(hs,{size:28,frozen:h})}),e.jsx("h1",{children:d.chat.title})]}),e.jsx(il,{}),e.jsx("span",{className:"flex-1"}),Y,!a&&e.jsx("a",{href:ne({name:"connection"}),"aria-label":d.nav.settings,title:d.nav.settings,className:Oa,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(gs,{}),l.turns.length===0&&!x&&e.jsxs("div",{className:"flex flex-1 flex-col justify-end gap-2.5",children:[e.jsx(O1,{store:t,sessions:r,tasks:n.tasks,syncedAt:n.syncedAt,fresh:n.fresh,onAnswer:v,...((ie=n.device)==null?void 0:ie.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:[K1(r,new Date).map(z=>e.jsx("button",{type:"button",onClick:()=>A(z),className:"inline-flex h-[34px] items-center gap-1.5 rounded-full border border-input bg-surface px-3 text-[13px] text-fg",children:z},z)),((ce=n.daemon)==null?void 0:ce.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(z=>{var k,_;return e.jsx("div",{id:`turn-${z.qid}`,className:"contents",children:e.jsx(Oo,{store:t,turn:z,list:P,canConfirm:!!((k=n.device)!=null&&k.confirm),live:((_=l.live)==null?void 0:_.qid)===z.qid?l.live:null,sessions:r.length,...!p&&!h?{onAskAgain:W=>A(W)}:{},limits:l.limits[z.qid]!==void 0?F(l.limits[z.qid]):void 0,inAnswer:V(z.qid)})},z.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(T1,{value:i,onChange:o,onSend:E,canSend:(i.trim()!==""||c.items.length>0)&&c.ready&&!p&&!h,images:c,running:p,offline:h,onStop:()=>t.cancelAsk(),fieldRef:C}),h&&e.jsx("p",{role:"status",className:"flex-none pb-2 text-[13px] text-attention",children:d.chat.offline}),w&&e.jsx(P1,{conversations:g,kept:y,turns:l.turns,running:p,now:new Date,onClose:()=>S(!1),onReset:()=>{S(!1),I()},onOpen:z=>{S(!1),t.openConversation(z.id),j(z)},onScrollTo:z=>{var k,_,W;S(!1),(W=(_=(k=document.getElementById(`turn-${z}`))==null?void 0:k.firstElementChild)==null?void 0:_.scrollIntoView)==null||W.call(_,{block:"start"})}})]})}const Jn=(t,s)=>(t.slice(0,s===void 0?void 0:s*4).match(/.{1,4}/g)??[]).join(" "),ox=t=>Jn(t,6),V1=t=>Jn(t,2);function cx(){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 G1=t=>{const s=atob(t.replace(/-/g,"+").replace(/_/g,"/"));return Uint8Array.from(s,n=>n.charCodeAt(0))};function dx(t,s){return new Promise(n=>{const a=()=>{var i;const r=(i=t.getState().ops[s])==null?void 0:i.phase;return!r||xs(r)&&r!=="uncertain"?!1:(l(),n(r==="applied"?"applied":"other"),!0)},l=t.subscribe(a);a()})}async function X1(t,s=(n,a)=>globalThis.fetch(n,a)){var a;if(cx()==="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 i=r.publicKey,o=G1(i),{pushManager:c}=await navigator.serviceWorker.ready;await((a=await c.getSubscription())==null?void 0:a.unsubscribe());const x=await c.subscribe({userVisibleOnly:!0,applicationServerKey:o}),u=lm.safeParse(x.toJSON());if(!u.success)return"failed";const m=t.pushSubscribe(u.data,i);return m===null?"failed":await dx(t,m)==="applied"?"on":"failed"}catch{return"failed"}}async function Q1(t){const s=t.pushUnsubscribe(),n=s!==null&&await dx(t,s)==="applied";try{await(await navigator.serviceWorker.ready).pushManager.getSubscription().then(a=>a==null?void 0:a.unsubscribe())}catch{}return n}const Ct=d.notifications,Y1=t=>t==="denied"?Ct.denied:t==="unsupported"?Ct.unsupported:t==="unavailable"?Ct.noPush:t==="failed"?Ct.failed:null;function ux(t,s){var x;const n=(x=me(t).device)==null?void 0:x.push,[a,l]=f.useState(!1),[r,i]=f.useState(null);return{push:n,busy:a,problem:r,enable:async()=>{if(a)return"failed";l(!0),i(null);const u=await X1(t,s);return l(!1),i(Y1(u)),u},disable:async()=>{a||(l(!0),i(null),await Q1(t),l(!1))}}}function Z1({store:t,fetchImpl:s}){const n=ux(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:Ct.row}),e.jsx("dd",{className:"flex min-w-0 items-center gap-3 text-right",children:n.push==="unavailable"?e.jsx("span",{children:Ct.noPush}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:a?Ct.on:Ct.off}),e.jsx(ml,{on:a,label:Ct.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:Ct.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:Ct.enable})]}),n.problem&&e.jsx(Ge,{title:n.problem,tone:"warning",role:"alert"})]})}const Jo=t=>(t==="off"||t==="stale")&&cx()!=="unsupported";function ec({store:t,onDone:s,fetchImpl:n,body:a=Ct.body}){const l=ux(t,n),r=me(t).fresh,i=()=>{l.enable().then(o=>{o==="on"&&(en({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:Ct.title}),e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:a}),l.problem&&e.jsx(Ge,{title:l.problem,tone:"warning",role:"alert"}),e.jsx("button",{type:"button",disabled:l.busy||!r,onClick:i,className:bt,children:l.busy?Ct.working:r?Ct.enable:Ct.waiting})]}),e.jsx("a",{href:ne({name:"atoi"}),onClick:s,className:dt,children:Ct.later})]})}function J1(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 Ae=d.connection.pcUpdate,Un="flex flex-col gap-3 rounded-card border bg-surface p-3.5";function ey({store:t,action:s,pc:n,from:a,to:l,onClose:r}){var h;const i=f.useId(),o=!!((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(J1(g,Ae.notDone))},()=>m({text:Ae.notDone,quiet:!1})).finally(()=>x(!1))};return e.jsxs(ct,{labelledBy:`${i}-title`,onClose:()=>{c||r()},children:[e.jsx("h2",{id:`${i}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:s==="update"?Ae.confirmUpdate:Ae.confirmRestart}),e.jsx("p",{className:"text-body text-muted",children:s==="update"?Ae.confirmUpdateBody(n,a,l):Ae.confirmRestartBody(n)}),e.jsx("p",{className:`rounded-control border border-dashed border-input px-3 py-2 text-small ${o?"text-muted":"text-attention"}`,children:o?Ae.passkey:Ae.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(Ue,{variant:"ghost",className:"flex-1",disabled:c,onClick:r,children:Ae.cancel}),e.jsx(Ue,{variant:"primary",className:"flex-[2]",disabled:c||!o,onClick:p,children:Ae.confirm})]})]})}function ty({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:Ae.steps[l]})]},l))})}function sy({store:t,run:s,fresh:n,from:a,onRetry:l}){const r=s.action==="update";return Oc(s)?e.jsxs("div",{className:`${Un} 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?Ae.updating(s.version):Ae.restarting}),e.jsx("span",{className:"text-meta text-info",children:Ae.running})]}),e.jsx(ty,{run:s,fresh:n}),e.jsx("p",{className:"text-small text-muted",children:Ae.leave})]}):s.step==="done"?e.jsxs("div",{className:`${Un} 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?Ae.done(s.version):Ae.restarted}),e.jsx("span",{className:"text-meta text-ok",children:Ae.upToDate})]}),e.jsx(Ue,{onClick:()=>t.dismissPc(),children:Ae.close})]}):e.jsxs("div",{className:`${Un} 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?Ae.failed:Ae.notRestarted}),e.jsx("span",{className:"text-meta text-danger-fg",children:Ae.refused})]}),e.jsxs("p",{className:"text-small text-muted",children:[Ae.unchanged(a)," ",s.reason?Ae.reasons[s.reason]:""]}),e.jsx(Ue,{onClick:l,children:Ae.retry})]})}function ny({store:t,appVersion:s}){const n=me(t),[a,l]=f.useState(null),r=n.daemon,i=n.pc;if(!r)return null;const o=s!==null&&Lc(r.version,s);if(!o&&!r.restart&&!i)return null;const c=r.name,x=()=>{t.dismissPc(),((i==null?void 0:i.action)==="restart"||s)&&l((i==null?void 0:i.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:Ae.title}),i?e.jsx(sy,{store:t,run:i,fresh:n.fresh,from:r.version,onRetry:x}):o&&(r.update?e.jsxs("div",{className:`${Un} border-input`,children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("strong",{className:"text-body",children:Ae.behind}),e.jsx("span",{className:"font-mono text-small text-muted",children:Ae.versions(r.version,s)})]}),e.jsx("p",{className:"text-small text-muted",children:Ae.why}),e.jsx(Ue,{variant:"primary",block:!0,disabled:!n.fresh,onClick:()=>l("update"),children:Ae.update}),e.jsx("p",{className:"text-meta text-muted",children:Ae.keepGoing})]}):e.jsxs("div",{className:`${Un} border-attention/40`,children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("strong",{className:"text-body",children:Ae.manual}),e.jsx("span",{className:"font-mono text-small text-muted",children:Ae.versions(r.version,s)})]}),e.jsx("p",{className:"text-small text-muted",children:r.restart?Ae.clone:Ae.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:Ae.restart}),e.jsx("span",{className:"text-small text-muted",children:Ae.restartHint})]}),e.jsx(Ue,{size:"sm",disabled:!n.fresh||Oc(i),onClick:()=>l("restart"),children:Ae.restartGo})]}),a&&e.jsx(ey,{store:t,action:a,pc:c,from:r.version,to:a==="update"&&s?s:r.version,onClose:()=>l(null)})]})}const bl="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",He=d.settings,jl="flex flex-col rounded-[10px] border border-line bg-surface text-body",ki="flex flex-col gap-1 border-b border-line px-4 py-3 last:border-b-0",ay=Array.from({length:Math.round((cm-Li)*20)+1},(t,s)=>Math.round((Li+s*.05)*100)),ly=["finished","chat","decision"],ry=["pc","claude","codex","cursor","omp"];function vi({label:t,hint:s,children:n}){const a=f.useId();return e.jsxs("div",{className:ki,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 iy(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 oy(t,s){const n=t.toLocaleTimeString(st,{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()?He.tomorrow(n):`${t.toLocaleDateString(st,{day:"numeric",month:"short"})} ${n}`}function xx(t){var u;const s=me(t),[n,a]=f.useState(null),[l,r]=f.useState(!1),i=f.useRef(0),o=f.useRef(!0);return f.useEffect(()=>()=>{o.current=!1},[]),{prefs:n??((u=s.device)==null?void 0:u.prefs)??om,send:m=>{const p=++i.current;a(m),r(!1),t.setDevicePrefs(m).then(h=>{!o.current||p!==i.current||(a(null),h.status!=="applied"&&r(!0))})},failed:l,fresh:s.fresh}}function cy({store:t}){var c,x;const s=me(t),n=xx(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,i=r!==null&&r.getTime()>a,o=u=>n.send({...l,quietUntil:iy(u,new Date(a)).toISOString()});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:jl,children:[ly.map(u=>e.jsx(vi,{label:He.notify[u],hint:He.notify[`${u}Hint`],children:m=>e.jsx(ml,{on:l.notify[u],label:He.notify[u],describedBy:m,disabled:!n.fresh,onChange:p=>n.send({...l,notify:{...l.notify,[u]:p}})})},u)),e.jsxs("div",{className:ki,children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{children:He.pause}),i&&e.jsx("span",{role:"status",className:"text-right text-attention",children:He.pausedUntil(oy(r,new Date(a)))})]}),e.jsx("p",{className:"text-small text-muted",children:He.pauseHint}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-2",children:i?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:He.resume}):["hour","four","morning"].map(u=>e.jsx("button",{type:"button","aria-label":He.pauseLabel[u],disabled:!n.fresh,onClick:()=>o(u),className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 font-medium disabled:opacity-45",children:He.pauseFor[u]},u))})]})]}),e.jsx("p",{className:"text-small text-muted",children:He.notify.always}),n.failed&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:He.failed})]})}function dy({store:t}){var m,p;const s=me(t),n=xx(t),[a,l]=f.useState(null),[r,i]=f.useState(!1),o=f.useRef(!0);if(f.useEffect(()=>()=>{o.current=!1},[]),!((m=s.daemon)!=null&&m.settings)||!((p=s.device)!=null&&p.prefs))return null;const c=Math.round((a??s.device.contextNear??vn)*100),x=h=>{l(h/100),i(!1),t.setContextNear(h/100).then(g=>{o.current&&(l(null),g.status!=="applied"&&i(!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:He.ledge}),e.jsxs("div",{className:jl,children:[e.jsx(vi,{label:He.context,hint:He.contextHint,children:h=>e.jsx("select",{className:`${bl} w-auto`,"aria-label":He.context,"aria-describedby":h,disabled:!s.fresh||a!==null,value:c,onChange:g=>x(Number(g.target.value)),children:ay.map(g=>e.jsx("option",{value:g,children:d.percent(g)},g))})}),s.device.chat&&e.jsxs("div",{className:ki,children:[e.jsx("span",{children:He.chatTool}),e.jsx("p",{className:"text-small text-muted",children:He.chatToolHint}),e.jsx("div",{className:"mt-1",children:e.jsx(Zn,{name:"chat-tool",legend:He.chatTool,value:u,options:ry.map(h=>({value:h,label:He.tools[h]})),onChange:h=>{s.fresh&&n.send({...n.prefs,chatTool:h==="pc"?null:h})}})}),e.jsx("p",{className:"text-meta text-muted",children:He.toolPcHint})]})]}),!s.fresh&&e.jsx("p",{className:"text-small text-muted",children:He.offline}),(r||n.failed)&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:He.failed})]})}function uy(){const t=rm();return e.jsx("div",{className:jl,children:e.jsx(vi,{label:He.motion,hint:He.motionHint,children:s=>e.jsx(ml,{on:t,label:He.motion,describedBy:s,onChange:im})})})}function xy({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:He.managed}),(s==null?void 0:s.terminal)&&e.jsx("dl",{className:jl,children:e.jsxs("div",{className:"flex items-baseline justify-between gap-4 px-4 py-3",children:[e.jsx("dt",{className:"text-muted",children:He.terminal}),e.jsx("dd",{children:s.terminalInput?He.allowed:He.notAllowed})]})}),e.jsx("p",{className:"text-small text-muted",children:He.managedBody})]})}const le=d.settings.projects,mx=Object.keys(jn),my=80,yl=t=>le.errors[t.status==="rejected"?t.reason:t.status]??le.errors.failed;function py(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 fy({color:t}){return e.jsx("span",{className:"size-3 flex-none rounded-full",style:{background:jn[t]},"aria-hidden":"true"})}function hy({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:le.color}),e.jsx("div",{className:"flex flex-wrap gap-2",children:mx.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":le.colors[a]}),e.jsx("span",{className:"size-6 rounded-full",style:{background:jn[a]},"aria-hidden":"true"})]},a))})]})}function gy({store:t,project:s,projects:n,onClose:a,onDelete:l,onFolders:r}){var I,L;const i=f.useId(),o=new Set(n.map($=>$.color)),[c,x]=f.useState((s==null?void 0:s.name)??""),[u,m]=f.useState((s==null?void 0:s.color)??mx.find($=>!o.has($))??"blue"),[p,h]=f.useState(!1),[g,y]=f.useState(null),w=me(t),S=s===null&&!!((I=w.daemon)!=null&&I.projectFolders),b=!!((L=w.device)!=null&&L.confirm),[j,N]=f.useState(null),[C,M]=f.useState(!1);f.useEffect(()=>{S&&t.requestRecentFolders()},[t,S]);const R=c.trim(),v=R!==""&&n.some($=>$.id!==(s==null?void 0:s.id)&&Di($.name)===Di(R)),T=s!==null&&R===s.name&&u===s.color,A=S&&(j===null||!b),E=()=>{if(!R||v||p||A)return;if(T){a();return}h(!0),y(null);const $=s?{...R!==s.name?{name:R}:{},...u!==s.color?{color:u}:{}}:null;(s?t.editProject(s.id,$):t.createProject(R,u,S?j:void 0)).then(O=>{h(!1),O.status==="applied"?a():y(yl(O))})};if(C)return e.jsxs(ct,{labelledBy:`${i}-title`,onClose:()=>M(!1),children:[e.jsx("h2",{id:`${i}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:le.firstFolder}),e.jsx(px,{store:t,busy:!1,skip:()=>!1,rowLabel:le.choose,rowAria:le.chooseLabel,pickLabel:le.chooseThis,pickAria:le.chooseLabel,pickDisabled:!1,error:null,onPick:$=>{N($),M(!1)},onBack:()=>M(!1)})]});const P=[...new Set([...j!==null?[j]:[],...w.recentFolders??[]])];return e.jsxs(ct,{labelledBy:`${i}-title`,onClose:()=>{p||a()},children:[e.jsx("h2",{id:`${i}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:s?le.editTitle:le.newTitle}),!s&&e.jsx("p",{className:"text-body text-muted",children:S?le.newBody:le.newBodyOld}),e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:$=>{$.preventDefault(),E()},children:[e.jsxs("label",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"text-small text-muted",children:le.name}),e.jsx("input",{className:bl,value:c,maxLength:my,autoFocus:!0,"aria-invalid":v||void 0,onChange:$=>x($.target.value)}),v&&e.jsx("span",{role:"alert",className:"text-small text-danger-fg",children:le.errors.name_taken})]}),e.jsx(hy,{name:`${i}-color`,value:u,onChange:m}),S&&e.jsxs("section",{"aria-labelledby":`${i}-first`,className:"flex flex-col gap-1.5",children:[e.jsxs("h3",{id:`${i}-first`,className:"flex items-center gap-2 text-small text-muted",children:[le.firstFolder,e.jsx("span",{className:"rounded-full border border-task/45 px-2 text-meta text-task",children:le.required})]}),P.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{className:"text-meta tracking-[.06em] text-muted uppercase",children:le.recents}),e.jsx("ul",{className:"flex flex-col rounded-control border border-line",children:P.map($=>e.jsxs("li",{className:Wn,children:[e.jsxs("button",{type:"button","aria-pressed":j===$,"aria-label":le.chooseLabel($),disabled:p,onClick:()=>N($),className:`flex min-h-10 min-w-0 flex-1 items-center gap-2 text-left ${j===$?"font-medium text-fg":""}`,children:[e.jsx(q,{name:j===$?"check":"folder",className:"size-4 flex-none"}),e.jsx("span",{className:"font-mono text-small break-all",children:$})]}),j===$&&e.jsx("span",{className:"text-meta text-ok",children:le.chosen})]},$))})]}),e.jsx(Ue,{size:"sm",className:"self-start",disabled:p,onClick:()=>M(!0),children:le.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:le.pickFirst}),!b&&e.jsx("p",{className:"text-small text-attention",children:le.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(Ue,{variant:"ghost",className:"flex-1",disabled:p,onClick:a,children:le.cancel}),e.jsx(Ue,{variant:"primary",type:"submit",className:"flex-[2]",disabled:p||!R||v||A,children:s?le.save:le.create})]}),s&&r&&e.jsx(Ue,{disabled:p,onClick:r,children:le.folders}),s&&e.jsx(Ue,{variant:"ghost",className:"text-danger-fg!",disabled:p,onClick:l,children:le.remove})]})]})}function by({store:t,project:s,projects:n,agents:a,onClose:l}){var y;const r=f.useId(),i=!!((y=me(t).device)!=null&&y.confirm),o=n.filter(w=>w.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(w=>{m(!1),w.status==="applied"?l():h(yl(w))})};return e.jsxs(ct,{labelledBy:`${r}-title`,onClose:()=>{u||l()},children:[e.jsx("h2",{id:`${r}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:le.deleteTitle(s.name)}),e.jsx("p",{className:"text-body text-muted",children:le.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:le.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)}),le.noProject]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:`${r}-move`,checked:c!==null,disabled:o.length===0,onChange:()=>{var w;return x(((w=o[0])==null?void 0:w.id)??null)}}),le.moveTo]}),c!==null&&e.jsx("select",{className:bl,"aria-label":le.target,value:c,onChange:w=>x(w.target.value),children:o.map(w=>e.jsx("option",{value:w.id,children:w.name},w.id))})]}),e.jsx("p",{className:`rounded-control border border-dashed border-input px-3 py-2 text-small ${i?"text-muted":"text-attention"}`,children:i?le.passkey:le.noPasskey}),p&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:p}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ue,{variant:"ghost",className:"flex-1",disabled:u,onClick:l,children:le.cancel}),e.jsx(Ue,{variant:"primary",className:"flex-[2]",disabled:u||!i,onClick:g,children:le.confirmDelete})]})]})}const jy=t=>t.machine==="local"?le.thisPc:t.label??t.machine,yy=t=>t.split("/").filter(Boolean).at(-1)??"/",Wn="flex items-center gap-3 border-b border-line px-3 py-2.5 last:border-b-0";function Ny({store:t,project:s,onClose:n}){var S;const a=f.useId(),l=me(t),[r,i]=f.useState(!1),[o,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(yl(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,()=>i(!1)))},w=()=>{o||n()};if(r){const b=Array.isArray(m)?m:[];return e.jsxs(ct,{labelledBy:`${a}-title`,onClose:w,children:[e.jsx("h2",{id:`${a}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:le.pickTitle}),e.jsx(px,{store:t,busy:o,skip:j=>b.some(N=>N.machine==="local"&&N.path===j),rowLabel:le.addShort,rowAria:le.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?le.folderPasskey:le.noPasskey}),error:x,pickLabel:le.addThis,pickAria:le.addThisLabel,pickDisabled:!p,onBack:()=>{i(!1),u(null)}})]})}return e.jsxs(ct,{labelledBy:`${a}-title`,onClose:w,children:[e.jsx("h2",{id:`${a}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:le.foldersTitle(s.name)}),m===void 0?e.jsx("p",{role:"status",className:"text-small text-muted",children:le.foldersLoading}):m==="gone"?e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:le.errors.stale}):m.length===0?e.jsx("p",{className:"text-body text-muted",children:le.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:Wn,children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"font-medium",children:yy(b.path)}),e.jsxs("span",{className:"font-mono text-meta break-all text-muted",children:[b.path," · ",jy(b)]})]}),e.jsx(Ue,{size:"sm",variant:"ghost","aria-label":le.removeFolderLabel(b.path),disabled:o||!l.fresh||m.length===1,onClick:()=>g(b),children:le.removeFolder})]},`${b.machine}
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:le.lastFolder}),x&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:x}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ue,{variant:"ghost",className:"flex-1",disabled:o,onClick:n,children:le.close}),e.jsxs(Ue,{variant:"primary",className:"flex-[2]",disabled:o||!l.fresh||m==="gone",onClick:()=>{u(null),i(!0)},children:[e.jsx(q,{name:"plus",className:"size-4"}),le.addFolder]})]})]})}function px({store:t,busy:s,skip:n,rowLabel:a,rowAria:l,onPick:r,note:i,error:o,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,w=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":le.recents,className:"flex flex-col gap-1.5",children:[e.jsx("h3",{className:"text-small text-muted",children:le.recents}),e.jsx("ul",{className:"flex flex-col rounded-control border border-line",children:b.map(j=>e.jsxs("li",{className:Wn,children:[e.jsx("span",{className:"min-w-0 flex-1 font-mono text-small break-all",children:j}),e.jsx(Ue,{size:"sm","aria-label":l(j),disabled:s||u,onClick:()=>r(j),children:a})]},j))})]}),e.jsxs("section",{"aria-label":le.browse,className:"flex flex-col gap-1.5",children:[e.jsx("h3",{className:"text-small text-muted",children:le.browse}),w?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"font-mono text-small break-all",children:w.path}),w.error&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:le.folderErrors[w.error]}),e.jsxs("ul",{className:"flex flex-col rounded-control border border-line",children:[w.parent&&e.jsx("li",{className:Wn,children:e.jsxs("button",{type:"button",className:"flex min-h-10 flex-1 items-center gap-2 text-left",onClick:()=>S(w.parent),children:[e.jsx(q,{name:"back",className:"size-4"}),le.parent]})}),w.entries.map(j=>{const N=w.repos.find(C=>C.name===j);return e.jsx("li",{className:Wn,children:e.jsxs("button",{type:"button","aria-label":le.open(j),className:"flex min-h-10 min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>S(`${w.path==="/"?"":w.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)}),!w.error&&w.entries.length===0&&e.jsx("li",{className:"px-3 py-2.5 text-small text-muted",children:le.empty})]}),w.cut&&e.jsx("p",{className:"text-meta text-muted",children:le.cut})]}):e.jsx("p",{role:"status",className:"text-small text-muted",children:le.loadingFolder})]})]}),e.jsx("p",{className:"text-small text-muted",children:le.onlyThisPc}),i,o&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:o}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ue,{variant:"ghost",className:"flex-1",disabled:s,onClick:m,children:le.back}),e.jsx(Ue,{variant:"primary",className:"flex-[2]",disabled:s||u||!w||!!w.error,"aria-label":w?x(w.path):c,onClick:()=>{w&&r(w.path)},children:c})]})]})}function ky({store:t}){var w;const s=me(t),[n,a]=f.useState(null),[l,r]=f.useState(null),[i,o]=f.useState(null),[c,x]=f.useState(!1),[u,m]=f.useState(null);if(!((w=s.daemon)!=null&&w.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(py(p.map(j=>j.id),S,b)).then(j=>{x(!1),j.status!=="applied"&&m(yl(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:le.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:le.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(fy,{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:le.agents(h(S.id))})]}),e.jsx(Oi,{label:le.up(S.name),disabled:g||b===0,onClick:()=>y(b,-1),children:e.jsx(q,{name:"arrowUp",className:"size-4"})}),e.jsx(Oi,{label:le.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(Ue,{size:"sm","aria-label":le.editLabel(S.name),disabled:!s.fresh,onClick:()=>a(S),children:le.edit})]},S.id))]}),e.jsxs(Ue,{disabled:!s.fresh,onClick:()=>a("new"),children:[e.jsx(q,{name:"plus",className:"size-4"}),le.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?le.folders_note:le.folders_note_old}),n!==null&&e.jsx(gy,{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"&&(o(n),a(null))}:null}),i&&e.jsx(Ny,{store:t,project:i,onClose:()=>o(null)}),l&&e.jsx(by,{store:t,project:l,projects:p,agents:h(l.id),onClose:()=>r(null)})]})}const ss=d.connection.device,fx=t=>{var s,n;return t??zm(((s=globalThis.navigator)==null?void 0:s.userAgent)??"",((n=globalThis.navigator)==null?void 0:n.maxTouchPoints)??0)};function vy({store:t,pinned:s}){const n=me(t),[a,l]=f.useState(null),[r,i]=f.useState(!1),o=n.device;if(!(o!=null&&o.id))return null;const c=fx(o.name),x=s?new Date(s.pinnedAt).toLocaleDateString(st,{day:"numeric",month:"short",year:"numeric"}):null,u=(a==null?void 0:a.trim())??"",m=()=>{if(!(!u||u.length>vl)){if(t.renameDevice(u)===null){i(!0);return}i(!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:ss.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:o.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:ss.linkedOn(x)})]}),e.jsx(Ue,{size:"sm","aria-label":ss.renameLabel(c),onClick:()=>{i(!1),l(c)},children:ss.rename})]}),r&&e.jsx("p",{role:"status",className:"text-small text-danger-fg",children:ss.failed}),e.jsx("p",{className:"text-small text-muted",children:ss.others}),a!==null&&e.jsxs(ct,{labelledBy:"rename-title",onClose:()=>l(null),children:[e.jsx("h2",{id:"rename-title",className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:ss.sheetTitle}),e.jsx("p",{className:"text-body text-muted",children:ss.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:ss.field}),e.jsx("input",{className:bl,value:a,maxLength:vl,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,"/",vl]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ue,{variant:"ghost",className:"flex-1",onClick:()=>l(null),children:ss.cancel}),e.jsx(Ue,{variant:"primary",type:"submit",className:"flex-[2]",disabled:!u,children:ss.save})]})]})]})]})}const tt=d.connection,Ws=d.settings,wy=()=>[{value:"system",label:tt.themes.system},{value:"light",label:tt.themes.light},{value:"dark",label:tt.themes.dark}],Sy=t=>t==="ready"?tt.states.online:t==="handshaking"?tt.states.connecting:tt.states.offline;function $y({store:t,login:s,relay:n,pinned:a,linkState:l,build:r,onSignOut:i,fetchImpl:o,section:c}){var y,w,S;const x=me(t),u=dm(),m=Ec();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&&Lc(x.daemon.version,r.version),g=[[tt.account,s?d.account(s):tt.unknown,!1],[tt.relay,n,!0],[tt.pc,p??tt.unknown,!1],[tt.pcFingerprint,a?Jn(a.fingerprint):tt.unknown,!0],[tt.status,Sy(l),!1],[tt.version,(r==null?void 0:r.version)??tt.none,!0],[tt.appFingerprint,r?ox(r.fingerprint):tt.none,!0],[tt.pcVersion,((w=x.daemon)==null?void 0:w.version)??tt.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:tt.back}),e.jsx("h1",{className:"text-base font-semibold",children:tt.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(vy,{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(Zn,{name:"theme",legend:Ws.theme,options:wy(),value:u,onChange:b=>um(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(Zn,{name:"lang",legend:Ws.lang,options:mm.map(b=>({value:b,label:Ws.langs[b],lang:b})),value:m,onChange:xm,fit:!0})]}),e.jsx(uy,{})]}),((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(Z1,{store:t,fetchImpl:o})}),e.jsx(cy,{store:t})]}),e.jsx(dy,{store:t}),e.jsx(ky,{store:t}),e.jsx(ny,{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:tt.section}),e.jsxs("dl",{className:"flex flex-col rounded-[10px] border border-line bg-surface text-body",children:[g.map(([b,j,N,C])=>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":""} ${C??""}`,children:j})]},b)),e.jsx(gh,{store:t}),e.jsx(Nh,{store:t})]})]}),e.jsx(xy,{store:t}),e.jsx("div",{className:"flex-grow","aria-hidden":"true"}),e.jsx("button",{type:"button",onClick:i,className:dt,children:tt.signOut})]})]})}function Cy({onOther:t}){return e.jsxs(St,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(hs,{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($t,{}),e.jsx("button",{type:"button",onClick:t,className:dt,children:d.denied.other})]})}const Qt=d.keyChanged,My=t=>{const s=new Date(t);return Number.isNaN(s.getTime())?d.connection.unknown:s.toLocaleDateString(st,{day:"numeric",month:"short"})};function Ay({pcName:t,known:s,received:n,onRelink:a,onSignOut:l}){return e.jsxs(St,{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:za,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(Jn(s.fingerprint,2),My(s.pinnedAt)):d.connection.unknown}),e.jsx("dt",{className:"text-muted",children:Qt.received}),e.jsx("dd",{className:"font-mono",children:n?Qt.receivedDetail(Jn(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($t,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:a,className:bt,children:Qt.relink}),e.jsx("button",{type:"button",onClick:l,className:dt,children:Qt.signOut})]})]})}const Ey="/auth/github/start";function Ry(t){return t==="denied"?d.login.errors.denied:t==="bad_state"||t==="error"?d.login.errors.failed:null}const Ty=[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 _y({server:t,error:s}){return e.jsxs(St,{children:[e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(hs,{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:`${za} 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($t,{}),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:`${za} text-fg`,viewBox:"0 0 24 24","aria-hidden":"true",children:Ty[a]}),e.jsx("span",{children:n})]},n))}),e.jsxs("a",{href:Ey,className:bt,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 Iy({onHere:t}){return e.jsxs(St,{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($t,{}),e.jsx("button",{type:"button",onClick:t,className:dt,children:d.replaced.here})]})}const _r=t=>e.jsx("a",{href:ne({name:"atoi"}),className:Oe({size:"sm"}),children:t});function wi({label:t,children:s}){return Et()?e.jsx("section",{"aria-label":t,className:"pt-[34px]",children:s}):e.jsx(rs,{label:t,children:s})}function Ly(){const{pc:t}=Ut();return e.jsxs(As,{title:d.prs.title,subtitle:d.prs.subtitle,children:[e.jsx(wi,{label:d.prs.title,children:e.jsx(Zt,{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 Oy(){const{pc:t}=Ut();return e.jsx(As,{title:d.rigs.title,subtitle:d.rigs.subtitle,children:e.jsx(wi,{label:d.rigs.title,children:e.jsx(Zt,{glyph:e.jsx(q,{name:"rigs",className:"size-[22px]"}),title:d.rigs.notSent(Ht(t)),body:d.rigs.notSentBody,action:_r(d.rigs.seeAtoi)})})})}function tc({onClose:t}={}){const{pc:s}=Ut();return t?e.jsxs(e.Fragment,{children:[e.jsx(rx,{frozen:!0,onClose:t}),e.jsx("section",{"aria-label":d.chat.title,className:"pt-[34px]",children:e.jsx(Zt,{framed:!1,glyph:e.jsx(hs,{size:64,frozen:!0}),title:d.chat.unavailable.title(Ht(s)),body:d.chat.unavailable.body,action:_r(d.chat.unavailable.seeAtoi)})})]}):e.jsx(As,{title:d.chat.title,children:e.jsx(wi,{label:d.chat.title,children:e.jsx(Zt,{framed:!1,glyph:e.jsx(hs,{size:64,frozen:!0}),title:d.chat.unavailable.title(Ht(s)),body:d.chat.unavailable.body,action:_r(d.chat.unavailable.seeAtoi)})})})}function sc({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 Dy({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 i=a.current;if(!i)return;const o=c=>{t&&c.target instanceof HTMLElement&&c.target.tagName==="MAIN"&&(r.current=c.target.scrollTop)};return i.addEventListener("scroll",o,!0),()=>i.removeEventListener("scroll",o,!0)},[t]),f.useEffect(()=>{var c;if(!t)return;const i=(c=a.current)==null?void 0:c.querySelector("main");i&&r.current!==null&&(i.scrollTop=r.current);const o=x=>{x.key!=="Escape"||x.defaultPrevented||x.isComposing||Nd()||(x.preventDefault(),l.current())};return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[t]),e.jsx("aside",{ref:a,hidden:!t,"aria-label":d.chat.title,"data-ledge-pane":"",className:"lpane",children:n})}const hx="ledge.mobile.ledgePane",Ir=new Set;let Lr=null;function Fy(t){var s;if(Lr!==null)return Lr;try{return((s=Qe(t))==null?void 0:s.getItem(hx))==="open"}catch{return!1}}function nc(t,s){var n;Lr=t;try{(n=Qe(s))==null||n.setItem(hx,t?"open":"closed")}catch{}for(const a of Ir)a()}const zy=t=>(Ir.add(t),()=>{Ir.delete(t)});function Py(t){return f.useSyncExternalStore(zy,()=>Fy(t),()=>!1)}function ac({store:t,id:s,onDone:n}){var p,h,g;const a=me(t),l=Ds(),r=(p=a.asks)==null?void 0:p.find(y=>y.id===s),i=f.useRef(void 0);r&&(i.current=r);const o=r??i.current,c=n??(()=>sl({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=o?e.jsx(Dd,{store:t,ask:o,end:ld(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(ra,{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 wa=d.storage;function By({onRetry:t,onReload:s}){return e.jsxs(St,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:qt,children:wa.title}),e.jsx("p",{className:"text-muted",children:wa.body})]}),e.jsx($t,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:t,className:bt,children:wa.retry}),e.jsx("button",{type:"button",onClick:s,className:dt,children:wa.reload})]})]})}const qy=30,Hy=/^(?:\x1b\[\??\d+(?:;\d+)*[Rc]|\x1b\[[?>][\d;]*c|\x1b\][0-9]+;rgb:[0-9a-f/]+(?:\x07|\x1b\\)|\x1b\[[IO])$/i,Uy={phase:"connecting",cols:80,rows:24,readOnly:!1,held:null,holding:!1,released:null,exit:null,refused:null,holdRefused:null};function Wy(t){if(t.length<=Fi)return t;let s=Fi;const n=t.charCodeAt(s-1);return n>=55296&&n<=56319&&(s-=1),t.slice(0,s)}function Ky(t,s){return`\x1B[H\x1B[2J\x1B[3J${t.replace(/\n/g,`\r
19
+ `)}\x1B[${s.y+1};${s.x+1}H`}class Vy{constructor(s,n,a,l=()=>crypto.randomUUID()){Pt(this,"view",Uy);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:i=>{this.holdOp=null,this.set({holding:!1,holdRefused:i}),r(i)}},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||Hy.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()},qy)))}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=Wy(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(Ky(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 Gy=11,rk=6,ik=16,lc=5*6e4,Xy={up:"A",down:"B",right:"C",left:"D"};function Qy(t,s){switch(t){case"esc":return"\x1B";case"tab":return" ";case"enter":return"\r";case"interrupt":return"";default:return`${s?"\x1BO":"\x1B["}${Xy[t]}`}}function Yy(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 Zy(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(),i=/^(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:i})}return n}const $e=d.terminal.live2,gx="ledge.mobile.terminalView",Jy=t=>{var s;try{return((s=Qe(t))==null?void 0:s.getItem(gx))==="fit"?"fit":"readable"}catch{return"readable"}},eN=(t,s)=>{var n;try{(n=Qe(s))==null||n.setItem(gx,t)}catch{}};function tN(t){return{send:s=>{t.send(s).catch(()=>{})},onMessage:s=>t.onMessage(s),ready:()=>t.state()==="ready",subscribe:s=>t.subscribe(s)}}const Xl=new Map,sN=t=>{const s=Math.max(0,Math.ceil(t/1e3));return`${Math.floor(s/60)}:${String(s%60).padStart(2,"0")}`},nN=t=>pm(()=>import("./xterm-DbCZs1Jk.js"),__vite__mapDeps([0,1,2,3,4])).then(s=>s.createXterm(t));function aN({store:t,link:s,session:n,storage:a,makeScreen:l,forge:r}){var et,jt,yt,Q;const i=me(t),o=Xt(),c=f.useRef(null),x=f.useRef(null),[u,m]=f.useState(null),[p,h]=f.useState(null),[g,y]=f.useState(()=>Jy(a)),[w,S]=f.useState(!1),[b,j]=f.useState({ctrl:"off",alt:"off"}),[N,C]=f.useState(!1),[M,R]=f.useState(""),[v,T]=f.useState(!1),[A,E]=f.useState(null),[P,I]=f.useState([]),[L,$]=f.useState(!1),O=Et(),U=rl(),D=f.useRef(!0),K=f.useRef(b);K.current=b,f.useEffect(()=>{const H=c.current;if(!H)return;let ye=!1,Te=null;const oe=Ee=>{if(ye){Ee.dispose();return}const nt=new Vy(tN(s),n.id,Ee);Ee.onData(Nt=>nt.type(te(Nt))),nt.start(),Te={c:nt,xt:Ee},m(nt),h(Ee)};return l?oe(l(H)):nN(H).then(oe),()=>{ye=!0,Te==null||Te.c.stop(),Te==null||Te.xt.dispose()}},[s,n.id,l]);const te=H=>{const ye=K.current;if(ye.ctrl==="off"&&ye.alt==="off")return H;const Te=Yy(H,{ctrl:ye.ctrl!=="off",alt:ye.alt!=="off"});return j(oe=>({ctrl:oe.ctrl==="armed"?"off":oe.ctrl,alt:oe.alt==="armed"?"off":oe.alt})),Te},V=f.useSyncExternalStore(H=>u?u.subscribe(H):()=>{},()=>(u==null?void 0:u.state)??null),F=!!(V!=null&&V.held);f.useEffect(()=>{p==null||p.setInput(F),F&&(D.current=!0,p==null||p.focus())},[p,F]),f.useEffect(()=>{!p||!x.current||!V||p.setFont(g==="fit"?p.fitFont(x.current.clientWidth-16):Gy)},[p,g,V==null?void 0:V.cols]),f.useEffect(()=>{if(!p)return;const H=x.current,ye=()=>{if(!H)return;const Te=Xl.get(n.id);if(Te&&H.scrollWidth>=Te.left+H.clientWidth&&H.scrollHeight>=Te.top+H.clientHeight&&(Xl.delete(n.id),H.scrollLeft=Te.left,H.scrollTop=Te.top,D.current=!1),D.current&&g==="readable"){const{x:Ee,cellWidth:nt}=p.cursor(),Nt=Ee*nt;(Nt<H.scrollLeft||Nt>H.scrollLeft+H.clientWidth-nt*4)&&(H.scrollLeft=Math.max(0,Nt-H.clientWidth/2))}E(H.scrollWidth>H.clientWidth+1?{left:H.scrollLeft/H.scrollWidth,width:H.clientWidth/H.scrollWidth}:null);const oe=Zy(p.rows());I(Ee=>Ee.length===oe.length&&Ee.every((nt,Nt)=>nt.digit===oe[Nt].digit&&nt.word===oe[Nt].word)?Ee:oe)};p.onDrawn(ye),ye()},[p,g]);const B=()=>{const H=x.current;H&&Xl.set(n.id,{left:H.scrollLeft,top:H.scrollTop})},Y=()=>{const H=x.current;H&&E(H.scrollWidth>H.clientWidth+1?{left:H.scrollLeft/H.scrollWidth,width:H.clientWidth/H.scrollWidth}:null)},G=f.useRef(null),X=H=>Math.hypot(H[0].clientX-H[1].clientX,H[0].clientY-H[1].clientY),re=H=>{H.touches.length===2&&p?G.current={d:X(H.touches),px:p.font()}:D.current=!1},ie=H=>{if(H.touches.length!==2||!G.current||!p||!x.current)return;const ye=p.fitFont(x.current.clientWidth-16);p.setFont(Math.max(ye,G.current.px*(X(H.touches)/G.current.d)))},ce=()=>{G.current=null},z=H=>{y(H),eN(H,a),D.current=!0},k=H=>{var ye,Te;if(!(!u||!p)){if(D.current=!0,H==="ctrl"||H==="alt"){j(oe=>({...oe,[H]:oe[H]==="off"?"armed":oe[H]==="armed"?"locked":"off"}));return}if(H==="line"){C(oe=>!oe);return}if(H==="paste"){T(!1),(Te=(ye=navigator.clipboard)==null?void 0:ye.readText)==null||Te.call(ye).then(oe=>{oe?p.paste(oe):T(!0)},()=>T(!0));return}u.type(te(Qy(H,p.appCursor())))}},_=()=>{!u||!M||(u.type(`${M.replace(/\r?\n/g,"\r")}\r`),R(""))},W=!!n.pending||n.state==="waiting_permission"||n.state==="waiting_input",ee=((et=n.pending)==null?void 0:et.kind)==="permission"||n.state==="waiting_permission",Z={name:"thread",sessionId:n.id},J=(V==null?void 0:V.phase)??"connecting",pe=J==="ended",be=J==="offline",Ze=!!((jt=i.daemon)!=null&&jt.terminalInput)&&!(V!=null&&V.readOnly)&&n.readOnly!==!0,pt=F?$e.status.held:$e.status[J],Ie=V!=null&&V.released&&V.released!=="asked"?$e.released[V.released]:null,De=(V==null?void 0:V.exit)==="gone"?$e.exit.gone(n.name):V!=null&&V.exit?$e.exit[V.exit]:null,fe=V!=null&&V.refused?$e.refused[V.refused]??$e.refused.unavailable:null,he=V!=null&&V.holdRefused?$e.holdRefused[V.holdRefused]??d.confirm.refused[V.holdRefused]??null:null,Me=V!=null&&V.held?Math.min(lc,Math.min(V.held.lastKey+lc,V.held.until)-o):0,Fe=F&&Me<=6e4,lt=ee?P:[];return e.jsxs(e.Fragment,{children:[e.jsx(nx,{store:t,session:n,current:"terminal",onLeave:B,model:L,onModel:$,display:J==="live"||be?{value:g==="readable"?$e.readable:$e.fit,onToggle:()=>z(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 ${F?"border-2 border-b-0 border-info":"border border-b-0 border-line"}`,children:[!Fe&&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 ${F?"bg-info text-white":be?"text-attention":J==="live"?"text-ok":"text-muted"}`,children:Fe?$e.heldLeft(sN(Me)):pt}),e.jsx("span",{className:"flex-1"}),F?e.jsx("button",{type:"button",onClick:()=>u==null?void 0:u.release(),className:"flex-none underline",children:$e.release}):V&&!pe&&J!=="refused"&&e.jsxs("span",{className:"flex-none font-mono",children:[V.cols," × ",V.rows]})]}),e.jsx("div",{ref:x,onScroll:Y,onTouchStart:re,onTouchMove:ie,onTouchEnd:ce,"aria-label":$e.screen(n.name),className:`relative min-h-0 flex-1 overflow-auto rounded-b-card bg-term-bg p-2 ${F?"border-2 border-t-0 border-info":"border border-t-0 border-line"} ${be||pe?"opacity-45":""}`,children:e.jsx("div",{ref:c,"data-term":"",className:"w-max"})}),A&&!F&&g==="readable"&&e.jsx("div",{"aria-label":$e.position,role:"img",className:"relative mt-2 h-1 flex-none rounded-full bg-raised",children:e.jsx("span",{className:"absolute inset-y-0 rounded-full bg-muted",style:{left:`${A.left*100}%`,width:`${A.width*100}%`}})})]}),F?e.jsxs("footer",{className:"flex flex-none flex-col gap-1 pt-2 pb-[max(8px,var(--foot-inset))]",children:[v&&e.jsx("p",{role:"alert",className:"text-meta text-attention",children:$e.pasteFailed}),e.jsxs("div",{role:"toolbar","aria-label":$e.keys,className:"flex gap-1.5 overflow-x-auto py-1.5",children:[lt.map(H=>e.jsx("button",{type:"button",onPointerDown:ye=>ye.preventDefault(),onClick:()=>{D.current=!0,u==null||u.type(H.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:H.word?`${H.digit} ${$e.contextKeys[H.word]}`:H.digit},H.digit)),(O?["interrupt","paste"]:N?["esc","tab","up","down","line"]:["esc","tab","ctrl","alt","left","up","down","right","enter","interrupt","paste","line"]).map(H=>{const ye=H==="ctrl"||H==="alt"?b[H]!=="off":H==="line"?N:!1,Te=H==="ctrl"||H==="alt"||H==="line"?ye:void 0,oe=(H==="ctrl"||H==="alt")&&b[H]!=="off"?`, ${b[H]==="locked"?$e.locked:$e.armed}`:"";return e.jsx("button",{type:"button","aria-pressed":Te,"aria-label":`${$e.keyLabel[H]}${oe}`,onPointerDown:Ee=>Ee.preventDefault(),onClick:()=>k(H),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 ${ye?"border-transparent bg-fg text-bg":"border-input bg-surface text-fg"}`,children:$e.key[H]},H)}),O&&e.jsx("span",{className:"ml-auto flex-none self-center pl-2 text-[12px] text-muted",children:$e.hardware})]}),N&&!O&&e.jsxs("form",{className:"flex items-center gap-2",onSubmit:H=>{H.preventDefault(),_()},children:[e.jsx("span",{"aria-hidden":"true",className:"font-mono text-muted",children:"$"}),e.jsx("input",{id:"term-line",value:M,onChange:H=>R(H.target.value),"aria-label":$e.lineField,placeholder:$e.lineField,autoCapitalize:"off",enterKeyHint:"send",className:"min-h-11 min-w-0 flex-1 rounded-control border border-input bg-transparent px-3 font-mono text-body"}),e.jsx("button",{type:"submit",disabled:!M,"aria-label":$e.lineSend,className:ze({variant:"primary",size:"sm"}),children:$e.lineGo})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("footer",{className:"flex flex-none flex-col gap-2 pt-2.5 pb-2.5",children:[(Ie||De||fe||he)&&e.jsx("p",{role:"status",className:"text-center text-small text-muted",children:fe??De??he??Ie}),pe?e.jsx("a",{href:ne(Z),className:ze({block:!0}),children:$e.back}):Ze&&J!=="refused"?e.jsxs("div",{className:"flex items-center gap-3",children:[W&&e.jsx("span",{className:"min-w-0 flex-1 text-small text-muted",children:$e.alsoInThread}),e.jsxs("button",{type:"button",disabled:J!=="live"||(V==null?void 0:V.holding),onClick:()=>S(!0),className:ze({size:"sm",className:W?"flex-none":"ml-auto flex-none"}),children:[e.jsx(q,{name:"keyboard"}),V!=null&&V.released?$e.holdAgain:$e.hold]})]}):!be&&((yt=i.daemon)==null?void 0:yt.terminal)&&!(V!=null&&V.readOnly)&&n.readOnly!==!0&&e.jsx("p",{className:"text-center text-meta text-muted",children:$e.inputOff}),be&&e.jsx("p",{className:"text-center text-meta text-muted",children:$e.offlineHint})]}),e.jsx(Gu,{store:t,forge:r,session:n,wide:U,threshold:((Q=i.device)==null?void 0:Q.contextNear)??vn,onModel:()=>$(!0)})]}),w&&u&&e.jsx(lN,{store:t,session:n,onClose:()=>S(!1),hold:H=>(S(!1),u.hold(H),"sent")})]})}function lN({store:t,session:s,onClose:n,hold:a}){const{fresh:l,device:r}=me(t),i=!!(r!=null&&r.confirm),o=Wu(t,"terminal",s.id,l&&i,a),c=u=>ze({variant:u,block:!0}),x=o.asking?d.confirm.asking:o.challenge?At()?`${$e.go}`:$e.go:d.confirm.preparing;return e.jsxs(ct,{labelledBy:"hold-title",onClose:n,children:[e.jsx("h2",{id:"hold-title",className:"text-heading leading-[1.3] tracking-[-.5px]",children:$e.sheetTitle(s.name)}),i?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:$e.sheetBody}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:$e.sheetNote}),o.problem&&e.jsx(Ge,{title:d.confirm[o.problem],tone:"warning",role:"alert"}),o.needsNew?e.jsx("button",{type:"button",onClick:o.retry,className:c("primary"),children:d.confirm.retry}):e.jsxs("button",{type:"button",disabled:o.asking||!o.challenge,onClick:()=>{o.go()},className:c("primary"),children:[e.jsx(q,{name:"passkey"}),x]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ge,{title:$e.unprotectedTitle,tone:"warning",role:"status",children:e.jsx("p",{children:$e.unprotectedBody})}),e.jsx("a",{href:ne({name:"connection"}),className:c("primary"),children:$e.openConnection})]}),e.jsx("button",{type:"button",onClick:n,className:c(),children:$e.cancel})]})}const bx="ledge.mobile.terminalSize",jx=11,yx=20,rc=12,rN=1e4,Nx=t=>Math.max(jx,Math.min(yx,t));function iN(t){var s;try{const n=Number((s=Qe(t))==null?void 0:s.getItem(bx));return Number.isFinite(n)&&n>0?Nx(Math.round(n)):rc}catch{return rc}}function oN(t,s){var n;try{(n=Qe(s))==null||n.setItem(bx,String(t))}catch{}}const ic=Mt({variant:"outline",className:"text-body font-medium"});function oc({store:t,link:s,sessionId:n,storage:a,forge:l}){var o;const r=me(t),i=r.sessions.get(n);return s&&i&&((o=r.daemon)!=null&&o.terminal)?e.jsx(aN,{store:t,link:s,session:i,forge:l,...a?{storage:a}:{}},n):e.jsx(cN,{store:t,sessionId:n,...a?{storage:a}:{}})}function cN({store:t,sessionId:s,storage:n}){const a=me(t),l=Xt(),{fresh:r,ops:i}=a,o=a.sessions.get(s),c=a.previews.get(s)??[],[x,u]=f.useState(()=>iN(n)),m=I=>u(L=>{const $=Nx(L+I);return oN($,n),$}),[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 I=g.current;I&&(I.scrollTop=I.scrollHeight)},[c.length,c[c.length-1],x]);const y={name:"thread",sessionId:s},w=Mn(a);if(!o)return e.jsxs(e.Fragment,{children:[e.jsx(ra,{title:d.thread.title,fallback:y,label:d.terminal.back,link:w}),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=!!o.pending||o.state==="waiting_permission"||o.state==="waiting_input",b=!r,j=b?d.terminal.offline:S?d.terminal.waiting:d.terminal.live,N=Object.values(i).filter(I=>I.message.type==="session.interrupt"&&I.message.id===s).sort((I,L)=>I.at.localeCompare(L.at)).at(-1),C=N!==void 0&&xs(N.phase),M=o.state==="working",R=(N==null?void 0:N.phase)==="applied"&&(!M||l-Date.parse(N.at)<rN),v=M&&!b&&!S&&!C&&!R,T=b?d.terminal.why.offline:S?d.terminal.why.waiting:M?null:d.terminal.why.idle,A=()=>{v&&h(!t.interrupt(s))},E=(N==null?void 0:N.phase)==="sending"?d.terminal.sending:R?d.terminal.sent:d.terminal.interrupt(o.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(nx,{store:t,session:o,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<=jx,onClick:()=>m(-1),"aria-label":d.terminal.smaller,className:ic,children:"A−"}),e.jsx("button",{type:"button",disabled:x>=yx,onClick:()=>m(1),"aria-label":d.terminal.larger,className:ic,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
+ `)})})]}),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:A,className:ze({block:!0}),children:[e.jsx(q,{name:"stop"}),E]}),T&&!C&&!R&&e.jsx("p",{className:"text-center text-meta text-muted",children:T}),e.jsx("p",{className:"text-center text-meta text-muted",children:d.terminal.note})]})]})}const On=d.unrecognized;function dN({pcName:t,onRelink:s,onSignOut:n}){return e.jsxs(St,{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:za,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($t,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:s,className:bt,children:On.relink}),e.jsx("button",{type:"button",onClick:n,className:dt,children:On.signOut})]})]})}const Ts=d.update,uN=t=>`https://github.com/kl-ledge/ledge/releases/tag/v${t}`;function xN({next:t,current:s,onLater:n,onApply:a}){return e.jsxs(ct,{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:Ts.version(t.version)}),e.jsx("p",{className:"text-muted",children:Ts.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:Ts.fingerprint}),e.jsx("code",{className:"font-mono text-base leading-[22px] tracking-[.02em] [word-spacing:4px]",children:ox(t.fingerprint)}),e.jsxs("span",{className:"text-small leading-4 text-muted",children:[Ts.current,e.jsx("span",{className:"font-mono",children:s?Ts.currentBuild(s.version,V1(s.fingerprint)):d.connection.none})]})]}),e.jsxs("a",{href:uN(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}),Ts.compare(`v${t.version}`)]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2.5",children:[e.jsx(Ue,{size:"lg",onClick:n,children:Ts.later}),e.jsx(Ue,{size:"lg",variant:"primary",onClick:a,children:Ts.apply})]})]})}const Or="ledge.mobile.rigs",mN=35e3,pN=()=>crypto.randomUUID(),cc=()=>crypto.randomUUID(),Sa=t=>t!=="checking"&&t!=="sending"&&t!=="received",fN=new Set(["assertion_invalid","assertion_expired","confirm_required","conflict"]);function hN(t){var s;try{const n=(s=Qe(t))==null?void 0:s.getItem(Or);if(!n)return null;const a=JSON.parse(n),l=fm.safeParse(a.state);return l.success&&typeof a.at=="string"?{state:l.data,at:a.at}:null}catch{return null}}function gN(t,s,n){var z;const a=hN(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,i=k=>{l={...l,...k};for(const _ of[...r])_()};let o=!1,c=!1,x=!1,u=!1,m=!1;const p=new Map,h=new Map,g=new Map;let y=s.getState().daemon?((z=s.getState().daemon)==null?void 0:z.boot)??null:void 0;const w=new Set,S=()=>!o&&t.state()==="ready",b=()=>{var k;return!!((k=s.getState().daemon)!=null&&k.rigs)},j=k=>{t.send(k).catch(()=>{})};function N(k,_,W){return!S()||!b()?!1:(j(_),clearTimeout(p.get(k)),p.set(k,setTimeout(()=>{p.delete(k),W()},mN)),!0)}const C=k=>{clearTimeout(p.get(k)),p.delete(k)},M=k=>({...k??{},loading:!0}),R=k=>({...k??{},loading:!1,error:"unavailable"});function v(){u||N("state",{type:"rigs.state"},()=>{u=!1,i({loading:!1,error:"unavailable"})})&&(u=!0,i({loading:!0}))}function T(){m||N("goals",{type:"rigs.goals"},()=>{m=!1,i({goals:R(l.goals??void 0)})})&&(m=!0,i({goals:M(l.goals??void 0)}))}const A=()=>{c&&v(),x&&T()};function E(k,_){const W=l.runs.findIndex(Z=>Z.id===k);if(W<0)return;const ee=_(l.runs[W]);if(i({runs:l.runs.map((Z,J)=>J===W?ee:Z)}),Sa(ee.phase)){ee.op&&ee.phase!=="uncertain"&&h.delete(ee.op);const Z=g.get(k);g.delete(k),Z==null||Z(ee)}}const P=k=>l.runs.find(_=>_.op===k),I=k=>!!k&&(!Sa(k.phase)||k.phase==="uncertain"),L=(k,_)=>{const W=P(k);C(`op:${k}`),I(W)&&E(W.id,ee=>({...ee,..._,endedAt:Date.now()}))},$=k=>{clearTimeout(p.get(`op:${k}`)),p.set(`op:${k}`,setTimeout(()=>{p.delete(`op:${k}`);const _=P(k);(_==null?void 0:_.phase)==="sending"&&E(_.id,W=>({...W,phase:"uncertain",endedAt:Date.now()}))},zc))},O=k=>k.sentAt!==void 0&&Date.now()-k.sentAt<Fc&&y!==void 0&&(k.boot??null)===y,U=k=>{C(`op:${k.op}`),h.delete(k.op),E(k.id,_=>({..._,phase:"uncertain",lost:!0,endedAt:_.endedAt??Date.now()}))};function D(k){for(const[_,W]of[...h]){if(k.has(_))continue;const ee=P(_);if(!ee){h.delete(_);continue}if(!O(ee)){U(ee);continue}E(ee.id,Z=>({...Z,again:!0})),j(W),ee.phase==="sending"&&$(_)}}const K=(k,_)=>!k||!k.again||!fN.has(_??"")?!1:(k.lost||U(k),!0),te=k=>{const _=k.kind==="seats"?k.rig:k.kind==="act"&&"rig"in k.action?k.action.rig:null;_&&(l.graphs[_]||l.queues[_])&&ce.openRig(_),_&&l.snapshots[_]&&ce.readSnapshots(_)};function V(k){var _;switch(k.type){case"snapshot":{const W=y;y=k.daemon.boot??null;const ee=new Set(w);w.clear();for(const Z of ee){const J=P(Z);J&&E(J.id,pe=>({...pe,boot:y}))}(W===void 0||W!==y)&&D(ee),A();return}case"rigs.state":if(C("state"),u=c,k.state){const W=new Date().toISOString();i({state:k.state,error:null,at:W,loading:!1});try{(_=Qe(n))==null||_.setItem(Or,JSON.stringify({state:k.state,at:W}))}catch{}}else i({error:k.error??"unavailable",loading:!1});return;case"rigs.graph":C(`graph:${k.rig}`),i({graphs:{...l.graphs,[k.rig]:k.graph?{data:k.graph,loading:!1,at:new Date().toISOString()}:{...l.graphs[k.rig],loading:!1,error:k.error??"unavailable"}}});return;case"rigs.queue":C(`queue:${k.rig}`),i({queues:{...l.queues,[k.rig]:k.error?{...l.queues[k.rig],loading:!1,error:k.error}:{data:{rows:k.rows,closed:k.closed,truncated:k.truncated},loading:!1,at:new Date().toISOString()}}});return;case"rigs.permissions":C(`permissions:${k.rig}`),i({permissions:{...l.permissions,[k.rig]:k.error?{...l.permissions[k.rig],loading:!1,error:k.error}:{data:{...k.policy!==void 0?{policy:k.policy}:{},seats:k.seats},loading:!1,at:new Date().toISOString()}}});return;case"rigs.snapshots":C(`snapshots:${k.rig}`),i({snapshots:{...l.snapshots,[k.rig]:k.error?{...l.snapshots[k.rig],loading:!1,error:k.error}:{data:k.snapshots,loading:!1,at:new Date().toISOString()}}});return;case"rigs.routing":C("routing"),i({routing:k.error?{...l.routing,loading:!1,error:k.error}:{data:k.entries,loading:!1,at:new Date().toISOString()}});return;case"rigs.goals":C("goals"),m=x&&!k.error,i({goals:k.error?{...l.goals,loading:!1,error:k.error}:{data:{goals:k.goals,partial:!!k.partial},loading:!1,at:new Date().toISOString()}});return;case"operation.result":{const W=P(k.op);if(!I(W))return;if(k.status==="received"){C(`op:${k.op}`),(W.phase==="sending"||W.phase==="uncertain")&&E(W.id,ee=>{const{endedAt:Z,...J}=ee;return{...J,phase:"received"}});return}if(k.status==="rejected"&&K(W,k.reason))return;k.status==="rejected"&&L(k.op,{phase:"rejected",reason:k.reason??"invalid"});return}case"rigs.done":{const W=P(k.op);if(k.rejected&&K(W,k.rejected))return;W&&(L(k.op,k.rejected?{phase:"rejected",reason:k.rejected,done:k}:{phase:"done",done:k,...k.error?{reason:k.error}:{}}),te(W.subject));return}case"rigs.reseated":{const W=P(k.op);if(k.rejected&&K(W,k.rejected))return;W&&(L(k.op,k.rejected?{phase:"rejected",reason:k.rejected,reseated:k}:{phase:"done",reseated:k,...k.error?{reason:k.error}:{}}),te(W.subject));return}case"rigs.goal.sent":case"rigs.goal.replied":if(k.rejected&&K(P(k.op),k.rejected))return;L(k.op,k.rejected?{phase:"rejected",reason:k.rejected,sent:k}:{phase:"done",sent:k,...k.error?{reason:k.error}:{}});return}}let F=S(),B=0;const Y=t.subscribe(()=>{const k=t.state();(k==="unpaired"||k==="pairing")&&X();const _=S();if(_&&!F)F=!0,B++,u=!1,m=!1,y=void 0,w.clear();else if(!_&&F){F=!1,u=!1,m=!1;for(const[W,ee]of p)clearTimeout(ee),p.delete(W);i({loading:!1});for(const W of l.runs)W.phase==="sending"&&W.op&&E(W.id,ee=>({...ee,phase:"uncertain",endedAt:Date.now()}))}}),G=t.onMessage(V);function X(){var k;if(!(!l.state&&!l.runs.length&&!Object.keys(l.graphs).length)){try{(k=Qe(n))==null||k.removeItem(Or)}catch{}h.clear(),i({state:null,error:null,at:null,loading:!1,graphs:{},queues:{},permissions:{},snapshots:{},routing:null,goals:null,runs:[]})}}async function re(k){var Z;if(!((Z=s.getState().device)!=null&&Z.confirm))return{phase:"rejected",reason:"confirm_required"};let _;try{_=await s.prepareConfirm(k)}catch(J){return{phase:J instanceof Error&&J.message==="timeout"?"expired":"unsent"}}if(!_.credentialId)return{phase:"rejected",reason:"confirm_required"};const W=Date.now(),ee=await ta({challenge:_.challenge,rpId:_.rpId,credentialId:_.credentialId}).catch(()=>"failed");return ee==="cancelled"?{phase:"cancelled"}:ee==="failed"?{phase:"unsent"}:Date.now()-W>=_.expiresInMs?{phase:"expired"}:{assertion:ee}}function ie(k,_,W){const ee=pN(),Z={op:"",id:ee,subject:k,phase:_?"checking":"sending",startedAt:Date.now()},J=new Promise(pe=>g.set(ee,pe));return!S()||!b()?(i({runs:[...l.runs,{...Z,phase:"unsent",endedAt:Date.now()}]}),g.delete(ee),Promise.resolve({...Z,phase:"unsent"})):(i({runs:[...l.runs,Z]}),(async()=>{var fe;let pe;if(_){const he=await re(_);if(!("assertion"in he)){E(ee,Me=>({...Me,phase:he.phase,...he.reason?{reason:he.reason}:{},endedAt:Date.now()}));return}pe=he.assertion}const be=Dc(),Ze=Tc.safeParse(W(be,pe));if(!Ze.success||!S()){E(ee,he=>({...he,phase:"unsent",endedAt:Date.now()}));return}h.set(be,Ze.data),y===void 0&&w.add(be),E(ee,he=>({...he,op:be,phase:"sending",sentAt:Date.now(),...y!==void 0?{boot:y}:{}})),$(be);const pt=B,Ie=await t.send(Ze.data).catch(()=>!1),De=(fe=P(be))==null?void 0:fe.phase;!Ie&&pt===B&&(De==="sending"||De==="uncertain")&&(C(`op:${be}`),E(ee,he=>({...he,phase:"unsent",endedAt:Date.now()})))})(),J)}const ce={getState:()=>l,subscribe(k){return r.add(k),()=>{r.delete(k)}},follow(){c=!0,v()},retry(){u=!1,v()},openRig(k){const _=`graph:${k}`,W=`queue:${k}`,ee=`permissions:${k}`;N(_,{type:"rigs.graph",rig:k},()=>i({graphs:{...l.graphs,[k]:R(l.graphs[k])}}))&&i({graphs:{...l.graphs,[k]:M(l.graphs[k])}}),N(W,{type:"rigs.queue",rig:k},()=>i({queues:{...l.queues,[k]:R(l.queues[k])}}))&&i({queues:{...l.queues,[k]:M(l.queues[k])}}),N(ee,{type:"rigs.permissions",rig:k},()=>i({permissions:{...l.permissions,[k]:R(l.permissions[k])}}))&&i({permissions:{...l.permissions,[k]:M(l.permissions[k])}})},readSnapshots(k){N(`snapshots:${k}`,{type:"rigs.snapshots",rig:k},()=>i({snapshots:{...l.snapshots,[k]:R(l.snapshots[k])}}))&&i({snapshots:{...l.snapshots,[k]:M(l.snapshots[k])}})},readPermissions(k){const _=`permissions:${k}`;N(_,{type:"rigs.permissions",rig:k},()=>i({permissions:{...l.permissions,[k]:R(l.permissions[k])}}))&&i({permissions:{...l.permissions,[k]:M(l.permissions[k])}})},readRouting(){N("routing",{type:"rigs.routing"},()=>i({routing:R(l.routing??void 0)}))&&i({routing:M(l.routing??void 0)})},followGoals(){x=!0,T()},act(k){return ie({kind:"act",action:k},Br(k)?{purpose:"rigs",rigAct:k}:null,(_,W)=>({type:"rigs.act",op:_,action:k,...W?{assertion:W}:{}}))},reseat(k,_,W={}){var J,pe;const ee=((pe=(J=l.state)==null?void 0:J.rigs.find(be=>be.name===k))==null?void 0:pe.nodes)??[],Z=W.check||Rc(ee,_).remove.length>0;return ie({kind:"seats",rig:k,seats:_,...W.delegation?{delegation:W.delegation}:{}},Z?{purpose:"rigs",rigSeats:{rig:k,seats:_}}:null,(be,Ze)=>({type:"rigs.seats",op:be,rig:k,seats:_,...W.delegation?{delegation:W.delegation}:{},...Ze?{assertion:Ze}:{}}))},sendGoal(k,_=cc()){return ie({kind:"goal",goalId:_,text:k},null,W=>({type:"rigs.goal.send",op:W,goalId:_,text:k}))},replyGoal(k,_,W=cc()){return ie({kind:"reply",goalId:k,replyId:W,text:_},null,ee=>({type:"rigs.goal.reply",op:ee,goalId:k,replyId:W,text:_}))},dismiss(k){const _=l.runs.find(W=>W.id===k);_&&Sa(_.phase)&&_.op&&(h.delete(_.op),C(`op:${_.op}`)),i({runs:l.runs.filter(W=>W.id!==k||!Sa(W.phase))})},close(){o=!0,Y(),G();for(const k of p.values())clearTimeout(k);p.clear()}};return ce}function En(t){return f.useSyncExternalStore(t.subscribe,t.getState,t.getState)}const Ql={relaunch:!0,noKernel:!1},kx="ledge.mobile.daemonPrefs",Dr=new Set;function vx(t){var s;try{const n=JSON.parse(((s=Qe(t))==null?void 0:s.getItem(kx))??"{}");return{relaunch:typeof n.relaunch=="boolean"?n.relaunch:Ql.relaunch,noKernel:typeof n.noKernel=="boolean"?n.noKernel:Ql.noKernel}}catch{return Ql}}function bN(t,s){var n;try{(n=Qe(s))==null||n.setItem(kx,JSON.stringify({...vx(s),...t}))}catch{}for(const a of[...Dr])a()}const jN=t=>(Dr.add(t),()=>{Dr.delete(t)});function Si(t){const s=f.useSyncExternalStore(jN,()=>JSON.stringify(vx(t)));return[JSON.parse(s),n=>bN(n,t)]}function wx(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 Ne=d.rigs;function yN(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 $i=t=>t.subject.kind==="act"?t.subject.action.kind:t.subject.kind==="seats"?"seats":null;function Dn(t){const s=$i(t);return s?Ne.notDone[s]:Ne.rejected.nothingSent}function NN(t){const s=$i(t),n=Ne.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 kN(t,s){const n=At(),a=t.phase==="expired"?"assertion_expired":t.phase==="cancelled"?"cancelled":t.phase==="unsent"?"unsent":t.reason??"unavailable",l=NN(t),r=l?Ne.rejected.again(l):Ne.rejected.nothingSent;switch(a){case"busy":return{mark:"warn",title:Ne.busy.title(s),sub:Ne.busy.body};case"confirm_required":return t.subject.kind==="seats"?{mark:"warn",title:n?Ne.reseat.wouldLeave.title:Ne.reseat.wouldLeave.titleDevice,sub:Ne.reseat.wouldLeave.body}:{mark:"warn",title:Ne.rejected.confirm_required};case"assertion_expired":return{mark:"bad",title:Ne.because(Dn(t),Ne.rejected.assertion_expired(n)),sub:r};case"assertion_invalid":return{mark:"bad",title:Ne.because(Dn(t),Ne.rejected.assertion_invalid(n)),sub:r};case"cancelled":return{mark:"bad",title:Ne.because(Dn(t),Ne.rejected.cancelled),sub:Ne.rejected.nothingSent};case"unsent":return{mark:"bad",title:Ne.because(Dn(t),Ne.rejected.unsent),sub:Ne.rejected.nothingSent};default:return{mark:"bad",title:Ne.because(Dn(t),`${Ne.notSent(s)}.`)}}}function Ya({run:t,rigs:s,pc:n,bar:a=!1}){const l=$i(t),r=yN(t),i={onClose:()=>s.dismiss(t.id),closeLabel:Ne.done.close};if(t.phase==="checking")return e.jsx(Yn,{bar:a,children:Ne.running.checking});if(t.phase==="sending"||t.phase==="received"){const m=l==="seats"?Ne.running.seats(r):l?Ne.running[l](r):"";return e.jsx(Yn,{bar:a,children:`${m} · ${Ne.running.note}`})}if(t.phase==="uncertain")return e.jsx(ve,{mark:"ask",title:Ne.uncertain.title,sub:Ne.uncertain.body,...i});if(t.phase!=="done"){const m=kN(t,n);return e.jsx(ve,{mark:m.mark,title:m.title,...m.sub?{sub:m.sub}:{},...i})}const o=Pe(t.endedAt?new Date(t.endedAt).toISOString():null);if(t.reseated){const m=t.reseated;if(m.ok){const p=m.added.length?Ne.reseat.added(m.added.length,m.links):Ne.reseat.removed(m.removed.length);return e.jsxs(ve,{mark:"ok",title:p,...i,children:[m.linksUnsupported&&e.jsxs("small",{className:"block text-[12px] text-attention",children:[Ne.reseat.noLinks.title," ",Ne.reseat.noLinks.body]}),e.jsx(Gs,{commands:m.commands})]})}return m.error==="busy"?e.jsx(ve,{mark:"warn",title:Ne.busy.title(n),sub:Ne.busy.body,...i}):m.error==="rig_not_running"?e.jsx(ve,{mark:"bad",title:Ne.reseat.notRunning.title,sub:Ne.reseat.notRunning.body,...i}):e.jsx(ve,{mark:"bad",title:Ne.failed(m.message??Ne.errors[m.error??"failed"]??Ne.errors.failed),...i,children:e.jsx(Gs,{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(ve,{mark:"ok",title:Ne.done[l](r),sub:[o,m?Ne.done.snapshotFirst:""].filter(Boolean).join(" · "),...i,children:e.jsx(Gs,{commands:c.commands})})}if(c.error==="busy")return e.jsx(ve,{mark:"warn",title:Ne.busy.title(n),sub:Ne.busy.body,...i});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(ve,{mark:"bad",title:Ne.completed(c.completed,x),...c.message?{sub:e.jsx("span",{className:"font-mono",children:c.message})}:{},...i});const u=c.error&&c.error!=="failed"?Ne.errors[c.error]:void 0;return e.jsx(ve,{mark:"bad",title:u??Ne.failed(Ne.errors.failed),...c.message?{sub:e.jsx("span",{className:"font-mono",children:c.message})}:{},...i,children:e.jsx(Gs,{commands:c.commands})})}function Ci(t,s){for(let n=t.length-1;n>=0;n--)if(s(t[n]))return t[n]}const Nl=t=>!!t&&(t.phase==="checking"||t.phase==="sending"||t.phase==="received"),je=d.rigs,vN={running:"on",stopped:"plain",stale:"bad",unknown:"plain"},Sx={ready:"on",starting:"go",stopped:"plain",skipped:"plain",absent:"plain",unknown:"plain"};function Mi({state:t,href:s}){const n=t.daemon.state==="running"&&t.daemon.startedAt?Pe(t.daemon.startedAt):null;return e.jsx(br,{lead:e.jsx(q,{name:"cpu",className:"size-[18px] text-muted"}),name:je.daemon,chip:e.jsx(kn,{tone:vN[t.daemon.state],children:je.daemonState[t.daemon.state]}),sub:je.daemonSub(t.version,n),...s?{href:s}:{}})}function $x({disabled:t,next:s=!1}){const[n,a]=Si();return e.jsxs(e.Fragment,{children:[e.jsx(fo,{on:n.relaunch,label:je.relaunch,disabled:t,onChange:l=>a({relaunch:l})}),e.jsx(fo,{on:n.noKernel,label:je.noKernel,hint:s?je.noKernelNext:je.noKernelHint,disabled:t,onChange:l=>a({noKernel:l})})]})}function Za({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 dc({state:t,rigs:s,store:n,pc:a}){const l=me(n).fresh,[r]=Si(),i=En(s),o=Ci(i.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(Mi,{state:t})})]}),e.jsxs(Ve,{children:[e.jsx(Za,{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($x,{disabled:!l})}),e.jsx("div",{className:"p-3",children:e.jsx("button",{type:"button",disabled:!l||Nl(o),onClick:()=>{s.act(wx("start",r))},className:ge({tone:"primary",className:"w-full"}),children:e.jsx(Dt,{icon:"power",children:je.stopped.start})})})]}),o&&e.jsx(Ya,{run:o,rigs:s,pc:a}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:je.stopped.note})]})}function wN(){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 SN({state:t,at:s,store:n,offline:a}){const l=me(n),r=sa(),i=Et(),o=Vd(t),c=gr(t),x=c.filter(h=>Ih(ps(h))).length,u=[...l.sessions.values()],m=((o==null?void 0:o.nodes)??[]).map(su),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(Pe(s)):void 0,children:je.openrig}),e.jsxs(Ve,{label:je.openrig,children:[e.jsx(Mi,{state:t,...a?{}:{href:ne({name:"kernel"})}}),t.kernel.state!=="absent"&&e.jsx(br,{lead:e.jsx(_e,{state:"rig"}),name:je.kernel,selected:r.name==="kernel"&&i,chip:e.jsx(kn,{tone:Sx[t.kernel.state],children:je.kernelState[t.kernel.state]}),sub:m.length?a||i?je.kernelSubShort(m):je.kernelSub(m):"",...a?{}:{href:ne({name:"kernel"})}})]}),p&&c.length===0?e.jsx(Ve,{children:e.jsx(Za,{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=ps(h),y=Xd(h.name,u,l.asks),w=g==="stopped",S=a?[w?je.seatCount(h.seats):je.seats(h.running,h.seats),!w&&s?je.at(Pe(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(br,{lead:e.jsx(_e,{state:Qd(h,y),pulse:g==="starting"&&!a}),name:h.name,dim:w,chip:e.jsx(kn,{tone:nu[g],children:je.status[g]}),sub:S,att:b,href:ne({name:"rig",rig:h.name}),selected:i&&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 $N({rigs:t,store:s}){const n=En(t),{pc:a,look:l}=Ut(),r=l==="offline";f.useEffect(()=>{t.follow()},[t]);const i=Ht(a),o=n.state,c=o?o.installed?!r&&Hh(o)?e.jsx(dc,{state:o,rigs:t,store:s,pc:i}):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(Pe(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(SN,{state:o,at:n.at,store:s,offline:r})]}):e.jsx(Ve,{children:e.jsx(Za,{title:je.notInstalled.title,body:je.notInstalled.body(i)})}):n.error==="not_installed"?e.jsx(Ve,{children:e.jsx(Za,{title:je.notInstalled.title,body:je.notInstalled.body(i)})}):n.error==="daemon_stopped"?e.jsx(dc,{state:null,rigs:t,store:s,pc:i}):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(wN,{});return e.jsx(As,{title:je.title,offlineBody:je.offlineBody,heading:!1,children:c})}const se=d.rigs;function Ja(t,s=new Date){const n=Va(t);if(!n)return{short:t,long:t};const a=n.toLocaleTimeString(st,{hour:"2-digit",minute:"2-digit"}),l=ui(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(st,{weekday:"short",day:"numeric",month:"short"});return{short:r,long:`${r} ${a}`}}function Fs({verb:t,confirm:s,disabled:n,onClick:a}){const l=At();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 fa=({onClose:t})=>e.jsx("button",{type:"button",onClick:t,className:ge({className:"w-full"}),children:se.confirm.cancel});function $a({title:t,conseq:s,note:n,verb:a,confirm:l,live:r,onConfirm:i,onClose:o}){return e.jsxs(os,{title:t,onClose:o,children:[s&&e.jsx(xi,{title:s.title,...s.body?{body:s.body}:{}}),n&&e.jsx("p",{className:"text-[12.5px] leading-[18px] text-muted",children:n}),e.jsx(Fs,{verb:a,confirm:l,disabled:!r,onClick:()=>{o(),i()}}),e.jsx(fa,{onClose:o})]})}function Xs({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 CN({rig:t,live:s,running:n,snapshots:a,level:l,onSnapshot:r,onSnapshots:i,onPermissions:o,onRefresh:c,onClose:x}){return e.jsx(os,{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(Xs,{icon:"camera",label:se.actions.snapshot,disabled:!s||n,onClick:r}),e.jsx(Xs,{icon:"list",label:se.actions.snapshots,...a!==null?{aside:String(a)}:{},onClick:i}),e.jsx(Xs,{icon:"shield",label:se.actions.permissions,...l?{aside:l}:{},onClick:o}),e.jsx(Xs,{icon:"refresh",label:se.actions.refresh,disabled:!s,onClick:c})]})})}function MN({live:t,up:s,onRefresh:n,onRestart:a,onStop:l,onClose:r}){return e.jsx(os,{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(Xs,{icon:"refresh",label:se.kernelView.menu.refresh,disabled:!t,onClick:n}),e.jsx(Xs,{icon:"refresh",label:se.kernelView.menu.restart,disabled:!t||!s,onClick:a}),e.jsx(Xs,{icon:"power",label:se.kernelView.menu.stop,danger:!0,disabled:!t||!s,onClick:l})]})})}function AN({rig:t,pc:s,verb:n,confirm:a,live:l,onAct:r,onClose:i}){const[o,c]=f.useState(!0),[x,u]=f.useState(!1),m=t.nodes.filter(y=>!y.stopped&&ua(y)).map(y=>bs(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,...o?{snapshot:!0}:{},...x?{force:!0}:{}}:{kind:"rig.restart",rig:t.name};return e.jsxs(os,{title:p?se.confirm.stop(t.name,s):se.confirm.restart(t.name,s),onClose:i,children:[e.jsx(xi,{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(po,{on:o,label:se.confirm.snapshot,onChange:c}),e.jsx(po,{on:x,label:se.confirm.force,onChange:u})]}),e.jsx(Fs,{verb:p?se.actions.stop:se.actions.restart,confirm:a,disabled:!l,onClick:()=>{i(),r(g)}}),e.jsx(fa,{onClose:i})]})}function Cx({rig:t,confirm:s,live:n,onReseat:a,onDone:l,context:r}){const i=eu(t),[o,c]=f.useState({}),[x,u]=f.useState("pairs"),m=Object.fromEntries(Object.entries(o).filter(([j,N])=>{var C;return((C=i.find(M=>M.role===j))==null?void 0:C.count)!==N})),p=Rc(t.nodes,m),h=p.add.length,g=p.remove.length,y=t.nodes.filter(j=>p.remove.includes(j.logicalId)&&ua(j)).map(j=>j.logicalId),w=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:i.map(j=>{const N=o[j.role]??j.count,C=p.add.filter(A=>A.role===j.role).map(A=>se.reseat.adds(`${A.pod}.${A.id}`)),M=p.remove.filter(A=>j.ids.includes(A)).map(se.reseat.removes),R=j.ids.map(A=>{var E;return bs(A,(E=t.nodes.find(P=>P.logicalId===A))==null?void 0:E.session)}).join(", "),v=b?j.ids.map(A=>r[A]).filter(A=>A!==void 0).map(A=>`${Math.round(A)} %`).join(", "):"",T=b?[...C,...M].join(" · "):[R,...C,...M].join(M.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,T&&e.jsx("small",{className:"block font-sans text-[11.5px] text-muted",children:T})]}),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(Qh,{value:N,changed:N!==j.count,disabled:!n,fewer:se.reseat.fewer(j.role),more:se.reseat.more(j.role),onChange:A=>c({...o,[j.role]:A})})})]},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(_a,{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(xi,{title:y.length?se.reseat.working(y):se.reseat.lastFirst,...y.length?{body:se.reseat.lastFirst}:{}}),(!b||h+g>0)&&(g>0?e.jsx(Fs,{verb:w,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:w})),b&&h+g>0&&e.jsx("button",{type:"button",onClick:()=>c({}),className:ge({className:"w-full"}),children:se.confirm.cancel})]})}function EN({rig:t,pc:s,confirm:n,live:a,onReseat:l,onClose:r}){return e.jsxs(os,{title:se.reseat.title(t.name,s),onClose:r,children:[e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:se.reseat.today(eu(t).map(i=>se.reseat.part(i.count,i.role)).join(", "))}),e.jsx(Cx,{rig:t,confirm:n,live:a,onReseat:l,onDone:r}),e.jsx(fa,{onClose:r})]})}function RN({rig:t,read:s,level:n,confirm:a,live:l,onAct:r,onClose:i}){var w,S;const[o,c]=f.useState(n==="mixed"?null:n),x=At(),u=zh((w=s==null?void 0:s.data)==null?void 0:w.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=o&&m.length?{kind:"rig.policy",rig:t.name,policy:o,seats:m}:null,h=!!p&&Br(p),g=()=>{p&&(i(),r(p))},y=!l||!p||o===n;return e.jsxs(os,{title:se.permissions.title(t.name),onClose:i,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:Dh.map(b=>e.jsx(jr,{pressed:o===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(Fs,{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 TN=(t,s)=>{const n=Kh(t,s.links).map(a=>{var r;const l=bs(a.who,(r=s.seats.find(i=>i.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 _N({rig:t,seat:s,graph:n,node:a,session:l,status:r,near:i,onSettings:o,onClose:c}){const x=ci({session:l,node:a,graph:s,rigStatus:r}),u=di(s.runtime),m=bs(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>=i?"text-attention":""}`,children:`${Math.round(s.context)} %`},"c")]]:[],[se.seat.now,h],[se.seat.work,g],[se.seat.links,TN(s.logicalId,n)]];return e.jsxs(os,{title:m,onClose:c,children:[e.jsxs("div",{className:"-mt-2 flex items-center gap-2",children:[e.jsx(_e,{state:Yd[x]}),u&&e.jsx(fs,{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(([w,S])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted",children:w}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:S})]},w))}),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:o,className:ge({className:"w-full"}),children:e.jsx(Dt,{icon:"gear",children:se.seat.settings})})]})}function IN({rig:t,seat:s,node:n,selection:a,confirm:l,live:r,onAct:i,onClose:o}){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),[w,S]=f.useState(null),[b,j]=f.useState(m),N=bs(s.logicalId,s.session),C=s.session??(n==null?void 0:n.session)??`${N}@${t}`,M=g.trim()===""||hm.safeParse(g.trim()).success,R=p!==null&&p!==x,v={kind:"seat.set",seat:C,...R?{runtime:p}:{},...g.trim()&&g.trim()!==u?{model:g.trim()}:{},...w?{effort:w}:{},...b&&b!==m?{permissions:b}:{}},T=Object.keys(v).length>2,A=Br(v),E=di(s.runtime),P=[E?d.tools[E]:s.runtime,u,m?c.perm[m]:""].filter(Boolean),I=!r||!T||!M,L=()=>{o(),i(v)},$=(O,U,D)=>e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"text-[12.5px] text-muted",children:`${O} · ${U}`}),D]});return e.jsxs(os,{title:c.title(N,t),onClose:o,children:[e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:c.today(P)}),$(c.harness,c.whenNow,e.jsx(_a,{label:c.harness,value:p,disabled:!r,onChange:h,options:[{value:"claude-code",label:d.tools.claude},{value:"codex",label:d.tools.codex}]})),$(c.model,c.whenResume,e.jsx("input",{"aria-label":c.modelLabel,value:g,disabled:!r,onChange:O=>y(O.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 ${M?"border-input":"border-approval/60"}`})),$(c.effort,c.whenResume,e.jsx(_a,{label:c.effort,value:w,disabled:!r,onChange:S,options:["medium","high","xhigh"].map(O=>({value:O,label:c.effortLevel[O]}))})),$(c.permissions,c.whenLaunch,e.jsx(_a,{label:c.permissions,value:b,disabled:!r,onChange:j,options:["inherit","auto","full_bypass"].map(O=>({value:O,label:c.perm[O]}))})),R&&e.jsx("p",{className:"text-[12.5px] text-attention",children:c.moveNote}),A?e.jsx(Fs,{verb:c.save,confirm:l,disabled:I,onClick:L}):e.jsx("button",{type:"button",disabled:I,onClick:L,className:ge({tone:"primary",className:"w-full"}),children:c.save})]})}function Mx({read:t,kindOnly:s=!1,retry:n}){const a=au((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(Os,{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(Os,{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:Ja(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 LN({rig:t,read:s,live:n,running:a,onSnapshot:l,onRetry:r,onClose:i}){return e.jsxs(os,{title:se.snapshots.title(t),onClose:i,children:[e.jsx(Mx,{read:s,retry:r}),e.jsx("button",{type:"button",disabled:!n||a,onClick:()=>{i(),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,Ms=t=>{var s;return((s=Va(t))==null?void 0:s.toISOString())??t},ON={mine:"border-attention/50 text-attention",progress:"border-info/45 text-info",pending:"border-input text-muted",blocked:"border-approval/45 text-approval"},DN=({tone:t})=>e.jsx("span",{"data-row":t,className:`flex-none rounded-[5px] border px-1.5 text-[11px] leading-[18px] whitespace-nowrap ${ON[t]}`,children:xe.queue.tone[t]}),Qs=t=>t.split("@")[0]??t;function Ax({seat:t,state:s,pod:n,tag:a,near:l,isNew:r,pulse:i,onOpen:o,onMore:c,top:x=!1,name:u,words:m}){const{swallow:p,...h}=Yh(c),g=u??bs(t.logicalId,t.session),y=di(t.runtime),w=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(_e,{state:Yd[s],pulse:i}),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(fs,{tool:y})})]}),e.jsxs("small",{className:`truncate text-[11.5px] ${s==="ask"?"text-attention":"text-muted"}`,children:[S,w!==null&&e.jsxs(e.Fragment,{children:[S?" · ":"",e.jsx("span",{className:`font-mono ${w>=l?"text-attention":""}`,children:`${w} %`})]})]})]}),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 o?e.jsx("button",{type:"button",...h,onClick:()=>{p!=null&&p()||o()},"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 FN({graph:t,rig:s,status:n,sessions:a,near:l,added:r,onSeat:i,wide:o=!1}){var h;const c=Oh(t.seats,t.links),x=t.seats.find(g=>g.logicalId===c),u=Lh(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 C;const w=Gd(a,s.name,g.logicalId),S=ci({session:w,node:s.nodes.find(M=>M.logicalId===g.logicalId),graph:g,rigStatus:n}),b=((C=t.pods.find(M=>M.id===g.pod))==null?void 0:C.label)??g.pod,j=i?()=>i(g.logicalId):void 0,N=o&&w?()=>en({name:"thread",sessionId:w.id}):void 0;return e.jsx(Ax,{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 zN({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,[Pe(Ms(t.createdAt)),t.claimedAt?xe.queue.claimed(Pe(Ms(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 PN({read:t,asks:s,now:n,retry:a}){const[l,r]=f.useState(null),[i,o]=f.useState(!1),c=t==null?void 0:t.data;if(!c)return e.jsx(Ve,{children:t!=null&&t.error?e.jsx(Os,{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=Ph(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(DN,{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(Ms(u.updatedAt),n)})]}),p&&e.jsx(zN,{row:u,mine:m==="mine"})]},u.id)}),c.closed.length>0&&e.jsxs("button",{type:"button","aria-expanded":i,onClick:()=>o(!i),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 ${i?"rotate-90":""}`}),e.jsx("span",{children:xe.queue.closed(c.closed.length)})]}),i&&c.closed.map(u=>{const m=Bh(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:Pe(Ms(u.updatedAt))})]},u.id)})]}),c.truncated&&e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:xe.queue.truncated})]})}function BN({rig:t,sessions:s,asks:n}){var g;const a=s.filter(y=>{var w;return((w=y.rig)==null?void 0:w.name)===t}),l=Vt(a),r=l.find(y=>y.filter==="permission")??l[0],i=r?a.find(y=>y.id===r.sessionId):void 0,o=r||n==null?void 0:n.find(y=>y.from.rig===t&&y.kind!=="update");if(!r&&!o)return null;const c=i?(g=i.rig)!=null&&g.role?bs(i.rig.role):i.name:o?Qs(o.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(_e,{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 qN({rig:t,rigs:s,store:n}){var jt,yt,Q,H,ye,Te;const a=En(s),l=me(n),{pc:r,look:i}=Ut(),o=Et(),[c,x]=f.useState(null),[u,m]=f.useState("last"),p=l.fresh,h=i==="offline",[g,y]=f.useState(()=>Date.now());f.useEffect(()=>{const oe=setInterval(()=>y(Date.now()),3e4);return()=>clearInterval(oe)},[]),f.useEffect(()=>{s.follow(),p&&(s.openRig(t),s.readSnapshots(t))},[s,t,p]);const w=Ht(r),S=a.state,b=S==null?void 0:S.rigs.find(oe=>oe.name===t),j=a.graphs[t],N=a.permissions[t],C=a.snapshots[t],M=a.queues[t],R=[...l.sessions.values()],v=((jt=l.device)==null?void 0:jt.contextNear)??70,T=!!((yt=l.device)!=null&&yt.confirm),A=Ci(a.runs,oe=>Wh(oe.subject)===t),E=Nl(A),P=oe=>{s.act(oe)},I=(oe,Ee)=>{s.reseat(t,oe,Ee?{delegation:Ee}:{})},L=()=>x(null),$=()=>s.openRig(t),O=e.jsx("button",{type:"button","aria-label":xe.more,title:xe.more,"aria-haspopup":"menu",onClick:()=>x({kind:"more"}),className:Mt(),children:e.jsx(q,{name:"more"})}),U=(oe,Ee,nt)=>o?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}),oe,Ee&&e.jsx("span",{className:"min-w-0 truncate text-[12.5px] text-muted",children:Ee}),e.jsx("span",{className:"flex-1"}),nt,b&&O]}):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}),oe,e.jsx("span",{className:"flex-1"}),b&&O]}),D=`tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pb-[18px] ${o?"pt-[18px]":"pt-3"}`;if(!!S&&(!b||(j==null?void 0:j.error)==="unknown_rig"||(M==null?void 0:M.error)==="unknown_rig"))return e.jsxs(e.Fragment,{children:[U(null),e.jsx("main",{"data-tab-scroll":"",className:D,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 oe=a.error?xe.readError[a.error]:null;return e.jsxs(e.Fragment,{children:[U(null),e.jsxs("main",{"data-tab-scroll":"",className:D,children:[e.jsx(gs,{body:xe.offlineBody}),oe?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:oe})}):e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:xe.loading})]})]})}const te=ps(b),V=te==="stopped",F=N!=null&&N.data?Jd(N.data.seats):null,B=F?xe.level[F]:null,Y=au((C==null?void 0:C.data)??[])[0],G=Y?Ja(Y.createdAt).short:b.snapshot||"",X=(A==null?void 0:A.phase)==="done"&&((Q=A.reseated)!=null&&Q.ok)?A.reseated.added:[],re=b.nodes.filter(oe=>oe.stopped).map(oe=>bs(oe.logicalId,oe.session)),ie=oe=>{var Ee;return(Ee=j==null?void 0:j.data)==null?void 0:Ee.seats.find(nt=>nt.logicalId===oe)},ce=()=>{var oe;return P(u==="fresh"?{kind:"rig.start",rig:t,fresh:((oe=j==null?void 0:j.data)==null?void 0:oe.seats.map(Ee=>Ee.logicalId))??b.nodes.map(Ee=>Ee.logicalId)}:{kind:"rig.start",rig:t})},z=A&&!E?A:void 0,k=p&&!E,_=o?"sm":"md",W=o?"":"!h-[42px] !px-2 !text-[13.5px]",ee=e.jsx("button",{type:"button",disabled:!k,onClick:ce,className:ge({tone:"primary",size:_,className:o?"":"!h-[42px]"}),children:e.jsx(Dt,{icon:"power",children:xe.actions.start})}),Z=e.jsx("button",{type:"button",disabled:!k,onClick:()=>x({kind:"restart"}),className:ge({size:_,className:W}),children:e.jsx(Dt,{icon:"refresh",children:xe.actions.restart})}),J=e.jsx("button",{type:"button",disabled:!k,onClick:()=>x({kind:"stop"}),className:ge({tone:"danger",size:_,className:W}),children:e.jsx(Dt,{icon:"power",children:xe.actions.stop})}),pe=e.jsx("button",{type:"button",disabled:!k,onClick:()=>x({kind:"reseat"}),className:ge({size:_,className:W}),children:e.jsx(Dt,{icon:"plus",children:xe.actions.seats})}),be=E?e.jsx(Ya,{run:A,rigs:s,pc:w,bar:!o}):te==="starting"?e.jsx(Yn,{bar:!o,children:xe.startingSeats(t,b.running,b.seats)}):null,Ze=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 ${V?"grid-cols-1":"grid-cols-3"}`,children:V?ee:e.jsxs(e.Fragment,{children:[pe,Z,J]})}),pt=p&&e.jsx(BN,{rig:t,sessions:R,asks:l.asks}),Ie=te==="partial"&&re.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(re,b.nodes.length-re.length)}),e.jsx("button",{type:"button",disabled:!k,onClick:()=>x({kind:"restart"}),className:ge({size:"sm",className:"self-start"}),children:xe.actions.restartRig})]}),De=e.jsxs(e.Fragment,{children:[e.jsx(Ft,{aside:V?xe.topologyStopped:j!=null&&j.data?xe.topologyHint:void 0,children:xe.topology}),j!=null&&j.data?e.jsx(FN,{graph:j.data,rig:b,status:te,sessions:R,near:v,added:X,onSeat:oe=>x({kind:"seat",id:oe}),wide:o}):e.jsx(Ve,{children:j!=null&&j.error?e.jsx(Os,{retry:$,retryLabel:xe.unavailable.retry,children:xe.readError[j.error]}):e.jsx("p",{role:"status",className:"p-3 text-[13px] text-muted",children:xe.loading})})]}),fe=V&&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(jr,{pressed:u==="last",disabled:!p,onClick:()=>m("last"),title:xe.resumeLast(Y?Ja(Y.createdAt).long:b.snapshot),sub:xe.resumeLastBody}),e.jsx(jr,{pressed:u==="fresh",disabled:!p,onClick:()=>m("fresh"),title:xe.fresh,sub:xe.freshBody})]})]}),he=e.jsx(PN,{read:M,asks:l.asks,now:g,retry:$}),Me=o?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:[pt,Ie,De,!V&&te!=="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(Cx,{rig:b,confirm:T,live:k,onReseat:I,context:Object.fromEntries((((H=j==null?void 0:j.data)==null?void 0:H.seats)??[]).map(oe=>[oe.logicalId,oe.context]))},b.nodes.length)})})]}),fe]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3.5",children:[he,e.jsx(Ft,{children:xe.actions.snapshots}),e.jsx(Mx,{read:C,kindOnly:!0,retry:()=>s.readSnapshots(t)}),e.jsx("button",{type:"button",disabled:!k,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(Fl,{label:xe.tiles.seats,value:`${b.running}/${b.seats}`}),e.jsx(Fl,{label:xe.tiles.permissions,value:B??"—",onOpen:()=>x({kind:"permissions"})}),e.jsx(Fl,{label:xe.tiles.snapshot,value:G||"—",onOpen:()=>x({kind:"snapshots"})})]}),pt,Ie,De,he,fe]}),Fe=(c==null?void 0:c.kind)==="seat"||(c==null?void 0:c.kind)==="settings"?ie(c.id):void 0,lt=Fe?b.nodes.find(oe=>oe.logicalId===Fe.logicalId):void 0,et=[xe.seats(b.running,b.seats),B??"",G?xe.snapshot(G):""].filter(Boolean).join(" · ");return e.jsxs(e.Fragment,{children:[U(e.jsx(kn,{tone:nu[te],children:xe.status[te]}),et,!be&&(V?ee:e.jsxs(e.Fragment,{children:[Z,J]}))),e.jsxs("main",{"data-tab-scroll":"",className:D,children:[e.jsx(gs,{body:xe.offlineBody}),o&&be,z&&e.jsx(Ya,{run:z,rigs:s,pc:w}),e.jsx("div",{className:`flex flex-col gap-3 ${h?"opacity-50":""}`,children:Me})]}),!o&&Ze,(c==null?void 0:c.kind)==="more"&&e.jsx(CN,{rig:t,live:p,running:E,snapshots:C!=null&&C.data?C.data.length:null,level:B,onClose:L,onSnapshot:()=>{L(),P({kind:"rig.snapshot",rig:t})},onSnapshots:()=>x({kind:"snapshots"}),onPermissions:()=>x({kind:"permissions"}),onRefresh:()=>{L(),s.retry(),s.openRig(t),s.readSnapshots(t)}}),((c==null?void 0:c.kind)==="stop"||(c==null?void 0:c.kind)==="restart")&&e.jsx(AN,{rig:b,pc:w,verb:c.kind,confirm:T,live:k,onAct:P,onClose:L}),(c==null?void 0:c.kind)==="reseat"&&e.jsx(EN,{rig:b,pc:w,confirm:T,live:k,onReseat:I,onClose:L}),(c==null?void 0:c.kind)==="permissions"&&e.jsx(RN,{rig:b,read:N,level:F,confirm:T,live:k,onAct:P,onClose:L}),(c==null?void 0:c.kind)==="snapshots"&&e.jsx(LN,{rig:t,read:C,live:p,running:E,onSnapshot:()=>P({kind:"rig.snapshot",rig:t}),onRetry:()=>s.readSnapshots(t),onClose:L}),(c==null?void 0:c.kind)==="seat"&&Fe&&(j==null?void 0:j.data)&&e.jsx(_N,{rig:t,seat:Fe,graph:j.data,node:lt,session:Gd(R,t,Fe.logicalId),status:te,near:v,onSettings:()=>x({kind:"settings",id:Fe.logicalId}),onClose:L}),(c==null?void 0:c.kind)==="settings"&&Fe&&e.jsx(IN,{rig:t,seat:Fe,node:lt,selection:(Te=(ye=N==null?void 0:N.data)==null?void 0:ye.seats.find(oe=>oe.logicalId===Fe.logicalId))==null?void 0:Te.selection,confirm:T,live:k,onAct:P,onClose:L})]})}const ds=d.rigs,ke=ds.max,HN={sent:"idle",taken:"work",asking:"ask",proposed:"rig",running:"work",done:"done",closed:"done"},UN={sent:"plain",taken:"work",asking:"ask",proposed:"rig",running:"work",done:"ok",closed:"plain"},WN=t=>{var s;return((s=t.trail.at(-1))==null?void 0:s.at)??t.sentAt},Ex=t=>{const s=el(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 KN(t){var n;const s=Ja(WN(t)).short;return t.state==="asking"?`${ke.asks} · ${s}`:t.state==="running"?[ke.state.running,((n=t.current)==null?void 0:n.seat.split("@")[0])??"",ke.since(s)].filter(Boolean).join(" · "):`${ke.state[t.state]} · ${s}`}const el=t=>{var s,n;return((s=t.question)==null?void 0:s.text)??((n=t.proposal)==null?void 0:n.text)??null};function VN({run:t,pc:s,onAgain:n,onClose:a}){var o,c;const l={onClose:a,closeLabel:ds.done.close},r=e.jsx("button",{type:"button",onClick:n,className:ge({size:"xs",className:"mt-1.5"}),children:ke.sendAgain}),i=t.phase==="uncertain"?"uncertain":t.phase==="done"?(o=t.sent)==null?void 0:o.error:void 0;return i?i==="uncertain"?e.jsx(ve,{mark:"ask",title:ke.errors.uncertain.title,sub:ke.errors.uncertain.body,...l,children:r}):i==="refused"?e.jsx(ve,{mark:"bad",title:ke.errors.refused.title,...(c=t.sent)!=null&&c.message?{sub:e.jsx("span",{className:"font-mono",children:t.sent.message})}:{},...l}):i==="openrig_stopped"?e.jsx(ve,{mark:"bad",title:ke.errors.openrig_stopped.title(s),sub:ke.errors.openrig_stopped.body,...l,children:r}):i==="no_operator"||i==="unreachable"?e.jsx(ve,{mark:"bad",title:ke.errors[i].title,sub:ke.errors[i].body,...l,children:r}):e.jsx(ve,{mark:"bad",title:ke.unsent,sub:ke.keeps,...l,children:r}):e.jsx(ve,{mark:"bad",title:ke.unsent,sub:ke.keeps,...l,children:r})}const GN=t=>{var s;return t.phase==="done"&&!!((s=t.sent)!=null&&s.ok)};function Rx({runs:t,rigs:s,pc:n,bubble:a}){return e.jsx(e.Fragment,{children:t.filter(l=>!GN(l)).map(l=>{const r=l.subject;if(r.kind!=="goal"&&r.kind!=="reply")return null;if(Nl(l))return e.jsxs("div",{role:"status","aria-label":ke.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(An,{className:"ml-1 align-[-1px] text-muted"})]},l.id);const i=()=>{s.dismiss(l.id),r.kind==="goal"?s.sendGoal(r.text,r.goalId):s.replyGoal(r.goalId,r.text,r.replyId)};return e.jsx(VN,{run:l,pc:n,onAgain:i,onClose:()=>s.dismiss(l.id)},l.id)})})}function XN(t){var s;switch(t.kind){case"sent":return ke.trail.sent;case"taken":return ke.trail.taken;case"note":return ke.trail.note(t.text??"");case"handed":return ke.trail.handed(((s=t.to)==null?void 0:s.split("@")[0])??"");case"closed":return ke.trail.closed}}function Tx({goal:t,runs:s,rigs:n,pc:a,compact:l=!1}){const r=el(t),i=Ex(t),o=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:Pe(Ms(x.at))}),e.jsx("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:XN(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(_e,{state:"idle"}),i?`${ds.kernelView.max} · ${Pe(Ms(i))}`:ds.kernelView.max]}),e.jsx("span",{className:"[overflow-wrap:anywhere]",children:r})]}),o&&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(_e,{state:"ask"}),e.jsx("b",{className:"text-[14px] font-semibold",children:t.question?ke.question:ke.proposal}),i&&e.jsx("span",{className:"ml-auto font-mono text-[11.5px] text-muted",children:Pe(Ms(i))})]}),!l&&e.jsx("p",{className:"text-[13px] text-muted",children:t.question?ke.questionBody:ke.proposalBody}),e.jsx("a",{href:ne({name:"atoi"}),className:ge({size:"sm",className:"self-start"}),children:ke.seeAtoi})]}),e.jsx(Rx,{runs:c,rigs:n,pc:a,bubble:!0})]})}function _x({goalId:t,rigs:s,live:n}){const[a,l]=f.useState("");return e.jsx(Yc,{label:ke.replyPlaceholder,sendLabel:ke.send,placeholder:ke.replyPlaceholder,offlinePlaceholder:ke.offlinePlaceholder,offline:!n,value:a,onChange:l,onSend:()=>{const r=a.trim();r&&(l(""),s.replyGoal(t,r).then(i=>{i.phase==="unsent"&&l(o=>o||r)}))}})}function QN({goalId:t,rigs:s,store:n}){var M,R,v,T;const a=En(s),l=me(n),{pc:r,look:i}=Ut(),o=Et(),c=l.fresh,x=i==="offline",u=Ht(r),[m,p]=f.useState("");f.useEffect(()=>{s.follow(),s.followGoals()},[s,c]);const h=((R=(M=a.goals)==null?void 0:M.data)==null?void 0:R.goals)??[],g=t?h.find(A=>A.goalId===t):void 0,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"}`,w=o?"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 A,E;return(A=a.goals)!=null&&A.error&&!a.goals.data?e.jsx(Ve,{children:e.jsx(Os,{retry:()=>s.followGoals(),retryLabel:ds.unavailable.retry,children:ke.goalsUnavailable})}):(E=a.goals)!=null&&E.data?null:e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:ds.loading})})();if(t)return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:w,children:[e.jsx(is,{fallback:{name:"max"},label:ds.backMax}),e.jsx("h1",{className:"min-w-0 truncate text-base font-semibold",children:(g==null?void 0:g.text)??ke.title}),g&&e.jsx("span",{className:"flex-none",children:e.jsx(zt,{tone:UN[g.state],children:ke.statePill[g.state]})})]}),e.jsxs("main",{"data-tab-scroll":"",className:`${y} justify-end`,children:[e.jsx(gs,{body:ds.offlineBody}),g?e.jsx("div",{className:x?"opacity-50":"",children:e.jsx(Tx,{goal:g,runs:a.runs,rigs:s,pc:u})}):b??e.jsx("p",{role:"alert",className:"text-[13px] text-attention",children:ke.goalsUnavailable})]}),g&&e.jsx("div",{className:S,children:e.jsx(_x,{goalId:g.goalId,rigs:s,live:c})})]});const j=a.runs.filter(A=>A.subject.kind==="goal"),N=()=>{const A=m.trim();A&&(p(""),s.sendGoal(A).then(E=>{E.phase==="unsent"&&p(P=>P||A)}))},C=()=>{var A;(A=document.querySelector("[data-goal-field] textarea"))==null||A.focus()};return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:w,children:[e.jsx(is,{fallback:{name:"kernel"},label:ds.backKernel}),e.jsx("h1",{className:"flex-none text-base font-semibold",children:ke.title}),e.jsx("span",{className:"min-w-0 truncate text-[12.5px] text-muted",children:ke.role}),e.jsx("span",{className:"flex-1"}),e.jsx("button",{type:"button",disabled:!c,onClick:C,className:ge({tone:"primary",size:"sm"}),children:e.jsx(Dt,{icon:"plus",children:ke.newGoal})})]}),e.jsxs("main",{"data-tab-scroll":"",className:y,children:[e.jsx(gs,{body:ds.offlineBody}),e.jsxs("div",{className:`flex flex-col gap-3 ${x?"opacity-50":""}`,children:[b??(h.length===0?e.jsx(Ve,{children:e.jsx(Os,{children:ke.none})}):e.jsx(Ve,{label:ke.goalsLabel,children:h.map(A=>e.jsxs("a",{href:ne({name:"max",goalId:A.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(_e,{state:HN[A.state],pulse:A.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:A.text}),e.jsx("small",{className:`text-[12px] ${A.state==="asking"?"text-attention":"text-muted"}`,children:KN(A)})]})]},A.goalId))})),((T=(v=a.goals)==null?void 0:v.data)==null?void 0:T.partial)&&e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:ke.partial}),e.jsx(Rx,{runs:j,rigs:s,pc:u,bubble:!1}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:ke.atoiNote})]})]}),e.jsx("div",{"data-goal-field":"",className:S,children:e.jsx(Yc,{label:ke.goalPlaceholder,sendLabel:ke.send,placeholder:ke.goalPlaceholder,offlinePlaceholder:ke.offlinePlaceholder,offline:!c,value:m,onChange:p,onSend:N})})]})}const Re=d.rigs,ht=Re.kernelView,YN=t=>/^qitem-\d{14}-[0-9a-f]{8,}$/.test(t)?`…${t.slice(-8)}`:t;function ZN({graph:t,status:s,near:n}){var c;const a=t.seats,l=a.find(x=>tu(x.logicalId)),r=a.filter(x=>x!==l),i=(l==null?void 0:l.runtime)??((c=a[0])==null?void 0:c.runtime),o=(x,u=!1)=>{var g;const m=ci({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"?"":Re.seatState[m]].filter(Boolean).join(" · ");return e.jsx(Ax,{seat:x,state:m,pod:p,top:u,near:n,isNew:!1,name:su({logicalId:x.logicalId,session:x.session??""}),words:h,tag:u||x.runtime!==i,pulse:m==="starting"},x.logicalId)};return e.jsxs("div",{className:"flex flex-col items-center",children:[l&&e.jsxs(e.Fragment,{children:[o(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=>o(x))})]})}function JN({rigs:t}){const s=En(t).routing,n=s!=null&&s.data?[...s.data].reverse():null,a=l=>{const r=qh(l);return r.verb==="handed"?ht.change.handed(r.to):r.verb==="blocked"?ht.change.blocked(YN(r.on)):r.verb==="other"?r.text:ht.change[r.verb]};return e.jsxs(e.Fragment,{children:[e.jsx(Ft,{aside:ht.allRigs,children:ht.routing}),e.jsx(Ve,{children:n?n.length===0?e.jsx(Os,{children:ht.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:Pe(Ms(l.at))}),e.jsxs("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:[e.jsx("b",{className:"font-semibold",children:ht.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(Os,{retry:()=>t.readRouting(),retryLabel:Re.unavailable.retry,children:Re.readError[s.error]}):e.jsx("p",{role:"status",className:"p-3 text-[13px] text-muted",children:Re.loading})})]})}function e0({rigs:t,store:s}){var _,W,ee,Z;const n=En(t),a=me(s),{pc:l,look:r}=Ut(),i=Et(),[o]=Si(),[c,x]=f.useState(null),u=a.fresh,m=r==="offline";f.useEffect(()=>{t.follow(),t.followGoals(),u&&(t.openRig(zn),t.readRouting())},[t,u]);const p=n.state?gr(n.state).filter(J=>ps(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] ${i?"pt-[18px]":"pt-3"}`,w=J=>e.jsxs("header",{className:i?"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:Re.back}),e.jsx("h1",{className:`min-w-0 truncate font-semibold ${i?"text-[17px]":"text-base"}`,children:Re.kernel}),J,e.jsx("span",{className:"flex-1"}),J&&e.jsx("button",{type:"button","aria-label":Re.more,title:Re.more,"aria-haspopup":"menu",onClick:()=>x("menu"),className:Mt(),children:e.jsx(q,{name:"more"})})]}),S=()=>{t.retry(),t.openRig(zn),t.readRouting()};if(!g){const J=n.error?Re.readError[n.error]:null;return e.jsxs(e.Fragment,{children:[w(null),e.jsxs("main",{"data-tab-scroll":"",className:y,children:[e.jsx(gs,{body:Re.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:Re.loading})]})]})}const b=Vd(g),j=g.kernel.state,N=b?ps(b):"stopped",C=n.graphs[zn],M=((_=a.device)==null?void 0:_.contextNear)??70,R=!!((W=a.device)!=null&&W.confirm),v=Ci(n.runs,J=>J.subject.kind==="act"&&/^(kernel|daemon)\./.test(J.subject.action.kind)),T=Nl(v),A=u&&!T,E=J=>{t.act(J)},P=[...a.sessions.values()],I=gr(g),L=g.daemon.state==="running",$=j==="ready"||j==="starting",O=((Z=(ee=n.goals)==null?void 0:ee.data)==null?void 0:Z.goals)??[],U=j==="stopped"?e.jsxs(Gt,{lead:e.jsx("span",{className:"mt-[5px]",children:e.jsx(_e,{state:"off"})}),children:[e.jsx("span",{children:e.jsx("b",{className:"font-semibold",children:ht.stoppedTitle})}),e.jsx("span",{className:"text-muted",children:ht.stoppedBody}),e.jsx("button",{type:"button",disabled:!A||!L,onClick:()=>E({kind:"kernel.start"}),className:ge({tone:"primary",size:"sm",className:"self-start"}),children:e.jsx(Dt,{icon:"power",children:ht.startKernel})})]}):j==="skipped"?e.jsxs(Gt,{lead:e.jsx("span",{className:"mt-[5px]",children:e.jsx(_e,{state:"off"})}),children:[e.jsx("span",{children:e.jsx("b",{className:"font-semibold",children:ht.skippedTitle})}),e.jsx("span",{className:"text-muted",children:ht.skippedBody})]}):null,D=O.find(J=>el(J)!==null),K=D?Ex(D):null,te=O.find(J=>J.state!=="done"&&J.state!=="closed"),V=e.jsx("a",{href:ne({name:"max"}),className:ge({tone:"primary",className:"w-full"}),children:ht.talk}),F=i&&te?e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:`${ht.max} · ${te.text}`}),e.jsx(Ve,{children:e.jsxs("div",{className:"flex flex-col gap-2.5 p-3",children:[e.jsx(Tx,{goal:te,runs:n.runs,rigs:t,pc:h,compact:!0}),e.jsx(_x,{goalId:te.goalId,rigs:t,live:u})]})})]}):e.jsx(Ve,{children:e.jsxs("div",{className:"flex flex-col gap-2 p-3",children:[D&&e.jsx("span",{className:"text-[12px] text-muted",children:ht.lastMessage(K?Pe(Ms(K)):null)}),D&&e.jsx("span",{className:"text-[13.5px] leading-[19px] [overflow-wrap:anywhere]",children:el(D)}),V]})}),B=J=>{var Ze;const pe=(Ze=n.permissions[J])==null?void 0:Ze.data,be=pe?Jd(pe.seats):null;return be?Re.level[be]:""},Y=I.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:ht.driven}),e.jsx(Ve,{children:I.map(J=>{const pe=ps(J),be=Qd(J,Xd(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(_e,{state:be}),e.jsx("span",{className:`min-w-0 flex-1 truncate ${pe==="stopped"?"text-muted":""}`,children:J.name}),e.jsx("span",{className:"text-[12px] text-muted",children:pe==="stopped"?Re.seatState.off:[Re.seatCount(J.seats),B(J.name)].filter(Boolean).join(" · ")}),e.jsx(q,{name:"chevron",className:"size-4 text-muted"})]},J.id)})})]}),G=(J,pe)=>e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{type:"button",disabled:!A,onClick:J,className:ge({}),children:e.jsx(Dt,{icon:"refresh",children:Re.actions.restart})}),e.jsx("button",{type:"button",disabled:!A,onClick:pe,className:ge({tone:"danger"}),children:e.jsx(Dt,{icon:"power",children:Re.actions.stop})})]}),X=$&&e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:Re.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:Re.confirm.kernelNote}),G(()=>x("kernel.restart"),()=>x("kernel.stop"))]})})]}),re=e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:Re.daemon}),e.jsxs(Ve,{children:[e.jsx(Mi,{state:g}),e.jsx($x,{disabled:!u,next:!0}),L&&e.jsx("div",{className:"px-3 pt-2.5 pb-3",children:G(()=>x("daemon.restart"),()=>x("daemon.stop"))})]}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:ht.daemonNote})]}),ie=I.flatMap(J=>Vh(J)).length,ce=I.filter(J=>ps(J)!=="stopped").length,z=[Re.confirm.daemonStops(ce),ie?Re.confirm.working(ie):""].filter(Boolean).join(" "),k=()=>x(null);return e.jsxs(e.Fragment,{children:[w(e.jsx(kn,{tone:Sx[j],children:Re.kernelState[j]})),e.jsxs("main",{"data-tab-scroll":"",className:y,children:[e.jsx(gs,{body:Re.offlineBody}),v&&e.jsx(Ya,{run:v,rigs:t,pc:h}),e.jsxs("div",{className:`flex flex-col gap-3 ${i?"max-w-[720px]":""} ${m?"opacity-50":""}`,children:[U,e.jsx("p",{className:"text-[12.5px] leading-[18px] text-muted",children:ht.role}),$&&(C!=null&&C.data?e.jsx(ZN,{graph:C.data,status:N,near:M}):e.jsx(Ve,{children:e.jsx("p",{role:C!=null&&C.error?"alert":"status",className:"p-3 text-[13px] text-muted",children:C!=null&&C.error?Re.readError[C.error]:Re.loading})})),$&&F,Y,e.jsx(JN,{rigs:t}),X,re]})]}),c==="menu"&&e.jsx(MN,{live:u,up:$&&!T,onClose:k,onRefresh:()=>{k(),S()},onRestart:()=>x("kernel.restart"),onStop:()=>x("kernel.stop")}),c==="kernel.restart"&&e.jsx($a,{title:Re.confirm.restartKernel(h),conseq:{title:Re.confirm.kernelNote},verb:Re.actions.restart,confirm:R,live:A,onConfirm:()=>E({kind:"kernel.restart"}),onClose:k}),c==="kernel.stop"&&e.jsx($a,{title:Re.confirm.stopKernel(h),conseq:{title:Re.confirm.kernelNote},verb:Re.actions.stop,confirm:R,live:A,onConfirm:()=>E({kind:"kernel.stop"}),onClose:k}),c==="daemon.restart"&&e.jsx($a,{title:Re.confirm.restartDaemon(h),conseq:{title:z},verb:Re.actions.restart,confirm:R,live:A,onConfirm:()=>E(wx("restart",o)),onClose:k}),c==="daemon.stop"&&e.jsx($a,{title:Re.confirm.stopDaemon(h),conseq:{title:z},verb:Re.actions.stop,confirm:R,live:A,onConfirm:()=>E({kind:"daemon.stop"}),onClose:k})]})}const ue=d.launch,t0=["claude","codex","cursor","omp"],s0=["always-ask","write","yolo"],n0=2e4,Ks={project:`${$s}launch.project`,prefs:`${$s}launch.prefs`,draft:`${$s}launch.draft`},Fr=(t,s)=>{try{return(t==null?void 0:t.getItem(s))??null}catch{return null}},Ca=(t,s,n)=>{try{n===null?t==null||t.removeItem(s):t==null||t.setItem(s,n)}catch{}};function uc(t){try{const s=JSON.parse(Fr(t,Ks.prefs)??"{}");return s&&typeof s=="object"?s:{}}catch{return{}}}const xc=t=>t.replace(/\/+$/,"").split("/").pop()||t,Ix=t=>t.machine==="local",mc=t=>Ix(t)&&t.exists!==!1;function pc({store:t,storage:s}){var he,Me,Fe,lt,et,jt,yt;const n=me(t),a=Qe(s),l=Ht(Ut().pc??((he=n.daemon)==null?void 0:he.name)??null),r=n.projects,[i,o]=f.useState(()=>Fr(a,Ks.project)),c=r.find(Q=>Q.id===i)??r[0],x=uc(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,w]=f.useState("always-ask"),[S,b]=f.useState(null),[j,N]=f.useState(()=>Fr(a,Ks.draft)??""),[C,M]=f.useState(null),[R,v]=f.useState(!1),[T,A]=f.useState(!1),[E,P]=f.useState(null),[I,L]=f.useState(null),$=f.useId(),O=c==null?void 0:c.id;f.useEffect(()=>{O&&n.fresh&&t.requestProjectFolders(O)},[O,n.fresh,t]),f.useEffect(()=>{var Q;n.fresh&&((Q=n.daemon)!=null&&Q.models)&&t.requestModels(m)},[m,n.fresh,(Me=n.daemon)==null?void 0:Me.models,t]);const U=O?n.projectFolders[O]:void 0,D=Array.isArray(U)?U:[],K=D.find(mc),te=(S??(K?[K.path]:[])).filter(Q=>D.some(H=>H.path===Q&&mc(H))),V=zi.includes(m),F=((Fe=n.models[m])==null?void 0:Fe.models)??[],B=Q=>{Q(),P(null),A(!1)},Y=Q=>B(()=>{o(Q.id),Ca(a,Ks.project,Q.id),b(null);const H=x[Q.id];p((H==null?void 0:H.tool)??"claude"),g({model:(H==null?void 0:H.model)??null,effort:(H==null?void 0:H.effort)??null}),M(null)}),G=Q=>B(()=>{p(Q),g({model:null,effort:null}),!zi.includes(Q)&&te.length>1&&b(te.slice(0,1))}),X=Q=>B(()=>{if(!V){b([Q]),M(null);return}const ye=te.includes(Q)?te.filter(Te=>Te!==Q):[...te,Q];b(ye.length?ye:te)}),re=Q=>{N(Q),Ca(a,Ks.draft,Q),P(null),A(!1)},ie=I?n.ops[I]:void 0,[ce,z]=f.useState(0);f.useEffect(()=>{if(!I)return;const Q=setTimeout(()=>{const H=t.getState().ops[I];H&&xs(H.phase)&&(v(!1),P({kind:"timeout",op:I}))},n0);return()=>clearTimeout(Q)},[I,ce,t]),f.useEffect(()=>{if(!I||!ie||xs(ie.phase))return;if(v(!1),L(null),ie.phase==="applied"){Ca(a,Ks.draft,null),c&&Ca(a,Ks.prefs,JSON.stringify({...uc(a),[c.id]:{tool:m,model:h.model,effort:h.effort}})),ie.id?(Nj(ie.id,(c==null?void 0:c.name)??"",s),ms({name:"thread",sessionId:ie.id})):ms({name:"sessions"});return}if(ie.phase==="failed"){P({kind:"failed"});return}const Q=ie.reason??"other";Q==="stale"&&O&&t.requestProjectFolders(O),P({kind:"refused",reason:Q})},[I,ie==null?void 0:ie.phase]);const k=async()=>{if(!c)return;const Q={project:c.id,tool:m,folders:te,prompt:j.trim(),...h.model?{model:h.model}:{},...h.effort?{effort:h.effort}:{},...m==="omp"&&y!=="always-ask"?{approval:y}:{}};v(!0),P(null),A(!1);const H=await t.launchSession(Q);if(H.status==="sent"){L(H.op),z(ye=>ye+1);return}v(!1),H.status==="cancelled"?A(!0):H.status==="noAnswer"?P({kind:"timeout",op:null}):H.status==="failed"?P({kind:"refused",reason:"other"}):P({kind:"refused",reason:H.reason})},_=Q=>{if(Q.kind==="timeout"&&Q.op){if(t.launchAgain(Q.op)){L(Q.op),z(ye=>ye+1),v(!0),P(null);return}const H=t.getState().ops[Q.op];if(H&&xs(H.phase)){P({...Q});return}}k()},W=Q=>Q.kind==="timeout"&&Q.op!==null&&!!n.ops[Q.op]&&xs(n.ops[Q.op].phase)&&!t.canLaunchAgain(Q.op),ee=d.tools[m],Z=!n.fresh,J=Z?{label:ue.missing.machine}:(lt=n.daemon)!=null&&lt.launch?(et=n.device)!=null&&et.confirm?!c||te.length===0?{label:ue.chooseProject}:j.trim()===""?{label:ue.missing.prompt}:null:{label:ue.missing.setup,body:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ue.setupBody}),e.jsxs("a",{href:"#/connection/link",className:Oe({size:"sm",className:"self-start"}),children:[e.jsx(q,{name:"gear",className:"size-4"}),ue.openSettings]})]})}:{label:ue.missing.pcOld(l),body:e.jsx("span",{className:"text-center text-[12px] leading-4 text-muted",children:ue.pcOldBody})},pe=E&&!(Z&&E.kind==="timeout")?E:null,be=h.model===null?null:((jt=F.find(Q=>Q.id===h.model))==null?void 0:jt.label)??h.model,Ze=h.model===null?d.model.byDefault:ue.pick(be,h.effort?oa(h.effort):null),pt=h.model===null?d.model.defaultHint:(()=>{const Q=F.find(H=>H.id===h.model);return Q?_d(m,Q):void 0})(),Ie=D.find(Q=>Q.path===te[0]),De=Ie?Ie===D[0]?Ie.branch?ue.onBranch(Ie.branch):ue.inFolder:xc(Ie.path):void 0,fe=Ie&&Ie!==D[0]?Ie.branch??void 0:void 0;return e.jsxs(e.Fragment,{children:[e.jsx(aa,{back:e.jsx("button",{type:"button","aria-label":ue.close,title:ue.close,onClick:()=>sl({name:"sessions"}),className:Mt({className:"text-muted"}),children:e.jsx(q,{name:"close"})}),name:ue.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(pn,{label:ue.project,children:r.length===0?e.jsxs("p",{className:"text-body text-muted",children:[d.launch.noProjects," ",ue.noProjectsBody]}):e.jsx(Yl,{onClick:()=>M("project"),lead:c?e.jsx(_e,{state:Z?"off":"idle"}):null,label:ue.project,text:c?e.jsx("b",{className:"font-semibold",children:c.name}):ue.chooseProject,sub:c?[l,Z?ue.offline:u?ue.remembered:null].filter(Boolean).join(" · "):void 0,dim:Z})}),c&&e.jsx(pn,{label:ue.where,children:e.jsx(Yl,{onClick:()=>M("where"),lead:e.jsx(q,{name:Ie!=null&&Ie.branch?"branch":"folder",className:"size-4 text-muted"}),label:ue.where,text:te.length>1&&De?e.jsxs(e.Fragment,{children:[e.jsxs("span",{"aria-hidden":"true",children:[De,e.jsx("span",{className:"ml-1.5 font-mono text-small text-muted",children:ue.more(te.length-1)})]}),e.jsx("span",{className:"sr-only",children:ue.moreLabel(De,te.length-1)})]}):De??"",sub:fe})}),e.jsx(pn,{label:ue.agent,children:e.jsx("div",{role:"group","aria-label":ue.agent,className:"grid grid-cols-2 gap-2",children:t0.map(Q=>e.jsxs("button",{type:"button","aria-pressed":Q===m,onClick:()=>G(Q),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[Q],e.jsx("small",{className:"text-[11.5px] font-normal text-muted",children:ue.tools[Q]})]},Q))})}),e.jsx(pn,{label:ue.model,children:e.jsx(Yl,{onClick:()=>M("model"),lead:e.jsx(q,{name:"cpu",className:"size-4 text-muted"}),label:ue.model,text:Ze,sub:pt})}),m==="omp"&&e.jsxs(pn,{label:ue.permissions,children:[e.jsx(Zn,{name:"launch-approval",legend:ue.permissions,value:y,onChange:Q=>B(()=>w(Q)),options:s0.map(Q=>({value:Q,label:ue.approvals[Q][0]}))}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ue.approvals[y][1]})]}),e.jsxs(pn,{label:ue.message,htmlFor:$,children:[e.jsx("textarea",{id:$,value:j,onChange:Q=>re(Q.target.value),placeholder:ue.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:ue.ideas.map(Q=>e.jsx("button",{type:"button",onClick:()=>re(Q),className:"h-8 rounded-lg border border-dashed border-input px-2.5 text-[12.5px] text-muted",children:Q},Q))})]})]}),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:[pe&&e.jsx(a0,{outcome:pe,agent:ee,machine:l,onRetry:W(pe)?null:()=>_(pe)}),J?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:!0,className:Oe({variant:"primary",className:"w-full"}),children:J.label}),J.body]}):e.jsx("button",{type:"button",disabled:R,onClick:()=>void k(),className:Oe({variant:"primary",className:"w-full"}),children:R?e.jsxs(e.Fragment,{children:[e.jsx(q,{name:"spinner",className:"size-4 motion-safe:animate-spin"}),ue.launching]}):e.jsxs(e.Fragment,{children:[At()&&e.jsx(q,{name:"face",className:"size-[18px]"}),At()?ue.launchCheck:ue.launchDevice]})}),T&&e.jsx("span",{role:"status",className:"text-center text-[12px] leading-4 text-destructive",children:ue.cancelled}),!J&&c&&e.jsx("span",{className:"text-center text-[12px] leading-4 text-muted",children:ue.summary(ee,be,l,c.name)})]}),C==="project"&&e.jsxs(ct,{labelledBy:"launch-project",onClose:()=>M(null),children:[e.jsx("h2",{id:"launch-project",className:"text-base font-semibold",children:ue.project}),e.jsx(fc,{children:r.map(Q=>e.jsx(hc,{on:Q.id===(c==null?void 0:c.id),onClick:()=>Y(Q),lead:e.jsx(_e,{state:Z?"off":"idle"}),text:Q.name,sub:Z?`${l} · ${ue.offline}`:l},Q.id))})]}),C==="where"&&c&&e.jsxs(ct,{labelledBy:"launch-where",onClose:()=>M(null),children:[e.jsxs("div",{children:[e.jsx("h2",{id:"launch-where",className:"text-base font-semibold",children:ue.where}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ue.folders(c.name)})]}),e.jsx(fc,{children:D.map((Q,H)=>{const ye=Ix(Q)?Q.exists===!1?ue.folder.missing(l):null:ue.folder.elsewhere(Q.label??Q.machine,l);return e.jsx(hc,{on:te.includes(Q.path),disabled:ye!==null,onClick:()=>X(Q.path),lead:e.jsx(q,{name:ye===null&&Q.branch?"branch":"folder",className:"size-5 text-muted"}),text:H===0?ue.projectFolder:xc(Q.path),sub:ye??Q.branch??void 0},`${Q.machine}:${Q.path}`)})}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ue.folder.single})]}),C==="model"&&e.jsx(ct,{labelledBy:pi,onClose:()=>M(null),children:e.jsx(yu,{tool:m,models:F,error:(yt=n.models[m])==null?void 0:yt.error,pick:h,onPick:Q=>B(()=>g(Q)),actions:e.jsx("button",{type:"button",onClick:()=>M(null),className:Oe({variant:"primary",className:"w-full"}),children:ue.done})})})]})}function pn({label:t,htmlFor:s,children:n}){const a=s?"label":"span";return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(a,{...s?{htmlFor:s}:{},className:"text-[12px] font-medium text-muted",children:t}),n]})}function Yl({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 fc({children:t}){return e.jsx("div",{className:"flex max-h-[50vh] flex-col overflow-y-auto rounded-[10px] border border-line",children:t})}function hc({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 a0({outcome:t,agent:s,machine:n,onRetry:a}){const l={label:ue.retry,onClick:a??(()=>{})};if(t.kind==="timeout")return a?e.jsx(at,{tone:"warn",title:ue.timeout,body:ue.timeoutBody,action:l}):e.jsx(at,{tone:"warn",title:ue.timeout,body:ue.lostBody,action:{label:d.atoi.seeSessions,href:ne({name:"sessions"})}});if(t.kind==="failed")return e.jsx(at,{tone:"fail",title:ue.failed(s),body:ue.failedBody(s),action:l});const r=ue.refused;switch(t.reason){case"not_found":return e.jsx(at,{tone:"fail",title:r.not_found,body:ue.kept});case"invalid":return e.jsx(at,{tone:"fail",title:r.invalid,body:r.invalidBody(s)});case"stale":return e.jsx(at,{tone:"fail",title:r.stale,body:r.staleBody});case"confirm_required":return e.jsx(at,{tone:"fail",title:r.confirm_required,body:r.setupKept,action:{label:ue.settings,href:"#/connection/link"}});case"assertion_invalid":return e.jsx(at,{tone:"fail",title:r.assertion_invalid,body:ue.kept,action:l});case"assertion_expired":return e.jsx(at,{tone:"warn",title:r.assertion_expired,body:r.expiredBody,action:l});case"unavailable":return e.jsx(at,{tone:"warn",title:r.unavailable(n),body:r.unavailableBody});default:return e.jsx(at,{tone:"fail",title:r.other,body:ue.kept})}}const zr="ledge.mobile.forge",l0=35e3,r0=65e3,Ai=(t,s)=>s?`${t}
21
+ ${s}`:t,Da=t=>t!=="checking"&&t!=="sending"&&t!=="received",Zl=t=>!!t&&(!Da(t.phase)||t.phase==="uncertain"&&!t.lost),gc=new Set(["assertion_invalid","assertion_expired","confirm_required","conflict"]);function i0(t){var s;try{const n=(s=Qe(t))==null?void 0:s.getItem(zr);if(!n)return null;const a=JSON.parse(n),l=gm.safeParse(a.state);return l.success&&typeof a.at=="string"?{state:l.data,at:a.at}:null}catch{return null}}function o0(t,s,n){var V;const a=i0(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,i=F=>{l={...l,...F};for(const B of[...r])B()};let o=!1,c=!1,x=!1;const u=new Map,m=new Map,p=new Map;let h=0,g=s.getState().daemon?((V=s.getState().daemon)==null?void 0:V.boot)??null:void 0;const y=new Set,w=()=>!o&&t.state()==="ready",S=()=>{var F;return!!((F=s.getState().daemon)!=null&&F.forge)},b=F=>{t.send(F).catch(()=>{})},j=(F,B,Y)=>{clearTimeout(u.get(F)),u.set(F,setTimeout(()=>{u.delete(F),Y()},B))},N=F=>{clearTimeout(u.get(F)),u.delete(F)};function C(){x||!c||!w()||!S()||(x=!0,b({type:"forge.state"}),i({loading:!0}),j("state",l0,()=>{x=!1,i({loading:!1})}))}const M=F=>l.runs.find(B=>B.op===F);function R(F,B){const Y=l.runs.findIndex(X=>X.id===F);if(Y<0)return;const G=B(l.runs[Y]);if(i({runs:l.runs.map((X,re)=>re===Y?G:X)}),Da(G.phase)){G.op&&G.phase!=="uncertain"&&m.delete(G.op);const X=p.get(F);p.delete(F),X==null||X(G)}}const v=F=>F.sentAt!==void 0&&Date.now()-F.sentAt<Fc&&g!==void 0&&(F.boot??null)===g,T=F=>{N(`op:${F.op}`),m.delete(F.op),R(F.id,B=>({...B,phase:"uncertain",lost:!0,endedAt:B.endedAt??Date.now()}))};function A(F){for(const[B,Y]of[...m]){const G=M(B);if(!G){m.delete(B);continue}if(!F.has(B)){if(!v(G)){T(G);continue}R(G.id,X=>({...X,again:!0})),b(Y),G.phase==="sending"&&P(B)}}}const E=(F,B)=>{N(`op:${F}`);const Y=M(F);Y&&Zl(Y)&&R(Y.id,G=>({...G,...B,endedAt:Date.now()}))},P=F=>j(`op:${F}`,zc,()=>{const B=M(F);(B==null?void 0:B.phase)==="sending"&&R(B.id,Y=>({...Y,phase:"uncertain",endedAt:Date.now()}))});function I(F){var B,Y,G;switch(F.type){case"snapshot":{const X=g;g=F.daemon.boot??null;const re=new Set(y);y.clear();for(const ie of re){const ce=M(ie);ce&&R(ce.id,z=>({...z,boot:g}))}(X===void 0||X!==g)&&A(re),C();return}case"forge.state":{N("state");const X=new Date().toISOString(),re={prs:F.prs,forges:F.forges,followed:F.followed,...F.mine?{mine:F.mine}:{}},ie=Object.keys(l.details).filter(ce=>{var _,W,ee;const z=(W=(_=l.details[ce])==null?void 0:_.data)==null?void 0:W.pr.headSha,k=(ee=[...re.prs,...re.mine??[]].find(Z=>Z.id===ce))==null?void 0:ee.headSha;return z&&k&&z!==k});i({state:re,at:X,loading:!1});try{(B=Qe(n))==null||B.setItem(zr,JSON.stringify({state:re,at:X}))}catch{}for(const ce of ie)te.readDetail(ce);return}case"forge.detail":{N(`detail:${F.prId}`);const X=l.details[F.prId];if(F.detail){const re=F.detail.log??((Y=X==null?void 0:X.data)!=null&&Y.log&&F.detail.jobs.some(ie=>ie.id===X.data.log.jobId)?X.data.log:void 0);i({details:{...l.details,[F.prId]:{data:{...F.detail,...re?{log:re}:{}},...F.cut?{cut:!0}:{},loading:!1,at:new Date().toISOString()}}})}else i({details:{...l.details,[F.prId]:{...X,loading:!1,error:F.error??"failed"}}});return}case"operation.result":{const X=M(F.op);if(!X||!Zl(X))return;if(F.status==="received"){N(`op:${F.op}`),(X.phase==="sending"||X.phase==="uncertain")&&R(X.id,re=>{const{endedAt:ie,...ce}=re;return{...ce,phase:"received"}});return}if(F.status==="rejected"&&X.again&&gc.has(F.reason??"")){T(X);return}F.status==="rejected"&&E(F.op,{phase:"rejected",reason:F.reason??"invalid"});return}case"forge.done":{const X=M(F.op);if(!X)return;if(X.again&&F.rejected&&gc.has(F.rejected)){X.lost||T(X);return}const re=F.rejected?{phase:"rejected",reason:F.rejected,done:F}:{phase:"done",done:F,...F.error?{reason:F.error}:{}};if(X.lost)m.delete(X.op),R(X.id,ie=>{const{lost:ce,...z}=ie;return{...z,...re,endedAt:Date.now()}});else{const ie=Zl(X);E(F.op,re),ie||R(X.id,ce=>({...ce,done:F}))}if(F.ok&&(X.action.kind==="comment"||X.action.kind==="reply")){const ie=Ai(X.prId,X.action.kind==="reply"?X.action.threadId:void 0);if(((G=l.drafts[ie])==null?void 0:G.trim())===X.action.body){const{[ie]:ce,...z}=l.drafts;i({drafts:z})}}l.details[X.prId]&&te.readDetail(X.prId);return}}}let L=w();const $=t.subscribe(()=>{const F=t.state();(F==="unpaired"||F==="pairing")&&U();const B=w();if(B&&!L)L=!0,h++,x=!1,g=void 0,y.clear();else if(!B&&L){L=!1,x=!1;for(const[G,X]of u)clearTimeout(X),u.delete(G);const Y=Object.fromEntries(Object.entries(l.details).map(([G,X])=>[G,X.loading?{...X,loading:!1}:X]));i({loading:!1,details:Y});for(const G of l.runs)G.phase==="sending"&&G.op&&R(G.id,X=>({...X,phase:"uncertain",endedAt:Date.now()}))}}),O=t.onMessage(I);function U(){var F;if(!(!l.state&&!l.runs.length&&!Object.keys(l.details).length&&!Object.keys(l.drafts).length)){try{(F=Qe(n))==null||F.removeItem(zr)}catch{}m.clear(),i({state:null,at:null,loading:!1,details:{},runs:[],drafts:{}})}}async function D(F){var X;if(!((X=s.getState().device)!=null&&X.confirm))return{phase:"rejected",reason:"confirm_required"};let B;try{B=await s.prepareConfirm(F)}catch(re){return{phase:re instanceof Error&&re.message==="timeout"?"expired":"unsent"}}if(!B.credentialId)return{phase:"rejected",reason:"confirm_required"};const Y=Date.now(),G=await ta({challenge:B.challenge,rpId:B.rpId,credentialId:B.credentialId}).catch(()=>"failed");return G==="cancelled"?{phase:"cancelled"}:G==="failed"?{phase:"unsent"}:Date.now()-Y>=B.expiresInMs?{phase:"expired"}:{assertion:G}}async function K(F,B,Y){var ie;P(B);const G=h,X=await t.send(Y).catch(()=>!1),re=(ie=M(B))==null?void 0:ie.phase;!X&&G===h&&(re==="sending"||re==="uncertain")&&(N(`op:${B}`),R(F,ce=>({...ce,phase:"unsent",endedAt:Date.now()})))}const te={getState:()=>l,subscribe(F){return r.add(F),()=>{r.delete(F)}},follow(){c=!0,C()},readDetail(F,B){!w()||!S()||(b({type:"forge.detail",prId:F,...B?{log:B}:{}}),i({details:{...l.details,[F]:{...l.details[F],loading:!0}}}),j(`detail:${F}`,r0,()=>i({details:{...l.details,[F]:{...l.details[F],loading:!1,error:"failed"}}})))},act(F,B){const Y=crypto.randomUUID(),G={op:"",id:Y,prId:F,action:B,phase:"checking",startedAt:Date.now()};if(!w()||!S()){const re={...G,phase:"unsent",endedAt:Date.now()};return i({runs:[...l.runs,re]}),Promise.resolve(re)}const X=new Promise(re=>p.set(Y,re));return i({runs:[...l.runs,G]}),(async()=>{const re=await D({purpose:"forge",forge:{prId:F,action:B}});if(!("assertion"in re)){R(Y,z=>({...z,phase:re.phase,...re.reason?{reason:re.reason}:{},endedAt:Date.now()}));return}const ie=Dc(),ce=Tc.safeParse({type:"forge.act",op:ie,prId:F,action:B,assertion:re.assertion});if(!ce.success||!w()){R(Y,z=>({...z,phase:"unsent",endedAt:Date.now()}));return}m.set(ie,ce.data),g===void 0&&y.add(ie),R(Y,z=>({...z,op:ie,phase:"sending",sentAt:Date.now(),boot:g??null})),await K(Y,ie,ce.data)})(),X},resend(F){const B=l.runs.find(G=>G.id===F),Y=B!=null&&B.op?m.get(B.op):void 0;if(!(!B||B.phase!=="uncertain"||B.lost||!Y||!w())){if(!v(B)){T(B);return}R(F,G=>{const{endedAt:X,...re}=G;return{...re,phase:"sending",again:!0}}),K(F,B.op,Y)}},setDraft(F,B){if(B)i({drafts:{...l.drafts,[F]:B}});else{const{[F]:Y,...G}=l.drafts;i({drafts:G})}},dismiss(F){const B=l.runs.find(Y=>Y.id===F);B&&Da(B.phase)&&B.op&&m.delete(B.op),i({runs:l.runs.filter(Y=>Y.id!==F||!Da(Y.phase))})},close(){o=!0,$(),O();for(const F of u.values())clearTimeout(F);u.clear()}};return te}function kl(t){return f.useSyncExternalStore(t.subscribe,t.getState,t.getState)}const Le=d.prs;function c0({status:t,pc:s}){const[n,a]=f.useState(!1),l=Jt(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:Le.missing(l.cli,s,t.host,l.kind)})});if(t.status==="unauthenticated"){const c=$h(t);return e.jsxs(Gt,{warn:!0,role:"alert",lead:r,children:[e.jsx("b",{"data-forge-strip":"unauthenticated",className:"font-semibold",children:Le.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?Le.copied:Le.copy})]})}const i=t.since??t.at,o=[t.retryAt?Le.retryAt(Pe(t.retryAt)):"",t.readAt?Le.readAt(l.kind,Pe(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:Le.error(l.host,s,Pe(i))}),o&&e.jsx("span",{className:"text-muted",children:o})]})})}function d0(){const t="block animate-[ledge-pulse_1.6s_ease-in-out_infinite] rounded-[5px] bg-raised";return e.jsxs("div",{role:"status","data-list-state":"",className:"flex flex-col gap-3",children:[e.jsx(Ve,{children:e.jsxs("div",{"aria-hidden":"true",className:"flex flex-col gap-2.5 p-2.5",children:[e.jsx("span",{className:`${t} h-3.5 w-[70%]`}),e.jsx("span",{className:`${t} h-3 w-[45%]`}),e.jsx("span",{className:`${t} h-3.5 w-[60%]`}),e.jsx("span",{className:`${t} h-3 w-1/2`})]})}),e.jsx("span",{className:"text-[12px] text-muted",children:Le.loading})]})}function u0(t,s,n){const a=n!=null&&n.readAt?Le.asOf(Pe(n.readAt)):Le.state[t.state];return[Le.host[t.forge],pl(t.repo),...s?[s]:[],a].join(" · ")}let bc={role:"all",q:""};function jc({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:Le.pill[a]},a)),t.sessions.length>0&&e.jsx("span",{"data-role-pill":"tracked",className:`${n} border-task/45 text-task`,children:Le.pill.tracked})]})}function x0({forge:t,store:s}){const n=kl(t),a=me(s),{pc:l,look:r}=Ut(),i=sa(),o=Et(),[c,x]=f.useState(!0),[u,m]=f.useState(null),[p,h]=f.useState(bc),g=C=>{bc=C,h(C)},y=r==="offline",w=Ht(l),S=n.state,b=C=>{var R;const M=C.sessions[0];return M?((R=a.sessions.get(M))==null?void 0:R.name)??null:null},j=C=>Le.offlineBody(n.at?Pe(n.at):C),N=(()=>{if(!S)return e.jsx(d0,{});const C=Sh(S.forges),M=D=>C.find(K=>K.forge===D.forge&&K.host===D.host),R=[...S.prs,...S.mine??[]],v={open:kh(R).open.sort((D,K)=>K.updatedAt.localeCompare(D.updatedAt)),closed:bm(R,Date.now())},T=jm(R),A=Pi(v.open,p.role,p.q),E=Pi(v.closed,p.role,p.q),P=p.role!=="all"||p.q.trim()!=="",I=`${p.role}
22
+ ${p.q.trim()}`,L=P&&A.length===0&&E.length>0,$=L?u!==I:!c,O=S.forges.length>0&&C.length===S.forges.length,U="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&&C.map(D=>e.jsx(c0,{status:D,pc:w},`${D.forge}:${D.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":Le.search,placeholder:Le.search,value:p.q,onChange:D=>g({...p,q:D.target.value}),className:"min-w-0 flex-1 bg-transparent text-[13px] text-fg outline-none placeholder:text-muted"})]}),e.jsx("div",{role:"group","aria-label":Le.rolesLabel,className:"-mx-1 flex gap-1.5 overflow-x-auto px-1 [scrollbar-width:none]",children:ym.map(D=>e.jsxs("button",{type:"button","aria-pressed":p.role===D,onClick:()=>g({...p,role:D}),className:`${U} ${p.role===D?"border-transparent bg-secondary text-fg":"border-line text-muted"}`,children:[Le.roles[D],e.jsx("span",{className:`font-mono text-[11px] ${D==="reviewer"?"text-attention":""}`,children:T[D]})]},D))})]}),L?null:A.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:Le.none}),e.jsx("button",{type:"button",className:ge({size:"sm"}),onClick:()=>g({role:"all",q:""}),children:Le.clear})]})}):A.length===0?e.jsx(Ve,{children:O?e.jsx(Zt,{framed:!1,glyph:null,title:Le.emptyTitle,body:Le.emptyUnread,list:E.length===0}):e.jsx(Zt,{glyph:e.jsx(q,{name:"pr",className:"size-[22px]"}),title:Le.emptyTitle,body:Le.emptyBody,list:E.length===0})}):e.jsxs(e.Fragment,{children:[e.jsx(Ft,{aside:!y&&n.at?Le.asOf(Pe(n.at)):void 0,children:Le.openHead(A.length)}),e.jsx(Ve,{label:Le.title,children:A.map(D=>{const K=M(D),te=Bd(D),V=e.jsxs(e.Fragment,{children:[e.jsx(ru,{pipeline:D.pipeline}),!y&&!K&&D.openThreads>0&&e.jsx(Qn,{children:Le.threads(D.openThreads)}),!y&&!K&&te&&e.jsx(Qn,{ok:!0,children:Le.ready})]});return e.jsx(ho,{pr:D,sub:u0(D,b(D),K),chips:V,pills:e.jsx(jc,{pr:D}),...y?{}:{href:ne({name:"pr",id:D.id})},selected:o&&i.name==="pr"&&i.id===D.id},D.id)})})]}),E.length>0&&e.jsxs(Ve,{children:[e.jsxs("button",{type:"button","aria-expanded":$,onClick:()=>L?m(D=>D===I?null:I):x(D=>!D),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:$?"down":"chevron",className:"size-3.5"}),Le.closedGroup(E.length)]}),$&&e.jsx("div",{className:"border-t border-line",children:E.map(D=>e.jsx(ho,{pr:D,dim:!0,pills:e.jsx(jc,{pr:D}),sub:[Le.host[D.forge],pl(D.repo),Le.state[D.state],Jh(D.updatedAt)].join(" · "),...y?{}:{href:ne({name:"pr",id:D.id})},selected:o&&i.name==="pr"&&i.id===D.id},D.id))})]})]}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:Le.tracked})]})})();return e.jsx(As,{title:Le.title,offlineBody:j,heading:!1,children:N})}const Xe=d.prs,it=d.rigs,fn=t=>Xe.notDone[t.action.kind],m0=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 Ei({run:t,pr:s,detail:n,forge:a,pc:l,onReload:r}){const i=Jt(s),o=At(),c={onClose:()=>a.dismiss(t.id),closeLabel:Xe.close};if(t.phase==="checking")return e.jsx(Yn,{children:it.running.checking});if(t.phase==="sending"||t.phase==="received")return e.jsx(Yn,{children:t.action.kind==="merge"?`${Xe.merging} · ${Xe.answers(i.cli)}`:Xe.answers(i.cli)});if(t.phase==="uncertain")return e.jsx(ve,{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:Xe.retry})});const x=m0(t),u=t.done;if(t.phase==="done"&&(u!=null&&u.ok)){const h=Pe(t.endedAt?new Date(t.endedAt).toISOString():null);return t.action.kind==="merge"?e.jsx(ve,{mark:"ok",title:Xe.merged(s.ref),sub:Xe.mergedSub(h,s.target),...c,children:u.command&&e.jsx(Gs,{commands:[u.command]})}):t.action.kind==="rerun"?e.jsx(ve,{mark:"ok",title:Xe.rerunDone(s.ref),sub:Xe.rerunDoneSub(h),...c,children:u.command&&e.jsx(Gs,{commands:[u.command]})}):t.action.kind==="reply"?e.jsx(ve,{mark:"ok",title:Xe.replyPosted(i.host),sub:h,...c}):t.action.kind==="comment"?e.jsx(ve,{mark:"ok",title:Xe.commentPosted(i.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(o):x==="assertion_invalid"?it.rejected.assertion_invalid(o):x==="cancelled"?it.rejected.cancelled:x==="unsent"?it.rejected.unsent:Xe.lastLine(i.cli),y=!["assertion_expired","assertion_invalid","cancelled","unsent"].includes(x??"");return e.jsx(ve,{mark:"bad",title:`${it.because(fn(t),g)} ${Xe.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:Xe.retry})})}const p=t.action.kind==="merge"?it.rejected.again(Xe.mergeAgain):it.rejected.nothingSent;switch(x){case"stale":return e.jsx(ve,{mark:"warn",title:Xe.stale(oi(s.headSha)),sub:Xe.staleBody,...c,children:e.jsx("button",{type:"button",onClick:r??(()=>a.readDetail(t.prId)),className:ge({size:"xs",className:"mt-1.5"}),children:Xe.reload})});case"not_offered":{if(t.action.kind==="rerun")return e.jsx(ve,{mark:"warn",title:Xe.nothingToRerun,...c});const h=n?xl(n).find(y=>!y.ok):void 0,g=h?hr(Bn(h,i.host),h):(u==null?void 0:u.message)??"";return e.jsx(ve,{mark:"bad",title:Xe.refused(i.host,g),...c})}case"busy":return e.jsx(ve,{mark:"warn",title:Xe.rerunRefused(Xe.rerunBusy),...c});case"confirm_required":return e.jsx(ve,{mark:"warn",title:it.rejected.confirm_required,...c});case"assertion_expired":return e.jsx(ve,{mark:"bad",title:it.because(fn(t),it.rejected.assertion_expired(o)),sub:p,...c});case"assertion_invalid":return e.jsx(ve,{mark:"bad",title:it.because(fn(t),it.rejected.assertion_invalid(o)),sub:p,...c});case"cancelled":return e.jsx(ve,{mark:"bad",title:it.because(fn(t),it.rejected.cancelled),sub:it.rejected.nothingSent,...c});case"unsent":return e.jsx(ve,{mark:"bad",title:it.because(fn(t),it.rejected.unsent),sub:it.rejected.nothingSent,...c});case"unavailable":return e.jsx(ve,{mark:"warn",title:Xe.gone(i.kind,l),sub:Xe.goneBody,...c});default:return e.jsx(ve,{mark:"bad",title:t.action.kind==="resolve"?it.because(fn(t),Xe.lastLine(i.cli)):Xe.failed(i.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(Gs,{commands:[u.command]})})}}const gn=d.prs,tl=t=>t.toLocaleString(st);function yc(t){return t.startsWith("@@")?"hunk":t.startsWith("+")?"add":t.startsWith("-")?"del":"ctx"}const p0={hunk:"bg-info/8 text-info",add:"bg-ok/15",del:"bg-danger-fg/15",ctx:"text-muted"};function Nc({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 kc({f:t}){return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"font-mono text-[12px] text-ok",children:["+",tl(t.added)]}),e.jsxs("span",{className:"font-mono text-[12px] text-danger-fg",children:["−",tl(t.removed)]})]})}function f0({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(Nc,{path:t.path}),r,e.jsx(kc,{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(i=>!i),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(Nc,{path:t.path}),r,e.jsx(kc,{f:t})]}),a&&e.jsx("pre",{className:"m-0 overflow-hidden border-t border-line bg-well font-mono text-[11px] leading-[17px]",children:t.patch.split(`
23
+ `).map((i,o)=>e.jsx("span",{"data-line":yc(i),className:`block overflow-hidden px-3 text-ellipsis whitespace-pre ${p0[yc(i)]}`,children:i||" "},o))})]})}function h0({detail:t}){if(t.files.length===0)return e.jsx("p",{className:"p-2.5 text-center text-[12px] text-muted",children:gn.noChange});const s=Rh(t),n=gn.host[t.pr.forge];return e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsx(Ft,{aside:e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"font-mono text-ok",children:["+",tl(s.added)]})," ",e.jsxs("span",{className:"font-mono text-danger-fg",children:["−",tl(s.removed)]})]}),children:gn.fileCount(t.files.length)}),e.jsx(Ve,{label:gn.tabs.changes,children:t.files.map(a=>e.jsx(f0,{f:a,threads:Th(t,a.path),host:n},a.path))})]})}const Jl=d.prs,g0=t=>[...t].sort((s,n)=>Date.parse(n.at)-Date.parse(s.at));function b0({detail:t}){return e.jsxs("div",{className:"flex flex-col gap-2.5",children:[t.commits.length>0&&e.jsx(Ve,{label:Jl.tabs.commits,children:g0(t.commits).map(s=>e.jsxs("div",{"data-commit":s.sha,className:"flex min-h-[52px] items-center gap-2.5 border-b border-line px-3 py-1.5 last:border-b-0",children:[e.jsx(q,{name:"commit",className:"size-4 text-muted"}),e.jsx("span",{className:"flex-none font-mono text-[12px] text-muted",children:oi(s.sha)}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col text-[13.5px]",children:[e.jsx("span",{className:"truncate",children:s.title}),e.jsx("small",{className:"text-[12px] text-muted",children:`${s.author} · ${yr(s.at)}`})]})]},s.sha))}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:Jl.commitsReadOnly(Jl.host[t.pr.forge])})]})}const ot=d.prs,Ri=t=>t.file?t.line!==void 0?ot.fileLine(t.file,t.line):t.file:null,Lx=(t,s,n)=>t.filter(a=>a.prId===s&&n(a)).at(-1),Ox=["checking","sending","received"];function Dx({sent:t,onClose:s}){return t==="refused"?e.jsx(ve,{mark:"bad",title:d.agents.notSent,onClose:s,closeLabel:ot.close}):e.jsx(ve,{mark:"ok",title:ot.commentSent(t.name),onClose:s,closeLabel:ot.close,children:e.jsx("a",{href:ne({name:"thread",sessionId:t.id}),className:ge({size:"xs",className:"mt-1.5"}),children:ot.openAgent(t.name)})})}function Fx({id:t,label:s,placeholder:n,verb:a,value:l,onChange:r,confirm:i,live:o,onPost:c,host:x,autoFocus:u=!1,rows:m=2,arrow:p=!1}){const h=e.jsx("textarea",{id:t,rows:l?Math.max(m,2):m,value:l,placeholder:n,autoFocus:u,onChange:g=>r(g.target.value),className:p?"min-h-[34px] min-w-0 flex-1 resize-none bg-transparent py-[6px] text-base leading-[22px] text-fg outline-none placeholder:text-muted":"min-h-11 w-full resize-none rounded-[14px] border border-input bg-surface px-3.5 py-[11px] text-base leading-5 text-fg placeholder:text-muted"});return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:t,className:"sr-only",children:s}),p?e.jsxs("div",{className:"flex min-w-0 items-end gap-2 rounded-[10px] border border-input bg-surface py-[5px] pr-[5px] pl-3 focus-within:border-ring focus-within:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)]",children:[h,l.trim()===""&&e.jsx("button",{type:"button",disabled:!0,"aria-label":a,title:a,className:"grid size-9 flex-none place-items-center rounded-lg bg-primary text-primary-fg disabled:opacity-40",children:e.jsx(q,{name:"send",className:"size-[18px]"})})]}):h,l.trim()!==""&&e.jsxs(e.Fragment,{children:[e.jsx(Fs,{verb:a,confirm:i,disabled:!o,onClick:c}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ot.postedAs(x)})]})]})}const j0=({who:t,at:s,body:n,reply:a})=>e.jsxs("p",{className:`m-0 text-[13.5px] leading-[19px] [overflow-wrap:anywhere] whitespace-pre-wrap ${a?"border-l-2 border-line pl-[9px]":""}`,children:[e.jsx("span",{className:"font-semibold",children:t}),e.jsx("span",{className:"ml-1 font-mono text-[11px] text-muted",children:Pe(s)}),e.jsx("br",{}),n]}),y0="flex flex-col gap-2 rounded-[10px] border border-line bg-surface p-2.5 dark:bg-transparent",er="h-9 !px-2.5 text-[12.5px]";function zx({pr:t,t:s,agent:n,forge:a,store:l,live:r,pc:i,readOnly:o=!1}){var v,T;const c=kl(a),x=me(l),[u,m]=f.useState(!1),[p,h]=f.useState(null),g=Ai(t.id,s.id),y=c.drafts[g]??"",w=Jt(t),S=Ri(s),b=s.comments[0],j=Lx(c.runs,t.id,A=>(A.action.kind==="reply"||A.action.kind==="resolve")&&A.action.threadId===s.id),N=()=>{n&&h(l.reply(n.id,ot.threadText(t.ref,b.author,S,b.body))?n:"refused")},C=()=>{m(!1),a.act(t.id,{kind:"reply",threadId:s.id,body:y.trim()})},M=!!j&&Ox.includes(j.phase),R=!M&&(u||y!==""&&(j==null?void 0:j.action.kind)==="reply"&&j.phase!=="uncertain"&&!(j.phase==="done"&&((v=j.done)!=null&&v.ok)));return e.jsxs("article",{"data-thread":s.id,className:y0,children:[S&&e.jsx("span",{className:"font-mono text-[11px] text-muted",children:S}),s.code&&e.jsx("code",{className:"block truncate rounded-md bg-ok/15 px-2 py-[3px] font-mono text-[11.5px] leading-[17px] whitespace-pre",children:s.code}),s.comments.map((A,E)=>e.jsx(j0,{who:A.author,at:A.at,body:A.body,reply:E>0},A.id)),!o&&e.jsxs(e.Fragment,{children:[R?e.jsx(Fx,{id:`reply-${s.id}`,label:ot.reply,placeholder:ot.replyPh,verb:ot.reply,value:y,onChange:A=>a.setDraft(g,A),confirm:!!((T=x.device)!=null&&T.confirm),live:r,onPost:C,host:w.host,autoFocus:u}):e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsx("button",{type:"button",disabled:!r||M,onClick:()=>m(!0),className:ge({className:er}),children:ot.reply}),n&&e.jsx("button",{type:"button",disabled:!x.fresh,onClick:N,className:ge({className:er}),children:ot.sendTo(n.name)}),s.resolvable&&e.jsx("button",{type:"button",disabled:!r||M,onClick:()=>void a.act(t.id,{kind:"resolve",threadId:s.id}),className:`${ge({className:er})} border-transparent`,children:ot.resolve})]}),p&&e.jsx(Dx,{sent:p,onClose:()=>h(null)}),j&&e.jsx(Ei,{run:j,pr:t,detail:void 0,forge:a,pc:i})]})]})}function N0({pr:t,t:s,forge:n,store:a,pc:l}){const[r,i]=f.useState(!1),o=Ri(s);return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-expanded":r,onClick:()=>i(c=>!c),"data-thread":s.id,className:"flex items-center gap-2 rounded-[10px] border border-dashed border-line px-2.5 py-2 text-left text-[12.5px] text-muted",children:[e.jsx("span",{"aria-hidden":"true",className:"text-ok",children:"✓"}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:ot.resolvedRow([...o?[o]:[],s.comments[0].author])}),e.jsx(q,{name:r?"down":"chevron",className:"size-3.5"})]}),r&&e.jsx(zx,{pr:t,t:s,agent:null,forge:n,store:a,live:!1,pc:l,readOnly:!0})]})}function Px(t,s){const n=me(s),[a,l]=f.useState(null),r=(t==null?void 0:t.threads)??[],i=t?iu(t.pr,n.sessions)[0]:void 0,o=i?{id:i.id,name:i.name}:null,c=r.filter(u=>!u.resolved),x=()=>{if(!o||!t)return;const u=c.map(m=>ot.note(m.comments[0].author,Ri(m),m.comments[0].body));l(s.reply(o.id,ot.notesText(t.pr.ref,u))?o:"refused")};return{agent:o,open:c,resolved:r.filter(u=>u.resolved),sent:a,send:x,clear:()=>l(null),fresh:n.fresh}}function Bx({all:t,className:s=""}){return!t.agent||!t.open.length?null:e.jsxs("button",{type:"button",disabled:!t.fresh,onClick:t.send,className:ge({size:"sm",className:s}),children:[e.jsx(q,{name:"send",className:"size-4"}),ot.sendAll(t.agent.name)]})}function vc({detail:t,forge:s,store:n,live:a,pc:l,column:r}){const i=Px(t,n),o=r??i,c=t.pr;return t.threads.length?e.jsxs(e.Fragment,{children:[!r&&e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[12.5px] text-muted",children:ot.discSub(o.open.length,o.resolved.length)}),e.jsx("span",{className:"flex-1"}),e.jsx(Bx,{all:o})]}),o.sent&&e.jsx(Dx,{sent:o.sent,onClose:o.clear}),o.open.map(x=>e.jsx(zx,{pr:c,t:x,agent:o.agent,forge:s,store:n,live:a,pc:l},x.id)),o.resolved.map(x=>e.jsx(N0,{pr:c,t:x,forge:s,store:n,pc:l},x.id))]}):e.jsx("p",{className:"m-0 p-2.5 text-center text-[12.5px] text-muted",children:ot.noComment})}function wc({pr:t,forge:s,store:n,live:a,pc:l}){var m;const r=kl(s),i=me(n),o=Ai(t.id),c=r.drafts[o]??"",x=Lx(r.runs,t.id,p=>p.action.kind==="comment"),u=!!x&&Ox.includes(x.phase);return e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[x&&e.jsx(Ei,{run:x,pr:t,detail:void 0,forge:s,pc:l}),e.jsx(Fx,{id:`comment-${t.id}`,label:ot.addComment,placeholder:ot.addComment,verb:ot.post,value:c,onChange:p=>s.setDraft(o,p),confirm:!!((m=i.device)!=null&&m.confirm),live:a&&!u,onPost:()=>void s.act(t.id,{kind:"comment",body:c.trim()}),host:Jt(t).host,rows:1,arrow:!0})]})}const k0=`${Yr} and (orientation: landscape)`,qx=()=>typeof globalThis.matchMedia=="function"?globalThis.matchMedia(k0):null,v0=t=>{var n;const s=qx();return(n=s==null?void 0:s.addEventListener)==null||n.call(s,"change",t),()=>{var a;return(a=s==null?void 0:s.removeEventListener)==null?void 0:a.call(s,"change",t)}};function w0(){return f.useSyncExternalStore(v0,()=>{var t;return((t=qx())==null?void 0:t.matches)??!1},()=>!1)}const ae=d.prs,S0={review:"border-attention/45 text-attention"};function $0({pr:t,landscape:s}){const n=Et(),a=Jt(t);return n?e.jsxs("header",{"data-pr-head":"",className:"flex h-[58px] flex-none items-center gap-[9px] border-b border-line pr-2.5 pl-[22px]",children:[e.jsx("span",{className:"inline-flex h-5 flex-none items-center rounded-lg border border-input px-[7px] text-[11.5px] whitespace-nowrap text-muted",children:`${a.host} · ${a.kind}`}),e.jsx("h1",{className:"min-w-0 truncate text-[16px] font-semibold",children:`${t.ref} ${t.title}`}),s&&e.jsx("span",{"data-pr-state":t.state,className:`inline-flex h-[22px] flex-none items-center rounded-full border px-[9px] text-[12px] font-medium whitespace-nowrap ${S0[t.state]??"border-input text-muted"}`,children:ae.state[t.state]}),e.jsx("span",{className:"flex-1"}),s?e.jsxs("a",{href:t.url,target:"_blank",rel:"noreferrer",className:ge({size:"sm",className:"flex-none"}),children:[e.jsx(q,{name:"external",className:"size-4"}),ae.openOn(a.host)]}):e.jsx("a",{href:t.url,target:"_blank",rel:"noreferrer","aria-label":ae.openOn(a.host),title:ae.openOn(a.host),className:Mt(),children:e.jsx(q,{name:"external",className:"size-[18px]"})})]}):e.jsxs("header",{className:`flex flex-none items-center gap-2 border-b border-line pr-1.5 ${n?"pane-head h-[58px]":"h-14 pl-0.5"}`,children:[e.jsx(is,{fallback:{name:"prs"},label:ae.title}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("h1",{className:"truncate text-[15px] font-semibold",children:`${t.ref} ${t.title}`}),e.jsx("small",{className:"truncate text-[12px] text-muted",children:[a.host,pl(t.repo),`${t.branch} → ${t.target}`].join(" · ")})]}),e.jsx("a",{href:t.url,target:"_blank",rel:"noreferrer","aria-label":ae.openOn(a.host),title:ae.openOn(a.host),className:Mt(),children:e.jsx(q,{name:"external",className:"size-[18px]"})})]})}const C0=["overview","discussion","changes","commits"],M0=["overview","changes","commits"];function A0({pr:t,d:s,view:n,views:a,onView:l,wide:r}){const i=s?{discussion:s.threads.length,changes:s.files.length,commits:s.commits.length}:{};return e.jsx("nav",{"aria-label":ae.title,className:`flex flex-none gap-0.5 overflow-x-auto overflow-y-hidden border-b border-line [scrollbar-width:none] ${r?"px-1.5 py-2":"p-2"}`,children:a.map(o=>e.jsxs("button",{type:"button","aria-current":n===o?"page":void 0,onClick:()=>l(o),className:"group inline-flex h-9 flex-none items-center gap-[5px] rounded-lg px-[7px] text-[13px] font-medium whitespace-nowrap text-muted aria-[current=page]:bg-raised aria-[current=page]:text-fg",children:[o==="overview"&&e.jsx(_e,{state:nn[t.pipeline],pulse:t.pipeline==="run"}),ae.tabs[o],i[o]!==void 0&&e.jsx("span",{className:"inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-raised px-1 font-mono text-[11px] group-aria-[current=page]:bg-bg",children:i[o]})]},o))})}const Hx={ok:"border-ok/40",fail:"border-approval/60",run:"border-info/50",wait:"border-line text-muted",skip:"border-line text-muted",none:"border-line text-muted"},Ux=t=>t==="fail"?"bg-danger-bg":"bg-surface dark:bg-transparent";function Wx(t){if(t.status==="run")return e.jsx("span",{className:"font-mono text-[12px] text-info",children:ae.pipe.run});const s=Wd(t.durationS);return s?e.jsx("span",{className:"font-mono text-[12px] text-muted",children:s.hours?ae.hours(s.text):s.text}):t.status==="wait"||t.status==="skip"?e.jsx("span",{className:"text-[12px]",children:ae.pipe[t.status]}):null}function E0({job:t,selected:s,onOpen:n}){const a=e.jsxs(e.Fragment,{children:[t.status==="run"?e.jsx(An,{}):e.jsx(_e,{state:nn[t.status]}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.name}),Wx(t)]}),l=`flex h-11 w-full items-center gap-2.5 rounded-[10px] border px-3 text-left text-[14px] ${Ux(t.status)} ${Hx[t.status]} ${s?"shadow-[0_0_0_2px_var(--color-ring)]":""}`;return n?e.jsx("button",{type:"button","data-job":t.id,onClick:n,className:l,children:a}):e.jsx("div",{"data-job":t.id,className:l,children:a})}function R0({after:t}){const s=t.jobs.some(a=>a.status==="fail"),n=t.jobs.every(a=>a.status==="ok");return e.jsx("span",{"aria-hidden":"true",className:`mt-[5px] mb-[5px] ml-[22px] block h-3 ${s?"border-l-2 border-dashed border-approval":`w-0.5 ${n?"bg-ok":"bg-input"}`}`})}function T0({pr:t,jobs:s,selected:n,onJob:a}){const l=Hd(s);return e.jsx("div",{className:"flex flex-col",children:l.map((r,i)=>e.jsxs("div",{className:"flex flex-col",children:[i>0&&e.jsx(R0,{after:l[i-1]}),e.jsx("div",{className:"mb-[5px] text-[11px] tracking-[.5px] text-muted uppercase",children:t.forge==="gitlab"?ae.stage(i+1,r.name):r.name}),e.jsx("div",{className:"flex flex-col gap-1.5",children:r.jobs.map(o=>e.jsx(E0,{job:o,selected:o.id===n,onOpen:o.id===n?void 0:()=>a(o)},o.id))})]},r.column))})}function _0({job:t,selected:s,onOpen:n}){const a=e.jsxs(e.Fragment,{children:[t.status==="run"?e.jsx(An,{}):e.jsx(_e,{state:nn[t.status]}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.name}),Wx(t)]}),l=`flex h-10 min-w-[92px] items-center gap-[7px] rounded-[10px] border px-[9px] text-left text-[13px] ${Ux(t.status)} ${Hx[t.status]} ${s?"shadow-[0_0_0_2px_var(--color-ring)]":""}`;return n?e.jsx("button",{type:"button","data-job":t.id,onClick:n,className:l,children:a}):e.jsx("div",{"data-job":t.id,className:l,children:a})}function I0({after:t}){const s=t.jobs.some(a=>a.status==="fail"),n=t.jobs.every(a=>a.status==="ok");return e.jsx("span",{"aria-hidden":"true",className:`mt-[39px] block w-5 flex-none ${s?"border-t-2 border-dashed border-approval":`h-0.5 ${n?"bg-ok":"bg-input"}`}`})}function L0({pr:t,jobs:s,selected:n,onJob:a}){const l=Hd(s);return e.jsx("div",{"data-pipeline":"side",className:"flex flex-none items-start overflow-x-auto rounded-[10px] border border-line bg-surface p-3.5 dark:bg-[oklch(0.18_0_0)]",children:l.map((r,i)=>e.jsxs("div",{className:"contents",children:[i>0&&e.jsx(I0,{after:l[i-1]}),e.jsxs("div",{className:"flex min-w-0 flex-[0_1_auto] flex-col gap-2",children:[e.jsx("div",{className:"mb-[5px] text-[11px] tracking-[.5px] whitespace-nowrap text-muted uppercase",children:t.forge==="gitlab"?ae.stage(i+1,r.name):r.name}),r.jobs.map(o=>e.jsx(_0,{job:o,selected:o.id===n,onOpen:o.id===n?void 0:()=>a(o)},o.id))]})]},r.column))})}const O0=({text:t,tall:s=!1})=>e.jsx("pre",{className:`m-0 overflow-hidden rounded-[10px] border border-white/10 bg-[#0c0c0d] px-[11px] py-[9px] font-mono text-[11.5px] leading-[17px] break-all whitespace-pre-wrap text-[#e5e5e5] ${s?"max-h-[300px] overflow-y-auto":""}`,children:t});function Kx({job:t,read:s,pr:n,onRetry:a,tall:l=!1}){var o,c;const r=Jt(n),i=((c=(o=s==null?void 0:s.data)==null?void 0:o.log)==null?void 0:c.jobId)===t.id?s.data.log.text:null;return i!==null?e.jsx(O0,{text:i,tall:l}):s!=null&&s.loading?e.jsxs("div",{role:"status",className:"flex items-center gap-2 text-[12px] text-muted",children:[e.jsx(An,{className:"text-muted"}),ae.log.reading(t.name)]}):e.jsx(ve,{mark:"bad",title:ae.log.failed,sub:ae.log.failedBody(r.cli,r.host),children:e.jsx("button",{type:"button",onClick:a,className:ge({size:"xs",className:"mt-1.5"}),children:ae.retry})})}function D0({job:t,read:s,pr:n,onRetry:a,onClose:l}){var x,u;const r=f.useId(),i=Jt(n),o=Wd(t.durationS),c=((u=(x=s==null?void 0:s.data)==null?void 0:x.log)==null?void 0:u.jobId)===t.id?s.data.log.text:null;return e.jsxs(ct,{labelledBy:r,onClose:l,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(_e,{state:nn[t.status]}),e.jsx("h2",{id:r,className:"text-[15px] font-semibold",children:ae.log.title(t.name)}),e.jsx("span",{className:"text-[12px] text-muted",children:[ae.pipe[t.status],o?o.hours?ae.hours(o.text):o.text:""].filter(Boolean).join(" · ")})]}),e.jsx(Kx,{job:t,read:s,pr:n,onRetry:a,tall:!0}),c!==null&&e.jsx("p",{className:"m-0 text-[12px] leading-4 text-muted",children:[ae.log.note,Ch(c)?ae.log.cut(i.host):""].filter(Boolean).join(" ")}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("a",{href:n.url,target:"_blank",rel:"noreferrer",className:ge(),children:[e.jsx(q,{name:"external",className:"size-4"}),ae.openOn(i.host)]}),e.jsx("button",{type:"button",onClick:l,className:ge(),children:ae.close})]})]})}function F0({text:t}){return e.jsx("div",{className:"text-[13.5px] leading-5",children:t.split(/\n\n+/).map((s,n)=>{const a=s.split(`
24
+ `);return a.every(l=>l.startsWith("- "))?e.jsx("ul",{className:"mt-1 list-disc pl-[18px]",children:a.map((l,r)=>e.jsx("li",{children:l.slice(2)},r))},n):e.jsx("p",{className:"m-0 whitespace-pre-wrap",children:s},n)})})}const z0={approved:"idle",changes:"perm",pending:"plain"};function P0({d:t}){const s="text-muted",n="m-0 flex min-w-0 flex-wrap items-center gap-1.5";return e.jsxs("dl",{className:"m-0 grid grid-cols-[auto_1fr] gap-x-3.5 gap-y-1.5 border-t border-line pt-2.5 text-[13px]",children:[e.jsx("dt",{className:s,children:ae.author}),e.jsx("dd",{className:n,children:t.author}),t.reviewers.map((a,l)=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:s,children:l===0?ae.reviewers:""}),e.jsxs("dd",{className:n,children:[e.jsx(_e,{state:z0[a.state]}),a.name," ",e.jsx("span",{className:"text-muted",children:ae.reviewer[a.state]})]})]},a.name)),t.labels.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:s,children:ae.labels}),e.jsx("dd",{className:n,children:t.labels.map(a=>e.jsx("span",{className:"rounded-full border border-line px-2 text-[12px]",children:a},a))})]}),t.issues.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:s,children:ae.issue}),e.jsx("dd",{className:`${n} font-mono text-[12px]`,children:t.issues.join(" ")})]})]})}function B0({conds:t,host:s}){return e.jsxs("section",{"aria-label":ae.toMerge,className:"flex-none overflow-hidden rounded-[10px] border border-line bg-surface dark:bg-transparent",children:[e.jsx("div",{className:"flex min-h-11 items-center border-b border-line px-3",children:e.jsx("b",{className:"text-[14px] font-semibold",children:ae.toMerge})}),e.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-2.5 text-[13px]",children:t.map((n,a)=>e.jsxs("li",{"data-cond":n.ok?"ok":n.key,className:"flex items-baseline gap-2",children:[e.jsx("span",{"aria-hidden":"true",className:`w-3.5 flex-none text-center text-[12px] font-semibold ${n.ok?"text-ok":"text-approval"}`,children:n.ok?"✓":"✕"}),e.jsx("span",{className:n.key==="raw"?"font-mono":"",children:Bn(n,s)})]},a))})]})}function q0(t,s){const n=xl(t),a=n.find(i=>!i.ok);if(a)return e.jsxs(e.Fragment,{children:[ae.footApprovals(Kd(t.pr))," · ",e.jsx("b",{className:"font-medium text-fg",children:hr(Bn(a,s),a)})]});const l=n.find(i=>i.key==="pipeline"||i.key==="noCi"),r=n.find(i=>i.key==="approved");return`${Bn(l,s)} · ${hr(Bn(r,s),r)}`}function Vx(){const t="block animate-[ledge-pulse_1.6s_ease-in-out_infinite] rounded-[10px] bg-raised";return e.jsxs("div",{role:"status",className:"flex flex-col gap-1.5",children:[e.jsx("span",{"aria-hidden":"true",className:`${t} h-11`}),e.jsx("span",{"aria-hidden":"true",className:`${t} h-11`}),e.jsx("span",{"aria-hidden":"true",className:`${t} h-[60px]`}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ae.detailLoading})]})}function H0({pr:t,job:s,store:n}){const a=me(n),l=iu(t,a.sessions),[r,i]=f.useState(null),[o,c]=f.useState(!1),[x,u]=f.useState(null),m=f.useId();if(!l.length)return e.jsx("p",{className:"m-0 text-[12px] leading-4 text-muted",children:ae.noSession(t.branch)});const p=l.find(y=>y.id===r)??l[0],h=a.fresh,g=()=>{u(n.reply(p.id,ae.fixText(t.ref,s))?{id:p.id,name:p.name}:"refused")};return e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("button",{type:"button",disabled:!h,onClick:g,className:ge({tone:"dangerfill",className:"flex-1"}),children:ae.askFix(p.name)}),l.length>1&&e.jsx("button",{type:"button","aria-label":ae.otherSession,title:ae.otherSession,"aria-haspopup":"menu",disabled:!h,onClick:()=>c(!0),className:ge({className:"w-12 !px-0"}),children:e.jsx(q,{name:"down",className:"size-4"})})]}),x==="refused"&&e.jsx(ve,{mark:"bad",title:d.agents.notSent,onClose:()=>u(null),closeLabel:ae.close}),x&&x!=="refused"&&e.jsx(ve,{mark:"ok",title:ae.sentTo(x.name),onClose:()=>u(null),closeLabel:ae.close,children:e.jsx("a",{href:ne({name:"thread",sessionId:x.id}),className:ge({size:"xs",className:"mt-1.5"}),children:ae.openAgent(x.name)})}),o&&e.jsxs(ct,{labelledBy:m,onClose:()=>c(!1),children:[e.jsx("h2",{id:m,className:"sr-only",children:ae.otherSession}),e.jsx("div",{role:"menu","aria-labelledby":m,className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:l.map((y,w)=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":y.id===p.id,onClick:()=>{i(y.id),c(!1)},className:"flex min-h-12 items-center gap-3 border-b border-line px-3.5 text-left text-[15px] last:border-b-0 aria-checked:bg-secondary",children:[e.jsx(_e,{state:Sn(y)}),e.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[y.name," ",e.jsx("small",{className:"text-[12px] text-muted",children:[d.tools[y.tool],y.repo].filter(Boolean).join(" · ")})]}),w===0&&e.jsx("span",{className:"text-[12px] text-muted",children:ae.mostActive})]},y.id))})]})]})}function U0({pr:t,confirm:s,live:n,onRerun:a,onClose:l}){return e.jsxs(os,{title:ae.rerunTitle(t.ref),onClose:l,children:[e.jsx("p",{className:"m-0 text-[12.5px] leading-[18px] text-muted",children:ae.rerunBody(Jt(t).host)}),e.jsx(Fs,{verb:ae.rerun,confirm:s,disabled:!n,onClick:()=>{l(),a()}}),e.jsx(fa,{onClose:l})]})}function W0({pr:t,read:s,store:n,live:a,onJob:l,onLog:r,onRerun:i,side:o}){const c=s==null?void 0:s.data,x=Jt(t),u=c?Ud(c.jobs):null,m=t.state!=="merged"&&t.state!=="closed",p=t.pipeline==="none"?ae.noCi:c!=null&&c.mergeBlockers.includes("pipeline_not_started")?ae.notStarted:null;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{className:"m-0 text-[15px] font-semibold",children:ae.pipelineTitle}),e.jsx(ru,{pipeline:t.pipeline,short:!0}),e.jsx("span",{className:"flex-1"}),Eh(t)&&e.jsxs("button",{type:"button",disabled:!a,onClick:i,className:ge({size:"sm"}),children:[e.jsx(q,{name:"refresh",className:"size-4"}),ae.rerun]})]}),p&&e.jsx("p",{className:"m-0 text-[12px] text-muted",children:p}),c?e.jsxs(e.Fragment,{children:[c.jobs.length>0&&(o?e.jsx(L0,{pr:t,jobs:c.jobs,selected:(u==null?void 0:u.id)??null,onJob:l}):e.jsx(T0,{pr:t,jobs:c.jobs,selected:(u==null?void 0:u.id)??null,onJob:l})),u&&e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"flex items-center gap-2 text-[12px] text-muted",children:e.jsx("span",{children:`${ae.log.title(u.name)} · ${ae.log.lines}`})}),e.jsx(Kx,{job:u,read:s,pr:t,onRetry:()=>r(u)}),m&&e.jsx(H0,{pr:t,job:u.name,store:n})]}),m&&e.jsx(B0,{conds:xl(c),host:x.host}),c.description&&e.jsxs("div",{className:"flex flex-col gap-1.5 border-t border-line pt-2.5",children:[e.jsx("h2",{className:"m-0 text-[15px] font-semibold",children:ae.description}),e.jsx(F0,{text:c.description})]}),e.jsx(P0,{d:c})]}):e.jsx(Vx,{})]})}function K0({read:t,pr:s,pc:n,onRetry:a}){const l=Jt(s);return t.error==="unavailable"?e.jsx(ve,{mark:"warn",title:ae.gone(l.kind,n),sub:ae.goneBody}):t.error==="too_large"?e.jsx(ve,{mark:"bad",title:ae.tooLarge,sub:ae.tooLargeBody(l.host),children:e.jsx("a",{href:s.url,target:"_blank",rel:"noreferrer",className:ge({size:"xs",className:"mt-1.5"}),children:ae.open})}):e.jsx(ve,{mark:"bad",title:ae.readFailed(l.cli,l.kind),sub:ae.readFailedBody,children:e.jsx("button",{type:"button",onClick:a,className:ge({size:"xs",className:"mt-1.5"}),children:ae.retry})})}function V0({d:t,pc:s,confirm:n,live:a,onMerge:l,onClose:r}){return e.jsxs(os,{title:ae.confirm(t.pr.ref,t.pr.target),onClose:r,children:[e.jsx("span",{className:"text-[12.5px] text-muted",children:ae.runsOn(s)}),e.jsx("code",{className:"block rounded-md bg-raised px-2 py-1.5 font-mono text-[12px] break-all",children:t.mergeCommand}),e.jsx("p",{className:"m-0 text-[12px] leading-4 text-muted",children:ae.headRead(oi(t.pr.headSha))}),e.jsx(Fs,{verb:ae.merge,confirm:n,disabled:!a,onClick:()=>{r(),l()}}),e.jsx(fa,{onClose:r})]})}const G0=(t,s)=>t.filter(n=>n.prId===s&&(n.action.kind==="merge"||n.action.kind==="rerun")).at(-1),X0=t=>!!t&&(t.phase==="checking"||t.phase==="sending"||t.phase==="received");function Q0({id:t,forge:s,store:n,pane:a=!1}){var ce,z,k,_,W,ee;const l=kl(s),r=me(n),[i,o]=f.useState(!1),[c,x]=f.useState(!1),{pc:u,look:m}=Ut(),p=Et(),h=w0()&&p&&!a,[g,y]=f.useState("overview"),[w,S]=f.useState(null),b=m==="offline",j=Ht(u),N=l.details[t],C=l.state&&[...l.state.prs,...l.state.mine??[]].find(Z=>Z.id===t),M=C??((ce=N==null?void 0:N.data)==null?void 0:ce.pr),R=Px(N==null?void 0:N.data,n);f.useEffect(()=>{s.readDetail(t)},[s,t]);const v=N!=null&&N.data?Ud(N.data.jobs):null,T=f.useRef(null);f.useEffect(()=>{var Z,J;!v||((J=(Z=N==null?void 0:N.data)==null?void 0:Z.log)==null?void 0:J.jobId)===v.id||T.current===v.id||(T.current=v.id,s.readDetail(t,v.id))},[s,t,v==null?void 0:v.id,(k=(z=N==null?void 0:N.data)==null?void 0:z.log)==null?void 0:k.jobId]);const A=f.useRef(null);f.useEffect(()=>{var Z,J;(J=(Z=A.current)==null?void 0:Z.scrollTo)==null||J.call(Z,{top:0})},[g]);const E=`tab-main flex min-h-0 flex-1 flex-col gap-2.5 overflow-y-auto overscroll-contain pb-[18px] ${p?"px-[22px] pt-[18px]":"pt-3"}`;if(!M)return e.jsx("main",{"data-tab-scroll":"",className:E,children:l.state?e.jsx(ve,{mark:"warn",title:ae.gone(ae.kind[((_=l.state.forges.find(Z=>Z.host===t.split("/")[0]))==null?void 0:_.forge)??"github"],j),sub:ae.goneBody}):e.jsx(Gt,{lead:e.jsx(An,{className:"text-muted"}),children:e.jsx("span",{children:ae.loading})})});const P=Jt(M),I=N==null?void 0:N.data,L=M.state==="merged"||M.state==="closed",$=!!l.state&&!C,O=w&&I?I.jobs.find(Z=>Z.id===w):void 0,U=Z=>{s.readDetail(t,Z.id)},D=G0(l.runs,t),K=X0(D),te=r.fresh&&!b,V=()=>{I&&s.act(t,{kind:"merge",headSha:I.pr.headSha})},F=h?M0:C0,B=F.includes(g)?g:"overview",Y=e.jsxs(e.Fragment,{children:[e.jsx(gs,{body:ae.offlineBody}),$&&!D&&e.jsx(ve,{mark:"warn",title:ae.gone(P.kind,j),sub:ae.goneBody}),D&&e.jsx(Ei,{run:D,pr:M,detail:I,forge:s,pc:j,onReload:()=>s.readDetail(t)}),(N==null?void 0:N.error)&&!I&&e.jsx(K0,{read:N,pr:M,pc:j,onRetry:()=>s.readDetail(t)}),(N==null?void 0:N.cut)&&e.jsx(Gt,{lead:e.jsx(q,{name:"alert",className:"mt-px size-4 text-muted"}),children:e.jsx("span",{children:ae.cut(P.host)})}),e.jsxs("div",{className:`flex flex-col ${h?"gap-4":"gap-2.5"} ${b?"opacity-50":""}`,children:[B==="overview"&&(!(N!=null&&N.error)||I)&&e.jsx(W0,{pr:M,read:N,store:n,live:te&&!K&&!$,side:h,onJob:Z=>{S(Z.id),U(Z)},onLog:U,onRerun:()=>x(!0)}),B!=="overview"&&!I&&!(N!=null&&N.error)&&e.jsx(Vx,{}),B==="discussion"&&I&&e.jsx(vc,{detail:I,forge:s,store:n,live:te&&!$,pc:j}),B==="changes"&&I&&e.jsx(h0,{detail:I}),B==="commits"&&I&&e.jsx(b0,{detail:I})]})]}),G=e.jsxs("span",{"data-foot":"done",className:`flex min-w-0 flex-1 flex-wrap items-center gap-1.5 leading-4 text-muted ${p?"text-[12.5px]":"text-[12px]"}`,children:[e.jsx("span",{className:"inline-flex h-[22px] items-center rounded-full border border-input px-[9px] text-[12px] font-medium",children:ae.state[M.state]}),M.state==="merged"?ae.mergedInto(M.target,yr(M.updatedAt)):yr(M.updatedAt)]}),X=e.jsx("span",{"data-foot":"why",className:`min-w-0 flex-1 leading-4 text-muted ${p?"text-[12.5px]":"text-[12px]"}`,children:I?q0(I,P.host):ae.footApprovals(Kd(M))}),re=e.jsxs("button",{type:"button",disabled:!te||$||K||!I||!Ah(I),onClick:()=>o(!0),className:ge(p?{tone:"primary",size:"sm",className:"flex-none"}:{tone:"primary",className:"h-[42px]"}),children:[e.jsx(q,{name:"merge",className:"size-4"}),ae.merge]}),ie=p?"flex flex-none items-center gap-2.5 border-t border-line bg-sidebar px-[18px] py-2.5":"flex flex-none items-center gap-2.5 border-t border-line bg-sidebar px-3.5 py-[9px]";return e.jsxs(e.Fragment,{children:[e.jsx($0,{pr:M,landscape:h}),e.jsx(A0,{pr:M,d:I,view:B,views:F,onView:y,wide:p}),h?e.jsxs("div",{className:"grid min-h-0 flex-1 grid-cols-[minmax(0,1fr)_320px]",children:[e.jsx("main",{ref:A,"data-tab-scroll":"",className:"tab-main flex min-h-0 min-w-0 flex-col gap-4 overflow-y-auto overscroll-contain px-[22px] py-[18px]",children:Y}),e.jsxs("aside",{"aria-labelledby":`disc-${t}`,"data-pr-discussion":"",className:"flex min-h-0 min-w-0 flex-col border-l border-line",children:[e.jsxs("div",{className:"flex h-12 flex-none items-center gap-2 border-b border-line px-3.5",children:[e.jsx("h2",{id:`disc-${t}`,className:"m-0 text-[15px] font-semibold",children:ae.tabs.discussion}),I&&I.threads.length>0&&e.jsx("span",{className:"text-[12.5px] text-muted",children:ae.discSub(R.open.length,R.resolved.length)})]}),e.jsx("div",{className:`flex min-h-0 flex-1 flex-col gap-2.5 overflow-y-auto overscroll-contain p-3 ${b?"opacity-50":""}`,children:I&&e.jsx(vc,{detail:I,forge:s,store:n,live:te&&!$,pc:j,column:R})}),!L&&e.jsx("div",{className:"flex flex-none border-t border-line px-3 py-2.5",children:e.jsx(wc,{pr:M,forge:s,store:n,live:te&&!$,pc:j})})]})]}):e.jsx("main",{ref:A,"data-tab-scroll":"",className:E,children:Y}),e.jsx("footer",{className:ie,children:h?e.jsxs(e.Fragment,{children:[L?G:X,e.jsx(Bx,{all:R,className:"flex-none"}),!L&&re]}):B==="discussion"&&!L?e.jsx(wc,{pr:M,forge:s,store:n,live:te&&!$,pc:j}):L?G:e.jsxs(e.Fragment,{children:[X,re]})}),c&&e.jsx(U0,{pr:M,confirm:!!((W=r.device)!=null&&W.confirm),live:te,onRerun:()=>{s.act(t,{kind:"rerun"})},onClose:()=>x(!1)}),i&&I&&e.jsx(V0,{d:I,pc:j,confirm:!!((ee=r.device)!=null&&ee.confirm),live:te,onMerge:V,onClose:()=>o(!1)}),O&&e.jsx(D0,{job:O,read:N,pr:M,onRetry:()=>U(O),onClose:()=>S(null)})]})}function Y0(t){const[,s]=f.useReducer(n=>n+1,0);return f.useEffect(()=>{const n=t.subscribe(s);return s(),n},[t]),t.state()}function Z0(t){const[,s]=f.useReducer(n=>n+1,0);return f.useEffect(()=>{if(!t)return;const n=t.subscribe(s);return s(),n},[t]),{build:(t==null?void 0:t.current())??null,waiting:(t==null?void 0:t.waiting())??null}}function J0(t){var n;const[,s]=f.useReducer(a=>a+1,0);return f.useEffect(()=>t==null?void 0:t.subscribe(s),[t]),((n=t==null?void 0:t.getState().state)==null?void 0:n.prs)??[]}function ek(t,s){const[n,a]=f.useState(null);return f.useEffect(()=>{if(!s){a(null);return}let l=!0;return t("/auth/me",{credentials:"same-origin",cache:"no-store"}).then(async r=>r.ok?vm.safeParse(await r.json()):null).then(r=>{l&&(r!=null&&r.success)&&a(r.data.login)}).catch(()=>{}),()=>{l=!1}},[t,s]),n}const tk=(t,s)=>globalThis.fetch(t,s),Sc=t=>t.name==="request"?{name:"request",sessionId:t.sessionId,key:t.key}:t.name==="ask"?{name:"ask",id:t.id}:null;function sk({link:t,store:s,storage:n,fetchImpl:a=tk,updates:l=null,signin:r=null,lost:i=!1,relay:o=globalThis.location.host}){var Te,oe,Ee,nt,Nt,js;const c=Ec(),x=Y0(t),u=me(s),m=sa(),p=ek(a,x!=="signed_out"),{build:h,waiting:g}=Z0(l),[y,w]=f.useState(null),[S,b]=f.useState(r),[j,N]=f.useState(i),[C,M]=f.useState(!1),[R,v]=f.useState(!1),[T,A]=f.useState(!1),E=f.useRef(!1),[P,I]=f.useState(!1),L=((Te=t.pairing())==null?void 0:Te.state())??null,$=((oe=t.recovery())==null?void 0:oe.state())??null,O=($==null?void 0:$.step)==="reaching"||($==null?void 0:$.step)==="faceid"||($==null?void 0:$.step)==="checking",U=Ds(),[D,K]=f.useState(!1),[te,V]=f.useState(!1),F=($==null?void 0:$.step)==="done"&&(!u.fresh||Jo((Ee=u.device)==null?void 0:Ee.push));f.useEffect(()=>{F&&V(!0)},[F]),f.useEffect(()=>{$&&$.step!=="done"&&V(!1)},[$==null?void 0:$.step]);const B=Ry(S),Y=S==="not_allowed"?"denied":x==="signed_out"||B||S==="another"?"login":x==="replaced"?"replaced":x==="key_changed"?"keyChanged":x==="denied"?"unrecognized":x==="storage_unavailable"?"storage":($==null?void 0:$.step)==="done"&&!R?"recover":(L==null?void 0:L.step)==="linked"&&!R?"compare":x==="unpaired"||x==="pairing"?L!==null||P||x==="pairing"&&!O?"compare":$&&$.step!=="cancelled"?"recover":"choose":"route",G=We=>{E.current=!0,I(!0),We()},X=()=>{K(($==null?void 0:$.step)==="failed"&&$.why==="old"),G(()=>t.startPairing())};f.useEffect(()=>{x==="ready"&&(E.current=!1,I(!1),N(!1),M(!1)),(x==="unpaired"||x==="pairing")&&(v(!1),A(!1))},[x]),f.useEffect(()=>{var Lt;const We=(Lt=globalThis.navigator)==null?void 0:Lt.serviceWorker;if(!We)return;const Rt=Se=>Wm(Se.data);return We.addEventListener("message",Rt),()=>We.removeEventListener("message",Rt)},[]);const re=f.useRef("atoi"),ie=f.useRef([]),ce=Zr(m);ce&&(re.current=ce),f.useEffect(()=>{nf(m)},[m]);const z=Et(),k=Py(n),_=We=>nc(We,n),W=f.useRef(!1);k&&z&&(W.current=!0);const ee=f.useRef("atoi");ce&&ce!=="chat"&&(ee.current=ce);const Z=z&&Y==="route"&&m.name==="chat";f.useEffect(()=>{Z&&(nc(!0,n),ms(Pa(Jr(ee.current))))},[Z,n]);const[J,pe]=f.useState(null);f.useEffect(()=>{const We=gN(t,s,n);return pe(We),()=>{We.close(),pe(null)}},[t,s,n]);const[be,Ze]=f.useState(null);f.useEffect(()=>{const We=o0(t,s,n);return We.follow(),Ze(We),()=>{We.close(),Ze(null)}},[t,s,n]);const pt=J0(be),Ie=m.name==="atelier"&&(!z||(u.fresh||u.daemon!==null)&&!((nt=u.daemon)!=null&&nt.atelier));f.useEffect(()=>{Ie&&ms({name:"sessions"})},[Ie]);const De=Sc(m);ei(z&&Y==="route"&&ce==="atoi",We=>{if(We!=="ArrowUp"&&We!=="ArrowDown")return!1;const Rt=s.getState(),Lt=Cp($l(Vt([...Rt.sessions.values()]),Rt.asks??[]),Sc(Pa(globalThis.location.hash)),We==="ArrowDown"?1:-1);return Lt?(ms(Lt),!0):!1});const fe=f.useRef(!1),he=x==="ready"&&u.fresh&&!!((Nt=u.device)!=null&&Nt.id)&&!u.device.name;f.useEffect(()=>{!he||fe.current||s.renameDevice(fx(void 0))!==null&&(fe.current=!0)},[he,s]);const Me=t.pinned(),Fe=(Me==null?void 0:Me.name)??null,lt=(Me==null?void 0:Me.name)??((js=u.daemon)==null?void 0:js.name)??null,et=()=>t.retry(),jt=f.useRef(!1),yt=We=>{if(!jt.current){if(x!=="ready"){x!=="denied"&&M(!0),We();return}jt.current=!0,s.forgetDevice().then(Rt=>{jt.current=!1,Rt||M(!0),We()})}},Q=()=>yt(()=>{t.signOut()}),H=()=>yt(()=>G(()=>{t.relink()})),ye=(()=>{var ln,rn,Tn,_n;switch(Y){case"denied":return e.jsx(Cy,{onOther:()=>b("another")});case"login":return e.jsx(_y,{server:o,error:B});case"replaced":return e.jsx(Iy,{onHere:()=>globalThis.location.reload()});case"keyChanged":return e.jsx(Ay,{pcName:lt,known:Me,received:t.receivedKey(),onRelink:H,onSignOut:Q});case"unrecognized":return e.jsx(dN,{pcName:lt,onRelink:H,onSignOut:Q});case"storage":return e.jsx(By,{onRetry:et,onReload:()=>globalThis.location.reload()});case"choose":return e.jsx(xh,{login:p,platform:U,onPasskey:()=>t.startRecovery(),onCode:X});case"recover":return e.jsx(hh,{state:$,login:p,reach:t.reach(),onRetry:()=>{var ut;(ut=t.recovery())!=null&&ut.again()||t.startRecovery()},onCode:X,onCancel:()=>t.cancelRecovery(),onSignOut:Q,onDone:()=>v(!0),actions:te?e.jsx(ec,{store:s,fetchImpl:a,body:d.recover.done.notify,onDone:()=>v(!0)}):void 0});case"compare":return e.jsx(dh,{step:L,login:p,pcName:Fe,lost:j,stalled:x==="unpaired"&&L===null&&P,reach:t.reach(),onRetry:et,onSame:()=>{var ut;return(ut=t.pairing())==null?void 0:ut.confirmOnPhone()},onCancel:()=>{var ut;return(ut=t.pairing())==null?void 0:ut.cancel()},onRestart:()=>G(()=>t.startPairing()),onDone:()=>v(!0),actions:T?e.jsx(ec,{store:s,fetchImpl:a,onDone:()=>{A(!1),v(!0)}}):e.jsx(bh,{store:s,update:D,onDone:()=>{var ut;Jo((ut=u.device)==null?void 0:ut.push)?A(!0):v(!0)}})})}const We=$l(Vt([...u.sessions.values()]),u.asks??[]);De&&We.some(ut=>JSON.stringify(ut)===JSON.stringify(De))&&(ie.current=We);const Rt=ut=>()=>{const Ps=$p($l(Vt([...s.getState().sessions.values()]),s.getState().asks??[]),ut,ie.current);ms(Ps??{name:"atoi"})},Lt={pc:lt,look:lf(u.fresh,!!u.syncedAt,t.reach()),reach:t.reach(),since:Pe(u.syncedAt),retry:et},Se=!!((ln=u.daemon)!=null&&ln.forge)&&be!==null,Tt=Se?vh(pt):0,Ot={atoi:af(Vt([...u.sessions.values()]),u.asks??[],Rd(u.tasks.values())),prs:Tt?{text:Tt>99?"99+":String(Tt),tone:"red"}:null},de=Se?e.jsx(x0,{forge:be,store:s}):e.jsx(Ly,{}),Ke=Se&&m.name==="pr"?e.jsx(Q0,{id:m.id,forge:be,store:s,pane:k},m.id):null,Je=e.jsx(hg,{store:s,onReconnect:et,forge:be}),kt=e.jsx(E1,{store:s,filter:m.name==="sessions"?m.filter:void 0}),es=!!((rn=u.device)!=null&&rn.chat)||!u.fresh&&!u.device,zs=es?e.jsx(Zo,{store:s,onReconnect:et}):e.jsx(tc,{}),ys=!!((Tn=u.daemon)!=null&&Tn.rigs)&&J!==null,Wt=ys?e.jsx($N,{rigs:J,store:s}):e.jsx(Oy,{}),an=ys?m.name==="rig"?e.jsx(qN,{rig:m.rig,rigs:J,store:s},m.rig):m.name==="kernel"?e.jsx(e0,{rigs:J,store:s}):m.name==="max"?e.jsx(QN,{goalId:m.goalId,rigs:J,store:s},m.goalId??""):null:null,Rn=e.jsx($y,{store:s,fetchImpl:a,login:p,relay:o,pinned:Me,linkState:x,build:h,onSignOut:Q,section:m.name==="connection"?m.section:void 0});if(z){const ut=(()=>{var Ti;switch(m.name){case"atoi":return e.jsx(ts,{list:Je,detail:e.jsx(Tl,{...d.split.request})});case"ask":return e.jsx(ts,{list:Je,detail:e.jsx(ac,{store:s,id:m.id,onDone:Rt({name:"ask",id:m.id})},m.id)});case"request":return e.jsx(ts,{list:Je,detail:e.jsx(Nr,{store:s,sessionId:m.sessionId,requestKey:m.key,onReconnect:et,onSettled:Rt({name:"request",sessionId:m.sessionId,key:m.key}),keys:!0},m.sessionId)});case"sessions":return e.jsx(ts,{tab:"sessions",list:kt,detail:e.jsx(Tl,{...d.split.agent})});case"routines":return e.jsx(ts,{tab:"sessions",list:kt,detail:e.jsx(io,{store:s,focus:m.routine})});case"thread":return e.jsx(ts,{tab:"sessions",list:kt,detail:e.jsx(Mr,{store:s,sessionId:m.sessionId,storage:n,onReconnect:et,forge:be},m.sessionId)});case"launch":return e.jsx(ts,{tab:"sessions",list:kt,detail:e.jsx(pc,{store:s,storage:n})});case"terminal":return e.jsx(ts,{tab:"sessions",fold:!0,list:kt,detail:e.jsx(oc,{store:s,link:t,sessionId:m.sessionId,storage:n,forge:be},m.sessionId)});case"prs":case"pr":return e.jsx(ts,{tab:"prs",list:de,detail:Ke??e.jsx(sc,{icon:"pr",...d.prs.pane})});case"rigs":case"rig":case"kernel":case"max":return e.jsx(ts,{list:Wt,detail:an??e.jsx(sc,{icon:"rigs",...d.rigs.pane})});case"atelier":return(Ti=u.daemon)!=null&&Ti.atelier?e.jsx(f1,{store:s,...m.sessionId?{sessionId:m.sessionId}:{},...m.requestKey?{requestKey:m.requestKey}:{},storage:n,onReconnect:et}):e.jsx(ts,{list:kt,detail:e.jsx(Tl,{...d.split.agent})});case"chat":return null;case"connection":return Rn}})(),Ps=W.current&&e.jsx(Dy,{open:k,onClose:()=>_(!1),children:es?e.jsx(Zo,{store:s,onReconnect:et,onClose:()=>_(!1)}):e.jsx(tc,{onClose:()=>_(!1)})});return e.jsxs(_l,{value:Lt,children:[ut,Ps,e.jsx(cf,{route:m,active:ce??"settings",badges:Ot,atelier:!!((_n=u.daemon)!=null&&_n.atelier),ledge:{open:k,onToggle:()=>_(!k)}})]})}const rt=(ut,Ps=!0)=>e.jsxs(_l,{value:Lt,children:[Ps&&e.jsx(rf,{...typeof Ps=="string"?{title:Ps}:{}}),ut,e.jsx(of,{route:m,active:ce??re.current,badges:Ot})]});switch(m.name){case"atoi":return rt(Je);case"sessions":case"atelier":return rt(kt);case"routines":return rt(e.jsx(io,{store:s,focus:m.routine},m.routine??""));case"prs":return rt(de,Se?d.prs.title:!0);case"pr":return Ke?rt(Ke,!1):rt(de,Se?d.prs.title:!0);case"rigs":return rt(Wt,ys?d.rigs.title:!0);case"rig":case"kernel":case"max":return an?rt(an,!1):rt(Wt,ys?d.rigs.title:!0);case"chat":return rt(zs,!es);case"connection":return rt(Rn,!1);case"thread":return rt(e.jsx(Mr,{store:s,sessionId:m.sessionId,storage:n,onReconnect:et,forge:be},m.sessionId),!1);case"terminal":return rt(e.jsx(oc,{store:s,link:t,sessionId:m.sessionId,storage:n,forge:be},m.sessionId),!1);case"ask":return rt(e.jsx(ac,{store:s,id:m.id},m.id),!1);case"launch":return e.jsx(_l,{value:Lt,children:e.jsx(pc,{store:s,storage:n})});case"request":return rt(e.jsx(Nr,{store:s,sessionId:m.sessionId,requestKey:m.key,onReconnect:et},m.sessionId),!1)}})();return e.jsx(Nm,{copy:km(c).ui,children:e.jsxs("div",{className:"app flex flex-col","data-route":m.name,children:[C&&x!=="ready"&&e.jsx("p",{role:"status",className:"mx-4 my-3 text-body text-muted",children:d.forget.pending}),ye,l&&g&&g.fingerprint!==y&&e.jsx(xN,{next:g,current:h,onLater:()=>w(g.fingerprint),onApply:()=>l.accept()})]})})}const ok=Object.freeze(Object.defineProperty({__proto__:null,App:sk},Symbol.toStringTag,{value:"Module"}));export{ok as A,rk as M,Gy as R,ik as a};