@paradow/ledge-relay 0.63.0 → 0.65.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-CDPb9wXW.js","assets/index-CJFu9LP7.js","assets/index-DlM6pK9t.css","assets/label-CbD8UGH0.js","assets/xterm-DYP7pi_n.css"])))=>i.map(i=>d[i]);
2
+ var sm=Object.defineProperty;var nm=(t,s,n)=>s in t?sm(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var Pt=(t,s,n)=>nm(t,typeof s!="symbol"?s+"":s,n);import{r as f,c as d,s as am,j as e,B as Ke,a as Pa,U as Tc,M as ta,o as _c,b as lm,i as Tt,u as qr,d as nn,e as rm,f as Pe,l as lt,t as Do,g as om,L as sr,W as Ra,O as mt,h as Et,H as qt,F as Rt,P as St,S as Vn,K as Pn,k as im,C as kn,m as Ic,n as Qe,I as cm,A as dm,p as um,q as xm,v as Lc,R as mm,w as Fo,x as jn,y as pm,z as fm,D as hm,E as gm,G as bm,J as jm,N as zo,Q as Po,T as Bo,V as Sl,X as ym,Y as Oc,Z as Nm,_ as vm,$ as km,a0 as Ba,a1 as qo,a2 as wm,a3 as Sm,a4 as Dc,a5 as Hr,a6 as Fc,a7 as $m,a8 as Cm,a9 as Mm,aa as Ho,ab as Em,ac as Rm,ad as Uo,ae as Am,af as Tm,ag as _m,ah as Wo,ai as Im,aj as Lm,ak as Om,al as Dm}from"./index-CJFu9LP7.js";import{e as zc,i as ps,a as Fm,p as zm,g as sa,c as Pm,b as Bm,u as me,d as Ur,r as qm,f as Hm,h as Um,j as Pc,k as Wm,l as Ko,m as Vo,n as Km,M as Cs,o as Vm,q as Gm,s as Xm,t as Wr,v as Ym,w as Qm,x as Zm,y as Bc,z as qc,A as Jm,B as Hc,R as Uc,U as Wc}from"./label-CbD8UGH0.js";const ep=["sessions","routines","prs","rigs","chat","connection","kernel","max"],Kc="new";function qa(t){const s=t.replace(/^#\/?/,"").split("/").filter(Boolean);try{if(s[0]==="request"&&s.length===3)return{name:"request",sessionId:decodeURIComponent(s[1]),key:decodeURIComponent(s[2])};if(s[0]==="ask"&&s.length===2)return{name:"ask",id:decodeURIComponent(s[1])};if((s[0]==="thread"||s[0]==="terminal")&&s.length===2)return{name:s[0],sessionId:decodeURIComponent(s[1])};if(s[0]==="atelier"&&s.length===4&&s[2]==="request")return{name:"atelier",sessionId:decodeURIComponent(s[1]),requestKey:decodeURIComponent(s[3])};if(s[0]==="atelier"&&s.length<=2)return s[1]?{name:"atelier",sessionId:decodeURIComponent(s[1])}:{name:"atelier"};if(s[0]==="connection"&&s.length===2&&s[1]==="link")return{name:"connection",section:"link"};if(s[0]==="rigs"&&s.length===2)return{name:"rig",rig:decodeURIComponent(s[1])};if(s[0]==="prs"&&s.length===2)return{name:"pr",id:decodeURIComponent(s[1])};if(s[0]==="routines"&&s.length===2)return{name:"routines",routine:decodeURIComponent(s[1])};if(s[0]==="max"&&s.length===2)return{name:"max",goalId:decodeURIComponent(s[1])};if(s[0]==="sessions"&&s.length===2&&(s[1]==="working"||s[1]==="waiting"))return{name:"sessions",filter:s[1]}}catch{}if(s[0]==="agents"&&s.length===1)return{name:"sessions"};if(s[0]===Kc&&s.length===1)return{name:"launch"};const n=ep.find(a=>a===s[0]);return n&&s.length===1?{name:n}:{name:"atoi"}}function ne(t){return t.name==="request"?`#/request/${encodeURIComponent(t.sessionId)}/${encodeURIComponent(t.key)}`:t.name==="ask"?`#/ask/${encodeURIComponent(t.id)}`:t.name==="thread"||t.name==="terminal"?`#/${t.name}/${encodeURIComponent(t.sessionId)}`:t.name==="atelier"?t.sessionId?t.requestKey?`#/atelier/${encodeURIComponent(t.sessionId)}/request/${encodeURIComponent(t.requestKey)}`:`#/atelier/${encodeURIComponent(t.sessionId)}`:"#/atelier":t.name==="connection"&&t.section?`#/connection/${t.section}`:t.name==="rig"?`#/rigs/${encodeURIComponent(t.rig)}`:t.name==="pr"?`#/prs/${encodeURIComponent(t.id)}`:t.name==="routines"&&t.routine?`#/routines/${encodeURIComponent(t.routine)}`:t.name==="max"&&t.goalId?`#/max/${encodeURIComponent(t.goalId)}`:t.name==="sessions"&&t.filter?`#/sessions/${t.filter}`:t.name==="launch"?`#/${Kc}`:t.name==="atoi"?"#/":`#/${t.name}`}const tn=t=>{globalThis.location.hash=ne(t)},nr=t=>typeof(t==null?void 0:t.ledge)=="number";let as=0,Bn=[],ar=!1;const lr=t=>{try{globalThis.history.replaceState({...globalThis.history.state,ledge:t},"")}catch{}};function tp(){const t=globalThis.location.hash,s=globalThis.history.state;nr(s)?as=s.ledge:(ar||(as+=1,Bn=Bn.slice(0,as)),lr(as)),ar=!1,Bn[as]=t}if(typeof globalThis.addEventListener=="function"&&globalThis.history&&globalThis.location){const t=globalThis.history.state;as=nr(t)?t.ledge:0,nr(t)||lr(0),Bn[as]=globalThis.location.hash,globalThis.addEventListener("hashchange",tp)}const fs=t=>{ar=!0,globalThis.location.replace(ne(t))};function sp(t){if(as===0)return{route:t,known:!1,inApp:!1};const s=Bn[as-1];return s===void 0?{route:t,known:!1,inApp:!0}:{route:qa(s),known:!0,inApp:!0}}function al(t){as>0?globalThis.history.back():fs(t)}const np=t=>(globalThis.addEventListener("hashchange",t),()=>globalThis.removeEventListener("hashchange",t));function na(){const t=f.useSyncExternalStore(np,()=>globalThis.location.hash,()=>"");return qa(t)}const ap=/^\/#\/[A-Za-z0-9/%._~-]*$/;function lp(t){if(typeof t!="object"||t===null)return;const s=t;s.type!=="ledge.open"||typeof s.url!="string"||!ap.test(s.url)||(globalThis.location.hash=s.url.slice(1))}const Vc=70,aa=6,Go=2,Kr=130,Is=90,Gc=t=>(Math.max(t,2)+1)*Vc,Xc=(t,s=aa,n=Kr)=>Gc(Math.min(t,s))+2*n;function rp(t,s,n=aa,a=Kr){const l=t.slice(0,n),r=Gc(l.length),o=h=>l.length===1?r/2:Vc*(h+1),i=l.map((h,g)=>({session:h,x:o(g),side:l.length===1||g%2===0?"t":"b"})),c={left:[],right:[]},x=new Map,u=[];if(s){for(const[h,g]of l.entries()){const y=g.helpers??[],k=y[0];k&&x.set(g.id,{helper:k,more:y.length-1});const S=o(h)>r/2?"right":"left",b=S==="left"?"right":"left";for(const j of y){const N=c[S].length<Go?S:c[b].length<Go?b:null;N?c[N].push({helper:j,parent:g}):u.push({helper:j,parent:g})}}for(const h of t.slice(n))for(const g of h.helpers??[])u.push({helper:g,parent:h})}const m=["left","right"].flatMap(h=>c[h].map((g,y)=>({...g,end:h,slot:y,count:c[h].length}))),p=t.slice(n);return{length:r,width:Xc(t.length,n,a),seats:i,ends:m,notes:x,extra:{mains:p,helpers:u},extraCount:p.length+u.length}}const qs=84,ga=52;function op(t,s,n){const a=[...s].sort((i,c)=>i-c),l=a.indexOf(t),r=(l<a.length-1?a[l+1]-qs/2:n-6)-(t+qs/2),o=t-qs/2-(l>0?a[l-1]+qs/2:6);return r>=ga+4?t+qs/2+2:o>=ga+4?t-qs/2-ga-2:t+qs/2-ga+8}function ip(t){const s=new Map;for(const a of t)a.branch&&s.set(a.branch,(s.get(a.branch)??0)+1);let n=null;for(const[a,l]of s)(n===null||l>s.get(n))&&(n=a);return n}function Xo(t,s){return t==="idle"?"done":t==="readonly"?"working":t}const cp={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"},Yc=t=>cp[t.state];function dp(t,s,n,a,l,r){const o=s??[],i=new Set(o.map(k=>k.id)),c=k=>{const S=n(k);return S!==null&&i.has(S)?S:null},x=t.filter(k=>!k.rig),u=o.filter(k=>a==="all").map(k=>({project:k,tables:[{key:`common:${k.id}`,mains:x.filter(S=>c(S)===k.id)}]})).filter(k=>k.tables[0].mains.length>0),m=up(t.filter(k=>k.rig),k=>{var S;return((S=o.find(b=>b.id===k))==null?void 0:S.name)??null},n,r),p=[...m.filter(k=>k.rig.kind==="kernel"),...u,...m.filter(k=>k.rig.kind==="rig")],h=a==="all"||a==="none"?x.filter(k=>c(k)===null):[],g=a==="all"||a==="none"?void 0:o.find(k=>k.id===a),y=g&&p.length===0?g:null;return{rooms:p,unassigned:h,empty:y}}const $l="kernel";function up(t,s,n,a){const l=new Map;for(const r of t)l.set(r.rig.name,[...l.get(r.rig.name)??[],r]);return[...l].sort(([r],[o])=>r===$l?-1:o===$l?1:r.localeCompare(o)).map(([r,o])=>{const i=r===$l?"kernel":"rig",c=n(o[0]);return{project:a({id:`rig:${r}`,name:r,kind:i}),tables:[{key:`rig:${r}`,mains:o}],rig:{kind:i,name:r,folder:o[0].cwd??"",project:c?s(c):null}}})}const xp=t=>t==="kernel"?"violet":"slate",Qc=110,mp=150,Zc=70,pp=(t,s=aa,n=Kr)=>t.reduce((a,l,r)=>a+Xc(l.mains.length,s,n)+(r>0?Zc:0),0)+2*Qc;function Vt(t){const s=[];for(const n of t){const a=n.pending;a!=null&&a.key&&s.push({sessionId:n.id,key:a.key,kind:a.kind,filter:a.kind==="question"?"question":"permission",task:n.topic??n.project,botName:n.name,tool:n.tool,repo:n.repo??n.project,...n.branch?{branch:n.branch}:{},...n.worktree?{worktree:!0}:{},since:n.lastActivityAt,text:a.text,...a.tool?{pendingTool:a.tool}:{},...a.body!==void 0?{body:a.body}:{},...a.cut?{cut:!0}:{},...a.options?{options:a.options}:{},...a.optionDetails?{optionDetails:a.optionDetails}:{},source:a.source,...a.questions?{questions:a.questions}:{},...a.requestId?{requestId:a.requestId}:{},risk:a.risk,riskReason:a.riskReason})}return s.sort((n,a)=>Date.parse(n.since)-Date.parse(a.since))}const Cl=(t,s)=>s==="all"?t:t.filter(n=>n.filter===s);function yn(t,s){const n=Math.max(0,Math.floor((s-Date.parse(t))/1e3)),a=d.inbox.age;return n<60?a.s(n):n<3600?a.min(Math.floor(n/60)):n<86400?a.h(Math.floor(n/3600)):a.d(Math.floor(n/86400))}const rr=t=>{var s;return((s=t.split(`
3
+ `).find(n=>n.trim()))==null?void 0:s.trim())??""};function wn(t){switch(t.kind){case"question":return t.text;case"plan":return d.inbox.plan;case"diff":return d.inbox.diff(rr(t.text)).trim();default:return rr(t.text)}}const Jc=["all","waiting","working"],or=t=>t.pending!==void 0||t.state==="waiting_permission"||t.state==="waiting_input";function ir(t,s){return s==="waiting"?or(t):s==="working"?t.state==="working"&&!or(t):!0}function Ha(t){return or(t)?0:t.state==="working"?1:t.state==="exited"?3:2}function Vr(t,s,n){n&&(t=am(t,{projectIds:n.projects.map(o=>o.id),order:n.order,projectOf:o=>o.projectId??null,keyOf:o=>o.id}));const a=new Map,l=new Map;for(const o of t){if(!ir(o,s))continue;const[i,c,x]=o.rig?[l,"rig",o.rig.name]:[a,"project",o.project];let u=i.get(x);u||i.set(x,u={id:`${c}:${x}`,kind:c,name:x,sessions:[],...c==="project"?{project:o.projectId??null}:{}}),u.sessions.push(o)}const r=o=>({...o,sessions:o.sessions.map((i,c)=>[i,c]).sort((i,c)=>Ha(i[0])-Ha(c[0])||i[1]-c[1]).map(([i])=>i)});return[...[...a.values()].map(o=>n?o:r(o)),...[...l.values()].map(r)]}const Gr=["projects","rigs"];function fp(t,s){const n=Vr(t,"all");if(s==="projects")return n;const a=t.filter(l=>!l.rig).map((l,r)=>[l,r]).sort((l,r)=>Ha(l[0])-Ha(r[0])||l[1]-r[1]).map(([l])=>l);return[...n.filter(l=>l.kind==="rig"),...a.length?[{id:"outside",kind:"outside",name:d.sessions.outsideRig,sessions:a}]:[]]}function hp(t){if(t.kind!=="project")return null;const s=t.sessions.map(Sn);return s.includes("perm")?"perm":s.includes("ask")?"ask":null}function gp(t){return t.finishedAt!==void 0||t.state==="exited"?"done":t.state==="waiting_permission"?"perm":t.state==="waiting_input"?"ask":t.state==="working"?"work":"idle"}const ed=t=>({all:t.length,waiting:t.filter(s=>ir(s,"waiting")).length,working:t.filter(s=>ir(s,"working")).length});function Sn(t){const s=Vt([t])[0];return s?s.kind==="question"?"ask":"perm":t.state==="waiting_permission"?"perm":t.state==="waiting_input"?"ask":t.state==="working"?"work":t.state==="exited"?"done":"idle"}const bp=t=>t.helpers.filter(s=>s.state!=="exited"&&s.finishedAt===void 0).length;function jp(t,s,n=Date.now()){const a=d.sessions.line;if(s==="working")return Xr(t);const l=td(t),r=l===void 0?"":` · ${l} %`,o=Vt([t])[0];if(o)return(o.kind==="permission"?a.permission:d.atoi.pill[o.kind])+r;switch(t.state){case"waiting_permission":return a.permission+r;case"waiting_input":return d.atoi.pill.question+r;case"working":return a.working+r;case"exited":return t.exitedAt?a.ended(zc(t.exitedAt,n)):a.endedPlain;case"error":return a.error;default:return a.idle+r}}const Xr=t=>{var s;return((s=t.doing)==null?void 0:s.label)||d.sessions.line.thinking},td=t=>t.context?Math.round(Math.min(1,t.context.used/t.context.window)*100):void 0;function yp(t){if(t.rig)return t.rig.role;if(t.branch)return t.branch.split("/").filter(Boolean).pop()??t.branch}function Nn({d:t,size:s=16,fill:n}){return e.jsxs("svg",{width:s,height:s,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:[t.map((a,l)=>e.jsx("path",{d:a},l)),n==null?void 0:n.map((a,l)=>e.jsx("path",{d:a,fill:"currentColor",stroke:"none"},`f${l}`))]})}const hn={chevronLeft:{d:["m15 18-6-6 6-6"]},chevronRight:{d:["m9 18 6-6-6-6"]},close:{d:["M18 6 6 18","m6 6 12 12"]},check:{d:["M20 6 9 17l-5-5"]},plus:{d:["M12 5v14","M5 12h14"]}},et=(t,s,n)=>`M${t-n} ${s}a${n} ${n} 0 1 0 ${2*n} 0a${n} ${n} 0 1 0 ${-2*n} 0`,cn=(t,s,n,a,l)=>`M${t+l} ${s}h${n-2*l}a${l} ${l} 0 0 1 ${l} ${l}v${a-2*l}a${l} ${l} 0 0 1 ${-l} ${l}h${-(n-2*l)}a${l} ${l} 0 0 1 ${-l} ${-l}v${-(a-2*l)}a${l} ${l} 0 0 1 ${l} ${-l}z`,Np={back:hn.chevronLeft.d,chevron:hn.chevronRight.d,close:hn.close.d,check:hn.check.d,plus:hn.plus.d,gear:["M15 12a3 3 0 1 1-6 0a3 3 0 1 1 6 0","M19.4 15a1.7 1.7 0 0 0 .3 1.8l.1.1a2 2 0 1 1-2.8 2.8l-.1-.1a1.7 1.7 0 0 0-1.8-.3 1.7 1.7 0 0 0-1 1.5V21a2 2 0 1 1-4 0v-.1a1.7 1.7 0 0 0-1.1-1.5 1.7 1.7 0 0 0-1.8.3l-.1.1a2 2 0 1 1-2.8-2.8l.1-.1a1.7 1.7 0 0 0 .3-1.8 1.7 1.7 0 0 0-1.5-1H3a2 2 0 1 1 0-4h.1a1.7 1.7 0 0 0 1.5-1.1 1.7 1.7 0 0 0-.3-1.8l-.1-.1a2 2 0 1 1 2.8-2.8l.1.1a1.7 1.7 0 0 0 1.8.3H9a1.7 1.7 0 0 0 1-1.5V3a2 2 0 1 1 4 0v.1a1.7 1.7 0 0 0 1 1.5 1.7 1.7 0 0 0 1.8-.3l.1-.1a2 2 0 1 1 2.8 2.8l-.1.1a1.7 1.7 0 0 0-.3 1.8V9a1.7 1.7 0 0 0 1.5 1H21a2 2 0 1 1 0 4h-.1a1.7 1.7 0 0 0-1.5 1Z"],terminal:["m4 17 6-6-6-6","M12 19h8"],eye:["M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12z",et(12,12,3)],arrowRight:["M5 12h14","m13 6 6 6-6 6"],arrowUp:["m5 12 7-7 7 7","M12 19V5"],arrowDown:["m5 12 7 7 7-7","M12 5v14"],plane:["m22 2-7 20-4-9-9-4Z","M22 2 11 13"],external:["M15 3h6v6","M10 14 21 3","M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"],stop:["M8 6h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2z"],power:["M12 3v9","M6.3 6.3a8 8 0 1 0 11.4 0"],resume:["M4 12a8 8 0 1 0 2.3-5.6","M4 4v4h4","M10 9l5 3-5 3z"],monitor:["M5 4h14a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2z","M8 20h8","M12 16v4"],warning:["m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3","M12 9v4","M12 17h.01"],edit:["M12 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7","M18.38 2.62a2.12 2.12 0 1 1 3 3L12.36 14.64a2 2 0 0 1-.85.51l-2.87.84.84-2.87a2 2 0 0 1 .5-.85z"],spinner:["M21 12a9 9 0 1 1-6.22-8.56"],inbox:["M4 13l3-8h10l3 8v6H4z","M4 13h5l1 2h4l1-2h5"],sessions:[cn(3,4,18,16,2),"M7 9h10M7 13h6"],pr:[et(6,5,2.2),et(6,19,2.2),et(18,19,2.2),"M6 7.2v9.6M18 16.8V10a3 3 0 0 0-3-3h-4","M13 5l-2 2 2 2"],rigs:[et(6,6,2.5),et(18,6,2.5),et(12,18,2.5),"M8 7.5l3 8M16 7.5l-3 8M8.5 6h7"],ledge:[cn(4,8,16,12,3),"M12 8V4.5",et(9,14,1),et(15,14,1)],search:[et(11,11,7),"M20 20l-4-4"],more:[et(12,5,1.4),et(12,12,1.4),et(12,19,1.4)],send:["M12 19V5M5 12l7-7 7 7"],wifioff:["M12 20h.01M8.5 16.4a5 5 0 0 1 7 0M5 12.9a10 10 0 0 1 5.2-2.7M19 12.9a10 10 0 0 0-1.9-1.3M2 8.8a15 15 0 0 1 4.2-2.7M22 8.8A15 15 0 0 0 10.7 5M2 2l20 20"],cloud:["M2 2l20 20M5.8 5.8A7 7 0 0 0 7 20h10a5 5 0 0 0 2.6-.7M20.8 16.4A5 5 0 0 0 17 10h-1.3A7 7 0 0 0 10 5.1"],refresh:["M3 12a9 9 0 0 1 15.7-6L21 8M21 3v5h-5M21 12a9 9 0 0 1-15.7 6L3 16M3 21v-5h5"],atelier:[cn(3,10,18,5,1),et(7,6,2),et(17,6,2),"M6 15v4M18 15v4"],plan:["M9 4h6v3H9z","M7 5H5v16h14V5h-2","m9 12 1.5 1.5L14 10","M9 17h6"],keyboard:["M3 7h18v10H3z","M7 11h.01","M11 11h.01","M15 11h.01","M8 14h8"],task:["M6.9 3.75h10.2a2.4 2.4 0 0 1 2.4 2.4v11.7a2.4 2.4 0 0 1-2.4 2.4H6.9a2.4 2.4 0 0 1-2.4-2.4V6.15a2.4 2.4 0 0 1 2.4-2.4z","M8.25 9h7.5","M8.25 13.5h5.25"],reply:["M9.75 6 3.75 12l6 6","M4.5 12h9.75a6 6 0 0 1 6 6v.75"],passkey:["M12 3a6 6 0 0 0-6 6v3h12V9a6 6 0 0 0-6-6z","M5 12h14v9H5z"],phone:["M8 2h8a2 2 0 0 1 2 2v16a2 2 0 0 1-2 2H8a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2z","M11 18h2"],tablet:["M6 3h12a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z","M11 18h2"],key:[et(7.5,15.5,5.5),"m21 2-9.6 9.6M15.5 7.5l3 3L22 7l-3-3"],shield:["M12 3 4 6v6c0 5 8 9 8 9s8-4 8-9V6z"],laptop:[cn(4,4,16,11,1.5),"M2 19h20"],face:["M4 8V6a2 2 0 0 1 2-2h2M16 4h2a2 2 0 0 1 2 2v2M20 16v2a2 2 0 0 1-2 2h-2M8 20H6a2 2 0 0 1-2-2v-2M9 9v1M15 9v1M12 9v4h-1M9 15.5a4 4 0 0 0 6 0"],unlink:["M18.8 13.4l1.6-1.6a4.5 4.5 0 0 0-6.4-6.4l-1.6 1.6M5.2 10.6l-1.6 1.6a4.5 4.5 0 0 0 6.4 6.4l1.6-1.6M8 2v3M2 8h3M16 22v-3M22 16h-3"],clock:[et(12,12,9),"M12 7v5l3 2"],alarm:[et(12,13,8),"M12 9v4l2.5 1.5M5 3 2 6M19 3l3 3"],play:["M7 5v14l11-7z"],lock:[cn(3,11,18,11,2),"M7 11V7a5 5 0 0 1 10 0v4"],bell:["M6 8a6 6 0 0 1 12 0c0 7 3 9 3 9H3s3-2 3-9M10.3 21a1.9 1.9 0 0 0 3.4 0"],alert:["M12 3l10 18H2z","M12 10v4M12 17.5v.01"],cpu:[cn(6,6,12,12,2),"M9 2v4M15 2v4M9 18v4M15 18v4M2 9h4M2 15h4M18 9h4M18 15h4"],camera:["M4 8h3l2-3h6l2 3h3v11H4z",et(12,13,3.5)],folder:["M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"],list:["M9 6h11M9 12h11M9 18h11M4 6l1 1 2-2M4 12l1 1 2-2M4 18h2"],down:["M6 9l6 6 6-6"],branch:[et(6,5,2),et(6,19,2),et(18,8,2),"M6 7v10M18 10c0 4-6 3-12 7"],merge:[et(6,5,2.2),et(6,19,2.2),et(18,12,2.2),"M6 7.2v9.6M6 7.2c0 3 4 4.8 9.8 4.8"],file:["M14 3H6a1 1 0 0 0-1 1v16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8z","M14 3v5h5"],commit:[et(12,12,3.5),"M3 12h5.5M15.5 12H21"]};function q({name:t,className:s="size-5",stroke:n=1.6}){return e.jsx("svg",{className:`flex-none ${s}`,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:n,strokeLinecap:"round",strokeLinejoin:"round","aria-hidden":"true",children:Np[t].map((a,l)=>e.jsx("path",{d:a},l))})}const vp={work:"bg-info",perm:"bg-approval",ask:"bg-attention",idle:"bg-ok",done:"bg-muted opacity-50",off:"bg-transparent shadow-[inset_0_0_0_1.5px_var(--color-muted)]",rig:"bg-task",plain:"bg-muted"};function Ie({state:t,pulse:s=!1,label:n}){return e.jsx("span",{"data-dot":t,...n?{role:"img","aria-label":n}:{"aria-hidden":!0},className:`inline-block size-2 flex-none rounded-full ${vp[t]} ${s?"animate-[ledge-pulse_1.6s_ease-in-out_infinite]":""}`})}const kp={claude:"CC",codex:"CX",cursor:"CU",omp:"OM"};function gs({tool:t}){return e.jsx("span",{"data-runtime":t,className:"flex-none rounded-[5px] bg-secondary px-[5px] py-px font-mono text-[11px] leading-4 font-medium",children:kp[t]})}const wp={plain:"border-input text-muted",perm:"border-approval/50 text-approval",urgent:"border-approval/50 text-approval",ask:"border-attention/50 text-attention",work:"border-info/45 text-info",ok:"border-ok/45 text-ok",rig:"border-task/50 text-task",risk:"border-transparent bg-destructive text-primary-fg font-semibold"};function zt({tone:t="plain",children:s}){return e.jsx("span",{"data-pill":t,className:`inline-flex h-5 flex-none items-center rounded-lg border px-[7px] text-[11.5px] whitespace-nowrap ${wp[t]}`,children:s})}function os({title:t,dot:s,count:n,sub:a,tone:l,none:r,label:o,children:i}){return e.jsxs("section",{"aria-label":t??o,className:`flex-none overflow-hidden rounded-[10px] border bg-surface dark:bg-transparent ${l==="rigs"?"border-task/45":"border-line"}`,children:[t&&e.jsxs("div",{className:"flex min-h-11 items-center gap-2 border-b border-line px-3",children:[s&&e.jsx(Ie,{state:s}),e.jsx("b",{className:"text-body font-semibold whitespace-nowrap",children:t}),n!==void 0&&e.jsx("span",{className:"text-[12.5px] text-muted",children:n}),a&&e.jsx("span",{className:"min-w-0 flex-1 truncate text-small text-muted",children:a})]}),r!==void 0?e.jsx("p",{className:"p-3 text-[13px] text-muted",children:r}):e.jsx("div",{className:"flex flex-col",children:i})]})}function Zs({lead:t,title:s,sub:n,subTone:a,meta:l,metaWarn:r=!1,selected:o=!1,stale:i=!1,pressed:c=!1,href:x,press:u,children:m}){const p=`flex min-h-[52px] items-center gap-2 border-b border-line px-3 py-1.5 text-[13.5px] last:border-b-0 ${i?"opacity-60":""} ${o?"bg-secondary shadow-[inset_2px_0_0_var(--color-primary)]":""} ${c?"shadow-[inset_0_0_0_2px_var(--color-ring)]":""}`,h=e.jsxs(e.Fragment,{children:[t,e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate",children:s}),n!==void 0&&e.jsx("span",{className:`truncate text-small leading-4 ${a==="perm"?"text-approval":"text-muted"}`,children:n})]}),l!==void 0&&e.jsx("span",{className:`font-mono text-small whitespace-nowrap ${r?"text-attention":"text-muted"}`,children:l}),m]});return x?e.jsx("a",{href:x,"aria-current":o?"page":void 0,className:p,...u,children:h}):e.jsx("div",{className:p,children:h})}const Sp={plain:"border-line",perm:"border-destructive/45",ask:"border-attention/45",rig:"border-destructive/40"};function $n({tone:t="plain",selected:s=!1,label:n,children:a}){return e.jsx("article",{"aria-label":n,"data-card":t,className:`flex flex-col gap-2.5 rounded-lg border bg-surface p-3 ${Sp[t]} ${s?"shadow-[0_0_0_2px_var(--color-ring)]":""}`,children:a})}function Jt({glyph:t,title:s,body:n,action:a,framed:l=!0,list:r=!1}){return e.jsxs("div",{"data-list-state":r?"":void 0,className:"flex flex-col items-center gap-1.5 px-4 pt-[26px] pb-[22px] text-center",children:[l?e.jsx("div",{"aria-hidden":"true",className:"grid size-12 place-items-center rounded-[10px] border border-line text-muted",children:t}):e.jsx("div",{"aria-hidden":"true",className:"text-muted",children:t}),e.jsx("h2",{className:"mt-1.5 text-[17px] leading-6 font-semibold",children:s}),e.jsx("p",{className:"max-w-[300px] text-[13.5px] text-muted",children:n}),a&&e.jsx("div",{className:"mt-2",children:a})]})}const $p={outline:"border-input bg-surface dark:bg-transparent text-fg active:bg-raised",primary:"border-transparent bg-primary text-primary-fg active:bg-primary-hover",ghost:"border-transparent bg-transparent text-muted text-[13px] active:bg-raised"},Cp={md:"h-11 px-3.5 text-body",sm:"h-9 px-3 text-[13px]",xs:"h-8 px-2.5 text-[12.5px]"},Fe=({variant:t="outline",size:s="md",className:n}={})=>["inline-flex items-center justify-center gap-2 rounded-lg border font-medium whitespace-nowrap transition-colors duration-100 disabled:opacity-45",$p[t],t==="ghost"?"h-9 px-3.5":Cp[s],n??""].filter(Boolean).join(" ");function Mp({label:t,options:s,value:n,onChange:a}){return e.jsx("div",{role:"group","aria-label":t,className:"flex flex-none gap-1.5 overflow-x-auto",children:s.map(l=>e.jsxs("button",{type:"button","aria-pressed":l.value===n,onClick:()=>a(l.value),className:"inline-flex h-8 flex-none items-center gap-1.5 rounded-lg border border-input px-3 text-[13px] font-medium whitespace-nowrap text-muted aria-pressed:border-ring aria-pressed:bg-raised aria-pressed:text-fg",children:[l.label,l.count!==void 0&&e.jsx("span",{className:"font-mono text-meta",children:l.count})]},l.value))})}function la({back:t,tool:s,name:n,dot:a,pulse:l=!1,sub:r,under:o=!1,more:i}){return e.jsxs("header",{className:"bleed flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-0.5",children:[t,s&&e.jsx(gs,{tool:s}),o&&r?e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-2",children:[e.jsx("b",{className:"min-w-0 truncate text-base leading-5 font-semibold",children:n}),a&&e.jsx(Ie,{state:a,pulse:l})]}),e.jsx("span",{className:"truncate text-[12px] leading-4 text-muted",children:r})]}):e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"text-base font-semibold whitespace-nowrap",children:n}),a&&e.jsx(Ie,{state:a,pulse:l}),r&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:r}),e.jsx("span",{className:"flex-1"})]}),i]})}function sd({label:t,sendLabel:s,placeholder:n,offlinePlaceholder:a,value:l,onChange:r,onSend:o,offline:i=!1}){const c=f.useId(),x=!i&&l.trim()!=="";return e.jsxs("div",{className:`flex items-end gap-2 rounded-[10px] border border-input bg-surface py-[5px] pr-[5px] pl-3 focus-within:border-ring focus-within:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)] ${i?"opacity-55":""}`,children:[e.jsx("label",{htmlFor:c,className:"sr-only",children:t}),e.jsx("textarea",{id:c,rows:1,value:i?"":l,disabled:i,placeholder:i?a:n,onChange:u=>r(u.target.value),className:"min-h-[34px] min-w-0 flex-1 resize-none bg-transparent py-[7px] text-base leading-[22px] text-fg outline-none placeholder:text-muted"}),e.jsx("button",{type:"button",disabled:!x,onClick:o,"aria-label":s,title:s,className:"grid size-9 flex-none place-items-center rounded-lg bg-primary text-primary-fg disabled:opacity-40",children:e.jsx(q,{name:"send",className:"size-[18px]"})})]})}function Ep({children:t}){return e.jsx("code",{className:"block rounded-[5px] bg-raised px-[9px] py-[7px] font-mono text-small leading-[18px] break-all whitespace-pre-wrap",children:t})}const nd={permission:"approval",question:"attention",plan:"info",diff:"info"};function Rp(t,s){if(s){const n=s.risk==="high"&&s.kind!=="question";return{tone:n?"danger":nd[s.kind],label:n?d.risk.badge:d.kind[s.kind]}}switch(t.state){case"waiting_permission":return{tone:"approval",label:d.kind.permission};case"waiting_input":return{tone:"attention",label:d.kind.question};case"idle":return{tone:"ok",label:d.agents.state.idle};case"exited":return{tone:"muted",label:d.agents.state.exited};case"error":return{tone:"danger",label:d.agents.state.error};default:return{tone:"info",label:d.agents.state.working}}}const Ap=t=>Rp(t,Vt([t])[0]);function ad({store:t,label:s,ids:n,offline:a,startOpen:l=!1,onCancel:r}){const[o,i]=f.useState(l),[c,x]=f.useState(""),[u,m]=f.useState(!1),[p,h]=f.useState(null),g=async()=>{if(n.length>Pa){h({lines:[d.agents.tooMany(n.length,Pa)],error:!0});return}m(!0);const y=await t.broadcast(n,c.trim());if(m(!1),y.sent){const k=y.sent;h({lines:[...k.length?[d.agents.sentTo(k)]:[d.agents.nobody],...(y.refused??[]).map(S=>d.agents.refusedLine(S.name,S.reason))],error:k.length===0}),k.length&&(i(l),x(""))}else y.status==="expired"?h({lines:[d.agents.uncertain],error:!0}):h({lines:[d.agents.notSent],error:!0})};return e.jsxs("div",{className:"pb-2",children:[!o&&e.jsx("button",{type:"button",disabled:a,onClick:()=>{h(null),i(!0)},className:"text-meta text-info disabled:opacity-60",children:d.agents.writeGroup}),o&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("label",{htmlFor:`group-${n[0]}`,className:"sr-only",children:d.agents.writeGroupLabel(s)}),e.jsx("textarea",{id:`group-${n[0]}`,rows:2,value:c,disabled:u,placeholder:d.agents.writeGroupPlaceholder,onChange:y=>x(y.target.value),className:"min-h-11 w-full resize-none rounded-[14px] border border-input bg-surface px-3.5 py-[11px] text-base leading-5 text-fg placeholder:text-muted disabled:opacity-60"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ke,{variant:"ghost",className:"flex-1",disabled:u,onClick:()=>{i(!1),x(""),r==null||r()},children:d.agents.cancel}),e.jsx(Ke,{variant:"primary",className:"flex-[2]",disabled:u||!c.trim(),onClick:()=>void g(),children:d.agents.send})]})]}),p&&e.jsx("div",{role:"status",className:`mt-1 text-meta ${p.error?"text-attention":"text-muted"}`,children:p.lines.map((y,k)=>e.jsx("p",{className:"[overflow-wrap:anywhere]",children:y},k))})]})}const Yo=new Set(["-o","--push-option","--repo","--receive-pack","--exec"]),Tp=new Set(["-f","--force","--force-with-lease","--force-if-includes","--delete","-d","--mirror","--prune"]);function _p(t){const s=t.trim().split(/\s+/);if(s[0]!=="git")return null;const n=s.indexOf("push");if(n<1)return null;let a=!1;const l=[],r=s.slice(n+1);for(let u=0;u<r.length;u++){const m=r[u];if(m.startsWith("--")){const p=m.split("=")[0];Tp.has(p)?a=!0:Yo.has(p)&&!m.includes("=")&&u++}else m.startsWith("-")&&m.length>1?/[fd]/.test(m.slice(1))?a=!0:Yo.has(m)&&u++:l.push(m)}const[o="",...i]=l;i.some(u=>u.startsWith("+")||u.startsWith(":"))&&(a=!0);const c=i[0],x=c==null?void 0:c.replace(/^\+/,"").split(":").pop();return{remote:o,...x?{branch:x}:{},force:a}}function Ip(t){return t.risk!=="low"||t.riskReason!=="edit_inside_folder"?null:{title:d.detail.editsInProject,body:d.detail.editsInProjectBody}}function ld(t){if(t.risk==="low")return null;const s=d.consequence,n=t.riskReason;if(n==="pushes"){const a=_p(t.text),l=a!=null&&a.remote?a.branch?`${a.remote}/${a.branch}`:a.remote:s.configuredRemote;return a!=null&&a.force?{title:s.forceTitle,body:s.forceBody(a.remote?l:void 0),destination:l}:{title:s.pushTitle,body:s.pushBody,destination:l}}switch(n){case"destroys":case"deploys":case"publishes":case"pipes_to_shell":case"network":case"writes_outside_folder":case"sensitive_path":case"script":case"plan":{const[a,l]=s[n];return{title:a,body:l}}default:{const[a,l]=s.unknown;return{title:a,body:l}}}}const Yr=ta,Lp=/^[1-9]$/;function rd(t){const s=t.trim();return s===""?{text:s,problem:"empty"}:Tc.test(s)?{text:s,problem:"untypable"}:s.length>Yr?{text:s,problem:"long"}:Lp.test(s)?{text:s,problem:"digit"}:{text:s,problem:null}}function Qr(t,s,n){var a;if(t.kind==="plan"||t.kind==="diff")return{kind:"examine"};if((s==null?void 0:s.decide)===!1||t.kind==="question"&&(s==null?void 0:s.questions)===!0&&t.requestId!==void 0&&((a=t.questions)!=null&&a.length))return{kind:"examine"};if(t.kind==="question"){if(n)return{kind:"readOnly"};const l=t.options??[],r=(s==null?void 0:s.freeTextAnswer)===!0;return r||l.length>0?{kind:"question",options:l,other:r}:{kind:"answerOnPc",options:l}}return t.risk==="high"?{kind:"high"}:{kind:"permission",always:_c(t.tool,t.kind,"always")}}const cr=t=>lm(t.tool,{kind:t.kind,...t.pendingTool?{tool:t.pendingTool}:{}}),Ua=t=>t==="project"?d.atoi.always:t==="plan"?d.atoi.approveAuto:d.atoi.alwaysSession,Qo={critical:0,urgent:1,routine:2},od=t=>[...t].sort((s,n)=>Qo[s.priority]-Qo[n.priority]||Date.parse(s.createdAt)-Date.parse(n.createdAt)),id=t=>t.kind==="update"?"update":t.kind==="parked"?"parked":t.questions.length>0?"decision":"question",Op=t=>(t==null?void 0:t.replace(/\.agent$|\.lead$|\.worker$/,""))??null,cd=t=>({name:t.from.seat.split("@")[0]||t.from.seat,role:Op(t.from.role)});function Zo(t,s){var l;const n=t.questions.find(r=>r.id===s),a=n==null?void 0:n.answer;return a?a.kind==="words"?a.text:((l=n.options.find(r=>r.id===a.id))==null?void 0:l.label)??a.id:null}function Dp(t,s){var n,a;switch(s.kind){case"choice":return((a=(n=t.questions.find(l=>l.id===s.questionId))==null?void 0:n.options.find(l=>l.id===s.optionId))==null?void 0:a.label)??s.optionId;case"words":case"resolve":return s.text;case"seen":return""}}function dd(t,s){const n=Object.values(s).filter(r=>r.message.type==="openrig.answer"&&r.message.qitemId===t).sort((r,o)=>r.at.localeCompare(o.at)),a=n[n.length-1];if(!a)return{kind:"none"};const l=a.message.answer;if(a.rig){const r=a.rig;return r.rejected?{kind:"refused",answer:l,reason:r.rejected}:r.ok?r.outcome==="recorded"?{kind:"recorded",answer:l}:r.outcome==="already"?{kind:"already"}:{kind:"sent",answer:l}:r.error==="closed"||r.error==="not_found"?{kind:"already"}:r.error==="uncertain"?{kind:"uncertain",answer:l}:{kind:"failed",answer:l,error:r.error??"unreachable",...r.message?{message:r.message}:{}}}return ps(a.phase)?a.phase==="uncertain"?{kind:"uncertain",answer:l}:{kind:"sending",answer:l}:a.phase==="applied"?{kind:"sent",answer:l}:{kind:"failed",answer:l,error:a.reason??"unreachable"}}const Aa=5;function Fp(t,s){return t.filter(n=>n.state==="working"&&!s.has(n.id)).sort((n,a)=>Date.parse(a.lastActivityAt)-Date.parse(n.lastActivityAt))}const zp=6,ud=5e3;function Ml(t,s){return[...t.map(n=>({name:"request",sessionId:n.sessionId,key:n.key})),...od(s).filter(n=>n.kind!=="update").map(n=>({name:"ask",id:n.id}))]}const Ta=(t,s)=>t.name==="request"?s.name==="request"&&t.sessionId===s.sessionId:s.name==="ask"&&t.id===s.id;function Pp(t,s,n=t){const a=t.filter(o=>!Ta(o,s)),l=n.findIndex(o=>Ta(o,s));return(l<0?[]:n.slice(l+1)).find(o=>a.some(i=>Ta(i,o)))??a[0]??null}function Bp(t,s,n){if(!t.length)return null;const a=s?t.findIndex(l=>Ta(l,s)):-1;return a<0?t[0]:t[Math.min(t.length-1,Math.max(0,a+n))]}function Gn(t,s,n){var i;const a=(i=s.find(c=>c.id===t.sessionId))==null?void 0:i.pending,l=(a==null?void 0:a.key)===t.key,r=Object.values(n).filter(c=>"id"in c.message&&c.message.id===t.sessionId&&Fm(c.message)===t.key).sort((c,x)=>c.at.localeCompare(x.at)),o=r.find(c=>c.phase==="applied")??r[r.length-1];if(o){const c=o.message;switch(o.phase){case"sending":return{kind:"sending"};case"uncertain":return{kind:"uncertain"};case"applied":return{kind:"applied",...c.type==="session.decide"?{decision:c.decision}:{},...c.type==="session.reply"?{answer:c.text}:{},...c.type==="session.answer"?{answer:c.answers.flatMap(x=>x.selected).join(", ")}:{}};case"rejected":return o.reason==="stale"&&!l?a!=null&&a.key?{kind:"changed"}:{kind:"handledElsewhere"}:{kind:"rejected",reason:o.reason??"invalid"};case"failed":return{kind:"failed",reason:o.reason??"invalid"}}}return l?{kind:"idle"}:{kind:"handledElsewhere"}}function Cn(t=4e3){const[s,n]=f.useState(!1);return f.useEffect(()=>{if(!s)return;const a=setTimeout(()=>n(!1),t);return()=>clearTimeout(a)},[s,t]),[s,n]}function Xt(){const[t,s]=f.useState(Date.now);return f.useEffect(()=>{const n=setInterval(()=>s(Date.now()),15e3);return()=>clearInterval(n)},[]),t}const qp={approval:"text-approval bg-approval/10",attention:"text-attention bg-attention/10",info:"text-info bg-info/10",ok:"text-ok bg-ok/10",muted:"text-muted bg-fg/[0.05]",danger:"text-danger-fg bg-danger-fg/10"};function ra({tone:t,label:s}){return e.jsx("span",{className:`inline-flex h-[22px] flex-none items-center rounded-md px-2 text-meta leading-none font-medium whitespace-nowrap ${qp[t]}`,children:s})}function Hp({kind:t,risk:s="low"}){const n=s==="high"&&t!=="question";return e.jsx(ra,{tone:n?"danger":nd[t],label:n?d.risk.badge:d.kind[t]})}function Up({text:t}){return e.jsx("pre",{className:"my-3.5 rounded-control border border-line bg-well p-3.5 font-mono text-small leading-[1.8] break-words whitespace-pre-wrap [overflow-wrap:anywhere]",children:t})}const Mn=t=>{var s;return{fresh:t.fresh,pc:((s=t.daemon)==null?void 0:s.name)??null}};function xd({link:t}){return e.jsxs("div",{className:"flex min-w-0 items-center gap-1.5 text-meta whitespace-nowrap text-muted",children:[e.jsx("i",{className:`inline-block size-1.5 flex-none rounded-full ${t.fresh?"bg-ok":"bg-muted"}`}),e.jsxs("span",{className:"truncate",children:[t.pc?`${t.pc} · `:"",t.fresh?d.link.online:d.link.offline]})]})}function is({fallback:t,label:s}){const n=sp(t),a=n.inApp?n.known?d.nav.backTo[n.route.name]??d.nav.back:d.nav.back:s;return e.jsx("a",{href:ne(n.route),"data-back":t.name,"aria-label":a,title:a,onClick:l=>{l.preventDefault(),al(t)},className:Tt({className:"-ml-2"}),children:e.jsx(q,{name:"back"})})}function oa({title:t,fallback:s,label:n,link:a}){return e.jsx("header",{className:"flex-none border-b border-line pt-2 pb-3",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx(is,{fallback:s,label:n}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t}),e.jsx(xd,{link:a})]})})}const El={},md={grow:{ms:320,ease:"cubic-bezier(.22,1,.36,1)",delayMs:0},shrink:{ms:260,ease:"cubic-bezier(.65,0,.35,1)",delayMs:60},cardExit:{ms:300,ease:"cubic-bezier(.65,0,.35,1)",delayMs:180},pop:{ms:260,ease:"cubic-bezier(.34,1.3,.64,1)",delayMs:0},fadeIn:{ms:180,ease:"ease-out",delayMs:140},fadeOut:{ms:100,ease:"ease-in",delayMs:0},hover:{ms:150,ease:"ease-out",delayMs:0}},Wp=()=>{const t=El==null?void 0:El.VITE_LEDGE_MOTION;return t===void 0?1:Number(t)},Ct=t=>`${Math.round(t*Wp())}ms`;function Kp(t){return t.map(([s,n,a])=>{const l=md[n];return`${s} ${Ct(l.ms)} ${l.ease} ${Ct(a??l.delayMs)}`}).join(", ")}const Vp="(prefers-reduced-motion: reduce)",pd=()=>typeof window<"u"&&typeof window.matchMedia=="function"?window.matchMedia(Vp):null;function Gp(t){const s=pd();return s==null||s.addEventListener("change",t),()=>s==null?void 0:s.removeEventListener("change",t)}const Xp=()=>{var t;return((t=pd())==null?void 0:t.matches)??!1};function Yp(){return!1}function fd(){return f.useSyncExternalStore(Gp,Xp,()=>!1)}const Qp=()=>({reduced:fd()||Yp(),app:!1,setReduced(){}});let Zp=Qp;function Jp(){return Zp()}function ef(t){return t==="dark"?"signal":"pebble"}function bn(t){let s=7;for(let n=0;n<t.length;n++)s=s*31+t.charCodeAt(n)>>>0;return s}function ll(t,s){return bn(`${t}:${s}`)%3+1}const Mt={blinkMs:180,gazePx:1.4,gazeYPx:.3,askDelayMs:180,transitionMs:500,hopMs:480,touchMs:360,idleMs:1700,askMs:850,nodMs:650},Rl=(t,s)=>s===0?1400+t%3500:3400+(t+s*997)%3300,Al=(t,s)=>s===0?800+t%1800:2400+(t+s*557)%2100,dr=new Set(["done","error","readonly"]),Tl=(t,s)=>s===0?3500+t%4e3:5500+(t+s*557)%3500,ws=t=>!document.hidden&&!t.closest("[inert]");function Wa(t,s){document.addEventListener("visibilitychange",s);const n=new MutationObserver(s);return n.observe(document.documentElement,{attributes:!0,subtree:!0,attributeFilter:["inert"]}),()=>{document.removeEventListener("visibilitychange",s),n.disconnect()}}function tf(t){f.useEffect(()=>{const s=t.current;if(!s)return;const n=()=>s.setAttribute("data-suspended",String(!ws(s)));return n(),Wa(s,n)},[t])}function dn(t,s,n){t.style.setProperty("--bot-gx",`${s}px`),t.style.setProperty("--bot-gy",`${n}px`)}function sf(t,s){const{seed:n,state:a,enabled:l,askKey:r,nodKey:o,gazeReach:i=0}=s,c=bn(n),x=l&&!dr.has(a),u=f.useRef(null),m=f.useRef(a),p=f.useRef(o),h=f.useRef(void 0);f.useEffect(()=>{const g=t.current;if(!g||!x)return;let y,k,S;const b=()=>ws(g),j=()=>{y!==void 0&&clearTimeout(y),k!==void 0&&clearTimeout(k),S!==void 0&&clearTimeout(S),y=k=S=void 0,g.removeAttribute("data-idle"),dn(g,0,0),g.removeAttribute("data-blink")},N=()=>{if(j(),!b())return;const M=Date.now();(!u.current||u.current.h!==c)&&(u.current={h:c,blinkAt:M+Rl(c,0),lookAt:M+Al(c,0),idleAt:M+Tl(c,0),blinks:0,looks:0,idles:0});const v=u.current;v.blinkAt<M&&(v.blinkAt=M+Rl(c,++v.blinks)),v.lookAt<M&&(v.lookAt=M+Al(c,++v.looks)),v.idleAt<M&&(v.idleAt=M+Tl(c,++v.idles)),y=setTimeout($,Math.min(v.blinkAt,v.lookAt,v.idleAt)-M)},$=()=>{if(y=void 0,!b()){j();return}const M=u.current,v=Date.now();if(v>=M.blinkAt&&(g.setAttribute("data-blink","true"),k!==void 0&&clearTimeout(k),k=setTimeout(()=>{k=void 0,g.removeAttribute("data-blink")},Mt.blinkMs),M.blinkAt=v+Rl(c,++M.blinks)),v>=M.lookAt){M.looks++;const A=a==="working";!g.hasAttribute("data-hover")&&!g.hasAttribute("data-transition")&&dn(g,A?M.looks%2?Mt.gazePx:-1.4:0,A?Mt.gazeYPx:0),M.lookAt=v+Al(c,M.looks)}if(v>=M.idleAt){M.idles++;const A=a;!g.hasAttribute("data-hover")&&!g.hasAttribute("data-transition")&&(A==="idle"||A==="question")&&(g.setAttribute("data-idle",A==="question"?"tilt":M.idles%4===0?"stretch":"look"),S=setTimeout(()=>{S=void 0,g.removeAttribute("data-idle")},Mt.idleMs)),M.idleAt=v+Tl(c,M.idles)}y=setTimeout($,Math.min(M.blinkAt,M.lookAt,M.idleAt)-v)};N();const C=Wa(g,()=>{b()&&y===void 0?N():b()||j()});return()=>{j(),C()}},[t,x,c,a]),f.useEffect(()=>{const g=t.current,y=m.current,k=h.current,S=p.current!==o&&o!==void 0;if(p.current=o,m.current=a,h.current=r,!g)return;dn(g,0,0),g.removeAttribute("data-idle");const b=a==="approval"&&(y!=="approval"||r!==void 0&&r!==k),j=new Set,N=(z,K)=>{const L=setTimeout(()=>{j.delete(L),ws(g)?z():$()},K);return j.add(L),L},$=()=>{j.forEach(clearTimeout),j.clear(),["data-transition","data-gesture","data-touch","data-hover","data-idle"].forEach(z=>g.removeAttribute(z)),dn(g,0,0)};let C=!1,M=!1;l&&ws(g)&&(y!==a&&["working","question","idle","done","error"].includes(a)&&(g.setAttribute("data-transition",a),N(()=>g.removeAttribute("data-transition"),a==="working"?Mt.hopMs:a==="question"?650:Mt.transitionMs)),b&&!S&&N(()=>{C=!0,g.setAttribute("data-gesture","ask"),N(()=>{g.getAttribute("data-gesture")==="ask"&&g.removeAttribute("data-gesture")},Mt.askMs)},Mt.askDelayMs));const v=()=>l&&!dr.has(a)&&ws(g),A=z=>{if(!v()||z.pointerType==="touch")return;const K=g.getBoundingClientRect();if(!K.width||!K.height)return;const L=z.clientX-K.left-K.width/2,W=z.clientY-K.top-K.height/2;if(i>0&&(Math.abs(L)>K.width/2+i||Math.abs(W)>K.height/2+i)){g.hasAttribute("data-hover")&&T();return}g.setAttribute("data-hover","true"),g.removeAttribute("data-idle");const ae=U=>Math.max(-2,Math.min(2,U));dn(g,ae(L/(K.width/2+i)*2),ae(W/(K.height/2+i)*2))},T=()=>{g.removeAttribute("data-hover"),dn(g,0,0)},R=i>0?window:g,P=i>0?document.documentElement:g;let _;const D=()=>{v()&&(_!==void 0&&(clearTimeout(_),j.delete(_)),g.removeAttribute("data-touch"),g.getBoundingClientRect(),g.setAttribute("data-touch","true"),_=N(()=>g.removeAttribute("data-touch"),Mt.touchMs))};R.addEventListener("pointermove",A),P.addEventListener("pointerleave",T),g.addEventListener("click",D);const E=Wa(g,()=>{ws(g)||(M=!0,$())});return()=>{$(),E(),R.removeEventListener("pointermove",A),P.removeEventListener("pointerleave",T),g.removeEventListener("click",D);const z=["data-paused","data-frozen","data-reduced","data-readonly"].some(K=>g.getAttribute(K)==="true");!C&&b&&!S&&g.getAttribute("data-state")===a&&l&&!M&&ws(g)&&!z&&(h.current=k)}},[t,a,l,r,o,c,i])}function nf(t,s,n,a,l){const r=f.useRef(s);f.useEffect(()=>{const o=t.current,i=r.current!==s;if(r.current=s,!o||!i||s===void 0||!n||!ws(o)||dr.has(a))return;o.setAttribute("data-gesture","nod");const c=setTimeout(()=>{o.getAttribute("data-gesture")==="nod"&&o.removeAttribute("data-gesture")},Mt.nodMs),x=()=>{clearTimeout(c),o.getAttribute("data-gesture")==="nod"&&o.removeAttribute("data-gesture")},u=Wa(o,()=>{ws(o)||x()});return()=>{u(),x()}},[t,s,n,a,l])}const af={claude:"Claude Code",codex:"Codex",cursor:"Cursor Agent",omp:"omp"},lf={starting:{eyes:"open",eye:"starting"},working:{eyes:"open",eye:"working"},approval:{eyes:"open",eye:"approval",tilt:[-4,3,-2],lift:-1},question:{eyes:"wide",eye:"question",tilt:[4,-3,6]},idle:{eyes:"happy",eye:"idle"},error:{eyes:"error",eye:"error",tilt:[-7,-6,-5],lift:2},done:{eyes:"sleep",eye:"done"},readonly:{eyes:"open",eye:"done"}},rf="0 0 96 96",hd={claude:"10 18 76 64",codex:"5 7 87 82",cursor:"11 8 74 82",omp:"10 18 76 68"},of=Object.fromEntries(Object.entries(hd).map(([t,s])=>[t,Number(s.split(" ")[2])])),cf={claude:"M24 24H72Q75 24 75 27V43H82Q84 43 84 45V52Q84 54 82 54H75V62Q75 64 73 64H70V75Q70 77 68 77H66Q64 77 64 75V64H59V75Q59 77 57 77H55Q53 77 53 75V64H43V75Q43 77 41 77H39Q37 77 37 75V64H32V75Q32 77 30 77H28Q26 77 26 75V64H23Q21 64 21 62V54H14Q12 54 12 52V45Q12 43 14 43H21V27Q21 24 24 24Z",codex:"M30 25C31 13 48 10 57 20C69 14 84 23 81 37C92 46 87 62 76 65C76 80 58 86 48 77C35 85 20 78 21 66C7 61 7 45 18 38C13 28 21 20 30 25Z",cursor:"M43 13Q48 10 53 13L77 27Q82 30 82 36V64Q82 69 77 72L53 85Q48 88 43 85L19 72Q14 69 14 64V36Q14 30 19 27Z",omp:"M17 22H79Q83 22 83 26V48Q83 52 79 52H71V79Q71 83 67 83H58Q54 83 54 79V52H41V67Q41 71 37 71H28Q24 71 24 67V52H17Q13 52 13 48V26Q13 22 17 22Z"},df={claude:"translate(0 -8)",codex:void 0,cursor:"translate(31.5 58) skewY(27) scale(.86) translate(-48.5 -49)",omp:"translate(0 -12)"},uf=240;function rl({tool:t,state:s,pose:n,size:a,shownSize:l,theme:r,seed:o,readOnly:i=!1,frozen:c=!1,paused:x=!1,reducedMotion:u,askKey:m,nodKey:p,className:h}){var K;const g=f.useRef(null),y=`bot-shell-${f.useId().replace(/[^A-Za-z0-9_-]/g,"")}`,k=Jp(),b=fd()||(u??k.reduced),j=a<=20,N=lf[s],$=!i&&s!=="done"&&s!=="readonly",C=qr(),M=bn(o),v=s==="working"&&!b&&!i&&!c&&!x,A=l??a,R=Math.min(7,Math.max(2,A*.12))/A*(j?of[t]:96),P=3600+M%9*100,_=!j&&A>20,D=!b&&!i&&s!=="readonly"&&!c&&!x;tf(g),sf(g,{seed:o,state:s,askKey:m,nodKey:p,enabled:D&&_,gazeReach:uf}),nf(g,p,D&&_,s,m);const E={"--bot-size":`${a}px`,"--bot-eye":`var(--bot-eye-${N.eye})`,"--bot-tilt":`${((K=N.tilt)==null?void 0:K[n-1])??0}deg`,"--bot-lift":`${N.lift??0}px`,"--bot-breath":Ct(4800+M%17*100),"--bot-phase":`-${Ct(M%43*100)}`,"--bot-hop":`${R.toFixed(2)}px`,"--bot-hop-cycle":Ct(P),"--bot-ease":md.grow.ease,"--bot-material-ms":Ct(240),"--bot-eye-ms":Ct(260),"--bot-pose-ms":Ct(300),"--bot-gaze-ms":Ct(450),"--bot-blink-ms":Ct(Mt.blinkMs),"--bot-ask-ms":Ct(Mt.askMs),"--bot-nod-ms":Ct(Mt.nodMs),"--bot-question-ms":Ct(650),"--bot-arrival-ms":Ct(Mt.transitionMs),"--bot-entry-hop-ms":Ct(Mt.hopMs),"--bot-touch-ms":Ct(Mt.touchMs),"--bot-idle-ms":Ct(Mt.idleMs)},z=`${af[t]} · ${C.botLabel[s]}${i&&s!=="readonly"?` · ${C.botReadOnly}`:""}${c?` · ${C.botNotLive}`:""}`;return e.jsxs("svg",{ref:g,className:h?`bot ${h}`:"bot",role:"img","aria-label":z,width:a,height:a,viewBox:j?hd[t]:rf,"data-tool":t,"data-state":s,"data-eyes":N.eyes,"data-pose":n,"data-material":ef(r),"data-simplified":String(j),"data-detailed":String(_),"data-readonly":String(i||s==="readonly"),"data-halo":String($),"data-frozen":String(c),"data-paused":String(x),"data-reduced":String(b),"data-hop":String(v),style:E,children:[e.jsx("defs",{children:e.jsxs("linearGradient",{id:y,x1:".1",y1:"0",x2:".8",y2:"1",gradientUnits:"objectBoundingBox",children:[e.jsx("stop",{className:"shell-top"}),e.jsx("stop",{className:"shell-bottom",offset:"1"})]})}),e.jsx("ellipse",{className:"ground",cx:"48",cy:"90",rx:"25",ry:"3"}),e.jsx("g",{className:"hop",children:e.jsx("g",{className:"body",children:e.jsx("g",{className:"arrival",children:e.jsx("g",{className:"signature",children:e.jsx("g",{className:"touch",children:e.jsxs("g",{className:"pose",children:[e.jsx("path",{className:"shell",d:cf[t],fill:`url(#${y})`}),t==="cursor"&&e.jsxs("g",{className:"facets",children:[e.jsx("path",{className:"cube-top",d:"M43 13Q48 10 53 13L77 27Q80 29 81 32L48 49L15 32Q16 29 19 27Z"}),e.jsx("path",{className:"cube-side",d:"M48 49L81 32Q82 34 82 36V64Q82 69 77 72L53 85Q50 87 48 87Z"}),e.jsx("path",{className:"cube-edge",d:"M17 32L48 49L79 32M48 49V83"})]}),t==="claude"&&e.jsx("path",{className:"shine",d:"M27 28H69"}),e.jsx("g",{transform:df[t],children:e.jsx("g",{className:"gaze",children:e.jsxs("g",{className:"eye-blink",children:[e.jsxs("g",{className:"eye-open",children:[e.jsx("rect",{x:"36",y:"43",width:"6",height:"12",rx:t==="claude"?.6:3}),e.jsx("rect",{x:"55",y:"43",width:"6",height:"12",rx:t==="claude"?.6:3})]}),_&&e.jsxs("g",{className:"eye-glint",children:[e.jsx("rect",{x:"37.5",y:"44.5",width:"2.4",height:"2.4",rx:t==="claude"?0:1.2}),e.jsx("rect",{x:"56.5",y:"44.5",width:"2.4",height:"2.4",rx:t==="claude"?0:1.2})]}),e.jsx("path",{className:"eye-happy",d:"M35 51Q39 43 43 51M54 51Q58 43 62 51"}),e.jsx("path",{className:"eye-error",d:"m35 45 8 3m11 0 8-3M38 54h2m16 0h2"}),e.jsx("path",{className:"eye-sleep",d:"M35 50q4 3 8 0m11 0q4 3 8 0"})]})})}),t==="claude"?e.jsx("rect",{className:"arm",x:"75",y:"56",width:"8",height:"12",rx:"2"}):e.jsx("ellipse",{className:"arm",cx:"79",cy:"63",rx:"5",ry:"8"})]})})})})})})]})}const xf={blink:180,curious:900,hello:1100,boop:700,happy:900,look:1800,stretch:1600,tap:1150,pulse:1400,nod:700,yawn:1700,sleep:3200},_l=(t,s)=>Math.max(-s,Math.min(s,t)),Jo="M25 60V41C25 28 35 23 48 23C61 23 71 28 71 41V60Z";function Zr({size:t,theme:s,paused:n=!1,frozen:a=!1,reducedMotion:l=!1,dnd:r=!1,pointer:o=null,center:i,gestureKey:c,gestureKind:x="hello",boopKey:u}){const m=qr(),p=`resident-${f.useId().replace(/[^A-Za-z0-9_-]/g,"")}`,[h,g]=f.useState(null),[y,k]=f.useState(!1),S=f.useRef(void 0),b=n||l||r||a,j=!b&&!!o&&!!i&&Math.hypot(o.x-i.x,o.y-i.y)<140,N=j?_l((o.x-i.x)/140*5,4):0,$=j?_l((o.y-i.y)/140*3,2):0,C=j?_l((o.x-i.x)/140*7,5):0,M=T=>{b||document.hidden||(clearTimeout(S.current),g(null),g(T),S.current=setTimeout(()=>g(null),xf[T]))};f.useEffect(()=>()=>clearTimeout(S.current),[]),f.useEffect(()=>{c&&M(x)},[c]),f.useEffect(()=>{u&&M("boop")},[u]);const v=f.useRef(!1);f.useEffect(()=>{j&&!v.current&&!y&&M("curious"),v.current=j},[j]),f.useEffect(()=>{if(b){g(null),clearTimeout(S.current);return}let T,R=0;const P=()=>{!document.hidden&&!y&&(R++,M(R%17===0?"sleep":R%13===0?"yawn":R%11===0?"tap":R%7===0?"stretch":R%5===0?"look":"blink")),T=setTimeout(P,4300+R%3*900)};T=setTimeout(P,3200);const _=()=>{document.hidden&&(g(null),clearTimeout(S.current))};return document.addEventListener("visibilitychange",_),()=>{clearTimeout(T),document.removeEventListener("visibilitychange",_)}},[b,y]);const A={"--resident-gx":N?`${N.toFixed(2)}px`:"0px","--resident-gy":$?`${$.toFixed(2)}px`:"0px","--resident-tilt":C?`${C.toFixed(2)}deg`:"0deg"};return e.jsxs("svg",{className:"resident",width:t,height:t,viewBox:t<=24?"5 8 86 74":"0 0 96 96",role:"img","aria-label":"Ledge","data-theme":s,"data-large":String(t>24),"data-near":String(j),"data-dnd":String(r),"data-frozen":String(a),"data-quiet":String(b),"data-gesture":h??void 0,style:A,onMouseEnter:()=>{k(!0),M("happy")},onMouseLeave:()=>k(!1),children:[e.jsxs("defs",{children:[e.jsxs("linearGradient",{id:`${p}-shell`,x1:".15",y1:"0",x2:".75",y2:"1",children:[e.jsx("stop",{className:"resident-top"}),e.jsx("stop",{className:"resident-bottom",offset:"1"})]}),e.jsxs("radialGradient",{id:`${p}-sheen`,cx:".3",cy:".2",r:".75",children:[e.jsx("stop",{className:"resident-sheen"}),e.jsx("stop",{className:"resident-sheen",offset:"1",stopOpacity:"0"})]})]}),e.jsx("g",{className:"resident-body",children:e.jsxs("g",{className:"resident-pose",children:[e.jsx("path",{className:"resident-antenna",d:"M48 23v-7"}),e.jsx("circle",{className:"resident-light",cx:"48",cy:"14",r:"2.6"}),e.jsx("path",{className:"resident-shell",d:Jo,fill:`url(#${p}-shell)`}),t>24&&e.jsx("path",{d:Jo,fill:`url(#${p}-sheen)`}),e.jsx("g",{className:"resident-gaze",children:e.jsxs("g",{className:"resident-blink",children:[e.jsxs("g",{className:"resident-eyes",children:[e.jsx("rect",{x:"37",y:"35",width:"6",height:"12",rx:"3"}),e.jsx("rect",{x:"53",y:"35",width:"6",height:"12",rx:"3"}),t>24&&e.jsxs("g",{className:"resident-glint",children:[e.jsx("circle",{cx:"38.8",cy:"37.8",r:"1.5"}),e.jsx("circle",{cx:"54.8",cy:"37.8",r:"1.5"})]})]}),e.jsx("path",{className:"resident-smile",d:"M36 43q4-7 8 0m8 0q4-7 8 0"}),e.jsx("path",{className:"resident-sleep",d:"M36 42q4 4 8 0m8 0q4 4 8 0"})]})})]})}),e.jsx("rect",{className:"resident-wall",x:"9",y:"59",width:"78",height:"20",rx:"6"}),e.jsx("rect",{className:"resident-slab",x:"6",y:"55",width:"84",height:"7",rx:"3.5"}),e.jsx("path",{className:"resident-rim",d:"M12 56.4H84"}),e.jsx("rect",{className:"resident-shell resident-grip",x:"26",y:"50",width:"12",height:"9",rx:"4.5",fill:`url(#${p}-shell)`}),e.jsx("rect",{className:"resident-shell resident-hand",x:"58",y:"50",width:"12",height:"9",rx:"4.5",fill:`url(#${p}-shell)`}),e.jsx("title",{children:a?m.residentOffline:m.residentName})]})}const mf={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"};function ol({tool:t,seed:s,state:n,large:a=!1,frozen:l=!1}){const r=mf[n],o=nn();return e.jsx("span",{className:"inline-flex flex-none","aria-hidden":"true",children:e.jsx(rl,{tool:t,seed:s,state:r,pose:ll(s,r),size:a?68:34,theme:o,frozen:l})})}function bs(t){return e.jsx(Zr,{...t,theme:nn()})}const pf={plain:"border-line bg-surface",warning:"border-attention/25 bg-attention/[0.06]",approval:"border-approval/25 bg-approval/[0.06]",danger:"border-danger-fg/25 bg-danger-bg"};function Xe({title:t,tone:s="plain",children:n,role:a}){return e.jsxs("div",{role:a,className:`rounded-control border p-3.5 text-small leading-[1.65] ${pf[s]}`,children:[e.jsx("strong",{className:"mb-[5px] block text-body",children:t}),n]})}var Jr=rm();const eo="(min-width: 768px) and (min-height: 501px)",ff=`${eo} and (orientation: landscape)`,ei=t=>typeof globalThis.matchMedia=="function"?globalThis.matchMedia(t):null;function gd(t){return f.useSyncExternalStore(s=>{var a;const n=ei(t);return(a=n==null?void 0:n.addEventListener)==null||a.call(n,"change",s),()=>{var l;return(l=n==null?void 0:n.removeEventListener)==null?void 0:l.call(n,"change",s)}},()=>{var s;return((s=ei(t))==null?void 0:s.matches)??!1},()=>!1)}function It(){return gd(eo)}function il(){return gd(ff)}const bd=f.createContext(void 0),jd=()=>f.useContext(bd);function ss({list:t,detail:s,tab:n,fold:a=!1}){const[l,r]=f.useState(null);return e.jsxs("div",{className:"split","data-split":n,"data-fold":a?"":void 0,children:[e.jsx("div",{ref:r,className:"split-banner"}),e.jsxs(bd.Provider,{value:l,children:[e.jsx("section",{className:"split-list",children:t}),e.jsx("section",{className:"split-detail",children:s})]})]})}function Il({title:t,body:s}){return e.jsx("div",{"data-split-empty":"",className:"flex flex-1 items-center justify-center px-6 text-center",children:e.jsxs("div",{className:"max-w-[280px]",children:[e.jsx("h2",{className:"text-base font-semibold",children:t}),e.jsx("p",{className:"mt-1 text-body text-muted",children:s})]})})}const hf=["atoi","sessions","prs","rigs","chat"];function to(t){switch(t.name){case"atoi":case"request":case"ask":return"atoi";case"sessions":case"routines":case"thread":case"terminal":case"launch":return"sessions";case"prs":case"rigs":case"chat":return t.name;case"rig":case"kernel":case"max":return"rigs";case"pr":return"prs";case"atelier":return"atelier";case"connection":return null}}const yd=t=>({name:t}),gf=t=>to(t)===t.name&&!(t.name==="atelier"&&t.sessionId),Nd=new Map;function bf(t){const s=to(t);s&&s!=="atelier"&&Nd.set(s,ne(t))}const so=t=>Nd.get(t)??ne(yd(t));function jf(t,s=[],n=[]){const a=t.filter(o=>o.filter==="permission").length+n.filter(o=>o.routine.kind==="failed").length,l=t.filter(o=>o.filter!=="permission").length+s.filter(o=>o.kind!=="update").length+n.filter(o=>o.routine.kind==="approve").length,r=a||l;return r?{text:r>99?"99+":String(r),tone:a?"red":"amber"}:null}function yf(t,s,n){return t?"online":n==="pc_offline"||n==="relay_unreachable"?"offline":s?"reconnecting":"loading"}const vd=f.createContext({pc:null,look:"online",reach:"pc_online",since:"",retry:()=>{}}),Ll=vd.Provider,Ut=()=>f.useContext(vd),Ht=t=>{const s=t??d.host.unknown;return s.length>14?`${s.slice(0,13)}…`:s};function kd({size:t=24}){return e.jsxs("svg",{"data-ledge-mark":!0,width:t,height:t,viewBox:"0 0 16 16","aria-hidden":"true",className:"flex-none",children:[e.jsx("rect",{width:"16",height:"16",rx:"3.5",fill:"#0A0A0A"}),e.jsx("rect",{x:"3",y:"3",width:"3",height:"10",rx:".5",fill:"#FAFAFA"}),e.jsx("rect",{x:"7",y:"10",width:"6",height:"3",rx:".5",fill:"#FAFAFA"}),e.jsx("circle",{cx:"10",cy:"6",r:"2",fill:"#FF6467"})]})}function cl(){const{pc:t,look:s}=Ut(),n=Ht(t),a=s==="offline";return e.jsxs("a",{href:ne({name:"connection",section:"link"}),"data-host":s,"aria-label":d.host.label(t??d.host.unknown,s),className:`inline-flex h-[26px] flex-none items-center gap-1.5 rounded-full border px-2.5 text-small whitespace-nowrap ${a?"border-attention/45 text-attention":"border-input text-muted"}`,children:[s==="loading"?e.jsx("span",{"aria-hidden":"true",className:"inline-block size-2.5 animate-spin rounded-full border-[1.5px] border-current border-r-transparent"}):e.jsx("span",{"aria-hidden":"true",className:`inline-block size-2 flex-none rounded-full ${s==="online"?"bg-ok":a?"bg-attention":"bg-muted"}`}),a?d.host.offline(n):n]})}function Nf({title:t}={}){return e.jsxs("header",{className:"bleed flex h-14 flex-none items-center gap-1.5 border-b border-line pr-1.5 pl-4",children:[t?e.jsx("h1",{className:"mr-1 text-[20px] font-semibold",children:t}):e.jsxs("span",{className:"mr-1 flex items-center gap-2 text-[17px] font-semibold",children:[e.jsx(kd,{}),d.brand]}),e.jsx(cl,{}),e.jsx("span",{className:"flex-1"}),e.jsx("a",{href:ne({name:"connection"}),"aria-label":d.nav.settings,title:d.nav.settings,className:"grid size-11 flex-none place-items-center rounded-lg text-muted active:bg-raised",children:e.jsx(q,{name:"gear"})})]})}function wd({badge:t,className:s}){return t?e.jsx("span",{"data-badge":t.tone,className:`absolute h-4 min-w-4 rounded-full px-1 text-center text-[10px] leading-4 font-semibold ${t.tone==="red"?"bg-primary text-primary-fg":"bg-attention text-[#1c1100]"} ${s}`,children:t.text}):null}const ur={atoi:"inbox",sessions:"sessions",prs:"pr",rigs:"rigs",chat:"ledge",atelier:"atelier"};function Sd(t){return(s,n)=>a=>{if(!n||t.name==="connection")return;a.preventDefault();const l=document.querySelector("[data-tab-scroll]");l&&l.scrollTop>0?l.scrollTo({top:0,behavior:"smooth"}):gf(t)||tn(yd(s))}}function vf({route:t,active:s,badges:n}){const a=Sd(t);return e.jsx("nav",{"aria-label":d.nav.label,className:"tabbar bleed grid flex-none grid-cols-5 border-t border-line bg-sidebar",children:hf.map(l=>e.jsxs("a",{href:so(l),onClick:a(l,s===l),"aria-current":s===l?"page":void 0,className:"tab group relative flex flex-col items-center justify-center gap-[3px] text-[11px] leading-[13px] text-muted aria-[current=page]:font-medium aria-[current=page]:text-fg",children:[e.jsx("span",{className:"pad grid h-7 w-[52px] place-items-center rounded-full group-aria-[current=page]:bg-raised",children:e.jsx(q,{name:ur[l]})}),d.nav[l],e.jsx(wd,{badge:n[l]??null,className:"top-[3px] left-1/2 ml-[7px]"})]},l))})}function kf({route:t,active:s,badges:n,atelier:a,ledge:l}){const r=Sd(t),o=i=>e.jsxs("a",{href:so(i),onClick:r(i,s===i),"aria-current":s===i?"page":void 0,className:"rb",children:[e.jsx(q,{name:ur[i]}),d.nav[i],e.jsx(wd,{badge:n[i]??null,className:"top-[3px] right-[7px]"})]},i);return e.jsxs("nav",{"aria-label":d.nav.label,className:"rail",children:[e.jsx("span",{className:"mb-2",children:e.jsx(kd,{size:30})}),["atoi","sessions","prs","rigs"].map(o),a&&o("atelier"),e.jsx("span",{className:"flex-1"}),e.jsxs("button",{type:"button","aria-pressed":l.open,onClick:l.onToggle,className:"rb",children:[e.jsx(q,{name:ur.chat}),d.nav.chat]}),e.jsx("span",{"aria-hidden":"true",className:"my-1.5 h-px w-[34px] bg-line"}),e.jsxs("a",{href:ne({name:"connection"}),"aria-current":s==="settings"?"page":void 0,className:"rb",children:[e.jsx(q,{name:"gear"}),d.nav.settings]})]})}function js({body:t,across:s=!1}={}){const{pc:n,look:a,reach:l,since:r,retry:o}=Ut(),[i,c]=Cn(),x=jd();if(a!=="offline")return null;const u=l==="relay_unreachable",m=u?d.compare.relayTitle:d.offline.title(n),p=u?d.compare.relayBody:r?(t??d.offline.body)(r):d.offline.bodyUnknown,h=y=>e.jsxs("button",{type:"button",disabled:i,onClick:()=>{c(!0),o()},className:Fe({size:"sm",className:y}),children:[e.jsx(q,{name:"refresh",className:"size-4"}),d.offline.retry]}),g=e.jsx(q,{name:u?"cloud":"wifioff",className:"mt-px size-4 flex-none text-attention"});return x!==void 0?!s||!x?null:Jr.createPortal(e.jsxs("section",{role:"status","data-strip":u?"relay":"pc",className:"strip flex items-center gap-[9px] rounded-lg border border-attention/40 px-3 py-2.5 text-[13px] leading-[18px]",children:[g,e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("b",{className:"font-semibold",children:m})," · ",e.jsx("span",{className:"text-muted",children:p})]}),h("flex-none")]}),x):e.jsxs("section",{role:"status","data-strip":u?"relay":"pc",className:"strip flex flex-none items-start gap-[9px] rounded-lg border border-attention/40 px-3 py-2.5 text-[13px] leading-[18px]",children:[g,e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[e.jsx("b",{className:"font-semibold",children:m}),e.jsx("span",{className:"text-muted",children:p}),h("self-start")]})]})}function wf(){const t="block animate-[ledge-pulse_1.6s_ease-in-out_infinite] rounded-[5px] bg-raised";return e.jsxs("div",{"aria-hidden":"true","data-loading":"","data-list-state":"",className:"flex flex-col gap-3",children:[e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-line bg-surface p-3",children:[e.jsxs("div",{className:"flex items-center gap-[7px]",children:[e.jsx("span",{className:`${t} h-4 w-[26px]`}),e.jsx("span",{className:`${t} h-3.5 w-20`}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:`${t} h-4 w-[70px]`})]}),e.jsx("span",{className:`${t} h-[34px]`}),e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("span",{className:`${t} h-11`}),e.jsx("span",{className:`${t} h-11`})]})]}),e.jsxs("div",{className:"flex flex-col gap-3 rounded-lg border border-line bg-surface p-3",children:[e.jsxs("div",{className:"flex items-center gap-[7px]",children:[e.jsx("span",{className:`${t} h-4 w-[26px]`}),e.jsx("span",{className:`${t} h-3.5 w-[110px]`})]}),e.jsx("span",{className:`${t} h-3.5 w-[85%]`})]})]})}function Rs({title:t,subtitle:s,wideSubtitle:n,actions:a,wideActions:l,children:r,bodyClassName:o="flex flex-col gap-3",offlineBody:i,heading:c=!0,offlinePill:x=!0}){const u=It(),{pc:m,look:p,since:h}=Ut(),g=p==="loading",y=g?d.link.connecting(Ht(m)):p==="offline"?h?d.link.lastKnownAt(h):d.inbox.lastKnown:n;return e.jsxs(e.Fragment,{children:[u&&e.jsxs("div",{className:"pane-head flex h-[58px] flex-none items-center gap-2 border-b border-line pr-1.5 pl-4",children:[e.jsx("h1",{className:"flex-none text-lg font-semibold whitespace-nowrap",children:t}),y&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:y}),!g&&(x||p!=="offline")&&e.jsx(cl,{}),l&&e.jsx("span",{className:"ml-auto flex flex-none items-center gap-2",children:l})]}),e.jsxs("main",{"data-tab-scroll":"",className:"tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pt-3.5 pb-[18px]",children:[e.jsx(js,{body:i,across:!0}),!u&&c&&e.jsxs("div",{className:"flex flex-none items-baseline gap-2",children:[e.jsx("h1",{className:"text-[22px] leading-7 font-semibold tracking-[-.02em]",children:t}),(g||s)&&e.jsx("span",{className:"min-w-0 truncate text-[12.5px] text-muted",children:g?d.link.connecting(Ht(m)):s}),a&&e.jsx("span",{className:"ml-auto flex flex-none items-center gap-2 self-center",children:a})]}),g?e.jsx(wf,{}):e.jsx("div",{className:`flex-none ${o}`,children:r})]})]})}function Fs(){const[t,s]=f.useState(!1);return f.useEffect(()=>{let n=!0;return zm().then(a=>{n&&s(a)}),()=>{n=!1}},[]),t}function _t(){const t=globalThis.navigator;return t?/iPhone|iPad/.test(t.userAgent)||/Macintosh/.test(t.userAgent)&&t.maxTouchPoints>1:!1}const As=d.confirm,Ol=t=>Pe({variant:t,block:!0});function ti({store:t,item:s,enabled:n,reason:a,onConfirm:l,onDeny:r,denyLabel:o}){const[i,c]=f.useState(null),[x,u]=f.useState(null),[m,p]=f.useState(!1),[h,g]=f.useState(a!==void 0),[y,k]=f.useState(0),S=f.useRef(!0),b=f.useRef(n);b.current=n;const j=f.useRef(null);f.useEffect(()=>(S.current=!0,()=>{S.current=!1}),[]),f.useEffect(()=>{var _;if(h||!n)return;const A=(_=t.getState().sessions.get(s.sessionId))==null?void 0:_.pending;if(!(A!=null&&A.key))return;let T=!0,R;c(null);const P={key:A.key,kind:A.kind,text:A.text};return t.prepareConfirm({purpose:"decide",id:s.sessionId,expect:P}).then(D=>{T&&(j.current=P,c(D),R=setTimeout(()=>{T&&(c(null),u("expired"))},D.expiresInMs))},()=>{T&&u("prepareFailed")}),()=>{T=!1,clearTimeout(R)}},[t,s.sessionId,s.key,n,h,y]);const N=h&&a?a==="assertion_expired"?"expired":"failed":x,$=()=>{u(null),g(!1),k(A=>A+1)},C=async()=>{var R,P;if(!n||m||!i)return;if(!i.credentialId){c(null),u("failed");return}p(!0),u(null);const A=await sa({challenge:i.challenge,rpId:i.rpId,credentialId:i.credentialId}).catch(()=>"failed");if(!S.current)return;p(!1);const T=j.current;if(!T||!b.current||((P=(R=t.getState().sessions.get(s.sessionId))==null?void 0:R.pending)==null?void 0:P.key)!==T.key){c(null),u("changed");return}if(A==="cancelled"){u("cancelled");return}if(A==="failed"){u("failed");return}c(null),l(A,T)===null&&u("failed")},M=N==="expired"||N==="failed"||N==="prepareFailed"||N==="changed",v=m?As.asking:i?_t()?As.goApple:As.go:As.preparing;return e.jsxs("section",{"aria-labelledby":"confirm-title",className:"flex flex-col gap-3 rounded-card border border-line bg-surface p-4",children:[e.jsx("h2",{id:"confirm-title",className:"text-title leading-[1.35] font-semibold",children:As.heading}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:As.note}),N&&e.jsx(Xe,{title:N==="changed"?d.decide.changed:As[N],tone:"warning",role:"alert"}),M?e.jsx("button",{type:"button",disabled:!n,onClick:$,className:Ol("primary"),children:As.retry}):e.jsx("button",{type:"button",disabled:!n||m||!i,onClick:()=>{C()},className:Ol("primary"),children:v}),e.jsx("button",{type:"button",disabled:!n,onClick:r,className:Ol(),children:o??d.decide.deny})]})}function xr(){return e.jsxs("p",{className:"inline-flex min-h-12 flex-1 items-center justify-center gap-2 rounded-control border border-dashed border-line px-4 py-2.5 text-center text-body leading-[1.4] font-medium text-muted",children:[e.jsx(q,{name:"monitor",className:"size-4"}),d.decide.onPc]})}function Sf(t){return t instanceof HTMLElement?t.isContentEditable||t.tagName==="INPUT"||t.tagName==="TEXTAREA"||t.tagName==="SELECT":!1}function $d(){return document.querySelector('[role="dialog"][aria-modal="true"]')!==null}function no(t,s){const n=f.useRef(s);n.current=s,f.useEffect(()=>{if(!t)return;const a=l=>{l.defaultPrevented||l.repeat||l.altKey||l.ctrlKey||l.metaKey||l.isComposing||Sf(l.target)||$d()||n.current(l.key)&&l.preventDefault()};return document.addEventListener("keydown",a),()=>document.removeEventListener("keydown",a)},[t])}const si=t=>Pe({variant:t,className:"flex-1"}),Hs=t=>Pe({variant:t,block:!0});function $f(t,s){const n=d.decide;switch(s){case"invalid":return t.kind==="question"?n.otherInvalid:n.failed;case"free_text":return n.otherUnsupported;case"untypable":return t.kind==="question"?d.question.untypable:n.failed;case"busy":return n.busy;case"not_taken":return n.notTaken;case"read_only":return n.readOnly;default:return n.failed}}function Cf(t){const{item:s,outcome:n,fresh:a,changed:l,stillPending:r,onReread:o,onDecide:i,answerable:c=!1,choice:x=null,onAnswer:u,answerBlocked:m=!1,onCheck:p,refused:h=!1,store:g,deviceConfirm:y=!1,optionReply:k,multi:S,keys:b=!1,withThread:j=!0}=t,N=d.decide,[$,C]=Cn(),M=Fs(),v=s.risk==="high"||n.kind==="rejected"&&n.reason==="confirm_required",A=a&&!l&&r,T=s.kind!=="question"&&!k&&!S&&!c&&!v,R=T&&_c(s.tool,s.kind,"always"),P=cr(s),_=R&&e.jsx("p",{className:"text-small text-muted phone-side:text-[12px] phone-side:leading-4",children:d.atoi.scope[P]}),D=n.kind!=="sending"&&n.kind!=="uncertain"&&!((n.kind==="rejected"||n.kind==="failed")&&(n.reason==="no_prompt"||n.reason==="nothing_to_decide"||n.reason==="stale"));no(b&&T&&A&&D,B=>{const Z=B.toLowerCase();return Z==="y"?(i("accept"),!0):Z==="n"?(i("deny"),!0):!1});const E=e.jsx("a",{href:t.threadHref??ne({name:"thread",sessionId:s.sessionId}),className:Hs("ghost"),children:d.result.thread(s.botName)}),z=(B,Z,H=!0)=>e.jsxs("footer",{className:"flex flex-none flex-col gap-2.5 border-t border-line bg-bg pt-3 pb-4 phone-side:pb-2",children:[B,H&&j&&e.jsx("div",{className:"phone-side:hidden",children:E}),Z&&e.jsx("p",{className:"text-center text-meta text-muted phone-side:hidden",children:Z})]});if(s.kind==="question"&&!c&&!k&&!S)return z(null,N.answerOnPc);const K=y&&M?g:void 0,L=k?k.canConfirm&&K!==void 0:v&&!c&&K!==void 0,W=n.kind==="rejected"&&(n.reason==="assertion_expired"||n.reason==="assertion_invalid"||n.reason==="confirm_required")?n.reason:void 0,ae=B=>k?L?k.picked!==null&&K?e.jsx(ti,{store:K,item:s,enabled:B,reason:W,onConfirm:k.onReply,onDeny:k.onBack,denyLabel:d.answers.change}):null:e.jsx(xr,{}):S?e.jsxs("div",{className:"flex flex-col gap-2.5",children:[S.missing>0&&e.jsx("p",{className:"text-center text-small text-muted",children:d.answers.missing(S.missing)}),e.jsx("button",{type:"button",disabled:!B||S.missing>0,onClick:S.onSend,className:Hs("primary"),children:d.answers.send}),e.jsx("button",{type:"button",disabled:!B,onClick:S.onCancel,className:Hs(),children:d.answers.cancel})]}):L&&K?e.jsx(ti,{store:K,item:s,enabled:B,reason:W,onConfirm:(Z,H)=>K.decide(s.sessionId,"accept",{assertion:Z,expect:H}),onDeny:()=>i("deny")}):c?e.jsx("button",{type:"button",disabled:!B||x===null||m,onClick:()=>u==null?void 0:u(),className:Hs("primary"),children:N.send}):b&&T?e.jsxs("div",{className:"flex flex-wrap items-center gap-2.5",children:[e.jsx("button",{type:"button",disabled:!B,onClick:()=>i("accept"),className:Pe({variant:"primary",className:"min-w-[150px]"}),children:N.allow}),e.jsx("button",{type:"button",disabled:!B,onClick:()=>i("deny"),className:Pe({className:"min-w-[120px]"}),children:N.deny}),R&&e.jsx("button",{type:"button",disabled:!B,onClick:()=>i("always"),className:Pe({variant:"ghost"}),children:Ua(P)}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono text-small text-muted",children:d.atoi.keys}),_&&e.jsx("div",{className:"basis-full",children:_})]}):e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsxs("div",{className:"flex flex-col gap-2.5 phone-side:flex-row",children:[e.jsxs("div",{className:"flex gap-2.5 phone-side:flex-[2]",children:[e.jsx("button",{type:"button",disabled:!B,onClick:()=>i("deny"),className:si(),children:N.deny}),v?e.jsx(xr,{}):e.jsx("button",{type:"button",disabled:!B,onClick:()=>i("accept"),className:si("primary"),children:N.allow})]}),R&&e.jsx("button",{type:"button",disabled:!B,onClick:()=>i("always"),className:Pe({variant:"ghost",block:!0,className:"phone-side:w-auto phone-side:flex-1"}),children:Ua(P)})]}),_]}),U=a?k?L?N.answerHint:N.onPcHint:S?N.answerHint:v&&!c&&!L?N.onPcHint:c?N.answerHint:N.hint:N.offlineHint,O=B=>z(e.jsxs(e.Fragment,{children:[B,ae(A)]}),U);if(l&&n.kind!=="sending"&&n.kind!=="uncertain")return z(e.jsxs(e.Fragment,{children:[e.jsx(Xe,{title:N.changed,tone:"warning",role:"status"}),ae(!1),e.jsx("button",{type:"button",onClick:o,className:Hs(),children:N.reread})]}));switch(n.kind){case"sending":return z(e.jsx(Xe,{title:N.sending,role:"status",children:e.jsx("p",{children:N.sendingBody})}));case"uncertain":return z(e.jsxs(e.Fragment,{children:[e.jsx(Xe,{title:N.uncertain,tone:"warning",role:"alert",children:e.jsx("p",{children:N.uncertainBody})}),p&&e.jsx("button",{type:"button",disabled:$,onClick:()=>{C(!0),p()},className:Hs("primary"),children:$?N.checking:N.check})]}));case"rejected":case"failed":{const B=n.reason;if(L&&W||B==="confirm_required")return O();if(B==="no_prompt"||B==="nothing_to_decide")return z(e.jsx(Xe,{title:N.noPrompt,tone:"warning",role:"alert"}));if(B==="stale")return z(e.jsxs(e.Fragment,{children:[e.jsx(Xe,{title:N.changed,tone:"warning",role:"alert"}),e.jsx("a",{href:ne({name:"atoi"}),className:Hs(),children:d.result.back})]}),void 0,!1);const Z=e.jsx(Xe,{title:$f(s,B),tone:"warning",role:"alert"});return r?O(Z):z(Z)}default:return O(h?e.jsx(Xe,{title:N.failed,tone:"warning",role:"alert"}):void 0)}}const un=(t,s)=>{var n,a;return(a=(n=t.match(new RegExp(`<${s}>([\\s\\S]*?)</${s}>`)))==null?void 0:n[1])==null?void 0:a.trim()};function Mf(t){const s=t.trim();if(!s.startsWith("<task-notification>"))return null;const n=un(s,"status"),a=un(s,"summary")??"",l=a.match(/^Agent "(.+)" (?:was |has )?(?:stopped|killed|completed|finished|failed)/),r=a.match(/^Background command "(.+)" (?:completed|failed|was stopped|was killed)(?: \(exit code (\d+)\))?/);return{...un(s,"task-id")!==void 0&&{id:un(s,"task-id")},...un(s,"output-file")!==void 0&&{output:un(s,"output-file")},status:n==="killed"||n==="completed"||n==="failed"?n:"other",summary:a,about:l?{kind:"agent",name:l[1]}:r?{kind:"command",command:r[1],...r[2]!==void 0&&{code:r[2]}}:null,raw:s}}const wt=d.thread.rig,ni=t=>t?`…${t.slice(-4)}`:"…";function Ef(t){const s=t.indexOf("@");return s>0?{seat:t.slice(0,s),rig:t.slice(s+1)}:{seat:t}}function _a(t,s,n){const a=s?n.get(s):void 0,{seat:l,rig:r}=Ef(t??"");return a?{name:a.name,...l?{seat:l}:{},session:{id:a.id,tool:a.tool,state:a.state}}:{name:l||(t??""),...r?{seat:r}:{}}}function Rf(t){const s=t.split(`
4
+ `).map(n=>n.trim()).find(n=>n!=="")??"";return`${wt.about(Cd(s))} `}const Cd=t=>t.length>80?`${t.slice(0,79).trimEnd()}…`:t;function Af(t,s){const n=t.split(`
5
+ `).slice(1).map(a=>a.trim()).find(a=>a!=="");return n?wt.refusedSaid(Gs(s),Cd(n)):wt.refusedSilent(Gs(s))}const Gs=t=>new Date(t).toLocaleTimeString(lt,{hour:"2-digit",minute:"2-digit"});function Tf(t,s,n){if(t.kind!=="received"&&t.kind!=="sent"&&t.kind!=="notice"||!t.rig)return;const a=t.rig,l=a.sentAt??t.at,r=n?{cut:!0}:{},o=(c=wt.raw)=>({label:c,text:a.raw});if(a.kind==="unreadable")return{key:t.id,kind:"rig-unreadable",at:l,text:a.raw||("text"in t?t.text:""),...r};if(t.kind==="received"){const c=_a(a.from??t.from,t.peer,s);return{key:t.id,kind:"rig-message",at:l,dir:"in",who:c,text:t.text,...a.count?{count:a.count}:{},...c.session?{reply:{sessionId:c.session.id,draft:Rf(t.text)}}:{},raw:o(),...r}}if(t.kind==="sent")return{key:t.id,kind:"rig-message",at:l,dir:"out",who:_a(a.to??t.to,t.peer,s),text:t.text,delivery:t.status,raw:o(wt.command),...r};if(a.kind==="handoff"){const c=!!t.outgoing,x=_a(c?a.to:a.from??t.name,t.peer,s),u=c&&t.status==="refused"?{refused:{log:Af(a.raw,t.at)}}:{},m=!("refused"in u)&&a.qitem?{qitem:a.qitem}:{};return{key:t.id,kind:"rig-task",at:l,outgoing:c,who:x,title:a.summary??t.summary??t.text,raw:o(c?wt.command:wt.raw),...u,...m,...r}}if(a.kind==="unblocked")return{key:t.id,kind:"rig-notice",at:l,tone:"task",title:wt.unblocked(ni(a.qitem)),raw:o(),...r};if(a.kind==="openrig"&&a.alert==="stalled")return{key:t.id,kind:"rig-notice",at:l,tone:"warn",title:wt.stalled(ni(a.qitem),a.minutes??0),raw:o(),...r};const i=t.text.split(`
6
+ `).map(c=>c.trim()).find(c=>c!=="")??"";return{key:t.id,kind:"rig-notice",at:l,tone:"plain",title:i,raw:o(),...r}}const _f=t=>{var s;return t.kind==="received"||t.kind==="sent"||t.kind==="notice"?(s=t.rig)==null?void 0:s.packet:void 0};function If(t){const s=new Map;for(const l of t){const r=_f(l);if(!r||!("rig"in l)||!l.rig)continue;const o=s.get(r.id)??{id:r.id,items:[],count:r.count};o.items.push({id:l.id,index:r.index,raw:l.rig.raw,at:l.at}),s.set(r.id,o)}const n=new Set,a=new Map;for(const l of s.values()){if(l.items.length<2)continue;for(const i of l.items)n.add(i.id);const r=l.items.at(-1),o=[...l.items].sort((i,c)=>i.index-c.index).map(i=>i.raw).join(`
7
+ `);a.set(r.id,{key:`packet-${l.id}`,kind:"rig-raw",at:r.at,raw:{label:wt.rawMany(l.count),text:o}})}return{inPacket:n,after:a}}function Lf(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 ai={pending:"pending","in-progress":"taken","handed-off":"passed",blocked:"blocked",done:"done"};function Of(t,s){if(!t)return{key:"unknown",text:wt.rowState.unknown};const n=ai[t.state]??"unknown",a=ai[t.state]?n==="passed"?wt.rowState.passed(_a(t.handedOffTo,void 0,new Map).name):wt.rowState[n]:t.state,l=[s?wt.log.passed(Gs(t.createdAt)):wt.log.handed(Gs(t.createdAt)),t.claimedAt?wt.log.taken(Gs(t.claimedAt)):n==="pending"?wt.log.notTaken:null,n==="done"?wt.log.done(Gs(t.updatedAt)):null].filter(Boolean).join(" · ");return{key:n,text:a,log:l}}const Df=t=>[...new Set(t.map(s=>s.name))],Ff=(t,s)=>t.length===s.length&&t.every((n,a)=>n===s[a]),Md=(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 zf(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 Ed(t,s,n,a){var r,o;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):((o=t.by)==null?void 0:o.kind)==="pc"?l.fromPc:zf(t,s,n)?l.fromHere:l.fromPc}function Pf(t,s,n,a){const l=d.thread.event;if(!t.decision)return null;if(t.decision==="unknown")return l.resolved;const r=Ed(t,s,n,a);return t.decision==="deny"?l.deny(r):l.accept(r)}const mr=2e4,Bf=(t,s,n)=>{const a=t.trim(),l=s.trim();return a===l||n&&a.length>0&&l.startsWith(a)};function qf(t,s,n,a=Date.now(),l=[],r=new Map,o=null){var b,j,N,$,C,M;let i=[];const c=new Set(l),x=v=>c.has(v)?{cut:!0}:{},u=Md(s.id,n),m=new Set,p=new Set;for(const v of u){if(v.phase!=="applied")continue;const A=v.message.attachments??[],T=t.find(R=>{var P;return R.kind==="prompt"&&Bf(R.text,v.message.text,c.has(R.id))&&!m.has(R.id)&&Ff(((P=R.images)==null?void 0:P.map(_=>_.id))??[],A)});T&&(m.add(T.id),p.add(v.op))}const h=If(t);let g=null,y=null;for(const v of t){const A=Tf(v,r,c.has(v.id));if(A){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,_=Gs(A.at);if(!(P&&P===y)&&_!==g&&i.push({key:`time-${v.id}`,kind:"time",label:_}),g=_,y=P,h.inPacket.has(v.id)){const{raw:D,...E}=A;i.push(E);const z=h.after.get(v.id);z&&i.push(z)}else i.push(A);continue}if(v.kind==="tool"&&!((N=v.images)!=null&&N.length)){const P={id:v.id,name:Do(v.tool),label:v.label,status:v.status},_=i.at(-1);(_==null?void 0:_.kind)==="tools"?_.tools.push(P):i.push({key:`tools-${v.id}`,kind:"tools",at:v.at,tools:[P]}),g=null,y=null;continue}const T=i.length,R=v.kind==="prompt"?Mf(v.text):null;if(R)i.push({key:v.id,kind:"task",task:R,at:v.at,...x(v.id)});else if(v.kind==="prompt")i.push({key:v.id,kind:"me",text:v.text,at:v.at,...($=v.images)!=null&&$.length?{images:v.images}:{},...m.has(v.id)?{delivery:"taken"}:{},...x(v.id)});else if(v.kind==="reply")i.push({key:v.id,kind:"agent",text:v.text,at:v.at,...x(v.id)});else if(v.kind==="tool"&&((C=v.images)!=null&&C.length))i.push({key:v.id,kind:"capture",label:om(v.tool)?d.thread.capture:Do(v.tool),at:v.at,images:v.images});else if(v.kind==="permission"){const P=Pf(v,s.id,n,o);P&&i.push({key:v.id,kind:"event",label:P,at:v.at})}i.length>T&&(g=null,y=null)}i=Lf(i);const k=Math.max(...t.map(v=>Date.parse(v.at)));for(const v of u){const A=Date.parse(v.at),T={key:v.op,kind:"me",text:v.message.text,at:v.at,...(M=v.message.attachments)!=null&&M.length?{attachments:v.message.attachments}:{}};if(v.phase==="sending")i.push({...T,delivery:"sending"});else if(v.phase==="uncertain")i.push({...T,delivery:"uncertain"});else if(v.phase==="applied"&&!p.has(v.op)&&!(k-A>mr)){const R=i.findIndex(_=>_.kind!=="awaiting"&&_.kind!=="time"&&!(_.kind==="me"&&_.delivery&&_.delivery!=="taken")&&Date.parse(_.at)>A),P=R<0?i.length:R>0&&i[R-1].kind==="time"?R-1:R;i.splice(P,0,{...T,delivery:"taken",...a-A<mr?{fresh:!0}:{}})}}s.exitedAt&&Pm(s,n)&&i.push({key:`closed-${s.exitedAt}`,kind:"event",label:d.sessionEnd.closedHere(Bm(s.exitedAt)),at:s.exitedAt});const S=Vt([s])[0];return S&&i.push({key:`awaiting-${S.key}`,kind:"awaiting",item:S}),i}const Bt=d.thread.composer;function Hf(t,s,n){const a=(l,r,o)=>({enabled:!1,placeholder:l,status:{tone:r,label:o}});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 Uf=["Montre le diff","Lance les tests","Explique les changements"],dl=t=>t.state==="done"||t.state==="refused"||t.state==="dropped",Rd=t=>t.owner===sr,Ad=t=>(t.giver??sr)===sr&&!Rd(t);function Wf(t){return[...t].filter(s=>Rd(s)&&!dl(s)&&!s.routine).sort((s,n)=>s.at.localeCompare(n.at))}function Kf(t){return[...t].filter(s=>Ad(s)&&dl(s)&&!s.seen).sort((s,n)=>s.updatedAt.localeCompare(n.updatedAt))}function Vf(t){return[...t].filter(s=>Ad(s)&&!dl(s)).sort((s,n)=>n.updatedAt.localeCompare(s.updatedAt))}const Gf=t=>new Date(Date.UTC(2026,10,23+Ra.indexOf(t))),Xf=t=>Gf(t).toLocaleDateString(lt,{weekday:"short",timeZone:"UTC"}),Td=(t,s)=>t.toLocaleDateString(lt,{weekday:"short",day:"numeric",month:"short",...s?{timeZone:"UTC"}:{}});function Dl(t){const s=d.routines,n=Ra.map((l,r)=>t.includes(l)?r:-1).filter(l=>l>=0);if(n.length===Ra.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 o=n.slice(l,r+1).map(i=>s.days[Ra[i]]);a.push(o.length>=3?`${o[0]}–${o[o.length-1]}`:o.join(", ")),l=r+1}return a.join(", ")}function Yf(t){const[s="",n=""]=t.split("T"),[a,l,r]=s.split("-").map(Number);return`${Td(new Date(Date.UTC(a,l-1,r)),!0)} ${n}`}function Xn(t){var l;const s=d.routines;if(t.kind==="once"){const r=[...t.at].sort().map(Yf),o=r.length>3?s.more(r.slice(0,3).join(", "),r.length-3):r.join(", ");return{card:s.oneShot,ask:o,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?Xf(t.days[0]):Dl(t.days)} ${n} · ${s.everyOther}`,ask:`${n} (${Dl(t.days)}, ${s.every2})`,dated:!0,moments:[]};const a=Dl(t.days);return{card:`${n} · ${a}`,ask:`${n} (${a})`,dated:!1,moments:[]}}const _d=t=>t.toLocaleTimeString(lt,{hour:"2-digit",minute:"2-digit"}),ba=t=>`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`;function Id(t,s,n=!1){const a=new Date(t),l=_d(a);if(!n){const r=new Date(s),o=new Date(s);if(o.setDate(o.getDate()+1),ba(a)===ba(r))return`${d.routines.today} ${l}`;if(ba(a)===ba(o))return`${d.routines.tomorrow} ${l}`}return`${Td(a,!1)} ${l}`}function Qf(t,s){if(!t.nextRun)return null;const n=Xn(t.schedule).dated,a=Id(t.nextRun,s,n);return n?d.routines.nextDated(a):d.routines.next(a)}function pr(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 ao=t=>t.state!=="done",lo=t=>{var s;return((s=t.lastRun)==null?void 0:s.outcome)==="failed"},li=t=>t.state==="pending"?0:lo(t)?1:t.state==="paused"?3:2,Zf=(t,s)=>li(t)-li(s)||(t.nextRun??"￿").localeCompare(s.nextRun??"￿")||t.name.localeCompare(s.name);function Jf(t){const s=t.filter(ao).sort(Zf);return{recurring:s.filter(n=>n.schedule.kind==="recurring"),once:s.filter(n=>n.schedule.kind==="once")}}function eh(t,s){const n=t.filter(ao),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()?_d(new Date(a)):Id(a,s);return{count:n.length,next:l,flagged:n.filter(r=>r.state==="pending"||lo(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 th(t,s){const n=[...s],a=new Set;for(const l of t??[]){if(!ao(l))continue;const r=ia(l,n);r&&a.add(r.id)}return a}const Ld=t=>{var s;return((s=t.proposal)==null?void 0:s.by.name)??(t.createdBy.kind==="session"?t.createdBy.name:void 0)};function Od(t){const s=n=>n.routine.kind==="approve"?0:1;return[...t].filter(n=>!!n.routine&&!dl(n)).sort((n,a)=>s(n)-s(a)||n.at.localeCompare(a.at))}const Dd=t=>t.ids??[t.id],sh={low:"Bas",medium:"Moyen",high:"Élevé",xhigh:"Très élevé",max:"Max",ultra:"Ultra"},nh={"claude:fable":"Le plus capable","claude:opus":"Très capable, plus lent","claude:sonnet":"Équilibré, au quotidien","claude:haiku":"Rapide et économique"};function ah(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 ca=t=>sh[t]??t,Fd=(t,s)=>nh[`${t}:${s.id}`]??s.description,lh=(t,s)=>t.model===s.model&&t.effort===s.effort,rh=t=>!((t.state==="idle"||t.state==="error")&&!t.pending),ro=t=>({model:t.model??null,effort:t.effort??null});function ri(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 oh(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 fr=t=>String(t).padStart(2,"0");function Ka(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 ${fr(n%60)}`:`${Math.floor(a/24)} j`}const ih=(t,s)=>t.getFullYear()===s.getFullYear()&&t.getMonth()===s.getMonth()&&t.getDate()===s.getDate(),Fl=t=>`${fr(t.getHours())}:${fr(t.getMinutes())}`,oi=t=>t.toLocaleDateString(lt,{weekday:"short"}),ch=168*36e5,zd=(t,s)=>new Date(t).getTime()-s>=ch;function oo(t,s,n=!1){const a=new Date(t);if(zd(t,s)){const l=a.toLocaleDateString(lt,{day:"numeric",month:"short"});return n?l:`${l} ${Fl(a)}`}return ih(a,new Date(s))?Fl(a):n?oi(a):`${oi(a)} ${Fl(a)}`}const dh=t=>t.pct>=100;function da(t,s){return t>=100?"red":s!==null&&t>=s*100?"amber":""}const uh=60*6e4;function ua(t,s,n=!0){return t.map(a=>{const l=a.readAt===null||s-Date.parse(a.readAt)>uh;return{...a,status:!n&&a.status==="ok"?"stale":a.status,windows:l?[]:a.windows}})}function xh(t,s,n=Date.now()){return ua(t,n).flatMap(a=>a.status==="expired"||a.status==="loading"?[]:a.windows.flatMap(l=>{const r=da(l.pct,s);return r?[{harness:a.harness,window:l,tone:r}]:[]}))}function ul(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:oh(t.model)}:{},...t.effort?{effort:ca(t.effort).toLowerCase()}:{},...l!==void 0?{context:{pct:Math.round(l*100),near:l>=n}}:{},...Number.isFinite(a)&&t.state!=="exited"?{duration:Ka(s-a)}:{}}}function ii(t){return t<1e3?String(Math.round(t)):t<1e6?`${Math.round(t/1e3)}k`:`${Number((t/1e6).toFixed(1))}M`}function mh(t,s,n,a,l){const r=s&&ua(s,a,l).find(i=>i.harness===t),o=r&&r.status!=="expired"&&r.status!=="loading"?r.windows[0]:void 0;return r&&o?{harness:r.harness,window:o,tone:da(o.pct,n)}:null}function Pd(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 o=await sa({challenge:r.challenge,rpId:r.rpId,credentialId:r.credentialId}).catch(()=>"failed");return o==="cancelled"?"cancelled":(s.current=null,o)}}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",o=t==="gone"?"border-dashed border-line text-muted":t==="fail"?"border-destructive/40":t==="warn"?"border-attention/45":"border-line";return e.jsxs("div",{role:"status","data-receipt":t,className:`flex min-h-[52px] items-center gap-2.5 rounded-lg border bg-surface px-3 py-2 ${o}`,children:[e.jsx(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:Fe({size:"xs",className:"flex-none"}),children:a.label}):e.jsx("button",{type:"button",disabled:a.disabled,onClick:a.onClick,className:Fe({size:"xs",className:"flex-none"}),children:a.label}))]})}function Va({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),ud);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 hr(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})),o=[...s.current].filter(([c])=>!l.has(c)&&!n.has(c)).sort((c,x)=>c[1].index-x[1].index);for(const[c,x]of o)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 i=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:i,dismissed:n}}const Bd=150,ph=t=>t.length>Bd||t.split(`
8
+ `).length>3,vt=()=>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 io(t){var Ze,Le;const{store:s,item:n,mode:a,outcome:l,fresh:r,ghost:o,changed:i,canConfirm:c,enroll:x,onGone:u,selected:m=!1,inThread:p=!1,keys:h=!1}=t,[g,y]=f.useState(null),[k,S]=f.useState(!1),[b,j]=f.useState(a.kind==="question"&&a.options.length===0&&a.other),[N,$]=f.useState(""),[C,M]=f.useState(!1),[v,A]=f.useState(null),T=Pd(s),R=il(),P=p&&R,_=d.atoi.receipt,D=n.botName,E=d.atoi.pill[n.kind],z=ne({name:"request",sessionId:n.sessionId,key:n.key}),K=f.useRef(null),L=h&&a.kind==="permission";if(no(L,de=>{var he;return((he=K.current)==null?void 0:he.call(K,de))??!1}),K.current=null,l.kind==="applied"){const de={label:_.thread,href:ne({name:"thread",sessionId:n.sessionId})},he=l.answer!==void 0?e.jsx(at,{tone:"ok",title:_.answered(l.answer.length>40?`${l.answer.slice(0,40)}…`:l.answer,D)}):l.decision==="deny"?e.jsx(at,{tone:"denied",title:_.denied(D),body:_.deniedBody,action:de}):e.jsx(at,{tone:"ok",title:_.allowed(D),body:_.allowedBody,action:de});return e.jsx(Va,{onGone:u,children:he})}if(l.kind==="uncertain")return e.jsx(at,{tone:"warn",title:d.decide.uncertain,body:_.uncertainBody,...t.onCheck?{action:{label:_.check,onClick:t.onCheck}}:{}});if(l.kind==="handledElsewhere"||o&&l.kind==="idle"){if(!r)return ci(u),null;const de=(Ze=t.session)==null?void 0:Ze.lastAnswer,he=de&&de.key===n.key,$e=he?de.by.kind==="pc"?d.thread.event.fromPc:de.by.id===((Le=s.getState().device)==null?void 0:Le.id)?d.thread.event.fromHere:d.thread.event.fromDevice(de.by.name):null,Oe=N.trim()!=="",rt=he?de.decision?_.decidedAt(D,de.decision,Be(de.at)):_.answeredAt(D,Be(de.at),Oe):_.gone(D,Oe);return e.jsx(Va,{onGone:u,children:e.jsx(at,{tone:"gone",title:$e?d.gone.titleOn($e):d.gone.titleElsewhere,body:rt})})}if((k||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))&&!o){const de=g;return e.jsx(at,{tone:"fail",title:d.decide.failed,body:_.what(D,E),action:de&&r?{label:_.retry,onClick:()=>{S(!1),B(de)}}:{label:d.inbox.examine,href:z}})}if(o)return ci(u),null;const ae=l.kind==="sending",U=r&&!i&&!ae&&!C,O={key:n.key,kind:n.kind,text:n.text},B=de=>{y(de),A(null);const he=de.kind==="decide"?s.decide(n.sessionId,de.decision,{expect:O}):s.reply(n.sessionId,de.text,{expect:O});S(he===null)},Z=async()=>{var he,$e;if(!U)return;M(!0),A(null);const de=await T({purpose:"decide",id:n.sessionId,expect:O});if(M(!1),typeof de=="string"){A(de);return}(($e=(he=s.getState().sessions.get(n.sessionId))==null?void 0:he.pending)==null?void 0:$e.key)===n.key&&(y({kind:"decide",decision:"accept"}),S(s.decide(n.sessionId,"accept",{assertion:de,expect:O})===null))};K.current=L&&U?de=>{const he=de.toLowerCase();return he==="y"?(B({kind:"decide",decision:"accept"}),!0):he==="n"?(B({kind:"decide",decision:"deny"}),!0):!1}:null;const H=de=>ae&&g!==null&&JSON.stringify(g)===JSON.stringify(de),X=rd(N),te=()=>{U&&X.problem===null&&B({kind:"reply",text:X.text,label:X.text})},pe=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,ue=a.kind==="high",F=ue?ld(n):null,w=n.kind==="permission"?n.body??n.text:wn(n),I=[n.repo,n.branch].filter(Boolean).join(" · "),V=(de="outline",he="")=>Fe({variant:de,className:`min-w-0 ${he}`}),ee=p?e.jsxs("a",{href:z,className:"-m-1 flex min-w-0 items-center gap-[7px] rounded-md p-1 active:bg-raised",children:[e.jsx(Ie,{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}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono text-small whitespace-nowrap text-muted",children:L?d.atoi.keys:yn(n.since,Date.now())}),ue&&e.jsx(zt,{tone:"risk",children:d.risk.badge})]}):e.jsxs("a",{href:z,className:"-m-1 flex min-w-0 items-center gap-[7px] rounded-md p-1 active:bg-raised",children:[e.jsx(gs,{tool:n.tool}),e.jsx("b",{className:"font-semibold whitespace-nowrap",children:D}),I&&e.jsx("span",{className:"min-w-0 truncate text-small text-muted",children:I}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"font-mono text-small whitespace-nowrap text-muted",children:yn(n.since,Date.now())}),ue?e.jsx(zt,{tone:"risk",children:d.risk.badge}):e.jsx(zt,{tone:n.kind==="question"?"ask":n.kind==="permission"?"perm":"plain",children:E})]}),Q=ph(w),J=n.kind==="permission"?e.jsx("a",{href:z,className:"block",children:e.jsx(Ep,{children:Q?w.split(`
9
+ `).slice(0,3).join(`
10
+ `).slice(0,Bd)+"…":w})}):e.jsx("a",{href:z,className:`block text-body [overflow-wrap:anywhere] ${n.kind==="question"?"":"font-semibold"} ${Q?"line-clamp-3":""}`,children:w}),fe=(de,he=!1)=>e.jsx("p",{className:`text-small [overflow-wrap:anywhere] ${he?"text-destructive":"text-muted"}`,role:he?"alert":void 0,children:de}),be=v==="cancelled"?d.confirm.cancelled:v==="prepareFailed"?d.confirm.prepareFailed:v==="failed"?d.confirm.failed:null,tt=(()=>{switch(a.kind){case"examine":return e.jsxs("a",{href:z,className:Fe({size:"sm",className:"self-start"}),children:[d.inbox.examine,e.jsx(q,{name:"chevron",className:"size-4"})]});case"readOnly":return fe(d.decide.readOnly);case"answerOnPc":return fe(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:!U,onClick:()=>B({kind:"decide",decision:"accept"}),className:V("primary","min-w-[140px]"),children:[H({kind:"decide",decision:"accept"})&&e.jsx(vt,{}),d.atoi.allow]}),e.jsxs("button",{type:"button",disabled:!U,onClick:()=>B({kind:"decide",decision:"deny"}),className:V("outline","min-w-[120px]"),children:[H({kind:"decide",decision:"deny"})&&e.jsx(vt,{}),d.atoi.deny]}),a.always&&e.jsxs("button",{type:"button",disabled:!U,onClick:()=>B({kind:"decide",decision:"always"}),className:Fe({variant:"ghost"}),children:[H({kind:"decide",decision:"always"})&&e.jsx(vt,{}),Ua(cr(n))]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsxs("button",{type:"button",disabled:!U,onClick:()=>B({kind:"decide",decision:"accept"}),className:V("primary"),children:[H({kind:"decide",decision:"accept"})&&e.jsx(vt,{}),d.atoi.allow]}),e.jsxs("button",{type:"button",disabled:!U,onClick:()=>B({kind:"decide",decision:"deny"}),className:V(),children:[H({kind:"decide",decision:"deny"})&&e.jsx(vt,{}),d.atoi.deny]})]}),a.always&&e.jsxs("button",{type:"button",disabled:!U,onClick:()=>B({kind:"decide",decision:"always"}),className:Fe({variant:"ghost",className:"-mt-1 self-stretch"}),children:[H({kind:"decide",decision:"always"})&&e.jsx(vt,{}),Ua(cr(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:!U,onClick:()=>{Z()},className:V("primary"),children:[C||H({kind:"decide",decision:"accept"})?e.jsx(vt,{}):e.jsx(q,{name:"face",className:"size-[18px]"}),e.jsx("span",{className:"truncate",children:C?d.confirm.checking:_t()?d.confirm.goApple:d.confirm.go})]}),e.jsxs("button",{type:"button",disabled:!U,onClick:()=>B({kind:"decide",decision:"deny"}),className:V(),children:[H({kind:"decide",decision:"deny"})&&e.jsx(vt,{}),d.atoi.deny]})]}),C&&fe(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:V(),children:d.decide.onPc}),e.jsxs("button",{type:"button",disabled:!U,onClick:()=>B({kind:"decide",decision:"deny"}),className:V(),children:[H({kind:"decide",decision:"deny"})&&e.jsx(vt,{}),d.atoi.deny]})]}),fe(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 de=`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(($e,Oe)=>{const rt={kind:"reply",text:String(Oe+1),label:$e};return e.jsxs("button",{type:"button",disabled:!U,onClick:()=>B(rt),className:Fe({className:"h-auto min-h-11 max-w-full py-2 text-left whitespace-normal [overflow-wrap:anywhere]"}),children:[H(rt)&&e.jsx(vt,{}),$e]},`${Oe}:${$e}`)})}),a.other&&!b&&a.options.length>0&&e.jsx("button",{type:"button",disabled:!U,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:de,className:"sr-only",children:d.question.fieldLabel(D)}),e.jsx("input",{id:de,value:N,onChange:$e=>$($e.target.value),placeholder:d.question.placeholder,autoComplete:"off",enterKeyHint:"send","aria-invalid":he,disabled:!r||i,onKeyDown:$e=>{$e.key==="Enter"&&!$e.nativeEvent.isComposing&&($e.preventDefault(),te())},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:!U||X.problem!==null,onClick:te,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"&&ae&&g.text===X.text?e.jsx(vt,{}):e.jsx(q,{name:"send",className:"size-[18px]"})})]}),he?fe(X.problem==="long"?d.question.long(Yr):X.problem==="digit"?d.question.digit:d.question.untypable,!0):fe(d.atoi.sendHint(D))]}),!a.other&&a.options.length>0&&fe(d.decide.otherUnsupported)]})}}})(),yt=ue?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(yt,D,n.repo),children:[ee,pe&&fe(pe,!0),i&&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,Q&&e.jsx("a",{href:z,className:"-mt-1 self-start text-[13px] font-medium underline-offset-2 hover:underline",children:d.atoi.readAll}),F&&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:F.title}),e.jsx("span",{className:"text-muted",children:F.body})]})]}),i&&e.jsx("button",{type:"button",onClick:t.onReread,className:Fe(),children:d.decide.reread}),be&&fe(be,!0),tt,ae&&fe(d.decide.sending)]})}function ci(t){queueMicrotask(t)}const fh=t=>Fe({variant:t?"primary":"outline",className:"h-auto min-h-11 w-full justify-start gap-2 px-3 py-2.5 text-left leading-[19px] whitespace-normal [overflow-wrap:anywhere]"}),di=t=>new Date(t).toLocaleTimeString(lt,{hour:"2-digit",minute:"2-digit"});function qd({store:t,ask:s,end:n,fresh:a,ghost:l,canConfirm:r,enroll:o,onGone:i,full:c=!1,selected:x=!1}){const u=d.asks,m=d.atoi.receipt,p=Pd(t),h=id(s),g=cd(s),[y,k]=f.useState(!1),[S,b]=f.useState(""),[j,N]=f.useState(null),[$,C]=f.useState(null),[M,v]=f.useState(!1),[A,T]=f.useState(null),R=ne({name:"ask",id:s.id}),P=async(w,I)=>{N(w),C(null),T({key:w,answer:I});let V;if(I.kind!=="seen"){const Q=await p({purpose:"rig",qitem:s.id,answer:I});if(typeof Q=="string"){N(null),C(Q);return}V=Q}const ee=t.answerAsk(s.id,I,V?{assertion:V}:{});if(N(null),ee===null){C("notSent");return}(I.kind==="words"||I.kind==="resolve")&&k(!1)},_=m.what(g.name,u.pill[h]);if(n.kind==="sent"){const w=Dp(s,n.answer),I=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,w?`« ${w.length>60?`${w.slice(0,60)}…`:w} »`:""].filter(Boolean).join(" · ")});return e.jsx(Va,{onGone:i,children:I})}if(n.kind==="already"||l&&n.kind!=="failed"&&n.kind!=="uncertain")return!a&&l&&n.kind!=="already"?(queueMicrotask(i),null):e.jsx(Va,{onGone:i,children:e.jsx(at,{tone:"gone",title:u.already,body:m.what(g.name,s.summary)})});const D=w=>{P((A==null?void 0:A.key)??"retry",w)};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)||D(n.answer)},disabled:!a||j!==null}});if(n.kind==="failed"){const w=n.error==="openrig_stopped"?u.stopped:n.error==="unreachable"?u.unreachable:n.message??n.error;return e.jsx(at,{tone:"fail",title:u.notSent(w),body:_,action:{label:u.retry,onClick:()=>D(n.answer),disabled:!a||j!==null}})}const E=n.kind==="sending"||j!==null,z=a&&!E,K=h!=="update",L=z&&(r||!K),W=w=>j===w||n.kind==="sending"&&(A==null?void 0:A.key)===w?e.jsx(vt,{}):null,ae=s.questions.length>1,U=s.questions.filter(w=>Zo(s,w.id)!==null||n.kind==="recorded"&&n.answer.kind==="choice"&&n.answer.questionId===w.id).length,O=s.bodyTruncated&&s.body===s.summary?"":s.body,B=s.priority==="routine"?null:u.priority[s.priority],Z=(w,I=!1)=>e.jsx("p",{className:`text-small [overflow-wrap:anywhere] ${I?"text-destructive":"text-muted"}`,role:I?"alert":void 0,children:w}),H=_t(),X=K?H?u.sendCheck:u.sendDevice:u.send,te=w=>{var ee;const I=Zo(s,w.id)??(n.kind==="recorded"&&n.answer.kind==="choice"&&n.answer.questionId===w.id?((ee=w.options.find(Q=>Q.id===n.answer.optionId))==null?void 0:ee.label)??null:null);if(I!==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"}),I]});const V=[...w.options].sort((Q,J)=>Number(J.recommended)-Number(Q.recommended));return e.jsx("div",{className:"flex flex-col gap-2",children:V.map(Q=>{const J=`${w.id}:${Q.id}`;return e.jsxs("button",{type:"button",disabled:!L||y,onClick:()=>{P(J,{kind:"choice",questionId:w.id,optionId:Q.id})},className:fh(Q.recommended),children:[W(J),e.jsx("span",{className:"min-w-0",children:Q.label}),Q.recommended&&e.jsx("span",{className:"ml-auto pl-2 text-xs whitespace-nowrap opacity-85",children:u.recommended})]},Q.id)})})},pe=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:w=>b(w.target.value),disabled:E,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:!L||!S.trim(),onClick:()=>{P("words",s.kind==="parked"?{kind:"resolve",text:S.trim()}:{kind:"words",text:S.trim()})},className:Fe({variant:"primary",className:"min-w-0"}),children:[W("words")??(K?e.jsx(q,{name:"face",className:"size-[18px]"}):null),e.jsx("span",{className:"truncate",children:X})]}),e.jsx("button",{type:"button",disabled:E,onClick:()=>k(!1),className:Fe({className:"min-w-0"}),children:u.cancel})]}),ae&&U<s.questions.length&&Z(u.settlesAll)]}),ue=$==="cancelled"?d.confirm.cancelled:$==="prepareFailed"?d.confirm.prepareFailed:$==="failed"?d.confirm.failed:$==="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,F=!K||s.questions.length===0&&!y&&h!=="parked"&&h!=="question"?null:r?j!==null&&j!=="seen"?Z(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"}),H?u.confirmHint:u.confirmHintDevice]}):e.jsxs(e.Fragment,{children:[Z(u.needsDevice),o&&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:R,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:di(s.updatedAt)})]}),e.jsx("a",{href:R,className:"block text-body font-semibold [overflow-wrap:anywhere]",children:s.summary}),O&&!y&&(c?e.jsx("p",{className:"text-body whitespace-pre-wrap [overflow-wrap:anywhere] text-muted",children:O}):e.jsx("a",{href:R,className:"line-clamp-3 text-body [overflow-wrap:anywhere] text-muted",children:O})),!c&&!y&&(s.bodyTruncated||O.length>180||O.split(`
11
+ `).length>3)&&e.jsx("a",{href:R,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:di(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":M,onClick:()=>v(w=>!w),className:"self-start text-[13px] font-medium",children:[M?"⌄":"›"," ",u.details]}),M&&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:!z,onClick:()=>{P("seen",{kind:"seen"})},className:Fe({size:"sm"}),children:[W("seen"),u.seen]})}):y&&!ae?pe:s.questions.length===0?y?pe:e.jsx("button",{type:"button",disabled:!L,onClick:()=>k(!0),className:Fe({className:"self-start"}),children:s.kind==="parked"?u.answerParked:u.writeAnswer}):ae?e.jsxs(e.Fragment,{children:[s.questions.map((w,I)=>e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("span",{className:"text-small text-muted [overflow-wrap:anywhere]",children:[I+1,". ",w.question]}),te(w)]},w.id)),e.jsx("span",{className:"text-small text-muted",children:u.progress(U,s.questions.length)}),y?pe:e.jsx("button",{type:"button",disabled:!L,onClick:()=>k(!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:[te(s.questions[0]),e.jsx("button",{type:"button",disabled:!L,onClick:()=>k(!0),className:"self-start text-[13px] font-medium text-muted underline-offset-2 hover:underline disabled:opacity-45",children:u.answerOther})]}),ue&&Z(ue,!0),!ue&&F]})}const Ms=(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 xl(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 Hd({routine:t,session:s,frozen:n}){return e.jsx(ol,{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 hh(){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 gh({store:t,routine:s,session:n,offline:a,now:l,focused:r}){const o=d.routines,[i,c]=f.useState(null),x=f.useRef(null),[u,m]=f.useState(r);f.useEffect(()=>{var M,v;if(!r)return;(v=(M=x.current)==null?void 0:M.scrollIntoView)==null||v.call(M,{block:"center"}),m(!0);const C=setTimeout(()=>m(!1),bh);return()=>clearTimeout(C)},[r]);const[p,h]=f.useState(null),g=s.state==="pending",y=lo(s),k=s.state==="paused",S=async(C,M)=>{c(C),h(null),h(xl(await t.routineCmd(s.id,M))),c(null)},b=g||k?null:Qf(s,l),j=s.lastRun,N=C=>i===C?e.jsx(vt,{}):null;let $;return g?$=e.jsx(zt,{tone:"ask",children:o.pending}):j?$=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:o.lastAt(j.slot,o.outcome[j.outcome])}),j.late&&e.jsx(hh,{})]}):$=e.jsx("span",{children:o.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(Hd,{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," · ",Xn(s.schedule).card]})]})]}),k?e.jsx("div",{children:e.jsx(zt,{children:o.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:$}),y&&pr(s)&&e.jsx("p",{className:"text-[13px] [overflow-wrap:anywhere] text-muted",children:pr(s)}),e.jsx("div",{className:"flex gap-2",children:g?e.jsx("a",{href:ne({name:"atoi"}),className:Ms(),children:o.seeInAtoi}):e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:a||i!==null,onClick:()=>{S("run","run")},className:Ms(),children:[N("run")??e.jsx(q,{name:"play",className:"size-3.5"}),e.jsx("span",{className:"truncate",children:y?o.retry:o.runNow})]}),e.jsxs("button",{type:"button",disabled:a||i!==null,onClick:()=>{S("toggle",k?"resume":"pause")},className:Ms(),children:[N("toggle"),e.jsx("span",{className:"truncate",children:k?o.resume:o.pause})]})]})}),p&&e.jsx("p",{role:"alert",className:"text-small text-destructive",children:p})]})})}const bh=1500;function ui({children:t}){return e.jsx("h2",{className:"mx-1 -mb-1 text-[10.5px] font-medium tracking-[.06em] text-muted uppercase",children:t})}function xi({store:t,focus:s}){const n=me(t),a=Xt(),l=It(),r=d.routines,o=Jf(n.routines??[]),i=!n.fresh,c=[...n.sessions.values()],x=u=>u.map(m=>e.jsx(gh,{store:t,routine:m,session:ia(m,c),offline:i,now:a,focused:m.id===s},m.id));return e.jsxs(Rs,{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(),al({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})]}),o.recurring.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ui,{children:r.groups.recurring}),x(o.recurring)]}),o.once.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(ui,{children:r.groups.once}),x(o.once)]}),e.jsx("p",{className:"px-2 text-center text-[12.5px] text-muted",children:r.readonly})]})}const jh=t=>new Date(t).toLocaleTimeString(lt,{hour:"2-digit",minute:"2-digit"});function co({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:jh(s)})]})]})}function uo({routine:t,session:s,frozen:n,children:a}){return e.jsxs("div",{className:"flex items-start gap-[9px]",children:[e.jsx(Hd,{routine:t,session:s,frozen:n}),e.jsx("p",{className:"min-w-0 flex-1 text-body [overflow-wrap:anywhere]",children:a})]})}const Ga=t=>{var s;return((s=t.proposal)==null?void 0:s.spec)??t};function yh(t){return t.task.routine.kind==="failed"?e.jsx(kh,{...t}):Dd(t.task.routine).length>1?e.jsx(vh,{...t}):e.jsx(Nh,{...t})}function Nh({store:t,task:s,state:n,canConfirm:a}){var C,M;const l=d.routines.atoi,r=s.routine.id,o=(C=n.routines)==null?void 0:C.find(v=>v.id===r),i=n.routineDetails[r],c=i&&i!=="gone"?i:void 0,[x,u]=f.useState(null),[m,p]=f.useState(null);f.useEffect(()=>{n.fresh&&t.showRoutine(r)},[t,r,n.fresh,i]);const h=c?Ga(c):o&&!o.proposed?o:void 0,g=c?!!c.proposal:!!(o!=null&&o.proposed),y=c??o,k=y?ia(y,n.sessions.values()):void 0,S=(y&&Ld(y))??s.giverName??"",[b,j]=f.useState(!1),N=async v=>{u(v),p(null),j(!1);const A=v==="approve"?await t.approveRoutine(r,c.key):await t.routineCmd(r,"refuse");v==="approve"&&A.status==="rejected"&&A.reason==="stale"?(j(!0),t.rereadRoutine(r)):p(xl(A)),u(null)},$=!n.fresh||x!==null;return e.jsxs($n,{tone:"ask",label:`${l.ask} · ${s.routine.name}`,children:[e.jsx(co,{failed:!1,at:s.at}),y?e.jsx(uo,{routine:y,session:k,frozen:!n.fresh,children:h?e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:S})," ",g?l.editAsks(h.name,Xn(h.schedule).ask):l.asks(h.name,Xn(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:Ga(c).prompt}),b&&e.jsx("p",{role:"status",className:"text-small text-attention [overflow-wrap:anywhere]",children:l.stale(((M=h??y)==null?void 0:M.name)??s.routine.name)}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button",disabled:$||!c,onClick:()=>{N("approve")},className:Ms(!0),children:[x==="approve"&&e.jsx(vt,{}),l.activate]}),e.jsxs("button",{type:"button",disabled:$,onClick:()=>{N("refuse")},className:Ms(),children:[x==="refuse"&&e.jsx(vt,{}),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 vh({store:t,task:s,state:n,canConfirm:a}){const l=d.routines.atoi,r=Dd(s.routine),o=r.map(R=>{var P;return(P=n.routines)==null?void 0:P.find(_=>_.id===R)}).filter(R=>!!R),i=n.routines?o.filter(R=>R.state==="pending"||R.proposed):[],c=n.routines?i.length:r.length,x=o[0],u=x?ia(x,n.sessions.values()):void 0,[m,p]=f.useState(null),[h,g]=f.useState(null),[y,k]=f.useState(!1),S=i.map(R=>n.routineDetails[R.id]),b=S.map(R=>R&&R!=="gone"?R.key:"-").join(",");f.useEffect(()=>{if(n.fresh)for(const R of i)t.showRoutine(R.id)},[t,n.fresh,i.map(R=>R.id).join(","),b]);const j=S.filter(R=>!!R&&R!=="gone"),N=i.length>0&&j.length===i.length,$=async R=>{p(R),g(null),k(!1);const P=i.map(E=>{const z=n.routineDetails[E.id];return{routine:E.id,routineKey:z&&z!=="gone"?z.key:E.key}}),[_,...D]=P;if(_){const E=R==="approve"?await t.approveRoutine(_.routine,_.routineKey,D):await t.routineCmd(_.routine,"refuse",D);if(R==="approve"&&E.status==="rejected"&&E.reason==="stale"){k(!0);for(const z of P)t.rereadRoutine(z.routine)}else g(xl(E))}p(null)},C=!n.fresh||m!==null||i.length===0,M=(x&&Ld(x))??s.giverName??"",v=new Set(j.map(R=>Ga(R).target.cwd)),A=v.size===1?[...v][0]:void 0,T=new Set;return e.jsxs($n,{tone:"ask",label:`${l.ask} · ${s.routine.name}`,children:[e.jsx(co,{failed:!1,at:s.at}),x?e.jsxs(uo,{routine:x,session:u,frozen:!n.fresh,children:[e.jsx("b",{className:"font-semibold",children:M})," ",l.groupAsks(c),A&&e.jsxs("span",{className:"text-muted",children:[" ",l.inDir(A)]})]}):e.jsx("p",{className:"text-body [overflow-wrap:anywhere]",children:l.fallbackAsk(s.routine.name)}),i.length>0&&e.jsx("ul",{className:"m-0 flex list-none flex-col gap-2.5 p-0",children:i.map(R=>{const P=n.routineDetails[R.id],_=P&&P!=="gone"?Ga(P):void 0,D=Xn((_??R).schedule),E=_&&!T.has(_.prompt)?_.prompt:void 0;return _&&T.add(_.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:(_??R).name})," ",e.jsxs("span",{className:"text-muted",children:["· ",D.moments[0]??D.card,_&&!A?` · ${l.inDir(_.target.cwd)}`:""]})]}),E&&e.jsx("pre",{"data-prompt":"",className:"m-0 rounded-md border border-line bg-raised px-[9px] py-1.5 font-mono text-[11.5px] leading-[17px] whitespace-pre-wrap [overflow-wrap:anywhere]",children:E})]},R.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:C||!N,onClick:()=>{$("approve")},className:Ms(!0),children:[m==="approve"&&e.jsx(vt,{}),l.activateAll(c)]}),e.jsxs("button",{type:"button",disabled:C,onClick:()=>{$("refuse")},className:Ms(),children:[m==="refuse"&&e.jsx(vt,{}),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 kh({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),o=r?ia(r,n.sessions.values()):void 0,[i,c]=f.useState(!1),[x,u]=f.useState(null),m=pr(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(xl(await t.routineCmd(l,"run"))),c(!1)};return e.jsxs($n,{tone:"perm",label:`${a.failed} · ${s.routine.name}`,children:[e.jsx(co,{failed:!0,at:s.at}),r?e.jsx(uo,{routine:r,session:o,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||i,onClick:()=>{h()},className:Ms(!0),children:[i&&e.jsx(vt,{}),a.retry]}),e.jsx("a",{href:ne({name:"routines",routine:l}),className:Ms(),children:a.see})]}),x&&e.jsx("p",{role:"alert",className:"text-small text-destructive",children:x})]})}const He=d.compare,mi=t=>{const s=t.replace(/\D/g,"");return[s.slice(0,3),s.slice(3)]},Ia="\0",zl=t=>{const[s="",n=""]=t.split(Ia);return[s,n]};function Ss({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 wh({step:t,login:s,pcName:n,lost:a,stalled:l=!1,reach:r="pc_online",onRetry:o,onSame:i,onCancel:c,onRestart:x,onDone:u,actions:m}){var $,C;const[p,h]=f.useState(!1),g=n??d.yourPc,y=()=>{h(!1),x()},k=e.jsx("button",{type:"button",onClick:y,className:mt,children:He.retry}),S=a&&(t==null?void 0:t.step)!=="linked"?e.jsx(Xe,{title:He.lostTitle,role:"status",children:e.jsx("p",{children:He.lostBody})}):null;if((t==null?void 0:t.step)==="linked")return e.jsxs(Et,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(bs,{size:88}),e.jsx("h1",{className:qt,children:He.doneTitle(t.pc.name??n??d.yourPc,Ur((($=globalThis.navigator)==null?void 0:$.userAgent)??"",((C=globalThis.navigator)==null?void 0:C.maxTouchPoints)??0).replace(/ tablette$/,""))}),e.jsx("p",{className:"max-w-[300px] text-muted",children:He.doneBody})]}),e.jsx(Rt,{}),m??e.jsx("a",{href:ne({name:"atoi"}),onClick:u,className:St,children:He.seePending})]});if((t==null?void 0:t.step)==="cancelled"&&p)return e.jsxs(Et,{children:[e.jsx(Ss,{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:He.cancelledTitle})]}),e.jsx("p",{className:"text-body leading-[1.6]",children:He.cancelledBody})]}),e.jsx(Rt,{}),k]});const b=(t==null?void 0:t.step)==="cancelled"?[He.cancelledTitle,null]:!t&&l?[He.stalledTitle,He.stalledBody]:(t==null?void 0:t.step)==="expired"?[He.expiredTitle,He.expiredBody]:(t==null?void 0:t.step)==="refused"?[He.refusedTitle,He.refusedBody]:null;if(b)return e.jsxs(Et,{children:[e.jsx(Ss,{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(Rt,{}),k]});if((t==null?void 0:t.step)==="compare"&&t.phoneConfirmed)return e.jsxs(Et,{top:"pt-40",children:[e.jsx(Ss,{login:s}),e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(Vn,{}),e.jsx("h1",{className:qt,children:He.waitTitle}),e.jsxs("p",{className:"max-w-[300px] text-muted",children:[zl(He.waitBody(g,Ia))[0],e.jsx("span",{className:"font-mono text-fg",children:mi(t.code).join(" ")}),zl(He.waitBody(g,Ia))[1]]})]}),e.jsx(Rt,{}),e.jsx("button",{type:"button",onClick:c,className:mt,children:He.cancel})]});if((t==null?void 0:t.step)==="compare"){const[M,v]=mi(t.code),[A,T]=zl(He.intro(Ia));return e.jsxs(Et,{children:[e.jsx(Ss,{login:s}),e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:qt,children:He.title}),e.jsxs("p",{className:"text-muted",children:[A,e.jsx("strong",{className:"font-semibold text-fg",children:g}),T]})]}),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":He.codeLabel(`${M} ${v}`),className:"flex justify-center gap-3.5 font-mono text-[2.5rem] leading-[48px] font-semibold tracking-[.06em]",children:[e.jsx("span",{children:M}),e.jsx("span",{children:v})]}),e.jsx("span",{className:"text-small text-muted",children:He.basis})]}),S,e.jsx(Rt,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:i,className:St,children:He.same}),e.jsx("button",{type:"button",onClick:()=>{h(!0),c()},className:mt,children:He.different})]})]})}const j=t&&e.jsx("button",{type:"button",onClick:c,className:mt,children:He.cancel}),N=r==="pc_offline"?[He.offlineTitle,He.offlineBody(g)]:r==="relay_unreachable"?[He.relayTitle,He.relayBody]:null;return N?e.jsxs(Et,{top:"pt-40",children:[e.jsx(Ss,{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(Rt,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:o,className:St,children:He.retryNow}),j]})]}):e.jsxs(Et,{top:"pt-40",children:[e.jsx(Ss,{login:s}),e.jsxs("div",{role:"status",className:"flex flex-col items-center gap-3.5 text-center text-muted",children:[e.jsx(Vn,{}),e.jsx("p",{children:He.waitCode})]}),S,e.jsx(Rt,{}),j]})}const bt=d.recover,Ce=d.recover.no;function Js(){var s,n;const t=Ur(((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 Sh=["key","shield","laptop"];function $h({login:t,platform:s,onPasskey:n,onCode:a}){const l=Js();return e.jsxs(Et,{children:[e.jsx(Ss,{login:t}),e.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[e.jsx(bs,{size:72}),e.jsx("h1",{className:qt,children:bt.title(l)}),e.jsx("p",{className:"max-w-[320px] text-muted",children:bt.lead})]}),s&&e.jsx("ul",{className:"flex flex-col gap-3 text-body leading-5 text-fg/85",children:bt.notes(Js()).map((r,o)=>e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx(q,{name:Sh[o],className:"size-5 text-muted"}),r]},o))}),e.jsx(Rt,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[s&&e.jsxs("button",{type:"button",onClick:n,className:St,children:[e.jsx(q,{name:"face"}),bt.go]}),e.jsx("button",{type:"button",onClick:a,className:s?mt:St,children:bt.code})]})]})}const Ch={warn:"bg-attention/12 text-attention",bad:"bg-danger-bg text-danger-fg"};function Mh({icon:t,tone:s}){return e.jsx("span",{"aria-hidden":"true",className:`inline-flex size-12 flex-none items-center justify-center rounded-full ${Ch[s]}`,children:e.jsx(q,{name:t,className:"size-6"})})}function ds({login:t,icon:s,tone:n,title:a,body:l,centred:r=!1,children:o,actions:i}){return e.jsxs(Et,{children:[e.jsx(Ss,{login:t}),e.jsxs("div",{role:"alert",className:`flex flex-col gap-3 ${r?"items-center text-center":"items-start"}`,children:[e.jsx(Mh,{icon:s,tone:n}),e.jsx("h1",{className:qt,children:a}),e.jsx("p",{className:"text-muted",children:l})]}),o&&e.jsx("div",{className:"flex flex-col gap-2.5 text-body leading-[1.5] text-muted",children:o}),e.jsx(Rt,{}),e.jsx("div",{className:"flex flex-col gap-3",children:i})]})}const xn=({lead:t,children:s})=>e.jsxs("p",{children:[t&&e.jsx("strong",{className:"font-semibold text-fg",children:t}),t&&" ",s]}),Eh=t=>{if(!t)return null;const s=new Date(t);return Number.isNaN(s.getTime())?null:s.toLocaleDateString(lt,{day:"numeric",month:"short"})};function Rh({state:t,login:s,reach:n,onRetry:a,onCode:l,onCancel:r,onSignOut:o,onDone:i,actions:c}){const x=Js(),u=(h=!0)=>e.jsx("button",{type:"button",onClick:l,className:h?St:mt,children:bt.code},"code"),m=(h=!1)=>e.jsx("button",{type:"button",onClick:a,className:h?St:mt,children:bt.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"?bt.checking.reaching(h):bt.checking.reached(h),t.step==="reaching"?"on":"done"],[_t()?bt.checking.faceId:bt.checking.check,t.step==="faceid"?"on":t.step==="checking"?"done":"next"],[bt.checking.verifying(h),t.step==="checking"?"on":"next"]];return e.jsxs(Et,{top:"pt-40",children:[e.jsx(Ss,{login:s}),e.jsxs("div",{role:"status",className:"flex flex-col items-center gap-3 text-center",children:[e.jsx(Vn,{}),e.jsx("h1",{className:qt,children:bt.checking.title}),e.jsx("p",{className:"max-w-[320px] text-muted",children:bt.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,k])=>e.jsxs("li",{className:`flex items-center gap-2.5 ${k==="on"?"font-medium text-fg":"text-muted"}`,children:[k==="done"?e.jsx(q,{name:"check",className:"size-[18px] text-ok"}):k==="on"?e.jsx(Vn,{size:"size-[18px]"}):e.jsx("span",{className:"size-[18px]","aria-hidden":"true"}),y]},y))}),e.jsx(Rt,{}),e.jsx("button",{type:"button",onClick:r,className:mt,children:bt.cancel})]})}if(t.step==="done"){const h=t.pc.name??d.yourPc;return e.jsxs(Et,{top:"pt-14",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3 text-center",children:[e.jsx(bs,{size:88}),e.jsx("h1",{className:qt,children:bt.done.title(x,h)}),e.jsx("p",{className:"max-w-[320px] text-muted",children:bt.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"}),bt.done.told(h)]}),e.jsx(Rt,{}),c??e.jsx("a",{href:ne({name:"atoi"}),onClick:i,className:St,children:d.compare.seePending})]})}if(t.step==="cancelled")return null;const p=t.pcName??d.yourPc;switch(t.why){case"none":return e.jsx(ds,{login:s,icon:"key",tone:"warn",title:Ce.none.title,body:Ce.none.body(p),actions:[m(!0),u(!1)],children:e.jsx(xn,{lead:Ce.none.hintTitle,children:Ce.none.hint})});case"revoked":return e.jsx(ds,{login:s,icon:"unlink",tone:"bad",title:Ce.revoked.title(x),body:Ce.revoked.body(p,Eh(t.revokedAt)),actions:[u()],children:e.jsx("p",{children:Ce.revoked.hint})});case"old":return e.jsx(ds,{login:s,icon:"key",tone:"warn",title:Ce.old.title,body:Ce.old.body,actions:[u()],children:e.jsx(xn,{lead:Ce.old.hintTitle,children:Ce.old.hint(x)})});case"offline":{const[h,g]=n==="relay_unreachable"?[d.compare.relayTitle,d.compare.relayBody]:[Ce.offline.title(p),Ce.offline.body(p)];return e.jsx(ds,{login:s,icon:"wifioff",tone:"warn",centred:!0,title:h,body:g,actions:[m(!0),e.jsx("button",{type:"button",onClick:r,className:mt,children:bt.cancel},"cancel")]})}case"otherPc":{const[h,g]=t.tags??["",""];return e.jsxs(ds,{login:s,icon:"shield",tone:"bad",title:Ce.otherPc.title(p),body:Ce.otherPc.body,actions:[u(),e.jsx("button",{type:"button",onClick:o,className:mt,children:Ce.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:Ce.otherPc.inPasskey}),e.jsxs("dd",{className:"font-mono",children:[h," · ",Ce.otherPc.expected]}),e.jsx("dt",{className:"text-muted",children:Ce.otherPc.received}),e.jsxs("dd",{className:"font-mono text-danger-fg",children:[g," · ",Ce.otherPc.unknown]})]}),e.jsx(xn,{lead:Ce.otherPc.reinstalledTitle,children:Ce.otherPc.reinstalledBody}),e.jsx(xn,{lead:Ce.otherPc.otherwise,children:Ce.otherPc.warning})]})}case"connected":return e.jsxs(ds,{login:s,icon:t.device==="iPhone"?"phone":"tablet",tone:"warn",title:Ce.connected.title(t.device),body:Ce.connected.body(p),actions:[u(),m()],children:[e.jsx(xn,{lead:Ce.connected.otherTitle(t.device),children:Ce.connected.other}),e.jsx(xn,{lead:Ce.connected.reinstalledTitle(t.device),children:Ce.connected.reinstalled(t.device)})]});case"rate":{const h=t.retryInMs!==void 0?Math.max(1,Math.ceil(t.retryInMs/6e4)):null;return e.jsx(ds,{login:s,icon:"clock",tone:"warn",title:Ce.rate.title,body:Ce.rate.body(p,h),actions:[u(),...h!==null?[e.jsx("button",{type:"button",disabled:!0,className:mt,children:Ce.rate.retryIn(h)},"wait")]:[]]})}case"blocked":return e.jsx(ds,{login:s,icon:"lock",tone:"bad",title:Ce.blocked.title(p),body:Ce.blocked.body(p),actions:[u()],children:e.jsxs("p",{children:[Ce.blocked.hintBefore(p),e.jsx("strong",{className:"font-semibold text-fg",children:Ce.blocked.unblock}),Ce.blocked.hintAfter]})});case"timeout":return e.jsx(ds,{login:s,icon:"clock",tone:"warn",centred:!0,title:Ce.timeout.title(p),body:Ce.timeout.body,actions:[m(!0),u(!1)]});case"unsaved":return e.jsx(ds,{login:s,icon:x==="iPad"?"tablet":"phone",tone:"warn",centred:!0,title:Ce.unsaved.title,body:Ce.unsaved.body(p,x),actions:[m(!0),u(!1)]})}}const $s=d.enroll;function ml(t,s="protect"){var M,v,A,T;const n=me(t),a=Fs(),l=(M=n.device)==null?void 0:M.confirm,r=a&&(s==="protect"?l===!1:l===!0&&!((v=n.device)!=null&&v.recover)),[o,i]=f.useState(null),[c,x]=f.useState(null),[u,m]=f.useState(!1),[p,h]=f.useState(null),[g,y]=f.useState(0),k=p?(A=n.ops[p])==null?void 0:A.phase:void 0,S=(s==="protect"?l===!0:((T=n.device)==null?void 0:T.recover)===!0)||k==="applied",b=k==="sending"||k==="uncertain",j=k==="rejected"||k==="failed";f.useEffect(()=>{if(!r||S)return;let R=!0;i(null);const P=t.pcKey();return Promise.all([t.prepareConfirm({purpose:"register"}),P?qm(P):Promise.reject(new Error("unpaired"))]).then(([_,D])=>{R&&i({challenge:_,userId:D})},()=>{R&&x("prepareFailed")}),()=>{R=!1}},[t,r,S,g]);const N=()=>{var D,E;if(!o||u||b)return;const{challenge:R,userId:P}=o;m(!0),x(null);const _=Ur(((D=globalThis.navigator)==null?void 0:D.userAgent)??"",((E=globalThis.navigator)==null?void 0:E.maxTouchPoints)??0);Hm({challenge:R.challenge,rpId:R.rpId},{label:_,id:P}).then(z=>{if(m(!1),z==="cancelled"){x("cancelled");return}if(z==="unsupported"){x("unsupported");return}i(null);const K=t.registerCredential(z,Um(P));K===null?x("failed"):h(K)},()=>{m(!1),x("failed")})},$=()=>{x(null),h(null),y(R=>R+1)},C=c??(j?"failed":null);return{offered:r,registered:S,challenge:(o==null?void 0:o.challenge)??null,asking:u||b,problem:C,go:N,retry:$}}function Ud({e:t,className:s,label:n=$s.go}){const a=t.problem==="failed"||t.problem==="prepareFailed",l=t.problem==="cancelled"?d.confirm.cancelled:t.problem==="unsupported"?$s.unsupported:t.problem==="failed"?d.confirm.failed:t.problem==="prepareFailed"?d.confirm.prepareFailed:null;return e.jsxs(e.Fragment,{children:[l&&e.jsx(Xe,{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 Ah({store:t}){const s=ml(t);return s.registered?e.jsx(pi,{children:$s.done}):s.offered?e.jsx(pi,{children:e.jsx("div",{className:"flex flex-col items-end gap-2",children:e.jsx(Ud,{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 pi({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:$s.row}),e.jsx("dd",{className:"min-w-0 text-right break-words",children:t})]})}function Th({store:t,onDone:s,update:n=!1}){const a=ml(t),[l,r]=f.useState(!1);f.useEffect(()=>{a.offered&&r(!0)},[a.offered]);const o=ne({name:"atoi"});return l?a.registered?e.jsxs(e.Fragment,{children:[e.jsx(Xe,{title:$s.done,role:"status"}),e.jsx("a",{href:o,onClick:s,className:St,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:$s.title}),e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:n?d.passkeyUpdate.stepBody(Js()):$s.body}),e.jsx(Ud,{e:a,className:St,label:n?d.passkeyUpdate.go:$s.go})]}),e.jsx("a",{href:o,onClick:s,className:mt,children:$s.later})]}):e.jsx("a",{href:o,onClick:s,className:St,children:d.compare.seePending})}const jt=d.passkeyUpdate,Wd="ledge.mobile.passkeyUpdateLater",_h=(t,s)=>{try{return!!s&&(t==null?void 0:t.getItem(Wd))===s}catch{return!1}};function Ih({store:t,storage:s=globalThis.localStorage}){var m;const n=ml(t,"update"),a=(m=me(t).device)==null?void 0:m.id,[l,r]=f.useState(()=>_h(s,a)),[o,i]=f.useState(!1);if(f.useEffect(()=>{n.offered&&!l&&i(!0)},[n.offered,l]),!o)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:jt.done}),e.jsx("small",{className:"text-small text-muted",children:jt.doneBody(Js())})]})]});if(l)return null;const c=()=>{try{a&&(s==null||s.setItem(Wd,a))}catch{}r(!0),i(!1)},x=n.problem==="failed"||n.problem==="prepareFailed"||n.problem==="unsupported",u=n.problem==="cancelled"?jt.cancelled:x?jt.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:jt.title})]}),u?e.jsx(Xe,{title:u,tone:n.problem==="cancelled"?"warning":"danger",role:"alert"}):e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:_t()?jt.body(Js()):jt.bodyOther(Js())}),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:St,children:jt.retry}):e.jsx("button",{type:"button",onClick:n.go,disabled:!n.challenge||n.asking,className:St,children:n.asking?e.jsxs(e.Fragment,{children:[e.jsx(Vn,{size:"size-4"}),jt.updating]}):n.challenge?jt.go:d.confirm.preparing}),e.jsx("button",{type:"button",onClick:c,disabled:n.asking,className:mt,children:jt.later})]})]})}const fi=t=>t.problem==="failed"||t.problem==="prepareFailed";function Lh({store:t}){const s=ml(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:jt.row}),e.jsx("dd",{className:"text-right text-ok",children:jt.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:jt.row}),e.jsx("span",{className:"text-small text-muted",children:jt.rowHint})]}),e.jsx("dd",{className:"flex-none",children:e.jsx("button",{type:"button",disabled:s.asking||!fi(s)&&!s.challenge,onClick:fi(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?jt.updating:jt.update})})]}),s.problem&&e.jsx(Xe,{title:s.problem==="cancelled"?jt.cancelled:jt.failed(t.pcName()??d.yourPc),tone:"warning",role:"alert"})]}):null:null}const an={ok:"idle",run:"work",fail:"perm",wait:"ask",skip:"plain",none:"off"},Yn=t=>t.state!=="merged"&&t.state!=="closed",Kd=t=>(t.state==="open"||t.state==="review")&&t.mergeable&&(t.pipeline==="ok"||t.pipeline==="none");function Oh(t){return{open:t.filter(Yn),closed:t.filter(s=>!Yn(s))}}const Dh=t=>t.filter(s=>Yn(s)&&s.pipeline==="fail").length;function Fh(t){const s=t.filter(Yn);return[...s.filter(n=>n.pipeline==="fail").map(n=>({pr:n,why:"fail"})),...s.filter(n=>n.pipeline!=="fail"&&Kd(n)).map(n=>({pr:n,why:"ready"}))]}const zh=t=>t.filter(s=>s.status!=="ok"),Vd=t=>t==="github"?"gh":"glab",Ph=t=>`${Vd(t.forge)} auth login --hostname ${t.host}`;function Gd(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 Xd=t=>t.find(s=>s.status==="fail")??null;function Yd(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 Bh=t=>t.startsWith("…"),qh=new Set(["draft","not_open","approvals","changes_requested","pipeline","pipeline_not_started"]);function pl(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)qh.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 Hh=t=>(t.pr.state==="open"||t.pr.state==="review")&&pl(t).every(s=>s.ok),Qd=t=>`${t.approvals.given}${t.approvals.required!==void 0?`/${t.approvals.required}`:""}`,gr=(t,s)=>{const n=t.replace(/\.$/,"");return s.key==="changes_requested"||s.key==="raw"?n:n.charAt(0).toLowerCase()+n.slice(1)},Uh=t=>t.pipeline==="fail"&&(t.state==="open"||t.state==="review"),Wh=t=>t.files.reduce((s,n)=>({added:s.added+n.added,removed:s.removed+n.removed}),{added:0,removed:0}),Kh=(t,s)=>t.threads.filter(n=>n.file===s).length,xo=t=>t.slice(0,7);function Vh(t,s){if(!t)return null;const n=t.prs.find(r=>Yn(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 hi=new Set(["starting","launching","booting"]);function hs(t){return hi.has(t.status)||hi.has(t.lifecycleState)?"starting":t.status==="partial"?"partial":t.status==="running"||t.running>0?t.nodes.some(n=>n.stopped)?"partial":"running":"stopped"}const Gh=t=>t!=="stopped",Zd=t=>t.rigs.find(s=>s.name===Pn),gi={running:0,partial:0,starting:0,stopped:1},br=t=>t.rigs.filter(s=>s.name!==Pn).map((s,n)=>({r:s,i:n})).sort((s,n)=>gi[hs(s.r)]-gi[hs(n.r)]||s.i-n.i).map(s=>s.r),Jd=(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 eu(t,s,n){var r;let a=0,l=0;for(const o of s)((r=o.rig)==null?void 0:r.name)!==t||!o.pending||(o.pending.kind==="question"?l+=1:a+=1);for(const o of n??[])o.from.rig===t&&o.kind!=="update"&&(l+=1);return{perm:a,ask:l}}const xa=t=>t.activity==="running"||t.work>0;function tu(t,s){if(s.perm)return"perm";if(s.ask)return"ask";const n=hs(t);return n==="stopped"?"off":n==="starting"||t.nodes.some(xa)?"work":"idle"}function mo(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&&xa(n)?"work":a!=null&&a.attention||n!=null&&n.attention?"ask":"idle"}const su={perm:"perm",ask:"ask",work:"work",idle:"idle",off:"off",starting:"work",waiting:"off"},po=t=>t==="claude-code"||t==="claude"?"claude":t==="codex"?"codex":t==="cursor"?"cursor":t==="omp"?"omp":null,ys=(t,s)=>(s==null?void 0:s.split("@")[0])||t.replace(".","-");function Xh(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 Yh(t,s){const n=s.filter(o=>/delegat/.test(o.kind)),a=new Set(n.map(o=>o.from)),l=new Set(n.map(o=>o.to)),r=t.filter(o=>a.has(o.logicalId)&&!l.has(o.logicalId));return r.length===1?r[0].logicalId:null}const Qh=["auto","standard","open","yolo","locked","spec"],nu=/^builtin:(auto|standard|open|yolo|locked)$/;function Zh(t){var s;switch(t.policySource){case"member_policy":return((s=nu.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 au(t){if(t.length===0)return null;const s=t.map(Zh),n=s[0];return n&&s.every(a=>a===n)?n:"mixed"}const Jh=t=>{var s;return((s=nu.exec(t??""))==null?void 0:s[1])??null},lu=t=>[...im(t.nodes)].map(([s,n])=>({role:s,count:n.length,ids:n}));function eg(t,s){return s!=null&&s.some(n=>n.id===t.id)?"mine":t.state==="in-progress"?"progress":t.state==="blocked"?"blocked":"pending"}const tg=t=>t==="done"?"done":t==="handed-off"?"handed":"stopped";function sg(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 Xa(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 fo(t,s){const n=a=>new Date(a.getFullYear(),a.getMonth(),a.getDate()).getTime();return Math.round((n(s)-n(t))/864e5)}const ru=t=>t.startsWith("operator."),ou=t=>ru(t.logicalId)?"Max":ys(t.logicalId,t.session),iu={running:"on",starting:"go",partial:"part",stopped:"plain"},ng=t=>t.daemon.state==="stopped"||t.daemon.state==="stale";function ag(t){return t.rig?t.rig:t.seat?t.seat.split("@")[1]??null:null}function lg(t){return t.kind==="seats"?t.rig??null:t.kind==="act"&&t.action?ag(t.action):null}const cu=t=>[...t].sort((s,n)=>{var a,l;return(((a=Xa(n.createdAt))==null?void 0:a.getTime())??0)-(((l=Xa(s.createdAt))==null?void 0:l.getTime())??0)});function rg(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 og=t=>t.nodes.filter(s=>!s.stopped&&xa(s)).map(s=>ys(s.logicalId,s.session)),ig='a[href], button:not([disabled]), input:not([disabled]), textarea:not([disabled]), select:not([disabled]), [tabindex]:not([tabindex="-1"])';function du(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=o=>{if(o.key==="Escape"){o.preventDefault(),n.current();return}if(o.key!=="Tab")return;const i=[...a.querySelectorAll(ig)],c=i[0],x=i.at(-1);if(!c||!x){o.preventDefault();return}o.shiftKey&&(document.activeElement===c||document.activeElement===a)?(o.preventDefault(),x.focus()):!o.shiftKey&&document.activeElement===x&&(o.preventDefault(),c.focus())};return document.addEventListener("keydown",r),()=>{document.removeEventListener("keydown",r),l!=null&&l.isConnected&&l.focus({preventScroll:!0})}},[t])}function dt({labelledBy:t,onClose:s,children:n}){const a=f.useRef(null);return du(a,s),Jr.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 fl({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 cg={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 vn({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 ${cg[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 jr({lead:t,name:s,chip:n,sub:a,att:l,href:r,dim:o=!1,selected:i=!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 ${o?"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 ${i?"bg-secondary":""}`;return r?e.jsx("a",{href:r,"aria-label":c,"aria-current":i?"page":void 0,className:u,children:x}):e.jsx("div",{className:u,children:x})}function Pl({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:o=!1}){return e.jsxs("div",{role:r,className:`strip flex flex-none gap-[9px] rounded-lg border text-[13px] leading-[18px] ${o?"items-center px-2.5 py-2":"items-start px-3 py-2.5"} ${n?"border-approval/45":s?"border-attention/40":"border-line"}`,children:[t,e.jsx("div",{className:`flex min-w-0 flex-1 flex-col ${o?"":"gap-2"}`,children:a}),l]})}function Se({mark:t,title:s,sub:n,children:a,onClose:l,closeLabel:r}){const o={ok:"✓",bad:"✕",warn:"!",ask:"?"}[t],i={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:i,children:o}),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 Xs({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 ho({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 En=({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 Zn({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(En,{}),e.jsx("span",{className:"min-w-0 flex-1",children:t})]})}function La({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 yr({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 bi({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 ji({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(fl,{on:t,label:s,onChange:a,...l?{disabled:l}:{},...n?{describedBy:r}:{}})]})}function dg({value:t,changed:s,min:n=0,max:a=9,fewer:l,more:r,onChange:o,disabled:i=!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:i||t<=n,onClick:()=>o(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:i||t>=a,onClick:()=>o(t+1),className:c,children:"+"})]})}function cs({title:t,onClose:s,children:n,busy:a=!1}){const l=f.useId();return e.jsxs(dt,{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=Fe({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 Ds({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 ug(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 o=!!n.current;l(),a.current||t(),o&&(a.current=!0)},swallow:()=>{const r=a.current;return a.current=!1,r}}:{}}const Kt=d.prs,xg={ok:"on",run:"go",fail:"bad",wait:"part",skip:"plain",none:"plain"};function uu({pipeline:t,short:s=!1}){return e.jsx(vn,{tone:xg[t],flat:t==="none",children:s?Kt.pipe[t]:Kt.pipeline[t]})}const hl=t=>t.split("/").at(-1)??t,es=t=>({host:Kt.host[t.forge],cli:Vd(t.forge),kind:Kt.kind[t.forge]}),xu=(t,s)=>t.sessions.map(n=>s.get(n)).filter(n=>!!n);function mg(t,s=new Date){const n=new Date(t),a=fo(n,s);return a<=0?Be(t):a===1?Kt.yesterday:a<7?n.toLocaleDateString(lt,{weekday:"long"}):n.toLocaleDateString(lt,{day:"numeric",month:"short"})}function Nr(t,s=new Date){const n=new Date(t),a=Be(t),l=fo(n,s);return l<=0?Kt.today(a):l===1?Kt.yesterdayAt(a):`${n.toLocaleDateString(lt,l<7?{weekday:"long"}:{day:"numeric",month:"short"})} ${a}`}function qn(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 yi({pr:t,sub:s,chips:n,pills:a,href:l,dim:r=!1,selected:o=!1}){const i=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"mt-1.5 self-start",children:e.jsx(Ie,{state:r?"done":an[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 ${o?"bg-secondary":""}`;return l?e.jsx("a",{href:l,"data-pr":t.id,"aria-current":o?"page":void 0,className:c,children:i}):e.jsx("div",{"data-pr":t.id,className:c,children:i})}const ls=d.prs,pg=()=>()=>{},Ni=()=>null;function mu(t){return f.useSyncExternalStore(t?t.subscribe:pg,t?t.getState:Ni,t?t.getState:Ni)}function fg(t,s,n,a){const l=s==="fail"?ls.pipeline.fail:t.pipeline==="none"?ls.atoi.readyNoCi:ls.atoi.ready;return a!==null?[ls.host[t.forge],l,ls.asOf(Be(a))].join(" · "):[ls.host[t.forge],hl(t.repo),l,...s==="fail"&&n?[n]:[]].join(" · ")}function hg({forge:t,mobile:s}){var o;const n=mu(t);if(!((o=s.daemon)!=null&&o.forge)||!(n!=null&&n.state))return null;const a=Fh(n.state.prs);if(a.length===0)return null;const l=!s.fresh,r=i=>{var x;const c=i.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"}),ls.atoi.title,e.jsx("span",{className:"min-w-0 truncate font-normal text-muted",children:ls.atoi.sub})]}),e.jsx(os,{label:ls.atoi.title,children:a.map(({pr:i,why:c})=>e.jsx(Zs,{href:ne({name:"pr",id:i.id}),stale:l,lead:e.jsx(Ie,{state:an[i.pipeline]}),title:e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:i.ref})," ",i.title]}),sub:fg(i,c,r(i),l?n.at:null),children:e.jsx(q,{name:"chevron",className:"size-4 text-muted"})},i.id))})]})}function gg({forge:t,mobile:s,session:n}){var o;const a=mu(t);if(!((o=s.daemon)!=null&&o.forge))return null;const l=Vh((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(Ie,{state:an[l.pr.pipeline],pulse:l.pr.pipeline==="run"}),l.pr.ref]});const r=es({forge:l.kind});return e.jsx(jg,{tip:ls.chipTip(r.host,s.daemon.name,r.kind),label:ls.chipUnknown(r.kind)})}const bg=4e3;function jg({tip:t,label:s}){const n=f.useRef(null),[a,l]=f.useState(null);f.useEffect(()=>{if(!a)return;const o=setTimeout(()=>l(null),bg),i=c=>{var x;(x=n.current)!=null&&x.contains(c.target)||l(null)};return document.addEventListener("pointerdown",i,!0),()=>{clearTimeout(o),document.removeEventListener("pointerdown",i,!0)}},[a]);const r=()=>{var x,u;if(a){l(null);return}const o=(x=n.current)==null?void 0:x.closest("footer"),i=(u=(o==null?void 0:o.previousElementSibling)??o)==null?void 0:u.getBoundingClientRect(),c=globalThis.innerHeight??0;l({bottom:i?Math.max(c-i.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 yg(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 Ng=["atoi","done","ongoing","rigs"],vg={perm:"bg-approval",ask:"bg-attention",work:"bg-info",idle:"bg-ok",off:"bg-muted/70"},pu="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",vi="border-approval/45 text-approval",kg=t=>t.replace(/\*\*/g,""),Hn=t=>new Date(t).toLocaleTimeString(lt,{hour:"2-digit",minute:"2-digit",hourCycle:"h23"});function ki(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 fu({tone:t,faded:s}){return e.jsx("span",{"aria-hidden":"true",className:`mt-[7px] size-2 rounded-full ${vg[t]} ${s?"opacity-50":""}`})}function wg(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(Hn(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} · ${Hn(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:Hn(t.turn.askedAt)})]}),e.jsx("div",{children:Ng.map(l=>{const r=n.items.filter(o=>o.group===l);return r.length?l==="ongoing"?e.jsxs("div",{"data-point-group":l,className:pu,children:[e.jsx(fu,{tone:"work"}),e.jsx("span",{className:"min-w-0",children:s.ongoing(r.length)})]},l):r.map(o=>e.jsx(Sg,{item:o,...t},o.id)):null})})]})}function Sg(t){var y,k;const s=d.chat.operator,n=d.chat.action,{item:a}=t,[l,r]=f.useState(!1),[o,i]=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=o.trim();S&&(t.onAnswer(a.id,{text:S}),r(!1),i(""))},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:Fe({variant:b.style==="primary"?"primary":"outline",size:"xs",className:b.style==="danger"?vi:""}),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:Fe({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:Fe({size:"xs",className:p.risk==="destructive"?vi:""}),children:b?n.running:ki(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:pu,children:[e.jsx(fu,{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}):kg(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],Hn(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:["✓ ",ki(p)," · ",n.done(p.doneAt?Hn(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&&((k=t.note)==null?void 0:k.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:o,disabled:c,onChange:S=>i(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),i("")},className:Fe({variant:"ghost",className:"h-8 px-2.5"}),children:s.answer.cancel}),e.jsx("button",{type:"button",disabled:c||!o.trim(),onClick:h,className:Fe({variant:"primary",size:"xs"}),children:s.answer.send})]})]})}function $g(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 Cg({store:t,turn:s,readOnly:n}){const a=me(t).fresh,[l,r]=f.useState(null),[o,i]=f.useState(null),c=(x,u)=>{r(x),i(null);const m=p=>{r(null);const h=$g(p);i(h?{item:x,text:h}:null)};t.pointAct(s.qid,x,u).then(m,()=>m({status:"failed"}))};return e.jsx(wg,{turn:s,busy:l,note:o,disabled:n||!a,onAnswer:c,onSuggestion:x=>c(x,"suggest")})}function hu(t){const s=Pc(t),n=me(t).fresh,a=yg(s.turns),l=a==null?void 0:a.eventId;f.useEffect(()=>{l!==void 0&&n&&t.operatorRead(l)},[l,n,t])}const Be=t=>t?new Date(t).toLocaleTimeString(lt,{hour:"2-digit",minute:"2-digit"}):"",gu=t=>`${t.sessionId}/${t.key}`;function Mg(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 bu({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(Ie,{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 Eg({sessions:t,threshold:s,now:n,stale:a}){const l=t.slice(0,Aa),r=t.length-l.length;return e.jsxs(os,{label:d.atoi.working,children:[l.map(o=>{const i=ul(o,n,s).context;return e.jsx(Zs,{href:ne({name:"thread",sessionId:o.id}),stale:a,lead:e.jsxs(e.Fragment,{children:[e.jsx(Ie,{state:"work",pulse:!a}),e.jsx(gs,{tool:o.tool})]}),title:e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:o.name}),o.rig&&e.jsxs("span",{className:"text-small text-muted",children:[" ",o.rig.name]})]}),sub:Xr(o),...i?{meta:`${i.pct} %`,metaWarn:i.near}:{}},o.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 Rg({store:t,onReconnect:s,forge:n}){var X,te,pe,ue;const a=me(t),l=It(),r=Fs(),o=Xt();hu(t);const[i,c]=f.useState("all"),[x,u]=f.useState(new Set),m=[...a.sessions.values()],p=Vt(m),h=od(a.asks??[]),g=Od(a.tasks.values()),y=a.fresh,k=((X=a.device)==null?void 0:X.confirm)===!0&&r,S=r&&((te=a.device)==null?void 0:te.confirm)!==!0,b=((pe=a.daemon)==null?void 0:pe.name)??"",j=((ue=a.device)==null?void 0:ue.contextNear)??kn,N=p.length+h.length+g.length,$=N>=zp,C=$?i:"all",M=C==="rigs"?[]:Cl(p,C),v=C==="all"||C==="rigs"?h:[],A=hr(M.map(F=>({id:gu(F),value:F}))),T=hr(v.map(F=>({id:F.id,value:F}))),R=A.entries.filter(F=>{var V,ee;if(!F.ghost||!y)return!1;const w=a.sessions.get(F.value.sessionId),I=(V=w==null?void 0:w.pending)==null?void 0:V.key;return!I||I===F.value.key||((ee=w==null?void 0:w.lastAnswer)==null?void 0:ee.key)===F.value.key?!1:Gn(F.value,m,a.ops).kind==="handledElsewhere"}),P=R.map(F=>F.id).join("|");f.useEffect(()=>{if(R.length){u(F=>{var I,V;const w=new Set(F);for(const ee of R){const Q=(V=(I=a.sessions.get(ee.value.sessionId))==null?void 0:I.pending)==null?void 0:V.key;Q&&w.add(`${ee.value.sessionId}/${Q}`)}return w});for(const F of R)A.dismiss(F.id)}},[P]);const _=new Set(R.map(F=>F.id)),D=F=>u(w=>{const I=new Set(w);return I.delete(F),I}),E=new Set(p.map(F=>F.sessionId)),z=Fp(m,E),K=C!=="permission"&&C!=="question"&&Mg(a,h),L=N===0,W=!y,ae=W?a.syncedAt?d.link.lastKnownAt(Be(a.syncedAt)):d.inbox.lastKnown:N?d.atoi.count(N):void 0,U=$&&e.jsx(Mp,{label:d.inbox.filtersLabel,value:C,onChange:c,options:[{value:"all",label:d.inbox.filters.all,count:N},{value:"permission",label:d.inbox.filters.permission,count:Cl(p,"permission").length},{value:"question",label:d.inbox.filters.question,count:Cl(p,"question").length},{value:"rigs",label:d.atoi.rigs,count:h.length}]}),O=L&&e.jsx(os,{label:d.atoi.noRequest,children:e.jsx(Jt,{framed:!1,glyph:e.jsx(bs,{size:96,frozen:W}),title:d.atoi.noRequest,list:z.length===0,body:z.length?d.atoi.calmHint:d.atoi.nothingRunning,...z.length?{}:{action:e.jsxs("a",{href:ne({name:"sessions"}),className:Fe({size:"sm"}),children:[d.atoi.seeSessions,e.jsx(q,{name:"chevron",className:"size-4"})]})}})}),B=!L&&M.length===0&&v.length===0&&!(C==="all"&&g.length>0)&&e.jsx(Jt,{glyph:e.jsx(q,{name:"inbox"}),title:d.inbox.emptyFilter,body:d.inbox.emptyFilterHint}),Z=e.jsx("div",{className:"flex flex-col gap-3 empty:hidden",children:e.jsx(Ih,{store:t})}),H=C==="all"&&g.map(F=>e.jsx(yh,{store:t,task:F,state:a,canConfirm:k},F.id));return l?e.jsx(Ag,{update:Z,state:a,items:M,asks:K?v:[],working:z,showRigs:K,chipBar:U,empty:O||B,subtitle:ae,threshold:j,now:o,machine:b,routines:H}):e.jsxs(Rs,{title:d.inbox.title,subtitle:ae,offlinePill:!1,children:[Z,U,O,B,A.entries.filter(F=>!_.has(F.id)).map(F=>{var V;const w=F.value,I=a.sessions.get(w.sessionId);return e.jsx(io,{store:t,item:w,session:I,mode:Qr(w,(V=a.capabilities)==null?void 0:V[w.tool],(I==null?void 0:I.readOnly)===!0),outcome:Gn(w,m,a.ops),fresh:y,ghost:F.ghost,changed:x.has(F.id),onReread:()=>D(F.id),canConfirm:k,enroll:S,onGone:()=>A.dismiss(F.id),onCheck:s},F.id)}),H,K&&e.jsxs(e.Fragment,{children:[e.jsxs("h2",{className:"mt-1 flex items-center gap-2 text-[13px] font-semibold",children:[e.jsx(Ie,{state:"rig"}),d.atoi.rigs,e.jsx("span",{className:"font-normal text-muted",children:h.length})]}),e.jsx(bu,{state:a,machine:b}),T.entries.map(F=>e.jsx(qd,{store:t,ask:F.value,end:dd(F.id,a.ops),fresh:y,ghost:F.ghost,canConfirm:k,enroll:S,onGone:()=>T.dismiss(F.id)},F.id))]}),z.length>0&&C==="all"&&e.jsxs(e.Fragment,{children:[e.jsx("h2",{className:"mt-1 text-[13px] font-semibold",children:d.atoi.working}),e.jsx(Eg,{sessions:z,threshold:j,now:o,stale:W})]}),C==="all"&&e.jsx(hg,{forge:n,mobile:a}),W&&e.jsx("p",{className:"text-small text-muted",children:d.inbox.offlineNote})]})}function Ag({update:t,state:s,items:n,asks:a,working:l,showRigs:r,chipBar:o,empty:i,subtitle:c,threshold:x,now:u,machine:m,routines:p}){const h=na(),g=!s.fresh;return e.jsxs(Rs,{title:d.inbox.title,subtitle:c,wideSubtitle:c,offlinePill:!1,children:[t,o,i,n.length>0&&e.jsx(os,{title:d.atoi.requests,dot:"perm",count:n.length,children:n.map(y=>e.jsx(Zs,{href:ne({name:"request",sessionId:y.sessionId,key:y.key}),stale:g,selected:h.name==="request"&&h.sessionId===y.sessionId,lead:e.jsx(gs,{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:rr(y.kind==="permission"?y.body??y.text:wn(y)),meta:yn(y.since,u)},gu(y)))}),p,r&&e.jsxs(os,{title:d.atoi.rigs,dot:"rig",count:a.length,tone:"rigs",children:[e.jsx("div",{className:"p-2 empty:hidden",children:e.jsx(bu,{state:s,machine:m})}),a.map(y=>{const k=cd(y);return e.jsx(Zs,{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:k.name}),y.from.rig?` · ${y.from.rig}`:""]}),sub:y.summary,meta:Be(y.updatedAt),children:e.jsx("span",{className:"sr-only",children:d.asks.pill[id(y)]})},y.id)})]}),l.length>0&&e.jsxs(os,{title:d.atoi.working,dot:"work",count:l.length,children:[l.slice(0,Aa).map(y=>{const k=ul(y,u,x).context;return e.jsx(Zs,{href:ne({name:"thread",sessionId:y.id}),stale:g,lead:e.jsx(gs,{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:Xr(y),...k?{meta:`${k.pct} %`,metaWarn:k.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 Oa({store:t,title:s,body:n,item:a,final:l=!1,children:r}){const o=Mn(me(t)),i=ne({name:"atoi"}),c={name:"atoi"};return e.jsxs(e.Fragment,{children:[e.jsx(oa,{title:d.result.header,fallback:c,label:d.detail.back,link:o}),e.jsx("main",{className:"min-h-0 flex-1 overflow-y-auto pb-[22px]",children:e.jsxs("div",{className:"flex flex-col items-start gap-4 pt-7",children:[e.jsx("div",{className:"grid size-14 place-items-center rounded-full border border-ok/20 bg-ok/10 text-ok",children:e.jsx(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(ol,{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(Xe,{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:i,className:Pe({variant:"primary",block:!0}),children:d.result.back}),a&&e.jsx("a",{href:ne({name:"thread",sessionId:a.sessionId}),className:Pe({block:!0}),children:d.result.thread(a.botName)})]})})]})}const Tg=Pe({variant:"primary",block:!0});function _g({store:t,stale:s=!1,item:n,panel:a}){var g,y,k,S;const l=me(t),r=Mn(l),o=n==null?void 0:n.sessionId,i=o!==void 0&&l.threads.has(o),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&&o!==void 0&&!i&&t.openThread(o)},[s,x,o,i,t]);const u=ne({name:"atoi"}),m={name:"atoi"};if(s)return e.jsxs(e.Fragment,{children:[a?a.header:e.jsx(oa,{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 ${Tg}`,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(Oa,{store:t,title:d.gone.titleOn(b),body:c.decision?d.gone.decided(c.decision,Be(c.at)):d.gone.answered(Be(c.at)),item:n})}const p=n&&n.kind==="permission"?[...((k=l.threads.get(n.sessionId))==null?void 0:k.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(Oa,{store:t,title:d.gone.titleElsewhere,body:d.gone.body,item:n});const h=Ed(p,n.sessionId,l.ops,((S=l.device)==null?void 0:S.id)??null);return e.jsx(Oa,{store:t,title:d.gone.titleOn(h),body:d.gone.decided(p.decision,Be(p.at)),item:n})}function Ig({options:t,value:s,onChange:n,disabled:a=!1,botName:l,other:r,onSubmit:o}){const i=t.length,c=t.length===0,x=r!==void 0&&(c||s===i),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:i,checked:x,onChange:()=>n(i),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(),o==null||o())},className:"max-h-[120px] min-h-12 w-full min-w-0 resize-y rounded-control border border-line bg-surface p-3 text-base leading-[22px] text-fg placeholder:text-muted focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-info"}),u&&e.jsx("p",{id:"other-problem",role:"alert",className:"mt-2 text-small text-danger-fg",children:r.problem==="long"?d.question.long(Yr):r.problem==="digit"?d.question.digit:d.question.untypable})]})]})]})}const Lg="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 Og({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(o=>{var i;return e.jsxs("label",{className:Lg,children:[e.jsx("input",{type:l.multi?"checkbox":"radio",name:`question-${r}`,checked:((i=s[r])==null?void 0:i.includes(o.label))===!0,onChange:()=>n(r,o.label),className:"size-4 flex-none accent-fg"}),e.jsxs("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:[o.label,o.description&&e.jsx("small",{className:"mt-0.5 block text-meta text-muted",children:o.description})]})]},o.label)})]},l.id))})}function Dg({onReconnect:t}){const[s,n]=Cn();return e.jsxs(Xe,{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:Pe({block:!0,className:"mt-3"}),children:s?d.link.reconnecting:d.link.reconnect})]})}const Fg=t=>t.decision==="deny"?d.result.denied:t.answer!==void 0?d.result.answered:d.result.allowed;function zg({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:Tt({}),children:e.jsx(q,{name:"close"})})]})})}const Pg="(orientation: landscape) and (max-height: 500px)",wi=["wheel","touchstart","keydown","pointerdown"];function vr({store:t,sessionId:s,requestKey:n,onReconnect:a,panel:l,onSettled:r,keys:o=!1}){var ze,ht,Nt,we,G,Ne;const i=me(t),c=Xt(),{fresh:x,ops:u,capabilities:m}=i,p=jd(),{look:h}=Ut(),g=p!==void 0&&h==="offline",[y,k]=f.useState(n),[S,b]=f.useState(!1),[j,N]=f.useState(null),[$,C]=f.useState(""),[M,v]=f.useState(null),[A,T]=f.useState({sig:"",v:[]}),R=Fs(),[P,_]=f.useState(!1),D=f.useRef(y);D.current=y,f.useEffect(()=>{n!==D.current&&(k(n),b(!1),N(null),C(""),v(null),_(!1))},[n]);const E=[...i.sessions.values()],z=Vt(E).find(oe=>oe.sessionId===s&&oe.key===y),K=f.useRef(void 0);z&&(K.current=z);const L=Gn({sessionId:s,key:y},E,u),W=(z==null?void 0:z.cut)===!0;f.useEffect(()=>{W&&x&&t.loadPending(s)},[t,s,y,W,x]);const ae=(ht=(ze=i.sessions.get(s))==null?void 0:ze.pending)==null?void 0:ht.key;f.useEffect(()=>{var oe;if(!(L.kind!=="changed"||!ae)){k(ae),b(!0),N(null),C(""),v(null);try{(oe=globalThis.history)==null||oe.replaceState(globalThis.history.state,"",ne(l?{name:"atelier",sessionId:s,requestKey:ae}:{name:"request",sessionId:s,key:ae}))}catch{}}},[L.kind,ae,s]);const U=Mn(i),O={name:"atoi"},B=L.kind==="applied"||z===void 0&&!(L.kind==="sending"||L.kind==="uncertain"||L.kind==="rejected"||L.kind==="failed"||L.kind==="changed")&&x,Z=l==null?void 0:l.onBack;f.useEffect(()=>{B&&Z&&Z()},[B,Z]);const H=f.useRef(r);H.current=r,f.useEffect(()=>{if(!B||!H.current)return;const oe=setTimeout(()=>{var qe;return(qe=H.current)==null?void 0:qe.call(H)},ud);return()=>clearTimeout(oe)},[B]);const[X,te]=f.useState(null),[pe,ue]=f.useState(null);f.useLayoutEffect(()=>{var ln,An;const oe=X,qe=pe,st=(ln=globalThis.matchMedia)==null?void 0:ln.call(globalThis,Pg);if(!oe||!qe||!st)return;let $t=!1;const ts=()=>{if($t||!st.matches)return;const ot=qe.firstElementChild??qe,rn=oe.getBoundingClientRect(),on=ot.getBoundingClientRect(),Tn=on.top-rn.top+oe.scrollTop,_n=parseFloat(getComputedStyle(oe).paddingBottom)||0;oe.scrollTop=on.height>oe.clientHeight-_n?Tn:Math.max(0,Tn+on.height-(oe.clientHeight-_n))},Ps=()=>{st.matches&&($t=!1,ts())},Ns=()=>{$t=!0};ts();const Wt=typeof ResizeObserver=="function"?new ResizeObserver(ts):null;Wt==null||Wt.observe(oe),Wt==null||Wt.observe(qe),(An=st.addEventListener)==null||An.call(st,"change",Ps);for(const ot of wi)oe.addEventListener(ot,Ns,{passive:!0});return()=>{var ot;Wt==null||Wt.disconnect(),(ot=st.removeEventListener)==null||ot.call(st,"change",Ps);for(const rn of wi)oe.removeEventListener(rn,Ns)}},[y,X,pe]);const F=oe=>l?e.jsx(zg,{title:oe,panel:l}):e.jsx(oa,{title:oe,fallback:O,label:d.detail.back,link:U});if(L.kind==="applied")return e.jsx(Oa,{store:t,title:Fg(L),body:d.result.body,item:K.current,final:!0});const w=L.kind==="sending"||L.kind==="uncertain"||L.kind==="rejected"||L.kind==="failed"||L.kind==="changed",I=z??(w?K.current:void 0);if(!I)return!x&&i.syncedAt===null?e.jsxs(e.Fragment,{children:[F(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(_g,{store:t,stale:!x,item:K.current,...l?{panel:{header:F(d.gone.header),back:{href:ne({name:"atelier",sessionId:s}),label:d.nav.backTo.thread}}}:{}});const V=I.kind==="question",ee=I.options??[],Q=m==null?void 0:m[I.tool],J=V&&(Q==null?void 0:Q.freeTextAnswer)===!0,fe=V&&(Q==null?void 0:Q.questions)===!0&&I.requestId!==void 0&&((Nt=I.questions)!=null&&Nt.length)?I.questions:void 0,be=!fe&&(Q==null?void 0:Q.decide)===!1&&ee.length>0,tt=!fe&&!be&&V&&(ee.length>0||J),yt=((we=i.device)==null?void 0:we.confirm)===!0&&R,Ze=I.risk!=="low",Le=JSON.stringify((fe??[]).map(oe=>[oe.id,oe.options.map(qe=>qe.label)])),de=A.sig===Le?A.v:[],he=(fe??[]).filter((oe,qe)=>{var st;return!((st=de[qe])!=null&&st.length)}).length,$e=(oe,qe)=>{const st=fe==null?void 0:fe[oe];if(!st)return;const $t=(fe??[]).map((Ps,Ns)=>de[Ns]??[]),ts=$t[oe]??[];$t[oe]=st.multi?ts.includes(qe)?ts.filter(Ps=>Ps!==qe):[...ts,qe]:[qe],T({sig:Le,v:$t}),_(!1)},Oe={key:I.key,kind:I.kind,text:I.text},rt=oe=>{if(!fe||I.requestId===void 0)return;const qe=oe?[]:fe.map((st,$t)=>({id:st.id,selected:de[$t]??[]}));_(!t.answer(s,I.requestId,qe,{expect:Oe,...oe?{cancel:!0}:{}}))},Ge=x&&!S&&z!==void 0&&L.kind!=="sending"&&L.kind!=="uncertain"&&(yt||!Ze),pt=oe=>{Ze?(v(oe),_(!1)):_(!t.reply(s,String(oe+1),{expect:Oe}))},ft=e.jsx("ul",{"aria-label":d.answers.legend,className:"my-3.5 flex list-none flex-col gap-2 p-0",children:ee.map((oe,qe)=>{var st;return e.jsx("li",{children:e.jsxs("button",{type:"button",disabled:!Ge,"aria-pressed":M===qe,onClick:()=>pt(qe),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:[oe,((st=I.optionDetails)==null?void 0:st[qe])&&e.jsx("small",{className:"mt-0.5 text-meta text-muted",children:I.optionDetails[qe]})]})},`${qe}:${oe}`)})}),ut=rd($),Y=J&&(ee.length===0||j===ee.length),Re=V?null:ld(I),ke=Ip(I),ie=(i.previews.get(s)??[]).slice(-12),Ae=L.kind==="sending"||L.kind==="uncertain",Je=()=>{Y?ut.problem===null&&_(!t.reply(s,ut.text,{expect:Oe})):j!==null&&j<ee.length&&_(!t.reply(s,String(j+1),{expect:Oe}))},xt=ne(l?{name:"atelier",sessionId:s}:{name:"thread",sessionId:s}),Yt=o&&!l&&e.jsx(la,{back:e.jsx("span",{className:"w-2.5"}),tool:I.tool,name:I.botName,dot:I.kind==="permission"?"perm":I.kind==="question"?"ask":"work",sub:[I.repo,I.branch].filter(Boolean).join(" · "),more:e.jsxs(e.Fragment,{children:[I.risk==="high"?e.jsx(zt,{tone:"risk",children:d.risk.badge}):e.jsx(zt,{tone:I.kind==="question"?"ask":I.kind==="permission"?"perm":"plain",children:d.atoi.pill[I.kind]}),e.jsxs("a",{href:xt,className:Fe({size:"sm",className:"ml-1"}),children:[e.jsx(q,{name:"terminal",className:"size-4"}),d.atoi.openThread]})]})});return e.jsxs(e.Fragment,{children:[Yt||F(d.detail.heading[I.kind]),e.jsxs("main",{ref:te,className:"min-h-0 flex-1 overflow-y-auto overscroll-contain pb-[22px]",children:[!Yt&&e.jsxs("div",{className:"mt-4 flex items-start gap-3 rounded-card border border-line bg-surface p-3.5",children:[e.jsx(ol,{tool:I.tool,seed:I.sessionId,state:((G=i.sessions.get(s))==null?void 0:G.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:I.task}),e.jsxs("p",{className:"mt-0.5 text-meta text-muted",children:[I.botName," · ",d.tools[I.tool]]}),e.jsxs("p",{className:"mt-0.5 text-meta [overflow-wrap:anywhere] text-muted",children:[I.repo,I.branch&&e.jsxs(e.Fragment,{children:[" · ",e.jsx("code",{className:`font-mono text-[.9em] ${I.worktree?"underline decoration-dotted underline-offset-2":""}`,children:I.branch})]})]})]})]}),e.jsxs("div",{className:"mt-[22px] mb-3",children:[e.jsx(Hp,{kind:I.kind,risk:I.risk}),e.jsx("h1",{className:`mt-2.5 text-display leading-[1.25] font-semibold tracking-[-1px] [overflow-wrap:anywhere] ${I.kind==="permission"?"phone-side:hidden":""}`,children:I.kind==="permission"?d.detail.commandTitle:wn(I)})]}),V?e.jsxs(e.Fragment,{children:[fe&&e.jsx(Og,{questions:fe,selected:de,onToggle:$e,disabled:Ae}),be&&ft,tt&&e.jsx(Ig,{options:ee,value:j,onChange:oe=>{N(oe),_(!1)},botName:I.botName,disabled:Ae,other:J?{text:$,onText:oe=>{C(oe),_(!1)},problem:ut.problem}:void 0,onSubmit:x&&!S&&!Ae&&z!==void 0?Je:void 0}),!J&&!be&&!fe&&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:ue,children:e.jsx(Up,{text:I.body??I.text})}),be&&ft,!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(oe=>e.jsx("li",{className:"rounded-control border border-line bg-surface px-3 py-3 text-body [overflow-wrap:anywhere]",children:oe},oe))}),Re&&e.jsx(Xe,{title:Re.title,tone:"danger",children:e.jsx("p",{children:Re.body})}),ke&&e.jsx(Xe,{title:ke.title,children:e.jsx("p",{className:"text-muted",children:ke.body})}),e.jsxs("dl",{className:"my-[18px] grid grid-cols-[74px_minmax(0,1fr)] gap-x-3 gap-y-2.5 text-small",children:[I.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:I.branch})})]}),(Re==null?void 0:Re.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:Re.destination})})]}),e.jsx("dt",{className:"text-muted",children:d.detail.asked}),e.jsx("dd",{className:"m-0",children:d.detail.ago(yn(I.since,c))})]}),ie.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:ie.join(`
13
+ `)})]})]}),!x&&!g&&L.kind!=="uncertain"&&e.jsx("div",{className:"mt-4",children:e.jsx(Dg,{onReconnect:a})})]}),e.jsx(Cf,{item:I,outcome:L,fresh:x,changed:S,stillPending:z!==void 0,threadHref:xt,withThread:!Yt,onReread:()=>{b(!1),N(null),v(null),_(!1)},onDecide:oe=>_(!t.decide(s,oe,{expect:Oe})),answerable:tt,choice:Y?ee.length:j,onAnswer:Je,answerBlocked:Y?ut.problem!==null:j===null||j>=ee.length,onCheck:a,refused:P,store:t,deviceConfirm:((Ne=i.device)==null?void 0:Ne.confirm)===!0,optionReply:be?{canConfirm:Ze?yt:!0,picked:Ze?M:null,onBack:()=>v(null),onReply:(oe,qe)=>M===null?null:t.reply(s,String(M+1),{assertion:oe,expect:qe})}:void 0,multi:fe?{missing:he,onSend:()=>rt(!1),onCancel:()=>rt(!0)}:void 0,keys:o})]})}const Bg=/^#{1,6}\s+(.+?)\s*#*\s*$/,qg=/^(?:\*\*|__)([^*_].*?)(?:\*\*|__)\s*:?\s*$/,Hg=/^(\s*)(?:[-*+]|\d+[.)])\s+(.*)$/,Ug=/^\s*\d+[.)]\s/,Wg=/^\[([ xX])\]\s+/,Kg=/^\s*([-*_])(\s*\1){2,}\s*$/,Vg=/^\s*(```|~~~)/,Gg=/^\s*\|?\s*:?-+:?\s*(\|\s*:?-+:?\s*)*\|?\s*$/,kr=new RegExp("(?<!\\\\)\\|"),Bl=/^\s*>\s?(.*)$/,Xg=t=>t.startsWith(":")&&t.endsWith(":")?"center":t.endsWith(":")?"right":"left",ja=t=>t.trim().replace(/^\|/,"").replace(new RegExp("(?<!\\\\)\\|$"),"").split(kr).map(s=>s.trim().replace(/\\\|/g,"|")),Yg=80,Qg=t=>t.toLowerCase().normalize("NFD").replace(/[̀-ͯ]/g,""),Zg=[["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 Jg(t){var n;const s=Qg(t).replace(/[’']/g,"'");return((n=Zg.find(([,a])=>a.test(s)))==null?void 0:n[0])??"other"}function ju(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=[])},o=()=>{l&&(n.push({type:"list",ordered:l.ordered,items:l.items}),l=null)};for(let i=0;i<s.length;i++){const c=s[i],x=c.match(Vg);if(x){r(),o();const g=[];for(i++;i<s.length&&!s[i].trim().startsWith(x[1]);i++)g.push(s[i]);n.push({type:"code",text:g.join(`
16
+ `).replace(/\s+$/,"")});continue}const u=s[i+1];if(kr.test(c)&&u!==void 0&&Gg.test(u)){const g=ja(c);if(ja(u).length===g.length){r(),o();const y=[];for(i+=2;i<s.length&&s[i].trim()!==""&&kr.test(s[i]);i++)y.push(Array.from({length:g.length},(k,S)=>ja(s[i])[S]??""));i--,n.push({type:"table",header:g,rows:y,align:ja(u).map(Xg)});continue}}const m=c.match(Bl);if(m){r(),o();const g=[m[1]];for(;i+1<s.length&&Bl.test(s[i+1]);i++)g.push(s[i+1].match(Bl)[1]);n.push({type:"quote",blocks:ju(g.join(`
17
+ `)).map(y=>y.type==="h"?{type:"p",text:y.text}:y)});continue}if(c.trim()===""){r();continue}if(Kg.test(c)){r(),o();continue}const p=c.match(Bg)??c.match(qg);if(p){r(),o(),n.push({type:"h",text:p[1].trim().replace(/\s*:\s*$/,"")});continue}const h=c.match(Hg);if(h){r();const g=h[1].length,y=h[2];if(l&&g>l.indent&&l.items.length){l.items[l.items.length-1].sub.push(y.trim());continue}const k=Ug.test(c);(!l||g<l.indent||l.ordered!==k)&&(o(),l={ordered:k,items:[],indent:g});const S=y.match(Wg);l.items.push({text:(S?y.slice(S[0].length):y).trim(),sub:[],...S?{checked:S[1]!==" "}:{}});continue}if(l&&/^\s+\S/.test(c)&&a.length===0){const g=l.items[l.items.length-1];g.text=`${g.text} ${c.trim()}`;continue}o(),a.push(c.trim())}return r(),o(),n}const Ya=t=>/[??]\s*$/.test(t);function wr(t){const s=t.replace(/\s*[??]\s*$/,"").match(/(?:^|[:;]\s*)([^:;?]*?)\s+(?:or|ou)\s+([^,:;?]{2,60})$/i);if(!s)return[];const n=[...s[1].split(/\s*,\s*/),s[2]].map(r=>r.trim()).filter(Boolean),a=r=>{var o,i,c;return(((o=r.match(/\(/g))==null?void 0:o.length)??0)===(((i=r.match(/\)/g))==null?void 0:i.length)??0)&&(((c=r.match(/`/g))==null?void 0:c.length)??0)%2===0},l=r=>r.length>=2&&r.length<=60&&r.split(/\s+/).length<=8&&!/[.!]\s/.test(r)&&a(r);return n.length>=2&&n.length<=6&&n.every(l)?n:[]}const Si=t=>t.replace(/\[([^\]]+)\]\([^)]*\)/g,"$1").replace(/`([^`]+)`/g,"$1").replace(/(\*\*|__)(.+?)\1/g,"$2").replace(new RegExp("(?<![\\w*])\\*([^*\\n]+)\\*(?![\\w*])","g"),"$1").trim(),Fn=/\s*[★⭐]\s*/g,yu=/^(.+?)\s*\(([^()]*(?:\([^()]*\)[^()]*)*)\)\s*$/,Os=(t,s)=>{const n=Fn.test(t)||Fn.test(s);return{label:Si(t.replace(Fn," ")),detail:Si(s.replace(Fn," ")),...n?{star:n}:{}}},en=/^(\*\*|__)(\S(?:.*?\S)?)\1\s*(?:[—–:-]\s*)?(.*)$/,$i=/^(.+?)(\s+[—–-]\s+|:\s+)(.+)$/,go=(t,s=!1)=>t.every(n=>n.label.length>0&&n.label.length<=Yg&&!Ya(n.label)&&(s||!Ya(n.detail)));function Ci(t){if(t.length<2||t.length>6)return null;const s=t.map(l=>{var r;return en.test(l)?null:((r=l.match($i))==null?void 0:r[2].trim()[0])??null}),n=s.every(l=>l!==null&&l===s[0]),a=t.map(l=>{const r=l.match(en);if(r)return Os(r[2],r[3]);const o=n?l.match($i):null;return o?Os(o[1],o[3]):Os(l,"")});return go(a)?a:null}const eb=/(^|[\s(:,;])([a-h])\)\s+/g;function Mi(t){const s=[];for(const r of t.matchAll(eb))r[2].charCodeAt(0)-97===s.length&&s.push({at:r.index+r[1].length,end:r.index+r[0].length});if(s.length<2||s.length>8)return null;const n=t.slice(0,s[0].at).trim().replace(/\s*[:—–-]\s*$/,"").trim();if(!n)return null;const a=s.map((r,o)=>{var i;return t.slice(r.end,(i=s[o+1])==null?void 0:i.at)});a[a.length-1]=a[a.length-1].split(new RegExp("(?<=[.!??])\\s+(?=\\p{Lu})","u"))[0];const l=a.map(r=>{const o=r.trim().replace(/[\s,;.??]+$/,""),i=/[★⭐]/.test(o),c=o.replace(Fn," ").trim().match(yu),x=c?Os(c[1],c[2]):Os(o,"");return i?{...x,star:i}:x});return go(l,!0)?{stem:n,options:l}:null}const tb=/^(\*\*|__)(.+?[??])\s*\1/,Ei=t=>{var s;return Ya(t)?t:((s=t.match(tb))==null?void 0:s[2])??null},Ri=/(^|[^\p{L}])(laquelle|lequel|lesquel|quelle (option|approche|solution)|quel choix|which|pr[ée]f[ée]r|prefer|choisi|choos|pick|reten|retien)/iu,sb=/^(\d+)[.)]\s+(.+)$/,nb=/^(\*\*|__)(\d+)[.)]\s+(.+?)\1\s*(.*)$/,ab=t=>t.length>160?t.split(new RegExp("(?<=[.!])\\s+(?=\\p{Lu}|\\()","u"))[0]:t;function ql(t,s,n){var r;t=t.trim().replace(/\.$/,"");const a=t.match(yu);let l=ab(s.trim()).replace(/^\((.*)\)\.?$/,"$1").replace(/^[—–:-]\s*/,"")||(a?a[2]:"");return!l&&n&&(l=n.type==="p"?n.text:n.type==="list"?((r=n.items[0])==null?void 0:r.text)??"":""),Os(a?a[1]:t,l)}const lb=/recommand|recommend/i;function Nu(t,s,n=[]){const a=t.toLowerCase(),l=u=>{const m=Math.min(...u);return m<1/0?u.indexOf(m):-1},r=u=>{const m=u.length>=2?a.search(new RegExp(`(^|[^\\p{L}])${u.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}($|[^\\p{L}])`,"u")):-1;return m<0?1/0:m},o=s.map(u=>u.label.toLowerCase().split(/\s+/)[0]),i=l(s.map((u,m)=>Math.min(r(u.label.toLowerCase()),o[m].length>=4&&o.filter(p=>p===o[m]).length===1?r(o[m]):1/0)));if(i>=0)return i;const c=a.match(/\boption\s+(\d+)/);return c&&Number(c[1])>=1&&Number(c[1])<=s.length?Number(c[1])-1:n.findIndex(u=>u&&new RegExp(`(^|[\\s:])${u}([.\\s,]|$)`).test(t))}const vu=(t,s)=>s<0||t.some(n=>n.star)?t:t.map((n,a)=>a===s?{...n,star:!0}:n);function rb(t){if(!/^(\*\*|__)[^*_]+\1:?$/.test(t.text.trim()))return null;const s=t.sub.find(i=>lb.test(i.slice(0,40)));if(!s)return null;const n=t.sub.filter(i=>i!==s),a=n.filter(i=>en.test(i)),l=a.length>=2?a:n;if(l.length<2||l.length>6)return null;const r=l.map(i=>{var c;return((c=i.replace(/^(\*\*|__)/,"").match(/^([A-Z])\.\s/))==null?void 0:c[1])??""}),o=l.map(i=>{const c=i.match(en);return c?Os(c[2].replace(/^[A-Z]\.\s+/,"").replace(/\.$/,""),c[3].replace(/^[,;]\s*/,"")):Os(i.replace(/\.$/,""),"")});return go(o)?{options:vu(o,Nu(s,o,r)),notes:t.sub.filter(i=>!l.includes(i))}:null}const ya=(t,s,n=t,a)=>{const l=s??wr(n).map(i=>({label:i,detail:""})),r=l.map(i=>i.detail),o=l.findIndex(i=>i.star);return{text:t,options:l.map(i=>i.label),...r.some(Boolean)?{details:r}:{},...o>=0?{recommended:o}:{},...a?{ref:a}:{}}};function ku(t,s={}){var k,S;const n=ju(t);let a,l;const r=n[0];(r==null?void 0:r.type)==="h"&&(a=r.text,n.shift()),a&&((k=n[0])==null?void 0:k.type)==="p"&&!Ya(n[0].text)&&(l=n[0].text,n.shift());const o=[];let i={kind:"other",blocks:[]};const c=()=>{(i.blocks.length||i.title)&&o.push(i)};for(const b of n)if(b.type==="h"){c();const j=Jg(b.text);i={kind:s.plan&&(j==="done"||j==="verified")?"other":j,title:b.text,blocks:[]}}else i.blocks.push(b);c();const x=[];let u=null,m="";const p=(b,j)=>{b===1?u=[j]:u&&b===u.length+1&&u.push(j)},h=b=>{var j,N;return(N=(j=b.match(en))==null?void 0:j[2])==null?void 0:N.replace(/\s*:$/,"")},g=()=>{const b=u&&u.length>=2&&u.length<=8?u:null;return u=null,b?vu(b,Nu(m,b)):null};for(const b of o){const j=b.kind==="done"||b.kind==="verified",N=(S=b.title)==null?void 0:S.match(sb);N&&p(Number(N[1]),ql(N[2],"",b.blocks[0]));for(let $=0;$<b.blocks.length;$++){const C=b.blocks[$];if(C.type==="p"){const M=C.text.match(nb);if(M){p(Number(M[2]),ql(M[3],M[4],b.blocks[$+1]));continue}if(/^(\*\*|__)[^*_]*(recommand|recommend)/i.test(C.text)&&(m=C.text),j)continue;const v=Ei(C.text),A=Mi(C.text);if(!v&&!A)continue;const T=b.blocks[$+1];let R=(T==null?void 0:T.type)==="list"&&!T.ordered?Ci(T.items.map(P=>P.text)):null;R?b.blocks.splice($+1,1):A?R=A.options:!wr(v).length&&Ri.test(v)&&(R=g()),C.q=x.length,x.push(ya(C.text,R,A&&!v?A.stem:v))}else C.type==="list"&&!j&&C.items.forEach((M,v)=>{const A=en.test(M.text)?M.text.lastIndexOf("?"):-1,T=Ei(M.text)??(A>0?M.text.slice(0,A+1):null),R=Mi(M.text),P=T||R?null:rb(M);if(!T&&!R&&!P){const D=C.ordered?M.text.match(en):null;D&&p(v+1,ql(D[2],D[3],void 0));return}M.q=x.length;const _=Ci(M.sub);P?(x.push(ya(M.text,P.options,M.text,h(M.text))),M.sub=P.notes):!_&&R?x.push(ya(R.stem,R.options,R.stem,h(R.stem))):x.push(ya(M.text,_??(!wr(T).length&&Ri.test(T)?g():null),T??M.text)),_&&!P&&(M.sub=[])})}}const y=!!a&&(r==null?void 0:r.type)==="h"||x.length>0||o.some(b=>!!b.title||b.blocks.some(j=>j.type!=="p"));return{title:a,lead:l,sections:o,questions:x,structured:y}}const Hl="mt-px inline-flex size-4 flex-none items-center justify-center rounded-[4px] border";function wu({checklist:t,current:s}){var u;const[n,a]=f.useState(!1),{tasks:l,done:r,total:o}=t,i=((u=l.find(m=>m.status==="in_progress"))==null?void 0:u.text)??s??(r===o?d.checklist.allDone:d.checklist.paused),c=l.some(m=>m.status==="in_progress")||!!s,x=f.useMemo(()=>{const m=new Map;return l.map(p=>{const h=m.get(p.text)??0;return m.set(p.text,h+1),h===0?p.text:`${p.text}#${h}`})},[l]);return e.jsxs("div",{className:"sticky top-0 z-10 flex-none bg-bg",children:[e.jsxs("button",{type:"button","aria-expanded":n,onClick:()=>a(m=>!m),className:`flex min-h-11 w-full flex-col gap-1.5 border border-line bg-surface px-3 py-2.5 text-left text-[12px] leading-[18px] text-muted shadow-[0_4px_14px_rgba(0,0,0,.35)] ${n?"rounded-t-card":"rounded-card"}`,children:[e.jsxs("span",{className:"flex w-full items-center gap-2",children:[e.jsx(q,{name:"plan",className:"size-3.5",stroke:1.8}),e.jsx("strong",{className:"font-medium text-fg",children:d.checklist.title}),e.jsx("span",{className:"flex-1"}),e.jsxs("span",{className:"font-mono text-[11px] text-fg",children:[r,"/",o]}),e.jsx("span",{"aria-hidden":"true",className:"h-1 w-16 overflow-hidden rounded-[2px] bg-raised",children:e.jsx("span",{className:"block h-full bg-ok",style:{width:`${o?r/o*100:0}%`}})}),e.jsx("span",{className:n?"-rotate-90":"rotate-90",children:e.jsx(q,{name:"chevron",className:"size-[13px]",stroke:2})})]}),e.jsxs("span",{className:"block w-full truncate",children:[c&&e.jsx("span",{className:"mr-1.5 inline-block size-1.5 rounded-full bg-info align-[1px]"}),i]})]}),n&&e.jsxs("ol",{className:"max-h-[50dvh] overflow-y-auto rounded-b-card border border-t-0 border-line bg-surface px-3 pt-1.5 pb-2.5 text-small",children:[l.map((m,p)=>e.jsxs("li",{className:`flex items-start gap-2.5 py-1.5 [overflow-wrap:anywhere] ${m.status==="completed"?"text-muted line-through":m.status==="in_progress"?"font-medium text-fg":"text-fg"}`,children:[m.status==="completed"&&e.jsx("span",{role:"img","aria-label":d.checklist.box.completed,className:`${Hl} border-ok/50 font-mono text-[10px] font-semibold text-ok no-underline`,children:"✓"}),m.status==="in_progress"&&e.jsx("span",{role:"img","aria-label":d.checklist.box.in_progress,className:`${Hl} border-info`,children:e.jsx("svg",{className:"size-2.5 text-info motion-safe:animate-spin",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"3",strokeLinecap:"round","aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})})}),m.status==="pending"&&e.jsx("span",{role:"img","aria-label":d.checklist.box.pending,className:`${Hl} border-fg/25`}),m.text]},x[p])),t.cut&&e.jsx("li",{className:"py-1.5 text-meta text-muted",children:d.checklist.cut})]})]})}function Jn({name:t,legend:s,options:n,value:a,onChange:l,fit:r=!1}){return e.jsxs("fieldset",{className:`m-0 min-w-0 border-0 p-0${r?" self-start":""}`,"data-fit":r||void 0,children:[e.jsx("legend",{className:"sr-only",children:s}),e.jsx("div",{className:`${r?"inline-flex":"grid auto-cols-fr grid-flow-col"} gap-1 rounded-control bg-raised p-1`,children:n.map(o=>e.jsxs("label",{lang:o.lang,className:`flex min-h-10 cursor-pointer items-center justify-center rounded-[9px] ${r?"px-3.5":"px-2"} text-body font-medium text-muted transition-colors duration-100 has-[:checked]:bg-fg has-[:checked]:text-bg has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-info`,children:[e.jsx("input",{type:"radio",name:t,value:o.value,checked:a===o.value,onChange:()=>l(o.value),className:"sr-only"}),o.label]},o.value))})]})}const bo="model-sheet-title",ob="flex min-h-12 w-full items-center gap-3 rounded-control border border-line bg-surface px-3 py-2.5 text-left active:bg-raised aria-pressed:border-fg/40 aria-pressed:bg-raised";function Su({tool:t,models:s,error:n,current:a,pick:l,onPick:r,note:o,actions:i,defaultHint:c=d.model.defaultHint}){var g;const x=!a||a.model===null||s.some(y=>y.id===a.model),u=ri(t,s,l),m=y=>{const k=ri(t,s,{model:y});r({model:y,effort:l.effort!==null&&(k!=null&&k.includes(l.effort))?l.effort:null})},p=(y,k,S)=>e.jsxs("button",{type:"button","aria-pressed":l.model===y,onClick:()=>m(y),className:ob,children:[e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-body font-medium",children:k}),S&&e.jsx("span",{className:"block text-meta text-muted",children:S})]}),(a==null?void 0:a.model)===y&&e.jsx("span",{className:"flex-none rounded-full bg-raised px-2 py-0.5 text-meta text-muted",children:d.model.current})]},y??""),h=u&&(l.effort??((g=s.find(y=>l.model===null?y.isDefault:y.id===l.model))==null?void 0:g.defaultEffort)??"");return e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("h2",{id:bo,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:d.model.title}),e.jsx("p",{className:"mt-1 text-meta text-muted",children:d.model.subtitle(d.tools[t]??t)})]}),n&&e.jsx("p",{role:"status",className:"text-meta text-attention",children:d.model.listError}),e.jsxs("div",{className:"flex max-h-[45vh] flex-col gap-1.5 overflow-y-auto",children:[p(null,d.model.byDefault,c),!x&&(a==null?void 0:a.model)!=null&&p(a.model,a.model,void 0),s.map(y=>p(y.id,y.label,Fd(t,y)))]}),u&&e.jsxs("div",{children:[e.jsxs("p",{className:"text-body font-medium",children:[d.model.effortTitle," ",e.jsx("span",{className:"text-meta font-normal text-muted",children:d.model.effortHint})]}),e.jsx("div",{className:"mt-2",children:e.jsx(Jn,{name:"model-effort",legend:d.model.effortTitle,value:h??"",onChange:y=>r({model:l.model,effort:y}),options:u.map(y=>({value:y,label:ca(y)}))})})]}),o&&e.jsx("p",{className:"text-small whitespace-pre-line text-muted",children:o}),i]})}const $u={models:[]},Cu=t=>t.modelNext?{model:t.modelNext.model??null,effort:t.modelNext.effort??null}:ro(t),sn=(t,s)=>!!(t!=null&&t.models)&&s.canSwitch===!0;function ib({store:t,session:s}){const{daemon:n,models:a,fresh:l}=me(t),[r,o]=f.useState(!1),i=sn(n,s);if(f.useEffect(()=>{i&&t.requestModels(s.tool)},[i,t,s.tool]),!i)return null;const c=a[s.tool]??$u,x=s.modelNext?Cu(s):null,u=x??ro(s),m=[ah(s.tool,u.model??void 0,c.models),u.effort?ca(u.effort):null].filter(Boolean).join(" · ");return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",disabled:!l,"aria-haspopup":"dialog","aria-label":d.model.chip(x?`${m}, ${d.model.nextTurn}`:m),onClick:()=>{t.requestModels(s.tool),o(!0)},className:`${Ic()} gap-2 whitespace-nowrap`,children:[e.jsx("span",{children:m}),x&&e.jsx("span",{className:"text-meta font-normal text-attention",children:d.model.nextTurn})]}),r&&e.jsx(gl,{store:t,session:s,onClose:()=>o(!1)})]})}function cb({store:t,session:s}){const{daemon:n,modelFailures:a}=me(t),l=a[s.id];return!sn(n,s)||!l?null:e.jsx("p",{role:"status",className:"pb-2 text-meta text-attention",children:d.model.failedLine(d.model.failed[l])})}function gl({store:t,session:s,onClose:n}){const{models:a}=me(t),l=a[s.tool]??$u,r=ro(s),[o,i]=f.useState(Cu(s)),[c,x]=f.useState(!1),[u,m]=f.useState(null),p=async g=>{x(!0),m(null);const y=await t.changeModel(s.id,g.model,g.effort);if(x(!1),y.status==="applied"){n();return}if(y.status==="expired"){m(d.model.uncertain);return}const k=y.status==="rejected"?y.reason:null;m(k&&k in d.model.failed?d.model.failed[k]:d.model.notApplied)},h=rh(s);return e.jsx(dt,{labelledBy:bo,onClose:n,children:e.jsx(Su,{tool:s.tool,models:l.models,error:l.error,current:r,pick:o,onPick:i,note:h?d.model.noteWorking(s.name):d.model.noteIdle(s.name),actions:e.jsxs(e.Fragment,{children:[u&&e.jsx("p",{role:"alert",className:"text-meta text-attention",children:u}),s.modelNext&&e.jsx(Ke,{variant:"outline",disabled:c,onClick:()=>void p(r),children:d.model.cancelPending}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ke,{variant:"ghost",className:"flex-1",onClick:n,children:d.model.cancel}),e.jsx(Ke,{variant:"primary",className:"flex-[2]",disabled:c||lh(o,r),onClick:()=>void p(o),children:d.model.apply})]})]})})})}const db=1e4;function Mu(t,s){const n=d.sessions.modelOff;return sn(t,s)?null:s.state==="exited"?n.ended:t!=null&&t.models?n.outside:n.olderPc}function ub(t,s){const n=l=>{var r;return t.rig?((r=l.rig)==null?void 0:r.name)===t.rig.name:!l.rig&&l.project===t.project},a=[...s].filter(l=>n(l)&&l.state!=="exited").map(l=>l.id);return{name:t.rig?d.sessions.rigGroup(t.rig.name):t.project,ids:a}}function us({icon:t,label:s,why:n,right:a,onClick:l,danger:r=!1}){const o=!l;return e.jsxs("button",{type:"button",disabled:o,onClick:l,className:`flex min-h-12 w-full items-center gap-3 border-b border-line px-3.5 py-2 text-left text-[15px] last:border-b-0 disabled:opacity-60 ${r?"text-danger-fg":"text-fg"}`,children:[e.jsx(q,{name:t,className:`size-5 ${r?"text-danger-fg":"text-muted"}`}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{children:s}),n&&e.jsx("small",{className:"text-small text-muted",children:n})]}),a!=null&&e.jsx("span",{className:"ml-auto flex-none text-[12.5px] text-muted",children:a})]})}const zn=({children:t})=>e.jsx("div",{className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:t});function jo({store:t,session:s,closable:n,closing:a,onClose:l,onModel:r,onCloseSession:o,display:i,lead:c,who:x,order:u}){var O,B,Z;const m=me(t),p=Xt(),h=f.useId(),[g,y]=f.useState("menu"),[k,S]=f.useState(!1),b=d.sessions,j=s.name,N=m.fresh,C=[ul(s,p,1).model,s.effort?ca(s.effort):null].filter(Boolean).join(" · "),M=Mu(m.daemon,s),v=(O=m.daemon)!=null&&O.checklist?m.checklists.get(s.id):void 0,A=!!s.pending||s.state==="waiting_permission"||s.state==="waiting_input",T=s.state==="working",R=Object.values(m.ops).filter(H=>H.message.type==="session.interrupt"&&H.message.id===s.id).sort((H,X)=>H.at.localeCompare(X.at)).at(-1),P=R!==void 0&&ps(R.phase),_=(R==null?void 0:R.phase)==="applied"&&(!T||p-Date.parse(R.at)<db),D=T&&N&&!A&&!P&&!_,E=d.terminal,z=P||_?null:N?A?E.why.waiting:T?null:E.why.idle:E.why.offline,K=(R==null?void 0:R.phase)==="sending"?E.sending:_?E.sent:E.interrupt(j),L=(R==null?void 0:R.phase)==="rejected"&&R.reason==="read_only"?E.readOnly:k||(R==null?void 0:R.phase)==="rejected"||(R==null?void 0:R.phase)==="failed"?E.fail:null,W=ub(s,m.sessions.values()),ae=!!((B=m.daemon)!=null&&B.broadcast)&&W.ids.length>1,U=x??[s.project,s.branch].filter(Boolean).join(" · ");return e.jsxs(dt,{labelledBy:h,onClose:l,children:[e.jsxs("h2",{id:h,"aria-label":b.sheet.label(j),className:"flex min-w-0 items-center gap-2",children:[e.jsx(gs,{tool:s.tool}),e.jsx("b",{className:"font-semibold whitespace-nowrap",children:j}),U&&e.jsx("span",{className:"min-w-0 truncate text-small font-normal text-muted",children:U})]}),g==="plan"&&v?e.jsxs(e.Fragment,{children:[e.jsx(wu,{checklist:v,...(Z=s.checklist)!=null&&Z.current?{current:s.checklist.current}:{}}),e.jsx("button",{type:"button",onClick:()=>y("menu"),className:"h-11 rounded-lg border border-input text-body",children:d.nav.back})]}):g==="group"?e.jsx(ad,{store:t,label:W.name,ids:W.ids,offline:!N,startOpen:!0,onCancel:()=>y("menu")}):e.jsxs(e.Fragment,{children:[c&&c.length>0&&e.jsx(zn,{children:c.map(H=>e.jsx(us,{icon:H.icon,label:H.label,onClick:H.onClick},H.label))}),u&&u.length>0&&e.jsx(zn,{children:u.map(H=>e.jsx(us,{icon:H.icon,label:H.label,onClick:H.onClick},H.label))}),e.jsxs(zn,{children:[e.jsx(us,{icon:"cpu",label:d.model.title,why:M,right:C||null,onClick:M||!N?void 0:r}),i&&e.jsx(us,{icon:"terminal",label:d.terminal.live2.view,right:i.value,onClick:i.onToggle}),v&&e.jsx(us,{icon:"list",label:d.checklist.title,right:b.sheet.planCount(v.done,v.total),onClick:()=>y("plan")}),e.jsx(us,{icon:"stop",label:K,why:L??z,onClick:D?()=>S(!t.interrupt(s.id)):void 0}),ae&&e.jsx(us,{icon:"send",label:b.sheet.writeGroup(W.name),onClick:N?()=>y("group"):void 0})]}),n&&s.state!=="exited"&&e.jsx(zn,{children:e.jsx(us,{icon:"power",danger:!0,label:a?d.sessionEnd.closingNamed(j):d.sessionEnd.close(j),right:_t()&&!a?e.jsx("span",{"aria-hidden":"true",children:b.sheet.faceId}):null,onClick:a?void 0:o})}),e.jsx("p",{className:"text-meta text-muted",children:b.sheet.interruptNote})]})]})}function xb({name:t,up:s,down:n,onClose:a}){const l=f.useId(),r=d.sessions.reorder;return e.jsxs(dt,{labelledBy:l,onClose:a,children:[e.jsx("h2",{id:l,className:"flex min-w-0 items-center gap-2",children:e.jsx("b",{className:"truncate font-semibold",children:t})}),e.jsxs(zn,{children:[e.jsx(us,{icon:"arrowUp",label:r.up,onClick:s?()=>{s(),a()}:void 0}),e.jsx(us,{icon:"arrowDown",label:r.down,onClick:n?()=>{n(),a()}:void 0})]})]})}const Sr=t=>`ledge.mobile.draft.${t}`;function Eu(t,s){var n;try{return((n=Qe(s))==null?void 0:n.getItem(Sr(t)))??""}catch{return""}}function Ru(t,s,n){try{const a=Qe(n);s===""?a==null||a.removeItem(Sr(t)):a==null||a.setItem(Sr(t),s)}catch{}}const Au="ledge.mobile.draft.cleared",mb=50;function Tu(t){var s;try{const n=JSON.parse(((s=Qe(t))==null?void 0:s.getItem(Au))??"[]");return Array.isArray(n)?n.filter(a=>typeof a=="string"):[]}catch{return[]}}function pb(t,s){return Tu(s).includes(t)}function fb(t,s){var n;try{const a=Tu(s).filter(l=>l!==t);(n=Qe(s))==null||n.setItem(Au,JSON.stringify([...a,t].slice(-mb)))}catch{}}let $r=null;const hb=t=>{$r=t};function gb(t){return $r!==t?!1:($r=null,!0)}function bb(t,s,n){const a=Eu(t,n);Ru(t,a.startsWith(s)?a:s+a,n),hb(t)}const jb=["image/png","image/gif","image/jpeg","image/webp"],yb=25e6,Nb=[.85,.7,.55,.4],Ai=640,vb=.8,kb=[.7,.5],wb={async decode(t){const s=await createImageBitmap(t);let n=null;const a=()=>{n&&(n.width=n.height=0),n=null};return{width:s.width,height:s.height,close:()=>{a(),s.close()},async draw(l,r){a();const o=n=document.createElement("canvas");o.width=l,o.height=r;const i=o.getContext("2d");if(!i)throw new Error("no canvas");return i.imageSmoothingQuality="high",i.drawImage(s,0,0,l,r),{encode:(c,x)=>new Promise((u,m)=>o.toBlob(p=>p?u(p):m(new Error("no blob")),c,x))}}}}},_u=(t,s,n)=>{const a=Math.min(1,n/Math.max(t,s));return{w:Math.max(1,Math.round(t*a)),h:Math.max(1,Math.round(s*a))}};async function Iu(t,s){let n=await t.encode("image/webp",s);return n.type==="image/webp"||n.type==="image/jpeg"?{blob:n,mime:n.type}:(n=await t.encode("image/jpeg",s),{blob:n,mime:"image/jpeg"})}const Lu=t=>new Promise((s,n)=>{const a=new FileReader;a.onload=()=>s(String(a.result).slice(String(a.result).indexOf(",")+1)),a.onerror=()=>n(a.error),a.readAsDataURL(t)});async function Sb(t,s=wb){var a;if(!jb.includes(t.type))return{ok:!1,reason:"notImage"};if(t.size>yb)return{ok:!1,reason:"tooLarge"};let n;try{n=await s.decode(t)}catch{return{ok:!1,reason:"unreadable"}}try{let l=Math.min(cm,Math.max(n.width,n.height));for(;;){const{w:r,h:o}=_u(n.width,n.height,l),i=await n.draw(r,o);for(const c of Nb){const{blob:x,mime:u}=await Iu(i,c);if(x.size>dm)continue;const m={mime:u,data:await Lu(x)},p=await $b(n);return p&&(m.preview=p),{ok:!0,value:{image:m,width:r,height:o,bytes:x.size}}}if(l<=Ai)return{ok:!1,reason:"tooLarge"};l=Math.max(Ai,Math.round(l*vb))}}catch{return{ok:!1,reason:"unreadable"}}finally{(a=n.close)==null||a.call(n)}}async function $b(t){try{return await Cb(t)}catch{return}}async function Cb(t){const{w:s,h:n}=_u(t.width,t.height,um),a=await t.draw(s,n);for(const l of kb){const{blob:r,mime:o}=await Iu(a,l);if(r.size<=xm)return{mime:o,data:await Lu(r)}}}function Mb(t,s){if(t>=1e6){const n=(Math.round(t/1e5)/10).toFixed(1);return`${s==="fr"?n.replace(".",","):n} ${s==="fr"?"Mo":"MB"}`}return`${Math.round(t/1e3)} ${s==="fr"?"Ko":"KB"}`}function Ou({items:t,onRemove:s,size:n,removeLabel:a,lang:l}){return t.length===0?null:e.jsx("div",{"data-attachment-chips":!0,style:{display:"flex",flexWrap:"wrap",gap:8},children:t.map(r=>e.jsxs("div",{"data-chip":r.state,title:r.reason,style:{position:"relative",width:n.w,height:n.h,flexShrink:0,borderRadius:"var(--radius-md)",overflow:"hidden",border:`1px solid ${r.state==="refused"?"var(--danger-text)":"var(--border)"}`,background:"var(--well)"},children:[e.jsx("img",{src:r.url,alt:"",draggable:!1,style:{width:"100%",height:"100%",objectFit:"cover",display:"block",opacity:r.state==="ready"?1:.45}}),r.state==="uploading"&&e.jsx("span",{role:"status","aria-label":"…",style:{position:"absolute",inset:0,display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",style:{color:"var(--foreground)"},children:e.jsx("path",{d:"M12 3a9 9 0 1 1-9 9",opacity:"0.9",children:e.jsx("animateTransform",{attributeName:"transform",type:"rotate",from:"0 12 12",to:"360 12 12",dur:"0.9s",repeatCount:"indefinite"})})})}),r.state==="refused"&&e.jsx("span",{style:{position:"absolute",left:0,right:0,bottom:0,padding:"2px 4px",fontSize:10,lineHeight:1.2,color:"var(--danger-text)",background:"var(--status-danger-soft)"},children:r.reason}),r.state!=="refused"&&e.jsx("span",{style:{position:"absolute",left:4,bottom:4,padding:"1px 5px",borderRadius:4,fontSize:10,lineHeight:1.3,color:"#fff",background:"rgba(0,0,0,0.6)"},children:Mb(r.bytes,l)}),e.jsx("button",{type:"button","aria-label":a,title:a,onClick:()=>s(r.key),style:{position:"absolute",top:3,right:3,width:20,height:20,padding:0,display:"flex",alignItems:"center",justifyContent:"center",borderRadius:10,border:"none",cursor:"pointer",color:"#fff",background:"rgba(0,0,0,0.6)"},children:e.jsx(Nn,{...hn.close,size:12})})]},r.key))})}function Eb({url:t,failed:s,width:n,height:a,maxW:l,maxH:r,alt:o,unavailable:i,onOpen:c}){const x=Math.min(1,l/n,r/a),u={width:Math.round(n*x),height:Math.round(a*x),maxWidth:"100%",borderRadius:"var(--radius-lg)",border:"1px solid var(--border)",background:"var(--well)",boxSizing:"border-box",overflow:"hidden"};return s?e.jsx("div",{"data-thumb":"failed",style:{...u,display:"flex",alignItems:"center",justifyContent:"center",padding:8,fontSize:12,color:"var(--muted-foreground)",textAlign:"center"},children:i}):t?e.jsx("button",{type:"button","data-thumb":"ready",onClick:c,style:{...u,padding:0,display:"block",cursor:"zoom-in"},children:e.jsx("img",{src:t,alt:o,draggable:!1,style:{width:"100%",height:"100%",objectFit:"cover",display:"block"}})}):e.jsx("div",{"data-thumb":"loading","aria-busy":"true",style:u})}function Du({onFiles:t,disabled:s,className:n,children:a}){const l=f.useRef(null);return e.jsxs(e.Fragment,{children:[e.jsx("input",{ref:l,type:"file",accept:"image/*",multiple:!0,hidden:!0,tabIndex:-1,"aria-hidden":"true",onChange:r=>{t([...r.target.files??[]]),r.target.value=""}}),e.jsx("button",{type:"button",disabled:s,"aria-label":a?void 0:d.images.attach,title:d.images.attach,onClick:()=>{var r;return(r=l.current)==null?void 0:r.click()},className:n??Tt({variant:"outline",round:!0}),children:a??e.jsx(q,{name:"plus"})})]})}const Fu=t=>{var s;return[...((s=t.clipboardData)==null?void 0:s.files)??[]].filter(n=>n.type.startsWith("image/"))},Ti=44,Rb=120,Qa=()=>{var t;return((t=globalThis.matchMedia)==null?void 0:t.call(globalThis,"(hover: hover) and (pointer: fine)").matches)===!0};function Ab({id:t,label:s,sendLabel:n,value:a,onChange:l,onSend:r,canSend:o,oneLine:i,images:c,placeholder:x,disabled:u=!1,attachDisabled:m,maxLength:p,invalid:h=!1,describedBy:g,fieldRef:y}){const k=f.useRef(null),S=y??k;f.useLayoutEffect(()=>{const j=S.current;j&&(j.style.height=`${Ti}px`,j.style.height=`${Math.min(Rb,Math.max(Ti,j.scrollHeight+j.offsetHeight-j.clientHeight))}px`)},[a,S]);const b=m??u;return e.jsxs("div",{className:"flex flex-col gap-2",children:[c.items.length>0&&e.jsx(Ou,{items:c.items,onRemove:c.remove,size:{w:72,h:54},removeLabel:d.images.remove,lang:Lc}),e.jsxs("div",{className:"flex items-end gap-2",children:[e.jsx(Du,{onFiles:c.add,disabled:b}),e.jsx("label",{htmlFor:t,className:"sr-only",children:s}),e.jsx("textarea",{id:t,ref:S,rows:1,value:a,disabled:u,placeholder:x,maxLength:p,enterKeyHint:i?"send":"enter","aria-invalid":h,"aria-describedby":g,onChange:j=>l(j.target.value),onPaste:j=>{const N=Fu(j);N.length===0||b||(j.preventDefault(),c.add(N))},onKeyDown:j=>{j.key!=="Enter"||j.nativeEvent.isComposing||!i&&(j.shiftKey||!Qa())||(j.preventDefault(),o&&r())},className:"max-h-[120px] min-h-11 min-w-0 flex-1 resize-none rounded-[22px] border border-input bg-surface px-3.5 py-[11px] text-base leading-5 text-fg placeholder:text-muted disabled:opacity-60"}),e.jsx("button",{type:"button",disabled:!o,onClick:r,"aria-label":n,title:n,className:Tt({variant:"primary",round:!0}),children:e.jsx(q,{name:"arrowUp"})})]})]})}const Tb={anthropic:{d:"M4.709 15.955l4.72-2.647.08-.23-.08-.128H9.2l-.79-.048-2.698-.073-2.339-.097-2.266-.122-.571-.121L0 11.784l.055-.352.48-.321.686.06 1.52.103 2.278.158 1.652.097 2.449.255h.389l.055-.157-.134-.098-.103-.097-2.358-1.596-2.552-1.688-1.336-.972-.724-.491-.364-.462-.158-1.008.656-.722.881.06.225.061.893.686 1.908 1.476 2.491 1.833.365.304.145-.103.019-.073-.164-.274-1.355-2.446-1.446-2.49-.644-1.032-.17-.619a2.97 2.97 0 01-.104-.729L6.283.134 6.696 0l.996.134.42.364.62 1.414 1.002 2.229 1.555 3.03.456.898.243.832.091.255h.158V9.01l.128-1.706.237-2.095.23-2.695.08-.76.376-.91.747-.492.584.28.48.685-.067.444-.286 1.851-.559 2.903-.364 1.942h.212l.243-.242.985-1.306 1.652-2.064.73-.82.85-.904.547-.431h1.033l.76 1.129-.34 1.166-1.064 1.347-.881 1.142-1.264 1.7-.79 1.36.073.11.188-.02 2.856-.606 1.543-.28 1.841-.315.833.388.091.395-.328.807-1.969.486-2.309.462-3.439.813-.042.03.049.061 1.549.146.662.036h1.622l3.02.225.79.522.474.638-.079.485-1.215.62-1.64-.389-3.829-.91-1.312-.329h-.182v.11l1.093 1.068 2.006 1.81 2.509 2.33.127.578-.322.455-.34-.049-2.205-1.657-.851-.747-1.926-1.62h-.128v.17l.444.649 2.345 3.521.122 1.08-.17.353-.608.213-.668-.122-1.374-1.925-1.415-2.167-1.143-1.943-.14.08-.674 7.254-.316.37-.729.28-.607-.461-.322-.747.322-1.476.389-1.924.315-1.53.286-1.9.17-.632-.012-.042-.14.018-1.434 1.967-2.18 2.945-1.726 1.845-.414.164-.717-.37.067-.662.401-.589 2.388-3.036 1.44-1.882.93-1.086-.006-.158h-.055L4.132 18.56l-1.13.146-.487-.456.061-.746.231-.243 1.908-1.312-.006.006z",fill:"#D97757",rule:"nonzero"},openai:{d:"M9.205 8.658v-2.26c0-.19.072-.333.238-.428l4.543-2.616c.619-.357 1.356-.523 2.117-.523 2.854 0 4.662 2.212 4.662 4.566 0 .167 0 .357-.024.547l-4.71-2.759a.797.797 0 00-.856 0l-5.97 3.473zm10.609 8.8V12.06c0-.333-.143-.57-.429-.737l-5.97-3.473 1.95-1.118a.433.433 0 01.476 0l4.543 2.617c1.309.76 2.189 2.378 2.189 3.948 0 1.808-1.07 3.473-2.76 4.163zM7.802 12.703l-1.95-1.142c-.167-.095-.239-.238-.239-.428V5.899c0-2.545 1.95-4.472 4.591-4.472 1 0 1.927.333 2.712.928L8.23 5.067c-.285.166-.428.404-.428.737v6.898zM12 15.128l-2.795-1.57v-3.33L12 8.658l2.795 1.57v3.33L12 15.128zm1.796 7.23c-1 0-1.927-.332-2.712-.927l4.686-2.712c.285-.166.428-.404.428-.737v-6.898l1.974 1.142c.167.095.238.238.238.428v5.233c0 2.545-1.974 4.472-4.614 4.472zm-5.637-5.303l-4.544-2.617c-1.308-.761-2.188-2.378-2.188-3.948A4.482 4.482 0 014.21 6.327v5.423c0 .333.143.571.428.738l5.947 3.449-1.95 1.118a.432.432 0 01-.476 0zm-.262 3.9c-2.688 0-4.662-2.021-4.662-4.519 0-.19.024-.38.047-.57l4.686 2.71c.286.167.571.167.856 0l5.97-3.448v2.26c0 .19-.07.333-.237.428l-4.543 2.616c-.619.357-1.356.523-2.117.523zm5.899 2.83a5.947 5.947 0 005.827-4.756C22.287 18.339 24 15.84 24 13.296c0-1.665-.713-3.282-1.998-4.448.119-.5.19-.999.19-1.498 0-3.401-2.759-5.947-5.946-5.947-.642 0-1.26.095-1.88.31A5.962 5.962 0 0010.205 0a5.947 5.947 0 00-5.827 4.757C1.713 5.447 0 7.945 0 10.49c0 1.666.713 3.283 1.998 4.448-.119.5-.19 1-.19 1.499 0 3.401 2.759 5.946 5.946 5.946.642 0 1.26-.095 1.88-.309a5.96 5.96 0 004.162 1.713z",fill:"currentColor",rule:"evenodd"},cursor:{d:"M22.106 5.68L12.5.135a.998.998 0 00-.998 0L1.893 5.68a.84.84 0 00-.419.726v11.186c0 .3.16.577.42.727l9.607 5.547a.999.999 0 00.998 0l9.608-5.547a.84.84 0 00.42-.727V6.407a.84.84 0 00-.42-.726zm-.603 1.176L12.228 22.92c-.063.108-.228.064-.228-.061V12.34a.59.59 0 00-.295-.51l-9.11-5.26c-.107-.062-.063-.228.062-.228h18.55c.264 0 .428.286.296.514z",fill:"currentColor",rule:"evenodd"}},_b={claude:"anthropic",codex:"openai",cursor:"cursor"};function zu(t,s,n,a=!0){const[l,r]=f.useState({key:"",url:null,failed:!1}),o=s?`${s}|${n}`:"";return f.useEffect(()=>{if(!s||!a)return;let i=!0;return t.imageUrl(s,n).then(c=>{i&&r({key:o,url:c,failed:!1})},()=>{i&&r({key:o,url:null,failed:!0})}),()=>{i=!1}},[t,s,n,a,o]),l.key===o&&o!==""?{url:l.url,failed:l.failed}:{url:null,failed:!1}}const Ts=d.images,Ib=1,Lb=4,Ob=120,Db=t=>Math.min(Lb,Math.max(Ib,t)),Fb={"image/png":"png","image/gif":"gif","image/jpeg":"jpg","image/webp":"webp"};function zb(t,s,n){const[a,l]=f.useState(null);return f.useEffect(()=>{if(l(null),!t||typeof navigator.canShare!="function"||typeof navigator.share!="function")return;let r=!0;return fetch(t).then(o=>o.blob()).then(o=>{const i=new File([o],s,{type:n});r&&navigator.canShare({files:[i]})&&l(i)},()=>{}),()=>{r=!1}},[t,s,n]),a}function Pb({store:t,refs:s,index:n,onIndex:a,onClose:l}){const r=s[n],{url:o,failed:i}=zu(t,r.id,!1),c=`capture-${n+1}.${Fb[r.mime]??"img"}`,x=zb(o,c,r.mime),[u,m]=f.useState(1),[p,h]=f.useState(0),g=f.useRef(new Map),y=f.useRef({pinch0:0,scale0:1,y0:0});f.useEffect(()=>{m(1),h(0),g.current.clear()},[n]);const k=()=>{const[A,T]=[...g.current.values()];return A&&T?Math.hypot(A.x-T.x,A.y-T.y):0},S=A=>{var T,R;g.current.set(A.pointerId,{x:A.clientX,y:A.clientY}),(R=(T=A.currentTarget).setPointerCapture)==null||R.call(T,A.pointerId),g.current.size===2?y.current={...y.current,pinch0:k(),scale0:u}:y.current={...y.current,y0:A.clientY}},b=A=>{g.current.has(A.pointerId)&&(g.current.set(A.pointerId,{x:A.clientX,y:A.clientY}),g.current.size===2?y.current.pinch0>0&&m(Db(y.current.scale0*k()/y.current.pinch0)):u===1&&h(A.clientY-y.current.y0))},j=A=>{if(g.current.delete(A.pointerId)&&g.current.size===0){if(u===1&&Math.abs(p)>Ob){l();return}h(0)}},N=f.useRef(null);du(N,l);const $=()=>{x&&navigator.share({files:[x]}).catch(()=>{})},C=A=>A.stopPropagation(),M="inline-flex min-h-11 items-center rounded-full bg-white/15 px-4 text-body font-medium text-white",v=(A,T,R,P)=>A>=0&&A<s.length&&e.jsx("button",{type:"button","aria-label":T,title:T,onPointerDown:C,onClick:()=>a(A),className:`absolute top-1/2 ${R} grid size-11 -translate-y-1/2 place-items-center rounded-full bg-white/15 text-white`,children:e.jsx("svg",{className:"size-5 fill-none stroke-current [stroke-linecap:round] [stroke-linejoin:round] [stroke-width:1.6]",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:P})})});return Jr.createPortal(e.jsxs("div",{ref:N,role:"dialog","aria-modal":"true","aria-label":Ts.view,tabIndex:-1,className:"fixed inset-0 z-50 flex flex-col bg-black/90 text-white outline-none",style:{opacity:p?Math.max(.4,1-Math.abs(p)/400):1},children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2.5",children:[e.jsxs("span",{className:"min-w-0 flex-1 text-small text-white/70",children:[r.width,"×",r.height,s.length>1?` · ${n+1}/${s.length}`:""]}),x&&e.jsx("button",{type:"button",onPointerDown:C,onClick:$,className:M,children:Ts.share}),o&&e.jsx("a",{href:o,download:c,onPointerDown:C,className:M,children:Ts.save}),e.jsx("button",{type:"button","aria-label":Ts.close,title:Ts.close,onPointerDown:C,onClick:l,className:"grid size-11 place-items-center rounded-full bg-white/15",children:e.jsx("svg",{className:"size-5 fill-none stroke-current [stroke-linecap:round] [stroke-width:1.8]",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"M6 6l12 12M18 6 6 18"})})})]}),e.jsxs("div",{className:"relative flex min-h-0 flex-1 items-center justify-center overflow-hidden",style:{touchAction:"none"},onPointerDown:S,onPointerMove:b,onPointerUp:j,onPointerCancel:j,children:[o&&e.jsx("img",{src:o,alt:"",draggable:!1,className:"max-h-full max-w-full select-none object-contain",style:{transform:`translateY(${p}px) scale(${u})`,transition:g.current.size?"none":"transform .15s"}}),!o&&e.jsx("p",{role:"status",className:"text-body text-white/70",children:i?Ts.unavailable:"…"}),v(n-1,Ts.prev,"left-3","m15 18-6-6 6-6"),v(n+1,Ts.next,"right-3","m9 18 6-6-6-6")]})]}),document.body)}const _i=d.images;function Bb({store:t,image:s,onOpen:n}){const[a,l]=f.useState(typeof IntersectionObserver>"u"),r=f.useRef(null);f.useEffect(()=>{if(a||!r.current)return;const c=new IntersectionObserver(x=>{x.some(u=>u.isIntersecting)&&(l(!0),c.disconnect())});return c.observe(r.current),()=>c.disconnect()},[a]);const{url:o,failed:i}=zu(t,s.id,!0,a&&s.preview);return s.preview?e.jsx("div",{ref:r,className:"max-w-full",children:e.jsx(Eb,{url:o,failed:i,width:s.width,height:s.height,maxW:240,maxH:240,alt:"",unavailable:_i.unavailable,onOpen:n})}):e.jsx("p",{className:"max-w-full rounded-lg border border-line bg-surface p-2.5 text-small text-muted",children:_i.noPreview})}function Cr({store:t,refs:s,align:n="start"}){const[a,l]=f.useState(null);return s.length===0?null:e.jsxs("div",{"data-thumbs":!0,className:`flex max-w-full flex-wrap gap-2 ${n==="end"?"justify-end":""}`,children:[s.map((r,o)=>e.jsx(Bb,{store:t,image:r,onOpen:()=>l(o)},`${r.id}:${o}`)),a!==null&&e.jsx(Pb,{store:t,refs:s,index:a,onIndex:l,onClose:()=>l(null)})]})}function qb(t){return!t||t.state==="exited"||t.state==="error"?"stopped":t.state==="waiting_input"||t.state==="waiting_permission"?"waiting":t.state==="idle"&&!t.helpers.some(s=>s.state!=="exited"&&s.state!=="idle")?"yours":"working"}const Hb=new RegExp("(?<code>`[^`\\n]+`)|\\*\\*(?<b>\\S(?:.*?\\S)?)\\*\\*(?!\\*)|(?<![\\w*])\\*(?<i>[^\\s*](?:[^*\\n]*?[^\\s*])?)\\*(?![\\w*])","g"),yo=f.createContext(void 0);function ms(t,s=0,n){let a=0;const l=i=>n?[e.jsx(f.Fragment,{children:n(i)},`t${a++}`)]:[i];if(s>2)return l(t);const r=[];let o=0;for(const i of t.matchAll(Hb)){const c=i.index;c>o&&r.push(...l(t.slice(o,c)));const x=i.groups;x.code?r.push(e.jsx("code",{className:"rounded-md bg-fg/[0.06] px-[5px] py-px font-mono text-[.92em] [overflow-wrap:anywhere]",children:x.code.slice(1,-1)},c)):x.b?r.push(e.jsx("strong",{className:"font-semibold",children:ms(x.b,s+1,n)},c)):r.push(e.jsx("em",{children:ms(x.i,s+1,n)},c)),o=c+i[0].length}return o<t.length&&r.push(...l(t.slice(o))),r}function Pu({b:t}){const s=f.useContext(yo);switch(t.type){case"p":return e.jsx("p",{className:"[&+*]:mt-2.5",children:ms(t.text,0,s)});case"code":return e.jsx("pre",{className:"my-2.5 overflow-x-auto rounded-lg bg-well p-2.5 font-mono text-small leading-[1.6] whitespace-pre",children:t.text});case"list":{const n=t.ordered?"ol":"ul";return e.jsx(n,{className:`my-2.5 flex flex-col gap-1 pl-[18px] text-fg/80 ${t.ordered?"list-decimal":"list-disc"}`,children:t.items.map((a,l)=>e.jsxs("li",{children:[a.checked!==void 0&&e.jsx("span",{"aria-hidden":"true",children:a.checked?"☑ ":"☐ "}),ms(a.text,0,s),a.sub.length>0&&e.jsx("ul",{className:"mt-1 flex list-[circle] flex-col gap-1 pl-4",children:a.sub.map((r,o)=>e.jsx("li",{children:ms(r,0,s)},o))})]},l))})}case"table":return e.jsx("div",{className:"my-2.5 overflow-x-auto",tabIndex:0,children:e.jsxs("table",{className:"w-full border-collapse text-small",children:[e.jsx("thead",{children:e.jsx("tr",{children:t.header.map((n,a)=>e.jsx("th",{className:"border-b border-line px-2 py-1.5 font-semibold",style:{textAlign:t.align[a]??"left"},children:ms(n,0,s)},a))})}),e.jsx("tbody",{children:t.rows.map((n,a)=>e.jsx("tr",{children:n.map((l,r)=>e.jsx("td",{className:"border-b border-line px-2 py-1.5 align-top",style:{textAlign:t.align[r]??"left"},children:ms(l,0,s)},r))},a))})]})});case"quote":return e.jsx("blockquote",{className:"my-2.5 border-l-2 border-line pl-3 text-muted",children:t.blocks.map((n,a)=>e.jsx(Pu,{b:n},a))})}}function Ub({s:t}){const s=f.useContext(yo),n=t.blocks.map((a,l)=>e.jsx(Pu,{b:a},l));return t.kind==="next"?e.jsxs("div",{className:"mt-3 rounded-[10px] border border-info/[0.13] bg-info/[0.03] p-3",children:[e.jsx("div",{className:"mb-1.5 text-meta font-medium tracking-[.5px] text-info uppercase",children:d.thread.suggestion}),n]}):e.jsxs("section",{className:"mt-2.5",children:[t.title&&e.jsx("h3",{className:"mb-1 text-body font-semibold",children:ms(t.title,0,s)}),n]})}function Bu({doc:t,plain:s}){return e.jsxs(yo.Provider,{value:s,children:[t.title&&e.jsx("strong",{className:"block text-body font-semibold",children:ms(t.title,0,s)}),t.lead&&e.jsx("p",{className:"mt-1.5",children:ms(t.lead,0,s)}),t.sections.map((n,a)=>e.jsx(Ub,{s:n},a))]})}const Wb="text-info underline underline-offset-2",bl=(t,s)=>e.jsx("a",{href:ne({name:"thread",sessionId:t}),className:Wb,children:s});function Kb(t){const s=[...t.keys()].filter(Boolean).sort((a,l)=>l.length-a.length);if(s.length===0)return a=>a;const n=new RegExp(`(?<![\\p{L}\\p{N}_])(${s.map(a=>a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")).join("|")})(?![\\p{L}\\p{N}_])`,"gu");return a=>{const l=[];let r=0;for(const o of a.matchAll(n))o.index>r&&l.push(a.slice(r,o.index)),l.push(e.jsx("span",{children:bl(t.get(o[1]),o[1])},o.index)),r=o.index+o[0].length;return r===0?a:(r<a.length&&l.push(a.slice(r)),l)}}function Vb({text:t,names:s}){const n=f.useMemo(()=>ku(t),[t]),a=f.useMemo(()=>Kb(s),[s]);return e.jsx("div",{className:"px-1 break-words [overflow-wrap:anywhere]",children:e.jsx(Bu,{doc:n,plain:a})})}function Gb({names:t,ids:s}){return t.length===0?null:e.jsxs("span",{className:"px-1 text-small text-muted",children:[d.chat.sources,t.map((n,a)=>e.jsxs("span",{children:[a>0&&", ",s.has(n)?bl(s.get(n),n):n]},n))]})}const Ii=t=>new Date(t).toLocaleTimeString(lt,{hour:"2-digit",minute:"2-digit"});function qu({store:t,qid:s,at:n,rest:a}){return e.jsxs("p",{className:"flex flex-wrap items-center gap-x-2 px-1 text-small text-muted",children:[a?d.chat.ignoredRest(Ii(n)):d.chat.action.ignored(1,Ii(n),{done:0,denied:0,failed:0}),e.jsx("button",{type:"button",className:rs,onClick:()=>{t.ignoreTurn(s,!0)},children:d.chat.review})]})}const ma="flex flex-col gap-2.5 rounded-xl border border-line bg-surface p-3.5",rs=Pe({size:"sm"}),pa=Pe({variant:"primary",size:"sm"});function Xb({store:t,qid:s,relay:n,target:a,known:l,ignoredAt:r}){const o=a==null?void 0:a.repo,[i,c]=f.useState(null),[x,u]=f.useState(!1),[m,p]=f.useState(null),h=n.status==="sent",g=qb(a!=null&&a.state?{state:a.state,helpers:a.helpers??[]}:void 0),y=n.status==="queued";if((m==="send"&&(h||y)||m==="cancel"&&!y)&&p(null),r!==void 0&&!h&&!y)return e.jsx(qu,{store:t,qid:s,at:r});const k=j=>{u(!0),c(null),(j==="send"?t.relay(s):t.cancelRelay(s)).then($=>{$.status==="applied"?p(j):j==="send"&&c($.status==="rejected"?$.reason??"":"")},()=>{j==="send"&&c("")}).finally(()=>u(!1))},S=i||(n.failed?n.code??"":i),b=h?e.jsxs("p",{role:"status",className:"text-body text-ok",children:[d.chat.sentTo(n.name),l?bl(n.id,d.chat.seeThread):d.chat.seeThread]}):y?e.jsx("p",{role:"status",className:"text-body text-attention",children:d.chat.queued(n.name)}):S!==null?e.jsx("p",{role:"alert",className:"text-body text-danger-fg",children:d.chat.relayFailed(S||void 0)}):null;return e.jsxs("section",{"aria-label":d.chat.relayLabel,className:ma,children:[e.jsxs("div",{className:"flex items-start justify-between gap-2",children:[e.jsxs("h3",{className:"text-body font-semibold",children:[d.chat.relayHead(n.name),o?` · ${o}`:""]}),!h&&e.jsx("span",{"data-pill":g,className:"shrink-0 rounded-full border border-line px-2 text-small text-muted",children:d.chat.relayPill[g]})]}),e.jsx("p",{className:"whitespace-pre-wrap break-words text-body text-fg/80",children:n.text}),b,y&&e.jsx("div",{className:"flex gap-2",children:e.jsx("button",{type:"button",className:rs,disabled:x||m!==null,onClick:()=>k("cancel"),children:d.chat.relayCancel})}),!h&&!y&&e.jsxs("div",{className:"flex gap-2",children:[m===null&&e.jsx("button",{type:"button",className:rs,disabled:x,onClick:()=>{t.ignoreTurn(s)},children:d.chat.ignore}),e.jsx("button",{type:"button",className:pa,disabled:x||m!==null,onClick:()=>k("send"),children:S!==null?d.chat.relayRetry:d.chat.relayGo})]})]})}const Ee=d.chat.action,Yb=Pe({size:"sm",className:"border-danger-fg/50 text-danger-fg"}),Qb=Pe({block:!0,className:"!border-transparent !bg-destructive !text-primary-fg active:opacity-75"});function Mr(t){return t.split(/\*\*(.+?)\*\*/g).map((s,n)=>n%2?e.jsx("strong",{className:"font-semibold",children:s},n):e.jsx(f.Fragment,{children:s},n))}const Zb=t=>t.replace(/\*\*/g,""),Na=t=>t?new Date(t).toLocaleTimeString(lt,{hour:"2-digit",minute:"2-digit"}):"",No=t=>(t.vars&&t.action!==void 0?Ee.line(t.action,t.vars):void 0)??t.summary,Jb=t=>(t.vars&&t.action==="session.decide"?Ee.line("session.decide",{...t.vars,decision:"deny"}):void 0)??No(t),Li=t=>Ee.why(t.code??(t.state==="failed"?"failed":void 0),t.action,t.vars??{});function Oi(t){var l,r;const s=t.vars;if(!(s!=null&&s.seats))return;const n=t.action==="rig.seats"?"removed":t.action!=="rig.act"?void 0:(l=s.kind)!=null&&l.endsWith(".restart")?"restart":(r=s.kind)!=null&&r.endsWith(".stop")?"stop":void 0;if(!n)return;const a=Number(s.seatCount)||s.seats.split(", ").length;return Ee.stops(n,a,s.seats,Number(s.seatsMore??0)||0)}const ej=t=>Ee.verb(t.action,t.vars??{})??(t.action!==void 0?Ee.verbs[t.action]:void 0)??Ee.apply;function tj({r:t}){const s=t.risk==="destructive";return e.jsxs("span",{className:`inline-flex items-center gap-1 text-small ${s?"font-medium text-danger-fg":"text-muted"}`,children:[s&&e.jsx(q,{name:"warning",className:"size-3.5"}),Ee.risk[t.risk]]})}function Di({s:t,k:s,r:n,last:a}){const l=t==="done"||t==="failed"||t==="refused"||t==="running"?Ee.stepState[t](s):Ee.step(s),r=t==="done"?"border-ok bg-ok text-bg":t==="failed"||t==="refused"?"border-transparent bg-destructive text-primary-fg":n.risk==="destructive"?`border-danger-fg/60 bg-surface text-danger-fg ${t==="held"?"border-dashed":""}`:`border-input bg-surface text-muted ${t==="held"?"border-dashed":""}`;return e.jsxs("div",{className:"relative flex justify-center self-stretch",children:[!a&&e.jsx("span",{"aria-hidden":"true",className:"absolute top-5 -bottom-3 left-1/2 w-px -translate-x-1/2 bg-muted/45"}),e.jsx("span",{role:"img","aria-label":l,className:`relative grid size-5 place-items-center rounded-full border-[1.5px] font-mono text-[11px] ${r}`,children:t==="done"?e.jsx(q,{name:"check",className:"size-3"}):t==="failed"||t==="refused"?e.jsx(q,{name:"close",className:"size-3"}):t==="running"?e.jsx(q,{name:"spinner",className:"size-3 motion-safe:animate-spin"}):s})]})}function Fi({r:t,s,whole:n}){return e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"break-words text-body",children:Mr(s==="denied"?Jb(t):No(t))}),s!=="denied"&&e.jsx(tj,{r:t}),n&&Oi(t)&&e.jsx("p",{className:"mt-1 break-words text-small text-muted",children:Oi(t)}),t.detail&&e.jsx("p",{className:`mt-1 break-words text-small text-muted ${n||s==="done"?"":"line-clamp-2"}`,children:t.detail}),t.request&&e.jsxs("pre",{className:`mt-1.5 max-h-40 overflow-auto rounded-md border border-line border-l-2 border-l-muted bg-bg px-2.5 py-2 font-mono text-small whitespace-pre-wrap break-words ${s==="stale"?"line-through opacity-60":s==="denied"?"opacity-60":""}`,children:[e.jsx("span",{className:"mb-0.5 block font-sans text-muted",children:Ee.kind[t.request.kind]??t.request.kind}),t.request.text,s==="cut"&&e.jsx("span",{className:"mt-1 block border-t border-dashed border-line pt-1 font-sans text-muted",children:Ee.cutMark})]})]})}function sj({store:t,qid:s,actions:n,ignoredAt:a,canConfirm:l,readOnly:r=!1}){const[o,i]=f.useState(null),[c,x]=f.useState(new Set),[u,m]=f.useState(null),p=f.useId(),h=n.map(Wm),g=h.length>1,{shown:y,stopAt:k}=Ko(h),S=y.map((D,E)=>c.has(E)&&(D==="proposed"||D==="held"||D==="failed")?"running":D),b=c.size>0,j=D=>D.some(E=>Vo(n[E])),N=(D,E)=>{x(new Set),E.status==="cancelled"||E.status==="expired"?m({rows:D,text:d.confirm[E.status]}):E.status==="rejected"&&E.reason==="confirm_required"?m({rows:D,text:d.chat.closeSetup}):E.status!=="applied"&&m({rows:D,text:Ee.notSent})},$=(D,E)=>{i(null),m(null),x(new Set(D)),t.act(s,D,E).then(z=>N(D,z),()=>N(D,{status:"failed"}))},C=D=>j(D)?i(D):$(D),M=D=>{t.ignoreTurn(s,D)};if(a!==void 0){const D=E=>S.filter(z=>z===E).length;return e.jsxs("p",{className:"flex flex-wrap items-center gap-x-2 px-1 text-small text-muted",children:[Ee.ignored(h.length,Na(a),{done:D("done"),denied:D("denied"),failed:D("failed")}),!r&&e.jsx("button",{type:"button",className:rs,onClick:()=>M(!0),children:Ee.review})]})}const v=e.jsx("button",{type:"button",className:rs,disabled:b,onClick:()=>M(),children:Ee.ignore}),A=(D,E,z)=>{const K=z.risk==="destructive",L=e.jsxs("button",{type:"button",className:K?Yb:rs,disabled:b||j([E])&&!l,onClick:()=>C([E]),children:[ej(z),j([E])?"…":""]}),W=z.deny&&e.jsx("button",{type:"button",className:rs,disabled:b,onClick:()=>$([E],{deny:!0}),children:Ee.deny}),ae=n[E].session;if(r&&(D==="proposed"||D==="held"||D==="failed"||D==="cut"||D==="stale"||D==="running"))return e.jsx("span",{className:"text-small text-muted",children:d.chat.history.notApplied});switch(D){case"proposed":case"held":return e.jsxs(e.Fragment,{children:[!g&&D==="proposed"&&v,W,L]});case"running":return e.jsx("span",{className:"text-body text-attention",children:Ee.running});case"done":return e.jsxs("span",{className:"inline-flex items-center gap-1 text-body text-ok",children:[e.jsx(q,{name:"check",className:"size-3.5"}),Ee.done(Na(z.doneAt))]});case"failed":return e.jsxs(e.Fragment,{children:[!g&&v,e.jsx("button",{type:"button",className:rs,disabled:b||j([E])&&!l,onClick:()=>C([E]),children:Ee.retry})]});case"refused":return e.jsx("span",{className:"text-body text-muted",children:Ee.refusedState});case"denied":return e.jsxs("span",{className:"inline-flex items-center gap-1 text-body text-muted",children:[e.jsx(q,{name:"check",className:"size-3.5"}),Ee.denied(Na(z.doneAt))]});case"stale":return ae?e.jsx("a",{className:rs,href:ne({name:"thread",sessionId:ae}),children:Ee.open(z.target??"")}):null;case"cut":return e.jsxs(e.Fragment,{children:[!g&&v,W,e.jsx(xr,{})]})}},T=(D,E)=>{const z=S[E];return e.jsxs("li",{className:`grid gap-x-2.5 gap-y-1 ${g?"grid-cols-[22px_minmax(0,1fr)]":"grid-cols-1"} ${E>0?"border-t border-line pt-2.5":""}`,children:[g&&e.jsx(Di,{s:z,k:E+1,r:D,last:E===h.length-1}),e.jsxs("div",{className:"min-w-0",children:[e.jsx(Fi,{r:D,s:z,whole:!1}),z==="failed"&&e.jsx("p",{role:"alert",className:"mt-1 text-small text-danger-fg",children:Mr(Ee.failed(Li(D)))}),z==="refused"&&e.jsx("p",{role:"alert",className:"mt-1 text-small text-danger-fg",children:Mr(Ee.refused(Li(D)))}),z==="held"&&e.jsx("p",{className:"mt-1 text-small text-muted",children:Ee.held(k+1)}),z==="stale"&&e.jsx("p",{className:"mt-1 text-small text-attention",children:Ee.stale}),z==="cut"&&e.jsx("p",{className:"mt-1 text-small text-muted",children:Ee.cutNote}),z==="denied"&&e.jsx("p",{className:"mt-1 text-small text-muted",children:Ee.deniedNote(D.target??"")}),e.jsx("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:A(z,E,D)})]})]},E)},R=()=>{if(!g||r&&!S.every(K=>K==="done"))return null;if(S.every(K=>K==="done")){const K=h.map(L=>L.doneAt).filter(L=>!!L).sort().at(-1);return e.jsxs("p",{className:"inline-flex items-center gap-1.5 text-body text-ok",children:[e.jsx(q,{name:"check",className:"size-3.5"}),Ee.planDone(Na(K))]})}const D=S.indexOf("running");if(D>=0)return e.jsx("button",{type:"button",className:Pe({variant:"primary",size:"sm",block:!0}),disabled:!0,children:Ee.progress(D+1,h.length)});const E=Km(h);if(!E.rows.length)return null;const z=E.from==="start"?Ee.all(E.rows.length):E.from==="resume"?Ee.resume(k+1,E.rows.length):Ee.skip(k+1,E.rows.length);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex gap-2",children:[v,e.jsxs("button",{type:"button",className:`${pa} flex-1`,disabled:b||j(E.rows)&&!l,onClick:()=>C(E.rows),children:[z,j(E.rows)?"…":""]})]}),e.jsx("span",{className:"text-small text-muted",children:k>=0?Ee.notReplayed:Ee.inOrder})]})},P=!r&&!l&&Ko(h).open.some(D=>Vo(n[D])),_=u&&u.rows.every(D=>(h[D].state??"proposed")==="proposed"||h[D].state==="failed")?u.text:null;return e.jsxs("section",{"aria-label":Ee.label(h.length),"aria-live":"polite",className:ma,children:[e.jsx("ol",{className:"flex flex-col gap-2.5",children:h.map(T)}),R(),_&&e.jsx("p",{role:"status",className:"text-body text-muted",children:_}),P&&e.jsxs("p",{className:"text-body text-attention",children:[d.chat.closeSetup," ",e.jsx("a",{href:ne({name:"connection"}),className:"text-info underline underline-offset-2",children:d.connection.title})]}),o&&e.jsxs(dt,{labelledBy:p,onClose:()=>i(null),children:[e.jsx("h2",{id:p,className:"text-heading leading-[1.3] tracking-[-.5px]",children:o.length>1?Ee.sheet.many(o.length):Ee.sheet.one(Zb(No(h[o[0]])))}),e.jsx("ol",{className:"flex flex-col gap-2.5",children:o.map((D,E)=>e.jsxs("li",{className:`grid gap-x-2.5 ${g?"grid-cols-[22px_minmax(0,1fr)]":"grid-cols-1"}`,children:[g&&e.jsx(Di,{s:"proposed",k:D+1,r:h[D],last:E===o.length-1}),e.jsx(Fi,{r:h[D],s:"proposed",whole:!0})]},D))}),e.jsxs("p",{className:"text-small leading-[1.6] text-muted",children:[o.length>1?`${Ee.sheet.stops} `:"",d.confirm.note]}),e.jsx("button",{type:"button",className:Qb,onClick:()=>$(o),children:_t()?d.confirm.goApple:d.confirm.go}),e.jsx("button",{type:"button",className:Pe({block:!0}),onClick:()=>i(null),children:Ee.sheet.cancel})]})]})}function nj(t,s,n,a,l){return t.closedAt!==void 0?t.how==="killed"?"killed":"closed":n?"ended":a==="all"||a!=null&&a.has(s)?"closing":t.failed||l?"failed":"open"}function aj({store:t,qid:s,closes:n,canConfirm:a,sessions:l}){const{ops:r}=me(t),[o,i]=f.useState(new Set),[c,x]=f.useState(!1),[u,m]=f.useState(null),p=Object.values(r).filter(j=>ps(j.phase)).map(j=>j.message).filter(j=>j.type==="chat.relay"||j.type==="chat.launch"||j.type==="chat.close").filter(j=>j.qid===s),h=(()=>{const j=p.filter(N=>N.type==="chat.close");return j.length===0?null:j.some(N=>!N.rows)?"all":new Set(j.flatMap(N=>N.rows??[]))})(),g=c||p.length>0,y=n.map((j,N)=>{const $=l.find(C=>C.id===j.id);return{row:j,i:N,name:($==null?void 0:$.name)??j.name,state:nj(j,N,!$||!!$.exited,h,o.has(N))}}),k=y.filter(j=>j.state==="open"||j.state==="failed"),S=j=>{x(!0),m(null),i(N=>new Set([...N].filter($=>!j.includes($)))),t.closeSessions(s,j).then(N=>{N.status==="cancelled"||N.status==="expired"?m(N.status):(N.status==="failed"||N.status==="rejected")&&i($=>new Set([...$,...j]))},()=>i(N=>new Set([...N,...j]))).finally(()=>x(!1))},b={closed:d.chat.closed,killed:d.chat.killed,ended:d.chat.ended,closing:d.chat.closing,failed:d.chat.closeFailed,open:""};return e.jsxs("section",{"aria-label":d.chat.closeLabel,"aria-live":"polite",className:ma,children:[e.jsx("ul",{className:"flex flex-col gap-2",children:y.map(({row:j,i:N,name:$,state:C})=>e.jsxs("li",{className:"flex items-center justify-between gap-2",children:[e.jsxs("span",{className:"min-w-0 flex-1 truncate text-body font-semibold",children:[$," ",e.jsxs("span",{className:"font-normal text-muted",children:["· ",d.tools[j.tool]]})]}),C!=="open"&&e.jsx("span",{className:`text-body ${C==="failed"?"text-danger-fg":C==="closing"?"text-attention":"text-ok"}`,children:b[C]}),(C==="open"||C==="failed")&&e.jsx("button",{type:"button",className:rs,disabled:g||!a,onClick:()=>S([N]),children:d.chat.closeRow})]},N))}),u&&e.jsx("p",{className:"text-body text-muted",children:d.confirm[u]}),k.length>0&&!a&&e.jsxs("p",{className:"text-body text-attention",children:[d.chat.closeSetup," ",e.jsx("a",{href:ne({name:"connection"}),className:"text-info underline underline-offset-2",children:d.connection.title})]}),k.length>=2&&e.jsx("div",{className:"flex gap-2",children:e.jsx("button",{type:"button",className:pa,disabled:g||!a,onClick:()=>S(k.map(j=>j.i)),children:d.chat.closeAll(k.length)})})]})}function lj({store:t,qid:s,row:n,proposal:a,canConfirm:l,known:r,ignored:o}){const[i,c]=f.useState(null),[x,u]=f.useState(!1),[m,p]=f.useState(!1),h=a.launchedId!==void 0;if(o&&!h)return null;const g=()=>{u(!0),c(null),t.launch(s,[n]).then(k=>{k.status==="applied"?p(!0):k.status==="cancelled"||k.status==="expired"?c(k.status):(k.status==="failed"||k.status==="rejected")&&c("failed")},()=>c("failed")).finally(()=>u(!1))},y=a.failed?"failed":i;return e.jsxs("section",{"aria-label":d.chat.launchLabel,className:ma,children:[e.jsx("h3",{className:"text-body font-semibold",children:d.chat.launchHead(d.tools[a.tool],a.project)}),a.prompt&&e.jsx("p",{className:"whitespace-pre-wrap break-words text-body text-fg/80",children:a.prompt}),h&&e.jsxs("p",{role:"status",className:"text-body text-ok",children:[d.chat.launchedTo,r?bl(a.launchedId,d.chat.seeThread):d.chat.seeThread]}),!h&&y&&e.jsx("p",{role:"status",className:`text-body ${y==="failed"?"text-danger-fg":"text-muted"}`,children:y==="failed"?d.chat.notLaunched:d.confirm[y]}),!h&&!l&&e.jsxs("p",{className:"text-body text-attention",children:[d.chat.launchSetup," ",e.jsx("a",{href:ne({name:"connection"}),className:"text-info underline underline-offset-2",children:d.connection.title})]}),!h&&e.jsxs("div",{className:"flex gap-2",children:[!m&&e.jsx("button",{type:"button",className:rs,disabled:x,onClick:()=>{t.ignoreTurn(s)},children:d.chat.ignore}),e.jsx("button",{type:"button",className:pa,disabled:x||m||!l,onClick:g,children:_t()?d.confirm.goApple:d.confirm.go})]})]})}function rj({store:t,qid:s,proposals:n,canConfirm:a,sessionIds:l,ignoredAt:r}){const o=r!==void 0;return e.jsxs(e.Fragment,{children:[n.map((i,c)=>e.jsx(lj,{store:t,qid:s,row:c,proposal:i,canConfirm:a,known:l.has(i.launchedId??""),ignored:o},c)),o&&n.some(i=>i.launchedId===void 0)&&e.jsx(qu,{store:t,qid:s,at:r,rest:n.some(i=>i.launchedId!==void 0)})]})}function oj({store:t,qid:s,row:n,task:a}){const[l,r]=f.useState(!1),[o,i]=f.useState(!1),[c,x]=f.useState(!1),u=a.taskId!==void 0,m=()=>{r(!0),i(!1),t.giveTask(s,n).then(p=>{p.status==="applied"?x(!0):i(!0)},()=>i(!0)).finally(()=>r(!1))};return e.jsxs("section",{"aria-label":d.chat.task.label,className:ma,children:[e.jsxs("p",{className:"text-body",children:[e.jsx("span",{className:"font-mono text-agent",children:a.toName??a.to})," · ",e.jsx("span",{className:"font-semibold",children:a.title})]}),a.text&&e.jsx("p",{className:"whitespace-pre-wrap break-words text-body text-fg/80",children:a.text}),u&&e.jsx("p",{role:"status",className:"text-body text-ok",children:d.chat.task.given(a.ownerName??a.toName??a.to,a.taskId,d.chat.point.state[a.state??"open"])}),!u&&(o||a.failed)&&e.jsx("p",{role:"status",className:"text-body text-danger-fg",children:d.chat.task.notGiven}),!u&&e.jsx("div",{className:"flex items-center gap-3",children:e.jsx("button",{type:"button",className:pa,disabled:l||c,onClick:m,children:d.chat.task.give})})]})}function ij({store:t,qid:s,tasks:n}){return e.jsx(e.Fragment,{children:n.map((a,l)=>e.jsx(oj,{store:t,qid:s,row:l,task:a},l))})}const vo="flex flex-col gap-1.5 border-l-2 border-line pl-2.5",zi="size-3.5 flex-none fill-none stroke-current [stroke-linecap:round] [stroke-linejoin:round] [stroke-width:1.6]";function cj(t,s){const n=t.name??t.id??"";switch(t.kind){case"sessions":return d.chat.steps.sessions(s);case"pane":return d.chat.steps.pane(n);case"reply":return d.chat.steps.reply(n);case"git":case"repo":return d.chat.steps.look(n)}}function dj(t){const s=t.filter(n=>n.kind==="pane"||n.kind==="reply").map(n=>n.name??n.id).filter(n=>!!n);return[...new Set(s)]}function uj({steps:t,sessions:s,running:n}){return t.length===0?null:e.jsx("ul",{className:"flex flex-col gap-2 px-1 py-0.5","aria-label":d.chat.stepsLabel,children:t.map((a,l)=>{const r=n&&l===t.length-1;return e.jsxs("li",{className:`flex items-center gap-2 text-small text-muted ${r?"motion-safe:animate-pulse":""}`,children:[r?e.jsx("svg",{className:`${zi} motion-safe:animate-spin`,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"M21 12a9 9 0 1 1-6.22-8.56"})}):e.jsx("svg",{className:`${zi} text-ok`,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"M20 6 9 17l-5-5"})}),cj(a,s)]},`${l}:${a.kind}:${a.id??""}`)})})}const xj=t=>({busy:d.chat.busy,timeout:d.chat.timeout,failed:d.chat.failed,cancelled:d.chat.cancelled})[t];function Pi({store:t,turn:s,live:n,sessions:a,list:l,canConfirm:r,onAskAgain:o,readOnly:i=!1,limits:c,inAnswer:x}){if(s.point)return e.jsx(Cg,{store:t,turn:{...s,point:s.point},readOnly:i});const u=(n==null?void 0:n.steps)??s.steps,m=n?n.text:s.answer,p=new Map,h=new Set;for(const y of l)y.name&&(p.has(y.name)?h.add(y.name):p.set(y.name,y.id));for(const y of h)p.delete(y);const g=s.relay;return e.jsxs("div",{className:"flex flex-col gap-3",children:[s.question&&e.jsx("div",{className:"max-w-[85%] self-end whitespace-pre-wrap break-words rounded-[12px_12px_4px_12px] bg-raised px-3 py-2",children:s.question}),s.attachments&&e.jsx("div",{className:"self-end max-w-full",children:e.jsx(Cr,{store:t,refs:s.attachments,align:"end"})}),e.jsx(uj,{steps:u,sessions:a,running:!!n&&!n.text}),n&&m&&e.jsx("p",{"aria-live":"polite",className:"px-1 whitespace-pre-wrap break-words",children:m}),!n&&m&&e.jsx(Vb,{text:m,names:p}),!n&&s.answer&&e.jsx(Gb,{names:dj(u),ids:p}),!n&&s.answer&&x,!n&&s.answer&&c&&e.jsx(gj,{usage:c.usage,now:Date.now(),alert:c.alert,fresh:c.fresh,at:c.at}),!n&&s.cut&&e.jsx("span",{className:"px-1 text-small text-muted",children:d.chat.cut}),!n&&s.error&&e.jsxs("div",{className:"flex flex-col items-start gap-1.5 px-1",children:[e.jsx("p",{role:"status",className:`text-[13.5px] ${s.error==="cancelled"?"text-muted":s.error==="busy"?"text-attention":"text-danger-fg"}`,children:xj(s.error)}),(s.error==="timeout"||s.error==="failed")&&s.question&&o&&e.jsx("button",{type:"button",onClick:()=>o(s.question),className:Fe({size:"xs"}),children:d.chat.askAgain})]}),!n&&e.jsxs("fieldset",{disabled:i,className:"contents",children:[!n&&s.closes&&e.jsx(aj,{store:t,qid:s.qid,closes:s.closes,canConfirm:r,sessions:l}),!n&&!s.closes&&g&&e.jsx(Xb,{store:t,qid:s.qid,relay:g,target:l.find(y=>y.id===g.id),known:l.some(y=>y.id===g.id),ignoredAt:s.ignoredAt}),!n&&!s.closes&&s.proposals&&s.proposals.length>0&&e.jsx(rj,{store:t,qid:s.qid,proposals:s.proposals,canConfirm:r,sessionIds:new Set(l.map(y=>y.id)),ignoredAt:s.ignoredAt}),!n&&s.actions&&e.jsx(sj,{store:t,qid:s.qid,actions:s.actions,ignoredAt:s.ignoredAt,canConfirm:r,readOnly:i}),!n&&s.tasks&&s.tasks.length>0&&e.jsx(ij,{store:t,qid:s.qid,tasks:s.tasks})]})]})}function mj({harness:t,size:s=14}){const{d:n,fill:a,rule:l}=Tb[_b[t]];return e.jsx("svg",{className:`harness-${t} inline-block flex-none`,width:s,height:s,viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:n,fill:a,fillRule:l})})}function ko(t){const s=d.chat.point;switch(t.kind){case"five_hour":return s.five;case"seven_day":return s.week;case"month":return s.month;case"pool":return t.pool==="other"?s.poolOther:s.poolCursor;default:return s.model(t.model??"")}}const pj={"":"",amber:"bg-attention",red:"bg-approval"},wo={"":"",amber:"text-attention",red:"text-approval"};function Hu({pct:t,alert:s}){const n=da(t,s);return e.jsx("span",{className:"block h-[5px] overflow-hidden rounded-[2px]",style:{background:"var(--u-track)"},children:e.jsx("span",{className:`block h-full rounded-[2px] ${pj[n]}`,style:{width:`${Math.min(100,t)}%`,...n?{}:{background:"var(--u-gauge)"}}})})}function fj({label:t,w:s,now:n,alert:a}){const l=d.chat.point,r=da(s.pct,a),o=s.resetsAt?oo(s.resetsAt,n):null;return e.jsxs("div",{className:"grid grid-cols-[58px_1fr_128px] items-center gap-2 py-[3px] text-small",children:[e.jsx("span",{children:t}),e.jsx(Hu,{pct:s.pct,alert:a}),e.jsxs("span",{className:"truncate font-mono text-[12px]",children:[e.jsx("b",{className:`font-medium ${wo[r]}`,children:d.percent(s.pct)}),o&&e.jsx("small",{className:"ml-1.5 text-[11px] text-muted",children:dh(s)?s.resetsAt&&zd(s.resetsAt,n)?l.resumesOn(o):l.resumes(o):`↺ ${o}`})]})]})}function hj(t,s){const n=d.chat.point,a=n.harnessShort[t]??t;switch(s.kind){case"five_hour":return`${a} ${n.five}`;case"seven_day":return`${a} ${n.weekShort}`;case"month":return`${a} ${n.monthShort}`;case"model":return`${n.model(s.model??a)} ${n.weekShort}`;default:return null}}function gj({usage:t,now:s,alert:n,fresh:a=!0,at:l}){const r=d.chat.point,o=[],i=[];if(ua(t,s,a).forEach((x,u)=>{const m=r.harnessShort[x.harness]??x.harness,p=(k,S)=>o.push({key:x.harness,label:m,sentence:k,amber:S});if(x.status==="loading")return p(r.loading,!1);if(x.status==="expired")return p(r.notOnPc(r.harness[x.harness]??m),!0);const h=t[u];if(h.harness==="cursor"&&h.status==="ok"&&h.windows.length===0&&h.readAt!==null)return p(r.unread,!1);const g=x.status==="stale"||x.status==="unreachable",y=x.windows.flatMap(k=>{const S=hj(x.harness,k);return S?[{key:`${x.harness}:${k.kind}:${k.model??""}`,label:S,w:k,dim:g}]:[]});if(y.length){o.push(...y),g&&x.readAt&&i.push(Date.parse(x.readAt));return}x.status==="unreachable"&&p(x.readAt?r.unreach(Ka(Math.max(0,s-Date.parse(x.readAt)))):r.unreachNever,!0)}),!o.length)return null;const c=Math.min(Date.parse(l),...i);return e.jsxs("div",{role:"group","aria-label":r.limitsLabel,className:vo,children:[e.jsx("div",{className:"flex flex-col",children:o.map(x=>{if("sentence"in x)return e.jsxs("div",{className:"grid grid-cols-[66px_1fr] items-center gap-2 py-0.5 text-[12px]",children:[e.jsx("span",{className:"whitespace-nowrap",children:x.label}),e.jsx("span",{className:x.amber?"text-attention":"text-muted",children:x.sentence})]},x.key);const u=da(x.w.pct,n);return e.jsxs("div",{className:`grid grid-cols-[66px_1fr_118px] items-center gap-2 py-0.5 text-[12px] ${x.dim?"opacity-50":""}`,children:[e.jsx("span",{className:"whitespace-nowrap",children:x.label}),e.jsx(Hu,{pct:x.w.pct,alert:n}),e.jsxs("span",{className:"whitespace-nowrap font-mono text-[12px]",children:[e.jsx("b",{className:u?`font-medium ${wo[u]}`:"font-normal",children:d.percent(x.w.pct)}),x.w.resetsAt&&e.jsxs("small",{className:"ml-[5px] text-[11px] text-muted",children:["↺ ",oo(x.w.resetsAt,s,!0)]})]})]},x.key)})}),o.some(x=>"w"in x)&&e.jsx("span",{className:"text-[11.5px] text-muted",children:r.stale(Ka(Math.max(0,s-c)))})]})}function bj({usage:t,now:s,alert:n,fresh:a=!0}){const l=d.chat.point,r=ua(t,s,a);if(!r.length)return null;const o=i=>t[i].harness==="cursor"&&t[i].status==="ok"&&t[i].windows.length===0&&t[i].readAt!==null;return e.jsxs("div",{role:"group","aria-label":l.limitsLabel,className:"flex flex-col",children:[e.jsx("h3",{className:"mt-1 text-meta tracking-[.4px] text-muted",children:l.limits}),r.map((i,c)=>{const x=i.readAt?Ka(s-Date.parse(i.readAt)):null,u=i.status==="stale"||i.status==="unreachable";return e.jsxs("div",{"data-harness":i.harness,className:"flex flex-col",children:[e.jsxs("div",{className:"mt-1.5 mb-0.5 flex items-baseline gap-1.5 text-small font-semibold",children:[e.jsx(mj,{harness:i.harness}),l.harness[i.harness]??i.harness]}),i.status==="loading"&&e.jsx("p",{className:"py-1 text-small text-muted",children:l.loading}),i.status==="expired"&&e.jsx("p",{className:"py-1 text-small text-attention",children:l.notOnPc(l.harness[i.harness]??i.harness)}),i.status==="ok"&&o(c)&&e.jsx("p",{className:"py-1 text-small text-muted",children:l.unread}),i.status!=="loading"&&i.status!=="expired"&&i.windows.length>0&&e.jsx("div",{className:u?"opacity-50":void 0,children:i.windows.map(m=>e.jsx(fj,{label:ko(m),w:m,now:s,alert:n},`${m.kind}:${m.model??m.pool??""}`))}),i.status==="stale"&&x&&e.jsx("p",{className:"py-1 text-small text-attention",children:l.stale(x)}),i.status==="unreachable"&&e.jsx("p",{className:"py-1 text-small text-attention",children:x?l.unreach(x):l.unreachNever})]},i.harness)})]})}const Ot=d.thread.rig,jj="inline-flex items-center gap-1 whitespace-nowrap text-small text-muted",yj="inline-flex items-center gap-1 whitespace-nowrap text-small font-medium text-fg",Uu="mt-1.5 rounded-[6px] border border-line bg-well px-2.5 py-2 font-mono text-meta whitespace-pre-wrap text-muted [overflow-wrap:anywhere]",jl=()=>e.jsx("div",{className:"text-meta text-muted",children:d.thread.cut});function Nj({session:t}){const s=nn(),n=t.state==="exited"?"done":t.state==="waiting_input"?"question":t.state==="waiting_permission"?"approval":t.state;return e.jsx("span",{className:"inline-flex flex-none","aria-hidden":"true",children:e.jsx(rl,{tool:t.tool,seed:t.id,state:n,pose:ll(t.id,n),size:16,theme:s,frozen:!0})})}function vj({lead:t,who:s,children:n}){return e.jsxs("div",{className:"flex flex-wrap items-center gap-1.5 text-meta leading-5 font-medium text-muted",children:[e.jsx("span",{children:t}),s.session&&e.jsx(Nj,{session:s.session}),e.jsx("strong",{className:"font-semibold text-fg",children:s.name}),s.seat&&e.jsx("span",{className:"font-mono font-normal",children:s.seat}),n]})}function fa(t){const[s,n]=f.useState(!1),a=t&&e.jsx("button",{type:"button","aria-expanded":s,onClick:()=>n(r=>!r),className:jj,children:t.label}),l=t&&s&&e.jsx("pre",{className:Uu,children:t.text});return{toggle:a,box:l}}function kj({e:t,storage:s}){const{toggle:n,box:a}=fa(t.raw),l=t.dir==="out",r=t.delivery&&Ot.sent[t.delivery];return e.jsxs("div",{className:`flex flex-col gap-1 ${l?"items-end":"items-start"}`,children:[e.jsxs("article",{"aria-label":l?`${Ot.to} ${t.who.name}`:`${Ot.from} ${t.who.name}`,className:`flex max-w-[92%] min-w-0 flex-col gap-1 px-3.5 py-2.5 ${l?"rounded-2xl rounded-br-[4px] bg-raised":"rounded-2xl rounded-bl-[4px] border border-line bg-surface"}`,children:[e.jsxs(vj,{lead:l?Ot.to:Ot.from,who:t.who,children:[t.count&&e.jsx("span",{className:"inline-flex h-[18px] items-center rounded-full bg-attention/12 px-1.5 text-[10.5px] text-attention",children:Ot.twice(t.count)}),l&&r&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:t.delivery==="failed"?"text-attention":"",children:r})]})]}),e.jsx("div",{className:"text-body whitespace-pre-wrap [overflow-wrap:anywhere]",children:t.text}),(t.reply||n)&&e.jsxs("div",{className:"mt-0.5 flex flex-wrap items-center gap-3",children:[t.reply&&e.jsxs("a",{href:ne({name:"thread",sessionId:t.reply.sessionId}),onClick:()=>bb(t.reply.sessionId,t.reply.draft,s),"aria-label":Ot.replyTo(t.who.name),className:yj,children:[e.jsx(q,{name:"reply",className:"size-3.5"}),Ot.reply]}),n]}),a]}),t.cut&&e.jsx(jl,{})]})}const Bi="inline-flex h-5 items-center rounded-full px-2 text-meta font-medium whitespace-nowrap",wj={pending:"bg-raised text-muted",taken:"bg-[var(--status-info-soft)] text-info",passed:"bg-task/14 text-task",blocked:"bg-[var(--status-warning-soft)] text-attention",done:"bg-[var(--status-success-soft)] text-ok",unknown:"border border-dashed border-line text-muted"};function Sj(t){const[s,n]=f.useState(typeof IntersectionObserver>"u");return f.useEffect(()=>{const a=t.current;if(!a||typeof IntersectionObserver>"u")return;const l=new IntersectionObserver(r=>n(r.some(o=>o.isIntersecting)));return l.observe(a),()=>l.disconnect()},[t]),s}function $j(t,s,n){var o,i;const a=me(t),l=((o=a.daemon)==null?void 0:o.rigRows)===!0,r=!!s&&n&&l&&a.fresh;return f.useEffect(()=>{if(!r)return;t.requestRigRow(s);const c=setInterval(()=>t.requestRigRow(s),mm);return()=>clearInterval(c)},[r,t,s]),s&&l?(i=a.rigRows[s])==null?void 0:i.row:void 0}function Cj({e:t,store:s}){const{toggle:n,box:a}=fa(t.raw),l=f.useRef(null),r=Sj(l),o=$j(s,t.qitem,r),i=t.refused?null:Of(o,t.outgoing),c=t.refused?t.refused.log:i==null?void 0:i.log;return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("section",{ref:l,"aria-label":t.outgoing?Ot.rowOut(t.who.name):Ot.rowIn(t.who.name),className:"flex w-full flex-col gap-1.5 rounded-[10px] border border-l-[3px] border-task/35 border-l-task bg-surface px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-small font-medium text-task",children:[e.jsx(q,{name:"task",className:"size-3.5"}),e.jsx("span",{className:"min-w-0 truncate",children:t.outgoing?Ot.rowOut(t.who.name):Ot.rowIn(t.who.name)}),e.jsx("span",{className:"flex-1"}),i?e.jsx("span",{"data-state":i.key,className:`${Bi} ${wj[i.key]}`,children:i.text}):e.jsx("span",{"data-state":"refused",className:`${Bi} bg-danger-bg text-danger-fg`,children:Ot.rowState.refused})]}),e.jsx("h4",{className:"line-clamp-2 text-[0.90625rem] leading-[1.3125rem] font-semibold [overflow-wrap:anywhere]",children:t.title}),c&&e.jsx("p",{className:"text-small text-muted [overflow-wrap:anywhere]",children:c}),n&&e.jsxs("div",{className:"flex items-center border-t border-dashed border-line pt-1.5",children:[e.jsx("span",{className:"flex-1"}),n]}),a]}),t.cut&&e.jsx(jl,{})]})}function Wu({e:t}){const{toggle:s,box:n}=fa(t.raw),a=t.tone==="warn"?"border-l-attention":t.tone==="task"?"border-l-task":"border-l-line";return e.jsxs("div",{role:"note",className:`min-w-0 border-l-2 ${a} py-0.5 pl-2.5 text-small leading-5 text-muted`,children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("span",{className:`text-[10px] font-medium tracking-[.04em] uppercase ${t.tone==="task"?"text-task":""}`,children:Ot.openrig}),e.jsx("span",{className:`min-w-0 font-medium [overflow-wrap:anywhere] ${t.tone==="warn"?"text-attention":"text-fg"}`,children:t.title}),e.jsx("span",{className:"flex-1"}),s]}),n,t.cut&&e.jsx(jl,{})]})}function Mj({e:t}){const[s,n]=f.useState(!1);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsxs("button",{type:"button","aria-expanded":s,onClick:()=>n(a=>!a),className:"flex items-center gap-1.5 py-0.5 text-left text-small text-muted",children:[e.jsx("span",{className:`inline-flex transition-transform motion-reduce:transition-none ${s?"rotate-90":""}`,children:e.jsx(q,{name:"chevron",className:"size-3.5"})}),e.jsx("strong",{className:"font-medium text-fg",children:Ot.folded(t.notices.length)})]}),s&&t.notices.map(a=>e.jsx(Wu,{e:a},a.key))]})}function Ej({e:t}){return e.jsxs("div",{className:"flex flex-col gap-1 border-l-2 border-dashed border-line pl-2.5",children:[e.jsx("div",{className:"text-meta leading-5 font-medium text-muted",children:Ot.unreadable}),e.jsx("pre",{className:Uu.replace("mt-1.5 ",""),children:t.text}),t.cut&&e.jsx(jl,{})]})}function Rj({e:t}){const{toggle:s,box:n}=fa(t.raw);return e.jsxs("div",{className:"-mt-2 flex flex-col items-start",children:[s,n&&e.jsx("div",{className:"w-full",children:n})]})}function Aj({e:t,storage:s,store:n}){switch(t.kind){case"rig-message":return e.jsx(kj,{e:t,storage:s});case"rig-task":return e.jsx(Cj,{e:t,store:n});case"rig-notice":return e.jsx(Wu,{e:t});case"rig-fold":return e.jsx(Mj,{e:t});case"rig-unreadable":return e.jsx(Ej,{e:t});case"rig-raw":return e.jsx(Rj,{e:t})}}const vs=d.thread.task,Tj={killed:{tone:"attention",text:"text-attention",icon:"stop"},completed:{tone:"ok",text:"text-ok",icon:"check"},failed:{tone:"danger",text:"text-danger-fg",icon:"close"},other:{tone:"muted",text:"text-muted",icon:"task"}};function _j({task:t,cut:s}){const{toggle:n,box:a}=fa({label:vs.raw,text:t.raw}),l=Tj[t.status],r=vs.statuses[t.status],{about:o}=t,i=(o==null?void 0:o.kind)==="command"?o.code:void 0,c=[i!==void 0?vs.code(i):null,t.output??null].filter(Boolean).join(" · ");return e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsxs("section",{"aria-label":vs.label(r),"data-status":t.status,className:"flex w-full flex-col gap-1.5 rounded-[10px] border border-line bg-surface px-3.5 py-2.5",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(q,{name:l.icon,className:`size-3.5 ${l.text}`}),e.jsx("span",{className:"text-meta font-medium tracking-[.04em] text-muted uppercase",children:vs.kicker}),e.jsx("span",{className:"flex-1"}),e.jsx(ra,{tone:l.tone,label:r})]}),e.jsx("p",{className:"text-body [overflow-wrap:anywhere]",children:(o==null?void 0:o.kind)==="agent"?e.jsxs(e.Fragment,{children:[vs.agent," ",e.jsx("strong",{className:"font-semibold",children:o.name})," ",vs.agentDid[t.status]]}):(o==null?void 0:o.kind)==="command"?e.jsxs(e.Fragment,{children:[vs.command," ",e.jsx("code",{className:"rounded-[4px] bg-fg/[0.05] px-1 font-mono text-[.9em]",children:o.command})," ",vs.commandDid[t.status]]}):t.summary}),c&&e.jsx("p",{className:"font-mono text-meta text-muted [overflow-wrap:anywhere]",children:c}),e.jsxs("div",{className:"flex items-center border-t border-dashed border-line pt-1.5",children:[e.jsx("span",{className:"flex-1"}),n]}),a]}),s&&e.jsx("div",{className:"text-meta text-muted",children:d.thread.cut})]})}const mn=d.images;let Ij=0;const Lj=t=>`data:${t.mime};base64,${t.data}`;function Ku(t){const[s,n]=f.useState([]),[a,l]=f.useState(0),[r,o]=f.useState(null),i=f.useRef([]),c=f.useRef(0),x=f.useRef(!0);f.useEffect(()=>(x.current=!0,()=>{x.current=!1}),[]);const u=j=>{i.current=j,n(j)},m=(j,N)=>{x.current&&u(i.current.map($=>$.item.key===j?{...$,...N,item:{...$.item,...N.item}}:$))},p=j=>{c.current+=j,l(c.current)},h=async j=>{const N=await Sb(j);if(p(-1),!x.current)return;if(!N.ok){o(N.reason==="tooLarge"?mn.tooLarge:mn.notImage);return}const{image:$,width:C,height:M,bytes:v}=N.value,A=`att-${Ij++}`;u([...i.current,{item:{key:A,url:Lj($.preview??$),width:C,height:M,bytes:v,state:"uploading"}}]);try{const T=await t.putImage($);m(A,{id:T.id,item:{state:"ready"}})}catch(T){const R=T instanceof Error&&T.message==="too_large"?mn.tooLarge:T instanceof Error&&T.message==="not_image"?mn.notImage:mn.failed;m(A,{item:{state:"refused",reason:R}}),x.current&&o(R)}},g=j=>{if(j.length!==0){o(null);for(const N of j){if(i.current.length+c.current>=Fo){o(mn.max);return}p(1),h(N)}}},y=j=>{const N=i.current.find($=>$.item.key===j);u(i.current.filter($=>$.item.key!==j)),(N==null?void 0:N.item.state)==="refused"&&o(null)},k=()=>{const j=i.current;return u([]),o(null),j},S=j=>{x.current&&u([...j,...i.current].slice(0,Fo))},b=s.map(j=>j.item);return{items:b,add:g,remove:y,clear:k,putBack:S,error:r,ready:a===0&&b.every(j=>j.state==="ready"),ids:()=>i.current.filter(j=>j.item.state==="ready"&&j.id).map(j=>j.id)}}const Vu=`${Cs}launch.started`;function Gu(t){var s;try{const n=JSON.parse(((s=Qe(t))==null?void 0:s.getItem(Vu))??"[]");return Array.isArray(n)?n.filter(a=>typeof(a==null?void 0:a.id)=="string"&&typeof(a==null?void 0:a.project)=="string"):[]}catch{return[]}}function Oj(t,s,n){var l;const a=[...Gu(n).filter(r=>r.id!==t),{id:t,project:s}].slice(-50);try{(l=Qe(n))==null||l.setItem(Vu,JSON.stringify(a))}catch{}}const Dj=(t,s)=>{var n;return((n=Gu(s).find(a=>a.id===t))==null?void 0:n.project)??null};function Fj(t){const s=/^\/(\S*)$/.exec(t);return s?s[1].toLowerCase():null}function zj(t,s){var l;const n=s.toLowerCase(),a=[];for(const r of t){const o=[r.name,...r.aliases??[]],i=o.map(g=>g.toLowerCase());let c=-1,x=r.name,u=-1;const m=i.indexOf(n),p=i.findIndex(g=>g.startsWith(n)),h=i.findIndex(g=>g.includes(n));m>=0&&n?(c=0,x=o[m],u=0):p>=0?(c=1,x=o[p],u=0):h>=0?(c=2,x=o[h],u=i[h].indexOf(n)):(l=r.description)!=null&&l.toLowerCase().includes(n)&&(c=3),!(c<0)&&(x!==r.name&&r.name.toLowerCase().startsWith(n)&&(x=r.name,u=0),a.push({command:r,shown:x,at:n?u:-1,rank:c}))}return a.sort((r,o)=>r.rank-o.rank||+!!r.command.blocked-+!!o.command.blocked||r.shown.localeCompare(o.shown)).map(({rank:r,...o})=>o)}function Pj(t,s){const n=/^\/(\S+)/.exec(t.trimStart());if(!n)return;const a=n[1].toLowerCase();return s.find(l=>{var r;return l.name.toLowerCase()===a||((r=l.aliases)==null?void 0:r.some(o=>o.toLowerCase()===a))})}const Bj=t=>`/${t.name} `,Us=d.thread.slash;function qj({listing:t,query:s,matches:n,tool:a,name:l,onPick:r}){const o="mb-2 overflow-hidden rounded-2xl border border-line bg-surface";return t?t.error?e.jsx("div",{className:`${o} px-3 py-3 text-meta text-muted`,role:"status",children:Us.unavailable(l)}):n.length===0?e.jsx("div",{className:`${o} px-3 py-3 text-meta text-muted`,role:"status",children:Us.none(`/${s}`,l)}):e.jsxs("div",{className:o,children:[e.jsx("p",{className:"px-3 pt-2 pb-1 text-meta text-muted",children:Us.count(a,n.length)}),e.jsx("ul",{"aria-label":Us.label(a),className:"max-h-[300px] overflow-y-auto overscroll-contain px-1 pb-1",children:n.map(i=>{const c=i.command,x=c.blocked!==void 0,u=s.length,m=Us.source[c.source];return e.jsx("li",{className:"border-t border-line first:border-t-0",children:e.jsxs("button",{type:"button",disabled:x,onMouseDown:p=>p.preventDefault(),onClick:()=>r(c),className:"flex min-h-[52px] w-full flex-col justify-center rounded-[10px] px-2.5 py-1.5 text-left enabled:active:bg-raised",children:[e.jsxs("span",{className:`font-mono text-[14px] leading-5 ${x?"text-muted":""}`,children:["/",i.at>=0&&u>0?e.jsxs(e.Fragment,{children:[i.shown.slice(0,i.at),e.jsx("mark",{className:"bg-transparent font-semibold text-fg underline underline-offset-2",children:i.shown.slice(i.at,i.at+u)}),i.shown.slice(i.at+u)]}):i.shown,c.argumentHint&&e.jsxs("span",{className:"text-[12px] text-muted",children:[" ",c.argumentHint]}),m&&e.jsx("span",{className:`ml-1.5 font-sans text-[10.5px] ${c.source==="project"?"text-info":"text-muted"}`,children:m})]}),e.jsx("span",{className:`truncate text-[12px] leading-4 ${x?"text-attention":"text-muted"}`,children:x?Us.blocked[c.blocked]:c.description})]})},c.name)})})]}):e.jsx("div",{className:`${o} px-3 py-3 text-meta text-muted`,role:"status",children:Us.loading(a)})}const Hj={ok:"text-ok",info:"text-info",approval:"text-approval",attention:"text-attention",muted:"text-muted"},Lt=d.thread.composer;function Xu(t){const s=t.trim();return s.length>ta?"long":Tc.test(s)?"untypable":null}function Uj(t){if(t.phase==="uncertain"||t.reason==="not_taken")return{title:Lt.uncertainTitle,body:Lt.uncertain};const s=t.reason==="busy"?Lt.busy:t.reason==="invalid"?Lt.invalid(ta):t.reason==="untypable"?Lt.untypable:t.reason==="read_only"?Lt.readOnly:t.reason==="attachment_missing"?Lt.imageGone:t.reason==="attachments_not_accepted"?d.images.dialog:Lt.lost;return{title:Lt.failTitle,body:s}}function Wj({name:t,focusAtEnd:s=!1,composer:n,draft:a,onDraft:l,onSend:r,fresh:o,taken:i,checking:c,error:x,alert:u,onReconnect:m,images:p,dialog:h,lead:g,leadNote:y,slash:k}){var E,z;const[S,b]=Cn(),j=i?{tone:"ok",label:Lt.status.taken}:c?{tone:"muted",label:d.decide.checking}:n.status,N=Xu(a),$=f.useRef(null),C=p.items.length>0;f.useEffect(()=>{const K=$.current;!s||!K||(K.focus(),K.setSelectionRange(K.value.length,K.value.length))},[]);const M=k&&n.enabled&&!h?Fj(a):null,v=M!==null;f.useEffect(()=>{v&&(k==null||k.ask())},[v]);const A=(E=k==null?void 0:k.listing)!=null&&E.error?[]:((z=k==null?void 0:k.listing)==null?void 0:z.commands)??[],T=f.useMemo(()=>M!==null?zj(A,M):[],[M,A]),R=k&&!h?Pj(a,A):void 0,P=K=>{var L;l(Bj(K)),(L=$.current)==null||L.focus()},_=!R||M!==null?null:R.blocked?{warn:!0,text:d.thread.slash.blocked[R.blocked]}:R.bare&&/^\/\S+\s*$/.test(a)?{warn:!0,text:d.thread.slash.bare(R.name)}:R.argumentHint?{warn:!1,text:`/${R.name} ${R.argumentHint}`}:null,D=n.enabled&&(!!a.trim()||C)&&N===null&&p.ready&&!(C&&h);return e.jsxs("footer",{className:"flex-none border-t border-line bg-bg pt-2 pb-3 [@media(max-height:650px)]:pb-2",children:[e.jsxs("div",{className:`flex items-center gap-1.5 pb-2 text-meta ${Hj[j.tone]}`,children:[e.jsx("i",{className:"inline-block size-1.5 flex-none rounded-full bg-current"}),j.label]}),u&&e.jsx("div",{className:"mb-2.5",children:u}),!u&&x&&e.jsx("div",{className:"mb-2.5",children:e.jsxs(Xe,{title:x.title,tone:"warning",role:"alert",children:[e.jsx("p",{children:x.body}),!o&&m&&e.jsx("button",{type:"button",disabled:S,onClick:()=>{b(!0),m()},className:Pe({block:!0,className:"mt-2"}),children:S?d.link.reconnecting:Lt.reconnect})]})}),v&&e.jsx(qj,{listing:k.listing,query:M,matches:T,tool:k.tool,name:t,onPick:P}),!v&&(n.enabled||g)&&e.jsxs("div",{role:"group","aria-label":Lt.quickLabel,className:"flex gap-1.5 overflow-x-auto pb-2 [scrollbar-width:none]",children:[g,n.enabled&&Uf.map(K=>e.jsx("button",{type:"button",onClick:()=>{var L;l(K),(L=$.current)==null||L.focus()},className:`${Ic()} whitespace-nowrap`,children:K},K))]}),y,e.jsx(Ab,{id:"draft",label:Lt.label(t),sendLabel:Lt.send(t),value:a,onChange:l,onSend:r,canSend:D,oneLine:!0,images:p,placeholder:n.placeholder,disabled:!n.enabled,fieldRef:$,invalid:N!==null,describedBy:N?"draft-problem":void 0}),_&&e.jsx("p",{role:"status",className:`pt-1.5 text-meta ${_.warn?"text-attention":"font-mono text-muted"}`,children:_.text}),C&&h&&e.jsx("p",{role:"status",className:"pt-1.5 text-meta text-attention",children:d.images.dialog}),p.error&&e.jsx("p",{role:"alert",className:"pt-1.5 text-meta text-attention",children:p.error}),N&&e.jsx("p",{id:"draft-problem",role:"status",className:"pt-1.5 text-meta text-attention",children:N==="long"?Lt.tooLong(ta):Lt.untypable})]})}const Ue=d.sessionEnd,In=t=>Pe({variant:t,block:!0});function Yu(t,s,n,a,l){const[r,o]=f.useState(null),[i,c]=f.useState(null),[x,u]=f.useState(!1),[m,p]=f.useState(0),h=f.useRef(!0);return f.useEffect(()=>(h.current=!0,()=>{h.current=!1}),[]),f.useEffect(()=>{if(!a)return;let S=!0,b;return o(null),t.prepareConfirm(s==="terminal"?{purpose:s,id:n}:{purpose:s,id:n}).then(j=>{S&&(o(j),b=setTimeout(()=>{S&&(o(null),c("expired"))},j.expiresInMs))},()=>{S&&c("prepareFailed")}),()=>{S=!1,clearTimeout(b)}},[t,s,n,a,m]),{challenge:r,problem:i,asking:x,needsNew:i==="expired"||i==="failed"||i==="prepareFailed",go:async()=>{if(!a||x||!r)return;if(!r.credentialId){o(null),c("failed");return}u(!0),c(null);const S=await sa({challenge:r.challenge,rpId:r.rpId,credentialId:r.credentialId}).catch(()=>"failed");if(h.current){if(u(!1),S==="cancelled"){c("cancelled");return}if(S==="failed"){o(null),c("failed");return}o(null),l(S)===null&&c("failed")}},retry:()=>{c(null),p(S=>S+1)}}}function So({store:t,session:s,mode:n,onClose:a,onSent:l,onReconnect:r}){const{fresh:o,device:i}=me(t),[c,x]=Cn(),u=s.name,m=n==="close",p=!!(i!=null&&i.confirm),h=Yu(t,m?"close":"act",s.id,o&&p,S=>{const b=m?t.sessionClose(s.id,S):t.sessionResume(s.id,S);return b!==null&&l(),b}),g=m?Vm(s):[],y=h.asking?d.confirm.asking:h.challenge?m?_t()?Ue.goCloseApple:Ue.goClose:_t()?Ue.goResumeApple:Ue.goResume:d.confirm.preparing,k=e.jsx("button",{type:"button",onClick:a,className:In(),children:Ue.cancel});return e.jsxs(dt,{labelledBy:"end-title",onClose:a,children:[e.jsx("h2",{id:"end-title",className:"text-heading leading-[1.3] tracking-[-.5px]",children:m?Ue.closeTitle(u):Ue.resumeTitle(u)}),o?p?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:m?Ue.closeBody:Ue.resumeBody}),g.length>0&&e.jsx(Xe,{title:Ue.cutsTitle,tone:"warning",children:e.jsx("ul",{className:"flex list-disc flex-col gap-1 pl-5",children:g.map(S=>e.jsx("li",{children:S},S))})}),h.problem&&e.jsx(Xe,{title:d.confirm[h.problem],tone:"warning",role:"alert"}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:g.length>0?`${Ue.force} ${Ue.check}`:Ue.check}),h.needsNew?e.jsx("button",{type:"button",onClick:h.retry,className:In("primary"),children:d.confirm.retry}):e.jsx("button",{type:"button",disabled:h.asking||!h.challenge,onClick:()=>{h.go()},className:In("primary"),children:y}),k]}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{title:Ue.unprotectedTitle,tone:"warning",role:"status",children:e.jsx("p",{children:m?Ue.unprotectedClose(u):Ue.unprotectedResume(u)})}),e.jsx("a",{href:ne({name:"connection"}),className:In("primary"),children:Ue.openConnection}),k]}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{title:Ue.offlineTitle,tone:"warning",role:"status",children:e.jsx("p",{children:m?Ue.offlineClose(u):Ue.offlineResume(u)})}),r&&e.jsx("button",{type:"button",disabled:c,onClick:()=>{x(!0),r()},className:In("primary"),children:c?d.link.reconnecting:Ue.reconnect}),k]})]})}function qi({tone:t,label:s}){return e.jsxs("div",{className:`flex items-center gap-1.5 text-meta ${t==="attention"?"text-attention":"text-info"}`,children:[e.jsx(q,{name:"spinner",className:"size-3 animate-spin motion-reduce:animate-none",stroke:2}),s]})}function Qu({error:t,fresh:s,onRetry:n,onReconnect:a}){const[l,r]=Cn();return e.jsxs(Xe,{title:t.title,tone:"warning",role:"alert",children:[e.jsx("p",{children:t.body}),t.retry&&e.jsx("button",{type:"button",onClick:n,className:Pe({size:"sm",className:"mt-2"}),children:Ue.retry}),t.reconnect&&!s&&a&&e.jsx("button",{type:"button",disabled:l,onClick:()=>{r(!0),a()},className:Pe({size:"sm",className:"mt-2"}),children:l?d.link.reconnecting:Ue.reconnect})]})}function Kj({ending:t,name:s,canResume:n,resumeHeld:a=!1,readOnly:l,fresh:r,focus:o,onResume:i,onReconnect:c}){const x=f.useRef(null);return f.useEffect(()=>{var u;o&&((u=x.current)==null||u.focus({preventScroll:!0}))},[o]),e.jsxs("footer",{ref:x,tabIndex:-1,role:"status",className:"flex flex-none flex-col gap-2.5 border-t border-line bg-bg pt-3 pb-3 outline-none [@media(max-height:650px)]:pb-2",children:[t.kind==="closing"&&e.jsxs(e.Fragment,{children:[e.jsx(qi,{tone:"attention",label:Ue.closing(s)}),e.jsx("p",{className:"text-small text-muted",children:Ue.closingHint})]}),t.kind==="resuming"&&e.jsx(qi,{tone:"info",label:Ue.resuming(s)}),t.kind==="ended"&&e.jsxs(e.Fragment,{children:[t.error&&e.jsx(Qu,{error:t.error,fresh:r,onRetry:i,onReconnect:c}),e.jsxs("section",{"aria-labelledby":"ended-title",className:"flex flex-col gap-2.5 rounded-card border border-line bg-surface p-4",children:[e.jsx("h2",{id:"ended-title",className:"text-body font-semibold",children:Ue.ended}),t.killed?e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:Ue.killed}):!l&&e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:n?Ue.endedBody:Ue.endedOnPc}),n&&!l&&e.jsxs("button",{type:"button","aria-disabled":a||void 0,onClick:()=>{a||i()},className:Pe({variant:t.killed?"outline":"primary",block:!0,className:a?"opacity-45":""}),children:[e.jsx(q,{name:"resume"}),Ue.resume(s)]})]})]})]})}function Vj({text:t}){const s=f.useMemo(()=>ku(t),[t]);return e.jsx(Bu,{doc:s})}const Hi=({align:t})=>e.jsx("div",{className:`text-meta text-muted ${t==="end"?"text-right":""}`,children:d.thread.cut}),Ui={success:{glyph:"✓",tone:"text-ok"},running:{glyph:"●",tone:"text-info"},failed:{glyph:"✕",tone:"text-danger-fg"},unknown:{glyph:"·",tone:"text-muted"}};function Gj({tools:t}){const[s,n]=f.useState(!1),a=d.sessions;return e.jsxs("div",{className:"rounded-lg border border-line font-mono text-small leading-4 text-muted",children:[e.jsxs("button",{type:"button","aria-expanded":s,onClick:()=>n(l=>!l),className:"flex h-[34px] w-full items-center gap-1.5 px-2.5 text-left font-sans text-[12.5px]",children:[e.jsx(q,{name:"chevron",className:`size-3.5 transition-transform ${s?"rotate-90":""}`}),e.jsx("span",{className:"min-w-0 truncate",children:s?a.tools(t.length):a.toolsNamed(t.length,Df(t).join(", "))})]}),s&&e.jsx("ul",{className:"pb-2",children:t.map(l=>e.jsxs("li",{className:"flex gap-1.5 px-2.5 py-[3px]",children:[e.jsx("span",{"aria-label":a.toolStatus[l.status],role:"img",className:Ui[l.status].tone,children:Ui[l.status].glyph}),e.jsxs("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:[e.jsx("b",{className:"font-medium text-fg",children:l.name})," ",l.label]})]},l.id))})]})}function Xj({store:t,item:s,onReconnect:n,keys:a}){var i,c,x;const l=me(t),r=Fs(),o=l.sessions.get(s.sessionId);return e.jsx(io,{store:t,item:s,session:o,inThread:!0,keys:a,mode:Qr(s,(i=l.capabilities)==null?void 0:i[s.tool],(o==null?void 0:o.readOnly)===!0),outcome:Gn(s,[...l.sessions.values()],l.ops),fresh:l.fresh,ghost:!1,changed:!1,onReread:()=>{},canConfirm:((c=l.device)==null?void 0:c.confirm)===!0&&r,enroll:r&&((x=l.device)==null?void 0:x.confirm)!==!0,onGone:()=>{},onCheck:n})}function Yj({item:t,store:s,storage:n,inPanel:a=!1,onReconnect:l,keys:r=!1}){switch(t.kind){case"tools":return e.jsx(Gj,{tools:t.tools});case"time":return e.jsx("div",{className:"text-center font-mono text-meta text-muted",children:t.label});case"rig-message":case"rig-task":case"rig-notice":case"rig-fold":case"rig-unreadable":case"rig-raw":return e.jsx(Aj,{e:t,storage:n,store:s});case"me":{const o=t.images??(t.attachments??[]).flatMap(i=>s.knownImage(i)??[]);return e.jsxs("div",{className:"flex flex-col items-end gap-1",children:[t.text&&e.jsx("div",{className:"max-w-[94%] rounded-2xl rounded-br-[4px] bg-raised p-3.5 text-body [overflow-wrap:anywhere] whitespace-pre-wrap",children:t.text}),e.jsx(Cr,{store:s,refs:o,align:"end"}),t.cut&&e.jsx(Hi,{align:"end"}),t.delivery&&e.jsx("div",{role:t.delivery==="sending"?"status":void 0,className:`text-meta ${t.delivery==="uncertain"?"text-attention":t.delivery==="sending"?"text-muted":"text-ok"}`,children:t.delivery==="sending"?d.thread.delivery.sending:t.delivery==="uncertain"?d.thread.delivery.uncertain:t.fresh?d.thread.delivery.takenNow:d.thread.delivery.taken})]})}case"agent":return e.jsxs("div",{className:"flex flex-col items-start gap-1",children:[e.jsx("article",{"aria-label":d.thread.agentLabel,className:"max-w-[94%] rounded-2xl rounded-bl-[4px] border border-line bg-surface p-3.5 text-body [overflow-wrap:anywhere]",children:e.jsx(Vj,{text:t.text})}),t.cut&&e.jsx(Hi,{align:"start"})]});case"task":return e.jsx(_j,{task:t.task,cut:t.cut});case"capture":{const o=t.images[0];return e.jsxs("div",{className:"flex flex-col items-start gap-1",children:[e.jsxs("div",{className:"text-meta text-muted",children:[e.jsx("span",{"aria-hidden":!0,children:"✓"})," ",e.jsx("span",{children:t.label}),o&&e.jsxs(e.Fragment,{children:[" ",e.jsxs("span",{className:"font-mono",children:[o.width,"×",o.height]})]})]}),e.jsx(Cr,{store:s,refs:t.images,align:"start"})]})}case"event":return e.jsx("div",{className:"text-center text-meta text-muted",children:t.label});case"awaiting":return a?e.jsxs(Xe,{title:a?d.atelier.awaiting:d.thread.awaiting,tone:t.item.kind==="question"?"warning":"approval",children:[e.jsx("p",{className:"[overflow-wrap:anywhere]",children:wn(t.item)}),e.jsxs("a",{href:ne(a?{name:"atelier",sessionId:t.item.sessionId,requestKey:t.item.key}:{name:"request",sessionId:t.item.sessionId,key:t.item.key}),className:Pe({block:!0,className:"mt-3"}),children:[d.thread.examine,e.jsx(q,{name:"arrowRight"})]})]}):e.jsx(Xj,{store:s,item:t.item,onReconnect:l,keys:r})}}function Qj({sessionId:t,panel:s}){return e.jsxs(e.Fragment,{children:[e.jsx("a",{href:ne({name:"thread",sessionId:t}),"aria-label":d.atelier.fullScreen,title:d.atelier.fullScreen,className:Tt({variant:"outline"}),children:e.jsx(q,{name:"external"})}),e.jsx("button",{type:"button",onClick:s.onClose,"aria-label":d.atelier.closePanel,title:d.atelier.closeTitle,className:Tt({}),children:e.jsx(q,{name:"close"})})]})}function Er({store:t,sessionId:s,storage:n,onReconnect:a,panel:l,forge:r}){var Y,Re,ke,ie,Ae,Je,xt,Yt,ze,ht,Nt;const o=me(t),i=Xt(),c=It(),x=il(),u=o.sessions.get(s),m=o.threads.get(s),{fresh:p,ops:h}=o,[g,y]=f.useState(()=>Eu(s,n)),[k]=f.useState(()=>gb(s)),[S,b]=f.useState(!1),j=Ku(t),N=f.useRef(new Map);f.useEffect(()=>{var we;for(const[G,Ne]of N.current){const oe=(we=h[G])==null?void 0:we.phase;oe==="applied"?N.current.delete(G):(oe==="rejected"||oe==="failed"||oe==="uncertain")&&(N.current.delete(G),j.putBack(Ne))}});const $=we=>{y(we),Ru(s,we,n),b(!1)},[C,M]=f.useState(null),[v,A]=f.useState(!1),[T,R]=f.useState(!1),[P,_]=f.useState(!1),[D,E]=f.useState(null),z=((Y=Gm(s,h))==null?void 0:Y.op)??null,K=f.useRef(u==null?void 0:u.state);f.useEffect(()=>{K.current!==(u==null?void 0:u.state)&&K.current!==void 0&&E(z),K.current=u==null?void 0:u.state},[u==null?void 0:u.state,z]),f.useEffect(()=>(t.openThread(s),()=>t.watch(null)),[t,s]),f.useEffect(()=>{p&&t.watch(s)},[t,s,p]);const L=(m==null?void 0:m.status)==="ready"?(Re=m.items.at(-1))==null?void 0:Re.at:void 0;f.useEffect(()=>{L&&t.read(s,L)},[t,s,L]);const W=Md(s,h).at(-1);f.useEffect(()=>{(W==null?void 0:W.phase)!=="applied"||pb(W.op,n)||(fb(W.op,n),g.trim()===W.message.text&&$(""))},[W==null?void 0:W.phase,W==null?void 0:W.op]);const[ae,U]=f.useState(""),O=u==null?void 0:u.state;f.useEffect(()=>{(W==null?void 0:W.phase)==="applied"&&O&&O!=="idle"&&U(W.op)},[O,W==null?void 0:W.phase,W==null?void 0:W.op]);const B=f.useRef(null),Z=(m==null?void 0:m.status)==="gone",H=u&&!Z?qf((m==null?void 0:m.items)??[],u,h,i,(m==null?void 0:m.cut)??[],o.sessions,((ke=o.device)==null?void 0:ke.id)??null):[],X=(ie=H.at(-1))==null?void 0:ie.key,te=f.useRef(!0),[pe,ue]=f.useState(!1),F=()=>{const we=B.current;we&&(we.scrollTop=we.scrollHeight),te.current=!0,ue(!1)},w=f.useRef(!1);f.useLayoutEffect(()=>{var G;const we=B.current;if(!(!we||H.length===0)){if(!w.current){w.current=!0;const Ne=Ul.get(s);if(Ul.delete(s),Ne!==void 0){we.scrollTop=Ne,te.current=we.scrollHeight-we.scrollTop-we.clientHeight<Wi;return}}te.current?F():((G=H.at(-1))==null?void 0:G.kind)==="awaiting"&&ue(!0)}},[X,H.length,m==null?void 0:m.items]);const I=()=>{const we=B.current;we&&(te.current=we.scrollHeight-we.scrollTop-we.clientHeight<Wi,te.current&&ue(!1))};if(!u||Z){const we=!Z&&!p&&o.syncedAt===null;return e.jsxs(e.Fragment,{children:[e.jsx("header",{className:"flex-none border-b border-line pt-2 pb-3",children:e.jsxs("div",{className:"flex items-center gap-2.5",children:[!l&&e.jsx(is,{fallback:{name:"sessions"},label:d.thread.back}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:d.thread.title}),e.jsx(xd,{link:Mn(o)}),l&&e.jsx("button",{type:"button",onClick:l.onClose,"aria-label":d.atelier.closePanel,title:d.atelier.closeTitle,className:Tt({}),children:e.jsx(q,{name:"close"})})]})}),e.jsx("main",{className:"min-h-0 flex-1 pt-7 text-body text-muted",role:"status",children:we?d.thread.loading:d.thread.unknown})]})}const V=W!==void 0&&ps(W.phase),ee=(W==null?void 0:W.phase)==="applied"&&ae!==W.op&&u.state==="idle"&&!u.pending&&i-Date.parse(W.at)<mr,Q=Hf(u,p?"ready":"pc_offline",V||ee),J=W&&(W.phase==="rejected"||W.phase==="failed"||W.phase==="uncertain")&&(W.phase==="uncertain"||g.trim()===W.message.text)?Uj(W):null,fe=S&&!J?{title:d.thread.composer.failTitle,body:d.thread.composer.lost}:J,be=!!u.pending||u.state==="waiting_input"||u.state==="waiting_permission",tt=()=>{const we=g.trim();if(!we&&j.items.length===0||!Q.enabled||Xu(g)||!j.ready||j.items.length>0&&be)return;E(z);const G=j.ids(),Ne=j.clear(),oe=t.reply(s,we,G.length?{attachments:G}:{});!oe&&Ne.length?j.putBack(Ne):oe&&Ne.length&&N.current.set(oe,Ne),b(!oe)},yt=(m==null?void 0:m.status)==="ready",Ze=((Ae=o.daemon)==null?void 0:Ae.boot)??null,Le=Xm(u,h,i,{fresh:p,boot:Ze}),de=Wr(u,h,Ze,i),he=!!((Je=o.daemon)!=null&&Je.sessionClose)&&!u.readOnly,$e=Le.kind==="open"&&Le.error&&Le.error.op!==D?Le.error:null,Oe=we=>{E(z),_(!1),M(we)},rt=!!l&&u.tool==="omp",Ge=Sn(u),pt=Dj(s,n),ft=u.state==="exited"&&u.exitedAt?d.sessions.line.ended(zc(u.exitedAt,i)):void 0,ut=x&&[u.project,u.branch].filter(Boolean).join(" · ")||void 0;return e.jsxs(e.Fragment,{children:[e.jsx(la,{back:l?e.jsx("span",{className:"w-2.5"}):e.jsx(is,{fallback:{name:"sessions"},label:d.thread.back}),tool:u.tool,name:u.name,dot:Ge,pulse:Ge==="work"&&p,sub:ft??ut,under:!x&&!!ft,more:e.jsxs(e.Fragment,{children:[l?e.jsx(Qj,{sessionId:s,panel:l}):e.jsx(Zu,{sessionId:s,current:"thread",onLeave:()=>{B.current&&Ul.set(s,B.current.scrollTop)}}),e.jsx("button",{type:"button","aria-haspopup":"dialog","aria-label":d.sessions.moreOf(u.name),title:d.sessions.more,onClick:()=>A(!0),className:Tt({className:v?"bg-raised text-fg":"text-muted"}),children:e.jsx(q,{name:"more"})})]})}),rt?e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col items-center justify-center gap-3 px-6 text-center",children:[e.jsx("h2",{className:"text-heading",children:d.atelier.ompNoThread}),e.jsx("p",{className:"max-w-[320px] text-body text-muted",children:d.atelier.ompBody}),e.jsxs("a",{href:ne({name:"terminal",sessionId:s}),className:Pe({variant:"primary"}),children:[e.jsx(q,{name:"terminal"}),d.atelier.ompTerminal]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("main",{ref:B,onScroll:I,"aria-label":d.thread.log(u.name),className:"flex min-h-0 flex-1 flex-col gap-3.5 overflow-y-auto overscroll-contain pt-5 pb-4 phone-side:pt-3 phone-side:pb-3",children:[((xt=o.daemon)==null?void 0:xt.checklist)&&o.checklists.get(s)&&e.jsx(wu,{checklist:o.checklists.get(s),current:(Yt=u==null?void 0:u.checklist)==null?void 0:Yt.current}),(m==null?void 0:m.more)&&e.jsx("p",{className:"text-center text-meta text-muted",children:d.thread.more}),!(m!=null&&m.more)&&pt!==null&&e.jsx("p",{className:"flex items-center gap-2 text-[12px] text-muted before:h-px before:flex-1 before:bg-line before:content-[''] after:h-px after:flex-1 after:bg-line after:content-['']",children:d.launch.started(u.name,pt)}),!yt&&H.length===0&&e.jsx("p",{className:"text-center text-meta text-muted",role:"status",children:p?d.thread.loading:d.thread.unavailable}),yt&&H.length===0&&e.jsx("p",{className:"text-center text-meta text-muted",children:d.thread.empty}),H.map(we=>e.jsx(Yj,{item:we,store:t,storage:n,inPanel:!!l,onReconnect:a,keys:c&&!l},we.key))]}),pe&&e.jsx("div",{className:"relative h-0",children:e.jsxs("button",{type:"button",onClick:F,className:"absolute bottom-3 left-1/2 inline-flex h-9 -translate-x-1/2 items-center gap-1.5 rounded-full border border-line bg-surface px-3.5 text-[13px] font-medium text-fg shadow-sm",children:[e.jsx(q,{name:"down",className:"size-4"}),d.sessions.requestBelow]})}),Le.kind==="open"?e.jsx(Wj,{name:u.name,focusAtEnd:k,composer:c&&Qa()?{...Q,placeholder:`${Q.placeholder} · ${d.sessions.keysHint}`}:Q,draft:g,onDraft:$,onSend:tt,fresh:p,taken:ee,checking:(W==null?void 0:W.phase)==="uncertain"&&p,error:fe,onReconnect:a,images:j,dialog:be,...(ze=o.daemon)!=null&&ze.commands&&u.tool==="claude"&&!u.readOnly?{slash:{tool:d.tools[u.tool],listing:o.commands[s],ask:()=>t.requestCommands(s)}}:{},alert:$e&&e.jsx(Qu,{error:$e,fresh:p,onRetry:()=>Oe("close"),onReconnect:a}),...sn(o.daemon,u)?{lead:e.jsx(ib,{store:t,session:u}),leadNote:e.jsx(cb,{store:t,session:u})}:{}}):e.jsx(Kj,{ending:Le.kind==="ended"&&((ht=Le.error)==null?void 0:ht.op)===D?{...Le,error:null}:Le,name:u.name,canResume:he,resumeHeld:Ym(u,h,Ze,i),readOnly:!!u.readOnly,fresh:p,focus:P,onResume:()=>Oe("resume"),onReconnect:a},Le.kind),e.jsx(Ju,{store:t,forge:r,session:u,wide:x,threshold:((Nt=o.device)==null?void 0:Nt.contextNear)??kn,onModel:()=>R(!0)})]}),v&&e.jsx(jo,{store:t,session:u,closable:he&&!rt,closing:de,onClose:()=>A(!1),onModel:()=>{A(!1),R(!0)},onCloseSession:()=>{A(!1),Oe("close")}}),T&&sn(o.daemon,u)&&e.jsx(gl,{store:t,session:u,onClose:()=>R(!1)}),C&&e.jsx(So,{store:t,session:u,mode:C,onClose:()=>M(null),onSent:()=>{_(!0),M(null)},onReconnect:a})]})}const Ul=new Map,Wi=48;function Zu({sessionId:t,current:s,onLeave:n}){const a=d.sessions.view,l="grid h-9 place-items-center px-3 tablet:px-3.5 text-[13px] font-medium text-muted aria-[current=page]:bg-raised aria-[current=page]:text-fg";return e.jsxs("nav",{"aria-label":a.label,className:"flex flex-none overflow-hidden rounded-lg border border-input",children:[e.jsx("a",{href:ne({name:"thread",sessionId:t}),onClick:s==="thread"?void 0:n,"aria-current":s==="thread"?"page":void 0,className:l,children:a.thread}),e.jsx("a",{href:ne({name:"terminal",sessionId:t}),onClick:s==="terminal"?void 0:n,"aria-current":s==="terminal"?"page":void 0,className:l,children:a.terminal})]})}function Ju({store:t,forge:s,session:n,wide:a,threshold:l,onModel:r}){const o=me(t),{daemon:i,fresh:c,usage:x,usageAlert:u}=o,m=Xt(),p=ul(n,m,l),h=d.sessions,g=Mu(i,n)===null,y=a?mh(n.tool,x,u,m,c):null;return e.jsxs("footer",{"aria-label":h.foot(n.name),className:"bleed flex h-10 flex-none items-center gap-2.5 border-t border-line bg-sidebar px-3 text-small whitespace-nowrap text-muted",children:[p.model&&(g?e.jsxs("button",{type:"button",disabled:!c,"aria-haspopup":"dialog","aria-label":d.model.chip(p.model),onClick:r,className:"inline-flex h-8 items-center gap-1 text-fg disabled:opacity-60",children:[p.model,e.jsx(q,{name:"down",className:"size-3.5"})]}):e.jsx("span",{className:"text-fg",children:p.model})),p.context&&e.jsxs("span",{role:"img","aria-label":h.contextLabel(p.context.pct),className:`inline-flex items-center gap-1.5 ${p.context.near?"text-attention":""}`,children:[e.jsx("span",{className:"relative block h-1 w-8 overflow-hidden rounded-sm bg-raised",children:e.jsx("span",{className:"absolute inset-y-0 left-0 bg-current",style:{width:`${p.context.pct}%`}})}),p.context.pct," %"]}),a&&n.context&&e.jsxs("span",{children:["· ",ii(n.context.used)," / ",ii(n.context.window)]}),(p.model||p.context)&&e.jsx("span",{className:"h-3 w-px flex-none bg-line"}),n.branch?e.jsx("span",{className:`min-w-0 truncate font-mono text-[11px] ${a?"":"flex-1"}`,children:n.branch}):e.jsxs("span",{"aria-label":h.folder(n.project),className:`inline-flex min-w-0 items-center gap-1 ${a?"":"flex-1"}`,children:[e.jsx(q,{name:"folder",className:"size-3.5"}),e.jsx("span",{className:"truncate",children:n.project})]}),n.branch&&e.jsx(gg,{forge:s,mobile:o,session:n}),a&&n.branch&&e.jsx("span",{className:"min-w-0 truncate",children:n.project}),a&&e.jsx("span",{className:"flex-1"}),y&&e.jsxs("span",{className:"flex-none",children:[d.chat.point.harnessShort[y.harness]??y.harness," ",ko(y.window)," ",e.jsxs("b",{className:`font-semibold ${y.tone==="red"?"text-approval":y.tone==="amber"?"text-attention":"text-fg"}`,children:[y.window.pct," %"]})]})]})}const Zj={approval:{fg:"var(--danger-text)"},question:{fg:"var(--warning)"},starting:{fg:"var(--info)"},idle:{fg:"var(--success)"},working:{fg:"var(--info)"},done:{fg:"var(--muted-foreground)"},error:{fg:"var(--danger-text)"},readonly:{fg:"var(--muted-foreground)"}};function Jj({state:t,label:s,tone:n,caps:a=!1}){const{stateLabel:l}=qr(),r=Zj[n??t].fg;return e.jsx("span",{"data-badge":t,style:{display:"inline-flex",alignItems:"center",flexShrink:0,height:a?24:22,padding:a?"0 9px":"0 8px",boxSizing:"border-box",borderRadius:5,color:r,background:"color-mix(in srgb, currentColor 10%, transparent)",fontSize:a?11:12,lineHeight:1,fontWeight:500,letterSpacing:a?"0.08em":void 0,textTransform:a?"uppercase":void 0,whiteSpace:"nowrap",transition:Kp([["background-color","hover"],["color","hover"]])},children:s??l[t]})}const Ki=["monstera","fern","snake","ficus","succulent"],e1=["tl","tr","br","ml","mr"];function t1(t,s){const n=bn(t),a=1+n%2;return e1.filter(l=>!s.includes(l)).sort((l,r)=>bn(t+l)-bn(t+r)).slice(0,a).map((l,r)=>({spot:l,species:Ki[(n+r*7)%Ki.length],flip:!!(n>>r&1)}))}const Ls={top:56,side:12,bottom:34},Vi=11/12,ex=t=>t.width>=t.height?"land":"port";function s1(t,s,n){if(t.length===0||s.width<=0||s.height<=0)return{zoom:1,along:n==="land"?"row":"column"};const a=Math.max(...t.map(o=>o.h)),l=Math.max(...t.map(o=>o.w));return{zoom:n==="land"?Math.min(1,Math.max(Vi,(s.height-4)/(a+Ls.top+Ls.bottom))):Math.min(1,Math.max(Vi,(s.width-4)/(l+2*Ls.side))),along:n==="land"?"row":"column"}}const n1={starting:"starting",working:"working",waiting_input:"question",waiting_permission:"approval",idle:"idle",exited:"done",error:"error"};function Za(t){return t.state==="idle"&&(t.helpers??[]).some(s=>s.state!=="exited"&&s.state!=="idle")?"working":n1[t.state]}const tx=t=>t.state==="waiting_permission"||t.state==="waiting_input",sx=["M5 10.4a1.6 1.6 0 1 0 0 3.2 1.6 1.6 0 0 0 0-3.2Z","M12 10.4a1.6 1.6 0 1 0 0 3.2 1.6 1.6 0 0 0 0-3.2Z","M19 10.4a1.6 1.6 0 1 0 0 3.2 1.6 1.6 0 0 0 0-3.2Z"],a1=["M12 2.5 20.5 7.25v9.5L12 21.5l-8.5-4.75v-9.5z","M12 8.5a3.5 3.5 0 1 0 0 7a3.5 3.5 0 1 0 0-7"],l1=["M4 7h16v12H4z","M4 7l2-3h4l2 3","M9 13h6"],Un=t=>t.topic??t.title;function Rr({session:t,size:s,frozen:n}){const a=nn(),l=Za(t);return e.jsx(rl,{tool:t.tool,state:l,pose:ll(t.id,t.state),size:s,theme:a,seed:t.id,frozen:n,readOnly:!!t.readOnly})}function Gi({helper:t,parent:s,size:n,frozen:a}){const l=nn(),r=`${s.id}:${t.id}`,o=Yc(t);return e.jsx(rl,{tool:s.tool,state:o,pose:ll(r,o),size:n,theme:l,seed:r,frozen:a,readOnly:!!s.readOnly})}const nx=({state:t})=>e.jsx(Jj,{state:t}),ax=({color:t})=>t?e.jsx("i",{className:"side-swatch",style:{background:t}}):e.jsx("i",{className:"filter-none"}),r1={monstera:()=>e.jsxs("span",{className:"p-monstera",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("b",{})]}),fern:()=>e.jsxs("span",{className:"p-fern",children:[[0,1,2,3,4,5,6].map(t=>e.jsx("i",{},t)),e.jsx("b",{})]}),snake:()=>e.jsxs("span",{className:"p-snake",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("b",{})]}),ficus:()=>e.jsxs("span",{className:"p-ficus",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("em",{}),e.jsx("b",{})]}),succulent:()=>e.jsxs("span",{className:"p-succulent",children:[e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("i",{}),e.jsx("b",{})]})};function o1({seed:t,left:s,width:n,avoid:a}){return e.jsx("div",{className:"plants","aria-hidden":"true",style:{left:s,width:n},children:t1(t,a).map(({spot:l,species:r,flip:o})=>{const i=r1[r];return e.jsx("span",{className:`plant-spot spot-${l}${o?" flip":""}`,children:e.jsx(i,{})},l)})})}const Xi=t=>e.jsxs(e.Fragment,{children:[(t==="approval"||t==="question")&&e.jsx("b",{className:"sheet-flag"}),t==="done"&&e.jsx("i",{className:"sheet-stamp",children:"✓"})]});function i1({sheets:t,length:s}){return e.jsx("div",{className:"table-top",children:t.map(a=>e.jsxs(f.Fragment,{children:[e.jsxs("div",{style:{left:a.x-84/2},className:`task-sheet sheet-${a.slot} sheet-${a.state}`,children:[e.jsx("p",{lang:"fr",children:a.task}),Xi(a.state)]}),a.note&&e.jsxs("div",{style:{left:op(a.x,t.filter(l=>l.slot===a.slot).map(l=>l.x),s)},className:`sheet-note note-${a.slot} sheet-${a.note.state}`,children:[e.jsx("p",{children:a.note.task}),Xi(a.note.state),a.note.more>0&&e.jsxs("em",{className:"note-more",children:["+",a.note.more]})]})]},a.id))})}function c1({table:t,project:s,color:n,frozen:a,act:l,helpers:r=!0}){const{length:o,width:i,seats:c,ends:x,notes:u,extra:m,extraCount:p}=rp(t.mains,r,aa,Is),h=b=>`calc(50% - ${o/2}px + ${b}px)`,g=ip(t.mains),y=c.map(({session:b,x:j,side:N})=>{const $=u.get(b.id);return{id:b.id,task:Un(b),state:Xo(Za(b)),slot:N,x:j,note:$&&{task:$.helper.task,state:Xo(Yc($.helper)),more:$.more}}}),k=[...m.mains.map(b=>({key:b.id,el:e.jsx(Rr,{session:b,size:18,frozen:a})})),...m.helpers.map(({helper:b,parent:j})=>({key:`${j.id}:${b.id}`,el:e.jsx(Gi,{helper:b,parent:j,size:18,frozen:a})}))].slice(0,3),S=[...p>0?["br"]:[],...x.some(b=>b.end==="left")?["ml"]:[],...x.some(b=>b.end==="right")?["mr"]:[]];return e.jsx("section",{className:"atelier-table","data-project":s.id,"data-table":t.key,"aria-label":d.atelier.table(s.name),style:{"--room":`${i}px`,"--project":n},children:e.jsxs("div",{className:"table-scene",children:[e.jsx("div",{className:"office-rug",style:{left:h(-Is),right:"auto",width:o+2*Is}}),e.jsxs("div",{className:"rug-labels",style:{left:h(-Is),width:o+2*Is},children:[e.jsxs("div",{className:"room-heading",children:[e.jsx(ax,{color:n}),e.jsxs("span",{className:"heading-names",children:[e.jsx("button",{type:"button",className:"project-conversations",title:s.name,"aria-label":d.atelier.conversations(s.name),onClick:()=>l.room(s.id),children:s.name}),g!==null&&e.jsxs("span",{className:"heading-branch",title:g,children:["⎇ ",g]})]}),e.jsx("span",{className:"spacer"}),e.jsx("span",{className:"room-menu-wrap",children:e.jsx("button",{type:"button",className:"icon-action","aria-label":d.atelier.roomMenu(s.name),onClick:()=>l.room(s.id),children:e.jsx(Nn,{d:[],fill:sx,size:14})})})]}),p>0&&e.jsxs("button",{type:"button",className:"table-more",onClick:()=>l.room(s.id),children:[e.jsx("span",{className:"more-faces","aria-hidden":"true",children:k.map(b=>e.jsx("i",{children:b.el},b.key))}),d.atelier.more(p)]})]}),e.jsx(o1,{seed:t.key,left:h(-Is),width:o+2*Is,avoid:S}),c.map(({session:b,x:j,side:N})=>e.jsx("div",{className:`office-chair chair-${N}`,"aria-hidden":"true",style:{left:h(j-27)}},b.id)),e.jsx("div",{className:"worktable","aria-hidden":"true",style:{left:h(0),right:"auto",width:o},children:e.jsx(i1,{length:o,sheets:y})}),c.map(({session:b,x:j,side:N})=>{var C;const $=Za(b);return e.jsxs("button",{type:"button",style:{left:h(j-56)},"data-agent":b.id,"aria-label":d.atelier.seat(b.name,Un(b)),onClick:()=>l.open(b.id),className:`agent-seat place-${N}${!a&&$==="working"?" seat-working":""}${a?" seat-offline":""}`,children:[e.jsx(Rr,{session:b,size:64,frozen:a}),e.jsx("strong",{children:e.jsx("span",{className:"seat-name",title:b.name,children:b.name})}),e.jsx("span",{className:"seat-machine",children:((C=b.rig)==null?void 0:C.role)??"local"}),e.jsx(nx,{state:$})]},b.id)}),x.map(({helper:b,parent:j,end:N,slot:$,count:C})=>e.jsxs("button",{type:"button",style:{left:h(N==="left"?-70:o+8),right:"auto",top:C>1?$?232:126:void 0},className:`agent-seat helper-seat end-${N}`,"aria-label":d.atelier.helperSeat(b.kind,j.name,b.task),title:b.task,onClick:()=>l.open(j.id),children:[e.jsx(Gi,{helper:b,parent:j,size:36,frozen:a}),e.jsx("strong",{children:b.kind}),e.jsxs("span",{className:"seat-meta",children:["↳ ",j.name]})]},`${j.id}:${b.id}`))]})})}function d1({project:t,tables:s,rig:n,width:a,act:l,children:r}){const o=s.flatMap(p=>p.mains),i=n?o.filter(p=>p.state!=="exited"):o,c=i.filter(tx).length,x=i.filter(p=>p.state==="working").length,u=(n==null?void 0:n.kind)==="kernel"?d.atelier.kernel:t.name,m=()=>l.room(t.id);return e.jsxs("section",{className:`project-room atelier-room${n?` rig-room ${n.kind}-room`:""}`,"data-room":t.id,"aria-label":n?d.atelier.rigRoom(n.kind,t.name):d.atelier.room(t.name),style:{"--room":`${a}px`,"--project":jn[t.color],"--room-side":`${Qc}px`,"--room-back":`${mp}px`,"--table-gap":`${Zc}px`},children:[e.jsxs("div",{className:"room-walls","aria-hidden":"true",children:[e.jsx("i",{className:"wall-back"}),e.jsx("i",{className:"wall-left"}),e.jsx("i",{className:"wall-right"}),e.jsx("i",{className:"wall-front"})]}),e.jsxs("div",{className:`room-plaque${n?" rig-plaque":""}`,children:[n?e.jsx("span",{className:"rig-hex","aria-hidden":"true",children:e.jsx(Nn,{d:a1,size:13})}):e.jsx(ax,{color:jn[t.color]}),e.jsx("strong",{className:"plaque-name",title:u,role:"button",tabIndex:0,"aria-label":d.atelier.roomMenu(u),onClick:m,onKeyDown:p=>{(p.key==="Enter"||p.key===" ")&&(p.preventDefault(),m())},children:u}),n?e.jsx("span",{className:"plaque-where",children:n.kind==="kernel"?d.atelier.kernelWhere:d.atelier.rigWhere(n.folder,n.project)}):e.jsx("span",{className:"plaque-counts",children:d.atelier.plaqueCounts(o.length)}),c>0&&e.jsxs("span",{className:"plaque-waiting",children:[e.jsx("i",{className:"approval-dot"}),d.atelier.waiting(c)]}),x>0&&e.jsxs("span",{className:"plaque-working",children:[e.jsx("i",{className:"live-dot"}),d.atelier.working(x)]}),!n&&e.jsx("span",{className:"room-menu-wrap",children:e.jsx("button",{type:"button",className:"icon-action","aria-label":d.atelier.roomMenu(u),onClick:m,children:e.jsx(Nn,{d:[],fill:sx,size:14})})})]}),e.jsx("div",{className:"room-tables",children:r}),e.jsx("span",{className:"room-entrance","aria-hidden":"true",children:d.atelier.entrance})]})}function u1({sessions:t,frozen:s,act:n}){return t.length===0?null:e.jsxs("section",{className:"unassigned-zone atelier","aria-labelledby":"unassigned-title",children:[e.jsxs("div",{className:"unassigned-heading",children:[e.jsx(Nn,{d:l1,size:15}),e.jsx("h2",{id:"unassigned-title",children:d.atelier.unassigned}),e.jsx("span",{className:"muted",children:d.atelier.unassignedHint})]}),e.jsx("div",{className:"unassigned-list",children:t.map(a=>e.jsxs("div",{className:"unassigned-card",children:[e.jsxs("button",{type:"button",className:"unassigned-open","data-agent":a.id,"aria-label":d.atelier.seat(a.name,Un(a)),onClick:()=>n.open(a.id),children:[e.jsx(Rr,{session:a,size:56,frozen:s}),e.jsxs("span",{className:"unassigned-copy",children:[e.jsx("strong",{children:a.name}),e.jsx("span",{title:Un(a),children:Un(a)}),e.jsx("code",{children:a.project})]})]}),e.jsx("div",{className:"unassigned-actions",children:e.jsx(nx,{state:Za(a)})})]},a.id))})]})}function x1({count:t,frozen:s,onOpen:n}){const a=nn();return e.jsx("div",{className:"ledge-corner",children:e.jsxs("button",{type:"button",className:"ledge-desk",onClick:n,disabled:!n,"aria-label":d.atelier.desk,children:[e.jsx("span",{className:"ledge-bubble",children:d.atelier.watching(t)}),e.jsx("span",{className:"ledge-seat",children:e.jsx(Zr,{size:80,theme:a,frozen:s})}),e.jsx("strong",{children:"Ledge"}),e.jsx("small",{children:d.atelier.assistant})]})})}function m1(){const t=d.atelier.legend;return e.jsxs("div",{className:"workspace-legend",children:[e.jsxs("span",{children:[e.jsx("i",{className:"live-dot"}),t.working]}),e.jsxs("span",{children:[e.jsx("i",{className:"approval-dot"}),t.approval]}),e.jsxs("span",{children:[e.jsx("i",{className:"question-dot"}),t.question]}),e.jsxs("span",{children:[e.jsx("i",{className:"done-dot"}),t.done]}),e.jsx("span",{className:"spacer"}),e.jsx("span",{children:t.helper})]})}const lx=.3,p1=2.5,f1=2.2,Ar=t=>Math.min(p1,Math.max(lx,t)),h1=(t,s)=>Ar(s>0?t*1.2:t/1.2);function g1(t,s,n){const a=(t.left+n.x)/t.zoom,l=(t.top+n.y)/t.zoom;return{left:a*s-n.x,top:l*s-n.y}}function b1(t,s){const n=Math.min(f1,Math.max(lx,Math.min(s.width*.92/t.w,s.height*.92/t.h)));return{zoom:n,left:(t.x+t.w/2)*n-s.width/2,top:(t.y+t.h/2)*n-s.height/2}}const j1=8,y1=320,N1=30,v1="button,a,[role=button],.unassigned-card",k1=".atelier-room,.unassigned-zone",w1=12;let ks={zoom:null,left:0,top:0};function S1(t){const s=f.useRef(null),n=f.useRef(null),[a,l]=f.useState(1),[r,o]=f.useState(ks.zoom),i=f.useRef(ks.zoom??1),c=f.useRef(ks.zoom),x=f.useRef({w:-1,h:-1}),u=f.useCallback(()=>{const b=s.current,j=n.current;if(!b||!j)return;const N=j.style;N.zoom="1";const $={width:b.clientWidth,height:b.clientHeight};x.current={w:b.offsetWidth,h:b.offsetHeight};const C=ex($);N.padding=`${Ls.top}px ${Ls.side}px ${Ls.bottom}px`,N.flexWrap="wrap",N.width="max-content",N.maxWidth="none",N.minHeight="",N.alignContent="flex-start",N.gap="0 8px";const M=j.querySelector(".ledge-corner");N.setProperty("--ledge-clear",`${M?Math.max(0,M.offsetTop+M.offsetHeight+w1-Ls.top):0}px`);const v=[...j.querySelectorAll(k1)].map(R=>({w:R.offsetWidth,h:R.offsetHeight})).filter(R=>R.w>0),{zoom:A,along:T}=s1(v,$,C);if(T==="row")N.flexWrap="nowrap",N.width="max-content",N.justifyContent="flex-start";else{const R=Math.max(0,...v.map(P=>P.w))+2*Ls.side;N.flexWrap="wrap",N.width=`${R}px`,N.maxWidth=`${R}px`,N.justifyContent="center"}v.length===0&&(N.width=`${$.width}px`,N.minHeight=`${$.height}px`),l(A),i.current=c.current??A,N.zoom=String(i.current)},[]);f.useLayoutEffect(()=>{u();const b=s.current;b&&(b.scrollLeft=ks.left,b.scrollTop=ks.top)},[u,...t]);const m=f.useRef(u);m.current=u,f.useEffect(()=>{var N,$;const b=s.current;if(!b||typeof ResizeObserver>"u")return;const j=new ResizeObserver(()=>{(b.offsetWidth!==x.current.w||b.offsetHeight!==x.current.h)&&m.current()});return j.observe(b),($=(N=globalThis.document)==null?void 0:N.fonts)==null||$.ready.then(()=>m.current()),()=>j.disconnect()},[]);const p=(b,j,N)=>{const $=s.current,C=n.current;i.current=b,c.current=b,o(b),ks.zoom=b,!(!$||!C)&&(C.style.zoom=String(b),$.scrollLeft=j,$.scrollTop=N)},h=b=>{const j=s.current,N=Ar(b);if(!j){p(N,0,0);return}const{left:$,top:C}=g1({zoom:i.current,left:j.scrollLeft,top:j.scrollTop},N,{x:j.clientWidth/2,y:j.clientHeight/2});p(N,$,C)},g=b=>h(h1(i.current,b)),y=()=>{c.current=null,o(null),ks.zoom=null,u();const b=s.current;b&&(b.scrollLeft=0,b.scrollTop=0)},k=b=>{const j=s.current;if(!j)return;const N=i.current,$=j.getBoundingClientRect(),C=b.getBoundingClientRect(),M={x:(j.scrollLeft+C.left-$.left)/N,y:(j.scrollTop+C.top-$.top)/N,w:C.width/N,h:C.height/N};if(M.w<=0||M.h<=0)return;const{zoom:v,left:A,top:T}=b1(M,{width:j.clientWidth,height:j.clientHeight});p(v,A,T)},S=f.useRef({setZoom:p,fit:y,frame:k});return S.current={setZoom:p,fit:y,frame:k},f.useEffect(()=>{const b=s.current;if(!b)return;const j=new Map;let N=null,$=null,C=null,M=!1;const v=(E,z)=>({x:(E.x+z.x)/2,y:(E.y+z.y)/2,d:Math.hypot(E.x-z.x,E.y-z.y)}),A=()=>{const[E,z]=[...j.values()];if(N=null,$=null,E&&z){const K=v(E,z),L=b.getBoundingClientRect(),W=i.current;N={d:Math.max(K.d,1),zoom:W,x:(b.scrollLeft+K.x-L.left)/W,y:(b.scrollTop+K.y-L.top)/W}}else E&&($={x:E.x,y:E.y,left:b.scrollLeft,top:b.scrollTop,moved:!1})},T=E=>{E.pointerType!=="mouse"&&(j.size===0&&(M=!1),j.set(E.pointerId,{x:E.clientX,y:E.clientY}),A())},R=E=>{if(!j.has(E.pointerId))return;j.set(E.pointerId,{x:E.clientX,y:E.clientY});const[z,K]=[...j.values()];if(N&&z&&K){const L=v(z,K),W=b.getBoundingClientRect(),ae=Ar(N.zoom*L.d/N.d);S.current.setZoom(ae,N.x*ae-(L.x-W.left),N.y*ae-(L.y-W.top))}else if($){const L=E.clientX-$.x,W=E.clientY-$.y;if(!$.moved&&Math.hypot(L,W)<j1)return;$.moved=!0,b.scrollLeft=$.left-L,b.scrollTop=$.top-W}},P=E=>{if(!j.has(E.pointerId))return;($!=null&&$.moved||N)&&(M=!0);const z=j.size===1&&$!==null&&!$.moved;if(j.delete(E.pointerId),A(),!z||E.type==="pointercancel")return;const K=E.target instanceof Element?E.target:null,L=E.timeStamp;if(C&&L-C.at<y1&&Math.hypot(E.clientX-C.x,E.clientY-C.y)<N1&&!(K!=null&&K.closest(v1))){C=null;const W=K==null?void 0:K.closest(".atelier-room");W?S.current.frame(W):S.current.fit();return}C={at:L,x:E.clientX,y:E.clientY}},_=E=>{M&&(M=!1,E.preventDefault(),E.stopPropagation())},D=()=>{ks.left=b.scrollLeft,ks.top=b.scrollTop};return b.addEventListener("pointerdown",T),b.addEventListener("pointermove",R),b.addEventListener("pointerup",P),b.addEventListener("pointercancel",P),b.addEventListener("click",_,!0),b.addEventListener("scroll",D,{passive:!0}),()=>{b.removeEventListener("pointerdown",T),b.removeEventListener("pointermove",R),b.removeEventListener("pointerup",P),b.removeEventListener("pointercancel",P),b.removeEventListener("click",_,!0),b.removeEventListener("scroll",D)}},[]),{scrollRef:s,shellRef:n,zoom:r??a,fitted:r===null,zoomTo:h,step:g,fit:y}}const $1=["M15 3h6v6","M9 21H3v-6","M21 3l-7 7","M3 21l7-7"],C1=80;function rx({label:t,onClose:s,children:n}){const a=f.useRef(null),l=f.useRef(null),[r,o]=f.useState(0),i=u=>{var p,h;const m=u.target;!m.closest(".atelier-panel-grab, .atelier-panel > header, .atelier-panel header")||m.closest("button,a,textarea,input")||(l.current={x:u.clientX,y:u.clientY,id:u.pointerId,land:ex({width:globalThis.innerWidth,height:globalThis.innerHeight})==="land"},(h=(p=a.current)==null?void 0:p.setPointerCapture)==null||h.call(p,u.pointerId))},c=u=>{const m=l.current;!m||m.id!==u.pointerId||o(Math.max(0,m.land?u.clientX-m.x:u.clientY-m.y))},x=u=>{const m=l.current;if(!m||m.id!==u.pointerId)return;l.current=null;const p=m.land?u.clientX-m.x:u.clientY-m.y;o(0),p>C1&&s()};return e.jsxs("aside",{ref:a,className:"atelier-panel","aria-label":t,onPointerDown:i,onPointerMove:c,onPointerUp:x,onPointerCancel:x,style:r?{"--pull":`${r}px`}:void 0,children:[e.jsx("div",{className:"atelier-panel-grab","aria-hidden":"true"}),n]})}function M1({store:t,name:s,ids:n,onOpen:a,onClose:l}){var x;const r=me(t),o=!r.fresh,i=n.map(u=>r.sessions.get(u)).filter(u=>u!==void 0),c=i.filter(u=>u.state!=="exited").map(u=>u.id);return e.jsxs(rx,{label:d.atelier.room(s),onClose:l,children:[e.jsxs("header",{className:"flex flex-none items-center gap-2.5 border-b border-line pt-2 pb-3",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("h1",{className:"text-title font-semibold [overflow-wrap:anywhere]",children:s}),e.jsx("p",{className:"mt-[3px] text-meta text-muted",children:d.atelier.roomAgents(i.length)})]}),e.jsx("button",{type:"button",onClick:l,"aria-label":d.atelier.closePanel,title:d.atelier.closeTitle,className:Tt({}),children:e.jsx(q,{name:"close"})})]}),e.jsxs("main",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain",children:[i.map(u=>{var m;return e.jsxs("button",{type:"button",onClick:()=>a(u.id),className:"flex w-full items-center gap-3 border-b border-line py-3 text-left active:bg-raised/60",children:[e.jsx(ol,{tool:u.tool,seed:u.id,state:u.state,frozen:o}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block text-body font-semibold",children:u.name}),e.jsx("span",{className:"block truncate text-meta text-muted",children:((m=u.rig)==null?void 0:m.role)??u.topic??u.branch??u.title})]}),e.jsx(ra,{...Ap(u)})]},u.id)}),((x=r.daemon)==null?void 0:x.broadcast)&&c.length>0&&e.jsx("div",{className:"pt-4",children:c.length>Pa?e.jsx("p",{className:"text-meta text-attention",children:d.agents.tooMany(c.length,Pa)}):e.jsx(ad,{store:t,label:s,ids:c,offline:o})})]})]})}function E1(t,s){var a;const n=t.rooms.find(l=>l.project.id===s);return n?{name:((a=n.rig)==null?void 0:a.kind)==="kernel"?d.atelier.kernel:n.project.name,ids:n.tables.flatMap(l=>l.mains.map(r=>r.id))}:null}const Yi=`${Cs}sessions.helpers`,Qi=`${Cs}sessions.groupBy`;function R1({store:t,sessionId:s,requestKey:n,storage:a,onReconnect:l}){var D;const r=me(t),o=!r.fresh,i=f.useMemo(()=>[...r.sessions.values()],[r.sessions]),c=f.useMemo(()=>i.map(E=>({...E,cwd:E.project})),[i]),x=f.useMemo(()=>dp(c,r.projects,E=>E.projectId??null,"all",!0,({id:E,name:z,kind:K})=>({id:E,name:z,color:xp(K)})),[c,r.projects]),[u,m]=f.useState(null),[p,h]=f.useState(()=>{var E;try{return((E=Qe(a))==null?void 0:E.getItem(Yi))!=="hidden"}catch{return!0}}),[g,y]=f.useState(()=>{var E;try{return((E=Qe(a))==null?void 0:E.getItem(Qi))==="rigs"?"rigs":"projects"}catch{return"projects"}}),k=E=>{var z;y(E);try{(z=Qe(a))==null||z.setItem(Qi,E)}catch{}},S=()=>{var z;const E=!p;h(E);try{(z=Qe(a))==null||z.setItem(Yi,E?"shown":"hidden")}catch{}},b=S1([x,o]),j=E=>{m(null),s?fs({name:"atelier",sessionId:E}):tn({name:"atelier",sessionId:E})},N=()=>fs({name:"atelier"}),$={open:j,room:E=>{s&&N(),m(E)},chat:()=>tn({name:"chat"})},C=i.filter(E=>E.state!=="exited").length,M=i.filter(tx).length,v=`${o?`${d.agents.offline} · `:""}${d.atelier.subtitle(C,M,ed(i).working)}`,A=u?E1(x,u):null,T=x.rooms.filter(E=>!E.rig),R=x.rooms.filter(E=>E.rig),P=g==="rigs"?[...R,...T]:[...T,...R],_=s?r.sessions.get(s):void 0;return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"atelier-col",children:[e.jsxs("header",{className:"flex flex-none items-center gap-3 pt-3 pb-3",children:[e.jsx("h1",{className:"text-title font-semibold tracking-[-.3px]",children:d.atelier.title}),e.jsx("span",{className:"min-w-0 truncate text-meta text-muted",children:v}),e.jsx("span",{className:"flex-1"}),e.jsx("div",{role:"group","aria-label":d.sessions.groupBy.label,className:"flex flex-none overflow-hidden rounded-lg border border-input",children:Gr.map(E=>e.jsx("button",{type:"button","aria-pressed":E===g,onClick:()=>k(E),className:"grid h-9 place-items-center px-3.5 text-[13px] font-medium text-muted aria-pressed:bg-raised aria-pressed:text-fg",children:d.sessions.groupBy[E]},E))}),e.jsxs("button",{type:"button","aria-pressed":!p,onClick:S,className:Fe({size:"sm",className:"flex-none"}),children:[e.jsx(q,{name:"eye",className:"size-4"}),p?d.sessions.helpersHide:d.sessions.helpersShow]}),e.jsx(cl,{})]}),e.jsx("div",{className:"mb-3 flex-none empty:hidden",children:e.jsx(js,{})}),e.jsxs("div",{className:`atelier-ipad${o?" atelier-frozen":""}`,children:[e.jsxs("div",{className:"zoom-controls",role:"toolbar","aria-label":d.atelier.zoom.bar,children:[e.jsx("button",{type:"button",className:"ledge-btn","data-variant":"ghost","aria-label":d.atelier.zoom.out,onClick:()=>b.step(-1),children:"−"}),e.jsx("button",{type:"button",className:"zoom-level","aria-label":d.atelier.zoom.reset,onClick:()=>b.zoomTo(1),children:d.percent(Math.round(b.zoom*100))}),e.jsx("button",{type:"button",className:"ledge-btn","data-variant":"ghost","aria-label":d.atelier.zoom.in,onClick:()=>b.step(1),children:"+"}),e.jsx("span",{className:"zoom-sep"}),e.jsxs("button",{type:"button",className:"ledge-btn zoom-fit","data-variant":b.fitted?"secondary":"ghost","aria-pressed":b.fitted,title:d.atelier.zoom.fitTitle,onClick:b.fit,children:[e.jsx(Nn,{d:$1,size:13}),d.atelier.zoom.fit]})]}),e.jsxs("div",{className:"overview-scroll atelier",role:"region","aria-label":d.atelier.region,ref:b.scrollRef,children:[e.jsx("div",{className:"atelier-floor",children:e.jsxs("div",{ref:b.shellRef,className:`office-shell${o?" office-paused":""}`,children:[e.jsx(x1,{count:C,frozen:o,...(D=r.device)!=null&&D.chat?{onOpen:$.chat}:{}}),e.jsx("div",{className:`project-grid ${P.length===1?"focused":""}`,children:P.map(({project:E,tables:z,rig:K})=>e.jsx(d1,{project:E,tables:z,...K?{rig:K}:{},width:pp(z,aa,Is),act:$,children:z.map(L=>e.jsx(c1,{table:L,project:E,color:jn[E.color],frozen:o,act:$,helpers:p},L.key))},E.id))}),e.jsx(u1,{sessions:x.unassigned,frozen:o,act:$})]})}),e.jsx(m1,{})]})]})]}),s&&e.jsx(rx,{label:d.atelier.session((_==null?void 0:_.name)??""),onClose:N,children:n?e.jsx(vr,{store:t,sessionId:s,requestKey:n,onReconnect:l,panel:{onBack:()=>fs({name:"atelier",sessionId:s}),onClose:N}},`${s}:request`):e.jsx(Er,{store:t,sessionId:s,storage:a,onReconnect:l,panel:{onClose:N}},s)}),!s&&A&&u&&e.jsx(M1,{store:t,name:A.name,ids:A.ids,onOpen:j,onClose:()=>m(null)})]})}const ox=500,Tr=10;function ix(t){const s=f.useRef(null),n=f.useRef(null),a=f.useRef(!1),l=()=>{s.current&&clearTimeout(s.current),s.current=null},r=()=>{var o;l(),a.current=!0;try{(o=navigator.vibrate)==null||o.call(navigator,10)}catch{}t()};return{onPointerDown:o=>{o.button>0||(a.current=!1,n.current={x:o.clientX,y:o.clientY},l(),s.current=setTimeout(r,ox))},onPointerMove:o=>{const i=n.current;i&&Math.hypot(o.clientX-i.x,o.clientY-i.y)>Tr&&l()},onPointerUp:l,onPointerCancel:l,onPointerLeave:l,onContextMenu:o=>{o.preventDefault(),a.current||r()},onClickCapture:o=>{a.current&&(o.preventDefault(),o.stopPropagation(),a.current=!1)}}}function cx(t){const s=f.useRef(t);s.current=t;const n=f.useRef(null),a=f.useRef(null),l=f.useRef("idle"),r=f.useRef(!1),o=f.useRef(null),i=()=>{n.current&&clearTimeout(n.current),n.current=null},c=()=>{var m;i(),(m=o.current)==null||m.call(o),o.current=null,l.current="idle"};f.useEffect(()=>()=>c(),[]);const x=()=>{const m=y=>{(l.current==="lifted"||l.current==="dragging")&&y.preventDefault()},p=y=>{var S,b;const k=a.current;k&&(l.current==="lifted"&&Math.hypot(y.clientX-k.x,y.clientY-k.y)>Tr&&(l.current="dragging"),l.current==="dragging"&&((b=(S=s.current).onDrag)==null||b.call(S,y.clientY)))},h=()=>{var k,S;const y=l.current;c(),y==="dragging"?(S=(k=s.current).onDrop)==null||S.call(k):y==="lifted"&&s.current.onLong()},g=()=>{var k,S;const y=l.current;c(),(y==="dragging"||y==="lifted")&&((S=(k=s.current).onCancel)==null||S.call(k))};document.addEventListener("touchmove",m,{passive:!1}),window.addEventListener("pointermove",p),window.addEventListener("pointerup",h),window.addEventListener("pointercancel",g),o.current=()=>{document.removeEventListener("touchmove",m),window.removeEventListener("pointermove",p),window.removeEventListener("pointerup",h),window.removeEventListener("pointercancel",g)}},u=()=>{var m,p,h,g;i(),r.current=!0,l.current="lifted";try{(m=navigator.vibrate)==null||m.call(navigator,10)}catch{}(g=(h=s.current).onLift)==null||g.call(h,((p=a.current)==null?void 0:p.y)??0),x()};return{onPointerDown:m=>{m.button>0||(r.current=!1,a.current={x:m.clientX,y:m.clientY},i(),l.current="pressing",n.current=setTimeout(u,ox))},onPointerMove:m=>{const p=a.current;l.current==="pressing"&&p&&Math.hypot(m.clientX-p.x,m.clientY-p.y)>Tr&&(i(),l.current="idle")},onPointerUp:()=>{l.current==="pressing"&&(i(),l.current="idle")},onPointerCancel:()=>{l.current==="pressing"&&(i(),l.current="idle")},onDragStart:m=>{m.preventDefault()},onContextMenu:m=>{m.preventDefault(),!r.current&&l.current!=="lifted"&&l.current!=="dragging"&&(i(),l.current="idle",r.current=!0,s.current.onLong())},onClickCapture:m=>{r.current&&(m.preventDefault(),m.stopPropagation(),r.current=!1)}}}function dx({store:t,session:s,current:n,onLeave:a,onReconnect:l,display:r,model:o,onModel:i}){var v,A;const c=me(t),x=Xt(),[u,m]=f.useState(!1),[p,h]=f.useState(!1),g=o??p,y=i??h,[k,S]=f.useState(!1),b=Sn(s),j=It(),N=il(),$=n==="terminal"&&j&&!N&&[s.project,s.branch].filter(Boolean).join(" · ")||void 0,C=!!((v=c.daemon)!=null&&v.sessionClose)&&!s.readOnly,M=Wr(s,c.ops,((A=c.daemon)==null?void 0:A.boot)??null,x);return e.jsxs(e.Fragment,{children:[e.jsx(la,{back:e.jsx(is,{fallback:{name:"sessions"},label:d.thread.back}),tool:s.tool,name:s.name,dot:b,pulse:b==="work"&&c.fresh,sub:$,more:e.jsxs(e.Fragment,{children:[e.jsx(Zu,{sessionId:s.id,current:n,...a?{onLeave:a}:{}}),e.jsx("button",{type:"button","aria-haspopup":"dialog","aria-label":d.sessions.moreOf(s.name),title:d.sessions.more,onClick:()=>m(!0),className:Tt({className:u?"bg-raised text-fg":"text-muted"}),children:e.jsx(q,{name:"more"})})]})}),u&&e.jsx(jo,{store:t,session:s,closable:C,closing:M,onClose:()=>m(!1),onModel:()=>{m(!1),y(!0)},onCloseSession:()=>{m(!1),S(!0)},display:r&&{value:r.value,onToggle:()=>{r.onToggle(),m(!1)}}}),g&&sn(c.daemon,s)&&e.jsx(gl,{store:t,session:s,onClose:()=>y(!1)}),k&&e.jsx(So,{store:t,session:s,mode:"close",onClose:()=>S(!1),onSent:()=>S(!1),onReconnect:l})]})}function A1({store:t,session:s,onDone:n,order:a}){var p,h;const l=me(t),r=Xt(),[o,i]=f.useState("menu"),c=!!((p=l.daemon)!=null&&p.sessionClose)&&!s.readOnly,x=Wr(s,l.ops,((h=l.daemon)==null?void 0:h.boot)??null,r),u=s.rig?d.sessions.seatOf(s.rig.role??s.name,s.rig.name):s.project,m=g=>{n(),tn(g)};return o==="model"?sn(l.daemon,s)?e.jsx(gl,{store:t,session:s,onClose:n}):null:o==="close"?e.jsx(So,{store:t,session:s,mode:"close",onClose:n,onSent:n}):e.jsx(jo,{store:t,session:s,closable:c,closing:x,onClose:n,who:u,onModel:()=>i("model"),onCloseSession:()=>i("close"),...a?{order:[{icon:"arrowUp",label:d.sessions.reorder.up,onClick:a.up?()=>{a.up(),n()}:void 0},{icon:"arrowDown",label:d.sessions.reorder.down,onClick:a.down?()=>{a.down(),n()}:void 0}]}:{},lead:[{icon:"sessions",label:d.atoi.openThread,onClick:()=>m({name:"thread",sessionId:s.id})},{icon:"terminal",label:d.thread.terminal(s.name),onClick:()=>m({name:"terminal",sessionId:s.id})}]})}function T1({by:t,onBy:s,helpers:n,onHelpers:a}){const l=d.sessions.groupBy;return e.jsxs("div",{className:"flex flex-none items-center gap-2",children:[e.jsx("div",{role:"group","aria-label":l.label,className:"grid flex-1 grid-cols-2 gap-[3px] rounded-[10px] border border-line p-[3px]",children:Gr.map(r=>e.jsx("button",{type:"button","aria-pressed":r===t,onClick:()=>s(r),className:"h-[34px] rounded-[7px] text-[13px] font-medium whitespace-nowrap text-muted aria-pressed:bg-raised aria-pressed:text-fg",children:l[r]},r))}),e.jsx("button",{type:"button",onClick:a,"aria-label":n?d.sessions.helpersHide:d.sessions.helpersShow,title:n?d.sessions.helpersHide:d.sessions.helpersShow,className:`grid size-[42px] flex-none place-items-center rounded-control border ${n?"border-input text-fg":"border-ring text-fg"}`,children:e.jsx(q,{name:"eye",className:"size-[18px]"})})]})}const Zi="inline-flex items-center gap-1.5 rounded-lg border bg-bg px-2.5 select-none [-webkit-touch-callout:none]";function _1({session:t,rig:s,helpers:n,pressed:a,onPress:l}){const r=ix(()=>l(t)),o=Sn(t),i=o==="perm"?"border-destructive/50":o==="ask"?"border-attention/50":"border-line",c=ne({name:"thread",sessionId:t.id}),x=d.atelier.session(t.name);return e.jsxs(e.Fragment,{children:[e.jsxs("a",{href:c,"aria-label":x,...r,className:`${Zi} h-10 text-[13px] font-medium ${i} ${t.state==="exited"?"opacity-60":""} ${a?"shadow-[0_0_0_2px_var(--color-ring)]":""}`,children:[!s&&e.jsx(gs,{tool:t.tool}),t.name,e.jsx(Ie,{state:o}),!n&&t.helpers.length>0&&e.jsx("span",{"aria-label":d.sessions.kidsLabel(t.helpers.length),className:"ml-0.5 rounded-lg border border-input px-1.5 font-mono text-[11px] leading-[18px] text-muted",children:d.sessions.kids(t.helpers.length)})]}),n&&t.helpers.map(u=>e.jsxs("a",{href:c,"aria-label":d.atelier.helperSeat(u.kind,t.name,u.task),...r,className:`${Zi} h-8 border-dashed border-line text-[12px] text-muted`,children:[u.kind,e.jsx(Ie,{state:gp(u)})]},u.id))]})}function I1({island:t,rigs:s,helpers:n,pressed:a,onPress:l}){const r=d.sessions,o=t.kind==="rig",i=hp(t),c=o?t.name==="kernel"&&s?r.kernelTag:r.rigTag:null,x=o?r.seats(t.sessions.length):d.atelier.plaqueCounts(t.sessions.length);return e.jsxs("section",{"aria-label":o?r.rigGroup(t.name):t.name,className:`flex flex-none flex-col gap-2.5 rounded-[10px] border bg-surface px-3 pt-2.5 pb-3 dark:bg-[oklch(0.18_0_0)] ${o?"border-task/45":"border-line"}`,children:[e.jsxs("div",{className:"flex items-center gap-2 text-[13px]",children:[o&&e.jsx(Ie,{state:"rig"}),e.jsx("b",{className:"font-semibold",children:t.name}),i&&e.jsx(Ie,{state:i}),c?e.jsx("small",{className:"text-[12px] text-muted",children:c}):e.jsx("small",{className:"text-[12px] text-muted",children:x}),o&&c===r.rigTag&&(s?e.jsx("a",{href:ne({name:"rigs"}),className:"ml-auto text-[12px] text-muted underline underline-offset-2",children:x}):e.jsx("span",{className:"ml-auto text-[12px] text-muted",children:x}))]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:t.sessions.map(u=>e.jsx(_1,{session:u,rig:o,helpers:n,pressed:a===u.id,onPress:l},u.id))})]})}function L1({sessions:t,by:s,onBy:n,helpers:a,onHelpers:l,rigs:r,pressed:o,onPress:i}){const c=nn(),x=t.filter(p=>p.state!=="exited").length,u=e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"grid size-[30px] flex-none place-items-center overflow-hidden",children:e.jsx(Zr,{size:30,theme:c,frozen:!0})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("b",{className:"font-semibold",children:d.sessions.deskTitle}),e.jsxs("small",{className:"text-[12px] text-muted",children:[d.atelier.desk," · ",d.atelier.watching(x)]})]})]});return e.jsxs(e.Fragment,{children:[e.jsx(T1,{by:s,onBy:n,helpers:a,onHelpers:l}),fp(t,s).map(p=>e.jsx(I1,{island:p,rigs:r,helpers:a,pressed:o,onPress:i},p.id)),e.jsxs("a",{href:ne({name:"chat"}),className:"flex min-h-[52px] flex-none items-center gap-2.5 rounded-[10px] border border-line bg-surface px-3 py-1.5 text-[13.5px] dark:bg-[oklch(0.18_0_0)]",children:[u,e.jsx(q,{name:"chevron",className:"size-4 text-muted"})]})]})}const Ji=`${Cs}sessions.filter`,O1=t=>Jc.includes(t);function D1(t,s){const n=Qe(s),[a,l]=f.useState(()=>{if(t)return t;try{const o=n==null?void 0:n.getItem(Ji);return O1(o)?o:"all"}catch{return"all"}}),r=o=>{l(o);try{n==null||n.setItem(Ji,o)}catch{}};return f.useEffect(()=>{t&&r(t)},[t]),[a,r]}function Wl(t,s,n,a){const l=Qe(a),[r,o]=f.useState(()=>{try{const c=l==null?void 0:l.getItem(`${Cs}${t}`);return s.includes(c)?c:n}catch{return n}});return[r,c=>{o(c);try{l==null||l.setItem(`${Cs}${t}`,c)}catch{}}]}const ux=["list","atelier"];function F1({value:t,onChange:s}){const n=d.sessions.mode;return e.jsx("div",{role:"group","aria-label":n.label,className:"flex flex-none overflow-hidden rounded-lg border border-input",children:ux.map(a=>e.jsx("button",{type:"button","aria-pressed":a===t,onClick:()=>s(a),className:"grid h-9 place-items-center px-3.5 text-[13px] font-medium text-muted aria-pressed:bg-raised aria-pressed:text-fg",children:n[a]},a))})}function z1({value:t,counts:s,onChange:n}){const a=d.sessions.filter;return e.jsx("div",{role:"group","aria-label":a.label,className:"flex flex-none rounded-lg border border-input p-0.5",children:Jc.map(l=>e.jsxs("button",{type:"button","aria-pressed":l===t,onClick:()=>n(l),className:"inline-flex h-8 min-w-0 flex-1 items-center justify-center gap-1.5 rounded-md text-[13px] font-medium whitespace-nowrap text-muted aria-pressed:bg-raised aria-pressed:text-fg",children:[a[l],e.jsx("span",{className:"font-mono text-meta",children:s[l]})]},l))})}function P1({session:t,filter:s,offline:n,threshold:a,now:l,closing:r,pressed:o,onPress:i,woken:c,drag:x}){const u=na(),m=ix(()=>i(t)),p=cx({onLong:()=>i(t),onLift:j=>x==null?void 0:x.onLift(j),onDrag:j=>x==null?void 0:x.onDrag(j),onDrop:()=>x==null?void 0:x.onDrop(),onCancel:()=>x==null?void 0:x.onCancel()}),h={...x?p:m,"data-reorder-row":t.id,...(x==null?void 0:x.lifted)!==null&&(x==null?void 0:x.lifted)!==void 0?{style:xx(x.lifted)}:{}},g=(u.name==="thread"||u.name==="terminal")&&u.sessionId===t.id,y=Sn(t),k=bp(t),S=td(t),b=s==="working"?S===void 0?void 0:`${S} %`:yp(t);return e.jsx(Zs,{href:ne({name:"thread",sessionId:t.id}),selected:g,stale:n,press:h,pressed:o,lead:e.jsxs(e.Fragment,{children:[e.jsx(Ie,{state:y,pulse:y==="work"&&!n}),e.jsx(gs,{tool:t.tool})]}),title:e.jsxs(e.Fragment,{children:[e.jsx("b",{className:"font-semibold",children:t.name}),c&&e.jsx("span",{"data-woken":"",className:"ml-1 inline-flex align-[-2px] text-muted",children:e.jsx(q,{name:"clock",className:"size-[13px]"})}),k>0&&e.jsx("span",{"aria-label":d.sessions.kidsLabel(k),className:"ml-1.5 font-mono text-small text-muted",children:d.sessions.kids(k)})]}),sub:r?e.jsx("span",{className:"text-attention",children:d.chat.closing}):e.jsx("span",{className:y==="ask"?"text-attention":void 0,children:jp(t,s,l)}),...y==="perm"?{subTone:"perm"}:{},...b!==void 0?{meta:b,metaWarn:s==="working"&&S!==void 0&&S/100>=a}:{}})}const xx=t=>({transform:`translateY(${t}px) scale(1.02)`,position:"relative",zIndex:5,boxShadow:"0 10px 28px #0008",background:"var(--color-surface)",borderRadius:10,touchAction:"none"}),va=()=>e.jsx("div",{"aria-hidden":"true","data-insert-line":"",className:"relative z-10 mx-3 my-0.5 h-[3px] rounded-full bg-task"});function B1({group:t,children:s,drag:n}){const a=t.kind==="rig",l=a?d.sessions.rigGroup(t.name):t.name,r=cx({onLong:()=>n==null?void 0:n.onLong(),onLift:o=>n==null?void 0:n.onLift(o),onDrag:o=>n==null?void 0:n.onDrag(o),onDrop:()=>n==null?void 0:n.onDrop(),onCancel:()=>n==null?void 0:n.onCancel()});return e.jsxs("section",{"aria-label":l,"data-reorder-section":t.id,className:"flex flex-col gap-1.5",style:n&&n.lifted!==null?xx(n.lifted):void 0,children:[e.jsxs("div",{className:"flex items-center gap-1.5 px-0.5 text-small font-semibold text-muted select-none",...n?r:{},children:[a&&e.jsx(Ie,{state:"rig"}),l,e.jsx("span",{className:"font-normal",children:t.sessions.length})]}),e.jsx(os,{...a?{tone:"rigs"}:{},children:s})]})}function q1({routines:t,now:s,offline:n}){const a=d.routines,l=eh(t,s);return l.count===0?null:e.jsx(os,{label:a.entry,children:e.jsxs(Zs,{href:ne({name:"routines"}),stale:n,lead:e.jsx(q,{name:"alarm",className:"size-5"}),title:e.jsx("b",{className:"font-semibold",children:a.entry}),...l.next?{sub:a.entrySub(l.count,l.next)}:{},children:[l.flagged>0&&e.jsx(zt,{tone:"perm",children:String(l.flagged)}),e.jsx(q,{name:"chevron",className:"size-4 text-muted"})]})})}function H1({store:t,filter:s,storage:n}){var E,z,K;const a=me(t),l=Xt(),[r,o]=D1(s,n),i=It(),[c,x]=Wl("sessions.mode",ux,"list",n),[u,m]=Wl("sessions.groupBy",Gr,"projects",n),[p,h]=Wl("sessions.helpers",["shown","hidden"],"shown",n),[g,y]=f.useState(null),k=g?a.sessions.get(g):void 0,S=!i&&c==="atelier",b=[...a.sessions.values()],j=ed(b),N=!a.fresh,$=(E=a.daemon)!=null&&E.sessionOrder&&a.daemon.atelier?{projects:a.projects,order:a.sessionOrder??{}}:null,C=Vr(b,r,$),M=U1(t,b,$,N),v=th(a.routines,b),A=((z=a.device)==null?void 0:z.contextNear)??kn,T=N?a.syncedAt?d.link.lastKnownAt(Be(a.syncedAt)):d.agents.offline:void 0,R=e.jsxs("a",{href:ne({name:"launch"}),className:Fe({variant:"primary",size:"sm",className:"flex-none"}),children:[e.jsx(q,{name:"plus",className:"size-4"}),d.sessions.new]}),P=(L,W)=>e.jsx("button",{type:"button",onClick:()=>o(L),className:Fe({size:"xs"}),children:W}),_=d.sessions,D=C.length===0&&b.length>0&&e.jsx(os,{label:_.filter[r],children:r==="waiting"?e.jsx(Jt,{framed:!1,glyph:null,title:_.filterEmpty,body:_.filterEmptyBody(j.working),action:P("all",_.seeAll)}):j.waiting>0?e.jsx(Jt,{framed:!1,glyph:null,title:_.emptyWorking.title,body:_.emptyWorking.waiting(j.waiting),action:P("waiting",_.seeWaiting)}):e.jsx(Jt,{framed:!1,glyph:null,title:_.emptyWorking.title,body:_.emptyWorking.idle,action:P("all",_.seeAll)})});return e.jsxs(Rs,{title:d.agents.title,subtitle:T,bodyClassName:"flex flex-col gap-2.5",actions:i?void 0:e.jsxs(e.Fragment,{children:[e.jsx(F1,{value:c,onChange:x}),R]}),wideActions:i?R:void 0,children:[k&&e.jsx(A1,{store:t,session:k,onDone:()=>y(null),...M.can?{order:M.stepsOf(C,k.id)}:{}}),M.sheet&&e.jsx(xb,{name:M.sheet.name,up:M.projectStep(C,M.sheet,-1),down:M.projectStep(C,M.sheet,1),onClose:()=>M.setSheet(null)}),e.jsx("div",{className:"sr-only","aria-live":"polite","aria-atomic":"true","data-reorder-said":"",children:M.said}),M.problem&&e.jsx("p",{role:"alert",className:"rounded-lg border border-destructive/40 px-3 py-2 text-small text-danger-fg",children:M.problem}),a.routines&&e.jsx(q1,{routines:a.routines,now:l,offline:N}),b.length===0?e.jsx(os,{label:d.agents.empty,children:e.jsx(Jt,{list:!0,glyph:e.jsx(q,{name:"sessions"}),title:d.agents.empty,body:d.agents.emptyHint,action:e.jsxs("a",{href:ne({name:"launch"}),className:Fe({variant:"primary",size:"sm"}),children:[e.jsx(q,{name:"plus",className:"size-4"}),d.sessions.newSession]})})}):S?e.jsx(L1,{sessions:b,by:u,onBy:m,helpers:p==="shown",onHelpers:()=>h(p==="shown"?"hidden":"shown"),rigs:!!((K=a.daemon)!=null&&K.rigs),pressed:g,onPress:L=>y(L.id)}):e.jsxs(e.Fragment,{children:[e.jsx(z1,{value:r,counts:j,onChange:o}),C.map((L,W)=>{const ae=M.can&&L.kind==="project",U=M.lift,O=U&&U.kind==="session"&&U.gid===L.id?U:null,B=O&&O.to!==O.from?O.to<O.from?O.to:O.to+1:-1,Z=U&&U.kind==="project"&&U.to!==U.from&&(U.to<U.from?U.to:U.to+1)===W;return e.jsxs("div",{className:"contents",children:[Z&&e.jsx(va,{}),e.jsxs(B1,{group:L,...ae&&L.project?{drag:M.projectDrag(C,L)}:{},children:[L.sessions.flatMap((H,X)=>[...X===B?[e.jsx(va,{},"line")]:[],e.jsx(P1,{session:H,filter:r,offline:N,threshold:A,now:l,closing:Qm(H,a.ops,l),pressed:g===H.id,onPress:te=>y(te.id),woken:v.has(H.id),...ae?{drag:M.rowDrag(L,X)}:{}},H.id)]),B===L.sessions.length&&e.jsx(va,{})]}),U&&U.kind==="project"&&U.to!==U.from&&U.to>U.from&&U.to===W&&W===C.filter(H=>H.kind==="project"&&H.project).length-1&&e.jsx(va,{})]},L.id)}),D]})]})}const ec=(t,s,n)=>t.filter((a,l)=>l!==s&&a<n).length,tc=(t,s,n)=>{const a=[...t],[l]=a.splice(s,1);return a.splice(n,0,l),a};function U1(t,s,n,a){const l=d.sessions.reorder,r=me(t),[o,i]=f.useState(null),[c,x]=f.useState(""),[u,m]=f.useState(null),[p,h]=f.useState(null),g=!!n&&!a,y=(N,$)=>N.status==="applied"?null:N.status==="rejected"&&N.reason==="unavailable"?l.outdated($):N.status==="rejected"?l.stale($):l.offline($),k=(N,$,C)=>{var R;if($===C||C<0||C>=N.sessions.length)return;const M=N.sessions[$],v=tc(N.sessions,$,C),A=((R=Vr(s,"all",n).find(P=>P.id===N.id))==null?void 0:R.sessions)??N.sessions,T=pm(A.map(P=>P.id),v.map(P=>P.id));m(null),t.orderSessions(N.project??null,T).then(P=>{const _=y(P,M.name);_?m(_):x(l.moved(M.name,l.ordinal(C+1,!0),v.length,N.name))})},S=()=>((n==null?void 0:n.projects)??[]).map(N=>N.id),b=(N,$)=>{const C=S(),M=C.indexOf(N.project??"");M<0||M===$||$<0||$>=C.length||(m(null),t.orderProjects(tc(C,M,$)).then(v=>{const A=y(v,N.name);A?m(A):x(l.movedProject(N.name,l.ordinal($+1,!1),C.length))}))},j=N=>[...document.querySelectorAll(N)].map($=>{const C=$.getBoundingClientRect();return C.top+C.height/2});return{can:g,said:c,problem:u,lift:o,sheet:p,setSheet:h,rowDrag:(N,$)=>({lifted:o&&o.kind==="session"&&o.gid===N.id&&o.from===$?o.dy:null,onLift:C=>i({kind:"session",gid:N.id,from:$,to:$,y0:C,dy:0,mids:j(`[data-reorder-section="${CSS.escape(N.id)}"] [data-reorder-row]`)}),onDrag:C=>i(M=>M&&{...M,dy:C-M.y0,to:ec(M.mids,M.from,C)}),onDrop:()=>{const C=o;i(null),C&&k(N,C.from,C.to)},onCancel:()=>i(null)}),projectDrag:(N,$)=>{const C=N.filter(v=>v.kind==="project"&&v.project),M=C.indexOf($);return{lifted:o&&o.kind==="project"&&o.gid===$.id?o.dy:null,onLong:()=>h($),onLift:v=>i({kind:"project",gid:$.id,from:M,to:M,y0:v,dy:0,mids:C.map(A=>j(`[data-reorder-section="${CSS.escape(A.id)}"]`)[0]??0)}),onDrag:v=>i(A=>A&&{...A,dy:v-A.y0,to:ec(A.mids,A.from,v)}),onDrop:()=>{const v=o;if(i(null),!v||v.to===v.from)return;const A=C[v.to],T=A?S().indexOf(A.project):-1;T>=0&&b($,T)},onCancel:()=>i(null)}},stepsOf:(N,$)=>{const C=N.find(v=>v.kind==="project"&&v.sessions.some(A=>A.id===$));if(!C)return{};const M=C.sessions.findIndex(v=>v.id===$);return{...M>0?{up:()=>k(C,M,M-1)}:{},...M<C.sessions.length-1?{down:()=>k(C,M,M+1)}:{}}},projectStep:(N,$,C)=>{var T;const M=S(),v=M.indexOf($.project??""),A=v+C;return v<0||A<0||A>=M.length||!((T=r.daemon)!=null&&T.projectEdit)?void 0:()=>b($,A)}}}const sc=34,W1=120;function K1({value:t,onChange:s,onSend:n,canSend:a,images:l,running:r,offline:o,onStop:i,fieldRef:c}){const x=f.useRef(null),u=c??x;f.useLayoutEffect(()=>{const p=u.current;p&&(p.style.height=`${sc}px`,p.style.height=`${Math.min(W1,Math.max(sc,p.scrollHeight))}px`)},[t,u]);const m=r||o;return e.jsxs("div",{className:"group flex flex-none flex-col gap-1.5 pt-1.5 pb-2",children:[l.items.length>0&&e.jsx(Ou,{items:l.items,onRemove:l.remove,size:{w:72,h:54},removeLabel:d.images.remove,lang:Lc}),e.jsxs("div",{className:`flex min-w-0 items-end gap-2 rounded-[10px] border border-input bg-surface py-[5px] pr-[5px] pl-3 focus-within:border-ring focus-within:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)] ${o?"opacity-55":""}`,children:[e.jsx("label",{htmlFor:"chat-ask",className:"sr-only",children:d.chat.field}),e.jsx("textarea",{id:"chat-ask",ref:u,rows:1,value:o?"":t,disabled:o,maxLength:ta,enterKeyHint:"enter",placeholder:r?d.chat.answering:d.chat.placeholder,onChange:p=>s(p.target.value),onPaste:p=>{const h=Fu(p);h.length===0||m||(p.preventDefault(),l.add(h))},onKeyDown:p=>{p.key!=="Enter"||p.nativeEvent.isComposing||p.shiftKey||!Qa()||(p.preventDefault(),a&&n())},className:"max-h-[120px] min-h-[34px] min-w-0 flex-1 resize-none bg-transparent py-[6px] text-base leading-[22px] text-fg outline-none placeholder:text-muted"}),r?e.jsx("button",{type:"button",onClick:i,"aria-label":d.chat.stop,title:d.chat.stop,className:"grid size-9 flex-none place-items-center rounded-lg bg-raised text-fg",children:e.jsx(q,{name:"stop",className:"size-4"})}):e.jsx("button",{type:"button",disabled:!a,onClick:n,"aria-label":d.chat.send,title:d.chat.send,className:"grid size-9 flex-none place-items-center rounded-lg bg-primary text-primary-fg disabled:opacity-40",children:e.jsx(q,{name:"send",className:"size-[18px]"})})]}),e.jsxs("p",{className:"hidden items-center gap-1 text-[12px] leading-4 text-muted group-focus-within:flex",children:[e.jsx(Du,{onFiles:l.add,disabled:m,className:"text-[12px] leading-4 text-muted disabled:opacity-50",children:d.chat.plusImage}),Qa()&&e.jsxs("span",{children:["· ",d.chat.enterSends]})]}),l.error&&e.jsx("p",{role:"alert",className:"text-body text-attention",children:l.error})]})}const Kl=Pe({variant:"primary",size:"sm",className:"min-w-[64px] flex-none"}),ka=Pe({size:"sm",className:"min-w-[64px] flex-none"}),Vl="w-full rounded-control border border-line bg-surface px-2.5 py-2 text-body text-fg",pn=t=>t.replace(/\s*[\r\n]+\s*/g," ").trim();function V1({task:t,store:s,fresh:n}){const a=d.chat.point.note,l=t.brain,r=f.useId(),[o,i]=f.useState(!1),[c,x]=f.useState(l.fact),[u,m]=f.useState(l.title??l.note),[p,h]=f.useState(l.when??""),[g,y]=f.useState(!1),[k,S]=f.useState(null),b=async $=>{y(!0),S(null);const C=pn(c),M=$?{yes:$,...C&&C!==l.fact?{text:C}:{},...l.create&&pn(u)?{title:pn(u)}:{},...l.create&&pn(p)?{when:pn(p)}:{}}:{yes:$},v=await s.answerNote(t.id,M);y(!1),v.status!=="applied"&&S(v.status==="rejected"&&v.reason==="confirm_required"?a.confirmRequired:v.status==="rejected"&&v.reason==="stale"?a.stale:v.status==="cancelled"?a.cancelled:v.status==="expired"?a.expired:a.failed)},j=l.kind==="flag"?a.flag(l.note):l.create?a.create(l.note):a.add(l.note),N=!n||g;return e.jsxs("div",{className:"flex flex-col gap-2 rounded-control bg-raised p-2.5","data-note-proposal":t.id,children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-1.5 text-body",children:[e.jsx(ra,{tone:"attention",label:a.tag}),e.jsx("span",{className:"font-medium",children:t.giverName??d.chat.point.someone}),e.jsx("span",{className:"text-muted",children:j})]}),l.create&&e.jsxs(e.Fragment,{children:[e.jsxs("label",{htmlFor:`${r}t`,className:"flex flex-col gap-1 text-small text-muted",children:[a.titleField,e.jsx("input",{id:`${r}t`,className:Vl,value:u,disabled:N,onChange:$=>m($.target.value)})]}),e.jsxs("label",{htmlFor:`${r}w`,className:"flex flex-col gap-1 text-small text-muted",children:[a.whenField,e.jsx("input",{id:`${r}w`,className:Vl,value:p,disabled:N,onChange:$=>h($.target.value)})]})]}),o?e.jsxs("label",{htmlFor:`${r}f`,className:"flex flex-col gap-1 text-small text-muted",children:[a.field,e.jsx("textarea",{id:`${r}f`,className:Vl,rows:3,value:c,disabled:N,onChange:$=>x($.target.value)})]}):e.jsx("p",{className:"m-0 whitespace-pre-wrap break-words rounded-control bg-surface px-2.5 py-2 text-body",children:l.fact}),l.source&&!o&&e.jsx("span",{className:"break-words text-small text-muted",children:a.source(l.source)}),k&&e.jsx("p",{role:"alert",className:"m-0 text-small text-approval",children:k}),e.jsx("div",{className:"flex flex-wrap gap-2",children:l.kind==="flag"?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Kl,disabled:N,onClick:()=>{b(!0)},children:a.mark}),e.jsx("button",{type:"button",className:ka,disabled:N,onClick:()=>{b(!1)},children:a.ignore})]}):o?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Kl,disabled:N||!pn(c),onClick:()=>{b(!0)},children:a.editYes}),e.jsx("button",{type:"button",className:ka,disabled:N,onClick:()=>{i(!1),x(l.fact)},children:a.cancel})]}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:Kl,disabled:N,onClick:()=>{b(!0)},children:l.create?a.createYes:a.yes}),e.jsx("button",{type:"button",className:ka,disabled:N,onClick:()=>i(!0),children:a.edit}),e.jsx("button",{type:"button",className:ka,disabled:N,onClick:()=>{b(!1)},children:a.no})]})})]})}const Ln=Pe({size:"sm",className:"min-w-[64px] flex-none"}),G1=Pe({variant:"primary",size:"sm",className:"min-w-[64px] flex-none"}),nc="mt-1 text-meta tracking-[.4px] text-muted";function wa({tone:t}){return e.jsx("span",{"aria-hidden":"true",className:`size-2 flex-none rounded-full ${t==="ok"?"bg-ok":t==="danger"?"bg-approval":"bg-attention"}`})}function X1(t){return t.state==="done"?d.chat.point.finished:t.state==="refused"?d.chat.point.refused:d.chat.point.dropped}function Y1({store:t,sessions:s,tasks:n,syncedAt:a,fresh:l,threshold:r=kn,onAnswer:o,usage:i=[],usageAlert:c=null}){const x=Xt(),[u,m]=f.useState(null),p=new Map(s.map(v=>[v.id,v])),h=Vt(s),g=Wf(n.values()),y=Kf(n.values()),k=s.filter(v=>v.state!=="exited"&&!v.handover&&v.context&&v.context.used/v.context.window>=r),S=Vf(n.values()).slice(0,5),b=d.chat.point,j=ua(i,x,l),N=l?xh(j,c,x):[],$=h.length+N.length+g.length+y.length+k.length,C=(v,A,T)=>{const R=h.find(P=>P.sessionId===v&&P.key===A);R&&(m(`${v}/${A}`),t.decide(v,T,{expect:{key:R.key,kind:R.kind,text:R.text}}))},M=v=>{t.seeTask(v.id),tn({name:"thread",sessionId:v.owner})};return e.jsxs("section",{"aria-label":b.label,className:"flex flex-col gap-2.5 rounded-card border border-line bg-surface p-4",children:[e.jsxs("h2",{className:"flex items-baseline gap-2 text-base font-bold",children:[b.title,a&&e.jsx("span",{className:"text-small font-normal text-muted",children:b.ago(yn(a,x))})]}),$===0&&e.jsx("p",{className:"text-body text-muted",children:b.calm}),$>0&&e.jsxs("div",{role:"group","aria-label":b.yoursLabel,className:"flex flex-col gap-2",children:[e.jsxs("h3",{className:nc,children:[b.yours," · ",$]}),h.map(v=>{p.get(v.sessionId);const A=v.kind==="permission"&&v.risk!=="high"&&v.source!=="rpc",T=`${v.sessionId}/${v.key}`;return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wa,{tone:"danger"}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5 text-body",children:[e.jsx("span",{className:"font-medium",children:v.botName}),e.jsx("span",{className:"min-w-0 truncate font-mono",children:wn(v)})]}),A?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",className:G1,disabled:!l||u===T,onClick:()=>C(v.sessionId,v.key,"accept"),children:b.yes}),e.jsx("button",{type:"button",className:Ln,disabled:!l||u===T,onClick:()=>C(v.sessionId,v.key,"deny"),children:b.no})]}):e.jsx("a",{href:ne({name:"request",sessionId:v.sessionId,key:v.key}),className:Ln,children:b.see})]},T)}),N.map(({harness:v,window:A,tone:T})=>{const R=ko(A);return e.jsxs("div",{"data-usage-over":T,className:"flex items-center gap-2","aria-label":T==="red"?b.reachedLabel(b.harnessShort[v]??v,R):b.overLabel(b.harnessShort[v]??v,R,A.pct),children:[e.jsx("span",{"aria-hidden":"true",className:`flex size-5 flex-none items-center justify-center rounded-md ${T==="red"?"bg-danger-bg text-approval":"text-attention"}`,style:T==="red"?void 0:{background:"var(--status-warning-soft)"},children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("path",{d:"M12 14l4-4"}),e.jsx("path",{d:"M3.3 19a10 10 0 1 1 17.4 0"})]})}),e.jsxs("span",{className:"min-w-0 flex-1 text-body",children:[b.harnessShort[v]??v," · ",R," ",e.jsx("b",{className:`font-medium ${wo[T]}`,children:d.percent(A.pct)})]}),A.resetsAt&&e.jsxs("span",{className:"flex-none whitespace-nowrap text-small text-muted",children:["↺ ",oo(A.resetsAt,x,!0)]})]},`usage:${v}:${A.kind}:${A.model??A.pool??""}`)}),g.map(v=>v.brain?e.jsx(V1,{task:{...v,brain:v.brain},store:t,fresh:l},`decision:${v.id}`):e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"mt-2 flex",children:e.jsx(wa,{tone:"attention"})}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-0.5 text-body",children:[e.jsxs("span",{className:"flex flex-wrap items-center gap-1.5",children:[e.jsx(ra,{tone:"attention",label:b.decision}),e.jsx("span",{className:"font-medium",children:v.giverName??b.someone}),e.jsx("span",{className:"text-muted",children:b.asks})]}),e.jsx("span",{className:"break-words",children:v.title}),v.text&&e.jsx("span",{className:"whitespace-pre-wrap break-words text-small text-muted",children:v.text})]}),o&&e.jsx("button",{type:"button",className:Ln,"aria-label":b.answerLabel(v.title),onClick:()=>o(v),children:b.answer})]},`decision:${v.id}`)),y.map(v=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wa,{tone:v.state==="done"?"ok":"attention"}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5 text-body",children:[e.jsx("span",{className:"font-medium",children:v.ownerName}),e.jsx("span",{children:X1(v)})]}),e.jsx("button",{type:"button",className:Ln,onClick:()=>M(v),children:b.see})]},v.id)),k.map(v=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(wa,{tone:"attention"}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-wrap items-center gap-1.5 text-body",title:b.nearHint,children:[e.jsx("span",{className:"font-medium",children:v.name}),e.jsxs("span",{className:"text-attention",children:["· ",b.near(Math.round(v.context.used/v.context.window*100))]})]}),e.jsx("a",{href:ne({name:"thread",sessionId:v.id}),className:Ln,children:b.see})]},`near:${v.id}`))]}),e.jsx(bj,{usage:j,now:x,alert:c}),S.length>0&&e.jsxs("div",{role:"group","aria-label":b.givenLabel,className:"flex flex-col gap-2",children:[e.jsx("h3",{className:nc,children:b.given}),S.map(v=>e.jsxs("a",{href:ne({name:"thread",sessionId:v.owner}),className:"flex items-center gap-2 text-body",children:[e.jsx("code",{className:"flex-none font-mono text-small text-muted",children:v.id}),e.jsxs("span",{className:"min-w-0 flex-1 truncate",children:[v.title," ",e.jsxs("span",{className:"text-muted",children:["→ ",v.ownerName]})]}),e.jsx("span",{className:v.state==="taken"?"text-info":"text-muted",children:b.state[v.state]})]},v.id))]})]})}const Zt=()=>d.chat.history,Da=t=>{const s=new Date(t);return`${s.getHours()}:${String(s.getMinutes()).padStart(2,"0")}`},Sa=t=>`${t.getFullYear()}-${t.getMonth()}-${t.getDate()}`;function mx(t,s){const n=new Date(t);if(Sa(n)===Sa(s))return Zt().today;const a=new Date(s);return a.setDate(s.getDate()-1),Sa(n)===Sa(a)?Zt().yesterday:n.toLocaleDateString(lt,{weekday:"short",day:"numeric",month:"short"})}const Q1=(t,s)=>`${mx(t.startedAt,s)}, ${Da(t.startedAt)}`,Z1="flex min-h-12 w-full items-center gap-3 border-b border-line px-3.5 py-2 text-left last:border-b-0",J1="px-1 pt-1.5 text-[12px] font-medium text-muted";function Gl({first:t,sub:s,current:n=!1,onClick:a}){return e.jsxs("button",{type:"button",onClick:a,"aria-current":n||void 0,className:`${Z1} ${n?"bg-raised":""}`,children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("b",{className:"truncate text-[14.5px] font-medium",children:Zt().quote(t)}),e.jsx("small",{className:"truncate text-[12px] text-muted",children:s})]}),!n&&e.jsx(q,{name:"chevron",className:"size-4 text-muted"})]})}function Xl({children:t}){return e.jsx("div",{className:"flex max-h-[55vh] flex-col overflow-y-auto rounded-[10px] border border-line",children:t})}function ey({conversations:t,kept:s,turns:n,running:a,now:l,onClose:r,onReset:o,onOpen:i,onScrollTo:c}){const x=f.useId();if(!s){const p=n.filter(h=>h.question);return e.jsxs(dt,{labelledBy:x,onClose:r,children:[e.jsx("h2",{id:x,className:"text-base font-semibold",children:Zt().today}),p.length===0?e.jsx("p",{className:"text-body text-muted",children:Zt().none}):e.jsx(Xl,{children:p.map(h=>e.jsx(Gl,{first:h.question,sub:Da(h.askedAt),onClick:()=>c(h.qid)},h.qid))})]})}const u=t.list,m=[];for(const p of(u==null?void 0:u.past)??[]){const h=mx(p.startedAt,l),g=m.at(-1);(g==null?void 0:g.day)===h?g.items.push(p):m.push({day:h,items:[p]})}return e.jsxs(dt,{labelledBy:x,onClose:r,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("h2",{id:x,className:"flex-1 text-base font-semibold",children:Zt().title}),e.jsxs("button",{type:"button",disabled:a,onClick:o,className:Fe({size:"sm"}),children:[e.jsx(q,{name:"edit",className:"size-4"}),d.chat.reset]})]}),u&&(u.current||m.length>0)&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[u.current&&e.jsx(Xl,{children:e.jsx(Gl,{current:!0,first:u.current.first,onClick:r,sub:[Zt().current,Zt().count(u.current.count),Zt().since(Da(u.current.startedAt))].join(" · ")})}),m.map(p=>e.jsxs("section",{"aria-label":p.day,className:"flex flex-col gap-1",children:[e.jsx("h3",{className:J1,children:p.day}),e.jsx(Xl,{children:p.items.map(h=>e.jsx(Gl,{first:h.first,sub:`${Zt().count(h.count)} · ${Da(h.startedAt)}`,onClick:()=>i(h)},h.id))})]},p.day))]}),e.jsx("p",{className:"text-small text-muted",children:Zt().kept})]}),u&&!u.current&&m.length===0&&e.jsx("p",{className:"text-body text-muted",children:Zt().empty})]})}const _r=3,Ir=t=>`${t.sessionId}/${t.key}`;function ty(t,s){return new Set(t.filter(n=>n.kind==="pane"||n.kind==="reply").flatMap(n=>{const a=n.id??(n.name?s.get(n.name):void 0);return a?[a]:[]}))}function sy({store:t,items:s,onGo:n}){const a=hr(s.slice(0,_r).map(r=>({id:Ir(r),value:r}))),l=s.length-_r;return a.entries.length===0?null:e.jsxs("div",{className:vo,children:[a.entries.map(r=>e.jsx(ny,{store:t,item:r.value,ghost:r.ghost,onGone:()=>a.dismiss(r.id),onGo:n},r.id)),l>0&&e.jsx("a",{href:ne({name:"atoi"}),className:"text-small text-info underline underline-offset-2",children:d.chat.inAnswer.more(l)})]})}function ny({store:t,item:s,ghost:n,onGone:a,onGo:l}){var c,x,u;const r=me(t),o=Fs(),i=r.sessions.get(s.sessionId);return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[!n&&e.jsx("span",{className:"text-[11.5px] text-muted",children:d.chat.inAnswer.request(s.botName)}),e.jsx(io,{store:t,item:s,session:i,mode:Qr(s,(c=r.capabilities)==null?void 0:c[s.tool],(i==null?void 0:i.readOnly)===!0),outcome:Gn(s,[...r.sessions.values()],r.ops),fresh:r.fresh,ghost:n,changed:!1,onReread:()=>{},canConfirm:((x=r.device)==null?void 0:x.confirm)===!0&&o,enroll:o&&((u=r.device)==null?void 0:u.confirm)!==!0,onGone:a,onCheck:l})]})}function ay({names:t}){return t.length===0?null:e.jsx("div",{className:vo,children:t.map(s=>e.jsxs("span",{className:"text-[11.5px] text-muted",children:[d.chat.inAnswer.settled," · ",s]},s))})}const ly="kernel";function ry(t,s){var l,r,o;const n=(r=(l=t.find(i=>i.rig&&i.rig.name!==ly))==null?void 0:l.rig)==null?void 0:r.name,a=(o=t.find(i=>i.name&&!i.rig))==null?void 0:o.name;return[d.chat.suggestions.waiting,...s.getHours()<12?[d.chat.suggestions.summarize]:[],...n?[d.chat.suggestions.rig(n)]:a?[d.chat.suggestions.session(a)]:[]]}const Fa="grid size-11 flex-none place-items-center rounded-lg text-muted active:bg-raised disabled:opacity-40";function px({frozen:t,onClose:s,children:n}){return e.jsxs("header",{className:"bleed flex h-[58px] flex-none items-center gap-1.5 border-b border-line pr-1.5 pl-3.5",children:[e.jsx("span",{"aria-hidden":"true",className:"flex size-[22px] flex-none",children:e.jsx(bs,{size:22,frozen:t})}),e.jsx("h2",{className:"text-base font-semibold",children:d.chat.title}),e.jsx("span",{className:"flex-1"}),n,e.jsx(fx,{onClose:s})]})}function fx({onClose:t}){return e.jsx("button",{type:"button",onClick:t,"aria-label":d.chat.pane.close,title:d.chat.pane.close,className:Fa,children:e.jsx(q,{name:"close"})})}function ac({store:t,onClose:s}){var H,X,te,pe,ue;const n=me(t),a=It(),l=Pc(t),r=[...n.sessions.values()],[o,i]=f.useState(""),c=Ku(t),[x,u]=f.useState(null),m=f.useRef(null),p=l.live!==null,h=!n.fresh,g=Zm(t),y=!!((H=n.daemon)!=null&&H.conversations),[k,S]=f.useState(!1),[b,j]=f.useState(null),N=f.useRef(new Map);hu(t);const $=f.useRef(null),[C,M]=f.useState(0);f.useEffect(()=>{const F=$.current;!C||!F||(F.focus(),F.setSelectionRange(F.value.length,F.value.length))},[C]);const v=F=>{u(null),i(d.chat.point.answerDraft(F.title,F.id,F.giverName??d.chat.point.someone)),M(w=>w+1)},A=f.useRef([]);f.useEffect(()=>{const F=l.error;(F==null?void 0:F.text)!==void 0&&(i(w=>w||F.text),A.current.length&&(c.putBack(A.current),A.current=[]),u(F.code==="offline"?null:{question:F.text,note:F.code==="busy"?d.chat.busy:d.chat.failed}),t.clearChatError())},[l.error,t]),f.useEffect(()=>{var F,w;(w=(F=m.current)==null?void 0:F.scrollIntoView)==null||w.call(F,{block:"end"})},[l.turns.length,(X=l.live)==null?void 0:X.text,(te=l.live)==null?void 0:te.steps.length,x]);const T=(F,w=[])=>{u(null),t.ask(F,w)},R=()=>{const F=o.trim();if(!F&&c.items.length===0||p||h||!c.ready)return;const w=c.ids();A.current=c.clear(),T(F,w),i("")},P=r.map(F=>({id:F.id,name:F.name,repo:F.repo,exited:F.state==="exited",state:F.state,helpers:F.helpers})),_=()=>{u(null),t.resetChat()},D=new Map,E=new Set;for(const F of r)F.name&&(D.has(F.name)?E.add(F.name):D.set(F.name,F.id));for(const F of E)D.delete(F);const z=Vt(r),K=new Set(z.map(Ir)),L=l.turns.at(-1),W=!p&&(L==null?void 0:L.answer)!==void 0?L:void 0,ae=W?(()=>{const F=ty(W.steps,D);return z.filter(w=>F.has(w.sessionId))})():[];if(W){const F=N.current.get(W.qid)??new Map;for(const w of ae.slice(0,_r))F.set(Ir(w),w.botName);N.current.set(W.qid,F)}const U=F=>F===(W==null?void 0:W.qid)?e.jsx(sy,{store:t,items:ae}):e.jsx(ay,{names:[...new Set([...N.current.get(F)??[]].filter(([w])=>!K.has(w)).map(([,w])=>w))]}),O=F=>({at:F,usage:n.usage??[],alert:n.usageAlert,fresh:n.fresh}),B=()=>{t.askConversations(),S(!0)},Z=e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",onClick:B,"aria-haspopup":"dialog","aria-label":y?d.chat.history.title:d.chat.history.today,title:y?d.chat.history.title:d.chat.history.today,className:Fa,children:e.jsx(q,{name:"clock"})}),e.jsx("button",{type:"button",disabled:p,onClick:_,"aria-label":d.chat.reset,title:d.chat.reset,className:Fa,children:e.jsx(q,{name:"edit"})})]});if(b){const F=g.open[b.id];return e.jsxs(e.Fragment,{children:[e.jsx(la,{name:Q1(b,new Date),back:e.jsx("button",{type:"button","aria-label":d.nav.backTo.chat,title:d.nav.backTo.chat,onClick:()=>j(null),className:Tt({className:"text-muted"}),children:e.jsx(q,{name:"back"})}),...s?{more:e.jsx(fx,{onClose:s})}:{}}),e.jsxs("p",{className:"bleed flex flex-none items-center gap-2 border-b border-line bg-raised px-3.5 py-2 text-small text-muted",children:[e.jsx(q,{name:"clock",className:"size-4 flex-none"}),d.chat.history.pastBanner]}),e.jsxs("main",{"data-tab-scroll":s?void 0:"",className:"flex min-h-0 flex-1 flex-col gap-2.5 overflow-y-auto overscroll-contain py-3 text-[14px]",children:[F&&"gone"in F&&e.jsx("p",{className:"px-1 text-body text-muted",children:d.chat.history.gone}),F&&"turns"in F&&F.turns.map(w=>{const I=F.limits.find(V=>V.qid===w.qid);return e.jsx(Pi,{store:t,turn:w,list:P,canConfirm:!1,live:null,sessions:r.length,readOnly:!0,limits:I&&O(I.at)},w.qid)})]}),e.jsx("div",{className:"flex-none pt-1.5 pb-3",children:e.jsx("button",{type:"button",onClick:()=>j(null),className:Fe({variant:"primary",className:"w-full"}),children:d.chat.history.backToday})})]})}return e.jsxs(e.Fragment,{children:[s?e.jsx(px,{frozen:h,onClose:s,children:Z}):e.jsxs("header",{className:"bleed flex h-14 flex-none items-center gap-1 border-b border-line pr-1 pl-3.5",children:[e.jsxs("span",{className:"mr-1 flex items-center gap-2 text-[17px] font-semibold",children:[e.jsx("span",{"aria-hidden":"true",className:"flex size-7 flex-none",children:e.jsx(bs,{size:28,frozen:h})}),e.jsx("h1",{children:d.chat.title})]}),e.jsx(cl,{}),e.jsx("span",{className:"flex-1"}),Z,!a&&e.jsx("a",{href:ne({name:"connection"}),"aria-label":d.nav.settings,title:d.nav.settings,className:Fa,children:e.jsx(q,{name:"gear"})})]}),e.jsxs("main",{"data-tab-scroll":s?void 0:"",className:"flex min-h-0 flex-1 flex-col gap-2.5 overflow-y-auto overscroll-contain py-3 text-[14px]",children:[e.jsx(js,{}),l.turns.length===0&&!x&&e.jsxs("div",{className:"flex flex-1 flex-col justify-end gap-2.5",children:[e.jsx(Y1,{store:t,sessions:r,tasks:n.tasks,syncedAt:n.syncedAt,fresh:n.fresh,onAnswer:v,...((pe=n.device)==null?void 0:pe.contextNear)!==void 0?{threshold:n.device.contextNear}:{},usage:n.usage??[],usageAlert:n.usageAlert}),!h&&e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[ry(r,new Date).map(F=>e.jsx("button",{type:"button",onClick:()=>T(F),className:"inline-flex h-[34px] items-center gap-1.5 rounded-full border border-input bg-surface px-3 text-[13px] text-fg",children:F},F)),((ue=n.daemon)==null?void 0:ue.launch)&&e.jsxs("a",{href:ne({name:"launch"}),className:"inline-flex h-[34px] items-center gap-1.5 rounded-full border border-dashed border-input px-3 text-[13px] text-muted",children:[e.jsx(q,{name:"plus",className:"size-3.5"}),d.chat.suggestions.newSession]})]})]}),l.turns.map(F=>{var w,I;return e.jsx("div",{id:`turn-${F.qid}`,className:"contents",children:e.jsx(Pi,{store:t,turn:F,list:P,canConfirm:!!((w=n.device)!=null&&w.confirm),live:((I=l.live)==null?void 0:I.qid)===F.qid?l.live:null,sessions:r.length,...!p&&!h?{onAskAgain:V=>T(V)}:{},limits:l.limits[F.qid]!==void 0?O(l.limits[F.qid]):void 0,inAnswer:U(F.qid)})},F.qid)}),x&&e.jsxs("div",{className:"flex flex-col gap-1.5",children:[x.question&&e.jsx("div",{className:"max-w-[85%] self-end whitespace-pre-wrap break-words rounded-[12px_12px_4px_12px] bg-raised px-3 py-2",children:x.question}),e.jsx("p",{role:"status",className:"text-[13.5px] text-attention",children:x.note})]}),e.jsx("div",{ref:m})]}),e.jsx(K1,{value:o,onChange:i,onSend:R,canSend:(o.trim()!==""||c.items.length>0)&&c.ready&&!p&&!h,images:c,running:p,offline:h,onStop:()=>t.cancelAsk(),fieldRef:$}),h&&e.jsx("p",{role:"status",className:"flex-none pb-2 text-[13px] text-attention",children:d.chat.offline}),k&&e.jsx(ey,{conversations:g,kept:y,turns:l.turns,running:p,now:new Date,onClose:()=>S(!1),onReset:()=>{S(!1),_()},onOpen:F=>{S(!1),t.openConversation(F.id),j(F)},onScrollTo:F=>{var w,I,V;S(!1),(V=(I=(w=document.getElementById(`turn-${F}`))==null?void 0:w.firstElementChild)==null?void 0:I.scrollIntoView)==null||V.call(I,{block:"start"})}})]})}const ea=(t,s)=>(t.slice(0,s===void 0?void 0:s*4).match(/.{1,4}/g)??[]).join(" "),hx=t=>ea(t,6),oy=t=>ea(t,2);function gx(){const t=globalThis;if(!t.Notification||!t.PushManager)return"unsupported";const s=t.navigator;return s&&"standalone"in s&&s.standalone!==!0?"unsupported":t.Notification.permission==="denied"?"denied":"ok"}const iy=t=>{const s=atob(t.replace(/-/g,"+").replace(/_/g,"/"));return Uint8Array.from(s,n=>n.charCodeAt(0))};function bx(t,s){return new Promise(n=>{const a=()=>{var o;const r=(o=t.getState().ops[s])==null?void 0:o.phase;return!r||ps(r)&&r!=="uncertain"?!1:(l(),n(r==="applied"?"applied":"other"),!0)},l=t.subscribe(a);a()})}async function cy(t,s=(n,a)=>globalThis.fetch(n,a)){var a;if(gx()==="unsupported")return"unsupported";try{if(await Notification.requestPermission()!=="granted")return"denied";const l=await s("/push/key",{credentials:"same-origin",cache:"no-store"});if(l.status===404)return"unavailable";if(!l.ok)return"failed";const r=await l.json();if(typeof r.publicKey!="string")return"failed";const o=r.publicKey,i=iy(o),{pushManager:c}=await navigator.serviceWorker.ready;await((a=await c.getSubscription())==null?void 0:a.unsubscribe());const x=await c.subscribe({userVisibleOnly:!0,applicationServerKey:i}),u=fm.safeParse(x.toJSON());if(!u.success)return"failed";const m=t.pushSubscribe(u.data,o);return m===null?"failed":await bx(t,m)==="applied"?"on":"failed"}catch{return"failed"}}async function dy(t){const s=t.pushUnsubscribe(),n=s!==null&&await bx(t,s)==="applied";try{await(await navigator.serviceWorker.ready).pushManager.getSubscription().then(a=>a==null?void 0:a.unsubscribe())}catch{}return n}const At=d.notifications,uy=t=>t==="denied"?At.denied:t==="unsupported"?At.unsupported:t==="unavailable"?At.noPush:t==="failed"?At.failed:null;function jx(t,s){var x;const n=(x=me(t).device)==null?void 0:x.push,[a,l]=f.useState(!1),[r,o]=f.useState(null);return{push:n,busy:a,problem:r,enable:async()=>{if(a)return"failed";l(!0),o(null);const u=await cy(t,s);return l(!1),o(uy(u)),u},disable:async()=>{a||(l(!0),o(null),await dy(t),l(!1))}}}function xy({store:t,fetchImpl:s}){const n=jx(t,s);if(!n.push)return null;const a=n.push==="on";return e.jsxs("div",{className:"flex flex-col gap-2 border-b border-line px-4 py-3 text-body last:border-b-0",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("dt",{className:"flex-none text-muted",children:At.row}),e.jsx("dd",{className:"flex min-w-0 items-center gap-3 text-right",children:n.push==="unavailable"?e.jsx("span",{children:At.noPush}):e.jsxs(e.Fragment,{children:[e.jsx("span",{children:a?At.on:At.off}),e.jsx(fl,{on:a,label:At.row,disabled:n.busy,onChange:l=>{l?n.enable():n.disable()}})]})})]}),n.push==="stale"&&e.jsxs("div",{className:"flex flex-col items-end gap-2",children:[e.jsx("p",{className:"text-muted",children:At.stale}),e.jsx("button",{type:"button",disabled:n.busy,onClick:()=>{n.enable()},className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 font-medium disabled:opacity-45",children:At.enable})]}),n.problem&&e.jsx(Xe,{title:n.problem,tone:"warning",role:"alert"})]})}const lc=t=>(t==="off"||t==="stale")&&gx()!=="unsupported";function rc({store:t,onDone:s,fetchImpl:n,body:a=At.body}){const l=jx(t,n),r=me(t).fresh,o=()=>{l.enable().then(i=>{i==="on"&&(tn({name:"atoi"}),s())})};return e.jsxs(e.Fragment,{children:[e.jsxs("section",{"aria-labelledby":"notify-title",className:"flex flex-col gap-3 rounded-control border border-line bg-surface p-4",children:[e.jsx("h2",{id:"notify-title",className:"text-title leading-[1.35] font-semibold",children:At.title}),e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:a}),l.problem&&e.jsx(Xe,{title:l.problem,tone:"warning",role:"alert"}),e.jsx("button",{type:"button",disabled:l.busy||!r,onClick:o,className:St,children:l.busy?At.working:r?At.enable:At.waiting})]}),e.jsx("a",{href:ne({name:"atoi"}),onClick:s,className:mt,children:At.later})]})}function my(t,s){switch(t.status){case"applied":return{text:s,quiet:!1};case"cancelled":return{text:d.confirm.cancelled,quiet:!0};case"expired":return{text:d.confirm.expired,quiet:!0};case"rejected":return t.reason==="assertion_expired"?{text:d.confirm.expired,quiet:!0}:{text:d.confirm.refused[t.reason]??s,quiet:!1};default:return{text:s,quiet:!1}}}const Te=d.connection.pcUpdate,Wn="flex flex-col gap-3 rounded-card border bg-surface p-3.5";function py({store:t,action:s,pc:n,from:a,to:l,onClose:r}){var h;const o=f.useId(),i=!!((h=me(t).device)!=null&&h.confirm),[c,x]=f.useState(!1),[u,m]=f.useState(null),p=()=>{x(!0),m(null),t.pcAction(s,s==="update"?l:void 0).then(g=>{g.status==="applied"?r():m(my(g,Te.notDone))},()=>m({text:Te.notDone,quiet:!1})).finally(()=>x(!1))};return e.jsxs(dt,{labelledBy:`${o}-title`,onClose:()=>{c||r()},children:[e.jsx("h2",{id:`${o}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:s==="update"?Te.confirmUpdate:Te.confirmRestart}),e.jsx("p",{className:"text-body text-muted",children:s==="update"?Te.confirmUpdateBody(n,a,l):Te.confirmRestartBody(n)}),e.jsx("p",{className:`rounded-control border border-dashed border-input px-3 py-2 text-small ${i?"text-muted":"text-attention"}`,children:i?Te.passkey:Te.noPasskey}),u&&e.jsx("p",{role:"status",className:`text-body ${u.quiet?"text-muted":"text-danger-fg"}`,children:u.text}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ke,{variant:"ghost",className:"flex-1",disabled:c,onClick:r,children:Te.cancel}),e.jsx(Ke,{variant:"primary",className:"flex-[2]",disabled:c||!i,onClick:p,children:Te.confirm})]})]})}function fy({run:t,fresh:s}){const n=t.action==="update"?["asked","installing","restarting","back"]:["asked","restarting","back"],a=t.step==="restarting"?s?n.indexOf("restarting"):n.length-1:1;return e.jsx("ol",{className:"flex flex-col gap-1.5 text-small",children:n.map((l,r)=>e.jsxs("li",{className:`flex items-center gap-2 ${r>a?"text-muted":""}`,children:[e.jsx("span",{"aria-hidden":"true",className:"w-4 text-center",children:r<a?"✓":r===a?"…":"·"}),e.jsx("span",{children:Te.steps[l]})]},l))})}function hy({store:t,run:s,fresh:n,from:a,onRetry:l}){const r=s.action==="update";return qc(s)?e.jsxs("div",{className:`${Wn} border-line`,role:"status",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("strong",{className:"text-body",children:r?Te.updating(s.version):Te.restarting}),e.jsx("span",{className:"text-meta text-info",children:Te.running})]}),e.jsx(fy,{run:s,fresh:n}),e.jsx("p",{className:"text-small text-muted",children:Te.leave})]}):s.step==="done"?e.jsxs("div",{className:`${Wn} border-ok/40`,role:"status",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("strong",{className:"text-body",children:r?Te.done(s.version):Te.restarted}),e.jsx("span",{className:"text-meta text-ok",children:Te.upToDate})]}),e.jsx(Ke,{onClick:()=>t.dismissPc(),children:Te.close})]}):e.jsxs("div",{className:`${Wn} border-danger-fg/40`,role:"alert",children:[e.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[e.jsx("strong",{className:"text-body",children:r?Te.failed:Te.notRestarted}),e.jsx("span",{className:"text-meta text-danger-fg",children:Te.refused})]}),e.jsxs("p",{className:"text-small text-muted",children:[Te.unchanged(a)," ",s.reason?Te.reasons[s.reason]:""]}),e.jsx(Ke,{onClick:l,children:Te.retry})]})}function gy({store:t,appVersion:s}){const n=me(t),[a,l]=f.useState(null),r=n.daemon,o=n.pc;if(!r)return null;const i=s!==null&&Bc(r.version,s);if(!i&&!r.restart&&!o)return null;const c=r.name,x=()=>{t.dismissPc(),((o==null?void 0:o.action)==="restart"||s)&&l((o==null?void 0:o.action)??"restart")};return e.jsxs("section",{"aria-labelledby":"pc-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"pc-title",className:"text-small font-medium text-muted",children:Te.title}),o?e.jsx(hy,{store:t,run:o,fresh:n.fresh,from:r.version,onRetry:x}):i&&(r.update?e.jsxs("div",{className:`${Wn} border-input`,children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("strong",{className:"text-body",children:Te.behind}),e.jsx("span",{className:"font-mono text-small text-muted",children:Te.versions(r.version,s)})]}),e.jsx("p",{className:"text-small text-muted",children:Te.why}),e.jsx(Ke,{variant:"primary",block:!0,disabled:!n.fresh,onClick:()=>l("update"),children:Te.update}),e.jsx("p",{className:"text-meta text-muted",children:Te.keepGoing})]}):e.jsxs("div",{className:`${Wn} border-attention/40`,children:[e.jsxs("div",{className:"flex flex-col",children:[e.jsx("strong",{className:"text-body",children:Te.manual}),e.jsx("span",{className:"font-mono text-small text-muted",children:Te.versions(r.version,s)})]}),e.jsx("p",{className:"text-small text-muted",children:r.restart?Te.clone:Te.byHand})]})),r.restart&&e.jsxs("div",{className:"flex items-center gap-3 rounded-control border border-line px-3.5 py-3",children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"text-body",children:Te.restart}),e.jsx("span",{className:"text-small text-muted",children:Te.restartHint})]}),e.jsx(Ke,{size:"sm",disabled:!n.fresh||qc(o),onClick:()=>l("restart"),children:Te.restartGo})]}),a&&e.jsx(py,{store:t,action:a,pc:c,from:r.version,to:a==="update"&&s?s:r.version,onClose:()=>l(null)})]})}const yl="min-h-12 w-full min-w-0 rounded-control border border-input bg-surface px-3 text-base text-fg focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-info",We=d.settings,Nl="flex flex-col rounded-[10px] border border-line bg-surface text-body",$o="flex flex-col gap-1 border-b border-line px-4 py-3 last:border-b-0",by=Array.from({length:Math.round((jm-zo)*20)+1},(t,s)=>Math.round((zo+s*.05)*100)),jy=["finished","chat","decision"],yy=["pc","claude","codex","cursor","omp"];function Co({label:t,hint:s,children:n}){const a=f.useId();return e.jsxs("div",{className:$o,children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"min-w-0",children:t}),n(s?a:void 0)]}),s&&e.jsx("p",{id:a,className:"text-small text-muted",children:s})]})}function Ny(t,s){if(t==="hour")return new Date(s.getTime()+36e5);if(t==="four")return new Date(s.getTime()+4*36e5);const n=new Date(s);return n.setDate(n.getDate()+1),n.setHours(8,0,0,0),n}function vy(t,s){const n=t.toLocaleTimeString(lt,{hour:"2-digit",minute:"2-digit"});if(t.toDateString()===s.toDateString())return n;const a=new Date(s);return a.setDate(a.getDate()+1),t.toDateString()===a.toDateString()?We.tomorrow(n):`${t.toLocaleDateString(lt,{day:"numeric",month:"short"})} ${n}`}function yx(t){var u;const s=me(t),[n,a]=f.useState(null),[l,r]=f.useState(!1),o=f.useRef(0),i=f.useRef(!0);return f.useEffect(()=>()=>{i.current=!1},[]),{prefs:n??((u=s.device)==null?void 0:u.prefs)??bm,send:m=>{const p=++o.current;a(m),r(!1),t.setDevicePrefs(m).then(h=>{!i.current||p!==o.current||(a(null),h.status!=="applied"&&r(!0))})},failed:l,fresh:s.fresh}}function ky({store:t}){var c,x;const s=me(t),n=yx(t),a=Xt();if(!((c=s.daemon)!=null&&c.settings)||!((x=s.device)!=null&&x.prefs)||s.device.push!=="on")return null;const{prefs:l}=n,r=l.quietUntil!==null?new Date(l.quietUntil):null,o=r!==null&&r.getTime()>a,i=u=>n.send({...l,quietUntil:Ny(u,new Date(a)).toISOString()});return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:Nl,children:[jy.map(u=>e.jsx(Co,{label:We.notify[u],hint:We.notify[`${u}Hint`],children:m=>e.jsx(fl,{on:l.notify[u],label:We.notify[u],describedBy:m,disabled:!n.fresh,onChange:p=>n.send({...l,notify:{...l.notify,[u]:p}})})},u)),e.jsxs("div",{className:$o,children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{children:We.pause}),o&&e.jsx("span",{role:"status",className:"text-right text-attention",children:We.pausedUntil(vy(r,new Date(a)))})]}),e.jsx("p",{className:"text-small text-muted",children:We.pauseHint}),e.jsx("div",{className:"mt-1 flex flex-wrap gap-2",children:o?e.jsx("button",{type:"button",disabled:!n.fresh,onClick:()=>n.send({...l,quietUntil:null}),className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 font-medium disabled:opacity-45",children:We.resume}):["hour","four","morning"].map(u=>e.jsx("button",{type:"button","aria-label":We.pauseLabel[u],disabled:!n.fresh,onClick:()=>i(u),className:"inline-flex min-h-10 items-center justify-center rounded-control border border-line px-3 font-medium disabled:opacity-45",children:We.pauseFor[u]},u))})]})]}),e.jsx("p",{className:"text-small text-muted",children:We.notify.always}),n.failed&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:We.failed})]})}function wy({store:t}){var m,p;const s=me(t),n=yx(t),[a,l]=f.useState(null),[r,o]=f.useState(!1),i=f.useRef(!0);if(f.useEffect(()=>()=>{i.current=!1},[]),!((m=s.daemon)!=null&&m.settings)||!((p=s.device)!=null&&p.prefs))return null;const c=Math.round((a??s.device.contextNear??kn)*100),x=h=>{l(h/100),o(!1),t.setContextNear(h/100).then(g=>{i.current&&(l(null),g.status!=="applied"&&o(!0))})},u=n.prefs.chatTool??"pc";return e.jsxs("section",{"aria-labelledby":"ledge-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"ledge-title",className:"text-small font-medium text-muted",children:We.ledge}),e.jsxs("div",{className:Nl,children:[e.jsx(Co,{label:We.context,hint:We.contextHint,children:h=>e.jsx("select",{className:`${yl} w-auto`,"aria-label":We.context,"aria-describedby":h,disabled:!s.fresh||a!==null,value:c,onChange:g=>x(Number(g.target.value)),children:by.map(g=>e.jsx("option",{value:g,children:d.percent(g)},g))})}),s.device.chat&&e.jsxs("div",{className:$o,children:[e.jsx("span",{children:We.chatTool}),e.jsx("p",{className:"text-small text-muted",children:We.chatToolHint}),e.jsx("div",{className:"mt-1",children:e.jsx(Jn,{name:"chat-tool",legend:We.chatTool,value:u,options:yy.map(h=>({value:h,label:We.tools[h]})),onChange:h=>{s.fresh&&n.send({...n.prefs,chatTool:h==="pc"?null:h})}})}),e.jsx("p",{className:"text-meta text-muted",children:We.toolPcHint})]})]}),!s.fresh&&e.jsx("p",{className:"text-small text-muted",children:We.offline}),(r||n.failed)&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:We.failed})]})}function Sy(){const t=hm();return e.jsx("div",{className:Nl,children:e.jsx(Co,{label:We.motion,hint:We.motionHint,children:s=>e.jsx(fl,{on:t,label:We.motion,describedBy:s,onChange:gm})})})}function $y({store:t}){const s=me(t).daemon;return e.jsxs("section",{"aria-labelledby":"managed-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"managed-title",className:"text-small font-medium text-muted",children:We.managed}),(s==null?void 0:s.terminal)&&e.jsx("dl",{className:Nl,children:e.jsxs("div",{className:"flex items-baseline justify-between gap-4 px-4 py-3",children:[e.jsx("dt",{className:"text-muted",children:We.terminal}),e.jsx("dd",{children:s.terminalInput?We.allowed:We.notAllowed})]})}),e.jsx("p",{className:"text-small text-muted",children:We.managedBody})]})}const re=d.settings.projects,Nx=Object.keys(jn),Cy=80,vl=t=>re.errors[t.status==="rejected"?t.reason:t.status]??re.errors.failed;function My(t,s,n){const a=s+n;if(a<0||a>=t.length)return[...t];const l=[...t];return[l[s],l[a]]=[l[a],l[s]],l}function Ey({color:t}){return e.jsx("span",{className:"size-3 flex-none rounded-full",style:{background:jn[t]},"aria-hidden":"true"})}function Ry({value:t,onChange:s,name:n}){return e.jsxs("fieldset",{className:"m-0 min-w-0 border-0 p-0",children:[e.jsx("legend",{className:"mb-1.5 text-small text-muted",children:re.color}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Nx.map(a=>e.jsxs("label",{className:"grid size-10 cursor-pointer place-items-center rounded-full border border-line has-[:checked]:border-fg has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-info",children:[e.jsx("input",{type:"radio",name:n,value:a,checked:t===a,onChange:()=>s(a),className:"sr-only","aria-label":re.colors[a]}),e.jsx("span",{className:"size-6 rounded-full",style:{background:jn[a]},"aria-hidden":"true"})]},a))})]})}function Ay({store:t,project:s,projects:n,onClose:a,onDelete:l,onFolders:r}){var _,D;const o=f.useId(),i=new Set(n.map(E=>E.color)),[c,x]=f.useState((s==null?void 0:s.name)??""),[u,m]=f.useState((s==null?void 0:s.color)??Nx.find(E=>!i.has(E))??"blue"),[p,h]=f.useState(!1),[g,y]=f.useState(null),k=me(t),S=s===null&&!!((_=k.daemon)!=null&&_.projectFolders),b=!!((D=k.device)!=null&&D.confirm),[j,N]=f.useState(null),[$,C]=f.useState(!1);f.useEffect(()=>{S&&t.requestRecentFolders()},[t,S]);const M=c.trim(),v=M!==""&&n.some(E=>E.id!==(s==null?void 0:s.id)&&Bo(E.name)===Bo(M)),A=s!==null&&M===s.name&&u===s.color,T=S&&(j===null||!b),R=()=>{if(!M||v||p||T)return;if(A){a();return}h(!0),y(null);const E=s?{...M!==s.name?{name:M}:{},...u!==s.color?{color:u}:{}}:null;(s?t.editProject(s.id,E):t.createProject(M,u,S?j:void 0)).then(z=>{h(!1),z.status==="applied"?a():y(vl(z))})};if($)return e.jsxs(dt,{labelledBy:`${o}-title`,onClose:()=>C(!1),children:[e.jsx("h2",{id:`${o}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:re.firstFolder}),e.jsx(vx,{store:t,busy:!1,skip:()=>!1,rowLabel:re.choose,rowAria:re.chooseLabel,pickLabel:re.chooseThis,pickAria:re.chooseLabel,pickDisabled:!1,error:null,onPick:E=>{N(E),C(!1)},onBack:()=>C(!1)})]});const P=[...new Set([...j!==null?[j]:[],...k.recentFolders??[]])];return e.jsxs(dt,{labelledBy:`${o}-title`,onClose:()=>{p||a()},children:[e.jsx("h2",{id:`${o}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:s?re.editTitle:re.newTitle}),!s&&e.jsx("p",{className:"text-body text-muted",children:S?re.newBody:re.newBodyOld}),e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:E=>{E.preventDefault(),R()},children:[e.jsxs("label",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"text-small text-muted",children:re.name}),e.jsx("input",{className:yl,value:c,maxLength:Cy,autoFocus:!0,"aria-invalid":v||void 0,onChange:E=>x(E.target.value)}),v&&e.jsx("span",{role:"alert",className:"text-small text-danger-fg",children:re.errors.name_taken})]}),e.jsx(Ry,{name:`${o}-color`,value:u,onChange:m}),S&&e.jsxs("section",{"aria-labelledby":`${o}-first`,className:"flex flex-col gap-1.5",children:[e.jsxs("h3",{id:`${o}-first`,className:"flex items-center gap-2 text-small text-muted",children:[re.firstFolder,e.jsx("span",{className:"rounded-full border border-task/45 px-2 text-meta text-task",children:re.required})]}),P.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("h4",{className:"text-meta tracking-[.06em] text-muted uppercase",children:re.recents}),e.jsx("ul",{className:"flex flex-col rounded-control border border-line",children:P.map(E=>e.jsxs("li",{className:Kn,children:[e.jsxs("button",{type:"button","aria-pressed":j===E,"aria-label":re.chooseLabel(E),disabled:p,onClick:()=>N(E),className:`flex min-h-10 min-w-0 flex-1 items-center gap-2 text-left ${j===E?"font-medium text-fg":""}`,children:[e.jsx(q,{name:j===E?"check":"folder",className:"size-4 flex-none"}),e.jsx("span",{className:"font-mono text-small break-all",children:E})]}),j===E&&e.jsx("span",{className:"text-meta text-ok",children:re.chosen})]},E))})]}),e.jsx(Ke,{size:"sm",className:"self-start",disabled:p,onClick:()=>C(!0),children:re.browseMore}),j===null&&e.jsx("p",{"data-pick-first":"",className:"rounded-control border border-dashed border-input px-3 py-2 text-small text-muted",children:re.pickFirst}),!b&&e.jsx("p",{className:"text-small text-attention",children:re.noPasskey})]}),g&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:g}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ke,{variant:"ghost",className:"flex-1",disabled:p,onClick:a,children:re.cancel}),e.jsx(Ke,{variant:"primary",type:"submit",className:"flex-[2]",disabled:p||!M||v||T,children:s?re.save:re.create})]}),s&&r&&e.jsx(Ke,{disabled:p,onClick:r,children:re.folders}),s&&e.jsx(Ke,{variant:"ghost",className:"text-danger-fg!",disabled:p,onClick:l,children:re.remove})]})]})}function Ty({store:t,project:s,projects:n,agents:a,onClose:l}){var y;const r=f.useId(),o=!!((y=me(t).device)!=null&&y.confirm),i=n.filter(k=>k.id!==s.id),[c,x]=f.useState(null),[u,m]=f.useState(!1),[p,h]=f.useState(null),g=()=>{m(!0),h(null),t.deleteProject(s.id,c).then(k=>{m(!1),k.status==="applied"?l():h(vl(k))})};return e.jsxs(dt,{labelledBy:`${r}-title`,onClose:()=>{u||l()},children:[e.jsx("h2",{id:`${r}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:re.deleteTitle(s.name)}),e.jsx("p",{className:"text-body text-muted",children:re.deleteAgents(a)}),e.jsxs("fieldset",{className:"m-0 flex min-w-0 flex-col gap-2 border-0 p-0",children:[e.jsx("legend",{className:"mb-1.5 text-small text-muted",children:re.deleteWhere}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:`${r}-move`,checked:c===null,onChange:()=>x(null)}),re.noProject]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"radio",name:`${r}-move`,checked:c!==null,disabled:i.length===0,onChange:()=>{var k;return x(((k=i[0])==null?void 0:k.id)??null)}}),re.moveTo]}),c!==null&&e.jsx("select",{className:yl,"aria-label":re.target,value:c,onChange:k=>x(k.target.value),children:i.map(k=>e.jsx("option",{value:k.id,children:k.name},k.id))})]}),e.jsx("p",{className:`rounded-control border border-dashed border-input px-3 py-2 text-small ${o?"text-muted":"text-attention"}`,children:o?re.passkey:re.noPasskey}),p&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:p}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ke,{variant:"ghost",className:"flex-1",disabled:u,onClick:l,children:re.cancel}),e.jsx(Ke,{variant:"primary",className:"flex-[2]",disabled:u||!o,onClick:g,children:re.confirmDelete})]})]})}const _y=t=>t.machine==="local"?re.thisPc:t.label??t.machine,Iy=t=>t.split("/").filter(Boolean).at(-1)??"/",Kn="flex items-center gap-3 border-b border-line px-3 py-2.5 last:border-b-0";function Ly({store:t,project:s,onClose:n}){var S;const a=f.useId(),l=me(t),[r,o]=f.useState(!1),[i,c]=f.useState(!1),[x,u]=f.useState(null);f.useEffect(()=>{t.requestProjectFolders(s.id)},[t,s.id]);const m=l.projectFolders[s.id],p=!!((S=l.device)!=null&&S.confirm),h=(b,j)=>{c(!1),b.status==="applied"?(t.requestProjectFolders(s.id),j()):u(vl(b))},g=b=>{c(!0),u(null),t.removeFolder(s.id,b.machine,b.path).then(j=>h(j,()=>{}))},y=b=>{c(!0),u(null),t.addFolder(s.id,b).then(j=>h(j,()=>o(!1)))},k=()=>{i||n()};if(r){const b=Array.isArray(m)?m:[];return e.jsxs(dt,{labelledBy:`${a}-title`,onClose:k,children:[e.jsx("h2",{id:`${a}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:re.pickTitle}),e.jsx(vx,{store:t,busy:i,skip:j=>b.some(N=>N.machine==="local"&&N.path===j),rowLabel:re.addShort,rowAria:re.addThisLabel,onPick:y,note:e.jsx("p",{className:`rounded-control border border-dashed border-input px-3 py-2 text-small ${p?"text-muted":"text-attention"}`,children:p?re.folderPasskey:re.noPasskey}),error:x,pickLabel:re.addThis,pickAria:re.addThisLabel,pickDisabled:!p,onBack:()=>{o(!1),u(null)}})]})}return e.jsxs(dt,{labelledBy:`${a}-title`,onClose:k,children:[e.jsx("h2",{id:`${a}-title`,className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:re.foldersTitle(s.name)}),m===void 0?e.jsx("p",{role:"status",className:"text-small text-muted",children:re.foldersLoading}):m==="gone"?e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:re.errors.stale}):m.length===0?e.jsx("p",{className:"text-body text-muted",children:re.foldersNone}):e.jsx("ul",{className:"flex max-h-[45dvh] flex-col overflow-y-auto rounded-control border border-line",children:m.map(b=>e.jsxs("li",{className:Kn,children:[e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"font-medium",children:Iy(b.path)}),e.jsxs("span",{className:"font-mono text-meta break-all text-muted",children:[b.path," · ",_y(b)]})]}),e.jsx(Ke,{size:"sm",variant:"ghost","aria-label":re.removeFolderLabel(b.path),disabled:i||!l.fresh||m.length===1,onClick:()=>g(b),children:re.removeFolder})]},`${b.machine}
18
+ ${b.path}`))}),Array.isArray(m)&&m.length===1&&e.jsx("p",{"data-last-folder":"",className:"rounded-control border border-dashed border-input px-3 py-2 text-small text-muted",children:re.lastFolder}),x&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:x}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ke,{variant:"ghost",className:"flex-1",disabled:i,onClick:n,children:re.close}),e.jsxs(Ke,{variant:"primary",className:"flex-[2]",disabled:i||!l.fresh||m==="gone",onClick:()=>{u(null),o(!0)},children:[e.jsx(q,{name:"plus",className:"size-4"}),re.addFolder]})]})]})}function vx({store:t,busy:s,skip:n,rowLabel:a,rowAria:l,onPick:r,note:o,error:i,pickLabel:c,pickAria:x,pickDisabled:u,onBack:m}){const p=me(t),[h,g]=f.useState(null);f.useEffect(()=>{t.requestRecentFolders(),t.listFolder()},[t]);const y=p.folderListing,k=y&&(h===null||y.path===h)?y:null,S=j=>{g(j),t.listFolder(j)},b=(p.recentFolders??[]).filter(j=>!n(j));return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex max-h-[55dvh] flex-col gap-3 overflow-y-auto",children:[h===null&&b.length>0&&e.jsxs("section",{"aria-label":re.recents,className:"flex flex-col gap-1.5",children:[e.jsx("h3",{className:"text-small text-muted",children:re.recents}),e.jsx("ul",{className:"flex flex-col rounded-control border border-line",children:b.map(j=>e.jsxs("li",{className:Kn,children:[e.jsx("span",{className:"min-w-0 flex-1 font-mono text-small break-all",children:j}),e.jsx(Ke,{size:"sm","aria-label":l(j),disabled:s||u,onClick:()=>r(j),children:a})]},j))})]}),e.jsxs("section",{"aria-label":re.browse,className:"flex flex-col gap-1.5",children:[e.jsx("h3",{className:"text-small text-muted",children:re.browse}),k?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"font-mono text-small break-all",children:k.path}),k.error&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:re.folderErrors[k.error]}),e.jsxs("ul",{className:"flex flex-col rounded-control border border-line",children:[k.parent&&e.jsx("li",{className:Kn,children:e.jsxs("button",{type:"button",className:"flex min-h-10 flex-1 items-center gap-2 text-left",onClick:()=>S(k.parent),children:[e.jsx(q,{name:"back",className:"size-4"}),re.parent]})}),k.entries.map(j=>{const N=k.repos.find($=>$.name===j);return e.jsx("li",{className:Kn,children:e.jsxs("button",{type:"button","aria-label":re.open(j),className:"flex min-h-10 min-w-0 flex-1 items-center gap-2 text-left",onClick:()=>S(`${k.path==="/"?"":k.path}/${j}`),children:[e.jsx("span",{className:"truncate",children:j}),N&&e.jsxs("span",{className:"flex-none rounded-full bg-raised px-2 text-meta text-muted",children:["⎇ ",N.branch]})]})},j)}),!k.error&&k.entries.length===0&&e.jsx("li",{className:"px-3 py-2.5 text-small text-muted",children:re.empty})]}),k.cut&&e.jsx("p",{className:"text-meta text-muted",children:re.cut})]}):e.jsx("p",{role:"status",className:"text-small text-muted",children:re.loadingFolder})]})]}),e.jsx("p",{className:"text-small text-muted",children:re.onlyThisPc}),o,i&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:i}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ke,{variant:"ghost",className:"flex-1",disabled:s,onClick:m,children:re.back}),e.jsx(Ke,{variant:"primary",className:"flex-[2]",disabled:s||u||!k||!!k.error,"aria-label":k?x(k.path):c,onClick:()=>{k&&r(k.path)},children:c})]})]})}function Oy({store:t}){var k;const s=me(t),[n,a]=f.useState(null),[l,r]=f.useState(null),[o,i]=f.useState(null),[c,x]=f.useState(!1),[u,m]=f.useState(null);if(!((k=s.daemon)!=null&&k.projectEdit)||!s.daemon.atelier)return null;const p=s.projects,h=S=>[...s.sessions.values()].filter(b=>b.projectId===S&&b.state!=="exited").length,g=!s.fresh||c,y=(S,b)=>{x(!0),m(null),t.orderProjects(My(p.map(j=>j.id),S,b)).then(j=>{x(!1),j.status!=="applied"&&m(vl(j))})};return e.jsxs("section",{"aria-labelledby":"projects-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"projects-title",className:"text-small font-medium text-muted",children:re.title}),e.jsxs("ul",{className:"flex flex-col rounded-[10px] border border-line bg-surface text-body",children:[p.length===0&&e.jsx("li",{className:"px-4 py-3 text-muted",children:re.none}),p.map((S,b)=>e.jsxs("li",{className:"flex items-center gap-3 border-b border-line px-4 py-2.5 last:border-b-0",children:[e.jsx(Ey,{color:S.color}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate font-medium",children:S.name}),e.jsx("span",{className:"text-small text-muted",children:re.agents(h(S.id))})]}),e.jsx(Po,{label:re.up(S.name),disabled:g||b===0,onClick:()=>y(b,-1),children:e.jsx(q,{name:"arrowUp",className:"size-4"})}),e.jsx(Po,{label:re.down(S.name),disabled:g||b===p.length-1,onClick:()=>y(b,1),children:e.jsx(q,{name:"arrowUp",className:"size-4 rotate-180"})}),e.jsx(Ke,{size:"sm","aria-label":re.editLabel(S.name),disabled:!s.fresh,onClick:()=>a(S),children:re.edit})]},S.id))]}),e.jsxs(Ke,{disabled:!s.fresh,onClick:()=>a("new"),children:[e.jsx(q,{name:"plus",className:"size-4"}),re.add]}),u&&e.jsx("p",{role:"alert",className:"text-small text-danger-fg",children:u}),e.jsx("p",{className:"text-small text-muted",children:s.daemon.projectFolders?re.folders_note:re.folders_note_old}),n!==null&&e.jsx(Ay,{store:t,project:n==="new"?null:n,projects:p,onClose:()=>a(null),onDelete:()=>{n!=="new"&&(r(n),a(null))},onFolders:s.daemon.projectFolders?()=>{n!=="new"&&(i(n),a(null))}:null}),o&&e.jsx(Ly,{store:t,project:o,onClose:()=>i(null)}),l&&e.jsx(Ty,{store:t,project:l,projects:p,agents:h(l.id),onClose:()=>r(null)})]})}const ns=d.connection.device,kx=t=>{var s,n;return t??Jm(((s=globalThis.navigator)==null?void 0:s.userAgent)??"",((n=globalThis.navigator)==null?void 0:n.maxTouchPoints)??0)};function Dy({store:t,pinned:s}){const n=me(t),[a,l]=f.useState(null),[r,o]=f.useState(!1),i=n.device;if(!(i!=null&&i.id))return null;const c=kx(i.name),x=s?new Date(s.pinnedAt).toLocaleDateString(lt,{day:"numeric",month:"short",year:"numeric"}):null,u=(a==null?void 0:a.trim())??"",m=()=>{if(!(!u||u.length>Sl)){if(t.renameDevice(u)===null){o(!0);return}o(!1),l(null)}};return e.jsxs("section",{"aria-labelledby":"device-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"device-title",className:"text-small font-medium text-muted",children:ns.title}),e.jsxs("div",{className:"flex items-center gap-3 rounded-[10px] border border-line bg-surface px-4 py-3",children:[e.jsx("span",{className:"grid size-9 flex-none place-items-center rounded-[10px] bg-raised","aria-hidden":"true",children:e.jsx(q,{name:i.kind==="tablet"?"tablet":"phone"})}),e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("p",{className:"text-body font-semibold [overflow-wrap:anywhere]",children:c}),x&&e.jsx("p",{className:"text-meta text-muted",children:ns.linkedOn(x)})]}),e.jsx(Ke,{size:"sm","aria-label":ns.renameLabel(c),onClick:()=>{o(!1),l(c)},children:ns.rename})]}),r&&e.jsx("p",{role:"status",className:"text-small text-danger-fg",children:ns.failed}),e.jsx("p",{className:"text-small text-muted",children:ns.others}),a!==null&&e.jsxs(dt,{labelledBy:"rename-title",onClose:()=>l(null),children:[e.jsx("h2",{id:"rename-title",className:"text-heading leading-[1.3] font-semibold tracking-[-.5px]",children:ns.sheetTitle}),e.jsx("p",{className:"text-body text-muted",children:ns.sheetBody}),e.jsxs("form",{className:"flex flex-col gap-4",onSubmit:p=>{p.preventDefault(),m()},children:[e.jsxs("label",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"sr-only",children:ns.field}),e.jsx("input",{className:yl,value:a,maxLength:Sl,autoFocus:!0,"aria-describedby":"rename-count",onChange:p=>l(p.target.value)}),e.jsxs("span",{id:"rename-count",className:"self-end text-meta text-muted",children:[a.length,"/",Sl]})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(Ke,{variant:"ghost",className:"flex-1",onClick:()=>l(null),children:ns.cancel}),e.jsx(Ke,{variant:"primary",type:"submit",className:"flex-[2]",disabled:!u,children:ns.save})]})]})]})]})}const nt=d.connection,Ws=d.settings,Fy=()=>[{value:"system",label:nt.themes.system},{value:"light",label:nt.themes.light},{value:"dark",label:nt.themes.dark}],zy=t=>t==="ready"?nt.states.online:t==="handshaking"?nt.states.connecting:nt.states.offline;function Py({store:t,login:s,relay:n,pinned:a,linkState:l,build:r,onSignOut:o,fetchImpl:i,section:c}){var y,k,S;const x=me(t),u=ym(),m=Oc();f.useEffect(()=>{var b;c==="link"&&((b=document.getElementById("link-title"))==null||b.scrollIntoView({block:"start"}))},[c]);const p=(a==null?void 0:a.name)??((y=x.daemon)==null?void 0:y.name)??null,h=!!x.daemon&&!!r&&Bc(x.daemon.version,r.version),g=[[nt.account,s?d.account(s):nt.unknown,!1],[nt.relay,n,!0],[nt.pc,p??nt.unknown,!1],[nt.pcFingerprint,a?ea(a.fingerprint):nt.unknown,!0],[nt.status,zy(l),!1],[nt.version,(r==null?void 0:r.version)??nt.none,!0],[nt.appFingerprint,r?hx(r.fingerprint):nt.none,!0],[nt.pcVersion,((k=x.daemon)==null?void 0:k.version)??nt.none,!0,h?"text-attention":void 0]];return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:"bleed flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-2.5",children:[e.jsx(is,{fallback:{name:"atoi"},label:nt.back}),e.jsx("h1",{className:"text-base font-semibold",children:nt.title})]}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col gap-6 overflow-y-auto pt-5 pb-[34px]",children:[e.jsx(Dy,{store:t,pinned:a}),e.jsxs("section",{"aria-labelledby":"appearance-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"appearance-title",className:"text-small font-medium text-muted",children:Ws.appearance}),e.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":"true",className:"text-small text-muted",children:Ws.theme}),e.jsx(Jn,{name:"theme",legend:Ws.theme,options:Fy(),value:u,onChange:b=>Nm(b),fit:!0})]}),e.jsxs("div",{className:"flex flex-col items-start gap-1.5",children:[e.jsx("span",{"aria-hidden":"true",className:"text-small text-muted",children:Ws.lang}),e.jsx(Jn,{name:"lang",legend:Ws.lang,options:km.map(b=>({value:b,label:Ws.langs[b],lang:b})),value:m,onChange:vm,fit:!0})]}),e.jsx(Sy,{})]}),((S=x.device)==null?void 0:S.push)&&e.jsxs("section",{"aria-labelledby":"notifications-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"notifications-title",className:"text-small font-medium text-muted",children:Ws.notifications}),e.jsx("dl",{className:"flex flex-col rounded-[10px] border border-line bg-surface text-body",children:e.jsx(xy,{store:t,fetchImpl:i})}),e.jsx(ky,{store:t})]}),e.jsx(wy,{store:t}),e.jsx(Oy,{store:t}),e.jsx(gy,{store:t,appVersion:(r==null?void 0:r.version)??null}),e.jsxs("section",{"aria-labelledby":"link-title",className:"flex flex-col gap-2.5",children:[e.jsx("h2",{id:"link-title",className:"text-small font-medium text-muted",children:nt.section}),e.jsxs("dl",{className:"flex flex-col rounded-[10px] border border-line bg-surface text-body",children:[g.map(([b,j,N,$])=>e.jsxs("div",{className:"flex items-baseline justify-between gap-4 border-b border-line px-4 py-3 last:border-b-0",children:[e.jsx("dt",{className:"flex-none text-muted",children:b}),e.jsx("dd",{className:`min-w-0 text-right break-words ${N?"font-mono":""} ${$??""}`,children:j})]},b)),e.jsx(Ah,{store:t}),e.jsx(Lh,{store:t})]})]}),e.jsx($y,{store:t}),e.jsx("div",{className:"flex-grow","aria-hidden":"true"}),e.jsx("button",{type:"button",onClick:o,className:mt,children:nt.signOut})]})]})}function By({onOther:t}){return e.jsxs(Et,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(bs,{size:80,frozen:!0}),e.jsx("h1",{className:qt,children:d.denied.title}),e.jsx("p",{className:"max-w-[300px] text-muted",children:d.denied.bodyNoLogin})]}),e.jsx(Rt,{}),e.jsx("button",{type:"button",onClick:t,className:mt,children:d.denied.other})]})}const Qt=d.keyChanged,qy=t=>{const s=new Date(t);return Number.isNaN(s.getTime())?d.connection.unknown:s.toLocaleDateString(lt,{day:"numeric",month:"short"})};function Hy({pcName:t,known:s,received:n,onRelink:a,onSignOut:l}){return e.jsxs(Et,{children:[e.jsxs("div",{className:"flex flex-col gap-3.5",children:[e.jsx("span",{"aria-hidden":"true",className:"inline-flex size-12 items-center justify-center rounded-full bg-danger-bg text-danger-fg",children:e.jsxs("svg",{className:Ba,viewBox:"0 0 24 24",children:[e.jsx("path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z"}),e.jsx("path",{d:"M12 8v4"}),e.jsx("path",{d:"M12 16h.01"})]})}),e.jsx("h1",{className:qt,children:Qt.title(t??d.yourPc)}),e.jsx("p",{className:"text-muted",children:Qt.body})]}),e.jsxs("dl",{className:"grid grid-cols-[auto_1fr] gap-x-4 gap-y-2.5 rounded-control border border-line bg-surface p-4 text-body",children:[e.jsx("dt",{className:"text-muted",children:Qt.known}),e.jsx("dd",{className:"font-mono",children:s?Qt.knownDetail(ea(s.fingerprint,2),qy(s.pinnedAt)):d.connection.unknown}),e.jsx("dt",{className:"text-muted",children:Qt.received}),e.jsx("dd",{className:"font-mono",children:n?Qt.receivedDetail(ea(n,2)):d.connection.unknown})]}),e.jsxs("div",{className:"flex flex-col gap-3 text-body leading-[1.6] text-muted",children:[e.jsxs("p",{children:[e.jsx("strong",{className:"text-fg",children:Qt.reinstalledTitle})," ",Qt.reinstalledBody]}),e.jsxs("p",{children:[e.jsx("strong",{className:"text-fg",children:Qt.otherwise})," ",Qt.warning]})]}),e.jsx(Rt,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:a,className:St,children:Qt.relink}),e.jsx("button",{type:"button",onClick:l,className:mt,children:Qt.signOut})]})]})}const Uy="/auth/github/start";function Wy(t){return t==="denied"?d.login.errors.denied:t==="bad_state"||t==="error"?d.login.errors.failed:null}const Ky=[e.jsxs(e.Fragment,{children:[e.jsx("circle",{cx:"7.5",cy:"15.5",r:"5.5"}),e.jsx("path",{d:"m21 2-9.6 9.6"}),e.jsx("path",{d:"m15.5 7.5 3 3L22 7l-3-3"})]}),e.jsxs(e.Fragment,{children:[e.jsx("rect",{width:"20",height:"14",x:"2",y:"3",rx:"2"}),e.jsx("line",{x1:"8",x2:"16",y1:"21",y2:"21"}),e.jsx("line",{x1:"12",x2:"12",y1:"17",y2:"21"})]}),e.jsxs(e.Fragment,{children:[e.jsx("rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2"}),e.jsx("path",{d:"M7 11V7a5 5 0 0 1 10 0v4"})]})];function Vy({server:t,error:s}){return e.jsxs(Et,{children:[e.jsxs("div",{className:"flex flex-col items-center gap-3.5 text-center",children:[e.jsx(bs,{size:88}),e.jsx("h1",{className:"text-display leading-[34px] font-bold tracking-[-.025em]",children:d.login.title}),e.jsx("p",{className:"max-w-[300px] text-muted",children:d.login.subtitle})]}),e.jsxs("div",{className:"flex h-8 items-center gap-2.5 self-center rounded-full border border-line px-3 text-small text-muted",children:[e.jsxs("svg",{className:`${Ba} size-3.5`,viewBox:"0 0 24 24","aria-hidden":"true",children:[e.jsx("rect",{width:"20",height:"8",x:"2",y:"2",rx:"2",ry:"2"}),e.jsx("rect",{width:"20",height:"8",x:"2",y:"14",rx:"2",ry:"2"}),e.jsx("line",{x1:"6",x2:"6.01",y1:"6",y2:"6"}),e.jsx("line",{x1:"6",x2:"6.01",y1:"18",y2:"18"})]}),e.jsx("span",{className:"font-mono",children:t})]}),s&&e.jsx("p",{role:"alert",className:"rounded-control border border-danger-fg/15 bg-danger-bg p-3.5 text-body text-danger-fg",children:s}),e.jsx(Rt,{}),e.jsx("ul",{className:"flex flex-col gap-3.5 text-fg/85",children:d.login.notes.map((n,a)=>e.jsxs("li",{className:"flex items-start gap-3",children:[e.jsx("svg",{className:`${Ba} text-fg`,viewBox:"0 0 24 24","aria-hidden":"true",children:Ky[a]}),e.jsx("span",{children:n})]},n))}),e.jsxs("a",{href:Uy,className:St,children:[e.jsx("svg",{className:"size-5 flex-none fill-current",viewBox:"0 0 24 24","aria-hidden":"true",children:e.jsx("path",{d:"M12 .3a12 12 0 0 0-3.8 23.38c.6.12.83-.26.83-.57L9 21.07c-3.34.72-4.04-1.61-4.04-1.61-.55-1.39-1.34-1.76-1.34-1.76-1.08-.74.09-.73.09-.73 1.2.09 1.83 1.24 1.83 1.24 1.07 1.83 2.81 1.3 3.5 1 .1-.78.42-1.31.76-1.6-2.67-.3-5.47-1.34-5.47-5.93 0-1.31.47-2.38 1.24-3.22-.14-.3-.54-1.52.1-3.18 0 0 1-.32 3.3 1.23a11.5 11.5 0 0 1 6 0c2.28-1.55 3.29-1.23 3.29-1.23.64 1.66.24 2.88.12 3.18a4.65 4.65 0 0 1 1.23 3.22c0 4.61-2.8 5.63-5.48 5.92.42.36.81 1.1.81 2.22l-.01 3.29c0 .31.2.69.82.57A12 12 0 0 0 12 .3"})}),d.login.github]})]})}function Gy({onHere:t}){return e.jsxs(Et,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:qt,children:d.replaced.title}),e.jsx("p",{className:"text-muted",children:d.replaced.body})]}),e.jsx(Rt,{}),e.jsx("button",{type:"button",onClick:t,className:mt,children:d.replaced.here})]})}const Lr=t=>e.jsx("a",{href:ne({name:"atoi"}),className:Fe({size:"sm"}),children:t});function Mo({label:t,children:s}){return It()?e.jsx("section",{"aria-label":t,className:"pt-[34px]",children:s}):e.jsx(os,{label:t,children:s})}function Xy(){const{pc:t}=Ut();return e.jsxs(Rs,{title:d.prs.title,subtitle:d.prs.subtitle,children:[e.jsx(Mo,{label:d.prs.title,children:e.jsx(Jt,{glyph:e.jsx(q,{name:"pr",className:"size-[22px]"}),title:d.prs.notSent(Ht(t)),body:d.prs.notSentBody})}),e.jsx("p",{className:"text-small text-muted",children:d.prs.tracked})]})}function Yy(){const{pc:t}=Ut();return e.jsx(Rs,{title:d.rigs.title,subtitle:d.rigs.subtitle,children:e.jsx(Mo,{label:d.rigs.title,children:e.jsx(Jt,{glyph:e.jsx(q,{name:"rigs",className:"size-[22px]"}),title:d.rigs.notSent(Ht(t)),body:d.rigs.notSentBody,action:Lr(d.rigs.seeAtoi)})})})}function oc({onClose:t}={}){const{pc:s}=Ut();return t?e.jsxs(e.Fragment,{children:[e.jsx(px,{frozen:!0,onClose:t}),e.jsx("section",{"aria-label":d.chat.title,className:"pt-[34px]",children:e.jsx(Jt,{framed:!1,glyph:e.jsx(bs,{size:64,frozen:!0}),title:d.chat.unavailable.title(Ht(s)),body:d.chat.unavailable.body,action:Lr(d.chat.unavailable.seeAtoi)})})]}):e.jsx(Rs,{title:d.chat.title,children:e.jsx(Mo,{label:d.chat.title,children:e.jsx(Jt,{framed:!1,glyph:e.jsx(bs,{size:64,frozen:!0}),title:d.chat.unavailable.title(Ht(s)),body:d.chat.unavailable.body,action:Lr(d.chat.unavailable.seeAtoi)})})})}function ic({icon:t,title:s,body:n}){return e.jsxs("div",{"data-split-empty":"",className:"flex flex-1 flex-col items-center justify-center gap-1 text-center text-muted",children:[e.jsx(q,{name:t,className:"size-[18px]"}),e.jsx("h2",{className:"mt-2.5 text-[17px] font-semibold text-fg",children:s}),e.jsx("p",{className:"max-w-[320px] text-small",children:n})]})}function Qy({open:t,onClose:s,children:n}){const a=f.useRef(null),l=f.useRef(s);l.current=s;const r=f.useRef(null);return f.useEffect(()=>{const o=a.current;if(!o)return;const i=c=>{t&&c.target instanceof HTMLElement&&c.target.tagName==="MAIN"&&(r.current=c.target.scrollTop)};return o.addEventListener("scroll",i,!0),()=>o.removeEventListener("scroll",i,!0)},[t]),f.useEffect(()=>{var c;if(!t)return;const o=(c=a.current)==null?void 0:c.querySelector("main");o&&r.current!==null&&(o.scrollTop=r.current);const i=x=>{x.key!=="Escape"||x.defaultPrevented||x.isComposing||$d()||(x.preventDefault(),l.current())};return document.addEventListener("keydown",i),()=>document.removeEventListener("keydown",i)},[t]),e.jsx("aside",{ref:a,hidden:!t,"aria-label":d.chat.title,"data-ledge-pane":"",className:"lpane",children:n})}const wx="ledge.mobile.ledgePane",Or=new Set;let Dr=null;function Zy(t){var s;if(Dr!==null)return Dr;try{return((s=Qe(t))==null?void 0:s.getItem(wx))==="open"}catch{return!1}}function cc(t,s){var n;Dr=t;try{(n=Qe(s))==null||n.setItem(wx,t?"open":"closed")}catch{}for(const a of Or)a()}const Jy=t=>(Or.add(t),()=>{Or.delete(t)});function eN(t){return f.useSyncExternalStore(Jy,()=>Zy(t),()=>!1)}function dc({store:t,id:s,onDone:n}){var p,h,g;const a=me(t),l=Fs(),r=(p=a.asks)==null?void 0:p.find(y=>y.id===s),o=f.useRef(void 0);r&&(o.current=r);const i=r??o.current,c=n??(()=>al({name:"atoi"})),x=((h=a.device)==null?void 0:h.confirm)===!0&&l,u=l&&((g=a.device)==null?void 0:g.confirm)!==!0,m=i?e.jsx(qd,{store:t,ask:i,end:dd(s,a.ops),fresh:a.fresh,ghost:!r,canConfirm:x,enroll:u,onGone:c,full:!0}):a.asks===null||!a.fresh?e.jsx("p",{role:"status",className:"text-body text-muted",children:d.loading}):e.jsx(at,{tone:"gone",title:d.asks.already});return e.jsxs(e.Fragment,{children:[e.jsx(oa,{title:d.atoi.kindName.rig,fallback:{name:"atoi"},label:d.detail.back,link:Mn(a)}),e.jsx("main",{className:"min-h-0 flex-1 overflow-y-auto overscroll-contain pt-4 pb-[22px]",children:m})]})}const $a=d.storage;function tN({onRetry:t,onReload:s}){return e.jsxs(Et,{top:"pt-40",children:[e.jsxs("div",{className:"flex flex-col gap-2 text-center",children:[e.jsx("h1",{className:qt,children:$a.title}),e.jsx("p",{className:"text-muted",children:$a.body})]}),e.jsx(Rt,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:t,className:St,children:$a.retry}),e.jsx("button",{type:"button",onClick:s,className:mt,children:$a.reload})]})]})}const sN=30,nN=/^(?:\x1b\[\??\d+(?:;\d+)*[Rc]|\x1b\[[?>][\d;]*c|\x1b\][0-9]+;rgb:[0-9a-f/]+(?:\x07|\x1b\\)|\x1b\[[IO])$/i,aN={phase:"connecting",cols:80,rows:24,readOnly:!1,held:null,holding:!1,released:null,exit:null,refused:null,holdRefused:null};function lN(t){if(t.length<=qo)return t;let s=qo;const n=t.charCodeAt(s-1);return n>=55296&&n<=56319&&(s-=1),t.slice(0,s)}function rN(t,s){return`\x1B[H\x1B[2J\x1B[3J${t.replace(/\n/g,`\r
19
+ `)}\x1B[${s.y+1};${s.x+1}H`}class oN{constructor(s,n,a,l=()=>crypto.randomUUID()){Pt(this,"view",aN);Pt(this,"listeners",new Set);Pt(this,"tid",null);Pt(this,"openOp",null);Pt(this,"holdOp",null);Pt(this,"seq",0);Pt(this,"resyncing",!1);Pt(this,"n",0);Pt(this,"pending","");Pt(this,"timer",null);Pt(this,"wasReady",!1);Pt(this,"offs",[]);Pt(this,"stopped",!1);this.wire=s,this.sessionId=n,this.screen=a,this.uuid=l}get state(){return this.view}subscribe(s){return this.listeners.add(s),()=>{this.listeners.delete(s)}}start(){this.offs.push(this.wire.onMessage(s=>this.onMessage(s))),this.offs.push(this.wire.subscribe(()=>this.onLink())),this.wasReady=this.wire.ready(),this.wasReady?this.open():this.set({phase:"offline"})}stop(){var s;if(!this.stopped){this.stopped=!0,this.flushKeys(),this.tid&&this.wire.ready()&&this.wire.send({type:"term.close",tid:this.tid});for(const n of this.offs.splice(0))n();this.timer&&clearTimeout(this.timer),(s=this.holdOp)==null||s.done("invalid"),this.holdOp=null}}hold(s){var l;if(!this.tid||this.view.phase!=="live"||this.view.readOnly||!this.wire.ready())return Promise.resolve("invalid");(l=this.holdOp)==null||l.done("invalid");const n=this.uuid(),a=this.tid;return new Promise(r=>{this.holdOp={op:n,done:o=>{this.holdOp=null,this.set({holding:!1,holdRefused:o}),r(o)}},this.set({holding:!0,holdRefused:null,released:null}),this.wire.send({type:"term.hold",op:n,tid:a,assertion:s})})}release(){!this.tid||!this.view.held||(this.flushKeys(),this.wire.send({type:"term.release",tid:this.tid}))}type(s){!this.view.held||!this.tid||nN.test(s)||(this.pending+=s,this.set({held:{...this.view.held,lastKey:Date.now()}}),this.timer===null&&(this.timer=setTimeout(()=>{this.timer=null,this.flushKeys()},sN)))}flushKeys(){if(this.timer&&(clearTimeout(this.timer),this.timer=null),!this.tid||!this.pending||!this.wire.ready()){this.pending="";return}for(;this.pending;){const s=lN(this.pending);this.pending=this.pending.slice(s.length),this.wire.send({type:"term.input",tid:this.tid,n:this.n++,data:s})}}open(){this.openOp=this.uuid(),this.tid=null,this.n=0,this.resyncing=!1,this.set({phase:"connecting",held:null,holding:!1,exit:null,refused:null}),this.wire.send({type:"term.open",op:this.openOp,id:this.sessionId})}onLink(){var n;const s=this.wire.ready();if(!(s===this.wasReady||this.stopped)){if(this.wasReady=s,!s){this.pending="",(n=this.holdOp)==null||n.done("invalid"),this.tid=null,this.view.phase!=="ended"&&this.view.phase!=="refused"&&this.set({phase:"offline",held:null,released:this.view.held?"link":this.view.released});return}this.view.phase==="offline"&&this.open()}}onMessage(s){if(!this.stopped)switch(s.type){case"term.opened":{if(!(s.op!==void 0?s.op===this.openOp:s.tid===this.tid))return;this.tid=s.tid,this.seq=s.seq,this.resyncing=!1,this.screen.reset(s.cols,s.rows),this.screen.write(rN(s.screen,s.cursor)),this.set({phase:"live",cols:s.cols,rows:s.rows,readOnly:s.readOnly===!0});return}case"term.output":if(s.tid!==this.tid||this.resyncing)return;if(s.seq!==this.seq){this.resyncing=!0,this.wire.send({type:"term.resync",tid:s.tid});return}this.seq++,this.screen.write(s.data);return;case"term.size":if(s.tid!==this.tid)return;this.screen.resize(s.cols,s.rows),this.set({cols:s.cols,rows:s.rows});return;case"term.held":if(s.tid!==this.tid)return;this.set({held:{until:Date.parse(s.until),lastKey:Date.now()},released:null});return;case"term.released":if(s.tid!==this.tid)return;this.pending="",this.set({held:null,released:s.why==="asked"?null:s.why});return;case"term.exit":if(s.tid!==this.tid)return;this.tid=null,this.set({phase:"ended",held:null,exit:s.why});return;case"operation.result":if(s.op===this.openOp&&s.status==="rejected"){this.openOp=null,this.set({phase:"refused",refused:s.reason??"invalid"});return}if(s.op===this.openOp&&s.status==="failed"){this.openOp=null,this.set({phase:"refused",refused:"unavailable"});return}this.holdOp&&s.op===this.holdOp.op&&s.status!=="received"&&this.holdOp.done(s.status==="applied"?null:s.reason??"invalid");return;default:return}}set(s){this.view={...this.view,...s};for(const n of[...this.listeners])n()}}const iN=11,yv=6,Nv=16,uc=5*6e4,cN={up:"A",down:"B",right:"C",left:"D"};function dN(t,s){switch(t){case"esc":return"\x1B";case"tab":return" ";case"enter":return"\r";case"interrupt":return"";default:return`${s?"\x1BO":"\x1B["}${cN[t]}`}}function uN(t,s){let n=t;if(s.ctrl&&[...t].length===1){const a=t.toUpperCase().charCodeAt(0);a>=64&&a<=95?n=String.fromCharCode(a-64):t===" "?n="\0":t==="?"&&(n="")}return s.alt?`\x1B${n}`:n}function xN(t){const s=t.findIndex(a=>/❯\s*1\.\s/.test(a));if(s<0)return[];const n=[];for(const a of t.slice(s,s+12)){const l=/^\s*(?:❯\s*)?(\d)\.\s+(.*)$/.exec(a);if(!l)continue;if(l[1]!==String(n.length+1))break;const r=l[2].trim(),o=/^(oui,?\s+toujours|yes,?\s+and\s+don.t\s+ask)/i.test(r)?"always":/^(oui|yes)\b/i.test(r)?"yes":/^(non|no)\b/i.test(r)?"no":null;n.push({digit:l[1],word:o})}return n}const Me=d.terminal.live2,Sx="ledge.mobile.terminalView",mN=t=>{var s;try{return((s=Qe(t))==null?void 0:s.getItem(Sx))==="fit"?"fit":"readable"}catch{return"readable"}},pN=(t,s)=>{var n;try{(n=Qe(s))==null||n.setItem(Sx,t)}catch{}};function fN(t){return{send:s=>{t.send(s).catch(()=>{})},onMessage:s=>t.onMessage(s),ready:()=>t.state()==="ready",subscribe:s=>t.subscribe(s)}}const Yl=new Map,hN=t=>{const s=Math.max(0,Math.ceil(t/1e3));return`${Math.floor(s/60)}:${String(s%60).padStart(2,"0")}`},gN=t=>wm(()=>import("./xterm-CDPb9wXW.js"),__vite__mapDeps([0,1,2,3,4])).then(s=>s.createXterm(t));function bN({store:t,link:s,session:n,storage:a,makeScreen:l,forge:r}){var Ge,pt,ft,ut;const o=me(t),i=Xt(),c=f.useRef(null),x=f.useRef(null),[u,m]=f.useState(null),[p,h]=f.useState(null),[g,y]=f.useState(()=>mN(a)),[k,S]=f.useState(!1),[b,j]=f.useState({ctrl:"off",alt:"off"}),[N,$]=f.useState(!1),[C,M]=f.useState(""),[v,A]=f.useState(!1),[T,R]=f.useState(null),[P,_]=f.useState([]),[D,E]=f.useState(!1),z=It(),K=il(),L=f.useRef(!0),W=f.useRef(b);W.current=b,f.useEffect(()=>{const Y=c.current;if(!Y)return;let Re=!1,ke=null;const ie=Ae=>{if(Re){Ae.dispose();return}const Je=new oN(fN(s),n.id,Ae);Ae.onData(xt=>Je.type(ae(xt))),Je.start(),ke={c:Je,xt:Ae},m(Je),h(Ae)};return l?ie(l(Y)):gN(Y).then(ie),()=>{Re=!0,ke==null||ke.c.stop(),ke==null||ke.xt.dispose()}},[s,n.id,l]);const ae=Y=>{const Re=W.current;if(Re.ctrl==="off"&&Re.alt==="off")return Y;const ke=uN(Y,{ctrl:Re.ctrl!=="off",alt:Re.alt!=="off"});return j(ie=>({ctrl:ie.ctrl==="armed"?"off":ie.ctrl,alt:ie.alt==="armed"?"off":ie.alt})),ke},U=f.useSyncExternalStore(Y=>u?u.subscribe(Y):()=>{},()=>(u==null?void 0:u.state)??null),O=!!(U!=null&&U.held);f.useEffect(()=>{p==null||p.setInput(O),O&&(L.current=!0,p==null||p.focus())},[p,O]),f.useEffect(()=>{!p||!x.current||!U||p.setFont(g==="fit"?p.fitFont(x.current.clientWidth-16):iN)},[p,g,U==null?void 0:U.cols]),f.useEffect(()=>{if(!p)return;const Y=x.current,Re=()=>{if(!Y)return;const ke=Yl.get(n.id);if(ke&&Y.scrollWidth>=ke.left+Y.clientWidth&&Y.scrollHeight>=ke.top+Y.clientHeight&&(Yl.delete(n.id),Y.scrollLeft=ke.left,Y.scrollTop=ke.top,L.current=!1),L.current&&g==="readable"){const{x:Ae,cellWidth:Je}=p.cursor(),xt=Ae*Je;(xt<Y.scrollLeft||xt>Y.scrollLeft+Y.clientWidth-Je*4)&&(Y.scrollLeft=Math.max(0,xt-Y.clientWidth/2))}R(Y.scrollWidth>Y.clientWidth+1?{left:Y.scrollLeft/Y.scrollWidth,width:Y.clientWidth/Y.scrollWidth}:null);const ie=xN(p.rows());_(Ae=>Ae.length===ie.length&&Ae.every((Je,xt)=>Je.digit===ie[xt].digit&&Je.word===ie[xt].word)?Ae:ie)};p.onDrawn(Re),Re()},[p,g]);const B=()=>{const Y=x.current;Y&&Yl.set(n.id,{left:Y.scrollLeft,top:Y.scrollTop})},Z=()=>{const Y=x.current;Y&&R(Y.scrollWidth>Y.clientWidth+1?{left:Y.scrollLeft/Y.scrollWidth,width:Y.clientWidth/Y.scrollWidth}:null)},H=f.useRef(null),X=Y=>Math.hypot(Y[0].clientX-Y[1].clientX,Y[0].clientY-Y[1].clientY),te=Y=>{Y.touches.length===2&&p?H.current={d:X(Y.touches),px:p.font()}:L.current=!1},pe=Y=>{if(Y.touches.length!==2||!H.current||!p||!x.current)return;const Re=p.fitFont(x.current.clientWidth-16);p.setFont(Math.max(Re,H.current.px*(X(Y.touches)/H.current.d)))},ue=()=>{H.current=null},F=Y=>{y(Y),pN(Y,a),L.current=!0},w=Y=>{var Re,ke;if(!(!u||!p)){if(L.current=!0,Y==="ctrl"||Y==="alt"){j(ie=>({...ie,[Y]:ie[Y]==="off"?"armed":ie[Y]==="armed"?"locked":"off"}));return}if(Y==="line"){$(ie=>!ie);return}if(Y==="paste"){A(!1),(ke=(Re=navigator.clipboard)==null?void 0:Re.readText)==null||ke.call(Re).then(ie=>{ie?p.paste(ie):A(!0)},()=>A(!0));return}u.type(ae(dN(Y,p.appCursor())))}},I=()=>{!u||!C||(u.type(`${C.replace(/\r?\n/g,"\r")}\r`),M(""))},V=!!n.pending||n.state==="waiting_permission"||n.state==="waiting_input",ee=((Ge=n.pending)==null?void 0:Ge.kind)==="permission"||n.state==="waiting_permission",Q={name:"thread",sessionId:n.id},J=(U==null?void 0:U.phase)??"connecting",fe=J==="ended",be=J==="offline",tt=!!((pt=o.daemon)!=null&&pt.terminalInput)&&!(U!=null&&U.readOnly)&&n.readOnly!==!0,yt=O?Me.status.held:Me.status[J],Ze=U!=null&&U.released&&U.released!=="asked"?Me.released[U.released]:null,Le=(U==null?void 0:U.exit)==="gone"?Me.exit.gone(n.name):U!=null&&U.exit?Me.exit[U.exit]:null,de=U!=null&&U.refused?Me.refused[U.refused]??Me.refused.unavailable:null,he=U!=null&&U.holdRefused?Me.holdRefused[U.holdRefused]??d.confirm.refused[U.holdRefused]??null:null,$e=U!=null&&U.held?Math.min(uc,Math.min(U.held.lastKey+uc,U.held.until)-i):0,Oe=O&&$e<=6e4,rt=ee?P:[];return e.jsxs(e.Fragment,{children:[e.jsx(dx,{store:t,session:n,current:"terminal",onLeave:B,model:D,onModel:E,display:J==="live"||be?{value:g==="readable"?Me.readable:Me.fit,onToggle:()=>F(g==="readable"?"fit":"readable")}:void 0}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col pt-2",children:[e.jsxs("div",{className:`flex h-9 flex-none items-center gap-2 rounded-t-card bg-term-bg px-3 text-[12px] text-term-fg ${O?"border-2 border-b-0 border-info":"border border-b-0 border-line"}`,children:[!Oe&&e.jsx("span",{className:"min-w-0 truncate font-mono",children:n.project}),e.jsx("span",{role:"status",className:`flex-none rounded-[6px] px-2 py-0.5 font-medium ${O?"bg-info text-white":be?"text-attention":J==="live"?"text-ok":"text-muted"}`,children:Oe?Me.heldLeft(hN($e)):yt}),e.jsx("span",{className:"flex-1"}),O?e.jsx("button",{type:"button",onClick:()=>u==null?void 0:u.release(),className:"flex-none underline",children:Me.release}):U&&!fe&&J!=="refused"&&e.jsxs("span",{className:"flex-none font-mono",children:[U.cols," × ",U.rows]})]}),e.jsx("div",{ref:x,onScroll:Z,onTouchStart:te,onTouchMove:pe,onTouchEnd:ue,"aria-label":Me.screen(n.name),className:`relative min-h-0 flex-1 overflow-auto rounded-b-card bg-term-bg p-2 ${O?"border-2 border-t-0 border-info":"border border-t-0 border-line"} ${be||fe?"opacity-45":""}`,children:e.jsx("div",{ref:c,"data-term":"",className:"w-max"})}),T&&!O&&g==="readable"&&e.jsx("div",{"aria-label":Me.position,role:"img",className:"relative mt-2 h-1 flex-none rounded-full bg-raised",children:e.jsx("span",{className:"absolute inset-y-0 rounded-full bg-muted",style:{left:`${T.left*100}%`,width:`${T.width*100}%`}})})]}),O?e.jsxs("footer",{className:"flex flex-none flex-col gap-1 pt-2 pb-[max(8px,var(--foot-inset))]",children:[v&&e.jsx("p",{role:"alert",className:"text-meta text-attention",children:Me.pasteFailed}),e.jsxs("div",{role:"toolbar","aria-label":Me.keys,className:"flex gap-1.5 overflow-x-auto py-1.5",children:[rt.map(Y=>e.jsx("button",{type:"button",onPointerDown:Re=>Re.preventDefault(),onClick:()=>{L.current=!0,u==null||u.type(Y.digit)},className:"inline-grid h-10 min-w-10 flex-none place-items-center rounded-control border border-attention/50 bg-attention/10 px-2.5 font-mono text-[13px] font-medium text-attention",children:Y.word?`${Y.digit} ${Me.contextKeys[Y.word]}`:Y.digit},Y.digit)),(z?["interrupt","paste"]:N?["esc","tab","up","down","line"]:["esc","tab","ctrl","alt","left","up","down","right","enter","interrupt","paste","line"]).map(Y=>{const Re=Y==="ctrl"||Y==="alt"?b[Y]!=="off":Y==="line"?N:!1,ke=Y==="ctrl"||Y==="alt"||Y==="line"?Re:void 0,ie=(Y==="ctrl"||Y==="alt")&&b[Y]!=="off"?`, ${b[Y]==="locked"?Me.locked:Me.armed}`:"";return e.jsx("button",{type:"button","aria-pressed":ke,"aria-label":`${Me.keyLabel[Y]}${ie}`,onPointerDown:Ae=>Ae.preventDefault(),onClick:()=>w(Y),className:`inline-grid h-10 min-w-10 flex-none place-items-center rounded-control border px-2.5 font-mono text-[13px] font-medium ${Re?"border-transparent bg-fg text-bg":"border-input bg-surface text-fg"}`,children:Me.key[Y]},Y)}),z&&e.jsx("span",{className:"ml-auto flex-none self-center pl-2 text-[12px] text-muted",children:Me.hardware})]}),N&&!z&&e.jsxs("form",{className:"flex items-center gap-2",onSubmit:Y=>{Y.preventDefault(),I()},children:[e.jsx("span",{"aria-hidden":"true",className:"font-mono text-muted",children:"$"}),e.jsx("input",{id:"term-line",value:C,onChange:Y=>M(Y.target.value),"aria-label":Me.lineField,placeholder:Me.lineField,autoCapitalize:"off",enterKeyHint:"send",className:"min-h-11 min-w-0 flex-1 rounded-control border border-input bg-transparent px-3 font-mono text-body"}),e.jsx("button",{type:"submit",disabled:!C,"aria-label":Me.lineSend,className:Pe({variant:"primary",size:"sm"}),children:Me.lineGo})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("footer",{className:"flex flex-none flex-col gap-2 pt-2.5 pb-2.5",children:[(Ze||Le||de||he)&&e.jsx("p",{role:"status",className:"text-center text-small text-muted",children:de??Le??he??Ze}),fe?e.jsx("a",{href:ne(Q),className:Pe({block:!0}),children:Me.back}):tt&&J!=="refused"?e.jsxs("div",{className:"flex items-center gap-3",children:[V&&e.jsx("span",{className:"min-w-0 flex-1 text-small text-muted",children:Me.alsoInThread}),e.jsxs("button",{type:"button",disabled:J!=="live"||(U==null?void 0:U.holding),onClick:()=>S(!0),className:Pe({size:"sm",className:V?"flex-none":"ml-auto flex-none"}),children:[e.jsx(q,{name:"keyboard"}),U!=null&&U.released?Me.holdAgain:Me.hold]})]}):!be&&((ft=o.daemon)==null?void 0:ft.terminal)&&!(U!=null&&U.readOnly)&&n.readOnly!==!0&&e.jsx("p",{className:"text-center text-meta text-muted",children:Me.inputOff}),be&&e.jsx("p",{className:"text-center text-meta text-muted",children:Me.offlineHint})]}),e.jsx(Ju,{store:t,forge:r,session:n,wide:K,threshold:((ut=o.device)==null?void 0:ut.contextNear)??kn,onModel:()=>E(!0)})]}),k&&u&&e.jsx(jN,{store:t,session:n,onClose:()=>S(!1),hold:Y=>(S(!1),u.hold(Y),"sent")})]})}function jN({store:t,session:s,onClose:n,hold:a}){const{fresh:l,device:r}=me(t),o=!!(r!=null&&r.confirm),i=Yu(t,"terminal",s.id,l&&o,a),c=u=>Pe({variant:u,block:!0}),x=i.asking?d.confirm.asking:i.challenge?_t()?`${Me.go}`:Me.go:d.confirm.preparing;return e.jsxs(dt,{labelledBy:"hold-title",onClose:n,children:[e.jsx("h2",{id:"hold-title",className:"text-heading leading-[1.3] tracking-[-.5px]",children:Me.sheetTitle(s.name)}),o?e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:Me.sheetBody}),e.jsx("p",{className:"text-small leading-[1.6] text-muted",children:Me.sheetNote}),i.problem&&e.jsx(Xe,{title:d.confirm[i.problem],tone:"warning",role:"alert"}),i.needsNew?e.jsx("button",{type:"button",onClick:i.retry,className:c("primary"),children:d.confirm.retry}):e.jsxs("button",{type:"button",disabled:i.asking||!i.challenge,onClick:()=>{i.go()},className:c("primary"),children:[e.jsx(q,{name:"passkey"}),x]})]}):e.jsxs(e.Fragment,{children:[e.jsx(Xe,{title:Me.unprotectedTitle,tone:"warning",role:"status",children:e.jsx("p",{children:Me.unprotectedBody})}),e.jsx("a",{href:ne({name:"connection"}),className:c("primary"),children:Me.openConnection})]}),e.jsx("button",{type:"button",onClick:n,className:c(),children:Me.cancel})]})}const $x="ledge.mobile.terminalSize",Cx=11,Mx=20,xc=12,yN=1e4,Ex=t=>Math.max(Cx,Math.min(Mx,t));function NN(t){var s;try{const n=Number((s=Qe(t))==null?void 0:s.getItem($x));return Number.isFinite(n)&&n>0?Ex(Math.round(n)):xc}catch{return xc}}function vN(t,s){var n;try{(n=Qe(s))==null||n.setItem($x,String(t))}catch{}}const mc=Tt({variant:"outline",className:"text-body font-medium"});function pc({store:t,link:s,sessionId:n,storage:a,forge:l}){var i;const r=me(t),o=r.sessions.get(n);return s&&o&&((i=r.daemon)!=null&&i.terminal)?e.jsx(bN,{store:t,link:s,session:o,forge:l,...a?{storage:a}:{}},n):e.jsx(kN,{store:t,sessionId:n,...a?{storage:a}:{}})}function kN({store:t,sessionId:s,storage:n}){const a=me(t),l=Xt(),{fresh:r,ops:o}=a,i=a.sessions.get(s),c=a.previews.get(s)??[],[x,u]=f.useState(()=>NN(n)),m=_=>u(D=>{const E=Ex(D+_);return vN(E,n),E}),[p,h]=f.useState(!1);f.useEffect(()=>()=>t.watch(null),[t,s]),f.useEffect(()=>{r&&t.watch(s)},[t,s,r]);const g=f.useRef(null);f.useEffect(()=>{const _=g.current;_&&(_.scrollTop=_.scrollHeight)},[c.length,c[c.length-1],x]);const y={name:"thread",sessionId:s},k=Mn(a);if(!i)return e.jsxs(e.Fragment,{children:[e.jsx(oa,{title:d.thread.title,fallback:y,label:d.terminal.back,link:k}),e.jsx("main",{className:"min-h-0 flex-1 pt-7 text-body text-muted",role:"status",children:!r&&a.syncedAt===null?d.thread.loading:d.terminal.unknown})]});const S=!!i.pending||i.state==="waiting_permission"||i.state==="waiting_input",b=!r,j=b?d.terminal.offline:S?d.terminal.waiting:d.terminal.live,N=Object.values(o).filter(_=>_.message.type==="session.interrupt"&&_.message.id===s).sort((_,D)=>_.at.localeCompare(D.at)).at(-1),$=N!==void 0&&ps(N.phase),C=i.state==="working",M=(N==null?void 0:N.phase)==="applied"&&(!C||l-Date.parse(N.at)<yN),v=C&&!b&&!S&&!$&&!M,A=b?d.terminal.why.offline:S?d.terminal.why.waiting:C?null:d.terminal.why.idle,T=()=>{v&&h(!t.interrupt(s))},R=(N==null?void 0:N.phase)==="sending"?d.terminal.sending:M?d.terminal.sent:d.terminal.interrupt(i.name),P=(N==null?void 0:N.phase)==="rejected"&&N.reason==="read_only"?d.terminal.readOnly:p||(N==null?void 0:N.phase)==="rejected"||(N==null?void 0:N.phase)==="failed"?d.terminal.fail:(N==null?void 0:N.phase)==="uncertain"&&!b?d.terminal.uncertain:null;return e.jsxs(e.Fragment,{children:[e.jsx(dx,{store:t,session:i,current:"terminal"}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col",children:[e.jsxs("div",{className:"mt-2 mb-4 flex items-center justify-between gap-2",children:[e.jsx("span",{role:"status",className:"text-small text-muted",children:j}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"button",disabled:x<=Cx,onClick:()=>m(-1),"aria-label":d.terminal.smaller,className:mc,children:"A−"}),e.jsx("button",{type:"button",disabled:x>=Mx,onClick:()=>m(1),"aria-label":d.terminal.larger,className:mc,children:"A+"})]})]}),e.jsx("div",{ref:g,tabIndex:0,"aria-label":d.terminal.output,className:"mb-3 min-h-0 flex-1 overflow-auto rounded-card border border-line bg-term-bg p-4",children:c.length===0?e.jsx("p",{className:"text-small text-muted",children:d.terminal.empty}):e.jsx("pre",{"data-size":x,style:{fontSize:x},className:"m-0 w-max min-w-full font-mono leading-[1.5] whitespace-pre text-term-fg",children:c.join(`
20
+ `)})})]}),e.jsxs("footer",{className:"flex flex-none flex-col gap-2.5 border-t border-line bg-bg pt-3 pb-[max(16px,env(safe-area-inset-bottom))] [@media(max-height:650px)]:pb-2.5",children:[e.jsx("p",{className:"text-center text-meta text-muted",children:d.terminal.scrollHint}),P&&e.jsx("p",{role:"alert",className:"text-center text-small text-attention",children:P}),e.jsxs("button",{type:"button",disabled:!v,onClick:T,className:Pe({block:!0}),children:[e.jsx(q,{name:"stop"}),R]}),A&&!$&&!M&&e.jsx("p",{className:"text-center text-meta text-muted",children:A}),e.jsx("p",{className:"text-center text-meta text-muted",children:d.terminal.note})]})]})}const On=d.unrecognized;function wN({pcName:t,onRelink:s,onSignOut:n}){return e.jsxs(Et,{children:[e.jsxs("div",{className:"flex flex-col gap-3.5",children:[e.jsx("span",{"aria-hidden":"true",className:"inline-flex size-12 items-center justify-center rounded-full bg-danger-bg text-danger-fg",children:e.jsxs("svg",{className:Ba,viewBox:"0 0 24 24",children:[e.jsx("rect",{x:"5",y:"2",width:"14",height:"20",rx:"2"}),e.jsx("path",{d:"m9.5 9.5 5 5"}),e.jsx("path",{d:"m14.5 9.5-5 5"})]})}),e.jsx("h1",{className:qt,children:On.title(t)}),e.jsx("p",{className:"text-muted",children:On.body})]}),e.jsx("p",{className:"text-body leading-[1.6] text-muted",children:On.kept}),e.jsx(Rt,{}),e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("button",{type:"button",onClick:s,className:St,children:On.relink}),e.jsx("button",{type:"button",onClick:n,className:mt,children:On.signOut})]})]})}const _s=d.update,SN=t=>`https://github.com/kl-ledge/ledge/releases/tag/v${t}`;function $N({next:t,current:s,onLater:n,onApply:a}){return e.jsxs(dt,{labelledBy:"update-title",onClose:n,children:[e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("h2",{id:"update-title",className:"text-heading leading-[26px] font-semibold tracking-[-.02em]",children:_s.version(t.version)}),e.jsx("p",{className:"text-muted",children:_s.body})]}),e.jsxs("div",{className:"flex flex-col gap-2 rounded-control border border-line bg-bg p-3.5",children:[e.jsx("span",{className:"text-small leading-4 text-muted",children:_s.fingerprint}),e.jsx("code",{className:"font-mono text-base leading-[22px] tracking-[.02em] [word-spacing:4px]",children:hx(t.fingerprint)}),e.jsxs("span",{className:"text-small leading-4 text-muted",children:[_s.current,e.jsx("span",{className:"font-mono",children:s?_s.currentBuild(s.version,oy(s.fingerprint)):d.connection.none})]})]}),e.jsxs("a",{href:SN(t.version),target:"_blank",rel:"noreferrer",className:"inline-flex min-h-11 items-center gap-2 font-medium",children:[e.jsx(q,{name:"external",className:"size-4",stroke:1.5}),_s.compare(`v${t.version}`)]}),e.jsxs("div",{className:"grid grid-cols-2 gap-2.5",children:[e.jsx(Ke,{size:"lg",onClick:n,children:_s.later}),e.jsx(Ke,{size:"lg",variant:"primary",onClick:a,children:_s.apply})]})]})}const Fr="ledge.mobile.rigs",CN=35e3,MN=()=>crypto.randomUUID(),fc=()=>crypto.randomUUID(),Ca=t=>t!=="checking"&&t!=="sending"&&t!=="received",EN=new Set(["assertion_invalid","assertion_expired","confirm_required","conflict"]);function RN(t){var s;try{const n=(s=Qe(t))==null?void 0:s.getItem(Fr);if(!n)return null;const a=JSON.parse(n),l=Sm.safeParse(a.state);return l.success&&typeof a.at=="string"?{state:l.data,at:a.at}:null}catch{return null}}function AN(t,s,n){var F;const a=RN(n);let l={state:(a==null?void 0:a.state)??null,error:null,at:(a==null?void 0:a.at)??null,loading:!1,graphs:{},queues:{},permissions:{},snapshots:{},routing:null,goals:null,runs:[]};const r=new Set,o=w=>{l={...l,...w};for(const I of[...r])I()};let i=!1,c=!1,x=!1,u=!1,m=!1;const p=new Map,h=new Map,g=new Map;let y=s.getState().daemon?((F=s.getState().daemon)==null?void 0:F.boot)??null:void 0;const k=new Set,S=()=>!i&&t.state()==="ready",b=()=>{var w;return!!((w=s.getState().daemon)!=null&&w.rigs)},j=w=>{t.send(w).catch(()=>{})};function N(w,I,V){return!S()||!b()?!1:(j(I),clearTimeout(p.get(w)),p.set(w,setTimeout(()=>{p.delete(w),V()},CN)),!0)}const $=w=>{clearTimeout(p.get(w)),p.delete(w)},C=w=>({...w??{},loading:!0}),M=w=>({...w??{},loading:!1,error:"unavailable"});function v(){u||N("state",{type:"rigs.state"},()=>{u=!1,o({loading:!1,error:"unavailable"})})&&(u=!0,o({loading:!0}))}function A(){m||N("goals",{type:"rigs.goals"},()=>{m=!1,o({goals:M(l.goals??void 0)})})&&(m=!0,o({goals:C(l.goals??void 0)}))}const T=()=>{c&&v(),x&&A()};function R(w,I){const V=l.runs.findIndex(Q=>Q.id===w);if(V<0)return;const ee=I(l.runs[V]);if(o({runs:l.runs.map((Q,J)=>J===V?ee:Q)}),Ca(ee.phase)){ee.op&&ee.phase!=="uncertain"&&h.delete(ee.op);const Q=g.get(w);g.delete(w),Q==null||Q(ee)}}const P=w=>l.runs.find(I=>I.op===w),_=w=>!!w&&(!Ca(w.phase)||w.phase==="uncertain"),D=(w,I)=>{const V=P(w);$(`op:${w}`),_(V)&&R(V.id,ee=>({...ee,...I,endedAt:Date.now()}))},E=w=>{clearTimeout(p.get(`op:${w}`)),p.set(`op:${w}`,setTimeout(()=>{p.delete(`op:${w}`);const I=P(w);(I==null?void 0:I.phase)==="sending"&&R(I.id,V=>({...V,phase:"uncertain",endedAt:Date.now()}))},Wc))},z=w=>w.sentAt!==void 0&&Date.now()-w.sentAt<Uc&&y!==void 0&&(w.boot??null)===y,K=w=>{$(`op:${w.op}`),h.delete(w.op),R(w.id,I=>({...I,phase:"uncertain",lost:!0,endedAt:I.endedAt??Date.now()}))};function L(w){for(const[I,V]of[...h]){if(w.has(I))continue;const ee=P(I);if(!ee){h.delete(I);continue}if(!z(ee)){K(ee);continue}R(ee.id,Q=>({...Q,again:!0})),j(V),ee.phase==="sending"&&E(I)}}const W=(w,I)=>!w||!w.again||!EN.has(I??"")?!1:(w.lost||K(w),!0),ae=w=>{const I=w.kind==="seats"?w.rig:w.kind==="act"&&"rig"in w.action?w.action.rig:null;I&&(l.graphs[I]||l.queues[I])&&ue.openRig(I),I&&l.snapshots[I]&&ue.readSnapshots(I)};function U(w){var I;switch(w.type){case"snapshot":{const V=y;y=w.daemon.boot??null;const ee=new Set(k);k.clear();for(const Q of ee){const J=P(Q);J&&R(J.id,fe=>({...fe,boot:y}))}(V===void 0||V!==y)&&L(ee),T();return}case"rigs.state":if($("state"),u=c,w.state){const V=new Date().toISOString();o({state:w.state,error:null,at:V,loading:!1});try{(I=Qe(n))==null||I.setItem(Fr,JSON.stringify({state:w.state,at:V}))}catch{}}else o({error:w.error??"unavailable",loading:!1});return;case"rigs.graph":$(`graph:${w.rig}`),o({graphs:{...l.graphs,[w.rig]:w.graph?{data:w.graph,loading:!1,at:new Date().toISOString()}:{...l.graphs[w.rig],loading:!1,error:w.error??"unavailable"}}});return;case"rigs.queue":$(`queue:${w.rig}`),o({queues:{...l.queues,[w.rig]:w.error?{...l.queues[w.rig],loading:!1,error:w.error}:{data:{rows:w.rows,closed:w.closed,truncated:w.truncated},loading:!1,at:new Date().toISOString()}}});return;case"rigs.permissions":$(`permissions:${w.rig}`),o({permissions:{...l.permissions,[w.rig]:w.error?{...l.permissions[w.rig],loading:!1,error:w.error}:{data:{...w.policy!==void 0?{policy:w.policy}:{},seats:w.seats},loading:!1,at:new Date().toISOString()}}});return;case"rigs.snapshots":$(`snapshots:${w.rig}`),o({snapshots:{...l.snapshots,[w.rig]:w.error?{...l.snapshots[w.rig],loading:!1,error:w.error}:{data:w.snapshots,loading:!1,at:new Date().toISOString()}}});return;case"rigs.routing":$("routing"),o({routing:w.error?{...l.routing,loading:!1,error:w.error}:{data:w.entries,loading:!1,at:new Date().toISOString()}});return;case"rigs.goals":$("goals"),m=x&&!w.error,o({goals:w.error?{...l.goals,loading:!1,error:w.error}:{data:{goals:w.goals,partial:!!w.partial},loading:!1,at:new Date().toISOString()}});return;case"operation.result":{const V=P(w.op);if(!_(V))return;if(w.status==="received"){$(`op:${w.op}`),(V.phase==="sending"||V.phase==="uncertain")&&R(V.id,ee=>{const{endedAt:Q,...J}=ee;return{...J,phase:"received"}});return}if(w.status==="rejected"&&W(V,w.reason))return;w.status==="rejected"&&D(w.op,{phase:"rejected",reason:w.reason??"invalid"});return}case"rigs.done":{const V=P(w.op);if(w.rejected&&W(V,w.rejected))return;V&&(D(w.op,w.rejected?{phase:"rejected",reason:w.rejected,done:w}:{phase:"done",done:w,...w.error?{reason:w.error}:{}}),ae(V.subject));return}case"rigs.reseated":{const V=P(w.op);if(w.rejected&&W(V,w.rejected))return;V&&(D(w.op,w.rejected?{phase:"rejected",reason:w.rejected,reseated:w}:{phase:"done",reseated:w,...w.error?{reason:w.error}:{}}),ae(V.subject));return}case"rigs.goal.sent":case"rigs.goal.replied":if(w.rejected&&W(P(w.op),w.rejected))return;D(w.op,w.rejected?{phase:"rejected",reason:w.rejected,sent:w}:{phase:"done",sent:w,...w.error?{reason:w.error}:{}});return}}let O=S(),B=0;const Z=t.subscribe(()=>{const w=t.state();(w==="unpaired"||w==="pairing")&&X();const I=S();if(I&&!O)O=!0,B++,u=!1,m=!1,y=void 0,k.clear();else if(!I&&O){O=!1,u=!1,m=!1;for(const[V,ee]of p)clearTimeout(ee),p.delete(V);o({loading:!1});for(const V of l.runs)V.phase==="sending"&&V.op&&R(V.id,ee=>({...ee,phase:"uncertain",endedAt:Date.now()}))}}),H=t.onMessage(U);function X(){var w;if(!(!l.state&&!l.runs.length&&!Object.keys(l.graphs).length)){try{(w=Qe(n))==null||w.removeItem(Fr)}catch{}h.clear(),o({state:null,error:null,at:null,loading:!1,graphs:{},queues:{},permissions:{},snapshots:{},routing:null,goals:null,runs:[]})}}async function te(w){var Q;if(!((Q=s.getState().device)!=null&&Q.confirm))return{phase:"rejected",reason:"confirm_required"};let I;try{I=await s.prepareConfirm(w)}catch(J){return{phase:J instanceof Error&&J.message==="timeout"?"expired":"unsent"}}if(!I.credentialId)return{phase:"rejected",reason:"confirm_required"};const V=Date.now(),ee=await sa({challenge:I.challenge,rpId:I.rpId,credentialId:I.credentialId}).catch(()=>"failed");return ee==="cancelled"?{phase:"cancelled"}:ee==="failed"?{phase:"unsent"}:Date.now()-V>=I.expiresInMs?{phase:"expired"}:{assertion:ee}}function pe(w,I,V){const ee=MN(),Q={op:"",id:ee,subject:w,phase:I?"checking":"sending",startedAt:Date.now()},J=new Promise(fe=>g.set(ee,fe));return!S()||!b()?(o({runs:[...l.runs,{...Q,phase:"unsent",endedAt:Date.now()}]}),g.delete(ee),Promise.resolve({...Q,phase:"unsent"})):(o({runs:[...l.runs,Q]}),(async()=>{var de;let fe;if(I){const he=await te(I);if(!("assertion"in he)){R(ee,$e=>({...$e,phase:he.phase,...he.reason?{reason:he.reason}:{},endedAt:Date.now()}));return}fe=he.assertion}const be=Hc(),tt=Fc.safeParse(V(be,fe));if(!tt.success||!S()){R(ee,he=>({...he,phase:"unsent",endedAt:Date.now()}));return}h.set(be,tt.data),y===void 0&&k.add(be),R(ee,he=>({...he,op:be,phase:"sending",sentAt:Date.now(),...y!==void 0?{boot:y}:{}})),E(be);const yt=B,Ze=await t.send(tt.data).catch(()=>!1),Le=(de=P(be))==null?void 0:de.phase;!Ze&&yt===B&&(Le==="sending"||Le==="uncertain")&&($(`op:${be}`),R(ee,he=>({...he,phase:"unsent",endedAt:Date.now()})))})(),J)}const ue={getState:()=>l,subscribe(w){return r.add(w),()=>{r.delete(w)}},follow(){c=!0,v()},retry(){u=!1,v()},openRig(w){const I=`graph:${w}`,V=`queue:${w}`,ee=`permissions:${w}`;N(I,{type:"rigs.graph",rig:w},()=>o({graphs:{...l.graphs,[w]:M(l.graphs[w])}}))&&o({graphs:{...l.graphs,[w]:C(l.graphs[w])}}),N(V,{type:"rigs.queue",rig:w},()=>o({queues:{...l.queues,[w]:M(l.queues[w])}}))&&o({queues:{...l.queues,[w]:C(l.queues[w])}}),N(ee,{type:"rigs.permissions",rig:w},()=>o({permissions:{...l.permissions,[w]:M(l.permissions[w])}}))&&o({permissions:{...l.permissions,[w]:C(l.permissions[w])}})},readSnapshots(w){N(`snapshots:${w}`,{type:"rigs.snapshots",rig:w},()=>o({snapshots:{...l.snapshots,[w]:M(l.snapshots[w])}}))&&o({snapshots:{...l.snapshots,[w]:C(l.snapshots[w])}})},readPermissions(w){const I=`permissions:${w}`;N(I,{type:"rigs.permissions",rig:w},()=>o({permissions:{...l.permissions,[w]:M(l.permissions[w])}}))&&o({permissions:{...l.permissions,[w]:C(l.permissions[w])}})},readRouting(){N("routing",{type:"rigs.routing"},()=>o({routing:M(l.routing??void 0)}))&&o({routing:C(l.routing??void 0)})},followGoals(){x=!0,A()},act(w){return pe({kind:"act",action:w},Hr(w)?{purpose:"rigs",rigAct:w}:null,(I,V)=>({type:"rigs.act",op:I,action:w,...V?{assertion:V}:{}}))},reseat(w,I,V={}){var J,fe;const ee=((fe=(J=l.state)==null?void 0:J.rigs.find(be=>be.name===w))==null?void 0:fe.nodes)??[],Q=V.check||Dc(ee,I).remove.length>0;return pe({kind:"seats",rig:w,seats:I,...V.delegation?{delegation:V.delegation}:{}},Q?{purpose:"rigs",rigSeats:{rig:w,seats:I}}:null,(be,tt)=>({type:"rigs.seats",op:be,rig:w,seats:I,...V.delegation?{delegation:V.delegation}:{},...tt?{assertion:tt}:{}}))},sendGoal(w,I=fc()){return pe({kind:"goal",goalId:I,text:w},null,V=>({type:"rigs.goal.send",op:V,goalId:I,text:w}))},replyGoal(w,I,V=fc()){return pe({kind:"reply",goalId:w,replyId:V,text:I},null,ee=>({type:"rigs.goal.reply",op:ee,goalId:w,replyId:V,text:I}))},dismiss(w){const I=l.runs.find(V=>V.id===w);I&&Ca(I.phase)&&I.op&&(h.delete(I.op),$(`op:${I.op}`)),o({runs:l.runs.filter(V=>V.id!==w||!Ca(V.phase))})},close(){i=!0,Z(),H();for(const w of p.values())clearTimeout(w);p.clear()}};return ue}function Rn(t){return f.useSyncExternalStore(t.subscribe,t.getState,t.getState)}const Ql={relaunch:!0,noKernel:!1},Rx="ledge.mobile.daemonPrefs",zr=new Set;function Ax(t){var s;try{const n=JSON.parse(((s=Qe(t))==null?void 0:s.getItem(Rx))??"{}");return{relaunch:typeof n.relaunch=="boolean"?n.relaunch:Ql.relaunch,noKernel:typeof n.noKernel=="boolean"?n.noKernel:Ql.noKernel}}catch{return Ql}}function TN(t,s){var n;try{(n=Qe(s))==null||n.setItem(Rx,JSON.stringify({...Ax(s),...t}))}catch{}for(const a of[...zr])a()}const _N=t=>(zr.add(t),()=>{zr.delete(t)});function Eo(t){const s=f.useSyncExternalStore(_N,()=>JSON.stringify(Ax(t)));return[JSON.parse(s),n=>TN(n,t)]}function Tx(t,s){const n=s.relaunch?"last":"none";return t==="restart"?{kind:"daemon.restart",restore:n}:{kind:"daemon.start",restore:n,...s.noKernel&&!s.relaunch?{noKernel:!0}:{}}}const ye=d.rigs;function IN(t){var a;const s=t.subject;if(s.kind==="seats")return s.rig;if(s.kind!=="act")return"";const n=s.action;return n.rig??((a=n.seat)==null?void 0:a.split("@")[0])??""}const Ro=t=>t.subject.kind==="act"?t.subject.action.kind:t.subject.kind==="seats"?"seats":null;function Dn(t){const s=Ro(t);return s?ye.notDone[s]:ye.rejected.nothingSent}function LN(t){const s=Ro(t),n=ye.rejected.againVerb;return s==="seats"?n.remove:s==="rig.stop"||s==="daemon.stop"||s==="kernel.stop"?n.stop:s==="rig.restart"||s==="daemon.restart"||s==="kernel.restart"?n.restart:s==="rig.policy"||s==="rig.permissions"?n.apply:s==="seat.set"?n.save:null}function ON(t,s){const n=_t(),a=t.phase==="expired"?"assertion_expired":t.phase==="cancelled"?"cancelled":t.phase==="unsent"?"unsent":t.reason??"unavailable",l=LN(t),r=l?ye.rejected.again(l):ye.rejected.nothingSent;switch(a){case"busy":return{mark:"warn",title:ye.busy.title(s),sub:ye.busy.body};case"confirm_required":return t.subject.kind==="seats"?{mark:"warn",title:n?ye.reseat.wouldLeave.title:ye.reseat.wouldLeave.titleDevice,sub:ye.reseat.wouldLeave.body}:{mark:"warn",title:ye.rejected.confirm_required};case"assertion_expired":return{mark:"bad",title:ye.because(Dn(t),ye.rejected.assertion_expired(n)),sub:r};case"assertion_invalid":return{mark:"bad",title:ye.because(Dn(t),ye.rejected.assertion_invalid(n)),sub:r};case"cancelled":return{mark:"bad",title:ye.because(Dn(t),ye.rejected.cancelled),sub:ye.rejected.nothingSent};case"unsent":return{mark:"bad",title:ye.because(Dn(t),ye.rejected.unsent),sub:ye.rejected.nothingSent};default:return{mark:"bad",title:ye.because(Dn(t),`${ye.notSent(s)}.`)}}}function Ja({run:t,rigs:s,pc:n,bar:a=!1}){const l=Ro(t),r=IN(t),o={onClose:()=>s.dismiss(t.id),closeLabel:ye.done.close};if(t.phase==="checking")return e.jsx(Zn,{bar:a,children:ye.running.checking});if(t.phase==="sending"||t.phase==="received"){const m=l==="seats"?ye.running.seats(r):l?ye.running[l](r):"";return e.jsx(Zn,{bar:a,children:`${m} · ${ye.running.note}`})}if(t.phase==="uncertain")return e.jsx(Se,{mark:"ask",title:ye.uncertain.title,sub:ye.uncertain.body,...o});if(t.phase!=="done"){const m=ON(t,n);return e.jsx(Se,{mark:m.mark,title:m.title,...m.sub?{sub:m.sub}:{},...o})}const i=Be(t.endedAt?new Date(t.endedAt).toISOString():null);if(t.reseated){const m=t.reseated;if(m.ok){const p=m.added.length?ye.reseat.added(m.added.length,m.links):ye.reseat.removed(m.removed.length);return e.jsxs(Se,{mark:"ok",title:p,...o,children:[m.linksUnsupported&&e.jsxs("small",{className:"block text-[12px] text-attention",children:[ye.reseat.noLinks.title," ",ye.reseat.noLinks.body]}),e.jsx(Xs,{commands:m.commands})]})}return m.error==="busy"?e.jsx(Se,{mark:"warn",title:ye.busy.title(n),sub:ye.busy.body,...o}):m.error==="rig_not_running"?e.jsx(Se,{mark:"bad",title:ye.reseat.notRunning.title,sub:ye.reseat.notRunning.body,...o}):e.jsx(Se,{mark:"bad",title:ye.failed(m.message??ye.errors[m.error??"failed"]??ye.errors.failed),...o,children:e.jsx(Xs,{commands:m.commands})})}const c=t.done;if(!c||!l||l==="seats")return null;if(c.ok){const m=t.subject.kind==="act"&&t.subject.action.kind==="rig.stop"&&t.subject.action.snapshot;return e.jsx(Se,{mark:"ok",title:ye.done[l](r),sub:[i,m?ye.done.snapshotFirst:""].filter(Boolean).join(" · "),...o,children:e.jsx(Xs,{commands:c.commands})})}if(c.error==="busy")return e.jsx(Se,{mark:"warn",title:ye.busy.title(n),sub:ye.busy.body,...o});const x=t.subject.kind==="act"&&"seats"in t.subject.action?t.subject.action.seats.length:0;if(c.completed!==void 0&&x)return e.jsx(Se,{mark:"bad",title:ye.completed(c.completed,x),...c.message?{sub:e.jsx("span",{className:"font-mono",children:c.message})}:{},...o});const u=c.error&&c.error!=="failed"?ye.errors[c.error]:void 0;return e.jsx(Se,{mark:"bad",title:u??ye.failed(ye.errors.failed),...c.message?{sub:e.jsx("span",{className:"font-mono",children:c.message})}:{},...o,children:e.jsx(Xs,{commands:c.commands})})}function Ao(t,s){for(let n=t.length-1;n>=0;n--)if(s(t[n]))return t[n]}const kl=t=>!!t&&(t.phase==="checking"||t.phase==="sending"||t.phase==="received"),je=d.rigs,DN={running:"on",stopped:"plain",stale:"bad",unknown:"plain"},_x={ready:"on",starting:"go",stopped:"plain",skipped:"plain",absent:"plain",unknown:"plain"};function To({state:t,href:s}){const n=t.daemon.state==="running"&&t.daemon.startedAt?Be(t.daemon.startedAt):null;return e.jsx(jr,{lead:e.jsx(q,{name:"cpu",className:"size-[18px] text-muted"}),name:je.daemon,chip:e.jsx(vn,{tone:DN[t.daemon.state],children:je.daemonState[t.daemon.state]}),sub:je.daemonSub(t.version,n),...s?{href:s}:{}})}function Ix({disabled:t,next:s=!1}){const[n,a]=Eo();return e.jsxs(e.Fragment,{children:[e.jsx(ji,{on:n.relaunch,label:je.relaunch,disabled:t,onChange:l=>a({relaunch:l})}),e.jsx(ji,{on:n.noKernel,label:je.noKernel,hint:s?je.noKernelNext:je.noKernelHint,disabled:t,onChange:l=>a({noKernel:l})})]})}function el({glyph:t,title:s,body:n,list:a=!0,children:l}){return e.jsxs("div",{"data-list-state":a?"":void 0,className:"flex flex-col items-center gap-1.5 px-4 pt-[26px] pb-[22px] text-center",children:[t&&e.jsx("div",{"aria-hidden":"true",className:"grid size-12 place-items-center rounded-[10px] border border-line text-muted",children:t}),e.jsx("h2",{className:"mt-1.5 text-[17px] leading-6 font-semibold",children:s}),e.jsx("p",{className:"max-w-[300px] text-[13.5px] text-muted",children:n}),l]})}function hc({state:t,rigs:s,store:n,pc:a}){const l=me(n).fresh,[r]=Eo(),o=Rn(s),i=Ao(o.runs,c=>c.subject.kind==="act"&&c.subject.action.kind==="daemon.start");return e.jsxs(e.Fragment,{children:[t&&e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:je.openrig}),e.jsx(Ve,{children:e.jsx(To,{state:t})})]}),e.jsxs(Ve,{children:[e.jsx(el,{glyph:e.jsx(q,{name:"power"}),title:je.stopped.title,body:je.stopped.body}),e.jsx("div",{className:"border-t border-line",children:e.jsx(Ix,{disabled:!l})}),e.jsx("div",{className:"p-3",children:e.jsx("button",{type:"button",disabled:!l||kl(i),onClick:()=>{s.act(Tx("start",r))},className:ge({tone:"primary",className:"w-full"}),children:e.jsx(Dt,{icon:"power",children:je.stopped.start})})})]}),i&&e.jsx(Ja,{run:i,rigs:s,pc:a}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:je.stopped.note})]})}function FN(){const t="block animate-[ledge-pulse_1.6s_ease-in-out_infinite] rounded-[5px] bg-raised";return e.jsxs("div",{role:"status","data-list-state":"",className:"flex flex-col gap-3",children:[e.jsx(Ve,{children:e.jsxs("div",{"aria-hidden":"true",className:"flex flex-col gap-2.5 p-2.5",children:[e.jsx("span",{className:`${t} h-3.5 w-[60%]`}),e.jsx("span",{className:`${t} h-3 w-[40%]`})]})}),e.jsx(Ve,{children:e.jsxs("div",{"aria-hidden":"true",className:"flex flex-col gap-2.5 p-2.5",children:[e.jsx("span",{className:`${t} h-3.5 w-1/2`}),e.jsx("span",{className:`${t} h-3 w-[70%]`}),e.jsx("span",{className:`${t} h-3.5 w-[45%]`}),e.jsx("span",{className:`${t} h-3 w-[65%]`})]})}),e.jsx("span",{className:"text-[12px] text-muted",children:je.loading})]})}function zN({state:t,at:s,store:n,offline:a}){const l=me(n),r=na(),o=It(),i=Zd(t),c=br(t),x=c.filter(h=>Gh(hs(h))).length,u=[...l.sessions.values()],m=((i==null?void 0:i.nodes)??[]).map(ou),p=t.daemon.state==="running";return e.jsxs("div",{className:`flex flex-col gap-3 ${a?"opacity-50":""}`,children:[e.jsx(Ft,{aside:!a&&s?je.updatedAt(Be(s)):void 0,children:je.openrig}),e.jsxs(Ve,{label:je.openrig,children:[e.jsx(To,{state:t,...a?{}:{href:ne({name:"kernel"})}}),t.kernel.state!=="absent"&&e.jsx(jr,{lead:e.jsx(Ie,{state:"rig"}),name:je.kernel,selected:r.name==="kernel"&&o,chip:e.jsx(vn,{tone:_x[t.kernel.state],children:je.kernelState[t.kernel.state]}),sub:m.length?a||o?je.kernelSubShort(m):je.kernelSub(m):"",...a?{}:{href:ne({name:"kernel"})}})]}),p&&c.length===0?e.jsx(Ve,{children:e.jsx(el,{title:je.empty.title,body:je.empty.body,list:!1,children:e.jsx("a",{href:ne({name:"max"}),className:ge({size:"sm",className:"mt-1.5"}),children:je.empty.talk})})}):c.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:je.rigsHead(x)}),e.jsx(Ve,{tone:"rigs",label:je.title,children:c.map(h=>{const g=hs(h),y=eu(h.name,u,l.asks),k=g==="stopped",S=a?[k?je.seatCount(h.seats):je.seats(h.running,h.seats),!k&&s?je.at(Be(s)):""].filter(Boolean).join(" · "):g==="stopped"?[je.seatCount(h.seats),h.snapshot?je.snapshot(h.snapshot):je.noSnapshot].join(" · "):g==="partial"?[je.seats(h.running,h.seats),je.stoppedCount(h.nodes.filter(j=>j.stopped).length||h.seats-h.running)].join(" · "):g==="starting"?je.seats(h.running,h.seats):[je.seats(h.running,h.seats),h.uptime?je.since(h.uptime):"",h.snapshot?je.snapshot(h.snapshot):""].filter(Boolean).join(" · "),b=!a&&(y.perm||y.ask)?e.jsxs(e.Fragment,{children:[y.perm>0&&e.jsx(Qn,{perm:!0,children:je.attention.permission(y.perm)}),y.ask>0&&e.jsx(Qn,{children:je.attention.question(y.ask)})]}):void 0;return e.jsx(jr,{lead:e.jsx(Ie,{state:tu(h,y),pulse:g==="starting"&&!a}),name:h.name,dim:k,chip:e.jsx(vn,{tone:iu[g],children:je.status[g]}),sub:S,att:b,href:ne({name:"rig",rig:h.name}),selected:o&&r.name==="rig"&&r.rig===h.name},h.id)})})]}),!a&&p&&e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:je.launchNote})]})}function PN({rigs:t,store:s}){const n=Rn(t),{pc:a,look:l}=Ut(),r=l==="offline";f.useEffect(()=>{t.follow()},[t]);const o=Ht(a),i=n.state,c=i?i.installed?!r&&ng(i)?e.jsx(hc,{state:i,rigs:t,store:s,pc:o}):e.jsxs(e.Fragment,{children:[!r&&n.error&&e.jsxs(Gt,{warn:!0,role:"alert",lead:e.jsx(q,{name:"warning",className:"mt-px size-4 text-attention"}),children:[e.jsx("b",{className:"font-semibold",children:je.unavailable.title}),n.at&&e.jsx("span",{className:"text-muted",children:je.unavailable.body(Be(n.at))}),e.jsx("button",{type:"button",onClick:()=>t.retry(),className:ge({size:"sm",className:"self-start"}),children:e.jsx(Dt,{icon:"refresh",children:je.unavailable.retry})})]}),e.jsx(zN,{state:i,at:n.at,store:s,offline:r})]}):e.jsx(Ve,{children:e.jsx(el,{title:je.notInstalled.title,body:je.notInstalled.body(o)})}):n.error==="not_installed"?e.jsx(Ve,{children:e.jsx(el,{title:je.notInstalled.title,body:je.notInstalled.body(o)})}):n.error==="daemon_stopped"?e.jsx(hc,{state:null,rigs:t,store:s,pc:o}):n.error?e.jsx("div",{"data-list-state":"",className:"flex flex-col",children:e.jsxs(Gt,{warn:!0,role:"alert",lead:e.jsx(q,{name:"warning",className:"mt-px size-4 text-attention"}),children:[e.jsx("b",{className:"font-semibold",children:je.unavailable.title}),e.jsx("button",{type:"button",onClick:()=>t.retry(),className:ge({size:"sm",className:"self-start"}),children:e.jsx(Dt,{icon:"refresh",children:je.unavailable.retry})})]})}):e.jsx(FN,{});return e.jsx(Rs,{title:je.title,offlineBody:je.offlineBody,heading:!1,children:c})}const se=d.rigs;function tl(t,s=new Date){const n=Xa(t);if(!n)return{short:t,long:t};const a=n.toLocaleTimeString(lt,{hour:"2-digit",minute:"2-digit"}),l=fo(n,s);if(l===0)return{short:a,long:se.snapshots.today(a)};if(l===1)return{short:se.snapshots.yesterday(a),long:se.snapshots.yesterday(a)};const r=n.toLocaleDateString(lt,{weekday:"short",day:"numeric",month:"short"});return{short:r,long:`${r} ${a}`}}function zs({verb:t,confirm:s,disabled:n,onClick:a}){const l=_t();return s?e.jsx("button",{type:"button",disabled:n,onClick:a,className:ge({tone:"dangerfill",className:"w-full"}),children:e.jsx(Dt,{icon:l?"face":"passkey",size:"size-[18px]",children:se.withCheck(t,l)})}):e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("p",{className:"text-[12.5px] text-muted",children:se.protectFirst}),e.jsx("a",{href:ne({name:"connection"}),className:ge({className:"w-full"}),children:se.openSettings})]})}const ha=({onClose:t})=>e.jsx("button",{type:"button",onClick:t,className:ge({className:"w-full"}),children:se.confirm.cancel});function Ma({title:t,conseq:s,note:n,verb:a,confirm:l,live:r,onConfirm:o,onClose:i}){return e.jsxs(cs,{title:t,onClose:i,children:[s&&e.jsx(ho,{title:s.title,...s.body?{body:s.body}:{}}),n&&e.jsx("p",{className:"text-[12.5px] leading-[18px] text-muted",children:n}),e.jsx(zs,{verb:a,confirm:l,disabled:!r,onClick:()=>{i(),o()}}),e.jsx(ha,{onClose:i})]})}function Ys({icon:t,label:s,aside:n,onClick:a,disabled:l=!1,danger:r=!1}){return e.jsxs("button",{type:"button",role:"menuitem",disabled:l,onClick:a,className:`flex min-h-12 items-center gap-3 border-b border-line px-3.5 text-left text-[15px] last:border-b-0 disabled:opacity-45 ${r?"text-approval":""}`,children:[e.jsx(q,{name:t,className:`size-[18px] ${r?"":"text-muted"}`}),e.jsx("span",{className:"min-w-0 flex-1",children:s}),n&&e.jsx("span",{className:"text-[13px] text-muted",children:n})]})}function BN({rig:t,live:s,running:n,snapshots:a,level:l,onSnapshot:r,onSnapshots:o,onPermissions:i,onRefresh:c,onClose:x}){return e.jsx(cs,{title:t,onClose:x,children:e.jsxs("div",{role:"menu","aria-label":se.more,className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:[e.jsx(Ys,{icon:"camera",label:se.actions.snapshot,disabled:!s||n,onClick:r}),e.jsx(Ys,{icon:"list",label:se.actions.snapshots,...a!==null?{aside:String(a)}:{},onClick:o}),e.jsx(Ys,{icon:"shield",label:se.actions.permissions,...l?{aside:l}:{},onClick:i}),e.jsx(Ys,{icon:"refresh",label:se.actions.refresh,disabled:!s,onClick:c})]})})}function qN({live:t,up:s,onRefresh:n,onRestart:a,onStop:l,onClose:r}){return e.jsx(cs,{title:se.kernel,onClose:r,children:e.jsxs("div",{role:"menu","aria-label":se.more,className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:[e.jsx(Ys,{icon:"refresh",label:se.kernelView.menu.refresh,disabled:!t,onClick:n}),e.jsx(Ys,{icon:"refresh",label:se.kernelView.menu.restart,disabled:!t||!s,onClick:a}),e.jsx(Ys,{icon:"power",label:se.kernelView.menu.stop,danger:!0,disabled:!t||!s,onClick:l})]})})}function HN({rig:t,pc:s,verb:n,confirm:a,live:l,onAct:r,onClose:o}){const[i,c]=f.useState(!0),[x,u]=f.useState(!1),m=t.nodes.filter(y=>!y.stopped&&xa(y)).map(y=>ys(y.logicalId,y.session)),p=n==="stop",h=m.length?se.confirm.working(m.length):se.confirm.noneWorking,g=p?{kind:"rig.stop",rig:t.name,...i?{snapshot:!0}:{},...x?{force:!0}:{}}:{kind:"rig.restart",rig:t.name};return e.jsxs(cs,{title:p?se.confirm.stop(t.name,s):se.confirm.restart(t.name,s),onClose:o,children:[e.jsx(ho,{title:h,body:p?m.length?m.join(", "):void 0:se.confirm.restartNote}),p&&e.jsxs("div",{className:"overflow-hidden rounded-[10px] border border-line",children:[e.jsx(bi,{on:i,label:se.confirm.snapshot,onChange:c}),e.jsx(bi,{on:x,label:se.confirm.force,onChange:u})]}),e.jsx(zs,{verb:p?se.actions.stop:se.actions.restart,confirm:a,disabled:!l,onClick:()=>{o(),r(g)}}),e.jsx(ha,{onClose:o})]})}function Lx({rig:t,confirm:s,live:n,onReseat:a,onDone:l,context:r}){const o=lu(t),[i,c]=f.useState({}),[x,u]=f.useState("pairs"),m=Object.fromEntries(Object.entries(i).filter(([j,N])=>{var $;return(($=o.find(C=>C.role===j))==null?void 0:$.count)!==N})),p=Dc(t.nodes,m),h=p.add.length,g=p.remove.length,y=t.nodes.filter(j=>p.remove.includes(j.logicalId)&&xa(j)).map(j=>j.logicalId),k=h&&g?se.reseat.change(h,g):h?se.reseat.add(h):g?se.reseat.remove(g):se.reseat.noChange,S=()=>{l==null||l(),c({}),a(m,h?x:void 0)},b=r!==void 0;return e.jsxs(e.Fragment,{children:[e.jsx("table",{className:"w-full border-collapse text-[13px]",children:e.jsx("tbody",{children:o.map(j=>{const N=i[j.role]??j.count,$=p.add.filter(T=>T.role===j.role).map(T=>se.reseat.adds(`${T.pod}.${T.id}`)),C=p.remove.filter(T=>j.ids.includes(T)).map(se.reseat.removes),M=j.ids.map(T=>{var R;return ys(T,(R=t.nodes.find(P=>P.logicalId===T))==null?void 0:R.session)}).join(", "),v=b?j.ids.map(T=>r[T]).filter(T=>T!==void 0).map(T=>`${Math.round(T)} %`).join(", "):"",A=b?[...$,...C].join(" · "):[M,...$,...C].join(C.length?" → ":" · ");return e.jsxs("tr",{className:"border-b border-line last:border-b-0",children:[e.jsxs("td",{className:"px-1 py-[7px] font-mono text-[12.5px]",children:[j.role,A&&e.jsx("small",{className:"block font-sans text-[11.5px] text-muted",children:A})]}),b&&e.jsx("td",{className:"px-1 py-[7px] text-[12px] text-muted",children:v}),e.jsx("td",{className:"px-1 py-[7px] text-right",children:e.jsx(dg,{value:N,changed:N!==j.count,disabled:!n,fewer:se.reseat.fewer(j.role),more:se.reseat.more(j.role),onChange:T=>c({...i,[j.role]:T})})})]},j.role)})})}),h>0&&e.jsxs("div",{className:"flex items-center gap-2.5",children:[e.jsx("span",{className:"flex-1 text-[12.5px] text-muted",children:se.reseat.delegation}),e.jsx(La,{label:se.reseat.delegation,value:x,onChange:u,options:[{value:"pairs",label:se.reseat.pairs},{value:"all",label:se.reseat.all}]})]}),g>0&&e.jsx(ho,{title:y.length?se.reseat.working(y):se.reseat.lastFirst,...y.length?{body:se.reseat.lastFirst}:{}}),(!b||h+g>0)&&(g>0?e.jsx(zs,{verb:k,confirm:s,disabled:!n,onClick:S}):e.jsx("button",{type:"button",disabled:!n||h===0,onClick:S,className:ge({tone:"primary",className:"w-full"}),children:k})),b&&h+g>0&&e.jsx("button",{type:"button",onClick:()=>c({}),className:ge({className:"w-full"}),children:se.confirm.cancel})]})}function UN({rig:t,pc:s,confirm:n,live:a,onReseat:l,onClose:r}){return e.jsxs(cs,{title:se.reseat.title(t.name,s),onClose:r,children:[e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:se.reseat.today(lu(t).map(o=>se.reseat.part(o.count,o.role)).join(", "))}),e.jsx(Lx,{rig:t,confirm:n,live:a,onReseat:l,onDone:r}),e.jsx(ha,{onClose:r})]})}function WN({rig:t,read:s,level:n,confirm:a,live:l,onAct:r,onClose:o}){var k,S;const[i,c]=f.useState(n==="mixed"?null:n),x=_t(),u=Jh((k=s==null?void 0:s.data)==null?void 0:k.policy),m=(((S=s==null?void 0:s.data)==null?void 0:S.seats.map(b=>b.session))??t.nodes.map(b=>b.session)).filter(b=>b.endsWith(`@${t.name}`)),p=i&&m.length?{kind:"rig.policy",rig:t.name,policy:i,seats:m}:null,h=!!p&&Hr(p),g=()=>{p&&(o(),r(p))},y=!l||!p||i===n;return e.jsxs(cs,{title:se.permissions.title(t.name),onClose:o,children:[e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:[se.permissions.sub,u?se.permissions.spec(se.level[u]):""].filter(Boolean).join(" ")}),(s==null?void 0:s.error)&&!s.data&&e.jsx("p",{role:"alert",className:"text-[12.5px] text-attention",children:se.permissions.unavailable}),e.jsx("div",{className:"flex flex-col gap-1.5",children:Qh.map(b=>e.jsx(yr,{pressed:i===b,disabled:!l,onClick:()=>c(b),sub:se.permissions.hint[b],title:e.jsxs(e.Fragment,{children:[se.level[b],(b==="yolo"||b==="spec")&&e.jsx("span",{className:"ml-1.5 inline-flex align-middle",children:e.jsx(zt,{tone:"perm",children:x?se.permissions.faceId:se.permissions.check})})]})},b))}),h?e.jsx(zs,{verb:se.permissions.apply,confirm:a,disabled:y,onClick:g}):e.jsx("button",{type:"button",disabled:y,onClick:g,className:ge({tone:"primary",className:"w-full"}),children:se.permissions.apply})]})}const KN=(t,s)=>{const n=rg(t,s.links).map(a=>{var r;const l=ys(a.who,(r=s.seats.find(o=>o.logicalId===a.who))==null?void 0:r.session);return a.kind==="linked"?se.seat.linked(l,a.label):se.seat[a.kind](l)});return n.length?n.join(" · "):se.seat.noLink};function VN({rig:t,seat:s,graph:n,node:a,session:l,status:r,near:o,onSettings:i,onClose:c}){const x=mo({session:l,node:a,graph:s,rigStatus:r}),u=po(s.runtime),m=ys(s.logicalId,s.session),p=[u?d.tools[u]:s.runtime,s.model??(a==null?void 0:a.model)??""].filter(Boolean).join(" · "),h=l!=null&&l.pending?se.seat.prompt(se.seatState[x]):se.seatState[x],g=a&&a.work>0?se.seat.tasks(a.work):se.seat.noTask,y=[[se.seat.harness,p],...s.context!==void 0?[[se.seat.context,e.jsx("span",{className:`font-mono ${s.context>=o?"text-attention":""}`,children:`${Math.round(s.context)} %`},"c")]]:[],[se.seat.now,h],[se.seat.work,g],[se.seat.links,KN(s.logicalId,n)]];return e.jsxs(cs,{title:m,onClose:c,children:[e.jsxs("div",{className:"-mt-2 flex items-center gap-2",children:[e.jsx(Ie,{state:su[x]}),u&&e.jsx(gs,{tool:u}),e.jsx("span",{className:"flex-1"}),e.jsx("span",{className:"text-[12.5px] text-muted",children:se.seat.of(s.logicalId,t)})]}),e.jsx("dl",{className:"m-0 grid grid-cols-[110px_1fr] gap-x-3 gap-y-1.5 text-[13px]",children:y.map(([k,S])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted",children:k}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:S})]},k))}),l?e.jsx("a",{href:ne({name:"thread",sessionId:l.id}),className:ge({tone:"primary",className:"w-full"}),children:se.seat.openSession}):e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:!0,className:ge({tone:"primary",className:"w-full"}),children:se.seat.openSession}),e.jsx("p",{className:"-mt-1 text-[12px] text-muted",children:se.seat.noSession})]}),e.jsx("button",{type:"button",onClick:i,className:ge({className:"w-full"}),children:e.jsx(Dt,{icon:"gear",children:se.seat.settings})})]})}function GN({rig:t,seat:s,node:n,selection:a,confirm:l,live:r,onAct:o,onClose:i}){const c=se.seatSettings,x=s.runtime==="codex"?"codex":s.runtime==="claude-code"||s.runtime==="claude"?"claude-code":null,u=s.model??(n==null?void 0:n.model)??"",m=a==="inherit"||a==="auto"||a==="full_bypass"?a:null,[p,h]=f.useState(x),[g,y]=f.useState(u),[k,S]=f.useState(null),[b,j]=f.useState(m),N=ys(s.logicalId,s.session),$=s.session??(n==null?void 0:n.session)??`${N}@${t}`,C=g.trim()===""||$m.safeParse(g.trim()).success,M=p!==null&&p!==x,v={kind:"seat.set",seat:$,...M?{runtime:p}:{},...g.trim()&&g.trim()!==u?{model:g.trim()}:{},...k?{effort:k}:{},...b&&b!==m?{permissions:b}:{}},A=Object.keys(v).length>2,T=Hr(v),R=po(s.runtime),P=[R?d.tools[R]:s.runtime,u,m?c.perm[m]:""].filter(Boolean),_=!r||!A||!C,D=()=>{i(),o(v)},E=(z,K,L)=>e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx("span",{className:"text-[12.5px] text-muted",children:`${z} · ${K}`}),L]});return e.jsxs(cs,{title:c.title(N,t),onClose:i,children:[e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:c.today(P)}),E(c.harness,c.whenNow,e.jsx(La,{label:c.harness,value:p,disabled:!r,onChange:h,options:[{value:"claude-code",label:d.tools.claude},{value:"codex",label:d.tools.codex}]})),E(c.model,c.whenResume,e.jsx("input",{"aria-label":c.modelLabel,value:g,disabled:!r,onChange:z=>y(z.target.value),autoCapitalize:"off",autoCorrect:"off",spellCheck:!1,className:`h-11 rounded-[10px] border bg-surface px-3 text-base outline-none focus:border-ring ${C?"border-input":"border-approval/60"}`})),E(c.effort,c.whenResume,e.jsx(La,{label:c.effort,value:k,disabled:!r,onChange:S,options:["medium","high","xhigh"].map(z=>({value:z,label:c.effortLevel[z]}))})),E(c.permissions,c.whenLaunch,e.jsx(La,{label:c.permissions,value:b,disabled:!r,onChange:j,options:["inherit","auto","full_bypass"].map(z=>({value:z,label:c.perm[z]}))})),M&&e.jsx("p",{className:"text-[12.5px] text-attention",children:c.moveNote}),T?e.jsx(zs,{verb:c.save,confirm:l,disabled:_,onClick:D}):e.jsx("button",{type:"button",disabled:_,onClick:D,className:ge({tone:"primary",className:"w-full"}),children:c.save})]})}function Ox({read:t,kindOnly:s=!1,retry:n}){const a=cu((t==null?void 0:t.data)??[]),l="overflow-hidden rounded-[10px] border border-line bg-surface dark:bg-transparent";return t!=null&&t.error&&!t.data?e.jsx("div",{className:l,children:e.jsx(Ds,{retry:n,retryLabel:se.unavailable.retry,children:se.snapshots.unavailable})}):t!=null&&t.data&&a.length===0?e.jsx("div",{className:l,children:e.jsx(Ds,{children:se.snapshots.none})}):a.length?e.jsx("div",{className:"flex max-h-[45dvh] flex-col overflow-y-auto rounded-[10px] border border-line bg-surface dark:bg-transparent",children:a.map(r=>e.jsxs("div",{className:"flex min-h-[46px] items-center gap-2.5 border-b border-line px-3 py-1.5 text-[13px] last:border-b-0",children:[e.jsx(q,{name:"camera",className:"size-4 text-muted"}),e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{children:tl(r.createdAt).long}),e.jsx("small",{className:"text-[11.5px] text-muted",children:s?se.snapshots.kind[r.kind]??r.kind:[se.snapshots.kind[r.kind]??r.kind,se.snapshots.status[r.status]??r.status].join(" · ")})]})]},r.id))}):e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:se.loading})}function XN({rig:t,read:s,live:n,running:a,onSnapshot:l,onRetry:r,onClose:o}){return e.jsxs(cs,{title:se.snapshots.title(t),onClose:o,children:[e.jsx(Ox,{read:s,retry:r}),e.jsx("button",{type:"button",disabled:!n||a,onClick:()=>{o(),l()},className:ge({className:"w-full"}),children:e.jsx(Dt,{icon:"camera",children:se.snapshots.take})}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:se.snapshots.utc})]})}const xe=d.rigs,Es=t=>{var s;return((s=Xa(t))==null?void 0:s.toISOString())??t},YN={mine:"border-attention/50 text-attention",progress:"border-info/45 text-info",pending:"border-input text-muted",blocked:"border-approval/45 text-approval"},QN=({tone:t})=>e.jsx("span",{"data-row":t,className:`flex-none rounded-[5px] border px-1.5 text-[11px] leading-[18px] whitespace-nowrap ${YN[t]}`,children:xe.queue.tone[t]}),Qs=t=>t.split("@")[0]??t;function Dx({seat:t,state:s,pod:n,tag:a,near:l,isNew:r,pulse:o,onOpen:i,onMore:c,top:x=!1,name:u,words:m}){const{swallow:p,...h}=ug(c),g=u??ys(t.logicalId,t.session),y=po(t.runtime),k=t.context!==void 0&&s!=="off"&&s!=="waiting"?Math.round(t.context):null,S=m??[x?n:void 0,xe.seatState[s]].filter(Boolean).join(" · "),b=r?"border-ok/55":s==="ask"?"border-attention/55":s==="perm"?"border-approval/55":s==="off"||s==="waiting"?"border-dashed border-input bg-transparent":"border-line",j=e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5",children:[e.jsx(Ie,{state:su[s],pulse:o}),e.jsx("b",{className:`truncate text-[13px] font-semibold ${s==="off"?"text-muted":""}`,children:g}),r?e.jsx("span",{className:"ml-auto",children:e.jsx(zt,{tone:"ok",children:xe.reseat.new})}):a&&y&&e.jsx("span",{className:"ml-auto",children:e.jsx(gs,{tool:y})})]}),e.jsxs("small",{className:`truncate text-[11.5px] ${s==="ask"?"text-attention":"text-muted"}`,children:[S,k!==null&&e.jsxs(e.Fragment,{children:[S?" · ":"",e.jsx("span",{className:`font-mono ${k>=l?"text-attention":""}`,children:`${k} %`})]})]})]}),N=`flex min-w-0 flex-col gap-px rounded-[9px] border bg-surface px-[9px] py-[7px] text-left ${b} ${x?"w-[190px] max-w-full":""}`;return i?e.jsx("button",{type:"button",...h,onClick:()=>{p!=null&&p()||i()},"aria-label":xe.seatLabel(g,xe.seatState[s]),"data-seat":t.logicalId,className:N,children:j}):e.jsx("div",{"data-seat":t.logicalId,className:N,children:j})}function ZN({graph:t,rig:s,status:n,sessions:a,near:l,added:r,onSeat:o,wide:i=!1}){var h;const c=Yh(t.seats,t.links),x=t.seats.find(g=>g.logicalId===c),u=Xh(t.seats.filter(g=>g.logicalId!==c),t.pods),m=(x==null?void 0:x.runtime)??((h=t.seats[0])==null?void 0:h.runtime),p=(g,y=!1)=>{var $;const k=Jd(a,s.name,g.logicalId),S=mo({session:k,node:s.nodes.find(C=>C.logicalId===g.logicalId),graph:g,rigStatus:n}),b=(($=t.pods.find(C=>C.id===g.pod))==null?void 0:$.label)??g.pod,j=o?()=>o(g.logicalId):void 0,N=i&&k?()=>tn({name:"thread",sessionId:k.id}):void 0;return e.jsx(Dx,{seat:g,state:S,pod:b,top:y,near:l,isNew:r.includes(g.logicalId),tag:y||g.runtime!==m,pulse:S==="starting"||n==="starting"&&S==="work",onOpen:N??j,onMore:N?j:void 0},g.logicalId)};return e.jsxs("div",{className:"flex flex-col items-center",children:[x&&e.jsxs(e.Fragment,{children:[p(x,!0),e.jsx("span",{"aria-hidden":"true",className:"h-3 w-[1.5px] bg-input"})]}),e.jsx("div",{className:`grid w-full gap-2 ${u.length>=3?"grid-cols-3":u.length===1&&!x?"grid-cols-1":"grid-cols-2"}`,children:u.map(g=>e.jsxs("div",{className:"flex min-w-0 flex-col gap-1.5 rounded-[10px] border border-dashed border-input p-1.5",children:[e.jsx("small",{className:"px-0.5 font-mono text-[10.5px] text-muted",children:g.label}),g.seats.map(y=>p(y))]},g.id))})]})}function JN({row:t,mine:s}){const n=[[xe.queue.from,`${Qs(t.from)} → ${Qs(t.to)}`],...t.blockedOn?[[xe.queue.blockedOn,t.blockedOn]]:[],[xe.queue.created,[Be(Es(t.createdAt)),t.claimedAt?xe.queue.claimed(Be(Es(t.claimedAt))):""].filter(Boolean).join(" · ")]];return e.jsxs("div",{className:"flex flex-col gap-2 border-b border-line bg-raised/40 px-3 py-2.5 last:border-b-0",children:[e.jsx("span",{className:"font-mono text-[12px] text-muted",children:t.id}),t.summary&&e.jsx("b",{className:"text-[14px] font-semibold",children:t.summary}),e.jsx("dl",{className:"m-0 grid grid-cols-[90px_1fr] gap-x-3 gap-y-1 text-[13px]",children:n.map(([a,l])=>e.jsxs("div",{className:"contents",children:[e.jsx("dt",{className:"text-muted",children:a}),e.jsx("dd",{className:"m-0 [overflow-wrap:anywhere]",children:l})]},a))}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:xe.queue.readOnly}),s&&e.jsx("a",{href:ne({name:"atoi"}),className:ge({size:"sm",className:"self-start"}),children:xe.queue.seeAtoi})]})}function e0({read:t,asks:s,now:n,retry:a}){const[l,r]=f.useState(null),[o,i]=f.useState(!1),c=t==null?void 0:t.data;if(!c)return e.jsx(Ve,{children:t!=null&&t.error?e.jsx(Ds,{retry:a,retryLabel:xe.unavailable.retry,children:xe.queue.unavailable}):e.jsx("p",{role:"status",className:"p-3 text-[13px] text-muted",children:xe.loading})});const x={done:e.jsx("span",{className:"text-ok",children:"✓"}),handed:e.jsx("span",{className:"text-muted",children:"↪"}),stopped:e.jsx("span",{className:"text-approval",children:"✕"})};return e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:xe.queue.title(c.rows.length)}),e.jsxs(Ve,{children:[c.rows.length===0&&e.jsx("p",{className:"p-3 text-[13px] text-muted",children:xe.queue.none}),c.rows.map(u=>{const m=eg(u,s),p=l===u.id;return e.jsxs("div",{className:"contents",children:[e.jsxs("button",{type:"button","aria-expanded":p,onClick:()=>r(p?null:u.id),className:"flex min-h-[46px] w-full items-center gap-[9px] border-b border-line px-3 py-1.5 text-left text-[13px] last:border-b-0",children:[e.jsx(QN,{tone:m}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate",children:u.summary??u.id}),e.jsx("small",{className:"truncate text-[11.5px] text-muted",children:[`${Qs(u.from)} → ${Qs(u.to)}`,u.needsInput?xe.queue.prompt:""].filter(Boolean).join(" · ")})]}),e.jsx("span",{className:"font-mono text-[11px] whitespace-nowrap text-muted",children:yn(Es(u.updatedAt),n)})]}),p&&e.jsx(JN,{row:u,mine:m==="mine"})]},u.id)}),c.closed.length>0&&e.jsxs("button",{type:"button","aria-expanded":o,onClick:()=>i(!o),className:"flex min-h-[46px] w-full items-center gap-[9px] border-t border-line px-3 text-left text-[13px] text-muted first:border-t-0",children:[e.jsx(q,{name:"chevron",className:`size-3.5 transition-transform ${o?"rotate-90":""}`}),e.jsx("span",{children:xe.queue.closed(c.closed.length)})]}),o&&c.closed.map(u=>{const m=tg(u.state);return e.jsxs("div",{className:"flex min-h-[46px] items-center gap-[9px] border-t border-line px-3 py-1.5 text-[13px] text-muted",children:[e.jsx("span",{"aria-hidden":"true",children:x[m]}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate text-fg",children:u.summary??u.id}),e.jsx("small",{className:"truncate text-[11.5px]",children:`${Qs(u.from)} → ${Qs(u.to)} · ${xe.queue.closedTone[m]}`})]}),e.jsx("span",{className:"font-mono text-[11px]",children:Be(Es(u.updatedAt))})]},u.id)})]}),c.truncated&&e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:xe.queue.truncated})]})}function t0({rig:t,sessions:s,asks:n}){var g;const a=s.filter(y=>{var k;return((k=y.rig)==null?void 0:k.name)===t}),l=Vt(a),r=l.find(y=>y.filter==="permission")??l[0],o=r?a.find(y=>y.id===r.sessionId):void 0,i=r||n==null?void 0:n.find(y=>y.from.rig===t&&y.kind!=="update");if(!r&&!i)return null;const c=o?(g=o.rig)!=null&&g.role?ys(o.rig.role):o.name:i?Qs(i.from.seat):"",x=(r==null?void 0:r.filter)==="permission",[u,m,p]=x?xe.waits.permission(c):xe.waits.question(c),h=ne(r?{name:"request",sessionId:r.sessionId,key:r.key}:{name:"atoi"});return e.jsx(Gt,{warn:!x,danger:x,compact:!0,lead:e.jsx(Ie,{state:x?"perm":"ask"}),action:e.jsx("a",{href:h,className:ge({size:"xs"}),children:xe.waits.see}),children:e.jsxs("span",{children:[u,e.jsx("b",{className:"font-semibold",children:m}),p]})})}function s0({rig:t,rigs:s,store:n}){var pt,ft,ut,Y,Re,ke;const a=Rn(s),l=me(n),{pc:r,look:o}=Ut(),i=It(),[c,x]=f.useState(null),[u,m]=f.useState("last"),p=l.fresh,h=o==="offline",[g,y]=f.useState(()=>Date.now());f.useEffect(()=>{const ie=setInterval(()=>y(Date.now()),3e4);return()=>clearInterval(ie)},[]),f.useEffect(()=>{s.follow(),p&&(s.openRig(t),s.readSnapshots(t))},[s,t,p]);const k=Ht(r),S=a.state,b=S==null?void 0:S.rigs.find(ie=>ie.name===t),j=a.graphs[t],N=a.permissions[t],$=a.snapshots[t],C=a.queues[t],M=[...l.sessions.values()],v=((pt=l.device)==null?void 0:pt.contextNear)??70,A=!!((ft=l.device)!=null&&ft.confirm),T=Ao(a.runs,ie=>lg(ie.subject)===t),R=kl(T),P=ie=>{s.act(ie)},_=(ie,Ae)=>{s.reseat(t,ie,Ae?{delegation:Ae}:{})},D=()=>x(null),E=()=>s.openRig(t),z=e.jsx("button",{type:"button","aria-label":xe.more,title:xe.more,"aria-haspopup":"menu",onClick:()=>x({kind:"more"}),className:Tt(),children:e.jsx(q,{name:"more"})}),K=(ie,Ae,Je)=>i?e.jsxs("header",{className:"pane-head flex h-[58px] flex-none items-center gap-2 border-b border-line pr-1.5",children:[e.jsx(is,{fallback:{name:"rigs"},label:xe.back}),e.jsx("h1",{className:"min-w-0 truncate text-[17px] font-semibold",children:t}),ie,Ae&&e.jsx("span",{className:"min-w-0 truncate text-[12.5px] text-muted",children:Ae}),e.jsx("span",{className:"flex-1"}),Je,b&&z]}):e.jsxs("header",{className:"flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-0.5",children:[e.jsx(is,{fallback:{name:"rigs"},label:xe.back}),e.jsx("h1",{className:"min-w-0 truncate text-base font-semibold",children:t}),ie,e.jsx("span",{className:"flex-1"}),b&&z]}),L=`tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pb-[18px] ${i?"pt-[18px]":"pt-3"}`;if(!!S&&(!b||(j==null?void 0:j.error)==="unknown_rig"||(C==null?void 0:C.error)==="unknown_rig"))return e.jsxs(e.Fragment,{children:[K(null),e.jsx("main",{"data-tab-scroll":"",className:L,children:e.jsxs("div",{className:"flex flex-col items-center gap-2 px-4 py-10 text-center",children:[e.jsx("h2",{className:"text-[17px] font-semibold",children:xe.readError.unknown_rig}),e.jsx("a",{href:ne({name:"rigs"}),className:ge({size:"sm",className:"mt-1.5"}),children:xe.back})]})})]});if(!b){const ie=a.error?xe.readError[a.error]:null;return e.jsxs(e.Fragment,{children:[K(null),e.jsxs("main",{"data-tab-scroll":"",className:L,children:[e.jsx(js,{body:xe.offlineBody}),ie?e.jsx(Gt,{warn:!0,role:"alert",lead:e.jsx(q,{name:"warning",className:"mt-px size-4 text-attention"}),children:e.jsx("b",{className:"font-semibold",children:ie})}):e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:xe.loading})]})]})}const ae=hs(b),U=ae==="stopped",O=N!=null&&N.data?au(N.data.seats):null,B=O?xe.level[O]:null,Z=cu(($==null?void 0:$.data)??[])[0],H=Z?tl(Z.createdAt).short:b.snapshot||"",X=(T==null?void 0:T.phase)==="done"&&((ut=T.reseated)!=null&&ut.ok)?T.reseated.added:[],te=b.nodes.filter(ie=>ie.stopped).map(ie=>ys(ie.logicalId,ie.session)),pe=ie=>{var Ae;return(Ae=j==null?void 0:j.data)==null?void 0:Ae.seats.find(Je=>Je.logicalId===ie)},ue=()=>{var ie;return P(u==="fresh"?{kind:"rig.start",rig:t,fresh:((ie=j==null?void 0:j.data)==null?void 0:ie.seats.map(Ae=>Ae.logicalId))??b.nodes.map(Ae=>Ae.logicalId)}:{kind:"rig.start",rig:t})},F=T&&!R?T:void 0,w=p&&!R,I=i?"sm":"md",V=i?"":"!h-[42px] !px-2 !text-[13.5px]",ee=e.jsx("button",{type:"button",disabled:!w,onClick:ue,className:ge({tone:"primary",size:I,className:i?"":"!h-[42px]"}),children:e.jsx(Dt,{icon:"power",children:xe.actions.start})}),Q=e.jsx("button",{type:"button",disabled:!w,onClick:()=>x({kind:"restart"}),className:ge({size:I,className:V}),children:e.jsx(Dt,{icon:"refresh",children:xe.actions.restart})}),J=e.jsx("button",{type:"button",disabled:!w,onClick:()=>x({kind:"stop"}),className:ge({tone:"danger",size:I,className:V}),children:e.jsx(Dt,{icon:"power",children:xe.actions.stop})}),fe=e.jsx("button",{type:"button",disabled:!w,onClick:()=>x({kind:"reseat"}),className:ge({size:I,className:V}),children:e.jsx(Dt,{icon:"plus",children:xe.actions.seats})}),be=R?e.jsx(Ja,{run:T,rigs:s,pc:k,bar:!i}):ae==="starting"?e.jsx(Zn,{bar:!i,children:xe.startingSeats(t,b.running,b.seats)}):null,tt=be??e.jsx("div",{className:`bleed grid flex-none gap-2 border-t border-line bg-bg px-3.5 pt-2.5 pb-3 ${U?"grid-cols-1":"grid-cols-3"}`,children:U?ee:e.jsxs(e.Fragment,{children:[fe,Q,J]})}),yt=p&&e.jsx(t0,{rig:t,sessions:M,asks:l.asks}),Ze=ae==="partial"&&te.length>0&&e.jsxs(Gt,{warn:!0,lead:e.jsx(q,{name:"warning",className:"mt-px size-4 text-attention"}),children:[e.jsx("span",{children:xe.partial(te,b.nodes.length-te.length)}),e.jsx("button",{type:"button",disabled:!w,onClick:()=>x({kind:"restart"}),className:ge({size:"sm",className:"self-start"}),children:xe.actions.restartRig})]}),Le=e.jsxs(e.Fragment,{children:[e.jsx(Ft,{aside:U?xe.topologyStopped:j!=null&&j.data?xe.topologyHint:void 0,children:xe.topology}),j!=null&&j.data?e.jsx(ZN,{graph:j.data,rig:b,status:ae,sessions:M,near:v,added:X,onSeat:ie=>x({kind:"seat",id:ie}),wide:i}):e.jsx(Ve,{children:j!=null&&j.error?e.jsx(Ds,{retry:E,retryLabel:xe.unavailable.retry,children:xe.readError[j.error]}):e.jsx("p",{role:"status",className:"p-3 text-[13px] text-muted",children:xe.loading})})]}),de=U&&b.snapshot&&e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:xe.resume}),e.jsxs("div",{className:"flex flex-col gap-1.5",children:[e.jsx(yr,{pressed:u==="last",disabled:!p,onClick:()=>m("last"),title:xe.resumeLast(Z?tl(Z.createdAt).long:b.snapshot),sub:xe.resumeLastBody}),e.jsx(yr,{pressed:u==="fresh",disabled:!p,onClick:()=>m("fresh"),title:xe.fresh,sub:xe.freshBody})]})]}),he=e.jsx(e0,{read:C,asks:l.asks,now:g,retry:E}),$e=i?e.jsxs("div",{className:"grid grid-cols-[minmax(0,1.15fr)_minmax(0,1fr)] content-start gap-[18px]",children:[e.jsxs("div",{className:"flex min-w-0 flex-col gap-3.5",children:[yt,Ze,Le,!U&&ae!=="starting"&&e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:xe.seatsByRole}),e.jsx(Ve,{children:e.jsx("div",{className:"flex flex-col gap-2.5 px-3 py-1",children:e.jsx(Lx,{rig:b,confirm:A,live:w,onReseat:_,context:Object.fromEntries((((Y=j==null?void 0:j.data)==null?void 0:Y.seats)??[]).map(ie=>[ie.logicalId,ie.context]))},b.nodes.length)})})]}),de]}),e.jsxs("div",{className:"flex min-w-0 flex-col gap-3.5",children:[he,e.jsx(Ft,{children:xe.actions.snapshots}),e.jsx(Ox,{read:$,kindOnly:!0,retry:()=>s.readSnapshots(t)}),e.jsx("button",{type:"button",disabled:!w,onClick:()=>P({kind:"rig.snapshot",rig:t}),className:ge({size:"sm",className:"max-w-full self-start !h-auto min-h-9 py-1.5 !whitespace-normal text-left [&>svg]:flex-none"}),children:e.jsx(Dt,{icon:"camera",children:xe.snapshots.take})})]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-3 gap-2",children:[e.jsx(Pl,{label:xe.tiles.seats,value:`${b.running}/${b.seats}`}),e.jsx(Pl,{label:xe.tiles.permissions,value:B??"—",onOpen:()=>x({kind:"permissions"})}),e.jsx(Pl,{label:xe.tiles.snapshot,value:H||"—",onOpen:()=>x({kind:"snapshots"})})]}),yt,Ze,Le,he,de]}),Oe=(c==null?void 0:c.kind)==="seat"||(c==null?void 0:c.kind)==="settings"?pe(c.id):void 0,rt=Oe?b.nodes.find(ie=>ie.logicalId===Oe.logicalId):void 0,Ge=[xe.seats(b.running,b.seats),B??"",H?xe.snapshot(H):""].filter(Boolean).join(" · ");return e.jsxs(e.Fragment,{children:[K(e.jsx(vn,{tone:iu[ae],children:xe.status[ae]}),Ge,!be&&(U?ee:e.jsxs(e.Fragment,{children:[Q,J]}))),e.jsxs("main",{"data-tab-scroll":"",className:L,children:[e.jsx(js,{body:xe.offlineBody}),i&&be,F&&e.jsx(Ja,{run:F,rigs:s,pc:k}),e.jsx("div",{className:`flex flex-col gap-3 ${h?"opacity-50":""}`,children:$e})]}),!i&&tt,(c==null?void 0:c.kind)==="more"&&e.jsx(BN,{rig:t,live:p,running:R,snapshots:$!=null&&$.data?$.data.length:null,level:B,onClose:D,onSnapshot:()=>{D(),P({kind:"rig.snapshot",rig:t})},onSnapshots:()=>x({kind:"snapshots"}),onPermissions:()=>x({kind:"permissions"}),onRefresh:()=>{D(),s.retry(),s.openRig(t),s.readSnapshots(t)}}),((c==null?void 0:c.kind)==="stop"||(c==null?void 0:c.kind)==="restart")&&e.jsx(HN,{rig:b,pc:k,verb:c.kind,confirm:A,live:w,onAct:P,onClose:D}),(c==null?void 0:c.kind)==="reseat"&&e.jsx(UN,{rig:b,pc:k,confirm:A,live:w,onReseat:_,onClose:D}),(c==null?void 0:c.kind)==="permissions"&&e.jsx(WN,{rig:b,read:N,level:O,confirm:A,live:w,onAct:P,onClose:D}),(c==null?void 0:c.kind)==="snapshots"&&e.jsx(XN,{rig:t,read:$,live:p,running:R,onSnapshot:()=>P({kind:"rig.snapshot",rig:t}),onRetry:()=>s.readSnapshots(t),onClose:D}),(c==null?void 0:c.kind)==="seat"&&Oe&&(j==null?void 0:j.data)&&e.jsx(VN,{rig:t,seat:Oe,graph:j.data,node:rt,session:Jd(M,t,Oe.logicalId),status:ae,near:v,onSettings:()=>x({kind:"settings",id:Oe.logicalId}),onClose:D}),(c==null?void 0:c.kind)==="settings"&&Oe&&e.jsx(GN,{rig:t,seat:Oe,node:rt,selection:(ke=(Re=N==null?void 0:N.data)==null?void 0:Re.seats.find(ie=>ie.logicalId===Oe.logicalId))==null?void 0:ke.selection,confirm:A,live:w,onAct:P,onClose:D})]})}const xs=d.rigs,ve=xs.max,n0={sent:"idle",taken:"work",asking:"ask",proposed:"rig",running:"work",done:"done",closed:"done"},a0={sent:"plain",taken:"work",asking:"ask",proposed:"rig",running:"work",done:"ok",closed:"plain"},l0=t=>{var s;return((s=t.trail.at(-1))==null?void 0:s.at)??t.sentAt},Fx=t=>{const s=sl(t);if(!s)return null;for(let n=t.trail.length-1;n>=0;n--)if(t.trail[n].text===s)return t.trail[n].at;return null};function r0(t){var n;const s=tl(l0(t)).short;return t.state==="asking"?`${ve.asks} · ${s}`:t.state==="running"?[ve.state.running,((n=t.current)==null?void 0:n.seat.split("@")[0])??"",ve.since(s)].filter(Boolean).join(" · "):`${ve.state[t.state]} · ${s}`}const sl=t=>{var s,n;return((s=t.question)==null?void 0:s.text)??((n=t.proposal)==null?void 0:n.text)??null};function o0({run:t,pc:s,onAgain:n,onClose:a}){var i,c;const l={onClose:a,closeLabel:xs.done.close},r=e.jsx("button",{type:"button",onClick:n,className:ge({size:"xs",className:"mt-1.5"}),children:ve.sendAgain}),o=t.phase==="uncertain"?"uncertain":t.phase==="done"?(i=t.sent)==null?void 0:i.error:void 0;return o?o==="uncertain"?e.jsx(Se,{mark:"ask",title:ve.errors.uncertain.title,sub:ve.errors.uncertain.body,...l,children:r}):o==="refused"?e.jsx(Se,{mark:"bad",title:ve.errors.refused.title,...(c=t.sent)!=null&&c.message?{sub:e.jsx("span",{className:"font-mono",children:t.sent.message})}:{},...l}):o==="openrig_stopped"?e.jsx(Se,{mark:"bad",title:ve.errors.openrig_stopped.title(s),sub:ve.errors.openrig_stopped.body,...l,children:r}):o==="no_operator"||o==="unreachable"?e.jsx(Se,{mark:"bad",title:ve.errors[o].title,sub:ve.errors[o].body,...l,children:r}):e.jsx(Se,{mark:"bad",title:ve.unsent,sub:ve.keeps,...l,children:r}):e.jsx(Se,{mark:"bad",title:ve.unsent,sub:ve.keeps,...l,children:r})}const i0=t=>{var s;return t.phase==="done"&&!!((s=t.sent)!=null&&s.ok)};function zx({runs:t,rigs:s,pc:n,bubble:a}){return e.jsx(e.Fragment,{children:t.filter(l=>!i0(l)).map(l=>{const r=l.subject;if(r.kind!=="goal"&&r.kind!=="reply")return null;if(kl(l))return e.jsxs("div",{role:"status","aria-label":ve.sending,className:"max-w-[85%] self-end rounded-[14px] rounded-br-[5px] bg-secondary px-3 py-2 text-[14px] leading-5 opacity-60",children:[r.text," ",e.jsx(En,{className:"ml-1 align-[-1px] text-muted"})]},l.id);const o=()=>{s.dismiss(l.id),r.kind==="goal"?s.sendGoal(r.text,r.goalId):s.replyGoal(r.goalId,r.text,r.replyId)};return e.jsx(o0,{run:l,pc:n,onAgain:o,onClose:()=>s.dismiss(l.id)},l.id)})})}function c0(t){var s;switch(t.kind){case"sent":return ve.trail.sent;case"taken":return ve.trail.taken;case"note":return ve.trail.note(t.text??"");case"handed":return ve.trail.handed(((s=t.to)==null?void 0:s.split("@")[0])??"");case"closed":return ve.trail.closed}}function Px({goal:t,runs:s,rigs:n,pc:a,compact:l=!1}){const r=sl(t),o=Fx(t),i=t.question??(t.proposal&&!t.proposal.answer?t.proposal:null),c=s.filter(x=>x.subject.kind==="reply"&&x.subject.goalId===t.goalId);return e.jsxs("div",{className:"flex flex-col gap-3",children:[e.jsx("div",{className:"max-w-[85%] self-end rounded-[14px] rounded-br-[5px] bg-secondary px-3 py-2 text-[14px] leading-5 [overflow-wrap:anywhere]",children:t.text}),!l&&t.trail.some(x=>x.kind!=="sent")&&e.jsx("ul",{className:"m-0 flex list-none flex-col gap-1 p-0 text-[12.5px] text-muted",children:t.trail.filter(x=>x.kind!=="sent").map((x,u)=>e.jsxs("li",{className:"flex gap-2",children:[e.jsx("span",{className:"font-mono text-[11.5px]",children:Be(Es(x.at))}),e.jsx("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:c0(x)})]},`${x.at}-${u}`))}),r&&e.jsxs("div",{className:"flex flex-col gap-1 text-[13.5px] leading-[19px]",children:[e.jsxs("span",{className:"flex items-center gap-1.5 text-[12px] text-muted",children:[e.jsx(Ie,{state:"idle"}),o?`${xs.kernelView.max} · ${Be(Es(o))}`:xs.kernelView.max]}),e.jsx("span",{className:"[overflow-wrap:anywhere]",children:r})]}),i&&e.jsxs("div",{className:"flex flex-col gap-2 rounded-[10px] border border-attention/45 bg-surface px-3 py-2.5",children:[e.jsxs("span",{className:"flex items-center gap-2",children:[e.jsx(Ie,{state:"ask"}),e.jsx("b",{className:"text-[14px] font-semibold",children:t.question?ve.question:ve.proposal}),o&&e.jsx("span",{className:"ml-auto font-mono text-[11.5px] text-muted",children:Be(Es(o))})]}),!l&&e.jsx("p",{className:"text-[13px] text-muted",children:t.question?ve.questionBody:ve.proposalBody}),e.jsx("a",{href:ne({name:"atoi"}),className:ge({size:"sm",className:"self-start"}),children:ve.seeAtoi})]}),e.jsx(zx,{runs:c,rigs:n,pc:a,bubble:!0})]})}function Bx({goalId:t,rigs:s,live:n}){const[a,l]=f.useState("");return e.jsx(sd,{label:ve.replyPlaceholder,sendLabel:ve.send,placeholder:ve.replyPlaceholder,offlinePlaceholder:ve.offlinePlaceholder,offline:!n,value:a,onChange:l,onSend:()=>{const r=a.trim();r&&(l(""),s.replyGoal(t,r).then(o=>{o.phase==="unsent"&&l(i=>i||r)}))}})}function d0({goalId:t,rigs:s,store:n}){var C,M,v,A;const a=Rn(s),l=me(n),{pc:r,look:o}=Ut(),i=It(),c=l.fresh,x=o==="offline",u=Ht(r),[m,p]=f.useState("");f.useEffect(()=>{s.follow(),s.followGoals()},[s,c]);const h=((M=(C=a.goals)==null?void 0:C.data)==null?void 0:M.goals)??[],g=t?h.find(T=>T.goalId===t):void 0,y=`tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pb-[18px] ${i?"pt-[18px]":"pt-3"}`,k=i?"pane-head flex h-[58px] flex-none items-center gap-2 border-b border-line pr-2":"flex h-14 flex-none items-center gap-2 border-b border-line pr-2 pl-0.5",S="bleed flex-none border-t border-line bg-bg px-3.5 pt-2.5 pb-3",b=(()=>{var T,R;return(T=a.goals)!=null&&T.error&&!a.goals.data?e.jsx(Ve,{children:e.jsx(Ds,{retry:()=>s.followGoals(),retryLabel:xs.unavailable.retry,children:ve.goalsUnavailable})}):(R=a.goals)!=null&&R.data?null:e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:xs.loading})})();if(t)return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:k,children:[e.jsx(is,{fallback:{name:"max"},label:xs.backMax}),e.jsx("h1",{className:"min-w-0 truncate text-base font-semibold",children:(g==null?void 0:g.text)??ve.title}),g&&e.jsx("span",{className:"flex-none",children:e.jsx(zt,{tone:a0[g.state],children:ve.statePill[g.state]})})]}),e.jsxs("main",{"data-tab-scroll":"",className:`${y} justify-end`,children:[e.jsx(js,{body:xs.offlineBody}),g?e.jsx("div",{className:x?"opacity-50":"",children:e.jsx(Px,{goal:g,runs:a.runs,rigs:s,pc:u})}):b??e.jsx("p",{role:"alert",className:"text-[13px] text-attention",children:ve.goalsUnavailable})]}),g&&e.jsx("div",{className:S,children:e.jsx(Bx,{goalId:g.goalId,rigs:s,live:c})})]});const j=a.runs.filter(T=>T.subject.kind==="goal"),N=()=>{const T=m.trim();T&&(p(""),s.sendGoal(T).then(R=>{R.phase==="unsent"&&p(P=>P||T)}))},$=()=>{var T;(T=document.querySelector("[data-goal-field] textarea"))==null||T.focus()};return e.jsxs(e.Fragment,{children:[e.jsxs("header",{className:k,children:[e.jsx(is,{fallback:{name:"kernel"},label:xs.backKernel}),e.jsx("h1",{className:"flex-none text-base font-semibold",children:ve.title}),e.jsx("span",{className:"min-w-0 truncate text-[12.5px] text-muted",children:ve.role}),e.jsx("span",{className:"flex-1"}),e.jsx("button",{type:"button",disabled:!c,onClick:$,className:ge({tone:"primary",size:"sm"}),children:e.jsx(Dt,{icon:"plus",children:ve.newGoal})})]}),e.jsxs("main",{"data-tab-scroll":"",className:y,children:[e.jsx(js,{body:xs.offlineBody}),e.jsxs("div",{className:`flex flex-col gap-3 ${x?"opacity-50":""}`,children:[b??(h.length===0?e.jsx(Ve,{children:e.jsx(Ds,{children:ve.none})}):e.jsx(Ve,{label:ve.goalsLabel,children:h.map(T=>e.jsxs("a",{href:ne({name:"max",goalId:T.goalId}),className:"flex items-start gap-2.5 border-b border-line px-3 py-2.5 last:border-b-0",children:[e.jsx("span",{className:"mt-1.5",children:e.jsx(Ie,{state:n0[T.state],pulse:T.state==="running"})}),e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col gap-0.5",children:[e.jsx("span",{className:"line-clamp-2 text-[14px] leading-5 [overflow-wrap:anywhere]",children:T.text}),e.jsx("small",{className:`text-[12px] ${T.state==="asking"?"text-attention":"text-muted"}`,children:r0(T)})]})]},T.goalId))})),((A=(v=a.goals)==null?void 0:v.data)==null?void 0:A.partial)&&e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:ve.partial}),e.jsx(zx,{runs:j,rigs:s,pc:u,bubble:!1}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:ve.atoiNote})]})]}),e.jsx("div",{"data-goal-field":"",className:S,children:e.jsx(sd,{label:ve.goalPlaceholder,sendLabel:ve.send,placeholder:ve.goalPlaceholder,offlinePlaceholder:ve.offlinePlaceholder,offline:!c,value:m,onChange:p,onSend:N})})]})}const _e=d.rigs,kt=_e.kernelView,u0=t=>/^qitem-\d{14}-[0-9a-f]{8,}$/.test(t)?`…${t.slice(-8)}`:t;function x0({graph:t,status:s,near:n}){var c;const a=t.seats,l=a.find(x=>ru(x.logicalId)),r=a.filter(x=>x!==l),o=(l==null?void 0:l.runtime)??((c=a[0])==null?void 0:c.runtime),i=(x,u=!1)=>{var g;const m=mo({graph:x,rigStatus:s}),p=((g=t.pods.find(y=>y.id===x.pod))==null?void 0:g.label)??x.pod,h=[u?p:"",m==="idle"?"":_e.seatState[m]].filter(Boolean).join(" · ");return e.jsx(Dx,{seat:x,state:m,pod:p,top:u,near:n,isNew:!1,name:ou({logicalId:x.logicalId,session:x.session??""}),words:h,tag:u||x.runtime!==o,pulse:m==="starting"},x.logicalId)};return e.jsxs("div",{className:"flex flex-col items-center",children:[l&&e.jsxs(e.Fragment,{children:[i(l,!0),e.jsx("span",{"aria-hidden":"true",className:"h-3 w-[1.5px] bg-input"})]}),e.jsx("div",{className:"grid w-full max-w-[420px] grid-cols-2 gap-2",children:r.map(x=>i(x))})]})}function m0({rigs:t}){const s=Rn(t).routing,n=s!=null&&s.data?[...s.data].reverse():null,a=l=>{const r=sg(l);return r.verb==="handed"?kt.change.handed(r.to):r.verb==="blocked"?kt.change.blocked(u0(r.on)):r.verb==="other"?r.text:kt.change[r.verb]};return e.jsxs(e.Fragment,{children:[e.jsx(Ft,{aside:kt.allRigs,children:kt.routing}),e.jsx(Ve,{children:n?n.length===0?e.jsx(Ds,{children:kt.noRouting}):n.map((l,r)=>e.jsxs("div",{className:"grid grid-cols-[44px_1fr] gap-x-2 border-b border-line px-3 py-2 text-[13px] leading-[18px] last:border-b-0",children:[e.jsx("span",{className:"font-mono text-[11.5px] text-muted",children:Be(Es(l.at))}),e.jsxs("span",{className:"min-w-0 [overflow-wrap:anywhere]",children:[e.jsx("b",{className:"font-semibold",children:kt.actor(l.seat.split("@")[0]??l.seat)})," ",a(l.change)]}),e.jsx("small",{className:"col-start-2 truncate text-[11.5px] text-muted",children:[l.rig,l.summary??""].filter(Boolean).join(" · ")})]},`${l.qitem}-${l.at}-${r}`)):s!=null&&s.error?e.jsx(Ds,{retry:()=>t.readRouting(),retryLabel:_e.unavailable.retry,children:_e.readError[s.error]}):e.jsx("p",{role:"status",className:"p-3 text-[13px] text-muted",children:_e.loading})})]})}function p0({rigs:t,store:s}){var I,V,ee,Q;const n=Rn(t),a=me(s),{pc:l,look:r}=Ut(),o=It(),[i]=Eo(),[c,x]=f.useState(null),u=a.fresh,m=r==="offline";f.useEffect(()=>{t.follow(),t.followGoals(),u&&(t.openRig(Pn),t.readRouting())},[t,u]);const p=n.state?br(n.state).filter(J=>hs(J)!=="stopped").map(J=>J.name).join(" "):"";f.useEffect(()=>{if(u&&p)for(const J of p.split(" "))t.readPermissions(J)},[t,u,p]);const h=Ht(l),g=n.state,y=`tab-main flex min-h-0 flex-1 flex-col gap-3 overflow-y-auto overscroll-contain pb-[18px] ${o?"pt-[18px]":"pt-3"}`,k=J=>e.jsxs("header",{className:o?"pane-head flex h-[58px] flex-none items-center gap-2 border-b border-line pr-1.5":"flex h-14 flex-none items-center gap-2 border-b border-line pr-1.5 pl-0.5",children:[e.jsx(is,{fallback:{name:"rigs"},label:_e.back}),e.jsx("h1",{className:`min-w-0 truncate font-semibold ${o?"text-[17px]":"text-base"}`,children:_e.kernel}),J,e.jsx("span",{className:"flex-1"}),J&&e.jsx("button",{type:"button","aria-label":_e.more,title:_e.more,"aria-haspopup":"menu",onClick:()=>x("menu"),className:Tt(),children:e.jsx(q,{name:"more"})})]}),S=()=>{t.retry(),t.openRig(Pn),t.readRouting()};if(!g){const J=n.error?_e.readError[n.error]:null;return e.jsxs(e.Fragment,{children:[k(null),e.jsxs("main",{"data-tab-scroll":"",className:y,children:[e.jsx(js,{body:_e.offlineBody}),J?e.jsx(Gt,{warn:!0,role:"alert",lead:e.jsx(q,{name:"warning",className:"mt-px size-4 text-attention"}),children:e.jsx("b",{className:"font-semibold",children:J})}):e.jsx("p",{role:"status",className:"text-[13px] text-muted",children:_e.loading})]})]})}const b=Zd(g),j=g.kernel.state,N=b?hs(b):"stopped",$=n.graphs[Pn],C=((I=a.device)==null?void 0:I.contextNear)??70,M=!!((V=a.device)!=null&&V.confirm),v=Ao(n.runs,J=>J.subject.kind==="act"&&/^(kernel|daemon)\./.test(J.subject.action.kind)),A=kl(v),T=u&&!A,R=J=>{t.act(J)},P=[...a.sessions.values()],_=br(g),D=g.daemon.state==="running",E=j==="ready"||j==="starting",z=((Q=(ee=n.goals)==null?void 0:ee.data)==null?void 0:Q.goals)??[],K=j==="stopped"?e.jsxs(Gt,{lead:e.jsx("span",{className:"mt-[5px]",children:e.jsx(Ie,{state:"off"})}),children:[e.jsx("span",{children:e.jsx("b",{className:"font-semibold",children:kt.stoppedTitle})}),e.jsx("span",{className:"text-muted",children:kt.stoppedBody}),e.jsx("button",{type:"button",disabled:!T||!D,onClick:()=>R({kind:"kernel.start"}),className:ge({tone:"primary",size:"sm",className:"self-start"}),children:e.jsx(Dt,{icon:"power",children:kt.startKernel})})]}):j==="skipped"?e.jsxs(Gt,{lead:e.jsx("span",{className:"mt-[5px]",children:e.jsx(Ie,{state:"off"})}),children:[e.jsx("span",{children:e.jsx("b",{className:"font-semibold",children:kt.skippedTitle})}),e.jsx("span",{className:"text-muted",children:kt.skippedBody})]}):null,L=z.find(J=>sl(J)!==null),W=L?Fx(L):null,ae=z.find(J=>J.state!=="done"&&J.state!=="closed"),U=e.jsx("a",{href:ne({name:"max"}),className:ge({tone:"primary",className:"w-full"}),children:kt.talk}),O=o&&ae?e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:`${kt.max} · ${ae.text}`}),e.jsx(Ve,{children:e.jsxs("div",{className:"flex flex-col gap-2.5 p-3",children:[e.jsx(Px,{goal:ae,runs:n.runs,rigs:t,pc:h,compact:!0}),e.jsx(Bx,{goalId:ae.goalId,rigs:t,live:u})]})})]}):e.jsx(Ve,{children:e.jsxs("div",{className:"flex flex-col gap-2 p-3",children:[L&&e.jsx("span",{className:"text-[12px] text-muted",children:kt.lastMessage(W?Be(Es(W)):null)}),L&&e.jsx("span",{className:"text-[13.5px] leading-[19px] [overflow-wrap:anywhere]",children:sl(L)}),U]})}),B=J=>{var tt;const fe=(tt=n.permissions[J])==null?void 0:tt.data,be=fe?au(fe.seats):null;return be?_e.level[be]:""},Z=_.length>0&&e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:kt.driven}),e.jsx(Ve,{children:_.map(J=>{const fe=hs(J),be=tu(J,eu(J.name,P,a.asks));return e.jsxs("a",{href:ne({name:"rig",rig:J.name}),className:"flex min-h-[46px] items-center gap-2.5 border-b border-line px-3 py-1.5 text-[13.5px] last:border-b-0",children:[e.jsx(Ie,{state:be}),e.jsx("span",{className:`min-w-0 flex-1 truncate ${fe==="stopped"?"text-muted":""}`,children:J.name}),e.jsx("span",{className:"text-[12px] text-muted",children:fe==="stopped"?_e.seatState.off:[_e.seatCount(J.seats),B(J.name)].filter(Boolean).join(" · ")}),e.jsx(q,{name:"chevron",className:"size-4 text-muted"})]},J.id)})})]}),H=(J,fe)=>e.jsxs("div",{className:"grid grid-cols-2 gap-2",children:[e.jsx("button",{type:"button",disabled:!T,onClick:J,className:ge({}),children:e.jsx(Dt,{icon:"refresh",children:_e.actions.restart})}),e.jsx("button",{type:"button",disabled:!T,onClick:fe,className:ge({tone:"danger"}),children:e.jsx(Dt,{icon:"power",children:_e.actions.stop})})]}),X=E&&e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:_e.kernel}),e.jsx(Ve,{children:e.jsxs("div",{className:"flex flex-col gap-2 p-3",children:[e.jsx("span",{className:"text-[12.5px] leading-[18px] text-muted",children:_e.confirm.kernelNote}),H(()=>x("kernel.restart"),()=>x("kernel.stop"))]})})]}),te=e.jsxs(e.Fragment,{children:[e.jsx(Ft,{children:_e.daemon}),e.jsxs(Ve,{children:[e.jsx(To,{state:g}),e.jsx(Ix,{disabled:!u,next:!0}),D&&e.jsx("div",{className:"px-3 pt-2.5 pb-3",children:H(()=>x("daemon.restart"),()=>x("daemon.stop"))})]}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:kt.daemonNote})]}),pe=_.flatMap(J=>og(J)).length,ue=_.filter(J=>hs(J)!=="stopped").length,F=[_e.confirm.daemonStops(ue),pe?_e.confirm.working(pe):""].filter(Boolean).join(" "),w=()=>x(null);return e.jsxs(e.Fragment,{children:[k(e.jsx(vn,{tone:_x[j],children:_e.kernelState[j]})),e.jsxs("main",{"data-tab-scroll":"",className:y,children:[e.jsx(js,{body:_e.offlineBody}),v&&e.jsx(Ja,{run:v,rigs:t,pc:h}),e.jsxs("div",{className:`flex flex-col gap-3 ${o?"max-w-[720px]":""} ${m?"opacity-50":""}`,children:[K,e.jsx("p",{className:"text-[12.5px] leading-[18px] text-muted",children:kt.role}),E&&($!=null&&$.data?e.jsx(x0,{graph:$.data,status:N,near:C}):e.jsx(Ve,{children:e.jsx("p",{role:$!=null&&$.error?"alert":"status",className:"p-3 text-[13px] text-muted",children:$!=null&&$.error?_e.readError[$.error]:_e.loading})})),E&&O,Z,e.jsx(m0,{rigs:t}),X,te]})]}),c==="menu"&&e.jsx(qN,{live:u,up:E&&!A,onClose:w,onRefresh:()=>{w(),S()},onRestart:()=>x("kernel.restart"),onStop:()=>x("kernel.stop")}),c==="kernel.restart"&&e.jsx(Ma,{title:_e.confirm.restartKernel(h),conseq:{title:_e.confirm.kernelNote},verb:_e.actions.restart,confirm:M,live:T,onConfirm:()=>R({kind:"kernel.restart"}),onClose:w}),c==="kernel.stop"&&e.jsx(Ma,{title:_e.confirm.stopKernel(h),conseq:{title:_e.confirm.kernelNote},verb:_e.actions.stop,confirm:M,live:T,onConfirm:()=>R({kind:"kernel.stop"}),onClose:w}),c==="daemon.restart"&&e.jsx(Ma,{title:_e.confirm.restartDaemon(h),conseq:{title:F},verb:_e.actions.restart,confirm:M,live:T,onConfirm:()=>R(Tx("restart",i)),onClose:w}),c==="daemon.stop"&&e.jsx(Ma,{title:_e.confirm.stopDaemon(h),conseq:{title:F},verb:_e.actions.stop,confirm:M,live:T,onConfirm:()=>R({kind:"daemon.stop"}),onClose:w})]})}const ce=d.launch,f0=["claude","codex","cursor","omp"],h0=["always-ask","write","yolo"],g0=2e4,Vs={project:`${Cs}launch.project`,prefs:`${Cs}launch.prefs`,draft:`${Cs}launch.draft`},Pr=(t,s)=>{try{return(t==null?void 0:t.getItem(s))??null}catch{return null}},Ea=(t,s,n)=>{try{n===null?t==null||t.removeItem(s):t==null||t.setItem(s,n)}catch{}};function gc(t){try{const s=JSON.parse(Pr(t,Vs.prefs)??"{}");return s&&typeof s=="object"?s:{}}catch{return{}}}const bc=t=>t.replace(/\/+$/,"").split("/").pop()||t,qx=t=>t.machine==="local",jc=t=>qx(t)&&t.exists!==!1;function yc({store:t,storage:s}){var Je,xt,Yt,ze,ht,Nt,we;const n=me(t),a=Qe(s),l=Ht(Ut().pc??((Je=n.daemon)==null?void 0:Je.name)??null),r=n.projects,[o,i]=f.useState(()=>Pr(a,Vs.project)),c=r.find(G=>G.id===o)??r[0],x=gc(a),u=c?x[c.id]:void 0,[m,p]=f.useState((u==null?void 0:u.tool)??"claude"),[h,g]=f.useState({model:(u==null?void 0:u.model)??null,effort:(u==null?void 0:u.effort)??null}),[y,k]=f.useState("always-ask"),[S,b]=f.useState(null),[j,N]=f.useState(()=>Pr(a,Vs.draft)??""),[$,C]=f.useState(null),[M,v]=f.useState(!1),[A,T]=f.useState(!1),[R,P]=f.useState(null),[_,D]=f.useState(null),E=f.useId(),[z,K]=f.useState(!1),[L,W]=f.useState(""),ae=f.useId(),U=f.useRef(null),O=f.useRef(!1);f.useEffect(()=>{var G;z&&O.current&&((G=U.current)==null||G.focus())},[z]);const B=c==null?void 0:c.id;f.useEffect(()=>{B&&n.fresh&&t.requestProjectFolders(B)},[B,n.fresh,t]),f.useEffect(()=>{var G;n.fresh&&((G=n.daemon)!=null&&G.models)&&t.requestModels(m)},[m,n.fresh,(xt=n.daemon)==null?void 0:xt.models,t]);const Z=B?n.projectFolders[B]:void 0,H=Array.isArray(Z)?Z:[],X=H.find(jc),te=(S??(X?[X.path]:[])).filter(G=>H.some(Ne=>Ne.path===G&&jc(Ne))),pe=Uo.includes(m),ue=((Yt=n.models[m])==null?void 0:Yt.models)??[],F=G=>{G(),P(null),T(!1)},w=G=>F(()=>{i(G.id),Ea(a,Vs.project,G.id),b(null);const Ne=x[G.id];p((Ne==null?void 0:Ne.tool)??"claude"),g({model:(Ne==null?void 0:Ne.model)??null,effort:(Ne==null?void 0:Ne.effort)??null}),C(null)}),I=G=>F(()=>{p(G),g({model:null,effort:null}),!Uo.includes(G)&&te.length>1&&b(te.slice(0,1))}),V=G=>F(()=>{if(!pe){b([G]),C(null);return}const oe=te.includes(G)?te.filter(qe=>qe!==G):[...te,G];b(oe.length?oe:te)}),ee=G=>{N(G),Ea(a,Vs.draft,G),P(null),T(!1)},Q=_?n.ops[_]:void 0,[J,fe]=f.useState(0);f.useEffect(()=>{if(!_)return;const G=setTimeout(()=>{const Ne=t.getState().ops[_];Ne&&ps(Ne.phase)&&(v(!1),P({kind:"timeout",op:_}))},g0);return()=>clearTimeout(G)},[_,J,t]),f.useEffect(()=>{if(!_||!Q||ps(Q.phase))return;if(v(!1),D(null),Q.phase==="applied"){Ea(a,Vs.draft,null),c&&Ea(a,Vs.prefs,JSON.stringify({...gc(a),[c.id]:{tool:m,model:h.model,effort:h.effort}})),Q.id?(Oj(Q.id,(c==null?void 0:c.name)??"",s),fs({name:"thread",sessionId:Q.id})):fs({name:"sessions"});return}if(Q.phase==="failed"){P({kind:"failed"});return}const G=Q.reason??"other";G==="stale"&&B&&t.requestProjectFolders(B),P({kind:"refused",reason:G})},[_,Q==null?void 0:Q.phase]);const be=async()=>{if(!c)return;const G={project:c.id,tool:m,folders:te,prompt:j.trim(),...de?{name:de}:{},...h.model?{model:h.model}:{},...h.effort?{effort:h.effort}:{},...m==="omp"&&y!=="always-ask"?{approval:y}:{}};v(!0),P(null),T(!1);const Ne=await t.launchSession(G);if(Ne.status==="sent"){D(Ne.op),fe(oe=>oe+1);return}v(!1),Ne.status==="cancelled"?T(!0):Ne.status==="noAnswer"?P({kind:"timeout",op:null}):Ne.status==="failed"?P({kind:"refused",reason:"other"}):P({kind:"refused",reason:Ne.reason})},tt=G=>{if(G.kind==="timeout"&&G.op){if(t.launchAgain(G.op)){D(G.op),fe(oe=>oe+1),v(!0),P(null);return}const Ne=t.getState().ops[G.op];if(Ne&&ps(Ne.phase)){P({...G});return}}be()},yt=G=>G.kind==="timeout"&&G.op!==null&&!!n.ops[G.op]&&ps(n.ops[G.op].phase)&&!t.canLaunchAgain(G.op),Ze=[...n.sessions.values()].filter(G=>G.state!=="exited"),Le=z?L:"",de=Cm(Le),he=Mm(Ho(Ze),Le)!==void 0,$e=he?Em(Ze,Le):void 0,Oe=he?$e?$e.name.toLowerCase()===de.toLowerCase()&&$e.project?ce.nameTaken(de,$e.project):ce.nameTakenBy(de,$e.name):ce.nameReserved:null,rt=d.tools[m],Ge=!n.fresh,pt=Ge?{label:ce.missing.machine}:(ze=n.daemon)!=null&&ze.launch?(ht=n.device)!=null&&ht.confirm?!c||te.length===0?{label:ce.chooseProject}:he?{label:ce.missing.name}:j.trim()===""?{label:ce.missing.prompt}:null:{label:ce.missing.setup,body:e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ce.setupBody}),e.jsxs("a",{href:"#/connection/link",className:Fe({size:"sm",className:"self-start"}),children:[e.jsx(q,{name:"gear",className:"size-4"}),ce.openSettings]})]})}:{label:ce.missing.pcOld(l),body:e.jsx("span",{className:"text-center text-[12px] leading-4 text-muted",children:ce.pcOldBody})},ft=R&&!(Ge&&R.kind==="timeout")?R:null,ut=h.model===null?null:((Nt=ue.find(G=>G.id===h.model))==null?void 0:Nt.label)??h.model,Y=h.model===null?d.model.byDefault:ce.pick(ut,h.effort?ca(h.effort):null),Re=h.model===null?d.model.defaultHint:(()=>{const G=ue.find(Ne=>Ne.id===h.model);return G?Fd(m,G):void 0})(),ke=H.find(G=>G.path===te[0]),ie=ke?ke===H[0]?ke.branch?ce.onBranch(ke.branch):ce.inFolder:bc(ke.path):void 0,Ae=ke&&ke!==H[0]?ke.branch??void 0:void 0;return e.jsxs(e.Fragment,{children:[e.jsx(la,{back:e.jsx("button",{type:"button","aria-label":ce.close,title:ce.close,onClick:()=>al({name:"sessions"}),className:Tt({className:"text-muted"}),children:e.jsx(q,{name:"close"})}),name:ce.title}),e.jsxs("main",{className:"flex min-h-0 flex-1 flex-col gap-3.5 overflow-y-auto overscroll-contain pt-3.5 pb-4",children:[e.jsx(Ks,{label:ce.project,aside:r.length>0?e.jsxs("button",{type:"button",role:"switch","aria-checked":z,onClick:()=>F(()=>{O.current=!0,K(G=>!G)}),className:"-my-1 inline-flex items-center gap-2 rounded-lg px-1.5 py-1 text-[13px] text-fg",children:[e.jsx("span",{"aria-hidden":"true",className:`relative inline-block h-[17px] w-[30px] flex-none rounded-full border ${z?"border-transparent bg-primary":"border-input bg-raised"}`,children:e.jsx("span",{className:`absolute top-[2px] size-[11px] rounded-full transition-all ${z?"left-[15px] bg-white":"left-[2px] bg-muted"}`})}),ce.nameToggle]}):void 0,children:r.length===0?e.jsxs("p",{className:"text-body text-muted",children:[d.launch.noProjects," ",ce.noProjectsBody]}):e.jsx(Zl,{onClick:()=>C("project"),lead:c?e.jsx(Ie,{state:Ge?"off":"idle"}):null,label:ce.project,text:c?e.jsx("b",{className:"font-semibold",children:c.name}):ce.chooseProject,sub:c?[l,Ge?ce.offline:u?ce.remembered:null].filter(Boolean).join(" · "):void 0,dim:Ge})}),z&&r.length>0&&e.jsxs(Ks,{label:ce.name,htmlFor:ae,children:[e.jsx("input",{id:ae,ref:U,type:"text",value:L,placeholder:ce.namePlaceholder(Rm(Ho(Ze))),spellCheck:!1,autoComplete:"off",autoCapitalize:"off","aria-invalid":he||void 0,"aria-describedby":`${ae}-say`,onChange:G=>{const Ne=G.target.value;F(()=>W(Ne))},className:`h-12 rounded-lg border bg-surface px-3 text-[15px] outline-none placeholder:text-muted focus:border-ring focus:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)] ${he?"border-danger-fg":"border-input"}`}),Oe?e.jsx("span",{id:`${ae}-say`,role:"alert",className:"text-[12px] leading-4 text-danger-fg",children:Oe}):e.jsx("span",{id:`${ae}-say`,className:`text-[12px] leading-4 ${de&&de!==Le?"text-fg":"text-muted"}`,children:de&&de!==Le?ce.nameCleaned(de):ce.nameHint})]}),c&&e.jsx(Ks,{label:ce.where,children:e.jsx(Zl,{onClick:()=>C("where"),lead:e.jsx(q,{name:ke!=null&&ke.branch?"branch":"folder",className:"size-4 text-muted"}),label:ce.where,text:te.length>1&&ie?e.jsxs(e.Fragment,{children:[e.jsxs("span",{"aria-hidden":"true",children:[ie,e.jsx("span",{className:"ml-1.5 font-mono text-small text-muted",children:ce.more(te.length-1)})]}),e.jsx("span",{className:"sr-only",children:ce.moreLabel(ie,te.length-1)})]}):ie??"",sub:Ae})}),e.jsx(Ks,{label:ce.agent,children:e.jsx("div",{role:"group","aria-label":ce.agent,className:"grid grid-cols-2 gap-2",children:f0.map(G=>e.jsxs("button",{type:"button","aria-pressed":G===m,onClick:()=>I(G),className:"flex flex-col items-start gap-0.5 rounded-lg border border-input px-[11px] py-[9px] text-left text-[13.5px] font-medium aria-pressed:border-ring aria-pressed:bg-raised aria-pressed:shadow-[inset_0_0_0_1px_var(--color-ring)]",children:[d.tools[G],e.jsx("small",{className:"text-[11.5px] font-normal text-muted",children:ce.tools[G]})]},G))})}),e.jsx(Ks,{label:ce.model,children:e.jsx(Zl,{onClick:()=>C("model"),lead:e.jsx(q,{name:"cpu",className:"size-4 text-muted"}),label:ce.model,text:Y,sub:Re})}),m==="omp"&&e.jsxs(Ks,{label:ce.permissions,children:[e.jsx(Jn,{name:"launch-approval",legend:ce.permissions,value:y,onChange:G=>F(()=>k(G)),options:h0.map(G=>({value:G,label:ce.approvals[G][0]}))}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ce.approvals[y][1]})]}),e.jsxs(Ks,{label:ce.message,htmlFor:E,children:[e.jsx("textarea",{id:E,value:j,onChange:G=>ee(G.target.value),placeholder:ce.placeholder,rows:4,className:"min-h-[92px] resize-none rounded-lg border border-input bg-surface px-3 py-2.5 text-[15px] leading-[22px] outline-none placeholder:text-muted focus:border-ring focus:shadow-[0_0_0_3px_color-mix(in_srgb,var(--color-ring)_30%,transparent)]"}),e.jsx("div",{className:"flex flex-wrap gap-1.5",children:ce.ideas.map(G=>e.jsx("button",{type:"button",onClick:()=>ee(G),className:"h-8 rounded-lg border border-dashed border-input px-2.5 text-[12.5px] text-muted",children:G},G))})]})]}),e.jsxs("div",{className:"bleed flex flex-none flex-col gap-1.5 border-t border-line bg-bg px-3.5 pt-2.5 pb-[calc(14px+var(--foot-inset))]",children:[ft&&e.jsx(b0,{outcome:ft,agent:rt,machine:l,taken:Oe??ce.missing.name,onRetry:yt(ft)?null:()=>tt(ft)}),pt?e.jsxs(e.Fragment,{children:[e.jsx("button",{type:"button",disabled:!0,className:Fe({variant:"primary",className:"w-full"}),children:pt.label}),pt.body]}):e.jsx("button",{type:"button",disabled:M,onClick:()=>void be(),className:Fe({variant:"primary",className:"w-full"}),children:M?e.jsxs(e.Fragment,{children:[e.jsx(q,{name:"spinner",className:"size-4 motion-safe:animate-spin"}),ce.launching]}):e.jsxs(e.Fragment,{children:[_t()&&e.jsx(q,{name:"face",className:"size-[18px]"}),_t()?ce.launchCheck:ce.launchDevice]})}),A&&e.jsx("span",{role:"status",className:"text-center text-[12px] leading-4 text-destructive",children:ce.cancelled}),!pt&&c&&e.jsx("span",{className:"text-center text-[12px] leading-4 text-muted",children:ce.summary(rt,ut,l,c.name)})]}),$==="project"&&e.jsxs(dt,{labelledBy:"launch-project",onClose:()=>C(null),children:[e.jsx("h2",{id:"launch-project",className:"text-base font-semibold",children:ce.project}),e.jsx(Nc,{children:r.map(G=>e.jsx(vc,{on:G.id===(c==null?void 0:c.id),onClick:()=>w(G),lead:e.jsx(Ie,{state:Ge?"off":"idle"}),text:G.name,sub:Ge?`${l} · ${ce.offline}`:l},G.id))})]}),$==="where"&&c&&e.jsxs(dt,{labelledBy:"launch-where",onClose:()=>C(null),children:[e.jsxs("div",{children:[e.jsx("h2",{id:"launch-where",className:"text-base font-semibold",children:ce.where}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ce.folders(c.name)})]}),e.jsx(Nc,{children:H.map((G,Ne)=>{const oe=qx(G)?G.exists===!1?ce.folder.missing(l):null:ce.folder.elsewhere(G.label??G.machine,l);return e.jsx(vc,{on:te.includes(G.path),disabled:oe!==null,onClick:()=>V(G.path),lead:e.jsx(q,{name:oe===null&&G.branch?"branch":"folder",className:"size-5 text-muted"}),text:Ne===0?ce.projectFolder:bc(G.path),sub:oe??G.branch??void 0},`${G.machine}:${G.path}`)})}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ce.folder.single})]}),$==="model"&&e.jsx(dt,{labelledBy:bo,onClose:()=>C(null),children:e.jsx(Su,{tool:m,models:ue,error:(we=n.models[m])==null?void 0:we.error,pick:h,onPick:G=>F(()=>g(G)),actions:e.jsx("button",{type:"button",onClick:()=>C(null),className:Fe({variant:"primary",className:"w-full"}),children:ce.done})})})]})}function Ks({label:t,htmlFor:s,aside:n,children:a}){const l=s?"label":"span",r=e.jsx(l,{...s?{htmlFor:s}:{},className:"text-[12px] font-medium text-muted",children:t});return e.jsxs("div",{className:"flex flex-col gap-1.5",children:[n?e.jsxs("div",{className:"flex items-center justify-between gap-2",children:[r,n]}):r,a]})}function Zl({onClick:t,lead:s,text:n,sub:a,dim:l=!1}){return e.jsxs("button",{type:"button","aria-haspopup":"dialog",onClick:t,className:`flex min-h-12 w-full items-center gap-2.5 rounded-lg border border-input bg-surface px-3 py-1.5 text-left ${l?"opacity-60":""}`,children:[s,e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate text-body",children:n}),a&&e.jsx("small",{className:"truncate text-[12px] text-muted",children:a})]}),e.jsx(q,{name:"down",className:"size-4 text-muted"})]})}function Nc({children:t}){return e.jsx("div",{className:"flex max-h-[50vh] flex-col overflow-y-auto rounded-[10px] border border-line",children:t})}function vc({on:t,disabled:s=!1,onClick:n,lead:a,text:l,sub:r}){return e.jsxs("button",{type:"button","aria-pressed":t,disabled:s,onClick:n,className:"flex min-h-12 items-center gap-3 border-b border-line px-3.5 py-1.5 text-left text-[15px] last:border-b-0 aria-pressed:bg-raised disabled:opacity-45",children:[a,e.jsxs("span",{className:"flex min-w-0 flex-1 flex-col",children:[e.jsx("span",{className:"truncate",children:l}),r&&e.jsx("small",{className:"truncate text-[12px] text-muted",children:r})]}),t&&e.jsx(q,{name:"check",className:"size-4"})]})}function b0({outcome:t,agent:s,machine:n,taken:a,onRetry:l}){const r={label:ce.retry,onClick:l??(()=>{})};if(t.kind==="timeout")return l?e.jsx(at,{tone:"warn",title:ce.timeout,body:ce.timeoutBody,action:r}):e.jsx(at,{tone:"warn",title:ce.timeout,body:ce.lostBody,action:{label:d.atoi.seeSessions,href:ne({name:"sessions"})}});if(t.kind==="failed")return e.jsx(at,{tone:"fail",title:ce.failed(s),body:ce.failedBody(s),action:r});const o=ce.refused;switch(t.reason){case"not_found":return e.jsx(at,{tone:"fail",title:o.not_found,body:ce.kept});case"invalid":return e.jsx(at,{tone:"fail",title:o.invalid,body:o.invalidBody(s)});case"stale":return e.jsx(at,{tone:"fail",title:o.stale,body:o.staleBody});case"confirm_required":return e.jsx(at,{tone:"fail",title:o.confirm_required,body:o.setupKept,action:{label:ce.settings,href:"#/connection/link"}});case"assertion_invalid":return e.jsx(at,{tone:"fail",title:o.assertion_invalid,body:ce.kept,action:r});case"assertion_expired":return e.jsx(at,{tone:"warn",title:o.assertion_expired,body:o.expiredBody,action:r});case"unavailable":return e.jsx(at,{tone:"warn",title:o.unavailable(n),body:o.unavailableBody});case"name_taken":return e.jsx(at,{tone:"fail",title:a});default:return e.jsx(at,{tone:"fail",title:o.other,body:ce.kept})}}const Br="ledge.mobile.forge",j0=35e3,y0=65e3,_o=(t,s)=>s?`${t}
21
+ ${s}`:t,za=t=>t!=="checking"&&t!=="sending"&&t!=="received",Jl=t=>!!t&&(!za(t.phase)||t.phase==="uncertain"&&!t.lost),kc=new Set(["assertion_invalid","assertion_expired","confirm_required","conflict"]);function N0(t){var s;try{const n=(s=Qe(t))==null?void 0:s.getItem(Br);if(!n)return null;const a=JSON.parse(n),l=Am.safeParse(a.state);return l.success&&typeof a.at=="string"?{state:l.data,at:a.at}:null}catch{return null}}function v0(t,s,n){var U;const a=N0(n);let l={state:(a==null?void 0:a.state)??null,at:(a==null?void 0:a.at)??null,loading:!1,details:{},runs:[],drafts:{}};const r=new Set,o=O=>{l={...l,...O};for(const B of[...r])B()};let i=!1,c=!1,x=!1;const u=new Map,m=new Map,p=new Map;let h=0,g=s.getState().daemon?((U=s.getState().daemon)==null?void 0:U.boot)??null:void 0;const y=new Set,k=()=>!i&&t.state()==="ready",S=()=>{var O;return!!((O=s.getState().daemon)!=null&&O.forge)},b=O=>{t.send(O).catch(()=>{})},j=(O,B,Z)=>{clearTimeout(u.get(O)),u.set(O,setTimeout(()=>{u.delete(O),Z()},B))},N=O=>{clearTimeout(u.get(O)),u.delete(O)};function $(){x||!c||!k()||!S()||(x=!0,b({type:"forge.state"}),o({loading:!0}),j("state",j0,()=>{x=!1,o({loading:!1})}))}const C=O=>l.runs.find(B=>B.op===O);function M(O,B){const Z=l.runs.findIndex(X=>X.id===O);if(Z<0)return;const H=B(l.runs[Z]);if(o({runs:l.runs.map((X,te)=>te===Z?H:X)}),za(H.phase)){H.op&&H.phase!=="uncertain"&&m.delete(H.op);const X=p.get(O);p.delete(O),X==null||X(H)}}const v=O=>O.sentAt!==void 0&&Date.now()-O.sentAt<Uc&&g!==void 0&&(O.boot??null)===g,A=O=>{N(`op:${O.op}`),m.delete(O.op),M(O.id,B=>({...B,phase:"uncertain",lost:!0,endedAt:B.endedAt??Date.now()}))};function T(O){for(const[B,Z]of[...m]){const H=C(B);if(!H){m.delete(B);continue}if(!O.has(B)){if(!v(H)){A(H);continue}M(H.id,X=>({...X,again:!0})),b(Z),H.phase==="sending"&&P(B)}}}const R=(O,B)=>{N(`op:${O}`);const Z=C(O);Z&&Jl(Z)&&M(Z.id,H=>({...H,...B,endedAt:Date.now()}))},P=O=>j(`op:${O}`,Wc,()=>{const B=C(O);(B==null?void 0:B.phase)==="sending"&&M(B.id,Z=>({...Z,phase:"uncertain",endedAt:Date.now()}))});function _(O){var B,Z,H;switch(O.type){case"snapshot":{const X=g;g=O.daemon.boot??null;const te=new Set(y);y.clear();for(const pe of te){const ue=C(pe);ue&&M(ue.id,F=>({...F,boot:g}))}(X===void 0||X!==g)&&T(te),$();return}case"forge.state":{N("state");const X=new Date().toISOString(),te={prs:O.prs,forges:O.forges,followed:O.followed,...O.mine?{mine:O.mine}:{}},pe=Object.keys(l.details).filter(ue=>{var I,V,ee;const F=(V=(I=l.details[ue])==null?void 0:I.data)==null?void 0:V.pr.headSha,w=(ee=[...te.prs,...te.mine??[]].find(Q=>Q.id===ue))==null?void 0:ee.headSha;return F&&w&&F!==w});o({state:te,at:X,loading:!1});try{(B=Qe(n))==null||B.setItem(Br,JSON.stringify({state:te,at:X}))}catch{}for(const ue of pe)ae.readDetail(ue);return}case"forge.detail":{N(`detail:${O.prId}`);const X=l.details[O.prId];if(O.detail){const te=O.detail.log??((Z=X==null?void 0:X.data)!=null&&Z.log&&O.detail.jobs.some(pe=>pe.id===X.data.log.jobId)?X.data.log:void 0);o({details:{...l.details,[O.prId]:{data:{...O.detail,...te?{log:te}:{}},...O.cut?{cut:!0}:{},loading:!1,at:new Date().toISOString()}}})}else o({details:{...l.details,[O.prId]:{...X,loading:!1,error:O.error??"failed"}}});return}case"operation.result":{const X=C(O.op);if(!X||!Jl(X))return;if(O.status==="received"){N(`op:${O.op}`),(X.phase==="sending"||X.phase==="uncertain")&&M(X.id,te=>{const{endedAt:pe,...ue}=te;return{...ue,phase:"received"}});return}if(O.status==="rejected"&&X.again&&kc.has(O.reason??"")){A(X);return}O.status==="rejected"&&R(O.op,{phase:"rejected",reason:O.reason??"invalid"});return}case"forge.done":{const X=C(O.op);if(!X)return;if(X.again&&O.rejected&&kc.has(O.rejected)){X.lost||A(X);return}const te=O.rejected?{phase:"rejected",reason:O.rejected,done:O}:{phase:"done",done:O,...O.error?{reason:O.error}:{}};if(X.lost)m.delete(X.op),M(X.id,pe=>{const{lost:ue,...F}=pe;return{...F,...te,endedAt:Date.now()}});else{const pe=Jl(X);R(O.op,te),pe||M(X.id,ue=>({...ue,done:O}))}if(O.ok&&(X.action.kind==="comment"||X.action.kind==="reply")){const pe=_o(X.prId,X.action.kind==="reply"?X.action.threadId:void 0);if(((H=l.drafts[pe])==null?void 0:H.trim())===X.action.body){const{[pe]:ue,...F}=l.drafts;o({drafts:F})}}l.details[X.prId]&&ae.readDetail(X.prId);return}}}let D=k();const E=t.subscribe(()=>{const O=t.state();(O==="unpaired"||O==="pairing")&&K();const B=k();if(B&&!D)D=!0,h++,x=!1,g=void 0,y.clear();else if(!B&&D){D=!1,x=!1;for(const[H,X]of u)clearTimeout(X),u.delete(H);const Z=Object.fromEntries(Object.entries(l.details).map(([H,X])=>[H,X.loading?{...X,loading:!1}:X]));o({loading:!1,details:Z});for(const H of l.runs)H.phase==="sending"&&H.op&&M(H.id,X=>({...X,phase:"uncertain",endedAt:Date.now()}))}}),z=t.onMessage(_);function K(){var O;if(!(!l.state&&!l.runs.length&&!Object.keys(l.details).length&&!Object.keys(l.drafts).length)){try{(O=Qe(n))==null||O.removeItem(Br)}catch{}m.clear(),o({state:null,at:null,loading:!1,details:{},runs:[],drafts:{}})}}async function L(O){var X;if(!((X=s.getState().device)!=null&&X.confirm))return{phase:"rejected",reason:"confirm_required"};let B;try{B=await s.prepareConfirm(O)}catch(te){return{phase:te instanceof Error&&te.message==="timeout"?"expired":"unsent"}}if(!B.credentialId)return{phase:"rejected",reason:"confirm_required"};const Z=Date.now(),H=await sa({challenge:B.challenge,rpId:B.rpId,credentialId:B.credentialId}).catch(()=>"failed");return H==="cancelled"?{phase:"cancelled"}:H==="failed"?{phase:"unsent"}:Date.now()-Z>=B.expiresInMs?{phase:"expired"}:{assertion:H}}async function W(O,B,Z){var pe;P(B);const H=h,X=await t.send(Z).catch(()=>!1),te=(pe=C(B))==null?void 0:pe.phase;!X&&H===h&&(te==="sending"||te==="uncertain")&&(N(`op:${B}`),M(O,ue=>({...ue,phase:"unsent",endedAt:Date.now()})))}const ae={getState:()=>l,subscribe(O){return r.add(O),()=>{r.delete(O)}},follow(){c=!0,$()},readDetail(O,B){!k()||!S()||(b({type:"forge.detail",prId:O,...B?{log:B}:{}}),o({details:{...l.details,[O]:{...l.details[O],loading:!0}}}),j(`detail:${O}`,y0,()=>o({details:{...l.details,[O]:{...l.details[O],loading:!1,error:"failed"}}})))},act(O,B){const Z=crypto.randomUUID(),H={op:"",id:Z,prId:O,action:B,phase:"checking",startedAt:Date.now()};if(!k()||!S()){const te={...H,phase:"unsent",endedAt:Date.now()};return o({runs:[...l.runs,te]}),Promise.resolve(te)}const X=new Promise(te=>p.set(Z,te));return o({runs:[...l.runs,H]}),(async()=>{const te=await L({purpose:"forge",forge:{prId:O,action:B}});if(!("assertion"in te)){M(Z,F=>({...F,phase:te.phase,...te.reason?{reason:te.reason}:{},endedAt:Date.now()}));return}const pe=Hc(),ue=Fc.safeParse({type:"forge.act",op:pe,prId:O,action:B,assertion:te.assertion});if(!ue.success||!k()){M(Z,F=>({...F,phase:"unsent",endedAt:Date.now()}));return}m.set(pe,ue.data),g===void 0&&y.add(pe),M(Z,F=>({...F,op:pe,phase:"sending",sentAt:Date.now(),boot:g??null})),await W(Z,pe,ue.data)})(),X},resend(O){const B=l.runs.find(H=>H.id===O),Z=B!=null&&B.op?m.get(B.op):void 0;if(!(!B||B.phase!=="uncertain"||B.lost||!Z||!k())){if(!v(B)){A(B);return}M(O,H=>{const{endedAt:X,...te}=H;return{...te,phase:"sending",again:!0}}),W(O,B.op,Z)}},setDraft(O,B){if(B)o({drafts:{...l.drafts,[O]:B}});else{const{[O]:Z,...H}=l.drafts;o({drafts:H})}},dismiss(O){const B=l.runs.find(Z=>Z.id===O);B&&za(B.phase)&&B.op&&m.delete(B.op),o({runs:l.runs.filter(Z=>Z.id!==O||!za(Z.phase))})},close(){i=!0,E(),z();for(const O of u.values())clearTimeout(O);u.clear()}};return ae}function wl(t){return f.useSyncExternalStore(t.subscribe,t.getState,t.getState)}const De=d.prs;function k0({status:t,pc:s}){const[n,a]=f.useState(!1),l=es(t),r=e.jsx(q,{name:"warning",className:"mt-px size-4 text-attention"});if(t.status==="missing")return e.jsx(Gt,{warn:!0,role:"alert",lead:r,children:e.jsx("span",{"data-forge-strip":"missing",children:De.missing(l.cli,s,t.host,l.kind)})});if(t.status==="unauthenticated"){const c=Ph(t);return e.jsxs(Gt,{warn:!0,role:"alert",lead:r,children:[e.jsx("b",{"data-forge-strip":"unauthenticated",className:"font-semibold",children:De.unauth(l.cli,t.host,s)}),e.jsx("code",{className:"block rounded-md bg-raised px-2 py-1.5 font-mono text-[12px] break-all",children:c}),e.jsx("button",{type:"button",className:ge({size:"sm",className:"self-start"}),onClick:()=>{var x;(x=navigator.clipboard)==null||x.writeText(c).then(()=>a(!0),()=>{})},children:n?De.copied:De.copy})]})}const o=t.since??t.at,i=[t.retryAt?De.retryAt(Be(t.retryAt)):"",t.readAt?De.readAt(l.kind,Be(t.readAt)):""].filter(Boolean).join(" ");return e.jsx(Gt,{warn:!0,role:"alert",lead:r,children:e.jsxs("div",{className:"flex flex-col gap-0.5",children:[e.jsx("b",{"data-forge-strip":"error",className:"font-semibold",children:De.error(l.host,s,Be(o))}),i&&e.jsx("span",{className:"text-muted",children:i})]})})}function w0(){const t="block animate-[ledge-pulse_1.6s_ease-in-out_infinite] rounded-[5px] bg-raised";return e.jsxs("div",{role:"status","data-list-state":"",className:"flex flex-col gap-3",children:[e.jsx(Ve,{children:e.jsxs("div",{"aria-hidden":"true",className:"flex flex-col gap-2.5 p-2.5",children:[e.jsx("span",{className:`${t} h-3.5 w-[70%]`}),e.jsx("span",{className:`${t} h-3 w-[45%]`}),e.jsx("span",{className:`${t} h-3.5 w-[60%]`}),e.jsx("span",{className:`${t} h-3 w-1/2`})]})}),e.jsx("span",{className:"text-[12px] text-muted",children:De.loading})]})}function S0(t,s,n){const a=n!=null&&n.readAt?De.asOf(Be(n.readAt)):De.state[t.state];return[De.host[t.forge],hl(t.repo),...s?[s]:[],a].join(" · ")}let wc={role:"all",q:""};function Sc({pr:t}){const s=t.roles??[];if(!s.length&&!t.sessions.length)return null;const n="rounded-[7px] border px-1.5 text-[11px] leading-4";return e.jsxs(e.Fragment,{children:[s.map(a=>e.jsx("span",{"data-role-pill":a,className:`${n} ${a==="reviewer"?"border-attention/50 text-attention":"border-line text-muted"}`,children:De.pill[a]},a)),t.sessions.length>0&&e.jsx("span",{"data-role-pill":"tracked",className:`${n} border-task/45 text-task`,children:De.pill.tracked})]})}function $0({forge:t,store:s}){const n=wl(t),a=me(s),{pc:l,look:r}=Ut(),o=na(),i=It(),[c,x]=f.useState(!0),[u,m]=f.useState(null),[p,h]=f.useState(wc),g=$=>{wc=$,h($)},y=r==="offline",k=Ht(l),S=n.state,b=$=>{var M;const C=$.sessions[0];return C?((M=a.sessions.get(C))==null?void 0:M.name)??null:null},j=$=>De.offlineBody(n.at?Be(n.at):$),N=(()=>{if(!S)return e.jsx(w0,{});const $=zh(S.forges),C=L=>$.find(W=>W.forge===L.forge&&W.host===L.host),M=[...S.prs,...S.mine??[]],v={open:Oh(M).open.sort((L,W)=>W.updatedAt.localeCompare(L.updatedAt)),closed:Tm(M,Date.now())},A=_m(M),T=Wo(v.open,p.role,p.q),R=Wo(v.closed,p.role,p.q),P=p.role!=="all"||p.q.trim()!=="",_=`${p.role}
22
+ ${p.q.trim()}`,D=P&&T.length===0&&R.length>0,E=D?u!==_:!c,z=S.forges.length>0&&$.length===S.forges.length,K="flex h-[30px] shrink-0 items-center gap-1.5 rounded-full border px-[11px] text-[12.5px]";return e.jsxs(e.Fragment,{children:[!y&&$.map(L=>e.jsx(k0,{status:L,pc:k},`${L.forge}:${L.host}`)),e.jsxs("div",{className:`flex flex-col gap-3 ${y?"opacity-50":""}`,children:[v.open.length+v.closed.length>0&&e.jsxs("div",{className:"flex flex-col gap-2.5",children:[e.jsxs("label",{className:"flex h-9 items-center gap-2 rounded-[9px] border border-line px-2.5 text-muted focus-within:border-muted",children:[e.jsx(q,{name:"search",className:"size-3.5 shrink-0"}),e.jsx("input",{type:"search","aria-label":De.search,placeholder:De.search,value:p.q,onChange:L=>g({...p,q:L.target.value}),className:"min-w-0 flex-1 bg-transparent text-[13px] text-fg outline-none placeholder:text-muted"})]}),e.jsx("div",{role:"group","aria-label":De.rolesLabel,className:"-mx-1 flex gap-1.5 overflow-x-auto px-1 [scrollbar-width:none]",children:Im.map(L=>e.jsxs("button",{type:"button","aria-pressed":p.role===L,onClick:()=>g({...p,role:L}),className:`${K} ${p.role===L?"border-transparent bg-secondary text-fg":"border-line text-muted"}`,children:[De.roles[L],e.jsx("span",{className:`font-mono text-[11px] ${L==="reviewer"?"text-attention":""}`,children:A[L]})]},L))})]}),D?null:T.length===0&&P?e.jsx(Ve,{children:e.jsxs("div",{"data-list-state":"none",className:"flex flex-col items-center gap-2.5 px-4 py-6 text-center text-[13px] text-muted",children:[e.jsx("b",{className:"font-medium text-fg",children:De.none}),e.jsx("button",{type:"button",className:ge({size:"sm"}),onClick:()=>g({role:"all",q:""}),children:De.clear})]})}):T.length===0?e.jsx(Ve,{children:z?e.jsx(Jt,{framed:!1,glyph:null,title:De.emptyTitle,body:De.emptyUnread,list:R.length===0}):e.jsx(Jt,{glyph:e.jsx(q,{name:"pr",className:"size-[22px]"}),title:De.emptyTitle,body:De.emptyBody,list:R.length===0})}):e.jsxs(e.Fragment,{children:[e.jsx(Ft,{aside:!y&&n.at?De.asOf(Be(n.at)):void 0,children:De.openHead(T.length)}),e.jsx(Ve,{label:De.title,children:T.map(L=>{const W=C(L),ae=Kd(L),U=e.jsxs(e.Fragment,{children:[e.jsx(uu,{pipeline:L.pipeline}),!y&&!W&&L.openThreads>0&&e.jsx(Qn,{children:De.threads(L.openThreads)}),!y&&!W&&ae&&e.jsx(Qn,{ok:!0,children:De.ready})]});return e.jsx(yi,{pr:L,sub:S0(L,b(L),W),chips:U,pills:e.jsx(Sc,{pr:L}),...y?{}:{href:ne({name:"pr",id:L.id})},selected:i&&o.name==="pr"&&o.id===L.id},L.id)})})]}),R.length>0&&e.jsxs(Ve,{children:[e.jsxs("button",{type:"button","aria-expanded":E,onClick:()=>D?m(L=>L===_?null:_):x(L=>!L),className:"flex min-h-11 w-full items-center gap-[9px] px-3 py-1.5 text-left text-[13px] text-muted",children:[e.jsx(q,{name:E?"down":"chevron",className:"size-3.5"}),De.closedGroup(R.length)]}),E&&e.jsx("div",{className:"border-t border-line",children:R.map(L=>e.jsx(yi,{pr:L,dim:!0,pills:e.jsx(Sc,{pr:L}),sub:[De.host[L.forge],hl(L.repo),De.state[L.state],mg(L.updatedAt)].join(" · "),...y?{}:{href:ne({name:"pr",id:L.id})},selected:i&&o.name==="pr"&&o.id===L.id},L.id))})]})]}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:De.tracked})]})})();return e.jsx(Rs,{title:De.title,offlineBody:j,heading:!1,children:N})}const Ye=d.prs,it=d.rigs,fn=t=>Ye.notDone[t.action.kind],C0=t=>{var s;return t.phase==="expired"?"assertion_expired":t.phase==="cancelled"?"cancelled":t.phase==="unsent"?"unsent":t.reason??((s=t.done)==null?void 0:s.error)};function Io({run:t,pr:s,detail:n,forge:a,pc:l,onReload:r}){const o=es(s),i=_t(),c={onClose:()=>a.dismiss(t.id),closeLabel:Ye.close};if(t.phase==="checking")return e.jsx(Zn,{children:it.running.checking});if(t.phase==="sending"||t.phase==="received")return e.jsx(Zn,{children:t.action.kind==="merge"?`${Ye.merging} · ${Ye.answers(o.cli)}`:Ye.answers(o.cli)});if(t.phase==="uncertain")return e.jsx(Se,{mark:"ask",title:it.uncertain.title,sub:it.uncertain.body,...c,children:!t.lost&&e.jsx("button",{type:"button",onClick:()=>a.resend(t.id),className:ge({size:"xs",className:"mt-1.5"}),children:Ye.retry})});const x=C0(t),u=t.done;if(t.phase==="done"&&(u!=null&&u.ok)){const h=Be(t.endedAt?new Date(t.endedAt).toISOString():null);return t.action.kind==="merge"?e.jsx(Se,{mark:"ok",title:Ye.merged(s.ref),sub:Ye.mergedSub(h,s.target),...c,children:u.command&&e.jsx(Xs,{commands:[u.command]})}):t.action.kind==="rerun"?e.jsx(Se,{mark:"ok",title:Ye.rerunDone(s.ref),sub:Ye.rerunDoneSub(h),...c,children:u.command&&e.jsx(Xs,{commands:[u.command]})}):t.action.kind==="reply"?e.jsx(Se,{mark:"ok",title:Ye.replyPosted(o.host),sub:h,...c}):t.action.kind==="comment"?e.jsx(Se,{mark:"ok",title:Ye.commentPosted(o.host),sub:h,...c}):null}if((t.action.kind==="comment"||t.action.kind==="reply")&&x!=="unavailable"&&x!=="confirm_required"){const h=t.action,g=x==="assertion_expired"?it.rejected.assertion_expired(i):x==="assertion_invalid"?it.rejected.assertion_invalid(i):x==="cancelled"?it.rejected.cancelled:x==="unsent"?it.rejected.unsent:Ye.lastLine(o.cli),y=!["assertion_expired","assertion_invalid","cancelled","unsent"].includes(x??"");return e.jsx(Se,{mark:"bad",title:`${it.because(fn(t),g)} ${Ye.keptText}`,...y&&(u!=null&&u.message)?{sub:e.jsx("span",{className:"font-mono",children:u.message})}:{},...c,children:e.jsx("button",{type:"button",onClick:()=>{a.dismiss(t.id),a.act(t.prId,h)},className:ge({size:"xs",className:"mt-1.5"}),children:Ye.retry})})}const p=t.action.kind==="merge"?it.rejected.again(Ye.mergeAgain):it.rejected.nothingSent;switch(x){case"stale":return e.jsx(Se,{mark:"warn",title:Ye.stale(xo(s.headSha)),sub:Ye.staleBody,...c,children:e.jsx("button",{type:"button",onClick:r??(()=>a.readDetail(t.prId)),className:ge({size:"xs",className:"mt-1.5"}),children:Ye.reload})});case"not_offered":{if(t.action.kind==="rerun")return e.jsx(Se,{mark:"warn",title:Ye.nothingToRerun,...c});const h=n?pl(n).find(y=>!y.ok):void 0,g=h?gr(qn(h,o.host),h):(u==null?void 0:u.message)??"";return e.jsx(Se,{mark:"bad",title:Ye.refused(o.host,g),...c})}case"busy":return e.jsx(Se,{mark:"warn",title:Ye.rerunRefused(Ye.rerunBusy),...c});case"confirm_required":return e.jsx(Se,{mark:"warn",title:it.rejected.confirm_required,...c});case"assertion_expired":return e.jsx(Se,{mark:"bad",title:it.because(fn(t),it.rejected.assertion_expired(i)),sub:p,...c});case"assertion_invalid":return e.jsx(Se,{mark:"bad",title:it.because(fn(t),it.rejected.assertion_invalid(i)),sub:p,...c});case"cancelled":return e.jsx(Se,{mark:"bad",title:it.because(fn(t),it.rejected.cancelled),sub:it.rejected.nothingSent,...c});case"unsent":return e.jsx(Se,{mark:"bad",title:it.because(fn(t),it.rejected.unsent),sub:it.rejected.nothingSent,...c});case"unavailable":return e.jsx(Se,{mark:"warn",title:Ye.gone(o.kind,l),sub:Ye.goneBody,...c});default:return e.jsx(Se,{mark:"bad",title:t.action.kind==="resolve"?it.because(fn(t),Ye.lastLine(o.cli)):Ye.failed(o.cli),...u!=null&&u.message?{sub:e.jsx("span",{className:"font-mono",children:u.message})}:{},...c,children:(u==null?void 0:u.command)&&e.jsx(Xs,{commands:[u.command]})})}}const gn=d.prs,nl=t=>t.toLocaleString(lt);function $c(t){return t.startsWith("@@")?"hunk":t.startsWith("+")?"add":t.startsWith("-")?"del":"ctx"}const M0={hunk:"bg-info/8 text-info",add:"bg-ok/15",del:"bg-danger-fg/15",ctx:"text-muted"};function Cc({path:t}){return e.jsx("span",{className:"min-w-0 flex-1 overflow-hidden text-left font-mono text-[12px] text-ellipsis whitespace-nowrap [direction:rtl]",children:e.jsx("span",{dir:"ltr",children:t})})}function Mc({f:t}){return e.jsxs(e.Fragment,{children:[e.jsxs("span",{className:"font-mono text-[12px] text-ok",children:["+",nl(t.added)]}),e.jsxs("span",{className:"font-mono text-[12px] text-danger-fg",children:["−",nl(t.removed)]})]})}function E0({f:t,threads:s,host:n}){const[a,l]=f.useState(!1),r=s>0&&e.jsx(Qn,{children:gn.fileThreads(s)});return t.patch===void 0?e.jsxs("div",{"data-file":t.path,className:"flex min-h-[46px] flex-wrap items-center gap-2 border-b border-line px-3 py-1.5 text-[13px] last:border-b-0",children:[e.jsx(q,{name:"file",className:"size-3.5 text-muted"}),e.jsx(Cc,{path:t.path}),r,e.jsx(Mc,{f:t}),e.jsx("span",{className:"basis-full pl-[22px] text-[12px] text-muted",children:gn.noPatch(n)})]}):e.jsxs("div",{"data-file":t.path,className:"border-b border-line last:border-b-0",children:[e.jsxs("button",{type:"button","aria-expanded":a,onClick:()=>l(o=>!o),className:"flex min-h-[46px] w-full items-center gap-2 px-3 py-1.5 text-left text-[13px]",children:[e.jsx(q,{name:a?"down":"chevron",className:"size-3.5 text-muted"}),e.jsx(Cc,{path:t.path}),r,e.jsx(Mc,{f:t})]}),a&&e.jsx("pre",{className:"m-0 overflow-hidden border-t border-line bg-well font-mono text-[11px] leading-[17px]",children:t.patch.split(`
23
+ `).map((o,i)=>e.jsx("span",{"data-line":$c(o),className:`block overflow-hidden px-3 text-ellipsis whitespace-pre ${M0[$c(o)]}`,children:o||" "},i))})]})}function R0({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=Wh(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:["+",nl(s.added)]})," ",e.jsxs("span",{className:"font-mono text-danger-fg",children:["−",nl(s.removed)]})]}),children:gn.fileCount(t.files.length)}),e.jsx(Ve,{label:gn.tabs.changes,children:t.files.map(a=>e.jsx(E0,{f:a,threads:Kh(t,a.path),host:n},a.path))})]})}const er=d.prs,A0=t=>[...t].sort((s,n)=>Date.parse(n.at)-Date.parse(s.at));function T0({detail:t}){return e.jsxs("div",{className:"flex flex-col gap-2.5",children:[t.commits.length>0&&e.jsx(Ve,{label:er.tabs.commits,children:A0(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:xo(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} · ${Nr(s.at)}`})]})]},s.sha))}),e.jsx("p",{className:"text-[12px] leading-4 text-muted",children:er.commitsReadOnly(er.host[t.pr.forge])})]})}const ct=d.prs,Lo=t=>t.file?t.line!==void 0?ct.fileLine(t.file,t.line):t.file:null,Hx=(t,s,n)=>t.filter(a=>a.prId===s&&n(a)).at(-1),Ux=["checking","sending","received"];function Wx({sent:t,onClose:s}){return t==="refused"?e.jsx(Se,{mark:"bad",title:d.agents.notSent,onClose:s,closeLabel:ct.close}):e.jsx(Se,{mark:"ok",title:ct.commentSent(t.name),onClose:s,closeLabel:ct.close,children:e.jsx("a",{href:ne({name:"thread",sessionId:t.id}),className:ge({size:"xs",className:"mt-1.5"}),children:ct.openAgent(t.name)})})}function Kx({id:t,label:s,placeholder:n,verb:a,value:l,onChange:r,confirm:o,live:i,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(zs,{verb:a,confirm:o,disabled:!i,onClick:c}),e.jsx("span",{className:"text-[12px] leading-4 text-muted",children:ct.postedAs(x)})]})]})}const _0=({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:Be(s)}),e.jsx("br",{}),n]}),I0="flex flex-col gap-2 rounded-[10px] border border-line bg-surface p-2.5 dark:bg-transparent",tr="h-9 !px-2.5 text-[12.5px]";function Vx({pr:t,t:s,agent:n,forge:a,store:l,live:r,pc:o,readOnly:i=!1}){var v,A;const c=wl(a),x=me(l),[u,m]=f.useState(!1),[p,h]=f.useState(null),g=_o(t.id,s.id),y=c.drafts[g]??"",k=es(t),S=Lo(s),b=s.comments[0],j=Hx(c.runs,t.id,T=>(T.action.kind==="reply"||T.action.kind==="resolve")&&T.action.threadId===s.id),N=()=>{n&&h(l.reply(n.id,ct.threadText(t.ref,b.author,S,b.body))?n:"refused")},$=()=>{m(!1),a.act(t.id,{kind:"reply",threadId:s.id,body:y.trim()})},C=!!j&&Ux.includes(j.phase),M=!C&&(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:I0,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((T,R)=>e.jsx(_0,{who:T.author,at:T.at,body:T.body,reply:R>0},T.id)),!i&&e.jsxs(e.Fragment,{children:[M?e.jsx(Kx,{id:`reply-${s.id}`,label:ct.reply,placeholder:ct.replyPh,verb:ct.reply,value:y,onChange:T=>a.setDraft(g,T),confirm:!!((A=x.device)!=null&&A.confirm),live:r,onPost:$,host:k.host,autoFocus:u}):e.jsxs("div",{className:"flex flex-wrap gap-1.5",children:[e.jsx("button",{type:"button",disabled:!r||C,onClick:()=>m(!0),className:ge({className:tr}),children:ct.reply}),n&&e.jsx("button",{type:"button",disabled:!x.fresh,onClick:N,className:ge({className:tr}),children:ct.sendTo(n.name)}),s.resolvable&&e.jsx("button",{type:"button",disabled:!r||C,onClick:()=>void a.act(t.id,{kind:"resolve",threadId:s.id}),className:`${ge({className:tr})} border-transparent`,children:ct.resolve})]}),p&&e.jsx(Wx,{sent:p,onClose:()=>h(null)}),j&&e.jsx(Io,{run:j,pr:t,detail:void 0,forge:a,pc:o})]})]})}function L0({pr:t,t:s,forge:n,store:a,pc:l}){const[r,o]=f.useState(!1),i=Lo(s);return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button","aria-expanded":r,onClick:()=>o(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:ct.resolvedRow([...i?[i]:[],s.comments[0].author])}),e.jsx(q,{name:r?"down":"chevron",className:"size-3.5"})]}),r&&e.jsx(Vx,{pr:t,t:s,agent:null,forge:n,store:a,live:!1,pc:l,readOnly:!0})]})}function Gx(t,s){const n=me(s),[a,l]=f.useState(null),r=(t==null?void 0:t.threads)??[],o=t?xu(t.pr,n.sessions)[0]:void 0,i=o?{id:o.id,name:o.name}:null,c=r.filter(u=>!u.resolved),x=()=>{if(!i||!t)return;const u=c.map(m=>ct.note(m.comments[0].author,Lo(m),m.comments[0].body));l(s.reply(i.id,ct.notesText(t.pr.ref,u))?i:"refused")};return{agent:i,open:c,resolved:r.filter(u=>u.resolved),sent:a,send:x,clear:()=>l(null),fresh:n.fresh}}function Xx({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"}),ct.sendAll(t.agent.name)]})}function Ec({detail:t,forge:s,store:n,live:a,pc:l,column:r}){const o=Gx(t,n),i=r??o,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:ct.discSub(i.open.length,i.resolved.length)}),e.jsx("span",{className:"flex-1"}),e.jsx(Xx,{all:i})]}),i.sent&&e.jsx(Wx,{sent:i.sent,onClose:i.clear}),i.open.map(x=>e.jsx(Vx,{pr:c,t:x,agent:i.agent,forge:s,store:n,live:a,pc:l},x.id)),i.resolved.map(x=>e.jsx(L0,{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:ct.noComment})}function Rc({pr:t,forge:s,store:n,live:a,pc:l}){var m;const r=wl(s),o=me(n),i=_o(t.id),c=r.drafts[i]??"",x=Hx(r.runs,t.id,p=>p.action.kind==="comment"),u=!!x&&Ux.includes(x.phase);return e.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-2",children:[x&&e.jsx(Io,{run:x,pr:t,detail:void 0,forge:s,pc:l}),e.jsx(Kx,{id:`comment-${t.id}`,label:ct.addComment,placeholder:ct.addComment,verb:ct.post,value:c,onChange:p=>s.setDraft(i,p),confirm:!!((m=o.device)!=null&&m.confirm),live:a&&!u,onPost:()=>void s.act(t.id,{kind:"comment",body:c.trim()}),host:es(t).host,rows:1,arrow:!0})]})}const O0=`${eo} and (orientation: landscape)`,Yx=()=>typeof globalThis.matchMedia=="function"?globalThis.matchMedia(O0):null,D0=t=>{var n;const s=Yx();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 F0(){return f.useSyncExternalStore(D0,()=>{var t;return((t=Yx())==null?void 0:t.matches)??!1},()=>!1)}const le=d.prs,z0={review:"border-attention/45 text-attention"};function P0({pr:t,landscape:s}){const n=It(),a=es(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 ${z0[t.state]??"border-input text-muted"}`,children:le.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"}),le.openOn(a.host)]}):e.jsx("a",{href:t.url,target:"_blank",rel:"noreferrer","aria-label":le.openOn(a.host),title:le.openOn(a.host),className:Tt(),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:le.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,hl(t.repo),`${t.branch} → ${t.target}`].join(" · ")})]}),e.jsx("a",{href:t.url,target:"_blank",rel:"noreferrer","aria-label":le.openOn(a.host),title:le.openOn(a.host),className:Tt(),children:e.jsx(q,{name:"external",className:"size-[18px]"})})]})}const B0=["overview","discussion","changes","commits"],q0=["overview","changes","commits"];function H0({pr:t,d:s,view:n,views:a,onView:l,wide:r}){const o=s?{discussion:s.threads.length,changes:s.files.length,commits:s.commits.length}:{};return e.jsx("nav",{"aria-label":le.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(i=>e.jsxs("button",{type:"button","aria-current":n===i?"page":void 0,onClick:()=>l(i),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:[i==="overview"&&e.jsx(Ie,{state:an[t.pipeline],pulse:t.pipeline==="run"}),le.tabs[i],o[i]!==void 0&&e.jsx("span",{className:"inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-raised px-1 font-mono text-[11px] group-aria-[current=page]:bg-bg",children:o[i]})]},i))})}const Qx={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"},Zx=t=>t==="fail"?"bg-danger-bg":"bg-surface dark:bg-transparent";function Jx(t){if(t.status==="run")return e.jsx("span",{className:"font-mono text-[12px] text-info",children:le.pipe.run});const s=Yd(t.durationS);return s?e.jsx("span",{className:"font-mono text-[12px] text-muted",children:s.hours?le.hours(s.text):s.text}):t.status==="wait"||t.status==="skip"?e.jsx("span",{className:"text-[12px]",children:le.pipe[t.status]}):null}function U0({job:t,selected:s,onOpen:n}){const a=e.jsxs(e.Fragment,{children:[t.status==="run"?e.jsx(En,{}):e.jsx(Ie,{state:an[t.status]}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.name}),Jx(t)]}),l=`flex h-11 w-full items-center gap-2.5 rounded-[10px] border px-3 text-left text-[14px] ${Zx(t.status)} ${Qx[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 W0({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 K0({pr:t,jobs:s,selected:n,onJob:a}){const l=Gd(s);return e.jsx("div",{className:"flex flex-col",children:l.map((r,o)=>e.jsxs("div",{className:"flex flex-col",children:[o>0&&e.jsx(W0,{after:l[o-1]}),e.jsx("div",{className:"mb-[5px] text-[11px] tracking-[.5px] text-muted uppercase",children:t.forge==="gitlab"?le.stage(o+1,r.name):r.name}),e.jsx("div",{className:"flex flex-col gap-1.5",children:r.jobs.map(i=>e.jsx(U0,{job:i,selected:i.id===n,onOpen:i.id===n?void 0:()=>a(i)},i.id))})]},r.column))})}function V0({job:t,selected:s,onOpen:n}){const a=e.jsxs(e.Fragment,{children:[t.status==="run"?e.jsx(En,{}):e.jsx(Ie,{state:an[t.status]}),e.jsx("span",{className:"min-w-0 flex-1 truncate",children:t.name}),Jx(t)]}),l=`flex h-10 min-w-[92px] items-center gap-[7px] rounded-[10px] border px-[9px] text-left text-[13px] ${Zx(t.status)} ${Qx[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 G0({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 X0({pr:t,jobs:s,selected:n,onJob:a}){const l=Gd(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,o)=>e.jsxs("div",{className:"contents",children:[o>0&&e.jsx(G0,{after:l[o-1]}),e.jsxs("div",{className:"flex min-w-0 flex-[0_1_auto] flex-col gap-2",children:[e.jsx("div",{className:"mb-[5px] text-[11px] tracking-[.5px] whitespace-nowrap text-muted uppercase",children:t.forge==="gitlab"?le.stage(o+1,r.name):r.name}),r.jobs.map(i=>e.jsx(V0,{job:i,selected:i.id===n,onOpen:i.id===n?void 0:()=>a(i)},i.id))]})]},r.column))})}const Y0=({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 em({job:t,read:s,pr:n,onRetry:a,tall:l=!1}){var i,c;const r=es(n),o=((c=(i=s==null?void 0:s.data)==null?void 0:i.log)==null?void 0:c.jobId)===t.id?s.data.log.text:null;return o!==null?e.jsx(Y0,{text:o,tall:l}):s!=null&&s.loading?e.jsxs("div",{role:"status",className:"flex items-center gap-2 text-[12px] text-muted",children:[e.jsx(En,{className:"text-muted"}),le.log.reading(t.name)]}):e.jsx(Se,{mark:"bad",title:le.log.failed,sub:le.log.failedBody(r.cli,r.host),children:e.jsx("button",{type:"button",onClick:a,className:ge({size:"xs",className:"mt-1.5"}),children:le.retry})})}function Q0({job:t,read:s,pr:n,onRetry:a,onClose:l}){var x,u;const r=f.useId(),o=es(n),i=Yd(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(dt,{labelledBy:r,onClose:l,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(Ie,{state:an[t.status]}),e.jsx("h2",{id:r,className:"text-[15px] font-semibold",children:le.log.title(t.name)}),e.jsx("span",{className:"text-[12px] text-muted",children:[le.pipe[t.status],i?i.hours?le.hours(i.text):i.text:""].filter(Boolean).join(" · ")})]}),e.jsx(em,{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:[le.log.note,Bh(c)?le.log.cut(o.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"}),le.openOn(o.host)]}),e.jsx("button",{type:"button",onClick:l,className:ge(),children:le.close})]})]})}function Z0({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 J0={approved:"idle",changes:"perm",pending:"plain"};function ev({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:le.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?le.reviewers:""}),e.jsxs("dd",{className:n,children:[e.jsx(Ie,{state:J0[a.state]}),a.name," ",e.jsx("span",{className:"text-muted",children:le.reviewer[a.state]})]})]},a.name)),t.labels.length>0&&e.jsxs(e.Fragment,{children:[e.jsx("dt",{className:s,children:le.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:le.issue}),e.jsx("dd",{className:`${n} font-mono text-[12px]`,children:t.issues.join(" ")})]})]})}function tv({conds:t,host:s}){return e.jsxs("section",{"aria-label":le.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:le.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:qn(n,s)})]},a))})]})}function sv(t,s){const n=pl(t),a=n.find(o=>!o.ok);if(a)return e.jsxs(e.Fragment,{children:[le.footApprovals(Qd(t.pr))," · ",e.jsx("b",{className:"font-medium text-fg",children:gr(qn(a,s),a)})]});const l=n.find(o=>o.key==="pipeline"||o.key==="noCi"),r=n.find(o=>o.key==="approved");return`${qn(l,s)} · ${gr(qn(r,s),r)}`}function tm(){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:le.detailLoading})]})}function nv({pr:t,job:s,store:n}){const a=me(n),l=xu(t,a.sessions),[r,o]=f.useState(null),[i,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:le.noSession(t.branch)});const p=l.find(y=>y.id===r)??l[0],h=a.fresh,g=()=>{u(n.reply(p.id,le.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:le.askFix(p.name)}),l.length>1&&e.jsx("button",{type:"button","aria-label":le.otherSession,title:le.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(Se,{mark:"bad",title:d.agents.notSent,onClose:()=>u(null),closeLabel:le.close}),x&&x!=="refused"&&e.jsx(Se,{mark:"ok",title:le.sentTo(x.name),onClose:()=>u(null),closeLabel:le.close,children:e.jsx("a",{href:ne({name:"thread",sessionId:x.id}),className:ge({size:"xs",className:"mt-1.5"}),children:le.openAgent(x.name)})}),i&&e.jsxs(dt,{labelledBy:m,onClose:()=>c(!1),children:[e.jsx("h2",{id:m,className:"sr-only",children:le.otherSession}),e.jsx("div",{role:"menu","aria-labelledby":m,className:"flex flex-col overflow-hidden rounded-[10px] border border-line",children:l.map((y,k)=>e.jsxs("button",{type:"button",role:"menuitemradio","aria-checked":y.id===p.id,onClick:()=>{o(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(Ie,{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(" · ")})]}),k===0&&e.jsx("span",{className:"text-[12px] text-muted",children:le.mostActive})]},y.id))})]})]})}function av({pr:t,confirm:s,live:n,onRerun:a,onClose:l}){return e.jsxs(cs,{title:le.rerunTitle(t.ref),onClose:l,children:[e.jsx("p",{className:"m-0 text-[12.5px] leading-[18px] text-muted",children:le.rerunBody(es(t).host)}),e.jsx(zs,{verb:le.rerun,confirm:s,disabled:!n,onClick:()=>{l(),a()}}),e.jsx(ha,{onClose:l})]})}function lv({pr:t,read:s,store:n,live:a,onJob:l,onLog:r,onRerun:o,side:i}){const c=s==null?void 0:s.data,x=es(t),u=c?Xd(c.jobs):null,m=t.state!=="merged"&&t.state!=="closed",p=t.pipeline==="none"?le.noCi:c!=null&&c.mergeBlockers.includes("pipeline_not_started")?le.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:le.pipelineTitle}),e.jsx(uu,{pipeline:t.pipeline,short:!0}),e.jsx("span",{className:"flex-1"}),Uh(t)&&e.jsxs("button",{type:"button",disabled:!a,onClick:o,className:ge({size:"sm"}),children:[e.jsx(q,{name:"refresh",className:"size-4"}),le.rerun]})]}),p&&e.jsx("p",{className:"m-0 text-[12px] text-muted",children:p}),c?e.jsxs(e.Fragment,{children:[c.jobs.length>0&&(i?e.jsx(X0,{pr:t,jobs:c.jobs,selected:(u==null?void 0:u.id)??null,onJob:l}):e.jsx(K0,{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:`${le.log.title(u.name)} · ${le.log.lines}`})}),e.jsx(em,{job:u,read:s,pr:t,onRetry:()=>r(u)}),m&&e.jsx(nv,{pr:t,job:u.name,store:n})]}),m&&e.jsx(tv,{conds:pl(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:le.description}),e.jsx(Z0,{text:c.description})]}),e.jsx(ev,{d:c})]}):e.jsx(tm,{})]})}function rv({read:t,pr:s,pc:n,onRetry:a}){const l=es(s);return t.error==="unavailable"?e.jsx(Se,{mark:"warn",title:le.gone(l.kind,n),sub:le.goneBody}):t.error==="too_large"?e.jsx(Se,{mark:"bad",title:le.tooLarge,sub:le.tooLargeBody(l.host),children:e.jsx("a",{href:s.url,target:"_blank",rel:"noreferrer",className:ge({size:"xs",className:"mt-1.5"}),children:le.open})}):e.jsx(Se,{mark:"bad",title:le.readFailed(l.cli,l.kind),sub:le.readFailedBody,children:e.jsx("button",{type:"button",onClick:a,className:ge({size:"xs",className:"mt-1.5"}),children:le.retry})})}function ov({d:t,pc:s,confirm:n,live:a,onMerge:l,onClose:r}){return e.jsxs(cs,{title:le.confirm(t.pr.ref,t.pr.target),onClose:r,children:[e.jsx("span",{className:"text-[12.5px] text-muted",children:le.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:le.headRead(xo(t.pr.headSha))}),e.jsx(zs,{verb:le.merge,confirm:n,disabled:!a,onClick:()=>{r(),l()}}),e.jsx(ha,{onClose:r})]})}const iv=(t,s)=>t.filter(n=>n.prId===s&&(n.action.kind==="merge"||n.action.kind==="rerun")).at(-1),cv=t=>!!t&&(t.phase==="checking"||t.phase==="sending"||t.phase==="received");function dv({id:t,forge:s,store:n,pane:a=!1}){var ue,F,w,I,V,ee;const l=wl(s),r=me(n),[o,i]=f.useState(!1),[c,x]=f.useState(!1),{pc:u,look:m}=Ut(),p=It(),h=F0()&&p&&!a,[g,y]=f.useState("overview"),[k,S]=f.useState(null),b=m==="offline",j=Ht(u),N=l.details[t],$=l.state&&[...l.state.prs,...l.state.mine??[]].find(Q=>Q.id===t),C=$??((ue=N==null?void 0:N.data)==null?void 0:ue.pr),M=Gx(N==null?void 0:N.data,n);f.useEffect(()=>{s.readDetail(t)},[s,t]);const v=N!=null&&N.data?Xd(N.data.jobs):null,A=f.useRef(null);f.useEffect(()=>{var Q,J;!v||((J=(Q=N==null?void 0:N.data)==null?void 0:Q.log)==null?void 0:J.jobId)===v.id||A.current===v.id||(A.current=v.id,s.readDetail(t,v.id))},[s,t,v==null?void 0:v.id,(w=(F=N==null?void 0:N.data)==null?void 0:F.log)==null?void 0:w.jobId]);const T=f.useRef(null);f.useEffect(()=>{var Q,J;(J=(Q=T.current)==null?void 0:Q.scrollTo)==null||J.call(Q,{top:0})},[g]);const R=`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(!C)return e.jsx("main",{"data-tab-scroll":"",className:R,children:l.state?e.jsx(Se,{mark:"warn",title:le.gone(le.kind[((I=l.state.forges.find(Q=>Q.host===t.split("/")[0]))==null?void 0:I.forge)??"github"],j),sub:le.goneBody}):e.jsx(Gt,{lead:e.jsx(En,{className:"text-muted"}),children:e.jsx("span",{children:le.loading})})});const P=es(C),_=N==null?void 0:N.data,D=C.state==="merged"||C.state==="closed",E=!!l.state&&!$,z=k&&_?_.jobs.find(Q=>Q.id===k):void 0,K=Q=>{s.readDetail(t,Q.id)},L=iv(l.runs,t),W=cv(L),ae=r.fresh&&!b,U=()=>{_&&s.act(t,{kind:"merge",headSha:_.pr.headSha})},O=h?q0:B0,B=O.includes(g)?g:"overview",Z=e.jsxs(e.Fragment,{children:[e.jsx(js,{body:le.offlineBody}),E&&!L&&e.jsx(Se,{mark:"warn",title:le.gone(P.kind,j),sub:le.goneBody}),L&&e.jsx(Io,{run:L,pr:C,detail:_,forge:s,pc:j,onReload:()=>s.readDetail(t)}),(N==null?void 0:N.error)&&!_&&e.jsx(rv,{read:N,pr:C,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:le.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)||_)&&e.jsx(lv,{pr:C,read:N,store:n,live:ae&&!W&&!E,side:h,onJob:Q=>{S(Q.id),K(Q)},onLog:K,onRerun:()=>x(!0)}),B!=="overview"&&!_&&!(N!=null&&N.error)&&e.jsx(tm,{}),B==="discussion"&&_&&e.jsx(Ec,{detail:_,forge:s,store:n,live:ae&&!E,pc:j}),B==="changes"&&_&&e.jsx(R0,{detail:_}),B==="commits"&&_&&e.jsx(T0,{detail:_})]})]}),H=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:le.state[C.state]}),C.state==="merged"?le.mergedInto(C.target,Nr(C.updatedAt)):Nr(C.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:_?sv(_,P.host):le.footApprovals(Qd(C))}),te=e.jsxs("button",{type:"button",disabled:!ae||E||W||!_||!Hh(_),onClick:()=>i(!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"}),le.merge]}),pe=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(P0,{pr:C,landscape:h}),e.jsx(H0,{pr:C,d:_,view:B,views:O,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:T,"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:Z}),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:le.tabs.discussion}),_&&_.threads.length>0&&e.jsx("span",{className:"text-[12.5px] text-muted",children:le.discSub(M.open.length,M.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:_&&e.jsx(Ec,{detail:_,forge:s,store:n,live:ae&&!E,pc:j,column:M})}),!D&&e.jsx("div",{className:"flex flex-none border-t border-line px-3 py-2.5",children:e.jsx(Rc,{pr:C,forge:s,store:n,live:ae&&!E,pc:j})})]})]}):e.jsx("main",{ref:T,"data-tab-scroll":"",className:R,children:Z}),e.jsx("footer",{className:pe,children:h?e.jsxs(e.Fragment,{children:[D?H:X,e.jsx(Xx,{all:M,className:"flex-none"}),!D&&te]}):B==="discussion"&&!D?e.jsx(Rc,{pr:C,forge:s,store:n,live:ae&&!E,pc:j}):D?H:e.jsxs(e.Fragment,{children:[X,te]})}),c&&e.jsx(av,{pr:C,confirm:!!((V=r.device)!=null&&V.confirm),live:ae,onRerun:()=>{s.act(t,{kind:"rerun"})},onClose:()=>x(!1)}),o&&_&&e.jsx(ov,{d:_,pc:j,confirm:!!((ee=r.device)!=null&&ee.confirm),live:ae,onMerge:U,onClose:()=>i(!1)}),z&&e.jsx(Q0,{job:z,read:N,pr:C,onRetry:()=>K(z),onClose:()=>S(null)})]})}function uv(t){const[,s]=f.useReducer(n=>n+1,0);return f.useEffect(()=>{const n=t.subscribe(s);return s(),n},[t]),t.state()}function xv(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 mv(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 pv(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?Dm.safeParse(await r.json()):null).then(r=>{l&&(r!=null&&r.success)&&a(r.data.login)}).catch(()=>{}),()=>{l=!1}},[t,s]),n}const fv=(t,s)=>globalThis.fetch(t,s),Ac=t=>t.name==="request"?{name:"request",sessionId:t.sessionId,key:t.key}:t.name==="ask"?{name:"ask",id:t.id}:null;function hv({link:t,store:s,storage:n,fetchImpl:a=fv,updates:l=null,signin:r=null,lost:o=!1,relay:i=globalThis.location.host}){var ke,ie,Ae,Je,xt,Yt;const c=Oc(),x=uv(t),u=me(s),m=na(),p=pv(a,x!=="signed_out"),{build:h,waiting:g}=xv(l),[y,k]=f.useState(null),[S,b]=f.useState(r),[j,N]=f.useState(o),[$,C]=f.useState(!1),[M,v]=f.useState(!1),[A,T]=f.useState(!1),R=f.useRef(!1),[P,_]=f.useState(!1),D=((ke=t.pairing())==null?void 0:ke.state())??null,E=((ie=t.recovery())==null?void 0:ie.state())??null,z=(E==null?void 0:E.step)==="reaching"||(E==null?void 0:E.step)==="faceid"||(E==null?void 0:E.step)==="checking",K=Fs(),[L,W]=f.useState(!1),[ae,U]=f.useState(!1),O=(E==null?void 0:E.step)==="done"&&(!u.fresh||lc((Ae=u.device)==null?void 0:Ae.push));f.useEffect(()=>{O&&U(!0)},[O]),f.useEffect(()=>{E&&E.step!=="done"&&U(!1)},[E==null?void 0:E.step]);const B=Wy(S),Z=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":(E==null?void 0:E.step)==="done"&&!M?"recover":(D==null?void 0:D.step)==="linked"&&!M?"compare":x==="unpaired"||x==="pairing"?D!==null||P||x==="pairing"&&!z?"compare":E&&E.step!=="cancelled"?"recover":"choose":"route",H=ze=>{R.current=!0,_(!0),ze()},X=()=>{W((E==null?void 0:E.step)==="failed"&&E.why==="old"),H(()=>t.startPairing())};f.useEffect(()=>{x==="ready"&&(R.current=!1,_(!1),N(!1),C(!1)),(x==="unpaired"||x==="pairing")&&(v(!1),T(!1))},[x]),f.useEffect(()=>{var Nt;const ze=(Nt=globalThis.navigator)==null?void 0:Nt.serviceWorker;if(!ze)return;const ht=we=>lp(we.data);return ze.addEventListener("message",ht),()=>ze.removeEventListener("message",ht)},[]);const te=f.useRef("atoi"),pe=f.useRef([]),ue=to(m);ue&&(te.current=ue),f.useEffect(()=>{bf(m)},[m]);const F=It(),w=eN(n),I=ze=>cc(ze,n),V=f.useRef(!1);w&&F&&(V.current=!0);const ee=f.useRef("atoi");ue&&ue!=="chat"&&(ee.current=ue);const Q=F&&Z==="route"&&m.name==="chat";f.useEffect(()=>{Q&&(cc(!0,n),fs(qa(so(ee.current))))},[Q,n]);const[J,fe]=f.useState(null);f.useEffect(()=>{const ze=AN(t,s,n);return fe(ze),()=>{ze.close(),fe(null)}},[t,s,n]);const[be,tt]=f.useState(null);f.useEffect(()=>{const ze=v0(t,s,n);return ze.follow(),tt(ze),()=>{ze.close(),tt(null)}},[t,s,n]);const yt=mv(be),Ze=m.name==="atelier"&&(!F||(u.fresh||u.daemon!==null)&&!((Je=u.daemon)!=null&&Je.atelier));f.useEffect(()=>{Ze&&fs({name:"sessions"})},[Ze]);const Le=Ac(m);no(F&&Z==="route"&&ue==="atoi",ze=>{if(ze!=="ArrowUp"&&ze!=="ArrowDown")return!1;const ht=s.getState(),Nt=Bp(Ml(Vt([...ht.sessions.values()]),ht.asks??[]),Ac(qa(globalThis.location.hash)),ze==="ArrowDown"?1:-1);return Nt?(fs(Nt),!0):!1});const de=f.useRef(!1),he=x==="ready"&&u.fresh&&!!((xt=u.device)!=null&&xt.id)&&!u.device.name;f.useEffect(()=>{!he||de.current||s.renameDevice(kx(void 0))!==null&&(de.current=!0)},[he,s]);const $e=t.pinned(),Oe=($e==null?void 0:$e.name)??null,rt=($e==null?void 0:$e.name)??((Yt=u.daemon)==null?void 0:Yt.name)??null,Ge=()=>t.retry(),pt=f.useRef(!1),ft=ze=>{if(!pt.current){if(x!=="ready"){x!=="denied"&&C(!0),ze();return}pt.current=!0,s.forgetDevice().then(ht=>{pt.current=!1,ht||C(!0),ze()})}},ut=()=>ft(()=>{t.signOut()}),Y=()=>ft(()=>H(()=>{t.relink()})),Re=(()=>{var rn,on,Tn,_n;switch(Z){case"denied":return e.jsx(By,{onOther:()=>b("another")});case"login":return e.jsx(Vy,{server:i,error:B});case"replaced":return e.jsx(Gy,{onHere:()=>globalThis.location.reload()});case"keyChanged":return e.jsx(Hy,{pcName:rt,known:$e,received:t.receivedKey(),onRelink:Y,onSignOut:ut});case"unrecognized":return e.jsx(wN,{pcName:rt,onRelink:Y,onSignOut:ut});case"storage":return e.jsx(tN,{onRetry:Ge,onReload:()=>globalThis.location.reload()});case"choose":return e.jsx($h,{login:p,platform:K,onPasskey:()=>t.startRecovery(),onCode:X});case"recover":return e.jsx(Rh,{state:E,login:p,reach:t.reach(),onRetry:()=>{var gt;(gt=t.recovery())!=null&&gt.again()||t.startRecovery()},onCode:X,onCancel:()=>t.cancelRecovery(),onSignOut:ut,onDone:()=>v(!0),actions:ae?e.jsx(rc,{store:s,fetchImpl:a,body:d.recover.done.notify,onDone:()=>v(!0)}):void 0});case"compare":return e.jsx(wh,{step:D,login:p,pcName:Oe,lost:j,stalled:x==="unpaired"&&D===null&&P,reach:t.reach(),onRetry:Ge,onSame:()=>{var gt;return(gt=t.pairing())==null?void 0:gt.confirmOnPhone()},onCancel:()=>{var gt;return(gt=t.pairing())==null?void 0:gt.cancel()},onRestart:()=>H(()=>t.startPairing()),onDone:()=>v(!0),actions:A?e.jsx(rc,{store:s,fetchImpl:a,onDone:()=>{T(!1),v(!0)}}):e.jsx(Th,{store:s,update:L,onDone:()=>{var gt;lc((gt=u.device)==null?void 0:gt.push)?T(!0):v(!0)}})})}const ze=Ml(Vt([...u.sessions.values()]),u.asks??[]);Le&&ze.some(gt=>JSON.stringify(gt)===JSON.stringify(Le))&&(pe.current=ze);const ht=gt=>()=>{const Bs=Pp(Ml(Vt([...s.getState().sessions.values()]),s.getState().asks??[]),gt,pe.current);fs(Bs??{name:"atoi"})},Nt={pc:rt,look:yf(u.fresh,!!u.syncedAt,t.reach()),reach:t.reach(),since:Be(u.syncedAt),retry:Ge},we=!!((rn=u.daemon)!=null&&rn.forge)&&be!==null,G=we?Dh(yt):0,Ne={atoi:jf(Vt([...u.sessions.values()]),u.asks??[],Od(u.tasks.values())),prs:G?{text:G>99?"99+":String(G),tone:"red"}:null},oe=we?e.jsx($0,{forge:be,store:s}):e.jsx(Xy,{}),qe=we&&m.name==="pr"?e.jsx(dv,{id:m.id,forge:be,store:s,pane:w},m.id):null,st=e.jsx(Rg,{store:s,onReconnect:Ge,forge:be}),$t=e.jsx(H1,{store:s,filter:m.name==="sessions"?m.filter:void 0}),ts=!!((on=u.device)!=null&&on.chat)||!u.fresh&&!u.device,Ps=ts?e.jsx(ac,{store:s,onReconnect:Ge}):e.jsx(oc,{}),Ns=!!((Tn=u.daemon)!=null&&Tn.rigs)&&J!==null,Wt=Ns?e.jsx(PN,{rigs:J,store:s}):e.jsx(Yy,{}),ln=Ns?m.name==="rig"?e.jsx(s0,{rig:m.rig,rigs:J,store:s},m.rig):m.name==="kernel"?e.jsx(p0,{rigs:J,store:s}):m.name==="max"?e.jsx(d0,{goalId:m.goalId,rigs:J,store:s},m.goalId??""):null:null,An=e.jsx(Py,{store:s,fetchImpl:a,login:p,relay:i,pinned:$e,linkState:x,build:h,onSignOut:ut,section:m.name==="connection"?m.section:void 0});if(F){const gt=(()=>{var Oo;switch(m.name){case"atoi":return e.jsx(ss,{list:st,detail:e.jsx(Il,{...d.split.request})});case"ask":return e.jsx(ss,{list:st,detail:e.jsx(dc,{store:s,id:m.id,onDone:ht({name:"ask",id:m.id})},m.id)});case"request":return e.jsx(ss,{list:st,detail:e.jsx(vr,{store:s,sessionId:m.sessionId,requestKey:m.key,onReconnect:Ge,onSettled:ht({name:"request",sessionId:m.sessionId,key:m.key}),keys:!0},m.sessionId)});case"sessions":return e.jsx(ss,{tab:"sessions",list:$t,detail:e.jsx(Il,{...d.split.agent})});case"routines":return e.jsx(ss,{tab:"sessions",list:$t,detail:e.jsx(xi,{store:s,focus:m.routine})});case"thread":return e.jsx(ss,{tab:"sessions",list:$t,detail:e.jsx(Er,{store:s,sessionId:m.sessionId,storage:n,onReconnect:Ge,forge:be},m.sessionId)});case"launch":return e.jsx(ss,{tab:"sessions",list:$t,detail:e.jsx(yc,{store:s,storage:n})});case"terminal":return e.jsx(ss,{tab:"sessions",fold:!0,list:$t,detail:e.jsx(pc,{store:s,link:t,sessionId:m.sessionId,storage:n,forge:be},m.sessionId)});case"prs":case"pr":return e.jsx(ss,{tab:"prs",list:oe,detail:qe??e.jsx(ic,{icon:"pr",...d.prs.pane})});case"rigs":case"rig":case"kernel":case"max":return e.jsx(ss,{list:Wt,detail:ln??e.jsx(ic,{icon:"rigs",...d.rigs.pane})});case"atelier":return(Oo=u.daemon)!=null&&Oo.atelier?e.jsx(R1,{store:s,...m.sessionId?{sessionId:m.sessionId}:{},...m.requestKey?{requestKey:m.requestKey}:{},storage:n,onReconnect:Ge}):e.jsx(ss,{list:$t,detail:e.jsx(Il,{...d.split.agent})});case"chat":return null;case"connection":return An}})(),Bs=V.current&&e.jsx(Qy,{open:w,onClose:()=>I(!1),children:ts?e.jsx(ac,{store:s,onReconnect:Ge,onClose:()=>I(!1)}):e.jsx(oc,{onClose:()=>I(!1)})});return e.jsxs(Ll,{value:Nt,children:[gt,Bs,e.jsx(kf,{route:m,active:ue??"settings",badges:Ne,atelier:!!((_n=u.daemon)!=null&&_n.atelier),ledge:{open:w,onToggle:()=>I(!w)}})]})}const ot=(gt,Bs=!0)=>e.jsxs(Ll,{value:Nt,children:[Bs&&e.jsx(Nf,{...typeof Bs=="string"?{title:Bs}:{}}),gt,e.jsx(vf,{route:m,active:ue??te.current,badges:Ne})]});switch(m.name){case"atoi":return ot(st);case"sessions":case"atelier":return ot($t);case"routines":return ot(e.jsx(xi,{store:s,focus:m.routine},m.routine??""));case"prs":return ot(oe,we?d.prs.title:!0);case"pr":return qe?ot(qe,!1):ot(oe,we?d.prs.title:!0);case"rigs":return ot(Wt,Ns?d.rigs.title:!0);case"rig":case"kernel":case"max":return ln?ot(ln,!1):ot(Wt,Ns?d.rigs.title:!0);case"chat":return ot(Ps,!ts);case"connection":return ot(An,!1);case"thread":return ot(e.jsx(Er,{store:s,sessionId:m.sessionId,storage:n,onReconnect:Ge,forge:be},m.sessionId),!1);case"terminal":return ot(e.jsx(pc,{store:s,link:t,sessionId:m.sessionId,storage:n,forge:be},m.sessionId),!1);case"ask":return ot(e.jsx(dc,{store:s,id:m.id},m.id),!1);case"launch":return e.jsx(Ll,{value:Nt,children:e.jsx(yc,{store:s,storage:n})});case"request":return ot(e.jsx(vr,{store:s,sessionId:m.sessionId,requestKey:m.key,onReconnect:Ge},m.sessionId),!1)}})();return e.jsx(Lm,{copy:Om(c).ui,children:e.jsxs("div",{className:"app flex flex-col","data-route":m.name,children:[$&&x!=="ready"&&e.jsx("p",{role:"status",className:"mx-4 my-3 text-body text-muted",children:d.forget.pending}),Re,l&&g&&g.fingerprint!==y&&e.jsx($N,{next:g,current:h,onLater:()=>k(g.fingerprint),onApply:()=>l.accept()})]})})}const vv=Object.freeze(Object.defineProperty({__proto__:null,App:hv},Symbol.toStringTag,{value:"Module"}));export{vv as A,yv as M,iN as R,Nv as a};