waterplane 0.1.15 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/README.md +2 -0
- package/node_modules/@waterplane/shared/dist/exposure.js +1 -0
- package/node_modules/@waterplane/shared/dist/exposure.js.map +1 -1
- package/node_modules/@waterplane/shared/dist/working.d.ts +18 -0
- package/node_modules/@waterplane/shared/dist/working.js +80 -9
- package/node_modules/@waterplane/shared/dist/working.js.map +1 -1
- package/node_modules/@waterplane/shared/dist/yamlfront.d.ts +8 -0
- package/node_modules/@waterplane/shared/dist/yamlfront.js +23 -5
- package/node_modules/@waterplane/shared/dist/yamlfront.js.map +1 -1
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
- package/packages/host/dist/context.js +15 -5
- package/packages/host/dist/context.js.map +1 -1
- package/packages/web/dist/assets/{demo-TmjAByxC.js → demo-DkCtg-SJ.js} +1 -1
- package/packages/web/dist/assets/{index-CVkUvHP9.js → index-EYc28CfH.js} +1 -1
- package/packages/web/dist/assets/{shared-PjlyyA4P.js → shared-DjRRLGfw.js} +4 -4
- package/packages/web/dist/assets/{sheets-DqpgjB8i.js → sheets-ByWNPa9p.js} +4 -4
- package/packages/web/dist/build-id.txt +1 -1
- package/packages/web/dist/buildstamp.json +1 -1
- package/packages/web/dist/index.html +4 -4
- package/packages/web/dist/sw.js +2 -2
- package/release.json +3 -3
- package/tools/repohealth/lang/typescript-resolve.mjs +4 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{n as e}from"./rolldown-runtime-BpQH8Ho1.js";import{$ as t,$a as n,$c as r,$i as i,$l as a,$n as o,$o as s,$r as c,$s as l,$t as u,A as d,Ac as f,Ai as p,Al as m,An as h,Ao as g,Ar as _,At as v,Ba as y,Bc as b,Bi as x,Bo as S,Br as C,Bt as w,C as T,Ca as E,Ci as D,Cn as O,Cr as k,Cu as A,D as j,Da as M,Dc as N,Di as P,Dl as F,Dn as I,Do as ee,Dr as te,Ds as ne,E as re,Ea as ie,Ec as ae,Ei as oe,El as se,En as ce,Eo as le,Er as ue,Es as de,F as fe,Fa as pe,Fc as me,Fi as he,Fl as ge,Fn as _e,Fo as ve,Fr as ye,Ft as be,Ga as xe,Gc as Se,Gi as Ce,Gn as we,Go as Te,Gr as Ee,Gs as De,Gt as Oe,Ha as ke,Hc as Ae,Hn as je,Ho as Me,Hr as Ne,Hs as Pe,Ht as Fe,Ia as Ie,Ic as Le,Ii as Re,Il as ze,In as Be,Io as Ve,Ir as He,It as Ue,Ja as We,Jc as Ge,Ji as Ke,Jl as qe,Jn as Je,Jo as Ye,Jr as Xe,Jt as Ze,K as Qe,Ka as $e,Kc as et,Kl as tt,Kn as nt,Ko as rt,Kr as it,Ks as at,Kt as ot,L as st,La as ct,Lc as lt,Li as ut,Ll as dt,Ln as ft,Lo as pt,Lr as mt,Lt as ht,M as gt,Mc as _t,Mi as vt,Ml as yt,Mn as bt,Mo as xt,Mr as St,Mt as Ct,N as wt,Nc as Tt,Ni as Et,Nl as Dt,Nn as Ot,No as kt,Nr as At,Ns as jt,Nt as Mt,O as Nt,Oc as Pt,Oi as Ft,On as It,Oo as Lt,Or as Rt,Ot as zt,P as Bt,Pc as Vt,Pi as Ht,Pl as Ut,Pn as Wt,Po as Gt,Pr as Kt,Pt as qt,Q as Jt,Qa as Yt,Qc as Xt,Qi as Zt,Ql as Qt,Qn as $t,Qo as en,Qr as tn,Qs as nn,Qt as rn,R as an,Rc as eee,Ri as on,Rl as sn,Rn as tee,Ro as cn,Rr as nee,Rs as ln,Rt as un,S as dn,Sa as ree,Sc as fn,Si as pn,Sl as iee,Sn as mn,Sr as hn,Su as gn,Ta as _n,Tc as vn,Ti as yn,Tl as aee,Tn as bn,Tr as xn,Tt as oee,Tu as Sn,U as Cn,Ua as wn,Uc as Tn,Ur as En,Us as Dn,Ut as On,Va as see,Vc as cee,Vl as kn,Vo as An,Vr as lee,Vs as jn,Vt as Mn,W as Nn,Wa as Pn,Wc as Fn,Wi as In,Wl as Ln,Wn as Rn,Wo as zn,Wr as Bn,Ws as Vn,Wt as uee,X as dee,Xa as Hn,Xc as Un,Xo as Wn,Xr as fee,Xs as Gn,Xt as pee,Y as Kn,Ya as mee,Yc as qn,Yl as hee,Yn as Jn,Yo as Yn,Ys as gee,Z as Xn,Za as Zn,Zc as Qn,Zi as $n,Zl as er,Zn as tr,Zo as nr,Zr as rr,Zs as ir,Zt as ar,_ as or,_a as sr,_c as cr,_i as lr,_l as _ee,_n as vee,_o as yee,_r as ur,_s as dr,_t as bee,_u as fr,a as pr,aa as xee,ac as L,ai as mr,al as hr,an as See,ao as Cee,ar as wee,as as gr,au as _r,b as Tee,ba as vr,bc as yr,bi as br,bl as Eee,bn as Dee,bo as Oee,br as kee,bu as Aee,c as jee,ca as xr,ci as Mee,cl as Sr,cn as Nee,co as Pee,cr as Cr,cs as Fee,cu as Iee,d as Lee,da as Ree,dc as wr,di as zee,dl as Bee,dn as Tr,do as Er,dr as Dr,ds as Or,dt as kr,du as Ar,ea as jr,ec as Mr,ei as Nr,el as Pr,en as Fr,eo as Ir,er as Lr,et as Rr,fa as zr,fc as Br,fi as Vr,fl as Hr,fn as Ur,fo as Wr,fr as Gr,fs as Kr,fu as qr,g as Jr,ga as Yr,gi as Xr,gl as Zr,gn as Vee,go as Hee,gr as Qr,gs as $r,gt as Uee,gu as Wee,h as ei,ha as Gee,hc as ti,hi as Kee,hl as qee,hn as ni,ho as Jee,hr as Yee,hs as Xee,ht as Zee,hu as ri,i as Qee,ia as ii,ic as ai,ii as $ee,il as oi,in as ete,ir as si,is as tte,it as nte,iu as ci,ja as rte,jc as li,ji as ui,jl as di,jo as ite,jr as fi,jt as ate,k as ote,kc as pi,ki as ste,kn as mi,ko as cte,kr as hi,kt as gi,lc as _i,li as lte,ll as vi,ln as ute,lo as dte,lr as fte,lu as pte,m as mte,ma as yi,mc as bi,mi as hte,ml as gte,mn as _te,mr as vte,ms as xi,mt as yte,mu as Si,n as bte,na as Ci,nc as xte,ni as Ste,nl as wi,nn as Ti,no as Ei,nr as Cte,nt as wte,nu as Tte,o as Di,oa as Oi,oc as ki,oi as Ete,ol as Dte,on as Ai,oo as ji,or as Ote,os as Mi,ot as kte,ou as Ate,p as jte,pa as Ni,pc as Mte,pi as Nte,pl as Pte,pn as Fte,po as Ite,pr as Lte,ps as Pi,pt as Rte,pu as zte,q as Bte,qa as Vte,qc as Fi,ql as Ii,qn as Hte,qo as Li,qr as Ute,qt as Wte,r as Ri,ra as Gte,rc as zi,ri as Bi,rl as Vi,rn as Hi,rr as Ui,rt as Wi,ru as Gi,s as Ki,sa as qi,sc as Ji,si as Yi,sl as Xi,sn as Zi,so as Qi,sr as $i,st as ea,su as ta,ta as na,tc as ra,ti as ia,tl as R,tn as aa,tr as oa,ts as sa,tt as ca,u as la,ua,ui as da,ul as fa,un as pa,uo as ma,ur as ha,us as ga,ut as _a,uu as va,v as ya,va as ba,vi as xa,vl as Sa,vn as Ca,vo as wa,vr as Ta,vt as Ea,vu as Da,w as Oa,wa as ka,wc as Aa,wi as ja,wl as Ma,wn as Na,wr as Pa,wt as Fa,wu as Ia,x as La,xa as Ra,xc as za,xi as Ba,xl as Va,xn as Ha,xr as Kte,xu as qte,y as Jte,ya as Ua,yc as Wa,yi as Ga,yl as Yte,yn as Xte,yo as Zte,yr as Qte,yu as Ka,z as $te,za as qa,zc as Ja,zi as ene,zl as tne,zn as Ya,zo as Xa,zr as nne,zt as rne}from"./shared-PjlyyA4P.js";import{C as Za,D as ine,E as ane,O as one,S as Qa,T as $a,_ as eo,b as z,c as to,d as sne,f as no,g as cne,h as ro,i as lne,m as B,o as une,r as dne,s as fne,u as pne,v as io,w as ao,x as oo,y as so}from"./demo-TmjAByxC.js";import{i as mne,r as hne,t as gne}from"./react-CoSyT_xY.js";import{$ as co,$i as lo,$n as _ne,$r as uo,$t as vne,A as fo,Ai as po,An as yne,Ar as mo,At as ho,B as go,Bi as _o,Bn as bne,Br as xne,Bt as vo,C as Sne,Ci as yo,Cr as Cne,Ct as bo,D as xo,Di as So,Dn as Co,Dr as wne,Dt as Tne,E as Ene,Ei as wo,En as To,Er as Dne,Et as Eo,F as Do,Fi as Oo,Fn as ko,Fr as Ao,Ft as One,G as jo,Gi as Mo,Gn as No,Gt as Po,H as Fo,Hi as Io,Hn as kne,Hr as Lo,Ht as Ro,I as zo,Ii as Bo,In as Vo,Ir as Ane,It as Ho,Ji as jne,Jn as Mne,Jr as Uo,Jt as Nne,K as Wo,Ki as Go,Kn as Ko,Kr as qo,Kt as Pne,L as Jo,Ln as Yo,Lr as Fne,Lt as Xo,M as Zo,Mi as Qo,Mn as Ine,Mr as $o,Mt as es,N as Lne,Ni as ts,Nn as ns,Nr as rs,Nt as Rne,Oi as is,On as zne,Or as as,Ot as os,Pi as ss,Pn as cs,Pr as ls,Pt as us,Q as ds,Qi as fs,Qn as ps,Qr as ms,Qt as hs,Ri as gs,Rn as _s,Rr as vs,Rt as Bne,S as Vne,Si as ys,Sn as bs,Sr as Hne,St as xs,T as Une,Ti as Ss,Tn as Cs,Tr as Wne,Tt as ws,U as Gne,Ui as Ts,Un as Es,Ur as Ds,Ut as Kne,V as Os,Vi as ks,Vn as As,Vr as js,Vt as Ms,Wi as qne,Wn as Ns,Wr as Ps,Wt as Fs,X as Is,Xn as Ls,Xr as Rs,Xt as zs,Yi as Bs,Yn as Vs,Yr as Hs,Z as Us,Zi as Ws,Zn as Gs,Zr as Ks,Zt as qs,_ as Js,_i as Ys,_n as Xs,_r as Zs,_t as Qs,a as $s,ai as ec,an as tc,ar as nc,at as rc,b as ic,bi as ac,bn as oc,br as sc,bt as cc,c as lc,ci as uc,cn as dc,ct as fc,d as pc,dn as mc,dr as hc,dt as gc,ea as _c,ei as vc,en as yc,er as bc,et as xc,f as Sc,fi as Cc,fn as wc,fr as Tc,ft as Ec,g as Dc,gr as Oc,gt as kc,h as Ac,hn as jc,hr as Mc,ht as Nc,i as V,ii as Pc,in as Fc,ir as Ic,it as Lc,j as Rc,ji as zc,jn as Bc,jr as Vc,jt as Hc,ki as Uc,kn as Wc,kr as Gc,kt as Kc,l as qc,li as Jc,lr as Yc,lt as Xc,mn as Zc,mr as Qc,mt as $c,n as el,na as tl,ni as nl,nn as rl,nr as il,nt as al,o as ol,oi as sl,or as cl,ot as ll,p as Jne,pi as Yne,pn as ul,pr as dl,pt as fl,q as Xne,qi as pl,qn as Zne,qt as ml,ra as hl,ri as gl,rn as Qne,rr as $ne,rt as _l,s as vl,si as yl,sn as bl,sr as xl,st as ere,t as tre,ta as Sl,ti as Cl,tn as nre,tr as wl,tt as Tl,u as El,ui as Dl,un as Ol,ur as rre,ut as kl,v as Al,vi as jl,vn as Ml,vr as Nl,vt as Pl,w as Fl,wi as Il,wn as Ll,wr as ire,wt as Rl,x as zl,xi as Bl,xn as Vl,xr as are,xt as ore,y as sre,yi as Hl,yn as Ul,yr as cre,yt as Wl,z as Gl,zn as Kl,zr as lre,zt as ql}from"./icons-B48F-4nA.js";import{t as ure}from"./vendor-BPwPmufs.js";function dre(e){if(e===B.syncTs)return!0;if(!e.startsWith(xr))return!1;let t=e.slice(xr.length),n=t.indexOf(`.`);return n>0&&`${L.storagePrefix}${t.slice(n+1)}`===B.syncTs}function fre(e){let t;try{t=JSON.parse(e)}catch{return e}if(!t||typeof t!=`object`||Array.isArray(t))return e;let n={},r=t;for(let[e,t]of Object.entries(r))re(e)===null&&(n[e]=t);for(let[e,t]of Object.entries(r)){let r=re(e);r!==null&&!(r in n)&&(n[r]=t)}return JSON.stringify(n)}function pre(e,t){let n=j(e,t);for(let[,t]of n.copied){if(!dre(t))continue;let n=e.getItem(t);n!==null&&e.setItem(t,fre(n))}return n}function mre(){try{let e=globalThis.localStorage;if(!e)return;let t=pre(e,Date.now());t.ran&&(t.copied.length||t.kept.length)&&console.info(`[storage] copied ${t.copied.length} keys from an older name, kept ${t.kept.length} newer ones`)}catch{}}function Jl(){try{let e=JSON.parse(globalThis.localStorage?.getItem(B.brandStores)??`[]`);return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}catch{return[]}}function Yl(e){try{let t=Jl();t.includes(e)||globalThis.localStorage?.setItem(B.brandStores,JSON.stringify([...t,e]))}catch{}}var hre=[`uploads`,`dictations`,`screenlog`,`pulls`];function gre(e){return new Promise(t=>{try{let n=indexedDB.open(e);n.onupgradeneeded=()=>{try{n.transaction?.abort()}catch{}},n.onsuccess=()=>t(n.result),n.onerror=e=>{e.preventDefault?.(),t(null)},n.onblocked=()=>t(null)}catch{t(null)}})}function _re(e,t){return new Promise(n=>{try{let r=e.transaction(t,`readonly`),i=r.objectStore(t),a=i.getAllKeys(),o=i.getAll();r.oncomplete=()=>n({keys:a.result,values:o.result}),r.onerror=()=>n(null),r.onabort=()=>n(null)}catch{n(null)}})}function vre(e,t,n,r){return new Promise(i=>{try{let a=e.transaction(t,`readwrite`),o=a.objectStore(t),s=o.getAllKeys();s.onsuccess=()=>{let e=new Set(s.result.map(e=>JSON.stringify(e)));n.forEach((t,n)=>{e.has(JSON.stringify(t))||o.put(r[n],t)})},a.oncomplete=()=>i(!0),a.onerror=()=>i(!1),a.onabort=()=>i(!1)}catch{i(!1)}})}async function yre(e,t){let n=`idb:${e.name}`;if(typeof indexedDB>`u`||Jl().includes(n))return;let r=!0;for(let n of t){if(n===e.name)continue;let t=await gre(n);if(t)try{for(let n of hre){if(!t.objectStoreNames.contains(n)||!e.objectStoreNames.contains(n))continue;let i=await _re(t,n);i?i.keys.length&&!await vre(e,n,i.keys,i.values)&&(r=!1):r=!1}}finally{t.close()}}r&&Yl(n)}var Xl=e=>`${e}-pulls-v1`,Zl=Xl(L.slug),Ql=ki.map(e=>Xl(e.slug)),bre=[Zl,...Ql],$l=null;function xre(){return $l||=(async()=>{let e=`cache:${Zl}`;if(!(typeof caches>`u`||Jl().includes(e))){for(let e of Ql){if(!await caches.has(e))continue;let t=await caches.open(e),n=await caches.open(Zl);for(let e of await t.keys()){if(await n.match(e))continue;let r=await t.match(e);r&&await n.put(e,r)}}Yl(e)}})().catch(()=>{}),$l}function eu(){try{return globalThis.localStorage??null}catch{return null}}function tu(e){let t=[];for(let n=0;n<e.length;n++){let r=e.key(n);r!=null&&t.push(r)}return t}function nu(e){if(!e)return null;try{let t=JSON.parse(e),n=e=>yi(e)?e:null;if(!t||typeof t!=`object`)return null;let r={from:n(t.from),to:n(t.to)};return yi(t.drop)&&(r.drop=t.drop),t.parked===!0&&(r.parked=!0),r}catch{return null}}function ru(e){return Ra(e.getItem(B.hosts))??[]}function iu(e){return Ra(e.getItem(B.hostsGone))??[]}function au(e){let t=e.getItem(B.hostActive);return t&&ru(e).some(e=>e.id===t)?t:null}function ou(e){let t=e.getItem(B.hostActive);return ru(e).find(e=>e.id===t)??null}function su(e,t){for(let n of t){if(n.op===`remove`){e.removeItem(n.key);continue}let t=e.getItem(n.from);t!==null&&e.setItem(n.to,t)}}function Sre(e,t,n){for(let r of tu(e)){let i=ua(r,t);if(!i||eo(i)||n&&e.getItem(i)!==null)continue;let a=e.getItem(r);a!==null&&e.setItem(i,a)}}function cu(e){let t=nu(e.getItem(B.hostSwitch));if(!t)return e.getItem(B.hostSwitch)!==null&&e.removeItem(B.hostSwitch),!1;let n=ru(e),r=e.getItem(B.hostActive),i=t.to&&n.some(e=>e.id===t.to)?t.to:null;if(t.from!==null&&r===t.from){let n=E(tu(e),eo,t.from,i??`-`),r=Ua(i??`-`),a=Ua(t.from),o=e=>e.op===`copy`&&e.from.startsWith(r),s=e=>e.op===`copy`&&!o(e)||e.op===`remove`&&e.key.startsWith(a),c=e=>e.op===`remove`&&!e.key.startsWith(a);t.parked||(su(e,n.filter(s)),e.setItem(B.hostSwitch,JSON.stringify({...t,parked:!0}))),su(e,n.filter(c)),i?e.setItem(B.hostActive,i):e.removeItem(B.hostActive),su(e,n.filter(o))}else(t.from===null||r===i)&&i&&(e.setItem(B.hostActive,i),Sre(e,i,t.from===null));if(t.drop&&t.drop!==e.getItem(B.hostActive)){let n=ru(e),r=n.find(e=>e.id===t.drop);r&&(e.setItem(B.hosts,ka(n.filter(e=>e.id!==t.drop))),e.setItem(B.hostsGone,ka([r,...iu(e).filter(e=>e.id!==r.id)])))}let a=ou(e);return a?e.setItem(B.hostBase,a.base):e.removeItem(B.hostBase),e.removeItem(B.hostSwitch),!0}function Cre(e){if(e){try{cu(e)}catch(t){try{wre(t)&&Ere(e)}catch{}}try{Mre(e);let t=ree({hosts:e.getItem(B.hosts),active:e.getItem(B.hostActive),hostBase:e.getItem(B.hostBase)});t.writes.hosts!==void 0&&e.setItem(B.hosts,t.writes.hosts),t.writes.active!==void 0&&e.setItem(B.hostActive,t.writes.active),t.writes.hostBase!==void 0&&e.setItem(B.hostBase,t.writes.hostBase)}catch{}}}function wre(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.name===`QuotaExceededError`||t.name===`NS_ERROR_DOM_QUOTA_REACHED`||t.code===22||t.code===1014}function Tre(e,t){let n=e.length>1?e.find(e=>e.id===t)?.name:void 0;return n?` — ${n} is not answering`:` — the connection may be down`}function Ere(e){let t=nu(e.getItem(B.hostSwitch));if(!t)return;let n=e.getItem(B.hostActive),r;if(t.from!==null&&n===t.from&&!t.parked){for(let n of tu(e)){let r=ua(n,t.from);r&&e.getItem(r)!==null&&e.removeItem(n)}e.removeItem(B.hostSwitch),r=`park`}else if(t.to!==null&&n===t.to)r=`restore`;else return;let i={stage:r,from:t.from,to:t.to,at:Date.now()};e.setItem(B.hostSwitchFailed,JSON.stringify(i))}function Dre(e){if(!e)return null;let t=e.getItem(B.hostSwitchFailed);if(t===null)return null;try{e.removeItem(B.hostSwitchFailed)}catch{}try{let e=JSON.parse(t);if(e.stage!==`park`&&e.stage!==`restore`)return null;let n=e=>yi(e)?e:null;return{stage:e.stage,from:n(e.from),to:n(e.to),at:typeof e.at==`number`?e.at:0}}catch{return null}}function lu(e){return!e||!e.base?null:Ree({base:e.base,ssids:e.ssids??[],auto:e.auto===!0})}function uu(e,t){let n=_n(t.base);if(!n)return{ok:!1,why:`Not an address. Use a host name or IP, optionally with a port.`};let r=ru(e);if(r.some(e=>e.base===n))return{ok:!1,why:`That address is already in the list.`};let i=iu(e),a=i.find(e=>e.base===n),o={id:a?.id??Yr([...r,...i].map(e=>e.id)),name:sr(t.name)??a?.name??Ni(n),base:n};a?.legacy&&!r.some(e=>e.legacy)&&(o.legacy=!0);let s=lu(t.lan);return s&&(o.lan=s),e.setItem(B.hosts,ka([...r,o])),a&&e.setItem(B.hostsGone,ka(i.filter(e=>e.id!==a.id))),{ok:!0,host:o,reused:!!a}}function du(e,t,n){let r=ru(e),i=r.findIndex(e=>e.id===t);if(i<0)return{ok:!1,why:`That host is no longer in the list.`};let a=_n(n.base);if(!a)return{ok:!1,why:`Not an address. Use a host name or IP, optionally with a port.`};if(r.some(e=>e.id!==t&&e.base===a))return{ok:!1,why:`Another host already has that address.`};let o=r[i],s={id:t,name:sr(n.name)??Ni(a),base:a};o.legacy&&(s.legacy=!0);let c=n.lan===void 0?o.lan??null:lu(n.lan);c&&(s.lan=c);let l=r.slice();return l[i]=s,e.setItem(B.hosts,ka(l)),e.getItem(B.hostActive)===t&&e.setItem(B.hostBase,a),{ok:!0,host:s,reused:!1}}function Ore(e,t){let n=ru(e);return n.some(e=>e.id===t)?e.getItem(B.hostActive)===t?{kind:`switch`,next:n.find(e=>e.id!==t)?.id??null}:{kind:`drop`}:null}function kre(e,t){if(e.getItem(B.hostActive)===t)return!1;let n=ru(e),r=n.find(e=>e.id===t);return r?(e.setItem(B.hosts,ka(n.filter(e=>e.id!==t))),e.setItem(B.hostsGone,ka([r,...iu(e).filter(e=>e.id!==t)])),!0):!1}function fu(e,t){t.from===`demohost`&&e.removeItem(B.demo),e.setItem(B.hostSwitch,JSON.stringify(t))}function pu(){try{history.replaceState(null,``,location.pathname)}catch{}location.reload()}function mu(e){let t=eu();if(!t)return!1;let n=t.getItem(B.hostActive);return n===e||!ru(t).some(t=>t.id===e)?!1:(fu(t,{from:yi(n)?n:null,to:e}),pu(),!0)}function Are(e){let t=eu();if(!t)return null;let n=Ore(t,e);return n?n.kind===`drop`?kre(t,e)?`dropped`:null:(fu(t,{from:e,to:n.next,drop:e}),pu(),`switching`):null}function hu(e){let t=eu();if(!t)return{ok:!1,why:`This phone's storage is not available.`};let n=uu(t,e);if(!n.ok)return n;let r=t.getItem(B.hostActive);return fu(t,{from:yi(r)&&ru(t).some(e=>e.id===r)?r:null,to:n.host.id}),pu(),n}function gu(){let e=eu();return e?ru(e):[]}function _u(){let e=eu();return e?ou(e):null}var vu=`demohost`,jre=`http://demo.invalid:8770`;function yu(e){return(typeof e==`string`?e:e?.id)===vu}function bu(e){return e.filter(e=>!yu(e))}function xu(e){let t=bu(ru(e)),n=e.getItem(B.demoReturn);return t.find(e=>e.id===n)?.id??t[0]?.id??null}function Mre(e){if(e.getItem(B.hostActive)===`demohost`&&!e.getItem(B.demo)&&(fu(e,{from:vu,to:xu(e)}),cu(e)),e.getItem(B.hostActive)===`demohost`)return;e.removeItem(B.demo);let t=ru(e);t.some(yu)&&e.setItem(B.hosts,ka(bu(t)));let n=iu(e);n.some(yu)&&e.setItem(B.hostsGone,ka(bu(n)));let r=Ua(vu);for(let t of tu(e))t.startsWith(r)&&e.removeItem(t)}function Nre(e,t){let n=e.getItem(B.hostActive);if(n===`demohost`)return!1;let r=ru(e);r.some(yu)||e.setItem(B.hosts,ka([...r,{id:vu,name:`Demo`,base:jre}]));let i=yi(n)&&r.some(e=>e.id===n)?n:null;return i?e.setItem(B.demoReturn,i):e.removeItem(B.demoReturn),e.setItem(B.demo,t),fu(e,{from:i,to:vu}),!0}function Pre(e){e.removeItem(B.demo),e.getItem(B.hostActive)===`demohost`&&fu(e,{from:vu,to:xu(e)})}function Fre(e){let t=eu();if(!t)return!1;try{globalThis.sessionStorage?.removeItem(ro(e))}catch{}if(!Nre(t,e))return!1;try{history.replaceState(null,``,location.pathname)}catch{}return location.reload(),!0}function Ire(){let e=eu();if(!e)return!1;let t=e.getItem(B.demo);try{t&&globalThis.sessionStorage?.removeItem(ro(t))}catch{}Pre(e);try{history.replaceState(null,``,location.pathname)}catch{}return location.reload(),!0}var Lre=L.wsProtocol,Rre=`${L.wsProtocol}-tok.`;function Su(e){return!!e&&/^[A-Za-z0-9_-]{16,256}$/.test(e)}function Cu(e){return typeof e==`string`&&Su(e)}function wu(){let e=z(B.deviceToken);return Su(e)?e:null}function zre(e){Su(e)&&Za(B.deviceToken,e)}function Tu(){so(B.deviceToken)}function Bre(e,t,n){if(!n||!t)return null;try{return new URL(e).origin===new URL(t).origin?`Bearer ${n}`:null}catch{return null}}function Vre(e){return e?[Lre,`${Rre}${e}`]:void 0}function Eu(e,t){return(e.trim()||t.trim()||`Android phone`).slice(0,60)}var Du=null;function Hre(e){Du=e}function Ou(e){try{Du?.(e)}catch{}}var Ure=B.hostBase;function ku(){let e=globalThis.Capacitor;try{return!!e?.isNativePlatform?.()}catch{return!1}}var Au,ju=null;function Wre(e,t,n){let r=t?Ra(e)?.find(e=>e.id===t):void 0;return r&&_n(r.base)||_n(n||``)}function Mu(){return Au===void 0&&(Au=null,ku()&&(Au=Wre(z(B.hosts),z(B.hostActive),z(Ure)))),Au}function Nu(){let e=Mu();return e===null?null:ju??e}function Pu(e){if(!ku()||Mu()===null)return ju=null,null;let t=e===null?null:_n(e);return ju=t&&t!==Mu()?t:null,Nu()}function Fu(){return ju}function Gre(){return no()?!0:!ku()||Nu()!==null}function Iu(e){return no()?une(e):ie(Mu(),e)}function Lu(){if(no())return fne;let e=Nu();return e?M(e,`/ws`):ku()?null:`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/ws`}var Ru=!1;function Kre(){if(Ru||no()||!Nu())return;Ru=!0;let e=()=>Nu()??``,t=globalThis.fetch.bind(globalThis),n=e=>Bre(e,Nu(),wu()),r=(e,t)=>t?e.then(e=>(e.status===401&&Ou(`http`),e)):e,i=(e,t)=>{if(!t)return e;let n=new Headers(e?.headers);return n.has(`authorization`)?e:(n.set(`authorization`,t),{...e,headers:n})};globalThis.fetch=((a,o)=>{if(typeof a!=`string`&&!(a instanceof URL)){let i=zu(a.url),s=i===null?a:new Request(ie(e(),i),a),c=n(s.url);if(c&&!s.headers.has(`authorization`))try{s.headers.set(`authorization`,c)}catch{}return r(t(s,o),c)}let s=String(a),c=s.startsWith(`/`)?s:zu(s);if(c===null){let e=n(s);return r(t(a,i(o,e)),e)}let l=ie(e(),c);if(l===c&&c===s)return t(a,o);let u=n(l);return r(t(l,i({credentials:`include`,...o},u)),u)});let a=XMLHttpRequest.prototype.open;if(XMLHttpRequest.prototype.open=function(t,r,...i){let o=String(r),s=o.startsWith(`/`)?o:zu(o),c=s===null?o:ie(e(),s),l=a.call(this,t,c,...i),u=n(c);if(u)try{this.setRequestHeader(`authorization`,u),this.addEventListener(`load`,()=>{this.status===401&&Ou(`http`)},{once:!0})}catch{}return l},qre(),typeof navigator<`u`&&typeof navigator.sendBeacon==`function`){let e=navigator.sendBeacon.bind(navigator);navigator.sendBeacon=((t,n)=>{let r=String(t),i=r.startsWith(`/`)?r:zu(r);return e(i===null?r:ie(Mu()??``,i),n)})}}function qre(){let e=e=>{let t=Mu(),n=Nu();return!!t&&e.startsWith(t)||!!n&&e.startsWith(n)},t=(t,n,r)=>(n===`src`||n===`poster`)&&(t instanceof HTMLImageElement||t instanceof HTMLVideoElement)&&typeof r==`string`&&e(r);try{let e=Element.prototype.setAttribute;Element.prototype.setAttribute=function(n,r){if(t(this,n,r)&&!this.crossOrigin)try{this.crossOrigin=`anonymous`}catch{}return e.call(this,n,r)};for(let e of[HTMLImageElement.prototype,HTMLVideoElement.prototype]){let n=Object.getOwnPropertyDescriptor(e,`src`);n?.set&&n.get&&Object.defineProperty(e,"src",{configurable:!0,enumerable:n.enumerable,get:n.get,set(e){if(t(this,`src`,e)&&!this.crossOrigin)try{this.crossOrigin=`anonymous`}catch{}n.set.call(this,e)}})}}catch{}}function zu(e){try{let t=new URL(e,location.href);return t.origin===location.origin?`${t.pathname}${t.search}${t.hash}`:null}catch{return null}}var H=mne(),Jre=[{label:`smaller`,value:.9},{label:`default`,value:1},{label:`larger`,value:1.15},{label:`largest`,value:1.3},{label:`huge`,value:1.45}],Yre=[{label:`smaller`,value:.9},{label:`default`,value:1},{label:`larger`,value:1.2},{label:`largest`,value:1.4}],Xre=.9,Zre=1.45,Qre=.9,$re=1.4;function Bu(e,t,n){let r=Number(e);return e===null||e.trim()===``||!Number.isFinite(r)?1:Math.min(n,Math.max(t,r))}var eie=[.6,.7,.8,.9,1,1.15,1.3,1.5],Vu=.6,Hu=1.5;function Uu(e,t){let n=Math.round(13*e*t);return Number.isFinite(n)?Math.min(28,Math.max(7,n)):13}function Wu(e,t,n){let r=eie,i=0;for(let t=1;t<r.length;t++)Math.abs(r[t]-e)<Math.abs(r[i]-e)&&(i=t);let a=n(e);for(let e=i+t;e>=0&&e<r.length;e+=t)if(n(r[e])!==a)return r[e];return null}var tie=(e,t,n)=>Wu(e,t,e=>Uu(n,e)),nie=.6,rie=1.9;function Gu(e,t){let n=e*t;return Number.isFinite(n)?Math.round(Math.min(rie,Math.max(nie,n))*100)/100:1}var Ku=(e,t,n)=>Wu(e,t,e=>Gu(n,e)),qu=()=>Bu(z(B.textScale),Xre,Zre),Ju=()=>Bu(z(B.iconScale),Qre,$re),Yu=()=>Bu(z(B.termZoom),Vu,Hu),iie=()=>Uu(qu(),Yu()),aie=()=>Bu(z(B.readerZoom),Vu,Hu),oie=()=>Bu(z(B.scrollZoom),Vu,Hu),sie=()=>Bu(z(B.gitZoom),Vu,Hu),Xu=`app:uiscale`;function Zu(){let e=document.documentElement;e.style.setProperty(`--ui-font`,String(qu())),e.style.setProperty(`--ui-icon`,String(Ju()));try{window.dispatchEvent(new CustomEvent(Xu))}catch{}}function cie(e){Za(B.textScale,String(e)),Zu()}function lie(e){Za(B.iconScale,String(e)),Zu()}function uie(e){Za(B.termZoom,String(e)),Zu()}function die(e){Za(B.readerZoom,String(e)),Zu()}function fie(e){Za(B.scrollZoom,String(e)),Zu()}function pie(e){Za(B.gitZoom,String(e)),Zu()}function mie(){Zu()}function hie(e){return window.addEventListener(Xu,e),()=>window.removeEventListener(Xu,e)}var Qu=`theme-overlay`,$u={},ed=null,td=new Set,nd=()=>$u,rd=()=>$u.displayName??L.name;function gie(e){return td.add(e),()=>{td.delete(e)}}function id(e){ed=e||null;try{document.title=ed?`${ed} — ${rd()}`:rd()}catch{}}function ad(e){try{let t=document.getElementById(Qu);if(!e){t?.remove();return}t||(t=document.createElement(`style`),t.id=Qu,document.head.appendChild(t)),t.textContent!==e&&(t.textContent=e)}catch{}}function od(e,t=!0){let{overlay:n}=Ki(e),r=Lee(n),i=r?{}:n,a=la(i);if(ad(a),t&&(r?(so(B.themeOverlay),so(B.themeOverlayCss)):(Za(B.themeOverlay,JSON.stringify(i)),a?Za(B.themeOverlayCss,a):so(B.themeOverlayCss))),JSON.stringify(i)===JSON.stringify($u))return!1;$u=i,id(ed);for(let e of td)try{e()}catch{}return!0}function _ie(){let e=oo(B.themeOverlay,void 0);e===void 0?ad(``):od(e,!1)}async function vie(e){try{let t=await e(`/api/theme`);t&&typeof t==`object`&&`overlay`in t&&od(t.overlay)}catch{}}var sd=new Map,cd=new Set,ld=!1;function ud(e){let t=sd.get(e);return t||(t={wroteAt:null,ackedAt:null,superseded:!1},sd.set(e,t)),t}function dd(){for(let e of cd)e()}function fd(e){return cd.add(e),()=>{cd.delete(e)}}function pd(e,t){let n=ud(e);n.wroteAt=t,n.superseded=!1,dd()}function md(e,t){let n=ud(e);n.ackedAt!=null&&n.ackedAt>=t||(n.ackedAt=t,n.superseded=!1,dd())}function hd(e,t){let n=ud(e);n.ackedAt=t,n.superseded=!0,dd()}function yie(e){ld!==e&&(ld=e,dd())}function gd(e){let t=sd.get(e);if(!t||t.wroteAt==null&&t.ackedAt==null)return{phase:`unknown`,wroteAt:null,ackedAt:null};let n={wroteAt:t.wroteAt,ackedAt:t.ackedAt};return t.superseded?{phase:`superseded`,...n}:t.wroteAt==null||t.ackedAt!=null&&t.ackedAt>=t.wroteAt?{phase:`synced`,...n}:{phase:ld?`pending`:`offline`,...n}}var _d={failed:5,superseded:4,pending:3,offline:2,synced:1,unknown:0};function bie(e){let t={phase:`unknown`,wroteAt:null,ackedAt:null};for(let n of e){let e=gd(n);_d[e.phase]>_d[t.phase]&&(t=e)}return t}function vd(e,t=`these`,n=!0){let r=n?`are`:`is`,i=n?`were`:`was`;switch(e.phase){case`synced`:return`saved on the desktop — ${t} ${r} on more than this phone`;case`pending`:return`not on the desktop yet — ${t} ${r} still only on this phone`;case`offline`:return`no connection — ${t} ${r} only on this phone until the link is back`;case`superseded`:return`another device wrote a newer version — ${t} ${i} replaced, and nothing of yours was deleted`;case`failed`:return`the send gave up — ${t} never reached the desktop, and the words are still here`;default:return null}}function yd(e){return e.failed?`failed`:e.queued?e.online?`pending`:`offline`:e.onHost?`synced`:`unknown`}function bd(e){switch(e){case`synced`:return`on desktop`;case`pending`:return`queued`;case`offline`:return`queued · offline`;case`superseded`:return`replaced`;case`failed`:return`not sent`;default:return null}}function xd(e,t=!1){return t&&e===`synced`?null:bd(e)}function xie(e){let t=e.filter(e=>e!==`unknown`).length,n=e.filter(e=>e===`synced`).length;if(n===0)return null;let r=bd(`synced`),i=n===t,a=i?t===1?`the one row here`:`all ${t} rows here`:`${n} of the ${t} rows here`;return{word:i?r:`${n} of ${t} ${r}`,title:vd({phase:`synced`,wroteAt:null,ackedAt:null},a,i?t!==1:n!==1)}}function Sie(e){let t=0;for(let n of e){let e=gd(n).phase;(e===`pending`||e===`offline`)&&t++}return t}function Cie(e,t,n){return e&&t!==n}function wie(e,t,n){if(t===void 0||!n)return null;let r;try{r=n(t,e)}catch{return null}return typeof r!=`string`||r===e?null:r}var Tie=6e4,Eie=3e3,Die=864e5,Sd=B.netlog,Cd=B.deviceId;function wd(e){return{since:e,rtt:[],send:[],reconnects:0,reloads:0,offlineMs:0,markTs:e,online:!1,sent:0,failed:0,expired:0,ackTimeouts:0,queuedMaxMs:0}}function Oie(){let e=Date.now(),t={v:2,log:wd(e),sync:{lastSeenAt:0,parts:{sessions:0,repos:0}},traffic:{since:e,up:0,down:0}},n=z(Sd);if(!n)return Ed(t);let r;try{r=JSON.parse(n)}catch{return t}let i=r;return!i||typeof i!=`object`?t:i.v===2?{v:2,log:Td(i.log??{},e),sync:{lastSeenAt:Number(i.sync?.lastSeenAt)||0,parts:{sessions:Number(i.sync?.parts?.sessions)||0,repos:Number(i.sync?.parts?.repos)||0}},traffic:{since:Number(i.traffic?.since)||e,up:Math.max(0,i.traffic?.up||0),down:Math.max(0,i.traffic?.down||0)}}:Ed({...t,log:Td(i,e)})}function Td(e,t){return typeof e.since!=`number`||t-e.since>Die?wd(t):{...wd(t),...e,rtt:Array.isArray(e.rtt)?e.rtt:[],send:Array.isArray(e.send)?e.send:[]}}function Ed(e){try{let t=z(B.netSync);if(t){let n=JSON.parse(t);n&&typeof n.lastSeenAt==`number`&&(e.sync={lastSeenAt:n.lastSeenAt,parts:{sessions:Number(n.parts?.sessions)||0,repos:Number(n.parts?.repos)||0}}),so(B.netSync)}}catch{}try{let t=z(B.netTraffic);if(t){let n=JSON.parse(t);n&&typeof n.since==`number`&&(e.traffic={since:n.since,up:Math.max(0,n.up|0),down:Math.max(0,n.down|0)}),so(B.netTraffic)}}catch{}return e}var Dd=Oie(),Od=null;function kd(){Od??=window.setTimeout(()=>{Od=null,$a(Sd,Dd)},Eie)}function Ad(){Od!=null&&(window.clearTimeout(Od),Od=null),$a(Sd,Dd)}var jd=new Set;function Md(...e){for(let t of e)jd.add(t)}var Nd=new Set,Pd=null;function kie(e){Pd=e}function Fd(){if(!Nd.size||!Pd)return;let e=Pd();for(let t of Nd)t.fn(e)}var Aie=12e4,Id={},Ld=null,Rd=`default`,zd=new Set;function Bd(e){Id=e;for(let e of zd)e()}function jie(e){return zd.add(e),()=>{zd.delete(e)}}function Vd(){return Id}function Mie(e=Date.now(),t){let n=oo(B.hostBoots,{})[Rd]?.usualMs;Bd({since:e,usualMs:n,...t?{reason:t}:{}})}function Nie(e=Date.now()){Ld??=e}function Pie(e,t=Date.now()){Rd=e.hostId??`default`;let n=oo(B.hostBoots,{}),r=n[Rd],i=Id.since??Ld??void 0,a=Id.since!=null;if(Ld=null,!r||r.bootId===e.bootId)return r||(n[Rd]={bootId:e.bootId},$a(B.hostBoots,n)),Id.since!=null&&Bd({}),null;if(i==null)return n[Rd]={...r,bootId:e.bootId},$a(B.hostBoots,n),null;let o=Math.max(0,t-i),s=e.startedAt!=null&&e.readyAt!=null?Math.max(0,e.readyAt-e.startedAt):void 0;return n[Rd]={bootId:e.bootId,usualMs:o},$a(B.hostBoots,n),Bd({back:{at:t,downMs:o,announced:a,reattachMs:s,...Id.reason?{reason:Id.reason}:{}}}),{downMs:o,announced:a}}function Hd(e){let t=Math.round(e/1e3);return t<90?`${t} s`:`${Math.round(t/60)} min`}function Fie(e,t){if(e.since!=null){let n=t-e.since,r=e.usualMs==null?``:` · usually ~${Hd(e.usualMs)}`,i=n>(e.usualMs==null?Aie:e.usualMs*3),a=e.reason?` (${e.reason})`:``;return{text:i?`desktop restarting${a} ${Hd(n)} — longer than usual, it may have failed to start`:`desktop restarting${a} · ${Hd(n)}${r}`,slow:i}}if(e.back&&t-e.back.at<12e4){let t=e.back.downMs==null?``:` after ${Hd(e.back.downMs)}`;return{text:e.back.announced?`desktop restarted${e.back.reason?` (${e.back.reason})`:``} — back${t}`:`desktop restarted unannounced (crash?) — back${t}`,slow:!e.back.announced}}return null}var Ud=null,Wd=`connecting`;function Gd(e){if(e===Wd)return;let t=Wd;Wd=e;let n=Date.now();t===`open`&&Nie(n),Dd.log.online||(Dd.log.offlineMs+=Math.max(0,n-Dd.log.markTs)),Dd.log.markTs=n,Dd.log.online=e===`open`,yie(e===`open`),e===`closed`&&Dd.log.reconnects++,e===`open`?(Ud=n,Dd.sync.lastSeenAt=n):Ud=null,t===`open`||e===`open`?Ad():kd(),Md(`status`),Fd()}function Kd(){return Wd===`open`}var qd=500,Jd=10,Iie=qd*Jd,Yd=Array.from({length:Jd},()=>({slot:-1,up:0,down:0})),Lie=Date.now();function Xd(e,t){if(!Number.isFinite(t)||t<=0)return;let n=Math.round(t);e===`up`?Dd.traffic.up+=n:Dd.traffic.down+=n;let r=Math.floor(Date.now()/qd),i=Yd[r%Jd];i.slot!==r&&(i.slot=r,i.up=0,i.down=0),e===`up`?i.up+=n:i.down+=n,kd()}function Rie(e){let t=Math.floor(e/qd),n=t-9,r=0,i=0;for(let e of Yd)e.slot<n||e.slot>t||(r+=e.up,i+=e.down);let a=Math.max(1e3,Math.min(Iie,e-Lie));return{up:r*1e3/a,down:i*1e3/a}}function zie(){let e=Rie(Date.now());return{since:Dd.traffic.since,up:Dd.traffic.up,down:Dd.traffic.down,upRate:e.up,downRate:e.down}}function Zd(e){return e<1024?`${Math.round(e)} B`:e<1048576?`${Math.round(e/1024)} kB`:e<1073741824?`${(e/1024/1024).toFixed(+(e<10485760))} MB`:`${(e/1024/1024/1024).toFixed(2)} GB`}function Qd(e){return!Number.isFinite(e)||e<1024?null:e<1048576?`${Math.round(e/1024)} kB/s`:`${(e/1024/1024).toFixed(1)} MB/s`}var $d=class{seq=0;wires=new Map;ring=[];page;deps;constructor(e,t){this.deps=e,this.page=t??e.now().toString(36)}inflight(){return this.wires.size}begin(e,t,n){let r={id:++this.seq,label:e,method:t.toUpperCase(),via:n,started:this.deps.now(),timer:null};this.wires.set(r.id,r),r.timer=this.deps.setTimer(()=>{this.wires.has(r.id)&&(r.snap=this.snapshot(r))},hte);let i=!1;return{progress:(e,t)=>{r.sent=e,t!=null&&(r.total=t)},end:({answered:e,fuseMs:t})=>{if(i)return;i=!0,this.deps.clearTimer(r.timer);let n=Math.max(0,this.deps.now()-r.started),a=Kee({ageMs:n,fuseFired:t!=null,answered:e}),o=a?r.snap??this.snapshot(r):null;if(this.wires.delete(r.id),!a||!o)return;let s={k:`${this.page}.${r.id}`,label:r.label,method:r.method,ageMs:n,outcome:a,...o};t!=null&&(s.fuseMs=t),r.sent!=null&&(s.sent=r.sent,r.total!=null&&(s.total=r.total)),this.add(s)}}}bodyTimeout(e,t,n){let r={k:`${this.page}.b${++this.seq}`,label:e,method:t.toUpperCase(),phase:`body`,ageMs:n,fuseMs:n,outcome:`timeout`,via:`fetch`,...this.snapshot(null)};this.add(r)}openStalls(){let e=this.deps.now(),t=[];for(let n of this.oldestFirst()){let r=e-n.started;if(r<12e3)continue;let i={k:`${this.page}.${n.id}`,label:n.label,method:n.method,ageMs:r,outcome:`open`,...n.snap??this.snapshot(n)};n.sent!=null&&(i.sent=n.sent,n.total!=null&&(i.total=n.total)),t.push(i)}return t}report(){return{events:this.ring.slice(),open:this.openStalls()}}add(e){Xr(this.ring,e,50),this.deps.changed()}oldestFirst(){return[...this.wires.values()].sort((e,t)=>e.started-t.started)}snapshot(e){let t=this.deps.now(),n=this.oldestFirst().filter(t=>t!==e).slice(0,8).map(e=>({label:e.label,ageMs:Math.max(0,t-e.started)})),r=this.deps.context(),i={at:t,via:e?.via??`fetch`,inflight:this.wires.size};return n.length&&(i.peers=n),r.ws&&(i.ws=r.ws),r.visible!=null&&(i.visible=r.visible),r.visForMs!=null&&(i.visForMs=r.visForMs),r.online!=null&&(i.online=r.online),i}},ef=0,tf=[];function nf(e){let t={id:++ef,label:e,started:Date.now()};tf.push(t),Md(`ops`),Fd();let n=!1;return()=>{if(n)return;n=!0;let e=tf.findIndex(e=>e.id===t.id);e>=0&&tf.splice(e,1),Md(`ops`),Fd()}}function rf(e,t=`GET`){let n=e.split(`?`)[0],r=t!==`GET`;return n.includes(`/artifacts`)||n.includes(`/api/search`)?`loading files`:n.includes(`/inbox/seen`)?`marking inbox read`:n.includes(`/inbox`)?r?`uploading`:`loading inbox`:n.includes(`/artifact`)?r?`deleting file`:`loading file`:n.includes(`/git/status`)?`reading git status`:n.includes(`/git/diff`)?`loading diff`:n.includes(`/git/blob`)?`loading the picture`:n.includes(`/git/text`)?`loading the file`:n.includes(`/git/branches`)?`loading branches`:n.includes(`/git/commit`)?`committing`:n.includes(`/git/push`)?`pushing`:n.includes(`/git/pull`)?`pulling`:n.includes(`/git/checkout`)?`switching branch`:n.includes(`/git/branch`)?`updating branches`:n.includes(`/git/stage`)?`staging`:n.includes(`/compliance`)?r?`applying fixes`:`checking repo setup`:n.includes(`/api/slash`)?`loading commands`:n.includes(`/api/repos`)?`loading repos`:n.includes(`/api/external`)?`looking for sessions`:n.includes(`/api/worktree`)?`creating worktree`:n.includes(`/api/project`)?`creating project`:n.includes(`/api/folder`)?`creating folder`:n.includes(`/api/secret`)?r?`setting secret`:`loading targets`:n.includes(`/api/envfiles`)?`loading env files`:n.includes(`/api/host/screenshot`)?`capturing screen`:n.includes(`/api/host/clipboard`)?`copying to host`:n.includes(`/api/host/stat`)?`reading host load`:n.includes(`/api/auth`)?`signing in`:n.includes(`/api/ui-usage`)?`loading usage`:r?`sending`:`loading`}var af=null,of=null;function sf(e){af=Date.now(),of=Math.round(e)}var cf=null;try{document.addEventListener(`visibilitychange`,()=>{cf=Date.now()})}catch{}function lf(){let e=Date.now(),t={},n={open:Wd===`open`};af!=null&&(n.pongAgeMs=Math.max(0,e-af)),of!=null&&(n.rttMs=of),t.ws=n;try{t.visible=document.visibilityState===`visible`}catch{}cf!=null&&(t.visForMs=Math.max(0,e-cf));try{typeof navigator.onLine==`boolean`&&(t.online=navigator.onLine)}catch{}return t}var uf=new $d({now:()=>Date.now(),context:lf,setTimer:(e,t)=>setTimeout(e,t),clearTimer:e=>clearTimeout(e),changed:()=>Tf()});function df(e,t,n){return uf.begin(rf(e,t),t,n)}function ff(e,t,n){uf.bodyTimeout(rf(e,t),t,n)}function pf(e){let t=e;return t&&t.name===`TimeoutError`&&typeof t.ms==`number`?t.ms:void 0}var mf=new WeakMap;function hf(e,t){let n=pf(t);n!=null&&mf.set(e,n),e.abort()}var gf=new WeakMap;function _f(){try{let e=globalThis.fetch.bind(globalThis);globalThis.fetch=(async(t,n)=>{let r=typeof Request<`u`&&t instanceof Request?t:null,i=df(typeof t==`string`?t:t instanceof URL?t.href:r?.url??``,n?.method??r?.method??`GET`,`fetch`);try{let r=await e(t,n);return i.end({answered:!0}),r}catch(e){throw i.end({answered:!1,fuseMs:n?.signal?.aborted?pf(n.signal.reason):void 0}),e}})}catch{}try{let e=XMLHttpRequest.prototype,t=e.open;e.open=function(e,n,...r){return gf.set(this,{method:String(e||`GET`),url:String(n)}),t.call(this,e,n,...r)};let n=e.send;e.send=function(e){let t=gf.get(this),r=df(t?.url??``,t?.method??`GET`,`xhr`),i=typeof Blob<`u`&&e instanceof Blob?e.size:void 0;i&&r.progress(0,i);try{this.upload?.addEventListener(`progress`,e=>r.progress(e.loaded,e.lengthComputable?e.total:i)),this.addEventListener(`loadend`,()=>r.end({answered:this.status>0,fuseMs:mf.get(this)}))}catch{r.end({answered:!1})}return n.call(this,e)}}catch{}}var vf=null,yf=null,bf=``,xf=null,Sf=15e3;function Cf(){return uf.openStalls().map(e=>e.k).join(`,`)}function wf(e=!1){if(!vf||vf.status!==`open`||!yf)return;let t=yf();if(!t||t===`unknown`)return;let n=`${uf.ring.length}:${uf.ring[uf.ring.length-1]?.k??``}|${Cf()}`;(e||n!==bf)&&(vf.send({t:`net.stalls`,deviceId:t,report:uf.report()}),bf=n)}function Tf(){xf||=setTimeout(()=>{xf=null,wf()},1e3)}function Ef(e,t){vf||(vf=e,yf=t,e.on(e=>{e.t===`welcome`&&(bf=``,wf(!0))}),setInterval(()=>wf(),Sf))}function Df(e,t){!Number.isFinite(t)||t<0||(e.push(Math.round(t)),e.length>200&&e.splice(0,e.length-200))}function Of(e,t){if(!e.length)return;let n=[...e].sort((e,t)=>e-t);return n[Math.min(n.length-1,Math.floor((n.length-1)*t))]}function kf(){let e=z(Cd);if(e)return e;try{let e=new Uint8Array(6);crypto.getRandomValues(e);let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return Za(Cd,t),t}catch{return`unknown`}}function Af(e){Df(Dd.log.rtt,e),sf(e),kd()}function jf(){Dd.log.reloads++,Ad()}function Mf(e){Dd.log.sent++,Df(Dd.log.send,e),Dd.log.queuedMaxMs=Math.max(Dd.log.queuedMaxMs,Math.round(e)),kd(),Md(`log`)}function Nf(){Dd.log.failed++,kd(),Md(`log`)}function Pf(){Dd.log.expired++,kd(),Md(`log`)}function Ff(){Dd.log.ackTimeouts++,kd(),Md(`log`)}function If(){let e=Date.now(),t=Dd.log.online?0:Math.max(0,e-Dd.log.markTs),n=Math.max(1,e-Dd.log.since);return{since:Dd.log.since,rttP50:Of(Dd.log.rtt,.5),rttP95:Of(Dd.log.rtt,.95),reconnects:Dd.log.reconnects,reloads:Dd.log.reloads,offlineShare:Math.min(1,(Dd.log.offlineMs+t)/n),sendP50:Of(Dd.log.send,.5),sendP95:Of(Dd.log.send,.95),sent:Dd.log.sent,failed:Dd.log.failed,expired:Dd.log.expired,ackTimeouts:Dd.log.ackTimeouts,queuedMaxMs:Dd.log.queuedMaxMs,ua:navigator.userAgent.slice(0,120)}}function Lf(){return Dd.log.rtt.length<4?null:Of(Dd.log.rtt,.95)??null}function Rf(){Dd.log=wd(Date.now()),Dd.log.online=Wd===`open`,Dd.traffic={since:Date.now(),up:0,down:0};for(let e of Yd)e.slot=-1,e.up=0,e.down=0;Ad(),Md(`log`,`traffic`),Fd()}var zf=0;function Bf(e){let t=Math.max(0,e|0);t!==zf&&(zf=t,Md(`sends`),Fd())}var Vf=0,Hf=!1;function Uf(e){let t=Math.max(0,e|0);t!==Vf&&(Vf=t,t>0&&(Hf=!0),Md(`sends`),Fd())}async function Wf(e,t,n){let r=nf(rf(e,t?.method??`GET`));try{return await pn(e,t,n)}finally{r()}}function Gf(e,t,n=lr,r=`GET`){let i,a=new Promise((e,a)=>{i=setTimeout(()=>{ff(t,r,n),a(new br(t,n))},n)});return Promise.race([e.json(),a]).finally(()=>clearTimeout(i))}async function Kf(e,t,n){let r=await Wf(e,n?{signal:n}:void 0,t);if(!r.ok)throw Error(`${r.status} ${e}`);return Gf(r,e,t)}async function qf(e,t,n){let r=await Wf(e,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)},n);if(!r.ok){let e=`${r.status}`;try{let t=await r.json(),n=typeof t.message==`string`?t.message:typeof t.error==`string`?t.error:null;n&&(e=`${r.status} ${n}`)}catch{}throw Error(e)}return Gf(r,e,n,`POST`)}async function Jf(e,t,n){return Gf(await Wf(e,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)},n),e,n,`POST`)}async function Yf(e){await Wf(e,{method:`DELETE`})}async function Xf(e,t,n){if(!e.body)return e.blob();let r=Number(e.headers.get(`content-length`)||0),i=e.body.getReader(),a=[],o=0;for(;;){let s,c=new Promise((n,a)=>{s=setTimeout(()=>{let n=new br(e.url,t);n.message=`stalled — no bytes for ${Math.round(t/1e3)}s after ${Nr(o)}${r?` of ${Nr(r)}`:``}`,a(n),i.cancel().catch(()=>{})},t)});try{let{done:e,value:t}=await Promise.race([i.read(),c]);if(e)break;a.push(t),o+=t.byteLength,n?.(o,r)}finally{clearTimeout(s)}}return new Blob(a,{type:e.headers.get(`content-type`)||``})}async function Zf(e,t){return JSON.parse(await(await Xf(e,t)).text())}var Qf={repos:()=>Kf(`/api/repos`).then(e=>e.targets),slash:(e,t)=>Kf(`/api/slash?cwd=${encodeURIComponent(e)}${t?`&backend=${encodeURIComponent(t)}`:``}`),external:()=>Kf(`/api/external`).then(e=>e.sessions),transcript:async(e,t,n=`lite`)=>{let r=new URLSearchParams({id:e});t&&r.set(`since`,String(t)),n===`full`&&r.set(`detail`,`full`);let i=await pn(`/api/transcript?${r}`,void 0,Ga);if(i.status===204)return null;if(!i.ok)throw Error(`${i.status} transcript`);return Zf(i,Ga)},scrollback:async(e,t)=>{let n=await Wf(`/api/scrollback?id=${encodeURIComponent(e)}`,t?{signal:t}:void 0,Ga);if(!n.ok)throw Error(`${n.status} scrollback`);let r=await Zf(n,Ga);return{lines:r.lines??[],history:!!r.history,bounded:!!r.bounded,at:r.at??Date.now()}},screenTail:async(e,t)=>{let n=new URLSearchParams({id:e});t!=null&&n.set(`since`,String(t));let r=await pn(`/api/screen/tail?${n}`,void 0,Ga);if(r.status===204)return null;if(!r.ok)throw Error(`${r.status} screen tail`);let i=await Zf(r,Ga);if(typeof i.data!=`string`||typeof i.seq!=`number`)throw Error(`screen tail shape`);return{data:i.data,seq:i.seq,boot:typeof i.boot==`string`?i.boot:void 0}},transcriptTools:async(e,t)=>{let n=new URLSearchParams({id:e,turn:t}),r=await pn(`/api/transcript/tools?${n}`,void 0,Ga);if(!r.ok)throw Error(`${r.status} tool details`);return(await Zf(r,12e3)).tools??{}},shellDetail:async(e,t)=>{let n=new URLSearchParams({id:e,pid:String(t)}),r=await pn(`/api/shell?${n}`,void 0,Ga);if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.error||`${r.status} shell`)}return Zf(r,Ga)},contextSeries:async(e,t)=>{let n=new URLSearchParams({id:e});t&&n.set(`since`,String(t));let r=await Wf(`/api/context?${n}`,void 0,Ga);if(r.status===204)return null;if(!r.ok)throw Error(`${r.status} context series`);return Zf(r,Ga)}},$f={tokenStats:(e=!1)=>Kf(`/api/tokenstats${e?`?fresh=1`:``}`,xa),getWeekBurn:()=>Kf(`/api/weekburn`),postWeekBurn:e=>qf(`/api/weekburn`,e),localUsage:()=>Kf(`/api/localusage`),peerJobs:()=>Kf(`/api/peerjobs`).then(e=>Array.isArray(e?.jobs)?e.jobs:[]),backendTokens:(e,t=!1)=>Kf(`/api/tokenstats/${encodeURIComponent(e)}${t?`?fresh=1`:``}`,xa),usageLog:(e=0)=>Kf(`/api/usagelog${e>0?`?hours=${e}`:``}`),usageLogSource:(e,t)=>Kf(`/api/usagelog/${encodeURIComponent(e)}`,void 0,t),tokenWindows:(e,t=!1)=>Kf(`/api/tokenwindows?${e.map(e=>`w=${encodeURIComponent(`${e.id}:${Math.round(e.anchor)}:${Math.round(e.lenMs)}`)}`).join(`&`)}${t?`&fresh=1`:``}`,xa),costWindow:(e,t,n=!1)=>Kf(`/api/costwindow?from=${Math.round(e)}&to=${Math.round(t)}${n?`&fresh=1`:``}`,xa)},ep={inbox:(e,t)=>Kf(`/api/repos/${e}/inbox`,void 0,t).then(e=>e.files),markInboxSeen:e=>fetch(`/api/repos/${e}/inbox/seen`,{method:`POST`}).catch(()=>void 0),markOutboxSeen:e=>fetch(`/api/repos/${e}/artifacts/seen`,{method:`POST`}).catch(()=>void 0),artifacts:(e,t,n,r)=>{let i=new URLSearchParams({scope:t});return n&&i.set(`since`,String(n)),r?.query&&i.set(`q`,r.query),r?.kind&&r.kind!==`all`&&i.set(`kind`,r.kind),r?.limit&&i.set(`limit`,String(r.limit)),Kf(`/api/repos/${e}/artifacts?${i}`,void 0,r?.signal)},search:e=>{let t=new URLSearchParams({scope:e.scope??`repo`});return e.query&&t.set(`q`,e.query),e.kind&&e.kind!==`all`&&t.set(`kind`,e.kind),e.sinceSeconds&&t.set(`since`,String(e.sinceSeconds)),e.repoIds?.length&&t.set(`repos`,e.repoIds.join(`,`)),e.limit&&t.set(`limit`,String(e.limit)),Kf(`/api/search?${t}`,void 0,e.signal)},uploadInbox:(e,t,n,r,i,a)=>new Promise((o,s)=>{let c=new XMLHttpRequest;c.open(`POST`,`/api/repos/${e}/inbox`),c.setRequestHeader(`x-file-name`,encodeURIComponent(n)),a&&c.setRequestHeader(`x-dedupe`,`1`),c.setRequestHeader(`content-type`,t.type||`application/octet-stream`),c.withCredentials=!0,i&&(c.upload.onprogress=e=>i(e.loaded,e.lengthComputable?e.total:t.size));let l=()=>hf(c,r?.reason);r?.addEventListener(`abort`,l,{once:!0});let u=()=>r?.removeEventListener(`abort`,l);c.onload=()=>{if(u(),c.status<200||c.status>299){let e=Error(`upload failed (${c.status})`);e.permanent=c.status===413||c.status===415,e.responded=!0,s(e)}else try{o(JSON.parse(c.responseText))}catch{let e=Error(`upload failed (${c.status})`);e.responded=!0,s(e)}},c.onerror=()=>{u(),s(Error(`upload failed`))},c.onabort=()=>{u(),s(new DOMException(`aborted`,`AbortError`))},c.send(t)}),fileBlob:e=>Wf(e).then(e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return e.blob()}),deleteInbox:(e,t)=>Wf(`/api/repos/${e}/inbox/${encodeURIComponent(t)}`,{method:`DELETE`}).then(e=>e.json()),deleteArtifact:(e,t)=>Wf(`/api/repos/${e}/artifact?path=${encodeURIComponent(t)}`,{method:`DELETE`}).then(e=>e.json()),sweepPlan:(e,t)=>Wf(`/api/repos/${e}/sweep?scope=${t}`).then(e=>e.json()),sweepRun:(e,t)=>Jf(`/api/repos/${e}/sweep`,{paths:t}),transportSurvey:()=>Wf(`/api/storage/transport`).then(e=>e.json()),hostStore:()=>Wf(`/api/storage/host`).then(e=>e.json()),hostStoreClear:(e,t)=>Jf(`/api/storage/host/clear`,{store:e,at:t})},tp={newFolder:(e,t)=>Jf(`/api/folder`,{parent:e,name:t}),newRepo:(e,t,n={})=>Jf(`/api/repo`,{parent:e,name:t,setup:n.setup!==!1,description:n.description}),plainFolders:()=>Kf(`/api/plainfolders`),initPlainFolder:e=>Jf(`/api/plainfolders/init`,{path:e}),cloneRepo:(e,t,n)=>Jf(`/api/clone`,{parent:e,url:t,name:n||void 0}),onboardPlan:e=>{let t=new URLSearchParams({name:e.name,path:e.path});return e.description&&t.set(`description`,e.description),e.setup===!1&&t.set(`setup`,`0`),Kf(`/api/onboard/plan?${t}`)},onboardJob:()=>Kf(`/api/onboard`),onboardStart:(e,t,n)=>Jf(`/api/onboard`,{answers:e,consent:t,confirm:n}),onboardResume:(e,t)=>Jf(`/api/onboard/resume`,e?{consent:e,confirm:t}:{}),newWorktree:(e,t)=>Jf(`/api/worktree`,{repoId:e,branch:t}),worktreeLeftover:(e,t)=>Kf(`/api/repos/${e}/worktree/leftover`,void 0,t),removeWorktree:e=>Jf(`/api/repos/${e}/worktree/remove`,{}),artifactUrl:(e,t)=>Iu(`/api/repos/${e}/artifact?path=${encodeURIComponent(t)}`),inboxUrl:(e,t)=>Iu(`/api/repos/${e}/inbox/${encodeURIComponent(t)}`)};async function np(e,t,n,r,i=xa,a){let o=new URLSearchParams({path:t,side:n});r&&o.set(`staged`,`1`);let s=await Wf(`${e}?${o}`,a?{signal:a}:void 0,i);if(s.status===404)return null;if(s.ok)return s;let c=await s.json().catch(()=>null);throw Error(c?.error||`the desktop answered ${s.status}`)}var rp=2e4,ip={gitStatus:e=>Kf(`/api/repos/${e}/git/status`),gitDiff:(e,t,n)=>{let r=new URLSearchParams;return t&&r.set(`path`,t),n&&r.set(`staged`,`1`),Kf(`/api/repos/${e}/git/diff?${r}`).then(e=>e.diff)},gitBlob:async(e,t,n,r,i,a)=>{let o=await np(`/api/repos/${e}/git/blob`,t,n,r,lr,a);return o?Xf(o,rp,i):null},gitText:async(e,t,n,r,i)=>(await np(`/api/repos/${e}/git/text`,t,n,r,void 0,i))?.json(),gitStage:(e,t,n)=>Jf(`/api/repos/${e}/git/stage`,{path:t,unstage:n}),gitCommit:(e,t,n=!0)=>Jf(`/api/repos/${e}/git/commit`,{message:t,all:n},xa),gitMessage:e=>Jf(`/api/repos/${e}/git/message`,{},xa),gitExplain:(e,t,n)=>Jf(`/api/repos/${e}/git/explain`,{foci:t,note:n,background:!0},33e4),gitExplainState:(e,t)=>Kf(`/api/repos/${e}/git/explain`,void 0,t).then(e=>e.explain),gitLog:e=>Kf(`/api/repos/${e}/git/log`),gitShow:(e,t)=>Kf(`/api/repos/${e}/git/show?${new URLSearchParams({sha:t})}`).then(e=>e.body),gitFetch:e=>Jf(`/api/repos/${e}/git/fetch`,{},xa),gitPull:e=>Jf(`/api/repos/${e}/git/pull`,{},xa),gitPush:e=>qf(`/api/repos/${e}/git/push`,{background:!0}),gitPushState:(e,t)=>Kf(`/api/repos/${e}/git/push`,void 0,t).then(e=>e.push),prLease:(e,t)=>Jf(`/api/repos/${e}/git/prs/lease`,{holder:t}),prMerge:(e,t,n)=>Jf(`/api/repos/${e}/git/prs/merge`,{number:t,method:n},xa),prAutoMerge:(e,t,n,r)=>Jf(`/api/repos/${e}/git/prs/automerge`,{number:t,on:n,method:r},xa),prClose:(e,t)=>Jf(`/api/repos/${e}/git/prs/close`,{number:t},xa),prLog:(e,t,n)=>Jf(`/api/repos/${e}/git/prs/log`,{number:t,check:n},xa)},ap={archive:(e,t={})=>{let n=new URLSearchParams;return t.offset&&n.set(`offset`,String(t.offset)),t.limit&&n.set(`limit`,String(t.limit)),t.q&&n.set(`q`,t.q),t.bookmarked&&n.set(`bookmarked`,`1`),Kf(`/api/repos/${e}/archive?${n}`,xa)},archiveDelete:async(e,t)=>(await Wf(`/api/repos/${e}/archive?id=${encodeURIComponent(t)}`,{method:`DELETE`})).json(),conversations:async(e,t,n={},r)=>{let i=await Wf(`/api/conversations?${new URLSearchParams({backend:e,cwd:t,...n.offset?{offset:String(n.offset)}:{},...n.limit?{limit:String(n.limit)}:{},...n.q?{q:n.q}:{}})}`,r?{signal:r}:void 0,xa);if(i.ok)return Zf(i,xa);let a=await Zf(i,xa).catch(()=>({error:void 0}));throw Error(typeof a.error==`string`&&a.error?a.error:`${i.status}`)},conversationsDelete:async(e,t,n)=>(await Wf(`/api/conversations?${new URLSearchParams({backend:e,cwd:t,id:n})}`,{method:`DELETE`})).json(),bookmarkSet:async(e,t,n={})=>(await Wf(`/api/repos/${e}/archive/bookmark`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({id:t,...n})})).json(),bookmarkRemove:async(e,t)=>(await Wf(`/api/repos/${e}/archive/bookmark?id=${encodeURIComponent(t)}`,{method:`DELETE`})).json(),archivedTranscript:async(e,t,n,r=`lite`)=>{let i=new URLSearchParams({conv:t});n&&i.set(`since`,String(n)),r===`full`&&i.set(`detail`,`full`);let a=await pn(`/api/repos/${e}/archive/transcript?${i}`,void 0,Ga);if(a.status===204)return null;if(!a.ok)throw Error(`${a.status} transcript`);return Zf(a,Ga)},archivedToolDetails:async(e,t,n)=>{let r=new URLSearchParams({conv:t,turn:n}),i=await pn(`/api/repos/${e}/archive/transcript/tools?${r}`,void 0,Ga);if(!i.ok)throw Error(`${i.status} tool details`);return(await Zf(i,12e3)).tools??{}},tree:(e,t=``,n)=>{let r=new URLSearchParams;return t&&r.set(`path`,t),n&&r.set(`q`,n),Kf(`/api/repos/${e}/tree?${r}`)},treeFile:(e,t)=>Kf(`/api/repos/${e}/tree/file?path=${encodeURIComponent(t)}`),treeWrite:async(e,t,n,r)=>(await Wf(`/api/repos/${e}/tree/file`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t,body:n,baseSha:r})},xa)).json()};function op(e){let t=Array.isArray(e?.rows)?e.rows:[];return{...e,rows:t.map(Hi).filter(e=>!!e)}}var sp={gitBranches:e=>Kf(`/api/repos/${e}/git/branches`).then(e=>e.branches),gitCheckout:(e,t)=>Jf(`/api/repos/${e}/git/checkout`,{branch:t},xa),gitCreateBranch:(e,t,n)=>Jf(`/api/repos/${e}/git/branch`,{name:t,...n}),gitDeleteBranch:(e,t,n=!1)=>Wf(`/api/repos/${e}/git/branch`,{method:`DELETE`,headers:{"content-type":`application/json`},body:JSON.stringify({name:t,force:n})}).then(e=>e.json()),envFiles:e=>Kf(`/api/repos/${e}/envfiles`).then(e=>e.files),secretTargets:()=>Kf(`/api/secret/targets`).then(e=>e.targets),setSecret:e=>Jf(`/api/secret`,e),compliance:e=>Kf(`/api/repos/${e}/compliance`),complianceFix:(e,t,n)=>Jf(`/api/repos/${e}/compliance/fix`,n?{fixes:t,confirm:n}:{fixes:t}),complianceLimits:(e,t)=>Jf(`/api/repos/${e}/compliance/limits`,t),complianceIgnore:(e,t,n)=>Jf(`/api/repos/${e}/compliance/ignore`,{id:t,ignore:n}),complianceAccept:(e,t)=>Jf(`/api/repos/${e}/compliance/accept`,t),complianceTriage:(e,t)=>Jf(`/api/repos/${e}/compliance/triage`,t),exposureRun:e=>Jf(`/api/repos/${e}/exposure/run`,{},33e4),optIns:e=>Kf(`/api/repos/${e}/optins`).then(op),optInChoice:(e,t,n)=>Jf(`/api/repos/${e}/optins/choice`,{id:t,choice:n}).then(e=>e.report?{...e,report:op(e.report)}:e),hostSetup:()=>Kf(`/api/host/setup`),hostSetupFix:e=>Jf(`/api/host/setup/fix`,{fixes:e}),setupPrefs:e=>Kf(`/api/host/setupprefs`,void 0,e),setSetupPrefs:e=>Jf(`/api/host/setupprefs`,{autoCompactDefault:e}),repoHealth:(e,t)=>Kf(`/api/repos/${e}/repohealth${t?`?scope=${encodeURIComponent(t)}`:``}`),healthIndex:e=>Kf(`/api/repos/${e}/healthindex`),repoHealthScopes:(e,t)=>Jf(`/api/repos/${e}/repohealth/scopes`,{scopes:t}),repoHealthRefresh:(e,t,n,r,i)=>Jf(`/api/repos/${e}/repohealth/refresh`,{...t?{scope:t}:{},...n?{approveEngine:!0,...r?{approveToken:r}:{}}:{},...i?{recut:!0}:{}},2e5)},cp={askRules:()=>Wf(`/api/askrules`).then(up),setAskRules:(e,t)=>Wf(`/api/askrules`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({rules:e,rev:t.rev,confirm:t.confirm})}).then(up)},lp=class extends Error{reread;constructor(e,t){super(e),this.reread=t}};async function up(e){let t=null;try{t=await e.json()}catch{}if(e.ok&&t?.ok)return t;throw new lp(typeof t?.error==`string`?t.error:`${e.status} /api/askrules`,e.status===409||e.status===403)}var dp={...cp,rootInfo:()=>Kf(`/api/host/root`),checkRoot:e=>Jf(`/api/host/root`,{path:e}),saveRoot:e=>Jf(`/api/host/root`,{path:e,save:!0}),hostStat:()=>Kf(`/api/host/stat`),screenshot:async e=>(await Wf(`/api/host/screenshot?repo=${encodeURIComponent(e)}`,{method:`POST`})).json(),ocrStatus:async()=>{try{let e=await Wf(`/api/host/ocr`);return e.ok?await e.json():{available:!1,reason:`this desktop is running an older host`}}catch{return{available:!1,reason:`the host could not be reached`}}},ocrImage:async e=>{try{let t=await Wf(`/api/host/ocr`,{method:`POST`,headers:{"content-type":e.type||`image/jpeg`},body:e},12e4);return t.status===404?{error:`this desktop is running an older host — update it to read pictures on-device`}:await t.json()}catch{return{error:`the host could not be reached`}}},dictateStatus:async()=>{try{let e=await Wf(`/api/host/dictate`);return e.ok?await e.json():{available:!1,reason:`this desktop is running an older host`}}catch{return{available:!1,reason:`the host could not be reached`}}},dictate:(e,t={})=>new Promise((n,r)=>{let{lang:i,terms:a,signal:o,onProgress:s}=t,c=new XMLHttpRequest,l=new URLSearchParams;i&&l.set(`lang`,i),a&&l.set(`terms`,a);let u=l.toString();c.open(`POST`,`/api/host/dictate${u?`?${u}`:``}`),c.setRequestHeader(`content-type`,`audio/wav`),c.withCredentials=!0,s&&(c.upload.onprogress=t=>s(t.loaded,t.lengthComputable?t.total:e.size));let d=()=>c.abort();o?.addEventListener(`abort`,d,{once:!0});let f=()=>o?.removeEventListener(`abort`,d);c.onload=()=>{if(f(),c.status<200||c.status>299){let e=Error(`the desktop could not read it (${c.status})`);e.permanent=c.status===413||c.status===415,e.responded=!0,r(e)}else try{n(JSON.parse(c.responseText))}catch{let e=Error(`the desktop answered something this app could not read`);e.responded=!0,r(e)}},c.onerror=()=>{f(),r(Error(`the desktop could not be reached`))},c.onabort=()=>{f(),r(new DOMException(`aborted`,`AbortError`))},c.send(e)}),setClipboard:e=>Jf(`/api/host/clipboard`,{text:e}),pluginAsset:(e,t,n)=>Wf(`/api/plugin/${encodeURIComponent(e)}/asset/${encodeURIComponent(t)}`,{signal:n,cache:`no-store`},3e4)};function fp(e,t,n){return pn(e,t,n)}async function pp(e,t,n){try{let r=await fp(e,t,n);return r.ok?await r.json():null}catch{return null}}var mp={speedtest:{download:async(e,t)=>{let n=performance.now(),r=await fetch(`/api/speedtest/download?bytes=${e}&_=${Date.now()}`,{cache:`no-store`});if(!r.ok||!r.body)throw Error(`download ${r.status}`);let i=r.body.getReader(),a=0;for(;;){let{done:e,value:n}=await i.read();if(e)break;a+=n.byteLength,t?.(a)}let o=performance.now()-n;return{bytes:a,ms:o,mbps:hp(a,o)}},upload:async e=>{let t=new Uint8Array(e);for(let n=0;n<e;n+=65536)crypto.getRandomValues(t.subarray(n,Math.min(n+65536,e)));let n=performance.now(),r=await(await fetch(`/api/speedtest/upload`,{method:`POST`,headers:{"content-type":`application/octet-stream`},body:t})).json(),i=performance.now()-n;if(!r.ok)throw Error(r.error||`upload failed`);return{bytes:e,ms:i,mbps:hp(e,i),serverMs:r.ms}},debug:()=>Kf(`/api/speedtest/debug`)},netstats:{get:()=>Kf(`/api/netstats`,void 0),reset:()=>Yf(`/api/netstats`),report:e=>fp(`/api/netstats`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e),keepalive:!0}).catch(()=>void 0)},push:{key:()=>Kf(`/api/push/key`),subscribe:e=>Jf(`/api/push/subscribe`,e),unsubscribe:e=>Jf(`/api/push/unsubscribe`,{endpoint:e})},uiUsage:{get:()=>pp(`/api/ui-usage`),flush:e=>fp(`/api/ui-usage`,{method:`POST`,headers:{"content-type":`application/json`},body:e,keepalive:!0}),reset:()=>fp(`/api/ui-usage`,{method:`DELETE`}).catch(()=>void 0)},webBundle:{manifest:()=>pp(`/api/webbundle`,{cache:`no-store`}),file:(e,t)=>fp(`/api/webbundle/file?path=${encodeURIComponent(e)}&v=${encodeURIComponent(t)}`,{cache:`no-store`})},auth:{status:()=>Kf(`/api/auth/status`),login:e=>Jf(`/api/auth/login`,{password:e}),logout:()=>Jf(`/api/auth/logout`,{})},tailnet:{peers:e=>Kf(`/api/tailnet/peers`,12e3,e)},pair:{mint:(e=!1)=>qf(`/api/pair/mint`,e?{passive:!0}:{}),redeem:async(e,t,n=null)=>{let r=await Wf(`${e}/api/pair/redeem`,{method:`POST`,credentials:`omit`,cache:`no-store`,headers:n?{"content-type":`application/json`,authorization:`Bearer ${n}`}:{"content-type":`application/json`},body:JSON.stringify(t)},1e4),i=null;try{i=await r.json()}catch{}return{status:r.status,body:i}}},peers:{on:async(e,t,n,r,i)=>{let a={};i!==void 0&&(a[`content-type`]=`application/json`),t&&(a.authorization=`Bearer ${t}`);let o=await Wf(`${e}${r}`,{method:n,credentials:`omit`,cache:`no-store`,headers:a,...i===void 0?{}:{body:JSON.stringify(i)}},1e4),s=null;try{s=await o.json()}catch{}return{status:o.status,body:s}}},devices:{list:()=>Kf(`/api/devices`),revoke:e=>qf(`/api/devices/revoke`,{id:e})}};function hp(e,t){return t>0?e*8/(t/1e3)/1e6:0}async function gp(e){try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}var U={...Qf,...$f,...ep,...tp,...ip,...ap,...sp,...dp,...mp};function _p(e){return e==null?null:typeof e==`string`?e.length:typeof Blob<`u`&&e instanceof Blob?e.size:e instanceof ArrayBuffer||ArrayBuffer.isView(e)?e.byteLength:typeof URLSearchParams<`u`&&e instanceof URLSearchParams?e.toString().length:null}function vp(){try{new PerformanceObserver(e=>{for(let t of e.getEntries()){let e=t.initiatorType;if(e===`fetch`||e===`xmlhttprequest`||e===`beacon`)continue;let n=t.transferSize||t.encodedBodySize||0;n>0&&Xd(`down`,n)}}).observe({type:`resource`,buffered:!0})}catch{}}var yp=!1;function bp(){if(!yp){yp=!0;try{let e=globalThis.fetch.bind(globalThis);globalThis.fetch=(async(t,n)=>{let r=_p(n?.body);r!=null&&Xd(`up`,r);let i=await e(t,n),a=Number(i.headers.get(`content-length`));return Number.isFinite(a)&&a>0&&Xd(`down`,a),i})}catch{}try{let e=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.send=function(t){let n=0;try{this.upload?.addEventListener(`progress`,e=>{e.loaded>n&&(Xd(`up`,e.loaded-n),n=e.loaded)})}catch{}let r=0;try{this.addEventListener(`progress`,e=>{e.loaded>r&&(Xd(`down`,e.loaded-r),r=e.loaded)}),this.addEventListener(`loadend`,()=>{let e=Number(this.getResponseHeader?.(`content-length`));if(Number.isFinite(e)&&e>r&&Xd(`down`,e-r),n===0){let e=_p(t);e!=null&&Xd(`up`,e)}})}catch{}return e.call(this,t)}}catch{}vp(),_f();try{window.addEventListener(`pagehide`,()=>{Ad(),Sp()}),document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`hidden`&&(Ad(),Sp())})}catch{}}}function xp(){U.netstats.report({deviceId:kf(),report:If()})}function Sp(){if(!Cp)return;let e=JSON.stringify({deviceId:kf(),report:If()});try{navigator.sendBeacon?navigator.sendBeacon(`/api/netstats`,new Blob([e],{type:`application/json`})):xp()}catch{}}var Cp=!1;function wp(){Cp||(Cp=!0,window.setInterval(()=>{document.visibilityState===`visible`&&xp()},Tie))}var Tp=3e3,Ep=2500,Dp=io(B.netPulse,!0),Op=[];function kp(){return Dp}function Ap(e){Dp=e,ao(B.netPulse,e),e||(Op=[]),Md(`pulse`),Fd()}function jp(e){Op.push(e),Op.length>90&&Op.splice(0,Op.length-90),Md(`pulse`),Fd()}var Mp=null,Np=!1,Pp=null;function Fp(e){Pp=e,Mp??(Mp=window.setInterval(Ip,Tp),document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`visible`&&Ip()}))}async function Ip(){if(Dp&&Pp&&document.visibilityState===`visible`&&!Np){if(Gd(Pp.status),Wd!==`open`)jp({at:Date.now(),ms:null});else{Np=!0;try{jp({at:Date.now(),ms:await Pp.probe(Ep)})}catch{jp({at:Date.now(),ms:null})}finally{Np=!1}}}}function Lp(e,t=200){let n=e.filter(e=>e.ms!=null).map(e=>e.ms),r=[...n].sort((e,t)=>e-t),i=r.length?r[Math.floor((r.length-1)/2)]:null,a=r.length?r[r.length-1]:0,o=e.length?e[e.length-1]:null;return{last:o&&o.ms!=null?o.ms:null,median:i,misses:e.length-n.length,ceiling:Math.max(t,a)}}var Rp=e=>e.split(/[/\\]/).filter(Boolean).pop()||e,zp=e=>e>=1e9?`${(e/1e9).toFixed(1)} GB`:e>=1e6?`${(e/1e6).toFixed(1)} MB`:e>=1e3?`${Math.round(e/1e3)} KB`:`${e} B`;function Bp(e){if(e==null)return`—`;let t=[`B`,`KB`,`MB`,`GB`],n=e,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r++;return`${n>=10||r===0?Math.round(n):n.toFixed(1)} ${t[r]}`}var Vp=yn;function Hp(e){Vp=e}function Up(e){return vt(e,Vp)}function Wp(e){let t=Up(e);return{"--repo-hue":`${t}`,"--repo-accent":`hsl(${t} var(--repo-sat) var(--repo-lit))`}}function Gp(e){let t=Math.max(0,Math.round((Date.now()-e)/1e3));if(t<60)return`${t}s ago`;let n=Math.round(t/60);if(n<60)return`${n}m ago`;let r=Math.round(n/60);if(r<24)return`${r}h ago`;let i=Math.round(r/24);return i<60?`${i}d ago`:`${Math.round(i/30)}mo ago`}function Kp(e){return e.running?e.turnActive?0:e.lastTurnAt?Date.now()-e.lastTurnAt:e.idleSince?Date.now()-e.idleSince:0:1/0}function qp(e){return!e.running||e.turnActive?!0:e.lastTurnAt!=null}function Jp(e){let t=Math.max(0,Math.round((Date.now()-e)/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return`${n}m`;let r=Math.floor(n/60);return r<24?`${r}h`:`${Math.floor(r/24)}d`}function Yp(e){if(e<45e3)return`just now`;let t=Math.round(e/6e4);if(t<60)return`${t} min ago`;let n=Math.round(t/60);return n<48?`${n} h ago`:`${Math.round(n/24)} d ago`}function Xp(e,t){let n=Math.max(0,Math.round(((t??Date.now())-e)/1e3));return n<60?`${n}s`:`${Math.floor(n/60)}m ${n%60}s`}var Zp=0;function Qp(e){return`${e}_${Date.now().toString(36)}_${(Zp++).toString(36)}`}var $p=/\x1b(?:\[[0-9;?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\))/g,em=e=>e.replace($p,``).replace(/\r(?!\n)/g,`
|
|
1
|
+
import{n as e}from"./rolldown-runtime-BpQH8Ho1.js";import{$ as t,$a as n,$c as r,$i as i,$l as a,$n as o,$o as s,$r as c,$s as l,$t as u,A as d,Ac as f,Ai as p,Al as m,An as h,Ao as g,Ar as _,At as v,Ba as y,Bc as b,Bi as x,Bo as S,Br as C,Bt as w,C as T,Ca as E,Ci as D,Cn as O,Cr as k,Cu as A,D as j,Da as M,Dc as N,Di as P,Dl as F,Dn as I,Do as ee,Dr as te,Ds as ne,E as re,Ea as ie,Ec as ae,Ei as oe,El as se,En as ce,Eo as le,Er as ue,Es as de,F as fe,Fa as pe,Fc as me,Fi as he,Fl as ge,Fn as _e,Fo as ve,Fr as ye,Ft as be,Ga as xe,Gc as Se,Gi as Ce,Gn as we,Go as Te,Gr as Ee,Gs as De,Gt as Oe,Ha as ke,Hc as Ae,Hn as je,Ho as Me,Hr as Ne,Hs as Pe,Ht as Fe,Ia as Ie,Ic as Le,Ii as Re,Il as ze,In as Be,Io as Ve,Ir as He,It as Ue,Ja as We,Jc as Ge,Ji as Ke,Jl as qe,Jn as Je,Jo as Ye,Jr as Xe,Jt as Ze,K as Qe,Ka as $e,Kc as et,Kl as tt,Kn as nt,Ko as rt,Kr as it,Ks as at,Kt as ot,L as st,La as ct,Lc as lt,Li as ut,Ll as dt,Ln as ft,Lo as pt,Lr as mt,Lt as ht,M as gt,Mc as _t,Mi as vt,Ml as yt,Mn as bt,Mo as xt,Mr as St,Mt as Ct,N as wt,Nc as Tt,Ni as Et,Nl as Dt,Nn as Ot,No as kt,Nr as At,Ns as jt,Nt as Mt,O as Nt,Oc as Pt,Oi as Ft,On as It,Oo as Lt,Or as Rt,Ot as zt,P as Bt,Pc as Vt,Pi as Ht,Pl as Ut,Pn as Wt,Po as Gt,Pr as Kt,Pt as qt,Q as Jt,Qa as Yt,Qc as Xt,Qi as Zt,Ql as Qt,Qn as $t,Qo as en,Qr as tn,Qs as nn,Qt as rn,R as an,Rc as eee,Ri as on,Rl as sn,Rn as tee,Ro as cn,Rr as nee,Rs as ln,Rt as un,S as dn,Sa as ree,Sc as fn,Si as pn,Sl as iee,Sn as mn,Sr as hn,Su as gn,Ta as _n,Tc as vn,Ti as yn,Tl as aee,Tn as bn,Tr as xn,Tt as oee,Tu as Sn,U as Cn,Ua as wn,Uc as Tn,Ur as En,Us as Dn,Ut as On,Va as see,Vc as cee,Vl as kn,Vo as An,Vr as lee,Vs as jn,Vt as Mn,W as Nn,Wa as Pn,Wc as Fn,Wi as In,Wl as Ln,Wn as Rn,Wo as zn,Wr as Bn,Ws as Vn,Wt as uee,X as dee,Xa as Hn,Xc as Un,Xo as Wn,Xr as fee,Xs as Gn,Xt as pee,Y as Kn,Ya as mee,Yc as qn,Yl as hee,Yn as Jn,Yo as Yn,Ys as gee,Z as Xn,Za as Zn,Zc as Qn,Zi as $n,Zl as er,Zn as tr,Zo as nr,Zr as rr,Zs as ir,Zt as ar,_ as or,_a as sr,_c as cr,_i as lr,_l as _ee,_n as vee,_o as yee,_r as ur,_s as dr,_t as bee,_u as fr,a as pr,aa as xee,ac as L,ai as mr,al as hr,an as See,ao as Cee,ar as wee,as as gr,au as _r,b as Tee,ba as vr,bc as yr,bi as br,bl as Eee,bn as Dee,bo as Oee,br as kee,bu as Aee,c as jee,ca as xr,ci as Mee,cl as Sr,cn as Nee,co as Pee,cr as Cr,cs as Fee,cu as Iee,d as Lee,da as Ree,dc as wr,di as zee,dl as Bee,dn as Tr,do as Er,dr as Dr,ds as Or,dt as kr,du as Ar,ea as jr,ec as Mr,ei as Nr,el as Pr,en as Fr,eo as Ir,er as Lr,et as Rr,fa as zr,fc as Br,fi as Vr,fl as Hr,fn as Ur,fo as Wr,fr as Gr,fs as Kr,fu as qr,g as Jr,ga as Yr,gi as Xr,gl as Zr,gn as Vee,go as Hee,gr as Qr,gs as $r,gt as Uee,gu as Wee,h as ei,ha as Gee,hc as ti,hi as Kee,hl as qee,hn as ni,ho as Jee,hr as Yee,hs as Xee,ht as Zee,hu as ri,i as Qee,ia as ii,ic as ai,ii as $ee,il as oi,in as ete,ir as si,is as tte,it as nte,iu as ci,ja as rte,jc as li,ji as ui,jl as di,jo as ite,jr as fi,jt as ate,k as ote,kc as pi,ki as ste,kn as mi,ko as cte,kr as hi,kt as gi,lc as _i,li as lte,ll as vi,ln as ute,lo as dte,lr as fte,lu as pte,m as mte,ma as yi,mc as bi,mi as hte,ml as gte,mn as _te,mr as vte,ms as xi,mt as yte,mu as Si,n as bte,na as Ci,nc as xte,ni as Ste,nl as wi,nn as Ti,no as Ei,nr as Cte,nt as wte,nu as Tte,o as Di,oa as Oi,oc as ki,oi as Ete,ol as Dte,on as Ai,oo as ji,or as Ote,os as Mi,ot as kte,ou as Ate,p as jte,pa as Ni,pc as Mte,pi as Nte,pl as Pte,pn as Fte,po as Ite,pr as Lte,ps as Pi,pt as Rte,pu as zte,q as Bte,qa as Vte,qc as Fi,ql as Ii,qn as Hte,qo as Li,qr as Ute,qt as Wte,r as Ri,ra as Gte,rc as zi,ri as Bi,rl as Vi,rn as Hi,rr as Ui,rt as Wi,ru as Gi,s as Ki,sa as qi,sc as Ji,si as Yi,sl as Xi,sn as Zi,so as Qi,sr as $i,st as ea,su as ta,ta as na,tc as ra,ti as ia,tl as R,tn as aa,tr as oa,ts as sa,tt as ca,u as la,ua,ui as da,ul as fa,un as pa,uo as ma,ur as ha,us as ga,ut as _a,uu as va,v as ya,va as ba,vi as xa,vl as Sa,vn as Ca,vo as wa,vr as Ta,vt as Ea,vu as Da,w as Oa,wa as ka,wc as Aa,wi as ja,wl as Ma,wn as Na,wr as Pa,wt as Fa,wu as Ia,x as La,xa as Ra,xc as za,xi as Ba,xl as Va,xn as Ha,xr as Kte,xu as qte,y as Jte,ya as Ua,yc as Wa,yi as Ga,yl as Yte,yn as Xte,yo as Zte,yr as Qte,yu as Ka,z as $te,za as qa,zc as Ja,zi as ene,zl as tne,zn as Ya,zo as Xa,zr as nne,zt as rne}from"./shared-DjRRLGfw.js";import{C as Za,D as ine,E as ane,O as one,S as Qa,T as $a,_ as eo,b as z,c as to,d as sne,f as no,g as cne,h as ro,i as lne,m as B,o as une,r as dne,s as fne,u as pne,v as io,w as ao,x as oo,y as so}from"./demo-DkCtg-SJ.js";import{i as mne,r as hne,t as gne}from"./react-CoSyT_xY.js";import{$ as co,$i as lo,$n as _ne,$r as uo,$t as vne,A as fo,Ai as po,An as yne,Ar as mo,At as ho,B as go,Bi as _o,Bn as bne,Br as xne,Bt as vo,C as Sne,Ci as yo,Cr as Cne,Ct as bo,D as xo,Di as So,Dn as Co,Dr as wne,Dt as Tne,E as Ene,Ei as wo,En as To,Er as Dne,Et as Eo,F as Do,Fi as Oo,Fn as ko,Fr as Ao,Ft as One,G as jo,Gi as Mo,Gn as No,Gt as Po,H as Fo,Hi as Io,Hn as kne,Hr as Lo,Ht as Ro,I as zo,Ii as Bo,In as Vo,Ir as Ane,It as Ho,Ji as jne,Jn as Mne,Jr as Uo,Jt as Nne,K as Wo,Ki as Go,Kn as Ko,Kr as qo,Kt as Pne,L as Jo,Ln as Yo,Lr as Fne,Lt as Xo,M as Zo,Mi as Qo,Mn as Ine,Mr as $o,Mt as es,N as Lne,Ni as ts,Nn as ns,Nr as rs,Nt as Rne,Oi as is,On as zne,Or as as,Ot as os,Pi as ss,Pn as cs,Pr as ls,Pt as us,Q as ds,Qi as fs,Qn as ps,Qr as ms,Qt as hs,Ri as gs,Rn as _s,Rr as vs,Rt as Bne,S as Vne,Si as ys,Sn as bs,Sr as Hne,St as xs,T as Une,Ti as Ss,Tn as Cs,Tr as Wne,Tt as ws,U as Gne,Ui as Ts,Un as Es,Ur as Ds,Ut as Kne,V as Os,Vi as ks,Vn as As,Vr as js,Vt as Ms,Wi as qne,Wn as Ns,Wr as Ps,Wt as Fs,X as Is,Xn as Ls,Xr as Rs,Xt as zs,Yi as Bs,Yn as Vs,Yr as Hs,Z as Us,Zi as Ws,Zn as Gs,Zr as Ks,Zt as qs,_ as Js,_i as Ys,_n as Xs,_r as Zs,_t as Qs,a as $s,ai as ec,an as tc,ar as nc,at as rc,b as ic,bi as ac,bn as oc,br as sc,bt as cc,c as lc,ci as uc,cn as dc,ct as fc,d as pc,dn as mc,dr as hc,dt as gc,ea as _c,ei as vc,en as yc,er as bc,et as xc,f as Sc,fi as Cc,fn as wc,fr as Tc,ft as Ec,g as Dc,gr as Oc,gt as kc,h as Ac,hn as jc,hr as Mc,ht as Nc,i as V,ii as Pc,in as Fc,ir as Ic,it as Lc,j as Rc,ji as zc,jn as Bc,jr as Vc,jt as Hc,ki as Uc,kn as Wc,kr as Gc,kt as Kc,l as qc,li as Jc,lr as Yc,lt as Xc,mn as Zc,mr as Qc,mt as $c,n as el,na as tl,ni as nl,nn as rl,nr as il,nt as al,o as ol,oi as sl,or as cl,ot as ll,p as Jne,pi as Yne,pn as ul,pr as dl,pt as fl,q as Xne,qi as pl,qn as Zne,qt as ml,ra as hl,ri as gl,rn as Qne,rr as $ne,rt as _l,s as vl,si as yl,sn as bl,sr as xl,st as ere,t as tre,ta as Sl,ti as Cl,tn as nre,tr as wl,tt as Tl,u as El,ui as Dl,un as Ol,ur as rre,ut as kl,v as Al,vi as jl,vn as Ml,vr as Nl,vt as Pl,w as Fl,wi as Il,wn as Ll,wr as ire,wt as Rl,x as zl,xi as Bl,xn as Vl,xr as are,xt as ore,y as sre,yi as Hl,yn as Ul,yr as cre,yt as Wl,z as Gl,zn as Kl,zr as lre,zt as ql}from"./icons-B48F-4nA.js";import{t as ure}from"./vendor-BPwPmufs.js";function dre(e){if(e===B.syncTs)return!0;if(!e.startsWith(xr))return!1;let t=e.slice(xr.length),n=t.indexOf(`.`);return n>0&&`${L.storagePrefix}${t.slice(n+1)}`===B.syncTs}function fre(e){let t;try{t=JSON.parse(e)}catch{return e}if(!t||typeof t!=`object`||Array.isArray(t))return e;let n={},r=t;for(let[e,t]of Object.entries(r))re(e)===null&&(n[e]=t);for(let[e,t]of Object.entries(r)){let r=re(e);r!==null&&!(r in n)&&(n[r]=t)}return JSON.stringify(n)}function pre(e,t){let n=j(e,t);for(let[,t]of n.copied){if(!dre(t))continue;let n=e.getItem(t);n!==null&&e.setItem(t,fre(n))}return n}function mre(){try{let e=globalThis.localStorage;if(!e)return;let t=pre(e,Date.now());t.ran&&(t.copied.length||t.kept.length)&&console.info(`[storage] copied ${t.copied.length} keys from an older name, kept ${t.kept.length} newer ones`)}catch{}}function Jl(){try{let e=JSON.parse(globalThis.localStorage?.getItem(B.brandStores)??`[]`);return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}catch{return[]}}function Yl(e){try{let t=Jl();t.includes(e)||globalThis.localStorage?.setItem(B.brandStores,JSON.stringify([...t,e]))}catch{}}var hre=[`uploads`,`dictations`,`screenlog`,`pulls`];function gre(e){return new Promise(t=>{try{let n=indexedDB.open(e);n.onupgradeneeded=()=>{try{n.transaction?.abort()}catch{}},n.onsuccess=()=>t(n.result),n.onerror=e=>{e.preventDefault?.(),t(null)},n.onblocked=()=>t(null)}catch{t(null)}})}function _re(e,t){return new Promise(n=>{try{let r=e.transaction(t,`readonly`),i=r.objectStore(t),a=i.getAllKeys(),o=i.getAll();r.oncomplete=()=>n({keys:a.result,values:o.result}),r.onerror=()=>n(null),r.onabort=()=>n(null)}catch{n(null)}})}function vre(e,t,n,r){return new Promise(i=>{try{let a=e.transaction(t,`readwrite`),o=a.objectStore(t),s=o.getAllKeys();s.onsuccess=()=>{let e=new Set(s.result.map(e=>JSON.stringify(e)));n.forEach((t,n)=>{e.has(JSON.stringify(t))||o.put(r[n],t)})},a.oncomplete=()=>i(!0),a.onerror=()=>i(!1),a.onabort=()=>i(!1)}catch{i(!1)}})}async function yre(e,t){let n=`idb:${e.name}`;if(typeof indexedDB>`u`||Jl().includes(n))return;let r=!0;for(let n of t){if(n===e.name)continue;let t=await gre(n);if(t)try{for(let n of hre){if(!t.objectStoreNames.contains(n)||!e.objectStoreNames.contains(n))continue;let i=await _re(t,n);i?i.keys.length&&!await vre(e,n,i.keys,i.values)&&(r=!1):r=!1}}finally{t.close()}}r&&Yl(n)}var Xl=e=>`${e}-pulls-v1`,Zl=Xl(L.slug),Ql=ki.map(e=>Xl(e.slug)),bre=[Zl,...Ql],$l=null;function xre(){return $l||=(async()=>{let e=`cache:${Zl}`;if(!(typeof caches>`u`||Jl().includes(e))){for(let e of Ql){if(!await caches.has(e))continue;let t=await caches.open(e),n=await caches.open(Zl);for(let e of await t.keys()){if(await n.match(e))continue;let r=await t.match(e);r&&await n.put(e,r)}}Yl(e)}})().catch(()=>{}),$l}function eu(){try{return globalThis.localStorage??null}catch{return null}}function tu(e){let t=[];for(let n=0;n<e.length;n++){let r=e.key(n);r!=null&&t.push(r)}return t}function nu(e){if(!e)return null;try{let t=JSON.parse(e),n=e=>yi(e)?e:null;if(!t||typeof t!=`object`)return null;let r={from:n(t.from),to:n(t.to)};return yi(t.drop)&&(r.drop=t.drop),t.parked===!0&&(r.parked=!0),r}catch{return null}}function ru(e){return Ra(e.getItem(B.hosts))??[]}function iu(e){return Ra(e.getItem(B.hostsGone))??[]}function au(e){let t=e.getItem(B.hostActive);return t&&ru(e).some(e=>e.id===t)?t:null}function ou(e){let t=e.getItem(B.hostActive);return ru(e).find(e=>e.id===t)??null}function su(e,t){for(let n of t){if(n.op===`remove`){e.removeItem(n.key);continue}let t=e.getItem(n.from);t!==null&&e.setItem(n.to,t)}}function Sre(e,t,n){for(let r of tu(e)){let i=ua(r,t);if(!i||eo(i)||n&&e.getItem(i)!==null)continue;let a=e.getItem(r);a!==null&&e.setItem(i,a)}}function cu(e){let t=nu(e.getItem(B.hostSwitch));if(!t)return e.getItem(B.hostSwitch)!==null&&e.removeItem(B.hostSwitch),!1;let n=ru(e),r=e.getItem(B.hostActive),i=t.to&&n.some(e=>e.id===t.to)?t.to:null;if(t.from!==null&&r===t.from){let n=E(tu(e),eo,t.from,i??`-`),r=Ua(i??`-`),a=Ua(t.from),o=e=>e.op===`copy`&&e.from.startsWith(r),s=e=>e.op===`copy`&&!o(e)||e.op===`remove`&&e.key.startsWith(a),c=e=>e.op===`remove`&&!e.key.startsWith(a);t.parked||(su(e,n.filter(s)),e.setItem(B.hostSwitch,JSON.stringify({...t,parked:!0}))),su(e,n.filter(c)),i?e.setItem(B.hostActive,i):e.removeItem(B.hostActive),su(e,n.filter(o))}else(t.from===null||r===i)&&i&&(e.setItem(B.hostActive,i),Sre(e,i,t.from===null));if(t.drop&&t.drop!==e.getItem(B.hostActive)){let n=ru(e),r=n.find(e=>e.id===t.drop);r&&(e.setItem(B.hosts,ka(n.filter(e=>e.id!==t.drop))),e.setItem(B.hostsGone,ka([r,...iu(e).filter(e=>e.id!==r.id)])))}let a=ou(e);return a?e.setItem(B.hostBase,a.base):e.removeItem(B.hostBase),e.removeItem(B.hostSwitch),!0}function Cre(e){if(e){try{cu(e)}catch(t){try{wre(t)&&Ere(e)}catch{}}try{Mre(e);let t=ree({hosts:e.getItem(B.hosts),active:e.getItem(B.hostActive),hostBase:e.getItem(B.hostBase)});t.writes.hosts!==void 0&&e.setItem(B.hosts,t.writes.hosts),t.writes.active!==void 0&&e.setItem(B.hostActive,t.writes.active),t.writes.hostBase!==void 0&&e.setItem(B.hostBase,t.writes.hostBase)}catch{}}}function wre(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.name===`QuotaExceededError`||t.name===`NS_ERROR_DOM_QUOTA_REACHED`||t.code===22||t.code===1014}function Tre(e,t){let n=e.length>1?e.find(e=>e.id===t)?.name:void 0;return n?` — ${n} is not answering`:` — the connection may be down`}function Ere(e){let t=nu(e.getItem(B.hostSwitch));if(!t)return;let n=e.getItem(B.hostActive),r;if(t.from!==null&&n===t.from&&!t.parked){for(let n of tu(e)){let r=ua(n,t.from);r&&e.getItem(r)!==null&&e.removeItem(n)}e.removeItem(B.hostSwitch),r=`park`}else if(t.to!==null&&n===t.to)r=`restore`;else return;let i={stage:r,from:t.from,to:t.to,at:Date.now()};e.setItem(B.hostSwitchFailed,JSON.stringify(i))}function Dre(e){if(!e)return null;let t=e.getItem(B.hostSwitchFailed);if(t===null)return null;try{e.removeItem(B.hostSwitchFailed)}catch{}try{let e=JSON.parse(t);if(e.stage!==`park`&&e.stage!==`restore`)return null;let n=e=>yi(e)?e:null;return{stage:e.stage,from:n(e.from),to:n(e.to),at:typeof e.at==`number`?e.at:0}}catch{return null}}function lu(e){return!e||!e.base?null:Ree({base:e.base,ssids:e.ssids??[],auto:e.auto===!0})}function uu(e,t){let n=_n(t.base);if(!n)return{ok:!1,why:`Not an address. Use a host name or IP, optionally with a port.`};let r=ru(e);if(r.some(e=>e.base===n))return{ok:!1,why:`That address is already in the list.`};let i=iu(e),a=i.find(e=>e.base===n),o={id:a?.id??Yr([...r,...i].map(e=>e.id)),name:sr(t.name)??a?.name??Ni(n),base:n};a?.legacy&&!r.some(e=>e.legacy)&&(o.legacy=!0);let s=lu(t.lan);return s&&(o.lan=s),e.setItem(B.hosts,ka([...r,o])),a&&e.setItem(B.hostsGone,ka(i.filter(e=>e.id!==a.id))),{ok:!0,host:o,reused:!!a}}function du(e,t,n){let r=ru(e),i=r.findIndex(e=>e.id===t);if(i<0)return{ok:!1,why:`That host is no longer in the list.`};let a=_n(n.base);if(!a)return{ok:!1,why:`Not an address. Use a host name or IP, optionally with a port.`};if(r.some(e=>e.id!==t&&e.base===a))return{ok:!1,why:`Another host already has that address.`};let o=r[i],s={id:t,name:sr(n.name)??Ni(a),base:a};o.legacy&&(s.legacy=!0);let c=n.lan===void 0?o.lan??null:lu(n.lan);c&&(s.lan=c);let l=r.slice();return l[i]=s,e.setItem(B.hosts,ka(l)),e.getItem(B.hostActive)===t&&e.setItem(B.hostBase,a),{ok:!0,host:s,reused:!1}}function Ore(e,t){let n=ru(e);return n.some(e=>e.id===t)?e.getItem(B.hostActive)===t?{kind:`switch`,next:n.find(e=>e.id!==t)?.id??null}:{kind:`drop`}:null}function kre(e,t){if(e.getItem(B.hostActive)===t)return!1;let n=ru(e),r=n.find(e=>e.id===t);return r?(e.setItem(B.hosts,ka(n.filter(e=>e.id!==t))),e.setItem(B.hostsGone,ka([r,...iu(e).filter(e=>e.id!==t)])),!0):!1}function fu(e,t){t.from===`demohost`&&e.removeItem(B.demo),e.setItem(B.hostSwitch,JSON.stringify(t))}function pu(){try{history.replaceState(null,``,location.pathname)}catch{}location.reload()}function mu(e){let t=eu();if(!t)return!1;let n=t.getItem(B.hostActive);return n===e||!ru(t).some(t=>t.id===e)?!1:(fu(t,{from:yi(n)?n:null,to:e}),pu(),!0)}function Are(e){let t=eu();if(!t)return null;let n=Ore(t,e);return n?n.kind===`drop`?kre(t,e)?`dropped`:null:(fu(t,{from:e,to:n.next,drop:e}),pu(),`switching`):null}function hu(e){let t=eu();if(!t)return{ok:!1,why:`This phone's storage is not available.`};let n=uu(t,e);if(!n.ok)return n;let r=t.getItem(B.hostActive);return fu(t,{from:yi(r)&&ru(t).some(e=>e.id===r)?r:null,to:n.host.id}),pu(),n}function gu(){let e=eu();return e?ru(e):[]}function _u(){let e=eu();return e?ou(e):null}var vu=`demohost`,jre=`http://demo.invalid:8770`;function yu(e){return(typeof e==`string`?e:e?.id)===vu}function bu(e){return e.filter(e=>!yu(e))}function xu(e){let t=bu(ru(e)),n=e.getItem(B.demoReturn);return t.find(e=>e.id===n)?.id??t[0]?.id??null}function Mre(e){if(e.getItem(B.hostActive)===`demohost`&&!e.getItem(B.demo)&&(fu(e,{from:vu,to:xu(e)}),cu(e)),e.getItem(B.hostActive)===`demohost`)return;e.removeItem(B.demo);let t=ru(e);t.some(yu)&&e.setItem(B.hosts,ka(bu(t)));let n=iu(e);n.some(yu)&&e.setItem(B.hostsGone,ka(bu(n)));let r=Ua(vu);for(let t of tu(e))t.startsWith(r)&&e.removeItem(t)}function Nre(e,t){let n=e.getItem(B.hostActive);if(n===`demohost`)return!1;let r=ru(e);r.some(yu)||e.setItem(B.hosts,ka([...r,{id:vu,name:`Demo`,base:jre}]));let i=yi(n)&&r.some(e=>e.id===n)?n:null;return i?e.setItem(B.demoReturn,i):e.removeItem(B.demoReturn),e.setItem(B.demo,t),fu(e,{from:i,to:vu}),!0}function Pre(e){e.removeItem(B.demo),e.getItem(B.hostActive)===`demohost`&&fu(e,{from:vu,to:xu(e)})}function Fre(e){let t=eu();if(!t)return!1;try{globalThis.sessionStorage?.removeItem(ro(e))}catch{}if(!Nre(t,e))return!1;try{history.replaceState(null,``,location.pathname)}catch{}return location.reload(),!0}function Ire(){let e=eu();if(!e)return!1;let t=e.getItem(B.demo);try{t&&globalThis.sessionStorage?.removeItem(ro(t))}catch{}Pre(e);try{history.replaceState(null,``,location.pathname)}catch{}return location.reload(),!0}var Lre=L.wsProtocol,Rre=`${L.wsProtocol}-tok.`;function Su(e){return!!e&&/^[A-Za-z0-9_-]{16,256}$/.test(e)}function Cu(e){return typeof e==`string`&&Su(e)}function wu(){let e=z(B.deviceToken);return Su(e)?e:null}function zre(e){Su(e)&&Za(B.deviceToken,e)}function Tu(){so(B.deviceToken)}function Bre(e,t,n){if(!n||!t)return null;try{return new URL(e).origin===new URL(t).origin?`Bearer ${n}`:null}catch{return null}}function Vre(e){return e?[Lre,`${Rre}${e}`]:void 0}function Eu(e,t){return(e.trim()||t.trim()||`Android phone`).slice(0,60)}var Du=null;function Hre(e){Du=e}function Ou(e){try{Du?.(e)}catch{}}var Ure=B.hostBase;function ku(){let e=globalThis.Capacitor;try{return!!e?.isNativePlatform?.()}catch{return!1}}var Au,ju=null;function Wre(e,t,n){let r=t?Ra(e)?.find(e=>e.id===t):void 0;return r&&_n(r.base)||_n(n||``)}function Mu(){return Au===void 0&&(Au=null,ku()&&(Au=Wre(z(B.hosts),z(B.hostActive),z(Ure)))),Au}function Nu(){let e=Mu();return e===null?null:ju??e}function Pu(e){if(!ku()||Mu()===null)return ju=null,null;let t=e===null?null:_n(e);return ju=t&&t!==Mu()?t:null,Nu()}function Fu(){return ju}function Gre(){return no()?!0:!ku()||Nu()!==null}function Iu(e){return no()?une(e):ie(Mu(),e)}function Lu(){if(no())return fne;let e=Nu();return e?M(e,`/ws`):ku()?null:`${location.protocol===`https:`?`wss`:`ws`}://${location.host}/ws`}var Ru=!1;function Kre(){if(Ru||no()||!Nu())return;Ru=!0;let e=()=>Nu()??``,t=globalThis.fetch.bind(globalThis),n=e=>Bre(e,Nu(),wu()),r=(e,t)=>t?e.then(e=>(e.status===401&&Ou(`http`),e)):e,i=(e,t)=>{if(!t)return e;let n=new Headers(e?.headers);return n.has(`authorization`)?e:(n.set(`authorization`,t),{...e,headers:n})};globalThis.fetch=((a,o)=>{if(typeof a!=`string`&&!(a instanceof URL)){let i=zu(a.url),s=i===null?a:new Request(ie(e(),i),a),c=n(s.url);if(c&&!s.headers.has(`authorization`))try{s.headers.set(`authorization`,c)}catch{}return r(t(s,o),c)}let s=String(a),c=s.startsWith(`/`)?s:zu(s);if(c===null){let e=n(s);return r(t(a,i(o,e)),e)}let l=ie(e(),c);if(l===c&&c===s)return t(a,o);let u=n(l);return r(t(l,i({credentials:`include`,...o},u)),u)});let a=XMLHttpRequest.prototype.open;if(XMLHttpRequest.prototype.open=function(t,r,...i){let o=String(r),s=o.startsWith(`/`)?o:zu(o),c=s===null?o:ie(e(),s),l=a.call(this,t,c,...i),u=n(c);if(u)try{this.setRequestHeader(`authorization`,u),this.addEventListener(`load`,()=>{this.status===401&&Ou(`http`)},{once:!0})}catch{}return l},qre(),typeof navigator<`u`&&typeof navigator.sendBeacon==`function`){let e=navigator.sendBeacon.bind(navigator);navigator.sendBeacon=((t,n)=>{let r=String(t),i=r.startsWith(`/`)?r:zu(r);return e(i===null?r:ie(Mu()??``,i),n)})}}function qre(){let e=e=>{let t=Mu(),n=Nu();return!!t&&e.startsWith(t)||!!n&&e.startsWith(n)},t=(t,n,r)=>(n===`src`||n===`poster`)&&(t instanceof HTMLImageElement||t instanceof HTMLVideoElement)&&typeof r==`string`&&e(r);try{let e=Element.prototype.setAttribute;Element.prototype.setAttribute=function(n,r){if(t(this,n,r)&&!this.crossOrigin)try{this.crossOrigin=`anonymous`}catch{}return e.call(this,n,r)};for(let e of[HTMLImageElement.prototype,HTMLVideoElement.prototype]){let n=Object.getOwnPropertyDescriptor(e,`src`);n?.set&&n.get&&Object.defineProperty(e,"src",{configurable:!0,enumerable:n.enumerable,get:n.get,set(e){if(t(this,`src`,e)&&!this.crossOrigin)try{this.crossOrigin=`anonymous`}catch{}n.set.call(this,e)}})}}catch{}}function zu(e){try{let t=new URL(e,location.href);return t.origin===location.origin?`${t.pathname}${t.search}${t.hash}`:null}catch{return null}}var H=mne(),Jre=[{label:`smaller`,value:.9},{label:`default`,value:1},{label:`larger`,value:1.15},{label:`largest`,value:1.3},{label:`huge`,value:1.45}],Yre=[{label:`smaller`,value:.9},{label:`default`,value:1},{label:`larger`,value:1.2},{label:`largest`,value:1.4}],Xre=.9,Zre=1.45,Qre=.9,$re=1.4;function Bu(e,t,n){let r=Number(e);return e===null||e.trim()===``||!Number.isFinite(r)?1:Math.min(n,Math.max(t,r))}var eie=[.6,.7,.8,.9,1,1.15,1.3,1.5],Vu=.6,Hu=1.5;function Uu(e,t){let n=Math.round(13*e*t);return Number.isFinite(n)?Math.min(28,Math.max(7,n)):13}function Wu(e,t,n){let r=eie,i=0;for(let t=1;t<r.length;t++)Math.abs(r[t]-e)<Math.abs(r[i]-e)&&(i=t);let a=n(e);for(let e=i+t;e>=0&&e<r.length;e+=t)if(n(r[e])!==a)return r[e];return null}var tie=(e,t,n)=>Wu(e,t,e=>Uu(n,e)),nie=.6,rie=1.9;function Gu(e,t){let n=e*t;return Number.isFinite(n)?Math.round(Math.min(rie,Math.max(nie,n))*100)/100:1}var Ku=(e,t,n)=>Wu(e,t,e=>Gu(n,e)),qu=()=>Bu(z(B.textScale),Xre,Zre),Ju=()=>Bu(z(B.iconScale),Qre,$re),Yu=()=>Bu(z(B.termZoom),Vu,Hu),iie=()=>Uu(qu(),Yu()),aie=()=>Bu(z(B.readerZoom),Vu,Hu),oie=()=>Bu(z(B.scrollZoom),Vu,Hu),sie=()=>Bu(z(B.gitZoom),Vu,Hu),Xu=`app:uiscale`;function Zu(){let e=document.documentElement;e.style.setProperty(`--ui-font`,String(qu())),e.style.setProperty(`--ui-icon`,String(Ju()));try{window.dispatchEvent(new CustomEvent(Xu))}catch{}}function cie(e){Za(B.textScale,String(e)),Zu()}function lie(e){Za(B.iconScale,String(e)),Zu()}function uie(e){Za(B.termZoom,String(e)),Zu()}function die(e){Za(B.readerZoom,String(e)),Zu()}function fie(e){Za(B.scrollZoom,String(e)),Zu()}function pie(e){Za(B.gitZoom,String(e)),Zu()}function mie(){Zu()}function hie(e){return window.addEventListener(Xu,e),()=>window.removeEventListener(Xu,e)}var Qu=`theme-overlay`,$u={},ed=null,td=new Set,nd=()=>$u,rd=()=>$u.displayName??L.name;function gie(e){return td.add(e),()=>{td.delete(e)}}function id(e){ed=e||null;try{document.title=ed?`${ed} — ${rd()}`:rd()}catch{}}function ad(e){try{let t=document.getElementById(Qu);if(!e){t?.remove();return}t||(t=document.createElement(`style`),t.id=Qu,document.head.appendChild(t)),t.textContent!==e&&(t.textContent=e)}catch{}}function od(e,t=!0){let{overlay:n}=Ki(e),r=Lee(n),i=r?{}:n,a=la(i);if(ad(a),t&&(r?(so(B.themeOverlay),so(B.themeOverlayCss)):(Za(B.themeOverlay,JSON.stringify(i)),a?Za(B.themeOverlayCss,a):so(B.themeOverlayCss))),JSON.stringify(i)===JSON.stringify($u))return!1;$u=i,id(ed);for(let e of td)try{e()}catch{}return!0}function _ie(){let e=oo(B.themeOverlay,void 0);e===void 0?ad(``):od(e,!1)}async function vie(e){try{let t=await e(`/api/theme`);t&&typeof t==`object`&&`overlay`in t&&od(t.overlay)}catch{}}var sd=new Map,cd=new Set,ld=!1;function ud(e){let t=sd.get(e);return t||(t={wroteAt:null,ackedAt:null,superseded:!1},sd.set(e,t)),t}function dd(){for(let e of cd)e()}function fd(e){return cd.add(e),()=>{cd.delete(e)}}function pd(e,t){let n=ud(e);n.wroteAt=t,n.superseded=!1,dd()}function md(e,t){let n=ud(e);n.ackedAt!=null&&n.ackedAt>=t||(n.ackedAt=t,n.superseded=!1,dd())}function hd(e,t){let n=ud(e);n.ackedAt=t,n.superseded=!0,dd()}function yie(e){ld!==e&&(ld=e,dd())}function gd(e){let t=sd.get(e);if(!t||t.wroteAt==null&&t.ackedAt==null)return{phase:`unknown`,wroteAt:null,ackedAt:null};let n={wroteAt:t.wroteAt,ackedAt:t.ackedAt};return t.superseded?{phase:`superseded`,...n}:t.wroteAt==null||t.ackedAt!=null&&t.ackedAt>=t.wroteAt?{phase:`synced`,...n}:{phase:ld?`pending`:`offline`,...n}}var _d={failed:5,superseded:4,pending:3,offline:2,synced:1,unknown:0};function bie(e){let t={phase:`unknown`,wroteAt:null,ackedAt:null};for(let n of e){let e=gd(n);_d[e.phase]>_d[t.phase]&&(t=e)}return t}function vd(e,t=`these`,n=!0){let r=n?`are`:`is`,i=n?`were`:`was`;switch(e.phase){case`synced`:return`saved on the desktop — ${t} ${r} on more than this phone`;case`pending`:return`not on the desktop yet — ${t} ${r} still only on this phone`;case`offline`:return`no connection — ${t} ${r} only on this phone until the link is back`;case`superseded`:return`another device wrote a newer version — ${t} ${i} replaced, and nothing of yours was deleted`;case`failed`:return`the send gave up — ${t} never reached the desktop, and the words are still here`;default:return null}}function yd(e){return e.failed?`failed`:e.queued?e.online?`pending`:`offline`:e.onHost?`synced`:`unknown`}function bd(e){switch(e){case`synced`:return`on desktop`;case`pending`:return`queued`;case`offline`:return`queued · offline`;case`superseded`:return`replaced`;case`failed`:return`not sent`;default:return null}}function xd(e,t=!1){return t&&e===`synced`?null:bd(e)}function xie(e){let t=e.filter(e=>e!==`unknown`).length,n=e.filter(e=>e===`synced`).length;if(n===0)return null;let r=bd(`synced`),i=n===t,a=i?t===1?`the one row here`:`all ${t} rows here`:`${n} of the ${t} rows here`;return{word:i?r:`${n} of ${t} ${r}`,title:vd({phase:`synced`,wroteAt:null,ackedAt:null},a,i?t!==1:n!==1)}}function Sie(e){let t=0;for(let n of e){let e=gd(n).phase;(e===`pending`||e===`offline`)&&t++}return t}function Cie(e,t,n){return e&&t!==n}function wie(e,t,n){if(t===void 0||!n)return null;let r;try{r=n(t,e)}catch{return null}return typeof r!=`string`||r===e?null:r}var Tie=6e4,Eie=3e3,Die=864e5,Sd=B.netlog,Cd=B.deviceId;function wd(e){return{since:e,rtt:[],send:[],reconnects:0,reloads:0,offlineMs:0,markTs:e,online:!1,sent:0,failed:0,expired:0,ackTimeouts:0,queuedMaxMs:0}}function Oie(){let e=Date.now(),t={v:2,log:wd(e),sync:{lastSeenAt:0,parts:{sessions:0,repos:0}},traffic:{since:e,up:0,down:0}},n=z(Sd);if(!n)return Ed(t);let r;try{r=JSON.parse(n)}catch{return t}let i=r;return!i||typeof i!=`object`?t:i.v===2?{v:2,log:Td(i.log??{},e),sync:{lastSeenAt:Number(i.sync?.lastSeenAt)||0,parts:{sessions:Number(i.sync?.parts?.sessions)||0,repos:Number(i.sync?.parts?.repos)||0}},traffic:{since:Number(i.traffic?.since)||e,up:Math.max(0,i.traffic?.up||0),down:Math.max(0,i.traffic?.down||0)}}:Ed({...t,log:Td(i,e)})}function Td(e,t){return typeof e.since!=`number`||t-e.since>Die?wd(t):{...wd(t),...e,rtt:Array.isArray(e.rtt)?e.rtt:[],send:Array.isArray(e.send)?e.send:[]}}function Ed(e){try{let t=z(B.netSync);if(t){let n=JSON.parse(t);n&&typeof n.lastSeenAt==`number`&&(e.sync={lastSeenAt:n.lastSeenAt,parts:{sessions:Number(n.parts?.sessions)||0,repos:Number(n.parts?.repos)||0}}),so(B.netSync)}}catch{}try{let t=z(B.netTraffic);if(t){let n=JSON.parse(t);n&&typeof n.since==`number`&&(e.traffic={since:n.since,up:Math.max(0,n.up|0),down:Math.max(0,n.down|0)}),so(B.netTraffic)}}catch{}return e}var Dd=Oie(),Od=null;function kd(){Od??=window.setTimeout(()=>{Od=null,$a(Sd,Dd)},Eie)}function Ad(){Od!=null&&(window.clearTimeout(Od),Od=null),$a(Sd,Dd)}var jd=new Set;function Md(...e){for(let t of e)jd.add(t)}var Nd=new Set,Pd=null;function kie(e){Pd=e}function Fd(){if(!Nd.size||!Pd)return;let e=Pd();for(let t of Nd)t.fn(e)}var Aie=12e4,Id={},Ld=null,Rd=`default`,zd=new Set;function Bd(e){Id=e;for(let e of zd)e()}function jie(e){return zd.add(e),()=>{zd.delete(e)}}function Vd(){return Id}function Mie(e=Date.now(),t){let n=oo(B.hostBoots,{})[Rd]?.usualMs;Bd({since:e,usualMs:n,...t?{reason:t}:{}})}function Nie(e=Date.now()){Ld??=e}function Pie(e,t=Date.now()){Rd=e.hostId??`default`;let n=oo(B.hostBoots,{}),r=n[Rd],i=Id.since??Ld??void 0,a=Id.since!=null;if(Ld=null,!r||r.bootId===e.bootId)return r||(n[Rd]={bootId:e.bootId},$a(B.hostBoots,n)),Id.since!=null&&Bd({}),null;if(i==null)return n[Rd]={...r,bootId:e.bootId},$a(B.hostBoots,n),null;let o=Math.max(0,t-i),s=e.startedAt!=null&&e.readyAt!=null?Math.max(0,e.readyAt-e.startedAt):void 0;return n[Rd]={bootId:e.bootId,usualMs:o},$a(B.hostBoots,n),Bd({back:{at:t,downMs:o,announced:a,reattachMs:s,...Id.reason?{reason:Id.reason}:{}}}),{downMs:o,announced:a}}function Hd(e){let t=Math.round(e/1e3);return t<90?`${t} s`:`${Math.round(t/60)} min`}function Fie(e,t){if(e.since!=null){let n=t-e.since,r=e.usualMs==null?``:` · usually ~${Hd(e.usualMs)}`,i=n>(e.usualMs==null?Aie:e.usualMs*3),a=e.reason?` (${e.reason})`:``;return{text:i?`desktop restarting${a} ${Hd(n)} — longer than usual, it may have failed to start`:`desktop restarting${a} · ${Hd(n)}${r}`,slow:i}}if(e.back&&t-e.back.at<12e4){let t=e.back.downMs==null?``:` after ${Hd(e.back.downMs)}`;return{text:e.back.announced?`desktop restarted${e.back.reason?` (${e.back.reason})`:``} — back${t}`:`desktop restarted unannounced (crash?) — back${t}`,slow:!e.back.announced}}return null}var Ud=null,Wd=`connecting`;function Gd(e){if(e===Wd)return;let t=Wd;Wd=e;let n=Date.now();t===`open`&&Nie(n),Dd.log.online||(Dd.log.offlineMs+=Math.max(0,n-Dd.log.markTs)),Dd.log.markTs=n,Dd.log.online=e===`open`,yie(e===`open`),e===`closed`&&Dd.log.reconnects++,e===`open`?(Ud=n,Dd.sync.lastSeenAt=n):Ud=null,t===`open`||e===`open`?Ad():kd(),Md(`status`),Fd()}function Kd(){return Wd===`open`}var qd=500,Jd=10,Iie=qd*Jd,Yd=Array.from({length:Jd},()=>({slot:-1,up:0,down:0})),Lie=Date.now();function Xd(e,t){if(!Number.isFinite(t)||t<=0)return;let n=Math.round(t);e===`up`?Dd.traffic.up+=n:Dd.traffic.down+=n;let r=Math.floor(Date.now()/qd),i=Yd[r%Jd];i.slot!==r&&(i.slot=r,i.up=0,i.down=0),e===`up`?i.up+=n:i.down+=n,kd()}function Rie(e){let t=Math.floor(e/qd),n=t-9,r=0,i=0;for(let e of Yd)e.slot<n||e.slot>t||(r+=e.up,i+=e.down);let a=Math.max(1e3,Math.min(Iie,e-Lie));return{up:r*1e3/a,down:i*1e3/a}}function zie(){let e=Rie(Date.now());return{since:Dd.traffic.since,up:Dd.traffic.up,down:Dd.traffic.down,upRate:e.up,downRate:e.down}}function Zd(e){return e<1024?`${Math.round(e)} B`:e<1048576?`${Math.round(e/1024)} kB`:e<1073741824?`${(e/1024/1024).toFixed(+(e<10485760))} MB`:`${(e/1024/1024/1024).toFixed(2)} GB`}function Qd(e){return!Number.isFinite(e)||e<1024?null:e<1048576?`${Math.round(e/1024)} kB/s`:`${(e/1024/1024).toFixed(1)} MB/s`}var $d=class{seq=0;wires=new Map;ring=[];page;deps;constructor(e,t){this.deps=e,this.page=t??e.now().toString(36)}inflight(){return this.wires.size}begin(e,t,n){let r={id:++this.seq,label:e,method:t.toUpperCase(),via:n,started:this.deps.now(),timer:null};this.wires.set(r.id,r),r.timer=this.deps.setTimer(()=>{this.wires.has(r.id)&&(r.snap=this.snapshot(r))},hte);let i=!1;return{progress:(e,t)=>{r.sent=e,t!=null&&(r.total=t)},end:({answered:e,fuseMs:t})=>{if(i)return;i=!0,this.deps.clearTimer(r.timer);let n=Math.max(0,this.deps.now()-r.started),a=Kee({ageMs:n,fuseFired:t!=null,answered:e}),o=a?r.snap??this.snapshot(r):null;if(this.wires.delete(r.id),!a||!o)return;let s={k:`${this.page}.${r.id}`,label:r.label,method:r.method,ageMs:n,outcome:a,...o};t!=null&&(s.fuseMs=t),r.sent!=null&&(s.sent=r.sent,r.total!=null&&(s.total=r.total)),this.add(s)}}}bodyTimeout(e,t,n){let r={k:`${this.page}.b${++this.seq}`,label:e,method:t.toUpperCase(),phase:`body`,ageMs:n,fuseMs:n,outcome:`timeout`,via:`fetch`,...this.snapshot(null)};this.add(r)}openStalls(){let e=this.deps.now(),t=[];for(let n of this.oldestFirst()){let r=e-n.started;if(r<12e3)continue;let i={k:`${this.page}.${n.id}`,label:n.label,method:n.method,ageMs:r,outcome:`open`,...n.snap??this.snapshot(n)};n.sent!=null&&(i.sent=n.sent,n.total!=null&&(i.total=n.total)),t.push(i)}return t}report(){return{events:this.ring.slice(),open:this.openStalls()}}add(e){Xr(this.ring,e,50),this.deps.changed()}oldestFirst(){return[...this.wires.values()].sort((e,t)=>e.started-t.started)}snapshot(e){let t=this.deps.now(),n=this.oldestFirst().filter(t=>t!==e).slice(0,8).map(e=>({label:e.label,ageMs:Math.max(0,t-e.started)})),r=this.deps.context(),i={at:t,via:e?.via??`fetch`,inflight:this.wires.size};return n.length&&(i.peers=n),r.ws&&(i.ws=r.ws),r.visible!=null&&(i.visible=r.visible),r.visForMs!=null&&(i.visForMs=r.visForMs),r.online!=null&&(i.online=r.online),i}},ef=0,tf=[];function nf(e){let t={id:++ef,label:e,started:Date.now()};tf.push(t),Md(`ops`),Fd();let n=!1;return()=>{if(n)return;n=!0;let e=tf.findIndex(e=>e.id===t.id);e>=0&&tf.splice(e,1),Md(`ops`),Fd()}}function rf(e,t=`GET`){let n=e.split(`?`)[0],r=t!==`GET`;return n.includes(`/artifacts`)||n.includes(`/api/search`)?`loading files`:n.includes(`/inbox/seen`)?`marking inbox read`:n.includes(`/inbox`)?r?`uploading`:`loading inbox`:n.includes(`/artifact`)?r?`deleting file`:`loading file`:n.includes(`/git/status`)?`reading git status`:n.includes(`/git/diff`)?`loading diff`:n.includes(`/git/blob`)?`loading the picture`:n.includes(`/git/text`)?`loading the file`:n.includes(`/git/branches`)?`loading branches`:n.includes(`/git/commit`)?`committing`:n.includes(`/git/push`)?`pushing`:n.includes(`/git/pull`)?`pulling`:n.includes(`/git/checkout`)?`switching branch`:n.includes(`/git/branch`)?`updating branches`:n.includes(`/git/stage`)?`staging`:n.includes(`/compliance`)?r?`applying fixes`:`checking repo setup`:n.includes(`/api/slash`)?`loading commands`:n.includes(`/api/repos`)?`loading repos`:n.includes(`/api/external`)?`looking for sessions`:n.includes(`/api/worktree`)?`creating worktree`:n.includes(`/api/project`)?`creating project`:n.includes(`/api/folder`)?`creating folder`:n.includes(`/api/secret`)?r?`setting secret`:`loading targets`:n.includes(`/api/envfiles`)?`loading env files`:n.includes(`/api/host/screenshot`)?`capturing screen`:n.includes(`/api/host/clipboard`)?`copying to host`:n.includes(`/api/host/stat`)?`reading host load`:n.includes(`/api/auth`)?`signing in`:n.includes(`/api/ui-usage`)?`loading usage`:r?`sending`:`loading`}var af=null,of=null;function sf(e){af=Date.now(),of=Math.round(e)}var cf=null;try{document.addEventListener(`visibilitychange`,()=>{cf=Date.now()})}catch{}function lf(){let e=Date.now(),t={},n={open:Wd===`open`};af!=null&&(n.pongAgeMs=Math.max(0,e-af)),of!=null&&(n.rttMs=of),t.ws=n;try{t.visible=document.visibilityState===`visible`}catch{}cf!=null&&(t.visForMs=Math.max(0,e-cf));try{typeof navigator.onLine==`boolean`&&(t.online=navigator.onLine)}catch{}return t}var uf=new $d({now:()=>Date.now(),context:lf,setTimer:(e,t)=>setTimeout(e,t),clearTimer:e=>clearTimeout(e),changed:()=>Tf()});function df(e,t,n){return uf.begin(rf(e,t),t,n)}function ff(e,t,n){uf.bodyTimeout(rf(e,t),t,n)}function pf(e){let t=e;return t&&t.name===`TimeoutError`&&typeof t.ms==`number`?t.ms:void 0}var mf=new WeakMap;function hf(e,t){let n=pf(t);n!=null&&mf.set(e,n),e.abort()}var gf=new WeakMap;function _f(){try{let e=globalThis.fetch.bind(globalThis);globalThis.fetch=(async(t,n)=>{let r=typeof Request<`u`&&t instanceof Request?t:null,i=df(typeof t==`string`?t:t instanceof URL?t.href:r?.url??``,n?.method??r?.method??`GET`,`fetch`);try{let r=await e(t,n);return i.end({answered:!0}),r}catch(e){throw i.end({answered:!1,fuseMs:n?.signal?.aborted?pf(n.signal.reason):void 0}),e}})}catch{}try{let e=XMLHttpRequest.prototype,t=e.open;e.open=function(e,n,...r){return gf.set(this,{method:String(e||`GET`),url:String(n)}),t.call(this,e,n,...r)};let n=e.send;e.send=function(e){let t=gf.get(this),r=df(t?.url??``,t?.method??`GET`,`xhr`),i=typeof Blob<`u`&&e instanceof Blob?e.size:void 0;i&&r.progress(0,i);try{this.upload?.addEventListener(`progress`,e=>r.progress(e.loaded,e.lengthComputable?e.total:i)),this.addEventListener(`loadend`,()=>r.end({answered:this.status>0,fuseMs:mf.get(this)}))}catch{r.end({answered:!1})}return n.call(this,e)}}catch{}}var vf=null,yf=null,bf=``,xf=null,Sf=15e3;function Cf(){return uf.openStalls().map(e=>e.k).join(`,`)}function wf(e=!1){if(!vf||vf.status!==`open`||!yf)return;let t=yf();if(!t||t===`unknown`)return;let n=`${uf.ring.length}:${uf.ring[uf.ring.length-1]?.k??``}|${Cf()}`;(e||n!==bf)&&(vf.send({t:`net.stalls`,deviceId:t,report:uf.report()}),bf=n)}function Tf(){xf||=setTimeout(()=>{xf=null,wf()},1e3)}function Ef(e,t){vf||(vf=e,yf=t,e.on(e=>{e.t===`welcome`&&(bf=``,wf(!0))}),setInterval(()=>wf(),Sf))}function Df(e,t){!Number.isFinite(t)||t<0||(e.push(Math.round(t)),e.length>200&&e.splice(0,e.length-200))}function Of(e,t){if(!e.length)return;let n=[...e].sort((e,t)=>e-t);return n[Math.min(n.length-1,Math.floor((n.length-1)*t))]}function kf(){let e=z(Cd);if(e)return e;try{let e=new Uint8Array(6);crypto.getRandomValues(e);let t=Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``);return Za(Cd,t),t}catch{return`unknown`}}function Af(e){Df(Dd.log.rtt,e),sf(e),kd()}function jf(){Dd.log.reloads++,Ad()}function Mf(e){Dd.log.sent++,Df(Dd.log.send,e),Dd.log.queuedMaxMs=Math.max(Dd.log.queuedMaxMs,Math.round(e)),kd(),Md(`log`)}function Nf(){Dd.log.failed++,kd(),Md(`log`)}function Pf(){Dd.log.expired++,kd(),Md(`log`)}function Ff(){Dd.log.ackTimeouts++,kd(),Md(`log`)}function If(){let e=Date.now(),t=Dd.log.online?0:Math.max(0,e-Dd.log.markTs),n=Math.max(1,e-Dd.log.since);return{since:Dd.log.since,rttP50:Of(Dd.log.rtt,.5),rttP95:Of(Dd.log.rtt,.95),reconnects:Dd.log.reconnects,reloads:Dd.log.reloads,offlineShare:Math.min(1,(Dd.log.offlineMs+t)/n),sendP50:Of(Dd.log.send,.5),sendP95:Of(Dd.log.send,.95),sent:Dd.log.sent,failed:Dd.log.failed,expired:Dd.log.expired,ackTimeouts:Dd.log.ackTimeouts,queuedMaxMs:Dd.log.queuedMaxMs,ua:navigator.userAgent.slice(0,120)}}function Lf(){return Dd.log.rtt.length<4?null:Of(Dd.log.rtt,.95)??null}function Rf(){Dd.log=wd(Date.now()),Dd.log.online=Wd===`open`,Dd.traffic={since:Date.now(),up:0,down:0};for(let e of Yd)e.slot=-1,e.up=0,e.down=0;Ad(),Md(`log`,`traffic`),Fd()}var zf=0;function Bf(e){let t=Math.max(0,e|0);t!==zf&&(zf=t,Md(`sends`),Fd())}var Vf=0,Hf=!1;function Uf(e){let t=Math.max(0,e|0);t!==Vf&&(Vf=t,t>0&&(Hf=!0),Md(`sends`),Fd())}async function Wf(e,t,n){let r=nf(rf(e,t?.method??`GET`));try{return await pn(e,t,n)}finally{r()}}function Gf(e,t,n=lr,r=`GET`){let i,a=new Promise((e,a)=>{i=setTimeout(()=>{ff(t,r,n),a(new br(t,n))},n)});return Promise.race([e.json(),a]).finally(()=>clearTimeout(i))}async function Kf(e,t,n){let r=await Wf(e,n?{signal:n}:void 0,t);if(!r.ok)throw Error(`${r.status} ${e}`);return Gf(r,e,t)}async function qf(e,t,n){let r=await Wf(e,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)},n);if(!r.ok){let e=`${r.status}`;try{let t=await r.json(),n=typeof t.message==`string`?t.message:typeof t.error==`string`?t.error:null;n&&(e=`${r.status} ${n}`)}catch{}throw Error(e)}return Gf(r,e,n,`POST`)}async function Jf(e,t,n){return Gf(await Wf(e,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(t)},n),e,n,`POST`)}async function Yf(e){await Wf(e,{method:`DELETE`})}async function Xf(e,t,n){if(!e.body)return e.blob();let r=Number(e.headers.get(`content-length`)||0),i=e.body.getReader(),a=[],o=0;for(;;){let s,c=new Promise((n,a)=>{s=setTimeout(()=>{let n=new br(e.url,t);n.message=`stalled — no bytes for ${Math.round(t/1e3)}s after ${Nr(o)}${r?` of ${Nr(r)}`:``}`,a(n),i.cancel().catch(()=>{})},t)});try{let{done:e,value:t}=await Promise.race([i.read(),c]);if(e)break;a.push(t),o+=t.byteLength,n?.(o,r)}finally{clearTimeout(s)}}return new Blob(a,{type:e.headers.get(`content-type`)||``})}async function Zf(e,t){return JSON.parse(await(await Xf(e,t)).text())}var Qf={repos:()=>Kf(`/api/repos`).then(e=>e.targets),slash:(e,t)=>Kf(`/api/slash?cwd=${encodeURIComponent(e)}${t?`&backend=${encodeURIComponent(t)}`:``}`),external:()=>Kf(`/api/external`).then(e=>e.sessions),transcript:async(e,t,n=`lite`)=>{let r=new URLSearchParams({id:e});t&&r.set(`since`,String(t)),n===`full`&&r.set(`detail`,`full`);let i=await pn(`/api/transcript?${r}`,void 0,Ga);if(i.status===204)return null;if(!i.ok)throw Error(`${i.status} transcript`);return Zf(i,Ga)},scrollback:async(e,t)=>{let n=await Wf(`/api/scrollback?id=${encodeURIComponent(e)}`,t?{signal:t}:void 0,Ga);if(!n.ok)throw Error(`${n.status} scrollback`);let r=await Zf(n,Ga);return{lines:r.lines??[],history:!!r.history,bounded:!!r.bounded,at:r.at??Date.now()}},screenTail:async(e,t)=>{let n=new URLSearchParams({id:e});t!=null&&n.set(`since`,String(t));let r=await pn(`/api/screen/tail?${n}`,void 0,Ga);if(r.status===204)return null;if(!r.ok)throw Error(`${r.status} screen tail`);let i=await Zf(r,Ga);if(typeof i.data!=`string`||typeof i.seq!=`number`)throw Error(`screen tail shape`);return{data:i.data,seq:i.seq,boot:typeof i.boot==`string`?i.boot:void 0}},transcriptTools:async(e,t)=>{let n=new URLSearchParams({id:e,turn:t}),r=await pn(`/api/transcript/tools?${n}`,void 0,Ga);if(!r.ok)throw Error(`${r.status} tool details`);return(await Zf(r,12e3)).tools??{}},shellDetail:async(e,t)=>{let n=new URLSearchParams({id:e,pid:String(t)}),r=await pn(`/api/shell?${n}`,void 0,Ga);if(!r.ok){let e=await r.json().catch(()=>({}));throw Error(e.error||`${r.status} shell`)}return Zf(r,Ga)},contextSeries:async(e,t)=>{let n=new URLSearchParams({id:e});t&&n.set(`since`,String(t));let r=await Wf(`/api/context?${n}`,void 0,Ga);if(r.status===204)return null;if(!r.ok)throw Error(`${r.status} context series`);return Zf(r,Ga)}},$f={tokenStats:(e=!1)=>Kf(`/api/tokenstats${e?`?fresh=1`:``}`,xa),getWeekBurn:()=>Kf(`/api/weekburn`),postWeekBurn:e=>qf(`/api/weekburn`,e),localUsage:()=>Kf(`/api/localusage`),peerJobs:()=>Kf(`/api/peerjobs`).then(e=>Array.isArray(e?.jobs)?e.jobs:[]),backendTokens:(e,t=!1)=>Kf(`/api/tokenstats/${encodeURIComponent(e)}${t?`?fresh=1`:``}`,xa),usageLog:(e=0)=>Kf(`/api/usagelog${e>0?`?hours=${e}`:``}`),usageLogSource:(e,t)=>Kf(`/api/usagelog/${encodeURIComponent(e)}`,void 0,t),tokenWindows:(e,t=!1)=>Kf(`/api/tokenwindows?${e.map(e=>`w=${encodeURIComponent(`${e.id}:${Math.round(e.anchor)}:${Math.round(e.lenMs)}`)}`).join(`&`)}${t?`&fresh=1`:``}`,xa),costWindow:(e,t,n=!1)=>Kf(`/api/costwindow?from=${Math.round(e)}&to=${Math.round(t)}${n?`&fresh=1`:``}`,xa)},ep={inbox:(e,t)=>Kf(`/api/repos/${e}/inbox`,void 0,t).then(e=>e.files),markInboxSeen:e=>fetch(`/api/repos/${e}/inbox/seen`,{method:`POST`}).catch(()=>void 0),markOutboxSeen:e=>fetch(`/api/repos/${e}/artifacts/seen`,{method:`POST`}).catch(()=>void 0),artifacts:(e,t,n,r)=>{let i=new URLSearchParams({scope:t});return n&&i.set(`since`,String(n)),r?.query&&i.set(`q`,r.query),r?.kind&&r.kind!==`all`&&i.set(`kind`,r.kind),r?.limit&&i.set(`limit`,String(r.limit)),Kf(`/api/repos/${e}/artifacts?${i}`,void 0,r?.signal)},search:e=>{let t=new URLSearchParams({scope:e.scope??`repo`});return e.query&&t.set(`q`,e.query),e.kind&&e.kind!==`all`&&t.set(`kind`,e.kind),e.sinceSeconds&&t.set(`since`,String(e.sinceSeconds)),e.repoIds?.length&&t.set(`repos`,e.repoIds.join(`,`)),e.limit&&t.set(`limit`,String(e.limit)),Kf(`/api/search?${t}`,void 0,e.signal)},uploadInbox:(e,t,n,r,i,a)=>new Promise((o,s)=>{let c=new XMLHttpRequest;c.open(`POST`,`/api/repos/${e}/inbox`),c.setRequestHeader(`x-file-name`,encodeURIComponent(n)),a&&c.setRequestHeader(`x-dedupe`,`1`),c.setRequestHeader(`content-type`,t.type||`application/octet-stream`),c.withCredentials=!0,i&&(c.upload.onprogress=e=>i(e.loaded,e.lengthComputable?e.total:t.size));let l=()=>hf(c,r?.reason);r?.addEventListener(`abort`,l,{once:!0});let u=()=>r?.removeEventListener(`abort`,l);c.onload=()=>{if(u(),c.status<200||c.status>299){let e=Error(`upload failed (${c.status})`);e.permanent=c.status===413||c.status===415,e.responded=!0,s(e)}else try{o(JSON.parse(c.responseText))}catch{let e=Error(`upload failed (${c.status})`);e.responded=!0,s(e)}},c.onerror=()=>{u(),s(Error(`upload failed`))},c.onabort=()=>{u(),s(new DOMException(`aborted`,`AbortError`))},c.send(t)}),fileBlob:e=>Wf(e).then(e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return e.blob()}),deleteInbox:(e,t)=>Wf(`/api/repos/${e}/inbox/${encodeURIComponent(t)}`,{method:`DELETE`}).then(e=>e.json()),deleteArtifact:(e,t)=>Wf(`/api/repos/${e}/artifact?path=${encodeURIComponent(t)}`,{method:`DELETE`}).then(e=>e.json()),sweepPlan:(e,t)=>Wf(`/api/repos/${e}/sweep?scope=${t}`).then(e=>e.json()),sweepRun:(e,t)=>Jf(`/api/repos/${e}/sweep`,{paths:t}),transportSurvey:()=>Wf(`/api/storage/transport`).then(e=>e.json()),hostStore:()=>Wf(`/api/storage/host`).then(e=>e.json()),hostStoreClear:(e,t)=>Jf(`/api/storage/host/clear`,{store:e,at:t})},tp={newFolder:(e,t)=>Jf(`/api/folder`,{parent:e,name:t}),newRepo:(e,t,n={})=>Jf(`/api/repo`,{parent:e,name:t,setup:n.setup!==!1,description:n.description}),plainFolders:()=>Kf(`/api/plainfolders`),initPlainFolder:e=>Jf(`/api/plainfolders/init`,{path:e}),cloneRepo:(e,t,n)=>Jf(`/api/clone`,{parent:e,url:t,name:n||void 0}),onboardPlan:e=>{let t=new URLSearchParams({name:e.name,path:e.path});return e.description&&t.set(`description`,e.description),e.setup===!1&&t.set(`setup`,`0`),Kf(`/api/onboard/plan?${t}`)},onboardJob:()=>Kf(`/api/onboard`),onboardStart:(e,t,n)=>Jf(`/api/onboard`,{answers:e,consent:t,confirm:n}),onboardResume:(e,t)=>Jf(`/api/onboard/resume`,e?{consent:e,confirm:t}:{}),newWorktree:(e,t)=>Jf(`/api/worktree`,{repoId:e,branch:t}),worktreeLeftover:(e,t)=>Kf(`/api/repos/${e}/worktree/leftover`,void 0,t),removeWorktree:e=>Jf(`/api/repos/${e}/worktree/remove`,{}),artifactUrl:(e,t)=>Iu(`/api/repos/${e}/artifact?path=${encodeURIComponent(t)}`),inboxUrl:(e,t)=>Iu(`/api/repos/${e}/inbox/${encodeURIComponent(t)}`)};async function np(e,t,n,r,i=xa,a){let o=new URLSearchParams({path:t,side:n});r&&o.set(`staged`,`1`);let s=await Wf(`${e}?${o}`,a?{signal:a}:void 0,i);if(s.status===404)return null;if(s.ok)return s;let c=await s.json().catch(()=>null);throw Error(c?.error||`the desktop answered ${s.status}`)}var rp=2e4,ip={gitStatus:e=>Kf(`/api/repos/${e}/git/status`),gitDiff:(e,t,n)=>{let r=new URLSearchParams;return t&&r.set(`path`,t),n&&r.set(`staged`,`1`),Kf(`/api/repos/${e}/git/diff?${r}`).then(e=>e.diff)},gitBlob:async(e,t,n,r,i,a)=>{let o=await np(`/api/repos/${e}/git/blob`,t,n,r,lr,a);return o?Xf(o,rp,i):null},gitText:async(e,t,n,r,i)=>(await np(`/api/repos/${e}/git/text`,t,n,r,void 0,i))?.json(),gitStage:(e,t,n)=>Jf(`/api/repos/${e}/git/stage`,{path:t,unstage:n}),gitCommit:(e,t,n=!0)=>Jf(`/api/repos/${e}/git/commit`,{message:t,all:n},xa),gitMessage:e=>Jf(`/api/repos/${e}/git/message`,{},xa),gitExplain:(e,t,n)=>Jf(`/api/repos/${e}/git/explain`,{foci:t,note:n,background:!0},33e4),gitExplainState:(e,t)=>Kf(`/api/repos/${e}/git/explain`,void 0,t).then(e=>e.explain),gitLog:e=>Kf(`/api/repos/${e}/git/log`),gitShow:(e,t)=>Kf(`/api/repos/${e}/git/show?${new URLSearchParams({sha:t})}`).then(e=>e.body),gitFetch:e=>Jf(`/api/repos/${e}/git/fetch`,{},xa),gitPull:e=>Jf(`/api/repos/${e}/git/pull`,{},xa),gitPush:e=>qf(`/api/repos/${e}/git/push`,{background:!0}),gitPushState:(e,t)=>Kf(`/api/repos/${e}/git/push`,void 0,t).then(e=>e.push),prLease:(e,t)=>Jf(`/api/repos/${e}/git/prs/lease`,{holder:t}),prMerge:(e,t,n)=>Jf(`/api/repos/${e}/git/prs/merge`,{number:t,method:n},xa),prAutoMerge:(e,t,n,r)=>Jf(`/api/repos/${e}/git/prs/automerge`,{number:t,on:n,method:r},xa),prClose:(e,t)=>Jf(`/api/repos/${e}/git/prs/close`,{number:t},xa),prLog:(e,t,n)=>Jf(`/api/repos/${e}/git/prs/log`,{number:t,check:n},xa)},ap={archive:(e,t={})=>{let n=new URLSearchParams;return t.offset&&n.set(`offset`,String(t.offset)),t.limit&&n.set(`limit`,String(t.limit)),t.q&&n.set(`q`,t.q),t.bookmarked&&n.set(`bookmarked`,`1`),Kf(`/api/repos/${e}/archive?${n}`,xa)},archiveDelete:async(e,t)=>(await Wf(`/api/repos/${e}/archive?id=${encodeURIComponent(t)}`,{method:`DELETE`})).json(),conversations:async(e,t,n={},r)=>{let i=await Wf(`/api/conversations?${new URLSearchParams({backend:e,cwd:t,...n.offset?{offset:String(n.offset)}:{},...n.limit?{limit:String(n.limit)}:{},...n.q?{q:n.q}:{}})}`,r?{signal:r}:void 0,xa);if(i.ok)return Zf(i,xa);let a=await Zf(i,xa).catch(()=>({error:void 0}));throw Error(typeof a.error==`string`&&a.error?a.error:`${i.status}`)},conversationsDelete:async(e,t,n)=>(await Wf(`/api/conversations?${new URLSearchParams({backend:e,cwd:t,id:n})}`,{method:`DELETE`})).json(),bookmarkSet:async(e,t,n={})=>(await Wf(`/api/repos/${e}/archive/bookmark`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({id:t,...n})})).json(),bookmarkRemove:async(e,t)=>(await Wf(`/api/repos/${e}/archive/bookmark?id=${encodeURIComponent(t)}`,{method:`DELETE`})).json(),archivedTranscript:async(e,t,n,r=`lite`)=>{let i=new URLSearchParams({conv:t});n&&i.set(`since`,String(n)),r===`full`&&i.set(`detail`,`full`);let a=await pn(`/api/repos/${e}/archive/transcript?${i}`,void 0,Ga);if(a.status===204)return null;if(!a.ok)throw Error(`${a.status} transcript`);return Zf(a,Ga)},archivedToolDetails:async(e,t,n)=>{let r=new URLSearchParams({conv:t,turn:n}),i=await pn(`/api/repos/${e}/archive/transcript/tools?${r}`,void 0,Ga);if(!i.ok)throw Error(`${i.status} tool details`);return(await Zf(i,12e3)).tools??{}},tree:(e,t=``,n)=>{let r=new URLSearchParams;return t&&r.set(`path`,t),n&&r.set(`q`,n),Kf(`/api/repos/${e}/tree?${r}`)},treeFile:(e,t)=>Kf(`/api/repos/${e}/tree/file?path=${encodeURIComponent(t)}`),treeWrite:async(e,t,n,r)=>(await Wf(`/api/repos/${e}/tree/file`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({path:t,body:n,baseSha:r})},xa)).json()};function op(e){let t=Array.isArray(e?.rows)?e.rows:[];return{...e,rows:t.map(Hi).filter(e=>!!e)}}var sp={gitBranches:e=>Kf(`/api/repos/${e}/git/branches`).then(e=>e.branches),gitCheckout:(e,t)=>Jf(`/api/repos/${e}/git/checkout`,{branch:t},xa),gitCreateBranch:(e,t,n)=>Jf(`/api/repos/${e}/git/branch`,{name:t,...n}),gitDeleteBranch:(e,t,n=!1)=>Wf(`/api/repos/${e}/git/branch`,{method:`DELETE`,headers:{"content-type":`application/json`},body:JSON.stringify({name:t,force:n})}).then(e=>e.json()),envFiles:e=>Kf(`/api/repos/${e}/envfiles`).then(e=>e.files),secretTargets:()=>Kf(`/api/secret/targets`).then(e=>e.targets),setSecret:e=>Jf(`/api/secret`,e),compliance:e=>Kf(`/api/repos/${e}/compliance`),complianceFix:(e,t,n)=>Jf(`/api/repos/${e}/compliance/fix`,n?{fixes:t,confirm:n}:{fixes:t}),complianceLimits:(e,t)=>Jf(`/api/repos/${e}/compliance/limits`,t),complianceIgnore:(e,t,n)=>Jf(`/api/repos/${e}/compliance/ignore`,{id:t,ignore:n}),complianceAccept:(e,t)=>Jf(`/api/repos/${e}/compliance/accept`,t),complianceTriage:(e,t)=>Jf(`/api/repos/${e}/compliance/triage`,t),exposureRun:e=>Jf(`/api/repos/${e}/exposure/run`,{},33e4),optIns:e=>Kf(`/api/repos/${e}/optins`).then(op),optInChoice:(e,t,n)=>Jf(`/api/repos/${e}/optins/choice`,{id:t,choice:n}).then(e=>e.report?{...e,report:op(e.report)}:e),hostSetup:()=>Kf(`/api/host/setup`),hostSetupFix:e=>Jf(`/api/host/setup/fix`,{fixes:e}),setupPrefs:e=>Kf(`/api/host/setupprefs`,void 0,e),setSetupPrefs:e=>Jf(`/api/host/setupprefs`,{autoCompactDefault:e}),repoHealth:(e,t)=>Kf(`/api/repos/${e}/repohealth${t?`?scope=${encodeURIComponent(t)}`:``}`),healthIndex:e=>Kf(`/api/repos/${e}/healthindex`),repoHealthScopes:(e,t)=>Jf(`/api/repos/${e}/repohealth/scopes`,{scopes:t}),repoHealthRefresh:(e,t,n,r,i)=>Jf(`/api/repos/${e}/repohealth/refresh`,{...t?{scope:t}:{},...n?{approveEngine:!0,...r?{approveToken:r}:{}}:{},...i?{recut:!0}:{}},2e5)},cp={askRules:()=>Wf(`/api/askrules`).then(up),setAskRules:(e,t)=>Wf(`/api/askrules`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({rules:e,rev:t.rev,confirm:t.confirm})}).then(up)},lp=class extends Error{reread;constructor(e,t){super(e),this.reread=t}};async function up(e){let t=null;try{t=await e.json()}catch{}if(e.ok&&t?.ok)return t;throw new lp(typeof t?.error==`string`?t.error:`${e.status} /api/askrules`,e.status===409||e.status===403)}var dp={...cp,rootInfo:()=>Kf(`/api/host/root`),checkRoot:e=>Jf(`/api/host/root`,{path:e}),saveRoot:e=>Jf(`/api/host/root`,{path:e,save:!0}),hostStat:()=>Kf(`/api/host/stat`),screenshot:async e=>(await Wf(`/api/host/screenshot?repo=${encodeURIComponent(e)}`,{method:`POST`})).json(),ocrStatus:async()=>{try{let e=await Wf(`/api/host/ocr`);return e.ok?await e.json():{available:!1,reason:`this desktop is running an older host`}}catch{return{available:!1,reason:`the host could not be reached`}}},ocrImage:async e=>{try{let t=await Wf(`/api/host/ocr`,{method:`POST`,headers:{"content-type":e.type||`image/jpeg`},body:e},12e4);return t.status===404?{error:`this desktop is running an older host — update it to read pictures on-device`}:await t.json()}catch{return{error:`the host could not be reached`}}},dictateStatus:async()=>{try{let e=await Wf(`/api/host/dictate`);return e.ok?await e.json():{available:!1,reason:`this desktop is running an older host`}}catch{return{available:!1,reason:`the host could not be reached`}}},dictate:(e,t={})=>new Promise((n,r)=>{let{lang:i,terms:a,signal:o,onProgress:s}=t,c=new XMLHttpRequest,l=new URLSearchParams;i&&l.set(`lang`,i),a&&l.set(`terms`,a);let u=l.toString();c.open(`POST`,`/api/host/dictate${u?`?${u}`:``}`),c.setRequestHeader(`content-type`,`audio/wav`),c.withCredentials=!0,s&&(c.upload.onprogress=t=>s(t.loaded,t.lengthComputable?t.total:e.size));let d=()=>c.abort();o?.addEventListener(`abort`,d,{once:!0});let f=()=>o?.removeEventListener(`abort`,d);c.onload=()=>{if(f(),c.status<200||c.status>299){let e=Error(`the desktop could not read it (${c.status})`);e.permanent=c.status===413||c.status===415,e.responded=!0,r(e)}else try{n(JSON.parse(c.responseText))}catch{let e=Error(`the desktop answered something this app could not read`);e.responded=!0,r(e)}},c.onerror=()=>{f(),r(Error(`the desktop could not be reached`))},c.onabort=()=>{f(),r(new DOMException(`aborted`,`AbortError`))},c.send(e)}),setClipboard:e=>Jf(`/api/host/clipboard`,{text:e}),pluginAsset:(e,t,n)=>Wf(`/api/plugin/${encodeURIComponent(e)}/asset/${encodeURIComponent(t)}`,{signal:n,cache:`no-store`},3e4)};function fp(e,t,n){return pn(e,t,n)}async function pp(e,t,n){try{let r=await fp(e,t,n);return r.ok?await r.json():null}catch{return null}}var mp={speedtest:{download:async(e,t)=>{let n=performance.now(),r=await fetch(`/api/speedtest/download?bytes=${e}&_=${Date.now()}`,{cache:`no-store`});if(!r.ok||!r.body)throw Error(`download ${r.status}`);let i=r.body.getReader(),a=0;for(;;){let{done:e,value:n}=await i.read();if(e)break;a+=n.byteLength,t?.(a)}let o=performance.now()-n;return{bytes:a,ms:o,mbps:hp(a,o)}},upload:async e=>{let t=new Uint8Array(e);for(let n=0;n<e;n+=65536)crypto.getRandomValues(t.subarray(n,Math.min(n+65536,e)));let n=performance.now(),r=await(await fetch(`/api/speedtest/upload`,{method:`POST`,headers:{"content-type":`application/octet-stream`},body:t})).json(),i=performance.now()-n;if(!r.ok)throw Error(r.error||`upload failed`);return{bytes:e,ms:i,mbps:hp(e,i),serverMs:r.ms}},debug:()=>Kf(`/api/speedtest/debug`)},netstats:{get:()=>Kf(`/api/netstats`,void 0),reset:()=>Yf(`/api/netstats`),report:e=>fp(`/api/netstats`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify(e),keepalive:!0}).catch(()=>void 0)},push:{key:()=>Kf(`/api/push/key`),subscribe:e=>Jf(`/api/push/subscribe`,e),unsubscribe:e=>Jf(`/api/push/unsubscribe`,{endpoint:e})},uiUsage:{get:()=>pp(`/api/ui-usage`),flush:e=>fp(`/api/ui-usage`,{method:`POST`,headers:{"content-type":`application/json`},body:e,keepalive:!0}),reset:()=>fp(`/api/ui-usage`,{method:`DELETE`}).catch(()=>void 0)},webBundle:{manifest:()=>pp(`/api/webbundle`,{cache:`no-store`}),file:(e,t)=>fp(`/api/webbundle/file?path=${encodeURIComponent(e)}&v=${encodeURIComponent(t)}`,{cache:`no-store`})},auth:{status:()=>Kf(`/api/auth/status`),login:e=>Jf(`/api/auth/login`,{password:e}),logout:()=>Jf(`/api/auth/logout`,{})},tailnet:{peers:e=>Kf(`/api/tailnet/peers`,12e3,e)},pair:{mint:(e=!1)=>qf(`/api/pair/mint`,e?{passive:!0}:{}),redeem:async(e,t,n=null)=>{let r=await Wf(`${e}/api/pair/redeem`,{method:`POST`,credentials:`omit`,cache:`no-store`,headers:n?{"content-type":`application/json`,authorization:`Bearer ${n}`}:{"content-type":`application/json`},body:JSON.stringify(t)},1e4),i=null;try{i=await r.json()}catch{}return{status:r.status,body:i}}},peers:{on:async(e,t,n,r,i)=>{let a={};i!==void 0&&(a[`content-type`]=`application/json`),t&&(a.authorization=`Bearer ${t}`);let o=await Wf(`${e}${r}`,{method:n,credentials:`omit`,cache:`no-store`,headers:a,...i===void 0?{}:{body:JSON.stringify(i)}},1e4),s=null;try{s=await o.json()}catch{}return{status:o.status,body:s}}},devices:{list:()=>Kf(`/api/devices`),revoke:e=>qf(`/api/devices/revoke`,{id:e})}};function hp(e,t){return t>0?e*8/(t/1e3)/1e6:0}async function gp(e){try{if(navigator.clipboard&&window.isSecureContext)return await navigator.clipboard.writeText(e),!0}catch{}try{let t=document.createElement(`textarea`);t.value=e,t.style.position=`fixed`,t.style.opacity=`0`,document.body.appendChild(t),t.select();let n=document.execCommand(`copy`);return document.body.removeChild(t),n}catch{return!1}}var U={...Qf,...$f,...ep,...tp,...ip,...ap,...sp,...dp,...mp};function _p(e){return e==null?null:typeof e==`string`?e.length:typeof Blob<`u`&&e instanceof Blob?e.size:e instanceof ArrayBuffer||ArrayBuffer.isView(e)?e.byteLength:typeof URLSearchParams<`u`&&e instanceof URLSearchParams?e.toString().length:null}function vp(){try{new PerformanceObserver(e=>{for(let t of e.getEntries()){let e=t.initiatorType;if(e===`fetch`||e===`xmlhttprequest`||e===`beacon`)continue;let n=t.transferSize||t.encodedBodySize||0;n>0&&Xd(`down`,n)}}).observe({type:`resource`,buffered:!0})}catch{}}var yp=!1;function bp(){if(!yp){yp=!0;try{let e=globalThis.fetch.bind(globalThis);globalThis.fetch=(async(t,n)=>{let r=_p(n?.body);r!=null&&Xd(`up`,r);let i=await e(t,n),a=Number(i.headers.get(`content-length`));return Number.isFinite(a)&&a>0&&Xd(`down`,a),i})}catch{}try{let e=XMLHttpRequest.prototype.send;XMLHttpRequest.prototype.send=function(t){let n=0;try{this.upload?.addEventListener(`progress`,e=>{e.loaded>n&&(Xd(`up`,e.loaded-n),n=e.loaded)})}catch{}let r=0;try{this.addEventListener(`progress`,e=>{e.loaded>r&&(Xd(`down`,e.loaded-r),r=e.loaded)}),this.addEventListener(`loadend`,()=>{let e=Number(this.getResponseHeader?.(`content-length`));if(Number.isFinite(e)&&e>r&&Xd(`down`,e-r),n===0){let e=_p(t);e!=null&&Xd(`up`,e)}})}catch{}return e.call(this,t)}}catch{}vp(),_f();try{window.addEventListener(`pagehide`,()=>{Ad(),Sp()}),document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`hidden`&&(Ad(),Sp())})}catch{}}}function xp(){U.netstats.report({deviceId:kf(),report:If()})}function Sp(){if(!Cp)return;let e=JSON.stringify({deviceId:kf(),report:If()});try{navigator.sendBeacon?navigator.sendBeacon(`/api/netstats`,new Blob([e],{type:`application/json`})):xp()}catch{}}var Cp=!1;function wp(){Cp||(Cp=!0,window.setInterval(()=>{document.visibilityState===`visible`&&xp()},Tie))}var Tp=3e3,Ep=2500,Dp=io(B.netPulse,!0),Op=[];function kp(){return Dp}function Ap(e){Dp=e,ao(B.netPulse,e),e||(Op=[]),Md(`pulse`),Fd()}function jp(e){Op.push(e),Op.length>90&&Op.splice(0,Op.length-90),Md(`pulse`),Fd()}var Mp=null,Np=!1,Pp=null;function Fp(e){Pp=e,Mp??(Mp=window.setInterval(Ip,Tp),document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`visible`&&Ip()}))}async function Ip(){if(Dp&&Pp&&document.visibilityState===`visible`&&!Np){if(Gd(Pp.status),Wd!==`open`)jp({at:Date.now(),ms:null});else{Np=!0;try{jp({at:Date.now(),ms:await Pp.probe(Ep)})}catch{jp({at:Date.now(),ms:null})}finally{Np=!1}}}}function Lp(e,t=200){let n=e.filter(e=>e.ms!=null).map(e=>e.ms),r=[...n].sort((e,t)=>e-t),i=r.length?r[Math.floor((r.length-1)/2)]:null,a=r.length?r[r.length-1]:0,o=e.length?e[e.length-1]:null;return{last:o&&o.ms!=null?o.ms:null,median:i,misses:e.length-n.length,ceiling:Math.max(t,a)}}var Rp=e=>e.split(/[/\\]/).filter(Boolean).pop()||e,zp=e=>e>=1e9?`${(e/1e9).toFixed(1)} GB`:e>=1e6?`${(e/1e6).toFixed(1)} MB`:e>=1e3?`${Math.round(e/1e3)} KB`:`${e} B`;function Bp(e){if(e==null)return`—`;let t=[`B`,`KB`,`MB`,`GB`],n=e,r=0;for(;n>=1024&&r<t.length-1;)n/=1024,r++;return`${n>=10||r===0?Math.round(n):n.toFixed(1)} ${t[r]}`}var Vp=yn;function Hp(e){Vp=e}function Up(e){return vt(e,Vp)}function Wp(e){let t=Up(e);return{"--repo-hue":`${t}`,"--repo-accent":`hsl(${t} var(--repo-sat) var(--repo-lit))`}}function Gp(e){let t=Math.max(0,Math.round((Date.now()-e)/1e3));if(t<60)return`${t}s ago`;let n=Math.round(t/60);if(n<60)return`${n}m ago`;let r=Math.round(n/60);if(r<24)return`${r}h ago`;let i=Math.round(r/24);return i<60?`${i}d ago`:`${Math.round(i/30)}mo ago`}function Kp(e){return e.running?e.turnActive?0:e.lastTurnAt?Date.now()-e.lastTurnAt:e.idleSince?Date.now()-e.idleSince:0:1/0}function qp(e){return!e.running||e.turnActive?!0:e.lastTurnAt!=null}function Jp(e){let t=Math.max(0,Math.round((Date.now()-e)/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return`${n}m`;let r=Math.floor(n/60);return r<24?`${r}h`:`${Math.floor(r/24)}d`}function Yp(e){if(e<45e3)return`just now`;let t=Math.round(e/6e4);if(t<60)return`${t} min ago`;let n=Math.round(t/60);return n<48?`${n} h ago`:`${Math.round(n/24)} d ago`}function Xp(e,t){let n=Math.max(0,Math.round(((t??Date.now())-e)/1e3));return n<60?`${n}s`:`${Math.floor(n/60)}m ${n%60}s`}var Zp=0;function Qp(e){return`${e}_${Date.now().toString(36)}_${(Zp++).toString(36)}`}var $p=/\x1b(?:\[[0-9;?]*[ -/]*[@-~]|\][^\x07\x1b]*(?:\x07|\x1b\\))/g,em=e=>e.replace($p,``).replace(/\r(?!\n)/g,`
|
|
2
2
|
`),tm=(e,t,n)=>Math.min(n,Math.max(t,e));function nm(e){return new TextDecoder().decode(Uint8Array.from(atob(e),e=>e.charCodeAt(0)))}var rm=e=>new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`});function im(e){let t=rm(e);return e-Date.now()>72e6?`${new Date(e).toLocaleDateString([],{weekday:`short`})} ${t}`:t}var am=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`;function om(e){let t=Math.round((e-Date.now())/1e3);if(t<=0)return`now`;let n=Math.floor(t/60);if(n<60)return`${n}m`;let r=Math.floor(n/60);return r<24?n%60?`${r}h ${n%60}m`:`${r}h`:`${Math.floor(r/24)}d ${r%24}h`}function sm(e){let t=(e,t,n)=>`${e} ${t==null?`?`:`${t}%`}${n?` · resets ${im(n)} (in ${om(n)})`:``}`;return e?.sessionGoneSince==null?`Claude usage — ${t(`5-hour session`,e?.sessionPct,e?.sessionResetAt)} · ${t(`week`,e?.weeklyPct,e?.weeklyResetAt)}${e?.checkedAt?` · checked ${Gp(e.checkedAt)}`:``}`:`Claude usage — ${t(`week`,e.weeklyPct,e.weeklyResetAt)}${e.checkedAt?` · checked ${Gp(e.checkedAt)}`:``}\n${Zn()}`}function cm(e){let t=new Date(e),n=new Date,r=t.toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`});if(t.toDateString()===n.toDateString())return r;let i=(n.getTime()-e)/864e5;return i>=0&&i<6?`${t.toLocaleDateString([],{weekday:`short`})} ${r}`:`${t.toLocaleDateString([],{day:`numeric`,month:`short`,...t.getFullYear()===n.getFullYear()?{}:{year:`numeric`}})} ${r}`}function lm(e){return e.turnActive||e.lastTurnAt!=null||e.firstPrompt||e.lastPrompt||e.contextUsedTok!=null||e.contextLeft!=null||(e.contextSpark?.pts?.length??0)>0?`started`:e.claudeSessionId||e.backendSessionId?`fresh`:`unknown`}var um=e=>e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e),dm=[`sessions`,`repos`],fm=1e4,pm=0;function mm(){let e=Date.now();Dd.sync.lastSeenAt=e,e-pm>fm&&(pm=e,Ad())}function hm(e){Dd.sync.parts[e]=Date.now(),Ad(),Md(`sync`),Fd()}function gm(){let e=Ud!=null,t=e?dm.filter(e=>Dd.sync.parts[e]<Ud):[],n=dm.map(e=>Dd.sync.parts[e]),r=!e||t.length||n.some(e=>!e)?null:Math.min(...n);return{online:e,connectedSince:Ud,lastSeenAt:Dd.sync.lastSeenAt||null,syncedAt:r,pending:t}}function _m(){let e=dm.map(e=>Dd.sync.parts[e]);return e.some(e=>!e)?null:Math.min(...e)}function vm(e){if(!e)return`never`;let t=new Date(e);return new Date().toDateString()===t.toDateString()?im(e):`${t.toLocaleDateString([],{weekday:`short`})} ${im(e)}`}var ym=null;function bm(){if(ym&&!jd.size)return ym;let e=ym,t={status:Wd,online:Wd===`open`,now:Sm,pulse:e&&!jd.has(`pulse`)&&!jd.has(`status`)?e.pulse:{enabled:Dp,status:Wd,samples:Op.slice()},sync:e&&!jd.has(`sync`)&&!jd.has(`status`)?e.sync:gm(),traffic:e&&!jd.has(`traffic`)?e.traffic:zie(),log:e&&!jd.has(`log`)&&!jd.has(`status`)?e.log:If(),ops:e&&!jd.has(`ops`)?e.ops:tf.slice(),stuckSends:zf,outstanding:Vf,everOutstanding:Hf||Dd.log.sent>0};return jd.clear(),ym=t,t}kie(bm);var xm=null,Sm=Date.now();function Cm(){Sm=Date.now(),Md(`traffic`,`log`,`sync`),Fd()}function wm(){let e=[...Nd].some(e=>e.live);e&&xm==null&&(xm=window.setInterval(Cm,1e3)),!e&&xm!=null&&(window.clearInterval(xm),xm=null)}function Tm(e,t=!1){let n={fn:e,live:t};return Nd.add(n),wm(),e(bm()),()=>{Nd.delete(n),wm()}}function Em(e,t=!1){let n=(0,H.useRef)(e);n.current=e;let[r,i]=(0,H.useState)(()=>e(bm()));return(0,H.useEffect)(()=>Tm(e=>{let t=n.current(e);i(e=>Object.is(e,t)?e:t)},t),[t]),r}function Dm(e){return e==null?`—`:e<1e3?`${Math.round(e)} ms`:e<6e4?`${(e/1e3).toFixed(1)} s`:`${Math.round(e/6e4)} min`}function Om(e){let t=Math.max(0,Math.round((Date.now()-e)/1e3));return t<90?`${t}s`:t<5400?`${Math.round(t/60)}m`:t<172800?`${Math.round(t/3600)}h`:`${Math.round(t/86400)}d`}function Bie(e,t,n){let r=t?.delivery,i=(r?.unsubmitted??0)+(r?.unconfirmed??0);if(i>0)return{tone:`bad`,text:i===1?`1 prompt reached a session but could not be confirmed as running — check that session before re-sending, never retype.`:`${i} prompts reached a session but could not be confirmed as running — check those sessions before re-sending, never retype.`};if(e.failed>0){let t=e.failed,r=n<=0?`Their words are kept — on their queue rows, for as long as it takes; nothing retires one.`:n>=t?`Each one is listed below with its words and what stopped it.`:`The newest ${n} are listed below with their words and what stopped them.`;return{tone:`bad`,text:`${t} send${t>1?`s`:``} stopped trying in the last ${Om(e.since)} — nothing was typed into a session, so nothing ran. ${r}`}}return e.reloads>0?{tone:`warn`,text:`The watchdog hard-reloaded the app ${e.reloads}×. That means the socket stayed dead long enough to look wedged — queued text survives (localStorage), but it is the clearest sign the tunnel is unhealthy.`}:(t?.ackReplays??0)>2?{tone:`warn`,text:`${t.ackReplays} receipts never made it back to a phone, so sends were retried against work the host had already done. Delivery is safe (the ack ledger de-dupes), but the link is dropping return traffic.`}:e.offlineShare>.15?{tone:`warn`,text:`No socket for ${Math.round(e.offlineShare*100)}% of the window. Sends queue and go out on reconnect, but nothing is live in the meantime.`}:(e.rttP95??0)>1500?{tone:`warn`,text:`Round trip is ${Dm(e.rttP95)} at the 95th percentile — likely a DERP-relayed Tailscale path rather than a direct one. Run the speed test for the direct/relay verdict.`}:{tone:`ok`,text:`Nothing queued has been lost or left unconfirmed in this window.`}}var km=B.syncTs,Vie=600,Am=`app:settings`,jm=null,Mm=!1,Nm=!1,Pm=new Map;function Fm(){try{let e=JSON.parse(localStorage.getItem(km)||`{}`),t={};for(let[n,r]of Object.entries(e))typeof r==`number`&&Number.isFinite(r)&&(t[n]=r);return t}catch{return{}}}function Im(e,t){try{let n=Fm();n[e]=t,localStorage.setItem(km,JSON.stringify(n))}catch{}}function Lm(e){try{return localStorage.getItem(e)}catch{return null}}var Rm=new Map;function zm(e,t){Rm.set(e,t)}function Bm(e,t,n){Mm=!0;let r=!1;try{t===``?localStorage.removeItem(e):localStorage.setItem(e,t),r=!0,Im(e,n)}catch{}finally{Mm=!1}return r}function Vm(e,t,n){let r=Rm.get(e),i;if(r)try{i=r(t,Lm(e))}catch{}let a=typeof i==`string`?i:t;if(Cie(Bm(e,a,n),a,t)){let t=Math.max(Date.now(),n+1);Im(e,t),pd(e,t),Um(e)}}function Hie(e){if(Pm.delete(e),!jm){Um(e);return}let t=Lm(e)??``,n=Fm()[e]??Date.now();jm({t:`settings.set`,key:e,value:t,ts:n,device:kf()})}function Hm(e){let t=Date.now();Im(e,t),pd(e,t),Um(e)}function Um(e){let t=Pm.get(e);t&&clearTimeout(t),Pm.set(e,setTimeout(()=>Hie(e),Vie))}function Uie(e){if(jm=e,Nm)return;Nm=!0;let t;try{t=window.localStorage}catch{return}let n=t.setItem.bind(t),r=t.removeItem.bind(t);if(t.setItem=(e,t)=>{n(e,t),!Mm&&on(e)&&Hm(e)},t.removeItem=e=>{r(e),!Mm&&on(e)&&Hm(e)},t.setItem===n){let e=Object.getPrototypeOf(t),n=e.setItem,r=e.removeItem;e.setItem=function(e,r){n.call(this,e,r),this===t&&!Mm&&on(e)&&Hm(e)},e.removeItem=function(e){r.call(this,e),this===t&&!Mm&&on(e)&&Hm(e)}}}function Wie(e){Wm(e)}function Wm(e){try{window.dispatchEvent(new CustomEvent(Am,{detail:{key:e}}))}catch{}}function Gie(e){let t=Fm();for(let n of Re){let r=e[n],i=t[n]??0,a=Lm(n);if(r&&r.ts>i)r.value===(a??``)?(Im(n,r.ts),md(n,r.ts)):(Vm(n,r.value,r.ts),hd(n,r.ts),Wm(n));else if(r&&r.ts===i&&md(n,r.ts),a!=null&&(!r||i>r.ts)){let e=t[n]||Date.now();t[n]||Im(n,e);let i=r?wie(a,r.value,Rm.get(n)):null;if(r&&i!==null){let t=Math.max(Date.now(),e+1,r.ts+1);Bm(n,i,t)&&(e=t,Wm(n))}pd(n,e),Um(n)}}}function Kie(e,t,n){on(e)&&(n<=(Fm()[e]??0)?md(e,n):(Lm(e)??``)===t?(Im(e,n),md(e,n)):(Vm(e,t,n),hd(e,n),Wm(e)))}function qie(){let e=0,t=Date.now();for(let n of Re)Lm(n)!=null&&(Im(n,t+e),Um(n),e++);return e}function Gm(e,t){let n=n=>{let r=n.detail?.key;r&&(t&&t.length&&!t.includes(r)||e(r))};return window.addEventListener(Am,n),()=>window.removeEventListener(Am,n)}var Km=B.composeDrafts,qm=B.composeOutbox,Jm=B.pad,Jie=1e3,Ym=B.deadUploads;function Yie(e,t){Zm(Ym,[...Xm(Ym,[]).filter(t=>t.p!==e),{p:e,r:t}].slice(-40))}function Xie(e){for(let t of Xm(Ym,[]))if(e.includes(t.p))return{relPath:t.p,reason:t.r};return null}function Zie(){let e={};for(let t of Xm(Ym,[]))e[t.p]=t.r;return e}function Qie(e){Zm(Ym,Xm(Ym,[]).filter(t=>t.p!==e))}function Xm(e,t){try{let n=z(e);return n?JSON.parse(n):t}catch{return t}}function Zm(e,t){$a(e,t)}function $ie(e){return Xm(Km,{})[e]??``}function eae(e,t){let n=Xm(Km,{});t?n[e]=t:delete n[e],Zm(Km,n)}function tae(){return new Set(Object.keys(Xm(Km,{})))}function nae(){return Xm(qm,[])}function rae(e){Zm(qm,e)}function Qm(){return tr(z(Jm))}function $m(e){try{localStorage.setItem(Jm,o(e))}catch{return!1}return Wie(Jm),!0}function eh(){return Qm().notes}function th(e){let t=Qm(),n=()=>Jn(t.notes.length,Math.round(o(t).length/1024));if(!t.notes.some(t=>t.id===e.id)&&t.notes.length>=400)return n();let r=Lr(t,e);return o(r).length>524288?n():$m(r)?null:we}function iae(e){let t=Qm(),n=Lr(t,e);return o(n).length>524288?Jn(t.notes.length,Math.round(o(t).length/1024)):$m(n)?null:we}function nh(e){e.length&&$m($t(Qm(),e,Date.now()))}zm(Jm,(e,t)=>nt(e,t,Date.now()).value);function rh(e){if(e.status!==`queued`||e.mode===`upload`||e.answer)return!1;if(e.mode!==`op`)return!0;let t=e.op?.t;return t===`fanout.run`||t===`fanout.followup`||t===`session.create`}function ih(e){return e.mode===`op`&&e.op?.t===`session.create`}function ah(e){return ih(e)&&!!e.op?.prompt&&!!e.cwd}function oh(){try{let e=new Uint8Array(8);return crypto.getRandomValues(e),Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)}catch{return`${Date.now().toString(36)}-${Math.floor(Math.random()*1e9).toString(36)}`}}var aae=`.claude/inbox`;function oae(e){let t=e.lastIndexOf(`.`),n=t>0?e.slice(t):``,r=`${(t>0?e.slice(0,t):e).replace(/[/\\\s]+/g,`_`).slice(0,40)||`file`}-${Date.now().toString(36)}${oh().slice(0,6)}${n}`;return{name:r,relPath:`${aae}/${r}`}}var sh=B.composeSheets,ch=20;function lh(e){return Xm(sh,{})[e]??``}function uh(){return oh()}function sae(e,t,n){let r=Hte(lh(e),t);return r?th({id:uh(),ts:Date.now(),...r,...n?{cwd:n}:{}})?`refused`:(dh(e,t),`kept`):(dh(e,t),`seeded`)}function cae(e,t){let n=lh(e).split(`\f`),r=n[0]??``;n[0]=r?`${r}${/\s$/.test(r)?``:` `}${t}`:t,dh(e,n.join(`\f`))}function lae(e){dh(e,``)}function dh(e,t){let n=Xm(sh,{});t?n[e]=t:delete n[e];let r=Object.keys(n);if(r.length>ch)for(let e of r.slice(0,r.length-ch))delete n[e];Zm(sh,n)}var uae=1500;function fh(e,t,n={}){let{enabled:r=!0,offline:i=!Kd(),fromCache:a,toCache:o}=n,[s,c]=(0,H.useState)(null),[l,u]=(0,H.useState)(`loading`),[d,f]=(0,H.useState)(null),[p,m]=(0,H.useState)(null),[h,g]=(0,H.useState)(0),_=(0,H.useRef)(e),[v,y]=(0,H.useState)(0),b=(0,H.useRef)(t);b.current=t;let x=(0,H.useRef)({fromCache:a,toCache:o});x.current={fromCache:a,toCache:o};let S=(0,H.useCallback)(e=>{e?.quiet||(c(null),f(null),m(null),u(`loading`)),y(e=>e+1)},[]);return(0,H.useEffect)(()=>{if(_.current=e,!r)return;let t=!1,n=new AbortController,a=e,o=()=>!t&&_.current===a;return g(e=>e+1),(async()=>{try{let e=await Promise.race([x.current.fromCache?.().catch(()=>null)??null,new Promise(e=>setTimeout(()=>e(null),uae))]);if(e&&o()&&(c(e.value),f(Date.now()-e.savedAt),u(`cached`)),i){o()&&!e&&u(`offline`);return}try{let e=await b.current(n.signal);if(!o())return;c(e),f(null),m(null),u(`fresh`);try{await x.current.toCache?.(e)}catch{}}catch(t){if(!o())return;let n=Ba(t);u(e?`cached`:n?`offline`:`error`),m(n?null:String(t?.message||t))}}finally{g(e=>e-1)}})(),()=>{t=!0,n.abort()}},[e,r,i,v]),{data:s,state:l,age:d,error:p,inflight:h>0,reload:S,set:c}}function dae(e,t,n=`listing`){return e!==`cached`||t==null?null:`Cached ${n} from ${Yp(t)} — the link is down, so anything added since won't be here.`}var fae={has:e=>!!e.starred,paint:(e,t)=>({...e,starred:t})},pae={has:e=>!!e.followUp,paint:(e,t)=>{if(t)return{...e,followUp:{by:`hand`,at:Date.now()}};let{followUp:n,...r}=e;return r}};function mae(e){try{let t=JSON.parse(e||`{}`);if(!t||typeof t!=`object`||Array.isArray(t))return{};let n={};for(let[e,r]of Object.entries(t))typeof r==`boolean`&&(n[e]=r);return n}catch{return{}}}function hae(e,t,n){if(Object.keys(t).length===0)return e;let r=!1,i=e.map(e=>{let i=t[e.id];return i===void 0||i===n.has(e)?e:(r=!0,n.paint(e,i))});return r?i:e}function gae(e,t,n,r){let i=Object.keys(e);if(i.length===0)return null;let a=new Map(t.map(e=>[e.id,e])),o={},s=!1;for(let t of i){let i=a.get(t);if(i)r.has(i)===e[t]?s=!0:o[t]=e[t];else{if(n){s=!0;continue}o[t]=e[t]}}return s?o:null}var ph=null;function _ae(e){ph=e}function W(){if(!ph)throw Error(`core() before App bound it — a feature ran outside App's lifecycle`);return ph}function G(e){let t=e,n=new Set;return{get:()=>t,set(e){let r=typeof e==`function`?e(t):e;if(!Object.is(r,t)){t=r;for(let e of[...n])e()}},subscribe(e){return n.add(e),()=>{n.delete(e)}}}}function K(e){return(0,H.useSyncExternalStore)(e.subscribe,e.get,e.get)}function mh(...e){return()=>{let t=e.map(e=>e.get());return()=>e.forEach((e,n)=>e.set(()=>t[n]))}}var hh=G([]),vae=G(new Map),gh=!1;function yae(e){gh||(gh=!0,hh.set(e()))}function _h(){return W()}function vh(){return K(hh)}function bae(e){let t=(0,H.useRef)(e);return t.current=e,t}function yh(e,t,n){let r=new Map(e);return r.set(t,n),r}function bh(e,t){if(!e.has(t))return e;let n=new Map(e);return n.delete(t),n}var xh=e=>e.charAt(0).toUpperCase()+e.slice(1),Sh=()=>globalThis;function Ch(e){let t=Sh().Capacitor?.Plugins;if(t)return t[`Shell${e}`]??ki.map(n=>t[`${xh(n.slug)}${e}`]).find(Boolean)}function wh(){let e=Sh();return e.ShellAndroidInterface??ki.map(t=>e[`${xh(t.slug)}ShellAndroidInterface`]).find(Boolean)}function Th(e,t,n=`Shell`){let r=Sh(),i=[`shell${e}`,...ki.map(t=>`${t.slug}${n}${e}`)];for(let e of i)r[e]=t;return()=>{for(let e of i)delete r[e]}}var xae=/^feature:([a-z][a-z0-9-]{1,39})\/([a-z][a-z0-9-]{0,39})$/;function Eh(e,t){let n=`feature:${e}/${t}`;if(!xae.test(n))throw Error(`"${n}" is not a feature sheet id — feature:<id>/<sheet>, lower-case letters, digits and -`);return n}var Dh=new Set([`gallery`,`new`,`backlog`,`git`,`model`,`toolbar`,`browse`,`archive`,`activity`,`clihealth`,`context`,`pull`,`tokens`,`repocolor`,`storage`]),Sae=new Set([`swipe`,`image`,`clip`,`collage`,`tokens`,`context`,`repohealth`,`scrollback`,`git`,`text`,`outline`]),Cae=e=>e!==null&&Sae.has(e);function wae(){let e=new URLSearchParams(location.hash.replace(/^#/,``)),t=e.get(`o`),n=e.get(`imgRepo`),r=e.get(`imgPath`),i=n&&r?{repoId:n,relPath:r}:void 0,a=e.get(`dlRepo`),o=e.get(`dlPath`),s=Number(e.get(`dlMtime`)||0),c=a&&o?{repoId:a,relPath:o,name:e.get(`dlName`)||void 0,mtime:s||void 0}:void 0,l=Vte(`notif:${e.get(`notif`)??``}`)??void 0;return{activeId:e.get(`a`)||null,overlay:t&&Dh.has(t)?t:null,image:i,file:c,plugin:e.get(`plugin`)||void 0,notif:l}}function Tae(e,t){let n=t&&Dh.has(t)?t:null,r=new URLSearchParams;e&&r.set(`a`,e),n&&r.set(`o`,n);let i=r.toString();return i?`#${i}`:``}function Oh(e,t,n=null){return`${e||``}|${t||``}|${n||``}`}function Eae(){return new URLSearchParams(location.search).get(`repo`)||null}function Dae(e,t,n){let r=[],i=null;try{i=new URLSearchParams(location.search).get(`demo`)}catch{}return i&&r.push(`demo=${encodeURIComponent(i)}`),n&&r.push(`repo=${encodeURIComponent(n)}`),location.pathname+(r.length?`?${r.join(`&`)}`:``)+Tae(e,t)}function kh(e){return e.split(`|`)[1]||null}function Oae(e,t){return`${e}#step${t}`}function Ah(e){let t=e.indexOf(`#step`);return t<0?e:e.slice(0,t)}var kae=`\0vacant`;function jh(e,t,n){let r=e=>e!==void 0&&e!==`\0vacant`,i=e=>e===`\0vacant`||e!==void 0&&e!==Ah(e),a=t;for(;a>0&&i(e[a]);)a--;if(e[a]===n)return a===t?{kind:`stay`}:{kind:`go`,delta:a-t};let o=e[a],[s,c,l]=n.split(`|`),u=e=>{if(!r(e))return!1;let[t,,n]=Ah(e).split(`|`);return t===s&&n===l};if(!c&&r(o)&&kh(o)&&u(o)){let n=a-1;for(;n>0&&e[n]===`\0vacant`;)n--;if(n>=0&&u(e[n]))return{kind:`go`,delta:n-t}}if(!s&&!c&&r(o)&&Ah(o).split(`|`)[0]){let n=a-1;for(;n>0&&e[n]===`\0vacant`;)n--;let o=n>=0?e[n]:void 0;if(r(o)&&!i(o)){let[e,r,i]=o.split(`|`),a=!r||Dh.has(r);if(!e&&i===l&&a)return{kind:`go`,delta:n-t}}}for(let r=a-1;r>=0;r--)if(e[r]===n)return{kind:`go`,delta:r-t};return{kind:`push`}}function Aae(e,t,n,r=0){if(!e?.navRoute)return{depth:r+1,key:Oh(t.activeId,t.overlay,t.focusRepo??null),activeId:t.activeId,overlay:t.overlay,adopt:!0};let i=e.navDepth||0,a=e.navRoute===n[i]?e.navRoute:null;return{depth:i,key:e.navRoute,activeId:t.activeId,overlay:a?kh(a):t.overlay,adopt:!1}}var Mh={depth:0,keys:[]};function Nh(){wh()?.setBackDepth?.(Mh.depth)}var Ph=new Map,jae=1;function Mae(e){for(let[t,n]of[...Ph])t<=e||(Ph.delete(t),n.close());let t=Mh.keys[e];return t===`\0vacant`||t!==void 0&&t.includes(`#step`)&&!Ph.has(e)}var Fh=!1;function Nae(){Fh||(Fh=!0,queueMicrotask(()=>{Fh=!1;let e=0;for(;Mh.depth-e>0&&Mh.keys[Mh.depth-e]===`\0vacant`;)e++;e&&(Mh.depth-=e,Mh.keys.length=Mh.depth+1,Nh(),history.go(-e))}))}function Pae(){let e=jae++,t=Mh.depth;for(;t>0&&Mh.keys[t]===`\0vacant`;)t--;let n=Mh.depth+1,r=Oae(Ah(Mh.keys[t]??``),e),i=Fae(n),a=i?Uh.get(i.d):void 0,o=i&&a&&a.key===i.k&&a.params?{navParams:a.params}:{};return history.pushState({navRoute:r,navDepth:n,...o},``),Mh.depth=n,Mh.keys[n]=r,Mh.keys.length=n+1,Nh(),{id:e,depth:n,key:r}}function Fae(e){let t=e-1;for(;t>0&&(Mh.keys[t]===`\0vacant`||Mh.keys[t]!==Ah(Mh.keys[t]??``));)t--;let n=Mh.keys[t];return n&&n!==`\0vacant`?{d:t,k:n}:null}function Ih(e,t){let n=(0,H.useRef)(t);n.current=t;let[r,i]=(0,H.useState)(0);(0,H.useEffect)(()=>{if(!e)return;let{id:t,depth:r,key:a}=Pae();return Ph.set(r,{id:t,close:()=>{n.current(),i(e=>e+1)}}),()=>{Ph.get(r)?.id===t&&(Ph.delete(r),Mh.keys[r]===a&&(Mh.keys[r]=kae),Nae())}},[e,r])}var Lh=()=>null,Rh=new Map;function Iae(e){Lh=e}function Lae(e){for(let t of[...Rh.keys()])t>=e&&Rh.delete(t);let t=Mh.keys[e];if(!t||t===`\0vacant`)return;let n=Lh(Ah(t));n&&Rh.set(e,{key:t,restore:n})}var zh=()=>{};function Rae(e){zh=e}function Bh(){return{depth:Mh.depth,keys:Mh.keys.slice(0,Mh.depth+1)}}var Vh=e=>!!e&&e!==`\0vacant`&&Ah(e)===e;function Hh(e){for(let t=e.depth;t>=0;t--){let n=e.keys[t];if(Vh(n))return{d:t,k:n}}return null}function zae(e,t){let n=Hh(t),r=n?kh(n.k):null,i=Hh(e),a=new Map;for(let o=e.depth;o>=0;o--){let s=e.keys[o];if(!Vh(s))continue;let c=kh(s);c&&c!==r&&(o<=t.depth&&t.keys[o]===s?i?.d===o&&n?.d!==o&&!a.has(c)&&a.set(c,`cover`):a.set(c,`close`))}return[...a].map(([e,t])=>({sheet:e,reason:t}))}function Bae(e){for(let{sheet:t,reason:n}of zae(e,Bh()))zh(t,n)}function Vae(e){Rh.delete(e)}function Hae(e,t){let n=Rh.get(e);for(let t of[...Rh.keys()])t>=e&&Rh.delete(t);n&&n.key===t&&n.restore()}var Uh=new Map,Wh=null,Gh=null,Kh=0,qh=new Set,Jh=()=>{for(let e of qh)e()};function Yh(e,t){Gh=Wh={overlay:e,params:t},Kh++,Jh()}function Xh(e){return Wh?.overlay===e?Wh.params:null}function Zh(e){return qh.add(e),()=>{qh.delete(e)}}function Uae(){return Kh}function Wae(e,t,n){let r=e,i=t;for(;r>0&&(i===`\0vacant`||i!==Ah(i));)r--,i=Mh.keys[r]??``;let a=Gh&&Gh.overlay===kh(i)?Gh:null;if(n===`push`){for(let e of[...Uh.keys()])e>=r&&Uh.delete(e);Uh.set(r,{key:i,params:a})}else(n===`open`||n===`stay`&&a)&&Uh.set(r,{key:i,params:a});Gh=null,Gae(r,i);let o=Uh.get(r),s=o&&o.key===i?o.params:null;s!==Wh&&(Wh=s,Jh())}function Gae(e,t){if(typeof history>`u`)return;let n=history.state;if(!n||n.navRoute!==t||(n.navDepth||0)!==e)return;let r=Uh.get(e);if(r&&r.key===t){if(qae(n.navParams??null,r.params))return;let{navParams:e,...t}=n;history.replaceState(r.params?{...t,navParams:r.params}:t,``);return}let i=Qh(n,t);i&&Uh.set(e,{key:t,params:i})}function Qh(e,t){if(!e||typeof e.navRoute!=`string`||Ah(e.navRoute)!==t)return null;let n=e.navParams;return n&&typeof n.overlay==`string`&&n.overlay===kh(t)&&n.params&&typeof n.params==`object`?{overlay:n.overlay,params:n.params}:null}function Kae(e){if(typeof history>`u`)return;let t=Qh(history.state,e);t&&(Gh=t)}function qae(e,t){if(!e||!t)return e===t;if(e.overlay!==t.overlay)return!1;let n=Object.keys(e.params),r=Object.keys(t.params);return n.length===r.length&&n.every(n=>e.params[n]===t.params[n])}function Jae(e){if(!e)return!1;let t=Mh.depth;for(;t>0&&(Mh.keys[t]===`\0vacant`||Mh.keys[t]!==Ah(Mh.keys[t]??``));)t--;let n=Mh.keys[t];if(!n||!kh(n))return!1;let[r,,i]=n.split(`|`),a=jh(Mh.keys,Mh.depth,Oh(r||null,null,i||null));if(a.kind!==`go`)return!1;let o=Mh.keys[Mh.depth+a.delta];return!!o&&kh(o)===e}function Yae(e,t){return e?t&&Jae(e)?`close`:`open`:t?`close`:null}function Xae(e,t,n,r,i){if(r&&i<=0)return{kind:`seed`,how:`push`};if(i>=0)return{kind:`known`,depth:i,how:`stay`};let a=jh(e,t,n);if(a.kind===`stay`)return{kind:`stay`,how:`stay`};if(a.kind===`go`){let r=(e[t+a.delta]??``)===n;return{kind:`go`,delta:a.delta,forget:r,how:r?`open`:`return`}}return{kind:`push`,how:`push`}}function $h(){return Em(e=>e.status)}function Zae(e){let t;return Tm(n=>{n.status!==t&&(t=n.status,e(n.status))})}function Qae(e){let t=Object.keys(e),n={};for(let r of t)n[r]=e[r].load();let r=G(n),i=new Map,a=(t,n,r)=>e[t].same?e[t].same(n,r):Object.is(n,r);function o(e,t){let n=r.get();if(a(e,n[e],t))return;let o=i.get(e);o&&(o.current=t),r.set({...n,[e]:t})}return{get:e=>r.get()[e],set(t,n){e[t].save(n),o(t,e[t].reread?e[t].load():n)},reload(t){o(t,e[t].load())},adopt(n){let r=!1;for(let i of t)e[i].keys?.includes(n)&&(o(i,e[i].load()),r=!0);return r},use(e){return(0,H.useSyncExternalStore)(r.subscribe,()=>r.get()[e])},ref(e){let t=i.get(e);return t||(t={current:r.get()[e]},i.set(e,t)),t},all:()=>r.get(),subscribe:r.subscribe}}var eg=e=>e!==`0`,$ae=e=>e===`1`,tg=e=>e?`1`:`0`;function eoe(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}var ng=[160,240,320,480,640,960,1280,1600],rg=B.dataSaver;function ig(){return z(rg)===`1`}function toe(e){Za(rg,e?`1`:`0`)}function ag(e){let t=Math.min(2,Math.max(1,typeof devicePixelRatio==`number`?devicePixelRatio:1)),n=Math.round(e*(ig()?1:t));return ng.find(e=>e>=n)??ng[ng.length-1]}function og(){return ig()?960:ag(Math.min(typeof innerWidth==`number`?innerWidth:400,800))}function sg(e,t,n){return`${e}${e.includes(`?`)?`&`:`?`}thumb=${t}${n?`&v=${Math.floor(n)}`:``}`}function cg(e){return e.type?e.type.startsWith(`image/`):/\.(png|jpe?g|gif|webp|bmp|svg|heic|heif)$/i.test(e.name)}var lg=[`live`,6e4,3e5,9e5,`off`],noe=3e5;function roe(e){if(e===`live`||e===`off`)return e;let t=Number(e);return e&&Number.isFinite(t)&&lg.includes(t)?t:noe}function ug(e){return e===`live`?`live`:e===`off`?`off`:`every ${Math.round(e/6e4)} min`}function ioe(e){return e===`live`?`Hidden, the open session keeps streaming. Freshest offline screen, most battery.`:e===`off`?`Hidden, the open session stops. Offline you read the screen as you left it.`:`Hidden, the open session stops and catches up ${ug(e)}. Offline you read a screen at most that old.`}function aoe(e){return e!==`live`}function ooe(e,t){return t&&e!==`off`}function soe(e){return typeof e==`number`?e:null}function dg(){return roe(z(B.bgFresh))}function coe(e){Za(B.bgFresh,String(e))}var loe={dark:`#0b0d10`,light:`#eef1f6`},fg=e=>jee(e,nd())??loe[e],uoe=e=>e===`system`||e===`dark`||e===`light`;function pg(){let e=z(B.theme);return uoe(e)?e:`system`}var mg=()=>{try{return window.matchMedia(`(prefers-color-scheme: light)`)}catch{return null}};function doe(){return mg()?.matches?`light`:`dark`}function hg(){let e=pg();return e===`system`?doe():e}var gg=new Set;function foe(e){return gg.add(e),()=>{gg.delete(e)}}var _g=null;function vg(){let e=hg(),t=pg();try{document.documentElement.setAttribute(`data-theme`,e),document.documentElement.style.colorScheme=e;let t=document.querySelector(`meta[name="theme-color"]`);t&&t.setAttribute(`content`,fg(e))}catch{}try{wh()?.setTheme?.(e,fg(e))}catch{}if(e!==_g){_g=e;for(let n of gg)try{n(e,t)}catch{}}return e}function poe(e){Za(B.theme,e),vg()}function moe(){vg(),gie(()=>{_g=null,vg()});let e=mg();if(!e)return;let t=()=>{pg()===`system`&&vg()};typeof e.addEventListener==`function`?e.addEventListener(`change`,t):typeof e.addListener==`function`&&e.addListener(t)}var hoe=3e3,goe=55,_oe=12e3,yg=80,voe=6e4;function yoe(e){return Math.min(_oe,hoe+e.length*goe)}var bg=null,xg,Sg=new Set,Cg=boe(),wg=new Set;function boe(){let e=oo(B.toastLog,[]);return Array.isArray(e)?e.filter(e=>!!e&&typeof e.text==`string`&&Number.isFinite(e.ts)).map(e=>({ts:e.ts,text:e.text,n:Number.isFinite(e.n)&&e.n>0?e.n:1,...e.notif&&typeof e.notif.id==`string`&&typeof e.notif.title==`string`?{notif:e.notif}:{}})).slice(0,yg):[]}function Tg(){for(let e of Sg)e(bg)}function Eg(){for(let e of wg)e(Cg)}function xoe(e,t,n){let r=Cg[0];Cg=r&&r.text===e&&t-r.ts<voe?[{ts:t,text:e,n:r.n+1,...n??r.notif?{notif:n??r.notif}:{}},...Cg.slice(1)]:[{ts:t,text:e,n:1,...n?{notif:n}:{}},...Cg].slice(0,yg),$a(B.toastLog,Cg),Eg()}function Dg(e,t){bg=e,Tg(),xoe(e,Date.now(),t),xg&&clearTimeout(xg),xg=setTimeout(()=>{xg=void 0,bg=null,Tg()},yoe(e))}function Og(){xg&&=(clearTimeout(xg),void 0),bg!==null&&(bg=null,Tg())}function Soe(e){bg===e&&Og()}function Coe(e){return Sg.add(e),e(bg),()=>{Sg.delete(e)}}function woe(e){return wg.add(e),e(Cg),()=>{wg.delete(e)}}function Toe(e,t){let n=t[0];return n?e===void 0||n.ts>e:!1}function Eoe(){Cg=[],$a(B.toastLog,Cg),Eg()}var Doe=25e3,Ooe=3e3;function kg(e){return`${(Math.max(0,e)/2**30).toFixed(1)} GB`}function Ag(e){return e.reduce((e,t)=>e+(Number.isFinite(t.size)?t.size:0),0)}function jg(e){return Pg(e,e=>e.reachable?Ag(e.models):null)}function Mg(e,t=2**30){let n=0;for(let t of e)t!=null&&t>n&&(n=t);return Math.max(t,n)}function koe(e){return Pg(e,e=>e.gpuPct)}function Ng(e){return Pg(e,Fg)}function Aoe(e){return Pg(e,e=>e.memTotal>0?Math.max(0,e.memTotal-Ig(e)):null)}function joe(e){return Pg(e,e=>e.sys?.thermal?.cpuTempC)}function Moe(e){return Pg(e,e=>e.sys?.thermal?.gpuTempC)}function Noe(e,t){return Pg(e,e=>e.sys?.thermal?.fans.find(e=>e.label===t)?.rpm)}function Pg(e,t){let n=[],r=null;for(let i of e)r!=null&&i.at-r>15e3&&n.push(null),n.push(t(i)??null),r=i.at;return n}function Fg(e){let t=e.sys?.cpu;return t?t.userPct+t.sysPct:e.cpuPct}function Ig(e){return e.sys?.mem?.availableBytes??e.memFree}function Lg(e){if(!(e.memTotal>0))return!1;let t=Ig(e);if(t<e.memTotal/10)return!0;let n=e.sys?.mem;return t<e.memTotal/4&&n?.swapTotalBytes!=null&&n.swapTotalBytes>0&&n.swapUsedBytes!=null&&n.swapUsedBytes/n.swapTotalBytes>.8}function Rg(e,t){let n=e.gpuPct==null?``:`, GPU ${Math.round(e.gpuPct)}%`,r=`CPU ${Math.round(Fg(e))}% busy${n}, ${kg(Ig(e))} of ${kg(e.memTotal)} available`,i=Lg(e)?` — memory is tight`:``;return t?`Last seen: ${r}${i}.`:`${r}${i}.`}function zg(e){let t={stale:!1,at:null,sample:null};if(e.disabled)return{...t,kind:`disabled`,text:`The local-runner poll is switched off on this desktop (${Ji(`LOCAL_RUNTIME`)}=0). Nothing here is being measured.`};if(e.answeredAt==null&&e.askedAt!=null&&e.online&&e.now-e.askedAt>5e3)return{...t,kind:`unanswered`,text:`This desktop didn’t answer — its ${L.name} may predate this readout.`};if(!e.last)return{...t,kind:`pending`,text:e.online?`Asking this desktop what its local runner is holding…`:`No reading yet — this phone hasn’t heard from the desktop.`};let n=!e.online||e.now-e.last.at>3e4,r=e.last.at,i=e.last;if(!e.last.reachable)return{kind:`unreachable`,stale:n,at:r,sample:i,text:n?`Last seen: the local runner did not answer.`:`The local runner did not answer — nothing is running it, or it is not listening where this desktop looks.`};if(!e.last.models.length)return{kind:`idle`,stale:n,at:r,sample:i,text:n?`Last seen: the runner was up and holding nothing.`:`The runner is up and holding nothing.`};let a=e.last.models.map(e=>e.name).join(`, `),o=kg(Ag(e.last.models));return{kind:`holding`,stale:n,at:r,sample:i,text:n?`Last seen: ${a} holding ${o}.`:`${a} ${e.last.models.length===1?`is`:`are`} resident, holding ${o}.`}}function Poe(e,t){return e&&t-e.at<=3e4?e:null}var Foe=[`off`,`auto`,`always`],Ioe={off:`off`,auto:`while a model is loaded`,always:`always on`};function Loe(){let e=z(B.localRtBar);if(e===null)return no()?`auto`:`always`;let t=e.replace(/^"|"$/g,``);return t===`off`||t===`auto`||t===`always`?t:t===`true`?`always`:`off`}var Bg=null,Vg=()=>Bg??Loe();function Roe(){return Vg()}function zoe(e){Vg()!==e&&(Bg=e,Za(B.localRtBar,JSON.stringify(e)),e===`off`&&(Ug=[]),Jg(),$g())}function Boe(e,t){for(let t=e.length-1;t>=0;t--){let n=e[t];if(n.reachable&&n.models.length>0)return n.at}return t&&t.reachable&&t.models.length>0?t.at:null}function Voe(e,t){return e===`off`?!1:e===`always`||t.holding?!0:t.lastHeldAt!=null&&t.now-t.lastHeldAt<6e4}function Hoe(){let e=oo(B.localRt,{});return{last:e.last&&typeof e.last.at==`number`&&Array.isArray(e.last.models)?e.last:null,disabled:e.disabled===!0,seenAt:typeof e.seenAt==`number`?e.seenAt:null}}var Hg=Hoe(),Ug=[],Wg=null,Gg=null,Kg=null;function Uoe(){Kg??=window.setTimeout(()=>{Kg=null,$a(B.localRt,Hg)},Ooe)}function Woe(){Kg!=null&&(window.clearTimeout(Kg),Kg=null),$a(B.localRt,Hg)}function Goe(e,t=!1){let n=Date.now();Gg=n,Hg.seenAt=n,Hg.disabled=t,Hg.last=e,t?Ug=[]:(Ug.push(e),Ug.length>120&&Ug.splice(0,Ug.length-120)),Uoe(),Jg(),$g()}var qg=null;function Jg(){qg=null}function Yg(){return qg||(qg={enabled:Vg()!==`off`,mode:Vg(),samples:Ug.slice(),last:Ug.length?Ug[Ug.length-1]:Hg.last,disabled:Hg.disabled,askedAt:Wg,answeredAt:Gg,seenAt:Hg.seenAt,now:Qg},qg)}var Xg=new Set,Zg=null,Qg=Date.now();function $g(){if(!Xg.size)return;let e=Yg();for(let t of Xg)t.fn(e)}function Koe(){Qg=Date.now(),Jg(),$g()}function e_(){let e=[...Xg].some(e=>e.live);e&&Zg==null&&(Zg=window.setInterval(Koe,1e3)),!e&&Zg!=null&&(window.clearInterval(Zg),Zg=null)}function qoe(e,t=!1){let n={fn:e,live:t};return Xg.add(n),e_(),e(Yg()),()=>{Xg.delete(n),e_()}}function t_(e,t=!1){let n=(0,H.useRef)(e);n.current=e;let[r,i]=(0,H.useState)(()=>e(Yg()));return(0,H.useEffect)(()=>qoe(e=>{let t=n.current(e);i(e=>Object.is(e,t)?e:t)},t),[t]),r}var n_=null,r_=null,i_=0;function a_(){return i_++,o_(),()=>{i_=Math.max(0,i_-1),o_()}}function o_(){let e=i_>0;e&&r_==null&&(r_=window.setInterval(s_,Doe),s_()),!e&&r_!=null&&(window.clearInterval(r_),r_=null)}function s_(){!n_||i_<=0||(typeof document>`u`||document.visibilityState===`visible`)&&n_.status===`open`&&(n_.send({t:`localrt.watch`}),Wg=Date.now(),Jg(),$g())}function Joe(e){!n_||n_.status!==`open`?Dg(`no connection — the local runner lives on the desktop and can't be ejected from here`):(n_.send({t:`localrt.evict`,name:e}),Dg(`ejecting ${e}…`))}function Yoe(e){n_||(n_=e,e.on(e=>{e.t===`localrt.sample`?Goe(e.sample,e.disabled===!0):e.t===`localrt.evict`?Dg(e.ok?`${e.name} ejected`:`could not eject ${e.name}${e.error?` — ${e.error}`:``}`):e.t===`welcome`&&s_()}),typeof document<`u`&&document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`visible`&&s_()}),typeof window<`u`&&window.addEventListener(`pagehide`,()=>Woe()),o_(),s_())}var c_=e=>`${e.repoId}:${e.path}`,l_=e=>`file:${c_(e)}`,u_=e=>e.split(`/`).pop()||e;function Xoe(e){if(!Array.isArray(e))return[];let t=new Set,n=[];for(let r of e){if(!r||typeof r!=`object`)continue;let{repoId:e,repo:i,path:a,at:o}=r;if(typeof e!=`string`||!e||typeof a!=`string`||!a)continue;let s=c_({repoId:e,path:a});if(t.has(s))continue;t.add(s);let c={repoId:e,repo:typeof i==`string`?i:``,path:a};typeof o==`number`&&Number.isFinite(o)&&o>0&&(c.at=o),n.push(c)}return n}function Zoe(e,t,n){let r=c_(t),i=e.filter(e=>c_(e)!==r);return n?[...i,t]:i}var d_=[`open`,`frequent`,`recent`],Qoe={open:`in the order opened`,frequent:`most opened first`,recent:`last opened first`};function $oe(e,t){return e&&t?34:0}function ese(e){if(typeof e==`number`)return Number.isFinite(e)&&e>0?{n:e,at:0}:null;if(!e||typeof e!=`object`)return null;let t=typeof e.n==`number`&&Number.isFinite(e.n)?e.n:0,n=typeof e.at==`number`&&Number.isFinite(e.at)?e.at:0;return t||n?{n:t,at:n}:null}function f_(e){let t={};for(let[n,r]of Object.entries(e??{})){let e=ese(r);e&&(t[n]=e)}return t}var tse=2592e6;function p_(e,t,n){let r={},i=n-tse;for(let n of[...new Set([...Object.keys(e),...Object.keys(t)])].sort()){let a=e[n],o=t[n],s=Math.max(a?.at??0,o?.at??0);s<i||(r[n]={n:Math.max(a?.n??0,o?.n??0),at:s})}return r}function m_(e){try{return f_(JSON.parse(e||`{}`))}catch{return{}}}function nse(e,t,n){let r=JSON.stringify(p_(m_(e),m_(t),n));return r===e?void 0:r}function h_(e){return Math.min(50,Math.max(2,typeof e==`number`&&Number.isFinite(e)?Math.round(e):10))}function rse(e,t,n){if(e.length<=t)return{shown:[...e],hidden:0};let r=e.slice(0,t);if(n&&!r.some(e=>e.id===n)){let i=e.find(e=>e.id===n);i&&(r[t-1]=i)}return{shown:r,hidden:e.length-r.length}}function g_(e){return Math.min(8,Math.max(2,typeof e==`number`&&Number.isFinite(e)?Math.round(e):3))}var __=`recent`;function ise(e){return d_.includes(e)?e:__}function v_(e,t){let n=(e.tabTitle??``).trim();if(n)return n;let r=Ye(e.title),i=`${t} · `;return t&&r.startsWith(i)&&r.length>i.length?r.slice(i.length):r||t||`session`}function ase(e,t,n){let r=y_(t,n);return[...e].sort((e,t)=>r({key:e.id,createdAt:e.createdAt},{key:t.id,createdAt:t.createdAt}))}function y_(e,t){let n=(e,t)=>e.createdAt-t.createdAt;return e===`open`?n:e===`recent`?(e,r)=>(t[r.key]?.at??0)-(t[e.key]?.at??0)||n(e,r):(e,r)=>(t[r.key]?.n??0)-(t[e.key]?.n??0)||n(e,r)}function b_(e,t,n,r){let i=y_(n,r),a=t.map(e=>({f:e,r:{key:l_(e),createdAt:e.at??0}})).sort((e,t)=>i(e.r,t.r)),o=new Set(e.map(e=>e.id)),s=[],c=0;for(let t of e){if(!(t.companionOf&&t.companionOf!==t.id&&o.has(t.companionOf))){let e={key:t.id,createdAt:t.createdAt};for(;c<a.length&&i(a[c].r,e)<0;)s.push({kind:`file`,file:a[c++].f})}s.push({kind:`session`,tab:t})}for(;c<a.length;)s.push({kind:`file`,file:a[c++].f});return s}function x_(e,t,n){return{...e,[t]:{n:(e[t]?.n??0)+1,at:n}}}function ose(e,t,n=[]){if(!t.length)return e;let r=new Set([...t,...n]),i={};for(let[t,n]of Object.entries(e))r.has(t)&&(i[t]=n);return i}function S_(e,t){return{title:t?`Close “${e}”?`:`Remove “${e}”?`,lines:[t?`The CLI process ends and the tab goes. The conversation itself is kept — reopen it under “Recently closed”, or in Archive.`:`The row goes off the list. The conversation itself is kept — it is in Archive.`],confirmLabel:t?`Close`:`Remove`}}function sse(e,t,n){let r=t.toLowerCase().split(/\s+/).filter(Boolean);return r.length?e.filter(e=>{let t=(e.kind===`file`?`${u_(e.file.path)} ${e.file.repo} pinned file ${e.file.path}`:`${e.tab.label} ${e.tab.repo} ${n(e.tab.status)}`).toLowerCase();return r.every(e=>t.includes(e))}):[...e]}function cse(e){return e.ctrlKey&&!e.metaKey&&!e.altKey&&!e.shiftKey&&!e.isComposing&&e.key.toLowerCase()===`e`}var C_=()=>io(B.sessionTabs,!0),w_=()=>g_(Qa(B.sessionTabsCount,3)),T_=()=>z(B.sessionTabsSync)!==`0`,E_=()=>ise(T_()?z(B.tabOrderShared)??z(B.sessionTabsOrder):z(B.sessionTabsOrder)),D_=()=>h_(Qa(B.sessionTabsLimit,10));function lse(e){ao(B.sessionTabs,e),B_()}function use(e){Za(B.sessionTabsCount,String(g_(e))),B_()}function dse(e){Za(T_()?B.tabOrderShared:B.sessionTabsOrder,e),B_()}function fse(e){Za(B.sessionTabsSync,e?`1`:`0`),B_()}var pse={app:`data saver`,"phone-data":`the phone's data saver`,battery:`battery saver`};function mse(e){return e.app?`app`:e.battery?`battery`:e.phoneData?`phone-data`:null}function hse(e,t,n){return e!==null&&t&&!n}function gse(){B_()}function _se(e){Za(B.sessionTabsLimit,String(h_(e))),B_()}var O_=()=>Xoe(oo(B.tabFiles,[]));function k_(e,t,n=Date.now()){$a(B.tabFiles,Zoe(O_(),t?{...e,at:e.at??n}:e,t)),B_()}function A_(e,t=Date.now()){F_!==e&&(F_=e,e&&$a(B.tabOpens,x_(j_(),`file:${e}`,t)),B_())}var j_=()=>f_(oo(B.tabOpens,{}));function M_(){let e=z(B.tabOpensShared);return e===null?Object.fromEntries(Object.entries(j_()).filter(([e])=>!e.startsWith(`file:`))):m_(e)}function vse(){return T_()?{...Object.fromEntries(Object.entries(j_()).filter(([e])=>e.startsWith(`file:`))),...M_()}:j_()}function yse(e,t,n){return!t||t===e?null:n.includes(t)?t:null}var N_=[],P_=null,F_=null,I_=null,L_={enabled:!1,count:3,order:__,tabs:[],hidden:0,activeId:null,files:[],strip:[],all:[],fileActive:null},R_=new Set;function z_(){let e=E_(),t=vse(),n=ote(ase(N_,e,t)),{shown:r,hidden:i}=rse(n,D_(),P_),a=O_();L_={enabled:C_(),count:w_(),order:e,tabs:r,hidden:i,activeId:P_,files:a,strip:b_(r,a,e,t),all:b_(n,a,e,t),fileActive:F_}}function B_(){z_();for(let e of R_)e(L_)}function bse(e,t){N_=[...e],P_=t;let n=N_.map(e=>e.id),r=j_(),i=ose(r,n,O_().map(l_)),a=yse(I_,t,n);t||(I_=null);let o=T_();if(a&&(I_=a),a&&o){let e=Date.now();$a(B.tabOpensShared,p_(x_(M_(),a,e),{},e))}a&&!o?$a(B.tabOpens,x_(i,a,Date.now())):Object.keys(i).length!==Object.keys(r).length&&$a(B.tabOpens,i),B_()}function xse(e){return R_.add(e),e(L_),()=>{R_.delete(e)}}function V_(e){let t=(0,H.useRef)(e);t.current=e;let[n,r]=(0,H.useState)(()=>e(L_));return(0,H.useEffect)(()=>xse(e=>{let n=t.current(e);r(e=>Object.is(e,n)?e:n)}),[]),n}var H_=`app:tab-attach`,U_=`app:tab-close`,W_=`app:tab-file`;function G_(e,t){try{window.dispatchEvent(new CustomEvent(e,{detail:{id:t}}))}catch{}}var K_=e=>G_(H_,e),q_=e=>G_(U_,e);function J_(e){try{window.dispatchEvent(new CustomEvent(W_,{detail:e}))}catch{}}z_();var Y_=e=>e?new Date(e).toLocaleTimeString([],{hour:`2-digit`,minute:`2-digit`}):``,X_=ine,Z_=e=>e.endedAt??e.sentAt??0,Q_=e=>e.reduce((e,t)=>Math.max(e,Z_(t)),0);function $_(e){let t=Number(z(X_(e)));return Number.isFinite(t)&&t>0?t:0}function ev(e,t){t>0&&Za(X_(e),String(t))}var tv=e=>e.kind===`tool`?`${e.name} ${e.label} ${e.input??``} ${e.result??``}`:e.text,nv=e=>`${e.prompt}\n${e.blocks.map(tv).join(`
|
|
3
3
|
`)}`,rv=(e,t)=>!!t&&e.toLowerCase().includes(t.toLowerCase()),iv=B.readerTools;function av(){let e=z(iv);return e===`list`||e===`full`?e:`fold`}function Sse(e){Za(iv,e)}var ov=(e=av())=>e===`full`?`full`:`lite`,sv=D,cv=B.hints,Cse=450,wse=10;function lv(){try{let e=JSON.parse(z(cv)||`{}`),t=e.mode===`press`||e.mode===`off`?e.mode:`first`,n={};for(let[t,r]of Object.entries(e.seen??{}))typeof r==`number`&&(n[t]=r);return{mode:t,seen:n}}catch{return{mode:`first`,seen:{}}}}function uv(e){$a(cv,e)}function Tse(){return lv().mode}function Ese(e){uv({...lv(),mode:e})}function dv(){return Object.keys(lv().seen).length}function Dse(){uv({mode:lv().mode,seen:{}})}function fv(e){let t=lv();t.seen[e]=Date.now(),uv(t)}var pv=!1,mv=new Set;function hv(){return pv}function gv(e){if(pv!==e){pv=e;for(let t of mv)t(e)}}function _v(e){return mv.add(e),()=>{mv.delete(e)}}var vv=null,yv=new Set;function Ose(e){return yv.add(e),e(vv),()=>{yv.delete(e)}}function bv(e){vv=e;for(let t of yv)t(e)}function xv(e){vv&&e&&fv(vv.id),bv(null)}function kse(){let e=vv;bv(null),e&&(fv(e.id),e.proceed?.())}function Ase(e){let t=sv[e];t&&bv({id:e,def:t,intercepted:!1})}function Sv(e){let t=e.dataset.hint;if(t&&sv[t])return{id:t,def:sv[t]};let n=e.getAttribute(`title`)||e.getAttribute(`aria-label`)||``;if(!n.trim())return null;let r=(e.textContent||``).trim().replace(/\s+/g,` `).slice(0,40),[i,...a]=n.split(/\s*[:—]\s+/),o=a.length>0;return{id:t||`title:${n.slice(0,80)}`,def:{title:r||(o?i:`What this does`),what:o&&!r?a.join(` — `):n}}}var Cv=null,wv=!1;function Tv(e){return!(e instanceof Element)||e.closest(`[data-nohint]`)?null:e.closest(`[data-hint], button[title], button[aria-label]`)}function Ev(){if(typeof document>`u`)return;let e=Ev;if(e.done)return;e.done=!0;let t,n=null;function r(e){n&&Math.hypot(e.clientX-n.x,e.clientY-n.y)>wse&&i()}function i(){t&&=(clearTimeout(t),void 0),n=null,window.removeEventListener(`pointermove`,r,!0),window.removeEventListener(`pointerup`,i,!0),window.removeEventListener(`pointercancel`,i,!0),window.removeEventListener(`scroll`,i,!0)}document.addEventListener(`pointerdown`,e=>{if(lv().mode===`off`||e.pointerType===`mouse`&&e.button!==0)return;let a=Tv(e.target);if(!a)return;let o=Sv(a);o&&(n={x:e.clientX,y:e.clientY},window.addEventListener(`pointermove`,r,!0),window.addEventListener(`pointerup`,i,!0),window.addEventListener(`pointercancel`,i,!0),window.addEventListener(`scroll`,i,!0),t=setTimeout(()=>{i(),wv=!0,navigator.vibrate?.(12),bv({...o,intercepted:!1})},Cse))},!0),document.addEventListener(`contextmenu`,e=>{wv&&Tv(e.target)&&e.preventDefault()},!0),document.addEventListener(`click`,e=>{let t=Tv(e.target);if(Cv&&t===Cv){Cv=null;return}if(wv){wv=!1,t&&(e.preventDefault(),e.stopPropagation());return}if(!t)return;let n=lv().mode;if(n===`off`&&!pv)return;let r=Sv(t);if(!r)return;let i=ja({mode:n,explain:pv,def:r.def,seen:!!lv().seen[r.id]});i!==`act`&&(e.preventDefault(),e.stopPropagation(),bv(i===`explain`?{...r,intercepted:!1}:{...r,intercepted:!0,proceed:()=>{Cv=t,t.click()}}))},!0)}var Dv=new Set;function Ov(){return Ea(z(B.dictateLang)||`auto`)}function kv(e){Za(B.dictateLang,Ea(e));for(let e of Dv)e()}function Av(){let e=oo(B.dictateLangs,[]);return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function jse(){return yte(Av(),Ov(),Mv())}function Mse(e){$a(B.dictateLangs,e);for(let e of Dv)e()}function jv(e){return Dv.add(e),()=>{Dv.delete(e)}}function Nse(){let e=Ov();return e===`auto`?typeof navigator<`u`&&navigator.language||`en-US`:e}function Mv(){return typeof navigator<`u`&&navigator.language||void 0}function Nv(){return z(B.dictateTerms)||``}function Pv(){return kte(Nv())}function Pse(e){Za(B.dictateTerms,e);for(let e of Dv)e()}var Fv=B.usage,Fse=2e4;function Ise(){try{let e=JSON.parse(z(Fv)||`{}`);return e&&typeof e==`object`?e:{}}catch{return{}}}var Iv=Ise(),Lv={},Rv=null,zv=new Set;function Bv(){$a(Fv,Iv)}function q(e){if(!e)return;let t=Iv[e];t?(t.count++,t.last=Date.now()):Iv[e]={count:1,last:Date.now()},Lv[e]=(Lv[e]||0)+1,Bv();for(let e of zv)e();Rv===null&&(Rv=window.setTimeout(()=>{Rv=null,Hv()},Fse))}function Vv(e){return Iv[e]?.count??0}function Hv(e=!1){let t=Lv;if(!Object.keys(t).length)return;Lv={};let n=JSON.stringify({counts:t});e&&typeof navigator<`u`&&navigator.sendBeacon?navigator.sendBeacon(`/api/ui-usage`,new Blob([n],{type:`application/json`}))||Uv(t):U.uiUsage.flush(n).catch(()=>Uv(t))}function Uv(e){for(let[t,n]of Object.entries(e))Lv[t]=(Lv[t]||0)+n}async function Lse(){return U.uiUsage.get()}async function Rse(){Iv={},Lv={},Bv();for(let e of zv)e();await U.uiUsage.reset()}typeof document<`u`&&document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`hidden`&&Hv(!0)}),typeof window<`u`&&window.addEventListener(`pagehide`,()=>Hv(!0));function zse(e){let t=0,n=0;for(let r of e)r.working&&t++,n+=Math.max(0,r.agents|0);return{sessions:t,subagents:n,total:t+n}}var Wv={warn:10,alarm:30},Bse=[3,5,8,10,15,20,25,30,40,50,75,100];function Gv(e,t){return typeof e==`number`&&Number.isInteger(e)&&e>=0&&e<=999?e:t}function Kv(e){let t=e&&typeof e==`object`?e:{};return{warn:Gv(t.warn,Wv.warn),alarm:Gv(t.alarm,Wv.alarm)}}function qv(e,t){return t.alarm>0&&e>t.alarm?`alarm`:t.warn>0&&e>t.warn?`warn`:`ok`}var Jv={ok:0,warn:1,alarm:2};function Vse(e,t){return Jv[t]>Jv[e]}function Yv(e){let t=`${e.sessions} session${e.sessions===1?``:`s`} working`,n=`${e.subagents} subagent${e.subagents===1?``:`s`}`;return`${e.total} agent${e.total===1?``:`s`} running at once on the desktop: ${t} + ${n}`}function Hse(e,t,n){let r=t===`alarm`?n.alarm:n.warn;return`${Yv(e)} — more than your ${t===`alarm`?`limit`:`warning`} of ${r}`}function Use(){return Kv(oo(B.agentWarn,null))}function Wse(e){$a(B.agentWarn,Kv(e))}var Gse=1e4;function Kse(e,t,n=360){let r=[...e,t];return r.length>n?r.slice(r.length-n):r}function Xv(e,t=e=>e.total){let n=[];for(let r=0;r<e.length;r++)r>0&&e[r].at-e[r-1].at>3e4&&n.push(null),n.push(t(e[r]));return n}function qse(e,t){return e===`ok`?!1:t==null||Jv[e]>Jv[t]}function Jse(e){let t=e=>e.agents.length+ +!!e.working;return e.filter(e=>t(e)>0).sort((e,n)=>t(n)-t(e)||e.label.localeCompare(n.label))}var Zv={count:null,rows:[],samples:[],level:`ok`,dismissed:null},Qv=new Set,$v=null;function ey(e){Zv=e;for(let e of Qv)e(Zv)}function ty(){let e=Zv.count;e&&ey({...Zv,samples:Kse(Zv.samples,{at:Date.now(),...e})})}function Yse(e,t,n){let r=!Zv.count||Zv.count.total!==e.total||Zv.count.sessions!==e.sessions||Zv.count.subagents!==e.subagents;ey({...Zv,count:e,rows:t,level:n,dismissed:n===`ok`?null:Zv.dismissed}),r&&ty(),!$v&&typeof window<`u`&&($v=setInterval(ty,Gse))}function Xse(){ey({...Zv,dismissed:Zv.level})}function ny(e){let t=(0,H.useRef)(e);t.current=e;let[n,r]=(0,H.useState)(()=>e(Zv));return(0,H.useEffect)(()=>{let e=e=>{let n=t.current(e);r(e=>Object.is(e,n)?e:n)};return Qv.add(e),e(Zv),()=>{Qv.delete(e)}},[]),n}var ry=()=>ny(e=>e.count),Zse=()=>ny(e=>qse(e.level,e.dismissed));function iy(e,t,n=!1){return{load:()=>t(z(e)),save:t=>Za(e,tg(t)),keys:n?[e]:void 0}}function Qse(){let e=z(B.typingRoom);if(e!=null)return e===`1`;try{return window.matchMedia?.(`(pointer: coarse)`).matches??!1}catch{return!1}}var ay=Qae({saver:{load:ig,save:toe},bgFresh:{load:dg,save:coe},autoSend:iy(B.autoSend,eg,!0),serialSessions:iy(B.serialSessions,eg,!0),confirmQueue:iy(B.confirmQueue,eg,!0),confirmClose:iy(B.confirmClose,eg,!0),updatesAutoCheck:{load:()=>![`false`,`0`,`off`].includes((z(B.updatesAutoCheck)??``).trim().toLowerCase()),save:e=>Za(B.updatesAutoCheck,e?`true`:`false`),keys:[B.updatesAutoCheck]},dismissedSelfUpdate:{load:()=>z(B.dismissedSelfUpdate)||``,save:e=>Za(B.dismissedSelfUpdate,e)},launchAsk:{load:()=>io(B.launchAsk),save:e=>ao(B.launchAsk,e),keys:[B.launchAsk]},spendWarn:{load:()=>rte(oo(B.spendWarn,null)),save:e=>$a(B.spendWarn,e),keys:[B.spendWarn],same:(e,t)=>JSON.stringify(e)===JSON.stringify(t)},closeWhenDone:{load:()=>io(B.closeWhenDone),save:e=>ao(B.closeWhenDone,e),keys:[B.closeWhenDone]},localSessions:{load:()=>z(B.localSessions)??``,save:e=>e?Za(B.localSessions,e):so(B.localSessions),keys:[B.localSessions]},agentWindowWarn:{load:()=>z(B.agentWindowWarn)??``,save:e=>e?Za(B.agentWindowWarn,e):so(B.agentWindowWarn),keys:[B.agentWindowWarn]},agentWarn:{load:Use,save:Wse,keys:[B.agentWarn],same:(e,t)=>e.warn===t.warn&&e.alarm===t.alarm},enterSends:iy(B.enterSends,eg,!0),cliMode:iy(B.cliMode,$ae),hints:{load:()=>({mode:Tse(),seen:dv()}),save:e=>Ese(e.mode),keys:[B.hints],same:(e,t)=>e.mode===t.mode&&e.seen===t.seen},closeKbOnSend:iy(B.closeKbOnSend,eg),shortcutCard:iy(B.shortcutCard,eg),btwToCli:{load:()=>{let e=z(B.btwToCli);return e===`switch`||e===`stay`?e:``},save:e=>{e?Za(B.btwToCli,e):so(B.btwToCli)}},busySend:{load:()=>{let e=z(B.busySend);return e===`now`||e===`idle`?e:``},save:e=>{e?Za(B.busySend,e):so(B.busySend)}},hintChip:{load:()=>{let e=z(B.hintChip);return e===`asked`||e===`hidden`?e:``},save:e=>{e?Za(B.hintChip,e):so(B.hintChip)}},typingRoom:{load:Qse,save:e=>Za(B.typingRoom,tg(e))},dismissedUpdate:{load:()=>z(B.dismissedUpdate)||``,save:e=>Za(B.dismissedUpdate,e)},netPulse:{load:kp,save:Ap},localRtBar:{load:Roe,save:zoe},unfoldToEnd:iy(B.unfoldToEnd,eg),repoSort:{load:()=>z(B.repoSort)===`name`?`name`:`sessions`,save:e=>{e===`name`?Za(B.repoSort,e):so(B.repoSort)}},tabsOn:{load:C_,save:lse},tabsN:{load:w_,save:use},tabsSort:{load:E_,save:dse,keys:[B.tabOrderShared]},tabsSync:{load:T_,save:fse},tabsMax:{load:D_,save:_se},toolsMode:{load:av,save:Sse,keys:[B.readerTools]},theme:{load:pg,save:poe},txtScale:{load:qu,save:cie},icScale:{load:Ju,save:lie},tZoom:{load:Yu,save:uie},rZoom:{load:aie,save:die},dictLang:{load:Ov,save:kv,reread:!0},dictLangCodes:{load:Av,save:Mse,reread:!0,same:eoe},dictTerms:{load:Nv,save:Pse,keys:[B.dictateTerms],reread:!0}});function oy(e){return ay.use(e)}function sy(e,t){ay.set(e,t)}function $se(){return ut(z(B.agentWindowWarn))}function ece(e){return ay.ref(e)}function tce(e){q(`action:uiscale.term`),sy(`tZoom`,e)}function nce(e){q(`action:uiscale.reader`),sy(`rZoom`,e)}Gm(e=>{ay.adopt(e)}),jv(()=>{for(let e of[`dictLang`,`dictLangCodes`,`dictTerms`])ay.reload(e)});function rce(e){let t=Object.entries(e);return{lists:new Map(t.map(([e,t])=>[e,t.v])),at:new Map(t.map(([e,t])=>[e,t.at]))}}function ice(e,t,n,r){let i=new Map(e.lists),a=new Map(e.at);return i.set(t,n),a.set(t,r),{lists:i,at:a}}function ace(e){let t=G(rce(e.load()));return{...t,put(n,r){let i=e.save(n,r)[n]?.at??Date.now();t.set(e=>ice(e,n,r,i))}}}var oce=3e5;function sce(e,t,n=60){return[t,...e.filter(e=>e.runId!==t.runId)].slice(0,n)}function cce(e,t,n){return[...n,...e.filter(e=>e.repoDir!==t)]}function lce(e,t,n,r=oce){let i=(n?``:e)+t;return i.length>r?i.slice(-r):i}function cy(e){let t=ace(e),n=G([]),r=G(0),i=new Map;return{cfgs:t,runs:n,outTick:r,output:i,outputOf:e=>i.get(e)??``,onList(e,r,i){t.put(e,r),n.set(t=>cce(t,e,i))},onRun(e){let t=sce(n.get(),e),r=new Set(t.map(e=>e.runId));for(let e of i.keys())r.has(e)||i.delete(e);n.set(t)},onOutput(e,t,n,a){i.set(e,lce(i.get(e)??``,t,n)),a&&r.set(e=>e+1)}}}var uce=1e5;function dce(e,t=uce){let n=null,r=new Map,i=(t,n)=>{let i=r.get(t);i&&(r.delete(t),e.clearTimer(i.timer),i.resolve(n))};return{call(a,o,s,c){let l={ok:!1,error:`no connection — the desktop can't be asked from here`};return e.status()===`open`?new Promise(u=>{let d=e.mintId(),f={t:`plugin.call`,plugin:a,method:o,...s===void 0?{}:{args:s},ackId:d},p=e.setTimer(()=>i(d,{ok:!1,error:`${a} did not answer within ${Math.round(t/1e3)} s`}),t);r.set(d,{plugin:a,method:o,read:c,hostId:n,frame:f,timer:p,resolve:u});let m=!1;try{m=e.trySend(f)}catch(e){i(d,{ok:!1,error:`could not reach the desktop: ${e instanceof Error?e.message:String(e)}`});return}if(!m)i(d,l);else if(!c){let e=r.get(d);e&&(e.frame=null)}}):Promise.resolve(l)},onFrame(t){if(t.t===`plugin.reply`){let e=r.get(t.ackId);if(!e||e.plugin!==t.plugin||e.method!==t.method)return;i(t.ackId,t.ok?{ok:!0,result:t.result}:{ok:!1,error:t.error??`${t.plugin} failed`})}else if(t.t===`welcome`){n=t.hostId??null;for(let[t,a]of[...r])if(a.read&&a.hostId!==n)i(t,{ok:!1,error:`the desktop changed before it answered — ask again`});else if(a.read&&a.frame)try{e.trySend(a.frame)}catch{}else i(t,{ok:!1,error:`the link dropped before ${a.plugin} answered — it may have run; look before trying again`})}},pending:()=>r.size,framesHeld:()=>[...r.values()].filter(e=>e.frame!==null).length}}var fce=null;function ly(){return fce??=dce({status:()=>W().conn.status,trySend:e=>W().conn.trySend(e),mintId:oh,setTimer:(e,t)=>setTimeout(e,t),clearTimer:e=>clearTimeout(e)})}function uy(e){let t=(t,n,r)=>{let i=dne(e,t,n);return i===void 0?ly().call(e,t,n,r):Promise.resolve(i)};return{call:(e,n)=>t(e,n,!1),read:(e,n)=>t(e,n,!0)}}var dy=/^[a-z][a-z0-9-]{0,39}$/,fy=/^[a-zA-Z][a-zA-Z0-9-]{0,39}$/;function py(e){if(!dy.test(e))throw Error(`extStorage: bad plugin id ${JSON.stringify(e)}`);let t=t=>{if(!fy.test(t))throw Error(`extStorage: bad name ${JSON.stringify(t)}`);return cne(e,t)};return{read:(e,n)=>oo(t(e),n),write:(e,n)=>$a(t(e),n),remove:e=>so(t(e))}}var my=G(null),hy=G(!1),gy=null;function _y(e,t){gy?.(),my.set(e.get()),hy.set(!t||t.get());let n=[e.subscribe(()=>my.set(e.get()))];t&&n.push(t.subscribe(()=>hy.set(t.get()))),gy=()=>n.forEach(e=>e())}function vy(e,t){let n=e?.find(e=>e.manifest.id===t);return!!n&&n.enabled&&n.state===`active`}function yy(e,t){for(let n of e)if(n.imageText&&t(n.id))return n.imageText;return null}var by=()=>[];function xy(e,t){for(let n of e)if(n.appsDoor&&t(n.id))return{feature:n.id,door:n.appsDoor};return null}function Sy(e){return e?{open:t=>{let n=W();try{e.door.open(n,t)}catch(t){console.error(`${_i} feature ${e.feature} failed opening its door`,t),n.say.toast(`${e.feature} could not open that screen`)}}}:null}function Cy(){let e=Oy();return(0,H.useMemo)(()=>Sy(xy(by(),t=>vy(e,t))),[e])}function wy(e){by=e}function Ty(){let e=Oy();return(0,H.useMemo)(()=>yy(by(),t=>vy(e,t)),[e])}function Ey(e){return vy(my.get(),e)}function Dy(e,t){let n=Ey(e),r=!1;t(n);let i=my.subscribe(()=>{let i=Ey(e);i!==n&&(n=i,r=!0,t(i))}),a=hy.subscribe(()=>{hy.get()&&(r||t(n=Ey(e)),r=!1)});return()=>{i(),a()}}function Oy(){return(0,H.useSyncExternalStore)(my.subscribe,my.get,my.get)}function ky(e){return(0,H.useSyncExternalStore)(my.subscribe,()=>Ey(e),()=>Ey(e))}function Ay(){let e=Ch(`Install`);return e&&typeof e.install==`function`?e:null}function jy(){return ku()&&Ay()!==null}async function My(){let e=Ay();if(!e)return{caps:v,allow:[],cleanup:null};try{let t=await e.status();return{caps:{supported:t?.supported!==!1,canInstall:!!t?.canInstall,silent:!!t?.silent,...uee(t)},allow:Array.isArray(t?.allow)?t.allow.filter(e=>typeof e==`string`):[],cleanup:typeof t?.cleanAfterInstall==`boolean`&&typeof e.setCleanAfterInstall==`function`?t.cleanAfterInstall:null}}catch{return{caps:v,allow:[],cleanup:null}}}async function Ny(e){let t=Ay();if(!t?.sources||!e.length)return null;try{let n=await t.sources({packages:e});return n?.self?{self:n.self,sdk:typeof n.sdk==`number`?n.sdk:void 0,byPkg:n.sources??{}}:null}catch{return null}}async function Py(){let e=Ay();if(!e)throw Error(`this device has no app installer to open`);await e.openSettings()}async function Fy(e){try{await Ay()?.setAllow({packages:e})}catch{}}async function Iy(e){let t=Ay();if(!t?.setCleanAfterInstall)throw Error(`this app build cannot do that yet`);await t.setCleanAfterInstall({on:e})}async function Ly(e){let t=Ay();if(!t)throw Error(`this device cannot install apps`);await t.install({id:e})}function Ry(){let e=oo(B.installAllow,[]);return Array.isArray(e)?e.filter(e=>typeof e==`string`&&!!e):[]}function zy(e){$a(B.installAllow,e),Fy(e);for(let e of[...By])e()}var By=new Set,Vy=!1;function Hy(e){return!Vy&&typeof window<`u`&&(Vy=!0,Gm(()=>{for(let e of[...By])e()},[B.installAllow])),By.add(e),()=>{By.delete(e)}}var Uy=!1;function Wy(){jy()&&(Fy(Ry()),!Uy&&(Uy=!0,Gm(()=>{Fy(Ry())},[B.installAllow])))}function Gy(e,t){let n=t,r=new Set,i=null,a=e=>{n=e;for(let e of[...r])e()};return{subscribe(e){return r.add(e),()=>{r.delete(e)}},get:()=>n,refresh(){return i||(i=e().then(a).catch(()=>{}).finally(()=>{i=null}),i)},set:a}}var Ky=Gy(()=>My().then(e=>({caps:e.caps,cleanup:e.cleanup})),{caps:null,cleanup:void 0}),qy=!1;function Jy(){return Ky.refresh()}function Yy(e){return!qy&&typeof document<`u`&&(qy=!0,document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`visible`&&Jy()})),Ky.subscribe(e)}var Xy=()=>Ky.get();function Zy(e){Ky.set({...Ky.get(),cleanup:e})}function Qy(){let e=(0,H.useSyncExternalStore)(Yy,Xy,Xy);return(0,H.useEffect)(()=>{Jy()},[]),{caps:e.caps,cleanup:e.cleanup,setCleanup:Zy}}function $y(e,t){let[n,r]=(0,H.useState)(null);return(0,H.useEffect)(()=>{let t=!0;return Ny([...e]).then(e=>{t&&r(e)}),()=>{t=!1}},[t]),n}var eb={supported:()=>jy(),status:()=>My(),install:e=>Ly(e),openSettings:()=>Py().finally(()=>{Jy()}),setCleanAfterInstall:e=>Iy(e)};function tb(){return Qy()}function nb(e,t){return $y(e,t)}var rb=G([]),ib=!1;function ab(){return ib||(ib=!0,rb.set(Ry())),rb.get()}var ob=!1;function sb(e){return ob||(ob=!0,Hy(()=>{ib=!0,rb.set(Ry())})),ib=!1,ab(),rb.subscribe(e)}function cb(){return(0,H.useSyncExternalStore)(sb,ab,ab)}function lb(e){zy([...e]),ob||(ib=!1)}var ub=B.pullState;async function db(){return await xre(),caches.open(Zl)}var fb=`/__pull-result/`,pb=B.pullAuto,mb=25e3,hb=3e4,gb=[2e3,5e3,1e4,2e4,3e4,6e4,12e4],_b=15e3,vb=6048e5,yb=8e3;function bb(e,t,n){let r=`${e} ${t} ${Math.round(n)}`,i=5381;for(let e=0;e<r.length;e++)i=(i*33^r.charCodeAt(e))>>>0;let a=52711;for(let e=r.length-1;e>=0;e--)a=(a*31^r.charCodeAt(e))>>>0;return`l_${i.toString(36)}${a.toString(36)}`}function xb(e){return e.src&&e.src.startsWith(`/api/plugin-file/`)?Iu(e.src):Iu(`/api/repos/${e.repoId}/artifact?path=${encodeURIComponent(e.relPath)}&download=1`)}function Sb(){try{let e=JSON.parse(z(ub)||`{}`);return e&&typeof e==`object`?e:{}}catch{return{}}}function Cb(){return z(pb)!==`0`}function wb(){return globalThis.Capacitor}function Tb(){if(no())return null;let e=Ch(`Pull`);return e&&typeof e.enqueue==`function`?e:null}function Eb(){return ku()&&Tb()!==null}async function Db(e){let t=Tb();if(!t)return null;let n=await t.enqueue(e);return{items:n?.items??[],running:!!n?.running}}async function Ob(e){try{await Tb()?.cancel({id:e})}catch{}}async function kb(e){try{await Tb()?.discard({id:e})}catch{}}async function Ab(e){let t=Tb();if(!t)throw Error(`no native download engine on this device`);await t.publish({id:e})}async function jb(e){let t=Tb();if(t&&typeof t.setAuto==`function`)try{await t.setAuto({on:e})}catch{}}async function Mb(){let e=Tb();if(!e)return{items:[],running:!1};try{let t=await e.list();return{items:t?.items??[],running:!!t?.running}}catch{return{items:[],running:!1}}}async function Nb(){let e=Tb();if(e?.setDropAfterSave)try{let t=await e.list();return typeof t?.dropAfterSave==`boolean`?t.dropAfterSave:void 0}catch{return}}async function Pb(e){let t=Tb();if(!t?.setDropAfterSave)throw Error(`this app build cannot do that yet`);await t.setDropAfterSave({on:e})}function Fb(e){let t=Tb();if(!t)return()=>void 0;let n=null,r=!1,i=e=>{r?e.remove():n=e};try{let n=t.addListener(`pullChanged`,t=>e(t?.items??[]));n&&typeof n.then==`function`?n.then(i).catch(()=>void 0):i(n)}catch{}return()=>{r=!0;try{n?.remove()}catch{}}}function Ib(e){if(!e)return null;let t=wb();try{return typeof t?.convertFileSrc==`function`?t.convertFileSrc(e):null}catch{return null}}var Lb=null;function Rb(){return Lb===null&&(Lb=zr(ku()?_u():null)),Lb}function zb(){return Gee(ku()?_u():null)}var Bb=8e3;function Vb(e){let t=yre(e,zb()).catch(()=>{});return Promise.race([t,new Promise(e=>setTimeout(e,Bb))]).then(()=>e)}var Hb=13;function Ub(e){e.objectStoreNames.contains(`transcripts`)||e.createObjectStore(`transcripts`),e.objectStoreNames.contains(`pty`)||e.createObjectStore(`pty`),e.objectStoreNames.contains(`uploads`)||e.createObjectStore(`uploads`),e.objectStoreNames.contains(`pulls`)||e.createObjectStore(`pulls`),e.objectStoreNames.contains(`tooldetail`)||e.createObjectStore(`tooldetail`),e.objectStoreNames.contains(`screenlog`)||e.createObjectStore(`screenlog`),e.objectStoreNames.contains(`gallery`)||e.createObjectStore(`gallery`),e.objectStoreNames.contains(`artifacttext`)||e.createObjectStore(`artifacttext`),e.objectStoreNames.contains(`thumbs`)||e.createObjectStore(`thumbs`),e.objectStoreNames.contains(`thumbmeta`)||e.createObjectStore(`thumbmeta`),e.objectStoreNames.contains(`tree`)||e.createObjectStore(`tree`),e.objectStoreNames.contains(`ctxseries`)||e.createObjectStore(`ctxseries`),e.objectStoreNames.contains(`tokenstats`)||e.createObjectStore(`tokenstats`),e.objectStoreNames.contains(`dictations`)||e.createObjectStore(`dictations`),e.objectStoreNames.contains(`extassets`)||e.createObjectStore(`extassets`)}var Wb=null;function Gb(){return Wb||=new Promise(e=>{if(typeof indexedDB>`u`){e(null);return}let t=!1,n=n=>{t||(t=!0,e(n))};try{let e=indexedDB.open(Rb(),Hb);e.onupgradeneeded=()=>Ub(e.result),e.onsuccess=()=>{Vb(qb(e.result)).then(n)},e.onerror=()=>n(null),e.onblocked=()=>{Kb().then(e=>e?Vb(e):null).then(n)}}catch{n(null)}}).then(e=>(e||(Wb=null),e)),Wb}function Kb(){return new Promise(e=>{try{let t=indexedDB.open(Rb());t.onsuccess=()=>e(qb(t.result)),t.onerror=()=>e(null),t.onblocked=()=>e(null)}catch{e(null)}})}function qb(e){let t=()=>{Wb&&=null};return e.onversionchange=()=>{e.close(),t()},e.onclose=t,e}async function Jb(e,t,n){try{let r=await Gb();return r?await new Promise(i=>{let a=r.transaction(e,t),o=n(a.objectStore(e));o.onsuccess=()=>i(o.result),o.onerror=()=>i(null),a.onerror=()=>i(null),a.onabort=()=>i(null)}):null}catch(e){return e?.name!==`NotFoundError`&&(Wb=null),null}}var Yb=(e,t)=>Jb(e,`readonly`,e=>e.get(t)),Xb=async(e,t,n)=>await Jb(e,`readwrite`,e=>e.put(n,t))!==null,Zb=async(e,t)=>{await Jb(e,`readwrite`,e=>e.delete(t))},Qb=async e=>await Jb(e,`readonly`,e=>e.getAll())??[],$b=async e=>(await Jb(e,`readonly`,e=>e.getAllKeys())??[]).map(String),ex=async(e,t,n)=>{try{let r=await Gb();return r?await new Promise(i=>{let a=0,o=0;try{let s=r.transaction(e,`readonly`),c=s.objectStore(e).openCursor();c.onsuccess=()=>{let e=c.result;if(e){if(!n||n(String(e.key))){a++;try{o+=t(e.value)||0}catch{}}e.continue()}},c.onerror=()=>i(null),s.oncomplete=()=>i({count:a,bytes:o}),s.onerror=()=>i(null),s.onabort=()=>i(null)}catch{i(null)}}):null}catch(e){return e?.name!==`NotFoundError`&&(Wb=null),null}},tx=async e=>{try{let t=await Gb();return t?await new Promise(n=>{try{let r=t.transaction(e,`readwrite`);r.objectStore(e).clear(),r.oncomplete=()=>n(!0),r.onerror=()=>n(!1),r.onabort=()=>n(!1)}catch{n(!1)}}):!1}catch(e){return e?.name!==`NotFoundError`&&(Wb=null),!1}},nx=async(e,t)=>{try{let n=await Gb();return n?await new Promise(r=>{try{let i=n.transaction(e,`readwrite`),a=i.objectStore(e).openCursor();a.onsuccess=()=>{let e=a.result;e&&(t(String(e.key))&&e.delete(),e.continue())},a.onerror=()=>r(!1),i.oncomplete=()=>r(!0),i.onerror=()=>r(!1),i.onabort=()=>r(!1)}catch{r(!1)}}):!1}catch(e){return e?.name!==`NotFoundError`&&(Wb=null),!1}};function rx(e){let t=e.item.size||e.received;return t>0?Math.min(100,Math.round(e.received/t*100)):0}function ix(e){if(!e||e.state===`done`&&e.evicted)return{phase:`idle`,pct:null,label:`download`,detail:e?.evicted?`downloaded before — the bytes were cleared to save space; fetch it again`:`fetch it to this phone — it resumes by itself if the link drops`};let t=rx(e);return e.state===`downloading`?{phase:`downloading`,pct:t,label:`downloading · ${t}%`,detail:`open Downloads to watch, pause or cancel it`}:e.state===`queued`||e.state===`paused`?{phase:`queued`,pct:e.received>0?t:null,label:e.state===`paused`?`paused`:`queued`,detail:e.received>0?`${t}% is already here — it resumes from there`:`waiting its turn — open Downloads`}:e.state===`failed`?{phase:`failed`,pct:e.received>0?t:null,label:`retry download`,detail:e.error?`the last attempt failed: ${e.error}`:`the last attempt failed`}:e.savedAt&&!e.saveError?e.droppedAt&&e.savedPresent!==!1?{phase:`saved`,pct:100,label:`in Downloads`,detail:`in ${e.savedTo} · the only copy — this app kept none of its own`}:e.saveVia===`browser`?{phase:`saved`,pct:100,label:`save again`,detail:`on this phone · handed to ${e.savedTo} — tap to hand it over again if it never arrived`}:e.savedPresent===!0?{phase:`saved`,pct:100,label:`in Downloads`,detail:`in ${e.savedTo} · nothing to do — a second save would only make another copy beside it`}:e.savedPresent===!1?{phase:`saved`,pct:100,label:`save again`,detail:`it was saved to ${e.savedTo}, and is not in Downloads any more · still on this phone — tap to put it back`}:{phase:`saved`,pct:100,label:`save again`,detail:`on this phone · saved to ${e.savedTo}`}:e.saveHandedAt&&!e.saveError?{phase:`have`,pct:100,label:`check Downloads`,detail:`on this phone · handed to Downloads, and the phone has not said where it went — open Downloads to look`}:{phase:`have`,pct:100,label:`save to phone`,detail:e.saveError?`on this phone — saving it out failed: ${e.saveError}`:`on this phone — put it where a file manager can see it`}}function ax(e){let{phase:t}=ix(e);return t===`saved`&&(e?.savedPresent===!0||e?.droppedAt)?`open`:t===`have`||t===`saved`?`save`:t===`downloading`||t===`queued`?`open`:`start`}function ox(e,t){return!(e.state!==`done`||e.evicted||!e.autoSave&&!t||e.savedAt||e.saveError||e.saveHandedAt)}function sx(e){return e.state===`downloading`?!1:e.state!==`done`||!!e.evicted}function cx(e,t,n,r){if(e.item.repoId!==t||e.item.relPath!==n)return null;let i=Math.round(r??0),a=Math.round(e.item.mtime??0);return i&&a?i===a?`exact`:null:i&&e.state===`done`&&!e.evicted?null:`loose`}function lx(e,t,n){return t||!!e.local||e.state===`done`||n}function ux(e,t){return!(!e||e.state!==`downloading`||t.activeId===e.item.id||e.nativeOwned||e.engine===`native`&&t.nativeSupported!==!1||e.engine===`bgfetch`&&t.bgLive!==!1)}function dx(e,t){return!(!e||e.state!==`queued`||e.nativeOwned||!t.force&&!t.auto&&!e.local||!t.force&&e.attempts>=t.maxAttempts||!t.force&&e.nextRetryAt&&e.nextRetryAt>t.now)}function fx(e,t){return!e&&!t}function px(e){return e.state===`failed`&&/^http (404|410)\b/.test(e.error??``)}function mx(e,t){return e.filter(e=>e.state!==`done`&&(t||!!e.local||e.state===`downloading`))}function hx(e){return e.native||!e.android||!e.auto||e.answered?!1:e.records.some(e=>!e.local&&e.state!==`done`)}function gx(){let e=this.list(),t={};if(e.length<=200)for(let n of e)t[n.item.id]=n;else{let n=e=>this.active===e.item.id||e.local&&e.state!==`done`||e.state===`done`&&!e.savedAt&&!e.evicted,r=[...e.filter(n),...e.filter(e=>!n(e))];for(let e of r.slice(0,200))t[e.item.id]=e;for(let e of r.slice(200))Zb(`pulls`,e.item.id),e.nativePath&&kb(e.item.id)}this.records=t,$a(ub,t),this.emit()}function _x(e,t){let n=this.records[e];n&&(this.records[e]={...n,...t,updatedAt:Date.now()},this.persist())}function vx(e){this.dropSuperseded(e.flatMap(e=>e.supersedes??[]));for(let t of e)t.family&&this.dropSuperseded(this.list().filter(e=>e.item.id!==t.id&&e.item.repoId===t.repoId&&(e.item.family??``)===t.family&&e.item.mtime<t.mtime).map(e=>e.item.id));let t=new Set(e.map(e=>e.id));for(let t of e){let e=this.records[t.id];if(e)this.records[t.id]={...e,item:t};else if(this.shadowed(t))continue;else this.records[t.id]={item:t,state:`queued`,received:0,attempts:0,updatedAt:Date.now()}}for(let e of Object.keys(this.records))lx(this.records[e],t.has(e),this.active===e)||(delete this.records[e],Zb(`pulls`,e));this.persist(),this.evictOld(),this.pump()}function yx(e){this.dropSuperseded(e.supersedes??[]),this.shadowed(e)?this.persist():(this.records[e.id]||(this.records[e.id]={item:e,state:`queued`,received:0,attempts:0,updatedAt:Date.now()},this.persist()),this.pump())}function bx(e,t={}){let n=Math.round(e.mtime??0),r=this.findFor(e.repoId,e.relPath,n);if(r){let i={local:!0};return t.autoSave&&(i.autoSave=!0),!r.item.mtime&&n&&(i.item={...r.item,mtime:n,size:r.item.size||Math.round(e.size??0)}),this.patch(r.item.id,i),sx(r)&&this.retry(r.item.id),r.item.id}let i=bb(e.repoId,e.relPath,n),a={id:i,repoId:e.repoId,repoDir:e.repoDir??``,repoName:e.repoName??``,name:e.name||e.relPath.split(`/`).pop()||e.relPath,relPath:e.relPath,size:Math.max(0,Math.round(e.size??0)),mtime:n,ts:Date.now(),source:`manual`,...e.src&&e.src.startsWith(`/api/plugin-file/`)?{src:e.src}:{}};return this.records[i]={item:a,state:`queued`,received:0,attempts:0,updatedAt:Date.now(),local:!0,autoSave:!!t.autoSave},this.persist(),this.pump(!0,i),i}function xx(e,t,n){let r=this.list();return r.find(r=>cx(r,e,t,n)===`exact`)??r.find(r=>cx(r,e,t,n)===`loose`)}function Sx(e){if(this.records[e.id])return!1;let t=this.findFor(e.repoId,e.relPath,e.mtime);return t?.local?(!t.item.mtime&&e.mtime&&(t.item={...t.item,mtime:e.mtime,size:t.item.size||e.size},this.records[t.item.id]={...t,updatedAt:Date.now()}),!0):!1}function Cx(e){let t=!1;for(let n of e){let e=this.records[n];e&&e.state!==`done`&&(this.active===n&&(this.abort?.abort(),this.active=null),delete this.records[n],kb(n),Zb(`pulls`,n),t=!0)}t&&this.persist()}function wx(e){let t=this.records[e];t&&(t.state!==`done`||t.evicted)&&t.state!==`downloading`&&(this.patch(e,{state:`queued`,attempts:0,error:void 0,nextRetryAt:void 0,evicted:!1,nativeOwned:!1}),this.pump(!0,e))}async function Tx(e){this.active===e&&(this.abort?.abort(),this.active=null),delete this.records[e],this.removed.add(e),this.persist(),kb(e),await Zb(`pulls`,e)}function Ex(e){let t=e??this.active;t&&(this.records[t]?.engine===`native`?(Ob(t),this.patch(t,{state:`paused`,rate:void 0,nextRetryAt:void 0})):this.active===t&&(this.abort?.abort(),this.active=null,this.patch(t,{state:`paused`,rate:void 0,nextRetryAt:void 0})))}function Dx(){for(let e of this.list())(e.state===`queued`||e.state===`paused`||e.state===`failed`)&&this.patch(e.item.id,{state:`queued`,attempts:0,error:void 0,nextRetryAt:void 0,nativeOwned:!1});this.pump(!0)}function Ox(){if(this.active)return null;if(this.list().filter(e=>ux(e,{activeId:this.active,nativeSupported:Eb()})).length)return`a transfer was interrupted and nothing is carrying it — putting it back in the queue`;let e=this.list().filter(e=>e.state===`queued`||e.state===`paused`||e.state===`failed`);return e.length?!Cb()&&e.every(e=>!e.local)?`auto-download is off — tap a file to fetch it now`:fx(navigator.onLine,Kd())?`the phone reports no network — will start when it is back`:e.every(e=>e.state===`paused`)?`paused — tap resume`:e.every(px)?`the desktop no longer has these files — remove them`:e.every(e=>e.state===`failed`||e.attempts>=50)?`stopped after repeated failures — tap retry`:e.every(e=>e.state===`paused`||e.state===`failed`||e.attempts>=50)?`nothing is running — each row below says why`:null:null}var kx=524288,Ax=8192;function jx(){let e=Ch(`Save`);return e&&typeof e.begin==`function`?e:null}function Mx(){return ku()&&jx()!==null}function Nx(){return ku()&&typeof jx()?.find==`function`}async function Px(e,t){let n=jx();if(!n?.find)return null;try{let r=await n.find({name:e,size:t||void 0});return{present:!!r?.present,where:r?.where,size:r?.size,modified:r?.modified}}catch{return null}}async function Fx(e,t){let n=jx();if(!n)throw Error(`no native save on this device`);let{token:r}=await n.begin({name:t,mime:e.type===`application/octet-stream`?``:e.type||``});try{for(let t=0;t<e.size;t+=kx){let i=await e.slice(t,Math.min(t+kx,e.size)).arrayBuffer();await n.chunk({token:r,dataBase64:Ix(i)})}let{where:t}=await n.finish({token:r});return t}catch(e){try{await n.abort({token:r})}catch{}throw e}}function Ix(e){let t=new Uint8Array(e),n=``;for(let e=0;e<t.length;e+=Ax)n+=String.fromCharCode(...t.subarray(e,e+Ax));return btoa(n)}var Lx={png:`image/png`,jpg:`image/jpeg`,jpeg:`image/jpeg`,jfif:`image/jpeg`,gif:`image/gif`,webp:`image/webp`,svg:`image/svg+xml`,bmp:`image/bmp`,avif:`image/avif`,heic:`image/heic`,heif:`image/heif`,ico:`image/x-icon`,tif:`image/tiff`,tiff:`image/tiff`,mp4:`video/mp4`,m4v:`video/x-m4v`,webm:`video/webm`,mov:`video/quicktime`,ogv:`video/ogg`,mkv:`video/x-matroska`,mp3:`audio/mpeg`,m4a:`audio/mp4`,aac:`audio/aac`,wav:`audio/wav`,ogg:`audio/ogg`,flac:`audio/flac`,opus:`audio/opus`,pdf:`application/pdf`,txt:`text/plain`,log:`text/plain`,md:`text/markdown`,csv:`text/csv`,json:`application/json`,html:`text/html`,htm:`text/html`,apk:`application/vnd.android.package-archive`,zip:`application/zip`};function Rx(e){let t=/\.([A-Za-z0-9]+)$/.exec(e);return t&&Lx[t[1].toLowerCase()]||`application/octet-stream`}function zx(e,t){return new Blob(e,{type:Rx(t)})}async function Bx(e){let t=this.records[e];if(t?.droppedAt&&t.savedTo&&t.savedPresent!==!1)return{ok:!0,where:t.savedTo,already:!0};if(t?.engine===`native`&&t.nativePath)return this.saveNative(e,t);let n=await Yb(`pulls`,e);if(!n?.blob){let t=`could not read the downloaded bytes on this phone — try again, or fetch it once more`;return this.patch(e,{saveError:t}),{ok:!1,error:t}}if(Mx()){let t=await Px(n.name,n.blob.size);if(t?.present)return this.patch(e,{savedTo:t.where,savedAt:Date.now(),saveError:void 0,saveVia:`device`,savedPresent:!0,savedCheckedAt:Date.now()}),{ok:!0,where:t.where,already:!0};try{let t=await Fx(n.blob,n.name);return this.patch(e,{savedTo:t,savedAt:Date.now(),saveError:void 0,saveVia:`device`,savedPresent:!0,savedCheckedAt:Date.now()}),await Nb()&&(await Zb(`pulls`,e),this.patch(e,{droppedAt:Date.now()})),{ok:!0,where:t}}catch(t){let n=t instanceof Error?t.message:String(t);return this.patch(e,{saveError:n}),{ok:!1,error:n}}}let r=URL.createObjectURL(zx([n.blob],n.name)),i=document.createElement(`a`);i.href=r,i.download=n.name,document.body.appendChild(i),i.click(),i.remove(),setTimeout(()=>URL.revokeObjectURL(r),6e4);let a=`your browser's downloads`;return this.patch(e,{savedTo:a,savedAt:Date.now(),saveError:void 0,saveVia:`browser`}),{ok:!0,where:a}}async function Vx(e,t){let n=await Px(t.item.name||t.item.relPath.split(`/`).pop()||t.item.relPath,t.item.size||void 0);if(n?.present)return this.patch(e,{savedTo:n.where,savedAt:Date.now(),saveError:void 0,saveVia:`device`,savedPresent:!0,savedCheckedAt:Date.now()}),{ok:!0,where:n.where,already:!0};try{await Ab(e);let t=Date.now()+yb;for(;;){let n=await Mb();if(!this.records[e])return{ok:!1,error:`the download was removed while it was being saved`};let r=n.items.find(t=>t.id===e);if(r?.where||r?.error){await this.syncNative(n);let t=this.records[e];if(t?.savedTo)return{ok:!0,where:t.savedTo};if(t?.saveError)return{ok:!1,error:t.saveError}}if(Date.now()>=t)break;await new Promise(e=>setTimeout(e,300))}return this.patch(e,{saveHandedAt:Date.now()}),{ok:!1,error:`the phone has not said where it went yet — look in Downloads`}}catch(t){let n=t instanceof Error?t.message:String(t);return this.patch(e,{saveError:n}),{ok:!1,error:n}}}async function Hx(e){let t=this.records[e];if(!t||t.state!==`done`||t.evicted||!Nx())return;let n=await Px(t.item.name||t.item.relPath.split(`/`).pop()||t.item.relPath,t.item.size||void 0);if(n)return this.patch(e,{savedPresent:n.present,savedCheckedAt:Date.now(),...!n.present&&t.droppedAt?{evicted:!0}:{},...n.present&&n.where?{savedTo:n.where,savedAt:t.savedAt??Date.now(),saveVia:t.saveVia??`device`,saveError:void 0,saveHandedAt:void 0}:{}}),n.present}async function Ux(){if(Nx())for(let e of this.list())e.state!==`done`||e.evicted||await this.verifySaved(e.item.id)}async function Wx(e){let t=this.records[e];if(t?.nativePath){let e=Ib(t.nativePath);if(e)return e}let n=await Yb(`pulls`,e);return n?.blob?URL.createObjectURL(zx([n.blob],n.name)):null}function Gx(){if(this.started)return;this.started=!0,jb(Cb());let e=[];for(let t of this.list())t.state===`downloading`&&(t.engine===`native`&&Eb()||(t.engine===`bgfetch`&&e.push(t.item.id),this.patch(t.item.id,{state:`queued`,rate:void 0})));addEventListener(`online`,()=>this.pump()),document.addEventListener(`visibilitychange`,()=>{document.hidden||this.pump()}),addEventListener(`pageshow`,()=>this.pump()),setInterval(()=>this.pump(),_b),Fb(e=>{this.syncNative({items:e,running:!0})}),this.syncNative(),this.recoverBackgroundFetches(e).then(()=>this.evictOld()),this.pump()}function Kx(e=!1,t){if(this.syncNativeSoon(),this.watchdog(),this.active||!e&&fx(navigator.onLine,Kd()))return;let n=Cb(),r=Date.now(),i=t=>dx(t,{auto:n,force:e,maxAttempts:50,now:r}),a=t?this.records[t]:void 0,o=i(a)?a:this.list().find(e=>i(e));o&&(this.active=o.item.id,this.run(o.item.id).finally(()=>{this.active=null,(Cb()||this.list().some(e=>e.local&&e.state===`queued`))&&this.pump()}))}function qx(){for(let e of this.list())ux(e,{activeId:this.active,nativeSupported:Eb()})&&this.patch(e.item.id,{state:`queued`,rate:void 0});let e=this.active;if(!e)return;let t=this.records[e];t&&t.state===`downloading`&&t.engine!==`bgfetch`&&t.engine!==`native`&&(Date.now()-(t.lastProgressAt??t.updatedAt)<6e4||(this.abort?.abort(),setTimeout(()=>this.pump(),250)))}async function Jx(e){let t=this.records[e];if(!t)return;let n=t.received;if(this.patch(e,{state:`downloading`,error:void 0,nextRetryAt:void 0,lastProgressAt:Date.now()}),!await this.startBackgroundFetch(t)&&!await this.startNative(t))try{await this.rangeFetch(e)}catch(t){let r=t,i=r?.name===`AbortError`?`connection stalled`:String(r?.message||t),a=this.records[e];if(!a||a.state===`paused`)return;let o=a.received>n?0:(a.attempts??0)+1,s=!!r?.permanent||o>=50;this.patch(e,{state:s?`failed`:`queued`,attempts:o,error:i,rate:void 0}),s||this.scheduleRetry(e,o)}}function Yx(e,t){this.retryTimer&&clearTimeout(this.retryTimer);let n=gb[Math.min(Math.max(1,t)-1,gb.length-1)];this.patch(e,{nextRetryAt:Date.now()+n}),this.retryTimer=setTimeout(()=>{this.retryTimer=null,this.pump()},n)}async function Xx(e){if(!Eb())return!1;try{let t=await Db({id:e.item.id,url:xb(e.item),name:e.item.name||e.item.relPath.split(`/`).pop()||e.item.relPath,size:e.item.size||void 0,etag:e.etag,autoSave:!!e.autoSave});return this.patch(e.item.id,{engine:`native`,nativeOwned:!0,lastProgressAt:Date.now()}),e.received>0&&!e.nativePath&&Zb(`pulls`,e.item.id),t&&await this.syncNative(t),!0}catch(t){return this.patch(e.item.id,{error:t instanceof Error?t.message:String(t)}),!1}}async function Zx(e){if(!Eb())return;this.lastNativeSync=Date.now();let{items:t,running:n}=e??await Mb();for(let e of t){let t=this.records[e.id]??this.adoptNative(e);if(!t){kb(e.id);continue}let r={engine:`native`,nativeOwned:!0,received:e.received,error:e.error||void 0,nextRetryAt:e.nextAt>Date.now()?e.nextAt:void 0};e.size>0&&!t.item.size&&(r.item={...t.item,size:e.size}),e.etag&&(r.etag=e.etag),e.received>t.received&&(r.lastProgressAt=Date.now()),e.state===`done`?(r.state=`done`,r.nativeOwned=!1,r.nativePath=e.path,r.droppedAt=e.droppedAt||void 0,r.evicted=!e.path&&!(e.droppedAt&&t.savedPresent!==!1),r.rate=void 0,r.nextRetryAt=void 0,r.error=void 0,e.error&&(r.saveError=e.error,r.saveHandedAt=void 0),e.pkg&&(r.pkg=e.pkg,r.pkgLabel=e.pkgLabel,r.pkgVersion=e.pkgVersion),r.install=e.install??``,r.installError=e.installError||void 0,r.installedAt=e.installedAt||void 0,r.installAuto=typeof e.installAuto==`boolean`?e.installAuto:void 0,r.installSnoozedUntil=e.installSnoozedUntil||void 0,r.cleanedAt=e.cleanedAt||void 0,r.cleanedBytes=e.cleanedAt&&e.cleanedBytes||void 0,r.cleanNote=e.cleanNote||void 0,e.cleanedAt&&!e.where&&t.savedTo&&t.saveVia===`device`&&(r.savedTo=void 0,r.savedPresent=void 0,r.savedCheckedAt=void 0),e.where&&(t.savedTo!==e.where&&(r.savedTo=e.where,r.savedAt=Date.now(),r.saveVia=`device`,r.savedPresent=!0,r.savedCheckedAt=Date.now()),r.saveError=void 0,r.saveHandedAt=void 0)):e.state===`failed`?(r.state=`failed`,r.nativeOwned=!1,r.attempts=e.attempts,r.rate=void 0):e.state===`paused`?(r.state=`paused`,r.nativeOwned=!1,r.rate=void 0):e.state===`downloading`?r.state=`downloading`:(t.state===`downloading`||t.state===`queued`)&&(r.state=`queued`,r.attempts=e.attempts,!n&&e.nextAt<=Date.now()&&(r.nativeOwned=!1)),this.patch(e.id,r)}let r=new Set(t.map(e=>e.id));for(let e of this.list())e.nativeOwned&&!r.has(e.item.id)&&this.patch(e.item.id,{nativeOwned:!1,state:e.state===`done`?`done`:`queued`,rate:void 0})}function Qx(e){let t=e.origin===`link`?e.item:void 0;if(!t||t.id!==e.id||!t.repoId||!t.relPath||this.removed.has(t.id)||(this.dropSuperseded(t.supersedes??[]),this.shadowed(t)))return;let n={item:t,state:`queued`,received:e.received,attempts:e.attempts,updatedAt:Date.now(),engine:`native`,nativeOwned:!0};return this.records[t.id]=n,this.persist(),Db({id:t.id,url:e.url,name:e.name,size:e.size||void 0,etag:e.etag||void 0}).catch(()=>void 0),n}function $x(){Eb()&&(Date.now()-this.lastNativeSync<2e3||this.syncNative())}async function eS(e){if(e.received>0||e.bgBlocked||Nu()||no())return!1;try{if(!(`serviceWorker`in navigator))return!1;let t=await navigator.serviceWorker.ready;if(!t?.backgroundFetch)return!1;let n=await t.backgroundFetch.fetch(e.item.id,[xb(e.item)],{title:e.item.name,downloadTotal:e.item.size,icons:[{src:`/assets/icon-192.png`,sizes:`192x192`,type:`image/png`}]});return this.patch(e.item.id,{engine:`bgfetch`}),this.watchBackgroundFetch(n),!0}catch{return!1}}function tS(e){if(!e)return;let t=e.id;e.addEventListener?.(`progress`,()=>{let n=Number(e.downloaded||0);e.result===`failure`?this.noteBgFailure(t,e.failureReason):this.patch(t,{state:e.result===`success`?`done`:`downloading`,received:n})})}async function nS(){let e=new Set;try{if(!(`serviceWorker`in navigator))return e;let t=await navigator.serviceWorker.ready;if(!t?.backgroundFetch)return e;let n=await t.backgroundFetch.getIds();for(let r of n){let n=await t.backgroundFetch.get(r);n&&(e.add(r),this.watchBackgroundFetch(n))}}catch{}return e}async function rS(e){let t=await this.adoptBackgroundFetches(),n=await this.drainBackgroundResults();await this.importAllCached();for(let r of e){if(t.has(r)||n.has(r))continue;let e=this.records[r];e&&e.state!==`done`&&e.state!==`paused`&&this.noteBgFailure(r,`the download ended while the app was closed`)}}async function iS(){let e=new Set;if(typeof caches>`u`)return e;try{let t=await db();for(let n of await t.keys()){let r=new URL(n.url).pathname;if(!r.startsWith(`/__pull-result/`))continue;let i=null;try{i=await(await t.match(n))?.json()}catch{}await t.delete(n);let a=String(i?.id||decodeURIComponent(r.slice(15)));a&&this.records[a]&&(e.add(a),this.noteBackgroundResult(a,!!i?.ok,Number(i?.received||0),i?.reason||void 0))}}catch{}return e}async function aS(e){if(typeof caches<`u`)try{await(await db()).delete(fb+encodeURIComponent(e))}catch{}}function oS(e,t){let n=this.records[e];if(!n||n.state===`paused`)return;let r=(n.attempts??0)+1,i=r>=50;this.patch(e,{state:i?`failed`:`queued`,attempts:r,error:t||`background fetch failed`,engine:void 0,bgBlocked:!0,rate:void 0}),i||this.scheduleRetry(e,r),this.pump()}function sS(e,t,n,r){this.records[e]&&(this.dropBackgroundResult(e),t?(this.patch(e,{received:n}),this.importFromCache(e).finally(()=>this.pump())):this.noteBgFailure(e,r))}async function cS(e){let t=this.records[e];if(t)try{let n=await db(),r=xb(t.item),i=await n.match(r);if(!i)return;let a=await i.blob();await this.store(e,a,a.size,t.item.size||a.size,t.item.name),await n.delete(r),this.patch(e,{state:`done`,received:a.size,error:void 0,engine:`bgfetch`})}catch(t){this.patch(e,{state:`queued`,error:String(t?.message||t)})}}async function lS(){if(typeof caches<`u`)for(let e of this.list())e.state!==`done`&&e.state!==`paused`&&await this.importFromCache(e.item.id)}async function uS(e){let t=this.records[e];if(!t)return;let n=await Yb(`pulls`,e),r=n?.blob??new Blob([]),i=n?Math.min(n.received,n.blob?.size??0):0;i!==r.size&&(r=new Blob([]),i=0);let a=new AbortController;this.abort=a;let o=setTimeout(()=>a.abort(),mb),s=e=>{clearTimeout(o),o=setTimeout(()=>a.abort(),e)};try{let n={};i>0&&(n.Range=`bytes=${i}-`),i>0&&t.etag&&(n[`if-range`]=t.etag);let o=await fetch(xb(t.item),{headers:n,signal:a.signal,cache:`no-store`});if(s(hb),o.status===416)throw await Zb(`pulls`,e),this.patch(e,{received:0,etag:void 0}),Error(`stored part no longer matches — starting over`);if(!o.ok&&o.status!==206){let e=Error(o.status===403?`http 403 — the host refused this request (origin not allowed)`:`http ${o.status}`);throw e.permanent=o.status===403||o.status===404||o.status===410,e}let c=o.headers.get(`etag`)||void 0;o.status===200&&i>0&&(r=new Blob([]),i=0);let l=o.status===206?Number((o.headers.get(`content-range`)||``).split(`/`)[1]||0)||t.item.size:Number(o.headers.get(`content-length`)||0)||t.item.size;if(!o.body){let n=await o.blob(),a=zx(i>0?[r,n]:[n],t.item.name);await this.store(e,a,a.size,l,t.item.name),this.patch(e,{state:`done`,received:a.size,etag:c,rate:void 0});return}let u=o.body.getReader(),d=[],f=0,p=Date.now();this.patch(e,{engine:`range`,etag:c,received:i,lastProgressAt:Date.now()});let m=async()=>{if(!f)return;let n=Date.now(),a=f;r=zx([r,...d],t.item.name),d=[],f=0,i=r.size,await this.store(e,r,i,l,t.item.name);let o=Math.max(1,n-p)/1e3;p=n;let s=a/o,c=this.records[e]?.rate;this.patch(e,{received:i,rate:c?c*.7+s*.3:s,lastProgressAt:n,wireBytes:(this.records[e]?.wireBytes??0)+a})};try{for(;;){let{done:e,value:t}=await u.read();if(e)break;s(hb),d.push(t),f+=t.byteLength,(f>=1048576||Date.now()-p>=1500)&&await m()}}catch(e){throw await m().catch(()=>void 0),e}if(await m(),l>0&&i<l)throw Error(`incomplete (${i}/${l})`);this.patch(e,{state:`done`,received:i,error:void 0,rate:void 0,nextRetryAt:void 0})}finally{clearTimeout(o)}}async function dS(e,t,n,r,i){this.records[e]&&await Xb(`pulls`,e,{id:e,blob:t,received:n,total:r,name:i})}async function fS(){let e=Date.now()-vb;for(let t of this.list())t.state===`done`&&!t.evicted&&!t.droppedAt&&t.updatedAt<e&&t.received>0&&await this.dropOne(t)}async function pS(e){await Zb(`pulls`,e.item.id),e.nativePath&&await kb(e.item.id),this.patch(e.item.id,{received:0,evicted:!0,nativePath:void 0})}async function mS(e){let t=0,n=0;for(let r of e){let e=this.records[r];if(!e||e.state!==`done`||e.evicted||e.droppedAt)continue;let i=e.received||e.item.size||0;await this.dropOne(e),t++,n+=i}return{count:t,bytes:n}}function hS(e){Za(pb,e?`1`:`0`),jb(e),e&&gS.pump(),gS.emit()}var gS=new class{records=Sb();listeners=new Set;active=null;abort=null;retryTimer=null;started=!1;lastNativeSync=0;removed=new Set;subscribe(e){return this.listeners.add(e),e(this.list()),()=>{this.listeners.delete(e)}}emit(){let e=this.list();for(let t of this.listeners)t(e)}list(){return Object.values(this.records).sort((e,t)=>t.item.ts-e.item.ts)}get(e){return this.records[e]}persist=gx;patch=_x;sync=vx;add=yx;addLocal=bx;findFor=xx;shadowed=Sx;dropSuperseded=Cx;retry=wx;remove=Tx;pause=Ex;resumeAll=Dx;whyIdle=Ox;save=Bx;saveNative=Vx;verifySaved=Hx;verifyAllSaved=Ux;objectUrl=Wx;start=Gx;pump=Kx;watchdog=qx;run=Jx;scheduleRetry=Yx;startNative=Xx;syncNative=Zx;adoptNative=Qx;syncNativeSoon=$x;startBackgroundFetch=eS;watchBackgroundFetch=tS;adoptBackgroundFetches=nS;recoverBackgroundFetches=rS;drainBackgroundResults=iS;dropBackgroundResult=aS;noteBgFailure=oS;noteBackgroundResult=sS;importFromCache=cS;importAllCached=lS;rangeFetch=uS;store=dS;evictOld=fS;dropOne=pS;dropBytes=mS};function _S(e){return!e||e.type!==`pull-result`?!1:(gS.noteBackgroundResult(String(e.id),!!e.ok,Number(e.received||0),e.reason),!0)}var vS=G(new Map);function yS(e,t){vS.set(n=>yh(n,e,t))}function bS(e,t,n,r){let i=vS.get().get(e);if(!i)return n.liveAsk({t:`pull.get`,repoDir:e},`no connection — the rule lives on the desktop`),r(`reading this repo's download rule — tap again in a moment`),`asked`;let a={...i,enabled:!0,builds:!0};return yS(e,a),n.liveSend({t:`pull.save`,repoDir:e,config:a},t,`no connection — the rule lives on the desktop and was not saved`),`saved`}function xS(){let[e,t]=(0,H.useState)(()=>gS.list());return(0,H.useEffect)(()=>gS.subscribe(t),[]),e}function SS(e){return gS.subscribe(e)}var CS={use(e){return K(vS).get(e)},ask(e){return W().conn.trySend({t:`pull.get`,repoDir:e})}};function wS(e,t){let n=W();bS(e,t,n.conn,n.say.toast)}function TS(){return(z(B.deviceName)??``).trim()}function ES(e){Za(B.deviceName,e.trim().slice(0,60))}function DS(){let e=typeof navigator>`u`?``:navigator.userAgent,t=(/Android[^;)]*;\s*([^;)]+?)(?:\s+Build\/[^;)]*)?\s*\)/.exec(e)?.[1]??``).trim();return t.length>1?t.slice(0,60):``}var OS=`extassets`,kS=/^[a-z][a-z0-9-]{0,39}$/,AS=/^[A-Za-z0-9][A-Za-z0-9._-]*$/;function jS(e){if(!kS.test(e))throw Error(`extAssets: bad plugin id ${JSON.stringify(e)}`);let t=`${e}/`,n=e=>{if(!AS.test(e))throw Error(`extAssets: bad file name ${JSON.stringify(e)}`);return t+e};return{fetch:(t,r)=>(n(t),U.pluginAsset(e,t,r)),get:async e=>{let t=await Yb(OS,n(e));return t instanceof Blob?t:null},put:(e,t)=>Xb(OS,n(e),t),remove:e=>Zb(OS,n(e)),list:async()=>(await $b(OS)).filter(e=>e.startsWith(t)).map(e=>e.slice(t.length)),clear:()=>nx(OS,e=>e.startsWith(t))}}var MS=15e3,NS=2e3;function PS(e){let t=new Set,n=new Map,r=new Map,i=!1,a=0,o=(t,n)=>{try{e.report?.(t,n)}catch{}},s=(e,t,n)=>{try{n()}catch(n){o(`${e.plugin}/${e.name} ${t}`,n)}},c=t=>{try{return e.trySend(t)}catch{return!1}},l=t=>{t.reqId&&n.delete(t.reqId),t.reqId=null,t.openTimer!=null&&(e.clearTimer(t.openTimer),t.openTimer=null)},u=t=>{t.streamId!=null&&r.delete(t.streamId),t.streamId=null,t.ackTimer!=null&&(e.clearTimer(t.ackTimer),t.ackTimer=null)},d=(e,n,r,i)=>{l(e),u(e),t.delete(e),e.state=n,e.reason=i,s(e,`onEnded`,()=>e.cb.onEnded?.(r,i))},f=t=>{l(t);let r=e.mintId(),i={t:`stream.open`,reqId:r,plugin:t.plugin,name:t.name,...t.params===void 0?{}:{params:t.params}};t.sentEpoch=a,c(i)?(t.reqId=r,t.sentParams=t.params,n.set(r,t),t.openTimer=e.setTimer(()=>{t.openTimer=null,t.reqId===r&&d(t,`refused`,`refused`,`the desktop did not answer — it may be running an older version without live streams`)},MS)):t.sentEpoch=-1},p=e=>{e.ackTimer=null,e.streamId!=null&&e.state===`open`&&c({t:`stream.ack`,streamId:e.streamId,seq:e.lastSeq,rxBytes:e.idBytes})},m=()=>{i=!1;for(let e of t)l(e),u(e),e.state=`opening`;n.clear(),r.clear()},h=(e,t)=>{let n=t-NS,r=0;for(;r<e.samples.length&&e.samples[r].t<=n;)r++;r&&e.samples.splice(0,r)};return{open(n,r,a,o){let s={plugin:n,name:r,params:a,cb:o,state:`opening`,reqId:null,sentParams:void 0,sentEpoch:-1,openTimer:null,streamId:null,closing:!1,openedAt:null,boundAt:0,rxBytes:0,frames:0,idBytes:0,lastSeq:0,ackTimer:null,samples:[]};return t.add(s),i&&f(s),{setParams(e){let t=ji(e);return t<0||t>8192?!1:(s.params=e,s.state===`open`&&s.streamId!=null&&c({t:`stream.params`,streamId:s.streamId,params:e})&&(s.sentParams=e),!0)},input(e){if(s.state!==`open`||s.streamId==null||!i)return!1;let t=ji(e);return t<0||t>4096?!1:c({t:`stream.input`,streamId:s.streamId,ev:e})},keyframe(){s.state===`open`&&s.streamId!=null&&c({t:`stream.keyframe`,streamId:s.streamId})},close(){s.closing||s.state===`ended`||s.state===`refused`||(s.closing=!0,t.delete(s),s.streamId!=null&&c({t:`stream.close`,streamId:s.streamId}),u(s),s.openTimer!=null&&(e.clearTimer(s.openTimer),s.openTimer=null),s.state=`ended`,s.reason=`closed`)},stats(){let t=e.now();h(s,t);let n=Math.max(1,Math.min(NS,t-s.boundAt)),r=s.samples.reduce((e,t)=>e+t.bytes,0);return{rxBytes:s.rxBytes,frames:s.frames,kbps:s.state===`open`?r*8/n:0,fps:s.state===`open`?s.samples.length*1e3/n:0,openedAt:s.openedAt,streamId:s.streamId,state:s.state,...s.reason===void 0?{}:{reason:s.reason}}}}},onText(o){switch(o.t){case`welcome`:i=!0,a++;for(let e of t)e.state===`opening`&&e.sentEpoch!==a&&f(e);return;case`error`:o.context===`__status`&&o.message!==`open`&&m();return;case`stream.opened`:{let t=n.get(o.reqId);if(!t||(l(t),t.closing)){c({t:`stream.close`,streamId:o.streamId});return}u(t),t.streamId=o.streamId,r.set(o.streamId,t),t.state=`open`;let i=e.now();t.openedAt??=i,t.boundAt=i,t.idBytes=0,t.lastSeq=0,t.samples=[],t.params!==t.sentParams&&c({t:`stream.params`,streamId:o.streamId,params:t.params})&&(t.sentParams=t.params),s(t,`onOpened`,()=>t.cb.onOpened?.(o.streamId));return}case`stream.refused`:{let e=n.get(o.reqId);if(!e)return;if(e.closing){l(e);return}d(e,`refused`,`refused`,o.reason);return}case`stream.status`:{let e=r.get(o.streamId);e&&s(e,`onStatus`,()=>e.cb.onStatus?.(o.data));return}case`stream.ended`:{let e=r.get(o.streamId);e&&d(e,`ended`,o.cause,o.reason);return}default:return}},onBinary(t){let n=Cee(t);if(!n)return;let i=r.get(n.streamId);if(!i||i.state!==`open`)return;let a=n.payload.byteLength,o=e.now();i.rxBytes+=a,i.idBytes+=a,i.frames++,i.lastSeq=n.seq,i.samples.push({t:o,bytes:a}),i.samples.length>512&&h(i,o),i.ackTimer??=e.setTimer(()=>p(i),250),s(i,`onFrame`,()=>i.cb.onFrame(n))},count:()=>t.size}}var FS=0,IS=()=>`st-${Date.now().toString(36)}-${(++FS).toString(36)}`,LS=null;function RS(){return LS??=PS({trySend:e=>W().conn.trySend(e),mintId:IS,now:()=>Date.now(),setTimer:(e,t)=>setTimeout(e,t),clearTimer:e=>clearTimeout(e),report:(e,t)=>console.error(`${_i} stream callback failed: ${e}`,t)})}function zS(e,t,n,r){return RS().open(e,t,n,r)}var BS=`transcripts`,VS=12;async function HS(e){let t={sessionId:e.sessionId,savedAt:Date.now(),doc:e};await Xb(BS,e.sessionId,t),aC()}async function US(e){return(await Yb(BS,e))?.doc??null}async function WS(e){let t=await Yb(BS,e);return t?{value:t.doc,savedAt:t.savedAt}:null}var GS=9e4,KS=new Map,qS=new Map;function JS(e,t=!1){let n=qS.get(e);if(n)return n;let r=YS(e,t).finally(()=>{qS.get(e)===r&&qS.delete(e)});return qS.set(e,r),r}async function YS(e,t){let n=Date.now(),r=KS.get(e)??0;if(!(!t&&n-r<GS*(ig()?4:1))){KS.set(e,n);try{let t=await US(e),n=ov(),r=t&&(t.detail??`full`)===n?t.updatedAt:void 0,i=await U.transcript(e,r,n);i&&await HS(i)}catch{KS.set(e,r)}}}function XS(e){e?KS.delete(e):KS.clear()}async function ZS(e){if(!QS){QS=!0;try{for(let t of e.slice(0,VS))await JS(t).catch(()=>void 0)}finally{QS=!1}}}var QS=!1,$S=`tooldetail`,eC=60,tC=(e,t)=>`${e}:${t}`;async function nC(e,t,n){let r=tC(e,t);await Xb($S,r,{key:r,savedAt:Date.now(),tools:n}),iC()}async function rC(e,t){return(await Yb($S,tC(e,t)))?.tools??null}async function iC(){let e=await Qb($S);if(e.length<=eC)return;let t=[...e].sort((e,t)=>t.savedAt-e.savedAt).slice(eC);for(let e of t)await Zb($S,e.key)}async function aC(){let e=await Qb(BS);if(e.length<=VS)return;let t=[...e].sort((e,t)=>t.savedAt-e.savedAt).slice(VS);for(let e of t)await Zb(BS,e.sessionId)}var oC=`ctxseries`,sC=12;async function cC(e){await Xb(oC,e.sessionId,{sessionId:e.sessionId,savedAt:Date.now(),doc:e}),uC()}async function lC(e){let t=await Yb(oC,e);return t?{value:t.doc,savedAt:t.savedAt}:null}async function uC(){let e=await Qb(oC);if(e.length<=sC)return;let t=[...e].sort((e,t)=>t.savedAt-e.savedAt).slice(sC);for(let e of t)await Zb(oC,e.sessionId)}var dC=`tokenstats`,fC=`all`,pC=3;async function mC(e){await Xb(dC,fC,{v:pC,savedAt:Date.now(),doc:e})}async function hC(){let e=await Yb(dC,fC);return!e||e.v!==pC||!gC(e.doc)?null:{value:e.doc,savedAt:e.savedAt}}function gC(e){return!e||typeof e!=`object`||!e.cost||typeof e.cost.total!=`number`||!e.subagentCost||!e.unpriced||!Array.isArray(e.days)||!Array.isArray(e.models)||!Array.isArray(e.repos)?!1:e.days.every(e=>!!e.cost)&&e.models.every(e=>!!e.cost)&&e.repos.every(e=>!!e.cost)}var _C=e=>/^[a-z][\w.-]*$/.test(e)&&e!==fC?e:null;async function vC(e,t,n){let r=_C(e);r&&await Xb(dC,r,{v:t,savedAt:Date.now(),doc:n})}async function yC(e,t,n){let r=_C(e);if(!r)return null;let i=await Yb(dC,r);return!i||i.v!==t||!n(i.doc)?null:{value:i.doc,savedAt:i.savedAt}}var bC=`gallery`,xC=24;async function SC(e,t,n,r){let i=Mee(e,t);await Xb(bC,i,{key:i,scopeKey:e,savedAt:Date.now(),rows:n,truncated:r,kind:t.kind,since:t.since}),wC()}async function CC(e,t){let n=await Qb(bC),r=da(n.filter(t=>t.scopeKey===e),t);if(!r)return null;let i=r.kind===t.kind&&r.since===t.since;return{rows:r.rows,truncated:r.truncated,savedAt:r.savedAt,exact:i}}async function wC(){let e=await Qb(bC);if(e.length<=xC)return;let t=[...e].sort((e,t)=>t.savedAt-e.savedAt).slice(xC);for(let e of t)await Zb(bC,e.key)}var TC=`tree`,EC=120,DC=(e,t)=>`${e}:${t}`;async function OC(e,t,n){let r=DC(e,t);await Xb(TC,r,{key:r,savedAt:Date.now(),listing:n}),AC()}async function kC(e,t){let n=await Yb(TC,DC(e,t));return n?{listing:n.listing,savedAt:n.savedAt}:null}async function AC(){let e=await Qb(TC);if(e.length<=EC)return;let t=[...e].sort((e,t)=>t.savedAt-e.savedAt).slice(EC);for(let e of t)await Zb(TC,e.key)}var jC=`artifacttext`,MC=40,NC=(e,t,n)=>`${e}:${t}:${Math.round(n)}`;async function PC(e,t,n,r,i){let a=NC(e,t,n);await Xb(jC,a,{key:a,savedAt:Date.now(),text:r,truncated:i}),IC()}async function FC(e,t,n){let r=await Yb(jC,NC(e,t,n));return r?{text:r.text,truncated:r.truncated,savedAt:r.savedAt}:null}async function IC(){let e=await Qb(jC);if(e.length<=MC)return;let t=[...e].sort((e,t)=>t.savedAt-e.savedAt).slice(MC);for(let e of t)await Zb(jC,e.key)}var LC=B.slashCache,RC=20;function zC(){return oo(LC,{})}function BC(e){$a(LC,e)}function VC(e){let t=zC()[e];return t?{value:t.commands,savedAt:t.ts}:null}function HC(e,t){let n=zC();delete n[e],n[e]={ts:Date.now(),commands:t};let r=Object.keys(n);if(r.length>RC)for(let e of r.slice(0,r.length-RC))delete n[e];BC(n)}var UC=B.snapHistory,WC=20;function GC(){return oo(UC,{})}function KC(e){$a(UC,e)}function qC(){return new Map(Object.entries(GC()))}function JC(e,t){let n=GC();delete n[e],n[e]=t.slice(-50).map(({output:e,...t})=>t);let r=Object.keys(n);if(r.length>WC)for(let e of r.slice(0,r.length-WC))delete n[e];KC(n)}async function YC(e){let t=await tx(e);return e===BS&&XS(),t}var XC=()=>[];function ZC(e){XC=e}var QC={peerJobs:()=>U.peerJobs(),tokenStats:{read:e=>U.tokenStats(e),fromCache:hC,toCache:mC},views:()=>XC(),viewDoc:e=>({read:t=>U.backendTokens(e.id,t),fromCache:()=>yC(e.id,e.cache.shape,e.cache.usable),toCache:t=>vC(e.id,e.cache.shape,t)}),backendTokens:(e,t)=>U.backendTokens(e,t),localUsage:()=>U.localUsage(),usageLog:e=>U.usageLog(e),sourceHistory:async(e,t)=>{try{let n=await U.usageLogSource(e,t);return n&&Array.isArray(n.samples)?n:null}catch{return null}},tokenWindows:(e,t)=>U.tokenWindows(e,t),costWindow:(e,t,n)=>U.costWindow(e,t,n),refreshUsage(e){let t=W();e?t.conn.status===`open`&&t.conn.send({t:`usage.refresh`}):t.conn.liveAsk({t:`usage.refresh`},`no connection — usage is scraped on the desktop`)}};function $C(e){return e.rows.length>0?`rows`:e.readAt>0?`empty`:`unread`}var ew=()=>[];function tw(e){ew=e}var nw=e=>ew(e);function rw(e){return/^https?:\/\/[^\s]+$/i.test(e)}function iw(e){return rw(e)?ku()?(location.href=e,!0):!!window.open(e,`_blank`,`noopener,noreferrer`):!1}async function aw(e){try{let t=await U.screenshot(e);return t.file?{file:t.file}:{error:t.error||`the desktop gave no reason`}}catch{return{error:`the desktop could not be reached`}}}function ow(e){let t=wh();return t?.setImmersive?(t.setImmersive(e),!0):!1}var sw=864e5,cw=36e5,lw=[`Sun`,`Mon`,`Tue`,`Wed`,`Thu`,`Fri`,`Sat`];35*sw;var uw=e=>e>=100?`$${Math.round(e)}`:Ii(e);function dw(e,t){return e?Tte(e).find(e=>e.periodId===t&&e.unit===`usd`)?.max??null:null}var fw=e=>e.kind===`calendar`?e.cycle===`month`?0:e.cycle===`week`?2:3:e.kind===`rolling`?1:4;function pw(e,t,n=Date.now()){let r=(e??[]).filter(e=>e.period.unit===`usd`&&e.active&&!(e.resetAt!=null&&n>=e.resetAt));if(!r.length)return null;let i=e=>(dw(t,e.period.id)==null?10:0)+fw(e.period);return r.slice().sort((e,t)=>i(e)-i(t))[0]}function mw(e,t,n){let r=e=>new Intl.DateTimeFormat(`en-US`,{...n,...e?{timeZone:e}:{}}),i;try{i=r(t)}catch{i=r()}let a=Object.fromEntries(i.formatToParts(e).map(e=>[e.type,e.value]));return[[a.day,a.month,a.year].filter(Boolean).join(` `),a.hour&&a.minute?`${a.hour}:${a.minute}`:``].filter(Boolean).join(` `)}var hw=e=>{let t=e%100;return`${e}${t>=11&&t<=13?`th`:{1:`st`,2:`nd`,3:`rd`}[e%10]??`th`}`};function gw(e){let t=e.period;return t.kind===`calendar`?t.cycle===`month`?mw(e.start+216e5,t.tz,(t.anchorDay??1)>1?{day:`numeric`,month:`short`}:{month:`short`}):t.cycle===`week`?`wk`:`today`:t.kind===`rolling`?`30d`:`span`}function _w(e){return e.kind===`calendar`?e.cycle===`month`?`Where the month went`:e.cycle===`week`?`Where this calendar week went`:`Where today went`:e.kind===`rolling`?`Where the last 30 days went`:`Where this span went`}function vw(e){if(e.kind===`calendar`)return e.cycle===`month`?`calendar month from the ${(e.anchorDay??1)===1?`1st`:hw(e.anchorDay??1)} · ${e.tz}`:e.cycle===`week`?`calendar week from ${lw[e.startDow??0]} · ${e.tz}`:`each day · ${e.tz}`;if(e.kind===`rolling`)return`rolling 30 days`;let t=e=>mw(e,void 0,{day:`numeric`,month:`short`,year:`numeric`});return`${t(e.from)} to ${t(e.to-1)}`}function yw(e,t,n){let r=e.spentUsd??null;if(r==null)return{pace:null,perDay:null,projected:null};let i=pte(r,e.start,e.resetAt,n);if(t==null)return{pace:null,perDay:null,projected:i};let a=ta(t,r,e.resetAt,n);if(r>=t)return{pace:`over`,perDay:a,projected:i};let o=Ate(t,e.start,e.resetAt,n);if(o==null||o<t*.01)return{pace:null,perDay:a,projected:i};let s=r/o;return{pace:s>1.1?`ahead`:s<.9?`under`:`on`,perDay:a,projected:i}}var bw={over:`over the cap`,ahead:`ahead of pace`,on:`on pace`,under:`under pace`};function xw(e,t,n){let r=e.spentUsd;if(r==null||!Number.isFinite(r)||e.resetAt!=null&&n>=e.resetAt)return null;let i=yw(e,t,n),a=`${gw(e)} ${uw(r)}${t==null?``:` / ${uw(t)}`}${i.pace?` · ${bw[i.pace]}`:``}`,o=[`${uw(r)} spent${t==null?``:` of a ${uw(t)} cap`} · ${vw(e.period)}`,...e.resetAt==null?[]:[`resets ${mw(e.resetAt,e.period.kind===`calendar`?e.period.tz:void 0,{day:`numeric`,month:`short`,hour:`2-digit`,minute:`2-digit`,hourCycle:`h23`})}`],...i.perDay==null?[]:[`${uw(i.perDay)}/day left`],...i.projected==null?[]:[`projected ${uw(i.projected)} at the reset`],`this desktop, list price`];return{text:a,hot:t!=null&&r>=t*.8,title:o.join(` · `)}}function Sw(e,t,n){let r=yw(e,t,n);return[...r.pace?[bw[r.pace]]:[],...r.perDay!=null&&r.pace!==`over`?[`${uw(r.perDay)}/day left`]:[],...r.projected==null?[]:[`projected ${uw(r.projected)} at the reset`]]}function Cw(e,t){let n=e.resetAt!=null&&e.resetAt<=t,r=e.resetAt==null?t:Math.min(e.resetAt,t),i=e.period.kind===`rolling`?Math.ceil(e.start/cw)*cw:e.start;return r<=i?{refusal:`This period has not begun.`}:i%cw!==0||n&&r%cw!==0?{refusal:`This period starts or ends inside an hour, and the desktop keeps its spend by the hour — no breakdown is drawn rather than one that counts the wrong minutes.`}:r-i>3024e6?{refusal:`This span is longer than 35 days, the most the desktop folds in one read — the figure on the chip is unaffected.`}:{from:i,to:r}}function ww(e,t){let n=new Map,r=e=>{for(let t of e??[]){let e=n.get(t.model)??{model:t.model,label:er(t.model)??(t.model||`unknown model`),usd:0,tokens:0};e.usd+=t.cost?.total??0,e.tokens+=(t.totals?.input??0)+(t.totals?.output??0)+(t.totals?.cacheRead??0)+(t.totals?.cacheWrite??0),n.set(t.model,e)}};for(let t of e)r(t.byModel);for(let e of t??[])r(e.byModel);return[...n.values()].sort((e,t)=>t.usd-e.usd||t.tokens-e.tokens)}var Tw=[{id:`month`,label:`calendar month`},{id:`week`,label:`calendar week`},{id:`day`,label:`day`},{id:`rolling30d`,label:`rolling 30 days`},{id:`span`,label:`from – to`}],Ew=()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone||`UTC`}catch{return`UTC`}},Dw=()=>({kind:`month`,anchorDay:`1`,startDow:1,tz:Ew(),from:``,to:``}),pce=e=>{try{return new Intl.DateTimeFormat(`en`,{timeZone:e}),!0}catch{return!1}};function Ow(e,t=0){let n=/^(\d{4})-(\d{2})-(\d{2})$/.exec(e.trim());if(!n)return null;let[r,i,a]=[Number(n[1]),Number(n[2]),Number(n[3])],o=new Date(r,i-1,a);return o.getFullYear()!==r||o.getMonth()!==i-1||o.getDate()!==a?null:new Date(r,i-1,a+t).getTime()}function mce(e){let t=e.tz.trim();if((e.kind===`month`||e.kind===`week`||e.kind===`day`)&&(!t||!pce(t)))return{ok:!1,reason:`“${t}” is not a time zone — try Europe/Berlin or America/New_York`};if(e.kind===`month`){let n=Number(e.anchorDay.trim().replace(/(st|nd|rd|th)$/i,``));return!Number.isInteger(n)||n<1||n>31?{ok:!1,reason:`the billing day is a whole number from 1 to 31`}:{ok:!0,period:{id:`month`,kind:`calendar`,unit:`usd`,cycle:`month`,anchorDay:n,tz:t}}}if(e.kind===`week`)return{ok:!0,period:{id:`calweek`,kind:`calendar`,unit:`usd`,cycle:`week`,startDow:e.startDow,tz:t}};if(e.kind===`day`)return{ok:!0,period:{id:`day`,kind:`calendar`,unit:`usd`,cycle:`day`,tz:t}};if(e.kind===`rolling30d`)return{ok:!0,period:{id:`rolling30d`,kind:`rolling`,unit:`usd`,lenMs:30*sw,scraped:!1}};let n=Ow(e.from),r=Ow(e.to,1);return n==null||r==null?{ok:!1,reason:`type both days as YYYY-MM-DD`}:r<=n?{ok:!1,reason:`the last day has to be on or after the first`}:n%cw!==0||r%cw!==0?{ok:!1,reason:`this phone's midnight is not on a whole UTC hour, and the desktop keeps spend by the hour — a span here would count the wrong minutes`}:{ok:!0,period:{id:`span-${e.from.trim()}`,kind:`span`,unit:`usd`,from:n,to:r}}}function kw(e){let t=e.claudeSessionId?.trim();return t?[`Explain what made one Claude Code session expensive, and outline how it could have been cheaper. Do NOT implement anything — no edits, no commits, no settings changes. This is an analysis; at the end, list the ideas and ask me which (if any) to implement.`,``,`The session: "${e.title}"`,`- working directory: ${e.cwd}`,`- conversation id: ${t}${e.model?`\n- model: ${e.model}`:``}`,`- transcript: find it with \`ls ~/.claude/projects/*/${t}.jsonl\` — its subagents' logs are under ${t}/subagents/ beside it, if that exists.`,``,`The transcript may be very large. Measure it with a script (node or jq over the JSONL "usage" fields), never by reading it whole into this conversation.`,``,`Find out:`,`1. The totals split by token kind (input, cache write, cache read, output) and by main conversation vs subagents, with a list-price estimate for the model(s) used.`,`2. How the context grew turn by turn: the turns where it jumped and what caused each jump (large tool results, file dumps, images, long outputs, pasted content, skill or CLAUDE.md loads).`,`3. Cache behaviour: cache writes after gaps long enough for the cache to expire, compactions, and what they cost.`,`4. The subagents: how many, what each was for, what each cost, and whether any duplicated work.`,`5. The always-on baseline: the size of the first turn's context (system prompt, CLAUDE.md, skill descriptions, tools, MCP servers) and how much of the total it accounts for across all turns.`,`6. Whether the work should have been split into separate sessions, and where.`,``,`Then give concrete, actionable ideas ranked by estimated saving, each naming what to change (a CLAUDE.md or skill trim, a habit, a subagent instead of inline reading, an earlier /compact or fresh session, a setting) and roughly how much it would have saved on this session. Keep the answer short and lead with the three biggest causes.`].join(`
|
|
4
4
|
`):null}var hce=hne(),gce=6048e5,_ce=36e5;function Aw(e,t){return!e||e.weeklyPct==null||e.weeklyResetAt==null||e.weeklyPct<5||e.weeklyResetAt<=t||e.checkedAt-(e.weeklyResetAt-6048e5)<_ce?null:`${e.weeklyResetAt}:${e.checkedAt}:${e.weeklyPct}`}function vce(e,t,n){if(Ya(e?.profile))return{kind:`windows`};let r=pw(t?.periods,t?.budget,n),i=r?xw(r,dw(t?.budget,r.period.id),n):null;return i?{kind:`usd`,chip:i}:{kind:`door`}}function yce(e,t){if(e)return[...e];let r=n(t);return r?[r]:[]}function bce(e,t){let n=t?e.filter(e=>e.backend===t):[];return n.length?n:e.filter(e=>e.backend==null)}function xce(e,t){let n=new Set(t.filter(e=>e.running).map(e=>e.backend??`claude`));return e.filter(e=>e.source===`claude`||e.backend==null||e.backend===`claude`||n.has(e.backend))}function Sce(e){let t=t=>e.windows.find(e=>e.id===t),n=t(`session`),r=t(`week`);return{sess:n?Ei(n):null,sessResetAt:n?.resetAt??null,wk:r?Ei(r):null}}var jw=e=>({sess:e?.sessionPct??null,sessResetAt:e?.sessionResetAt??null,wk:e?.weeklyPct??null,...e?.sessionGoneSince==null?{}:{noSess:!0}}),Cce=(e,t)=>t?.ok?jw(t):Sce(e),wce=e=>(e.sess??0)>=80||(e.wk??0)>=80,Tce=e=>e===`claude`?null:e;function Ece(e,t){return!!t&&e.length>0&&!e.some(e=>e.source===`claude`)}var Dce=e=>e?.length?`\n+ ${e.join(`, `)} not shown here`:``,Mw=G(null);function Oce(){return K(Mw)}var Nw=G(null),Pw=36e5;function kce(){let e=K(Mw),t=K(Nw);return!t||!e||Aw(e,Date.now())==null?null:Math.abs(t.resetAt-e.weeklyResetAt)<Pw?t.usdPerPct:null}function Ace(){let e=K(Mw),t=K(Nw);return!t?.incl||!e||Aw(e,Date.now())==null?null:Math.abs(t.resetAt-e.weeklyResetAt)<Pw?t.incl:null}var Fw=G(null),Iw=G([]),jce=()=>K(Iw),Lw=G(null),Mce=()=>Iw.get(),Nce=()=>Lw.get();function Pce(e){Lw.set(e),W().nav.open(`tokens`)}var Fce=()=>Lw.set(null),Rw=()=>K(Fw);function Ice(){let e=K(Fw),t=_h().world.budget;return vce(e,t,Date.now())}var zw=null;function Lce(e){let t=Aw(e,Date.now());if(!e||!t||t===zw||Nw.get()?.key===t)return;zw=t;let n=e.weeklyResetAt-gce;Promise.all([QC.tokenWindows([{id:`weekcal`,anchor:e.checkedAt,lenMs:e.checkedAt-n}]),QC.peerJobs().catch(()=>null)]).then(([r,i])=>{let a=r.series.find(e=>e.id===`weekcal`)?.windows.find(e=>e.back===0),o=T(i,n,e.checkedAt),s=a?.cost.total,c=kn(s!=null&&s>0?s+(o?.usd??0):s,e.weeklyPct);c!=null&&Aw(Mw.get(),Date.now())===t&&Nw.set({key:t,resetAt:e.weeklyResetAt,usdPerPct:c,...o?{incl:o.text}:{}})}).catch(()=>void 0).finally(()=>{zw===t&&(zw=null)})}var J=gne();function Bw({options:e,value:t,onChange:n,label:r,className:i}){let a=(0,H.useRef)([]),o=e.findIndex(e=>e.key===t),s=(t,r)=>{let i=t.key===`ArrowDown`||t.key===`ArrowRight`?1:t.key===`ArrowUp`||t.key===`ArrowLeft`?-1:0;if(!i||e.length===0)return;t.preventDefault();let o=(r+i+e.length)%e.length;a.current[o]?.focus(),n(e[o].key)};return(0,J.jsx)(`div`,{role:`radiogroup`,"aria-label":r,className:i?`radio-rows ${i}`:`radio-rows`,children:e.map((e,t)=>{let r=t===o;return(0,J.jsxs)(`button`,{ref:e=>{a.current[t]=e},type:`button`,role:`radio`,"aria-checked":r,tabIndex:r||o<0&&t===0?0:-1,className:r?`radio-row on`:`radio-row`,title:e.title,onClick:()=>{r||n(e.key)},onKeyDown:e=>s(e,t),children:[(0,J.jsx)(`span`,{className:`radio-dot`,"aria-hidden":!0}),(0,J.jsxs)(`span`,{className:`radio-label`,children:[e.label,e.note!=null&&(0,J.jsx)(`span`,{className:`radio-note`,children:e.note})]})]},e.key)})})}var Rce=[{id:`sessions`,title:`Sessions`},{id:`notifications`,title:`Notifications`},{id:`appearance`,title:`Appearance`},{id:`writing`,title:`Writing & reading`},{id:`offline`,title:`Offline & data`},{id:`connection`,title:`Connection`},{id:`tools`,title:`Tools & diagnostics`}],Vw=[{id:`launch-backend`,group:`sessions`,label:`backend`,keywords:`binary claude engine which runs cli plugin`},{id:`launch-model`,group:`sessions`,label:`model`,keywords:`opus sonnet haiku alias version local hosted default`},{id:`launch-effort`,group:`sessions`,label:`effort`,keywords:`reasoning thinking depth high low`},{id:`launch-permission`,group:`sessions`,label:`permission mode`,keywords:`approvals dangerous skip ask tool calls yolo bypass`},{id:`launch-remote`,group:`sessions`,label:`remote control`,keywords:`claude.ai steer remote-control`},{id:`launch-ask`,group:`sessions`,label:`ask before each launch`,keywords:`prompt every time silently defaults pick`},{id:`spend-warn`,group:`sessions`,label:`spend marks`,keywords:`cost warning orange red triangle threshold dollars percent week alert expensive api`},{id:`confirm-close`,group:`sessions`,label:`ask before closing a session`,keywords:`close confirm uncommitted unmerged warning don't ask again dialog`},{id:`close-when-done`,group:`sessions`,label:`close automatic sessions when done`,keywords:`backlog scheduled linger keep open reap slot auto-close`},{id:`local-sessions`,group:`sessions`,label:`local model sessions at once`,keywords:`ollama qwen gpu runner local model limit cap one at a time concurrent`},{id:`hosted-notice`,group:`sessions`,label:`hosted-model notice`,keywords:`privacy disclaimer acknowledge server third party leaves machine`},{id:`limit-auto`,group:`sessions`,label:`auto-continue after a usage limit`,keywords:`rate limit resume reset blocked wall resurrect`},{id:`net-retry`,group:`sessions`,label:`retry on network errors`,keywords:`network wifi offline dns outage api error continue retry automatic connection lost`},{id:`budget`,group:`sessions`,label:`usage budget`,keywords:`reserve headroom pause unattended percent ceiling session window`},{id:`budget-session`,group:`sessions`,label:`session ceiling`,keywords:`5-hour window percent reserve pause headroom`},{id:`automation`,group:`sessions`,label:`automation`,keywords:`schedule schedules clock cron runs on its own backlog auto peer`},{id:`weekburn`,group:`sessions`,label:`week-end burn`,keywords:`this week's burn spend leftover unused budget subscription repos improve`},{id:`budget-weekly`,group:`sessions`,label:`weekly ceiling`,keywords:`week cap percent reserve`},{id:`budget-leftover`,group:`sessions`,label:`leftovers in a new week`,keywords:`leftover reset week spare budget before reset waiver`},{id:`billing-profile`,group:`sessions`,label:`billing profile`,keywords:`api key subscription bedrock vertex cloud account detect override console`},{id:`billing-periods`,group:`sessions`,label:`dollar periods and caps`,keywords:`month monthly week day spend cap budget dollars billing cycle anchor rolling span time zone limit`},{id:`ask-rules`,group:`sessions`,label:`ask before`,keywords:`ask rules permission confirm git push force main master deploy publish dangerous irreversible guard tap prod release`},{id:`auto-compact-default`,group:`sessions`,label:`auto-compact window`,keywords:`autoCompactWindow compact context 400k repo setup settings.json threshold`},{id:`notif-feed`,group:`notifications`,label:`open the feed`,keywords:`alerts unread inbox in-app list bell notification`},{id:`notif-info-push`,group:`notifications`,label:`push information too`,keywords:`receipts buzz quiet information pushes push`},{id:`notif-kinds`,group:`notifications`,label:`what may fire`,keywords:`mute kinds needs you limit cli backlog prompt not delivered per type`},{id:`phone-setup`,group:`notifications`,label:`phone setup`,keywords:`permission allow android background notifications install unknown apps checklist`},{id:`notif-push`,group:`notifications`,label:`OS push`,keywords:`web push system notification https secure context service worker`},{id:`notif-shell-link`,group:`notifications`,label:`background link`,keywords:`android apk foreground service app closed freezer wake`},{id:`notif-shell-battery`,group:`notifications`,label:`allow background use`,keywords:`battery doze exemption reboot android optimisation optimization`},{id:`theme`,group:`appearance`,label:`theme`,keywords:`dark light mode night follow device colour color scheme`},{id:`text-size`,group:`appearance`,label:`text size`,keywords:`font bigger smaller larger zoom readable accessibility scale`},{id:`icon-size`,group:`appearance`,label:`icon size`,keywords:`glyph bigger smaller tap target thumb scale`},{id:`terminal-zoom`,group:`appearance`,label:`terminal size`,keywords:`console font columns rows grid pty wrap diff cli zoom`},{id:`repo-colours`,group:`appearance`,label:`repo colours`,keywords:`color hue ring pin per repo tab stripe colour blind cvd`},{id:`tabs`,group:`appearance`,label:`session tabs`,keywords:`strip open sessions switch between bar top`},{id:`tabs-count`,group:`appearance`,label:`tabs that fit`,keywords:`how many width narrower wider strip`},{id:`tabs-limit`,group:`appearance`,label:`most tabs shown`,keywords:`limit cap max maximum how many strip hide`},{id:`tabs-order`,group:`appearance`,label:`tab order`,keywords:`sort opened frequent recent where was i`},{id:`tabs-sync`,group:`appearance`,label:`same tab order on every device`,keywords:`sync share phone desktop devices order opened recent across`},{id:`repo-order`,group:`appearance`,label:`repo order`,keywords:`launcher sort alphabetical sessions open busiest list repos rank`},{id:`unfold-to-end`,group:`appearance`,label:`unfolding a repo shows its last row`,keywords:`launcher expand collapse fold scroll bottom end list sessions chevron`},{id:`net-pulse`,group:`appearance`,label:`connection strip`,keywords:`ping latency graph round trip bar link live network`},{id:`local-rt`,group:`appearance`,label:`desktop strip`,keywords:`local runner ollama lm studio model loaded memory pressure cpu gpu utilization machine mac bar`},{id:`agent-warn`,group:`appearance`,label:`warn above this many agents`,keywords:`parallel subagents running at once count concurrent amber notice threshold`},{id:`agent-alarm`,group:`appearance`,label:`alarm above this many agents`,keywords:`parallel subagents running at once count concurrent red limit threshold too many`},{id:`ui-reset`,group:`appearance`,label:`reset UI settings to default`,keywords:`restore defaults factory look layout hidden buttons theme size zoom tabs strips`},{id:`enter-sends`,group:`writing`,label:`what Return does`,keywords:`enter key send newline keyboard compose submit`},{id:`dictate-lang`,group:`writing`,label:`dictation is read as`,keywords:`voice speech microphone mic whisper language german english translate transcribe auto detect`},{id:`dictate-langs`,group:`writing`,label:`languages on the microphone`,keywords:`voice speech dictation picker list offer languages mic which`},{id:`dictate-terms`,group:`writing`,label:`words dictation should know`,keywords:`voice speech vocabulary glossary dictionary custom terms names jargon misheard recognise spelling whisper prompt`},{id:`close-kb-on-send`,group:`writing`,label:`keyboard after Send`,keywords:`keyboard close hide dismiss blur send focus`},{id:`shortcut-card`,group:`writing`,label:`hold Ctrl to see shortcuts`,keywords:`keyboard shortcut shortcuts chord hotkey cheat sheet ctrl cmd command alt option modifier hold card`},{id:`busy-send`,group:`writing`,label:`Send while it works`,keywords:`send busy working turn running queue when free ask now wait`},{id:`btw-to-cli`,group:`writing`,label:`/btw from the reader`,keywords:`btw aside overlay cli terminal switch ask reader`},{id:`typing-room`,group:`writing`,label:`typing room`,keywords:`hide chrome header keyboard space terminal rows full`},{id:`reader-tools`,group:`writing`,label:`tool calls in the reader`,keywords:`transcript fold list full download details offline`},{id:`hints-mode`,group:`writing`,label:`button hints`,keywords:`explain long press help tooltip first time`},{id:`hints-explain`,group:`writing`,label:`explain mode`,keywords:`help what does this button do tap`},{id:`hints-chip`,group:`writing`,label:`? button in the headers`,keywords:`help question mark explain chip hide remove space header launcher`},{id:`hints-reset`,group:`writing`,label:`explain them again`,keywords:`reset dismissed hints help`},{id:`install`,group:`offline`,label:`install this app`,keywords:`pwa home screen add standalone chrome ios safari`},{id:`auto-send`,group:`offline`,label:`auto-send the queue`,keywords:`offline queued messages reconnect deliver hold send now`},{id:`serial-sessions`,group:`offline`,label:`one session at a time per repo`,keywords:`queue parallel serialize worktree agents limit`},{id:`confirm-queue`,group:`offline`,label:`ask on reconnect`,keywords:`queue review before sending offline drafts stale`},{id:`queue-manage`,group:`offline`,label:`manage the queue`,keywords:`queued messages waiting outbox`},{id:`bg-fresh`,group:`offline`,label:`in the background`,keywords:`battery drain power hidden background stream offline dead zone fresh latest screen catch up`},{id:`data-saver`,group:`offline`,label:`data saver`,keywords:`roaming hotel bandwidth smaller images polling mobile`},{id:`downloads`,group:`offline`,label:`downloads`,keywords:`pull files artifacts background fetch resume auto copy once duplicate space keep`},{id:`upload-scale`,group:`offline`,label:`upload size`,keywords:`image width shrink annotator camera photo auto slow link`},{id:`hosts`,group:`connection`,label:`hosts`,keywords:`desktop address daemon apk android pair change ip switch add remove lan wifi peer desktops tailnet tailscale computer machine`},{id:`code-folder`,group:`connection`,label:`Code folder`,keywords:`root repos folder scan dev projects directory path where desktop host workspace env variable`},{id:`add-desktop`,group:`connection`,label:`add a desktop`,keywords:`new desktop host computer machine pc mac linux windows tailnet tailscale found discover scan add pair peer`},{id:`web-desktops`,group:`connection`,label:`another desktop, without the app`,keywords:`browser web pwa no app without apk iphone ios pair second desktop another phone home screen address tailnet code`},{id:`demo`,group:`connection`,label:`try the demo`,keywords:`demo sample example pretend fake tour first look leave play store reviewer`},{id:`pair-phone`,group:`connection`,label:`pair another phone`,keywords:`qr code pairing new phone add device scan invite tailscale`},{id:`paired-devices`,group:`connection`,label:`paired devices`,keywords:`revoke sign in token phones ledger last seen remove device`},{id:`app-version`,group:`connection`,label:`app version`,keywords:`apk update build install shell android`},{id:`endpoints`,group:`connection`,label:`how you reach this host`,keywords:`url address lan tailscale https tunnel origin reopen connection`},{id:`lan-password`,group:`connection`,label:`LAN password`,keywords:`auth gate local network secure token login public`},{id:`lan-gate-tailscale`,group:`connection`,label:`gate Tailscale too`,keywords:`password auth peers trusted`},{id:`lan-logout`,group:`connection`,label:`log out this device`,keywords:`auth token sign out lan`},{id:`sync-push`,group:`connection`,label:`push this device's settings`,keywords:`sync host copy conflict templates presets pad toolbar wins`},{id:`token-stats`,group:`tools`,label:`token statistics`,keywords:`usage cost spend money per day model repo cache history tokens`},{id:`tool-secret`,group:`tools`,label:`secret`,keywords:`api key write only env credential`},{id:`desktop-setup`,group:`tools`,label:`desktop setup`,keywords:`checklist mac screen recording accessibility permission grant live desktop helper privacy security system settings`},{id:`tool-repo-setup`,group:`tools`,label:`repo setup`,keywords:`checklist gitignore claude.md context weight check fix`},{id:`tool-speedtest`,group:`tools`,label:`speed test`,keywords:`bandwidth latency diagnostics connection throughput`},{id:`tool-net-health`,group:`tools`,label:`connection health`,keywords:`link prompts delivery retries lost dropped`},{id:`tool-storage`,group:`tools`,label:`storage`,keywords:`space full disk bytes cache clear downloads thumbnails quota evicted free up`},{id:`tool-cli-health`,group:`tools`,label:`CLI health`,keywords:`heuristics detector hook echo probe conversation log broken degraded`},{id:`tool-features`,group:`tools`,label:`feature usage`,keywords:`which features used never analytics track`},{id:`tool-host-stat`,group:`tools`,label:`host stat`,keywords:`cpu memory load desktop mac pressure temperature`},{id:`tool-screenshot`,group:`tools`,label:`screenshot the desktop`,keywords:`capture screen mac image`},{id:`whats-new`,group:`tools`,label:`what's new`,keywords:`release version changelog new features overview 0.1.8 automation burn downloads notifications`},{id:`tool-updates`,group:`tools`,label:`updates`,keywords:`update self plugin install available new version restart roll back`},{id:`tool-decisions`,group:`tools`,label:`decision log`,keywords:`activity auto-continue usage limit what a plugin answered suggested history archive`},{id:`updates-auto`,group:`tools`,label:`check daily for updates`,keywords:`update plugin automatic check github new version`},{id:`plugins`,group:`tools`,label:`plugins`,keywords:`plugin extension add-on installed oracle gemini enable disable`}],Hw=new Map(Vw.map(e=>[e.id,e])),zce=new Map(Rce.map(e=>[e.id,e]));function Uw(e){let t=zce.get(e.group);return[e.label,e.keywords,t?.title,e.id.replace(/-/g,` `)].filter(Boolean).join(` `).toLowerCase()}var Ww=new Map(Vw.map(e=>[e.id,Uw(e)])),Gw=[];function Bce(e){for(let t of e)Hw.has(t.id)||(Gw.push(t),Hw.set(t.id,t),Ww.set(t.id,Uw(t)))}var Kw=new Map;function Vce(e,t){Kw.set(e,t.toLowerCase())}function qw(e,t){let n=t.trim().toLowerCase();if(!n)return!0;let r=Ww.get(e);return r==null||Jw(Kw.has(e)?`${r} ${Kw.get(e)}`:r,n)}function Jw(e,t){let n=t.trim().toLowerCase();if(!n)return!0;let r=e.toLowerCase();return n.split(/\s+/).every(e=>r.includes(e))}function Hce(e,t,n){if(!n.trim())return!0;let r=Ww.get(e);return r!=null&&Jw(r,n)?!0:Jw(t,n)}function Uce(e,t){return!t.trim()||[...Vw,...Gw].some(n=>n.group===e&&qw(n.id,t))}function Wce(e,t,n){return n?e===n:qw(e,t)}function Gce(e,t,n){return n?Hw.get(n)?.group===e:Uce(e,t)}function Kce(e){return Hw.get(e)}function qce(e,t,n,r){if(r){let n=Hw.get(r)?.label??r;return e===0?`“${n}” is not on this screen right now — ${t} settings here`:`showing “${n}” only — ${e} of ${t} settings`}let i=n.trim();return i?e===0?`nothing matches “${i}” — ${t} settings on this screen`:`${e} of ${t} settings match “${i}”`:``}function Jce(e,t){return`key`+(e===void 0?``:` ${e}`)+(t!==void 0&&t!==``?` ${t}`:``)}var Y=(0,H.forwardRef)(function({variant:e,className:t,...n},r){return(0,J.jsx)(`button`,{className:Jce(e,t),...n,ref:r})});function Yce(e,t){return`form-hint`+(e?` ${e}`:``)+(t?` ${t}`:``)}function Xce(e,t){return`tag`+(e?` ${e}`:``)+(t?` ${t}`:``)}function Zce(e){return`set-note`+(e?` ${e}`:``)}var Yw=16,Xw=(0,H.createContext)(null);function Qce(e,t=null){return{query:e,only:t,seen:[],shown:[]}}function $ce({value:e,children:t}){return(0,J.jsx)(Xw.Provider,{value:e,children:t})}function Zw(e){let t=(0,H.useContext)(Xw);if(!t||!e)return!0;t.seen.push(e);let n=Wce(e,t.query,t.only);return n&&t.shown.push(e),n}function ele(e,t){let n=(0,H.useContext)(Xw);return!n||n.only?!0:Hce(e,t,n.query)}function X(e){let{children:t,more:n}=e;if(!t&&!n)return null;if(!n){let{as:n,className:r,children:i,more:a,...o}=e;return(0,H.createElement)(n??`div`,{className:Zce(r),...o},t)}return(0,J.jsxs)(`details`,{className:`set-note set-more`,children:[(0,J.jsx)(`summary`,{children:t}),(0,J.jsx)(`div`,{className:`set-more-body`,children:n})]})}function Qw(e){return(0,H.createElement)(`div`,{className:`set-row`,...e})}function $w({tone:e=`bad`,icon:t,children:n}){return(0,J.jsxs)(`div`,{className:`set-note${e===`bad`?` oracle-warn`:``}`,children:[t&&(0,J.jsx)(t,{size:13,style:{verticalAlign:`-2px`,marginRight:4}}),n]})}function tle({id:e,title:t,icon:n,children:r}){let i=(0,H.useContext)(Xw),a=!!i&&!Gce(e,i.query,i.only);return(0,J.jsxs)(`section`,{className:`set-group${a?` gone`:``}`,"data-group":e,children:[(0,J.jsxs)(`h3`,{className:`set-title`,children:[n&&(0,J.jsx)(n,{size:14,style:{verticalAlign:`-2px`,marginRight:5}}),t]}),r]})}function eT({id:e,label:t,icon:n,on:r,onChange:i,state:a,tone:o,note:s,more:c,children:l}){return Zw(e)?(0,J.jsxs)(`div`,{className:`set-item`,children:[(0,J.jsxs)(`button`,{className:`set-sw${r?` on`:``}${o===`danger`?` danger`:``}`,"aria-pressed":r,onClick:i,children:[n&&(0,J.jsx)(n,{size:Yw,className:`set-ico`}),(0,J.jsx)(`span`,{className:`set-lbl`,children:t}),(0,J.jsx)(`span`,{className:`set-state`,children:a??(r?`on`:`off`)})]}),(0,J.jsx)(X,{more:c,children:s}),l]}):null}function tT({id:e,label:t,icon:n,value:r,options:i,onChange:a,note:o,more:s,radio:c,children:l}){return Zw(e)?(0,J.jsxs)(`div`,{className:`set-item`,children:[(0,J.jsxs)(`div`,{className:`set-lead`,children:[n&&(0,J.jsx)(n,{size:Yw,className:`set-ico`}),(0,J.jsx)(`span`,{className:`set-lbl`,children:t})]}),c?(0,J.jsx)(Bw,{label:typeof t==`string`?t:void 0,value:String(r),options:i.map(e=>({key:String(e.value),label:e.label,title:e.title})),onChange:e=>{let t=i.find(t=>String(t.value)===e);t&&a(t.value)}}):(0,J.jsx)(`div`,{className:`set-chips`,children:i.map(e=>(0,J.jsxs)(Y,{className:r===e.value?`active`:``,style:e.style,title:e.title,onClick:()=>a(e.value),children:[e.icon&&(0,J.jsx)(e.icon,{size:Yw}),` `,e.label]},String(e.value)))}),(0,J.jsx)(X,{more:s,children:o}),l]}):null}function nle({id:e,label:t,icon:n,value:r,options:i,onChange:a,note:o,more:s,children:c}){if(!Zw(e))return null;let l=new Set(r);return(0,J.jsxs)(`div`,{className:`set-item`,children:[(0,J.jsxs)(`div`,{className:`set-lead`,children:[n&&(0,J.jsx)(n,{size:Yw,className:`set-ico`}),(0,J.jsx)(`span`,{className:`set-lbl`,children:t})]}),(0,J.jsx)(`div`,{className:`set-chips`,children:i.map(e=>(0,J.jsxs)(Y,{className:l.has(e.value)?`active`:``,"aria-pressed":l.has(e.value),title:e.title,onClick:()=>a(i.map(e=>e.value).filter(t=>t===e.value?!l.has(t):l.has(t))),children:[e.icon&&(0,J.jsx)(e.icon,{size:Yw}),` `,e.label]},String(e.value)))}),(0,J.jsx)(X,{more:s,children:o}),c]})}function nT({id:e,label:t,icon:n,control:r,note:i,more:a,children:o}){return Zw(e)?(0,J.jsxs)(`div`,{className:`set-item`,children:[(0,J.jsxs)(`div`,{className:`set-lead`,children:[n&&(0,J.jsx)(n,{size:Yw,className:`set-ico`}),(0,J.jsx)(`span`,{className:`set-lbl`,children:t}),(0,J.jsx)(`span`,{className:`set-pick`,children:r})]}),(0,J.jsx)(X,{more:a,children:i}),o]}):null}function rle({id:e,label:t,icon:n,readout:r,onLess:i,onMore:a,lessLabel:o=`smaller`,moreLabel:s=`bigger`,extra:c,note:l,more:u,children:d}){return Zw(e)?(0,J.jsxs)(`div`,{className:`set-item`,children:[(0,J.jsxs)(`div`,{className:`set-lead`,children:[n&&(0,J.jsx)(n,{size:Yw,className:`set-ico`}),(0,J.jsx)(`span`,{className:`set-lbl`,children:t})]}),(0,J.jsxs)(`div`,{className:`set-chips`,children:[i&&(0,J.jsxs)(Y,{onClick:i,children:[(0,J.jsx)(hs,{size:Yw}),` `,o]}),(0,J.jsx)(`span`,{className:`set-readout`,"aria-live":`polite`,children:r}),a&&(0,J.jsxs)(Y,{onClick:a,children:[(0,J.jsx)(os,{size:Yw}),` `,s]}),c]}),(0,J.jsx)(X,{more:u,children:l}),d]}):null}function rT({id:e,label:t,icon:n,value:r,min:i,max:a,step:o,readout:s,onInput:c,onCommit:l,note:u,more:d,children:f}){return Zw(e)?(0,J.jsxs)(`div`,{className:`set-item`,children:[(0,J.jsxs)(`div`,{className:`set-lead`,children:[n&&(0,J.jsx)(n,{size:Yw,className:`set-ico`}),(0,J.jsx)(`span`,{className:`set-lbl`,children:t}),(0,J.jsx)(`span`,{className:`set-state`,children:s})]}),(0,J.jsx)(`input`,{type:`range`,className:`set-range`,min:i,max:a,step:o,value:r,onChange:e=>c(Number(e.target.value)),onPointerUp:l,onKeyUp:l}),(0,J.jsx)(X,{more:d,children:u}),f]}):null}function iT({id:e,label:t,icon:n,onClick:r,opens:i,cant:a,busy:o,tone:s,compact:c,title:l,note:u,more:d,children:f}){return Zw(e)?c?(0,J.jsxs)(`button`,{className:`set-door${s?` ${s}`:``}`,title:l,onClick:r,children:[n&&(0,J.jsx)(n,{size:Yw}),` `,t]}):(0,J.jsxs)(`div`,{className:`set-item`,children:[a?(0,J.jsxs)(`div`,{className:`set-lead set-cant`,children:[n&&(0,J.jsx)(n,{size:Yw,className:`set-ico`}),(0,J.jsx)(`span`,{className:`set-lbl`,children:t}),(0,J.jsx)(`span`,{className:`set-cant-why`,children:a})]}):(0,J.jsxs)(`button`,{className:`set-act${s?` ${s}`:``}${o?` busy`:``}`,title:l,onClick:()=>{o||r()},"aria-busy":o||void 0,children:[o?(0,J.jsx)(Ml,{size:Yw,className:`set-ico spin`}):n&&(0,J.jsx)(n,{size:Yw,className:`set-ico`}),(0,J.jsx)(`span`,{className:`set-lbl`,children:t}),i&&!o&&(0,J.jsx)(jl,{size:Yw,className:`set-go`})]}),(0,J.jsx)(X,{more:d,children:u}),f]}):null}function aT({id:e,label:t,icon:n,children:r,note:i,more:a}){return Zw(e)?(0,J.jsxs)(`div`,{className:`set-item`,children:[t!=null&&t!==``&&(0,J.jsxs)(`div`,{className:`set-lead`,children:[n&&(0,J.jsx)(n,{size:Yw,className:`set-ico`}),(0,J.jsx)(`span`,{className:`set-lbl`,children:t})]}),r,(0,J.jsx)(X,{more:a,children:i})]}):null}function ile({value:e,onChange:t}){return(0,J.jsxs)(`div`,{className:`set-search`,children:[(0,J.jsx)(Lc,{size:Yw,className:`set-search-ico`}),(0,J.jsx)(`input`,{type:`search`,placeholder:`search settings`,value:e,onChange:e=>t(e.target.value),autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`none`,spellCheck:!1}),e!==``&&(0,J.jsx)(`button`,{className:`set-search-x`,"aria-label":`clear the search`,onClick:()=>t(``),children:(0,J.jsx)(V,{size:Yw})})]})}function ale({tally:e,onClear:t}){return!e.only&&!e.query.trim()?null:(0,J.jsxs)(`div`,{className:`filter-bar set-filter-bar`,children:[(0,J.jsx)(`span`,{className:`filter-bar-txt`,children:qce(e.shown.length,e.seen.length,e.query,e.only)}),(0,J.jsxs)(`button`,{className:`filter-bar-clear`,onClick:t,children:[(0,J.jsx)(V,{size:13}),` clear`]})]})}var ole=6e3,oT=null,sT,cT=new Set;function lT(e){oT=e,sT&&clearTimeout(sT),sT=void 0,e&&(sT=setTimeout(()=>{oT=null,sT=void 0;for(let e of cT)e()},ole));for(let e of cT)e()}function uT({children:e,confirm:t=`sure?`,className:n=`key`,title:r,confirmTitle:i,disabled:a,onConfirm:o,...s}){let c=(0,H.useId)(),[,l]=(0,H.useState)(0);(0,H.useEffect)(()=>{let e=()=>l(e=>e+1);return cT.add(e),()=>{cT.delete(e),oT===c&&lT(null)}},[c]);let u=oT===c,d=u?`${n} danger`:n,f={title:u?i??r:r,"aria-label":s[`aria-label`],disabled:a,onClick:()=>{u?(lT(null),o()):lT(c)}},p=/^key(?:\s+|$)(.*)$/.exec(d);return p?(0,J.jsx)(Y,{className:p[1]||void 0,...f,children:u?t:e}):(0,J.jsx)(`button`,{className:d,...f,children:u?t:e})}var dT=null,fT=new Set;function pT(){for(let e of fT)e(dT)}function mT(e){return dT?.resolve(!1,!1,!0),new Promise(t=>{dT={title:e.title,lines:e.lines??[],confirmLabel:e.confirmLabel??`Yes`,cancelLabel:e.cancelLabel??`Cancel`,tone:e.tone??`warn`,resolve:t},pT()})}function sle(e){return dT?.resolve(!1,!1,!0),new Promise(t=>{dT={title:e.title,lines:e.lines??[],confirmLabel:e.confirmLabel??`Yes`,cancelLabel:e.cancelLabel??`Cancel`,tone:e.tone??`info`,rememberLabel:e.rememberLabel??`don't ask again`,resolve:(e,n)=>t({ok:e,remember:n})},pT()})}function cle(e){return dT?.resolve(!1,!1,!0),new Promise(t=>{dT={title:e.title,lines:e.lines??[],confirmLabel:e.confirmLabel,cancelLabel:e.cancelLabel,tone:e.tone??`info`,rememberLabel:e.rememberLabel,altLabel:e.altLabel,resolve:(e,n,r,i)=>t(r?null:{ok:e,remember:n,...i?{alt:!0}:{}})},pT()})}function lle(){let[e,t]=(0,H.useState)(null),[n,r]=(0,H.useState)(!1);(0,H.useEffect)(()=>(fT.add(t),t(dT),()=>{fT.delete(t)}),[]),(0,H.useEffect)(()=>{r(!1)},[e]);let i=(0,H.useCallback)((e,t,n=!1,r=!1)=>{let i=dT;dT=null,pT(),i?.resolve(e,t,n,r)},[]);return e?(0,J.jsx)(`div`,{className:`bl-modal-backdrop confirm-backdrop`,onClick:()=>i(!1,!1,!0),children:(0,J.jsxs)(`div`,{className:`bl-modal confirm-modal`,onClick:e=>e.stopPropagation(),children:[(0,J.jsxs)(`div`,{className:`bl-modal-title`,children:[e.tone===`info`?(0,J.jsx)(cs,{size:15,style:{verticalAlign:`-2px`,marginRight:6}}):(0,J.jsx)(Js,{size:15,style:{verticalAlign:`-2px`,marginRight:6,color:`var(--dead)`}}),e.title]}),e.lines.length>0&&(0,J.jsx)(`ul`,{className:`confirm-lines`,children:e.lines.map((e,t)=>(0,J.jsx)(`li`,{children:e},t))}),e.rememberLabel&&(0,J.jsxs)(`label`,{className:`confirm-remember`,children:[(0,J.jsx)(`input`,{type:`checkbox`,checked:n,onChange:e=>r(e.target.checked)}),e.rememberLabel]}),(0,J.jsxs)(`div`,{className:`bl-modal-actions`,children:[(0,J.jsx)(`button`,{className:`send confirm-go${e.tone===`info`?` info`:``}`,onClick:()=>i(!0,n),children:e.confirmLabel}),(0,J.jsx)(Y,{onClick:()=>i(!1,n),children:e.cancelLabel}),e.altLabel&&(0,J.jsx)(Y,{onClick:()=>i(!1,n,!1,!0),children:e.altLabel})]})]})}):null}var hT=`claude`,gT=[`low`,`medium`,`high`,`xhigh`,`max`],_T=[`default`,`plan`,`acceptEdits`,`auto`,`dontAsk`,`bypassPermissions`],ule={fork:`transcript`,resumePick:`transcript`,contextSeries:`contextMeter`};function dle(e){return e===`fork`||e===`resumePick`||e===`contextSeries`}function vT(e){return e.backend||`claude`}function yT(e,t){return e?e.find(e=>e.id===(t||`claude`))??null:null}function fle(e,t){return yT(e,t)?.caps.autoAcceptsTrust!==!1&&void 0}function bT(e,t){return yT(e,t)?.kind===`shell`||t===`shell`}function xT(e){return e?e.filter(t=>!bT(e,t.id)):null}function ple(e){return e?.find(e=>e.kind===`shell`)??null}function ST(e){let t=xT(e);return!!t&&t.length>1}function mle(e,t){return bT(e,t)?`A plain shell on the desktop — no conversation, models or context gauge here.`:null}function CT(e,t){let n=yT(e,t);return!n||n.id===`claude`?null:n.label}function wT(e,t,n){let r=yT(e,t);if(!r)return!0;if(!dle(n))return r.caps[n];let i=r.caps[n];return typeof i==`boolean`?i:r.caps[ule[n]]}function TT(e,t,n){let r=yT(e,t);return!r||wT(e,t,n)?null:gle(n,r.label)}function hle(e){return`${e}'s quota is read (see usage), but no limit wall is detected here, so a session is never held for a reset.`}function gle(e,t){switch(e){case`transcript`:return`this session runs ${t}, which keeps no Claude conversation log — there is no transcript to fork from here. The terminal scrollback is still on this screen.`;case`contextMeter`:return`${t} doesn’t print a context gauge this app can read, so nothing here is measured — this is not a session that has run out of room.`;case`usageLimits`:return`${t} runs against no account quota this app can wait out, so nothing here is counted against one.`;case`slash`:return`${t} doesn’t take Claude’s slash commands, so there is nothing to send one to here.`;case`promptBoxes`:return`${t} doesn’t draw choice boxes this app can read — answer it by typing into the terminal.`;case`hooks`:return`${t} doesn’t report when a turn ends, so “finished” here is inferred from silence rather than known.`;case`effort`:return`${t} has no reasoning-effort setting to pick.`;case`remoteControl`:return`${t} can’t be mirrored to a remote-control session.`;case`fork`:return`${t} keeps its conversation somewhere this app may read and must not rewrite, so a turn here can be read but not forked or reset to. Everything else in the reader works.`;case`resumePick`:return`${t} has no “pick an older conversation” list this desktop knows how to drive — reopening carries on the folder’s own conversation instead.`;case`contextSeries`:return`${t} leaves no context history this app can plot, so nothing here is measured — this is not a session that has run out of room.`}}function ET(e,t){return wT(e,t,`slash`)&&wT(e,t,`promptBoxes`)&&wT(e,t,`hooks`)&&wT(e,t,`transcript`)}function _le(e,t){return ET(e,t)?`claude`:bT(e,t)?`the running command`:yT(e,t)?.label??`the agent`}function vle(e,t,n){return n&&vT({backend:t})===`claude`&&ET(e,t)}function DT(e,t){let n=yT(e,t);return!n||ET(e,t)||n.caps.modes===!0}function OT(e,t){return yT(e,t)?.caps.commands===!0}function yle(e,t){let n=yT(e,t);return n?n.caps.permissionModes.length===0?`${n.label} has no permission modes to switch between, so there is no mode picker${ET(e,t)?` and no ultracode switch`:``} here.`:DT(e,t)?null:`${n.label} takes its permission mode when a session starts; the phone cannot switch it on a running session, so choose it when you start one.`:null}function ble(e,t){return`${ET(e,t)?`claude`:yT(e,t)?.label??`the agent`} is not signed in on the desktop yet: the terminal stays up for its setup (theme, sign-in). The reader comes back once it reaches its prompt.`}function xle(e,t){return`${ET(e,t)?`claude`:yT(e,t)?.label??`the agent`} is set up: back to the reader.`}function Sle(e,t,n={}){let r=[];if(bT(e,t))return r;let i=(n,i,a=``)=>{let o=TT(e,t,i);o&&r.push({label:n,reason:o+a})};i(`reader view`,`transcript`),wT(e,t,`transcript`)&&i(`fork or reset to a turn`,`fork`),i(`context graph`,`contextSeries`),ET(e,t)||(yT(e,t)?.caps.usage===!0&&!wT(e,t,`usageLimits`)?r.push({label:`usage limits`,reason:hle(yT(e,t)?.label??`this backend`)}):i(`usage limits`,`usageLimits`),i(`turn-end reports`,`hooks`),i(`readable choice boxes`,`promptBoxes`));let a=n.hiddenSlash??0,o=a>0?`${a} of your header chips ${a===1?`is a Claude slash command and is`:`are Claude slash commands and are`} not offered here`:``;return OT(e,t)?o&&r.push({label:`your Claude header chips`,reason:`${o} — ${yT(e,t)?.label??`this backend`} lists its own commands under /.`}):i(`slash commands`,`slash`,o?` — ${o}.`:``),r}function kT(e,t){let n=yT(e,t);if(!n)return{aliases:[],ids:[],freeText:!0};let r=[...n.models.aliases],i=[...n.models.ids];return{aliases:r,ids:i,freeText:r.length+i.length===0}}function Cle(e,t){return yT(e,t)?`This backend did not name its models, so type one.`:`This desktop has not listed its models yet, so type one.`}function wle(e,t,n){return e&&!t&&!n}function AT(e,t){let n=yT(e,t);if(!n)return gT;let r=n.caps.efforts;return r&&r.length>0?r:n.caps.effort?gT:[]}var Tle={"Claude Code":`Claude`};function Ele(e,t){let n=yT(e,t)?.label;return n?Tle[n]??n:!t||t===`claude`?`Claude`:`CLI`}function Dle(e,t){let n=yT(e,t);return n?[...xn(n.caps)]:_T}function Ole(e,t){let n=yT(e,t);return n?[...n.caps.permissionModes]:_T}function jT(e,t){let n=yT(e,t)?.contextWindowTokens;return typeof n!=`number`||!Number.isFinite(n)||n<=0?null:`${n>=1e3?`${Math.round(n/1e3)}k`:String(n)} token window`}function kle(e,t){let n={...e},r=yT(t,n.backend);return bT(t,n.backend)&&(delete n.model,delete n.effort,delete n.permissionMode,delete n.remoteControlled),r?(r.id===`claude`&&delete n.backend,r.caps.effort||delete n.effort,r.caps.remoteControl||delete n.remoteControlled,n.permissionMode&&!xn(r.caps).includes(n.permissionMode)&&delete n.permissionMode,MT(n)):(t||delete n.backend,MT(n))}function Ale(e,t){let n=e.permissionMode;if(!n||bT(t,e.backend))return null;let r=yT(t,e.backend);if(!r||!r.caps.permissionModes.includes(n)||xn(r.caps).includes(n))return null;let i=Pa(r.label,n,r.caps);return i?`${i} This launch goes without it.`:null}function MT(e){return Object.keys(e).forEach(t=>{e[t]||delete e[t]}),e}function NT(e,t,n){let r={backend:t.backend,model:t.model};if(!n)return r;let i=n.backend;return bT(e,i)||!yT(e,i)?r:{backend:i,model:n.model}}var PT={local:`On this desktop`,hosted:`Hosted`,unknown:`Not sure`},jle={local:`Runs on the Mac. No network, no bill, nothing leaves the machine.`,hosted:`Runs on somebody’s server.`,unknown:`This desktop couldn’t say where these run.`},FT=`Your prompts — and the contents of every file the agent reads — leave this machine and are processed on the operator’s servers, under the operator’s terms, not ${L.displayName}’s. Read them before you point one of these at a private repo.`;function IT(e,t){return!!e&&e.includes(t)}function Mle(e,t){if(!t)return e.length?[{where:`unknown`,ids:[...e]}]:[];let n={local:[],hosted:[],unknown:[]};for(let r of e){let e=t[r];n[e===`local`||e===`hosted`?e:`unknown`].push(r)}return[`local`,`hosted`,`unknown`].filter(e=>n[e].length>0).map(e=>({where:e,ids:n[e]}))}function Nle(e){return e.length>1}function LT(e,t){let n=yT(e,t)?.unavailable;return typeof n==`string`&&n.trim()?n.trim():null}function RT(e,t){let n=yT(e,t)?.measured?.drift;return n&&n.trim()?n.trim():null}function zT(e){let t=[...e.experimental===!0?[`experimental`]:[],...e.unavailable&&e.unavailable.trim()?[`not available now`]:[]];return t.length?`${e.label} (${t.join(`, `)})`:e.label}function Ple(e){return!e||e.state!==`down`?null:e.note?.trim()||`The CLI’s own channel is down — turns and questions are read off the screen meanwhile.`}var BT=e=>e.kind===`repo`||e.kind===`repos`?e.launch:void 0;function VT(e,t){if(e.kind!==`repo`&&e.kind!==`repos`)return e;let{launch:n,...r}=e;return t?{...r,launch:t}:r}function HT(e){return!e||!e.model&&!e.effort&&!e.backend?`new-session defaults`:`${e.backend&&e.backend!==`claude`?`${e.backend} · `:``}${e.model||`the default model`}${e.effort?` · ${e.effort}`:``}`}var UT=e=>e&&(e.model||e.effort||e.backend)?`, ${HT(e)}`:``;function WT(e,t){return ET(e,t)?null:Aa(e?.find(e=>e.id===t)?.label||`this backend`)}var GT=[{unit:`usd`,label:`dollars`,example:`2 or 0.50`,prefix:`$`,presets:[`1`,`2`,`5`]},{unit:`tok`,label:`tokens`,example:`500k or 2m`,suffix:`tokens`,presets:[`250k`,`1m`,`3m`]},{unit:`sessionPct`,label:`% of 5h window`,example:`2 or 0.5`,suffix:`% of 5h`,presets:[`5`,`10`,`25`]},{unit:`weeklyPct`,label:`% of week`,example:`5 or 0.5`,suffix:`% of week`,presets:[`5`,`10`,`25`]}];function Fle(e,t,n,r=!1){let i=GT.filter(n=>e?!eE(n.unit)||n.unit===t:!(r&&n.unit===`sessionPct`&&t!==`sessionPct`)),a=n?.trim()||(t===`native`?`native unit`:``);return a?[...i,{unit:`native`,label:a,example:`5 or 0.5`,suffix:a,presets:[`1`,`5`,`20`]}]:i}function KT(e,t){return e?.find(e=>e.id===t)?.caps?.spendUnit?.trim()||void 0}function qT(e,t,n){if(!t)return null;let r=n??void 0,i=yT(t,r)?.label||`this backend`,a=`nothing is picked, so a later run opens on the desktop's own defaults, which this phone cannot see`;if(e.unit===`native`){let o=KT(t,r),s=e.nativeUnit?.trim();return o&&s&&o===s?null:n===null?`${a} — they may not count ${s||`that unit`}`:o?`${i} counts ${o}, not ${s||`that unit`}`:`${i} does not count ${s||`that unit`}`}return eE(e.unit)&&WT(t,r)?n===null?`${a} — they may not spend from claude's usage windows`:`${i} does not spend from claude's usage windows`:null}function JT(e,t){let n=BT(e);return n?n.backend:t.now?t.defaults?.backend:null}function YT(e,t,n,r,i,a){if(t.kind!==`repo`&&t.kind!==`repos`)return{target:t,kept:n};if(t.budget){let n=JT(t,a),o=n===JT(e,i)?null:qT(t.budget,r,n);if(!o)return{target:t,kept:null};let{budget:s,...c}=t;return{target:c,kept:{budget:s,said:$T(s,o)}}}if(!n)return{target:t,kept:null};let o=JT(t,a);if(o===JT(e,i))return{target:t,kept:n};let s=qT(n.budget,r,o);return s?{target:t,kept:{budget:n.budget,said:$T(n.budget,s)}}:{target:{...t,budget:n.budget},kept:null}}function XT(e,t,n,r,i){let a=t=>({kind:`repo`,cwd:``,...e?{budget:e}:{},...t===null?{}:{launch:{backend:t}}}),o={now:!1},s=YT(a(r),a(i),t,n,o,o);return{budget:(s.target.kind===`repo`?s.target.budget:void 0)??null,kept:s.kept}}var ZT=e=>e===`to`?`budget`:`summary`,Ile=e=>e?.kept??null,QT=e=>null,$T=(e,t)=>`Your cap ${yr(e)} is set aside: ${t}. It comes back if you switch back; a cap typed now replaces it.`,Lle=e=>GT.find(t=>t.unit===e)??GT[0];function Rle(e,t){return e===`native`?t:e===`usd`?`$${t}`:eE(e)?`${t}%`:t}var eE=e=>e===`sessionPct`||e===`weeklyPct`;function tE(e,t){let n=t.trim().toLowerCase().replace(/\s+/g,``);if(!n)return{ok:!1,reason:`type a number`};e===`usd`&&(n=n.replace(/^\$/,``).replace(/\$$/,``)),eE(e)&&(n=n.replace(/%$/,``));let r=1;if(e===`tok`){let e=/^([\d.,_]+)([kmb])$/.exec(n);e&&(n=e[1],r=e[2]===`k`?1e3:e[2]===`m`?1e6:1e9)}if(n=/^\d+,\d{1,2}$/.test(n)?n.replace(`,`,`.`):n.replace(/[,_]/g,``),!/^(\d+\.?\d*|\.\d+)$/.test(n))return{ok:!1,reason:`“${t.trim()}” is not a number${e===`tok`?` — try 500k or 2m`:``}`};let i=Number(n)*r;return!Number.isFinite(i)||!(i>0)?{ok:!1,reason:`a budget has to be more than zero — clear it to have none`}:eE(e)&&i>100?{ok:!1,reason:`a percent of a window cannot be more than 100`}:{ok:!0,max:i}}function zle(e){if(e.unit===`tok`){if(e.max>=1e6&&e.max%1e5==0)return`${e.max/1e6}m`;if(e.max>=1e3&&e.max%100==0)return`${e.max/1e3}k`}return String(e.max)}function Ble(e,t,n){if(!eE(e))return null;if(!t)return fn(`noReading`);let r=n-t.checkedAt;if(r>15e5)return fn(`stale`,r);let i=e===`sessionPct`?t.sessionUsdPerPct:t.weeklyUsdPerPct;if(i==null||!(i>0)){let n=e===`sessionPct`?t.sessionUndated:t.weeklyUndated;return n?fn(`undated`,void 0,e,void 0,n):fn(`noCalibration`)}let a=e===`sessionPct`?`the 5-hour window`:`the week`,o=Math.max(0,Math.round(r/6e4));return`1% of ${a} ≈ ${Ii(i)} of list-price spend, from the usage reading ${o} min ago (${bi})`}function nE(e){return e<10?e.toFixed(1).replace(/\.0$/,``):String(Math.round(e))}function rE(e,t,n){return e===`native`?Vi(t):e===`usd`?Ii(t):e===`tok`?R(t):`${n?`≈`:``}${nE(t)}%`}function Vle(e,t,n){return e===`native`?`${Vi(t)} ${n??`of the backend's own unit`}`:e===`tok`?`${R(t)} tokens`:e===`usd`?Ii(t):`≈${nE(t)}% of ${e===`sessionPct`?`the 5-hour window`:`the week`}`}function iE(e,t,n,r=n,i=!1){return t==null?`${n(e)} so far — the subagent share is not ${i?`stated by this session's backend`:`logged for this session`}`:t>0?`${n(e)} so far — ${r(Math.max(0,e-t))} in this conversation, ${r(t)} in subagents`:`${n(e)} so far, none of it in subagents`}function aE(e,t,n,r,i){if(t===void 0)return null;if(eE(e)&&n===void 0&&!t?.source)return t&&t.costUsd!=null?`in dollars, ${iE(t.costUsd,t.agentCostUsd??null,Ii)}`:fn(t?`unpriced`:`noSpark`);let a=vn(e,t,n,r,i);if(a.value!=null)return iE(a.value,a.agent,t=>Vle(e,t,i),eE(e)?t=>rE(e,t,!0):void 0,!!t?.source);let o=fn(a.why??`noSpark`,a.why===`stale`&&n?r-n.checkedAt:void 0,e,i,a.undated);return eE(e)&&t&&t.costUsd!=null?`${o}. In dollars: ${iE(t.costUsd,t.agentCostUsd??null,Ii)}.`:o}function Hle(e,t,n,r){if(!t)return null;let i=vn(e.unit,t,n,r,e.nativeUnit);if(i.value==null)return null;let a=eE(e.unit),o=`${rE(e.unit,i.value,a)} of ${rE(e.unit,e.max,!1)}`;if(i.value>=e.max)return`${o} — already past it: this session's sends would be held as soon as it is set`;let s=i.value/e.max*100;return`${o} — ${s<1?`under 1`:Math.round(s)}% used`}var Ule=[{key:`soft`,label:`soft (default) — hold queued work, never block me`,note:`At the cap, queued and scheduled sends to this session wait and you are told. What you send yourself still goes, without a question. The switch below decides whether the turn running at that moment gets one Esc; later turns are left to run.`},{key:`hard`,label:`hard — ask before my sends, stop every other turn`,note:`At the cap, queued and scheduled sends wait and you are told. Each send you make yourself asks “send anyway?” first, and that one turn then runs. Every turn you did not send yourself — a subagent reporting back, a chained prompt — is stopped with one Esc, turn after turn.`}];function Wle(e){return{title:`Past this session's hard budget`,lines:[`${e}.`,`Send anyway: this message goes and its turn runs to the end. Turns you did not send still get one Esc.`,`Keep it: the words stay in the box. Tap budget hit on the session to raise or clear the budget.`],confirmLabel:`send anyway`,cancelLabel:`keep it`}}Wa({});function oE(e,t,n){if(!e){if(n===void 0)return`No budget on this session.`;let e=vn(`usd`,n,null,t).value==null?vn(`tok`,n,null,t).value==null?null:`tok`:`usd`,r=e&&aE(e,n,null,t);return r?`Spent: ${r}.`:null}let r=e.verdict;return r.state===`unknown`?fn(r.why??`noSpark`,r.why===`stale`&&e.cal?t-e.cal.checkedAt:void 0,r.unit,r.nativeUnit,r.undated):`${za(r)}${r.state===`over`?`. ${Wa(e.cfg)}`:`.`}`}var sE=e=>`budget ${yr(e)}`;function cE({children:e,onClear:t,clearLabel:n=`clear`,clearTitle:r,section:i=!1,className:a}){let o=`${i?`section `:``}filter-bar${a?` ${a}`:``}`;return(0,J.jsxs)(`div`,{className:o,children:[(0,J.jsx)(`span`,{className:`filter-bar-txt`,children:e}),(0,J.jsx)(`button`,{className:`filter-bar-clear`,title:r,onClick:t,children:n})]})}var lE=(0,H.forwardRef)(function({className:e,...t},n){return(0,J.jsx)(`input`,{ref:n,className:e?`search ${e}`:`search`,...t})});function uE(e,t){return t.detail?`${e} · ${t.count} · ${t.detail}`:`${e} · ${t.count}`}function dE(e,t){return e===t?null:t}function fE(e,t,n){return e.map(e=>{let r=t(e);return{key:e,text:uE(n(e),r),count:r.count}})}function pE({on:e,busy:t=!1,clears:n=!0,title:r,onClick:i,children:a}){return(0,J.jsx)(`button`,{className:`fchip${e?` on`:``}`,"aria-pressed":e,title:r,onClick:i,children:(0,J.jsxs)(`span`,{className:`fchip-pill`,children:[a,e&&t?(0,J.jsx)(Ul,{size:12,className:`spin fchip-x`}):e&&n?(0,J.jsx)(V,{size:13,className:`fchip-x`,"aria-hidden":!0}):null]})})}function mE({keys:e,bucket:t,label:n,active:r,onPick:i,className:a=`fchips`}){return(0,J.jsx)(`div`,{className:a,children:fE(e,t,n).map(e=>(0,J.jsx)(pE,{on:r===e.key,onClick:()=>i(dE(r,e.key)),children:e.text},e.key))})}var Gle=24;function hE({title:e,icon:t,onClose:n,actions:r,head:i,footer:a,className:o,full:s,children:c}){let l=[`sheet`,s?`sheet-full`:``,o??``].filter(Boolean).join(` `);return(0,J.jsxs)(`div`,{className:l,children:[(0,J.jsx)(gE,{title:e,icon:t,onClose:n,children:r}),i,s?(0,J.jsx)(`div`,{className:`sheet-full-body`,children:c}):c,a?(0,J.jsx)(`div`,{className:`sheet-actions`,children:a}):null]})}function gE({title:e,icon:t,onClose:n,brandClass:r,children:i}){return(0,J.jsxs)(`div`,{className:`sheet-head`,children:[(0,J.jsx)(`button`,{className:`back`,onClick:n,"aria-label":`back`,children:(0,J.jsx)(Hl,{size:Gle})}),(0,J.jsxs)(`span`,{className:r?`brand ${r}`:`brand`,children:[t,t?` `:null,e]}),i?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`spacer`}),i]}):null]})}function _E(e){let[t,n]=(0,H.useState)(()=>Date.now());return(0,H.useEffect)(()=>{let t=window.setInterval(()=>n(Date.now()),e);return()=>window.clearInterval(t)},[e]),t}function Kle({at:e}){return _E(1e4),(0,J.jsx)(`span`,{className:`muted`,children:Gp(e)})}function vE({title:e,onClose:t,onRefresh:n,refreshTitle:r,at:i,iconSize:a=16,bare:o=!1,children:s}){let c=(0,J.jsxs)(J.Fragment,{children:[i!=null&&(0,J.jsx)(Kle,{at:i}),s,(0,J.jsx)(Y,{title:r,onClick:n,children:(0,J.jsx)(Wl,{size:a})})]});return(0,J.jsx)(gE,{title:e,onClose:t,children:o?c:(0,J.jsx)(`span`,{className:`head-acts tight`,children:c})})}function Z({as:e=`div`,tone:t,className:n,...r}){return(0,H.createElement)(e,{className:Yce(t,n),...r})}function yE({tone:e,className:t,...n}){return(0,J.jsx)(`span`,{className:Xce(e,t),...n})}function qle(e){return e===`wrap`?`row-wrap`:e===`grow`?`row grow`:`row`}function bE(e,t){return e+(t?` ${t}`:``)}function xE({as:e=`div`,kind:t,...n}){return(0,H.createElement)(e,{className:qle(t),...n})}function SE({as:e=`span`,className:t,...n}){return(0,H.createElement)(e,{className:bE(`row-title`,t),...n})}function Q({as:e=`span`,className:t,...n}){return(0,H.createElement)(e,{className:bE(`row-sub`,t),...n})}function $({res:e,empty:t=!0,thing:n,offlineNote:r,note:i,noun:a=`listing`,children:o}){let s=e?.state===`cached`&&e.age!=null?(0,J.jsxs)(`div`,{className:`empty empty-stale`,children:[`Cached `,a,` from `,Yp(e.age),` — the link is down, so anything added since won’t be here.`]}):null;if(!t)return s;let c=n??`this`,l=o??null;if(e)switch(e.state){case`loading`:l=(0,J.jsxs)(J.Fragment,{children:[`Reading `,c,`…`]});break;case`offline`:l=(0,J.jsxs)(J.Fragment,{children:[`No connection — this phone could not reach the desktop, so `,c,` cannot be read.`,r?(0,J.jsxs)(J.Fragment,{children:[` `,r]}):null]});break;case`error`:l=(0,J.jsxs)(J.Fragment,{children:[`The host could not read `,c,e.error?(0,J.jsxs)(J.Fragment,{children:[`: `,e.error]}):`.`]})}return l?(0,J.jsxs)(J.Fragment,{children:[s,(0,J.jsxs)(`div`,{className:`empty empty-msg`,children:[l,i?(0,J.jsxs)(J.Fragment,{children:[` `,i]}):null]})]}):s}function CE({cants:e,className:t}){if(!e.length)return null;let n=new Map;for(let t of e)n.set(t.reason,[...n.get(t.reason)??[],t.label]);return(0,J.jsx)(`div`,{className:`act-cants${t?` ${t}`:``}`,children:[...n].map(([e,t])=>(0,J.jsxs)(`span`,{className:`act-cant`,children:[(0,J.jsx)(nl,{size:11}),` no `,t.join(`, `),` — `,e]},e))})}function wE({children:e}){return(0,J.jsxs)(`span`,{className:`act-cant act-cant-inline`,children:[(0,J.jsx)(nl,{size:11}),` `,e]})}function Jle({cants:e,className:t}){return e.length?(0,J.jsxs)(`details`,{className:`act-cants act-cants-fold${t?` ${t}`:``}`,children:[(0,J.jsxs)(`summary`,{className:`act-cant`,children:[(0,J.jsx)(nl,{size:11}),` Not here: `,e.map(e=>e.label).join(` · `),` `,(0,J.jsx)(ac,{size:11,"aria-label":`tap for the reasons`})]}),(0,J.jsx)(CE,{cants:e})]}):null}function TE({of:e,label:t,children:n}){let[r,i]=(0,H.useState)(!1);return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{type:`button`,className:`hint-chip explain-chip${r?` open`:``}`,"aria-expanded":r,"aria-label":`what ${e} means`,onClick:e=>{e.stopPropagation(),i(e=>!e)},children:[(0,J.jsx)(gl,{size:13,"aria-hidden":!0}),t?(0,J.jsx)(`span`,{className:`explain-label`,children:t}):null]}),r&&(0,J.jsx)(`div`,{className:`explain-body`,children:n})]})}function Yle(){return oo(B.launch,{})}function Xle(){try{return new Set(JSON.parse(z(B.hiddenRepos)||`[]`))}catch{return new Set}}function EE(e,t){return oo(e,t)}function DE(e,t){$a(e,t)}var OE=B.snapAt;function Zle(e){DE(B.snapSessions,e),DE(OE,Date.now())}function Qle(e){DE(B.snapRepos,e),DE(B.snapReposAt,Date.now())}function $le(){return Qa(B.snapReposAt,0)}function eue(){return oo(B.cmdHistory,[])}function kE(){return oo(B.snippets,[])}var AE=B.sessionOrder;function tue(){try{let e=JSON.parse(z(AE)||`[]`);return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}catch{return[]}}var jE=B.collapsedRepos;function nue(){try{let e=JSON.parse(z(jE)||`[]`);return new Set(Array.isArray(e)?e.filter(e=>typeof e==`string`):[])}catch{return new Set}}var rue=B.pendingStars,iue=B.pendingFollowUps;function aue(e){return mae(z(e))}function oue(e,t){Object.keys(t).length===0?so(e):$a(e,t)}var ME=40;function NE(){let e=oo(B.snapBuilds,{});if(!e||typeof e!=`object`||Array.isArray(e))return{};let t={};for(let[n,r]of Object.entries(e))r&&Array.isArray(r.v)&&typeof r.at==`number`&&(t[n]=r);return t}function sue(e,t){let n=NE();n[e]={v:t,at:Date.now()};let r=Object.keys(n);if(r.length>ME)for(let e of r.sort((e,t)=>n[e].at-n[t].at).slice(0,r.length-ME))delete n[e];return $a(B.snapBuilds,n),n}var PE=40;function FE(){let e=oo(B.snapCapture,{});if(!e||typeof e!=`object`||Array.isArray(e))return{};let t={};for(let[n,r]of Object.entries(e))r&&Array.isArray(r.v)&&typeof r.at==`number`&&(t[n]=r);return t}function cue(e,t){let n=FE();n[e]={v:t,at:Date.now()};let r=Object.keys(n);if(r.length>PE)for(let e of r.sort((e,t)=>n[e].at-n[t].at).slice(0,r.length-PE))delete n[e];return $a(B.snapCapture,n),n}function IE(){let e=oo(B.snapSchedules,{v:[],at:0});return e&&Array.isArray(e.v)&&typeof e.at==`number`?e:{v:[],at:0}}function lue(e){$a(B.snapSchedules,{v:e.map(({running:e,...t})=>t),at:Date.now()})}function LE(){let e=oo(B.snapCliHealth,null);if(!e||typeof e.at!=`number`||!e.v?.health||!e.v?.rollup)return null;let t=e.v.source,n=t&&typeof t.repo==`string`&&typeof t.stateDir==`string`?{repo:t.repo,stateDir:t.stateDir}:void 0;return{value:{health:h(e.v.health),rollup:e.v.rollup,source:n},savedAt:e.at}}function uue(e){$a(B.snapCliHealth,{v:e,at:Date.now()})}function due(e,t){return e.length>=12?`${e.length} recordings are already waiting for the desktop — nothing is lost, but this one was not kept`:e.reduce((e,t)=>e+t.bytes,0)+t>50331648?`there is already more audio waiting than this phone will hold — this one was not kept`:null}function fue(e,t){let n=e.filter(e=>(e.retryAt??0)<=t);return n.length?n.reduce((e,t)=>e.ts<=t.ts?e:t):null}function pue(e,t){let n=e.tries+1;return{...e,tries:n,retryAt:t+ln(n)}}function mue(e){return e.map(e=>({...e,retryAt:void 0}))}function hue(e,t){if(e.some(e=>(e.retryAt??0)<=t))return null;let n=e.map(e=>e.retryAt??0).filter(e=>e>t);return n.length?Math.min(...n):null}function RE(e){let t=Math.max(1,Math.round(e));if(t<60)return`${t}s`;let n=Math.floor(t/60),r=t%60;return r?`${n}m ${r}s`:`${n}m`}function gue(e,t){return t&&e>1?`the desktop is reading what you said — ${e-1} more recording${e-1==1?``:`s`} behind it`:t?`the desktop is reading what you said`:e===1?`one recording is waiting for the desktop — it is read the moment the link is back, and the words come to the box`:e>1?`${e} recordings are waiting for the desktop — they are read in the order you said them, the moment the link is back`:null}function _ue(e){return!/[\p{L}\p{N}]/u.test(e)}function vue(e){return`${RE(e.seconds)} of what you said is held — the desktop could not be reached. It is read as soon as it can be, and the words come back to the box.`}function yue(e){return`${RE(e)} of dictation came back after the box it was said into had gone — the words are on the pad.`}function bue(e){return`your words came back but could not be parked: ${e}`}var xue=45e3,Sue=3e5,zE=`dictations`,BE=[],VE=!1,HE=null,UE=!1,WE=0,GE=new Map,KE=new Set;function qE(){if(VE)return BE;VE=!0;let e=oo(B.dictations,[]);return BE=Array.isArray(e)?e.filter(e=>!!e&&typeof e.id==`string`).map(e=>({...e,tries:Number(e.tries)||0})):[],BE}function JE(e){BE=e,$a(B.dictations,e),YE()}function YE(){for(let e of KE)e()}function XE(){return{held:qE().length,sending:HE!==null}}function Cue(e){return KE.add(e),()=>{KE.delete(e)}}async function wue(e,t){let n=due(qE(),e.size);if(n)return{error:n};let r=`d_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,8)}`;return await Xb(zE,r,e),(await $b(zE)).includes(r)?(JE([...qE(),{id:r,ts:Date.now(),seconds:t.seconds,bytes:e.size,lang:t.lang,tries:0}]),QE(),{id:r}):{error:`this phone would not store the recording, so it was not kept`}}function Tue(e,t){return GE.set(e,t),()=>{GE.get(e)===t&&GE.delete(e)}}function ZE(e){GE.delete(e),JE(qE().filter(t=>t.id!==e)),Zb(zE,e)}async function QE(){if(!UE){UE=!0;try{for(;;){let e=fue(qE(),Date.now());if(!e){kue();return}await Eue(e)}}finally{UE=!1}}}async function Eue(e){let t=await Yb(zE,e.id);if(!t){ZE(e.id),Dg(`a recording waiting to be read is no longer on this phone`);return}HE=e.id,YE();let n=new AbortController,r=0,i=()=>{window.clearTimeout(r),r=window.setTimeout(()=>n.abort(),xue)};i();try{let r=ea(Pv()),a=await U.dictate(t,{lang:e.lang,terms:r,signal:n.signal,onProgress:i});`error`in a?(ZE(e.id),Dg(a.error)):await Oue(e,a.text)}catch(t){t?.permanent?(ZE(e.id),Dg(t.message)):Due(e)}finally{window.clearTimeout(r),HE=null,YE()}}function Due(e){let t=pue(e,Date.now()),n=!e.told;JE(qE().map(n=>n.id===e.id?{...t,told:!0}:n)),n&&Dg(vue(e))}async function Oue(e,t){let n=t.trim();if(!n||_ue(n)){ZE(e.id),Dg(`nothing was said`);return}let r=GE.get(e.id);if(r&&r(n)){ZE(e.id);return}let i=th({id:`p_${e.id}`,text:n,ts:Date.now()});i?(JE(qE().map(t=>t.id===e.id?{...t,tries:t.tries+1,retryAt:Date.now()+Sue,told:!0}:t)),e.told||Dg(bue(i))):(ZE(e.id),Dg(yue(e.seconds)))}function kue(){window.clearTimeout(WE);let e=hue(qE(),Date.now());e!==null&&(WE=window.setTimeout(()=>{QE()},Math.max(250,e-Date.now())))}function $E(){qE().some(e=>e.retryAt)&&JE(mue(qE())),QE()}function Aue(){qE(),window.addEventListener(`online`,$E);let e=!1;Tm(t=>{let n=t.status===`open`;n&&!e&&$E(),e=n}),jue(),QE()}async function jue(){let e=await $b(zE),t=new Set(qE().map(e=>e.id));for(let n of e)t.has(n)||Zb(zE,n)}async function Mue(){let e=qE(),t=HE,n=e.filter(e=>e.id!==t);for(let e of n)await Zb(zE,e.id);return JE(e.filter(e=>e.id===t)),{dropped:n.length,bytes:n.reduce((e,t)=>e+(t.bytes||0),0),kept:e.length-n.length}}function Nue(e){let t=``;for(let n of e){let e=n.replace(/\s+/g,` `).trim();if(e){if(!t||e.startsWith(t))t=e;else if(t.endsWith(e)||t.startsWith(e))continue;else t=`${t} ${e}`}}return t}var Pue=`phone recogniser`;function eD(e){let t=`dictating with the phone's own recogniser, not the desktop's whisper`;return e.secure?e.canRecord?!e.status||e.status.available?null:`${t}: ${e.status.reason??`the desktop says whisper is not available`}`:`${t}: this browser gives the app no way to record audio`:`${t}: this page is plain http, where the app may not record audio — open it over its https address and whisper takes over`}function Fue(e){return e.track===`ended`?`the microphone was taken away (a call, another app, or a headset disconnecting)`:e.ctx===`closed`?`the recording was closed`:e.now-e.lastFrameAt<2e3&&e.now-e.startedAt-e.heardSeconds*1e3<3e3?null:e.visible?e.ctx===`running`?`the audio was interrupted (usually the screen turning off or the app leaving the foreground)`:`the phone paused the audio (usually the screen turning off)`:`the app went to the background or the screen turned off`}function tD(e){let t=Math.max(0,Math.floor(e));return`${Math.floor(t/60)}:${String(t%60).padStart(2,`0`)}`}function Iue(e,t){return`dictation stopped hearing you at ${tD(e)} — ${t}. Everything up to then is being read; tap the mic to go on.`}var nD=!1;function rD(){let e=window;return e.SpeechRecognition||e.webkitSpeechRecognition||null}var iD=null;function Lue(){if(!iD){let e=U.dictateStatus();iD=e,e.then(t=>{!t.available&&iD===e&&(iD=null)})}return iD}function aD(){return typeof navigator<`u`&&!!navigator.mediaDevices?.getUserMedia&&typeof AudioContext<`u`}async function Rue(){let e=await navigator.mediaDevices.getUserMedia({audio:{channelCount:1,echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0}}),t=new AudioContext({sampleRate:_a});t.state===`suspended`&&await t.resume();let n=t.createMediaStreamSource(e),r=t.createScriptProcessor(4096,1,1),i={ctx:t,stream:e,node:r,chunks:[],frames:0,openedAt:Date.now(),lastFrameAt:Date.now()};r.onaudioprocess=e=>{i.chunks.push(new Float32Array(e.inputBuffer.getChannelData(0))),i.frames+=e.inputBuffer.length,i.lastFrameAt=Date.now()},n.connect(r);let a=t.createGain();return a.gain.value=0,r.connect(a),a.connect(t.destination),i}function oD(e){try{e.node.onaudioprocess=null,e.node.disconnect()}catch{}for(let t of e.stream.getTracks())try{t.stop()}catch{}e.ctx.close().catch(()=>{})}function zue(e){let t=new Float32Array(e.frames),n=0;for(let r of e.chunks)t.set(r,n),n+=r.length;return new Blob([bee(Uee(t),e.ctx.sampleRate).buffer],{type:`audio/wav`})}function sD(){try{navigator.vibrate?.([120,80,120])}catch{}}function cD(e){let[t,n]=(0,H.useState)(!1),[r,i]=(0,H.useState)(rD()?`browser`:null),[a,o]=(0,H.useState)(XE),[s,c]=(0,H.useState)(()=>eD({secure:typeof window<`u`&&window.isSecureContext,canRecord:aD()})),l=(0,H.useRef)(null),u=(0,H.useRef)(null),d=(0,H.useRef)(null),f=(0,H.useRef)(0),[p,m]=(0,H.useState)(0),h=(0,H.useRef)(null),g=(0,H.useRef)(!1),_=(0,H.useRef)(``),v=(0,H.useRef)(e);v.current=e;let y=(0,H.useRef)([]);(0,H.useEffect)(()=>{let e=!0,t=!1,n=()=>{aD()&&!t&&Lue().then(n=>{e&&(n.available&&(t=!0,i(`host`)),c(eD({secure:window.isSecureContext,canRecord:!0,status:n})))})};n();let r=bm().status===`open`,a=Tm(e=>{let t=e.status===`open`;t&&!r&&n(),r=t}),s=Cue(()=>o(XE()));return()=>{e=!1,a(),s(),g.current=!0,l.current?.stop(),u.current&&=(oD(u.current),null),d.current&&window.clearInterval(d.current),w();for(let e of y.current)e();y.current=[]}},[]);async function b(){let e;try{e=await Rue()}catch(e){Dg(e?.name===`NotAllowedError`?`this app has no permission to use the microphone`:`no microphone this app can open`),n(!1),w();return}u.current=e,f.current=Date.now(),m(0),n(!0),C();let t=!1;d.current=window.setInterval(()=>{if(u.current!==e)return;let n=e.frames/e.ctx.sampleRate;m(n);let r=Fue({now:Date.now(),startedAt:e.openedAt,heardSeconds:n,lastFrameAt:e.lastFrameAt,track:e.stream.getAudioTracks()[0]?.readyState??`ended`,ctx:e.ctx.state,visible:document.visibilityState===`visible`});r?(sD(),Dg(Iue(n,r)),x()):(!t&&n>=280&&(t=!0,Dg(`at ${tD(300)} this part goes to the desktop and a new one starts — keep talking`)),n>=300&&(sD(),x({rollOver:!0}).then(()=>b())))},500)}async function x(e={}){let t=u.current;if(u.current=null,d.current&&=(window.clearInterval(d.current),null),!t)return;e.rollOver||(n(!1),w());let r=t.frames/t.ctx.sampleRate,i=zue(t);if(oD(t),r<.25){Dg(`nothing was said`);return}let a=await wue(i,{seconds:r,lang:Ov()});if(`error`in a){Dg(a.error);return}let o=v.current.key?.();y.current.push(Tue(a.id,e=>{let t=v.current;return t.key?.()===o&&(t.write(kr(t.read(),e)),!0)}))}function S(){let e=rD();if(!e)return;let t=new e;t.lang=Nse(),t.continuous=!0,t.interimResults=!0;let r=Pv(),i=v.current.key?.(),a=!1;t.onresult=e=>{if(v.current.key?.()!==i){a||(a=!0,g.current=!0,t.stop(),Dg(`dictation stopped — you left the box it was writing into; what was recognised is still there`));return}let n=[];for(let t=0;t<e.results.length;t++)n.push(e.results[t][0].transcript);v.current.write(_.current+nte(Nue(n),r))},t.onerror=e=>{n(!1);let t=e?.error;t&&t!==`no-speech`&&t!==`aborted`&&(g.current=!0,sD(),Dg(`dictation stopped — this browser's recogniser could not finish. What was already recognised is in the box.`))},t.onend=()=>{n(!1),d.current&&=(window.clearInterval(d.current),null),w(),l.current===t&&(l.current=null),!g.current&&!a&&(sD(),Dg(`the phone's recogniser stopped listening at ${tD((Date.now()-f.current)/1e3)} — what it heard is in the box; tap the mic to go on`))},l.current=t,g.current=!1,s&&!nD&&(nD=!0,Dg(s)),t.start(),f.current=Date.now(),m(0),n(!0),C(),d.current=window.setInterval(()=>m((Date.now()-f.current)/1e3),500)}async function C(){try{h.current=await navigator.wakeLock?.request(`screen`)??null}catch{h.current=null}}function w(){h.current?.release().catch(()=>{}),h.current=null}function T(){if(t){u.current?x():(g.current=!0,l.current?.stop());return}let e=v.current.read();_.current=e?e.replace(/\s*$/,``)+` `:``,r===`host`?b():S()}return{supported:r!==null,listening:t,heard:t?tD(p):null,transcribing:a.sending,held:a.held,engine:r,fallback:r===`browser`?s:null,toggle:T}}function Bue(){let[e,t]=(0,H.useState)(Ov);(0,H.useEffect)(()=>jv(()=>t(Ov())),[]);let n=jse(),r=Zee(e);return(0,J.jsxs)(`span`,{className:`dict-lang`,title:r,children:[(0,J.jsx)(Bc,{size:14}),(0,J.jsx)(`span`,{className:`dict-lang-face`,children:Rte(e)}),(0,J.jsx)(`select`,{value:e,"aria-label":`dictation language — ${r}`,onChange:e=>{q(`action:voice.lang`),kv(e.target.value)},children:n.map(e=>(0,J.jsx)(`option`,{value:e.code,children:e.label},e.code))})]})}function Vue({why:e}){return(0,J.jsxs)(`button`,{type:`button`,className:`dict-lang dict-fallback`,onPointerDown:e=>e.preventDefault(),onClick:()=>{q(`action:voice.fallback`),Dg(e)},"aria-label":e,children:[(0,J.jsx)(go,{size:14}),(0,J.jsx)(`span`,{className:`dict-lang-face`,children:Pue})]})}function lD({voice:e,onPointerDown:t,idleTitle:n}){return e.supported?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{type:`button`,className:`mic ${e.listening?`on`:``}${e.transcribing?` busy`:``}`,onPointerDown:t,onClick:()=>{q(`action:voice`),e.toggle()},title:e.listening?`listening ${e.heard??``} — tap to stop`:gue(e.held,e.transcribing)??n??(e.engine===`host`?`Dictate — read on the desktop`:`Dictate`),children:[e.transcribing&&!e.listening?(0,J.jsx)(Kl,{size:18}):(0,J.jsx)(nre,{size:18}),e.held>0&&(0,J.jsx)(`span`,{className:`mic-badge`,children:e.held}),e.heard&&(0,J.jsx)(`span`,{className:`mic-clock`,children:e.heard})]}),e.listening&&e.engine===`host`&&(0,J.jsx)(Bue,{}),e.listening&&e.fallback&&(0,J.jsx)(Vue,{why:e.fallback})]}):null}var Hue={autoCapitalize:`none`,autoCorrect:`off`,spellCheck:!1};function uD({prompts:e,onChange:t,placeholder:n,chain:r,stepPlaceholder:i=`…and then?`,stepHint:a=`then, once the turn before it finishes:`,addLabel:o=`another prompt`,trackAdd:s,autoFocus:c,children:l,inline:u,rows:d,focusRef:f,plain:p}){let m=e[0]??``,h=e.slice(1),g=(n,r)=>{let i=e.length?e.slice():[``];i[n]=r,t(i)},_=e.map(e=>e.trim()).filter(Boolean);return(0,J.jsxs)(`div`,{className:`promptc${u?` promptc-inline`:``}`,children:[(0,J.jsx)(`textarea`,{className:`search promptc-area`,autoFocus:c,rows:u?d??3:void 0,...p?Hue:{},placeholder:n,value:m,onChange:e=>g(0,e.target.value),onFocus:()=>{f&&(f.current=0)},style:{resize:`vertical`,fontFamily:`inherit`}}),l,r&&h.map((n,r)=>(0,J.jsxs)(`div`,{className:`promptc-step`,children:[(0,J.jsx)(Z,{style:{padding:0},children:a}),(0,J.jsx)(`textarea`,{className:`search`,rows:4,placeholder:i,value:n,onChange:e=>g(r+1,e.target.value),onFocus:()=>{f&&(f.current=r+1)},style:{resize:`vertical`,fontFamily:`inherit`}}),(0,J.jsxs)(`div`,{className:`queue-row-acts`,children:[(0,J.jsx)(`span`,{className:`spacer`}),(0,J.jsx)(Y,{variant:`danger`,title:`drop this step`,onClick:()=>t(e.filter((e,t)=>t!==r+1)),children:(0,J.jsx)(ic,{size:16})})]})]},r)),r&&!!_.length&&(0,J.jsx)(`div`,{className:`queue-row-acts promptc-add`,children:(0,J.jsxs)(Y,{title:`add another prompt, delivered after this one's turn ends`,onClick:()=>{s&&q(s),t([...e,``])},children:[(0,J.jsx)(os,{size:16}),` `,o]})})]})}function dD({prompts:e,onPrompts:t,busy:n,unavailable:r,onFiles:i,trackImage:a,trackFile:o,focusRef:s,onBrowse:c,browseLabel:l=`in repo`}){let u=(0,H.useRef)(null),d=(0,H.useRef)(null),f=e=>{let t=Array.from(e.target.files??[]);e.target.value=``,t.length&&i(t)};return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(fD,{prompts:e,onPrompts:t,focusRef:s}),(0,J.jsx)(Uue,{prompts:e,onPrompts:t,focusRef:s}),r?(0,J.jsxs)(wE,{children:[`no attach — `,r]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(Y,{disabled:n,title:`attach an image (mark it up before it goes)`,onClick:()=>{a&&q(a),u.current?.click()},children:[(0,J.jsx)(Il,{size:16}),` `,n?`adding…`:`image`]}),(0,J.jsxs)(Y,{disabled:n,title:`attach a file of any kind (PDF, doc, zip, audio…)`,onClick:()=>{o&&q(o),d.current?.click()},children:[(0,J.jsx)(Xo,{size:16}),` file`]}),c&&(0,J.jsxs)(Y,{disabled:n,title:`name a file that is already in this repo — the gallery, and the path comes back into the prompt`,onClick:c,children:[(0,J.jsx)(Vo,{size:16}),` `,l]})]}),(0,J.jsx)(`input`,{ref:u,type:`file`,accept:`image/*`,multiple:!0,style:{display:`none`},onChange:f}),(0,J.jsx)(`input`,{ref:d,type:`file`,multiple:!0,style:{display:`none`},onChange:f})]})}function Uue({prompts:e,onPrompts:t,focusRef:n}){let[r,i]=(0,H.useState)(null),a=r=>{q(`action:snippet.insert`);let a=Math.min(Math.max(n?.current??0,0),Math.max(e.current.length-1,0)),o=e.current.length?e.current.slice():[``],s=o[a]??``;o[a]=(s&&!/\s$/.test(s)?s+`
|
|
@@ -120,7 +120,7 @@ Bring this repo onto the latest engine. In order of cost, pick the one that fits
|
|
|
120
120
|
2. If the copy carries readings only this repo has, move them into \`${a}\` (committed; \`readings\` is a list of argv commands that each print one number), then remove the copy as in 1.
|
|
121
121
|
3. If this repo is where the engine is developed (it is the engine's own source), keep the copy and make it run here instead — the failure above says what is missing.
|
|
122
122
|
|
|
123
|
-
Do not delete the measured series (\`${Jt}\`) — the desktop's engine reads it. Run \`node <engine> status --root=.\` with the engine you end up on to show it loads, say which option you took and why, and commit it.`}function jme(e){return e.reading?e.ranked?`${L.displayName}'s repo-health series reads it as: ${e.reading}`:`${L.displayName}'s repo-health series has no reading of it yet — ${e.reading}. So the series has nothing to say about this one, and the question below is entirely about the repo.`:null}function Mme(e,t){return
|
|
123
|
+
Do not delete the measured series (\`${Jt}\`) — the desktop's engine reads it. Run \`node <engine> status --root=.\` with the engine you end up on to show it loads, say which option you took and why, and commit it.`}function jme(e){return e.reading?e.ranked?`${L.displayName}'s repo-health series reads it as: ${e.reading}`:`${L.displayName}'s repo-health series has no reading of it yet — ${e.reading}. So the series has nothing to say about this one, and the question below is entirely about the repo.`:null}function Mme(e,t,n=0){return n>0?`${e} of ${t} — open findings only; ${n} to consider and the rest of the checklist are hidden`:`${e} of ${t} — open findings only, the rest of the checklist is hidden`}function tA(e,t){return t?`${e}, under ${t}`:e}function nA(e){return e?`This reading is of ${e} alone, measured as though it were the repo: only the commits that touched it are in the series, and every path above is relative to ${e}/.`:null}function Nme(e,t,n,r){let i=e.map((e,t)=>{let n=[`${t+1}. ${e.label} (\`${e.key}\`) — ${e.absent?`no reading`:e.value}`];return e.absent?n.push(` ${e.absent}`):e.reading&&n.push(` ${e.ranked?e.reading:`no reading of it yet — ${e.reading}`}`),e.detail&&n.push(` ${e.detail.trim()}`),n.join(`
|
|
124
124
|
`)}),a=e.length;return`${`${L.displayName}'s repo-health series holds ${a} reading${a===1?``:`s`} of ${tA(t,r)}, all taken from the same commit. Here they are, worded as the tool words them.`}
|
|
125
125
|
${n?`\n${n}\n`:``}
|
|
126
126
|
${i.join(`
|
|
@@ -147,7 +147,7 @@ Read them together: they are one tree on one day, so say which of them move for
|
|
|
147
147
|
`),q:t,onCopy:n,files:r}))),e=s-1}else if(!s.trim())m(`p${i}`),h(`l${i}`);else if(p&&/^\s/.test(s)){let t=p.items.length-1,n=p.subs[t],r=n[n.length-1];r?r.items[r.items.length-1]+=`
|
|
148
148
|
`+s.trim():p.items[t]+=`
|
|
149
149
|
`+s.trim(),p.to[t]=e}else h(`l${i}`),d.length||(f=e),d.push(s)}m(`pe${o}`),h(`le${o}`)}),(0,J.jsx)(J.Fragment,{children:a})}var zj=64,Bj=e=>{if(!e||!e.length)return null;let t=e[e.length-1].v;return t==null||!Number.isFinite(t)?null:t},Oge=e=>{for(let t=e.length-1;t>=0;t--)if(e[t].v!=null)return e[t];return null};function Vj({points:e,label:t,unit:n,width:r,hint:i}){let[a,o]=(0,H.useState)(null);if(!e.length)return null;let s=a==null?null:e[a]??null,c=e.reduce((e,t)=>t.v==null?e:e+1,0),l=r>0&&c>=2;return(0,J.jsxs)(`li`,{className:`rh-tile`,children:[(0,J.jsx)(`div`,{className:`rh-tile-head`,children:(0,J.jsxs)(`span`,{className:`rh-tile-label`,children:[t,` `,(0,J.jsx)(SA,{id:i,of:t})]})}),(0,J.jsx)(`div`,{className:`rh-tile-val`,children:Ck(Bj(e),n)}),l?(0,J.jsx)(IA,{points:e,width:r,label:t,unit:n,axes:!0,onPick:o}):null,l?(0,J.jsx)(`div`,{className:`rh-scrub`,children:Ek(s??Oge(e),n)}):null]})}function kge({classics:e,width:t}){let n=e.packages.filter(e=>e.points.length).map(e=>({key:e.pkg,label:e.pkg,values:TA(e.points),bySize:e.rank}));if(!n.length)return null;let r=yA(n,`the rest`);return(0,J.jsx)(FA,{inputs:r.map(e=>({key:e.key,label:e.label,slot:e.slot,values:e.values})),points:e.packages[0].points,unit:`lines`,totalLabel:`every group`,label:`lines of source by group`,width:t,caption:she(),hint:`repohealth.packages`})}function Age({classics:e,width:t}){let[n,r]=(0,H.useState)(()=>new Set),i=(e.types??[]).filter(e=>e.points.length);if(!i.length)return(0,J.jsx)(`div`,{className:`rh-cap`,children:ghe()});let a=i.filter(e=>!n.has(e.ext)),o=i.reduce((e,t)=>e+(Bj(t.points)??0),0),s=a.reduce((e,t)=>e+(Bj(t.points)??0),0),c=phe(a.length,i.length,s,o),l=new Map([...a].sort((e,t)=>e.rank-t.rank).map((e,t)=>[e.ext,t])),u=a.map(e=>({key:e.ext,label:e.ext,values:TA(e.points),bySize:l.get(e.ext)??0})),d=u.length?yA(u,`the rest`):[],f=e=>r(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n});return(0,J.jsxs)(`div`,{className:`rh-types`,children:[(0,J.jsx)(`ul`,{className:`rh-filter rh-filter-chips`,children:i.map(e=>(0,J.jsx)(`li`,{children:(0,J.jsx)(pE,{on:!n.has(e.ext),clears:!1,onClick:()=>f(e.ext),children:mhe(e.ext,e.pack,Bj(e.points))})},e.ext))}),d.length?(0,J.jsx)(FA,{inputs:d.map(e=>({key:e.key,label:e.label,slot:e.slot,values:e.values})),points:i[0].points,unit:`lines`,totalLabel:a.length===i.length?`every type`:`these ${a.length} types`,label:`lines of source by file type`,width:t,caption:fhe(),hint:`repohealth.types`}):(0,J.jsx)(`div`,{className:`rh-cap`,children:`No type is selected, so there is nothing to stack.`}),c?(0,J.jsxs)(`div`,{className:`rh-cap`,children:[c,` `,(0,J.jsx)(Y,{onClick:()=>r(new Set),children:hhe})]}):null]})}function jge({classics:e,width:t}){let n=Bj(e.files),r=Bj(e.loc),i=Bj(e.deps),a=lhe(n,r),o=Math.max(0,Math.floor((t-8)/2));return(0,J.jsxs)(`div`,{className:`rh-mags`,children:[(0,J.jsx)(`div`,{className:`rh-mags-head`,children:`the magnitudes these are percentiles of`}),e.absent?(0,J.jsxs)(`div`,{className:`rh-cap`,children:[`This reading was not taken on the latest day — `,e.absent]}):null,a?(0,J.jsx)(`div`,{className:`rh-lead`,children:a}):null,(0,J.jsxs)(`details`,{className:`hint-more rh-more`,children:[(0,J.jsx)(`summary`,{children:`what these are`}),ohe()]}),(0,J.jsx)(kge,{classics:e,width:t}),(0,J.jsx)(Age,{classics:e,width:t}),(0,J.jsxs)(`ul`,{className:`rh-tiles rh-tiles-compact`,children:[(0,J.jsx)(Vj,{points:e.files,label:`source files`,unit:`files`,width:o,hint:`repohealth.classics.files`}),(0,J.jsx)(Vj,{points:e.deps,label:`production dependencies`,unit:``,width:o,hint:`repohealth.classics.deps`})]}),MA(i)?(0,J.jsx)(`div`,{className:`rh-cap`,children:MA(i)}):null]})}function Mge({tape:e,paths:t,width:n,caption:r,onOpenFile:i,holderHue:a}){let[o,s]=(0,H.useState)(null),c=(0,H.useRef)(null),l=n>0?qme(e,n,zj):null;if(!l)return null;let u=t=>{let n=t.currentTarget.getBoundingClientRect(),r=Math.floor((t.clientX-n.left)/Math.max(1,n.width)*e.length);return Math.max(0,Math.min(e.length-1,r))},d=o!=null&&o<e.length?{rank:o+1,lines:e[o],path:t?.[o]??null}:null;return(0,J.jsxs)(`div`,{className:`rh-chart`,children:[(0,J.jsxs)(`div`,{className:`rh-chart-head`,children:[(0,J.jsx)(`span`,{className:`rh-chart-label`,children:`the longest files`}),(0,J.jsx)(SA,{id:`repohealth.classics.tape`,of:`the longest-files tape`})]}),(0,J.jsxs)(`svg`,{width:n,height:zj,viewBox:`0 0 ${n} ${zj}`,role:`img`,"aria-label":`the ${e.length} longest source files`,style:{touchAction:`pan-y`,cursor:`pointer`},onPointerDown:e=>{let t=u(e);c.current={start:o,moved:!1},s(t===o?null:t)},onPointerMove:e=>{let t=c.current;t&&(t.moved=!0,s(u(e)))},onPointerUp:()=>{c.current=null},onPointerLeave:e=>{e.pointerType===`mouse`&&(c.current=null)},onPointerCancel:()=>{let e=c.current;c.current=null,e&&s(e.start)},children:[(0,J.jsxs)(`title`,{children:[`the `,e.length,` longest source files, biggest first`]}),l.bars.map((t,n)=>(0,J.jsx)(`rect`,{x:t.x,y:t.y,width:t.w,height:t.h,rx:1,fill:n===o?`var(--accent)`:n===0&&a?a:`currentColor`,fillOpacity:n===o||n===0&&a?1:.6-.3*(n/Math.max(1,e.length-1))},n))]}),(0,J.jsxs)(`div`,{className:`rh-scrub rh-tape-pick`,children:[(0,J.jsx)(`span`,{className:`rh-tape-pick-words${d?``:` scrub-hint`}`,children:dhe(d,!!t)}),d?.path&&i?(0,J.jsxs)(Y,{onClick:()=>i(d.path),children:[(0,J.jsx)(Nl,{size:14}),` open`]}):null]}),(0,J.jsx)(`div`,{className:`rh-cap`,children:r.lead}),(0,J.jsxs)(`details`,{className:`hint-more rh-more`,children:[(0,J.jsx)(`summary`,{children:`why these are words`}),r.more]})]})}var Hj=64,Uj=e=>e>=0&&e<UD.length?UD[e]:`currentColor`,Wj=e=>e===-1?CA:1;function Nge(e,t){let n=/^M([\d.-]+),[\d.-]+/.exec(e),r=/L([\d.-]+),[\d.-]+$/.exec(e);return n&&r?bD(e,n[1],r[1],t.toFixed(1)):null}function Pge({longest:e,width:t}){let n=(0,H.useRef)(null),[r,i]=(0,H.useState)(null),a=(0,H.useRef)(null),{points:o}=e,s=e.paths??null,c=TA(o),l=t>0?gA(c,t,Hj):null,u=l?l.flat?[Ck(l.hi)]:[Ck(l.hi),Ck(l.lo)]:[],d=l?EA(u):0,f=Math.max(1,t-d),p=l?gA(c,f,Hj):null;if(!p)return null;let m=Jme(s??o.map(()=>null),p.pts),h=(e,a=!1)=>{let o=DA(e,n.current,t,d);if(o==null)return;let s=_A(p.pts,o);s&&i(a&&s.i===r?null:s.i)},g=r==null?null:p.pts.find(e=>e.i===r)??null,_=g??p.pts[p.pts.length-1]??null,v=_he(_?o[_.i]:null,_&&s?s[_.i]:null,!!s),y=Hj+15,b=m.holders.filter(e=>e.slot===-1).length,x=p.readings,S=`the longest file over time`,C=yhe({handovers:m.handovers.length,folded:b,unnamed:m.unnamed,named:!!s});return(0,J.jsxs)(`div`,{className:`rh-chart`,children:[(0,J.jsxs)(`svg`,{ref:n,className:`rh-spark`,width:t,height:y,viewBox:`0 0 ${t} ${y}`,onPointerDown:e=>{a.current=r,h(e,!0)},onPointerMove:h,onPointerLeave:e=>{kA(e)&&i(null)},onPointerCancel:()=>i(a.current),role:`img`,"aria-label":`${S}: ${m.holders.length} file${m.holders.length===1?``:`s`} held the top spot, ${m.handovers.length} change${m.handovers.length===1?``:`s`}`,children:[(0,J.jsxs)(`title`,{children:[S,` over `,x,` readings`]}),p.flat?(0,J.jsx)(`text`,{className:`rh-tick`,x:d-5,y:p.hiY+3.5,textAnchor:`end`,children:u[0]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`line`,{x1:d,x2:t,y1:p.hiY,y2:p.hiY,stroke:`currentColor`,strokeOpacity:.1,strokeWidth:1}),(0,J.jsx)(`text`,{className:`rh-tick`,x:d-5,y:Math.max(8,p.hiY+3.5),textAnchor:`end`,children:u[0]}),(0,J.jsx)(`text`,{className:`rh-tick`,x:d-5,y:Math.min(63.5,p.loY+3.5),textAnchor:`end`,children:u[1]})]}),(0,J.jsxs)(`g`,{transform:`translate(${d},0)`,children:[(0,J.jsx)(`line`,{x1:0,x2:f,y1:63.5,y2:63.5,stroke:`currentColor`,strokeOpacity:.14,strokeWidth:1}),m.handovers.map(e=>(0,J.jsx)(`line`,{x1:e.fromX,y1:e.fromY,x2:e.x,y2:e.y,stroke:`currentColor`,strokeOpacity:.35,strokeWidth:1},`s${e.i}`)),m.runs.map((e,t)=>{let n=e.d?Nge(e.d,63.5):null;return n?(0,J.jsx)(`path`,{d:n,fill:Uj(e.slot),fillOpacity:.07,stroke:`none`},`a${t}`):null}),m.runs.map((e,t)=>e.d?(0,J.jsx)(`path`,{d:e.d,fill:`none`,stroke:Uj(e.slot),strokeOpacity:Wj(e.slot),strokeWidth:2,strokeLinecap:`round`,strokeLinejoin:`round`},t):e.dot?(0,J.jsx)(`circle`,{cx:e.dot.x,cy:e.dot.y,r:1.8,fill:Uj(e.slot),fillOpacity:Wj(e.slot)},t):null),m.handovers.map(e=>(0,J.jsx)(`circle`,{cx:e.x,cy:e.y,r:4,fill:`var(--panel)`,stroke:Uj(e.slot),strokeWidth:2},`h${e.i}`)),(0,J.jsx)(`circle`,{cx:p.endX,cy:p.endY,r:wA+1,fill:`var(--panel)`}),(0,J.jsx)(`circle`,{cx:p.endX,cy:p.endY,r:wA,fill:`var(--accent)`})]}),(0,J.jsx)(OA,{points:o,w:f,y:Hj+11,gutter:d}),g?(0,J.jsx)(AA,{at:g,h:Hj,gutter:d}):null]}),(0,J.jsx)(`div`,{className:`rh-scrub`,children:v}),m.holders.length?(0,J.jsx)(`ul`,{className:`rh-legend rh-legend-rows rh-legend-compact`,children:m.holders.map(e=>(0,J.jsxs)(`li`,{children:[(0,J.jsx)(`span`,{className:`rh-swatch rh-swatch-line`,style:{background:Uj(e.slot),opacity:Wj(e.slot)},"aria-hidden":!0}),vhe(e,o[e.first]?.day,o[e.last]?.day,x)]},e.path))}):null,C.lead?(0,J.jsx)(`div`,{className:`rh-cap`,children:C.lead}):null,(0,J.jsxs)(`details`,{className:`hint-more rh-more`,children:[(0,J.jsx)(`summary`,{children:`how it is drawn`}),C.more]})]})}function Fge({longest:e,classics:t,p95:n,width:r,onOpenFile:i}){let a=e?e.points.reduce((e,t)=>t.v==null?e:e+1,0):0,o=e&&a>=2&&r>0,s=t.tape&&t.tape.length?t.tape:null;if(!o&&!s)return null;let c=e?.points.length?e.points[e.points.length-1].v:null,l=t.files.length?t.files[t.files.length-1].v:null;return(0,J.jsxs)(`div`,{className:`rh-longest`,children:[(0,J.jsx)(`div`,{className:`rh-tile-head`,children:(0,J.jsxs)(`span`,{className:`rh-tile-label`,children:[`the longest file `,(0,J.jsx)(SA,{id:`repohealth.longest`,of:`the longest file over time`})]})}),c==null?null:(0,J.jsxs)(`div`,{className:`rh-tile-val`,children:[Ck(c,`lines`),e?.path?(0,J.jsxs)(`span`,{className:`rh-longest-path`,title:e.path,children:[` · `,fpe(e.path,44)]}):null]}),o&&e?(0,J.jsx)(Pge,{longest:e,width:r}):null,s?(0,J.jsx)(Mge,{tape:s,paths:t.tapePaths??null,width:r,onOpenFile:i,holderHue:t.tapePaths?UD[0]:void 0,caption:uhe(s.length,c==null?s[0]??null:null,n,l,e?.path??null)}):null]})}var Ige=e=>e.map(e=>e.v),Lge=14;function Rge({plot:e}){let t=e.series.find(e=>e.key===`size.p95`)??null,n=e.classics.files.length?e.classics.files:t?.points??[];if(!n.length)return null;let r=e.classics.packages.filter(e=>e.points.length===n.length).map(e=>({key:e.pkg,label:e.pkg,values:Ige(e.points),bySize:e.rank})),i=r.length?yA(r,`the rest`):[],a=Math.max(0,n.length-Lge),o=[];for(let e=a;e<n.length;e++)o.push(e);let s=e.longest?.points.length===n.length?e.longest.points:null,c=[{head:`p95`,at:e=>t?.points[e]?.v??null},...s?[{head:`longest`,at:e=>s[e]?.v??null}]:[],{head:`files`,at:t=>e.classics.files[t]?.v??null},...i.map(e=>({head:e.label,at:t=>e.values[t]??null})),{head:`deps`,at:t=>e.classics.deps[t]?.v??null}];return(0,J.jsxs)(`div`,{className:`rh-chart`,children:[(0,J.jsxs)(`div`,{className:`rh-chart-head`,children:[(0,J.jsx)(`span`,{className:`rh-chart-label`,children:`the readings, as numbers`}),(0,J.jsx)(SA,{id:`repohealth.table`,of:`the numbers table`})]}),(0,J.jsx)(`div`,{className:`rh-table-wrap rh-fade`,children:(0,J.jsxs)(`table`,{className:`rh-table`,children:[(0,J.jsx)(`thead`,{children:(0,J.jsxs)(`tr`,{children:[(0,J.jsx)(`th`,{scope:`col`,children:`day`}),c.map(e=>(0,J.jsx)(`th`,{scope:`col`,className:`num`,children:e.head},e.head))]})}),(0,J.jsx)(`tbody`,{children:o.map(e=>(0,J.jsxs)(`tr`,{children:[(0,J.jsx)(`th`,{scope:`row`,children:Tk(n[e].day)}),c.map(t=>(0,J.jsx)(`td`,{className:`num`,children:Ck(t.at(e))},t.head))]},n[e].day??e))})]})}),(0,J.jsx)(`div`,{className:`rh-cap`,children:Wpe(o.length,e.days)})]})}function zge({plot:e,repoName:t,actionsFor:n,series:r,axis:i}){let a=kk(e);if(a.kind===`none`)return null;if(a.kind===`add`)return(0,J.jsx)(`div`,{className:`rh-card`,id:`rh-own`,children:(0,J.jsx)(`div`,{className:`rh-cap`,children:ame(a.file)})});let{own:o}=a,s=r??o.series;return(0,J.jsxs)(`div`,{className:`rh-card`,id:`rh-own`,children:[(0,J.jsx)(`h3`,{className:`rh-h`,children:ime(t,o.file)}),o.absent?(0,J.jsx)(`div`,{className:`rh-cap`,children:o.absent}):null,o.problems?.length?(0,J.jsx)(`div`,{className:`rh-cap`,children:o.problems.join(` · `)}):null,s.length?(0,J.jsx)(RA,{series:s,axis:i,meansFor:e=>[e.means,ome(e.better,t)].filter(Boolean).join(` `),actionsFor:n}):null,(0,J.jsxs)(`details`,{className:`hint-more rh-more`,children:[(0,J.jsx)(`summary`,{children:ehe}),(0,J.jsx)(`p`,{children:sme(L.displayName)})]})]})}function Bge(e){let t=e.split(/\n(?=## )/),n=[],r=``;return t.forEach((e,t)=>{if(t===0&&!e.startsWith(`## `)){r=e;return}let i=e.indexOf(`
|
|
150
|
-
`),a=i===-1?e:e.slice(0,i);n.push({day:a.slice(3).trim(),body:i===-1?``:e.slice(i)})}),{preamble:r,days:n}}function Gj(e){let t=new Map,n=e.map(()=>!1);e.forEach((e,r)=>{let i=Kn(e);i===null?n[r]=!0:t.set(i,r)});for(let e of t.values())n[e]=!0;let r=[];return n.forEach((e,t)=>{e&&r.push(t)}),r}function Vge(e){return Gj(e.map(e=>e.day)).map(t=>e[t])}var Kj=e=>Vge(e);function qj(e){let t=e.variant;return{...e,points:Kj(e.points),...t&&t.kind===`override`?{variant:{...t,points:Kj(t.points)}}:{}}}function Hge(e,t){if(t===`commits`)return e;let n=e.classics,r=e.longest,i=r;if(r){let e=Gj(r.points.map(e=>e.day)),t=r.paths;i={...r,points:e.map(e=>r.points[e]),...t&&t.length===r.points.length?{paths:e.map(e=>t[e])}:{}}}return{...e,series:e.series.map(qj),classics:{...n,loc:Kj(n.loc),files:Kj(n.files),deps:Kj(n.deps),packages:n.packages.map(e=>({...e,points:Kj(e.points)})),...n.types?{types:n.types.map(e=>({...e,points:Kj(e.points)}))}:{}},...i?{longest:i}:{},...e.own?{own:{...e.own,series:e.own.series.map(qj)}}:{}}}function Uge({index:e,drawn:t,plot:n,own:r}){let i=t?.longest?t.longest.points.reduce((e,t)=>t.v==null?e:e+1,0):0;return{score:e,longest:!!t&&(i>=2||!!t.classics.tape?.length),tiles:!!t?.series.length,weight:!!t,size:!!t,table:!!n&&(n.classics.files.length>0||!!n.series.find(e=>e.key===`size.p95`)?.points.length),own:r&&!!n&&kk(n).kind!==`none`}}var Wge=e=>Object.keys(e).filter(t=>e[t]),Jj=e=>`rh-${e}`;function Gge({keys:e,refresh:t}){let n=e=>document.getElementById(Jj(e))?.scrollIntoView({behavior:`smooth`,block:`start`});return(0,J.jsxs)(`nav`,{className:`rh-nav`,"aria-label":`jump to`,children:[(0,J.jsx)(`div`,{className:`rh-nav-chips`,children:e.map(e=>(0,J.jsx)(`button`,{type:`button`,className:`fchip rh-nav-chip`,onClick:()=>n(e),children:(0,J.jsx)(`span`,{className:`fchip-pill`,children:npe[e]})},e))}),t]})}function Kge({busy:e,label:t,onClick:n}){return(0,J.jsxs)(Y,{className:`rh-nav-refresh`,type:`button`,onClick:n,children:[(0,J.jsx)(Wl,{size:14,className:e?`spin`:void 0,"aria-hidden":!0}),` `,t]})}function qge({axis:e,onAxis:t,commits:n}){let r=n!==`absent`;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`ts-filter rh-axis`,role:`group`,"aria-label":`x axis`,children:[(0,J.jsx)(`span`,{className:`ctx-stackpick-lab`,children:`x axis`}),(0,J.jsx)(pE,{on:e===`weeks`,clears:!1,onClick:()=>t(`weeks`),children:`weeks`}),r?(0,J.jsx)(pE,{on:e===`commits`,clears:!1,onClick:()=>t(`commits`),children:`commits`}):null,(0,J.jsxs)(TE,{of:`the x axis`,children:[(0,J.jsxs)(`p`,{children:[mk(`weeks`),`.`]}),r?(0,J.jsxs)(`p`,{children:[mk(`commits`),`.`]}):null]})]}),r?null:(0,J.jsx)(`div`,{className:`rh-cap rh-gutter`,children:hk(L.displayName)}),(0,J.jsx)(`div`,{className:`rh-cap rh-gutter rh-scrubhint`,children:rpe})]})}function Yj({id:e,children:t}){let[n,r]=JD();return(0,J.jsx)(`div`,{className:`rh-card`,id:Jj(e),ref:r,children:t(n)})}function Jge({days:e}){return e.length?(0,J.jsxs)(`details`,{className:`hint-more rh-notes`,children:[(0,J.jsx)(`summary`,{children:Ype(e.length)}),e.map(e=>(0,J.jsx)(`div`,{className:`tr-say rh-doc`,children:(0,J.jsx)(Rj,{src:`## ${e.day}${e.body}`,q:``,onCopy:e=>void gp(e)})},e.day))]}):null}var Yge=16,Xge=1500;function Zge({repo:e,res:t,view:n,onRemedy:r,scope:i,onScope:a,onOpenFile:o}){let s=n?.series??null,c=n?.plot??null,[l,u]=(0,H.useState)(!1),[d,f]=(0,H.useState)(0),[p,m]=(0,H.useState)(null),[h,g]=(0,H.useState)(null),[_,v]=(0,H.useState)(!1),y=_E(1e3),{reload:b}=t,x=!!n?.run;(0,H.useEffect)(()=>{if(!x)return;let e=window.setInterval(()=>b({quiet:!0}),Xge);return()=>window.clearInterval(e)},[x,b]);let[S,C]=(0,H.useState)(ane),w=e=>{q(`action:repohealth.axis.${e}`),one(e),C(e)},[T,E]=(0,H.useState)(null),D=(0,H.useCallback)(e=>E(e),[]),O=S===`commits`&&T===`absent`?`weeks`:S,k=(0,H.useMemo)(()=>c?Hge(c,O):null,[c,O]),A=n?.scopes??[],j=(n?.measure?.groups??[]).filter(e=>e&&e!==`.`),[M,N]=(0,H.useState)(!1),[P,F]=(0,H.useState)(!1);async function I(t){if(e&&!P){F(!0);try{let n=await U.repoHealthScopes(e.id,t);i&&!n.scopes.includes(i)&&a(null),await b({quiet:!0})}catch(e){m(String(e?.message||e))}finally{F(!1)}}}async function ee(r=!1,a=!1){if(!l&&e){q(`action:repohealth.refresh`),u(!0),f(Date.now()),m(null),g(null);try{let o=await U.repoHealthRefresh(e.id,i,r,r?n?.engine?.approveToken:void 0,a),s=o.error;typeof s==`string`&&!o.engine?g(s):t.set(o)}catch(e){m(String(e?.message||e))}finally{u(!1)}}}let te={behind:n?.behind,lastSha:s?.lastSha,lastDay:s?.lastDay,headSha:n?.head?.sha},ne=vpe(te),re=ype({...te,rows:s?.rows,days:s?.days}),ie=n?.measure??null,ae=!!e&&n?.engine?.kind===`bundled`&&n?.engine?.needsApproval!==!0,oe=Epe(s?.versions,ie?.engineVersion??s?.preregVersion,dee(ie),ae),se=hpe({kind:n?.engine?.kind??null,ownSkipped:n?.engine?.ownSkipped,version:ie?.engineVersion,packs:ie?.packs}),ce=!!n&&!n.tool,le=Cpe(s?.staleRows),ue=kpe(n?.run,y),de=n?.last&&!Dpe(n.last,n.readError,!!n.series)?n.last:null,fe=ae&&(!!oe||!!de?.refused),pe=n?.narrative??null,me=bpe(s),he=xpe(de?.warnings),ge=pe?Bge(pe.text):null,_e=ge?[...ge.days].reverse():[],ve=ca(n),ye=n?.tool&&s?wte(ve,n?.plotError??null):null,be=c?.series.find(e=>e.key===`size.p95`)?.last??null,xe=e=>Dme({absent:e.absent,last:e.last,readings:e.points.reduce((e,t)=>t.v==null?e:e+1,0)}),Se=e=>({key:e.key,label:e.label,value:Ck(e.last,e.unit),reading:wk(e.reading),ranked:e.reading?.rank!=null,detail:e.detail,...xe(e)?{absent:xe(e)}:{}}),Ce=t=>{r&&e&&(q(`action:repohealth.ask`),r(Ome(Se(t),e.repoName,i),e,t.label.toLowerCase()))},we=(t,i)=>{r&&e&&(q(`action:repohealth.askindex`),r(hme(t,e.repoName,jk(c,n?.engine?.kind,``,i)),e,`the health index, week of ${t.week}`))},Te=(t,i,a,o)=>{r&&e&&(q(`action:repohealth.asktrend`),r(gme(t,i,e.repoName,{...jk(c,n?.engine?.kind,i,a),now:o??null}),e,`the health index trend`))},Ee=()=>{r&&e&&(q(`action:repohealth.qualityrun`),r(_me(e.repoName,jk(c,n?.engine?.kind,``,null)),e,`a design-quality run`))},De=()=>{r&&e&&c?.series.length&&(q(`action:repohealth.askall`),r(Nme(c.series.map(Se),e.repoName,se,i),e,i?`all the readings of ${i}`:`all the readings`))},Oe=n?.engine?.needsApproval===!0,ke=n?.engine?.kind===`repo`&&!Oe&&!!(de?.error||n.readError),Ae=()=>{r&&e&&n&&(q(`action:repohealth.adoptengine`),r(Ame(e.repoName,de?.error??n.readError,n.engine?.bundled),e,`the repo-health engine`))},je=re||se?(0,J.jsxs)(J.Fragment,{children:[re?(0,J.jsx)(`p`,{children:xk()}):null,ne?(0,J.jsxs)(`p`,{children:[ne,pe?(0,J.jsxs)(J.Fragment,{children:[` · `,wpe(Gp(pe.mtime))]}):null,n?.head?(0,J.jsxs)(J.Fragment,{children:[` · `,Tpe(Gp(n.head.ts))]}):null,me?(0,J.jsxs)(J.Fragment,{children:[` · `,me]}):null]}):null,se?(0,J.jsx)(`p`,{children:se}):null]}):null,Me=e&&!ce&&!Oe?(0,J.jsx)(Kge,{busy:l,onClick:()=>void ee(),label:l?Sk(s,y-d):gpe(s)}):null,Ne=!!e&&!i&&!ce,Pe=Uge({index:Ne,drawn:k,plot:c,own:!!e}),Fe=Wge(Pe);return(0,J.jsxs)(`div`,{className:`rh-region`,children:[(0,J.jsxs)(`div`,{className:`section-head rh-head`,children:[(0,J.jsx)(`span`,{className:`section section-hint rh-status${je?``:` rh-push`}`,children:re??xk()}),je?(0,J.jsx)(TE,{of:`this series`,children:je}):null]}),e&&!ce&&(A.length||j.length)?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`fchips wrap rh-scope`,role:`group`,"aria-label":`which part of the repo`,children:[(0,J.jsx)(`span`,{className:`ctx-stackpick-lab`,children:`reading of`}),(0,J.jsx)(pE,{on:i===null,clears:!1,onClick:()=>a(null),children:Qpe}),A.map(e=>(0,J.jsx)(pE,{on:i===e,clears:!1,onClick:()=>{q(`action:repohealth.scope`),a(e)},children:e},e)),j.length?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`fchips-gap`,"aria-hidden":!0}),(0,J.jsxs)(pE,{on:M,clears:!1,onClick:()=>N(e=>!e),children:[(0,J.jsx)(cl,{size:12}),` break down…`]})]}):null]}),i?(0,J.jsx)(`div`,{className:`section section-hint`,children:$pe(i)}):null,M?(0,J.jsxs)(`div`,{className:`section section-hint`,children:[(0,J.jsx)(`div`,{children:tme(j.length)}),(0,J.jsx)(`div`,{className:`fchips wrap rh-filter-chips`,role:`group`,"aria-label":`subtrees to measure`,children:j.map(e=>(0,J.jsx)(pE,{on:A.includes(e),busy:P&&A.includes(e),onClick:()=>void I(A.includes(e)?A.filter(t=>t!==e):[...A,e]),children:e},e))}),(0,J.jsx)(`div`,{children:eme()})]}):null]}):null,(0,J.jsx)($,{res:t,empty:!s&&!c,thing:`the repo-health series`,noun:`reading`,children:ce?Wi(`absent`):n?.engine?.needsApproval&&n.engine.kind===`repo`?`Not read yet — the repo's own engine is waiting for your approval.`:n?.engine?.needsApproval&&n.engine.kind===`bundled`?`Measured without this repo's own readings — they wait for your approval.`:n?.readError?mpe(n.readError):i?nme(i,ie?.commits):ppe(ie?.commits,n?.stepTimeoutMs)}),oe?(0,J.jsx)(`div`,{className:`section section-hint`,children:oe}):null,le?(0,J.jsx)(`div`,{className:`section section-hint`,children:le}):null,ue?(0,J.jsx)(`div`,{className:`section section-hint`,children:ue}):null,fe?(0,J.jsx)(`div`,{className:`section`,children:(0,J.jsxs)(uT,{className:`key rh-verb`,confirm:Mpe,onConfirm:()=>void ee(!1,!0),children:[(0,J.jsx)(Wl,{size:12,"aria-hidden":!0}),` `,l?Sk(s,y-d):jpe]})}):null,de?(0,J.jsxs)(`div`,{className:`section section-hint`,children:[Ope(de),de.at?(0,J.jsxs)(J.Fragment,{children:[` (`,Gp(de.at),`)`]}):null,de.refused?(0,J.jsx)(`pre`,{className:`update-log rh-refusal`,children:de.refused.text}):null,he?(0,J.jsx)(`div`,{children:he}):null]}):null,Oe&&e?(0,J.jsxs)(`div`,{className:`section section-hint`,children:[(0,J.jsx)(`div`,{children:n?.readError}),n?.engine?.path?(0,J.jsx)(`div`,{children:(0,J.jsx)(`code`,{children:n.engine.path})}):null,(0,J.jsxs)(`div`,{className:`rh-tile-acts`,children:[(0,J.jsxs)(Y,{type:`button`,className:`rh-verb`,onClick:()=>void ee(!0),children:[(0,J.jsx)(Hc,{size:12,"aria-hidden":!0}),` `,l?Sk(s,y-d):cme(n?.engine?.kind===`repo`?`repo`:`bundled`,s)]}),n?.engine?.kind===`repo`?null:(0,J.jsxs)(Y,{type:`button`,className:`rh-verb`,onClick:()=>void ee(),children:[(0,J.jsx)(Wl,{size:12,"aria-hidden":!0}),` `,lme(s)]})]})]}):null,ke&&r&&e?(0,J.jsx)(`div`,{className:`section`,children:(0,J.jsxs)(Y,{className:`rh-verb`,type:`button`,onClick:Ae,children:[(0,J.jsx)(al,{size:12,"aria-hidden":!0}),` `,kme,`…`]})}):null,h?(0,J.jsx)(`div`,{className:`section section-hint`,children:h}):null,p?(0,J.jsx)(`div`,{className:`section section-hint`,children:Spe(p)}):null,ye?(0,J.jsx)(`div`,{className:`section section-hint`,children:ye}):null,Fe.length||Me?(0,J.jsx)(Gge,{keys:Fe,refresh:Me}):null,Ne||k?(0,J.jsx)(qge,{axis:O,onAxis:w,commits:T}):null,Ne&&e?(0,J.jsx)(Zhe,{repoId:e.id,axis:O,onCommits:D,seriesStamp:`${s?.lastSha??``}:${s?.rows??0}`,onAsk:r?we:void 0,onAskTrend:r?Te:void 0,onQualityRun:r?Ee:void 0}):null,k&&c?(0,J.jsxs)(J.Fragment,{children:[Ok(s?.versions)?(0,J.jsx)(`div`,{className:`rh-cap rh-gutter`,children:Ok(s?.versions)}):null,(0,J.jsx)(`div`,{className:`section rh-prov`,children:rme(L.displayName)}),fme(c.central).map(e=>(0,J.jsx)(`div`,{className:`rh-cap rh-gutter`,children:e},e)),Pe.longest?(0,J.jsx)(Yj,{id:`longest`,children:t=>(0,J.jsx)(Fge,{longest:k.longest,classics:k.classics,p95:be,width:t,onOpenFile:e&&o?t=>o(e.id,c.scope?`${c.scope.replace(/\/+$/,``)}/${t}`:t):void 0})}):null,(0,J.jsx)(khe,{series:k.series,windowReadings:c.windowReadings,minReadings:c.minReadings,axis:O,onAsk:r&&e?Ce:void 0,onAskAll:r&&e&&c.series.length?De:void 0}),(0,J.jsx)(whe,{claudeMd:k.series.find(e=>e.key===`context.claudeMdChars`)??null,descriptions:k.series.find(e=>e.key===`context.descChars`)??null,context:c.context}),(0,J.jsx)(Yj,{id:`size`,children:e=>(0,J.jsx)(jge,{classics:k.classics,width:e})}),Pe.table?(0,J.jsx)(Yj,{id:`table`,children:()=>(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Rge,{plot:c}),(0,J.jsxs)(`details`,{className:`hint-more rh-more`,children:[(0,J.jsx)(`summary`,{children:`not drawn here`}),(0,J.jsx)(`p`,{children:Gpe()}),(0,J.jsx)(`p`,{children:Ape(!!n?.page)})]})]})}):null,e?(0,J.jsx)(zge,{plot:c,repoName:e.repoName,series:k.own?.series,axis:O,actionsFor:r?e=>(0,J.jsxs)(Y,{className:`rh-verb`,type:`button`,onClick:()=>Ce({...e,detail:e.means}),children:[(0,J.jsx)(al,{size:12,"aria-hidden":!0}),` `,Kpe,`…`]}):void 0}):null]}):null,ge&&ge.preamble?(0,J.jsxs)(`details`,{className:`hint-more rh-notes`,open:_,onToggle:e=>v(e.currentTarget.open),children:[(0,J.jsx)(`summary`,{children:`how to read this`}),(0,J.jsx)(`div`,{className:`tr-say rh-doc`,children:(0,J.jsx)(Rj,{src:ge.preamble,q:``,onCopy:e=>void gp(e)})})]}):null,(0,J.jsx)(Jge,{days:_e})]})}function Qge({repo:e,onOpen:t}){let n=Rr(e);return n===`unknown`?null:n===`absent`?(0,J.jsx)(`div`,{className:`act-cants`,children:(0,J.jsx)(wE,{children:Wi(n)})}):(0,J.jsxs)(`button`,{className:`more-act`,onClick:t,children:[(0,J.jsx)(hl,{size:Yge}),`over time`]})}function $ge(e,t){return{when:e?.when??t??{kind:`now`},parkedAt:e?.parkedAt??null}}var Xj=`send.compose`;function e_e(e,t){return t!==`refused`||e.padId===void 0&&e.ackId===void 0?e:{...e,padId:void 0,ackId:void 0}}var Zj=(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone||``}catch{return``}})(),t_e=e=>new Date(e-new Date(e).getTimezoneOffset()*6e4).toISOString().slice(0,16);function Qj(e,t,n=0){let r=new Date;return r.setDate(r.getDate()+n),r.setHours(e,t,0,0),r.getTime()}function n_e(){let e=Date.now(),t=Qj(20,0),n=t<=e,r=(()=>{let e=new Date;return e.setDate(e.getDate()+((8-e.getDay())%7||7)),e.setHours(9,0,0,0),e.getTime()})();return[{key:`1h`,label:`in 1h`,at:e+36e5},{key:`3h`,label:`in 3h`,at:e+108e5},{key:`eve`,label:n?`tomorrow 20:00`:`tonight 20:00`,at:n?Qj(20,0,1):t},{key:`tom`,label:`tomorrow 09:00`,at:Qj(9,0,1)},{key:`mon`,label:`Mon 09:00`,at:r}]}var $j=[0,30,60,120,180,360],r_e=[10,25,50,75];function eM(e){let t=typeof e==`string`?Number(e.trim()):typeof e==`number`?e:NaN;if(!Number.isFinite(t))return null;let n=Math.round(t);return n>=1&&n<=100?n:null}function i_e(e,t){let n=new Set(r_e);for(let r of[e,t]){let e=eM(r);e!=null&&n.add(e)}return[...n].sort((e,t)=>e-t)}function a_e(e){let t=e.trim();if(!t)return`Type a percentage — 1 to 100 — or pick one above.`;if(eM(t)!=null)return null;let n=Number(t);return Number.isFinite(n)?Math.round(n)===0?`0% left is met by every meter, which is what no condition already says — tap that instead.`:`${t}% is outside 1–100: a window reads 100% at its reset and 0% when it is spent.`:`“${t}” is not a number. 1 to 100.`}var o_e=[{min:0,label:`skip it`},{min:120,label:`up to 2h late`},{min:720,label:`up to 12h late`},{min:4320,label:`up to 3 days late`}],tM=e=>({kind:`at`,rule:{kind:`once`,at:Date.now()+e,offsetMin:0},graceMin:120}),s_e=(e=!1)=>({kind:`at`,rule:{kind:`window`,window:e?`weekly`:`session`,edge:`before`,offsetMin:-60,oneShot:!0},graceMin:120}),nM=(e,t)=>!t||e.kind!==`window`||e.periodId||e.window===`weekly`?e:{...e,window:`weekly`,guardWindow:e.guardWindow===`weekly`?void 0:e.guardWindow};function rM(e){if(e<60)return`${e}m`;let t=Math.floor(e/60),n=e%60;return n?`${t}h${n}m`:`${t}h`}function iM(e){let t=typeof e==`number`?e:typeof e==`string`?aM(e):NaN;if(!Number.isFinite(t))return null;let n=Math.round(t);return n>=1&&n<=1440?n:null}function aM(e){let t=e.trim().toLowerCase().replace(/\s+/g,``),n=/^(?:(\d+(?:\.\d+)?)h)?(?:(\d+(?:\.\d+)?)m?)?$/.exec(t);return!t||!n||n[1]==null&&n[2]==null?NaN:Number(n[1]??0)*60+Number(n[2]??0)}function c_e(e,t){let n=new Set($j.filter(e=>e>0));for(let r of[e,t]){let e=iM(r);e!=null&&n.add(e)}return[...n].sort((e,t)=>e-t)}function l_e(e){let t=e.trim();if(!t)return`Type a lead — 45m, 4h, 1h30 — or pick one above.`;if(iM(t)!=null)return null;if(t.startsWith(`-`))return`Type how long before, without a minus — the segment above already says before.`;let n=aM(t);return Number.isFinite(n)?Math.round(n)===0?`0 before the reset is the reset itself — that is right after it resets, above.`:`Up to 24h before: the host keeps a lead within a day of the reset.`:`“${t}” is not a duration. Try 45m, 4h or 1h30.`}function oM(e,t){return e.kind===`repo`?t.kind!==`now`:e.kind===`repos`&&t.kind!==`at`}function u_e(e,t){return(e.kind===`repo`||e.kind===`repos`)&&e.flagWhenDone===!0&&oM(e,t)?!0:void 0}var sM=e=>e.kind===`repo`||e.kind===`repos`?e.budget:void 0;function cM(e,t){if(e.kind!==`repo`&&e.kind!==`repos`)return e;let{budget:n,...r}=e;return t?{...r,budget:t}:r}function d_e(e,t,n){let r=(e.kind===`repo`||e.kind===`repos`)&&e.flagWhenDone&&(!n||oM(e,n))?`, flagged when done`:``;switch(e.kind){case`session`:return t.sessionTitle(e.sessionId);case`repo`:return`${t.repoName(e.cwd)} · a new session${e.resume?`, continued`:``}`+(e.closeWhenDone===!0?`, closes when done`:e.closeWhenDone===!1?`, kept open`:``)+r+UT(e.launch)+(e.budget?`, budget ${yr(e.budget)}`:``);case`repos`:return(e.dirs.length===1?t.repoName(e.dirs[0]):`${e.dirs.length} repos`)+r+UT(e.launch)+(e.budget?`, budget ${yr(e.budget)}`:``);case`shell`:return`${t.buildName(e.cwd,e.buildId)} · ${t.repoName(e.cwd)}`}}function f_e(e,t,n){let r=BT(e.target),i=p_e(e,t,n)+(UT(r)?` · ${HT(r)}`:``);return(e.target.kind===`repo`||e.target.kind===`repos`)&&e.target.budget?`${i} · budget ${yr(e.target.budget)}`:i}function p_e(e,t,n){if(e.when.kind===`at`)return n==null?e.when.rule.kind===`window`?`Save for ${va(e.when.rule)}`:`pick a time it can still reach`:`Save for ${Pe(n)}`;if(e.when.kind===`after`){let n=jn(e.when.title,e.when.onlyIfOk);switch(e.target.kind){case`session`:return`Send to ${t.sessionTitle(e.target.sessionId)} ${n}`;case`repo`:return`Queue for ${t.repoName(e.target.cwd)} · a new session ${n}`;case`repos`:{let r=e.target.dirs.length;return`Fan out to ${r===1?t.repoName(e.target.dirs[0]):`${r} repos`} ${n}`}case`shell`:return`${t.buildName(e.target.cwd,e.target.buildId)} cannot wait for another item`}}let r=e.when.kind===`idle`;switch(e.target.kind){case`session`:return r?`Send to ${t.sessionTitle(e.target.sessionId)} when it's free`:`Send to ${t.sessionTitle(e.target.sessionId)}`;case`repo`:return r?`Queue for ${t.repoName(e.target.cwd)} · a new session when this repo is free`:`Start in ${t.repoName(e.target.cwd)}`;case`repos`:{let n=e.target.dirs.length,r=n===1?t.repoName(e.target.dirs[0]):`${n} repos`;return e.sequential?`Queue in ${r}`:`Fan out to ${r}`}case`shell`:return r?`Queue ${t.buildName(e.target.cwd,e.target.buildId)}`:`Run ${t.buildName(e.target.cwd,e.target.buildId)}`}}function m_e(e){return/^queue\b/i.test(e)?e:`Queue · ${e}`}var lM=`those words are running now — changing their when would describe a run that never happened, and posting them again would run them twice`,h_e=`this row is one repo's work — send it to several repos and it would be a second copy beside it, so drop its clock first`,g_e=`this row runs a prompt — a build is a different thing, so post it as its own and delete this one`;function uM(e,t){return e.when.kind===`at`?e.target.kind===`session`?!t||t.state===`done`||t.state===`canceled`?{kind:`post`}:t.state===`starting`||t.state===`running`?{kind:`refuse`,why:lM}:{kind:`patch`}:{kind:`upsert`}:!t||t.state===`done`||t.state===`canceled`?{kind:`post`}:t.state===`starting`||t.state===`running`?{kind:`refuse`,why:lM}:e.target.kind===`repos`?{kind:`refuse`,why:h_e}:e.target.kind===`shell`?{kind:`refuse`,why:g_e}:{kind:`patch`}}function __e(e){return e.kind===`now`?`re-timed — the same row, and it goes as soon as the desktop can take it`:e.kind===`idle`?`re-timed — the same row, waiting its turn instead of waiting for its clock`:e.kind===`after`?`re-timed — the same row, and it goes ${jn(e.title,e.onlyIfOk)}`:`re-timed — the same row`}var v_e=`no connection — this row's clock lives on the desktop and nothing here changed. Its words are still in the box.`,dM=(e,t)=>e.kind===`at`&&t==null&&e.rule.kind===`once`?`the time it resolves to has already passed`:null,y_e=`write the prompt first`;function b_e(e,t,n){let r=e.prompts.map(e=>e.trim()).filter(Boolean);if(e.target.kind!==`shell`&&!r.length)return y_e;if(e.target.kind===`repos`&&!e.target.dirs.length)return`pick at least one repo`;if(e.target.kind===`repo`&&!e.target.cwd)return`pick the repo it runs in`;if(e.target.kind===`session`&&!e.target.sessionId)return`pick where it goes`;let i=dM(e.when,t);if(i)return i;if(e.when.kind===`at`&&e.target.kind===`shell`)return`a build cannot be scheduled — the clock only fires prompts`;if(e.when.kind===`at`&&e.target.kind===`session`&&!e.target.cwd)return`this session has no repo on it — the clock has nowhere to reopen its conversation`;if(e.when.kind===`after`&&!e.when.id)return`pick the item it waits for`;if(e.when.kind===`after`&&e.target.kind===`shell`)return`a build cannot wait for another item — a chain only queues prompts`;if(e.when.kind===`after`&&e.target.kind===`repos`&&r.length>1)return`a sweep is one prompt — chain a single repo, or send one turn`;let a=uM(e,n);return a.kind===`refuse`?a.why:null}var fM={activity:`Activity`,automation:`Automation`,weekburn:`Week-end burn`,whatsnew:`What's new`},x_e=216e5,S_e=e=>e?`If that item fails, this one fails too and says so — it is never left waiting for something that cannot happen twice.`:`It runs either way — “run the tests, then tell me what happened” wants to run when they fail. Tick it to run only after a success.`,C_e=`The desktop holds this, with no deadline: if it was asleep when that item finished, this still goes in when it wakes. A chain is not a schedule — it has no clock to arm and appears in ${fM.activity} as work, not in ${fM.automation}.`;function w_e(e,t,n){let r=e=>e.state===`running`||e.state===`starting`?0:e.state===`queued`||e.state===`blocked`?1:2;return e.filter(e=>n&&e.id===n||e.trigger.kind===`at`&&Ia(e.trigger.rule)?!1:r(e)<2||e.state!==`canceled`&&t-(e.settledAt??e.createdAt)<=x_e).sort((e,t)=>r(e)-r(t)||(r(e)===2?(t.settledAt??t.createdAt)-(e.settledAt??e.createdAt):(e.order??0)-(t.order??0)||e.createdAt-t.createdAt))}function pM(e,t,n){return t.kind!==`at`||e.kind!==`session`||!e.cwd?null:`This goes to ${n}. A session lasts as long as its process, so if that one has gone when the clock comes round, the desktop reopens the conversation it was in and sends it there.`}var mM=(e,t)=>e.kind===`at`?ri(e.rule,Date.now(),t):null;function T_e(e){return e.kind===`repos`?{off:`all at once — a fresh session in each repo`,on:`one at a time — it waits in each repo's backlog and opens its own session there`}:e.kind===`repo`?{off:`start it straight away, alongside anything else queued for this repo`,on:`wait for this repo's other queued sessions to finish first`}:null}var hM={session:`the session window`,weekly:`the weekly window`},E_e={session:`checks the session meter`,weekly:`checks the weekly meter`},gM=e=>e.window===`weekly`?`weekly`:`session`,_M=e=>e.guardWindow??gM(e);function D_e(e){let t=gM(e),n=_M(e),r=t===`weekly`?`session`:`weekly`,[i,a]=[hM[t],hM[r]],o=bn(hM,n,`the window the rule names`),s=e.minPctLeft;if(e.edge===`after`&&n===t)return`A window that has just reset is empty by definition, so there is nothing to ask about ${i} at the instant this fires — written like this the condition is dropped and the rule runs every time. Point it at ${a}, or set it back to no condition.`;let c=e.oneShot===!0?` It stays armed for the next reset, and the next, until one meets the condition — then it runs once.`:``;return n===t?`If less than ${s}% of ${i} is left when it fires, nothing runs and you get a notification saying it was skipped.${c} A meter the host cannot read counts as not met — the condition exists to stop work, so an unreadable one stops it too.`:`It waits for ${i} to reset, then asks about ${o}: unless at least ${s}% of that one is left, nothing runs and you get a notification saying it was skipped.${c}`}function O_e(e){let t=e.hours;if(!t)return`Any hour. Set a window and the rule still becomes due when the anchor above says — it waits for the window to open, and how late it counts as is measured from that opening, not from the anchor.`;if(t.from===t.to)return`Both ends name the same minute, which is a window with no width. It is dropped rather than guessed at, so the rule would run at any hour — move one of them.`;let n=`${String(Math.floor(t.from/60)).padStart(2,`0`)}:${String(t.from%60).padStart(2,`0`)}`,r=e.tz?`, ${e.tz}`:``,i=t.from>t.to?` — overnight, through midnight`:``;return`Only ${Wee(e)}${i}${r}. Due outside it, the run waits for ${n} and its lateness is counted from there.`}function k_e(e){let t=new Set;for(let n of e.matchAll(/\.claude\/inbox\/[A-Za-z0-9._-]+/g))t.add(n[0]);return[...t]}function A_e(e,t,n){return n===0?`tick the rows to move first`:e.kind===`at`&&t==null&&e.rule.kind===`once`?`the time it resolves to has already passed`:e.kind===`after`&&!e.id?`pick the item it waits for`:null}function j_e(e,t){return`Re-time ${e===1?`it`:`these ${e}`} — ${t}`}var vM=`next in line`;function M_e(e,t,n){return!e||n<=0?null:`Held: ${e}${t?` — resumes ${Pe(t)}`:``}. These are queued work, so whatever when you pick, they wait for the budget like the rest of the queue.`}function N_e(e,t,n){switch(e.trigger.kind){case`now`:case`idle`:case`budget`:return!0;case`at`:return typeof e.nextAt==`number`&&e.nextAt<=t;case`after`:{let t=n.get(e.trigger.id);return t?t.state===`done`||!e.trigger.onlyIfOk&&(t.state===`failed`||t.state===`canceled`):!1}default:return!1}}function yM(e,t,n){return e.state!==`queued`&&e.state!==`blocked`||e.blockReason!==`budget`||xi(e,t)?!1:N_e(e,t,n??new Map)}function P_e(e,t,n=Date.now()){let r=new Map(t.map(e=>[e.id,e]));return e.filter(e=>{let t=r.get(e);return!!t&&yM(t,n,r)})}function bM(e){return`let ${e===1?`it`:`these ${e}`} past the budget`}function xM(e,t){return`${e<t?`${e} of the ${t} you ticked are held by the budget; the rest wait on something else. `:``}Lifts the budget for ${e===1?`this row`:`these ${e}`} and nothing else — ${e>1?`rows in the same repo still run one at a time, `:``}wait until free, the session cap and each row's own when all still apply. It lasts until the row starts, or until this budget window resets.`}function F_e(e){return`let ${e} past the budget?`}function I_e(e){return`let ${e===1?`it`:e} past the budget — ${e===1?`it runs`:`they run`} in turn`}function SM(e){return e?`starts it this second in a session of its own — skips the queue: the budget, one at a time and wait until free`:`goes into its session this second — skips the queue: the budget and waiting for that session to be free`}var CM=`another agent is working in this checkout — this starts a second one beside it`;function wM(e,t,n,r){return e?t.some(t=>t.id!==n&&t.cwd===e&&(t.state===`starting`||t.state===`running`))?!0:(r??[]).some(t=>t.running&&t.turnActive===!0&&t.cwd===e):!1}var L_e=`queues an item in its backlog — it runs in turn`;function TM(e,t){return`From ${e}'s opt-ins — ${t}`}function EM(e,t,n){let r=Ai(e),i=Zi(e,t.repoName);if(!r||i==null)return null;let a=r.action;if(a.kind!==`agent`&&a.kind!==`schedule`)return null;let o={prompts:[i],target:{kind:`repo`,cwd:t.worktreePath},cwdHint:t.worktreePath,repoId:t.id,origin:TM(t.repoName,r.title)};if(a.kind===`agent`)return o;let s=Nee(e,n||`UTC`);return s?{...o,target:{kind:`repo`,cwd:t.worktreePath,launch:{model:a.model}},when:{kind:`at`,rule:s,graceMin:a.graceMin,name:r.title,waitUntilFree:!0}}:null}function R_e(e){return e.filter(e=>{let t=Ai(e.id)?.action.kind;return t===`agent`||t===`schedule`})}function z_e(e){return R_e(e).length>=2}function B_e(e){return`walk me through these ${e}…`}function V_e(e,t){let n=ute(e,t.repoName);return n==null?null:{prompts:[n],target:{kind:`repo`,cwd:t.worktreePath},cwdHint:t.worktreePath,repoId:t.id,origin:TM(t.repoName,`walk through ${e.length} offers`)}}function H_e(e){return`${e} you said not for me`}function U_e(e){return`${e} ${e===1?`doesn't`:`don't`} fit this repo`}function W_e(e){return`Started here · ${e}`}function G_e(e){return new Date(e).toLocaleDateString(void 0,{day:`numeric`,month:`short`})}function K_e(e,t=G_e){let n=`Sent ${t(e.at)}`;switch(e.status){case`waiting`:return`${n} — waiting in this repo's backlog.`;case`running`:return`${n} — running now.`;case`open`:return`${n} to a session that is still open.`;case`done`:return`${n} — that run finished, but it is not set up yet.`;case`failed`:return`${n} — that run failed.`;case`canceled`:return`${n} — that row was cancelled.`;case`ended`:return`${n} — that session has closed, and it is not set up yet.`;default:return`${n} — this app version cannot say what became of it.`}}var q_e=`already sent — again?`;function J_e(e,t){return`Nothing to offer here right now — every opt-in is either on or answered.${e+t>0?` What you turned down and what does not fit this repo are folded below.`:``}`}var Y_e=`Optional things this repo can turn on. Nothing here is a problem, and nothing is sent until you send it.`,X_e=`Opt-ins compare nothing: they are offers, not readings. Each is on, off or not for you, and none is counted in the repo's badge.`,Z_e=16;function DM(e){switch(e.kind){case`fix`:return(0,J.jsx)($s,{size:14});case`open`:return e.to===`series`?(0,J.jsx)(hl,{size:14}):(0,J.jsx)(kl,{size:14});case`agent`:return(0,J.jsx)(al,{size:14});case`schedule`:return(0,J.jsx)(Ss,{size:14})}}function Q_e({repo:e,onSeed:t,onSeries:n,onCapture:r,onChecklist:i}){let a=e?.id??``,o=fh(`optins:${a}`,()=>U.optIns(a),{enabled:!!a}),s=o.data,[c,l]=(0,H.useState)(null),[u,d]=(0,H.useState)(null),[f,p]=(0,H.useState)([]),[m,h]=(0,H.useState)(!1),[g,_]=(0,H.useState)(!1);async function v(e,t){if(a&&!c){q(t===`declined`?`action:optins.decline`:t===`done`?`action:optins.done`:`action:optins.clear`),l(e),d(null),p([]);try{let n=await U.optInChoice(a,e,t);n.ok&&n.report?o.set(n.report):n.ok?o.reload({quiet:!0}):d(n.error||`the desktop did not store it`)}catch(e){d(String(e.message||e))}finally{l(null)}}}async function y(e,t){if(a&&!c){q(`action:optins.fix`),l(e),d(null),p([]);try{let e=await U.complianceFix(a,[t]);e.ok?(p(e.notes??[]),e.report&&i?.(e.report),o.reload({quiet:!0})):d(e.error||`the fix did not run`)}catch(e){d(String(e.message||e))}finally{l(null)}}}function b(e){e&&t&&(q(`action:optins.seed`),t(e))}let x=See(s?.rows??[]);function S(i,a){let o=Ai(i.id),s=o.action,l=c===i.id?`working…`:o.verb;return s.kind===`fix`?(0,J.jsxs)(Y,{onClick:()=>void y(i.id,s.fix),children:[DM(s),` `,l]}):s.kind===`open`&&s.to===`series`?(0,J.jsxs)(Y,{onClick:()=>{q(`action:optins.series`),n()},children:[DM(s),` `,l]}):s.kind===`open`?!e||!r?(0,J.jsx)(wE,{children:`The capture screen cannot be opened from here.`}):(0,J.jsxs)(Y,{onClick:()=>{q(`action:optins.capture`),r(e)},children:[DM(s),` `,l]}):!e||!t?(0,J.jsx)(wE,{children:`No send surface here — open this repo from the launcher to send it.`}):a?(0,J.jsxs)(uT,{confirm:q_e,onConfirm:()=>b(EM(i.id,e,Zj)),children:[DM(s),` `,l]}):(0,J.jsxs)(Y,{onClick:()=>b(EM(i.id,e,Zj)),children:[DM(s),` `,l]})}function C(e,t){let n=Ai(e.id);return(0,J.jsxs)(`li`,{className:`check-row optin-card`,children:[(0,J.jsx)(`div`,{className:`check-top`,children:(0,J.jsx)(`span`,{className:`check-label`,children:n.title})}),e.sent&&(0,J.jsx)(`div`,{className:`check-detail optin-sent`,children:K_e(e.sent)}),(0,J.jsx)(`div`,{className:`check-detail optin-pitch`,children:n.pitch}),(0,J.jsx)(`div`,{className:`check-detail check-detail-quiet`,children:n.cost}),e.detail&&(0,J.jsx)(`div`,{className:`check-detail optin-seen`,children:e.detail}),(0,J.jsxs)(`div`,{className:`check-acts optin-acts`,children:[S(e,t&&!!e.sent),(0,J.jsxs)(Y,{onClick:()=>void v(e.id,`done`),children:[(0,J.jsx)(ys,{size:14}),` mark as done`]}),(0,J.jsxs)(Y,{onClick:()=>void v(e.id,`declined`),children:[(0,J.jsx)(Gc,{size:14}),` not for me`]})]})]},e.id)}return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`section-head`,children:[(0,J.jsx)(`span`,{className:`section section-hint`,children:Y_e}),(0,J.jsxs)(Y,{onClick:()=>o.reload({quiet:!0}),title:`read the offers again`,children:[(0,J.jsx)(Wl,{size:14,className:o.inflight?`spin`:void 0}),` re-check`]})]}),(0,J.jsx)($,{res:o,empty:!s,thing:`the opt-ins`,noun:`list of opt-ins`,children:`The desktop listed no opt-ins for this repo.`}),u&&(0,J.jsxs)(Z,{style:{color:`var(--dead)`},children:[`The desktop said: `,u]}),f.map((e,t)=>(0,J.jsx)(Z,{children:e},t)),s&&(0,J.jsxs)(J.Fragment,{children:[e&&t&&z_e(x.offered)&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{className:`send`,onClick:()=>b(V_e(x.offered,e)),children:[(0,J.jsx)(Ps,{size:14,style:{verticalAlign:`-2px`,marginRight:4}}),B_e(x.offered.length)]}),(0,J.jsx)(Z,{children:`One session that asks which of these you want, then posts each one as its own piece of work. Nothing is set up in it.`})]}),x.started.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`section`,children:W_e(x.started.length)}),(0,J.jsx)(Z,{children:`You began these in this repo, and the desktop does not see them set up yet. Sending one again starts it over.`}),(0,J.jsx)(`ul`,{className:`check-list`,children:x.started.map(e=>C(e,!0))})]}),x.offered.length>0?(0,J.jsxs)(J.Fragment,{children:[x.started.length>0&&(0,J.jsx)(`div`,{className:`section`,children:`Not started`}),(0,J.jsx)(`ul`,{className:`check-list`,children:x.offered.map(e=>C(e,!1))})]}):x.started.length===0&&(0,J.jsx)(`div`,{className:`empty`,children:J_e(x.declined.length,x.unfit.length)}),x.active.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`section`,children:`On`}),(0,J.jsx)(`ul`,{className:`check-list`,children:x.active.map(e=>(0,J.jsxs)(`li`,{className:`check-row optin-on`,children:[(0,J.jsxs)(`div`,{className:`check-top`,children:[(0,J.jsxs)(`span`,{className:`check-label`,children:[Ai(e.id).title,(0,J.jsxs)(`span`,{className:`check-kind`,children:[` · `,ete(e)]})]}),e.choice===`done`&&(0,J.jsxs)(Y,{onClick:()=>void v(e.id,null),children:[(0,J.jsx)(Ac,{size:14}),` undo`]})]}),e.detail&&(0,J.jsx)(`div`,{className:`check-detail check-detail-quiet`,children:e.detail})]},e.id))})]}),x.declined.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{className:`section optin-fold`,onClick:()=>h(e=>!e),"aria-expanded":m,children:[m?(0,J.jsx)(ac,{size:14}):(0,J.jsx)(jl,{size:14}),` `,H_e(x.declined.length)]}),m&&(0,J.jsx)(`ul`,{className:`check-list`,children:x.declined.map(e=>(0,J.jsx)(`li`,{className:`check-row optin-on`,children:(0,J.jsxs)(`div`,{className:`check-top`,children:[(0,J.jsx)(`span`,{className:`check-label`,children:Ai(e.id).title}),(0,J.jsxs)(Y,{onClick:()=>void v(e.id,null),children:[(0,J.jsx)(Nc,{size:14}),` offer again`]})]})},e.id))})]}),x.unfit.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{className:`section optin-fold`,onClick:()=>_(e=>!e),"aria-expanded":g,children:[g?(0,J.jsx)(ac,{size:14}):(0,J.jsx)(jl,{size:14}),` `,U_e(x.unfit.length)]}),g&&(0,J.jsx)(`ul`,{className:`check-list`,children:x.unfit.map(e=>(0,J.jsxs)(`li`,{className:`check-row optin-on`,children:[(0,J.jsx)(`div`,{className:`check-top`,children:(0,J.jsx)(`span`,{className:`check-label`,children:Ai(e.id).title})}),(0,J.jsx)(`div`,{className:`check-detail check-detail-quiet`,children:e.detail||`The desktop did not say why.`})]},e.id))})]})]})]})}function $_e({onOpen:e}){return(0,J.jsxs)(`button`,{className:`more-act`,onClick:e,title:`optional things this repo can turn on`,children:[(0,J.jsx)(zl,{size:Z_e}),`opt-ins`]})}var eve=[`counted`,`listed`,`desktop`],OM={counted:0,listed:2,desktop:3},kM=1.5,tve=e=>e.scope===`desktop`?`desktop`:mn(e)?`counted`:`listed`;function nve(e){return e.parts.filter(e=>e.readers.includes(`claude`)&&e.when.kind===`always`).reduce((e,t)=>e+t.chars,0)}function AM(e,t){let n=e.filter(e=>t.includes(e.scope??`repo`)),r=[],i=[],a=0;n.forEach((e,t)=>{let n=e.scope??`repo`;if(e.unsized){r.push({key:`${n}:${e.path}:${e.kind}`,path:e.path,kind:e.kind,scope:n,why:e.unsized});return}let o=nve(e);o<=0?a++:i.push({f:e,i:t,chars:o,band:tve(e)})}),i.sort((e,t)=>OM[e.band]-OM[t.band]||t.chars-e.chars||e.i-t.i);let o=i.reduce((e,t)=>e+t.chars,0),s=0,c=i.map(e=>{let t=o>0?s/o*100:0;s+=e.chars;let n=o>0?e.chars/o*100:0,r=e.f.scope??`repo`;return{key:`${r}:${e.f.path}:${e.f.kind}`,path:e.f.path,kind:e.f.kind,scope:r,band:e.band,chars:e.chars,x:t,w:n,seam:!1}});for(let e=0;e<c.length-1;e++)c[e].seam=c[e].w>=kM&&c[e+1].w>=kM;return{segs:c,bands:eve.map(e=>{let t=c.filter(t=>t.band===e);return{band:e,chars:t.reduce((e,t)=>e+t.chars,0),files:t.length}}).filter(e=>e.files>0),total:o,markers:r,idle:a,rows:n.length}}function rve(e,t){if(!e.length||!(t>=0)||t>1)return null;let n=t*100;for(let t=0;t<e.length;t++)if(n<e[t].x+e[t].w)return t;return e.length-1}function ive(e,t=6){return{shown:e.slice(0,t),more:Math.max(0,e.length-t)}}var jM=e=>Math.round(e/4),ave={counted:`threshold counts`,listed:`listed beside it`,desktop:`this desktop`},ove={counted:`counted by the threshold row`,listed:`listed beside the threshold, not counted by it`,desktop:`this desktop's, in every session — the threshold counts none of it`},sve=(e,t)=>`~${t(jM(e.chars))} tok`;function cve(e,t){return e.segs.length?`Every turn: ~${t(jM(e.total))} tokens (${t(e.total)} chars) from ${e.segs.length} ${e.segs.length===1?`file`:`files`}`:`Nothing from these files reaches Claude Code on every turn.`}function lve(e,t,n,r){let i=t>0?e.chars/t*100:0,a=i<1?`<1%`:`${Math.round(i)}%`;return`${n(e)} · ~${r(jM(e.chars))} tokens (${r(e.chars)} chars, ${a}) · ${ove[e.band]}`}function uve(e){let t=[];return e.idle&&t.push(`${e.idle} ${e.idle===1?`row carries`:`rows carry`} nothing every turn (scoped, on demand, or not read by Claude Code)`),e.markers.length&&t.push(`${e.markers.length} ${e.markers.length===1?`row has`:`rows have`} no size and ${e.markers.length===1?`is`:`are`} named below the bar, never drawn as a length`),t.length?`${e.segs.length} of ${e.rows} rows drawn; ${t.join(`; `)}.`:null}var MM=[`repo`,`desktop`],NM={repo:`In this repo`,desktop:`On this desktop`},PM=3;function FM(e){let t=vee([...e.files,...e.desktop??[]]),n=e=>t.filter(t=>t.scope===e);return{rows:t,bucket:n,chips:fE(MM.filter(t=>t!==`desktop`||e.desktop!=null),e=>({count:n(e).length}),e=>e)}}function IM({files:e,scopes:t,configDir:n,pick:r,onPick:i}){let a=AM(e,t),[o,s]=(0,H.useState)(null),c=i?r??null:o,l=i??s,[u,d]=(0,H.useState)(null),f=u??c,p=a.segs.find(e=>e.key===f)??null,m=e=>e.scope===`desktop`?Ha(e.path,n):e.path,h=e=>{let t=e.currentTarget.getBoundingClientRect(),n=t.width>0?rve(a.segs,(e.clientX-t.left)/t.width):null;return n==null?null:a.segs[n].key},{shown:g,more:_}=ive(a.markers),v=uve(a);return!a.segs.length&&!a.markers.length?null:(0,J.jsxs)(`div`,{className:`ao-strip`,children:[!a.segs.length&&(0,J.jsx)(`div`,{className:`ao-strip-head`,children:cve(a,R)}),a.segs.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`carried-bar`,role:`group`,"aria-label":`where the every-turn characters go; the line under it reads the picked file`,onPointerDown:e=>{let t=h(e);l(t!=null&&t===c?null:t),e.pointerType===`mouse`&&d(null)},onPointerMove:e=>{if(e.buttons){let t=h(e);t!=null&&l(t),e.pointerType===`mouse`&&d(null)}else e.pointerType===`mouse`&&d(h(e))},onPointerLeave:e=>{e.pointerType===`mouse`&&d(null)},children:a.segs.map(e=>(0,J.jsx)(`span`,{className:`carried-seg${e.key===f?` carried-on`:``}`,style:{left:`${e.x}%`,width:`${e.w}%`,background:UD[OM[e.band]]}},e.key))}),(0,J.jsx)(`div`,{className:`ctx-readout carried-readout`,children:p?lve(p,a.total,m,R):(0,J.jsx)(YD,{})}),(0,J.jsx)(`div`,{className:`ts-legend`,children:a.bands.map(e=>(0,J.jsxs)(`span`,{className:`ts-leg`,children:[(0,J.jsx)(`i`,{style:{background:UD[OM[e.band]]}}),(0,J.jsx)(`b`,{children:ave[e.band]}),` `,sve(e,R),(0,J.jsxs)(`em`,{children:[e.files,` `,e.files===1?`file`:`files`]})]},e.band))})]}),g.length>0&&(0,J.jsxs)(`div`,{className:`ao-marks`,"aria-label":`rows with no size`,children:[(0,J.jsx)(`span`,{className:`ao-marks-lead`,children:`no size:`}),g.map(e=>(0,J.jsx)(`span`,{className:`ao-mark`,children:e.kind},e.key)),_>0&&(0,J.jsxs)(`span`,{className:`ao-marks-lead`,children:[`+`,_,` more`]})]}),v&&(0,J.jsx)(`div`,{className:`ao-strip-note`,children:v})]})}function LM({rows:e,plot:t,configDir:n,onOpen:r,pick:i=null,onPick:a}){let o=e=>`${e.scope}:${e.path}:${e.kind}`,s=new Map(t.segs.map((e,t)=>[e.key,t])),c=e.map((e,t)=>({r:e,i:t,o:s.get(o(e))??1/0})).sort((e,t)=>e.o-t.o||e.i-t.i).map(e=>e.r),l=e=>a?.(i===e?null:e);return(0,J.jsx)(`ul`,{className:`carried-list ao-list`,children:c.map(e=>{let s=o(e),c=t.segs.find(e=>e.key===s),u=Vee(e,R),d=e.scope===`desktop`?Ha(e.path,n):e.path,f=[e.readers.length>0&&!e.unsized?`read by ${e.readers.join(`, `)}`:null,e.off??null].filter(Boolean).join(` · `),p=e.scope===`repo`&&!e.counted&&!e.unsized&&e.readers.includes(`claude`),m=(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`carried-head`,children:[(0,J.jsxs)(SE,{className:`carried-label`,children:[(0,J.jsx)(`span`,{className:`carried-path`,children:d}),` `,(0,J.jsx)(yE,{className:`carried-type`,children:e.kind})]}),u.num&&(0,J.jsx)(Q,{className:`carried-num`,children:u.num})]}),c&&(0,J.jsx)(`span`,{className:`carried-meter`,"aria-hidden":!0,children:(0,J.jsx)(`span`,{className:`carried-fill`,style:{width:`max(1px, ${c.w}%)`,background:UD[OM[c.band]]}})})]});return(0,J.jsx)(`li`,{className:c&&i===s?`carried-picked`:void 0,children:(0,J.jsxs)(xE,{children:[c&&a?(0,J.jsx)(`div`,{className:`carried-pick`,role:`button`,tabIndex:0,"aria-pressed":i===s,title:`read this file on the strip above`,onClick:()=>l(s),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),l(s))},children:m}):(0,J.jsx)(`div`,{className:`carried-pick ao-still`,children:m}),(f||p)&&(0,J.jsxs)(Q,{as:`div`,children:[f,p&&(0,J.jsxs)(J.Fragment,{children:[f?` `:``,(0,J.jsx)(yE,{children:`not under the threshold`})]})]}),u.rest&&(0,J.jsx)(Q,{as:`div`,className:e.unsized?`ao-unsized`:void 0,children:u.rest}),r&&(0,J.jsxs)(`button`,{type:`button`,className:`link-btn ao-open`,onClick:()=>r(e.path),children:[(0,J.jsx)(Nl,{size:12}),` open`]})]})},s)})})}function RM({doc:e,repoId:t,onOpenFile:n,sessionDoors:r,onAllSessions:i}){let[a,o]=(0,H.useState)(null),[s,c]=(0,H.useState)(null),l=r??[],u=i||r?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`sheet-actions ao-doors`,children:[l.slice(0,PM).map(e=>(0,J.jsxs)(Y,{title:`Open the context sheet of ${e.title}: what its first request actually carried`,onClick:e.open,children:[(0,J.jsx)(yo,{size:12}),` what `,e.title,` carries →`]},e.id)),i&&(0,J.jsxs)(Y,{title:`Every conversation on this desktop, with its token split`,onClick:i,children:[(0,J.jsx)(qo,{size:12}),` all sessions`]})]}),l.length>PM&&(0,J.jsx)(Z,{children:`+${l.length-PM} more live in this repo — open them from the launcher.`}),r&&!l.length&&(0,J.jsx)(CE,{cants:[{label:`session view`,reason:`no live session in this repo — open one to see what its turns carry`}]})]}):null;if(!e||e.why)return(0,J.jsxs)(`div`,{className:`ao-rows`,children:[(0,J.jsx)(Z,{children:e?.why?`${e.why}; the sentence above is the whole reading.`:`This desktop did not send the per-file list (an older host); the sentence above is the whole reading.`}),u]});let d=Ca([...e.files,...e.desktop??[]],R),{rows:f,bucket:p,chips:m}=FM(e),h=a?[a]:MM,g=[...e.files,...e.desktop??[]],_=AM(g,h),v=f.some(e=>e.scope===`repo`&&!e.counted&&!e.unsized&&e.readers.includes(`claude`));return(0,J.jsxs)(`div`,{className:`ao-rows`,children:[d&&(0,J.jsx)(`div`,{className:`check-detail`,children:d}),(0,J.jsx)(`div`,{className:`ts-filter`,role:`group`,"aria-label":`which files`,children:m.map(e=>(0,J.jsx)(pE,{on:a===e.key,onClick:()=>o(dE(a,e.key)),title:`Only the files ${e.key===`repo`?`this repo`:`this desktop`} adds`,children:e.text},e.key))}),a&&(0,J.jsx)(Z,{children:`${p(a).length} of ${f.length} rows — tap the lit chip to show all.`}),(0,J.jsx)(IM,{files:g,scopes:h,configDir:e.configDir,pick:s,onPick:c}),v&&(!a||a===`repo`)&&(0,J.jsx)(Z,{children:`Rows tagged “not under the threshold” are listed beside the threshold row, not counted by it.`}),h.map(r=>{let i=p(r);return r===`desktop`&&e.desktop===null?(0,J.jsxs)(`div`,{className:`ao-group`,children:[(0,J.jsx)(`div`,{className:`ao-group-head`,children:NM[r]}),(0,J.jsx)(Z,{children:e.desktopWhy??`This desktop's own files could not be read.`})]},r):i.length?(0,J.jsxs)(`div`,{className:`ao-group`,children:[(0,J.jsx)(`div`,{className:`ao-group-head`,children:NM[r]}),r===`desktop`&&(0,J.jsx)(Z,{children:`These live outside the repo, so they do not open from here. They are what this desktop's files show; plugin packs synced from claude.ai are not on disk — a session's own sheet (below) lists the skills it actually carried.`}),(0,J.jsx)(LM,{rows:i,plot:_,configDir:e.configDir,pick:s,onPick:c,onOpen:r===`repo`&&n?e=>n(t,e):void 0})]},r):null}),u]})}function zM(e){return e.id===`exposure`?`summary`:e.exposure?e.accepted?`accepted`:e.exposure.level===`digest`?`digest`:`alerts`:null}function BM(e){let t=[],n=[],r=[],i=null;for(let a of e){let e=zM(a);e===`summary`?i=a:e===`accepted`?r.push(a):e===`digest`?n.push(a):e===`alerts`&&t.push(a)}return{alerts:t,digest:n,accepted:r,summary:i}}var VM=e=>{let t=zM(e);return t!==`accepted`&&t!==`digest`};function HM(e){return`Digest · ${e} — counted in nothing`}var UM=e=>`Accepted (${e})`;function WM(e){let t=[];return e.threshold&&t.push(e.threshold),e.severity&&t.push(e.severity),e.sources.length&&t.push(`from ${e.sources.join(`, `)}`),e.since&&t.push(`since ${e.since.slice(0,10)}`),t.join(` · `)}function GM(e){return e&&`version`in e&&e.version?`ends once a version newer than ${e.version} is installed`:e&&`date`in e&&e.date?`until ${e.date}`:e&&`change`in e&&e.change?`until the reading changes`:`for good`}var KM=864e5;function qM(e,t){let n=Date.parse(e);if(!Number.isFinite(n))return``;let r=Math.max(0,Math.floor((t-n)/KM));return r===0?`today`:r===1?`yesterday`:`${r} days ago`}function JM(e,t){if(e.builtIn)return`Accepted in code — ${e.reason}`;let n=qM(e.at,t);return`Accepted${n?` ${n}`:``}: ${e.reason} (${GM(e.until)})`}var YM=`accepted in code`;function XM(e){let t=[{key:`change`,label:`until the reading changes`},{key:`date`,label:`until a date`}];return e&&t.push({key:`version`,label:`ends once a version newer than the one you type is installed (now ${e})`}),t}function ZM(e){return e.exposure?.version?.trim()||null}var QM=`Say why you accept it — the reason stays with the row.`,$M=`Pick the date the accept ends.`,eN=`Type the newest version you accept; the accept ends once a newer one is installed.`;function tN(e,t,n){return e.trim()?t===`date`&&!n.trim()?$M:t===`version`&&!n.trim()?eN:null:QM}function nN(e,t,n,r){let i=n===`date`?{date:r.trim()}:n===`version`?{version:r.trim()}:{change:!0};return{id:e,accept:!0,reason:t.trim(),until:i}}var rN=[{key:`seen`,label:`seen`,hint:`Still counted. Quiet for this app version; a newer version alerts again.`},{key:`investigating`,label:`investigating`,hint:`Still counted. Quiet for this app version; a newer version alerts again.`},{key:`fixed`,label:`fixed`,hint:`Older versions stop counting; the same crash in this version or newer alerts as a regression. Needs an app version on the finding.`}],iN=`Type the version that carries the fix, like 1.4.2.`,aN=`A version is letters, digits and . + - only, up to 32 characters.`,oN=`A commit is 7 to 40 hex characters.`,sN=`The note is up to 280 characters.`;function cN(e,t,n,r){if(r.trim().length>280)return sN;if(e!==`fixed`)return null;let i=t.trim();if(!i)return iN;if(i.length>32||!/^[0-9A-Za-z.+-]+$/.test(i))return aN;let a=n.trim();return a&&!/^[0-9a-fA-F]{7,40}$/.test(a)?oN:null}function lN(e,t,n,r,i){return{id:e,state:t,...t===`fixed`?{fixedIn:n.trim()}:{},...t===`fixed`&&r.trim()?{commit:r.trim()}:{},...i.trim()?{note:i.trim()}:{}}}var uN=e=>({id:e,clear:!0});function dN(e){let t=e.exposure?.triage,n=!!e.exposure?.appVersion,r=n?null:fN;if(!t)return{open:`Mark…`,canClear:!1,line:null,offerFixed:n,noFixedWhy:r};let i=e.detail.includes(`crashes again in`);return{open:`Change mark…`,canClear:!0,line:t.state===`fixed`&&!i?y(t):null,offerFixed:n,noFixedWhy:r}}var fN=`Fixed needs an app version; Accept it instead.`,pN=e=>`Marked, not in today's reading (${e})`,mN=e=>!!e.accepted&&!e.accepted.builtIn&&e.accepted.byMark===!0,hN=`Against the outside world, read daily: published advisories on what is installed, deprecations, store and Scorecard readings. A finding here counts in the repo's badge like a set-up one; an accepted one stays listed with its reason.`,gN=`What the daily exposure watch and Scorecard found about this repo's dependencies, stores and published surface.`,_N=`re-check`,vN=`Run the exposure watch for this repo now, then re-read its findings`,yN=e=>`The watch did not run: ${e}`;function bN(e,t){return`${e} more ${e===1?`finding is`:`findings are`} under ${t===`watch`?`watch`:`set-up`}`}function xN({check:e,onAccept:t}){let[n,r]=(0,H.useState)(!1),[i,a]=(0,H.useState)(``),[o,s]=(0,H.useState)(`change`),[c,l]=(0,H.useState)(``),[u,d]=(0,H.useState)(null),[f,p]=(0,H.useState)(!1),m=ZM(e);if(!n)return(0,J.jsx)(`div`,{className:`check-acts`,children:(0,J.jsxs)(Y,{onClick:()=>r(!0),title:`Accept this finding, with a reason`,children:[(0,J.jsx)(Is,{size:12}),` Accept…`]})});let h=tN(i,o,c);async function g(){p(!0),d(null);let n=await t(nN(e.id,i,o,c));p(!1),n?d(n):r(!1)}return(0,J.jsxs)(`div`,{className:`check-acts`,style:{display:`block`},children:[(0,J.jsx)(Z,{children:`Accepting keeps the row, with your reason, under Accepted — it is not counted while accepted.`}),(0,J.jsx)(`textarea`,{className:`search`,rows:2,value:i,autoFocus:!0,placeholder:`why is this fine here?`,"aria-label":`reason`,onChange:e=>a(e.target.value)}),(0,J.jsx)(Bw,{label:`How long`,value:o,onChange:e=>{s(e),l(``)},options:XM(m)}),o===`date`&&(0,J.jsx)(`input`,{className:`search`,type:`date`,value:c,"aria-label":`accept until`,onChange:e=>l(e.target.value)}),o===`version`&&(0,J.jsx)(`input`,{className:`search mono`,value:c,"aria-label":`newest version you accept`,placeholder:`newest version you accept (now ${m})`,onChange:e=>l(e.target.value)}),u&&(0,J.jsx)(Z,{tone:`warn`,children:u}),(0,J.jsxs)(`div`,{className:`check-acts check-acts-split`,children:[h?(0,J.jsx)(Z,{as:`span`,children:h}):(0,J.jsx)(Y,{variant:`primary`,onClick:()=>void g(),children:f?`Accepting…`:`Accept`}),(0,J.jsx)(Y,{onClick:()=>{r(!1),d(null)},children:`cancel`})]})]})}function SN({check:e,onMark:t}){let n=e.exposure?.triage,[r,i]=(0,H.useState)(!1),[a,o]=(0,H.useState)(n?.state??`seen`),[s,c]=(0,H.useState)(n?.fixedIn??``),[l,u]=(0,H.useState)(n?.commit??``),[d,f]=(0,H.useState)(n?.note??``),[p,m]=(0,H.useState)(null),[h,g]=(0,H.useState)(!1),_=dN(e);function v(){let t=e.exposure?.triage;o(t?.state===`fixed`&&!_.offerFixed?`seen`:t?.state??`seen`),c(t?.fixedIn??``),u(t?.commit??``),f(t?.note??``),m(null),i(!0)}async function y(e,n){g(!0),m(null);let r=await t(e);g(!1),r?m(r):n&&i(!1)}if(!r)return(0,J.jsxs)(`div`,{className:`check-acts`,style:{display:`block`},children:[_.line&&(0,J.jsx)(`div`,{className:`check-detail check-detail-quiet`,children:_.line}),(0,J.jsxs)(`div`,{className:`check-acts`,children:[(0,J.jsxs)(Y,{onClick:v,children:[(0,J.jsx)(_o,{size:12}),` `,_.open]}),_.canClear&&(0,J.jsx)(Y,{onClick:()=>void y(uN(e.id),!1),children:h?`Clearing…`:`Clear mark`})]}),p&&(0,J.jsx)(Z,{tone:`warn`,children:p})]});let b=cN(a,s,l,d);return(0,J.jsxs)(`div`,{className:`check-acts`,style:{display:`block`},children:[(0,J.jsx)(Z,{children:rN.find(e=>e.key===a).hint}),(0,J.jsx)(Bw,{label:`Mark as`,value:a,onChange:o,options:rN.filter(e=>e.key!==`fixed`||_.offerFixed).map(e=>({key:e.key,label:e.label}))}),!_.offerFixed&&(0,J.jsx)(Z,{children:_.noFixedWhy}),a===`fixed`&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`input`,{className:`search mono`,value:s,"aria-label":`version that carries the fix`,autoFocus:!0,placeholder:`the version that carries the fix`,onChange:e=>c(e.target.value)}),(0,J.jsx)(`input`,{className:`search mono`,value:l,"aria-label":`commit (optional)`,placeholder:`commit (optional)`,onChange:e=>u(e.target.value)})]}),(0,J.jsx)(`textarea`,{className:`search`,rows:2,value:d,"aria-label":`note (optional)`,placeholder:`note (optional)`,onChange:e=>f(e.target.value)}),p&&(0,J.jsx)(Z,{tone:`warn`,children:p}),(0,J.jsxs)(`div`,{className:`check-acts check-acts-split`,children:[b?(0,J.jsx)(Z,{as:`span`,children:b}):(0,J.jsx)(Y,{variant:`primary`,onClick:()=>void y(lN(e.id,a,s,l,d),!0),children:h?`Marking…`:`Mark`}),(0,J.jsx)(Y,{onClick:()=>{i(!1),m(null)},children:`cancel`})]})]})}function CN({rows:e,now:t,onStop:n,onClearMark:r}){return e.length?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`section`,children:UM(e.length)}),(0,J.jsx)(`ul`,{className:`check-list`,children:e.map(e=>(0,J.jsxs)(`li`,{className:`check-row check-ignored`,children:[(0,J.jsxs)(`div`,{className:`check-top`,children:[(0,J.jsx)(`span`,{className:`check-icon`,children:(0,J.jsx)(Is,{size:16,color:`var(--dim)`})}),(0,J.jsx)(`span`,{className:`check-label`,children:e.label}),e.accepted.builtIn?(0,J.jsx)(Z,{as:`span`,children:YM}):mN(e)?(0,J.jsx)(Y,{onClick:()=>r(e.id),children:`Clear mark`}):(0,J.jsx)(Y,{onClick:()=>n(e.id),children:`stop accepting`})]}),(0,J.jsx)(`div`,{className:`check-detail check-detail-quiet`,children:JM(e.accepted,t)})]},e.id))})]}):null}function wN({marks:e,onClear:t}){return e.length?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`section`,children:pN(e.length)}),(0,J.jsx)(`ul`,{className:`check-list`,children:e.map(e=>(0,J.jsxs)(`li`,{className:`check-row check-ignored`,children:[(0,J.jsxs)(`div`,{className:`check-top`,children:[(0,J.jsx)(`span`,{className:`check-icon`,children:(0,J.jsx)(_o,{size:16,color:`var(--dim)`})}),(0,J.jsx)(`span`,{className:`check-label`,children:e.triageId.replace(/^exposure:/,``)}),(0,J.jsx)(Y,{onClick:()=>t(e.triageId),children:`Clear mark`})]}),(0,J.jsx)(`div`,{className:`check-detail check-detail-quiet`,children:y(e.triage)})]},e.triageId))})]}):null}function TN({n:e,children:t}){let[n,r]=(0,H.useState)(!1);return e?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`section`,children:(0,J.jsxs)(Y,{onClick:()=>r(!n),"aria-expanded":n,children:[n?(0,J.jsx)(ac,{size:14}):(0,J.jsx)(jl,{size:14}),` `,HM(e)]})}),n&&(0,J.jsx)(`ul`,{className:`check-list`,children:t})]}):null}var EN={pass:(0,J.jsx)(ys,{size:16,color:`var(--ok)`}),warn:(0,J.jsx)(Js,{size:16,color:`var(--warn)`}),fail:(0,J.jsx)(V,{size:16,color:`var(--dead)`})};function DN({repos:e,initialRepoId:t,initialRegion:n=`setup`,focus:r,onRemedy:i,onOpenFile:a,onSeed:o,onCapture:s,sessionDoorsFor:c,onAllSessions:l,onOpenInstructionFile:u,onClose:d}){let f=e.filter(e=>e.isPrimary),[p,m]=(0,H.useState)(t&&e.some(e=>e.id===t)?t:f[0]?.id??``),[h,g]=(0,H.useState)(n),[_,v]=(0,H.useState)(r===`findings`);(0,H.useEffect)(()=>{v(r===`findings`)},[r]),(0,H.useEffect)(()=>{g(n)},[n]);let[y,b]=(0,H.useState)(!1);(0,H.useEffect)(()=>{b(!1)},[r,n,p]);let[x,S]=(0,H.useState)(!1),[C,w]=(0,H.useState)(null),[T,E]=(0,H.useState)([]),[D]=(0,H.useState)(rk),O=fh(p,()=>U.compliance(p),{enabled:!!p}),[k,A]=(0,H.useState)(null),j=fh(`repohealth:${p}:${k??``}`,()=>U.repoHealth(p,k),{enabled:!!p}),M=O.data,N=j.data,P=e.find(e=>e.id===p)??null;async function F(e,t){if(p){q(t?`action:setup.ignore`:`action:setup.unignore`),S(!0),w(null),E([]);try{let n=await U.complianceIgnore(p,e,t);n.ok&&n.report?O.set(n.report):w(n.error||`the desktop did not store it`)}catch(e){w(String(e.message||e))}finally{S(!1)}}}async function I(e){if(!p)return`No repo is open, so there is nothing to accept.`;q(e.accept?`action:setup.accept`:`action:setup.unaccept`),S(!0),w(null);try{let t=await U.complianceAccept(p,e);return t.ok&&t.report?(O.set(t.report),null):t.error||`the desktop did not store it`}catch(e){return String(e.message||e)}finally{S(!1)}}async function ee(e){if(!p)return`No repo is open, so there is nothing to mark.`;q(e.clear?`action:setup.unmark`:`action:setup.mark`),S(!0),w(null);try{let t=await U.complianceTriage(p,e);return t.ok&&t.report?(O.set(t.report),null):t.error||`the desktop did not store it`}catch(e){return String(e.message||e)}finally{S(!1)}}async function te(e){if(!p||!e.length)return null;q(`action:setup.fix`),S(!0),w(null);try{let t=e.length===1?M?.confirm?.[e[0]]:void 0,n=await U.complianceFix(p,e,t);if(n.ok&&E(n.notes??[]),n.ok&&n.report)return O.set(n.report),n.report;n.ok||w(n.error||`fix failed`)}catch(e){w(String(e.message||e))}finally{S(!1)}return null}let ne=M?.checks??[],re=ne.filter(qa),ie=ne.filter(e=>!qa(e)),ae=h===`watch`?re:ie,oe=(h===`watch`?ie:re).filter(ct).length,se=qk(ae),ce=Kk(ae),le=!!i&&!!P,ue=se.length+(le?ce.length:0),de=ae.filter(ct),fe=_?de:ae;async function pe(){if(!P)return;let e=M;if(se.length){let t=await te(wme(ae));if(!t)return;e=t}let t=e?Kk(e.checks.filter(e=>qa(e)===(h===`watch`))):[];t.length&&i&&i($k(t,P.repoName,Gk()),P,t.length===1?t[0].label.toLowerCase():`${t.length} setup findings`)}(0,H.useEffect)(()=>{!y&&M&&_&&h===`setup`&&(b(!0),!ie.some(ct)&&re.some(ct)&&g(`watch`))},[y,M,_,h,ie,re]),(0,H.useEffect)(()=>{r===`context-weight`&&M&&h===`setup`&&document.querySelector(`[data-check="context-weight"]`)?.scrollIntoView({block:`start`})},[r,M,h,p]);let me=N?.plot??null,he=me?.series.find(e=>e.key===`context.claudeMdChars`)??null;return(0,J.jsx)(hE,{className:`readings-sheet`,title:`Repo readings`,icon:(0,J.jsx)(hl,{size:18}),onClose:d,children:(0,J.jsx)(`div`,{className:`sheet-scroll`,children:(0,J.jsxs)(`div`,{className:`form`,children:[(0,J.jsx)(ZO,{repos:e.filter(e=>e.isPrimary||e.id===p),value:e.find(e=>e.id===p)?.worktreePath??``,onChange:t=>{let n=e.find(e=>e.worktreePath===t);n&&m(n.id)},"aria-label":`repo`}),(0,J.jsxs)(`div`,{className:`ts-filter`,role:`group`,"aria-label":`reading`,children:[(0,J.jsx)(`span`,{className:`ctx-stackpick-lab`,children:`reading`}),(0,J.jsxs)(pE,{on:h===`setup`,clears:!1,onClick:()=>{g(`setup`),A(null)},children:[(0,J.jsx)(Cs,{size:14}),` set-up`]}),(0,J.jsxs)(pE,{on:h===`series`,clears:!1,onClick:()=>g(`series`),children:[(0,J.jsx)(hl,{size:14}),` over time`]}),(0,J.jsxs)(pE,{on:h===`watch`,clears:!1,onClick:()=>{g(`watch`),A(null)},children:[(0,J.jsx)(Us,{size:14}),` watch`]}),(0,J.jsxs)(pE,{on:h===`optins`,clears:!1,onClick:()=>{g(`optins`),A(null)},children:[(0,J.jsx)(zl,{size:14}),` opt-ins`]}),(0,J.jsx)(TE,{of:`what this region compares`,children:h===`optins`?X_e:h===`watch`?hN:Zpe(h)})]}),h===`setup`||h===`watch`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(ON,{kind:h,elsewhere:_?oe:0,onElsewhere:()=>g(h===`watch`?`setup`:`watch`),onOptIns:()=>{g(`optins`),A(null)},repoId:p,repo:P,res:O,report:M,rows:fe,allRows:ae,cut:_,onClearCut:()=>v(!1),busy:x,fixError:C,fixNotes:T,presets:D,canAsk:le,bulkCount:ue,patchable:se.length,forAgent:ce.length,onFix:te,onIgnore:F,onAccept:I,onMark:ee,onFixAll:()=>void pe(),onRemedy:i,claudeMdSeries:he,descSeries:me?.series.find(e=>e.key===`context.descChars`)??null,onOpenFile:u??a,sessionDoors:c?.(p),onAllSessions:l}),P&&h===`setup`&&(0,J.jsx)(Ume,{repo:P,say:Dg})]}):h===`optins`?(0,J.jsx)(Q_e,{repo:P,onSeed:o,onCapture:s,onSeries:()=>g(`series`),onChecklist:e=>O.set(e)}):(0,J.jsx)(Zge,{repo:P,res:j,view:N,onRemedy:i,scope:k,onScope:A,onOpenFile:a})]})})})}function ON({kind:e,elsewhere:t,onElsewhere:n,onOptIns:r,repoId:i,repo:a,res:o,report:s,rows:c,allRows:l,cut:u,onClearCut:d,busy:f,fixError:p,fixNotes:m,presets:h,canAsk:g,bulkCount:_,patchable:v,forAgent:y,onFix:b,onIgnore:x,onAccept:S,onMark:C,onFixAll:w,onRemedy:T,claudeMdSeries:E,descSeries:D,onOpenFile:O,sessionDoors:k,onAllSessions:A}){let[j,M]=(0,H.useState)(null),N=j?.repoId===i?j:null,P=s?(0,J.jsx)(RM,{doc:s.instructions,repoId:i,onOpenFile:O,sessionDoors:k,onAllSessions:A}):null;function F(e){if(!s)return null;let t=(ct(e)||Ie(e))&&!e.fix,n=t&&g?Ife(e.id,h):null,r=t&&g&&a?n?{label:n.title,run:()=>T(n.text,a,n.title)}:Gk().byCheck(e.id)?.agent?{label:Zk(e.id,Gk()),run:()=>AN(Gk().byCheck(e.id).agent,a,e.label)}:{label:Zk(e.id,Gk()),run:()=>T($k([e],a.repoName,Gk()),a,e.label.toLowerCase())}:null,c=e.id===`context-weight`&&s.contextLimits?(0,J.jsx)(oA,{repoId:i,view:s.contextLimits,setAt:s.contextLimitsSetAt,onReport:e=>o.set(e)}):null,l=e.id===`context-weight`?(0,J.jsx)(kN,{claudeMd:E,desc:D,workingTree:e.alwaysOnChars??null}):null,u=e.exposure?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`check-detail check-detail-quiet`,children:WM(e.exposure)}),(0,J.jsx)(xN,{check:e,onAccept:S}),(0,J.jsx)(SN,{check:e,onMark:C})]}):null;return(0,J.jsx)(jN,{c:e,busy:f,onFix:b,remedy:r,size:s.autoCompactDefault,onIgnore:x,extra:(0,J.jsxs)(J.Fragment,{children:[l,e.id===`context-weight`?P:null,c,u]})},e.id)}async function I(){if(N?.running)return;let e=i;M({repoId:e,running:!0});let t;try{let n=await U.exposureRun(e);t={ok:!!n?.ok,sentence:typeof n?.sentence==`string`&&n.sentence?n.sentence:yN(`the desktop gave no answer.`)}}catch(e){t={ok:!1,sentence:yN(e.message||`no link to the desktop.`)}}o.reload({quiet:!0}),M({repoId:e,running:!1,...t})}let ee=BM(l),te=!!(s?.instructions?.files.length||s?.instructions?.desktop?.length);return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`section-head`,children:[(0,J.jsx)(`span`,{className:`section section-hint`,children:e===`watch`?gN:(0,J.jsx)(J.Fragment,{children:`Checks a repo follows the conventions: CLAUDE.md tells the agent to use the outbox, inbox/outbox are gitignored and secrets aren't committed. Re-run regularly.`})}),(0,J.jsxs)(Y,{onClick:e===`watch`?I:()=>o.reload({quiet:!0}),title:e===`watch`?vN:`re-check`,children:[(0,J.jsx)(Wl,{size:14,className:o.inflight||N?.running?`spin`:void 0}),` `,e===`watch`?_N:`re-check`]})]}),e===`watch`&&N?.running&&(0,J.jsx)(Z,{children:`running the exposure watch for this repo — a first run can take a minute or two…`}),e===`watch`&&N?.sentence&&(0,J.jsx)(Z,{tone:N.ok?void 0:`warn`,children:N.sentence}),(0,J.jsx)($,{res:o,empty:!s,thing:`the setup checklist`,noun:`checklist`,children:`Nothing in this checklist applies to this repo yet.`}),s&&e===`watch`&&!l.length&&(0,J.jsxs)(Z,{children:[`Not watched yet: the daily exposure watch has no rows for this repo, and Scorecard has no reading yet.`,` `,(0,J.jsx)(`button`,{className:`link-btn`,onClick:r,children:`add this repo to the exposure watch`})]}),p&&(0,J.jsxs)(Z,{style:{color:`var(--dead)`},children:[`Fix failed: `,p]}),m.map((e,t)=>(0,J.jsx)(Z,{children:e},t)),s&&(0,J.jsxs)(J.Fragment,{children:[_>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{className:`send`,onClick:w,disabled:f,children:[(0,J.jsx)($s,{size:14,style:{verticalAlign:`-2px`,marginRight:4}}),f?`Fixing…`:Eme(v,g?y:0)]}),g&&a&&eA(v,y,a.repoName)&&(0,J.jsx)(Z,{children:eA(v,y,a.repoName)})]}),u&&(0,J.jsxs)(`div`,{className:`section filter-bar`,children:[(0,J.jsxs)(`span`,{className:`filter-bar-txt`,children:[Mme(c.length,l.length),t>0&&(0,J.jsxs)(J.Fragment,{children:[` · `,(0,J.jsx)(`button`,{className:`link-btn`,onClick:n,children:bN(t,e===`watch`?`setup`:`watch`)})]})]}),(0,J.jsxs)(`button`,{className:`filter-bar-clear`,onClick:d,children:[(0,J.jsx)(V,{size:14}),` clear`]})]}),(0,J.jsx)(`ul`,{className:`check-list`,children:c.filter(e=>!e.ignored&&VM(e)).map(F)}),!u&&(0,J.jsx)(TN,{n:ee.digest.length,children:ee.digest.map(F)}),!u&&l.some(e=>e.ignored)&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`section`,children:`Ignored in this repo`}),(0,J.jsx)(`ul`,{className:`check-list`,children:l.filter(e=>e.ignored).map(e=>(0,J.jsxs)(`li`,{className:`check-row check-ignored`,children:[(0,J.jsxs)(`div`,{className:`check-top`,children:[(0,J.jsx)(`span`,{className:`check-icon`,children:(0,J.jsx)(Gc,{size:16,color:`var(--dim)`})}),(0,J.jsx)(`span`,{className:`check-label`,children:e.label}),(0,J.jsx)(Y,{onClick:()=>x(e.id,!1),children:`stop ignoring`})]}),(0,J.jsx)(`div`,{className:`check-detail check-detail-quiet`,children:e.status===`pass`?`Fine here now.`:`Still on the far side of its line — not counted, not suggested.`})]},e.id))})]}),!u&&(0,J.jsx)(CN,{rows:ee.accepted,now:Date.now(),onStop:e=>void S({id:e,accept:!1}).then(e=>{e&&Dg(e)}),onClearMark:e=>void C(uN(e)).then(e=>{e&&Dg(e)})}),!u&&(0,J.jsx)(wN,{marks:ee.summary?.staleMarks??[],onClear:e=>void C(uN(e)).then(e=>{e&&Dg(e)})}),e===`setup`&&(s.contextLimits||te)&&!l.some(e=>e.id===`context-weight`)&&(0,J.jsxs)(`div`,{className:`check-row check-pass`,children:[(0,J.jsx)(`div`,{className:`check-top`,children:(0,J.jsx)(`span`,{className:`check-label`,children:`Agent context weight`})}),(0,J.jsxs)(`div`,{className:`check-detail`,children:[`Nothing to weigh yet — this repo has no CLAUDE.md.`,s.contextLimits?` These are the thresholds it will be measured against once it does.`:``]}),te&&P,s.contextLimits&&(0,J.jsx)(oA,{repoId:i,view:s.contextLimits,setAt:s.contextLimitsSetAt,onReport:e=>o.set(e)})]})]})]})}function kN({claudeMd:e,desc:t,workingTree:n}){if(!e&&!t)return null;let r=e?.points[e.points.length-1]?.sha7??t?.points[t.points.length-1]?.sha7??null,i=Hpe(n,e?.last!=null&&t?.last!=null?e.last+t.last:null,r);return(0,J.jsxs)(`div`,{className:`rh-twin`,children:[i?(0,J.jsx)(`div`,{className:`rh-twin-line`,children:i}):null,(0,J.jsx)(`ul`,{className:`rh-twin-rows`,children:[e,t].filter(Boolean).map(e=>(0,J.jsxs)(`li`,{children:[(0,J.jsx)(`span`,{className:`rh-twin-key`,children:e.label}),(0,J.jsx)(`span`,{className:`rh-twin-val`,children:Ck(e.last,e.unit)}),(0,J.jsx)(IA,{points:e.points,width:96,height:18,label:e.label})]},e.key))}),wk(e?.reading??t?.reading)?(0,J.jsx)(`div`,{className:`rh-twin-read`,children:wk(e?.reading??t?.reading)}):null]})}function AN(e,t,n){try{e(t,W())}catch(e){Dg(`${n} could not start: ${e instanceof Error?e.message:String(e)}`)}}function jN({c:e,busy:t,onFix:n,onIgnore:r,size:i,remedy:a,extra:o}){let s=Ie(e);return(0,J.jsxs)(`li`,{className:`check-row check-${s?`consider`:e.status}`,"data-check":e.id,children:[(0,J.jsxs)(`div`,{className:`check-top`,children:[(0,J.jsx)(`span`,{className:`check-icon`,children:s?(0,J.jsx)(Co,{size:16,color:`var(--accent)`}):EN[e.status]}),(0,J.jsxs)(`span`,{className:`check-label`,children:[e.label,s&&(0,J.jsx)(`span`,{className:`check-kind`,children:` · consider`})]}),e.fix&&!Jk(e.fix)&&(0,J.jsxs)(Y,{onClick:()=>n([e.fix]),disabled:t,children:[(0,J.jsx)($s,{size:12}),` `,Yk(e.fix,i,Gk())]})]}),(0,J.jsx)(`div`,{className:`check-detail`,children:e.detail}),e.fix&&!Jk(e.fix)&&Xk(e.fix)&&(0,J.jsx)(Z,{children:Xk(e.fix)}),s&&!e.exposure&&(0,J.jsxs)(`div`,{className:`check-acts check-acts-split`,children:[(0,J.jsx)(Z,{as:`span`,children:`Not counted in the badge. Leaving it is a fine answer.`}),(0,J.jsxs)(Y,{onClick:()=>r(e.id,!0),children:[(0,J.jsx)(Gc,{size:12}),` ignore in this repo`]})]}),e.fix&&Jk(e.fix)&&(0,J.jsx)(`div`,{className:`check-acts`,children:(0,J.jsxs)(uT,{confirm:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)($s,{size:12}),` `,Cme(e.fix,i)]}),disabled:t,onConfirm:()=>void n([e.fix]),children:[(0,J.jsx)($s,{size:12}),` `,Yk(e.fix,i,Gk())]})}),a&&(0,J.jsx)(`div`,{className:`check-acts`,children:(0,J.jsxs)(Y,{onClick:a.run,children:[(0,J.jsx)(al,{size:12}),` `,a.label,`…`]})}),o]})}var MN=G(null),NN=G({}),PN=G(null),FN=`first-look`;function IN(e=FN){so(B.demoTour),!(ku()&&Fre(e))&&pne(e)}function LN(){so(B.demoTour),!(ku()&&Ire())&&sne()}function RN(e,t){if(e)return`shell`;let n=t.toLowerCase();return n===`localhost`||n===`[::1]`||n.endsWith(`.ts.net`)||n.endsWith(`.local`)||/^\d{1,3}(\.\d{1,3}){3}$/.test(n)?`host`:`static`}function zN(){return RN(ku(),globalThis.location?.hostname??``)}var BN=`app:open-demotour`;function VN(){try{window.dispatchEvent(new CustomEvent(BN))}catch{}}var HN=`app:open-repohealth`;function UN(e){try{window.dispatchEvent(new CustomEvent(HN,{detail:{repoId:e??null}}))}catch{}}function WN(){return bu(gu()).length>0}function GN(e,t,n){return{prompts:[e],target:{kind:`repo`,cwd:t.worktreePath},cwdHint:t.worktreePath,repoId:t.id,origin:`From ${t.repoName}'s repo readings — ${n}`}}function KN(e){return{...e,region:`series`}}function qN(e,t={}){MN.set(e),NN.set(t),W().nav.open(`setup`)}function JN(e){PN.set(e),W().nav.open(`repohealth`)}function YN(e,t,n){W().say.track(`action:setup.remedy`),XN(GN(e,t,n))}function XN(e){MN.set(null),PN.set(null),W().nav.openSend(e)}function ZN(e){W().nav.openCapture(e)}function QN(e,t){let n=W();n.say.track(`action:files.fromReadings`);let r=n.nav.overlay;r===`setup`&&NN.set(KN(NN.get())),n.files.browseTo(e,t,r)}function $N(){let e=W();MN.set(null),NN.set({}),e.nav.close(`setup`),e.world.refreshRepos()}function eP(){let e=e=>{let t=W(),n=e.detail?.repoId??null,r=(n?t.world.repos.find(e=>e.id===n):null)??t.world.activeRepo??t.world.repos.find(e=>e.isPrimary)??null;r&&JN(r)};return window.addEventListener(HN,e),()=>window.removeEventListener(HN,e)}function tP(){PN.set(null),W().nav.close(`repohealth`)}function nP(e,t){let n=W();n.say.track(`action:files.fromReadings`);let r=n.nav.overlay;r===`setup`&&NN.set({...NN.get(),region:`setup`}),n.files.browseTo(e,t,r)}function rP(e){W().say.track(`action:setup.ctxFromRow`),W().nav.openContext(e)}function iP(){W().say.track(`action:setup.allSessions`),W().nav.open(`tokens`)}function aP(e){let t=W().world;return t.sessions.filter(n=>n.running&&!n.id.startsWith(`pending:`)&&t.sessionRepo(n)?.id===e).map(e=>({id:e.id,title:t.sessionRowTitle(e),open:()=>rP(e.id)}))}function oP(){let e=_h(),t=K(MN),n=K(NN);return(0,J.jsx)(DN,{repos:e.world.repos,initialRepoId:t??void 0,initialRegion:n.region,focus:n.focus,onRemedy:YN,onOpenFile:QN,onSeed:XN,onCapture:ZN,sessionDoorsFor:aP,onAllSessions:iP,onOpenInstructionFile:nP,onClose:$N})}function sP({repo:e}){let t=_h();return(0,J.jsx)(DN,{repos:t.world.repos,initialRepoId:e.id,initialRegion:`series`,onRemedy:YN,onOpenFile:QN,onSeed:XN,onCapture:ZN,sessionDoorsFor:aP,onAllSessions:iP,onOpenInstructionFile:nP,onClose:tP})}function cP(){let[e,t]=(0,H.useState)(null),[n,r]=(0,H.useState)(null);(0,H.useEffect)(()=>{let e=new AbortController;return U.setupPrefs(e.signal).then(n=>{e.signal.aborted||t(n.autoCompactDefault)}).catch(t=>{e.signal.aborted||r(String(t.message||t))}),()=>e.abort()},[]);async function i(n){let i=e;t(n);try{let e=await U.setSetupPrefs(n===`400k`?null:n);if(!e.ok){t(i),Dg(e.error||`the desktop did not store it`);return}t(e.autoCompactDefault??n),r(null)}catch(e){t(i),Dg(`not saved — ${String(e.message||e)}`)}}return(0,J.jsx)(tT,{id:`auto-compact-default`,label:`auto-compact window`,icon:yc,value:e??``,options:pa.map(e=>({value:e,label:e===`400k`?`${e} (default)`:e})),onChange:e=>void i(e),note:n?`Could not read this desktop's choice: ${n}`:`What Repo readings offers to write into a repo's .claude/settings.json, and the size under which a repo's window counts as fine. Nothing is written until you tap it there.`,more:(0,J.jsx)(`p`,{children:`A conversation compacts once its context passes this, so one long agent stops re-reading a whole 1M window on every step. Smaller is cheaper per step and compacts more often. Stored on the desktop, the same for every device.`})})}var lP={id:`setup`,sheets:[{id:`setup`,persisted:!1,render:()=>(0,H.createElement)(oP)},{id:`repohealth`,persisted:!1,render:()=>{let e=PN.get();return e?(0,H.createElement)(sP,{repo:e}):null}}],boot:()=>eP(),settings:[{group:`sessions`,order:30,render:()=>(0,H.createElement)(cP)}]};function uP({l:e,windowTok:t,tok:n}){let r=Zr(e);if(r.count<=0&&r.unmeasured<=0)return null;let i=Hr(r),a=Yte(r)??gte(r),o=qee(r),s=Bee(r),c=Va(r,n,t),l=Eee(r),u=(e,t)=>t.count>0&&(0,J.jsxs)(`div`,{className:`row ctx-row ctx-val`,children:[(0,J.jsx)(SE,{children:Sa(e,t.count)}),(0,J.jsx)(`span`,{className:`row-meta`,children:_ee(t).map(e=>(0,J.jsx)(Q,{children:e},e))})]},e);return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`ctx-summary`,children:`What compacting saved`}),i&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:i}),u(`manual`,e.manual),u(`auto`,e.auto),a&&(0,J.jsxs)(`div`,{className:`empty ctx-note`,children:[a,o?` ${o}`:``]}),c&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:c}),s&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:s}),(r.savedTok>0||r.rebuildTok>0)&&(0,J.jsxs)(`details`,{className:`hint-more ctx-method`,children:[(0,J.jsx)(`summary`,{children:`how these two figures were arrived at`}),(0,J.jsx)(`p`,{children:Pte()})]}),l&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:l})]})}function dP({cost:e,onFresh:t,onCompact:n,noDoors:r}){return(0,J.jsxs)(`div`,{className:`ctx-cost ctx-cost-${e.level}`,children:[(0,J.jsxs)(`div`,{className:`ctx-cost-head`,children:[(0,J.jsx)(Al,{size:14}),(0,J.jsx)(`span`,{children:e.chip?`${e.chip} a fresh session`:`about a fresh session`})]}),(0,J.jsx)(`div`,{className:`ctx-cost-note`,children:e.note}),e.advice&&(0,J.jsx)(`div`,{className:`ctx-cost-note`,children:e.advice}),e.advice&&!r&&t&&(0,J.jsx)(`div`,{className:`sheet-actions`,children:(0,J.jsxs)(Y,{onClick:t,children:[(0,J.jsx)(os,{size:14}),` new session in this repo`]})}),e.advice&&!r&&!t&&(0,J.jsx)(CE,{cants:[{label:`a new session from here`,reason:`this session's directory is not one of this desktop's repos, so there is nowhere to start one`}]}),(0,J.jsxs)(`details`,{className:`hint-more ctx-method ctx-cost-more`,children:[(0,J.jsx)(`summary`,{children:`why the next turn costs this`}),(0,J.jsxs)(`p`,{children:[`Every turn re-sends the whole conversation, so the next one is priced by what is already here, not by what you are about to ask.`,e.advice&&!r&&n&&Ma(!0)?` ${Ma(!0)}`:``]})]})]})}var fP=27e5;function pP(e,t,n,r,i){let a=[...new Set([r,...e,i])].filter(e=>e>=r&&e<=i).sort((e,t)=>e-t),o=i-r,s=()=>({t0:r,t1:i,px:e=>t+(e-r)/(o||1)*n,tx:e=>r+(e-t)/(n||1)*(o||1),breaks:[]});if(o<=0||a.length<2)return s();let c=a.slice(0,-1).map((e,t)=>({from:e,to:a[t+1]})).filter(e=>e.to-e.from>fP).sort((e,t)=>t.to-t.from-(e.to-e.from)).slice(0,8).sort((e,t)=>e.from-t.from);if(!c.length)return s();let l=Math.min(18,n/(c.length*3||1)),u=o-c.reduce((e,t)=>e+(t.to-t.from),0),d=n-c.length*l;if(u<=0||d<=0)return s();let f=[],p=t,m=r;for(let e of c){if(e.from>m){let t=(e.from-m)/u*d;f.push({t0:m,t1:e.from,x0:p,w:t,dead:!1}),p+=t}f.push({t0:e.from,t1:e.to,x0:p,w:l,dead:!0}),p+=l,m=e.to}return i>m&&f.push({t0:m,t1:i,x0:p,w:t+n-p,dead:!1}),{t0:r,t1:i,px:e=>{if(e<=r)return t;if(e>=i)return t+n;for(let t of f)if(e<=t.t1)return t.x0+(t.t1>t.t0?(e-t.t0)/(t.t1-t.t0)*t.w:0);return t+n},tx:e=>{if(e<=t)return r;if(e>=t+n)return i;for(let t of f)if(e<=t.x0+t.w)return t.t0+(t.w>0?(e-t.x0)/t.w*(t.t1-t.t0):0);return i},breaks:f.filter(e=>e.dead).map(e=>({x:e.x0,w:e.w,from:e.t0,to:e.t1}))}}function mP(e){return(e??[]).flatMap(e=>(e.ctx??[]).map(([e])=>e))}function hP(e){let{width:t,height:n,pad:r,samples:i,refs:a,events:o,windowTok:s}=e,c=mP(e.agents),{w:l,h:u}=hD(t,n,r),d=[...i.map(e=>e.t),...o.map(e=>e.t),...o.flatMap(e=>e.resetAt==null?[]:[e.resetAt]),...c],f=d.length?Math.min(...d):0,p=d.length?Math.max(...d):1;p<=f&&(f-=3e4,p+=3e4);let m=e.value??yP,h=i.reduce((e,t)=>m(t)>e?m(t):e,0),g=e.value?h:Math.max(h,...(e.agents??[]).map(e=>e.peakTok??0)),{top:_,ticks:v}=s?mD(s,Math.max(g,...a)):pD(Math.max(g,...a,1),e.yWant),y=pP([...i.map(e=>e.t),...c].sort((e,t)=>e-t),r.left,l,f,p);return{x:r.left,y:r.top,w:l,h:u,t0:f,t1:p,yMax:_,yTicks:v,windowTok:s,px:y.px,tx:y.tx,breaks:y.breaks,py:gD(r.top,u,_)}}function gP(e){let t=Math.round(e/6e4);if(t<90)return`${t} min`;let n=t/60;return n<36?`${Math.round(n*10)/10} h`:`${Math.round(n/24*10)/10} d`}function _P(e,t){let n=mi(t,e.windowTok);return n==null?OD(t):`${Math.round(n)}%`}function vP(e,t){let n=mi(e,t);return n==null?OD(e):`${Math.round(n)}% · ${OD(e)}`}var yP=e=>e.tok,bP=e=>e.used??0;function xP(e){return e.some(e=>e.used!=null&&e.used>0)}function SP(e,t,n,r){if(!xP(e))return null;let i=e.reduce((e,t)=>t.used!=null&&t.used>e?t.used:e,0),a=t!=null&&t>=i?t:null,o=a!=null&&n!=null&&n>0?n:null,s=r?.total!=null&&r.total>0?r.total:null;return{end:i,total:a,agents:o,top:Math.max(i,a??0),costUsd:s,agentCostUsd:s!=null&&r?.agents!=null&&r.agents>0?r.agents:null,unpricedTok:r?.unpricedTok!=null&&r.unpricedTok>0?r.unpricedTok:null}}function CP(e,t){let n=e.total==null?e.end:e.total,r=e.costUsd==null?`${OD(n)} spent`:`${Ii(e.costUsd)} at list prices · ${OD(n)} spent`,i=[t?`${r} (at least)`:`${r} so far`];return e.agents!=null&&i.push(e.agentCostUsd==null?`${OD(e.agents)} of it in subagents`:`${Ii(e.agentCostUsd)} / ${OD(e.agents)} of it in subagents`),i.join(` · `)}function wP(e,t,n=!1){let r=[];e.costUsd!=null&&e.unpricedTok!=null&&r.push(`${OD(e.unpricedTok)} of these tokens ran on a model with no published rate and are in neither dollar figure.`),t&&r.push(`This log is longer than the host reads in one go, so the curve starts part-way up.`);let i=[`Every request's input, cache reads and cache writes plus what it wrote back, added up as the conversation went. It only rises — a compaction resets the window, never the bill.`];return e.costUsd!=null&&i.push(`The ${Ii(e.costUsd)} is what the API would have charged for those tokens at published rates, priced per request on the model that ran it — not what anybody paid, and nothing to do with what a subscription costs.`),e.agents!=null&&i.push(n?`The grey band on top is the ${OD(e.agents)} its subagents spent, placed at the times their own logs record, so its top edge ends on the dashed whole-session total.`:`The dashed line is the session's whole total; the gap between it and the curve is the ${OD(e.agents)} its subagents spent, which this host did not send as a series over time.`),i.push(`A floor: an agent log this desktop never saw is one nothing here can add.`),{lead:r.length?r.join(` `):null,more:i.join(` `)}}function TP(e,t){if(!e)return null;let n=t&&Xi(t)>0?t:null,r=Un(Un(vi(),e),n??{});return Xi(r)<=0?null:{all:r,main:e,agents:n}}function EP(e){let t=Qn(e.all);return t==null?null:`What those tokens were · ${Math.round(t)}% of everything sent in came out of the cache`}function DP(e,t){let n=[];return e.agents&&n.push(`Subagents are IN this bar: ${OD(Xi(e.agents))} of it.`),t&&n.push(`A floor: this log is longer than the host reads in one go, so every kind here starts part-way up.`),{lead:n.length?n.join(` `):null,more:[`The same four kinds, counted the same way, as the all-sessions token screen — this conversation is a slice of that total, not a second opinion about it.`,`Turns here are REQUESTS, not prompts — a turn that ran thirteen tools sent fourteen of them, which is the denominator the all-sessions screen uses too.`].join(` `)}}function OP(e,t,n){if(!n?.length||!t.length)return{area:``,top:``};let r=vD,i=e=>{if(e<t[0].t)return 0;let n=t[t.length-1];if(e>=n.t)return bP(n);let r=0;for(;r<t.length-1&&t[r+1].t<=e;)r++;let i=t[r],a=t[r+1];return a.t===i.t?bP(a):bP(i)+(bP(a)-bP(i))*(e-i.t)/(a.t-i.t)},a=[...new Set([...t.map(e=>e.t).filter(e=>e>n[0][0]),...n.map(([e])=>e)])].sort((e,t)=>e-t),o=[],s=[],c=0,l=0;for(let t of a){let a=i(t),u=r(e.px(t)),d=l;for(;c<n.length&&n[c][0]<=t;)l=n[c++][1];l!==d&&o.push(`${u},${r(e.py(a+d))}`),o.push(`${u},${r(e.py(a+l))}`),s.unshift(`${u},${r(e.py(a))}`)}return o.length<2?{area:``,top:``}:{area:xD(o,s),top:`M${o.join(`L`)}`}}function kP(e,t,n=yP){return yD(t,t=>e.px(t.t),t=>e.py(n(t)))}function AP(e,t,n=yP){let r=kP(e,t,n);return r?bD(r,vD(e.px(t[0].t)),vD(e.px(t[t.length-1].t)),vD(e.py(0))):``}function jP(e,t,n){if(!t.length)return n.map(e=>({...e,d:``,total:0}));let r=vD,i=t.length>1&&n.length>0&&n.every(e=>e.perRequest),a=e=>n.reduce((t,n)=>t+n.at(e),0);return n.map((o,s)=>{let c=[],l=[],u=0;t.forEach((d,f)=>{let p=0;for(let e=0;e<s;e++)p+=n[e].at(d);let m=o.at(d);u+=m;let h=r(e.px(d.t));c.push(`${h},${r(e.py(p+m))}`),l.unshift(`${h},${r(e.py(p))}`);let g=t[f+1];if(i&&g){let t=a(d),n=t>0?a(g)/t:0,i=r(e.px(g.t));c.push(`${i},${r(e.py((p+m)*n))}`),l.unshift(`${i},${r(e.py(p*n))}`)}});let d=t.length>1?xD(c,l):``;return{...o,d,total:u}})}function MP(e,t,n){return e.some(e=>e[t])?qn.filter(e=>!n||n(e.id)).map(e=>({key:e.id,name:e.name,slot:e.slot,at:n=>{let r=n[t];return r?Dte(r)[e.id]:0},perRequest:t===`kinds`})):null}function NP(e,t,n){return _D(t,e.tx(n),e=>e.t)}function PP(e,t){if(!e?.length)return null;let n=RD(e),r=e.map((e,t)=>({id:e,idx:t,slot:n.get(e)})).filter(t=>t.slot!=null&&e.indexOf(t.id)===t.idx).sort((e,t)=>ID(e.slot,t.slot)),i=new Map(r.map(e=>[e.idx,e.slot])),a=e.length-r.length;return{named:r,rest:a>0||t?{slot:4,name:a>0?`${a} more`:`unattributed`}:null,slotOf:e=>(e==null?void 0:i.get(e))??4}}function FP(e){return(er(e)??e).replace(/^claude-/,``)}var IP=3,LP=2;function RP(e,t,n){let r=t.reduce((e,t)=>!e||t.tok>e.tok?t:e,null),i=[],a=[];for(let o of[...t].sort((e,t)=>e.at-t.at||e.endAt-t.endAt)){let t=Math.max(e.x,Math.min(e.x+e.w-IP,e.px(o.at))),s=o.running?e.x+e.w:Math.min(e.x+e.w,Math.max(t+IP,e.px(Math.max(o.at,o.endAt)))),c=i.findIndex(e=>e+LP<=t);c<0?(c=i.length,i.push(s)):i[c]=s,a.push({run:o,x:t,w:s-t,lane:c,slot:n?n.slotOf(o.model):0,dearest:o===r,open:!!o.running})}return{bars:a,lanes:i.length}}function zP(e){let t=e<=8?13:Math.max(5,Math.floor(104/e));return{laneH:t,barH:Math.max(3,t-3),plotH:Math.max(1,e)*t}}function BP(e,t,n,r,i){if(!e.length)return null;let a=Math.floor((i-n)/t),o=e=>r<e.x?e.x-r:r>e.x+e.w?r-(e.x+e.w):0,s=e.some(e=>e.lane===a)?e.filter(e=>e.lane===a):e;return s.reduce((e,t)=>o(t)<o(e)?t:e,s[0])}function VP(e){let t=e.flatMap(e=>[[e.at,1],[e.running?1/0:Math.max(e.at,e.endAt),-1]]).sort((e,t)=>e[0]-t[0]||e[1]-t[1]),n=0,r=0;for(let[,e]of t)n+=e,n>r&&(r=n);return r}function HP(e,t,n){let r=t&&e.model!=null?t[e.model]:null;return[e.type??`agent`,r?FP(r):null,e.running?`started ${AD(e.at,n)} · still running, last wrote ${AD(e.endAt,n)}`:`${AD(e.at,n)}–${AD(e.endAt,n)} (${gP(Math.max(0,e.endAt-e.at))})`,`${OD(e.tok)} spent`,e.peakTok?`window peaked at ${OD(e.peakTok)}`:null,e.costUsd==null?null:Ii(e.costUsd)].filter(Boolean).join(` · `)}function UP(e,t){if(!e.length)return`No subagents — every turn here ran in this conversation.`;let n=e.filter(e=>!e.running&&e.endAt>e.at),r=e.reduce((e,t)=>t.tok>e.tok?t:e,e[0]),i=[`${e.length} subagent${e.length>1?`s`:``}`],a=e.filter(e=>e.running).length;a&&i.push(`${a===e.length&&a>1?`all`:a} still running (fading out at the right)`);let o=VP(e);if(o>1&&i.push(`up to ${o} at once`),n.length){let e=n.map(e=>e.endAt-e.at).sort((e,t)=>e-t)[Math.floor(n.length/2)];i.push(`median ${gP(e)} each`)}let s=t&&r.model!=null?t[r.model]:null;return i.push(`dearest ${OD(r.tok)}${s?` on ${FP(s)}`:``}${e.length>1?` (outlined)`:``}`),i.join(` · `)}function WP(e,t){if(t==null)return null;let n=t-e.reduce((e,t)=>e+t.tok,0);return n>0?`${OD(n)} of the subagents' tokens are in logs with no timestamp: in every total here, and on no chart.`:null}function GP(e,t){let n=vD;return t.filter(e=>(e.ctx?.length??0)>0).map(t=>({id:t.id,d:t.ctx.length===1?`M${n(e.px(t.ctx[0][0])-1)},${n(e.py(t.ctx[0][1]))}h2`:`M${t.ctx.map(([t,r])=>`${n(e.px(t))},${n(e.py(r))}`).join(`L`)}`}))}function KP(e){let t=Math.max(0,...(e??[]).map(e=>e.peakTok??0));return t>0?t:null}function qP(e,t,n){let r=e.pts;if(!r.length)return null;let i=e.autoCompactTok??null,a=e.autoCompactSetTok?Math.max(e.autoCompactSetTok,e.peak,...r):e.windowTok?mD(e.windowTok,Math.max(e.peak,i??0)).top:Math.max(e.peak,i??0,...r,1),o=e=>r.length===1?t:e/(r.length-1)*t,s=e=>n-Math.max(0,Math.min(e,a))/a*n,c=yD(r,(e,t)=>o(t),e=>s(e));return{line:c,area:bD(c,`0`,vD(o(r.length-1)),n),endX:o(r.length-1),endY:s(r[r.length-1]),ticks:e.marks.map(e=>({x:e.at*t,kind:e.kind})),refY:i==null?null:s(i),...JP(e.agentEnv,r.length,o,s,n)}}function JP(e,t,n,r,i){if(!e||e.length!==t||!e.some(e=>e>0))return{agentArea:null,agentPeak:null};let a=e.map((e,t)=>`L${n(t).toFixed(1)},${r(e).toFixed(1)}`).join(``);return{agentArea:`M${n(0).toFixed(1)},${i}${a}L${n(t-1).toFixed(1)},${i}Z`,agentPeak:Math.max(...e)}}function YP(e,t,n){let r=e.usedPts;if(!r||!r.length)return null;let i=r[r.length-1];if(!(i>0))return null;let a=e.usageTok!=null&&e.usageTok>=i?e.usageTok:null,o=a!=null&&e.agentTok!=null&&e.agentTok>0?a:null,s=e.agentUsedPts,c=o!=null&&s&&s.length===r.length&&s.every(e=>Number.isFinite(e)&&e>=0)?r.map((e,t)=>e+s[t]):null,l=c&&c[c.length-1]<=o*1.001?c:null,u=Math.max(i,o??0,1),d=e=>r.length===1?t:e/(r.length-1)*t,f=e=>n-.5-Math.max(0,Math.min(e,u))/u*(n-1),p=yD(r,(e,t)=>d(t),e=>f(e));return{line:p,area:bD(p,`0`,vD(d(r.length-1)),n),endX:d(r.length-1),endY:f(i),totalY:o!=null&&!l?f(o):null,agentBand:l?XP(r,l,d,f):null,top:u,end:i}}function XP(e,t,n,r){let i=yD(t,(e,t)=>n(t),e=>r(e));return{area:`${i}${e.map((e,t)=>[n(t),r(e)]).reverse().map(([e,t])=>`L${vD(e)},${vD(t)}`).join(``)}Z`,top:i}}function ZP(e,t){let n=e.agentTok!=null&&e.agentTok>0?e.agentTok:null;return[`spent: ${OD(t.end)} in this conversation so far`,n==null?null:`${OD(n)} more in its subagents — ${t.agentBand?`the grey band stacked on top`:`the dashed line`}`,e.costUsd==null?null:Dt(e.costUsd,e.agentCostUsd??null,e.unpricedTok??null),`this curve tops out at ${OD(t.top)} and is scaled to this session, not to the others`].filter(Boolean).join(` · `)}function QP(e){return e.kind===`compact`?{kind:`compact`,text:(e.trigger===`auto`?`Auto-compacted`:e.trigger===`manual`?`Compacted (/compact)`:`Compacted`)+(e.preTok&&e.postTok?` · ${OD(e.preTok)} → ${OD(e.postTok)}`:``)}:e.kind===`rebuild`?{kind:`rebuild`,text:`Cache expired — re-wrote ${e.wroteTok?OD(e.wroteTok):`the window`}${e.gapMs?` after ${gP(e.gapMs)} quiet`:``}`}:{kind:`limit`,text:(e.weekly?`Weekly usage limit`:`Usage limit`)+(e.resetAt==null?``:` · back at ${AD(e.resetAt,0)}`)}}function $P(e,t,n,r){if(t==null||!(t>0))return`This model’s context window is not known here, so the axis is in tokens and is NOT the shared 0–100% scale — this graph cannot be compared with another session’s.`;let i=OD(t);switch(e){case`measured`:return`100% is ${i} — the window ${n??`this model`} has been SEEN to hold, so it is the same scale as every other session’s graph.`;case`screen`:return`100% is the ${i} window the CLI printed on screen.`;case`source`:return`100% is ${i}, the window ${r??`this backend`} states${n?` for ${n}`:``} in this session.`;case`config`:return`100% is ${i}, as ${r??`this backend`}’s configuration states it${n?` for ${n}`:``} — a setting this app read, not something anybody watched happen. A model running locally may be holding less than that, and nothing here would show it.`;case`model`:return`100% is ${i}, assumed from the model id${n?` (${n})`:``} — nothing here has held more than that yet, so if it is really a larger window this axis will correct itself the first time a conversation goes past.`;default:return`This model’s context window is not known here, so the axis is in tokens and is NOT the shared 0–100% scale — this graph cannot be compared with another session’s.`}}function eF(e,t,n,r){if(!e.length)return null;let i=e[e.length-1],a=e.reduce((e,t)=>t.tok>e?t.tok:e,0),o=t.filter(e=>e.kind===`compact`).length,s=t.filter(e=>e.kind===`limit`).length,c=mi(i.tok,n),l=mi(a,n),u=[c==null?`${OD(i.tok)} now`:`${Math.round(c)}% of ${OD(n)}`,l==null?`peak ${OD(a)}`:`peak ${Math.round(l)}%`],d=KP(r);return d!=null&&u.push(`an agent held ${OD(d)}`),o&&u.push(`${o} compaction${o>1?`s`:``}`),s&&u.push(`${s} usage limit${s>1?`s`:``}`),u.join(` · `)}var tF={env:`the daemon's CLAUDE_CODE_AUTO_COMPACT_WINDOW`,local:`.claude/settings.local.json`,project:`.claude/settings.json`,user:`~/.claude/settings.json`,unset:``};function nF(e){return`auto-compact set ${ni(e)}`}function rF(e){if(e.source===`unset`)return`No autoCompactWindow is set for this repo, so the CLI compacts near the model's own window — no setting line is drawn.`;let t=bn(tF,e.source,`a place this app version cannot name`);return e.tokens==null?/^auto$/i.test(e.raw?.trim()??``)?`autoCompactWindow is "auto" in ${t}, so the CLI compacts near the model's own window — no setting line is drawn.`:`autoCompactWindow in ${t} reads ${JSON.stringify(e.raw??``)}, which is not a size — no setting line is drawn.`:`The dotted line is autoCompactWindow as ${t} sets it now (${ni(e.tokens)}) — the setting today, not necessarily what this conversation ran under.`}var iF=`var(--ctx-series)`,aF=`var(--ctx-compact)`,oF=`var(--ctx-limit)`,sF={top:10,right:10,bottom:20,left:40},cF={top:12,right:10,bottom:20,left:40};function lF({spark:e,width:t=76,height:n=20,value:r=!1}){let i=uF((0,H.useId)()),a=qP(e,t,n);if(!a)return null;let o=e.pts[e.pts.length-1],s=mi(o,e.windowTok),c=e.marks.filter(e=>e.kind===`compact`).length,l=e.marks.filter(e=>e.kind===`limit`).length,u=yt(e.costUsd)??sn(e.usageTok),d=[s==null?`context: ${OD(o)} now, peak ${OD(e.peak)} (window unknown — this row's scale is its own)`:`context: ${Math.round(s)}% of ${OD(e.windowTok)}, peak ${OD(e.peak)}`,e.usageTok!=null&&e.usageTok>0?tne(e.usageTok,e.agentTok??null):null,e.costUsd==null?null:Dt(e.costUsd,e.agentCostUsd??null,e.unpricedTok??null),a.agentPeak==null?null:`agents peaked at ${OD(a.agentPeak)}`,e.autoCompactTok==null?null:`compacts at ${OD(e.autoCompactTok)}`,e.autoCompactSetTok?`curve tops out at the auto-compact setting, ${OD(e.autoCompactSetTok)}`:null,c?`${c} compaction${c>1?`s`:``}`:null,l?`${l} usage limit${l>1?`s`:``}`:null].filter(Boolean).join(` · `),f=(0,J.jsxs)(`svg`,{className:`ctx-spark`,width:t,height:n,viewBox:`0 0 ${t} ${n}`,role:`img`,"aria-label":d,children:[(0,J.jsx)(`title`,{children:d}),(0,J.jsx)(`defs`,{children:(0,J.jsx)(dF,{id:i})}),(0,J.jsx)(`line`,{x1:0,x2:t,y1:n-.5,y2:n-.5,stroke:`currentColor`,strokeOpacity:.16,strokeWidth:1}),a.refY!=null&&(0,J.jsx)(`line`,{x1:0,x2:t,y1:a.refY,y2:a.refY,stroke:`currentColor`,strokeOpacity:.35,strokeWidth:1,strokeDasharray:`2 3`}),a.agentArea&&(0,J.jsx)(`path`,{d:a.agentArea,fill:`currentColor`,fillOpacity:.13}),(0,J.jsx)(`path`,{d:a.area,fill:`url(#${i})`}),(0,J.jsx)(`path`,{d:a.line,fill:`none`,stroke:iF,strokeWidth:1.5,strokeLinejoin:`round`,strokeLinecap:`round`}),a.ticks.map((e,t)=>(0,J.jsx)(`line`,{x1:e.x,x2:e.x,y1:1,y2:n-1.5,strokeLinecap:`round`,stroke:e.kind===`compact`?aF:oF,strokeWidth:1.25,strokeOpacity:.7},t)),(0,J.jsx)(`circle`,{cx:a.endX,cy:a.endY,r:2.6,fill:iF,stroke:`var(--panel)`,strokeWidth:2})]});return r?(0,J.jsxs)(`span`,{className:`ctx-spark-pair`,title:d,children:[f,(0,J.jsx)(`span`,{className:`ctx-spark-val`,children:kD(o)}),u&&!YP(e,t,n)&&(0,J.jsxs)(`span`,{className:`ctx-spark-use`,children:[(0,J.jsx)(Wo,{size:10}),` `,u]})]}):f}function uF(e){return`w${e.replace(/[^a-zA-Z0-9_-]/g,``)}`}function dF({id:e}){return(0,J.jsxs)(`linearGradient`,{id:e,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,J.jsx)(`stop`,{offset:`0%`,stopColor:iF,stopOpacity:.3}),(0,J.jsx)(`stop`,{offset:`100%`,stopColor:iF,stopOpacity:.02})]})}function fF({spark:e,width:t=76,height:n=14,warn:r=null}){let i=uF((0,H.useId)()),a=YP(e,t,n);if(!a)return null;let o=yt(e.costUsd)??sn(e.usageTok)??kD(a.end),s=r?`${r.text}\n${ZP(e,a)}`:ZP(e,a);return(0,J.jsxs)(`span`,{className:`ctx-spark-pair`,title:s,children:[(0,J.jsxs)(`svg`,{className:`ctx-spark`,width:t,height:n,viewBox:`0 0 ${t} ${n}`,role:`img`,"aria-label":s,children:[(0,J.jsx)(`title`,{children:s}),(0,J.jsx)(`defs`,{children:(0,J.jsx)(dF,{id:i})}),(0,J.jsx)(`line`,{x1:0,x2:t,y1:n-.5,y2:n-.5,stroke:`currentColor`,strokeOpacity:.16,strokeWidth:1}),a.totalY!=null&&(0,J.jsx)(`line`,{x1:0,x2:t,y1:a.totalY,y2:a.totalY,stroke:`currentColor`,strokeOpacity:.45,strokeWidth:1,strokeDasharray:`3 3`}),(0,J.jsx)(`path`,{d:a.area,fill:`url(#${i})`}),a.agentBand&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`path`,{d:a.agentBand.area,fill:`var(--fg)`,fillOpacity:.16}),(0,J.jsx)(`path`,{d:a.agentBand.top,fill:`none`,stroke:`var(--fg)`,strokeOpacity:.5,strokeWidth:1,strokeLinejoin:`round`,strokeLinecap:`round`})]}),(0,J.jsx)(`path`,{d:a.line,fill:`none`,stroke:iF,strokeWidth:1.5,strokeLinejoin:`round`,strokeLinecap:`round`}),(0,J.jsx)(`circle`,{cx:a.endX,cy:a.endY,r:2.2,fill:iF,stroke:`var(--panel)`,strokeWidth:1.5})]}),(0,J.jsxs)(`span`,{className:r?`ctx-spark-use spend-warn-${r.level}`:`ctx-spark-use`,children:[r?(0,J.jsx)(Js,{size:10,"aria-label":r.level===`high`?`past the red spend mark`:`past the orange spend mark`}):(0,J.jsx)(Wo,{size:10}),` `,o]})]})}function pF({samples:e,events:t,windowTok:n,autoCompactTok:r,autoCompactSetTok:i=null,width:a,height:o=200,onHover:s,bands:c,agents:l}){let u=(0,H.useRef)(null),[d,f]=(0,H.useState)(null),p=(0,H.useCallback)(e=>{f(e),s?.(e)},[s]),m=hP({width:a,height:o,pad:sF,samples:e,events:t,refs:[r,i].filter(e=>e!=null),windowTok:n,agents:l}),h=m.t1-m.t0,g=(0,H.useCallback)(t=>{let n=u.current?.getBoundingClientRect();if(!n)return;let r=(t.clientX-n.left)/n.width*a;p(NP(m,e,r))},[m,e,a,p]),_=m.yTicks,v=[0,.5,1].map(e=>m.tx(m.x+e*m.w));return(0,J.jsxs)(`svg`,{ref:u,className:`ctx-chart`,width:a,height:o,viewBox:`0 0 ${a} ${o}`,onPointerDown:g,onPointerMove:g,onPointerLeave:()=>p(null),onPointerCancel:()=>p(null),role:`img`,"aria-label":`context window over time`,children:[_.map(e=>(0,J.jsx)(`line`,{x1:m.x,x2:m.x+m.w,y1:m.py(e),y2:m.py(e),stroke:`var(--line)`,strokeWidth:1},`g${e}`)),c?(0,J.jsx)(hF,{p:m,samples:e,series:c}):(0,J.jsx)(`path`,{d:AP(m,e),fill:iF,fillOpacity:.14}),l&&GP(m,l).map(e=>(0,J.jsx)(`path`,{d:e.d,fill:`none`,stroke:`var(--fg)`,strokeOpacity:.45,strokeWidth:1.25,strokeLinejoin:`round`,strokeLinecap:`round`},`a${e.id}`)),(0,J.jsx)(`path`,{d:kP(m,e),fill:`none`,stroke:iF,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`}),m.breaks.map((e,t)=>(0,J.jsxs)(`g`,{children:[(0,J.jsx)(`title`,{children:`${gP(e.to-e.from)} with no activity — the axis is compressed here`}),(0,J.jsx)(`rect`,{x:e.x,y:m.y,width:e.w,height:m.h,fill:`var(--panel)`}),[0,1].map(t=>(0,J.jsx)(`line`,{x1:e.x+1+t*5,y1:m.y+m.h,x2:e.x+e.w-5+t*5,y2:m.y,stroke:`var(--line)`,strokeWidth:1},t))]},`k${t}`)),t.filter(e=>e.kind===`limit`&&e.resetAt!=null).map((e,t)=>(0,J.jsx)(`rect`,{x:m.px(e.t),y:m.y,width:Math.max(1,m.px(e.resetAt)-m.px(e.t)),height:m.h,fill:oF,fillOpacity:.12},`b${t}`)),r!=null&&(0,J.jsx)(bF,{p:m,v:r,label:`compacts ~${_P(m,r)}`,below:m.py(r)-m.y<13}),i!=null&&(0,J.jsx)(bF,{p:m,v:i,label:nF(i),below:m.py(i)-m.y<13,start:!0,dash:`1.5 3`}),t.filter(e=>e.kind!==`rebuild`).map((e,t)=>{let n=m.px(e.t),r=Math.min(m.x+m.w-5,Math.max(m.x+5,n)),i=e.kind===`compact`?aF:oF;return(0,J.jsxs)(`g`,{children:[(0,J.jsx)(`title`,{children:QP(e).text}),(0,J.jsx)(`line`,{x1:n,x2:n,y1:m.y,y2:m.y+m.h,stroke:i,strokeWidth:1.5,strokeOpacity:.85}),e.kind===`compact`?(0,J.jsx)(`path`,{d:`M${r-4},${m.y}L${r+4},${m.y}L${r},${m.y+6}Z`,fill:i,stroke:`var(--panel)`,strokeWidth:1}):(0,J.jsx)(`rect`,{x:r-3.5,y:m.y,width:7,height:7,fill:i,stroke:`var(--panel)`,strokeWidth:1})]},`e${t}`)}),_.map(e=>(0,J.jsx)(`text`,{className:`ctx-tick`,x:m.x-6,y:m.py(e)+3.5,textAnchor:`end`,children:_P(m,e)},`t${e}`)),v.map((e,t)=>(0,J.jsx)(`text`,{className:`ctx-tick`,x:m.px(e),y:o-6,textAnchor:t===0?`start`:t===v.length-1?`end`:`middle`,children:AD(e,h)},`x${t}`)),d&&(0,J.jsxs)(`g`,{children:[(0,J.jsx)(`line`,{x1:m.px(d.t),x2:m.px(d.t),y1:m.y,y2:m.y+m.h,stroke:`var(--fg)`,strokeOpacity:.35,strokeWidth:1}),(0,J.jsx)(`circle`,{cx:m.px(d.t),cy:m.py(d.tok),r:4.5,fill:`var(--ctx-series)`,stroke:`var(--panel)`,strokeWidth:2})]})]})}function mF({samples:e,events:t,facts:n,width:r,height:i=96,bands:a,agents:o,agentCum:s}){let c=hP({width:r,height:i,pad:cF,samples:e,events:t,windowTok:null,agents:o,value:bP,refs:n.total==null?[]:[n.total],yWant:3}),l=c.t1-c.t0,u=[0,.5,1].map(e=>c.tx(c.x+e*c.w)),d=n.agents==null?{area:``,top:``}:OP(c,e,s);return(0,J.jsxs)(`svg`,{className:`ctx-chart`,width:r,height:i,viewBox:`0 0 ${r} ${i}`,role:`img`,"aria-label":`tokens spent over time`,children:[c.yTicks.map(e=>(0,J.jsx)(`line`,{x1:c.x,x2:c.x+c.w,y1:c.py(e),y2:c.py(e),stroke:`var(--line)`,strokeWidth:1},`g${e}`)),a?(0,J.jsx)(hF,{p:c,samples:e,series:a}):(0,J.jsx)(`path`,{d:AP(c,e,bP),fill:iF,fillOpacity:.14}),d.area&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`path`,{d:d.area,fill:`var(--fg)`,fillOpacity:.16}),(0,J.jsx)(`path`,{d:d.top,fill:`none`,stroke:`var(--fg)`,strokeOpacity:.5,strokeWidth:1.25,strokeLinejoin:`round`})]}),(0,J.jsx)(`path`,{d:kP(c,e,bP),fill:`none`,stroke:iF,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`}),c.breaks.map((e,t)=>(0,J.jsxs)(`g`,{children:[(0,J.jsx)(`title`,{children:`${gP(e.to-e.from)} with no activity — the axis is compressed here`}),(0,J.jsx)(`rect`,{x:e.x,y:c.y,width:e.w,height:c.h,fill:`var(--panel)`}),[0,1].map(t=>(0,J.jsx)(`line`,{x1:e.x+1+t*5,y1:c.y+c.h,x2:e.x+e.w-5+t*5,y2:c.y,stroke:`var(--line)`,strokeWidth:1},t))]},`k${t}`)),t.filter(e=>e.kind!==`rebuild`).map((e,t)=>(0,J.jsx)(`line`,{x1:c.px(e.t),x2:c.px(e.t),y1:c.y,y2:c.y+c.h,stroke:e.kind===`compact`?aF:oF,strokeWidth:1.5,strokeOpacity:.55},`e${t}`)),n.total!=null&&n.agents!=null&&(0,J.jsx)(bF,{p:c,v:n.total,label:`${OD(n.total)} with subagents`,below:c.py(n.total)-c.y<13}),c.yTicks.map(e=>(0,J.jsx)(`text`,{className:`ctx-tick`,x:c.x-6,y:c.py(e)+3.5,textAnchor:`end`,children:OD(e)},`t${e}`)),u.map((e,t)=>(0,J.jsx)(`text`,{className:`ctx-tick`,x:c.px(e),y:i-6,textAnchor:t===0?`start`:t===u.length-1?`end`:`middle`,children:AD(e,l)},`x${t}`))]})}function hF({p:e,samples:t,series:n}){let r=jP(e,t,n);return(0,J.jsx)(`g`,{children:r.map(e=>e.d&&(0,J.jsx)(`path`,{d:e.d,fill:UD[e.slot]??WD[4],fillOpacity:.85,stroke:`var(--panel)`,strokeWidth:.75,strokeOpacity:.6,children:(0,J.jsx)(`title`,{children:`${e.name}: ${OD(e.total)}`})},e.key))})}function gF({p:e,samples:t,series:n,fmt:r=OD}){let i=jP(e,t,n),a=i.reduce((e,t)=>e+t.total,0);return(0,J.jsx)(`div`,{className:`ctx-legend ctx-legend-stack`,children:i.map(e=>(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`10`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`rect`,{x:`0`,y:`1`,width:`10`,height:`8`,rx:`2`,fill:UD[e.slot]??WD[4]})}),e.name,` `,(0,J.jsx)(`b`,{children:r(e.total)}),a>0&&(0,J.jsxs)(`span`,{className:`ctx-legend-pct`,children:[` `,oi(e.total/a)]})]},e.key))})}function _F({samples:e,events:t,agents:n,slots:r,width:i,onPick:a,picked:o}){let s=(0,H.useRef)(null),c=uF((0,H.useId)()),l=hP({width:i,height:100,pad:{...cF,top:6},samples:e,events:t,windowTok:null,refs:[],agents:n}),{bars:u,lanes:d}=RP(l,n,r),{laneH:f,barH:p,plotH:m}=zP(d),h=6+m+cF.bottom,g=l,_=g.t1-g.t0,v=[0,.5,1].map(e=>g.tx(g.x+e*g.w)),y=(e,t)=>{let n=s.current?.getBoundingClientRect();if(!n||!a)return;let r=(e.clientX-n.left)/n.width*i,c=(e.clientY-n.top)/n.height*h,l=BP(u,f,6,r,c);a(t&&l&&o&&l.run.id===o.id?null:l?.run??null)};return(0,J.jsxs)(`svg`,{ref:s,className:`ctx-chart`,width:i,height:h,viewBox:`0 0 ${i} ${h}`,onPointerDown:e=>y(e,!0),onPointerMove:e=>{e.buttons&&y(e,!1)},role:`img`,"aria-label":`subagents over time, one bar each`,children:[g.breaks.map((e,t)=>(0,J.jsxs)(`g`,{children:[(0,J.jsx)(`rect`,{x:e.x,y:6,width:e.w,height:m,fill:`var(--panel)`}),[0,1].map(t=>(0,J.jsx)(`line`,{x1:e.x+1+t*5,y1:6+m,x2:e.x+e.w-5+t*5,y2:6,stroke:`var(--line)`,strokeWidth:1},t))]},`k${t}`)),(0,J.jsx)(`line`,{x1:g.x,x2:g.x+g.w,y1:6+m+.5,y2:6+m+.5,stroke:`var(--line)`,strokeWidth:1}),u.map((e,t)=>{let n=o?.id===e.run.id,r=UD[e.slot]??WD[4],i=Math.min(24,e.w);return(0,J.jsxs)(`g`,{children:[e.open&&(0,J.jsx)(`defs`,{children:(0,J.jsxs)(`linearGradient`,{id:`${c}-${t}`,gradientUnits:`userSpaceOnUse`,x1:e.x+e.w-i,x2:e.x+e.w,y1:0,y2:0,children:[(0,J.jsx)(`stop`,{offset:`0`,stopColor:r}),(0,J.jsx)(`stop`,{offset:`1`,stopColor:r,stopOpacity:0})]})}),(0,J.jsx)(`rect`,{x:e.x,y:6+e.lane*f+(f-p)/2,width:e.w,height:p,rx:e.open?0:Math.min(2,p/2),fill:e.open?`url(#${c}-${t})`:r,fillOpacity:o&&!n?.55:.9,stroke:n?`var(--accent)`:e.dearest?`var(--fg)`:`none`,strokeWidth:n?2:1,strokeOpacity:e.open&&!n?.5:1,children:(0,J.jsx)(`title`,{children:`${e.run.type??`agent`} · ${OD(e.run.tok)}${e.run.running?` · still running`:``}`})})]},e.run.id)}),v.map((e,t)=>(0,J.jsx)(`text`,{className:`ctx-tick`,x:g.px(e),y:h-6,textAnchor:t===0?`start`:t===v.length-1?`end`:`middle`,children:AD(e,_)},`x${t}`))]})}function vF({agents:e,dashed:t,stacked:n}){return!e&&!t?null:(0,J.jsxs)(`div`,{className:`ctx-legend`,children:[(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`14`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`rect`,{x:`0`,y:`3`,width:`14`,height:`2.5`,rx:`1.2`,fill:iF})}),` this conversation`,n?` (stacked as the window below)`:``]}),e&&(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`10`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`rect`,{x:`0`,y:`1`,width:`10`,height:`8`,rx:`2`,fill:`var(--fg)`,fillOpacity:.3})}),` subagents`]}),t&&(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`14`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`line`,{x1:`0`,x2:`14`,y1:`5`,y2:`5`,stroke:`var(--fg)`,strokeOpacity:.5,strokeDasharray:`4 3`})}),` whole session`]})]})}function yF({slots:e,only:t}){if(!e)return null;let n=[...e.named.map(e=>({slot:e.slot,name:FP(e.id)})),...e.rest?[{slot:e.rest.slot,name:e.rest.name}]:[]].filter(e=>!t||t.has(e.slot));return n.length<2?null:(0,J.jsx)(`div`,{className:`ctx-legend ctx-legend-stack`,children:n.map(e=>(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`10`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`rect`,{x:`0`,y:`1`,width:`10`,height:`8`,rx:`2`,fill:UD[e.slot]??WD[4]})}),e.name]},e.name))})}function bF({p:e,v:t,label:n,below:r,start:i,dash:a=`4 4`}){let o=e.py(t),s=r?Math.min(e.y+e.h-2,o+11):Math.max(e.y+9,o-4);return(0,J.jsxs)(`g`,{children:[(0,J.jsx)(`line`,{x1:e.x,x2:e.x+e.w,y1:o,y2:o,stroke:`var(--fg)`,strokeOpacity:.4,strokeWidth:1,strokeDasharray:a}),(0,J.jsx)(`text`,{className:`ctx-ref`,x:i?e.x+4:e.x+e.w,y:s,textAnchor:i?`start`:`end`,children:n})]})}function xF({events:e,agents:t=0}){let n=e.filter(e=>e.kind===`compact`).length,r=e.filter(e=>e.kind===`limit`).length;return(0,J.jsxs)(`div`,{className:`ctx-legend`,children:[(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`14`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`rect`,{x:`0`,y:`3`,width:`14`,height:`2.5`,rx:`1.2`,fill:iF})}),` context`]}),t>0&&(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`14`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`rect`,{x:`0`,y:`4`,width:`14`,height:`1.25`,fill:`var(--fg)`,fillOpacity:.45})}),` each agent's own window (`,t,`)`]}),n>0&&(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`10`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`path`,{d:`M1,1L9,1L5,8Z`,fill:`var(--ctx-compact)`})}),` compaction (`,n,`)`]}),r>0&&(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`10`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`rect`,{x:`1.5`,y:`1.5`,width:`7`,height:`7`,fill:`var(--ctx-limit)`})}),` usage limit (`,r,`)`]})]})}function SF(e,t,n=5){return e.map((e,t)=>({run:e,i:t})).sort((e,t)=>{let n=e.run.costUsd??null,r=t.run.costUsd??null;return n!=null&&r!=null?r-n||t.run.tok-e.run.tok||e.i-t.i:n==null?r==null?t.run.tok-e.run.tok||e.i-t.i:1:-1}).slice(0,Math.max(0,n)).map(({run:e})=>{let n=t&&e.model!=null?t[e.model]:null;return{run:e,id:e.id,type:e.type??`agent`,model:n?FP(n):null,turns:e.turns&&e.turns>0?e.turns:null,peakTok:e.peakTok&&e.peakTok>0?e.peakTok:null,tok:e.tok,costUsd:e.costUsd??null,running:!!e.running}})}var CF=5;function wF({agents:e,models:t,picked:n,onPick:r}){let i=SF(e,t,CF);return i.length?(0,J.jsxs)(`div`,{className:`agent-top`,children:[(0,J.jsx)(`div`,{className:`ctx-summary`,children:e.length>i.length?`${i.length} dearest of ${e.length} agents`:`${i.length} agent${i.length>1?`s`:``}, dearest first`}),(0,J.jsxs)(`table`,{className:`agent-top-t`,children:[(0,J.jsx)(`thead`,{children:(0,J.jsxs)(`tr`,{children:[(0,J.jsx)(`th`,{scope:`col`,children:`agent`}),(0,J.jsx)(`th`,{scope:`col`,children:`requests`}),(0,J.jsx)(`th`,{scope:`col`,children:`peak window`}),(0,J.jsx)(`th`,{scope:`col`,children:`tokens`}),(0,J.jsx)(`th`,{scope:`col`,children:`cost`})]})}),(0,J.jsx)(`tbody`,{children:i.map(e=>(0,J.jsxs)(`tr`,{className:e.run===n||e.id===n?.id?`on`:void 0,tabIndex:0,onClick:()=>r(e.run),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),r(e.run))},children:[(0,J.jsxs)(`th`,{scope:`row`,children:[e.type,(0,J.jsx)(`small`,{children:[e.model,e.running?`running`:null].filter(Boolean).join(` · `)})]}),(0,J.jsx)(`td`,{children:e.turns==null?``:e.turns}),(0,J.jsx)(`td`,{children:e.peakTok==null?``:OD(e.peakTok)}),(0,J.jsx)(`td`,{children:OD(e.tok)}),(0,J.jsx)(`td`,{children:e.costUsd==null?``:Ii(e.costUsd)})]},e.id))})]}),(0,J.jsx)(Z,{children:`Tap a row to ring that agent in the chart above. Cost is roughly requests times window; an empty cell was not measured.`})]}):null}var TF=[2e5,3e5,4e5,5e5];function EF({value:e,onChange:t}){let n=!TF.some(t=>t===e);return(0,J.jsxs)(`div`,{className:`agent-warn`,children:[(0,J.jsxs)(`div`,{className:`ts-filter agent-warn-row`,role:`group`,"aria-label":`warn when an agent passes`,children:[(0,J.jsx)(`span`,{className:`ctx-stackpick-lab`,children:`warn when an agent passes`}),TF.map(n=>(0,J.jsx)(Y,{className:n===e?`active`:void 0,"aria-pressed":n===e,onClick:()=>t(n),children:OD(n)},n))]}),(0,J.jsxs)(`div`,{className:`ctx-cost-note`,children:[n?`Set to ${OD(e)} elsewhere. `:``,`It warns you - a chip on the session, a toast and a push - and never stops an agent. Syncs to the desktop, which sends the push.`]})]})}function DF(e){let t=(e.models??[]).map(e=>({...e}));for(let n of e.agentModels??[]){let e=t.find(e=>e.id===n.id);e?(e.tok+=n.tok,n.costUsd!=null&&(e.costUsd=(e.costUsd??0)+n.costUsd)):t.push({...n})}return t}function OF(e){let t=new Map;for(let n of e)for(let e of DF(n))t.set(e.id,(t.get(e.id)??0)+e.tok);if(!t.size)return null;let n=[...t.entries()].sort((e,t)=>t[1]-e[1]).map(([e])=>e),r=RD(n);return{of:r,rest:n.some(e=>!r.has(e))?4:null}}var kF=e=>(er(e)??e).replace(/^claude-/,``);function AF(e,t){let n=DF(e).filter(e=>e.tok>0);if(!n.length||!t)return null;let r=n.every(e=>e.costUsd!=null&&e.costUsd>0),i=e=>r?e.costUsd:e.tok,a=n.reduce((e,t)=>e+i(t),0);if(a<=0)return null;let o=[],s=[];for(let e of n){let n=t.of.get(e.id);n==null?s.push(e):o.push({id:e.id,name:kF(e.id),slot:n,share:i(e)/a,costUsd:e.costUsd,tok:e.tok})}if(s.length){let e=s.reduce((e,t)=>e+t.tok,0),t=s.every(e=>e.costUsd!=null)?s.reduce((e,t)=>e+t.costUsd,0):void 0;o.push({id:s.length===1?s[0].id:`\0rest`,name:s.length===1?kF(s[0].id):`${s.length} more`,slot:4,share:s.reduce((e,t)=>e+i(t),0)/a,costUsd:t,tok:e})}return o.sort((e,t)=>ID(e.slot,t.slot)),{by:r?`cost`:`tokens`,parts:o}}var jF=e=>e.sidechains+e.blocks.filter(e=>e.kind===`tool`&&(e.name===`Task`||e.name===`Agent`)).length,MF=e=>e!=null&&Number.isFinite(e)&&e>0;function NF(e){return e.marker||e.queued?!1:MF(e.costUsd)||MF(e.ctxTok)||MF(e.cumCostUsd)||MF(e.agentCostUsd)||dt(e.tokens)!=null||DF(e).some(e=>e.tok>0)}function PF(e){for(let t=e.length-1;t>=0;t--)if(NF(e[t]))return e[t];return null}function FF(e,t){for(let n of e){if(jF(n)>0)return!0;if(n.id===t)return!1}return!1}var IF=1e4;function LF(e,t,n){return t?n!=null&&e.sentAt!=null&&e.sentAt>=n-IF?`running`:`previous`:`last`}function RF(e,t){let n=`#${e.n}`;return t===`running`?`prompt ${n} so far · running`:t===`previous`?`prompt ${n} · a newer one is running`:t===`earlier`?`prompt ${n}`:`last prompt ${n}`}function zF(e){return e===`running`?`Figures for the prompt still running, as far as its log has got; they are re-read when it ends.`:e===`previous`?`The prompt now running is not in the log yet — its figures replace these when it ends.`:null}function BF(e){let t=MF(e.costUsd)?e.costUsd+(MF(e.agentCostUsd)?e.agentCostUsd:0):null,n=e.tokens?[e.tokens.input,e.tokens.output,e.tokens.cacheRead,e.tokens.cacheWrite].reduce((e,t)=>e+(MF(t)?t:0),0):0,r=[t==null?n>0?`${Ut(n)} tokens`:null:Ii(t),MF(e.ctxTok)?`${Ut(e.ctxTok)} ctx`:null].filter(Boolean);return r.length?r.join(` · `):null}var VF=[`var(--chart-1)`,`var(--chart-2)`,`var(--chart-3)`,`var(--chart-4)`,`var(--muted)`];function HF({parts:e}){let t=2*Math.PI*12,n=e.length>1?1.2:0,r=0;return(0,J.jsxs)(`svg`,{className:`tr-mix-donut`,viewBox:`0 0 32 32`,width:`32`,height:`32`,"aria-hidden":!0,children:[(0,J.jsx)(`circle`,{cx:`16`,cy:`16`,r:12,fill:`none`,stroke:`var(--line)`,strokeWidth:`6`}),e.map(e=>{let i=e.share*t,a=(0,J.jsx)(`circle`,{cx:`16`,cy:`16`,r:12,fill:`none`,stroke:VF[e.slot],strokeWidth:`6`,strokeDasharray:`${Math.max(.6,i-n)} ${t}`,strokeDashoffset:-r,transform:`rotate(-90 16 16)`},e.id);return r+=i,a})]})}function UF({t:e,slots:t,agentsSoFar:n,usdPerWeekPct:r,weekIncl:i,onOpen:a,next:o,trackId:s=`action:read.cost`,why:c=!1}){let l=ze({costUsd:e.costUsd,cumCostUsd:e.cumCostUsd,ctxTok:e.ctxTok,agents:jF(e),agentsSoFar:n,agentCostUsd:e.agentCostUsd,cumAgentCostUsd:e.cumAgentCostUsd,agentsRunning:e.agentsRunning,agentUnpricedTok:e.agentUnpricedTok,usdPerWeekPct:r,weekIncl:i}),u=AF(e,t),d=e.agentTypes??[],f=dt(e.tokens);if(!l&&!u&&!d.length&&!f&&!o)return null;let p=(0,J.jsxs)(J.Fragment,{children:[l?.turn&&(0,J.jsx)(`span`,{className:`tr-cost-head`,children:l.turn}),l&&(l.agents||l.total||l.ctx)&&(0,J.jsx)(`span`,{className:`tr-cost-parts`,children:[l.agents,l.total,l.ctx].filter(Boolean).map((e,t)=>(0,J.jsx)(`span`,{children:e},t))}),f&&(0,J.jsx)(`span`,{className:`tr-cost-toks`,children:f}),o&&(0,J.jsx)(`span`,{className:`tr-cost-next`,children:o}),u&&(0,J.jsxs)(`span`,{className:`tr-mix-legend`,children:[u.parts.map(e=>(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`i`,{style:{background:VF[e.slot]}}),e.name,` `,e.costUsd!=null&&e.costUsd>0?Ii(e.costUsd):Ut(e.tok),u.parts.length>1&&(0,J.jsxs)(`span`,{className:`tr-mix-share`,children:[` `,Math.round(e.share*100),`%`]})]},e.id)),u.parts.length>1&&(0,J.jsxs)(`span`,{className:`tr-mix-share`,children:[`split by `,u.by]})]}),d.length>0&&(0,J.jsx)(`span`,{className:`tr-cost-agents`,children:d.map(e=>(0,J.jsxs)(`span`,{className:`tr-cost-agent`,children:[(0,J.jsx)(Uc,{size:11}),` `,e.type,e.n>1?` ×${e.n}`:``]},e.type))}),l?.note&&(0,J.jsx)(`span`,{className:`tr-cost-note`,children:l.note})]}),m=(0,J.jsxs)(J.Fragment,{children:[u?(0,J.jsx)(HF,{parts:u.parts}):l&&(0,J.jsx)(uc,{size:12}),u?(0,J.jsx)(`span`,{className:`tr-cost-col`,children:p}):p,a&&(0,J.jsx)(jl,{size:12,className:`tr-cost-go`})]}),h=a?(0,J.jsx)(`button`,{type:`button`,className:`tr-cost tr-cost-btn`,onClick:()=>{q(s),a()},children:m}):(0,J.jsx)(`div`,{className:`tr-cost`,children:m}),g=!!(l?.turn||l?.total)||u?.by===`cost`;return c&&g?(0,J.jsx)(WF,{children:h}):h}function WF({children:e}){let[t,n]=(0,H.useState)(!1);return(0,J.jsxs)(`div`,{className:`tr-cost-why`,children:[e,(0,J.jsx)(`button`,{type:`button`,className:`tr-cost-q`,"aria-label":di,"aria-expanded":t,onClick:()=>n(e=>!e),children:(0,J.jsx)(gl,{size:14})}),t&&(0,J.jsxs)(`p`,{className:`tr-cost-why-text`,children:[(0,J.jsx)(`b`,{children:`Why dollars on a subscription?`}),` `,`Your plan's session and weekly limits don't count every token the same: on one model a cache read costs a hundredth of an output token. Adding tokens up treats them as equal, so the total says little about how much of your limit a prompt used. Pricing each kind at Anthropic's API list price weighs it by its own rate — the one number you can compare across prompts, sessions and models. It is not a bill.`]}),t&&(0,J.jsxs)(`p`,{className:`tr-cost-why-text`,children:[(0,J.jsx)(`b`,{children:`Why only the last prompt in the CLI view?`}),` `,`The reader folds this card under every prompt — tap a line to open it, and scroll up for older ones. The CLI view has no scroll-back of its own to hang a card on, so it keeps only the last prompt's, pinned under the terminal at a fixed height: opening or updating it never resizes the screen, which would make the CLI redraw. Same figures, same card; the newest one remembers open or folded in both.`]})]})}function GF({t:e,which:t,open:n,onToggle:r,onChip:i,growsUp:a=!1,className:o=``,bodyClass:s=``,...c}){if(!NF(e)&&!c.next)return null;let l=BF(e),u=RF(e,t),d=zF(t);return(0,J.jsxs)(`div`,{className:`cost-fold${n?` open`:``}${o?` ${o}`:``}`,children:[(0,J.jsxs)(`button`,{type:`button`,className:`cost-fold-head`,"aria-expanded":i?void 0:n,"aria-label":i?`open the context and cost sheet`:`${n?`collapse`:`expand`} the cost of ${u}`,onPointerDown:e=>e.preventDefault(),onClick:i??r,children:[(0,J.jsx)(uc,{size:13,className:`cost-fold-glyph`}),l&&!(n&&!i)&&(0,J.jsx)(`span`,{className:`cost-fold-chip`,children:l}),(0,J.jsx)(`span`,{className:`cost-fold-label`,children:u}),!i&&(n===a?(0,J.jsx)(ac,{size:14,className:`cost-fold-chev`}):(0,J.jsx)(Ys,{size:14,className:`cost-fold-chev`}))]}),n&&!i&&(0,J.jsxs)(`div`,{className:`cost-fold-body${s?` ${s}`:``}`,children:[d&&(0,J.jsx)(`div`,{className:`cost-fold-note`,children:d}),(0,J.jsx)(UF,{t:e,...c})]})]})}function KF({className:e=``}){return(0,J.jsxs)(`details`,{className:`hint-more dollars-why ${e}`.trim(),children:[(0,J.jsxs)(`summary`,{children:[(0,J.jsx)(gl,{size:12}),` `,di]}),(0,J.jsx)(`p`,{children:m})]})}function qF(e,t){let n=(e??[]).map(e=>({load:e}));for(let e of t)for(let t of e.skills??[])n.push({load:t,agent:e});return n.sort((e,t)=>e.load.t-t.load.t)}function JF(e,t,n){let r=[],i=new Map;for(let{load:a,agent:o}of qF(t,n)){let t=i.get(a.name);t??(t=r.length,i.set(a.name,t),r.push({name:a.name,marks:[]}));let n=Math.max(e.x,Math.min(e.x+e.w,e.px(a.t)));r[t].marks.push({load:a,...o?{agent:o}:{},x:n,row:t})}return r}function YF(e,t,n,r){let i=Math.floor((r-t)/24),a=e[i]?.marks.length?e[i].marks:e.flatMap(e=>e.marks);return a.length?a.reduce((e,t)=>Math.abs(t.x-n)<Math.abs(e.x-n)?t:e,a[0]):null}function XF(e){return`≈${OD(Math.round(e/4))} tokens`}function ZF(e){return e?`a subagent${e.type?` (${e.type})`:``}`:`this conversation`}function QF(e,t){let n=qF(e,t);if(!n.length)return null;let r=new Set(n.map(e=>e.load.name)).size,i=n.filter(e=>!e.agent).length,a=n.length-i,o=n.reduce((e,t)=>e+t.load.chars,0),s=a===0?`all by this conversation`:i===0?`all by subagents`:`${i} by this conversation, ${a} by subagents`,c=n.length===1?`1 load`:`${n.length} loads`;return`${r} skill${r===1?``:`s`} · ${c}, ${s} · ${XF(o)} of skill text`}function $F(e){let t=e.reduce((e,t)=>!e||t.marks.length>e.marks.length?t:e,null);if(!t||t.marks.length<2)return null;let n=t.marks.reduce((e,t)=>e+t.load.chars,0);return`${t.name} was loaded ${t.marks.length} times — ${XF(n)} in all.`}function eI(e,t){return`${e.load.name} · ${AD(e.load.t,t)} · by ${ZF(e.agent)} · ${OD(e.load.chars)} chars, ${XF(e.load.chars)}`}var tI=`A mark is the moment the Skill tool wrote that skill's text into a context window, read off the CLI's log. A filled dot is this conversation's own window; a ring is a subagent's — its own window, not this one. Size is the text's length in characters; the token figure divides by 4, an estimate, because the request that carried the text reports one total for everything it held. A skill typed as a slash command is not counted here.`,nI={top:4,right:10,bottom:20,left:40},rI=3.5;function iI({samples:e,events:t,own:n,agents:r,width:i,picked:a,onPick:o}){let s=(0,H.useRef)(null),c=hP({width:i,height:100,pad:nI,samples:e,events:t,windowTok:null,refs:[],agents:r}),l=JF(c,n,r),u=nI.top,d=l.length*24,f=u+d+nI.bottom,p=c.t1-c.t0,m=[0,.5,1].map(e=>c.tx(c.x+e*c.w)),h=(e,t)=>!!t&&e.load===t.load,g=(e,t)=>{let n=s.current?.getBoundingClientRect();if(!n)return;let r=(e.clientX-n.left)/n.width*i,c=(e.clientY-n.top)/n.height*f,d=YF(l,u,r,c);o(t&&d&&h(d,a)?null:d)};return(0,J.jsxs)(`svg`,{ref:s,className:`ctx-chart`,width:i,height:f,viewBox:`0 0 ${i} ${f}`,onPointerDown:e=>g(e,!0),onPointerMove:e=>{e.buttons&&g(e,!1)},role:`img`,"aria-label":`skills loaded over time, one row per skill`,children:[c.breaks.map((e,t)=>(0,J.jsxs)(`g`,{children:[(0,J.jsx)(`rect`,{x:e.x,y:u,width:e.w,height:d,fill:`var(--panel)`}),[0,1].map(t=>(0,J.jsx)(`line`,{x1:e.x+1+t*5,y1:u+d,x2:e.x+e.w-5+t*5,y2:u,stroke:`var(--line)`,strokeWidth:1},t))]},`k${t}`)),l.map((e,t)=>{let n=u+t*24;return(0,J.jsxs)(`g`,{children:[(0,J.jsx)(`line`,{x1:c.x,x2:c.x+c.w,y1:n+17+.5,y2:n+17+.5,stroke:`var(--line)`,strokeWidth:1,strokeOpacity:.6}),(0,J.jsxs)(`text`,{className:`ctx-tick`,x:c.x,y:n+9,children:[e.name,e.marks.length>1?` ×${e.marks.length}`:``]}),e.marks.map((e,t)=>{let r=h(e,a);return(0,J.jsx)(`circle`,{cx:e.x,cy:n+17,r:rI,fill:e.agent?`var(--panel)`:iF,stroke:r?`var(--accent)`:e.agent?`var(--fg)`:iF,strokeOpacity:r?1:e.agent?.6:1,strokeWidth:r?2:1.25},t)})]},e.name)}),(0,J.jsx)(`line`,{x1:c.x,x2:c.x+c.w,y1:u+d+.5,y2:u+d+.5,stroke:`var(--line)`,strokeWidth:1}),m.map((e,t)=>(0,J.jsx)(`text`,{className:`ctx-tick`,x:c.px(e),y:f-6,textAnchor:t===0?`start`:t===m.length-1?`end`:`middle`,children:AD(e,p)},`x${t}`))]})}function aI({samples:e,events:t,own:n,agents:r,width:i,span:a}){let[o,s]=(0,H.useState)(null),c=QF(n,r);if(n===void 0&&!c)return null;if(!c)return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`ctx-chart-title`,children:`Skills`}),(0,J.jsx)(`div`,{className:`empty ctx-note`,children:`No skill has been loaded in this conversation or its subagents.`})]});let l=r.some(e=>e.skills?.length),u=!!n?.length,d=$F(JF(hP({width:Math.max(i,1),height:100,pad:nI,samples:e,events:t,windowTok:null,refs:[],agents:r}),n,r));return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`ctx-chart-title`,children:`Skills`}),(0,J.jsx)(`div`,{className:`ctx-summary`,children:c}),(0,J.jsx)(`div`,{className:`ctx-box`,children:i>0&&(0,J.jsx)(iI,{samples:e,events:t,own:n,agents:r,width:i,picked:o,onPick:s})}),(0,J.jsx)(`div`,{className:`ctx-readout`,children:o?eI(o,a):`tap a mark to read that load`}),(0,J.jsxs)(`div`,{className:`ctx-legend`,children:[u&&(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`10`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`circle`,{cx:`5`,cy:`5`,r:rI,fill:`var(--ctx-series)`})}),` this conversation`]}),l&&(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`10`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`circle`,{cx:`5`,cy:`5`,r:rI,fill:`none`,stroke:`var(--fg)`,strokeOpacity:.6,strokeWidth:1.25})}),` a subagent`]})]}),d&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:d}),(0,J.jsxs)(`details`,{className:`hint-more ctx-method`,children:[(0,J.jsx)(`summary`,{children:`how the skills chart is counted`}),(0,J.jsx)(`p`,{children:tI})]})]})}function oI(e){let t=e.filter(e=>e.key===`remainder`);return[...e.filter(e=>e.key!==`remainder`).sort((e,t)=>t.tok-e.tok),...t]}var sI=e=>e.key===`remainder`?`rest`:e.undocumented?`undoc`:`doc`;function cI(e,t){let n=oI(e),r=n.some(e=>e.key===`remainder`),i=n.reduce((e,t)=>e+Math.max(0,t.tok),0),a=r&&t!=null&&t>0?`request`:`parts`,o=a===`request`?Math.max(t,i):i;if(!(o>0))return null;let s=0;return{segs:n.map(e=>{let t=Math.max(0,e.tok)/o*100,n={key:e.key,label:e.label,tok:e.tok,words:e.words,cls:sI(e),x:s,w:t};return s+=t,n}),whole:o,scale:a}}function lI(e,t){if(!e.length)return null;let n=Math.min(100,Math.max(0,t*100));for(let t of e)if(n<t.x+t.w)return t;return e[e.length-1]}function uI(e,t){if(!(t>0))return``;let n=e/t*100;return n>0&&n<1?`<1%`:`${Math.round(n)}%`}function dI(e,t){let n=t.scale===`request`?`of the first request`:`of the parts`;return`${e.label} · ${e.words} · about ${uI(e.tok,t.whole)} ${n}`}function fI(e,t,n){return e.scale===`request`?null:t==null?`The bar is the parts' own sum: the first request has not been answered yet, so its size is unknown.`:`The bar is the parts' own sum: their estimate exceeds the first request's ${n(t)} tokens, so the rest cannot be drawn.`}var pI={doc:`logged attachment (~)`,undoc:`undocumented record (~)`,rest:`the rest of the request (≈)`};function mI(e){let t=new Set(e.segs.filter(e=>e.tok>0).map(e=>e.cls));return[`doc`,`undoc`,`rest`].filter(e=>t.has(e))}function hI(e){let t=/^(\/Users\/[^/]+|\/home\/[^/]+|\/root|[A-Za-z]:\\Users\\[^\\]+)(?=$|[/\\])/.exec(e);return t?`~${e.slice(t[1].length)}`:e}var gI=(e,t)=>e.length>0&&e.length<=3&&(t==null||t<=e.length),_I=`This desktop did not measure what the first request carried (an older host, or a log whose start held no attachment record).`;function vI({carried:e,fmt:t=R}){return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`ctx-chart-title`,children:`What every turn carries`}),e?(0,J.jsx)(yI,{carried:e,fmt:t}):(0,J.jsx)(`div`,{className:`empty ctx-note`,children:_I})]})}function yI({carried:e,fmt:t}){let[n,r]=(0,H.useState)(null),i=oI(Xte(e,t)),a=cI(i,e.firstRequestTok),o=new Map(e.parts.map(e=>[e.kind,e.count])),s=e=>r(t=>t===e?null:e),c=!!a&&a.scale===`parts`&&e.firstRequestTok!=null;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`ctx-summary`,children:Dee(e,t,{unplacedShown:c})}),a&&(0,J.jsx)(bI,{strip:a,picked:n,onPick:r,firstRequestTok:e.firstRequestTok,fmt:t}),(0,J.jsxs)(`div`,{className:`empty ctx-note`,children:[`Measured on this log's first request`,e.firstRequestAt==null?``:` (${new Date(e.firstRequestAt).toLocaleString()})`,`, not on what a new session would carry today.`]}),i.length>0&&(0,J.jsx)(`ul`,{className:`carried-list`,children:i.map(e=>{let t=e.key===`remainder`?void 0:o.get(e.key),r=e.names&&t!=null&&t>e.names.length,i=a?.segs.find(t=>t.key===e.key);return(0,J.jsx)(`li`,{className:n===e.key?`carried-picked`:void 0,children:(0,J.jsxs)(xE,{children:[(0,J.jsxs)(`div`,{className:`carried-pick`,role:`button`,tabIndex:0,"aria-pressed":n===e.key,title:`read this part on the strip above`,onClick:()=>s(e.key),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),s(e.key))},children:[(0,J.jsxs)(`div`,{className:`carried-head`,children:[(0,J.jsx)(SE,{className:`carried-label`,children:e.label}),(0,J.jsx)(Q,{className:`carried-num`,children:e.words})]}),i&&(0,J.jsx)(`span`,{className:`carried-meter`,"aria-hidden":!0,children:(0,J.jsx)(`span`,{className:`carried-fill carried-${sI(e)}`,style:{width:i.w>0?`max(1px, ${i.w}%)`:0}})})]}),e.files&&e.files.length>0&&(0,J.jsx)(`ul`,{className:`carried-files`,children:e.files.map((e,t)=>(0,J.jsxs)(`li`,{className:`carried-head`,children:[(0,J.jsxs)(Q,{className:`carried-label`,children:[(0,J.jsx)(`span`,{className:`carried-path`,children:hI(e.path)}),` `,(0,J.jsx)(yE,{className:`carried-type`,children:e.type})]}),(0,J.jsx)(Q,{className:`carried-num`,children:e.words})]},`${t}:${e.label}`))}),e.names&&e.names.length>0&&(gI(e.names,t)?(0,J.jsx)(Q,{className:`carried-inline`,children:e.names.join(`, `)}):(0,J.jsxs)(`details`,{className:`hint-more carried-names`,children:[(0,J.jsx)(`summary`,{children:r?`the first ${e.names.length} of ${t} names`:`the ${e.names.length} names`}),(0,J.jsx)(`p`,{children:e.names.join(`, `)})]}))]})},e.key)})}),!e.parts.length&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:`The log holds no attachment records before the first request, so no part can be named.`})]})}function bI({strip:e,picked:t,onPick:n,firstRequestTok:r,fmt:i}){let a=t=>{let n=t.currentTarget.getBoundingClientRect();return n.width>0?lI(e.segs,(t.clientX-n.left)/n.width):null},[o,s]=(0,H.useState)(null),c=o??t,l=e.segs.find(e=>e.key===c)??null,u=fI(e,r,i);return(0,J.jsxs)(`div`,{className:`carried-comp`,children:[(0,J.jsx)(`div`,{className:`carried-bar`,role:`group`,"aria-label":`${e.scale===`request`?`what the first request was made of`:`what the parts were made of`}; the line under it reads the picked part`,onPointerDown:e=>{let r=a(e);n(r&&r.key===t?null:r?.key??null),e.pointerType===`mouse`&&s(null)},onPointerMove:e=>{if(e.buttons){let t=a(e);t&&n(t.key),e.pointerType===`mouse`&&s(null)}else e.pointerType===`mouse`&&s(a(e)?.key??null)},onPointerLeave:e=>{e.pointerType===`mouse`&&s(null)},children:e.segs.map(e=>(0,J.jsx)(`span`,{className:`carried-seg carried-${e.cls}${e.key===c?` carried-on`:``}`,style:{left:`${e.x}%`,width:`${e.w}%`}},e.key))}),(0,J.jsx)(`div`,{className:`ctx-readout carried-readout`,children:l?dI(l,e):(0,J.jsx)(YD,{})}),(0,J.jsx)(`div`,{className:`ctx-legend carried-legend`,children:mI(e).map(e=>(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`i`,{className:`carried-swatch carried-${e}`,"aria-hidden":!0}),pI[e]]},e))}),u&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:u})]})}var xI=220,SI=110;function CI({sessionId:e,title:t,online:n,liveAgentNote:r,onReplan:i,replanCant:a,replanNote:o,agentWarn:s,budget:c,onFresh:l,onCompact:u,compactCant:d,onExplainCost:f,unmeasured:p,backendLabel:m,onOpenSetup:h,setupCant:g,onOpenAllSessions:_,onClose:v}){let y=fh(`ctx:${e}`,async()=>{let t=await U.contextSeries(e);if(!t)throw Error(`no context series`);return t},{enabled:!p,offline:!n,fromCache:()=>lC(e),toCache:cC}),b=y.data,[x,S]=(0,H.useState)(null),[C,w]=(0,H.useState)(null),T=(0,H.useRef)(null),[E,D]=(0,H.useState)(0),O=(0,H.useCallback)(e=>{if(T.current?.disconnect(),T.current=null,!e)return;let t=e=>{let t=getComputedStyle(e);return e.clientWidth-parseFloat(t.paddingLeft||`0`)-parseFloat(t.paddingRight||`0`)};if(D(t(e)),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>D(t(e)));n.observe(e),T.current=n},[]);(0,H.useEffect)(()=>()=>T.current?.disconnect(),[]);let k=(0,H.useCallback)(e=>S(e),[]),A=b?.samples??[],j=b?.events??[],M=A.length?A[A.length-1].t-A[0].t:0,N=b?.windowTok??null,P=eF(A,j,N,b?.agents),I=fa(b?.coldStarts,`session`),ee=F(A,b?.truncated??!1,b?.turns??null,b?{usageTok:b.usageTok,agentTok:b.agentTok}:null,A.length?{lastTurnAt:A[A.length-1].t,now:Date.now()}:null),te=SP(A,b?.usageTok,b?.agentTok,b?.cost?{total:b.cost.total+(b.agentCost?.total??0),agents:b.agentCost?.total??null,unpricedTok:b.unpricedTok??null}:null),ne=TP(b?.split,b?.agentSplit),re=b?.agents??[],ie=PP(b?.models,A.some(e=>e.model==null)||re.some(e=>e.model==null)),ae=MP(A,`kinds`,e=>e!==`output`),oe=MP(A,`cum`),se=ae,ce=oe,le=A.slice(0,-1).map((e,t)=>A[t+1].t-e.t).filter(e=>e>fP),ue=(h||_)&&(0,J.jsxs)(`div`,{className:`sheet-actions ctx-doors`,children:[h&&(0,J.jsxs)(Y,{onClick:h,title:`What this repo and this desktop put in every turn, file by file`,children:[(0,J.jsx)(Cs,{size:12}),` repo readings`]}),_&&(0,J.jsxs)(Y,{onClick:_,title:`Every conversation on this desktop, with its token split`,children:[(0,J.jsx)(qo,{size:12}),` all sessions`]})]});if(p)return(0,J.jsxs)(`div`,{className:`sheet`,children:[(0,J.jsx)(gE,{title:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(yo,{size:16,style:{verticalAlign:`-3px`,marginRight:4}}),`Context window & cost`]}),onClose:v}),ue,(0,J.jsx)(CE,{cants:[{label:`context graph`,reason:p}]}),(0,J.jsxs)(Z,{children:[t,` — nothing on this screen is a measurement of it. The terminal is still the whole story.`]})]});let de=te?wP(te,b?.truncated??!1,!!b?.agentCum?.length):null,fe=ne?DP(ne,b?.truncated??!1):null,pe=WP(re,b?.agentTok);return(0,J.jsxs)(`div`,{className:`sheet`,children:[(0,J.jsx)(gE,{title:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(yo,{size:16,style:{verticalAlign:`-3px`,marginRight:4}}),`Context window & cost`]}),onClose:v,children:(0,J.jsx)(Y,{onClick:()=>{y.inflight||y.reload({quiet:!0})},title:`re-read — this is a point-in-time answer, not a live feed`,children:y.inflight?(0,J.jsx)(Ml,{size:14,className:`spin`}):(0,J.jsx)(Wl,{size:14})})}),(0,J.jsx)(Z,{children:t}),ue,!h&&g&&(0,J.jsx)(CE,{cants:[{label:`repo readings`,reason:g}]}),(0,J.jsx)($,{res:y,empty:!A.length,thing:`the context history`,noun:`graph`,note:y.state===`error`?`A session that has not run a turn yet has no log to read.`:void 0,children:`Nothing to plot yet — this conversation has not completed a turn.`}),!A.length&&b&&(0,J.jsx)(vI,{carried:b.carried}),A.length>0&&(0,J.jsxs)(`div`,{className:`list`,children:[(0,J.jsxs)(J.Fragment,{children:[te&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`ctx-chart-title`,children:te.costUsd==null?`Tokens spent`:`Total cost`}),(0,J.jsx)(`div`,{className:`ctx-summary`,children:CP(te,b?.truncated??!1)}),(0,J.jsx)(`div`,{className:`ctx-box`,children:E>0&&(0,J.jsx)(mF,{samples:A,events:j,facts:te,width:E,height:SI,bands:ce,agents:re,agentCum:b?.agentCum})}),(0,J.jsx)(vF,{agents:te.agents!=null&&!!b?.agentCum?.length,dashed:te.total!=null&&te.agents!=null,stacked:!!ce}),de?.lead&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:de.lead}),te.costUsd!=null&&(0,J.jsx)(KF,{className:`ctx-method`})]}),(0,J.jsxs)(`div`,{className:`ctx-chart-title ctx-chart-title-row`,children:[(0,J.jsx)(`span`,{children:`Context window`}),u&&(0,J.jsxs)(Y,{onClick:u,children:[(0,J.jsx)(ere,{size:14}),` /compact`]})]}),!u&&d&&(0,J.jsx)(CE,{cants:[{label:`/compact from here`,reason:d}]}),P&&(0,J.jsx)(`div`,{className:`ctx-summary`,children:P}),(0,J.jsx)(`div`,{className:`ctx-box`,ref:O,children:E>0&&(0,J.jsx)(pF,{samples:A,events:j,width:E,height:xI,windowTok:N,autoCompactTok:b?.autoCompactTok??null,autoCompactSetTok:b?.autoCompactSet?.tokens??null,onHover:k,bands:se,agents:re})}),(0,J.jsx)(`div`,{className:`ctx-readout`,children:x?`${AD(x.t,M)} · ${vP(x.tok,N)}`:(0,J.jsx)(YD,{})}),(0,J.jsx)(xF,{events:j,agents:re.filter(e=>e.ctx?.length).length}),se&&E>0&&(0,J.jsx)(gF,{p:hP({width:E,height:xI,pad:{top:10,right:10,bottom:20,left:40},samples:A,events:j,refs:[],windowTok:N,agents:re}),samples:A,series:se}),re.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`ctx-chart-title`,children:`Subagents`}),(0,J.jsx)(`div`,{className:`ctx-summary`,children:UP(re,b?.models)}),(0,J.jsx)(`div`,{className:`ctx-box`,children:E>0&&(0,J.jsx)(_F,{samples:A,events:j,agents:re,slots:ie,width:E,picked:C,onPick:w})}),(0,J.jsx)(`div`,{className:`ctx-readout`,children:C?HP(C,b?.models,M):`tap a bar to read that agent`}),(0,J.jsx)(yF,{slots:ie,only:new Set(re.map(e=>ie?.slotOf(e.model)??0))}),(0,J.jsx)(wF,{agents:re,models:b?.models,picked:C,onPick:w})]}),pe&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:pe}),(0,J.jsx)(aI,{samples:A,events:j,own:b?.skills,agents:re,width:E,span:M}),b&&(0,J.jsx)(vI,{carried:b.carried}),(de||re.length>0)&&(0,J.jsxs)(`details`,{className:`hint-more ctx-method`,children:[(0,J.jsx)(`summary`,{children:`how the spend and agent charts are counted`}),de&&(0,J.jsx)(`p`,{children:de.more}),re.length>0&&(0,J.jsx)(`p`,{children:`Each bar runs from an agent's first dated record to its last, coloured by the model that ran it, and packed into as few rows as fit without two bars overlapping — a row is not an identity, only the first one that had room. The outlined bar spent the most. A floor, like every reading here: an agent log this desktop never saw is one nothing can place.`})]})]}),ne&&(0,J.jsxs)(J.Fragment,{children:[EP(ne)&&(0,J.jsx)(`div`,{className:`ctx-summary`,children:EP(ne)}),(0,J.jsx)(KD,{bag:ne.all,whole:Xi(ne.all)}),fe?.lead&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:fe.lead}),(0,J.jsx)(qD,{totals:ne.all,scope:`session`}),fe&&(0,J.jsxs)(`details`,{className:`hint-more ctx-method`,children:[(0,J.jsx)(`summary`,{children:`how these kinds are counted`}),(0,J.jsx)(`p`,{children:fe.more})]})]}),r&&(0,J.jsxs)(`div`,{className:`ctx-cost ctx-cost-heavy`,children:[(0,J.jsxs)(`div`,{className:`ctx-cost-head`,children:[(0,J.jsx)(Uc,{size:14}),(0,J.jsx)(`span`,{children:`a subagent is running on a large window`})]}),(0,J.jsx)(`div`,{className:`ctx-cost-note`,children:r}),i?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`sheet-actions`,children:(0,J.jsxs)(Y,{onClick:i,children:[(0,J.jsx)(Nc,{size:14}),` interrupt and re-plan`]})}),o&&(0,J.jsx)(Z,{children:o})]}):a?(0,J.jsx)(CE,{cants:[{label:`interrupt and re-plan`,reason:a}]}):null]}),ee&&(0,J.jsx)(dP,{cost:ee,onFresh:l,onCompact:u}),(c||s)&&(0,J.jsxs)(`div`,{className:`ctx-cost`,children:[c&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`ctx-cost-head`,children:[(0,J.jsx)(El,{size:14}),(0,J.jsx)(`span`,{children:c.label?`budget ${c.label}`:`no budget on this session`})]}),c.line?(0,J.jsx)(`div`,{className:`ctx-cost-note`,children:c.line}):null,(0,J.jsx)(`div`,{className:`sheet-actions`,children:(0,J.jsxs)(Y,{onClick:c.onOpen,children:[(0,J.jsx)(El,{size:14}),` `,c.label?`change or clear the budget`:`set a budget`]})})]}),s&&(0,J.jsxs)(J.Fragment,{children:[!c&&(0,J.jsxs)(`div`,{className:`ctx-cost-head`,children:[(0,J.jsx)(Uc,{size:14}),(0,J.jsx)(`span`,{children:`large subagents`})]}),(0,J.jsx)(EF,{value:s.value,onChange:s.onChange})]})]}),(0,J.jsxs)(`div`,{className:`ctx-cost`,children:[(0,J.jsxs)(`div`,{className:`ctx-cost-head`,children:[(0,J.jsx)(rc,{size:14}),(0,J.jsx)(`span`,{children:`why it cost this much`})]}),f?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`ctx-cost-note`,children:`A new session in this directory measures this conversation's transcript, names what made it expensive and lists ideas to make it cheaper — it changes nothing until you pick one.`}),(0,J.jsx)(`div`,{className:`sheet-actions`,children:(0,J.jsxs)(Y,{onClick:f,children:[(0,J.jsx)(rc,{size:14}),` explain the cost of this session`]})})]}):(0,J.jsx)(CE,{cants:[{label:`explain the cost of this session`,reason:`this session has no conversation id yet, so there is no transcript to point a new session at`}]})]}),I&&(0,J.jsxs)(`div`,{className:`ctx-panel`,children:[(0,J.jsx)(`div`,{className:`ctx-summary`,children:`Expired cache`}),(0,J.jsx)(Z,{children:I}),(0,J.jsxs)(`details`,{className:`hint-more ctx-method`,children:[(0,J.jsx)(`summary`,{children:`why a cold cache costs more`}),(0,J.jsx)(`p`,{children:`A conversation resumed inside the hour re-reads its window out of the cache at a tenth of the write rate. After that the window has to be written again before it can answer anything — the same tokens, up to twenty times the price, and the chart does not move when it happens.`})]})]}),b?.compaction&&(0,J.jsx)(uP,{l:b.compaction,windowTok:N,tok:A.length?A[A.length-1].tok:null}),b?.truncated&&!de&&!fe&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:`This conversation’s log is longer than the host reads in one go, so the curve starts part-way through it.`}),(0,J.jsxs)(`div`,{className:`empty ctx-note`,children:[$P(b?.windowFrom,N,b?.model,m),b?.autoCompactTok!=null&&` The dashed line is where a compaction was last observed to fire — a measurement, not a setting.`,b?.autoCompactSet&&` ${rF(b.autoCompactSet)}`]}),le.length>0&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:le.length===1?`One stretch of ${gP(le[0])} with no activity is compressed on the time axis (the ⁄⁄ mark).`:`${le.length} stretches with no activity — the longest ${gP(Math.max(...le))} — are compressed on the time axis (the ⁄⁄ marks).`}),(0,J.jsxs)(`details`,{className:`hint-more ctx-method`,children:[(0,J.jsx)(`summary`,{children:`where these numbers come from`}),(0,J.jsx)(`p`,{children:`How many tokens each request carried, read off the CLI’s own conversation log and each subagent’s own log. Both are dated, which is what lets a compaction, a usage wall and every agent sit on the same time axis as the curve.`})]})]})]})}function wI(e,t,n){return(e?t.find(t=>t.id===e):null)??n}function TI(e){return e?`that conversation is not listed — showing ${e}`:`that conversation is not listed, and none is attached`}function EI(e,t){return e?`sent /compact to ${t}`:`queued /compact — sends when the link is back`}function DI(e){return`sent Esc to ${e} and queued the re-plan prompt`}function OI(e){return`no connection — Esc did not reach ${e}, and the re-plan prompt was not queued. Try again when the link is back.`}var kI=`Sends Esc, which stops the agent the session is waiting on, then queues a prompt asking the main agent to re-plan it narrower. Work that agent has not reported back is lost. An agent running in the background keeps going; the prompt asks the main agent to stop it.`,AI=G(null);function jI(e){let t=W();t.say.track(`action:session.context`),AI.set(e.id),t.nav.open(`context`)}function MI(){AI.set(null),W().nav.open(`context`)}function NI(e){let t=W();if(e===null&&AI.get()!==null)return;let n=e?t.world.sessions.find(t=>t.id===e):void 0;n?jI(n):(MI(),e&&t.say.toast(TI(t.world.active?t.world.sessionRowTitle(t.world.active):null)))}function PI(){AI.set(null),W().nav.close(`context`)}function FI(e){let t=W();t.say.track(`action:ctx.setup`),t.nav.openSetup(e,{region:`setup`,focus:`context-weight`})}function II(){let e=W();e.say.track(`action:ctx.tokens`),e.nav.open(`tokens`)}function LI(e){PI(),W().nav.openRepo(e)}function RI(e){let t=W();t.say.track(`action:ctx.compact`),t.queue.submitInput(e.id,e.cwd,`/compact`,`command`),t.compose.pushHistory(`/compact`),t.say.toast(EI(t.conn.status===`open`,t.world.sessionRowTitle(e)))}function zI(e,t){let n=kw({title:t,cwd:e.cwd,claudeSessionId:e.claudeSessionId,model:e.model});if(!n)return!1;let r=W();return r.say.track(`action:ctx.explainCost`),PI(),r.nav.startSessionWithPrompt(e.cwd,`cost of ${t}`,[n]),!0}function BI(e,t){let n=W();n.say.track(`action:ctx.replan`);let r=e.contextSpark;n.conn.liveSend({t:`session.input`,id:e.id,data:`\x1B`},DI(t),OI(t))&&n.queue.submitInput(e.id,e.cwd,se(r?.liveAgentTok??0,r?.liveAgentType),`prompt`)}function VI({subject:e}){let t=_h(),{backends:n}=t.world,r=t.world.sessionRepo(e),i=t.world.sessionRowTitle(e),a=ut(oy(`agentWindowWarn`));return(0,J.jsx)(CI,{sessionId:e.id,title:i,online:t.conn.status===`open`,unmeasured:t.world.sessionCant(e,`contextSeries`)??void 0,backendLabel:CT(n,e.backend)??void 0,onFresh:r?()=>LI(r):void 0,onCompact:t.world.sessionCan(e,`slash`)?()=>RI(e):void 0,compactCant:t.world.sessionCant(e,`slash`)??void 0,onExplainCost:e.claudeSessionId?()=>{zI(e,i)}:void 0,liveAgentNote:e.running?aee(e.contextSpark?.liveAgentTok,e.contextSpark?.liveAgentAt,Date.now(),a):null,onReplan:t.world.sessionCan(e,`slash`)?()=>BI(e,i):void 0,replanCant:t.world.sessionCant(e,`slash`)??void 0,replanNote:kI,agentWarn:{value:a,onChange:e=>{t.say.track(`action:ctx.agentWarn`),sy(`agentWindowWarn`,e===5e5?``:String(e))}},budget:{label:e.budget?yr(e.budget.cfg):null,line:oE(e.budget,Date.now(),ti(e)),onOpen:()=>QD(e.id)},onOpenSetup:r?()=>FI(r.id):void 0,setupCant:r?void 0:`this session's repo is not one the desktop lists`,onOpenAllSessions:II,onClose:PI})}var HI={id:`context`,sheets:[{id:`context`,persisted:!0,render:e=>{let t=wI(AI.get(),e.world.sessions,e.world.active);return t?(0,H.createElement)(VI,{subject:t}):null}}]},UI=wr(`builds.json`),WI=`\`${UI}\` is a JSON array of objects \`{ "id", "name", "cmd", "dir", "params" }\`:
|
|
150
|
+
`),a=i===-1?e:e.slice(0,i);n.push({day:a.slice(3).trim(),body:i===-1?``:e.slice(i)})}),{preamble:r,days:n}}function Gj(e){let t=new Map,n=e.map(()=>!1);e.forEach((e,r)=>{let i=Kn(e);i===null?n[r]=!0:t.set(i,r)});for(let e of t.values())n[e]=!0;let r=[];return n.forEach((e,t)=>{e&&r.push(t)}),r}function Vge(e){return Gj(e.map(e=>e.day)).map(t=>e[t])}var Kj=e=>Vge(e);function qj(e){let t=e.variant;return{...e,points:Kj(e.points),...t&&t.kind===`override`?{variant:{...t,points:Kj(t.points)}}:{}}}function Hge(e,t){if(t===`commits`)return e;let n=e.classics,r=e.longest,i=r;if(r){let e=Gj(r.points.map(e=>e.day)),t=r.paths;i={...r,points:e.map(e=>r.points[e]),...t&&t.length===r.points.length?{paths:e.map(e=>t[e])}:{}}}return{...e,series:e.series.map(qj),classics:{...n,loc:Kj(n.loc),files:Kj(n.files),deps:Kj(n.deps),packages:n.packages.map(e=>({...e,points:Kj(e.points)})),...n.types?{types:n.types.map(e=>({...e,points:Kj(e.points)}))}:{}},...i?{longest:i}:{},...e.own?{own:{...e.own,series:e.own.series.map(qj)}}:{}}}function Uge({index:e,drawn:t,plot:n,own:r}){let i=t?.longest?t.longest.points.reduce((e,t)=>t.v==null?e:e+1,0):0;return{score:e,longest:!!t&&(i>=2||!!t.classics.tape?.length),tiles:!!t?.series.length,weight:!!t,size:!!t,table:!!n&&(n.classics.files.length>0||!!n.series.find(e=>e.key===`size.p95`)?.points.length),own:r&&!!n&&kk(n).kind!==`none`}}var Wge=e=>Object.keys(e).filter(t=>e[t]),Jj=e=>`rh-${e}`;function Gge({keys:e,refresh:t}){let n=e=>document.getElementById(Jj(e))?.scrollIntoView({behavior:`smooth`,block:`start`});return(0,J.jsxs)(`nav`,{className:`rh-nav`,"aria-label":`jump to`,children:[(0,J.jsx)(`div`,{className:`rh-nav-chips`,children:e.map(e=>(0,J.jsx)(`button`,{type:`button`,className:`fchip rh-nav-chip`,onClick:()=>n(e),children:(0,J.jsx)(`span`,{className:`fchip-pill`,children:npe[e]})},e))}),t]})}function Kge({busy:e,label:t,onClick:n}){return(0,J.jsxs)(Y,{className:`rh-nav-refresh`,type:`button`,onClick:n,children:[(0,J.jsx)(Wl,{size:14,className:e?`spin`:void 0,"aria-hidden":!0}),` `,t]})}function qge({axis:e,onAxis:t,commits:n}){let r=n!==`absent`;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`ts-filter rh-axis`,role:`group`,"aria-label":`x axis`,children:[(0,J.jsx)(`span`,{className:`ctx-stackpick-lab`,children:`x axis`}),(0,J.jsx)(pE,{on:e===`weeks`,clears:!1,onClick:()=>t(`weeks`),children:`weeks`}),r?(0,J.jsx)(pE,{on:e===`commits`,clears:!1,onClick:()=>t(`commits`),children:`commits`}):null,(0,J.jsxs)(TE,{of:`the x axis`,children:[(0,J.jsxs)(`p`,{children:[mk(`weeks`),`.`]}),r?(0,J.jsxs)(`p`,{children:[mk(`commits`),`.`]}):null]})]}),r?null:(0,J.jsx)(`div`,{className:`rh-cap rh-gutter`,children:hk(L.displayName)}),(0,J.jsx)(`div`,{className:`rh-cap rh-gutter rh-scrubhint`,children:rpe})]})}function Yj({id:e,children:t}){let[n,r]=JD();return(0,J.jsx)(`div`,{className:`rh-card`,id:Jj(e),ref:r,children:t(n)})}function Jge({days:e}){return e.length?(0,J.jsxs)(`details`,{className:`hint-more rh-notes`,children:[(0,J.jsx)(`summary`,{children:Ype(e.length)}),e.map(e=>(0,J.jsx)(`div`,{className:`tr-say rh-doc`,children:(0,J.jsx)(Rj,{src:`## ${e.day}${e.body}`,q:``,onCopy:e=>void gp(e)})},e.day))]}):null}var Yge=16,Xge=1500;function Zge({repo:e,res:t,view:n,onRemedy:r,scope:i,onScope:a,onOpenFile:o}){let s=n?.series??null,c=n?.plot??null,[l,u]=(0,H.useState)(!1),[d,f]=(0,H.useState)(0),[p,m]=(0,H.useState)(null),[h,g]=(0,H.useState)(null),[_,v]=(0,H.useState)(!1),y=_E(1e3),{reload:b}=t,x=!!n?.run;(0,H.useEffect)(()=>{if(!x)return;let e=window.setInterval(()=>b({quiet:!0}),Xge);return()=>window.clearInterval(e)},[x,b]);let[S,C]=(0,H.useState)(ane),w=e=>{q(`action:repohealth.axis.${e}`),one(e),C(e)},[T,E]=(0,H.useState)(null),D=(0,H.useCallback)(e=>E(e),[]),O=S===`commits`&&T===`absent`?`weeks`:S,k=(0,H.useMemo)(()=>c?Hge(c,O):null,[c,O]),A=n?.scopes??[],j=(n?.measure?.groups??[]).filter(e=>e&&e!==`.`),[M,N]=(0,H.useState)(!1),[P,F]=(0,H.useState)(!1);async function I(t){if(e&&!P){F(!0);try{let n=await U.repoHealthScopes(e.id,t);i&&!n.scopes.includes(i)&&a(null),await b({quiet:!0})}catch(e){m(String(e?.message||e))}finally{F(!1)}}}async function ee(r=!1,a=!1){if(!l&&e){q(`action:repohealth.refresh`),u(!0),f(Date.now()),m(null),g(null);try{let o=await U.repoHealthRefresh(e.id,i,r,r?n?.engine?.approveToken:void 0,a),s=o.error;typeof s==`string`&&!o.engine?g(s):t.set(o)}catch(e){m(String(e?.message||e))}finally{u(!1)}}}let te={behind:n?.behind,lastSha:s?.lastSha,lastDay:s?.lastDay,headSha:n?.head?.sha},ne=vpe(te),re=ype({...te,rows:s?.rows,days:s?.days}),ie=n?.measure??null,ae=!!e&&n?.engine?.kind===`bundled`&&n?.engine?.needsApproval!==!0,oe=Epe(s?.versions,ie?.engineVersion??s?.preregVersion,dee(ie),ae),se=hpe({kind:n?.engine?.kind??null,ownSkipped:n?.engine?.ownSkipped,version:ie?.engineVersion,packs:ie?.packs}),ce=!!n&&!n.tool,le=Cpe(s?.staleRows),ue=kpe(n?.run,y),de=n?.last&&!Dpe(n.last,n.readError,!!n.series)?n.last:null,fe=ae&&(!!oe||!!de?.refused),pe=n?.narrative??null,me=bpe(s),he=xpe(de?.warnings),ge=pe?Bge(pe.text):null,_e=ge?[...ge.days].reverse():[],ve=ca(n),ye=n?.tool&&s?wte(ve,n?.plotError??null):null,be=c?.series.find(e=>e.key===`size.p95`)?.last??null,xe=e=>Dme({absent:e.absent,last:e.last,readings:e.points.reduce((e,t)=>t.v==null?e:e+1,0)}),Se=e=>({key:e.key,label:e.label,value:Ck(e.last,e.unit),reading:wk(e.reading),ranked:e.reading?.rank!=null,detail:e.detail,...xe(e)?{absent:xe(e)}:{}}),Ce=t=>{r&&e&&(q(`action:repohealth.ask`),r(Ome(Se(t),e.repoName,i),e,t.label.toLowerCase()))},we=(t,i)=>{r&&e&&(q(`action:repohealth.askindex`),r(hme(t,e.repoName,jk(c,n?.engine?.kind,``,i)),e,`the health index, week of ${t.week}`))},Te=(t,i,a,o)=>{r&&e&&(q(`action:repohealth.asktrend`),r(gme(t,i,e.repoName,{...jk(c,n?.engine?.kind,i,a),now:o??null}),e,`the health index trend`))},Ee=()=>{r&&e&&(q(`action:repohealth.qualityrun`),r(_me(e.repoName,jk(c,n?.engine?.kind,``,null)),e,`a design-quality run`))},De=()=>{r&&e&&c?.series.length&&(q(`action:repohealth.askall`),r(Nme(c.series.map(Se),e.repoName,se,i),e,i?`all the readings of ${i}`:`all the readings`))},Oe=n?.engine?.needsApproval===!0,ke=n?.engine?.kind===`repo`&&!Oe&&!!(de?.error||n.readError),Ae=()=>{r&&e&&n&&(q(`action:repohealth.adoptengine`),r(Ame(e.repoName,de?.error??n.readError,n.engine?.bundled),e,`the repo-health engine`))},je=re||se?(0,J.jsxs)(J.Fragment,{children:[re?(0,J.jsx)(`p`,{children:xk()}):null,ne?(0,J.jsxs)(`p`,{children:[ne,pe?(0,J.jsxs)(J.Fragment,{children:[` · `,wpe(Gp(pe.mtime))]}):null,n?.head?(0,J.jsxs)(J.Fragment,{children:[` · `,Tpe(Gp(n.head.ts))]}):null,me?(0,J.jsxs)(J.Fragment,{children:[` · `,me]}):null]}):null,se?(0,J.jsx)(`p`,{children:se}):null]}):null,Me=e&&!ce&&!Oe?(0,J.jsx)(Kge,{busy:l,onClick:()=>void ee(),label:l?Sk(s,y-d):gpe(s)}):null,Ne=!!e&&!i&&!ce,Pe=Uge({index:Ne,drawn:k,plot:c,own:!!e}),Fe=Wge(Pe);return(0,J.jsxs)(`div`,{className:`rh-region`,children:[(0,J.jsxs)(`div`,{className:`section-head rh-head`,children:[(0,J.jsx)(`span`,{className:`section section-hint rh-status${je?``:` rh-push`}`,children:re??xk()}),je?(0,J.jsx)(TE,{of:`this series`,children:je}):null]}),e&&!ce&&(A.length||j.length)?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`fchips wrap rh-scope`,role:`group`,"aria-label":`which part of the repo`,children:[(0,J.jsx)(`span`,{className:`ctx-stackpick-lab`,children:`reading of`}),(0,J.jsx)(pE,{on:i===null,clears:!1,onClick:()=>a(null),children:Qpe}),A.map(e=>(0,J.jsx)(pE,{on:i===e,clears:!1,onClick:()=>{q(`action:repohealth.scope`),a(e)},children:e},e)),j.length?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`fchips-gap`,"aria-hidden":!0}),(0,J.jsxs)(pE,{on:M,clears:!1,onClick:()=>N(e=>!e),children:[(0,J.jsx)(cl,{size:12}),` break down…`]})]}):null]}),i?(0,J.jsx)(`div`,{className:`section section-hint`,children:$pe(i)}):null,M?(0,J.jsxs)(`div`,{className:`section section-hint`,children:[(0,J.jsx)(`div`,{children:tme(j.length)}),(0,J.jsx)(`div`,{className:`fchips wrap rh-filter-chips`,role:`group`,"aria-label":`subtrees to measure`,children:j.map(e=>(0,J.jsx)(pE,{on:A.includes(e),busy:P&&A.includes(e),onClick:()=>void I(A.includes(e)?A.filter(t=>t!==e):[...A,e]),children:e},e))}),(0,J.jsx)(`div`,{children:eme()})]}):null]}):null,(0,J.jsx)($,{res:t,empty:!s&&!c,thing:`the repo-health series`,noun:`reading`,children:ce?Wi(`absent`):n?.engine?.needsApproval&&n.engine.kind===`repo`?`Not read yet — the repo's own engine is waiting for your approval.`:n?.engine?.needsApproval&&n.engine.kind===`bundled`?`Measured without this repo's own readings — they wait for your approval.`:n?.readError?mpe(n.readError):i?nme(i,ie?.commits):ppe(ie?.commits,n?.stepTimeoutMs)}),oe?(0,J.jsx)(`div`,{className:`section section-hint`,children:oe}):null,le?(0,J.jsx)(`div`,{className:`section section-hint`,children:le}):null,ue?(0,J.jsx)(`div`,{className:`section section-hint`,children:ue}):null,fe?(0,J.jsx)(`div`,{className:`section`,children:(0,J.jsxs)(uT,{className:`key rh-verb`,confirm:Mpe,onConfirm:()=>void ee(!1,!0),children:[(0,J.jsx)(Wl,{size:12,"aria-hidden":!0}),` `,l?Sk(s,y-d):jpe]})}):null,de?(0,J.jsxs)(`div`,{className:`section section-hint`,children:[Ope(de),de.at?(0,J.jsxs)(J.Fragment,{children:[` (`,Gp(de.at),`)`]}):null,de.refused?(0,J.jsx)(`pre`,{className:`update-log rh-refusal`,children:de.refused.text}):null,he?(0,J.jsx)(`div`,{children:he}):null]}):null,Oe&&e?(0,J.jsxs)(`div`,{className:`section section-hint`,children:[(0,J.jsx)(`div`,{children:n?.readError}),n?.engine?.path?(0,J.jsx)(`div`,{children:(0,J.jsx)(`code`,{children:n.engine.path})}):null,(0,J.jsxs)(`div`,{className:`rh-tile-acts`,children:[(0,J.jsxs)(Y,{type:`button`,className:`rh-verb`,onClick:()=>void ee(!0),children:[(0,J.jsx)(Hc,{size:12,"aria-hidden":!0}),` `,l?Sk(s,y-d):cme(n?.engine?.kind===`repo`?`repo`:`bundled`,s)]}),n?.engine?.kind===`repo`?null:(0,J.jsxs)(Y,{type:`button`,className:`rh-verb`,onClick:()=>void ee(),children:[(0,J.jsx)(Wl,{size:12,"aria-hidden":!0}),` `,lme(s)]})]})]}):null,ke&&r&&e?(0,J.jsx)(`div`,{className:`section`,children:(0,J.jsxs)(Y,{className:`rh-verb`,type:`button`,onClick:Ae,children:[(0,J.jsx)(al,{size:12,"aria-hidden":!0}),` `,kme,`…`]})}):null,h?(0,J.jsx)(`div`,{className:`section section-hint`,children:h}):null,p?(0,J.jsx)(`div`,{className:`section section-hint`,children:Spe(p)}):null,ye?(0,J.jsx)(`div`,{className:`section section-hint`,children:ye}):null,Fe.length||Me?(0,J.jsx)(Gge,{keys:Fe,refresh:Me}):null,Ne||k?(0,J.jsx)(qge,{axis:O,onAxis:w,commits:T}):null,Ne&&e?(0,J.jsx)(Zhe,{repoId:e.id,axis:O,onCommits:D,seriesStamp:`${s?.lastSha??``}:${s?.rows??0}`,onAsk:r?we:void 0,onAskTrend:r?Te:void 0,onQualityRun:r?Ee:void 0}):null,k&&c?(0,J.jsxs)(J.Fragment,{children:[Ok(s?.versions)?(0,J.jsx)(`div`,{className:`rh-cap rh-gutter`,children:Ok(s?.versions)}):null,(0,J.jsx)(`div`,{className:`section rh-prov`,children:rme(L.displayName)}),fme(c.central).map(e=>(0,J.jsx)(`div`,{className:`rh-cap rh-gutter`,children:e},e)),Pe.longest?(0,J.jsx)(Yj,{id:`longest`,children:t=>(0,J.jsx)(Fge,{longest:k.longest,classics:k.classics,p95:be,width:t,onOpenFile:e&&o?t=>o(e.id,c.scope?`${c.scope.replace(/\/+$/,``)}/${t}`:t):void 0})}):null,(0,J.jsx)(khe,{series:k.series,windowReadings:c.windowReadings,minReadings:c.minReadings,axis:O,onAsk:r&&e?Ce:void 0,onAskAll:r&&e&&c.series.length?De:void 0}),(0,J.jsx)(whe,{claudeMd:k.series.find(e=>e.key===`context.claudeMdChars`)??null,descriptions:k.series.find(e=>e.key===`context.descChars`)??null,context:c.context}),(0,J.jsx)(Yj,{id:`size`,children:e=>(0,J.jsx)(jge,{classics:k.classics,width:e})}),Pe.table?(0,J.jsx)(Yj,{id:`table`,children:()=>(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Rge,{plot:c}),(0,J.jsxs)(`details`,{className:`hint-more rh-more`,children:[(0,J.jsx)(`summary`,{children:`not drawn here`}),(0,J.jsx)(`p`,{children:Gpe()}),(0,J.jsx)(`p`,{children:Ape(!!n?.page)})]})]})}):null,e?(0,J.jsx)(zge,{plot:c,repoName:e.repoName,series:k.own?.series,axis:O,actionsFor:r?e=>(0,J.jsxs)(Y,{className:`rh-verb`,type:`button`,onClick:()=>Ce({...e,detail:e.means}),children:[(0,J.jsx)(al,{size:12,"aria-hidden":!0}),` `,Kpe,`…`]}):void 0}):null]}):null,ge&&ge.preamble?(0,J.jsxs)(`details`,{className:`hint-more rh-notes`,open:_,onToggle:e=>v(e.currentTarget.open),children:[(0,J.jsx)(`summary`,{children:`how to read this`}),(0,J.jsx)(`div`,{className:`tr-say rh-doc`,children:(0,J.jsx)(Rj,{src:ge.preamble,q:``,onCopy:e=>void gp(e)})})]}):null,(0,J.jsx)(Jge,{days:_e})]})}function Qge({repo:e,onOpen:t}){let n=Rr(e);return n===`unknown`?null:n===`absent`?(0,J.jsx)(`div`,{className:`act-cants`,children:(0,J.jsx)(wE,{children:Wi(n)})}):(0,J.jsxs)(`button`,{className:`more-act`,onClick:t,children:[(0,J.jsx)(hl,{size:Yge}),`over time`]})}function $ge(e,t){return{when:e?.when??t??{kind:`now`},parkedAt:e?.parkedAt??null}}var Xj=`send.compose`;function e_e(e,t){return t!==`refused`||e.padId===void 0&&e.ackId===void 0?e:{...e,padId:void 0,ackId:void 0}}var Zj=(()=>{try{return Intl.DateTimeFormat().resolvedOptions().timeZone||``}catch{return``}})(),t_e=e=>new Date(e-new Date(e).getTimezoneOffset()*6e4).toISOString().slice(0,16);function Qj(e,t,n=0){let r=new Date;return r.setDate(r.getDate()+n),r.setHours(e,t,0,0),r.getTime()}function n_e(){let e=Date.now(),t=Qj(20,0),n=t<=e,r=(()=>{let e=new Date;return e.setDate(e.getDate()+((8-e.getDay())%7||7)),e.setHours(9,0,0,0),e.getTime()})();return[{key:`1h`,label:`in 1h`,at:e+36e5},{key:`3h`,label:`in 3h`,at:e+108e5},{key:`eve`,label:n?`tomorrow 20:00`:`tonight 20:00`,at:n?Qj(20,0,1):t},{key:`tom`,label:`tomorrow 09:00`,at:Qj(9,0,1)},{key:`mon`,label:`Mon 09:00`,at:r}]}var $j=[0,30,60,120,180,360],r_e=[10,25,50,75];function eM(e){let t=typeof e==`string`?Number(e.trim()):typeof e==`number`?e:NaN;if(!Number.isFinite(t))return null;let n=Math.round(t);return n>=1&&n<=100?n:null}function i_e(e,t){let n=new Set(r_e);for(let r of[e,t]){let e=eM(r);e!=null&&n.add(e)}return[...n].sort((e,t)=>e-t)}function a_e(e){let t=e.trim();if(!t)return`Type a percentage — 1 to 100 — or pick one above.`;if(eM(t)!=null)return null;let n=Number(t);return Number.isFinite(n)?Math.round(n)===0?`0% left is met by every meter, which is what no condition already says — tap that instead.`:`${t}% is outside 1–100: a window reads 100% at its reset and 0% when it is spent.`:`“${t}” is not a number. 1 to 100.`}var o_e=[{min:0,label:`skip it`},{min:120,label:`up to 2h late`},{min:720,label:`up to 12h late`},{min:4320,label:`up to 3 days late`}],tM=e=>({kind:`at`,rule:{kind:`once`,at:Date.now()+e,offsetMin:0},graceMin:120}),s_e=(e=!1)=>({kind:`at`,rule:{kind:`window`,window:e?`weekly`:`session`,edge:`before`,offsetMin:-60,oneShot:!0},graceMin:120}),nM=(e,t)=>!t||e.kind!==`window`||e.periodId||e.window===`weekly`?e:{...e,window:`weekly`,guardWindow:e.guardWindow===`weekly`?void 0:e.guardWindow};function rM(e){if(e<60)return`${e}m`;let t=Math.floor(e/60),n=e%60;return n?`${t}h${n}m`:`${t}h`}function iM(e){let t=typeof e==`number`?e:typeof e==`string`?aM(e):NaN;if(!Number.isFinite(t))return null;let n=Math.round(t);return n>=1&&n<=1440?n:null}function aM(e){let t=e.trim().toLowerCase().replace(/\s+/g,``),n=/^(?:(\d+(?:\.\d+)?)h)?(?:(\d+(?:\.\d+)?)m?)?$/.exec(t);return!t||!n||n[1]==null&&n[2]==null?NaN:Number(n[1]??0)*60+Number(n[2]??0)}function c_e(e,t){let n=new Set($j.filter(e=>e>0));for(let r of[e,t]){let e=iM(r);e!=null&&n.add(e)}return[...n].sort((e,t)=>e-t)}function l_e(e){let t=e.trim();if(!t)return`Type a lead — 45m, 4h, 1h30 — or pick one above.`;if(iM(t)!=null)return null;if(t.startsWith(`-`))return`Type how long before, without a minus — the segment above already says before.`;let n=aM(t);return Number.isFinite(n)?Math.round(n)===0?`0 before the reset is the reset itself — that is right after it resets, above.`:`Up to 24h before: the host keeps a lead within a day of the reset.`:`“${t}” is not a duration. Try 45m, 4h or 1h30.`}function oM(e,t){return e.kind===`repo`?t.kind!==`now`:e.kind===`repos`&&t.kind!==`at`}function u_e(e,t){return(e.kind===`repo`||e.kind===`repos`)&&e.flagWhenDone===!0&&oM(e,t)?!0:void 0}var sM=e=>e.kind===`repo`||e.kind===`repos`?e.budget:void 0;function cM(e,t){if(e.kind!==`repo`&&e.kind!==`repos`)return e;let{budget:n,...r}=e;return t?{...r,budget:t}:r}function d_e(e,t,n){let r=(e.kind===`repo`||e.kind===`repos`)&&e.flagWhenDone&&(!n||oM(e,n))?`, flagged when done`:``;switch(e.kind){case`session`:return t.sessionTitle(e.sessionId);case`repo`:return`${t.repoName(e.cwd)} · a new session${e.resume?`, continued`:``}`+(e.closeWhenDone===!0?`, closes when done`:e.closeWhenDone===!1?`, kept open`:``)+r+UT(e.launch)+(e.budget?`, budget ${yr(e.budget)}`:``);case`repos`:return(e.dirs.length===1?t.repoName(e.dirs[0]):`${e.dirs.length} repos`)+r+UT(e.launch)+(e.budget?`, budget ${yr(e.budget)}`:``);case`shell`:return`${t.buildName(e.cwd,e.buildId)} · ${t.repoName(e.cwd)}`}}function f_e(e,t,n){let r=BT(e.target),i=p_e(e,t,n)+(UT(r)?` · ${HT(r)}`:``);return(e.target.kind===`repo`||e.target.kind===`repos`)&&e.target.budget?`${i} · budget ${yr(e.target.budget)}`:i}function p_e(e,t,n){if(e.when.kind===`at`)return n==null?e.when.rule.kind===`window`?`Save for ${va(e.when.rule)}`:`pick a time it can still reach`:`Save for ${Pe(n)}`;if(e.when.kind===`after`){let n=jn(e.when.title,e.when.onlyIfOk);switch(e.target.kind){case`session`:return`Send to ${t.sessionTitle(e.target.sessionId)} ${n}`;case`repo`:return`Queue for ${t.repoName(e.target.cwd)} · a new session ${n}`;case`repos`:{let r=e.target.dirs.length;return`Fan out to ${r===1?t.repoName(e.target.dirs[0]):`${r} repos`} ${n}`}case`shell`:return`${t.buildName(e.target.cwd,e.target.buildId)} cannot wait for another item`}}let r=e.when.kind===`idle`;switch(e.target.kind){case`session`:return r?`Send to ${t.sessionTitle(e.target.sessionId)} when it's free`:`Send to ${t.sessionTitle(e.target.sessionId)}`;case`repo`:return r?`Queue for ${t.repoName(e.target.cwd)} · a new session when this repo is free`:`Start in ${t.repoName(e.target.cwd)}`;case`repos`:{let n=e.target.dirs.length,r=n===1?t.repoName(e.target.dirs[0]):`${n} repos`;return e.sequential?`Queue in ${r}`:`Fan out to ${r}`}case`shell`:return r?`Queue ${t.buildName(e.target.cwd,e.target.buildId)}`:`Run ${t.buildName(e.target.cwd,e.target.buildId)}`}}function m_e(e){return/^queue\b/i.test(e)?e:`Queue · ${e}`}var lM=`those words are running now — changing their when would describe a run that never happened, and posting them again would run them twice`,h_e=`this row is one repo's work — send it to several repos and it would be a second copy beside it, so drop its clock first`,g_e=`this row runs a prompt — a build is a different thing, so post it as its own and delete this one`;function uM(e,t){return e.when.kind===`at`?e.target.kind===`session`?!t||t.state===`done`||t.state===`canceled`?{kind:`post`}:t.state===`starting`||t.state===`running`?{kind:`refuse`,why:lM}:{kind:`patch`}:{kind:`upsert`}:!t||t.state===`done`||t.state===`canceled`?{kind:`post`}:t.state===`starting`||t.state===`running`?{kind:`refuse`,why:lM}:e.target.kind===`repos`?{kind:`refuse`,why:h_e}:e.target.kind===`shell`?{kind:`refuse`,why:g_e}:{kind:`patch`}}function __e(e){return e.kind===`now`?`re-timed — the same row, and it goes as soon as the desktop can take it`:e.kind===`idle`?`re-timed — the same row, waiting its turn instead of waiting for its clock`:e.kind===`after`?`re-timed — the same row, and it goes ${jn(e.title,e.onlyIfOk)}`:`re-timed — the same row`}var v_e=`no connection — this row's clock lives on the desktop and nothing here changed. Its words are still in the box.`,dM=(e,t)=>e.kind===`at`&&t==null&&e.rule.kind===`once`?`the time it resolves to has already passed`:null,y_e=`write the prompt first`;function b_e(e,t,n){let r=e.prompts.map(e=>e.trim()).filter(Boolean);if(e.target.kind!==`shell`&&!r.length)return y_e;if(e.target.kind===`repos`&&!e.target.dirs.length)return`pick at least one repo`;if(e.target.kind===`repo`&&!e.target.cwd)return`pick the repo it runs in`;if(e.target.kind===`session`&&!e.target.sessionId)return`pick where it goes`;let i=dM(e.when,t);if(i)return i;if(e.when.kind===`at`&&e.target.kind===`shell`)return`a build cannot be scheduled — the clock only fires prompts`;if(e.when.kind===`at`&&e.target.kind===`session`&&!e.target.cwd)return`this session has no repo on it — the clock has nowhere to reopen its conversation`;if(e.when.kind===`after`&&!e.when.id)return`pick the item it waits for`;if(e.when.kind===`after`&&e.target.kind===`shell`)return`a build cannot wait for another item — a chain only queues prompts`;if(e.when.kind===`after`&&e.target.kind===`repos`&&r.length>1)return`a sweep is one prompt — chain a single repo, or send one turn`;let a=uM(e,n);return a.kind===`refuse`?a.why:null}var fM={activity:`Activity`,automation:`Automation`,weekburn:`Week-end burn`,whatsnew:`What's new`},x_e=216e5,S_e=e=>e?`If that item fails, this one fails too and says so — it is never left waiting for something that cannot happen twice.`:`It runs either way — “run the tests, then tell me what happened” wants to run when they fail. Tick it to run only after a success.`,C_e=`The desktop holds this, with no deadline: if it was asleep when that item finished, this still goes in when it wakes. A chain is not a schedule — it has no clock to arm and appears in ${fM.activity} as work, not in ${fM.automation}.`;function w_e(e,t,n){let r=e=>e.state===`running`||e.state===`starting`?0:e.state===`queued`||e.state===`blocked`?1:2;return e.filter(e=>n&&e.id===n||e.trigger.kind===`at`&&Ia(e.trigger.rule)?!1:r(e)<2||e.state!==`canceled`&&t-(e.settledAt??e.createdAt)<=x_e).sort((e,t)=>r(e)-r(t)||(r(e)===2?(t.settledAt??t.createdAt)-(e.settledAt??e.createdAt):(e.order??0)-(t.order??0)||e.createdAt-t.createdAt))}function pM(e,t,n){return t.kind!==`at`||e.kind!==`session`||!e.cwd?null:`This goes to ${n}. A session lasts as long as its process, so if that one has gone when the clock comes round, the desktop reopens the conversation it was in and sends it there.`}var mM=(e,t)=>e.kind===`at`?ri(e.rule,Date.now(),t):null;function T_e(e){return e.kind===`repos`?{off:`all at once — a fresh session in each repo`,on:`one at a time — it waits in each repo's backlog and opens its own session there`}:e.kind===`repo`?{off:`start it straight away, alongside anything else queued for this repo`,on:`wait for this repo's other queued sessions to finish first`}:null}var hM={session:`the session window`,weekly:`the weekly window`},E_e={session:`checks the session meter`,weekly:`checks the weekly meter`},gM=e=>e.window===`weekly`?`weekly`:`session`,_M=e=>e.guardWindow??gM(e);function D_e(e){let t=gM(e),n=_M(e),r=t===`weekly`?`session`:`weekly`,[i,a]=[hM[t],hM[r]],o=bn(hM,n,`the window the rule names`),s=e.minPctLeft;if(e.edge===`after`&&n===t)return`A window that has just reset is empty by definition, so there is nothing to ask about ${i} at the instant this fires — written like this the condition is dropped and the rule runs every time. Point it at ${a}, or set it back to no condition.`;let c=e.oneShot===!0?` It stays armed for the next reset, and the next, until one meets the condition — then it runs once.`:``;return n===t?`If less than ${s}% of ${i} is left when it fires, nothing runs and you get a notification saying it was skipped.${c} A meter the host cannot read counts as not met — the condition exists to stop work, so an unreadable one stops it too.`:`It waits for ${i} to reset, then asks about ${o}: unless at least ${s}% of that one is left, nothing runs and you get a notification saying it was skipped.${c}`}function O_e(e){let t=e.hours;if(!t)return`Any hour. Set a window and the rule still becomes due when the anchor above says — it waits for the window to open, and how late it counts as is measured from that opening, not from the anchor.`;if(t.from===t.to)return`Both ends name the same minute, which is a window with no width. It is dropped rather than guessed at, so the rule would run at any hour — move one of them.`;let n=`${String(Math.floor(t.from/60)).padStart(2,`0`)}:${String(t.from%60).padStart(2,`0`)}`,r=e.tz?`, ${e.tz}`:``,i=t.from>t.to?` — overnight, through midnight`:``;return`Only ${Wee(e)}${i}${r}. Due outside it, the run waits for ${n} and its lateness is counted from there.`}function k_e(e){let t=new Set;for(let n of e.matchAll(/\.claude\/inbox\/[A-Za-z0-9._-]+/g))t.add(n[0]);return[...t]}function A_e(e,t,n){return n===0?`tick the rows to move first`:e.kind===`at`&&t==null&&e.rule.kind===`once`?`the time it resolves to has already passed`:e.kind===`after`&&!e.id?`pick the item it waits for`:null}function j_e(e,t){return`Re-time ${e===1?`it`:`these ${e}`} — ${t}`}var vM=`next in line`;function M_e(e,t,n){return!e||n<=0?null:`Held: ${e}${t?` — resumes ${Pe(t)}`:``}. These are queued work, so whatever when you pick, they wait for the budget like the rest of the queue.`}function N_e(e,t,n){switch(e.trigger.kind){case`now`:case`idle`:case`budget`:return!0;case`at`:return typeof e.nextAt==`number`&&e.nextAt<=t;case`after`:{let t=n.get(e.trigger.id);return t?t.state===`done`||!e.trigger.onlyIfOk&&(t.state===`failed`||t.state===`canceled`):!1}default:return!1}}function yM(e,t,n){return e.state!==`queued`&&e.state!==`blocked`||e.blockReason!==`budget`||xi(e,t)?!1:N_e(e,t,n??new Map)}function P_e(e,t,n=Date.now()){let r=new Map(t.map(e=>[e.id,e]));return e.filter(e=>{let t=r.get(e);return!!t&&yM(t,n,r)})}function bM(e){return`let ${e===1?`it`:`these ${e}`} past the budget`}function xM(e,t){return`${e<t?`${e} of the ${t} you ticked are held by the budget; the rest wait on something else. `:``}Lifts the budget for ${e===1?`this row`:`these ${e}`} and nothing else — ${e>1?`rows in the same repo still run one at a time, `:``}wait until free, the session cap and each row's own when all still apply. It lasts until the row starts, or until this budget window resets.`}function F_e(e){return`let ${e} past the budget?`}function I_e(e){return`let ${e===1?`it`:e} past the budget — ${e===1?`it runs`:`they run`} in turn`}function SM(e){return e?`starts it this second in a session of its own — skips the queue: the budget, one at a time and wait until free`:`goes into its session this second — skips the queue: the budget and waiting for that session to be free`}var CM=`another agent is working in this checkout — this starts a second one beside it`;function wM(e,t,n,r){return e?t.some(t=>t.id!==n&&t.cwd===e&&(t.state===`starting`||t.state===`running`))?!0:(r??[]).some(t=>t.running&&t.turnActive===!0&&t.cwd===e):!1}var L_e=`queues an item in its backlog — it runs in turn`;function TM(e,t){return`From ${e}'s opt-ins — ${t}`}function EM(e,t,n){let r=Ai(e),i=Zi(e,t.repoName);if(!r||i==null)return null;let a=r.action;if(a.kind!==`agent`&&a.kind!==`schedule`)return null;let o={prompts:[i],target:{kind:`repo`,cwd:t.worktreePath},cwdHint:t.worktreePath,repoId:t.id,origin:TM(t.repoName,r.title)};if(a.kind===`agent`)return o;let s=Nee(e,n||`UTC`);return s?{...o,target:{kind:`repo`,cwd:t.worktreePath,launch:{model:a.model}},when:{kind:`at`,rule:s,graceMin:a.graceMin,name:r.title,waitUntilFree:!0}}:null}function R_e(e){return e.filter(e=>{let t=Ai(e.id)?.action.kind;return t===`agent`||t===`schedule`})}function z_e(e){return R_e(e).length>=2}function B_e(e){return`walk me through these ${e}…`}function V_e(e,t){let n=ute(e,t.repoName);return n==null?null:{prompts:[n],target:{kind:`repo`,cwd:t.worktreePath},cwdHint:t.worktreePath,repoId:t.id,origin:TM(t.repoName,`walk through ${e.length} offers`)}}function H_e(e){return`${e} you said not for me`}function U_e(e){return`${e} ${e===1?`doesn't`:`don't`} fit this repo`}function W_e(e){return`Started here · ${e}`}function G_e(e){return new Date(e).toLocaleDateString(void 0,{day:`numeric`,month:`short`})}function K_e(e,t=G_e){let n=`Sent ${t(e.at)}`;switch(e.status){case`waiting`:return`${n} — waiting in this repo's backlog.`;case`running`:return`${n} — running now.`;case`open`:return`${n} to a session that is still open.`;case`done`:return`${n} — that run finished, but it is not set up yet.`;case`failed`:return`${n} — that run failed.`;case`canceled`:return`${n} — that row was cancelled.`;case`ended`:return`${n} — that session has closed, and it is not set up yet.`;default:return`${n} — this app version cannot say what became of it.`}}var q_e=`already sent — again?`;function J_e(e,t){return`Nothing to offer here right now — every opt-in is either on or answered.${e+t>0?` What you turned down and what does not fit this repo are folded below.`:``}`}var Y_e=`Optional things this repo can turn on. Nothing here is a problem, and nothing is sent until you send it.`,X_e=`Opt-ins compare nothing: they are offers, not readings. Each is on, off or not for you, and none is counted in the repo's badge.`,Z_e=16;function DM(e){switch(e.kind){case`fix`:return(0,J.jsx)($s,{size:14});case`open`:return e.to===`series`?(0,J.jsx)(hl,{size:14}):(0,J.jsx)(kl,{size:14});case`agent`:return(0,J.jsx)(al,{size:14});case`schedule`:return(0,J.jsx)(Ss,{size:14})}}function Q_e({repo:e,onSeed:t,onSeries:n,onCapture:r,onChecklist:i}){let a=e?.id??``,o=fh(`optins:${a}`,()=>U.optIns(a),{enabled:!!a}),s=o.data,[c,l]=(0,H.useState)(null),[u,d]=(0,H.useState)(null),[f,p]=(0,H.useState)([]),[m,h]=(0,H.useState)(!1),[g,_]=(0,H.useState)(!1);async function v(e,t){if(a&&!c){q(t===`declined`?`action:optins.decline`:t===`done`?`action:optins.done`:`action:optins.clear`),l(e),d(null),p([]);try{let n=await U.optInChoice(a,e,t);n.ok&&n.report?o.set(n.report):n.ok?o.reload({quiet:!0}):d(n.error||`the desktop did not store it`)}catch(e){d(String(e.message||e))}finally{l(null)}}}async function y(e,t){if(a&&!c){q(`action:optins.fix`),l(e),d(null),p([]);try{let e=await U.complianceFix(a,[t]);e.ok?(p(e.notes??[]),e.report&&i?.(e.report),o.reload({quiet:!0})):d(e.error||`the fix did not run`)}catch(e){d(String(e.message||e))}finally{l(null)}}}function b(e){e&&t&&(q(`action:optins.seed`),t(e))}let x=See(s?.rows??[]);function S(i,a){let o=Ai(i.id),s=o.action,l=c===i.id?`working…`:o.verb;return s.kind===`fix`?(0,J.jsxs)(Y,{onClick:()=>void y(i.id,s.fix),children:[DM(s),` `,l]}):s.kind===`open`&&s.to===`series`?(0,J.jsxs)(Y,{onClick:()=>{q(`action:optins.series`),n()},children:[DM(s),` `,l]}):s.kind===`open`?!e||!r?(0,J.jsx)(wE,{children:`The capture screen cannot be opened from here.`}):(0,J.jsxs)(Y,{onClick:()=>{q(`action:optins.capture`),r(e)},children:[DM(s),` `,l]}):!e||!t?(0,J.jsx)(wE,{children:`No send surface here — open this repo from the launcher to send it.`}):a?(0,J.jsxs)(uT,{confirm:q_e,onConfirm:()=>b(EM(i.id,e,Zj)),children:[DM(s),` `,l]}):(0,J.jsxs)(Y,{onClick:()=>b(EM(i.id,e,Zj)),children:[DM(s),` `,l]})}function C(e,t){let n=Ai(e.id);return(0,J.jsxs)(`li`,{className:`check-row optin-card`,children:[(0,J.jsx)(`div`,{className:`check-top`,children:(0,J.jsx)(`span`,{className:`check-label`,children:n.title})}),e.sent&&(0,J.jsx)(`div`,{className:`check-detail optin-sent`,children:K_e(e.sent)}),(0,J.jsx)(`div`,{className:`check-detail optin-pitch`,children:n.pitch}),(0,J.jsx)(`div`,{className:`check-detail check-detail-quiet`,children:n.cost}),e.detail&&(0,J.jsx)(`div`,{className:`check-detail optin-seen`,children:e.detail}),(0,J.jsxs)(`div`,{className:`check-acts optin-acts`,children:[S(e,t&&!!e.sent),(0,J.jsxs)(Y,{onClick:()=>void v(e.id,`done`),children:[(0,J.jsx)(ys,{size:14}),` mark as done`]}),(0,J.jsxs)(Y,{onClick:()=>void v(e.id,`declined`),children:[(0,J.jsx)(Gc,{size:14}),` not for me`]})]})]},e.id)}return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`section-head`,children:[(0,J.jsx)(`span`,{className:`section section-hint`,children:Y_e}),(0,J.jsxs)(Y,{onClick:()=>o.reload({quiet:!0}),title:`read the offers again`,children:[(0,J.jsx)(Wl,{size:14,className:o.inflight?`spin`:void 0}),` re-check`]})]}),(0,J.jsx)($,{res:o,empty:!s,thing:`the opt-ins`,noun:`list of opt-ins`,children:`The desktop listed no opt-ins for this repo.`}),u&&(0,J.jsxs)(Z,{style:{color:`var(--dead)`},children:[`The desktop said: `,u]}),f.map((e,t)=>(0,J.jsx)(Z,{children:e},t)),s&&(0,J.jsxs)(J.Fragment,{children:[e&&t&&z_e(x.offered)&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{className:`send`,onClick:()=>b(V_e(x.offered,e)),children:[(0,J.jsx)(Ps,{size:14,style:{verticalAlign:`-2px`,marginRight:4}}),B_e(x.offered.length)]}),(0,J.jsx)(Z,{children:`One session that asks which of these you want, then posts each one as its own piece of work. Nothing is set up in it.`})]}),x.started.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`section`,children:W_e(x.started.length)}),(0,J.jsx)(Z,{children:`You began these in this repo, and the desktop does not see them set up yet. Sending one again starts it over.`}),(0,J.jsx)(`ul`,{className:`check-list`,children:x.started.map(e=>C(e,!0))})]}),x.offered.length>0?(0,J.jsxs)(J.Fragment,{children:[x.started.length>0&&(0,J.jsx)(`div`,{className:`section`,children:`Not started`}),(0,J.jsx)(`ul`,{className:`check-list`,children:x.offered.map(e=>C(e,!1))})]}):x.started.length===0&&(0,J.jsx)(`div`,{className:`empty`,children:J_e(x.declined.length,x.unfit.length)}),x.active.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`section`,children:`On`}),(0,J.jsx)(`ul`,{className:`check-list`,children:x.active.map(e=>(0,J.jsxs)(`li`,{className:`check-row optin-on`,children:[(0,J.jsxs)(`div`,{className:`check-top`,children:[(0,J.jsxs)(`span`,{className:`check-label`,children:[Ai(e.id).title,(0,J.jsxs)(`span`,{className:`check-kind`,children:[` · `,ete(e)]})]}),e.choice===`done`&&(0,J.jsxs)(Y,{onClick:()=>void v(e.id,null),children:[(0,J.jsx)(Ac,{size:14}),` undo`]})]}),e.detail&&(0,J.jsx)(`div`,{className:`check-detail check-detail-quiet`,children:e.detail})]},e.id))})]}),x.declined.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{className:`section optin-fold`,onClick:()=>h(e=>!e),"aria-expanded":m,children:[m?(0,J.jsx)(ac,{size:14}):(0,J.jsx)(jl,{size:14}),` `,H_e(x.declined.length)]}),m&&(0,J.jsx)(`ul`,{className:`check-list`,children:x.declined.map(e=>(0,J.jsx)(`li`,{className:`check-row optin-on`,children:(0,J.jsxs)(`div`,{className:`check-top`,children:[(0,J.jsx)(`span`,{className:`check-label`,children:Ai(e.id).title}),(0,J.jsxs)(Y,{onClick:()=>void v(e.id,null),children:[(0,J.jsx)(Nc,{size:14}),` offer again`]})]})},e.id))})]}),x.unfit.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{className:`section optin-fold`,onClick:()=>_(e=>!e),"aria-expanded":g,children:[g?(0,J.jsx)(ac,{size:14}):(0,J.jsx)(jl,{size:14}),` `,U_e(x.unfit.length)]}),g&&(0,J.jsx)(`ul`,{className:`check-list`,children:x.unfit.map(e=>(0,J.jsxs)(`li`,{className:`check-row optin-on`,children:[(0,J.jsx)(`div`,{className:`check-top`,children:(0,J.jsx)(`span`,{className:`check-label`,children:Ai(e.id).title})}),(0,J.jsx)(`div`,{className:`check-detail check-detail-quiet`,children:e.detail||`The desktop did not say why.`})]},e.id))})]})]})]})}function $_e({onOpen:e}){return(0,J.jsxs)(`button`,{className:`more-act`,onClick:e,title:`optional things this repo can turn on`,children:[(0,J.jsx)(zl,{size:Z_e}),`opt-ins`]})}var eve=[`counted`,`listed`,`desktop`],OM={counted:0,listed:2,desktop:3},kM=1.5,tve=e=>e.scope===`desktop`?`desktop`:mn(e)?`counted`:`listed`;function nve(e){return e.parts.filter(e=>e.readers.includes(`claude`)&&e.when.kind===`always`).reduce((e,t)=>e+t.chars,0)}function AM(e,t){let n=e.filter(e=>t.includes(e.scope??`repo`)),r=[],i=[],a=0;n.forEach((e,t)=>{let n=e.scope??`repo`;if(e.unsized){r.push({key:`${n}:${e.path}:${e.kind}`,path:e.path,kind:e.kind,scope:n,why:e.unsized});return}let o=nve(e);o<=0?a++:i.push({f:e,i:t,chars:o,band:tve(e)})}),i.sort((e,t)=>OM[e.band]-OM[t.band]||t.chars-e.chars||e.i-t.i);let o=i.reduce((e,t)=>e+t.chars,0),s=0,c=i.map(e=>{let t=o>0?s/o*100:0;s+=e.chars;let n=o>0?e.chars/o*100:0,r=e.f.scope??`repo`;return{key:`${r}:${e.f.path}:${e.f.kind}`,path:e.f.path,kind:e.f.kind,scope:r,band:e.band,chars:e.chars,x:t,w:n,seam:!1}});for(let e=0;e<c.length-1;e++)c[e].seam=c[e].w>=kM&&c[e+1].w>=kM;return{segs:c,bands:eve.map(e=>{let t=c.filter(t=>t.band===e);return{band:e,chars:t.reduce((e,t)=>e+t.chars,0),files:t.length}}).filter(e=>e.files>0),total:o,markers:r,idle:a,rows:n.length}}function rve(e,t){if(!e.length||!(t>=0)||t>1)return null;let n=t*100;for(let t=0;t<e.length;t++)if(n<e[t].x+e[t].w)return t;return e.length-1}function ive(e,t=6){return{shown:e.slice(0,t),more:Math.max(0,e.length-t)}}var jM=e=>Math.round(e/4),ave={counted:`threshold counts`,listed:`listed beside it`,desktop:`this desktop`},ove={counted:`counted by the threshold row`,listed:`listed beside the threshold, not counted by it`,desktop:`this desktop's, in every session — the threshold counts none of it`},sve=(e,t)=>`~${t(jM(e.chars))} tok`;function cve(e,t){return e.segs.length?`Every turn: ~${t(jM(e.total))} tokens (${t(e.total)} chars) from ${e.segs.length} ${e.segs.length===1?`file`:`files`}`:`Nothing from these files reaches Claude Code on every turn.`}function lve(e,t,n,r){let i=t>0?e.chars/t*100:0,a=i<1?`<1%`:`${Math.round(i)}%`;return`${n(e)} · ~${r(jM(e.chars))} tokens (${r(e.chars)} chars, ${a}) · ${ove[e.band]}`}function uve(e){let t=[];return e.idle&&t.push(`${e.idle} ${e.idle===1?`row carries`:`rows carry`} nothing every turn (scoped, on demand, or not read by Claude Code)`),e.markers.length&&t.push(`${e.markers.length} ${e.markers.length===1?`row has`:`rows have`} no size and ${e.markers.length===1?`is`:`are`} named below the bar, never drawn as a length`),t.length?`${e.segs.length} of ${e.rows} rows drawn; ${t.join(`; `)}.`:null}var MM=[`repo`,`desktop`],NM={repo:`In this repo`,desktop:`On this desktop`},PM=3;function FM(e){let t=vee([...e.files,...e.desktop??[]]),n=e=>t.filter(t=>t.scope===e);return{rows:t,bucket:n,chips:fE(MM.filter(t=>t!==`desktop`||e.desktop!=null),e=>({count:n(e).length}),e=>e)}}function IM({files:e,scopes:t,configDir:n,pick:r,onPick:i}){let a=AM(e,t),[o,s]=(0,H.useState)(null),c=i?r??null:o,l=i??s,[u,d]=(0,H.useState)(null),f=u??c,p=a.segs.find(e=>e.key===f)??null,m=e=>e.scope===`desktop`?Ha(e.path,n):e.path,h=e=>{let t=e.currentTarget.getBoundingClientRect(),n=t.width>0?rve(a.segs,(e.clientX-t.left)/t.width):null;return n==null?null:a.segs[n].key},{shown:g,more:_}=ive(a.markers),v=uve(a);return!a.segs.length&&!a.markers.length?null:(0,J.jsxs)(`div`,{className:`ao-strip`,children:[!a.segs.length&&(0,J.jsx)(`div`,{className:`ao-strip-head`,children:cve(a,R)}),a.segs.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`carried-bar`,role:`group`,"aria-label":`where the every-turn characters go; the line under it reads the picked file`,onPointerDown:e=>{let t=h(e);l(t!=null&&t===c?null:t),e.pointerType===`mouse`&&d(null)},onPointerMove:e=>{if(e.buttons){let t=h(e);t!=null&&l(t),e.pointerType===`mouse`&&d(null)}else e.pointerType===`mouse`&&d(h(e))},onPointerLeave:e=>{e.pointerType===`mouse`&&d(null)},children:a.segs.map(e=>(0,J.jsx)(`span`,{className:`carried-seg${e.key===f?` carried-on`:``}`,style:{left:`${e.x}%`,width:`${e.w}%`,background:UD[OM[e.band]]}},e.key))}),(0,J.jsx)(`div`,{className:`ctx-readout carried-readout`,children:p?lve(p,a.total,m,R):(0,J.jsx)(YD,{})}),(0,J.jsx)(`div`,{className:`ts-legend`,children:a.bands.map(e=>(0,J.jsxs)(`span`,{className:`ts-leg`,children:[(0,J.jsx)(`i`,{style:{background:UD[OM[e.band]]}}),(0,J.jsx)(`b`,{children:ave[e.band]}),` `,sve(e,R),(0,J.jsxs)(`em`,{children:[e.files,` `,e.files===1?`file`:`files`]})]},e.band))})]}),g.length>0&&(0,J.jsxs)(`div`,{className:`ao-marks`,"aria-label":`rows with no size`,children:[(0,J.jsx)(`span`,{className:`ao-marks-lead`,children:`no size:`}),g.map(e=>(0,J.jsx)(`span`,{className:`ao-mark`,children:e.kind},e.key)),_>0&&(0,J.jsxs)(`span`,{className:`ao-marks-lead`,children:[`+`,_,` more`]})]}),v&&(0,J.jsx)(`div`,{className:`ao-strip-note`,children:v})]})}function LM({rows:e,plot:t,configDir:n,onOpen:r,pick:i=null,onPick:a}){let o=e=>`${e.scope}:${e.path}:${e.kind}`,s=new Map(t.segs.map((e,t)=>[e.key,t])),c=e.map((e,t)=>({r:e,i:t,o:s.get(o(e))??1/0})).sort((e,t)=>e.o-t.o||e.i-t.i).map(e=>e.r),l=e=>a?.(i===e?null:e);return(0,J.jsx)(`ul`,{className:`carried-list ao-list`,children:c.map(e=>{let s=o(e),c=t.segs.find(e=>e.key===s),u=Vee(e,R),d=e.scope===`desktop`?Ha(e.path,n):e.path,f=[e.readers.length>0&&!e.unsized?`read by ${e.readers.join(`, `)}`:null,e.off??null].filter(Boolean).join(` · `),p=e.scope===`repo`&&!e.counted&&!e.unsized&&e.readers.includes(`claude`),m=(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`carried-head`,children:[(0,J.jsxs)(SE,{className:`carried-label`,children:[(0,J.jsx)(`span`,{className:`carried-path`,children:d}),` `,(0,J.jsx)(yE,{className:`carried-type`,children:e.kind})]}),u.num&&(0,J.jsx)(Q,{className:`carried-num`,children:u.num})]}),c&&(0,J.jsx)(`span`,{className:`carried-meter`,"aria-hidden":!0,children:(0,J.jsx)(`span`,{className:`carried-fill`,style:{width:`max(1px, ${c.w}%)`,background:UD[OM[c.band]]}})})]});return(0,J.jsx)(`li`,{className:c&&i===s?`carried-picked`:void 0,children:(0,J.jsxs)(xE,{children:[c&&a?(0,J.jsx)(`div`,{className:`carried-pick`,role:`button`,tabIndex:0,"aria-pressed":i===s,title:`read this file on the strip above`,onClick:()=>l(s),onKeyDown:e=>{(e.key===`Enter`||e.key===` `)&&(e.preventDefault(),l(s))},children:m}):(0,J.jsx)(`div`,{className:`carried-pick ao-still`,children:m}),(f||p)&&(0,J.jsxs)(Q,{as:`div`,children:[f,p&&(0,J.jsxs)(J.Fragment,{children:[f?` `:``,(0,J.jsx)(yE,{children:`not under the threshold`})]})]}),u.rest&&(0,J.jsx)(Q,{as:`div`,className:e.unsized?`ao-unsized`:void 0,children:u.rest}),r&&(0,J.jsxs)(`button`,{type:`button`,className:`link-btn ao-open`,onClick:()=>r(e.path),children:[(0,J.jsx)(Nl,{size:12}),` open`]})]})},s)})})}function RM({doc:e,repoId:t,onOpenFile:n,sessionDoors:r,onAllSessions:i}){let[a,o]=(0,H.useState)(null),[s,c]=(0,H.useState)(null),l=r??[],u=i||r?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`sheet-actions ao-doors`,children:[l.slice(0,PM).map(e=>(0,J.jsxs)(Y,{title:`Open the context sheet of ${e.title}: what its first request actually carried`,onClick:e.open,children:[(0,J.jsx)(yo,{size:12}),` what `,e.title,` carries →`]},e.id)),i&&(0,J.jsxs)(Y,{title:`Every conversation on this desktop, with its token split`,onClick:i,children:[(0,J.jsx)(qo,{size:12}),` all sessions`]})]}),l.length>PM&&(0,J.jsx)(Z,{children:`+${l.length-PM} more live in this repo — open them from the launcher.`}),r&&!l.length&&(0,J.jsx)(CE,{cants:[{label:`session view`,reason:`no live session in this repo — open one to see what its turns carry`}]})]}):null;if(!e||e.why)return(0,J.jsxs)(`div`,{className:`ao-rows`,children:[(0,J.jsx)(Z,{children:e?.why?`${e.why}; the sentence above is the whole reading.`:`This desktop did not send the per-file list (an older host); the sentence above is the whole reading.`}),u]});let d=Ca([...e.files,...e.desktop??[]],R),{rows:f,bucket:p,chips:m}=FM(e),h=a?[a]:MM,g=[...e.files,...e.desktop??[]],_=AM(g,h),v=f.some(e=>e.scope===`repo`&&!e.counted&&!e.unsized&&e.readers.includes(`claude`));return(0,J.jsxs)(`div`,{className:`ao-rows`,children:[d&&(0,J.jsx)(`div`,{className:`check-detail`,children:d}),(0,J.jsx)(`div`,{className:`ts-filter`,role:`group`,"aria-label":`which files`,children:m.map(e=>(0,J.jsx)(pE,{on:a===e.key,onClick:()=>o(dE(a,e.key)),title:`Only the files ${e.key===`repo`?`this repo`:`this desktop`} adds`,children:e.text},e.key))}),a&&(0,J.jsx)(Z,{children:`${p(a).length} of ${f.length} rows — tap the lit chip to show all.`}),(0,J.jsx)(IM,{files:g,scopes:h,configDir:e.configDir,pick:s,onPick:c}),v&&(!a||a===`repo`)&&(0,J.jsx)(Z,{children:`Rows tagged “not under the threshold” are listed beside the threshold row, not counted by it.`}),h.map(r=>{let i=p(r);return r===`desktop`&&e.desktop===null?(0,J.jsxs)(`div`,{className:`ao-group`,children:[(0,J.jsx)(`div`,{className:`ao-group-head`,children:NM[r]}),(0,J.jsx)(Z,{children:e.desktopWhy??`This desktop's own files could not be read.`})]},r):i.length?(0,J.jsxs)(`div`,{className:`ao-group`,children:[(0,J.jsx)(`div`,{className:`ao-group-head`,children:NM[r]}),r===`desktop`&&(0,J.jsx)(Z,{children:`These live outside the repo, so they do not open from here. They are what this desktop's files show; plugin packs synced from claude.ai are not on disk — a session's own sheet (below) lists the skills it actually carried.`}),(0,J.jsx)(LM,{rows:i,plot:_,configDir:e.configDir,pick:s,onPick:c,onOpen:r===`repo`&&n?e=>n(t,e):void 0})]},r):null}),u]})}function zM(e){return e.id===`exposure`?`summary`:e.exposure?e.accepted?`accepted`:e.exposure.level===`digest`?`digest`:`alerts`:null}function BM(e){let t=[],n=[],r=[],i=null;for(let a of e){let e=zM(a);e===`summary`?i=a:e===`accepted`?r.push(a):e===`digest`?n.push(a):e===`alerts`&&t.push(a)}return{alerts:t,digest:n,accepted:r,summary:i}}var VM=e=>{let t=zM(e);return t!==`accepted`&&t!==`digest`};function HM(e){return`Digest · ${e} — counted in nothing`}var UM=e=>`Accepted (${e})`;function WM(e){let t=[];return e.threshold&&t.push(e.threshold),e.severity&&t.push(e.severity),e.sources.length&&t.push(`from ${e.sources.join(`, `)}`),e.since&&t.push(`since ${e.since.slice(0,10)}`),t.join(` · `)}function GM(e){return e&&`version`in e&&e.version?`ends once a version newer than ${e.version} is installed`:e&&`date`in e&&e.date?`until ${e.date}`:e&&`change`in e&&e.change?`until the reading changes`:`for good`}var KM=864e5;function qM(e,t){let n=Date.parse(e);if(!Number.isFinite(n))return``;let r=Math.max(0,Math.floor((t-n)/KM));return r===0?`today`:r===1?`yesterday`:`${r} days ago`}function JM(e,t){if(e.builtIn)return`Accepted in code — ${e.reason}`;let n=qM(e.at,t);return`Accepted${n?` ${n}`:``}: ${e.reason} (${GM(e.until)})`}var YM=`accepted in code`;function XM(e){let t=[{key:`change`,label:`until the reading changes`},{key:`date`,label:`until a date`}];return e&&t.push({key:`version`,label:`ends once a version newer than the one you type is installed (now ${e})`}),t}function ZM(e){return e.exposure?.version?.trim()||null}var QM=`Say why you accept it — the reason stays with the row.`,$M=`Pick the date the accept ends.`,eN=`Type the newest version you accept; the accept ends once a newer one is installed.`;function tN(e,t,n){return e.trim()?t===`date`&&!n.trim()?$M:t===`version`&&!n.trim()?eN:null:QM}function nN(e,t,n,r){let i=n===`date`?{date:r.trim()}:n===`version`?{version:r.trim()}:{change:!0};return{id:e,accept:!0,reason:t.trim(),until:i}}var rN=[{key:`seen`,label:`seen`,hint:`Still counted. Quiet for this app version; a newer version alerts again.`},{key:`investigating`,label:`investigating`,hint:`Still counted. Quiet for this app version; a newer version alerts again.`},{key:`fixed`,label:`fixed`,hint:`Older versions stop counting; the same crash in this version or newer alerts as a regression. Needs an app version on the finding.`}],iN=`Type the version that carries the fix, like 1.4.2.`,aN=`A version is letters, digits and . + - only, up to 32 characters.`,oN=`A commit is 7 to 40 hex characters.`,sN=`The note is up to 280 characters.`;function cN(e,t,n,r){if(r.trim().length>280)return sN;if(e!==`fixed`)return null;let i=t.trim();if(!i)return iN;if(i.length>32||!/^[0-9A-Za-z.+-]+$/.test(i))return aN;let a=n.trim();return a&&!/^[0-9a-fA-F]{7,40}$/.test(a)?oN:null}function lN(e,t,n,r,i){return{id:e,state:t,...t===`fixed`?{fixedIn:n.trim()}:{},...t===`fixed`&&r.trim()?{commit:r.trim()}:{},...i.trim()?{note:i.trim()}:{}}}var uN=e=>({id:e,clear:!0});function dN(e){let t=e.exposure?.triage,n=!!e.exposure?.appVersion,r=n?null:fN;if(!t)return{open:`Mark…`,canClear:!1,line:null,offerFixed:n,noFixedWhy:r};let i=e.detail.includes(`crashes again in`);return{open:`Change mark…`,canClear:!0,line:t.state===`fixed`&&!i?y(t):null,offerFixed:n,noFixedWhy:r}}var fN=`Fixed needs an app version; Accept it instead.`,pN=e=>`Marked, not in today's reading (${e})`,mN=e=>!!e.accepted&&!e.accepted.builtIn&&e.accepted.byMark===!0,hN=`Against the outside world, read daily: published advisories on what is installed, deprecations, store and Scorecard readings. A finding here counts in the repo's badge like a set-up one; an accepted one stays listed with its reason.`,gN=`What the daily exposure watch and Scorecard found about this repo's dependencies, stores and published surface.`,_N=`re-check`,vN=`Run the exposure watch for this repo now, then re-read its findings`,yN=e=>`The watch did not run: ${e}`;function bN(e,t){return`${e} more ${e===1?`finding is`:`findings are`} under ${t===`watch`?`watch`:`set-up`}`}function xN({check:e,onAccept:t}){let[n,r]=(0,H.useState)(!1),[i,a]=(0,H.useState)(``),[o,s]=(0,H.useState)(`change`),[c,l]=(0,H.useState)(``),[u,d]=(0,H.useState)(null),[f,p]=(0,H.useState)(!1),m=ZM(e);if(!n)return(0,J.jsx)(`div`,{className:`check-acts`,children:(0,J.jsxs)(Y,{onClick:()=>r(!0),title:`Accept this finding, with a reason`,children:[(0,J.jsx)(Is,{size:12}),` Accept…`]})});let h=tN(i,o,c);async function g(){p(!0),d(null);let n=await t(nN(e.id,i,o,c));p(!1),n?d(n):r(!1)}return(0,J.jsxs)(`div`,{className:`check-acts`,style:{display:`block`},children:[(0,J.jsx)(Z,{children:`Accepting keeps the row, with your reason, under Accepted — it is not counted while accepted.`}),(0,J.jsx)(`textarea`,{className:`search`,rows:2,value:i,autoFocus:!0,placeholder:`why is this fine here?`,"aria-label":`reason`,onChange:e=>a(e.target.value)}),(0,J.jsx)(Bw,{label:`How long`,value:o,onChange:e=>{s(e),l(``)},options:XM(m)}),o===`date`&&(0,J.jsx)(`input`,{className:`search`,type:`date`,value:c,"aria-label":`accept until`,onChange:e=>l(e.target.value)}),o===`version`&&(0,J.jsx)(`input`,{className:`search mono`,value:c,"aria-label":`newest version you accept`,placeholder:`newest version you accept (now ${m})`,onChange:e=>l(e.target.value)}),u&&(0,J.jsx)(Z,{tone:`warn`,children:u}),(0,J.jsxs)(`div`,{className:`check-acts check-acts-split`,children:[h?(0,J.jsx)(Z,{as:`span`,children:h}):(0,J.jsx)(Y,{variant:`primary`,onClick:()=>void g(),children:f?`Accepting…`:`Accept`}),(0,J.jsx)(Y,{onClick:()=>{r(!1),d(null)},children:`cancel`})]})]})}function SN({check:e,onMark:t}){let n=e.exposure?.triage,[r,i]=(0,H.useState)(!1),[a,o]=(0,H.useState)(n?.state??`seen`),[s,c]=(0,H.useState)(n?.fixedIn??``),[l,u]=(0,H.useState)(n?.commit??``),[d,f]=(0,H.useState)(n?.note??``),[p,m]=(0,H.useState)(null),[h,g]=(0,H.useState)(!1),_=dN(e);function v(){let t=e.exposure?.triage;o(t?.state===`fixed`&&!_.offerFixed?`seen`:t?.state??`seen`),c(t?.fixedIn??``),u(t?.commit??``),f(t?.note??``),m(null),i(!0)}async function y(e,n){g(!0),m(null);let r=await t(e);g(!1),r?m(r):n&&i(!1)}if(!r)return(0,J.jsxs)(`div`,{className:`check-acts`,style:{display:`block`},children:[_.line&&(0,J.jsx)(`div`,{className:`check-detail check-detail-quiet`,children:_.line}),(0,J.jsxs)(`div`,{className:`check-acts`,children:[(0,J.jsxs)(Y,{onClick:v,children:[(0,J.jsx)(_o,{size:12}),` `,_.open]}),_.canClear&&(0,J.jsx)(Y,{onClick:()=>void y(uN(e.id),!1),children:h?`Clearing…`:`Clear mark`})]}),p&&(0,J.jsx)(Z,{tone:`warn`,children:p})]});let b=cN(a,s,l,d);return(0,J.jsxs)(`div`,{className:`check-acts`,style:{display:`block`},children:[(0,J.jsx)(Z,{children:rN.find(e=>e.key===a).hint}),(0,J.jsx)(Bw,{label:`Mark as`,value:a,onChange:o,options:rN.filter(e=>e.key!==`fixed`||_.offerFixed).map(e=>({key:e.key,label:e.label}))}),!_.offerFixed&&(0,J.jsx)(Z,{children:_.noFixedWhy}),a===`fixed`&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`input`,{className:`search mono`,value:s,"aria-label":`version that carries the fix`,autoFocus:!0,placeholder:`the version that carries the fix`,onChange:e=>c(e.target.value)}),(0,J.jsx)(`input`,{className:`search mono`,value:l,"aria-label":`commit (optional)`,placeholder:`commit (optional)`,onChange:e=>u(e.target.value)})]}),(0,J.jsx)(`textarea`,{className:`search`,rows:2,value:d,"aria-label":`note (optional)`,placeholder:`note (optional)`,onChange:e=>f(e.target.value)}),p&&(0,J.jsx)(Z,{tone:`warn`,children:p}),(0,J.jsxs)(`div`,{className:`check-acts check-acts-split`,children:[b?(0,J.jsx)(Z,{as:`span`,children:b}):(0,J.jsx)(Y,{variant:`primary`,onClick:()=>void y(lN(e.id,a,s,l,d),!0),children:h?`Marking…`:`Mark`}),(0,J.jsx)(Y,{onClick:()=>{i(!1),m(null)},children:`cancel`})]})]})}function CN({rows:e,now:t,onStop:n,onClearMark:r}){return e.length?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`section`,children:UM(e.length)}),(0,J.jsx)(`ul`,{className:`check-list`,children:e.map(e=>(0,J.jsxs)(`li`,{className:`check-row check-ignored`,children:[(0,J.jsxs)(`div`,{className:`check-top`,children:[(0,J.jsx)(`span`,{className:`check-icon`,children:(0,J.jsx)(Is,{size:16,color:`var(--dim)`})}),(0,J.jsx)(`span`,{className:`check-label`,children:e.label}),e.accepted.builtIn?(0,J.jsx)(Z,{as:`span`,children:YM}):mN(e)?(0,J.jsx)(Y,{onClick:()=>r(e.id),children:`Clear mark`}):(0,J.jsx)(Y,{onClick:()=>n(e.id),children:`stop accepting`})]}),(0,J.jsx)(`div`,{className:`check-detail check-detail-quiet`,children:JM(e.accepted,t)})]},e.id))})]}):null}function wN({marks:e,onClear:t}){return e.length?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`section`,children:pN(e.length)}),(0,J.jsx)(`ul`,{className:`check-list`,children:e.map(e=>(0,J.jsxs)(`li`,{className:`check-row check-ignored`,children:[(0,J.jsxs)(`div`,{className:`check-top`,children:[(0,J.jsx)(`span`,{className:`check-icon`,children:(0,J.jsx)(_o,{size:16,color:`var(--dim)`})}),(0,J.jsx)(`span`,{className:`check-label`,children:e.triageId.replace(/^exposure:/,``)}),(0,J.jsx)(Y,{onClick:()=>t(e.triageId),children:`Clear mark`})]}),(0,J.jsx)(`div`,{className:`check-detail check-detail-quiet`,children:y(e.triage)})]},e.triageId))})]}):null}function TN({n:e,children:t}){let[n,r]=(0,H.useState)(!1);return e?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`section`,children:(0,J.jsxs)(Y,{onClick:()=>r(!n),"aria-expanded":n,children:[n?(0,J.jsx)(ac,{size:14}):(0,J.jsx)(jl,{size:14}),` `,HM(e)]})}),n&&(0,J.jsx)(`ul`,{className:`check-list`,children:t})]}):null}var EN={pass:(0,J.jsx)(ys,{size:16,color:`var(--ok)`}),warn:(0,J.jsx)(Js,{size:16,color:`var(--warn)`}),fail:(0,J.jsx)(V,{size:16,color:`var(--dead)`})};function DN({repos:e,initialRepoId:t,initialRegion:n=`setup`,focus:r,onRemedy:i,onOpenFile:a,onSeed:o,onCapture:s,sessionDoorsFor:c,onAllSessions:l,onOpenInstructionFile:u,onClose:d}){let f=e.filter(e=>e.isPrimary),[p,m]=(0,H.useState)(t&&e.some(e=>e.id===t)?t:f[0]?.id??``),[h,g]=(0,H.useState)(n),[_,v]=(0,H.useState)(r===`findings`);(0,H.useEffect)(()=>{v(r===`findings`)},[r]),(0,H.useEffect)(()=>{g(n)},[n]);let[y,b]=(0,H.useState)(!1);(0,H.useEffect)(()=>{b(!1)},[r,n,p]);let[x,S]=(0,H.useState)(!1),[C,w]=(0,H.useState)(null),[T,E]=(0,H.useState)([]),[D]=(0,H.useState)(rk),O=fh(p,()=>U.compliance(p),{enabled:!!p}),[k,A]=(0,H.useState)(null),j=fh(`repohealth:${p}:${k??``}`,()=>U.repoHealth(p,k),{enabled:!!p}),M=O.data,N=j.data,P=e.find(e=>e.id===p)??null;async function F(e,t){if(p){q(t?`action:setup.ignore`:`action:setup.unignore`),S(!0),w(null),E([]);try{let n=await U.complianceIgnore(p,e,t);n.ok&&n.report?O.set(n.report):w(n.error||`the desktop did not store it`)}catch(e){w(String(e.message||e))}finally{S(!1)}}}async function I(e){if(!p)return`No repo is open, so there is nothing to accept.`;q(e.accept?`action:setup.accept`:`action:setup.unaccept`),S(!0),w(null);try{let t=await U.complianceAccept(p,e);return t.ok&&t.report?(O.set(t.report),null):t.error||`the desktop did not store it`}catch(e){return String(e.message||e)}finally{S(!1)}}async function ee(e){if(!p)return`No repo is open, so there is nothing to mark.`;q(e.clear?`action:setup.unmark`:`action:setup.mark`),S(!0),w(null);try{let t=await U.complianceTriage(p,e);return t.ok&&t.report?(O.set(t.report),null):t.error||`the desktop did not store it`}catch(e){return String(e.message||e)}finally{S(!1)}}async function te(e){if(!p||!e.length)return null;q(`action:setup.fix`),S(!0),w(null);try{let t=e.length===1?M?.confirm?.[e[0]]:void 0,n=await U.complianceFix(p,e,t);if(n.ok&&E(n.notes??[]),n.ok&&n.report)return O.set(n.report),n.report;n.ok||w(n.error||`fix failed`)}catch(e){w(String(e.message||e))}finally{S(!1)}return null}let ne=M?.checks??[],re=ne.filter(qa),ie=ne.filter(e=>!qa(e)),ae=h===`watch`?re:ie,oe=(h===`watch`?ie:re).filter(ct).length,se=qk(ae),ce=Kk(ae),le=!!i&&!!P,ue=se.length+(le?ce.length:0),de=ae.filter(ct),fe=_?de:ae;async function pe(){if(!P)return;let e=M;if(se.length){let t=await te(wme(ae));if(!t)return;e=t}let t=e?Kk(e.checks.filter(e=>qa(e)===(h===`watch`))):[];t.length&&i&&i($k(t,P.repoName,Gk()),P,t.length===1?t[0].label.toLowerCase():`${t.length} setup findings`)}(0,H.useEffect)(()=>{!y&&M&&_&&h===`setup`&&(b(!0),!ie.some(ct)&&re.some(ct)&&g(`watch`))},[y,M,_,h,ie,re]),(0,H.useEffect)(()=>{r===`context-weight`&&M&&h===`setup`&&document.querySelector(`[data-check="context-weight"]`)?.scrollIntoView({block:`start`})},[r,M,h,p]);let me=N?.plot??null,he=me?.series.find(e=>e.key===`context.claudeMdChars`)??null;return(0,J.jsx)(hE,{className:`readings-sheet`,title:`Repo readings`,icon:(0,J.jsx)(hl,{size:18}),onClose:d,children:(0,J.jsx)(`div`,{className:`sheet-scroll`,children:(0,J.jsxs)(`div`,{className:`form`,children:[(0,J.jsx)(ZO,{repos:e.filter(e=>e.isPrimary||e.id===p),value:e.find(e=>e.id===p)?.worktreePath??``,onChange:t=>{let n=e.find(e=>e.worktreePath===t);n&&m(n.id)},"aria-label":`repo`}),(0,J.jsxs)(`div`,{className:`ts-filter`,role:`group`,"aria-label":`reading`,children:[(0,J.jsx)(`span`,{className:`ctx-stackpick-lab`,children:`reading`}),(0,J.jsxs)(pE,{on:h===`setup`,clears:!1,onClick:()=>{g(`setup`),A(null)},children:[(0,J.jsx)(Cs,{size:14}),` set-up`]}),(0,J.jsxs)(pE,{on:h===`series`,clears:!1,onClick:()=>g(`series`),children:[(0,J.jsx)(hl,{size:14}),` over time`]}),(0,J.jsxs)(pE,{on:h===`watch`,clears:!1,onClick:()=>{g(`watch`),A(null)},children:[(0,J.jsx)(Us,{size:14}),` watch`]}),(0,J.jsxs)(pE,{on:h===`optins`,clears:!1,onClick:()=>{g(`optins`),A(null)},children:[(0,J.jsx)(zl,{size:14}),` opt-ins`]}),(0,J.jsx)(TE,{of:`what this region compares`,children:h===`optins`?X_e:h===`watch`?hN:Zpe(h)})]}),h===`setup`||h===`watch`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(ON,{kind:h,elsewhere:_?oe:0,onElsewhere:()=>g(h===`watch`?`setup`:`watch`),onOptIns:()=>{g(`optins`),A(null)},repoId:p,repo:P,res:O,report:M,rows:fe,allRows:ae,cut:_,onClearCut:()=>v(!1),busy:x,fixError:C,fixNotes:T,presets:D,canAsk:le,bulkCount:ue,patchable:se.length,forAgent:ce.length,onFix:te,onIgnore:F,onAccept:I,onMark:ee,onFixAll:()=>void pe(),onRemedy:i,claudeMdSeries:he,descSeries:me?.series.find(e=>e.key===`context.descChars`)??null,onOpenFile:u??a,sessionDoors:c?.(p),onAllSessions:l}),P&&h===`setup`&&(0,J.jsx)(Ume,{repo:P,say:Dg})]}):h===`optins`?(0,J.jsx)(Q_e,{repo:P,onSeed:o,onCapture:s,onSeries:()=>g(`series`),onChecklist:e=>O.set(e)}):(0,J.jsx)(Zge,{repo:P,res:j,view:N,onRemedy:i,scope:k,onScope:A,onOpenFile:a})]})})})}function ON({kind:e,elsewhere:t,onElsewhere:n,onOptIns:r,repoId:i,repo:a,res:o,report:s,rows:c,allRows:l,cut:u,onClearCut:d,busy:f,fixError:p,fixNotes:m,presets:h,canAsk:g,bulkCount:_,patchable:v,forAgent:y,onFix:b,onIgnore:x,onAccept:S,onMark:C,onFixAll:w,onRemedy:T,claudeMdSeries:E,descSeries:D,onOpenFile:O,sessionDoors:k,onAllSessions:A}){let[j,M]=(0,H.useState)(null),N=j?.repoId===i?j:null,P=s?(0,J.jsx)(RM,{doc:s.instructions,repoId:i,onOpenFile:O,sessionDoors:k,onAllSessions:A}):null;function F(e){if(!s)return null;let t=(ct(e)||Ie(e))&&!e.fix,n=t&&g?Ife(e.id,h):null,r=t&&g&&a?n?{label:n.title,run:()=>T(n.text,a,n.title)}:Gk().byCheck(e.id)?.agent?{label:Zk(e.id,Gk()),run:()=>AN(Gk().byCheck(e.id).agent,a,e.label)}:{label:Zk(e.id,Gk()),run:()=>T($k([e],a.repoName,Gk()),a,e.label.toLowerCase())}:null,c=e.id===`context-weight`&&s.contextLimits?(0,J.jsx)(oA,{repoId:i,view:s.contextLimits,setAt:s.contextLimitsSetAt,onReport:e=>o.set(e)}):null,l=e.id===`context-weight`?(0,J.jsx)(kN,{claudeMd:E,desc:D,workingTree:e.alwaysOnChars??null}):null,u=e.exposure?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`check-detail check-detail-quiet`,children:WM(e.exposure)}),(0,J.jsx)(xN,{check:e,onAccept:S}),(0,J.jsx)(SN,{check:e,onMark:C})]}):null;return(0,J.jsx)(jN,{c:e,busy:f,onFix:b,remedy:r,size:s.autoCompactDefault,onIgnore:x,extra:(0,J.jsxs)(J.Fragment,{children:[l,e.id===`context-weight`?P:null,c,u]})},e.id)}async function I(){if(N?.running)return;let e=i;M({repoId:e,running:!0});let t;try{let n=await U.exposureRun(e);t={ok:!!n?.ok,sentence:typeof n?.sentence==`string`&&n.sentence?n.sentence:yN(`the desktop gave no answer.`)}}catch(e){t={ok:!1,sentence:yN(e.message||`no link to the desktop.`)}}o.reload({quiet:!0}),M({repoId:e,running:!1,...t})}let ee=BM(l),te=!!(s?.instructions?.files.length||s?.instructions?.desktop?.length);return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`section-head`,children:[(0,J.jsx)(`span`,{className:`section section-hint`,children:e===`watch`?gN:(0,J.jsx)(J.Fragment,{children:`Checks a repo follows the conventions: CLAUDE.md tells the agent to use the outbox, inbox/outbox are gitignored and secrets aren't committed. Re-run regularly.`})}),(0,J.jsxs)(Y,{onClick:e===`watch`?I:()=>o.reload({quiet:!0}),title:e===`watch`?vN:`re-check`,children:[(0,J.jsx)(Wl,{size:14,className:o.inflight||N?.running?`spin`:void 0}),` `,e===`watch`?_N:`re-check`]})]}),e===`watch`&&N?.running&&(0,J.jsx)(Z,{children:`running the exposure watch for this repo — a first run can take a minute or two…`}),e===`watch`&&N?.sentence&&(0,J.jsx)(Z,{tone:N.ok?void 0:`warn`,children:N.sentence}),(0,J.jsx)($,{res:o,empty:!s,thing:`the setup checklist`,noun:`checklist`,children:`Nothing in this checklist applies to this repo yet.`}),s&&e===`watch`&&!l.length&&(0,J.jsxs)(Z,{children:[`Not watched yet: the daily exposure watch has no rows for this repo, and Scorecard has no reading yet.`,` `,(0,J.jsx)(`button`,{className:`link-btn`,onClick:r,children:`add this repo to the exposure watch`})]}),p&&(0,J.jsxs)(Z,{style:{color:`var(--dead)`},children:[`Fix failed: `,p]}),m.map((e,t)=>(0,J.jsx)(Z,{children:e},t)),s&&(0,J.jsxs)(J.Fragment,{children:[_>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{className:`send`,onClick:w,disabled:f,children:[(0,J.jsx)($s,{size:14,style:{verticalAlign:`-2px`,marginRight:4}}),f?`Fixing…`:Eme(v,g?y:0)]}),g&&a&&eA(v,y,a.repoName)&&(0,J.jsx)(Z,{children:eA(v,y,a.repoName)})]}),u&&(0,J.jsxs)(`div`,{className:`section filter-bar`,children:[(0,J.jsxs)(`span`,{className:`filter-bar-txt`,children:[Mme(c.length,l.length,e===`watch`?ee.digest.length:l.filter(Ie).length),t>0&&(0,J.jsxs)(J.Fragment,{children:[` · `,(0,J.jsx)(`button`,{className:`link-btn`,onClick:n,children:bN(t,e===`watch`?`setup`:`watch`)})]})]}),(0,J.jsxs)(`button`,{className:`filter-bar-clear`,onClick:d,children:[(0,J.jsx)(V,{size:14}),` clear`]})]}),(0,J.jsx)(`ul`,{className:`check-list`,children:c.filter(e=>!e.ignored&&VM(e)).map(F)}),!u&&(0,J.jsx)(TN,{n:ee.digest.length,children:ee.digest.map(F)}),!u&&l.some(e=>e.ignored)&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`section`,children:`Ignored in this repo`}),(0,J.jsx)(`ul`,{className:`check-list`,children:l.filter(e=>e.ignored).map(e=>(0,J.jsxs)(`li`,{className:`check-row check-ignored`,children:[(0,J.jsxs)(`div`,{className:`check-top`,children:[(0,J.jsx)(`span`,{className:`check-icon`,children:(0,J.jsx)(Gc,{size:16,color:`var(--dim)`})}),(0,J.jsx)(`span`,{className:`check-label`,children:e.label}),(0,J.jsx)(Y,{onClick:()=>x(e.id,!1),children:`stop ignoring`})]}),(0,J.jsx)(`div`,{className:`check-detail check-detail-quiet`,children:e.status===`pass`?`Fine here now.`:`Still on the far side of its line — not counted, not suggested.`})]},e.id))})]}),!u&&(0,J.jsx)(CN,{rows:ee.accepted,now:Date.now(),onStop:e=>void S({id:e,accept:!1}).then(e=>{e&&Dg(e)}),onClearMark:e=>void C(uN(e)).then(e=>{e&&Dg(e)})}),!u&&(0,J.jsx)(wN,{marks:ee.summary?.staleMarks??[],onClear:e=>void C(uN(e)).then(e=>{e&&Dg(e)})}),e===`setup`&&(s.contextLimits||te)&&!l.some(e=>e.id===`context-weight`)&&(0,J.jsxs)(`div`,{className:`check-row check-pass`,children:[(0,J.jsx)(`div`,{className:`check-top`,children:(0,J.jsx)(`span`,{className:`check-label`,children:`Agent context weight`})}),(0,J.jsxs)(`div`,{className:`check-detail`,children:[`Nothing to weigh yet — this repo has no CLAUDE.md.`,s.contextLimits?` These are the thresholds it will be measured against once it does.`:``]}),te&&P,s.contextLimits&&(0,J.jsx)(oA,{repoId:i,view:s.contextLimits,setAt:s.contextLimitsSetAt,onReport:e=>o.set(e)})]})]})]})}function kN({claudeMd:e,desc:t,workingTree:n}){if(!e&&!t)return null;let r=e?.points[e.points.length-1]?.sha7??t?.points[t.points.length-1]?.sha7??null,i=Hpe(n,e?.last!=null&&t?.last!=null?e.last+t.last:null,r);return(0,J.jsxs)(`div`,{className:`rh-twin`,children:[i?(0,J.jsx)(`div`,{className:`rh-twin-line`,children:i}):null,(0,J.jsx)(`ul`,{className:`rh-twin-rows`,children:[e,t].filter(Boolean).map(e=>(0,J.jsxs)(`li`,{children:[(0,J.jsx)(`span`,{className:`rh-twin-key`,children:e.label}),(0,J.jsx)(`span`,{className:`rh-twin-val`,children:Ck(e.last,e.unit)}),(0,J.jsx)(IA,{points:e.points,width:96,height:18,label:e.label})]},e.key))}),wk(e?.reading??t?.reading)?(0,J.jsx)(`div`,{className:`rh-twin-read`,children:wk(e?.reading??t?.reading)}):null]})}function AN(e,t,n){try{e(t,W())}catch(e){Dg(`${n} could not start: ${e instanceof Error?e.message:String(e)}`)}}function jN({c:e,busy:t,onFix:n,onIgnore:r,size:i,remedy:a,extra:o}){let s=Ie(e);return(0,J.jsxs)(`li`,{className:`check-row check-${s?`consider`:e.status}`,"data-check":e.id,children:[(0,J.jsxs)(`div`,{className:`check-top`,children:[(0,J.jsx)(`span`,{className:`check-icon`,children:s?(0,J.jsx)(Co,{size:16,color:`var(--accent)`}):EN[e.status]}),(0,J.jsxs)(`span`,{className:`check-label`,children:[e.label,s&&(0,J.jsx)(`span`,{className:`check-kind`,children:` · consider`})]}),e.fix&&!Jk(e.fix)&&(0,J.jsxs)(Y,{onClick:()=>n([e.fix]),disabled:t,children:[(0,J.jsx)($s,{size:12}),` `,Yk(e.fix,i,Gk())]})]}),(0,J.jsx)(`div`,{className:`check-detail`,children:e.detail}),e.fix&&!Jk(e.fix)&&Xk(e.fix)&&(0,J.jsx)(Z,{children:Xk(e.fix)}),s&&!e.exposure&&(0,J.jsxs)(`div`,{className:`check-acts check-acts-split`,children:[(0,J.jsx)(Z,{as:`span`,children:`Not counted in the badge. Leaving it is a fine answer.`}),(0,J.jsxs)(Y,{onClick:()=>r(e.id,!0),children:[(0,J.jsx)(Gc,{size:12}),` ignore in this repo`]})]}),e.fix&&Jk(e.fix)&&(0,J.jsx)(`div`,{className:`check-acts`,children:(0,J.jsxs)(uT,{confirm:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)($s,{size:12}),` `,Cme(e.fix,i)]}),disabled:t,onConfirm:()=>void n([e.fix]),children:[(0,J.jsx)($s,{size:12}),` `,Yk(e.fix,i,Gk())]})}),a&&(0,J.jsx)(`div`,{className:`check-acts`,children:(0,J.jsxs)(Y,{onClick:a.run,children:[(0,J.jsx)(al,{size:12}),` `,a.label,`…`]})}),o]})}var MN=G(null),NN=G({}),PN=G(null),FN=`first-look`;function IN(e=FN){so(B.demoTour),!(ku()&&Fre(e))&&pne(e)}function LN(){so(B.demoTour),!(ku()&&Ire())&&sne()}function RN(e,t){if(e)return`shell`;let n=t.toLowerCase();return n===`localhost`||n===`[::1]`||n.endsWith(`.ts.net`)||n.endsWith(`.local`)||/^\d{1,3}(\.\d{1,3}){3}$/.test(n)?`host`:`static`}function zN(){return RN(ku(),globalThis.location?.hostname??``)}var BN=`app:open-demotour`;function VN(){try{window.dispatchEvent(new CustomEvent(BN))}catch{}}var HN=`app:open-repohealth`;function UN(e){try{window.dispatchEvent(new CustomEvent(HN,{detail:{repoId:e??null}}))}catch{}}function WN(){return bu(gu()).length>0}function GN(e,t,n){return{prompts:[e],target:{kind:`repo`,cwd:t.worktreePath},cwdHint:t.worktreePath,repoId:t.id,origin:`From ${t.repoName}'s repo readings — ${n}`}}function KN(e){return{...e,region:`series`}}function qN(e,t={}){MN.set(e),NN.set(t),W().nav.open(`setup`)}function JN(e){PN.set(e),W().nav.open(`repohealth`)}function YN(e,t,n){W().say.track(`action:setup.remedy`),XN(GN(e,t,n))}function XN(e){MN.set(null),PN.set(null),W().nav.openSend(e)}function ZN(e){W().nav.openCapture(e)}function QN(e,t){let n=W();n.say.track(`action:files.fromReadings`);let r=n.nav.overlay;r===`setup`&&NN.set(KN(NN.get())),n.files.browseTo(e,t,r)}function $N(){let e=W();MN.set(null),NN.set({}),e.nav.close(`setup`),e.world.refreshRepos()}function eP(){let e=e=>{let t=W(),n=e.detail?.repoId??null,r=(n?t.world.repos.find(e=>e.id===n):null)??t.world.activeRepo??t.world.repos.find(e=>e.isPrimary)??null;r&&JN(r)};return window.addEventListener(HN,e),()=>window.removeEventListener(HN,e)}function tP(){PN.set(null),W().nav.close(`repohealth`)}function nP(e,t){let n=W();n.say.track(`action:files.fromReadings`);let r=n.nav.overlay;r===`setup`&&NN.set({...NN.get(),region:`setup`}),n.files.browseTo(e,t,r)}function rP(e){W().say.track(`action:setup.ctxFromRow`),W().nav.openContext(e)}function iP(){W().say.track(`action:setup.allSessions`),W().nav.open(`tokens`)}function aP(e){let t=W().world;return t.sessions.filter(n=>n.running&&!n.id.startsWith(`pending:`)&&t.sessionRepo(n)?.id===e).map(e=>({id:e.id,title:t.sessionRowTitle(e),open:()=>rP(e.id)}))}function oP(){let e=_h(),t=K(MN),n=K(NN);return(0,J.jsx)(DN,{repos:e.world.repos,initialRepoId:t??void 0,initialRegion:n.region,focus:n.focus,onRemedy:YN,onOpenFile:QN,onSeed:XN,onCapture:ZN,sessionDoorsFor:aP,onAllSessions:iP,onOpenInstructionFile:nP,onClose:$N})}function sP({repo:e}){let t=_h();return(0,J.jsx)(DN,{repos:t.world.repos,initialRepoId:e.id,initialRegion:`series`,onRemedy:YN,onOpenFile:QN,onSeed:XN,onCapture:ZN,sessionDoorsFor:aP,onAllSessions:iP,onOpenInstructionFile:nP,onClose:tP})}function cP(){let[e,t]=(0,H.useState)(null),[n,r]=(0,H.useState)(null);(0,H.useEffect)(()=>{let e=new AbortController;return U.setupPrefs(e.signal).then(n=>{e.signal.aborted||t(n.autoCompactDefault)}).catch(t=>{e.signal.aborted||r(String(t.message||t))}),()=>e.abort()},[]);async function i(n){let i=e;t(n);try{let e=await U.setSetupPrefs(n===`400k`?null:n);if(!e.ok){t(i),Dg(e.error||`the desktop did not store it`);return}t(e.autoCompactDefault??n),r(null)}catch(e){t(i),Dg(`not saved — ${String(e.message||e)}`)}}return(0,J.jsx)(tT,{id:`auto-compact-default`,label:`auto-compact window`,icon:yc,value:e??``,options:pa.map(e=>({value:e,label:e===`400k`?`${e} (default)`:e})),onChange:e=>void i(e),note:n?`Could not read this desktop's choice: ${n}`:`What Repo readings offers to write into a repo's .claude/settings.json, and the size under which a repo's window counts as fine. Nothing is written until you tap it there.`,more:(0,J.jsx)(`p`,{children:`A conversation compacts once its context passes this, so one long agent stops re-reading a whole 1M window on every step. Smaller is cheaper per step and compacts more often. Stored on the desktop, the same for every device.`})})}var lP={id:`setup`,sheets:[{id:`setup`,persisted:!1,render:()=>(0,H.createElement)(oP)},{id:`repohealth`,persisted:!1,render:()=>{let e=PN.get();return e?(0,H.createElement)(sP,{repo:e}):null}}],boot:()=>eP(),settings:[{group:`sessions`,order:30,render:()=>(0,H.createElement)(cP)}]};function uP({l:e,windowTok:t,tok:n}){let r=Zr(e);if(r.count<=0&&r.unmeasured<=0)return null;let i=Hr(r),a=Yte(r)??gte(r),o=qee(r),s=Bee(r),c=Va(r,n,t),l=Eee(r),u=(e,t)=>t.count>0&&(0,J.jsxs)(`div`,{className:`row ctx-row ctx-val`,children:[(0,J.jsx)(SE,{children:Sa(e,t.count)}),(0,J.jsx)(`span`,{className:`row-meta`,children:_ee(t).map(e=>(0,J.jsx)(Q,{children:e},e))})]},e);return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`ctx-summary`,children:`What compacting saved`}),i&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:i}),u(`manual`,e.manual),u(`auto`,e.auto),a&&(0,J.jsxs)(`div`,{className:`empty ctx-note`,children:[a,o?` ${o}`:``]}),c&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:c}),s&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:s}),(r.savedTok>0||r.rebuildTok>0)&&(0,J.jsxs)(`details`,{className:`hint-more ctx-method`,children:[(0,J.jsx)(`summary`,{children:`how these two figures were arrived at`}),(0,J.jsx)(`p`,{children:Pte()})]}),l&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:l})]})}function dP({cost:e,onFresh:t,onCompact:n,noDoors:r}){return(0,J.jsxs)(`div`,{className:`ctx-cost ctx-cost-${e.level}`,children:[(0,J.jsxs)(`div`,{className:`ctx-cost-head`,children:[(0,J.jsx)(Al,{size:14}),(0,J.jsx)(`span`,{children:e.chip?`${e.chip} a fresh session`:`about a fresh session`})]}),(0,J.jsx)(`div`,{className:`ctx-cost-note`,children:e.note}),e.advice&&(0,J.jsx)(`div`,{className:`ctx-cost-note`,children:e.advice}),e.advice&&!r&&t&&(0,J.jsx)(`div`,{className:`sheet-actions`,children:(0,J.jsxs)(Y,{onClick:t,children:[(0,J.jsx)(os,{size:14}),` new session in this repo`]})}),e.advice&&!r&&!t&&(0,J.jsx)(CE,{cants:[{label:`a new session from here`,reason:`this session's directory is not one of this desktop's repos, so there is nowhere to start one`}]}),(0,J.jsxs)(`details`,{className:`hint-more ctx-method ctx-cost-more`,children:[(0,J.jsx)(`summary`,{children:`why the next turn costs this`}),(0,J.jsxs)(`p`,{children:[`Every turn re-sends the whole conversation, so the next one is priced by what is already here, not by what you are about to ask.`,e.advice&&!r&&n&&Ma(!0)?` ${Ma(!0)}`:``]})]})]})}var fP=27e5;function pP(e,t,n,r,i){let a=[...new Set([r,...e,i])].filter(e=>e>=r&&e<=i).sort((e,t)=>e-t),o=i-r,s=()=>({t0:r,t1:i,px:e=>t+(e-r)/(o||1)*n,tx:e=>r+(e-t)/(n||1)*(o||1),breaks:[]});if(o<=0||a.length<2)return s();let c=a.slice(0,-1).map((e,t)=>({from:e,to:a[t+1]})).filter(e=>e.to-e.from>fP).sort((e,t)=>t.to-t.from-(e.to-e.from)).slice(0,8).sort((e,t)=>e.from-t.from);if(!c.length)return s();let l=Math.min(18,n/(c.length*3||1)),u=o-c.reduce((e,t)=>e+(t.to-t.from),0),d=n-c.length*l;if(u<=0||d<=0)return s();let f=[],p=t,m=r;for(let e of c){if(e.from>m){let t=(e.from-m)/u*d;f.push({t0:m,t1:e.from,x0:p,w:t,dead:!1}),p+=t}f.push({t0:e.from,t1:e.to,x0:p,w:l,dead:!0}),p+=l,m=e.to}return i>m&&f.push({t0:m,t1:i,x0:p,w:t+n-p,dead:!1}),{t0:r,t1:i,px:e=>{if(e<=r)return t;if(e>=i)return t+n;for(let t of f)if(e<=t.t1)return t.x0+(t.t1>t.t0?(e-t.t0)/(t.t1-t.t0)*t.w:0);return t+n},tx:e=>{if(e<=t)return r;if(e>=t+n)return i;for(let t of f)if(e<=t.x0+t.w)return t.t0+(t.w>0?(e-t.x0)/t.w*(t.t1-t.t0):0);return i},breaks:f.filter(e=>e.dead).map(e=>({x:e.x0,w:e.w,from:e.t0,to:e.t1}))}}function mP(e){return(e??[]).flatMap(e=>(e.ctx??[]).map(([e])=>e))}function hP(e){let{width:t,height:n,pad:r,samples:i,refs:a,events:o,windowTok:s}=e,c=mP(e.agents),{w:l,h:u}=hD(t,n,r),d=[...i.map(e=>e.t),...o.map(e=>e.t),...o.flatMap(e=>e.resetAt==null?[]:[e.resetAt]),...c],f=d.length?Math.min(...d):0,p=d.length?Math.max(...d):1;p<=f&&(f-=3e4,p+=3e4);let m=e.value??yP,h=i.reduce((e,t)=>m(t)>e?m(t):e,0),g=e.value?h:Math.max(h,...(e.agents??[]).map(e=>e.peakTok??0)),{top:_,ticks:v}=s?mD(s,Math.max(g,...a)):pD(Math.max(g,...a,1),e.yWant),y=pP([...i.map(e=>e.t),...c].sort((e,t)=>e-t),r.left,l,f,p);return{x:r.left,y:r.top,w:l,h:u,t0:f,t1:p,yMax:_,yTicks:v,windowTok:s,px:y.px,tx:y.tx,breaks:y.breaks,py:gD(r.top,u,_)}}function gP(e){let t=Math.round(e/6e4);if(t<90)return`${t} min`;let n=t/60;return n<36?`${Math.round(n*10)/10} h`:`${Math.round(n/24*10)/10} d`}function _P(e,t){let n=mi(t,e.windowTok);return n==null?OD(t):`${Math.round(n)}%`}function vP(e,t){let n=mi(e,t);return n==null?OD(e):`${Math.round(n)}% · ${OD(e)}`}var yP=e=>e.tok,bP=e=>e.used??0;function xP(e){return e.some(e=>e.used!=null&&e.used>0)}function SP(e,t,n,r){if(!xP(e))return null;let i=e.reduce((e,t)=>t.used!=null&&t.used>e?t.used:e,0),a=t!=null&&t>=i?t:null,o=a!=null&&n!=null&&n>0?n:null,s=r?.total!=null&&r.total>0?r.total:null;return{end:i,total:a,agents:o,top:Math.max(i,a??0),costUsd:s,agentCostUsd:s!=null&&r?.agents!=null&&r.agents>0?r.agents:null,unpricedTok:r?.unpricedTok!=null&&r.unpricedTok>0?r.unpricedTok:null}}function CP(e,t){let n=e.total==null?e.end:e.total,r=e.costUsd==null?`${OD(n)} spent`:`${Ii(e.costUsd)} at list prices · ${OD(n)} spent`,i=[t?`${r} (at least)`:`${r} so far`];return e.agents!=null&&i.push(e.agentCostUsd==null?`${OD(e.agents)} of it in subagents`:`${Ii(e.agentCostUsd)} / ${OD(e.agents)} of it in subagents`),i.join(` · `)}function wP(e,t,n=!1){let r=[];e.costUsd!=null&&e.unpricedTok!=null&&r.push(`${OD(e.unpricedTok)} of these tokens ran on a model with no published rate and are in neither dollar figure.`),t&&r.push(`This log is longer than the host reads in one go, so the curve starts part-way up.`);let i=[`Every request's input, cache reads and cache writes plus what it wrote back, added up as the conversation went. It only rises — a compaction resets the window, never the bill.`];return e.costUsd!=null&&i.push(`The ${Ii(e.costUsd)} is what the API would have charged for those tokens at published rates, priced per request on the model that ran it — not what anybody paid, and nothing to do with what a subscription costs.`),e.agents!=null&&i.push(n?`The grey band on top is the ${OD(e.agents)} its subagents spent, placed at the times their own logs record, so its top edge ends on the dashed whole-session total.`:`The dashed line is the session's whole total; the gap between it and the curve is the ${OD(e.agents)} its subagents spent, which this host did not send as a series over time.`),i.push(`A floor: an agent log this desktop never saw is one nothing here can add.`),{lead:r.length?r.join(` `):null,more:i.join(` `)}}function TP(e,t){if(!e)return null;let n=t&&Xi(t)>0?t:null,r=Un(Un(vi(),e),n??{});return Xi(r)<=0?null:{all:r,main:e,agents:n}}function EP(e){let t=Qn(e.all);return t==null?null:`What those tokens were · ${Math.round(t)}% of everything sent in came out of the cache`}function DP(e,t){let n=[];return e.agents&&n.push(`Subagents are IN this bar: ${OD(Xi(e.agents))} of it.`),t&&n.push(`A floor: this log is longer than the host reads in one go, so every kind here starts part-way up.`),{lead:n.length?n.join(` `):null,more:[`The same four kinds, counted the same way, as the all-sessions token screen — this conversation is a slice of that total, not a second opinion about it.`,`Turns here are REQUESTS, not prompts — a turn that ran thirteen tools sent fourteen of them, which is the denominator the all-sessions screen uses too.`].join(` `)}}function OP(e,t,n){if(!n?.length||!t.length)return{area:``,top:``};let r=vD,i=e=>{if(e<t[0].t)return 0;let n=t[t.length-1];if(e>=n.t)return bP(n);let r=0;for(;r<t.length-1&&t[r+1].t<=e;)r++;let i=t[r],a=t[r+1];return a.t===i.t?bP(a):bP(i)+(bP(a)-bP(i))*(e-i.t)/(a.t-i.t)},a=[...new Set([...t.map(e=>e.t).filter(e=>e>n[0][0]),...n.map(([e])=>e)])].sort((e,t)=>e-t),o=[],s=[],c=0,l=0;for(let t of a){let a=i(t),u=r(e.px(t)),d=l;for(;c<n.length&&n[c][0]<=t;)l=n[c++][1];l!==d&&o.push(`${u},${r(e.py(a+d))}`),o.push(`${u},${r(e.py(a+l))}`),s.unshift(`${u},${r(e.py(a))}`)}return o.length<2?{area:``,top:``}:{area:xD(o,s),top:`M${o.join(`L`)}`}}function kP(e,t,n=yP){return yD(t,t=>e.px(t.t),t=>e.py(n(t)))}function AP(e,t,n=yP){let r=kP(e,t,n);return r?bD(r,vD(e.px(t[0].t)),vD(e.px(t[t.length-1].t)),vD(e.py(0))):``}function jP(e,t,n){if(!t.length)return n.map(e=>({...e,d:``,total:0}));let r=vD,i=t.length>1&&n.length>0&&n.every(e=>e.perRequest),a=e=>n.reduce((t,n)=>t+n.at(e),0);return n.map((o,s)=>{let c=[],l=[],u=0;t.forEach((d,f)=>{let p=0;for(let e=0;e<s;e++)p+=n[e].at(d);let m=o.at(d);u+=m;let h=r(e.px(d.t));c.push(`${h},${r(e.py(p+m))}`),l.unshift(`${h},${r(e.py(p))}`);let g=t[f+1];if(i&&g){let t=a(d),n=t>0?a(g)/t:0,i=r(e.px(g.t));c.push(`${i},${r(e.py((p+m)*n))}`),l.unshift(`${i},${r(e.py(p*n))}`)}});let d=t.length>1?xD(c,l):``;return{...o,d,total:u}})}function MP(e,t,n){return e.some(e=>e[t])?qn.filter(e=>!n||n(e.id)).map(e=>({key:e.id,name:e.name,slot:e.slot,at:n=>{let r=n[t];return r?Dte(r)[e.id]:0},perRequest:t===`kinds`})):null}function NP(e,t,n){return _D(t,e.tx(n),e=>e.t)}function PP(e,t){if(!e?.length)return null;let n=RD(e),r=e.map((e,t)=>({id:e,idx:t,slot:n.get(e)})).filter(t=>t.slot!=null&&e.indexOf(t.id)===t.idx).sort((e,t)=>ID(e.slot,t.slot)),i=new Map(r.map(e=>[e.idx,e.slot])),a=e.length-r.length;return{named:r,rest:a>0||t?{slot:4,name:a>0?`${a} more`:`unattributed`}:null,slotOf:e=>(e==null?void 0:i.get(e))??4}}function FP(e){return(er(e)??e).replace(/^claude-/,``)}var IP=3,LP=2;function RP(e,t,n){let r=t.reduce((e,t)=>!e||t.tok>e.tok?t:e,null),i=[],a=[];for(let o of[...t].sort((e,t)=>e.at-t.at||e.endAt-t.endAt)){let t=Math.max(e.x,Math.min(e.x+e.w-IP,e.px(o.at))),s=o.running?e.x+e.w:Math.min(e.x+e.w,Math.max(t+IP,e.px(Math.max(o.at,o.endAt)))),c=i.findIndex(e=>e+LP<=t);c<0?(c=i.length,i.push(s)):i[c]=s,a.push({run:o,x:t,w:s-t,lane:c,slot:n?n.slotOf(o.model):0,dearest:o===r,open:!!o.running})}return{bars:a,lanes:i.length}}function zP(e){let t=e<=8?13:Math.max(5,Math.floor(104/e));return{laneH:t,barH:Math.max(3,t-3),plotH:Math.max(1,e)*t}}function BP(e,t,n,r,i){if(!e.length)return null;let a=Math.floor((i-n)/t),o=e=>r<e.x?e.x-r:r>e.x+e.w?r-(e.x+e.w):0,s=e.some(e=>e.lane===a)?e.filter(e=>e.lane===a):e;return s.reduce((e,t)=>o(t)<o(e)?t:e,s[0])}function VP(e){let t=e.flatMap(e=>[[e.at,1],[e.running?1/0:Math.max(e.at,e.endAt),-1]]).sort((e,t)=>e[0]-t[0]||e[1]-t[1]),n=0,r=0;for(let[,e]of t)n+=e,n>r&&(r=n);return r}function HP(e,t,n){let r=t&&e.model!=null?t[e.model]:null;return[e.type??`agent`,r?FP(r):null,e.running?`started ${AD(e.at,n)} · still running, last wrote ${AD(e.endAt,n)}`:`${AD(e.at,n)}–${AD(e.endAt,n)} (${gP(Math.max(0,e.endAt-e.at))})`,`${OD(e.tok)} spent`,e.peakTok?`window peaked at ${OD(e.peakTok)}`:null,e.costUsd==null?null:Ii(e.costUsd)].filter(Boolean).join(` · `)}function UP(e,t){if(!e.length)return`No subagents — every turn here ran in this conversation.`;let n=e.filter(e=>!e.running&&e.endAt>e.at),r=e.reduce((e,t)=>t.tok>e.tok?t:e,e[0]),i=[`${e.length} subagent${e.length>1?`s`:``}`],a=e.filter(e=>e.running).length;a&&i.push(`${a===e.length&&a>1?`all`:a} still running (fading out at the right)`);let o=VP(e);if(o>1&&i.push(`up to ${o} at once`),n.length){let e=n.map(e=>e.endAt-e.at).sort((e,t)=>e-t)[Math.floor(n.length/2)];i.push(`median ${gP(e)} each`)}let s=t&&r.model!=null?t[r.model]:null;return i.push(`dearest ${OD(r.tok)}${s?` on ${FP(s)}`:``}${e.length>1?` (outlined)`:``}`),i.join(` · `)}function WP(e,t){if(t==null)return null;let n=t-e.reduce((e,t)=>e+t.tok,0);return n>0?`${OD(n)} of the subagents' tokens are in logs with no timestamp: in every total here, and on no chart.`:null}function GP(e,t){let n=vD;return t.filter(e=>(e.ctx?.length??0)>0).map(t=>({id:t.id,d:t.ctx.length===1?`M${n(e.px(t.ctx[0][0])-1)},${n(e.py(t.ctx[0][1]))}h2`:`M${t.ctx.map(([t,r])=>`${n(e.px(t))},${n(e.py(r))}`).join(`L`)}`}))}function KP(e){let t=Math.max(0,...(e??[]).map(e=>e.peakTok??0));return t>0?t:null}function qP(e,t,n){let r=e.pts;if(!r.length)return null;let i=e.autoCompactTok??null,a=e.autoCompactSetTok?Math.max(e.autoCompactSetTok,e.peak,...r):e.windowTok?mD(e.windowTok,Math.max(e.peak,i??0)).top:Math.max(e.peak,i??0,...r,1),o=e=>r.length===1?t:e/(r.length-1)*t,s=e=>n-Math.max(0,Math.min(e,a))/a*n,c=yD(r,(e,t)=>o(t),e=>s(e));return{line:c,area:bD(c,`0`,vD(o(r.length-1)),n),endX:o(r.length-1),endY:s(r[r.length-1]),ticks:e.marks.map(e=>({x:e.at*t,kind:e.kind})),refY:i==null?null:s(i),...JP(e.agentEnv,r.length,o,s,n)}}function JP(e,t,n,r,i){if(!e||e.length!==t||!e.some(e=>e>0))return{agentArea:null,agentPeak:null};let a=e.map((e,t)=>`L${n(t).toFixed(1)},${r(e).toFixed(1)}`).join(``);return{agentArea:`M${n(0).toFixed(1)},${i}${a}L${n(t-1).toFixed(1)},${i}Z`,agentPeak:Math.max(...e)}}function YP(e,t,n){let r=e.usedPts;if(!r||!r.length)return null;let i=r[r.length-1];if(!(i>0))return null;let a=e.usageTok!=null&&e.usageTok>=i?e.usageTok:null,o=a!=null&&e.agentTok!=null&&e.agentTok>0?a:null,s=e.agentUsedPts,c=o!=null&&s&&s.length===r.length&&s.every(e=>Number.isFinite(e)&&e>=0)?r.map((e,t)=>e+s[t]):null,l=c&&c[c.length-1]<=o*1.001?c:null,u=Math.max(i,o??0,1),d=e=>r.length===1?t:e/(r.length-1)*t,f=e=>n-.5-Math.max(0,Math.min(e,u))/u*(n-1),p=yD(r,(e,t)=>d(t),e=>f(e));return{line:p,area:bD(p,`0`,vD(d(r.length-1)),n),endX:d(r.length-1),endY:f(i),totalY:o!=null&&!l?f(o):null,agentBand:l?XP(r,l,d,f):null,top:u,end:i}}function XP(e,t,n,r){let i=yD(t,(e,t)=>n(t),e=>r(e));return{area:`${i}${e.map((e,t)=>[n(t),r(e)]).reverse().map(([e,t])=>`L${vD(e)},${vD(t)}`).join(``)}Z`,top:i}}function ZP(e,t){let n=e.agentTok!=null&&e.agentTok>0?e.agentTok:null;return[`spent: ${OD(t.end)} in this conversation so far`,n==null?null:`${OD(n)} more in its subagents — ${t.agentBand?`the grey band stacked on top`:`the dashed line`}`,e.costUsd==null?null:Dt(e.costUsd,e.agentCostUsd??null,e.unpricedTok??null),`this curve tops out at ${OD(t.top)} and is scaled to this session, not to the others`].filter(Boolean).join(` · `)}function QP(e){return e.kind===`compact`?{kind:`compact`,text:(e.trigger===`auto`?`Auto-compacted`:e.trigger===`manual`?`Compacted (/compact)`:`Compacted`)+(e.preTok&&e.postTok?` · ${OD(e.preTok)} → ${OD(e.postTok)}`:``)}:e.kind===`rebuild`?{kind:`rebuild`,text:`Cache expired — re-wrote ${e.wroteTok?OD(e.wroteTok):`the window`}${e.gapMs?` after ${gP(e.gapMs)} quiet`:``}`}:{kind:`limit`,text:(e.weekly?`Weekly usage limit`:`Usage limit`)+(e.resetAt==null?``:` · back at ${AD(e.resetAt,0)}`)}}function $P(e,t,n,r){if(t==null||!(t>0))return`This model’s context window is not known here, so the axis is in tokens and is NOT the shared 0–100% scale — this graph cannot be compared with another session’s.`;let i=OD(t);switch(e){case`measured`:return`100% is ${i} — the window ${n??`this model`} has been SEEN to hold, so it is the same scale as every other session’s graph.`;case`screen`:return`100% is the ${i} window the CLI printed on screen.`;case`source`:return`100% is ${i}, the window ${r??`this backend`} states${n?` for ${n}`:``} in this session.`;case`config`:return`100% is ${i}, as ${r??`this backend`}’s configuration states it${n?` for ${n}`:``} — a setting this app read, not something anybody watched happen. A model running locally may be holding less than that, and nothing here would show it.`;case`model`:return`100% is ${i}, assumed from the model id${n?` (${n})`:``} — nothing here has held more than that yet, so if it is really a larger window this axis will correct itself the first time a conversation goes past.`;default:return`This model’s context window is not known here, so the axis is in tokens and is NOT the shared 0–100% scale — this graph cannot be compared with another session’s.`}}function eF(e,t,n,r){if(!e.length)return null;let i=e[e.length-1],a=e.reduce((e,t)=>t.tok>e?t.tok:e,0),o=t.filter(e=>e.kind===`compact`).length,s=t.filter(e=>e.kind===`limit`).length,c=mi(i.tok,n),l=mi(a,n),u=[c==null?`${OD(i.tok)} now`:`${Math.round(c)}% of ${OD(n)}`,l==null?`peak ${OD(a)}`:`peak ${Math.round(l)}%`],d=KP(r);return d!=null&&u.push(`an agent held ${OD(d)}`),o&&u.push(`${o} compaction${o>1?`s`:``}`),s&&u.push(`${s} usage limit${s>1?`s`:``}`),u.join(` · `)}var tF={env:`the daemon's CLAUDE_CODE_AUTO_COMPACT_WINDOW`,local:`.claude/settings.local.json`,project:`.claude/settings.json`,user:`~/.claude/settings.json`,unset:``};function nF(e){return`auto-compact set ${ni(e)}`}function rF(e){if(e.source===`unset`)return`No autoCompactWindow is set for this repo, so the CLI compacts near the model's own window — no setting line is drawn.`;let t=bn(tF,e.source,`a place this app version cannot name`);return e.tokens==null?/^auto$/i.test(e.raw?.trim()??``)?`autoCompactWindow is "auto" in ${t}, so the CLI compacts near the model's own window — no setting line is drawn.`:`autoCompactWindow in ${t} reads ${JSON.stringify(e.raw??``)}, which is not a size — no setting line is drawn.`:`The dotted line is autoCompactWindow as ${t} sets it now (${ni(e.tokens)}) — the setting today, not necessarily what this conversation ran under.`}var iF=`var(--ctx-series)`,aF=`var(--ctx-compact)`,oF=`var(--ctx-limit)`,sF={top:10,right:10,bottom:20,left:40},cF={top:12,right:10,bottom:20,left:40};function lF({spark:e,width:t=76,height:n=20,value:r=!1}){let i=uF((0,H.useId)()),a=qP(e,t,n);if(!a)return null;let o=e.pts[e.pts.length-1],s=mi(o,e.windowTok),c=e.marks.filter(e=>e.kind===`compact`).length,l=e.marks.filter(e=>e.kind===`limit`).length,u=yt(e.costUsd)??sn(e.usageTok),d=[s==null?`context: ${OD(o)} now, peak ${OD(e.peak)} (window unknown — this row's scale is its own)`:`context: ${Math.round(s)}% of ${OD(e.windowTok)}, peak ${OD(e.peak)}`,e.usageTok!=null&&e.usageTok>0?tne(e.usageTok,e.agentTok??null):null,e.costUsd==null?null:Dt(e.costUsd,e.agentCostUsd??null,e.unpricedTok??null),a.agentPeak==null?null:`agents peaked at ${OD(a.agentPeak)}`,e.autoCompactTok==null?null:`compacts at ${OD(e.autoCompactTok)}`,e.autoCompactSetTok?`curve tops out at the auto-compact setting, ${OD(e.autoCompactSetTok)}`:null,c?`${c} compaction${c>1?`s`:``}`:null,l?`${l} usage limit${l>1?`s`:``}`:null].filter(Boolean).join(` · `),f=(0,J.jsxs)(`svg`,{className:`ctx-spark`,width:t,height:n,viewBox:`0 0 ${t} ${n}`,role:`img`,"aria-label":d,children:[(0,J.jsx)(`title`,{children:d}),(0,J.jsx)(`defs`,{children:(0,J.jsx)(dF,{id:i})}),(0,J.jsx)(`line`,{x1:0,x2:t,y1:n-.5,y2:n-.5,stroke:`currentColor`,strokeOpacity:.16,strokeWidth:1}),a.refY!=null&&(0,J.jsx)(`line`,{x1:0,x2:t,y1:a.refY,y2:a.refY,stroke:`currentColor`,strokeOpacity:.35,strokeWidth:1,strokeDasharray:`2 3`}),a.agentArea&&(0,J.jsx)(`path`,{d:a.agentArea,fill:`currentColor`,fillOpacity:.13}),(0,J.jsx)(`path`,{d:a.area,fill:`url(#${i})`}),(0,J.jsx)(`path`,{d:a.line,fill:`none`,stroke:iF,strokeWidth:1.5,strokeLinejoin:`round`,strokeLinecap:`round`}),a.ticks.map((e,t)=>(0,J.jsx)(`line`,{x1:e.x,x2:e.x,y1:1,y2:n-1.5,strokeLinecap:`round`,stroke:e.kind===`compact`?aF:oF,strokeWidth:1.25,strokeOpacity:.7},t)),(0,J.jsx)(`circle`,{cx:a.endX,cy:a.endY,r:2.6,fill:iF,stroke:`var(--panel)`,strokeWidth:2})]});return r?(0,J.jsxs)(`span`,{className:`ctx-spark-pair`,title:d,children:[f,(0,J.jsx)(`span`,{className:`ctx-spark-val`,children:kD(o)}),u&&!YP(e,t,n)&&(0,J.jsxs)(`span`,{className:`ctx-spark-use`,children:[(0,J.jsx)(Wo,{size:10}),` `,u]})]}):f}function uF(e){return`w${e.replace(/[^a-zA-Z0-9_-]/g,``)}`}function dF({id:e}){return(0,J.jsxs)(`linearGradient`,{id:e,x1:`0`,y1:`0`,x2:`0`,y2:`1`,children:[(0,J.jsx)(`stop`,{offset:`0%`,stopColor:iF,stopOpacity:.3}),(0,J.jsx)(`stop`,{offset:`100%`,stopColor:iF,stopOpacity:.02})]})}function fF({spark:e,width:t=76,height:n=14,warn:r=null}){let i=uF((0,H.useId)()),a=YP(e,t,n);if(!a)return null;let o=yt(e.costUsd)??sn(e.usageTok)??kD(a.end),s=r?`${r.text}\n${ZP(e,a)}`:ZP(e,a);return(0,J.jsxs)(`span`,{className:`ctx-spark-pair`,title:s,children:[(0,J.jsxs)(`svg`,{className:`ctx-spark`,width:t,height:n,viewBox:`0 0 ${t} ${n}`,role:`img`,"aria-label":s,children:[(0,J.jsx)(`title`,{children:s}),(0,J.jsx)(`defs`,{children:(0,J.jsx)(dF,{id:i})}),(0,J.jsx)(`line`,{x1:0,x2:t,y1:n-.5,y2:n-.5,stroke:`currentColor`,strokeOpacity:.16,strokeWidth:1}),a.totalY!=null&&(0,J.jsx)(`line`,{x1:0,x2:t,y1:a.totalY,y2:a.totalY,stroke:`currentColor`,strokeOpacity:.45,strokeWidth:1,strokeDasharray:`3 3`}),(0,J.jsx)(`path`,{d:a.area,fill:`url(#${i})`}),a.agentBand&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`path`,{d:a.agentBand.area,fill:`var(--fg)`,fillOpacity:.16}),(0,J.jsx)(`path`,{d:a.agentBand.top,fill:`none`,stroke:`var(--fg)`,strokeOpacity:.5,strokeWidth:1,strokeLinejoin:`round`,strokeLinecap:`round`})]}),(0,J.jsx)(`path`,{d:a.line,fill:`none`,stroke:iF,strokeWidth:1.5,strokeLinejoin:`round`,strokeLinecap:`round`}),(0,J.jsx)(`circle`,{cx:a.endX,cy:a.endY,r:2.2,fill:iF,stroke:`var(--panel)`,strokeWidth:1.5})]}),(0,J.jsxs)(`span`,{className:r?`ctx-spark-use spend-warn-${r.level}`:`ctx-spark-use`,children:[r?(0,J.jsx)(Js,{size:10,"aria-label":r.level===`high`?`past the red spend mark`:`past the orange spend mark`}):(0,J.jsx)(Wo,{size:10}),` `,o]})]})}function pF({samples:e,events:t,windowTok:n,autoCompactTok:r,autoCompactSetTok:i=null,width:a,height:o=200,onHover:s,bands:c,agents:l}){let u=(0,H.useRef)(null),[d,f]=(0,H.useState)(null),p=(0,H.useCallback)(e=>{f(e),s?.(e)},[s]),m=hP({width:a,height:o,pad:sF,samples:e,events:t,refs:[r,i].filter(e=>e!=null),windowTok:n,agents:l}),h=m.t1-m.t0,g=(0,H.useCallback)(t=>{let n=u.current?.getBoundingClientRect();if(!n)return;let r=(t.clientX-n.left)/n.width*a;p(NP(m,e,r))},[m,e,a,p]),_=m.yTicks,v=[0,.5,1].map(e=>m.tx(m.x+e*m.w));return(0,J.jsxs)(`svg`,{ref:u,className:`ctx-chart`,width:a,height:o,viewBox:`0 0 ${a} ${o}`,onPointerDown:g,onPointerMove:g,onPointerLeave:()=>p(null),onPointerCancel:()=>p(null),role:`img`,"aria-label":`context window over time`,children:[_.map(e=>(0,J.jsx)(`line`,{x1:m.x,x2:m.x+m.w,y1:m.py(e),y2:m.py(e),stroke:`var(--line)`,strokeWidth:1},`g${e}`)),c?(0,J.jsx)(hF,{p:m,samples:e,series:c}):(0,J.jsx)(`path`,{d:AP(m,e),fill:iF,fillOpacity:.14}),l&&GP(m,l).map(e=>(0,J.jsx)(`path`,{d:e.d,fill:`none`,stroke:`var(--fg)`,strokeOpacity:.45,strokeWidth:1.25,strokeLinejoin:`round`,strokeLinecap:`round`},`a${e.id}`)),(0,J.jsx)(`path`,{d:kP(m,e),fill:`none`,stroke:iF,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`}),m.breaks.map((e,t)=>(0,J.jsxs)(`g`,{children:[(0,J.jsx)(`title`,{children:`${gP(e.to-e.from)} with no activity — the axis is compressed here`}),(0,J.jsx)(`rect`,{x:e.x,y:m.y,width:e.w,height:m.h,fill:`var(--panel)`}),[0,1].map(t=>(0,J.jsx)(`line`,{x1:e.x+1+t*5,y1:m.y+m.h,x2:e.x+e.w-5+t*5,y2:m.y,stroke:`var(--line)`,strokeWidth:1},t))]},`k${t}`)),t.filter(e=>e.kind===`limit`&&e.resetAt!=null).map((e,t)=>(0,J.jsx)(`rect`,{x:m.px(e.t),y:m.y,width:Math.max(1,m.px(e.resetAt)-m.px(e.t)),height:m.h,fill:oF,fillOpacity:.12},`b${t}`)),r!=null&&(0,J.jsx)(bF,{p:m,v:r,label:`compacts ~${_P(m,r)}`,below:m.py(r)-m.y<13}),i!=null&&(0,J.jsx)(bF,{p:m,v:i,label:nF(i),below:m.py(i)-m.y<13,start:!0,dash:`1.5 3`}),t.filter(e=>e.kind!==`rebuild`).map((e,t)=>{let n=m.px(e.t),r=Math.min(m.x+m.w-5,Math.max(m.x+5,n)),i=e.kind===`compact`?aF:oF;return(0,J.jsxs)(`g`,{children:[(0,J.jsx)(`title`,{children:QP(e).text}),(0,J.jsx)(`line`,{x1:n,x2:n,y1:m.y,y2:m.y+m.h,stroke:i,strokeWidth:1.5,strokeOpacity:.85}),e.kind===`compact`?(0,J.jsx)(`path`,{d:`M${r-4},${m.y}L${r+4},${m.y}L${r},${m.y+6}Z`,fill:i,stroke:`var(--panel)`,strokeWidth:1}):(0,J.jsx)(`rect`,{x:r-3.5,y:m.y,width:7,height:7,fill:i,stroke:`var(--panel)`,strokeWidth:1})]},`e${t}`)}),_.map(e=>(0,J.jsx)(`text`,{className:`ctx-tick`,x:m.x-6,y:m.py(e)+3.5,textAnchor:`end`,children:_P(m,e)},`t${e}`)),v.map((e,t)=>(0,J.jsx)(`text`,{className:`ctx-tick`,x:m.px(e),y:o-6,textAnchor:t===0?`start`:t===v.length-1?`end`:`middle`,children:AD(e,h)},`x${t}`)),d&&(0,J.jsxs)(`g`,{children:[(0,J.jsx)(`line`,{x1:m.px(d.t),x2:m.px(d.t),y1:m.y,y2:m.y+m.h,stroke:`var(--fg)`,strokeOpacity:.35,strokeWidth:1}),(0,J.jsx)(`circle`,{cx:m.px(d.t),cy:m.py(d.tok),r:4.5,fill:`var(--ctx-series)`,stroke:`var(--panel)`,strokeWidth:2})]})]})}function mF({samples:e,events:t,facts:n,width:r,height:i=96,bands:a,agents:o,agentCum:s}){let c=hP({width:r,height:i,pad:cF,samples:e,events:t,windowTok:null,agents:o,value:bP,refs:n.total==null?[]:[n.total],yWant:3}),l=c.t1-c.t0,u=[0,.5,1].map(e=>c.tx(c.x+e*c.w)),d=n.agents==null?{area:``,top:``}:OP(c,e,s);return(0,J.jsxs)(`svg`,{className:`ctx-chart`,width:r,height:i,viewBox:`0 0 ${r} ${i}`,role:`img`,"aria-label":`tokens spent over time`,children:[c.yTicks.map(e=>(0,J.jsx)(`line`,{x1:c.x,x2:c.x+c.w,y1:c.py(e),y2:c.py(e),stroke:`var(--line)`,strokeWidth:1},`g${e}`)),a?(0,J.jsx)(hF,{p:c,samples:e,series:a}):(0,J.jsx)(`path`,{d:AP(c,e,bP),fill:iF,fillOpacity:.14}),d.area&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`path`,{d:d.area,fill:`var(--fg)`,fillOpacity:.16}),(0,J.jsx)(`path`,{d:d.top,fill:`none`,stroke:`var(--fg)`,strokeOpacity:.5,strokeWidth:1.25,strokeLinejoin:`round`})]}),(0,J.jsx)(`path`,{d:kP(c,e,bP),fill:`none`,stroke:iF,strokeWidth:2,strokeLinejoin:`round`,strokeLinecap:`round`}),c.breaks.map((e,t)=>(0,J.jsxs)(`g`,{children:[(0,J.jsx)(`title`,{children:`${gP(e.to-e.from)} with no activity — the axis is compressed here`}),(0,J.jsx)(`rect`,{x:e.x,y:c.y,width:e.w,height:c.h,fill:`var(--panel)`}),[0,1].map(t=>(0,J.jsx)(`line`,{x1:e.x+1+t*5,y1:c.y+c.h,x2:e.x+e.w-5+t*5,y2:c.y,stroke:`var(--line)`,strokeWidth:1},t))]},`k${t}`)),t.filter(e=>e.kind!==`rebuild`).map((e,t)=>(0,J.jsx)(`line`,{x1:c.px(e.t),x2:c.px(e.t),y1:c.y,y2:c.y+c.h,stroke:e.kind===`compact`?aF:oF,strokeWidth:1.5,strokeOpacity:.55},`e${t}`)),n.total!=null&&n.agents!=null&&(0,J.jsx)(bF,{p:c,v:n.total,label:`${OD(n.total)} with subagents`,below:c.py(n.total)-c.y<13}),c.yTicks.map(e=>(0,J.jsx)(`text`,{className:`ctx-tick`,x:c.x-6,y:c.py(e)+3.5,textAnchor:`end`,children:OD(e)},`t${e}`)),u.map((e,t)=>(0,J.jsx)(`text`,{className:`ctx-tick`,x:c.px(e),y:i-6,textAnchor:t===0?`start`:t===u.length-1?`end`:`middle`,children:AD(e,l)},`x${t}`))]})}function hF({p:e,samples:t,series:n}){let r=jP(e,t,n);return(0,J.jsx)(`g`,{children:r.map(e=>e.d&&(0,J.jsx)(`path`,{d:e.d,fill:UD[e.slot]??WD[4],fillOpacity:.85,stroke:`var(--panel)`,strokeWidth:.75,strokeOpacity:.6,children:(0,J.jsx)(`title`,{children:`${e.name}: ${OD(e.total)}`})},e.key))})}function gF({p:e,samples:t,series:n,fmt:r=OD}){let i=jP(e,t,n),a=i.reduce((e,t)=>e+t.total,0);return(0,J.jsx)(`div`,{className:`ctx-legend ctx-legend-stack`,children:i.map(e=>(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`10`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`rect`,{x:`0`,y:`1`,width:`10`,height:`8`,rx:`2`,fill:UD[e.slot]??WD[4]})}),e.name,` `,(0,J.jsx)(`b`,{children:r(e.total)}),a>0&&(0,J.jsxs)(`span`,{className:`ctx-legend-pct`,children:[` `,oi(e.total/a)]})]},e.key))})}function _F({samples:e,events:t,agents:n,slots:r,width:i,onPick:a,picked:o}){let s=(0,H.useRef)(null),c=uF((0,H.useId)()),l=hP({width:i,height:100,pad:{...cF,top:6},samples:e,events:t,windowTok:null,refs:[],agents:n}),{bars:u,lanes:d}=RP(l,n,r),{laneH:f,barH:p,plotH:m}=zP(d),h=6+m+cF.bottom,g=l,_=g.t1-g.t0,v=[0,.5,1].map(e=>g.tx(g.x+e*g.w)),y=(e,t)=>{let n=s.current?.getBoundingClientRect();if(!n||!a)return;let r=(e.clientX-n.left)/n.width*i,c=(e.clientY-n.top)/n.height*h,l=BP(u,f,6,r,c);a(t&&l&&o&&l.run.id===o.id?null:l?.run??null)};return(0,J.jsxs)(`svg`,{ref:s,className:`ctx-chart`,width:i,height:h,viewBox:`0 0 ${i} ${h}`,onPointerDown:e=>y(e,!0),onPointerMove:e=>{e.buttons&&y(e,!1)},role:`img`,"aria-label":`subagents over time, one bar each`,children:[g.breaks.map((e,t)=>(0,J.jsxs)(`g`,{children:[(0,J.jsx)(`rect`,{x:e.x,y:6,width:e.w,height:m,fill:`var(--panel)`}),[0,1].map(t=>(0,J.jsx)(`line`,{x1:e.x+1+t*5,y1:6+m,x2:e.x+e.w-5+t*5,y2:6,stroke:`var(--line)`,strokeWidth:1},t))]},`k${t}`)),(0,J.jsx)(`line`,{x1:g.x,x2:g.x+g.w,y1:6+m+.5,y2:6+m+.5,stroke:`var(--line)`,strokeWidth:1}),u.map((e,t)=>{let n=o?.id===e.run.id,r=UD[e.slot]??WD[4],i=Math.min(24,e.w);return(0,J.jsxs)(`g`,{children:[e.open&&(0,J.jsx)(`defs`,{children:(0,J.jsxs)(`linearGradient`,{id:`${c}-${t}`,gradientUnits:`userSpaceOnUse`,x1:e.x+e.w-i,x2:e.x+e.w,y1:0,y2:0,children:[(0,J.jsx)(`stop`,{offset:`0`,stopColor:r}),(0,J.jsx)(`stop`,{offset:`1`,stopColor:r,stopOpacity:0})]})}),(0,J.jsx)(`rect`,{x:e.x,y:6+e.lane*f+(f-p)/2,width:e.w,height:p,rx:e.open?0:Math.min(2,p/2),fill:e.open?`url(#${c}-${t})`:r,fillOpacity:o&&!n?.55:.9,stroke:n?`var(--accent)`:e.dearest?`var(--fg)`:`none`,strokeWidth:n?2:1,strokeOpacity:e.open&&!n?.5:1,children:(0,J.jsx)(`title`,{children:`${e.run.type??`agent`} · ${OD(e.run.tok)}${e.run.running?` · still running`:``}`})})]},e.run.id)}),v.map((e,t)=>(0,J.jsx)(`text`,{className:`ctx-tick`,x:g.px(e),y:h-6,textAnchor:t===0?`start`:t===v.length-1?`end`:`middle`,children:AD(e,_)},`x${t}`))]})}function vF({agents:e,dashed:t,stacked:n}){return!e&&!t?null:(0,J.jsxs)(`div`,{className:`ctx-legend`,children:[(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`14`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`rect`,{x:`0`,y:`3`,width:`14`,height:`2.5`,rx:`1.2`,fill:iF})}),` this conversation`,n?` (stacked as the window below)`:``]}),e&&(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`10`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`rect`,{x:`0`,y:`1`,width:`10`,height:`8`,rx:`2`,fill:`var(--fg)`,fillOpacity:.3})}),` subagents`]}),t&&(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`14`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`line`,{x1:`0`,x2:`14`,y1:`5`,y2:`5`,stroke:`var(--fg)`,strokeOpacity:.5,strokeDasharray:`4 3`})}),` whole session`]})]})}function yF({slots:e,only:t}){if(!e)return null;let n=[...e.named.map(e=>({slot:e.slot,name:FP(e.id)})),...e.rest?[{slot:e.rest.slot,name:e.rest.name}]:[]].filter(e=>!t||t.has(e.slot));return n.length<2?null:(0,J.jsx)(`div`,{className:`ctx-legend ctx-legend-stack`,children:n.map(e=>(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`10`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`rect`,{x:`0`,y:`1`,width:`10`,height:`8`,rx:`2`,fill:UD[e.slot]??WD[4]})}),e.name]},e.name))})}function bF({p:e,v:t,label:n,below:r,start:i,dash:a=`4 4`}){let o=e.py(t),s=r?Math.min(e.y+e.h-2,o+11):Math.max(e.y+9,o-4);return(0,J.jsxs)(`g`,{children:[(0,J.jsx)(`line`,{x1:e.x,x2:e.x+e.w,y1:o,y2:o,stroke:`var(--fg)`,strokeOpacity:.4,strokeWidth:1,strokeDasharray:a}),(0,J.jsx)(`text`,{className:`ctx-ref`,x:i?e.x+4:e.x+e.w,y:s,textAnchor:i?`start`:`end`,children:n})]})}function xF({events:e,agents:t=0}){let n=e.filter(e=>e.kind===`compact`).length,r=e.filter(e=>e.kind===`limit`).length;return(0,J.jsxs)(`div`,{className:`ctx-legend`,children:[(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`14`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`rect`,{x:`0`,y:`3`,width:`14`,height:`2.5`,rx:`1.2`,fill:iF})}),` context`]}),t>0&&(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`14`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`rect`,{x:`0`,y:`4`,width:`14`,height:`1.25`,fill:`var(--fg)`,fillOpacity:.45})}),` each agent's own window (`,t,`)`]}),n>0&&(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`10`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`path`,{d:`M1,1L9,1L5,8Z`,fill:`var(--ctx-compact)`})}),` compaction (`,n,`)`]}),r>0&&(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`10`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`rect`,{x:`1.5`,y:`1.5`,width:`7`,height:`7`,fill:`var(--ctx-limit)`})}),` usage limit (`,r,`)`]})]})}function SF(e,t,n=5){return e.map((e,t)=>({run:e,i:t})).sort((e,t)=>{let n=e.run.costUsd??null,r=t.run.costUsd??null;return n!=null&&r!=null?r-n||t.run.tok-e.run.tok||e.i-t.i:n==null?r==null?t.run.tok-e.run.tok||e.i-t.i:1:-1}).slice(0,Math.max(0,n)).map(({run:e})=>{let n=t&&e.model!=null?t[e.model]:null;return{run:e,id:e.id,type:e.type??`agent`,model:n?FP(n):null,turns:e.turns&&e.turns>0?e.turns:null,peakTok:e.peakTok&&e.peakTok>0?e.peakTok:null,tok:e.tok,costUsd:e.costUsd??null,running:!!e.running}})}var CF=5;function wF({agents:e,models:t,picked:n,onPick:r}){let i=SF(e,t,CF);return i.length?(0,J.jsxs)(`div`,{className:`agent-top`,children:[(0,J.jsx)(`div`,{className:`ctx-summary`,children:e.length>i.length?`${i.length} dearest of ${e.length} agents`:`${i.length} agent${i.length>1?`s`:``}, dearest first`}),(0,J.jsxs)(`table`,{className:`agent-top-t`,children:[(0,J.jsx)(`thead`,{children:(0,J.jsxs)(`tr`,{children:[(0,J.jsx)(`th`,{scope:`col`,children:`agent`}),(0,J.jsx)(`th`,{scope:`col`,children:`requests`}),(0,J.jsx)(`th`,{scope:`col`,children:`peak window`}),(0,J.jsx)(`th`,{scope:`col`,children:`tokens`}),(0,J.jsx)(`th`,{scope:`col`,children:`cost`})]})}),(0,J.jsx)(`tbody`,{children:i.map(e=>(0,J.jsxs)(`tr`,{className:e.run===n||e.id===n?.id?`on`:void 0,tabIndex:0,onClick:()=>r(e.run),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),r(e.run))},children:[(0,J.jsxs)(`th`,{scope:`row`,children:[e.type,(0,J.jsx)(`small`,{children:[e.model,e.running?`running`:null].filter(Boolean).join(` · `)})]}),(0,J.jsx)(`td`,{children:e.turns==null?``:e.turns}),(0,J.jsx)(`td`,{children:e.peakTok==null?``:OD(e.peakTok)}),(0,J.jsx)(`td`,{children:OD(e.tok)}),(0,J.jsx)(`td`,{children:e.costUsd==null?``:Ii(e.costUsd)})]},e.id))})]}),(0,J.jsx)(Z,{children:`Tap a row to ring that agent in the chart above. Cost is roughly requests times window; an empty cell was not measured.`})]}):null}var TF=[2e5,3e5,4e5,5e5];function EF({value:e,onChange:t}){let n=!TF.some(t=>t===e);return(0,J.jsxs)(`div`,{className:`agent-warn`,children:[(0,J.jsxs)(`div`,{className:`ts-filter agent-warn-row`,role:`group`,"aria-label":`warn when an agent passes`,children:[(0,J.jsx)(`span`,{className:`ctx-stackpick-lab`,children:`warn when an agent passes`}),TF.map(n=>(0,J.jsx)(Y,{className:n===e?`active`:void 0,"aria-pressed":n===e,onClick:()=>t(n),children:OD(n)},n))]}),(0,J.jsxs)(`div`,{className:`ctx-cost-note`,children:[n?`Set to ${OD(e)} elsewhere. `:``,`It warns you - a chip on the session, a toast and a push - and never stops an agent. Syncs to the desktop, which sends the push.`]})]})}function DF(e){let t=(e.models??[]).map(e=>({...e}));for(let n of e.agentModels??[]){let e=t.find(e=>e.id===n.id);e?(e.tok+=n.tok,n.costUsd!=null&&(e.costUsd=(e.costUsd??0)+n.costUsd)):t.push({...n})}return t}function OF(e){let t=new Map;for(let n of e)for(let e of DF(n))t.set(e.id,(t.get(e.id)??0)+e.tok);if(!t.size)return null;let n=[...t.entries()].sort((e,t)=>t[1]-e[1]).map(([e])=>e),r=RD(n);return{of:r,rest:n.some(e=>!r.has(e))?4:null}}var kF=e=>(er(e)??e).replace(/^claude-/,``);function AF(e,t){let n=DF(e).filter(e=>e.tok>0);if(!n.length||!t)return null;let r=n.every(e=>e.costUsd!=null&&e.costUsd>0),i=e=>r?e.costUsd:e.tok,a=n.reduce((e,t)=>e+i(t),0);if(a<=0)return null;let o=[],s=[];for(let e of n){let n=t.of.get(e.id);n==null?s.push(e):o.push({id:e.id,name:kF(e.id),slot:n,share:i(e)/a,costUsd:e.costUsd,tok:e.tok})}if(s.length){let e=s.reduce((e,t)=>e+t.tok,0),t=s.every(e=>e.costUsd!=null)?s.reduce((e,t)=>e+t.costUsd,0):void 0;o.push({id:s.length===1?s[0].id:`\0rest`,name:s.length===1?kF(s[0].id):`${s.length} more`,slot:4,share:s.reduce((e,t)=>e+i(t),0)/a,costUsd:t,tok:e})}return o.sort((e,t)=>ID(e.slot,t.slot)),{by:r?`cost`:`tokens`,parts:o}}var jF=e=>e.sidechains+e.blocks.filter(e=>e.kind===`tool`&&(e.name===`Task`||e.name===`Agent`)).length,MF=e=>e!=null&&Number.isFinite(e)&&e>0;function NF(e){return e.marker||e.queued?!1:MF(e.costUsd)||MF(e.ctxTok)||MF(e.cumCostUsd)||MF(e.agentCostUsd)||dt(e.tokens)!=null||DF(e).some(e=>e.tok>0)}function PF(e){for(let t=e.length-1;t>=0;t--)if(NF(e[t]))return e[t];return null}function FF(e,t){for(let n of e){if(jF(n)>0)return!0;if(n.id===t)return!1}return!1}var IF=1e4;function LF(e,t,n){return t?n!=null&&e.sentAt!=null&&e.sentAt>=n-IF?`running`:`previous`:`last`}function RF(e,t){let n=`#${e.n}`;return t===`running`?`prompt ${n} so far · running`:t===`previous`?`prompt ${n} · a newer one is running`:t===`earlier`?`prompt ${n}`:`last prompt ${n}`}function zF(e){return e===`running`?`Figures for the prompt still running, as far as its log has got; they are re-read when it ends.`:e===`previous`?`The prompt now running is not in the log yet — its figures replace these when it ends.`:null}function BF(e){let t=MF(e.costUsd)?e.costUsd+(MF(e.agentCostUsd)?e.agentCostUsd:0):null,n=e.tokens?[e.tokens.input,e.tokens.output,e.tokens.cacheRead,e.tokens.cacheWrite].reduce((e,t)=>e+(MF(t)?t:0),0):0,r=[t==null?n>0?`${Ut(n)} tokens`:null:Ii(t),MF(e.ctxTok)?`${Ut(e.ctxTok)} ctx`:null].filter(Boolean);return r.length?r.join(` · `):null}var VF=[`var(--chart-1)`,`var(--chart-2)`,`var(--chart-3)`,`var(--chart-4)`,`var(--muted)`];function HF({parts:e}){let t=2*Math.PI*12,n=e.length>1?1.2:0,r=0;return(0,J.jsxs)(`svg`,{className:`tr-mix-donut`,viewBox:`0 0 32 32`,width:`32`,height:`32`,"aria-hidden":!0,children:[(0,J.jsx)(`circle`,{cx:`16`,cy:`16`,r:12,fill:`none`,stroke:`var(--line)`,strokeWidth:`6`}),e.map(e=>{let i=e.share*t,a=(0,J.jsx)(`circle`,{cx:`16`,cy:`16`,r:12,fill:`none`,stroke:VF[e.slot],strokeWidth:`6`,strokeDasharray:`${Math.max(.6,i-n)} ${t}`,strokeDashoffset:-r,transform:`rotate(-90 16 16)`},e.id);return r+=i,a})]})}function UF({t:e,slots:t,agentsSoFar:n,usdPerWeekPct:r,weekIncl:i,onOpen:a,next:o,trackId:s=`action:read.cost`,why:c=!1}){let l=ze({costUsd:e.costUsd,cumCostUsd:e.cumCostUsd,ctxTok:e.ctxTok,agents:jF(e),agentsSoFar:n,agentCostUsd:e.agentCostUsd,cumAgentCostUsd:e.cumAgentCostUsd,agentsRunning:e.agentsRunning,agentUnpricedTok:e.agentUnpricedTok,usdPerWeekPct:r,weekIncl:i}),u=AF(e,t),d=e.agentTypes??[],f=dt(e.tokens);if(!l&&!u&&!d.length&&!f&&!o)return null;let p=(0,J.jsxs)(J.Fragment,{children:[l?.turn&&(0,J.jsx)(`span`,{className:`tr-cost-head`,children:l.turn}),l&&(l.agents||l.total||l.ctx)&&(0,J.jsx)(`span`,{className:`tr-cost-parts`,children:[l.agents,l.total,l.ctx].filter(Boolean).map((e,t)=>(0,J.jsx)(`span`,{children:e},t))}),f&&(0,J.jsx)(`span`,{className:`tr-cost-toks`,children:f}),o&&(0,J.jsx)(`span`,{className:`tr-cost-next`,children:o}),u&&(0,J.jsxs)(`span`,{className:`tr-mix-legend`,children:[u.parts.map(e=>(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`i`,{style:{background:VF[e.slot]}}),e.name,` `,e.costUsd!=null&&e.costUsd>0?Ii(e.costUsd):Ut(e.tok),u.parts.length>1&&(0,J.jsxs)(`span`,{className:`tr-mix-share`,children:[` `,Math.round(e.share*100),`%`]})]},e.id)),u.parts.length>1&&(0,J.jsxs)(`span`,{className:`tr-mix-share`,children:[`split by `,u.by]})]}),d.length>0&&(0,J.jsx)(`span`,{className:`tr-cost-agents`,children:d.map(e=>(0,J.jsxs)(`span`,{className:`tr-cost-agent`,children:[(0,J.jsx)(Uc,{size:11}),` `,e.type,e.n>1?` ×${e.n}`:``]},e.type))}),l?.note&&(0,J.jsx)(`span`,{className:`tr-cost-note`,children:l.note})]}),m=(0,J.jsxs)(J.Fragment,{children:[u?(0,J.jsx)(HF,{parts:u.parts}):l&&(0,J.jsx)(uc,{size:12}),u?(0,J.jsx)(`span`,{className:`tr-cost-col`,children:p}):p,a&&(0,J.jsx)(jl,{size:12,className:`tr-cost-go`})]}),h=a?(0,J.jsx)(`button`,{type:`button`,className:`tr-cost tr-cost-btn`,onClick:()=>{q(s),a()},children:m}):(0,J.jsx)(`div`,{className:`tr-cost`,children:m}),g=!!(l?.turn||l?.total)||u?.by===`cost`;return c&&g?(0,J.jsx)(WF,{children:h}):h}function WF({children:e}){let[t,n]=(0,H.useState)(!1);return(0,J.jsxs)(`div`,{className:`tr-cost-why`,children:[e,(0,J.jsx)(`button`,{type:`button`,className:`tr-cost-q`,"aria-label":di,"aria-expanded":t,onClick:()=>n(e=>!e),children:(0,J.jsx)(gl,{size:14})}),t&&(0,J.jsxs)(`p`,{className:`tr-cost-why-text`,children:[(0,J.jsx)(`b`,{children:`Why dollars on a subscription?`}),` `,`Your plan's session and weekly limits don't count every token the same: on one model a cache read costs a hundredth of an output token. Adding tokens up treats them as equal, so the total says little about how much of your limit a prompt used. Pricing each kind at Anthropic's API list price weighs it by its own rate — the one number you can compare across prompts, sessions and models. It is not a bill.`]}),t&&(0,J.jsxs)(`p`,{className:`tr-cost-why-text`,children:[(0,J.jsx)(`b`,{children:`Why only the last prompt in the CLI view?`}),` `,`The reader folds this card under every prompt — tap a line to open it, and scroll up for older ones. The CLI view has no scroll-back of its own to hang a card on, so it keeps only the last prompt's, pinned under the terminal at a fixed height: opening or updating it never resizes the screen, which would make the CLI redraw. Same figures, same card; the newest one remembers open or folded in both.`]})]})}function GF({t:e,which:t,open:n,onToggle:r,onChip:i,growsUp:a=!1,className:o=``,bodyClass:s=``,...c}){if(!NF(e)&&!c.next)return null;let l=BF(e),u=RF(e,t),d=zF(t);return(0,J.jsxs)(`div`,{className:`cost-fold${n?` open`:``}${o?` ${o}`:``}`,children:[(0,J.jsxs)(`button`,{type:`button`,className:`cost-fold-head`,"aria-expanded":i?void 0:n,"aria-label":i?`open the context and cost sheet`:`${n?`collapse`:`expand`} the cost of ${u}`,onPointerDown:e=>e.preventDefault(),onClick:i??r,children:[(0,J.jsx)(uc,{size:13,className:`cost-fold-glyph`}),l&&!(n&&!i)&&(0,J.jsx)(`span`,{className:`cost-fold-chip`,children:l}),(0,J.jsx)(`span`,{className:`cost-fold-label`,children:u}),!i&&(n===a?(0,J.jsx)(ac,{size:14,className:`cost-fold-chev`}):(0,J.jsx)(Ys,{size:14,className:`cost-fold-chev`}))]}),n&&!i&&(0,J.jsxs)(`div`,{className:`cost-fold-body${s?` ${s}`:``}`,children:[d&&(0,J.jsx)(`div`,{className:`cost-fold-note`,children:d}),(0,J.jsx)(UF,{t:e,...c})]})]})}function KF({className:e=``}){return(0,J.jsxs)(`details`,{className:`hint-more dollars-why ${e}`.trim(),children:[(0,J.jsxs)(`summary`,{children:[(0,J.jsx)(gl,{size:12}),` `,di]}),(0,J.jsx)(`p`,{children:m})]})}function qF(e,t){let n=(e??[]).map(e=>({load:e}));for(let e of t)for(let t of e.skills??[])n.push({load:t,agent:e});return n.sort((e,t)=>e.load.t-t.load.t)}function JF(e,t,n){let r=[],i=new Map;for(let{load:a,agent:o}of qF(t,n)){let t=i.get(a.name);t??(t=r.length,i.set(a.name,t),r.push({name:a.name,marks:[]}));let n=Math.max(e.x,Math.min(e.x+e.w,e.px(a.t)));r[t].marks.push({load:a,...o?{agent:o}:{},x:n,row:t})}return r}function YF(e,t,n,r){let i=Math.floor((r-t)/24),a=e[i]?.marks.length?e[i].marks:e.flatMap(e=>e.marks);return a.length?a.reduce((e,t)=>Math.abs(t.x-n)<Math.abs(e.x-n)?t:e,a[0]):null}function XF(e){return`≈${OD(Math.round(e/4))} tokens`}function ZF(e){return e?`a subagent${e.type?` (${e.type})`:``}`:`this conversation`}function QF(e,t){let n=qF(e,t);if(!n.length)return null;let r=new Set(n.map(e=>e.load.name)).size,i=n.filter(e=>!e.agent).length,a=n.length-i,o=n.reduce((e,t)=>e+t.load.chars,0),s=a===0?`all by this conversation`:i===0?`all by subagents`:`${i} by this conversation, ${a} by subagents`,c=n.length===1?`1 load`:`${n.length} loads`;return`${r} skill${r===1?``:`s`} · ${c}, ${s} · ${XF(o)} of skill text`}function $F(e){let t=e.reduce((e,t)=>!e||t.marks.length>e.marks.length?t:e,null);if(!t||t.marks.length<2)return null;let n=t.marks.reduce((e,t)=>e+t.load.chars,0);return`${t.name} was loaded ${t.marks.length} times — ${XF(n)} in all.`}function eI(e,t){return`${e.load.name} · ${AD(e.load.t,t)} · by ${ZF(e.agent)} · ${OD(e.load.chars)} chars, ${XF(e.load.chars)}`}var tI=`A mark is the moment the Skill tool wrote that skill's text into a context window, read off the CLI's log. A filled dot is this conversation's own window; a ring is a subagent's — its own window, not this one. Size is the text's length in characters; the token figure divides by 4, an estimate, because the request that carried the text reports one total for everything it held. A skill typed as a slash command is not counted here.`,nI={top:4,right:10,bottom:20,left:40},rI=3.5;function iI({samples:e,events:t,own:n,agents:r,width:i,picked:a,onPick:o}){let s=(0,H.useRef)(null),c=hP({width:i,height:100,pad:nI,samples:e,events:t,windowTok:null,refs:[],agents:r}),l=JF(c,n,r),u=nI.top,d=l.length*24,f=u+d+nI.bottom,p=c.t1-c.t0,m=[0,.5,1].map(e=>c.tx(c.x+e*c.w)),h=(e,t)=>!!t&&e.load===t.load,g=(e,t)=>{let n=s.current?.getBoundingClientRect();if(!n)return;let r=(e.clientX-n.left)/n.width*i,c=(e.clientY-n.top)/n.height*f,d=YF(l,u,r,c);o(t&&d&&h(d,a)?null:d)};return(0,J.jsxs)(`svg`,{ref:s,className:`ctx-chart`,width:i,height:f,viewBox:`0 0 ${i} ${f}`,onPointerDown:e=>g(e,!0),onPointerMove:e=>{e.buttons&&g(e,!1)},role:`img`,"aria-label":`skills loaded over time, one row per skill`,children:[c.breaks.map((e,t)=>(0,J.jsxs)(`g`,{children:[(0,J.jsx)(`rect`,{x:e.x,y:u,width:e.w,height:d,fill:`var(--panel)`}),[0,1].map(t=>(0,J.jsx)(`line`,{x1:e.x+1+t*5,y1:u+d,x2:e.x+e.w-5+t*5,y2:u,stroke:`var(--line)`,strokeWidth:1},t))]},`k${t}`)),l.map((e,t)=>{let n=u+t*24;return(0,J.jsxs)(`g`,{children:[(0,J.jsx)(`line`,{x1:c.x,x2:c.x+c.w,y1:n+17+.5,y2:n+17+.5,stroke:`var(--line)`,strokeWidth:1,strokeOpacity:.6}),(0,J.jsxs)(`text`,{className:`ctx-tick`,x:c.x,y:n+9,children:[e.name,e.marks.length>1?` ×${e.marks.length}`:``]}),e.marks.map((e,t)=>{let r=h(e,a);return(0,J.jsx)(`circle`,{cx:e.x,cy:n+17,r:rI,fill:e.agent?`var(--panel)`:iF,stroke:r?`var(--accent)`:e.agent?`var(--fg)`:iF,strokeOpacity:r?1:e.agent?.6:1,strokeWidth:r?2:1.25},t)})]},e.name)}),(0,J.jsx)(`line`,{x1:c.x,x2:c.x+c.w,y1:u+d+.5,y2:u+d+.5,stroke:`var(--line)`,strokeWidth:1}),m.map((e,t)=>(0,J.jsx)(`text`,{className:`ctx-tick`,x:c.px(e),y:f-6,textAnchor:t===0?`start`:t===m.length-1?`end`:`middle`,children:AD(e,p)},`x${t}`))]})}function aI({samples:e,events:t,own:n,agents:r,width:i,span:a}){let[o,s]=(0,H.useState)(null),c=QF(n,r);if(n===void 0&&!c)return null;if(!c)return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`ctx-chart-title`,children:`Skills`}),(0,J.jsx)(`div`,{className:`empty ctx-note`,children:`No skill has been loaded in this conversation or its subagents.`})]});let l=r.some(e=>e.skills?.length),u=!!n?.length,d=$F(JF(hP({width:Math.max(i,1),height:100,pad:nI,samples:e,events:t,windowTok:null,refs:[],agents:r}),n,r));return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`ctx-chart-title`,children:`Skills`}),(0,J.jsx)(`div`,{className:`ctx-summary`,children:c}),(0,J.jsx)(`div`,{className:`ctx-box`,children:i>0&&(0,J.jsx)(iI,{samples:e,events:t,own:n,agents:r,width:i,picked:o,onPick:s})}),(0,J.jsx)(`div`,{className:`ctx-readout`,children:o?eI(o,a):`tap a mark to read that load`}),(0,J.jsxs)(`div`,{className:`ctx-legend`,children:[u&&(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`10`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`circle`,{cx:`5`,cy:`5`,r:rI,fill:`var(--ctx-series)`})}),` this conversation`]}),l&&(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`svg`,{width:`10`,height:`10`,"aria-hidden":!0,children:(0,J.jsx)(`circle`,{cx:`5`,cy:`5`,r:rI,fill:`none`,stroke:`var(--fg)`,strokeOpacity:.6,strokeWidth:1.25})}),` a subagent`]})]}),d&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:d}),(0,J.jsxs)(`details`,{className:`hint-more ctx-method`,children:[(0,J.jsx)(`summary`,{children:`how the skills chart is counted`}),(0,J.jsx)(`p`,{children:tI})]})]})}function oI(e){let t=e.filter(e=>e.key===`remainder`);return[...e.filter(e=>e.key!==`remainder`).sort((e,t)=>t.tok-e.tok),...t]}var sI=e=>e.key===`remainder`?`rest`:e.undocumented?`undoc`:`doc`;function cI(e,t){let n=oI(e),r=n.some(e=>e.key===`remainder`),i=n.reduce((e,t)=>e+Math.max(0,t.tok),0),a=r&&t!=null&&t>0?`request`:`parts`,o=a===`request`?Math.max(t,i):i;if(!(o>0))return null;let s=0;return{segs:n.map(e=>{let t=Math.max(0,e.tok)/o*100,n={key:e.key,label:e.label,tok:e.tok,words:e.words,cls:sI(e),x:s,w:t};return s+=t,n}),whole:o,scale:a}}function lI(e,t){if(!e.length)return null;let n=Math.min(100,Math.max(0,t*100));for(let t of e)if(n<t.x+t.w)return t;return e[e.length-1]}function uI(e,t){if(!(t>0))return``;let n=e/t*100;return n>0&&n<1?`<1%`:`${Math.round(n)}%`}function dI(e,t){let n=t.scale===`request`?`of the first request`:`of the parts`;return`${e.label} · ${e.words} · about ${uI(e.tok,t.whole)} ${n}`}function fI(e,t,n){return e.scale===`request`?null:t==null?`The bar is the parts' own sum: the first request has not been answered yet, so its size is unknown.`:`The bar is the parts' own sum: their estimate exceeds the first request's ${n(t)} tokens, so the rest cannot be drawn.`}var pI={doc:`logged attachment (~)`,undoc:`undocumented record (~)`,rest:`the rest of the request (≈)`};function mI(e){let t=new Set(e.segs.filter(e=>e.tok>0).map(e=>e.cls));return[`doc`,`undoc`,`rest`].filter(e=>t.has(e))}function hI(e){let t=/^(\/Users\/[^/]+|\/home\/[^/]+|\/root|[A-Za-z]:\\Users\\[^\\]+)(?=$|[/\\])/.exec(e);return t?`~${e.slice(t[1].length)}`:e}var gI=(e,t)=>e.length>0&&e.length<=3&&(t==null||t<=e.length),_I=`This desktop did not measure what the first request carried (an older host, or a log whose start held no attachment record).`;function vI({carried:e,fmt:t=R}){return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`ctx-chart-title`,children:`What every turn carries`}),e?(0,J.jsx)(yI,{carried:e,fmt:t}):(0,J.jsx)(`div`,{className:`empty ctx-note`,children:_I})]})}function yI({carried:e,fmt:t}){let[n,r]=(0,H.useState)(null),i=oI(Xte(e,t)),a=cI(i,e.firstRequestTok),o=new Map(e.parts.map(e=>[e.kind,e.count])),s=e=>r(t=>t===e?null:e),c=!!a&&a.scale===`parts`&&e.firstRequestTok!=null;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`ctx-summary`,children:Dee(e,t,{unplacedShown:c})}),a&&(0,J.jsx)(bI,{strip:a,picked:n,onPick:r,firstRequestTok:e.firstRequestTok,fmt:t}),(0,J.jsxs)(`div`,{className:`empty ctx-note`,children:[`Measured on this log's first request`,e.firstRequestAt==null?``:` (${new Date(e.firstRequestAt).toLocaleString()})`,`, not on what a new session would carry today.`]}),i.length>0&&(0,J.jsx)(`ul`,{className:`carried-list`,children:i.map(e=>{let t=e.key===`remainder`?void 0:o.get(e.key),r=e.names&&t!=null&&t>e.names.length,i=a?.segs.find(t=>t.key===e.key);return(0,J.jsx)(`li`,{className:n===e.key?`carried-picked`:void 0,children:(0,J.jsxs)(xE,{children:[(0,J.jsxs)(`div`,{className:`carried-pick`,role:`button`,tabIndex:0,"aria-pressed":n===e.key,title:`read this part on the strip above`,onClick:()=>s(e.key),onKeyDown:t=>{(t.key===`Enter`||t.key===` `)&&(t.preventDefault(),s(e.key))},children:[(0,J.jsxs)(`div`,{className:`carried-head`,children:[(0,J.jsx)(SE,{className:`carried-label`,children:e.label}),(0,J.jsx)(Q,{className:`carried-num`,children:e.words})]}),i&&(0,J.jsx)(`span`,{className:`carried-meter`,"aria-hidden":!0,children:(0,J.jsx)(`span`,{className:`carried-fill carried-${sI(e)}`,style:{width:i.w>0?`max(1px, ${i.w}%)`:0}})})]}),e.files&&e.files.length>0&&(0,J.jsx)(`ul`,{className:`carried-files`,children:e.files.map((e,t)=>(0,J.jsxs)(`li`,{className:`carried-head`,children:[(0,J.jsxs)(Q,{className:`carried-label`,children:[(0,J.jsx)(`span`,{className:`carried-path`,children:hI(e.path)}),` `,(0,J.jsx)(yE,{className:`carried-type`,children:e.type})]}),(0,J.jsx)(Q,{className:`carried-num`,children:e.words})]},`${t}:${e.label}`))}),e.names&&e.names.length>0&&(gI(e.names,t)?(0,J.jsx)(Q,{className:`carried-inline`,children:e.names.join(`, `)}):(0,J.jsxs)(`details`,{className:`hint-more carried-names`,children:[(0,J.jsx)(`summary`,{children:r?`the first ${e.names.length} of ${t} names`:`the ${e.names.length} names`}),(0,J.jsx)(`p`,{children:e.names.join(`, `)})]}))]})},e.key)})}),!e.parts.length&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:`The log holds no attachment records before the first request, so no part can be named.`})]})}function bI({strip:e,picked:t,onPick:n,firstRequestTok:r,fmt:i}){let a=t=>{let n=t.currentTarget.getBoundingClientRect();return n.width>0?lI(e.segs,(t.clientX-n.left)/n.width):null},[o,s]=(0,H.useState)(null),c=o??t,l=e.segs.find(e=>e.key===c)??null,u=fI(e,r,i);return(0,J.jsxs)(`div`,{className:`carried-comp`,children:[(0,J.jsx)(`div`,{className:`carried-bar`,role:`group`,"aria-label":`${e.scale===`request`?`what the first request was made of`:`what the parts were made of`}; the line under it reads the picked part`,onPointerDown:e=>{let r=a(e);n(r&&r.key===t?null:r?.key??null),e.pointerType===`mouse`&&s(null)},onPointerMove:e=>{if(e.buttons){let t=a(e);t&&n(t.key),e.pointerType===`mouse`&&s(null)}else e.pointerType===`mouse`&&s(a(e)?.key??null)},onPointerLeave:e=>{e.pointerType===`mouse`&&s(null)},children:e.segs.map(e=>(0,J.jsx)(`span`,{className:`carried-seg carried-${e.cls}${e.key===c?` carried-on`:``}`,style:{left:`${e.x}%`,width:`${e.w}%`}},e.key))}),(0,J.jsx)(`div`,{className:`ctx-readout carried-readout`,children:l?dI(l,e):(0,J.jsx)(YD,{})}),(0,J.jsx)(`div`,{className:`ctx-legend carried-legend`,children:mI(e).map(e=>(0,J.jsxs)(`span`,{children:[(0,J.jsx)(`i`,{className:`carried-swatch carried-${e}`,"aria-hidden":!0}),pI[e]]},e))}),u&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:u})]})}var xI=220,SI=110;function CI({sessionId:e,title:t,online:n,liveAgentNote:r,onReplan:i,replanCant:a,replanNote:o,agentWarn:s,budget:c,onFresh:l,onCompact:u,compactCant:d,onExplainCost:f,unmeasured:p,backendLabel:m,onOpenSetup:h,setupCant:g,onOpenAllSessions:_,onClose:v}){let y=fh(`ctx:${e}`,async()=>{let t=await U.contextSeries(e);if(!t)throw Error(`no context series`);return t},{enabled:!p,offline:!n,fromCache:()=>lC(e),toCache:cC}),b=y.data,[x,S]=(0,H.useState)(null),[C,w]=(0,H.useState)(null),T=(0,H.useRef)(null),[E,D]=(0,H.useState)(0),O=(0,H.useCallback)(e=>{if(T.current?.disconnect(),T.current=null,!e)return;let t=e=>{let t=getComputedStyle(e);return e.clientWidth-parseFloat(t.paddingLeft||`0`)-parseFloat(t.paddingRight||`0`)};if(D(t(e)),typeof ResizeObserver>`u`)return;let n=new ResizeObserver(()=>D(t(e)));n.observe(e),T.current=n},[]);(0,H.useEffect)(()=>()=>T.current?.disconnect(),[]);let k=(0,H.useCallback)(e=>S(e),[]),A=b?.samples??[],j=b?.events??[],M=A.length?A[A.length-1].t-A[0].t:0,N=b?.windowTok??null,P=eF(A,j,N,b?.agents),I=fa(b?.coldStarts,`session`),ee=F(A,b?.truncated??!1,b?.turns??null,b?{usageTok:b.usageTok,agentTok:b.agentTok}:null,A.length?{lastTurnAt:A[A.length-1].t,now:Date.now()}:null),te=SP(A,b?.usageTok,b?.agentTok,b?.cost?{total:b.cost.total+(b.agentCost?.total??0),agents:b.agentCost?.total??null,unpricedTok:b.unpricedTok??null}:null),ne=TP(b?.split,b?.agentSplit),re=b?.agents??[],ie=PP(b?.models,A.some(e=>e.model==null)||re.some(e=>e.model==null)),ae=MP(A,`kinds`,e=>e!==`output`),oe=MP(A,`cum`),se=ae,ce=oe,le=A.slice(0,-1).map((e,t)=>A[t+1].t-e.t).filter(e=>e>fP),ue=(h||_)&&(0,J.jsxs)(`div`,{className:`sheet-actions ctx-doors`,children:[h&&(0,J.jsxs)(Y,{onClick:h,title:`What this repo and this desktop put in every turn, file by file`,children:[(0,J.jsx)(Cs,{size:12}),` repo readings`]}),_&&(0,J.jsxs)(Y,{onClick:_,title:`Every conversation on this desktop, with its token split`,children:[(0,J.jsx)(qo,{size:12}),` all sessions`]})]});if(p)return(0,J.jsxs)(`div`,{className:`sheet`,children:[(0,J.jsx)(gE,{title:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(yo,{size:16,style:{verticalAlign:`-3px`,marginRight:4}}),`Context window & cost`]}),onClose:v}),ue,(0,J.jsx)(CE,{cants:[{label:`context graph`,reason:p}]}),(0,J.jsxs)(Z,{children:[t,` — nothing on this screen is a measurement of it. The terminal is still the whole story.`]})]});let de=te?wP(te,b?.truncated??!1,!!b?.agentCum?.length):null,fe=ne?DP(ne,b?.truncated??!1):null,pe=WP(re,b?.agentTok);return(0,J.jsxs)(`div`,{className:`sheet`,children:[(0,J.jsx)(gE,{title:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(yo,{size:16,style:{verticalAlign:`-3px`,marginRight:4}}),`Context window & cost`]}),onClose:v,children:(0,J.jsx)(Y,{onClick:()=>{y.inflight||y.reload({quiet:!0})},title:`re-read — this is a point-in-time answer, not a live feed`,children:y.inflight?(0,J.jsx)(Ml,{size:14,className:`spin`}):(0,J.jsx)(Wl,{size:14})})}),(0,J.jsx)(Z,{children:t}),ue,!h&&g&&(0,J.jsx)(CE,{cants:[{label:`repo readings`,reason:g}]}),(0,J.jsx)($,{res:y,empty:!A.length,thing:`the context history`,noun:`graph`,note:y.state===`error`?`A session that has not run a turn yet has no log to read.`:void 0,children:`Nothing to plot yet — this conversation has not completed a turn.`}),!A.length&&b&&(0,J.jsx)(vI,{carried:b.carried}),A.length>0&&(0,J.jsxs)(`div`,{className:`list`,children:[(0,J.jsxs)(J.Fragment,{children:[te&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`ctx-chart-title`,children:te.costUsd==null?`Tokens spent`:`Total cost`}),(0,J.jsx)(`div`,{className:`ctx-summary`,children:CP(te,b?.truncated??!1)}),(0,J.jsx)(`div`,{className:`ctx-box`,children:E>0&&(0,J.jsx)(mF,{samples:A,events:j,facts:te,width:E,height:SI,bands:ce,agents:re,agentCum:b?.agentCum})}),(0,J.jsx)(vF,{agents:te.agents!=null&&!!b?.agentCum?.length,dashed:te.total!=null&&te.agents!=null,stacked:!!ce}),de?.lead&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:de.lead}),te.costUsd!=null&&(0,J.jsx)(KF,{className:`ctx-method`})]}),(0,J.jsxs)(`div`,{className:`ctx-chart-title ctx-chart-title-row`,children:[(0,J.jsx)(`span`,{children:`Context window`}),u&&(0,J.jsxs)(Y,{onClick:u,children:[(0,J.jsx)(ere,{size:14}),` /compact`]})]}),!u&&d&&(0,J.jsx)(CE,{cants:[{label:`/compact from here`,reason:d}]}),P&&(0,J.jsx)(`div`,{className:`ctx-summary`,children:P}),(0,J.jsx)(`div`,{className:`ctx-box`,ref:O,children:E>0&&(0,J.jsx)(pF,{samples:A,events:j,width:E,height:xI,windowTok:N,autoCompactTok:b?.autoCompactTok??null,autoCompactSetTok:b?.autoCompactSet?.tokens??null,onHover:k,bands:se,agents:re})}),(0,J.jsx)(`div`,{className:`ctx-readout`,children:x?`${AD(x.t,M)} · ${vP(x.tok,N)}`:(0,J.jsx)(YD,{})}),(0,J.jsx)(xF,{events:j,agents:re.filter(e=>e.ctx?.length).length}),se&&E>0&&(0,J.jsx)(gF,{p:hP({width:E,height:xI,pad:{top:10,right:10,bottom:20,left:40},samples:A,events:j,refs:[],windowTok:N,agents:re}),samples:A,series:se}),re.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`ctx-chart-title`,children:`Subagents`}),(0,J.jsx)(`div`,{className:`ctx-summary`,children:UP(re,b?.models)}),(0,J.jsx)(`div`,{className:`ctx-box`,children:E>0&&(0,J.jsx)(_F,{samples:A,events:j,agents:re,slots:ie,width:E,picked:C,onPick:w})}),(0,J.jsx)(`div`,{className:`ctx-readout`,children:C?HP(C,b?.models,M):`tap a bar to read that agent`}),(0,J.jsx)(yF,{slots:ie,only:new Set(re.map(e=>ie?.slotOf(e.model)??0))}),(0,J.jsx)(wF,{agents:re,models:b?.models,picked:C,onPick:w})]}),pe&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:pe}),(0,J.jsx)(aI,{samples:A,events:j,own:b?.skills,agents:re,width:E,span:M}),b&&(0,J.jsx)(vI,{carried:b.carried}),(de||re.length>0)&&(0,J.jsxs)(`details`,{className:`hint-more ctx-method`,children:[(0,J.jsx)(`summary`,{children:`how the spend and agent charts are counted`}),de&&(0,J.jsx)(`p`,{children:de.more}),re.length>0&&(0,J.jsx)(`p`,{children:`Each bar runs from an agent's first dated record to its last, coloured by the model that ran it, and packed into as few rows as fit without two bars overlapping — a row is not an identity, only the first one that had room. The outlined bar spent the most. A floor, like every reading here: an agent log this desktop never saw is one nothing can place.`})]})]}),ne&&(0,J.jsxs)(J.Fragment,{children:[EP(ne)&&(0,J.jsx)(`div`,{className:`ctx-summary`,children:EP(ne)}),(0,J.jsx)(KD,{bag:ne.all,whole:Xi(ne.all)}),fe?.lead&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:fe.lead}),(0,J.jsx)(qD,{totals:ne.all,scope:`session`}),fe&&(0,J.jsxs)(`details`,{className:`hint-more ctx-method`,children:[(0,J.jsx)(`summary`,{children:`how these kinds are counted`}),(0,J.jsx)(`p`,{children:fe.more})]})]}),r&&(0,J.jsxs)(`div`,{className:`ctx-cost ctx-cost-heavy`,children:[(0,J.jsxs)(`div`,{className:`ctx-cost-head`,children:[(0,J.jsx)(Uc,{size:14}),(0,J.jsx)(`span`,{children:`a subagent is running on a large window`})]}),(0,J.jsx)(`div`,{className:`ctx-cost-note`,children:r}),i?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`sheet-actions`,children:(0,J.jsxs)(Y,{onClick:i,children:[(0,J.jsx)(Nc,{size:14}),` interrupt and re-plan`]})}),o&&(0,J.jsx)(Z,{children:o})]}):a?(0,J.jsx)(CE,{cants:[{label:`interrupt and re-plan`,reason:a}]}):null]}),ee&&(0,J.jsx)(dP,{cost:ee,onFresh:l,onCompact:u}),(c||s)&&(0,J.jsxs)(`div`,{className:`ctx-cost`,children:[c&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`ctx-cost-head`,children:[(0,J.jsx)(El,{size:14}),(0,J.jsx)(`span`,{children:c.label?`budget ${c.label}`:`no budget on this session`})]}),c.line?(0,J.jsx)(`div`,{className:`ctx-cost-note`,children:c.line}):null,(0,J.jsx)(`div`,{className:`sheet-actions`,children:(0,J.jsxs)(Y,{onClick:c.onOpen,children:[(0,J.jsx)(El,{size:14}),` `,c.label?`change or clear the budget`:`set a budget`]})})]}),s&&(0,J.jsxs)(J.Fragment,{children:[!c&&(0,J.jsxs)(`div`,{className:`ctx-cost-head`,children:[(0,J.jsx)(Uc,{size:14}),(0,J.jsx)(`span`,{children:`large subagents`})]}),(0,J.jsx)(EF,{value:s.value,onChange:s.onChange})]})]}),(0,J.jsxs)(`div`,{className:`ctx-cost`,children:[(0,J.jsxs)(`div`,{className:`ctx-cost-head`,children:[(0,J.jsx)(rc,{size:14}),(0,J.jsx)(`span`,{children:`why it cost this much`})]}),f?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`ctx-cost-note`,children:`A new session in this directory measures this conversation's transcript, names what made it expensive and lists ideas to make it cheaper — it changes nothing until you pick one.`}),(0,J.jsx)(`div`,{className:`sheet-actions`,children:(0,J.jsxs)(Y,{onClick:f,children:[(0,J.jsx)(rc,{size:14}),` explain the cost of this session`]})})]}):(0,J.jsx)(CE,{cants:[{label:`explain the cost of this session`,reason:`this session has no conversation id yet, so there is no transcript to point a new session at`}]})]}),I&&(0,J.jsxs)(`div`,{className:`ctx-panel`,children:[(0,J.jsx)(`div`,{className:`ctx-summary`,children:`Expired cache`}),(0,J.jsx)(Z,{children:I}),(0,J.jsxs)(`details`,{className:`hint-more ctx-method`,children:[(0,J.jsx)(`summary`,{children:`why a cold cache costs more`}),(0,J.jsx)(`p`,{children:`A conversation resumed inside the hour re-reads its window out of the cache at a tenth of the write rate. After that the window has to be written again before it can answer anything — the same tokens, up to twenty times the price, and the chart does not move when it happens.`})]})]}),b?.compaction&&(0,J.jsx)(uP,{l:b.compaction,windowTok:N,tok:A.length?A[A.length-1].tok:null}),b?.truncated&&!de&&!fe&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:`This conversation’s log is longer than the host reads in one go, so the curve starts part-way through it.`}),(0,J.jsxs)(`div`,{className:`empty ctx-note`,children:[$P(b?.windowFrom,N,b?.model,m),b?.autoCompactTok!=null&&` The dashed line is where a compaction was last observed to fire — a measurement, not a setting.`,b?.autoCompactSet&&` ${rF(b.autoCompactSet)}`]}),le.length>0&&(0,J.jsx)(`div`,{className:`empty ctx-note`,children:le.length===1?`One stretch of ${gP(le[0])} with no activity is compressed on the time axis (the ⁄⁄ mark).`:`${le.length} stretches with no activity — the longest ${gP(Math.max(...le))} — are compressed on the time axis (the ⁄⁄ marks).`}),(0,J.jsxs)(`details`,{className:`hint-more ctx-method`,children:[(0,J.jsx)(`summary`,{children:`where these numbers come from`}),(0,J.jsx)(`p`,{children:`How many tokens each request carried, read off the CLI’s own conversation log and each subagent’s own log. Both are dated, which is what lets a compaction, a usage wall and every agent sit on the same time axis as the curve.`})]})]})]})}function wI(e,t,n){return(e?t.find(t=>t.id===e):null)??n}function TI(e){return e?`that conversation is not listed — showing ${e}`:`that conversation is not listed, and none is attached`}function EI(e,t){return e?`sent /compact to ${t}`:`queued /compact — sends when the link is back`}function DI(e){return`sent Esc to ${e} and queued the re-plan prompt`}function OI(e){return`no connection — Esc did not reach ${e}, and the re-plan prompt was not queued. Try again when the link is back.`}var kI=`Sends Esc, which stops the agent the session is waiting on, then queues a prompt asking the main agent to re-plan it narrower. Work that agent has not reported back is lost. An agent running in the background keeps going; the prompt asks the main agent to stop it.`,AI=G(null);function jI(e){let t=W();t.say.track(`action:session.context`),AI.set(e.id),t.nav.open(`context`)}function MI(){AI.set(null),W().nav.open(`context`)}function NI(e){let t=W();if(e===null&&AI.get()!==null)return;let n=e?t.world.sessions.find(t=>t.id===e):void 0;n?jI(n):(MI(),e&&t.say.toast(TI(t.world.active?t.world.sessionRowTitle(t.world.active):null)))}function PI(){AI.set(null),W().nav.close(`context`)}function FI(e){let t=W();t.say.track(`action:ctx.setup`),t.nav.openSetup(e,{region:`setup`,focus:`context-weight`})}function II(){let e=W();e.say.track(`action:ctx.tokens`),e.nav.open(`tokens`)}function LI(e){PI(),W().nav.openRepo(e)}function RI(e){let t=W();t.say.track(`action:ctx.compact`),t.queue.submitInput(e.id,e.cwd,`/compact`,`command`),t.compose.pushHistory(`/compact`),t.say.toast(EI(t.conn.status===`open`,t.world.sessionRowTitle(e)))}function zI(e,t){let n=kw({title:t,cwd:e.cwd,claudeSessionId:e.claudeSessionId,model:e.model});if(!n)return!1;let r=W();return r.say.track(`action:ctx.explainCost`),PI(),r.nav.startSessionWithPrompt(e.cwd,`cost of ${t}`,[n]),!0}function BI(e,t){let n=W();n.say.track(`action:ctx.replan`);let r=e.contextSpark;n.conn.liveSend({t:`session.input`,id:e.id,data:`\x1B`},DI(t),OI(t))&&n.queue.submitInput(e.id,e.cwd,se(r?.liveAgentTok??0,r?.liveAgentType),`prompt`)}function VI({subject:e}){let t=_h(),{backends:n}=t.world,r=t.world.sessionRepo(e),i=t.world.sessionRowTitle(e),a=ut(oy(`agentWindowWarn`));return(0,J.jsx)(CI,{sessionId:e.id,title:i,online:t.conn.status===`open`,unmeasured:t.world.sessionCant(e,`contextSeries`)??void 0,backendLabel:CT(n,e.backend)??void 0,onFresh:r?()=>LI(r):void 0,onCompact:t.world.sessionCan(e,`slash`)?()=>RI(e):void 0,compactCant:t.world.sessionCant(e,`slash`)??void 0,onExplainCost:e.claudeSessionId?()=>{zI(e,i)}:void 0,liveAgentNote:e.running?aee(e.contextSpark?.liveAgentTok,e.contextSpark?.liveAgentAt,Date.now(),a):null,onReplan:t.world.sessionCan(e,`slash`)?()=>BI(e,i):void 0,replanCant:t.world.sessionCant(e,`slash`)??void 0,replanNote:kI,agentWarn:{value:a,onChange:e=>{t.say.track(`action:ctx.agentWarn`),sy(`agentWindowWarn`,e===5e5?``:String(e))}},budget:{label:e.budget?yr(e.budget.cfg):null,line:oE(e.budget,Date.now(),ti(e)),onOpen:()=>QD(e.id)},onOpenSetup:r?()=>FI(r.id):void 0,setupCant:r?void 0:`this session's repo is not one the desktop lists`,onOpenAllSessions:II,onClose:PI})}var HI={id:`context`,sheets:[{id:`context`,persisted:!0,render:e=>{let t=wI(AI.get(),e.world.sessions,e.world.active);return t?(0,H.createElement)(VI,{subject:t}):null}}]},UI=wr(`builds.json`),WI=`\`${UI}\` is a JSON array of objects \`{ "id", "name", "cmd", "dir", "params" }\`:
|
|
151
151
|
- It is COMMITTED with the repo, so every checkout gets the buttons. An entry whose command names a path that exists on this desktop alone (a \`JAVA_HOME\`, a local SDK) goes in \`${Br(`builds.json`)}\` instead — same shape, gitignored; there an entry with a shared entry's \`id\` replaces it on this desktop only.
|
|
152
152
|
- \`id\`: short unique slug. If the file already exists, KEEP the ids that are there.
|
|
153
153
|
- \`name\`: short button label, e.g. "Release APK". It is read on a phone, so keep it short.
|
|
@@ -202,7 +202,7 @@ Finish with one line: the button you wrote, its command, and what it will ask fo
|
|
|
202
202
|
|
|
203
203
|
`)||null}function RH(e,t){return e.trigger.kind===`at`&&zte({rule:e.trigger.rule,nextAt:e.nextAt,lastOccurrence:e.lastOccurrence},t)}function zH(e,t){let n=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`);return!!e&&!!t&&/\bsession\b/i.test(e)&&RegExp(`(^|[^\\w-])${n}($|[^\\w-])`,`i`).test(e)}function BH(e,t,n,r){if(e.blockDetail)return e.blockDetail;if(e.blockReason)return dr(e.blockReason);if(t===`fanout`&&r){let e=r.targets.filter(e=>e.status===`done`).length,t=r.targets.filter(e=>e.status===`failed`).length,n=r.targets.length;return r.finishedAt?t?`${t} of ${n} repos failed${e?`, ${e} finished`:``}`:`all ${n} repos finished`:`${e} of ${n} repos done${t?`, ${t} failed`:``} — still going`}switch(e.state){case`running`:return t===`build`?`running the command now`:t===`capture`?`taking the picture now`:`running in the session now`;case`starting`:return`starting it now`;case`canceled`:return`stopped`;case`failed`:return PH(e.result?.detail,e.settledAt??e.createdAt,n,`it ran and did not finish`);case`done`:if(t===`build`){let t=e.result?.artifacts??[];return t.length&&t.every(e=>e.stale)?`finished — nothing was rebuilt, so these are the newest matching files, not this run's output`:t.length?`finished — ${t.length} ${t.length===1?`file`:`files`} written`:`finished — it wrote no build output`}return t===`schedule`&&RH(e,n)?e.result?.detail??`that instant has passed and this was a one-off — post it again if you still want it`:e.result?.detail??`finished`;default:return e.state===`blocked`?`the desktop is holding this one and did not say why`:t===`schedule`?`armed — it will fire on its own`:`next in line for this repo`}}function VH(e){let t=gr(e),n=LH(e),r=e.payload.kind===`build`?e.payload:null,i=e.payload.kind===`capture`?e.payload:null;return(t===`schedule`?e.label||Ar(e.title,n??``)||n||e.id:t===`schedule`||t===`build`||t===`assess`||t===`capture`?e.label||e.title||r?.name||i?.name||r?.cmd||n||e.id:e.headline||n||e.label||e.title||e.id).trim()}var HH=e=>!Ia(e.rule)&&e.action.kind===`backlog`,UH=e=>e.state===`done`||e.state===`failed`||e.state===`canceled`;function WH(e,t){return e.archived||e.trigger.kind!==`at`||UH(e)?!1:Si({rule:e.trigger.rule,nextAt:e.nextAt,lastOccurrence:e.lastOccurrence},t)}function GH(e){return e.archived||e.trigger.kind!==`at`?!1:e.state!==`starting`&&e.state!==`running`&&e.state!==`done`&&e.state!==`canceled`}function KH(e){let{focus:t,focusIds:n,now:r}=e,i=(e.text??``).trim().toLowerCase(),a=e.intents.filter(e=>ga(e)&&!e.archived),o=a.filter(e=>WH(e,r)).sort((e,t)=>(e.nextAt??1/0)-(t.nextAt??1/0)),s=new Set(o.map(e=>e.id)),c=a.filter(e=>!s.has(e.id)&&!e.dismissedAt),l=n?a.filter(e=>n.ids.includes(e.id)):t?o.filter(e=>at(e.nextAt,r)===t):o,u=i?l.filter(e=>JH(e,i)):l,d=[];for(let e of c){let t=d.find(([t])=>t===e.cwd);t?t[1].push(e):d.push([e.cwd,[e]])}let f=t=>e.intents.some(e=>e.id===t.entry.id),p=e.pending.filter(e=>HH(e.entry)&&!f(e)),m=e.pending.filter(e=>!HH(e.entry)),h=new Set(m.map(e=>e.entry.id)),g=[...m.map(e=>e.entry),...(e.entries??[]).filter(e=>!h.has(e.id))].sort((e,t)=>(e.nextAt??1/0)-(t.nextAt??1/0)),_=g.filter(e=>Si(e,r)),v=g.filter(e=>!Si(e,r)),y=n?g.filter(e=>n.ids.includes(e.id)):t?_.filter(e=>at(e.nextAt,r)===t):_,b=i?y.filter(e=>YH(e,i)):y,x=i?p.filter(e=>YH(e.entry,i)):p,S={soon:0,day:0,twoDay:0,week:0,later:0,unarmed:0,total:0};for(let e of[..._.map(e=>e.nextAt),...o.map(e=>e.nextAt),...p.map(e=>e.entry.nextAt)])S.total++,S[at(e,r)]++;return{cards:_,spentCards:v,shownCards:b,pendingCards:m,live:o,gone:c,shown:u,pending:p,shownPending:x,goneByRepo:d,horizon:S,kinds:{rules:_.length,timed:o.length+p.length},standingTotal:S.total,cutTotal:y.length+l.length+p.length,shownTotal:b.length+u.length+x.length}}var qH=e=>e.split(`/`).filter(Boolean).pop()??``;function JH(e,t){return`${VH(e)}\n${LH(e)??``}\n${qH(e.cwd)}`.toLowerCase().includes(t)}function YH(e,t){let n=Ka(e.action);return`${Ar(e.name,n)??``}\n${n}\n${XH(e).map(qH).join(` `)}`.toLowerCase().includes(t)}var XH=e=>e.action.kind===`fanout`?e.action.dirs:[e.action.repoDir];function ZH(e){let{cuts:t,repoOf:n,now:r}=e,i=new Map,a=(e,t,a)=>{let o=new Set;for(let t of e){let e=t?n(t):null;e&&o.add(e)}for(let e of o){let n=i.get(e);n||(n={ids:[],horizon:{soon:0,day:0,twoDay:0,week:0,later:0,unarmed:0,total:0}},i.set(e,n)),n.ids.push(t),n.horizon.total++,n.horizon[at(a??null,r)]++}};for(let e of t.cards)a(XH(e),e.id,e.nextAt);for(let e of t.live)a([e.cwd],e.id,e.nextAt);for(let e of t.pending)a(XH(e.entry),e.entry.id,e.entry.nextAt);return i}function QH(e,t){return`the ${t} on a clock in ${e}`}function $H(e){return e?`schedule deleted — and ${e===1?`the queue row that named it`:`${e} queue rows that named it`}`:`schedule deleted`}function eU(e){return e.filter(e=>e.mode===`op`&&e.op?.t===`schedule.save`).map(e=>({entry:e.op.entry,failed:e.status===`failed`}))}function tU(e){return`the ${e} one-off${e===1?` that has`:`s that have`} been and gone`}var nU=G(IE().v),rU=G(IE().at),iU=G(null),aU=G(null);function oU(){return K(nU)}function sU(e,t,n){let r=K(nU),i=(0,H.useMemo)(()=>eU(t),[t]);return(0,H.useMemo)(()=>KH({intents:e,entries:r,pending:i,focus:null,focusIds:null,now:Date.now()}),[e,r,i,n])}function cU(e){if(e.source!==`queue`)return`this one lives on the desktop — run it again from its own row`;if(e.bucket!==`failed`&&e.blockReason!==`sessionGone`)return`this one has not failed — it is still on its way`;if(!e.cwd)return`nothing recorded which repo these words were for`;let t=e.actions.find(e=>e.id===`retry`)??e.actions.find(e=>e.id===`sendNow`);return t?t.disabledReason??null:`this row is not a message that can be sent again`}function lU(e){return e.dismissedAt==null?e.state===`running`||e.state===`starting`?`this one is running — stopping it is “cancel”`:null:`already filed`}function uU(e,t){let n=[],r=[];for(let i of e){let e=t(i);e?r.push({row:i,why:e}):n.push(i)}return{go:n,skip:r}}var dU=3,fU=70;function pU(e,t){let n=[],r=e.length,i=r===1?`row`:`rows`;t.verb===`dismiss`?(n.push(`${r} ${i} filed away as dealt with.`),n.push(`Nothing is deleted: the words, the verdict and the buttons stay on the row, under the “dismissed” chip, and “bring back” undoes this.`)):t.verb===`restore`?n.push(`${r} ${i} back in the list.`):(n.push(`${r} ${r===1?`message goes`:`messages go`} out again as backlog items, each in the repo it was written for.`),n.push(`They run one at a time per repo, each in a new session. Nothing is re-typed and nothing is asked.`));let a=new Map,o=0;for(let t of e)t.cwd?a.set(t.cwd,(a.get(t.cwd)??0)+1):o+=1;let s=[...a.entries()].sort((e,t)=>t[1]-e[1]).map(([e,n])=>`${t.repoName(e)} ${n}`);o&&s.push(`no repo recorded ${o}`),s.length&&n.push(s.join(` · `));for(let t of e.slice(0,dU)){let e=(t.title||``).replace(/\s+/g,` `).trim();n.push(`“${e.length>fU?`${e.slice(0,fU)}…`:e}”`)}return r>dU&&n.push(`…and ${r-dU} more`),t.skipped&&n.push(`${t.skipped} of the selected ${t.skipped===1?`row is`:`rows are`} left alone — each says why on its own row.`),n}function mU(e,t){return e===`failed`?`failed`:e===`done`||e===`canceled`?`done`:e===`running`||e===`starting`?`running`:t===`sessionGone`||t===`gate`||t===`awaitingAnswer`||t===`auth`?`needsYou`:t===`notYet`?`scheduled`:`waiting`}function hU(e,t,n){let{online:r,now:i,deps:a}=t,o=gr(e),s=FH[o],c=e.blockReason??null,l=LH(e),u=o===`schedule`&&RH(e,i),d=wH(VH(e)),f=t.sessions?.find(t=>t.id===e.sessionId),p=u?qr:null,m=e.state===`done`||e.state===`failed`||e.state===`canceled`,h=e.state===`running`||e.state===`starting`,g=e.target.kind===`repo`,_=Kr(e)?{note:L_e}:g||e.target.kind===`session`?{note:g&&wM(e.cwd,t.intents??[],e.id,t.sessions)?`${SM(g)} — ${CM}`:SM(g)}:{},v=Mi(e)?sa:``,y=ga(e)&&e.trigger.kind===`at`?va(e.trigger.rule):``,b=a.repoName(e.cwd),x=e.target.kind===`repo`&&zH(e.result?.detail,b),S=[e.target.kind===`repos`?`${e.target.dirs.length} ${e.target.dirs.length===1?`repo`:`repos`}`:e.target.kind===`sessions`?`${e.target.sessionIds.length} sessions`:f?.title??(e.target.kind===`repo`?e.resume?`${x?``:`${b} · `}picking up the last conversation`:x?``:`${b} · in a new session`:e.target.kind===`session`?`in ${t.sessions?.find(t=>t.id===e.target.sessionId)?.title??b}`:b),v,y].filter(Boolean).join(` · `),C=e.trigger.kind===`files`?e.trigger.needs:null,w=n?.followUps,T=w?.length?w[w.length-1]:null,E=e.result?.artifacts??[],D=[];if(o===`launch`)D.push(AH(`runNow`,`open it without the files`,{primary:e.state===`blocked`,disabledReason:e.state===`blocked`?jH(r,`opening it`):`it is not waiting any more`}),AH(`cancel`,`call it off`,{danger:!0,disabledReason:m?`it is not waiting any more`:jH(r,`calling it off`)}));else if(o===`schedule`)D.push(AH(`runNow`,`run it now`,{primary:!0,disabledReason:h?`it is firing`:jH(r,`running it`),..._}),AH(`toggle`,e.nextAt==null?`switch it on`:`switch it off`,{disabledReason:p??jH(r,`the switch`)}),AH(`edit`,`edit the schedule`,{disabledReason:jH(r,`an edit`)}),AH(`cancel`,`delete it`,{danger:!0,disabledReason:jH(r,`deleting it`)}));else if(o===`fanout`){let e=n?.targets.find(e=>e.sessionId);D.push(AH(`open`,`open a session from it`,{primary:!0,disabledReason:e?void 0:`no session was opened by this sweep`}),AH(`sendNow`,`send a follow-up to these sessions`,{disabledReason:e?jH(r,`a follow-up`):`no session is left to drive`}))}else o===`build`||o===`capture`?D.push(AH(`download`,E.length===1?`download what it made`:`download (${E.length})`,{primary:E.length>0,disabledReason:E.length?void 0:`it produced no file to fetch`}),AH(`cancel`,`stop it`,{danger:!0,disabledReason:h?jH(r,`stopping it`):`it is not running`}),AH(`runNow`,`run it again`,{disabledReason:jH(r,`a run`)})):D.push(AH(`sendNow`,`run it now`,{primary:e.state===`queued`||e.state===`blocked`,disabledReason:h?`it is running`:e.state===`done`?`it already ran`:jH(r,`running it`),..._}),AH(`check`,`check whether it is already done`,{primary:e.state===`failed`,disabledReason:jH(r,`a check`)}),AH(`edit`,`rewrite it`,{disabledReason:h?`it is running — rewriting it now would change work already in flight`:jH(r,`an edit`)}),AH(`retarget`,`aim it at another session`,{disabledReason:h?`it is running`:jH(r,`a re-aim`)}),AH(`toggle`,e.pinned?`stop firing it on its own`:`fire it on its own`,{disabledReason:m?`it has already run`:jH(r,`the switch`)}),AH(`discard`,`remove it`,{danger:!0,alwaysShown:!0,disabledReason:jH(r,`removing it`)}));e.sessionId&&D.push(AH(`open`,`open the session`,{alwaysShown:!0,disabledReason:f?void 0:`that session is not open any more`}));let O=BH(e,o,i,n),k=!!e.result?.detail&&O.includes(e.result.detail);return{key:EH(e.id),id:e.id,source:s,kind:IH[o],state:e.state,bucket:mU(e.state,c),blockReason:c,verdict:O,...d,fullText:l,attachText:o===`build`?null:l,where:S,cwd:e.cwd||null,sessionId:e.sessionId??null,delivery:null,at:e.settledAt??e.startedAt??e.createdAt,createdAt:e.createdAt,dueAt:e.trigger.kind===`at`?e.nextAt??null:e.trigger.kind===`files`&&e.state===`blocked`?e.trigger.deadlineAt:null,asOf:r?null:t.hostSeenAt,progress:C?.length?{done:C.length-(e.missing?.length??0),total:C.length,label:`files`}:n?{done:n.targets.filter(e=>e.status===`done`).length,total:n.targets.length,label:`repos`}:null,targets:n?n.targets.map(e=>({label:e.title||MH(e.dir),sessionId:e.sessionId,state:gU[e.status]??`queued`,detail:e.error})):[],lastRun:T?{at:T.at,ok:!0,detail:`follow-up sent to ${T.dirs.length} of them`}:e.result&&!(k&&m&&!e.result.late)?{at:e.result.at,ok:e.result.ok,detail:k?``:e.result.detail,late:e.result.late}:null,attempts:e.attempts??0,actions:D,subject:{source:`intent`,intent:e,run:n},...o===`build`?_U(e,t.intents??[]):{}}}var gU={pending:`queued`,starting:`starting`,running:`running`,done:`done`,failed:`failed`};function _U(e,t){let n=rR(e,t);return n?{fromSchedule:n}:{}}function vU(e,t){let n=e.state===`downloading`?`running`:e.state===`done`?`done`:e.state===`failed`?`failed`:e.state===`paused`?`blocked`:`queued`,r=e.item.size?Math.floor(e.received/e.item.size*100):0,i=e.rate?`${yU(Math.round(e.rate))}/s`:null,a=`downloaded${e.item.size?` · ${yU(e.item.size)}`:``}`,o=n===`running`?`${r}% — ${i??`waiting for bytes`}`:n===`failed`?e.error||`the transfer stopped and nothing said why`:n===`blocked`?`paused — it resumes from where it stopped`:n===`done`?e.savedTo?`${a} · ${e.saveVia===`browser`?`handed to`:`saved to`} ${e.savedTo}`:e.evicted?`${a} — the bytes were cleared to make room; fetching again is one tap`:`${a} · on this phone`:r>0?`queued — ${r}% already here from an earlier attempt`:`queued`;return{key:`pull:${e.item.id}`,id:e.item.id,source:`pull`,kind:`download`,state:n,bucket:mU(n,null),blockReason:null,verdict:o,title:e.item.name,clipped:!1,fullText:null,attachText:null,where:e.item.repoName||t.deps.repoName(e.item.repoDir),cwd:e.item.repoDir,sessionId:null,delivery:null,at:e.updatedAt,createdAt:e.item.ts,dueAt:e.nextRetryAt??null,asOf:null,progress:n===`running`||n===`blocked`?{done:e.received,total:e.item.size,label:`bytes`}:null,targets:[],lastRun:null,attempts:e.attempts,actions:[AH(`save`,`save to phone`,{primary:n===`done`&&!e.evicted,disabledReason:n===`done`&&!e.evicted?void 0:`there is nothing downloaded to save yet`}),AH(`retry`,n===`failed`?`try again`:`fetch it now`,{primary:n!==`done`,disabledReason:n===`running`?`it is downloading`:n===`done`&&!e.evicted?`it is already on this phone — save it out instead`:void 0}),AH(`discard`,`drop it`,{danger:!0,alwaysShown:!0})],subject:{source:`pull`,record:e}}}var yU=e=>e>=1e9?`${(e/1e9).toFixed(1)} GB`:e>=1e6?`${(e/1e6).toFixed(1)} MB`:e>=1e3?`${Math.round(e/1e3)} kB`:`${e} B`,bU=15e4,xU=new Set([`unconfirmed`]);function SU(e,t){return e.status!==`failed`||e.hostSettled||!e.failState||!xU.has(e.failState)?!1:t-(e.failedAt??e.sentAt??e.ts)<bU}function CU(e){return e===1?`1 message typed — confirming it ran; types it again itself if not`:`${e} messages typed — confirming they ran; types one again itself if not`}var wU=`the desktop is still confirming this one — it may be running, and it re-sends it itself if it never landed`;function TU(e){return e.status===`failed`&&(!e.failState||e.failState===`other`)}function EU(e){return e.status===`failed`&&(e.failState===`unconfirmed`||e.failState===`unsubmitted`)}function DU(e,t){return e.status===`pending`?`sending`:e.status===`queued`?e.retryAt!=null&&e.retryAt>t?`retrying`:`waiting`:SU(e,t)?`confirming`:TU(e)?`failed-retryable`:EU(e)?`failed-unknown`:`failed-final`}function OU(e){return e===`failed-retryable`||e===`failed-unknown`||e===`failed-final`}var kU={waiting:`waiting`,retrying:`retrying`,sending:`sending`,confirming:`confirming it ran`,"failed-retryable":`not delivered`,"failed-unknown":`may be in that session`,"failed-final":`refused`},AU={waiting:``,retrying:``,sending:`already on its way`,confirming:`the desktop is still confirming this one — it may be running`,"failed-retryable":`it didn't go through — try it again first`,"failed-unknown":`it may already be in that session — open it and look, or rewrite it`,"failed-final":`the desktop refused it — rewrite it to send it as a new one`};function jU(e,t,n){return e===`unconfirmed`?`Typed — the desktop is confirming it ran. It re-sends it itself if it never landed.`:e===`unsubmitted`?`Typed, but it is still sitting in that session's box — open it and press Return. The desktop won't send it again.`:n?`Not sent — ${t}. Your words are kept; the row is below.`:`Not sent — ${t}. Your words are kept below — restore or re-aim them.`}function MU(e,t){let n=null;for(let r of e){if(!SU(r,t))continue;let e=(r.failedAt??r.sentAt??r.ts)+bU-t;(n==null||e<n)&&(n=e)}return n}function NU(e,t,n){let r=[];return e>0&&r.push(e>1?`${e} were typed and the desktop is still confirming that they ran — it types them again itself if not.`:`1 was typed and the desktop is still confirming that it ran — it types it again itself if not.`),t>0&&r.push(t>1?`${t} may already be in their sessions — open each and look, or rewrite them to send fresh copies.`:`1 may already be in its session — open it and look, or rewrite it to send a fresh copy.`),n>0&&r.push(n>1?`The desktop refused ${n} — rewrite them to send as new ones.`:`The desktop refused 1 — rewrite it to send as a new one.`),r}function PU(e){return e.status===`failed`&&e.failState===`unconfirmed`}function FU(e,t){let n=e.prompt?.kind===`trust`?fle(t??null,e.backend):void 0;return{turnActive:e.turnActive,limitBlocked:e.limit?.blocked,promptKind:e.prompt?.kind,awaitingInput:e.awaitingInput,block:fte(e),...n===!1?{trustAutoAccepted:!1}:{}}}var IU=(e,t)=>e.map(e=>({id:e.id,cwd:e.cwd,running:e.running,turnStartedAt:e.turnStartedAt,...FU(e,t),name:Yn(e)}));function LU(e,t,n){return ne(e?de(IU(t,n),[]).get(e):void 0)}var RU={gate:`gate`,budget:`budget`,sessionBudget:`sessionBudget`,sessionGone:`sessionGone`,serial:`serial`,held:`sessionBusy`,lane:`sessionBusy`,inflight:`sessionBusy`,pendingCreate:`sessionBusy`,backoff:null},zU={held:`held until the agent finishes this turn`,lane:`another message for that session is going out first`,inflight:`a delivery for that session is already in flight`,pendingCreate:`waiting for its session to open`},BU={unconfirmed:`unconfirmed`,unsubmitted:`unsubmitted`,stale:`refused`,refused:`refused`,other:`unknown`},VU=e=>e?BU[e]:`unknown`,HU={unconfirmed:`it was typed into the session and the desktop could not read the screen back — it may have run. Sending it again could run it twice: open the session and look, or rewrite it to send a fresh copy.`,unsubmitted:`the words are already sitting in that session's composer — open it and press Return. Sending again would leave two copies.`,stale:`the desktop refused this one because the question it answers is gone, and it remembers refusing it — a re-send is answered with the same no. Answer the question that is up now.`,refused:`the desktop answered no and remembers it, so this exact message can only be refused again — rewrite it to send it as a new one.`,other:void 0};function UU(e,t){return e.answer?`answer`:e.mode===`upload`?`upload`:e.mode===`op`?t.isCreateOp(e)?`prompt`:`action`:`prompt`}function WU(e,t){let{deps:n,now:r,online:i}=t,a=UU(e,n),o=t.queueBlocked?.get(e.ackId),s=(e.mode??`input`)===`input`&&!!t.goneLanes?.has(e.sessionId),c=DU(e,r),l=c===`sending`?`starting`:OU(c)?`failed`:`queued`,u=null,d,f=c===`confirming`;if(f&&(l=`running`,d=`the desktop is confirming whether it ran — it types it again itself if it never did`),e.status===`queued`){if(!i)u=`offline`;else if(s)u=`sessionGone`;else if(o){if(u=RU[o],d=zU[o],o===`serial`&&t.sessions&&(d=LU(e.serial,t.sessions)),o===`backoff`){let t=e.retryAt&&e.retryAt>r?e.retryAt-r:null,n=t==null?null:t<6e4?`${Math.max(1,Math.round(t/1e3))}s`:`${Math.round(t/6e4)} min`,i=e.waitReason??`a send just failed`;d=n?`${i} — trying again in ${n}`:`${i} — trying again in a moment`}if(o===`held`){let n=t.sessions?.find(t=>t.id===e.sessionId),r=n?jt({...FU(n),turnActive:void 0}):null;r===`limit`||r===`auth`||r===`net`?(u=r,d=void 0):(n?.awaitingInput||n?.prompt&&n.prompt.kind!==`trust`)&&(u=`awaitingAnswer`,d=n.prompt?`the session is waiting on a question — “${(n.prompt.ask||n.prompt.question).slice(0,80)}”`:`the session is showing a dialog it wants an answer to`)}}(u||d)&&(l=`blocked`)}let p=e.failedAt??e.sentAt??e.ts,m=l===`failed`?PH(e.reason,p,r,`it never went — nothing here says why, so treat it as unrun only if the session shows nothing`):l===`starting`?`on its way to the desktop`:u?dr(u,d):d??`next in line`,h=n.isEditableEntry(e)||e.status===`failed`&&a===`prompt`,g=e.mode===`upload`||e.mode===`op`||!!e.answer,_=e.status===`pending`,v=kH(e),y=a===`upload`?e.upload?.relPath??null:a===`answer`?null:v||null,b=u===`awaitingAnswer`,x=e.status===`failed`?f?wU:e.failState?HU[e.failState]:void 0:void 0,S=[...b?[AH(`answer`,`answer the question`,{primary:!0})]:[],AH(`sendNow`,e.status===`failed`?`try again`:`send now`,{primary:!b,disabledReason:_?`already on its way`:x??(!i&&e.status!==`failed`?`no connection yet — it goes out when the link is back`:void 0)}),AH(`hold`,e.holdUntilIdle?`send without waiting`:`wait for the agent`,{disabledReason:_?`already on its way`:g?`this one is an action or a file, not text — there is no turn to wait for`:void 0}),AH(`retarget`,`aim it elsewhere`,{disabledReason:_?`already on its way`:e.answer?`an answer names one question box in one session — it cannot go anywhere else`:e.mode===`upload`?`a file goes to the repo inbox its path names`:e.mode===`op`?`this one is an action — its payload already names its own subject`:void 0}),AH(`edit`,`rewrite it`,{primary:!!x,disabledReason:h?void 0:_?`already on its way`:e.answer?`an answer is the option you tapped, not text`:e.mode===`upload`?`a file has no words to rewrite`:`this one is an action, not text`}),AH(`fix`,`fix its files & send`,{disabledReason:e.answer||e.mode===`upload`?`there are no words on this row to rewrite`:void 0}),...PU(e)?[AH(`confirmDone`,`save as done`,{disabledReason:f?wU:_?`already on its way`:void 0})]:[],AH(`discard`,`discard`,{danger:!0,alwaysShown:!0,disabledReason:_?`already on its way`:void 0})];e.sessionId&&!e.sessionId.startsWith(`create:`)&&S.push(AH(`open`,`open the session`,{alwaysShown:!0,disabledReason:s?`that session is gone`:void 0}));let C=wH(a===`answer`&&e.answer?`${e.answer.label} — ${e.answer.question}`:v);return{key:TH(e.ackId),id:e.ackId,source:`queue`,kind:a,state:l,bucket:mU(l,u),blockReason:u,verdict:m,...C,fullText:a===`upload`||a===`answer`?null:v,attachText:y,where:n.laneLabel(e),cwd:e.cwd||null,sessionId:e.sessionId.startsWith(`create:`)?null:e.sessionId,delivery:e.status===`failed`?VU(e.failState):null,at:p,createdAt:e.ts,dueAt:null,asOf:null,progress:null,targets:[],lastRun:null,attempts:e.attempts??0,actions:S,subject:{source:`queue`,entry:e}}}var GU={needsYou:0,failed:1,running:2,waiting:3,scheduled:4,done:5},KU=new Map(Xee.map((e,t)=>[e,t]));function qU(e,t){let n=GU[e.bucket]-GU[t.bucket];if(n)return n;if(e.bucket===`scheduled`){let n=e.dueAt??2**53-1,r=t.dueAt??2**53-1;if(n!==r)return n-r}if(e.bucket===`waiting`||e.bucket===`needsYou`){let n=e.blockReason?KU.get(e.blockReason)??99:99,r=t.blockReason?KU.get(t.blockReason)??99:99;if(n!==r)return n-r}return t.at-e.at}function JU(e){let t=[];for(let n of e.outbox??[])t.push(WU(n,e));let n=e.intents??[],r=new Map;for(let e of Fr(n))r.set(e.id,e);let i=new Set((e.outbox??[]).map(e=>e.ackId));for(let a of n){if(a.archived||a.groupId!=null&&a.groupId!==a.id)continue;let n=a.groupId?r.get(a.groupId)??null:null;if(i.has(a.id)&&(a.state===`queued`||a.state===`blocked`||a.state===`starting`)){let e=t.findIndex(e=>e.subject.source===`queue`&&e.id===a.id);e>=0&&t.splice(e,1)}t.push(hU(a,e,n))}for(let n of e.pulls??[])t.push(vU(n,e));let a=e.dismissed;if(a?.size)for(let e of t){let t=a.get(e.key);t!=null&&(e.dismissedAt=t)}let o=e.confirmedDone;if(o?.size)for(let e of t){let t=o.get(e.key);t!=null&&(e.confirmedDoneAt=t,e.bucket=`done`,e.state=`done`,e.blockReason=null,e.verdict=`you marked this done ${new Date(t).toLocaleString()} — the desktop's own check never confirmed it`)}for(let e of t)e.actions.push(AH(`dismiss`,`save for later`,{disabledReason:lU(e)??void 0}));return t.sort(qU)}var YU=new Set([`needsYou`,`failed`,`running`,`waiting`]),XU=[{id:`open`,label:`open`},{id:`all`,label:`all`},{id:`needsYou`,label:`needs you`},{id:`failed`,label:`failed`},{id:`running`,label:`running`},{id:`waiting`,label:`waiting`},{id:`scheduled`,label:`scheduled`},{id:`done`,label:`done`},{id:`dismissed`,label:`dismissed`}];function ZU(e,t){return t===`dismissed`?e.dismissedAt!=null:e.dismissedAt==null?t===`open`?YU.has(e.bucket):t===`all`||e.bucket===t:!1}function QU(e){let t={open:0,all:0,needsYou:0,failed:0,running:0,waiting:0,scheduled:0,done:0,dismissed:0};for(let n of e)n.dismissedAt==null?(t.all+=1,t[n.bucket]+=1,YU.has(n.bucket)&&(t.open+=1)):t.dismissed+=1;return t}function $U(e,t){let n=e.filter(e=>e.dismissedAt==null);if(!t){let e=n.filter(e=>e.blockReason===`offline`).length;if(e)return{text:`${e} ${e===1?`thing is`:`things are`} still on this phone — nothing expires while the link is down`,cut:null}}let r=n.filter(e=>e.bucket===`needsYou`).length;if(r)return{text:`${r} ${r===1?`row needs`:`rows need`} a decision from you`,cut:`needsYou`};let i=n.filter(e=>e.bucket===`failed`).length;return i?{text:`${i} ${i===1?`thing`:`things`} never ran`,cut:`failed`}:null}function eW(e){if(e.kind===`upload`||e.kind===`download`||e.kind===`build`)return null;let t=(e.fullText??e.title).trim();if(!t)return null;let n=t.toLowerCase().replace(/\s+/g,` `).trim();return n.replace(/[.!?…]+$/u,``).trim()||n}var tW=new Set(`continue.continue please.please continue.go on.carry on.keep going.done.finished.did it work.any progress.progress.status.update.try again.again.retry.redo.rerun.run it again.ok.okay.k.yes.yep.yeah.sure.no.nope.n.y.thanks.thank you.ty.hi.hello.test.ping.hmm.next.next step.proceed.go.go ahead.stop.wait.fix.fix it.fix this.do it.continue working.and`.split(`.`));function nW(e){let t=eW(e);return!t||e.clipped||/[\n`/.]/.test(t.slice(1))?!1:tW.has(t)||/^\/[a-z][\w-]*$/.test(t)?!0:t.split(` `).length===1&&t.length<=3}function rW(e,t){return t===`ranked`?[...e]:[...e].sort((e,t)=>e.at-t.at)}function iW(e,t,n){let r=new Map;for(let e of t){let t=eW(e);if(!t)continue;let n=r.get(t);n?n.push(e):r.set(t,[e])}let i=[],a=new Map;for(let t of e){let e=eW(t),r=n.group&&e?`t:${e}`:t.key,o=a.get(r);if(o){o.rows.push(t),o.oldestAt=Math.min(o.oldestAt,t.at),o.newestAt=Math.max(o.newestAt,t.at),t.cwd&&!o.cwds.includes(t.cwd)&&o.cwds.push(t.cwd);continue}let s={key:r,rows:[t],elsewhere:{done:0,other:0},cwds:t.cwd?[t.cwd]:[],oldestAt:t.at,newestAt:t.at};a.set(r,s),i.push(s)}for(let e of i){let t=eW(e.rows[0]);if(!t)continue;let n=new Set(e.rows.map(e=>e.key));for(let i of r.get(t)??[])n.has(i.key)||(i.dismissedAt??(i.bucket===`done`?e.elsewhere.done+=1:e.elsewhere.other+=1))}return i}var aW=e=>e.status===`failed`&&!e.calledOff,oW=e=>e.calledOff?`done`:e.status,sW=e=>e.calledOff===`agent`?`withdrawn`:e.calledOff?`called off`:e.status,cW=e=>e.calledOff?`calledoff`:e.status,lW=e=>e.status===`done`||e.status===`failed`&&e.calledOff!==`agent`,uW=36e5,dW=[`hour`,`day`,`week`,`older`],fW={hour:`past hour`,day:`past 24h`,week:`past week`,older:`older`},pW=[`running`,`queued`,`failed`,`done`];function mW(e,t){let n=Math.max(0,t-e);return n<=uW?`hour`:n<=24*uW?`day`:n<=168*uW?`week`:`older`}function hW(e,t,n){let r=mW(e,n);if(t===`older`)return r===`older`;let i={hour:0,day:1,week:2,older:3};return i[r]<=i[t]}var gW=[...Xa,`none`];function _W(e){return e.category??`none`}var vW={bug:Me(`bug`),feature:Me(`feature`),enhancement:Me(`enhancement`),chore:Me(`chore`),none:S};function yW(e,t){return t?`show every kind again`:e===`none`?`show only the items nothing has said a kind for — the rows a naming pass is for`:`show only the ${e===`bug`?`bugs`:`${e}s`}`}var bW=`no connection — the backlog lives on the desktop, so nothing here changed. Adding still queues.`,xW=`no connection — the desktop is holding this one. It stays held; try again when the link is back.`,SW={status:null,age:null,category:null,ids:null,clock:null},CW=e=>!!(e.status||e.age||e.category||e.ids||e.clock);function wW(e,t,n){return!(t.ids&&!t.ids.includes(e.id)||t.status&&oW(e)!==t.status||t.age&&!hW(e.createdAt,t.age,n)||t.category&&_W(e)!==t.category||t.clock&&!e.at)}function TW(e,t){let n=[];if(e.status&&n.push(e.status),e.category&&n.push(e.category===`none`?`with no kind`:`${e.category===`bug`?`bug`:e.category}s`),e.clock&&n.push(`on a clock`),e.age&&n.push(e.age===`older`?`added over a week ago`:`added in the ${fW[e.age]}`),e.ids){let e=t?.trim()||`made from these`;return n.length?`${e} · ${n.join(` · `)}`:e}return n.length?`showing ${n.join(` · `)}`:`showing everything`}function EW(e){return!!e.archived&&e.status!==`running`}var DW={newest:`newest first`,run:`run order`},OW=`the number is each row's place in the run order — switch to run order to move rows`,kW=`the on-a-clock cut is always in run order`;function AW(e,t){return t?`run`:e}function jW(e,t){return t===`run`?e:[...e].sort((e,t)=>t.createdAt-e.createdAt)}function MW(e){return new Map(e.map((e,t)=>[e.id,t+1]))}function NW(e,t,n){let r={running:0,queued:0,failed:0,done:0},i={hour:0,day:0,week:0,older:0},a={bug:0,feature:0,enhancement:0,chore:0,none:0},o=0,s={status:0,age:0,category:0,clock:0};for(let c of e){if(t.ids&&!t.ids.includes(c.id))continue;let e=oW(c),l=!t.status||e===t.status,u=!t.age||hW(c.createdAt,t.age,n),d=!t.category||_W(c)===t.category,f=!t.clock||!!c.at;if(u&&d&&f&&(r[e]=(r[e]??0)+1,s.status++),l&&d&&f){s.age++;for(let e of dW)hW(c.createdAt,e,n)&&i[e]++}l&&u&&f&&(a[_W(c)]++,s.category++),l&&u&&d&&(s.clock++,c.at&&o++)}return{status:r,age:i,category:a,clock:o,pool:s}}function PW(e,t){let n=(e,t,n,r=!1)=>n||e>0&&(r||e<t);return{status:pW.filter(r=>n(e.status[r],e.pool.status,t.status===r,r===`failed`||r===`done`)),age:dW.filter(r=>n(e.age[r],e.pool.age,t.age===r)),category:gW.filter(r=>n(e.category[r],e.pool.category,t.category===r)),clock:n(e.clock,e.pool.clock,!!t.clock,!0)}}function FW(e,t){let n=e.fresh+e.aimed;if(n<=0)return null;let r=e.held+e.other,i=r?` The other ${r} here ${r===1?`is`:`are`} not going to start — each row says why.`:``;if(!t)return`auto is off on this desktop, so ${n===1?`this one does not start on its own`:`none of these ${n} start on their own`}. Turn auto back on, or ${n===1?`tap fire on the row to start it now`:`tap fire on a row to start that one now`}.${i}`;let a=n===1?` fire on the row starts it now.`:` fire on a row starts that one now.`,o=e.aimed===0&&n>1?`, in the order you see`:``,s;if(e.aimed===0)s=e.fresh===1?`this one starts when the repo is free, in a session of its own`:`these ${e.fresh} start one at a time in this repo, each in a session of its own${o}`;else if(e.fresh===0)s=e.aimed===1?`this one starts in the session it is aimed at, as soon as that session is free`:`these ${e.aimed} start in their sessions, each as soon as its session is free`;else{let t=e.aimed===1?`1 in the session it is aimed at`:`${e.aimed} in their sessions`;s=`of these ${n}, ${e.fresh} start in a session of their own and ${t}, each as soon as what it waits for is free`}return`auto is on: ${s}.${a}${i}`}function IW(e,t,n){return`${e} of ${t}${n.ids?`, archived included`:``}`}function LW(e){return`archive ${e===1?`this one`:`these ${e}`}`}function RW(e,t){return`${e===t?`every one of the ${t} rows here is finished`:`${e===1?`one row`:`${e} rows`} of the ${t} shown ${e===1?`is`:`are`} finished and not yet archived — the rest are already archived and are left alone`}. Archiving is not deleting: the words stay, the archived count keeps them, and any one of them can be brought back from its own row.`}function zW(e){return e===1?`archived — its words stay, and show archived still lists it`:`${e} archived — their words stay, and show archived still lists them`}function BW(e){return`assess ${e===1?`this one`:`these ${e}`}`}function VW(e,t){return`${e===t?`every one of the ${t} rows here is still open`:`${e===1?`one row`:`${e} rows`} of the ${t} shown ${e===1?`is`:`are`} still open — the rest are finished or running and cannot be judged`}. It still reads the whole repo as evidence — what narrows is which rows it may return a verdict on.`}var HW=`assess: nothing in this cut is still open — an assessment judges work that is waiting or failed, and these rows are finished or running`;function UW(e){return e.filter(e=>!e.archived&&(e.status===`queued`||aW(e))).map(e=>e.id)}function WW(e,t,n){let r=va(e.rule);return e.nextAt!=null&&n===`queued`?`${r} · next ${Dn(e.nextAt,t)}`:e.rule.kind===`window`&&n===`queued`?`${r} · waiting for a usage reading`:r}var GW=e=>e.at?tte(e.at.rule,e.at.graceMin,e.holdForHost):null;function KW(e){let t=[],n=new Map;for(let r of e){let e=r.calledOff?null:GW(r);if(!e)continue;let i=n.get(e);i||(i={key:e,at:r.at?.nextAt??null,hold:!!r.holdForHost,items:[]},n.set(e,i),t.push(i)),i.items.push(r)}return t}function qW(e,t){for(let n of e){let e=n.items.findIndex(e=>e.id===t);if(!(e<0))return n.items.length>1?{idx:e,of:n.items.length}:null}return null}var JW=[`1st`,`2nd`,`3rd`,`4th`,`5th`,`6th`,`7th`,`8th`,`9th`,`10th`],YW=e=>JW[e-1]??`${e}th`;function XW(e){return`${YW(e.idx+1)} of ${e.of} on this clock`}function ZW(e,t){let n=e.items.length,r=e.at==null?`waiting for a usage reading`:`${Dn(e.at,t)} · ${new Date(e.at).toLocaleString()}`,i=va(e.items[0].at.rule);return`${n} item${n===1?``:`s`} on one clock — ${i} · ${r}${e.hold?` · held until the desktop is free`:``}`}var QW=`moves it among the items waiting on this same clock — the instant does not change, and it never crosses an item on a different clock`;function $W(e){return`on a clock in ${e}`}function eG(e){return`been and gone on a clock in ${e}`}var tG=`holds until the desktop is free`;function nG(e){return e?`${tG} · survives a dropped clock`:tG}var rG=`let past the budget`;function iG(e){return e?`${rG} · undo`:rG}var aG=`held for the budget again`;function oG(e){return e===`failed`?`its instant has passed and a one-off cannot be re-armed — drop the clock and it waits its turn, where auto takes it from there`:`drop the clock and it runs in turn instead of at its time — the words and their place in the list stay`}var sG=`clock dropped — it waits its turn like any other item`;function cG(e){return e===1?sG:`clocks dropped on ${e} — they wait their turn like any other item`}function lG(e){return`drop the clocks on ${e===1?`this one`:`these ${e}`}`}function uG(e,t){return`${e===t?`every one of the ${t} rows here carries a clock`:`${e===1?`one row`:`${e} rows`} of the ${t} shown carr${e===1?`ies`:`y`} a clock — the rest have none and are left alone`}. Dropping a clock leaves the words where they are: they wait their turn, auto takes it from there, and any that hold until the desktop is free keep doing so.`}function dG(e){let t=`it failed, so nothing will pick it up again — put it back in the queue and it runs again `,n=` The failure it had stays on the row. “re-fire” beside it runs it this second instead.`;return e.targetSessionId?`${t}in the session it is aimed at, as soon as that session is free — auto takes it from there. It does not open a session of its own.${n}`:`${t}in a new session of its own when its turn comes, where auto takes it from there.${n}`}function fG(){return`it failed, and it is aimed at a session that has closed — nothing re-aims it, so putting it back in the queue would only make it wait for ever instead of stopping. Edit it to pick another session, or take the aim off so it opens a session of its own, and “run it again” comes back.`}var pG=`put back in the queue — it runs again when its turn comes`;function mG(e){return e===1?pG:`${e} put back in the queue — they run again as their turns come`}function hG(e,t){return e.status!==`failed`||e.calledOff||e.at||e.archived?`none`:e.targetSessionId&&!t.has(e.targetSessionId)?`held-closed`:`offered`}function gG(e,t){return hG(e,t)===`offered`}function _G(e,t){return e.filter(e=>gG(e,t)).map(e=>e.id)}function vG(e,t){return e.filter(e=>gG(e,t)&&!!e.targetSessionId).length}function yG(e){return`run ${e===1?`this one`:`these ${e}`} again`}function bG(e,t,n=0){return`${e===t?`every one of the ${t} rows here can go back in the queue`:`${e===1?`one row`:`${e} rows`} of the ${t} shown can go back in the queue — the rest carry a clock (they wear “drop the clock”), are aimed at a session that closed, or are set aside, and are left alone`}. ${n===0?`They run again one at a time in this repo, each in a session of its own, as their turns come — auto takes it from there`:n===e?`They run again in the session${e===1?``:`s`} they are aimed at, as ${e===1?`it comes`:`those come`} free — auto takes ${e===1?`it`:`them`} from there`:`${e-n} run again in a session of its own, one at a time in this repo, and ${n} in the session${n===1?``:`s`} ${n===1?`it names`:`they name`}, as those come free — auto takes them from there`}, and the failure each one had stays on its row.`}function xG(e,t,n){let r=SG(n-e.at),i=e.by===`run`?`started again ${r}`:`put back in the queue ${e.by===`assess`?`by the assessment`:`from the phone`} ${r}`,a=e.n!=null&&e.n>1?` (${CG(e.n)} time)`:``,o=e.error?` · failed before: “${e.error}”`:``;return t===`failed`?`failed again — it was ${i}${a}${o}`:t===`done`?`ran after being ${i}${a}${o}`:`${i}${a}${o}`}function SG(e){let t=Math.max(0,Math.round(e/1e3));if(t<60)return`${t}s ago`;let n=Math.round(t/60);if(n<60)return`${n}m ago`;let r=Math.round(n/60);if(r<24)return`${r}h ago`;let i=Math.round(r/24);return i<60?`${i}d ago`:`${Math.round(i/30)}mo ago`}function CG(e){let t=e%100;return t>=11&&t<=13?`${e}th`:`${e}${[`th`,`st`,`nd`,`rd`][e%10]??`th`}`}var wG={hand:`you typed this title`,assess:`titled by the assessment`,name:`titled by the naming pass`};function TG(e){return e===`hand`?`this title is yours — the assessment and the naming pass will not change it. Clear the field to let them suggest one again.`:`saving makes it yours — the assessment and the naming pass will not change it again. Clear the field to let them suggest one again.`}function EG(e){return`name ${e===1?`this one`:`these ${e}`}`}function DG(e){return e.filter(e=>!e.archived&&(e.status===`queued`||e.status===`failed`&&!e.calledOff)&&(zn(e)===null||!e.category)).map(e=>e.id)}function OG(e,t){return`${e===t?`all ${t} rows here need a title or a kind`:`${e} of the ${t} shown need a title or a kind — the rest have both, or are running, finished or set aside`}. Nothing you typed is replaced.`}function kG(e){return`asked the desktop to ${e} — the titles land on the rows as the pass answers, and anything you typed yourself is left alone`}function AG(e){let t=Math.max(0,Math.round(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return`${n}m ${t%60}s`;let r=Math.floor(n/60);return r<24?`${r}h ${n%60}m`:`${Math.floor(r/24)}d ${r%24}h`}function jG(e){return Ar(e.label,e.text,40)}var MG=`A new session (default)`,NG=`→ the session it was aimed at (closed)`;function PG(e,t){let n=[{value:``,label:MG}];for(let t of e)n.push({value:t.id,label:`→ ${Li(t)}`});return t&&!e.some(e=>e.id===t)&&n.push({value:t,label:NG}),n}function FG(e,t,n=[]){let r=e.status===`queued`&&e.holderSessionId?t.find(t=>t.id===e.holderSessionId&&t.running):void 0;if(!r)return null;let i=n.find(e=>e.sessionId===r.id&&ur({state:e.status,sessionId:e.sessionId},[r]));if(i)return{sessionId:r.id,itemId:i.id,cut:`the stalled item this row waits behind`,label:`show the stalled item`,title:`this row waits behind an item stalled on the API — it starts once that one gets a reply or you settle it`};let a=Yn(r)??`the session`,o=a.length>32?`${a.slice(0,31)}…`:a;return r.awaitingInput||r.asking||r.prompt&&r.prompt.kind!==`trust`?{sessionId:r.id,label:`answer in '${o}'`,title:`this row waits until that question is answered — open the session to answer it`}:{sessionId:r.id,label:`open '${o}'`,title:`the automatic session this row waits behind — it starts when that one is idle`}}function IG(e){return e.archived||e.status===`running`||e.status===`done`?!1:e.status!==`failed`||!!e.at&&!e.calledOff}function LG(e,t,n){let r=`${e} of ${t} picked`,i=n-t;return`${r}${i>0?` · ${i} ${i===1?`has`:`have`} no box: running, finished, archived, or failed with no clock to move`:``}. A new when replaces each one's — the words, where it goes and the place in the list stay.`}var RG=`tick the rows to move — the button appears with the count`;function zG(e,t){return e===1?`re-timed — the same row, now ${t}`:`re-timed ${e} — the same rows, now ${t}`}function BG(e,t,n,r){let i=e===1?`re-timed — now ${t}`:`re-timed ${e} — now ${t}`,a=n.length===1?` on ${n[0]}`:n.length>1?` on each repo's row`:``;return`${i}${`. Off the clock list: ${e===1?`it waits`:`they wait`} in the queue, ⌛${a}`}${r?` — held by the budget until ${r}`:``}.`}function VG(e){return e===1?`No clock: it leaves the ${fM.automation} clock list and waits in its repo's queue — the ⌛ chip on the repo's row.`:`No clock: these leave the ${fM.automation} clock list and wait in their repo's queue — the ⌛ chip on the repo's row.`}function HG(e,t){return t<=0?``:t>=e?` · budget`:` · ${t} budget`}function UG(e,t){let n=new Set(t.map(e=>e.id)),r=[];for(let t of e){let e=t.items.filter(e=>n.has(e.id)).map(e=>e.id);e.length<2||!t.items[0].at||r.push({key:t.key,rule:va(t.items[0].at.rule),ids:e})}return r}function dve(e){return`re-time the ${e.ids.length} on “${e.rule}”`}function fve(e){let t={waiting:[],failed:[]};for(let n of e)EW(n)||(n.status===`queued`||n.status===`running`?t.waiting.push(n.id):aW(n)&&t.failed.push(n.id));return t}function pve(e){return e.failed.length?e.waiting.length?`waiting, running or failed`:`failed`:`waiting or running`}function mve(e){let t=[];return e.waiting.length&&t.push(`${e.waiting.length} waiting or running`),e.failed.length&&t.push(`${e.failed.length} failed`),t.length?t.join(`, `):`nothing waiting`}function WG({picked:e,eligible:t,shown:n,onAll:r,onNone:i,onDone:a,onChoose:o,where:s}){return(0,J.jsx)(`div`,{className:`form`,children:(0,J.jsxs)(Z,{children:[LG(e,t,n),(0,J.jsxs)(`div`,{className:`annot-tools wrap`,style:{marginTop:6},children:[e>0?(0,J.jsxs)(Y,{title:`choose the new when — a time, a usage window, a condition, a repeat — for the ticked rows`,onClick:()=>{q(`action:${s}.retime.choose`),o()},children:[(0,J.jsx)(Ss,{size:14}),` `,e===1?`new when for it…`:`new when for these ${e}…`]}):(0,J.jsx)(`span`,{children:RG}),e<t&&(0,J.jsxs)(Y,{title:`tick every row on screen that can be re-timed`,onClick:r,children:[(0,J.jsx)(Do,{size:14}),` all `,t]}),e>0&&(0,J.jsxs)(Y,{title:`untick every row`,onClick:i,children:[(0,J.jsx)(Rc,{size:14}),` none`]}),(0,J.jsxs)(Y,{title:`close the pick list — nothing is changed`,onClick:a,children:[(0,J.jsx)(V,{size:14}),` done`]})]})]})})}function GG({children:e}){return(0,J.jsx)(`div`,{className:`retime-layer`,children:e})}function KG({on:e,onToggle:t}){return(0,J.jsx)(`button`,{className:`bl-pick`,"aria-pressed":e,"aria-label":e?`untick this row`:`tick this row to re-time it`,onClick:e=>{e.stopPropagation(),t()},children:e?(0,J.jsx)(Do,{size:18}):(0,J.jsx)(Rc,{size:18})})}function qG(e,t){let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}function hve({i:e,repoName:t,onOpen:n,pick:r}){let i=e.trigger.kind===`at`?e.trigger.rule:null,a=i&&e.nextAt&&!Da(i,e.nextAt)?fr(i,e.nextAt):null,o=t(e.cwd),s=(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`sched-clock-name`,children:VH(e)}),(0,J.jsxs)(`span`,{className:`sched-clock-when`,children:[i?va(i):`on a clock`,e.nextAt?(0,J.jsxs)(J.Fragment,{children:[` · next `,Pe(e.nextAt)]}):null,a?(0,J.jsxs)(J.Fragment,{children:[` · held until `,Pe(a),`, when its hours open`]}):null,e.holdForHost?(0,J.jsx)(J.Fragment,{children:` · waits until free`}):null]}),(0,J.jsx)(`span`,{className:`sched-clock-state`,children:gve(e)}),e.state===`blocked`&&e.blockReason&&e.blockReason!==`notYet`&&e.blockDetail?(0,J.jsx)(`span`,{className:`sched-clock-why`,children:e.blockDetail}):null]});return r===void 0?n?(0,J.jsxs)(`button`,{className:`sched-clock`,title:`open it in ${o}'s backlog — it is waiting work that happens to carry a clock, and every verb it has is on its row there`,onClick:()=>{q(`action:schedule.clockrow`),n(e.cwd,[e.id],$W(o))},children:[s,(0,J.jsx)(Vl,{size:13,className:`sched-clock-go`})]}):(0,J.jsx)(`div`,{className:`sched-clock`,children:s}):r?(0,J.jsxs)(`div`,{className:`sched-clock sched-clock-pick`,role:`button`,onClick:r.toggle,children:[(0,J.jsx)(KG,{on:r.on,onToggle:r.toggle}),(0,J.jsx)(`div`,{className:`sched-clock sched-clock-inner`,children:s})]}):(0,J.jsx)(`div`,{className:`sched-clock`,children:s})}function gve(e){return e.state===`starting`||e.state===`running`?`running`:e.state===`blocked`?`waiting`:e.state}function _ve({p:e,repoName:t,online:n}){let r=e.entry,i=r.action.kind===`backlog`?t(r.action.repoDir):``;return(0,J.jsxs)(`div`,{className:`sched-clock`,children:[(0,J.jsx)(`span`,{className:`sched-clock-name`,children:Ar(r.name,Ka(r.action))??Ka(r.action)}),(0,J.jsxs)(`span`,{className:`sched-clock-when`,children:[va(r.rule),r.nextAt&&!e.failed?(0,J.jsxs)(J.Fragment,{children:[` · next `,Pe(r.nextAt)]}):null,i?(0,J.jsxs)(J.Fragment,{children:[` · `,i]}):null]}),(0,J.jsx)(`span`,{className:`sched-clock-state`,children:(0,J.jsx)(YR,{phase:yd({queued:!0,failed:!!e.failed,onHost:!1,online:n}),thing:`this one`})})]})}function vve({rows:e,pending:t,repoName:n,online:r,onOpen:i,renderRetime:a,counted:o=!0}){let[s,c]=(0,H.useState)(!1),[l,u]=(0,H.useState)(()=>new Set),[d,f]=(0,H.useState)(!1);if(!e.length&&!t.length)return null;let p=r&&!!a,m=e.filter(GH),h=m.filter(e=>l.has(e.id)).map(e=>e.id),g=s&&p,_=()=>{c(!1),u(new Set)},v=[];for(let t of e){let e=v.find(([e])=>e===t.cwd);e?e[1].push(t):v.push([t.cwd,[t]])}return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`sched-head`,children:[(0,J.jsx)(Ss,{size:13}),` On a clock`,o?(0,J.jsxs)(J.Fragment,{children:[` · `,e.length+t.length]}):null,(0,J.jsx)(`span`,{className:`sched-head-note`,children:`waiting in their backlogs — the row is there, this is the door`})]}),p&&!g&&m.length>0&&(0,J.jsx)(`div`,{className:`bl-bulk`,children:(0,J.jsxs)(`button`,{className:`link-btn`,title:`tick the lines you want — in any repo — and move them all to one new time`,onClick:()=>{q(`action:schedule.retime.pick`),c(!0)},children:[(0,J.jsx)(Cs,{size:14}),` `,`pick to re-time`]})}),g&&(0,J.jsx)(WG,{picked:h.length,eligible:m.length,shown:e.length,where:`schedule`,onAll:()=>u(new Set(m.map(e=>e.id))),onNone:()=>u(new Set),onDone:_,onChoose:()=>f(!0)}),d&&a&&h.length>0&&(0,J.jsx)(GG,{children:a(h,{onSent:()=>{f(!1),_()},onCancel:()=>f(!1)})}),t.length>0&&(0,J.jsx)(`div`,{className:`sched-clocks`,children:t.map(e=>(0,J.jsx)(_ve,{p:e,repoName:n,online:r},e.entry.id))}),v.map(([e,t])=>(0,J.jsxs)(`div`,{className:`sched-clocks`,children:[(0,J.jsxs)(`div`,{className:`sched-clocks-repo`,children:[n(e),` · `,t.length]}),t.map(e=>(0,J.jsx)(hve,{i:e,repoName:n,onOpen:i,pick:g?GH(e)?{on:l.has(e.id),toggle:()=>u(t=>qG(t,e.id))}:null:void 0},e.id))]},e))]})}function yve({goneByRepo:e,repoName:t,onOpen:n}){return!e.length||!n?null:(0,J.jsxs)(Z,{className:`sched-spent`,children:[(0,J.jsx)(kc,{size:13,style:{verticalAlign:`-2px`}}),` `,`On a clock, and been and gone — run or missed, the row says which:`,(0,J.jsx)(`div`,{className:`annot-tools`,style:{marginTop:6},children:e.map(([e,r])=>(0,J.jsxs)(Y,{title:`show the ${r.length} timed one-off${r.length===1?``:`s`} of ${t(e)} that have been and gone — they are rows in that backlog, with re-fire and “drop the clock” on them`,onClick:()=>{q(`action:schedule.clockspent`),n(e,r.map(e=>e.id),eG(t(e)))},children:[r.length,` in `,t(e)]},e))})]})}function bve({act:e,child:t,childSession:n,typed:r,repoName:i,onOpenSession:a,onOpenBacklog:o,onOpenBuildRun:s}){if(n&&a)return(0,J.jsxs)(`button`,{className:`link-btn`,"data-hint":`schedule.session`,title:`Open the session this item ran in`,onClick:()=>{q(`action:schedule.session`),a(n)},children:[(0,J.jsx)(xo,{size:13}),` session`]});if(e.kind===`build`){if(!t||!s)return null;let n=iR(t),r=t.settledAt??t.startedAt;return(0,J.jsxs)(`button`,{className:`link-btn`,"data-hint":`schedule.buildrun`,title:`Open the run this rule last started, in ${i(e.repoDir)}'s builds`,onClick:()=>{q(`action:schedule.buildrun`),s(e.repoDir,t.id)},children:[(0,J.jsx)(No,{size:13}),` last run · `,n,r&&n!==`running`&&n!==`waiting`?` ${Gp(r)}`:``]})}return e.kind!==`backlog`||!o?null:t?(0,J.jsxs)(`button`,{className:`link-btn`,"data-hint":`schedule.backlogitems`,title:`Show the item this rule wrote, in ${i(e.repoDir)}'s backlog`,onClick:()=>{q(`action:schedule.backlog`),o(e.repoDir,[t.id],JL(r||e.text.slice(0,40)))},children:[(0,J.jsx)(Vl,{size:13}),` backlog · 1 item`]}):(0,J.jsxs)(`button`,{className:`link-btn`,"data-hint":`schedule.backlogitems`,title:`Show ${i(e.repoDir)}'s backlog — this is the list each run of this rule writes into`,onClick:()=>{q(`action:schedule.backlog`),o(e.repoDir)},children:[(0,J.jsx)(Vl,{size:13}),` backlog`]})}function xve({query:e,setQuery:t,cutTotal:n,shownTotal:r}){let i=e.trim()!==``;return n<=1&&!i?null:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`section quick-filter`,children:[(0,J.jsx)(Lc,{size:14,className:`quick-filter-icon`}),(0,J.jsx)(`input`,{type:`search`,value:e,placeholder:`search these schedules`,"aria-label":`search the schedules by their words or repo`,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`none`,spellCheck:!1,onChange:e=>t(e.target.value),onKeyDown:n=>{n.key===`Escape`&&e&&(n.preventDefault(),n.stopPropagation(),t(``))}}),i&&(0,J.jsxs)(`span`,{className:`quick-filter-n`,children:[r,` of `,n]}),i&&(0,J.jsx)(`button`,{className:`head-act`,"aria-label":`clear the search`,title:`clear the search — every row of the cut again`,onClick:()=>t(``),children:(0,J.jsx)(V,{size:16})})]}),i&&r===0&&(0,J.jsxs)($,{children:[`Nothing here matches “`,e.trim(),`”.`]})]})}var JG=`no connection — it is armed on the desktop and can only be changed there`,YG=`no connection — it lives on the desktop and can only be deleted there`,XG=new Set([JG,YG]);function Sve(e){return e.state===`starting`||e.state===`running`?`running`:e.state===`blocked`?`waiting`:e.state===`queued`?`queued`:e.state}function Cve({repos:e,entries:t,onRemove:n,onSetEnabled:r,onRunNow:i,onSkipNext:a,onEdit:o,onClose:s,intents:c=[],sessions:l=[],onOpenSession:u,onOpenBacklog:d,onOpenBuildRun:f,renderRetime:p,online:m=!0,pending:h=[],listAt:g=0,focus:_=null,focusIds:v=null,onClearFocus:y,onOpenSpent:b,usage:x=null,foot:S}){let C=t=>{let n=e.find(e=>e.worktreePath===t);return n?Wn(n):t.split(`/`).pop()??t},[w,T]=(0,H.useState)(null),[E,D]=(0,H.useState)(``),O=E.trim()!==``,k=Date.now(),A=(0,H.useMemo)(()=>KH({intents:c,entries:t,pending:h,focus:_,focusIds:v,text:E,now:k}),[c,t,h,_,v,E,k]),j=(0,H.useMemo)(()=>new Map(A.pendingCards.map(e=>[e.entry.id,!!e.failed])),[A.pendingCards]),M=(0,H.useMemo)(()=>new Set(t.map(e=>e.id)),[t]),N=A.cards,P=A.spentCards,F=A.shownCards,I=(0,H.useMemo)(()=>F.filter(e=>Ia(e.rule)),[F]),ee=(0,H.useMemo)(()=>F.filter(e=>!Ia(e.rule)),[F]),te=A.shownTotal,ne=A.standingTotal,re=[I.length,ee.length,A.shown.length+A.shownPending.length].filter(e=>e>0).length===1,ie=e=>yd({queued:j.has(e.id),failed:j.get(e.id)===!0,onHost:M.has(e.id),online:m}),ae=[...F.map(ie),...A.shown.map(()=>`synced`),...A.shownPending.map(e=>yd({queued:!0,failed:!!e.failed,onHost:!1,online:m}))],oe=e=>{let t=e.action,s=j.has(e.id),p=j.get(e.id)===!0,h=ie(e),g=!Si(e,k),_=Ia(e.rule),v=_&&!e.enabled,y=v?ri(e.rule,k):null,b=Ar(e.name,Ka(t)),x=e.lastResult?.childId?c.find(t=>t.id===e.lastResult.childId):void 0,S=c.find(t=>t.id===e.id),E=S?.state===`blocked`&&S.blockReason&&S.blockReason!==`notYet`?S.blockDetail:void 0,D=x?.sessionId&&l.some(e=>e.id===x.sessionId&&e.running!==!1)?x.sessionId:null,O=e.nextAt&&!Da(e.rule,e.nextAt)?fr(e.rule,e.nextAt):null,A=t.kind===`backlog`&&t.steps&&t.steps.length>1?` · ${t.steps.length} turns`:``,M=t.kind===`fanout`?`fan-out · ${t.dirs.length} repo${t.dirs.length===1?``:`s`}`:t.kind===`build`?`build ${t.buildId} in ${C(t.repoDir)}`:t.autoFire===!1?`${C(t.repoDir)} · added to the backlog, not run${A}`:`a new session in ${C(t.repoDir)}${A}`,N=s||e.nextAt&&!e.running?null:e.running?(0,J.jsxs)(yE,{children:[(0,J.jsx)(Ml,{size:12,className:`spin`}),` running`]}):g?(0,J.jsx)(yE,{children:`been and gone`}):(0,J.jsx)(yE,{children:e.enabled?De.unarmed:v?`paused`:`off`}),P=xd(h,!0)!=null;return(0,J.jsxs)(`div`,{className:`q-card${e.running?` resuming`:``}`,children:[b&&(0,J.jsx)(`div`,{className:`sched-title`,children:b}),(P||N)&&(0,J.jsxs)(`div`,{className:`q-head`,children:[(0,J.jsx)(YR,{phase:h,thing:`this schedule`,saidAbove:!0}),N]}),(0,J.jsxs)(`div`,{className:`approve-hint`,children:[va(e.rule),` · `,M,e.waitUntilFree?(0,J.jsx)(J.Fragment,{children:` · waits until free`}):null,e.nextAt&&!p?(0,J.jsxs)(J.Fragment,{children:[` · next `,Pe(e.nextAt)]}):null,O&&!p?(0,J.jsxs)(J.Fragment,{children:[` · held until `,Pe(O),`, when its hours open`]}):null,y?(0,J.jsxs)(J.Fragment,{children:[` · would next run `,Pe(y),` once resumed`]}):null]}),g&&!s&&(0,J.jsx)(`div`,{className:`approve-hint`,children:`that instant has passed and a one-off cannot be re-armed — run it now, edit it, or post it again`}),!s&&E&&(0,J.jsx)(`div`,{className:`approve-hint`,children:E}),s&&(0,J.jsx)(`div`,{className:`approve-hint`,children:p?(0,J.jsx)(J.Fragment,{children:`the send gave up — this rule is on this phone and nowhere else, and it will not arm itself. Its words are kept; re-send it from the queue, or edit it here to replace the copy that failed.`}):(0,J.jsx)(J.Fragment,{children:`waiting for the link — it is armed on the desktop as soon as the queue drains, and the time above holds (the rule is a wall clock, not a countdown from when it is saved).`})}),(0,J.jsx)(`button`,{className:`bl-text bl-text-btn ${w===e.id?`open`:``}`,title:w===e.id?`collapse`:`expand — the whole prompt this fires`,onClick:()=>T(t=>t===e.id?null:e.id),children:Ka(t)}),e.lastResult&&(0,J.jsxs)(`div`,{className:`approve-hint`,children:[e.lastResult.ok?(0,J.jsx)(Dl,{size:12,style:{verticalAlign:`-2px`}}):(0,J.jsx)(Cc,{size:12,style:{verticalAlign:`-2px`}}),` `,Gp(e.lastResult.at),` · `,e.lastResult.detail,e.lastResult.occurrence?(0,J.jsxs)(J.Fragment,{children:[` · due `,Pe(e.lastResult.occurrence)]}):null,e.lastResult.late?` · ran late (the host had been asleep)`:``,x?(0,J.jsxs)(J.Fragment,{children:[` · the item is `,(0,J.jsx)(`b`,{children:Sve(x)})]}):null]}),(()=>{let c={run:p?`the send gave up — the desktop never got it, so there is nothing there to run`:s?`it is still in the send queue — the desktop does not have it yet`:null,toggle:p?`the send gave up — the desktop never got it, so there is nothing there to switch`:s?`it is still in the send queue — the desktop does not have it yet`:m?null:JG,remove:p?`the send gave up — nothing was stored, so there is nothing to delete`:s?`it is still in the send queue — cancel it there instead`:m?null:YG},l=[[`now`,c.run],[_?`pause/resume`:`on/off`,c.toggle&&XG.has(c.toggle)?null:c.toggle],[`delete`,c.remove&&XG.has(c.remove)?null:c.remove]];return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`approve-opts`,children:[c.run?null:(0,J.jsxs)(`button`,{className:`approve-btn`,"data-hint":`schedule.runnow`,title:`Run it now. This does not use up the next scheduled run.`,onClick:()=>{q(`action:schedule.runnow`),i(e.id)},children:[(0,J.jsx)(Hc,{size:14}),` now`]}),(0,J.jsxs)(`button`,{className:`approve-btn`,"data-hint":`schedule.edit`,onClick:()=>{q(`action:schedule.edit`),o(e)},children:[(0,J.jsx)(us,{size:14}),` edit`]})]}),(0,J.jsxs)(`div`,{className:`sched-acts`,children:[(0,J.jsx)(bve,{act:t,child:x,childSession:D,typed:b,repoName:C,onOpenSession:u,onOpenBacklog:d,onOpenBuildRun:f}),_&&e.nextAt&&a&&!s&&m&&(0,J.jsxs)(`button`,{className:`link-btn`,"data-hint":`schedule.skipnext`,title:`Let this one run go by, then carry on as scheduled`,onClick:()=>{q(`action:schedule.skipnext`),a(e.id)},children:[(0,J.jsx)(Gne,{size:13}),` skip next`]}),c.toggle?null:(0,J.jsx)(`button`,{className:`link-btn`,"data-hint":`schedule.toggle`,title:_?e.enabled?`Pause it — nothing runs until you resume, and then it carries on at its own times`:`Resume it — the next run is its own next occurrence from now, never the ones it slept through`:e.enabled?`Stop it running`:`Arm it again — the next run is computed from now, not from what was missed`,onClick:()=>{q(`action:schedule.toggle`),r(e.id,!e.enabled)},children:_?e.enabled?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Ho,{size:13}),` pause`]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Hc,{size:13}),` resume`]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Eo,{size:13}),` `,e.enabled?`off`:`on`]})}),c.remove?null:(0,J.jsx)(`span`,{className:`sched-acts-hint`,"data-hint":`schedule.remove`,children:(0,J.jsxs)(uT,{className:`link-btn danger`,confirm:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(ic,{size:13}),` delete it?`]}),title:`Delete this schedule — the next tap asks once more`,confirmTitle:`Tap again to delete it for good`,onConfirm:()=>{q(`action:schedule.remove`),n(e.id)},children:[(0,J.jsx)(ic,{size:13}),` delete`]})})]}),(0,J.jsx)(CE,{cants:l.flatMap(([e,t])=>t?[{label:e,reason:t}]:[])})]})})()]},e.id)};return(0,J.jsxs)(`div`,{className:`sheet`,children:[(0,J.jsxs)(gE,{title:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Ss,{size:16}),` `,fM.automation]}),onClose:s,children:[ne>0&&!_&&!v&&!O&&(0,J.jsx)(`span`,{className:`muted`,children:ne}),(0,J.jsx)(XR,{phases:ae})]}),(0,J.jsxs)(`div`,{className:`sheet-scroll`,children:[(_||v)&&(0,J.jsxs)(`div`,{className:`section filter-bar`,children:[(0,J.jsxs)(`span`,{className:`filter-bar-txt`,children:[v?v.label:_?`showing the ${De[_]===`not armed`?`not armed`:`ones ${De[_]}`}`:``,` · `,A.cutTotal,` of `,ne,A.cutTotal===0&&(v?v.ids.length===1?` — that rule is not on this desktop any more`:` — none of those are on this desktop any more`:` — nothing is in that window any more`)]}),y&&(0,J.jsxs)(`button`,{className:`filter-bar-clear`,title:`clear the filter — show every schedule again`,onClick:()=>{q(`action:schedule.focus.clear`),y()},children:[(0,J.jsx)(V,{size:13}),` clear`]})]}),(0,J.jsx)(xve,{query:E,setQuery:D,cutTotal:A.cutTotal,shownTotal:te}),!m&&(0,J.jsxs)(Z,{children:[(0,J.jsx)(Hs,{size:13,style:{verticalAlign:`-2px`}}),` offline — a new or edited schedule is queued and saved when the link is back, so `,(0,J.jsx)(`b`,{children:`edit`}),` still works on every row below (the save replaces the copy it edits rather than arming a second one). What the cards do not show while the link is down is`,` `,(0,J.jsx)(`b`,{children:`pause/resume`}),`, `,(0,J.jsx)(`b`,{children:`on/off`}),`, `,(0,J.jsx)(`b`,{children:`skip next`}),`, `,(0,J.jsx)(`b`,{children:`delete`}),` and the `,(0,J.jsx)(`b`,{children:`session`}),` button: the first four are decisions about a run that may be minutes away and only the host can make them, and the last one needs a desktop to open a session on.`,t.length>0&&(g?` The armed rows are this device's copy, last confirmed ${Gp(g)} ago.`:` The armed rows are this device's copy.`),` `,`Items waiting on a clock are not listed below while the link is down — this device caches the rules, not the rows. Each of them is in its repo's `,(0,J.jsx)(`b`,{children:`backlog`}),`, which does keep a copy.`]}),ne===0&&!m&&(0,J.jsx)($,{children:`No copy of the schedule list on this device — whatever is armed on the desktop is still armed.`}),ne===0&&m&&(0,J.jsxs)($,{children:[`Nothing is scheduled.`,` `,(0,J.jsx)(TE,{of:`a schedule`,label:`what is one?`,children:`A schedule fires a prompt on its own, at a time you pick — once tonight, or every week two hours before your usage window rolls over.`})]}),N.length===0&&ne>0&&!O&&(0,J.jsxs)(Z,{className:`sched-nothing-repeats`,children:[(0,J.jsx)(Pl,{size:13,style:{verticalAlign:`-2px`}}),` Nothing repeats — there is no standing rule on this desktop. `,ne,` one-off`,ne===1?``:`s`,` wait`,ne===1?`s`:``,` on a clock in `,ne===1?`its repo's backlog`:`their repos' backlogs`,`, where every verb they have lives. A rule that repeats would be a card here; `,(0,J.jsx)(`b`,{children:`new schedule`}),` writes one.`]}),!_&&!O&&S,ne>0&&(0,J.jsx)(NL,{entries:F,usage:x,now:k,title:e=>Ar(e.name,Ka(e.action))??Ka(e.action).split(`
|
|
204
204
|
`)[0]}),I.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`sched-head`,children:[(0,J.jsx)(Pl,{size:13}),` Repeating`,re?null:(0,J.jsxs)(J.Fragment,{children:[` · `,I.length]})]}),(0,J.jsx)(`div`,{className:`list`,children:I.map(oe)})]}),ee.length>0&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`sched-head`,children:[(0,J.jsx)(Ss,{size:13}),` One-off`,re?null:(0,J.jsxs)(J.Fragment,{children:[` · `,ee.length]})]}),(0,J.jsx)(`div`,{className:`list`,children:ee.map(oe)})]}),(0,J.jsx)(vve,{rows:A.shown,pending:A.shownPending,repoName:C,online:m,onOpen:d,renderRetime:p,counted:!re}),P.length>0&&!_&&!v&&!O&&(0,J.jsxs)(Z,{className:`sched-spent`,children:[(0,J.jsx)(kc,{size:13,style:{verticalAlign:`-2px`}}),` `,P.length,` one-off sweep`,P.length===1?` has`:`s have`,` been and gone — run or missed,`,` `,`Activity's row says which — and a one-off cannot be re-armed, so`,` `,P.length===1?`it is not a row here`:`they are not rows here`,` any more.`,b&&(0,J.jsxs)(J.Fragment,{children:[` `,(0,J.jsxs)(Y,{"data-hint":`schedule.spent`,onClick:()=>{q(`action:schedule.spent`),b(P.map(e=>e.id))},children:[`see `,P.length===1?`it`:`them`,` in `,fM.activity]})]})]}),!_&&!v&&!O&&(0,J.jsx)(yve,{goneByRepo:A.goneByRepo,repoName:C,onOpen:d})]}),(0,J.jsx)(`div`,{className:`sheet-actions`,children:(0,J.jsxs)(`button`,{className:`send`,onClick:()=>{q(`action:schedule.new`),o(null)},children:[(0,J.jsx)(os,{size:16}),` new schedule`]})})]})}var wve={backlog:Vl,pull:rs,weekburn:Tc,peer:To};function Tve({lines:e,onDoor:t}){return e.length?(0,J.jsxs)(`div`,{className:`auto-foot`,children:[(0,J.jsx)(`div`,{className:`sched-head`,children:`Runs on its own, no clock`}),e.map(e=>{let n=wve[e.icon];return(0,J.jsxs)(xE,{kind:`wrap`,children:[(0,J.jsxs)(Q,{children:[(0,J.jsx)(n,{size:13,style:{verticalAlign:`-2px`}}),` `,e.text]}),(0,J.jsx)(Y,{onClick:()=>{q(`action:automation.${e.icon}`),t(e.door)},children:e.verb})]},e.key)})]}):null}var ZG=`__closed`;function QG(e,t){return e.targetSessionId?t.has(e.targetSessionId)?e.targetSessionId:e.reopensConv?``:ZG:``}function $G(e,t){return!!e.manual||!!e.at&&(e.at.nextAt==null||e.at.nextAt>t)}function eK(e,t,n,r){let i=new Set;if(!n)return i;let a=new Set;for(let n of e){let e=QG(n,t);e===`__closed`||a.has(e)||n.status===`queued`&&!$G(n,r)&&(a.add(e),i.add(n.id))}return i}var tK=e=>`${e} row${e===1?``:`s`}`;function nK(e){return[...new Set(e.map(e=>e.repoDir))]}function Eve(e,t){return e.filter(e=>e.repoDir===t&&!EW(e))}function Dve(e,t){let n=new Set(e.sessions.filter(e=>e.running&&e.cwd===t).map(e=>e.id));return[...eK(Eve(e.items,t),n,e.auto,e.now)]}function Ove(e){let t=e=>({kind:`backlog`,repoDir:e});if(!e.auto)return[{key:`backlog`,icon:`backlog`,verb:`open the backlog`,door:t(e.repoDir),text:`Backlog auto is off: no backlog row starts by itself.`}];let n=(e.repoDir?[e.repoDir]:nK(e.items)).map(t=>({dir:t,ids:Dve(e,t)})).filter(e=>e.ids.length>0);return n.length?n.map(({dir:t,ids:n},r)=>{let i=n.length,a=e.repoName(t),o=`${tK(i)} in ${a} will start when free`;return{key:`backlog:${t}`,icon:`backlog`,verb:i===1?`see it`:`see those ${i}`,door:{kind:`backlog`,repoDir:t,ids:n,label:`the ${tK(i)} auto starts next in ${a}`},text:r===0?`Backlog auto is on: ${o}.`:`${o[0].toUpperCase()}${o.slice(1)}.`}}):[{key:`backlog`,icon:`backlog`,verb:`open the backlog`,door:t(e.repoDir),text:e.repoDir?`Backlog auto is on; nothing in ${e.repoName(e.repoDir)} is waiting to start.`:`Backlog auto is on; no backlog row is waiting to start.`}]}function kve(e){if(!e.repoDir||!e.pull)return null;let t=e.repoName(e.repoDir),n=e.pull.scope===`repo`?`anywhere in the repo`:`in its outbox`;return{key:`pull`,icon:`pull`,verb:`download rules`,door:{kind:`pull`,repoDir:e.repoDir},text:e.pull.enabled?`Auto-download is on for ${t}: new files ${n}${e.pull.builds?` and build artifacts`:``} come to this phone by themselves.`:`Auto-download is off for ${t}.`}}function rK(e){let t=e.weekburn;if(!t||!t.available)return null;let n=e=>({key:`weekburn`,icon:`weekburn`,verb:`open the burn`,door:{kind:`weekburn`},text:e}),r=t.pickedThisWeek?t.prefs.repos:[],i=t.plan?`, from ${e.when(t.plan.startAt)}`:``;if(e.repoDir){let a=e.repoName(e.repoDir);return t.running.some(t=>t.repoDir===e.repoDir)?n(`The week-end burn is posting small one-commit items in ${a} now.`):r.includes(e.repoDir)?n(`The week-end burn picked ${a} this week: small one-commit items post there by themselves${i}.`):null}return t.running.length?n(`The week-end burn is posting small one-commit items in ${t.running.length===1?e.repoName(t.running[0].repoDir):`${t.running.length} repos`} now.`):r.length?n(`The week-end burn picked ${r.length===1?e.repoName(r[0]):`${r.length} repos`} this week${i}.`):n(`No repo is picked for this week's week-end burn.`)}function Ave(e){let t=e.items.filter(t=>Fee(t)&&t.status===`queued`&&!EW(t)&&(!e.repoDir||t.repoDir===e.repoDir));return nK(t).map(n=>{let r=t.filter(e=>e.repoDir===n).map(e=>e.id),i=[...new Set(t.filter(e=>e.repoDir===n).map(e=>Or(e.origin)))],a=r.length,o=e.repoName(n),s=i.length===1?`peer ${i[0]}`:`${i.length} peer desktops`;return{key:`peer:${n}`,icon:`peer`,verb:a===1?`see it`:`see those ${a}`,door:{kind:`backlog`,repoDir:n,ids:r,label:`the ${a} from a peer desktop in ${o}`},text:`${a===1?`1 job`:`${a} jobs`} from ${s} ${a===1?`waits`:`wait`} in ${o}'s backlog.`}})}function jve(e){let t=Ove(e),n=kve(e);n&&t.push(n);let r=rK(e);return r&&t.push(r),t.push(...Ave(e)),t}function Mve(e){nU.set(e),lue(e),rU.set(Date.now())}function Nve(e){iU.set(e),W().nav.open(`schedule`)}function Pve(e,t,n){iU.set(null),aU.set(n?{ids:e,label:t,repoDir:n}:{ids:e,label:t}),W().nav.open(`schedule`)}function iK(){iU.set(null),aU.set(null)}function Fve(e){let t=W(),{queueOp:n}=t.queue,r=nU.get().find(t=>t.id===e),i=n({t:`schedule.run`,id:e},`fanout`,r?.name||`scheduled run`);t.say.toast(i?`queued — it runs when the link is back`:`running it now`)}function Ive(e){let t=W(),n=t.queue.verbs.scheduleQueueRows(e);t.conn.liveSend({t:`schedule.remove`,id:e},$H(n.length),`no connection — this one lives on the desktop and can only be deleted there`)&&t.queue.verbs.dropScheduleQueue(n)}function Lve(){let e=_h(),{liveSend:t}=e.conn,{sessions:n,visibleRepos:r,active:i,intents:a}=e.world,o=t=>{let n=t.action.kind===`build`?e.world.repoForCwd(t.action.repoDir):null;n?e.nav.openBuild(n,{schedule:t}):e.say.toast(`that build's repo is not on this desktop's list — the rule cannot be edited from here`)},s=K(nU),c=K(rU),l=K(iU),u=K(aU),d=vh(),f=(0,H.useMemo)(()=>eU(d),[d]),p=u?u.repoDir??null:null,m=!u||!!u.repoDir,h=UV(),g=!p||!!h?.configs.has(p),_=h?.ask;(0,H.useEffect)(()=>{p&&_&&!g&&_(p)},[p,_,g]);let v=fh(`weekburn`,()=>U.getWeekBurn()),y=m?jve({repoDir:p,items:e.world.backlog,auto:e.world.backlogAuto,sessions:n,now:Date.now(),repoName:t=>{let n=e.world.repoForCwd(t);return n?Wn(n):t.split(/[/\\]/).filter(Boolean).pop()||t},pull:p?h?.configs.get(p):void 0,weekburn:v.state===`fresh`?v.data:null,when:Pe}):[];return(0,J.jsx)(Cve,{foot:(0,J.jsx)(Tve,{lines:y,onDoor:t=>{t.kind===`pull`?h?.open(t.repoDir):t.kind===`weekburn`?e.nav.open(`weekburn`):t.repoDir?e.nav.openBacklogCut(t.repoDir,t.ids,t.label):e.nav.open(`backlog`)}}),repos:r,entries:s,pending:f,listAt:c,focus:l,focusIds:u,onClearFocus:iK,onOpenSpent:t=>e.nav.openActivity({keys:t.map(EH),label:tU(t.length)}),online:e.conn.status===`open`,usage:e.world.usage,intents:a,sessions:n,onSkipNext:e=>{t({t:`schedule.skipNext`,id:e},`skipping the next run…`,`no connection — a skip has to reach the desktop before the run does`)},onOpenSession:t=>{let r=n.find(e=>e.id===t);r?(e.nav.close(`schedule`),e.nav.attach(r)):e.say.toast(`that session is no longer open`)},onOpenBacklog:(t,n,r)=>e.nav.openBacklogCut(t,n,r),onOpenBuildRun:(t,n)=>{let r=e.world.repoForCwd(t);r?e.nav.openBuild(r,{run:n}):e.say.toast(`that build's repo is not on this desktop's list`)},renderRetime:e.send.renderRetime,onEdit:t=>t?.action.kind===`build`?o(t):e.nav.openSend(t?e.send.seedFromSchedule(t):{when:tM(36e5),target:{kind:`repo`,cwd:i?.cwd??r.find(e=>e.isPrimary)?.worktreePath??``},cwdHint:i?.cwd??null,origin:`New schedule`}),onRunNow:Fve,onSetEnabled:(e,n)=>t({t:`schedule.setEnabled`,id:e,enabled:n},n?`armed`:`switched off`,`no connection — this one is armed on the desktop and can only be changed there`),onRemove:Ive,onClose:()=>e.nav.close(`schedule`)})}var Rve={id:`schedule`,sheets:[{id:`schedule`,persisted:!1,render:()=>(0,H.createElement)(Lve),onLeave:iK,keep:mh(iU,aU)}],messages:{"schedule.list":e=>Mve(e.entries)}},zve=[`done`,`obsolete`,`superseded`,`merged`];function aK(e){return zve.includes(e)}function Bve(e){return`the words for “${e}” are not on this phone`}var Vve=`this run's own record of what it judged is what both ends apply from, and this id is not in it — so there is nothing here to agree with, and a tick would do nothing`,Hve=`a pad note the run still wants — it is offered below, in its own words, as a backlog item; the pad itself is never edited by this app`;function Uve(e,t,n=!1){return n?Vve:t===`note`?e===`wanted`?Hve:`a pad note — this app never edits the pad, so there is nothing to apply here. If you agree it is done, delete it on the pad.`:e===`unclear`?`nothing to accept — the run did not decide about this one, so it stays exactly as it is`:e===`merged`?`a merge is one decision about all of its items — approve it on the merge itself, below`:null}function Wve(e){return e.verdict===`wanted`?e.rank==null?e.failed?`put back in the queue`:null:e.failed?`put back in the queue, position ${e.rank}`:`position ${e.rank} in the order`:null}var Gve=`retire this item: its words are kept with the reason on the row, and nothing is built`,oK=`tap to change your mind`;function sK(e){return`${e?``:`each `}where it was already aimed — a session of its own, or the session it names`}function cK(e,t,n=!1){return e===`wanted`?n?{label:`put it back`,title:`put this failed item back in the queue at the position the run proposes — it runs again ${sK(!0)} when its turn comes, and the failure it had stays on the row`,effect:`ticking keeps the item and gives it the position the run proposes; one that failed goes back in the queue and runs again when its turn comes — nothing is started now`,picked:`will be put back in the queue`,pickedTitle:oK}:{label:`keep it`,title:`keep this item and give it the position the run proposes — it does not run it`,effect:`ticking keeps the item and gives it the position the run proposes — nothing is started`,picked:`will be kept`,pickedTitle:oK}:e===`merged`?{label:`accept`,title:`a merge is approved on the merge card itself`,effect:`one decision about all of its items — approved on the card`,picked:`will be retired`,pickedTitle:oK}:e===`unclear`?{label:`accept`,title:`nothing was decided about this one`,effect:`nothing was decided here — these rows are yours to read`,picked:`stays as it is`,pickedTitle:oK}:{label:`retire it`,title:Gve,effect:`ticking a row here marks it to be retired when you Apply — its words are kept, with the reason on the row, and nothing is implemented`,picked:`will be retired`,pickedTitle:oK}}var lK={label:`leave it`,picked:`left alone`,title:`leave this one exactly as it is`,pickedTitle:`un-mark it`};function Kve(e,t){let n=new Map;for(let e of t)e&&typeof e.id==`string`&&e.id&&n.set(e.id,e);let r=e=>{let t=n.get(e.id),r=t?.source??`intent`,i=e.supersededBy?n.get(e.supersededBy):void 0;return{id:e.id,verdict:e.verdict,source:r,text:t?.text??``,missing:!t,failed:t?.state===`failed`,label:t?.label,headline:e.headline,category:e.category,verdictLabel:ve(e.verdict),sentence:kt(e),downgraded:e.downgraded,rank:e.rank,supersededBy:e.supersededBy,supersededByText:i?.text,gid:e.gid,acceptBlocked:Uve(e.verdict,r,!t),row:e}},i=e.rows.map(r),a=e.merges.map(e=>qve(e,i,n,r)),o=[];for(let e of cn){let t=i.filter(t=>t.verdict===e),n=e===`merged`?a:[];if(!t.length&&!n.length)continue;e===`wanted`&&t.sort((e,t)=>(e.rank??2**53-1)-(t.rank??2**53-1));let r=e===`merged`?[]:t,s=new Set;for(let e of n)for(let t of e.originals)s.add(t.id);o.push({verdict:e,label:ve(e),rows:r,merges:n,count:e===`merged`?s.size:t.length,acceptable:r.filter(e=>!e.acceptBlocked).length,failed:e===`wanted`?r.filter(e=>!e.acceptBlocked&&e.failed).length:0,retires:aK(e),defaultOpen:aK(e),fixedOpen:e===`merged`})}return o}function qve(e,t,n,r){let i=[],a=[];for(let o of e.ids){let s=t.find(e=>e.id===o);s?(i.push(s),s.missing&&a.push(o)):n.has(o)?i.push(r({id:o,verdict:`merged`,evidence:e.rationale,gid:e.gid})):a.push(o)}return{gid:e.gid,prompt:e.prompt,rank:e.rank,rationale:e.rationale,ids:[...e.ids],originals:i,missingIds:a,headline:e.headline,category:e.category}}function uK(e){let t=Ar(e.label,e.text,40),n={kind:e.source===`note`?`pad note`:`backlog item`,suggested:!t&&!!e.headline};t&&(n.name=t);let r=t??(e.headline?.trim()||void 0);return r&&(n.headline=r),e.category&&(n.category=e.category),e.missing&&(n.id=e.id),n}var dK=90;function Jve(e){let t=new Map;for(let n of e)n.downgraded&&t.set(n.downgraded,(t.get(n.downgraded)??0)+1);return[...t.entries()].sort((e,t)=>t[1]-e[1]||e[0].localeCompare(t[0])).map(([e,t])=>({down:e,text:Ve(e),n:t}))}var fK=e=>{let t=(e||``).replace(/\s+/g,` `).trim();return t?`“${t.length>dK?`${t.slice(0,dK)}…`:t}”`:`“” (the words for this one are not on this phone)`};function Yve(e,t){let n=e.length,r=e.filter(e=>e.failed).length,i=[`${n} ${n===1?`item`:`items`} in ${t.repoName} — ${ve(t.verdict)}.`];i.push(aK(t.verdict)?`Nothing is deleted: each row keeps its words and the evidence it was retired on, dimmed rather than hidden, and one tap brings it back.`:r?`${r} of them failed: ${r===1?`it goes`:`they go`} back in the queue and run${r===1?`s`:``} again when ${r===1?`its turn comes`:`their turn comes`}, one at a time in this repo, ${sK(r===1)}. The failure ${r===1?`it`:`they`} had stays on the row. Nothing is retired and nothing is started now.`:`This only sets the order they run in. Nothing is sent and nothing is retired.`);for(let t of e.slice(0,3))i.push(fK(t.text));return n>3&&i.push(`…and ${n-3} more`),i}var Xve=e=>e.retires?`retire`:`keep`,pK=e=>e.slice(0,1).toUpperCase()+e.slice(1);function Zve(e,t,n){if(e.verdict===`merged`||e.verdict===`unclear`||!e.acceptable)return null;if(t>=e.acceptable)return{label:`un-tick ${t}`,title:`take the marks off this strip — nothing has been applied yet, so nothing is undone`,confirm:!1};let r=Xve(e),i=e.acceptable;if(e.retires)return{label:`${r} all ${i}`,title:`mark all ${i} to be retired when you Apply — their words are kept with the reason on each row, and nothing is implemented. You are shown the repo and 3 of the items first.`,confirm:!0,ask:{title:`${pK(r)} ${i} “${e.label}” in ${n.repoName}?`,confirmLabel:`${pK(r)} ${i}`}};let a=e.failed;return a?{label:`${r} all ${i}`,title:`keep all ${i} and give them the order the run proposes — ${a} of them failed and ${a===1?`is`:`are`} put back in the queue to run again when ${a===1?`its turn comes`:`their turn comes`}, one at a time in this repo, ${sK(a===1)}; nothing is started now and nothing is retired`,confirm:!0,ask:{title:`${pK(r)} ${i} in ${n.repoName} — put ${a} back in the queue?`,confirmLabel:`${pK(r)} ${i}`}}:{label:`${r} all ${i}`,title:`keep all ${i} and give them the order the run proposes — nothing is started and nothing is retired`,confirm:!1}}function Qve(e,t){let n=e.originals.length||e.ids.length,r=[`One new prompt replaces ${n} ${n===1?`item`:`items`} in ${t.repoName}.`,`The prompt below was written by the assessment, not by you. The items it replaces are retired with a reason and keep their words.`,fK(e.prompt)];for(let t of e.originals.slice(0,3))r.push(`replaces ${fK(t.text)}`);return e.originals.length>3&&r.push(`…and ${e.originals.length-3} more`),e.missingIds.length&&r.push(`${e.missingIds.length} of the items it names ${e.missingIds.length===1?`is`:`are`} not on this phone, so ${e.missingIds.length===1?`its words are`:`their words are`} not shown above.`),r}function $ve(e){let t=e.judged,n=[`The run read ${e.repoName} and is saying what it thinks of ${t} ${t===1?`item`:`items`} you wrote — it is a proposal, not a to-do list.`,`retire it / keep it on a row means you agree with that verdict. Nothing happens yet.`,`retire all on a strip agrees with every row on it in one go — you are shown the repo and 3 of the items first.`,`Apply, at the bottom, is the only thing that changes anything: retired items keep their words and go dim in the backlog (one tap brings one back); kept items stay where they are and each still runs in its own session when it fires — a kept item that had failed is put back in the queue and runs again when its turn comes, with its old failure kept on the row; new items are posted to the backlog the same way. Anything you left alone is untouched.`];return e.named&&n.push(`The run also suggested a title and a kind for each item — the switch at the bottom decides whether they are written on the rows. A title you typed yourself is never replaced.`),e.planPath&&n.push(`read the plan opens ${e.planPath}, the run's write-up. It is for reading, not something to run — the work is the items below.`),{lead:`A proposal. Nothing here builds, runs or sends anything.`,lines:n}}function eye(e){return e.rows.size+e.merges.size+e.news.size+(e.splits?.size??0)}function tye(e){return`${e} ticked`}var mK=e=>Array.isArray(e)?new Set(e):e;function nye(e,t,n){let r=mK(t.rows),i=mK(t.merges),a=mK(t.news),o=new Map;for(let e of n)e&&typeof e.id==`string`&&e.id&&o.set(e.id,e);let s=e=>{let t=o.get(e);return!!t&&!t.context&&t.source===`intent`},c=new Set,l=0;for(let t of e.merges)if(i.has(t.gid)){l++;for(let e of t.ids)s(e)&&c.add(e)}let u=0,d=0;for(let t of e.rows)if(r.has(t.id)){if(t.verdict===`wanted`){if(!s(t.id))continue;o.get(t.id)?.state===`failed`?d++:t.rank!=null&&u++}else t.verdict!==`merged`&&t.verdict!==`unclear`&&s(t.id)&&c.add(t.id)}e.news.forEach((e,t)=>{a.has(t)&&l++});let f=0;for(let t of e.rows)(t.headline||t.category)&&s(t.id)&&f++;return{retire:c.size,keep:u,requeue:d,post:l,name:f}}function rye(e,t,n={}){let r=[];return e.retire&&r.push(`retire ${e.retire}`),e.keep&&r.push(`keep ${e.keep} in order`),e.requeue&&r.push(`put ${e.requeue} back in the queue`),e.post&&r.push(`post ${e.post} new`),n.splits&&r.push(`split ${n.splits} in two`),n.ranked&&r.push(`order ${n.pinRanks===!1?`free`:`pinned`}`),n.writeNames&&e.name&&r.push(`title ${e.name}`),r.length?`Apply in ${t} — ${r.join(` · `)}`:`Apply in ${t}`}function iye(e){let t=`Retired items keep their words and can be brought back.`;if(!e)return`${t} Nothing is built or sent by this.`;let n=e===1;return`${t} Nothing is started now: the ${n?`one put back runs`:`${e} put back run`} again when ${n?`its turn comes`:`their turn comes`}, one at a time per repo, ${sK(n)}.`}var aye=new Set([`queued`,`blocked`]);function oye(e,t){if(!e?.applied)return{ids:[],n:0};let n=[];for(let e of t)e&&typeof e.id==`string`&&e.id&&(e.archived||aye.has(e.status??``)&&n.push(e.id));return{ids:n,n:n.length}}function sye(e,t){return e>0?`open the backlog — ${e} waiting in ${t}`:`open the backlog in ${t}`}function hK(e){return e>0?`Opens exactly those ${e} — everything waiting in this repo, filtered, with the clear button on the bar. Nothing else is applied by this — the apply above already happened.`:`Nothing is waiting in this repo, so the list opens unfiltered. Nothing else is applied by this.`}function cye(e){return`everything waiting in ${e}, from the assessment`}function lye(e){let t=[`${e.dismissed} retired`,`${e.ranked} ranked`];return e.requeued&&t.push(`${e.requeued} put back`),e.named&&t.push(`${e.named} titled`),t.push(`${e.posted} posted`),`applied: ${t.join(` · `)}`}var uye={label:`post it`,picked:`will be posted`,title:`add this to the backlog when you Apply — it is not started by this`,pickedTitle:`tap to change your mind`};function dye(e){return`becomes a backlog item in ${e}, in its own session when it fires`}var fye={label:`file it`,picked:`will be filed`,title:`file your own words as a backlog item when you Apply, and take the note off the pad — nothing is started by this`,pickedTitle:oK};function pye(e){return`your note, word for word, becomes a backlog item in ${e} — and comes off the pad once the desktop has it`}function mye(e){return e===1?`your note is on the backlog and off the pad`:`${e} notes are on the backlog and off the pad`}function hye(e,t){if(!Array.isArray(t))return{clear:[],stay:[...e],told:!1};let n=new Set(t),r=[],i=[];for(let t of e)(n.has(t)?r:i).push(t);return{clear:r,stay:i,told:!0}}function gye(e){let t=e.clear.length,n=e.stay.length;return!t&&!n?null:e.told?n?t?`${t===1?`1 note is on the backlog and off the pad`:`${t} notes are on the backlog and off the pad`}; ${n===1?`1 is still on your pad — the desktop did not file it`:`${n} are still on your pad — the desktop did not file them`}`:n===1?`nothing was filed — your note is still on the pad`:`nothing was filed — your ${n} notes are still on the pad`:mye(t):n===1?`your note is left on the pad — the desktop could not say whether it filed it`:`your ${n} notes are left on the pad — the desktop could not say which it filed`}function _ye(e){let t=e.run;if(!t)return`no assessment has been run for this repo yet`;if(t.status===`running`)return`the assessment is still running — its verdicts are not final until it finishes`;if(t.status===`failed`)return`the run did not produce a proposal${t.detail?` — ${t.detail}`:``}`;let n=t.proposal;return!n||!(n.rows.length+n.merges.length+n.news.length+(n.splits?.length??0)+(n.conflicts?.length??0))?`this run came back with nothing to decide`:t.status===`applied`?`this proposal has already been applied — run a new assessment to judge what is left now`:e.busy?`the decisions have been sent — waiting for the desktop`:e.picked?e.online?null:`no connection — applying starts work on the desktop, so it cannot be queued from here`:`nothing is ticked yet — tap retire it or keep it on the rows you agree with, or retire all on a strip`}function gK(e){return e.run?.status===`running`?`an assessment is already running for this repo — two of them would propose different verdicts on one list`:e.busy?`the run has been asked for — waiting for the desktop`:e.budgetNote?e.budgetNote:e.online?null:`no connection — the run happens on the desktop`}function _K(e,t){let n=Math.max(e||0,t||0),r=`step${n===1?``:`s`}`,i=t>0&&n>t;return{line:i?`${n} ${r} · last ${t} shown`:`${n} ${r}`,button:i?`last ${t} of ${n} ${r}`:`${n} ${r}`}}function vK(e){let t=Math.max(0,Math.round(e/1e3));if(t<60)return`${t}s`;let n=Math.floor(t/60);if(n<60)return t%60?`${n}m ${t%60}s`:`${n}m`;let r=Math.floor(n/60);return n%60?`${r}h ${n%60}m`:`${r}h`}function vye(e){let t=e.detail;switch(e.kind){case`read`:return t?`reading ${t}`:`reading`;case`search`:return t?`searching for ${t}`:`searching`;case`edit`:return t?`writing ${t}`:`writing`;case`run`:return t?`running ${t}`:`running a command`;case`task`:return t?`running an agent: ${t}`:`running an agent`;case`web`:return t?`fetching ${t}`:`fetching`;case`say`:return`thinking it over`;default:return t?`${e.label}: ${t}`:e.label}}function yye(e,t){if(!e||e.status!==`running`)return null;let n=vK(t-e.startedAt),r=e.progress,i=r?.tail.length?r.tail[r.tail.length-1]:null,a=!r||!i?`starting up`:r.wroteOut?`writing its answer`:vye(i),o=r?r.tail.length:0;return{doing:a,elapsed:n,counts:r&&r.steps?_K(r.steps,o).line:void 0,quiet:r&&t-r.at>=9e4?`nothing new for ${vK(t-r.at)}`:void 0,say:r?.say}}var yK=[`inherit`,`keep`,`close`];function bK(e){return e===!0?`close`:e===!1?`keep`:`inherit`}function bye(e){return e===`close`||e!==`keep`&&null}function xye(e){return e===`close`||e!==`keep`&&void 0}var Sye=e=>e?`close when done`:`keep open`;function xK(e,t){return e===`close`?`close when done`:e===`keep`?`keep open`:`as set globally (currently: ${Sye(t)})`}function SK(e,t){let n=bK(e);return`${(n===`inherit`?t:n===`close`)?`Its session closes itself once the work is done (it stays under Recently closed, reopenable)`:`Its session stays open once the work is done, until you close it`} — ${n===`inherit`?`as set globally`:`this item's own choice`}.`}function Cye(e,t){return e===`inherit`?`follows the global setting — ${t?`closes when done`:`stays open`}`:e===`close`?`its session will close when done`:`its session will stay open`}function CK(e){let t=bK(e);return t===`close`?`closes when done`:t===`keep`?`stays open`:null}var wK=e=>!e.targetSessionId,TK=e=>wK(e)&&e.status===`queued`;function EK(e,t){return!e||!t?!1:$r(t).length>=t.max&&/free slot/i.test(e)}function wye(e,t){if(!e)return[];let n=new Map(t.map(e=>[e.id,e])),r=[];for(let t of $r(e)){let e=n.get(t.id);e&&e.running&&r.push({s:e,closeWhenDone:t.closeWhenDone})}return r}function Tye(e){return`close one to make room — ${e} working`}function Eye(e,t){let n=e.turnActive?`working`:`idle`;return t?`${n} · closes itself when done`:`${n} · stays open until closed`}function DK(e,t){let n=[];for(let r of e){if(r.repoDir!==t)continue;let e=Zte(r);e&&n.push(e)}return n}function OK(e,t){return{repoDir:e,ids:[...t.ids],scope:{kind:`slot`,key:t.key},kind:t.kind,at:t.at,period:t.period}}function Dye(e,t,n,r){if(r)return null;let i=DK(e,t),a=Hee(i,n);if(!a.length)return null;let o=yee(i,n);return o?{id:n,others:a.length,check:OK(t,o)}:null}function Oye(e){return`${wa(e.others,e.check.kind)} — check them together?`}var kye=`check`,Aye=`not now`,jye=`don't ask in this repo`,Mye=`ask after a timed send`;function Nye(e){return`won't ask in ${e} again — “${Mye}” in its backlog brings it back`}function Pye(e){return`will ask again in ${e} when a timed send lands beside others`}function kK(e){return e?.at?JSON.stringify([e.at.rule,e.at.nextAt]):null}function Fye(e,t,n,r){if(r||n-e.since>6e5)return{kind:`drop`};let i=t.find(t=>t.id===e.id);if(!i||kK(i)===e.was)return{kind:`wait`};let a=Dye(t,e.repoDir,e.id,r);return a?{kind:`ask`,ask:a}:{kind:`drop`}}function Iye(e,t){return Oee(DK(e,t)).filter(e=>e.ids.length>=2).map(e=>OK(t,e))}function AK(e){return e.kind===`reset`?`at the ${e.period??`usage`} reset, ${Pe(e.at)}`:`at ${Pe(e.at)}`}function Lye(e,t){return`check these ${e.ids.length} · ${Dn(e.at,t)}`}function jK(e){return`the ${e.ids.length} rows that run together ${AK(e)} — one assessment reads them as a group (rows that contradict each other, a row that is two jobs, their order). Nothing changes until you approve it.`}function Rye(e,t,n){if(!e||e.kind!==`slot`)return null;let r=Jee(e.key),i=t?t===2?`these two`:`these ${t}`:`these rows`;return r?`A slot check: ${i} run together ${AK(r)} (${Dn(r.at,n)}). It looks for rows that contradict each other, a row that is two jobs, and the order they should go in.`:`A slot check: ${i} run together.`}function MK(e,t){return`${t?`check again`:`check`} ${e===2?`these two`:`these ${e}`} together`}var NK=(e,t)=>({id:t,text:e.get(t)?.text??null}),PK=e=>{let t=new Map;for(let n of e)n?.id&&t.set(n.id,n);return t};function zye(e,t){let n=PK(t);return(e?.conflicts??[]).map(e=>({cid:e.cid,sentence:le(e),rows:e.ids.map(e=>NK(n,e))}))}var Bye=`words only — nothing here is applied. Edit one, drop one, or leave them as they are.`,Vye=`drop this one`,Hye=`archive it?`,Uye=`archive this row — its words are kept and the backlog's archived cut brings it back`,Wye=`leave them`;function Gye(e,t){let n=PK(t);return(e?.splits??[]).map(e=>({sid:e.sid,id:e.id,sentence:Gt(e),original:NK(n,e.id),texts:[...e.texts]}))}function Kye(e,t){if(!e||e.status===`applied`||e.status===`failed`)return`run`;if(e.status===`running`)return`busy`;let n=e.scopedIds??[];return e.scope?.kind===`slot`&&e.scope.key===t.scope.key&&n.length===t.ids.length&&t.ids.every(e=>n.includes(e))?`same`:`waiting`}function qye(e,t){return e===`busy`?`an assessment is already running here — when it ends, the sheet's check button runs this one`:e===`waiting`?`another proposal is waiting here — decide it, or tap “${MK(t,!0)}” to replace it`:null}function Jye(e){let t=[...e.splits];return{rows:[...e.rows],merges:[...e.merges],news:[...e.news],...t.length?{splits:t}:{},pinRanks:e.pinRanks,writeNames:e.writeNames}}function Yye(e,t){return[`In ${t}, this row is archived (its words kept):`,e.original.text??`${e.id} — its words are not on this phone`,`and two rows are posted on the same clock:`,`1. ${e.texts[0]??``}`,`2. ${e.texts[1]??``}`]}var FK=[],IK=[],LK=null,RK=null,zK=new Set,BK=()=>{for(let e of zK)e()};function VK(){let e=oo(B.slotAskOff,[]);return Array.isArray(e)?e.filter(e=>typeof e==`string`):[]}function HK(e){return VK().includes(e)}function UK(e,t){let n=VK().filter(t=>t!==e);$a(B.slotAskOff,t?[...n,e]:n),t&&(IK=IK.filter(t=>t.repoDir!==e),LK?.check.repoDir===e&&(LK=null)),BK()}function Xye(e,t){if(!e||!t||HK(t))return;let n=kK(FK.find(t=>t.id===e));IK=[...IK.filter(t=>t.id!==e),{id:e,repoDir:t,was:n,since:Date.now()}]}function Zye(e){if(FK=e,!IK.length)return;let t=Date.now(),n=[],r=null;for(let i of IK){let a=Fye(i,e,t,HK(i.repoDir));a.kind===`wait`?n.push(i):a.kind===`ask`&&(r=a.ask)}IK=n,r&&(LK=r,BK())}function Qye(){return LK}function WK(e){return zK.add(e),()=>{zK.delete(e)}}function GK(){LK&&(LK=null,BK())}function KK(e){RK=e}function $ye(e){return RK?(RK(e),!0):!1}var qK=e=>e.status===`queued`||aW(e),ebe={checking:`checking…`,done:`implemented`,partial:`partial`,questions:`open questions`,not_done:`not done`,error:`check failed`,limited:`not checked — usage limit`,signedOut:`not checked — signed out`},tbe={checking:Ml,done:ys,partial:Jc,questions:gl,not_done:V,error:Js,limited:Kl,signedOut:ns},nbe={validating:`validating…`,achieved:`outcome achieved`,likely:`likely achieved`,unlikely:`likely not achieved`,unclear:`unclear`,error:`validate failed`,limited:`not validated — usage limit`,signedOut:`not validated — signed out`},rbe={validating:Ml,achieved:ys,likely:Jc,unlikely:V,unclear:gl,error:Js,limited:Kl,signedOut:ns},JK=e=>({label:bn(ebe,e,`a check result this app version cannot name`),Icon:bn(tbe,e,gl)}),YK=e=>({label:bn(nbe,e,`a validate result this app version cannot name`),Icon:bn(rbe,e,gl)}),XK={bug:wo,feature:Co,enhancement:Al,chore:$s};function ibe(e,t,{text:n,repoDir:r,filter:i,showArchived:a,sort:o},s){let c=(0,H.useMemo)(()=>wye(e.autoSlots,e.sessions),[e.autoSlots,e.sessions]),l=r?e.cutVerbs.assessBlocked?.(r)??null:null,u=e.sessions.filter(e=>e.running&&e.cwd===r),d=(0,H.useMemo)(()=>new Set(e.sessions.filter(e=>e.running).map(e=>e.id)),[e.sessions]),f=e=>gG(e,d),p=t=>!t.targetSessionId&&wM(t.repoDir,e.intents,t.id,e.sessions),m=e=>hG(e,d)===`held-closed`,h=e=>!!e.targetSessionId&&!d.has(e.targetSessionId)&&!e.reopensConv,g=e=>!!e.targetSessionId&&!d.has(e.targetSessionId)&&!!e.reopensConv,_=e=>!!e.targetSessionId&&d.has(e.targetSessionId),v=e.activeSession&&e.sessions.some(t=>t.running&&t.id===e.activeSession.id)?e.activeSession:null,y=v&&v.cwd===r?v:null,b=e=>!!v&&e.targetSessionId===v.id&&!!e.autoFire,x=t=>{let n=e.repos.find(e=>e.worktreePath===t);return n?Te(n):t.split(/[/\\]/).filter(Boolean).pop()||t},S=e.items.filter(e=>e.repoDir===r),C=i.ids||a?S:S.filter(e=>!EW(e)),w=NW(C,i,t),T=(0,H.useMemo)(()=>Iye(S,r),[S,r]),E=(0,H.useSyncExternalStore)(WK,()=>HK(r)),D=CW(i),O=D?C.filter(e=>wW(e,i,t)):C,k=n.trim().toLowerCase(),A=k?O.filter(e=>`${zn(e)??``} ${e.label??``} ${e.text}`.toLowerCase().includes(k)):O,j=S.filter(e=>e.archived).length,M=new Map(e.items.map(e=>[e.id,e])),N=e=>jG(e)??(e.text.length>40?`${e.text.slice(0,40)}…`:e.text),P=(0,H.useMemo)(()=>new Set(e.naming??[]),[e.naming]),F=new Set(u.map(e=>e.id)),I=e=>QG(e,F),ee=AW(o,!!i.clock),te=[],ne=(e,t,n,r)=>({key:e,title:t,running:n,items:jW(r,ee),seats:MW(r)}),re=A.filter(e=>I(e)===``);re.length&&te.push(ne(``,`Each in a new session`,!0,re));let ie=A.filter(e=>I(e)===ZG);ie.length&&te.push(ne(ZG,`Aimed at a session that closed`,!1,ie));for(let e of u){let t=A.filter(t=>I(t)===e.id);t.length&&te.push(ne(e.id,`In ${Li(e)}`,!0,t))}let ae=te.flatMap(e=>e.items),oe=ae.filter(IG),se=oe.filter(e=>s.has(e.id)).map(e=>e.id),ce=(0,H.useMemo)(()=>KW(C),[C]),le=UG(ce,oe),ue=e=>$G(e,t),de=eK(ae,F,e.auto,t),fe={fresh:0,aimed:0,held:0,other:0};for(let e of O){let t=I(e);e.archived?fe.other++:e.status===`queued`&&!ue(e)?t===``?fe.fresh++:t===`__closed`?fe.held++:fe.aimed++:e.status===`queued`&&(ue(e)||t===`__closed`)?fe.held++:fe.other++}return{slotSessions:c,assessWhyNot:l,repoSessions:u,liveSessionIds:d,runAgainOffered:f,fireIntoBusy:p,runAgainHeld:m,targetClosed:h,targetReopens:g,targetLive:_,here:v,hereInRepo:y,queuedHere:b,repoLabel:x,inRepo:S,base:C,counts:w,filtering:D,cut:O,q:k,visible:A,archivedCount:j,byId:M,nameOf:N,namingIds:P,groupKeyOf:I,drawSort:ee,groups:te,displayOrder:ae,retimeable:oe,retimeIds:se,clockCuts:ce,retimeClocks:le,nextFireIds:de,clockAhead:ue,focusBreakdown:fe,focusWords:i.ids?FW(fe,e.auto):null,bulkClockIds:i.status===`failed`?O.filter(e=>!!e.at).map(e=>e.id):[],bulkRunAgainIds:i.status===`failed`?_G(O,d):[],bulkRunAgainAimed:i.status===`failed`?vG(O,d):0,bulkDoneIds:i.status===`done`?O.filter(e=>!e.archived).map(e=>e.id):[],assessIds:UW(O),nameIds:DG(O),namingHere:S.some(e=>P.has(e.id)),slotCheckList:T,slotAskOff:E}}var ZK=B.backlogDraft;function abe(){let[e,t]=(0,H.useState)(()=>(z(ZK)??``).trim());return{strandedDraft:e,dropStrandedDraft:()=>{so(ZK),t(``)}}}function obe(e,{displayOrder:t,groupKeyOf:n,drawSort:r}){let[i,a]=(0,H.useState)(null),o=e.online&&r===`run`,s=(0,H.useRef)({displayOrder:t,groupKeyOf:n,verbs:e.cutVerbs});return s.current={displayOrder:t,groupKeyOf:n,verbs:e.cutVerbs},(0,H.useEffect)(()=>{if(!i)return;let e=e=>{let t=(document.elementFromPoint(e.clientX,e.clientY)?.closest(`[data-blid]`))?.getAttribute(`data-blid`);if(!t||t===i)return;let{displayOrder:n,groupKeyOf:r}=s.current,a=n.find(e=>e.id===i),o=n.find(e=>e.id===t);if(!a||!o||r(a)!==r(o))return;let c=n.map(e=>e.id),l=c.indexOf(i),u=c.indexOf(t);l!==-1&&u!==-1&&(c.splice(l,1),c.splice(u,0,i),s.current.verbs.onReorder(c))},t=()=>a(null);return window.addEventListener(`pointermove`,e,{passive:!1}),window.addEventListener(`pointerup`,t),window.addEventListener(`pointercancel`,t),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`pointerup`,t),window.removeEventListener(`pointercancel`,t)}},[i]),{dragId:i,setDragId:a,canDrag:o}}function sbe(e){let[t,n]=(0,H.useState)(null),[r,i]=(0,H.useState)(``),[a,o]=(0,H.useState)(``),[s,c]=(0,H.useState)(``),[l,u]=(0,H.useState)(``),[d,f]=(0,H.useState)(``),[p,m]=(0,H.useState)(``);function h(e){n(e.id),i(e.text),o(e.label??``),c(e.repoDir),u(e.targetSessionId??``),f(e.headline??``),m(e.category??``)}function g(t){let i=r.trim();if(!i)return;let o={};i!==t.text&&(o.text=i),(a||void 0)!==t.label&&(o.label=a);let c=d.trim();c!==(t.headline??``)&&(o.headline=c),p!==(t.category??``)&&(o.category=p),t.status!==`running`&&(s&&s!==t.repoDir&&(o.repoDir=s),(l||``)!==(t.targetSessionId??``)&&(o.targetSessionId=l)),Object.keys(o).length>0&&e.verbs.onUpdate(t.id,o),n(null)}return{editingId:t,setEditingId:n,editText:r,setEditText:i,editLabel:a,setEditLabel:o,editRepo:s,setEditRepo:c,editTarget:l,setEditTarget:u,editHeadline:d,setEditHeadline:f,editCategory:p,setEditCategory:m,beginEdit:h,saveEdit:g}}function cbe(e){let t=t=>!!t&&e.repos.some(e=>e.worktreePath===t);if(t(e.cutRepo))return{repoDir:e.cutRepo,derived:!1};if(t(e.sessionRepo))return{repoDir:e.sessionRepo,derived:!1};if(t(e.saved))return{repoDir:e.saved,derived:!1};let n=e.items.find(e=>!e.archived&&t(e.repoDir))?.repoDir;return n?{repoDir:n,derived:!0}:{repoDir:e.repos[0]?.worktreePath??``,derived:!1}}var QK=B.backlogShowArchived,$K=B.backlogRepo;function lbe(e){let{cut:t,setCut:n}=e,{text:r,filter:i,idsLabel:a}=t,o=e=>n(t=>({...t,text:e})),{repoDir:s,derived:c}=cbe({repos:e.repos,items:e.items,cutRepo:t.repoDir,sessionRepo:e.defaultRepoDir,saved:z($K)});(0,H.useEffect)(()=>{c&&n(e=>e.repoDir===s?e:{...e,repoDir:s})},[c,s,n]);let[l,u]=(0,H.useState)(()=>z(QK)===`1`),d=(e,t)=>n(n=>({...n,idsLabel:t,filter:{...n.filter,ids:e}})),f=()=>n(e=>({...e,idsLabel:void 0,filter:SW}));function p(e){e&&Za($K,e),n(t=>({...t,repoDir:e,filter:t.filter.ids?{...t.filter,ids:null}:t.filter,idsLabel:void 0}))}let m=e=>n(t=>({...t,filter:e(t.filter)})),h=e=>m(t=>({...t,status:t.status===e?null:e})),g=e=>m(t=>({...t,age:t.age===e?null:e})),_=e=>m(t=>({...t,category:t.category===e?null:e})),v=()=>m(e=>({...e,clock:!e.clock||null}));function y(){let e=!l;u(e),e?Za(QK,`1`):so(QK)}return{text:r,setText:o,repoDir:s,showArchived:l,filter:i,idsLabel:a,showIds:d,clearFilter:f,selectRepo:p,pickStatus:h,pickAge:g,pickCategory:_,pickClock:v,toggleArchived:y}}var eq=B.backlogSortRun;function ube(){let[e,t]=(0,H.useState)(()=>z(eq)===`1`?`run`:`newest`);return{sort:e,setSort:e=>{t(e),e===`run`?Za(eq,`1`):so(eq)}}}function dbe(){let[e,t]=(0,H.useState)(!1),[n,r]=(0,H.useState)(()=>new Set),[i,a]=(0,H.useState)(!1),[o,s]=(0,H.useState)(new Set),c=e=>s(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),[l,u]=(0,H.useState)(new Set),d=e=>u(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),[f,p]=(0,H.useState)(new Set),[m,h]=(0,H.useState)(new Set),[g,_]=(0,H.useState)(new Set);return{picking:e,setPicking:t,picked:n,setPicked:r,choosing:i,setChoosing:a,openDetail:o,toggleDetail:c,openValidate:l,toggleValidate:d,openText:f,toggleText:e=>p(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),slotOpen:m,setSlotOpen:h,budgetOpen:g,toggleBudget:e=>_(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n})}}function fbe({m:e,repoDir:t}){let{p:n}=e,r=n.items.filter(e=>e.repoDir===t&&Ri(e.origin)).map(e=>e.id),i=n.nav.weekBurnText?.(t)??null;return(0,J.jsxs)(`div`,{className:`form bl-repobar`,children:[i&&(0,J.jsxs)(Z,{as:`span`,children:[(0,J.jsx)(Tc,{size:13,style:{verticalAlign:`-2px`}}),` `,i]}),r.length>0&&n.nav.onOpenCut&&(0,J.jsx)(Y,{onClick:()=>{q(`action:backlog.weekburnrows`),n.nav.onOpenCut(t,r,pr(r.length))},children:pr(r.length)}),(0,J.jsxs)(Y,{onClick:()=>{q(`action:backlog.weekburn`),n.nav.onOpenWeekBurn()},children:[!i&&(0,J.jsx)(Tc,{size:14}),` week-end burn…`]})]})}function pbe({m:e}){let{p:t,repoDir:n}=e;return(0,J.jsxs)(gE,{title:`Backlog`,onClose:t.nav.onClose,children:[n&&(0,J.jsxs)(`button`,{className:`rc`,title:`write something for this repo — the send sheet, with the repo already chosen`,onClick:()=>{q(`action:backlog.send`),t.nav.onOpenSend(n)},children:[(0,J.jsx)(_l,{size:14}),` send…`]}),(0,J.jsx)(`button`,{className:`rc ${t.auto?`on`:`off`}`,onClick:()=>t.cutVerbs.onSetAuto(!t.auto),children:t.auto?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(yl,{size:14}),` auto`]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(vc,{size:14}),` auto off`]})})]})}function mbe({m:e}){let{assessIds:t,assessWhyNot:n,cut:r,filtering:i,p:a,repoDir:o,selectRepo:s}=e;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`form bl-repobar`,children:[(0,J.jsx)(ZO,{repos:a.repos,value:o,onChange:s,"aria-label":`repo`}),a.cutVerbs.onAssess&&o?n?(0,J.jsxs)(Z,{as:`span`,children:[`assess: `,n]}):i&&!t.length?(0,J.jsx)(Z,{as:`span`,children:HW}):(0,J.jsxs)(Y,{title:i?`judge exactly the open rows in this cut — it still reads the whole repo as evidence, and nothing applies itself`:`read this repo and judge what is left in it — with evidence, and nothing applies itself`,onClick:()=>{q(`action:backlog.assess`),a.cutVerbs.onAssess?.(o,i?t:void 0)},children:[(0,J.jsx)(uo,{size:14}),` `,i?BW(t.length):`assess`]}):null,a.cutVerbs.onAssess&&o&&!n&&i&&t.length>0&&(0,J.jsx)(Z,{as:`span`,children:VW(t.length,r.length)})]}),o&&a.nav.onOpenWeekBurn&&(0,J.jsx)(fbe,{m:e,repoDir:o})]})}function hbe({m:e}){let{focusWords:t,p:n}=e;return(0,J.jsx)(J.Fragment,{children:!n.auto&&!t&&(0,J.jsx)(`div`,{className:`form`,children:(0,J.jsx)(Z,{children:(0,J.jsxs)(TE,{of:`auto off`,label:`what does auto off stop?`,children:[(0,J.jsx)(`b`,{children:`auto`}),` is off on this desktop: nothing queued anywhere runs until you turn it back on or fire an item by hand.`]})})})})}function gbe({m:e}){let{dropStrandedDraft:t,p:n,repoDir:r,strandedDraft:i}=e;return(0,J.jsx)(J.Fragment,{children:i&&(0,J.jsx)(`div`,{className:`form`,children:(0,J.jsxs)(Z,{children:[(0,J.jsx)(`b`,{children:`Kept from before`}),` — this was the old add/search field, so it may be a search you typed:`,` `,`“`,i.length>160?`${i.slice(0,160)}…`:i,`”`,(0,J.jsxs)(`div`,{className:`annot-tools`,style:{marginTop:6},children:[(0,J.jsxs)(Y,{onClick:()=>{let e=i;t(),n.nav.onOpenSend(r,e)},children:[(0,J.jsx)(_l,{size:14}),` send it`]}),(0,J.jsxs)(uT,{confirm:`discard it?`,title:`throw these words away`,onConfirm:t,children:[(0,J.jsx)(V,{size:14}),` discard`]})]})]})})})}function _be({m:e}){let{here:t,hereInRepo:n,p:r}=e;return(0,J.jsxs)(J.Fragment,{children:[r.online&&!n&&(t?(0,J.jsx)(`div`,{className:`form`,children:(0,J.jsxs)(Z,{children:[`No wait verb on these items: the session you came from (`,(0,J.jsx)(`b`,{children:t.title}),`) is in another repo, and an item can only run in a session opened on its own checkout.`]})}):r.activeSession?(0,J.jsx)(`div`,{className:`form`,children:(0,J.jsx)(Z,{children:`No wait verb on these items: the session you came from is no longer running, so there is nothing to hand one to.`})}):null),!r.online&&(0,J.jsx)(`div`,{className:`form`,children:(0,J.jsxs)(Z,{children:[`Offline — showing the last synced backlog. Every mutation (fire, edit, done, check, validate, continue, reorder, archive, remove) is disabled until the connection is back; `,(0,J.jsx)(`b`,{children:`send…`}),` still queues normally.`]})})]})}var vbe=[`newest`,`run`];function ybe({m:e}){let{base:t,drawSort:n,setSort:r,sort:i}=e;return t.length<2?null:(0,J.jsxs)(`div`,{className:`ts-filter bl-sort`,role:`group`,"aria-label":`sort`,children:[(0,J.jsx)(`span`,{className:`ctx-stackpick-lab`,children:`sort`}),vbe.map(e=>(0,J.jsx)(pE,{on:i===e,clears:!1,onClick:()=>{q(e===`run`?`action:backlog.sort.run`:`action:backlog.sort.newest`),r(e)},children:DW[e]},e)),(0,J.jsxs)(TE,{of:`the sort`,children:[(0,J.jsx)(`p`,{children:`Newest first draws the rows most recently added at the top. Run order is the order they will start in.`}),(0,J.jsxs)(`p`,{children:[`Either way, `,OW,`.`]}),n===i?null:(0,J.jsxs)(`p`,{children:[`Right now `,kW,`.`]})]})]})}function bbe({m:e}){let{archivedCount:t,base:n,counts:r,filter:i,filtering:a,pickAge:o,pickCategory:s,pickClock:c,pickStatus:l,setText:u,showArchived:d,text:f,toggleArchived:p}=e,m=PW(r,i),h=m.status.length>0||m.clock||m.age.length>0||m.category.length>0;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`form bl-searchrow`,children:[(0,J.jsxs)(`div`,{className:`bl-search`,children:[(0,J.jsx)(Lc,{size:16,className:`bl-search-icon`}),(0,J.jsx)(`textarea`,{className:`search bl-combo`,rows:1,placeholder:`Search this repo…`,value:f,onChange:e=>u(e.target.value)}),f&&(0,J.jsx)(`button`,{className:`bl-search-clear`,onClick:()=>u(``),title:`clear`,children:(0,J.jsx)(V,{size:16})})]}),t>0&&(0,J.jsxs)(pE,{on:d,onClick:p,title:d?`hide archived items again`:`show this repo's archived items too`,children:[(0,J.jsx)(lo,{size:13,"aria-hidden":!0}),uE(`archived`,{count:t})]})]}),(0,J.jsx)(ybe,{m:e}),n.length>0&&h&&(0,J.jsxs)(`div`,{className:`bl-fchips`,children:[(m.status.length>0||m.clock)&&(0,J.jsxs)(`div`,{className:`fchips wrap`,children:[m.status.map(e=>(0,J.jsx)(pE,{on:i.status===e,title:`show only ${e} items${i.age?` from the ${fW[i.age]}`:``}`,onClick:()=>{q(`action:backlog.filter.status`),l(e)},children:uE(e,{count:r.status[e]})},e)),m.status.length>0&&m.clock&&(0,J.jsx)(`span`,{className:`fchips-gap`,"aria-hidden":!0}),m.clock&&(0,J.jsxs)(pE,{on:!!i.clock,title:i.clock?`show the items with no clock again`:`show only the ${r.clock} item${r.clock===1?``:`s`} waiting for an instant${i.status?` · ${i.status}`:``} — grouped by the clock they share, in the order they will run`,onClick:()=>{q(`action:backlog.filter.clock`),c()},children:[(0,J.jsx)(Ss,{size:12,"aria-hidden":!0}),uE(`on a clock`,{count:r.clock})]})]}),m.age.length>0&&(0,J.jsx)(`div`,{className:`fchips wrap`,children:m.age.map(e=>(0,J.jsx)(pE,{on:i.age===e,title:`show only ${i.status?`${i.status} `:``}items added ${e===`older`?`over a week ago`:`in the ${fW[e]}`}`,onClick:()=>{q(`action:backlog.filter.age`),o(e)},children:uE(fW[e],{count:r.age[e]})},e))}),m.category.length>0&&(0,J.jsx)(`div`,{className:`fchips wrap`,children:m.category.map(e=>{let t=e===`none`?null:XK[e];return(0,J.jsxs)(pE,{on:i.category===e,title:yW(e,i.category===e),onClick:()=>{q(`action:backlog.filter.category`),s(e)},children:[t&&(0,J.jsx)(t,{size:12,"aria-hidden":!0}),uE(vW[e],{count:r.category[e]})]},e)})})]}),a&&!i.ids&&(0,J.jsx)(tq,{m:e})]})}function tq({m:e}){let{base:t,clearFilter:n,cut:r,filter:i,idsLabel:a}=e;return(0,J.jsxs)(`div`,{className:`section filter-bar`,children:[(0,J.jsxs)(`span`,{className:`filter-bar-txt`,children:[TW(i,a),` · `,IW(r.length,t.length,i),r.length===0&&` — nothing here is in that cut`]}),(0,J.jsxs)(`button`,{className:`filter-bar-clear`,title:`clear the filter — show every item in this repo again`,onClick:()=>{q(`action:backlog.filter.clear`),n()},children:[(0,J.jsx)(V,{size:13}),` clear`]})]})}function nq({note:e,children:t}){return(0,J.jsxs)(`div`,{className:`bl-bulk-bar`,children:[(0,J.jsx)(Z,{children:e}),(0,J.jsx)(`div`,{className:`bl-bulk`,children:t})]})}function xbe({m:e}){let{bulkClockIds:t,bulkDoneIds:n,bulkRunAgainAimed:r,bulkRunAgainIds:i,cut:a,focusWords:o,p:s,runAgainOffered:c}=e;return(0,J.jsxs)(J.Fragment,{children:[o&&s.auto&&(0,J.jsx)(`div`,{className:`bl-bulk-bar`,children:(0,J.jsx)(Z,{children:(0,J.jsx)(TE,{of:`when these run`,label:`when do these run?`,children:o})})}),o&&!s.auto&&(0,J.jsx)(nq,{note:o,children:(0,J.jsxs)(`button`,{className:`link-btn`,title:`turn the desktop's auto switch back on — the same switch as the chip in this sheet's head`,onClick:()=>{q(`action:backlog.auto.focus`),s.cutVerbs.onSetAuto(!0)},children:[(0,J.jsx)(yl,{size:14}),` `,`turn auto on`]})}),t.length>1&&s.online&&(0,J.jsx)(nq,{note:uG(t.length,a.length),children:(0,J.jsxs)(uT,{className:`link-btn`,confirm:`drop all ${t.length}?`,title:oG(`failed`),onConfirm:()=>{q(`action:backlog.dropclock.all`),s.cutVerbs.onDropClocks(t)},children:[(0,J.jsx)(tl,{size:14}),` `,lG(t.length)]})}),i.length>1&&(0,J.jsx)(nq,{note:bG(i.length,a.length,r),children:(0,J.jsxs)(uT,{className:`link-btn`,confirm:`run all ${i.length} again?`,title:bG(i.length,a.length,r),onConfirm:()=>{q(`action:backlog.runagain.all`),s.cutVerbs.onRunAgainMany(a.filter(e=>c(e)).map(e=>({id:e.id,failedAt:e.finishedAt})))},children:[(0,J.jsx)(Nc,{size:14}),` `,yG(i.length)]})}),n.length>1&&s.online&&(0,J.jsx)(nq,{note:RW(n.length,a.length),children:(0,J.jsxs)(uT,{className:`link-btn`,confirm:`archive all ${n.length}?`,title:`they keep their words and stay in show archived — any one of them comes back from its own row`,onConfirm:()=>{q(`action:backlog.archive.done`),s.cutVerbs.onArchiveMany(n)},children:[(0,J.jsx)(lo,{size:14}),` `,LW(n.length)]})})]})}function Sbe({m:e}){let{choosing:t,cut:n,displayOrder:r,nameIds:i,namingHere:a,p:o,picking:s,repoDir:c,retimeable:l,retimeClocks:u,retimeIds:d,setChoosing:f,setPicked:p,setPicking:m,slotCheckList:h,slotAskOff:g,now:_}=e,v=o.online&&!s&&!!o.cutVerbs.onSlotCheck&&h.length>0,y=o.online&&g,b=o.online&&!s&&l.length>1,x=e=>{q(`action:backlog.retime.clock`),p(new Set(e)),m(!0)},S=i.length>0&&o.online;return(0,J.jsxs)(J.Fragment,{children:[(b||S||v||y)&&(0,J.jsxs)(`div`,{className:`bl-bulk`,children:[b&&(0,J.jsxs)(`button`,{className:`link-btn`,title:`tick several rows and move them all to one new time`,onClick:()=>{q(`action:backlog.retime.pick`),m(!0)},children:[(0,J.jsx)(Cs,{size:14}),` `,`pick to re-time`]}),b&&u.map(e=>(0,J.jsxs)(`button`,{className:`link-btn`,title:`tick every row on this clock — then choose their new when`,onClick:()=>x(e.ids),children:[(0,J.jsx)(Ss,{size:14}),` `,dve(e)]},e.key)),v&&h.map(e=>(0,J.jsxs)(`button`,{className:`link-btn`,title:jK(e),onClick:()=>{q(`action:backlog.slotcheck`),o.cutVerbs.onSlotCheck?.(e)},children:[(0,J.jsx)(uo,{size:14}),` `,Lye(e,_)]},e.scope.key)),y&&(0,J.jsxs)(`button`,{className:`link-btn`,title:`after you post a timed row here that runs together with others, offer to check them as a group`,onClick:()=>{q(`action:backlog.slotask.on`),UK(c,!1),Dg(Pye(Rp(c)))},children:[(0,J.jsx)(Oo,{size:14}),` `,`ask after a timed send`]}),S&&(a?(0,J.jsx)(CE,{cants:[{label:EG(i.length),reason:`a naming pass is already running for this repo`}]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`button`,{className:`link-btn`,"data-hint":`backlog.name`,title:OG(i.length,n.length),onClick:()=>{q(`action:backlog.name`),o.cutVerbs.onName(c,i)},children:[(0,J.jsx)(Gl,{size:14}),` `,EG(i.length)]}),(0,J.jsxs)(TE,{of:`naming`,children:[OG(i.length,n.length),(0,J.jsx)(`div`,{className:`bl-cost`,children:`one short toolless call on the cheap model — reads the items' own words and nothing else`})]})]}))]}),o.online&&s&&(0,J.jsx)(`div`,{className:`bl-pick-bar`,children:(0,J.jsx)(WG,{picked:d.length,eligible:l.length,shown:r.length,where:`backlog`,onAll:()=>p(new Set(l.map(e=>e.id))),onNone:()=>p(new Set),onDone:()=>{m(!1),p(new Set)},onChoose:()=>f(!0)})}),t&&d.length>0&&(0,J.jsx)(GG,{children:o.nav.renderRetime(d,{onSent:()=>{f(!1),m(!1),p(new Set)},onCancel:()=>f(!1)})})]})}function Cbe({m:e,row:t}){let{beginEdit:n,fireIntoBusy:r,here:i,p:a,queuedHere:o,runAgainOffered:s}=e,{it:c}=t,l=r(c)?`${SM(!c.targetSessionId)} — ${CM}`:SM(!c.targetSessionId),u=FG(c,a.sessions,a.items);return(0,J.jsxs)(`div`,{className:`bl-actions`,children:[a.online&&(0,J.jsx)(Y,{title:`edit`,onClick:()=>n(c),children:(0,J.jsx)(us,{size:14})}),c.status===`queued`&&i&&i.cwd===c.repoDir&&a.online&&(o(c)?(0,J.jsxs)(Y,{className:`on`,"data-hint":`backlog.queuehere`,title:`waiting for ${i.title} — it goes in when that session is next free, whether or not the global auto switch is on. Tap to take it back off`,onClick:()=>{q(`action:backlog.unqueuehere`),a.verbs.onQueueHere(c.id,``)},children:[(0,J.jsx)(Kl,{size:14}),` waits for `,i.title]}):(0,J.jsxs)(Y,{"data-hint":`backlog.queuehere`,title:`hand it to ${i.title} — it goes to the bottom of that session's queue and runs when the session is next free, whether or not the global auto switch is on`,onClick:()=>{q(`action:backlog.queuehere`),a.verbs.onQueueHere(c.id,i.id)},children:[(0,J.jsx)(Kl,{size:14}),` when `,i.title,` is free`]})),c.at&&qK(c)&&a.online&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(Y,{title:`change its time — the send sheet, with this row already in it`,onClick:()=>{q(`action:backlog.editwhen`),a.verbs.onEditWhen(c.id)},children:[(0,J.jsx)(Ss,{size:14}),` when`]}),(0,J.jsxs)(uT,{confirm:`drop it?`,title:oG(c.status),onConfirm:()=>{q(`action:backlog.dropclock`),a.verbs.onDropClock(c.id,c.status)},children:[(0,J.jsx)(tl,{size:14}),` drop the clock`]})]}),u&&(0,J.jsxs)(Y,{"data-hint":`backlog.openholder`,title:u.title,onClick:()=>{q(`action:backlog.openholder`),u.itemId?(e.clearFilter(),e.showIds([u.itemId],u.cut??``)):a.nav.onOpenSession(u.sessionId)},children:[(0,J.jsx)(Go,{size:14}),` `,u.label]}),c.status===`queued`&&a.online&&(0,J.jsx)(Y,{className:c.manual?`primary`:void 0,"data-hint":`backlog.fire`,title:l,onClick:()=>{q(`action:backlog.fire`),a.verbs.onFire(c.id)},children:`fire`}),s(c)&&(0,J.jsxs)(Y,{"data-hint":`backlog.runagain`,title:dG(c),onClick:()=>{q(`action:backlog.runagain`),a.verbs.onRunAgain(c.id,c.finishedAt)},children:[(0,J.jsx)(Nc,{size:14}),` `,`run it again`]}),lW(c)&&a.online&&(0,J.jsx)(Y,{"data-hint":`backlog.refire`,title:l,onClick:()=>{q(`action:backlog.refire`),a.verbs.onFire(c.id)},children:`re-fire`}),c.sessionId&&(0,J.jsxs)(Y,{title:`go to the session it ran in`,onClick:()=>a.nav.onOpenSession(c.sessionId),children:[(0,J.jsx)(Go,{size:14}),` open`]}),(c.status===`done`||aW(c)||c.status===`running`)&&a.online&&(c.checkStatus===`checking`?(0,J.jsxs)(`span`,{className:`bl-waiting`,children:[(0,J.jsx)(Bl,{size:14}),` checking…`]}):(0,J.jsxs)(Y,{title:`check if implemented`,onClick:()=>a.verbs.onCheck(c.id),children:[(0,J.jsx)(Bl,{size:14}),` check`]})),(c.status===`done`||aW(c)||c.status===`running`)&&a.online&&(c.validateStatus===`validating`?(0,J.jsxs)(`span`,{className:`bl-waiting`,children:[(0,J.jsx)(Gl,{size:14}),` validating…`]}):(0,J.jsxs)(Y,{title:`validate the expected outcome & get next steps`,onClick:()=>a.verbs.onValidate(c.id),children:[(0,J.jsx)(Gl,{size:14}),` validate`]})),c.status===`running`&&a.online&&(0,J.jsx)(Y,{"data-hint":`backlog.done`,onClick:()=>{q(`action:backlog.done`),a.verbs.onDone(c.id)},children:`done`}),c.status!==`running`&&a.online&&(c.archived?(0,J.jsx)(Y,{title:`unarchive`,onClick:()=>a.verbs.onArchive(c.id,!1),children:(0,J.jsx)(_c,{size:14})}):(0,J.jsx)(Y,{title:`archive`,onClick:()=>a.verbs.onArchive(c.id,!0),children:(0,J.jsx)(lo,{size:14})})),a.online&&(0,J.jsx)(Y,{variant:`danger`,onClick:()=>{q(`action:backlog.remove`),a.verbs.onRemove(c.id)},children:(0,J.jsx)(V,{size:16})})]})}function wbe({m:e,row:t}){let{clockCuts:n,namingIds:r,nextFireIds:i,now:a,p:o,targetClosed:s,targetReopens:c}=e,{it:l}=t;return(0,J.jsxs)(`span`,{className:`bl-meta`,children:[(0,J.jsx)(`span`,{className:`tag-${cW(l)}`,children:sW(l)}),l.category&&(()=>{let e=XK[l.category];return(0,J.jsxs)(`span`,{className:`bl-chip bl-cat`,children:[(0,J.jsx)(e,{size:11,style:{verticalAlign:`-1px`}}),` `,l.category]})})(),r.has(l.id)&&(0,J.jsxs)(`span`,{className:`bl-chip bl-naming`,title:`a naming pass is reading this row's words right now`,children:[(0,J.jsx)(Gl,{size:11,style:{verticalAlign:`-1px`}}),` naming…`]}),(0,J.jsxs)(`span`,{className:`bl-age`,title:`added ${new Date(l.createdAt).toLocaleString()} (${fW[mW(l.createdAt,a)]})`,children:[`added `,Gp(l.createdAt)]}),l.status===`running`&&l.startedAt!=null&&(0,J.jsxs)(`span`,{className:`bl-age`,title:`started ${new Date(l.startedAt).toLocaleString()}`,children:[`running `,AG(a-l.startedAt)]}),l.status!==`running`&&l.finishedAt!=null&&(0,J.jsxs)(`span`,{className:`bl-age`,title:`finished ${new Date(l.finishedAt).toLocaleString()}`,children:[l.status===`failed`?sW(l):`finished`,` `,Gp(l.finishedAt),l.startedAt!=null&&l.finishedAt>=l.startedAt?` · took ${AG(l.finishedAt-l.startedAt)}`:``]}),l.checkedAt!=null&&(0,J.jsxs)(`span`,{className:`bl-age`,title:`checked ${new Date(l.checkedAt).toLocaleString()}`,children:[`checked `,Gp(l.checkedAt)]}),l.validatedAt!=null&&(0,J.jsxs)(`span`,{className:`bl-age`,title:`validated ${new Date(l.validatedAt).toLocaleString()}`,children:[`validated `,Gp(l.validatedAt)]}),(l.steps??1)>1&&(0,J.jsxs)(`span`,{className:`bl-age`,title:`delivered one turn at a time, in one session`,children:[l.steps,` turns`]}),l.resume&&(0,J.jsxs)(`span`,{className:`bl-age`,title:`it reopens this repo's last conversation instead of starting clean`,children:[(0,J.jsx)(kc,{size:11,style:{verticalAlign:`-1px`}}),` continued`]}),wK(l)&&CK(l.closeWhenDone)&&(0,J.jsxs)(`span`,{className:`bl-age`,children:[l.closeWhenDone?(0,J.jsx)(Ao,{size:11,style:{verticalAlign:`-1px`}}):(0,J.jsx)(ls,{size:11,style:{verticalAlign:`-1px`}}),` `,CK(l.closeWhenDone)]}),wK(l)&&l.flagWhenDone&&(0,J.jsxs)(`span`,{className:`bl-age fu-launch`,title:`its session gets the follow-up flag once it is done`,children:[(0,J.jsx)(dl,{size:11,style:{verticalAlign:`-1px`}}),` flag when done`]}),wK(l)&&l.status===`queued`&&UT(l.launch)&&(0,J.jsxs)(`span`,{className:`bl-age`,children:[`opens on `,HT(l.launch)]}),wK(l)&&l.budget&&(TK(l)&&o.online?(0,J.jsxs)(`button`,{className:`bl-age${e.budgetOpen.has(l.id)?` active`:``}`,"aria-pressed":e.budgetOpen.has(l.id),onClick:()=>e.toggleBudget(l.id),children:[(0,J.jsx)(El,{size:11,style:{verticalAlign:`-1px`}}),` `,sE(l.budget)]}):(0,J.jsxs)(`span`,{className:`bl-age`,children:[(0,J.jsx)(El,{size:11,style:{verticalAlign:`-1px`}}),` `,sE(l.budget)]})),l.at&&(0,J.jsxs)(`span`,{className:`bl-chip bl-clock`,title:`this one waits for an instant rather than for its turn — tap “when” to change it, or “drop the clock” to put it back in the queue`,children:[(0,J.jsx)(Ss,{size:11,style:{verticalAlign:`-1px`}}),` `,WW(l.at,a,l.status)]}),(()=>{let e=l.at?qW(n,l.id):null;if(!e)return null;let t=n.find(e=>e.items.some(e=>e.id===l.id)),r=t.items[e.idx-1]?.id,i=t.items[e.idx+1]?.id;return(0,J.jsxs)(`span`,{className:`bl-chip bl-clock-seat`,title:QW,children:[XW(e),o.online&&r&&(0,J.jsx)(`button`,{className:`bl-seat-move`,"aria-label":`run earlier on this clock`,title:`run it earlier on this clock — moves it among the items waiting on this same clock — the instant does not change, and it never crosses an item on a different clock`,onClick:()=>{q(`action:backlog.clock.up`),o.verbs.onSwap(l.id,r)},children:(0,J.jsx)(Ts,{size:11})}),o.online&&i&&(0,J.jsx)(`button`,{className:`bl-seat-move`,"aria-label":`run later on this clock`,title:`run it later on this clock — moves it among the items waiting on this same clock — the instant does not change, and it never crosses an item on a different clock`,onClick:()=>{q(`action:backlog.clock.down`),o.verbs.onSwap(l.id,i)},children:(0,J.jsx)(Bs,{size:11})})]})})(),l.holdForHost&&(0,J.jsxs)(`span`,{className:`bl-chip bl-hold`,title:`it waits for nothing else to be starting or running anywhere on this desktop — not just in this repo. This is the schedule vocabulary's “wait until free”, and dropping the clock does not drop it`,children:[(0,J.jsx)(Kl,{size:11,style:{verticalAlign:`-1px`}}),` `,nG(!!l.at&&qK(l)&&o.online)]}),xi(l,a)&&(o.online&&l.status===`queued`?(0,J.jsxs)(`button`,{className:`bl-chip bl-hold`,title:`you let this past the usage budget — it still waits its turn; tap to hold it for the budget again`,onClick:()=>{q(`action:backlog.holdforbudget`),o.verbs.onHoldForBudget(l.id)},children:[(0,J.jsx)(wl,{size:11,style:{verticalAlign:`-1px`}}),` `,iG(!0)]}):(0,J.jsxs)(`span`,{className:`bl-chip bl-hold`,title:`you let this past the usage budget — it still waits its turn; tap to hold it for the budget again`,children:[(0,J.jsx)(wl,{size:11,style:{verticalAlign:`-1px`}}),` `,iG(!1)]})),i.has(l.id)&&(0,J.jsxs)(`span`,{className:`bl-next`,title:`auto will run this one next`,children:[(0,J.jsx)(Hc,{size:10,style:{verticalAlign:`-1px`}}),` next`]}),s(l)&&(0,J.jsx)(`span`,{className:`bl-next`,title:`the session it was aimed at has exited — nothing re-aims it; edit it to pick another session, take the aim off, or remove it`,children:`target closed — held`}),c(l)&&(0,J.jsx)(`span`,{className:`bl-next`,title:`the session it was aimed at has exited, but this row remembers the conversation — at its time it reopens that conversation in a session of its own and sends the words there`,children:`session closed — reopens its conversation`}),(()=>{let e=o.nav.scheduleFor?.(l);return e?o.nav.onOpenSchedule?(0,J.jsxs)(`button`,{className:`bl-chip bl-merged`,title:`open the schedule “${e.name}” — the rule that wrote this row`,onClick:()=>{q(`action:backlog.fromschedule`),o.nav.onOpenSchedule(e.id,e.name)},children:[(0,J.jsx)(Ss,{size:11,style:{verticalAlign:`-1px`}}),` `,KL(e.name)]}):(0,J.jsxs)(`span`,{className:`bl-chip bl-merged`,children:[(0,J.jsx)(Ss,{size:11,style:{verticalAlign:`-1px`}}),` `,KL(e.name)]}):null})(),Ri(l.origin)&&(o.nav.onOpenWeekBurn?(0,J.jsxs)(`button`,{className:`bl-chip bl-merged`,title:`open the week-end burn — what picked this repo and wrote this row`,onClick:()=>{q(`action:backlog.fromweekburn`),o.nav.onOpenWeekBurn()},children:[(0,J.jsx)(Tc,{size:11,style:{verticalAlign:`-1px`}}),` `,`from the week-end burn`]}):(0,J.jsxs)(`span`,{className:`bl-chip bl-merged`,children:[(0,J.jsx)(Tc,{size:11,style:{verticalAlign:`-1px`}}),` `,`from the week-end burn`]})),l.handOrdered&&(0,J.jsxs)(`span`,{className:`bl-chip bl-hand`,title:`its position was decided by you — a drag, or an assessment ranking you approved`,children:[(0,J.jsx)(Ns,{size:11,style:{verticalAlign:`-1px`}}),` you placed this`]})]})}function Tbe({m:e,it:t}){let{editCategory:n,editHeadline:r,editLabel:i,editRepo:a,editTarget:o,editText:s,p:c,repoLabel:l,saveEdit:u,setEditCategory:d,setEditHeadline:f,setEditingId:p,setEditLabel:m,setEditRepo:h,setEditTarget:g,setEditText:_}=e,v=t.status===`running`;return(0,J.jsx)(`div`,{className:`bl-row bl-${t.status} bl-edit`,children:(0,J.jsxs)(`div`,{className:`form`,style:{width:`100%`},children:[(0,J.jsx)(uD,{inline:!0,rows:3,prompts:[s],onChange:e=>_(e[0]??``),placeholder:`Instruction…`}),(0,J.jsx)(`input`,{className:`search`,value:i,onChange:e=>m(e.target.value),placeholder:`Label (optional)`}),(0,J.jsx)(`input`,{className:`search`,value:r,maxLength:80,onChange:e=>f(e.target.value),placeholder:`Suggested title (optional)`}),(0,J.jsx)(Z,{children:TG(t.headlineBy)}),(0,J.jsxs)(`select`,{className:`search`,value:n,"aria-label":`kind`,onChange:e=>d(e.target.value),children:[(0,J.jsx)(`option`,{value:``,children:`— none —`}),Xa.map(e=>(0,J.jsx)(`option`,{value:e,children:e},e))]}),v?(0,J.jsx)(Z,{as:`span`,children:l(a)}):(0,J.jsx)(ZO,{repos:c.repos,value:a,keepValue:!0,"aria-label":`repo`,onChange:e=>{h(e),g(``)}}),(()=>{let e=PG(c.sessions.filter(e=>e.running&&e.cwd===a),o);return e.length<2||v?null:(0,J.jsx)(`select`,{className:`search`,value:o,"aria-label":`session`,onChange:e=>g(e.target.value),children:e.map(e=>(0,J.jsx)(`option`,{value:e.value,children:e.label},e.value))})})(),(0,J.jsxs)(`div`,{className:`annot-tools`,children:[s.trim()&&c.online&&(0,J.jsx)(`button`,{className:`send`,onClick:()=>u(t),children:`Save`}),(0,J.jsx)(Y,{onClick:()=>p(null),children:`Cancel`})]}),!s.trim()&&(0,J.jsx)(Z,{children:`Nothing to save — type the task text.`}),v&&(0,J.jsx)(Z,{children:`Repo & session can't change while running.`}),!c.online&&(0,J.jsx)(Z,{children:`Offline — edits can't be saved until the connection is back.`})]})},t.id)}function Ebe({on:e,onSet:t}){return(0,J.jsx)(`div`,{className:`bl-close-chips`,children:(0,J.jsxs)(Y,{className:e?`active`:void 0,"aria-pressed":e,"data-hint":`session.followup`,onClick:()=>t(!e),children:[(0,J.jsx)(dl,{size:13,fill:e?`currentColor`:`none`}),` Flag for follow up when done`]})})}var Dbe=`A percent is converted from dollars at the window's measured rate once the session is running — until there is a fresh usage reading, nothing is held.`;function Obe({current:e,online:t,onSet:n,windowsOff:r}){let[i,a]=(0,H.useState)(e??null);if(!t)return(0,J.jsx)(`span`,{className:`bl-waiting`,children:`Changing the budget needs the desktop — the link is down.`});let o=!!i&&!!e&&i.unit===e.unit&&i.max===e.max&&i.interrupt===e.interrupt;return(0,J.jsxs)(`div`,{className:`bl-budget-edit`,children:[(0,J.jsx)($D,{initial:e??null,onChange:a,calFor:Dbe,windowsOff:r}),(0,J.jsxs)(`div`,{className:`bl-close-chips`,children:[i&&!o&&(0,J.jsxs)(Y,{className:`active`,onClick:()=>n(i),children:[(0,J.jsx)(El,{size:13}),` `,e?`change budget`:`set budget`]}),e&&(0,J.jsxs)(Y,{onClick:()=>n(null),children:[(0,J.jsx)(El,{size:13}),` clear budget`]})]})]})}function kbe({m:e,row:t}){let{fireIntoBusy:n,now:r,openDetail:i,openText:a,openValidate:o,p:s,runAgainHeld:c,runAgainOffered:l,setSlotOpen:u,slotOpen:d,slotSessions:f,targetLive:p,toggleDetail:m,toggleValidate:h}=e,{it:g,agentPosted:_}=t;return(0,J.jsxs)(J.Fragment,{children:[_&&a.has(g.id)&&(0,J.jsx)(`span`,{className:`bl-smart-note`,children:`posted by an agent — edit or delete it like any other`}),g.manual&&g.status===`queued`&&(0,J.jsx)(`span`,{className:`bl-hold`,children:`waits for your tap — nothing starts it by itself`}),g.at&&qK(g)&&s.online&&(0,J.jsx)(`span`,{className:`bl-smart-note`,children:oG(g.status)}),l(g)&&(0,J.jsx)(`span`,{className:`bl-smart-note`,children:dG(g)}),s.online&&g.status!==`running`&&(n(g)||g.status===`done`&&!l(g))&&(0,J.jsx)(`span`,{className:`bl-smart-note`,children:SM(!g.targetSessionId)}),c(g)&&(0,J.jsx)(`span`,{className:`bl-smart-note`,children:fG()}),g.requeued&&(0,J.jsx)(`span`,{className:`bl-smart-note`,children:xG(g.requeued,g.status,r)}),a.has(g.id)&&g.headline&&g.headlineBy&&(0,J.jsx)(`span`,{className:`bl-smart-note`,children:wG[g.headlineBy]}),g.status===`failed`&&g.error&&(0,J.jsx)(`span`,{className:g.calledOff?`bl-smart-note`:`bl-error`,children:g.error}),s.online&&g.status===`queued`&&s.waiting?.[g.id]&&!(EK(s.waiting[g.id],s.autoSlots)&&f.length>0)&&(p(g)&&/that session/i.test(s.waiting[g.id])?(0,J.jsx)(`button`,{className:`bl-waiting bl-waiting-act`,onClick:()=>s.nav.onOpenSession(g.targetSessionId),title:`go to the session this one is aimed at`,children:s.waiting[g.id]}):(0,J.jsx)(`span`,{className:`bl-waiting`,children:s.waiting[g.id]})),s.online&&g.status===`queued`&&EK(s.waiting?.[g.id],s.autoSlots)&&f.length>0&&(0,J.jsxs)(`div`,{className:`bl-slots`,children:[(0,J.jsxs)(Y,{className:`bl-step${d.has(g.id)?` active`:``}`,onClick:()=>u(e=>qG(e,g.id)),children:[(0,J.jsx)(Ao,{size:14}),` `,Tye(f.length)]}),d.has(g.id)&&(0,J.jsx)(`ul`,{className:`bl-slot-list`,children:f.map(({s:e,closeWhenDone:t})=>(0,J.jsxs)(`li`,{className:`bl-slot`,children:[(0,J.jsxs)(`button`,{className:`bl-slot-open`,onClick:()=>s.nav.onOpenSession(e.id),children:[(0,J.jsx)(`span`,{className:`bl-slot-title`,children:e.title}),(0,J.jsxs)(`span`,{className:`bl-slot-sub`,children:[`opened `,Gp(e.createdAt),` · `,Eye(e,t)]})]}),(0,J.jsxs)(Y,{variant:`danger`,onClick:()=>{q(`action:backlog.slotClose`),s.nav.onCloseSession(e)},children:[(0,J.jsx)(V,{size:14}),` close`]})]},e.id))})]}),a.has(g.id)&&wK(g)&&(0,J.jsxs)(`div`,{className:`bl-close-choice`,children:[(0,J.jsx)(`span`,{className:`bl-smart-note`,children:SK(g.closeWhenDone,s.closeWhenDoneGlobal)}),s.online?(0,J.jsx)(Bw,{label:`when this item is done`,options:yK.map(e=>({key:e,label:xK(e,s.closeWhenDoneGlobal)})),value:bK(g.closeWhenDone),onChange:e=>s.verbs.onSetCloseWhenDone(g.id,e)}):(0,J.jsx)(`span`,{className:`bl-waiting`,children:`Changing it needs the desktop — the link is down.`}),s.online&&(0,J.jsx)(Ebe,{on:!!g.flagWhenDone,onSet:e=>s.verbs.onSetFlagWhenDone(g.id,e)}),s.online&&TK(g)&&!g.budget&&(0,J.jsx)(`div`,{className:`bl-close-chips`,children:(0,J.jsxs)(Y,{className:e.budgetOpen.has(g.id)?`active`:void 0,"aria-pressed":e.budgetOpen.has(g.id),onClick:()=>e.toggleBudget(g.id),children:[(0,J.jsx)(El,{size:13}),` budget…`]})})]}),TK(g)&&e.budgetOpen.has(g.id)&&(0,J.jsx)(Obe,{current:g.budget,online:s.online,windowsOff:WT(s.backends??null,g.launch?.backend),onSet:t=>{s.verbs.onSetBudget(g.id,t),e.toggleBudget(g.id)}},`${g.id}:${g.budget?`${g.budget.unit}${g.budget.max}${g.budget.interrupt}`:`none`}`),a.has(g.id)&&(0,J.jsx)(`div`,{className:`bl-check-detail`,children:(0,J.jsx)(`div`,{className:`bl-steps`,children:s.online&&(0,J.jsxs)(Y,{className:`bl-step`,title:`open/resume a session seeded with this task as context`,onClick:()=>s.verbs.onContinue(g.id),children:[(0,J.jsx)(Go,{size:14}),` Continue in a session`]})})}),g.checkStatus&&(()=>{let e=g.checkStatus!==`checking`&&!!g.checkDetail,t=i.has(g.id);return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(e?`button`:`span`,{className:`bl-check bl-check-${g.checkStatus}`,title:e?`tap for full check details`:g.checkNote||``,onClick:e?()=>m(g.id):void 0,children:[(()=>{let e=JK(g.checkStatus).Icon;return(0,J.jsx)(e,{size:12,style:{verticalAlign:`-2px`}})})(),` `,JK(g.checkStatus).label,g.checkNote?` · ${g.checkNote}`:``,e?t?(0,J.jsx)(ac,{size:12,style:{verticalAlign:`-2px`}}):(0,J.jsx)(jl,{size:12,style:{verticalAlign:`-2px`}}):null]}),e&&t&&(0,J.jsxs)(`div`,{className:`bl-check-detail`,children:[(0,J.jsx)(`pre`,{children:g.checkDetail}),(0,J.jsx)(`div`,{className:`bl-steps`,children:s.online&&(0,J.jsxs)(Y,{className:`bl-step`,title:`open/resume a session with this task + verdict as context`,onClick:()=>s.verbs.onContinue(g.id),children:[(0,J.jsx)(Go,{size:14}),` Continue in a session`]})}),g.checkedAt&&(0,J.jsxs)(`span`,{className:`bl-check-when`,children:[`checked `,new Date(g.checkedAt).toLocaleString()]})]})]})})(),g.validateStatus&&(()=>{let e=g.validateStatus!==`validating`&&(!!g.validateDetail||!!g.validateSteps?.length),t=o.has(g.id);return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(e?`button`:`span`,{className:`bl-check bl-validate-${g.validateStatus}`,title:e?`tap for validation details & next steps`:g.validateNote||``,onClick:e?()=>h(g.id):void 0,children:[(()=>{let e=YK(g.validateStatus).Icon;return(0,J.jsx)(e,{size:12,style:{verticalAlign:`-2px`}})})(),` `,YK(g.validateStatus).label,g.validateNote?` · ${g.validateNote}`:``,e?t?(0,J.jsx)(ac,{size:12,style:{verticalAlign:`-2px`}}):(0,J.jsx)(jl,{size:12,style:{verticalAlign:`-2px`}}):null]}),e&&t&&(0,J.jsxs)(`div`,{className:`bl-check-detail`,children:[g.validateDetail&&(0,J.jsx)(`pre`,{children:g.validateDetail}),!!g.validateSteps?.length&&(0,J.jsxs)(`div`,{className:`bl-steps`,children:[(0,J.jsx)(`span`,{className:`bl-steps-head`,children:`Next steps — tap to run in the CLI:`}),g.validateSteps.map((e,t)=>s.online&&(0,J.jsxs)(Y,{className:`bl-step`,title:e.prompt,onClick:()=>s.verbs.onNextStep(g.id,t),children:[(0,J.jsx)(Go,{size:14}),` `,e.label]},t))]}),(0,J.jsx)(`div`,{className:`bl-steps`,children:s.online&&(0,J.jsxs)(Y,{className:`bl-step`,title:`open/resume a session with this task + verdict as context`,onClick:()=>s.verbs.onContinue(g.id),children:[(0,J.jsx)(Go,{size:14}),` Continue in a session`]})}),g.validatedAt&&(0,J.jsxs)(`span`,{className:`bl-check-when`,children:[`validated `,new Date(g.validatedAt).toLocaleString()]})]})]})})()]})}var rq=G(null);function Abe(){return K(rq)}function jbe(e,t=!1){W().conn.liveSend({t:`netretry.set`,enabled:e},Gr(e,t))}function iq(e,t){W().conn.liveSend({t:`session.netRetryCancel`,id:e},t?`hidden — stalled work keeps its note`:`retry cancelled — nothing more is typed`)}function aq(e){W().conn.liveSend({t:`session.netRetryNow`,id:e},vte)}function Mbe(){W().conn.liveSend({t:`netretry.set`,enabled:!1},`${Gr(!1)} — Settings › Sessions turns it back on`)}function oq({id:e,label:t,note:n,more:r}){let i=Abe();return i?(0,J.jsx)(eT,{id:e,label:t,icon:vl,on:i.envOff?i.enabled:ha(i),state:i.envOff?i.enabled?`saved on`:`saved off`:void 0,onChange:()=>jbe(!i.enabled,!!i.envOff),note:n,more:r,children:i.envOff&&(0,J.jsx)($w,{tone:`plain`,icon:Js,children:Dr()})}):null}function Nbe(e,t){if(e.state!==`running`||!e.sessionId)return null;let n=t.find(t=>t.id===e.sessionId),r=n?Cr(n):null;return!r||r.kind!==`auth`?null:r.phase===`needsYou`?Yee:r.detail??`stopped: the CLI is signed out — sign in, then continue`}function sq({state:e,sessionId:t,sessions:n}){let r=ur({state:e,sessionId:t},n);if(r&&t)return(0,J.jsx)(Pbe,{n:r,sessionId:t});let i=Nbe({state:e,sessionId:t},n);return i?(0,J.jsx)(`div`,{className:`net-stalled`,role:`status`,children:(0,J.jsxs)(`span`,{className:`netretry-line`,children:[(0,J.jsx)(ns,{size:14,"aria-hidden":`true`}),` `,i]})}):null}function Pbe({n:e,sessionId:t}){let n=_E(3e4);return(0,J.jsxs)(`div`,{className:`net-stalled`,role:`status`,children:[(0,J.jsxs)(`span`,{className:`netretry-line`,children:[(0,J.jsx)(vl,{size:14,"aria-hidden":`true`}),` `,Ta(e,n)]}),(0,J.jsx)(Z,{children:e.error}),(0,J.jsx)(`div`,{className:`net-stalled-verbs`,children:(0,J.jsxs)(Y,{title:Lte,onClick:()=>aq(t),children:[(0,J.jsx)(Kc,{size:14,"aria-hidden":`true`}),` retry now`]})}),(0,J.jsx)(oq,{label:`auto-retry`,note:`The desktop's own switch (Settings › Sessions): on, it retries the next give-up by itself and tries this stalled one again on a slow clock (the note says when); off, this row waits for retry now or your typing.`})]})}function Fbe({m:e,g:t,it:n,idx:r}){let{canDrag:i,clockCuts:a,dragId:o,editingId:s,filter:c,now:l,openText:u,p:d,picked:f,picking:p,setDragId:m,setPicked:h,drawSort:g,toggleText:_}=e,v=g===`run`?t.items[r-1]?.id:void 0,y=g===`run`?t.items[r+1]?.id:void 0,b={it:n,idx:r,g:t,up:v,down:y,agentPosted:Mi(n)};if(s===n.id)return(0,J.jsx)(Tbe,{m:e,it:n});let x=(()=>{if(!c.clock||!n.at)return null;let e=GW(n),r=a.find(t=>t.key===e);return!r||t.items.find(t=>GW(t)===e)?.id!==n.id?null:(0,J.jsxs)(`div`,{className:`bl-group-head bl-clock-head`,children:[(0,J.jsxs)(`span`,{className:`bl-group-title`,children:[(0,J.jsx)(Ss,{size:13}),` `,ZW(r,l)]}),(0,J.jsx)(`span`,{className:`bl-group-meta`,children:`in this order`})]})})();return(0,J.jsxs)(H.Fragment,{children:[x,(0,J.jsxs)(`div`,{"data-blid":n.id,className:`bl-row bl-${cW(n)} ${o===n.id?`dragging`:``}`,children:[(0,J.jsxs)(`div`,{className:`bl-head`,children:[p&&IG(n)&&(0,J.jsx)(KG,{on:f.has(n.id),onToggle:()=>h(e=>qG(e,n.id))}),(0,J.jsx)(`span`,{className:`bl-num`,children:t.seats.get(n.id)??r+1}),(0,J.jsxs)(`div`,{className:`bl-main`,children:[(()=>{let e=jG(n);if(e)return(0,J.jsx)(`span`,{className:`bl-label`,children:e});let t=zn(n);if(!t)return null;let r=n.headlineBy!==`hand`;return(0,J.jsxs)(`span`,{className:`bl-label${r?` bl-headline`:``}`,children:[r?(0,J.jsx)(Gl,{size:11}):null,r?` `:``,t]})})(),(0,J.jsx)(`button`,{className:`bl-text bl-text-btn ${u.has(n.id)?`open`:``}`,title:u.has(n.id)?`collapse`:`expand — full task & continue in a session`,onClick:()=>_(n.id),children:n.text}),(()=>{let e=pt(n.text).filter(e=>!/[<>*{}]/.test(e));return e.length?(0,J.jsx)(`div`,{className:`bl-thumbs`,children:e.map(e=>{let t=d.nav.imageSrc(n.repoDir,e);return t?(0,J.jsx)(`button`,{className:`bl-thumb`,title:`view & mark ${e}`,onClick:()=>d.verbs.onEditImage(n,e),children:(0,J.jsx)(`img`,{src:t,alt:``,loading:`lazy`,onError:e=>{e.currentTarget.parentElement.hidden=!0}})},e):null})}):null})(),(0,J.jsx)(wbe,{m:e,row:b}),(0,J.jsx)(kbe,{m:e,row:b}),(0,J.jsx)(sq,{state:n.status,sessionId:n.sessionId,sessions:d.sessions})]}),(0,J.jsxs)(`div`,{className:`bl-order`,children:[i&&(0,J.jsx)(Y,{className:`drag-handle`,title:`drag to reorder`,style:{touchAction:`none`,cursor:`grab`},onPointerDown:e=>{e.preventDefault(),m(n.id)},children:(0,J.jsx)(Ko,{size:14})}),v&&d.online&&(0,J.jsx)(Y,{onClick:()=>d.verbs.onSwap(n.id,v),title:`move up`,children:(0,J.jsx)(Ts,{size:14})}),y&&d.online&&(0,J.jsx)(Y,{onClick:()=>d.verbs.onSwap(n.id,y),title:`move down`,children:(0,J.jsx)(Bs,{size:14})})]})]}),(0,J.jsx)(Cbe,{m:e,row:b})]})]},n.id)}function Ibe({m:e}){let{base:t,displayOrder:n,dragId:r,groups:i,hereInRepo:a,q:o}=e;return(0,J.jsxs)(`div`,{className:`list`,style:{touchAction:r?`none`:void 0},children:[n.length===0&&(0,J.jsx)($,{children:t.length===0?`Nothing waiting for this repo — “send…” above writes one.`:o?`No match in this repo.`:`Nothing here matches that filter — ${t.length} item${t.length===1?``:`s`} are hidden by it.`}),i.map(t=>(0,J.jsxs)(`div`,{className:`bl-group`,children:[(0,J.jsxs)(`div`,{className:`bl-group-head`,children:[(0,J.jsxs)(`span`,{className:`bl-group-title`,children:[t.key===`__closed`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(ec,{size:13}),` `,t.title]}):t.key?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Go,{size:13}),` `,t.title]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(yl,{size:13}),` `,t.title]}),a&&t.key===a.id&&(0,J.jsx)(yE,{className:`bl-here`,children:`on screen`})]}),(0,J.jsx)(`span`,{className:`bl-group-meta`,children:`${t.items.length} item${t.items.length===1?``:`s`}`})]}),t.key===`__closed`&&(0,J.jsx)(`div`,{className:`empty bl-group-empty`,children:`The session each of these was aimed at has exited. Nothing re-aims them: edit one to pick another session or a new one, take the aim off, or remove it.`}),t.items.map((n,r)=>(0,J.jsx)(Fbe,{m:e,g:t,it:n,idx:r},n.id))]},t.key||`__default`))]})}function Lbe({m:e}){let{filter:t}=e;return(0,J.jsxs)(`div`,{className:`sheet-scroll`,children:[t.ids&&(0,J.jsx)(tq,{m:e}),(0,J.jsx)(mbe,{m:e}),(0,J.jsx)(hbe,{m:e}),(0,J.jsx)(gbe,{m:e}),(0,J.jsx)(_be,{m:e}),(0,J.jsx)(bbe,{m:e}),(0,J.jsx)(Sbe,{m:e}),(0,J.jsx)(xbe,{m:e}),(0,J.jsx)(Ibe,{m:e})]},t.ids?t.ids.join(`,`):``)}function Rbe(e){let t=abe(),n=lbe(e),r=ube(),i=dbe(),a=_E(3e4),o=sbe(e),s=ibe(e,a,{...n,...r},i.picked),c=obe(e,s),l={p:e,now:a,...t,...n,...r,...i,...o,...s,...c};return(0,J.jsxs)(`div`,{className:`sheet`,children:[(0,J.jsx)(pbe,{m:l}),(0,J.jsx)(Lbe,{m:l})]})}function zbe(e){return e===`idle`?`When free`:`Send`}function Bbe(e){return e===`idle`?`Hand it to the desktop and let it go in when this session is free — turn ended, no question open, no usage-limit block`:`Send to this session`}function cq(e,t){return e===`now`?null:t.holder===`phone`?t.phoneHold===`opens-a-view`?t.online?`held on this phone — it opens a view rather than starting a turn, so it goes in when this turn ends. Leave the app open`:`held on this phone — it goes in when the link is back and this turn has ended. Leave the app open`:t.online?`queued — it runs in this session when it opens`:`queued — the session opens and runs this when the link is back`:t.online?`queued on the desktop — it goes in when this session is free`:`queued — it reaches the desktop when the link is back, and goes in when this session is free`}var Vbe=`kept on the pad — nothing runs it; open the pad to send it or file it onto a backlog`,Hbe=`nothing in the box to keep — the pad holds words, and there are none yet`;function Ube(){return[{key:`now`,label:`now`,icon:`send`,mode:`now`,title:`type it into this session straight away`},{key:`idle`,label:`when it's free`,icon:`hourglass`,mode:`idle`,title:`the desktop holds it and types it in when this session can take it — turn ended, no question open, no usage-limit block`},{key:`pad`,label:`keep it on the pad`,icon:`pad`,mode:null,title:`park the words on the pad — nothing runs them, no backlog, no trigger; you decide later whether they go anywhere`},{key:`elsewhere`,label:`elsewhere or later…`,icon:`elsewhere`,mode:null,title:`a different session, a new one, several repos — or at a time`}]}var Wbe=`Runs in`;function lq(){return[{key:`this`,label:`this session`,title:`the conversation on screen — it already knows what you have said in it, and every turn pays for that whole window again`},{key:`new`,label:`a new session`,title:`open a fresh session in this repo and run it there — none of this conversation comes with it, which is what makes it cheaper`},{key:`other`,label:`another open session`,title:`one of the other sessions running right now — pick which one below`}]}function Gbe(e){return lq().find(t=>t.key===e)?.label??`this session`}function Kbe(e,t){if(e===`this`)return null;if(e===`new`)return`Send opens a NEW session in ${t.repoName||`this repo`} — not the conversation on screen.`;let n=(t.sessionName??``).trim();return n?`Send goes to ${n} — not the conversation on screen.`:`Send is aimed at another session and none is picked — choose one under the chevron, or aim it back here.`}var qbe=`aim it here`,Jbe=`no session picked — choose one under the chevron, or aim it back at this session`;function Ybe(e){let t=(e??``).trim();return`${t?`“${t}”`:`that session`} has closed — nothing was sent, and the aim is back on this session`}function Xbe(e,t,n){if(t===`this`)return Bbe(e);if(t===`new`)return e===`idle`?`Open a fresh session in this repo and run it there when this repo is free — not the conversation on screen`:`Open a fresh session in this repo and run it there — not the conversation on screen`;let r=(n??``).trim()||`another open session`;return e===`idle`?`Hand it to the desktop and let it go in when ${r} is free — not the conversation on screen`:`Send it to ${r} — not the conversation on screen`}function Zbe(e){return e.how!==`now`||e.explicit||!e.aimedHere||!e.turnActive||e.pending||e.localCmd?e.how:e.pref===``?`ask`:e.pref}var uq={title:`This session is still working`,lines:[`Send now: claude queues the words and takes them at its next pause — after the command it is running, which can be minutes.`,`When it's free: the desktop holds them and sends them once this turn ends.`,`Tap outside to keep the words in the box.`],confirmLabel:`Send now`,cancelLabel:`When it's free`,rememberLabel:`don't ask again`},Qbe=`When it's free, past the budget`;function $be(e){if(!e)return{...uq,lines:[...uq.lines]};let[t,n,r]=uq.lines;return{...uq,lines:[t,`${n} The usage budget holds it after that: ${e}.`,`When it's free, past the budget: the same, but this prompt does not wait for the budget.`,r],altLabel:Qbe}}function exe(e){return e?`queued past the budget — the desktop sends it once this turn ends`:`queued past the budget — it reaches the desktop when the link is back, then goes in once this session is free`}function txe(e){return e===`idle`?`won't ask again — Send on a working session now waits until it is free; Settings › Writing & reading › Send while it works changes it`:`won't ask again — Send on a working session now goes straight in; Settings › Writing & reading › Send while it works changes it`}function nxe(e){return Ar(e.name,Ka(e.action))??(e.name.length>40?`${e.name.slice(0,40)}…`:e.name)}function rxe(e){let t=new Map,n=new Map;for(let r of e){let e={id:r.id,name:nxe(r)};t.set(r.id,e);let i=r.lastResult?.childId;i&&n.set(i,e)}return{byId:t,byChild:n}}function ixe(e,t){let n=new Map,r=new Map;for(let i of e){if(!ga(i))continue;let e=t(i),a={id:i.id,name:e.length>40?`${e.slice(0,40)}…`:e};n.set(i.id,a);let o=i.result?.childId;o&&r.set(o,a)}return{byId:n,byChild:r}}function axe(e){return e?`reading the repo to judge ${e.length===1?`this one`:`these ${e.length}`} — this takes a while; the proposal lands here`:`reading the repo — this takes a while; the proposal lands here`}function oxe(e){return`queued — ${e===1?`it goes`:`all ${e} go`} back in the queue when the link is back`}var dq={repoDir:null,text:``,filter:SW,idsLabel:void 0};function fq(e,t){return{...e,repoDir:t,filter:e.filter.ids?{...e.filter,ids:null}:e.filter,idsLabel:void 0}}function sxe(e,t){return!t||t===e.repoDir?e:fq(e,t)}function cxe(e,t,n,r){return n?.length?{...e,repoDir:t,filter:{...SW,ids:n},idsLabel:r??`made from these`}:{...e,repoDir:t,filter:SW,idsLabel:void 0}}function lxe(e){return{...dq,repoDir:e.repoDir}}function uxe(){let e=EE(B.snapBacklog,{});return{items:e.items??[],auto:e.auto??!1,waiting:{},naming:[],autoSlots:null,snapAt:e.at??null}}var pq=G(uxe()),mq=G(dq),hq=G(new Map),gq=G(null),_q=G(null),vq=G(null),yq=G(new Map);function dxe(){return K(pq)}function fxe(e){let t=Date.now();pq.set({items:e.items,auto:e.auto,waiting:e.waiting??{},naming:e.naming??[],autoSlots:e.autoSlots??null,snapAt:t}),DE(B.snapBacklog,{items:e.items,auto:e.auto,idleMs:e.idleMs,at:t}),Zye(e.items)}function pxe(e,t){let n=W().nav.overlay;hq.set(r=>{let i=r.get(e);return t&&i&&n!==`assess`&&i.runId===t.runId&&i.status===`running`&&t.status===`running`?r:t?yh(r,e,t):bh(r,e)})}function mxe(){W().conn.send({t:`assess.state`})}function bq(e,t){yq.set(yh(yq.get(),e,t))}function hxe(e,t,n,r){let i=yq.get().get(e);if(i===void 0||(yq.set(bh(yq.get(),e)),!t||!i.length))return;let a=hye(i,n);a.clear.length&&r(a.clear);let o=gye(a);o&&W().say.toast(o)}function gxe(e){mq.set(t=>fq(t,e.worktreePath)),W().nav.open(`backlog`)}function _xe(e){mq.set(t=>sxe(t,e)),W().nav.open(`backlog`)}function xq(e,t,n){mq.set(r=>cxe(r,e,t,n)),W().nav.open(`backlog`)}function vxe(e){mq.set(e)}function yxe(){mq.set(lxe)}function Sq(e,t){let n=W(),r=e.worktreePath;gq.set(e),_q.set(t?.length?t:null),vq.set(null),n.conn.liveAsk({t:`assess.state`,repoDir:r}),n.nav.open(`assess`),!hq.get().get(r)&&Cq(r,t)}function Cq(e,t,n){let r=W();r.say.track(`action:assess.run`);let i=r.queue.mintAckId(),a=t?.length?t:void 0,o=a&&n?{scope:n}:{};r.conn.liveSend({t:`assess.run`,repoDir:e,ids:a,...o,ackId:i,firstSentAt:Date.now()},axe(a),`no connection — the assessment runs on the desktop`)&&bq(i,[])}function bxe(e,t){let n=W();n.say.track(`action:assess.apply`);let r=n.queue.mintAckId(),i=t.news??[],a=(e.proposal?.news??[]).filter((e,t)=>i.includes(t)&&e.fromNote).map(e=>e.fromNote);n.conn.liveSend({t:`assess.apply`,runId:e.runId,choices:t,ackId:r,firstSentAt:Date.now()},`applying your decisions…`,`no connection — applying starts work on the desktop and can't be queued from here`)&&bq(r,a)}function wq(e){let t=W(),n=t.world.repos.find(t=>t.worktreePath===e.repoDir)??t.world.repoForCwd(e.repoDir);if(!n){t.say.toast(`that repo is not on this desktop's list any more`);return}let r=n.worktreePath;gq.set(n),_q.set([...e.ids]),vq.set(e.scope),t.conn.liveAsk({t:`assess.state`,repoDir:r}),t.nav.open(`assess`);let i=Kye(hq.get().get(r),e);if(i===`run`){Cq(r,e.ids,e.scope);return}let a=qye(i,e.ids.length);a&&t.say.toast(a)}function xxe(){gq.set(null),_q.set(null),vq.set(null),W().nav.close(`assess`)}function Sxe(e,t){let n=W(),r=Tq(n,e,t,n.world.intents.find(t=>t.id===e));n.say.toast(r?`queued — it goes back in the queue when the link is back`:pG)}function Cxe(e){let t=W(),n=!1;for(let{id:r,failedAt:i}of e)n=Tq(t,r,i,t.world.intents.find(e=>e.id===r))||n;t.say.toast(n?oxe(e.length):mG(e.length))}function Tq(e,t,n,r){return e.queue.queueOp({t:`intent.requeue`,id:t,failedAt:n},`intent:${t}`,r?.label||r?.title||`run it again`,{cwd:r?.cwd})}function wxe(){let e=_h(),{liveSend:t,liveSendAll:n}=e.conn,{queueOp:r}=e.queue,{intents:i,sessions:a,visibleRepos:o,active:s,pending:c,budget:l,schedules:u}=e.world,d=e.conn.status===`open`,f=K(pq),p=K(mq),m=K(hq),h=K(yq),g=oy(`closeWhenDone`),{cwdVisible:_}=e.world,v=(0,H.useMemo)(()=>f.items.filter(e=>_(e.repoDir)),[f.items,_]),y=(0,H.useMemo)(()=>rxe(u),[u]),b=fh(`weekburn`,()=>U.getWeekBurn()),x=(0,H.useMemo)(()=>ixe(i,VH),[i]),S=t=>e.world.repos.find(e=>e.worktreePath===t)?.id;return(0,J.jsx)(Rbe,{items:v,auto:f.auto,repos:o,backends:e.world.backends,waiting:f.waiting,autoSlots:d?f.autoSlots:null,closeWhenDoneGlobal:g,intents:i,naming:d?f.naming:[],snapAt:f.snapAt,online:d,cut:p,setCut:vxe,activeSession:s&&!c?{id:s.id,cwd:s.cwd,title:s.title||`this session`}:null,sessions:a,defaultRepoDir:s?.cwd,verbs:{onSetCloseWhenDone:(e,n)=>t({t:`backlog.update`,id:e,closeWhenDone:bye(n)},Cye(n,g),bW),onSetFlagWhenDone:(e,n)=>t({t:`backlog.update`,id:e,flagWhenDone:n?!0:null},n?`its session gets the follow-up flag once it is done`:`no follow-up flag when it is done`,bW),onSetBudget:(e,n)=>t({t:`backlog.update`,id:e,budget:n},n?`its session will start with that budget`:`no budget on its session`,bW),onDropClock:e=>t({t:`intent.update`,id:e,patch:{trigger:{kind:`idle`}}},sG,bW),onHoldForBudget:e=>t({t:`intent.waive`,id:e,rung:`budget`,on:!1},aG,bW),onRunAgain:Sxe,onEditWhen:t=>{let n=i.find(e=>e.id===t);n?e.nav.openSend(e.send.seedFromIntent(n)):e.say.toast(`that row is gone`)},onRemove:e=>t({t:`backlog.remove`,id:e},`removed`,bW),onUpdate:(e,n)=>t({t:`backlog.update`,id:e,...n},`saved`,bW),onQueueHere:(e,n)=>t({t:`backlog.update`,id:e,targetSessionId:n,autoFire:!!n},n?cq(`idle`,{online:d,holder:`desktop`}):`taken off this session's queue`,bW),onSwap:(e,n)=>t({t:`backlog.swap`,id:e,otherId:n},`reordered`,bW),onFire:n=>{t({t:`backlog.fire`,id:n},`running it now…`,`no connection — the backlog lives on the desktop, so nothing here changed. Adding still queues.`)&&e.nav.followFire(n)},onDone:e=>t({t:`backlog.done`,id:e},`marked done`,bW),onArchive:(e,n)=>t({t:`backlog.archive`,id:e,archived:n},n?`archived`:`unarchived`,bW),onCheck:e=>t({t:`backlog.check`,id:e},`checking…`,bW),onValidate:e=>t({t:`backlog.validate`,id:e},`validating…`,bW),onNextStep:(n,r)=>{t({t:`backlog.nextStep`,id:n,step:r},`firing the next step…`,`no connection — the backlog lives on the desktop, so nothing here changed. Adding still queues.`)&&e.nav.followFire(n)},onContinue:n=>{t({t:`backlog.continue`,id:n},`continuing…`,`no connection — the backlog lives on the desktop, so nothing here changed. Adding still queues.`)&&e.nav.followFire(n)},onEditImage:e.files.editBacklogImage},cutVerbs:{onDropClocks:e=>n(e.map(e=>({t:`intent.update`,id:e,patch:{trigger:{kind:`idle`}}})),cG(e.length),bW),onRunAgainMany:Cxe,onName:(t,n)=>{let i=r({t:`backlog.name`,repoDir:t,ids:n},`name:${t}`,EG(n.length),{cwd:t});e.say.toast(i?`Queued · ${kG(EG(n.length))}`:kG(EG(n.length)))},onReorder:e=>t({t:`backlog.reorder`,ids:e},`order saved`,bW),onSetAuto:e=>t({t:`backlog.setAuto`,enabled:e},`auto ${e?`on`:`off`}`,bW),onArchiveMany:e=>n(e.map(e=>({t:`backlog.archive`,id:e,archived:!0})),zW(e.length),bW),onAssess:(e,t)=>{let n=o.find(t=>t.worktreePath===e);n&&Sq(n,t)},onSlotCheck:e=>wq(e),assessBlocked:e=>m.get(e)??null?null:gK({run:null,online:d,busy:h.size>0,budgetNote:l?.verdict.blocked?Gi(l.verdict):null})},nav:{onCloseSession:e.nav.closeSession,scheduleFor:e=>{let t=Pi(e.origin);return(t?y.byId.get(t):void 0)??y.byChild.get(e.id)??(t?x.byId.get(t):void 0)??x.byChild.get(e.id)??null},onOpenSchedule:(t,n)=>{if(y.byId.has(t)){e.nav.openScheduleCut([t],qL(n));return}let r=i.find(e=>e.id===t);r?xq(r.cwd,[t],YL(n)):e.say.toast(`that schedule is no longer on the desktop`)},onOpenWeekBurn:()=>e.nav.open(`weekburn`),onOpenCut:(e,t,n)=>xq(e,t,n),weekBurnText:e=>rK({repoDir:e,weekburn:b.state===`fresh`?b.data:null,when:Pe,repoName:e=>{let t=o.find(t=>t.worktreePath===e);return t?Wn(t):e.split(/[/\\]/).filter(Boolean).pop()||e}})?.text??null,renderRetime:e.send.renderRetime,onClose:()=>e.nav.close(`backlog`),onOpenSend:(t,n)=>{let r=o.find(e=>e.worktreePath===t);e.nav.openSend({prompts:n?[n]:void 0,target:{kind:`repo`,cwd:t},when:{kind:`idle`},cwdHint:t,repoId:r?.id??null,origin:n?`Kept from the backlog's old add field`:`From the backlog`})},onOpenSession:t=>{let n=a.find(e=>e.id===t);n&&e.nav.attach(n)},imageSrc:(e,t)=>{let n=S(e);return n?(bj(n,t),sg(U.artifactUrl(n,t),ag(72),gj(n,t))):null}}})}var Eq=new Map,Dq=e=>({rows:[...e.rows],merges:[...e.merges],news:[...e.news],rejected:[...e.rejected],pinRanks:e.pinRanks===!0,writeNames:e.writeNames===!0,...e.splits?{splits:[...e.splits]}:{}});function Oq(e){if(!e)return null;let t=Eq.get(e);return t?Dq(t):null}function Txe(e,t){e&&Eq.set(e,Dq(t))}function kq(e){Eq.delete(e)}function Exe(e){let t=e.run,n=t?.proposal??null,r=(0,H.useMemo)(()=>t?.input?.items??[],[t]),i=t?.runId,[a,o]=(0,H.useState)(()=>new Set(Oq(i??``)?.rows??[])),[s,c]=(0,H.useState)(()=>new Set(Oq(i??``)?.merges??[])),[l,u]=(0,H.useState)(()=>new Set(Oq(i??``)?.news??[])),[d,f]=(0,H.useState)(()=>new Set(Oq(i??``)?.rejected??[])),[p,m]=(0,H.useState)(()=>new Set(Oq(i??``)?.splits??[])),[h,g]=(0,H.useState)(()=>new Set),_=(0,H.useRef)(i);(0,H.useEffect)(()=>{if(_.current===i)return;let e=_.current;_.current=i,e&&kq(e),o(new Set),c(new Set),u(new Set),f(new Set),m(new Set),g(new Set)},[i]);let v=(0,H.useMemo)(()=>n?Kve(n,r):[],[n,r]),y=(0,H.useMemo)(()=>n?ee(n):null,[n]),b=(0,H.useMemo)(()=>zye(n,r),[n,r]),x=(0,H.useMemo)(()=>Gye(n,r),[n,r]),S=(0,H.useMemo)(()=>{let e=new Map;for(let t of r)t?.id&&e.set(t.id,t);return e},[r]),C=_E(t?.status===`running`?1e3:6e4),w=yye(t,C),[T,E]=(0,H.useState)(!1),D=t&&t.status!==`running`?t.progress:void 0,O=eye({rows:a,merges:s,news:l,splits:p}),[k,A]=(0,H.useState)(!1),j=_ye({run:t,picked:O,online:e.online,busy:e.busy}),M=gK({run:t,online:e.online,busy:e.busy,budgetNote:e.budgetNote}),N=e.scope?.length??0,P=(0,H.useMemo)(()=>n?n.rows.filter(e=>e.verdict===`wanted`&&e.rank!=null&&a.has(e.id)).length+s.size+l.size:0,[n,a,s,l]),[F,I]=(0,H.useState)(()=>Oq(i??``)?.pinRanks??!0),te=(0,H.useMemo)(()=>n?Lt(n):0,[n]),[ne,re]=(0,H.useState)(()=>Oq(i??``)?.writeNames??!0);(0,H.useEffect)(()=>{i&&Txe(i,{rows:[...a],merges:[...s],news:[...l],rejected:[...d],pinRanks:F,writeNames:ne,...p.size?{splits:[...p]}:{}})},[i,a,s,l,d,F,ne,p]);let ie=e=>{o(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n}),f(t=>{let n=new Set(t);return n.delete(`row:${e}`),n})},ae=e=>{c(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n}),f(t=>{let n=new Set(t);return n.delete(`merge:${e}`),n})},oe=e=>{u(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n}),f(t=>{let n=new Set(t);return n.delete(`new:${e}`),n})},se=(e,t)=>{f(n=>{let r=new Set(n);return r.delete(e)||(r.add(e),t()),r})},ce=(t,n)=>{let r=t.rows.filter(e=>!e.acceptBlocked);if(!r.length)return;if(r.every(e=>a.has(e.id))){q(`action:assess.untick.${t.verdict}`),o(e=>{let n=new Set(e);for(let e of t.rows)n.delete(e.id);return n});return}q(`action:assess.bulk.${t.verdict}`);let i=()=>{o(e=>{let t=new Set(e);for(let e of r)t.add(e.id);return t}),f(e=>{let t=new Set(e);for(let e of r)t.delete(`row:${e.id}`);return t})},s=n.ask;!n.confirm||!s?i():(async()=>{await mT({title:s.title,lines:Yve(r,{repoName:e.repoName,verdict:t.verdict}),confirmLabel:s.confirmLabel})&&i()})()},le=t=>{q(`action:assess.merge`),s.has(t.gid)?ae(t.gid):(async()=>{await mT({title:`Replace ${t.originals.length||t.ids.length} items with one prompt?`,lines:Qve(t,{repoName:e.repoName}),confirmLabel:`Approve the merge`})&&ae(t.gid)})()},ue=e=>{m(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n}),f(t=>{let n=new Set(t);return n.delete(`split:${e}`),n})},de=t=>{q(`action:assess.split`),p.has(t.sid)?ue(t.sid):(async()=>{await mT({title:`Split this item in two?`,lines:Yye(t,e.repoName),confirmLabel:`Approve the split`})&&ue(t.sid)})()},fe=()=>{q(`action:assess.apply`),e.onApply(Jye({rows:a,merges:s,news:l,splits:p,pinRanks:P>0?F:void 0,writeNames:te>0?ne:void 0})),i&&kq(i)},pe=e.res??{state:e.online?t?`fresh`:`loading`:`offline`},me=!n||!(n.rows.length+n.merges.length+n.news.length+x.length+b.length),he=t?.finishedAt??t?.startedAt,ge=t?.planPath,_e=n?nye(n,{rows:[...a],merges:[...s],news:[...l]},r):null,ve=_e?rye(_e,e.repoName,{writeNames:te>0&&ne,ranked:P,pinRanks:F,splits:p.size}):``,ye=(0,H.useMemo)(()=>t?.applied&&e.onOpenBacklog?oye(t,e.backlog??[]):null,[t,e.backlog,e.onOpenBacklog]),be=N&&e.slot?MK(N,!!t):N?`${t?`run again on`:`assess`} ${N===1?`this one`:`these ${N}`}`:t?`run again`:`assess`;return{conflicts:b,splits:x,pickedSplits:p,setPickedSplits:m,acceptSplit:de,slotIntro:Rye(t?.scope,t?.scopedIds?.length,C),p:e,run:t,proposal:n,items:r,runId:i,pickedRows:a,setPickedRows:o,pickedMerges:s,setPickedMerges:c,pickedNews:l,setPickedNews:u,rejected:d,setRejected:f,flipped:h,setFlipped:g,seeded:_,groups:v,counts:y,itemsById:S,now:C,watch:w,logOpen:T,setLogOpen:E,pastSteps:D,picked:O,guideOpen:k,setGuideOpen:A,applyBlocked:j,runBlocked:M,scopeN:N,rankedN:P,pinRanks:F,setPinRanks:I,nameCount:te,writeNames:ne,setWriteNames:re,toggleRow:ie,toggleMerge:ae,toggleNew:oe,toggleReject:se,bulkGroup:ce,acceptMerge:le,apply:fe,res:pe,nothing:me,finishedAt:he,planPath:ge,applySummary:_e,applyLabel:ve,ready:ye,runLabel:be,guide:$ve({repoName:e.repoName,judged:t?.assessableCount??n?.rows.length??0,planPath:ge||void 0,named:te})}}var Aq=G(null);function Dxe(){return K(Aq)}function jq(e){let t=W();Aq.set(Kce(e)?e:null),t.say.track(`action:settings.door`),t.nav.open(`settings`)}var Mq={done:`tag-done`,obsolete:`tag-done`,superseded:`tag-done`,merged:`tag-running`,wanted:`tag-queued`,unclear:`queued`},Oxe={running:`tag-running`,done:`tag-queued`,failed:`tag-failed`,applied:`tag-done`},kxe={read:Qo,search:Lc,edit:us,run:xo,task:Uc,web:Vs,say:rl,tool:$s};function Axe({m:e}){let{p:t,run:n,proposal:r,runBlocked:i,scopeN:a,planPath:o,runLabel:s}=e;return(0,J.jsxs)(J.Fragment,{children:[o&&t.onOpenPlan?(0,J.jsxs)(Y,{title:`open ${o}, the write-up the run left for you — for reading; it does not run anything, and your ticks are kept`,onClick:()=>{q(`action:assess.plan`),t.onOpenPlan?.(o)},children:[(0,J.jsx)(Nl,{size:16}),` read the plan`]}):null,r&&t.onDiscard?(0,J.jsxs)(uT,{className:`key`,title:`throw this proposal away without applying any of it`,confirm:`discard it?`,confirmTitle:`nothing is applied, and the items keep their words`,onConfirm:()=>{q(`action:assess.discard`),t.onDiscard?.()},children:[(0,J.jsx)(ic,{size:16}),` discard`]}):null,i?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(CE,{cants:[{label:s,reason:i}]}),t.budgetNote&&i===t.budgetNote&&(0,J.jsxs)(Y,{onClick:()=>jq(`budget`),children:[(0,J.jsx)(co,{size:16}),` change the usage budget`]})]}):(0,J.jsxs)(Y,{title:a?`judge ${a===1?`the one row`:`the ${a} rows`} you came here with — it still reads ${t.repoName} as evidence`:n?`read ${t.repoName} again and judge what is left now`:`read ${t.repoName} and judge what is left`,onClick:()=>{q(`action:assess.run`),t.onRun()},children:[(0,J.jsx)(Hc,{size:16}),` `,s]})]})}function jxe({m:e}){let{p:t,setPickedRows:n,setPickedMerges:r,setPickedNews:i,picked:a,applyBlocked:o,apply:s,applySummary:c,applyLabel:l,ready:u}=e;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`act-bulk`,children:[(0,J.jsx)(`span`,{className:`act-bulk-n`,children:tye(a)}),a?(0,J.jsxs)(Y,{title:`un-tick everything — nothing has happened yet, so nothing is undone`,onClick:()=>{q(`action:assess.clear`),n(new Set),r(new Set),i(new Set)},children:[(0,J.jsx)(V,{size:14}),` clear`]}):null,o?(0,J.jsx)(CE,{cants:[{label:`apply`,reason:o}]}):(0,J.jsxs)(Y,{variant:`primary`,title:l,onClick:s,children:[(0,J.jsx)(Bl,{size:14}),` `,l]}),u?(0,J.jsxs)(Y,{variant:`primary`,className:`asr-route`,title:hK(u.n),onClick:()=>{q(`action:assess.backlog`),t.onOpenBacklog?.(u.ids,cye(t.repoName))},children:[(0,J.jsx)(Vl,{size:14}),` `,sye(u.n,t.repoName)]}):null]}),(0,J.jsx)(Z,{children:iye(c?.requeue??0)}),u?(0,J.jsx)(Z,{children:hK(u.n)}):null]})}function Mxe({m:e}){let{run:t,finishedAt:n}=e;return t?(0,J.jsxs)(`div`,{className:`act-triage`,children:[(0,J.jsx)(yE,{className:Oxe[t.status],children:t.status}),n?(0,J.jsx)(`span`,{className:`act-count`,children:Gp(n)}):null,t.assessableCount==null?null:(0,J.jsxs)(`span`,{className:`act-count`,children:[t.assessableCount,` judged`,t.itemCount!=null&&t.itemCount>t.assessableCount?` · ${t.itemCount-t.assessableCount} read as context`:``]}),t.scopedIds?.length?(0,J.jsxs)(`span`,{className:`act-count`,title:`this run was asked about a cut of the backlog, not the whole repo — it still read the repo as evidence`,children:[t.scope?.kind===`slot`?`slot check ·`:`scoped to`,` `,t.scopedIds.length===1?`1 row`:`${t.scopedIds.length} rows`]}):null,t.applied?(0,J.jsx)(`span`,{className:`act-count`,children:lye(t.applied)}):null]}):null}var Nq=`keep:`,Pq=e=>e.startsWith(Nq)?e.slice(5):null,Fq=12;async function Nxe(e,t){await Xb(`uploads`,Nq+e,{relPath:e,blob:t,ts:Date.now()}),await Ixe()}async function Iq(e){return(await Yb(`uploads`,Nq+e))?.blob??null}async function Pxe(){return(await $b(`uploads`)).map(Pq).filter(e=>!!e)}async function Fxe(e){await Zb(`uploads`,Nq+e)}async function Ixe(){let e=(await $b(`uploads`)).filter(e=>Pq(e));if(e.length<=Fq)return;let t=await Promise.all(e.map(async e=>({k:e,ts:(await Yb(`uploads`,e))?.ts??0})));t.sort((e,t)=>e.ts-t.ts);for(let{k:e}of t.slice(0,t.length-Fq))await Zb(`uploads`,e)}async function Lxe(e,t,n,r,i){let a=rj(e);if(!a.length)return{refs:a,states:[]};let o={onHost:null,sending:hn(n),kept:await Pxe(),dead:Zie()};if(t&&r){let e=a.some(e=>e.relPath.startsWith(`.claude/inbox/`)),n=a.some(e=>!e.relPath.startsWith(`.claude/inbox/`)),[r,s]=await Promise.all([e?U.inbox(t,i).catch(()=>null):Promise.resolve([]),n?U.artifacts(t,`outbox`,void 0,{signal:i}).then(e=>e.files).catch(()=>null):Promise.resolve([])]);o.onHost=r&&s?[...r,...s].map(e=>e.relPath):null}return{refs:a,states:kee(a.map(e=>e.relPath),o)}}async function Lq(e,t,n){if(t===`sending`){let t=n.find(t=>t.mode===`upload`&&t.upload?.relPath===e),r=t?await Yb(`uploads`,t.ackId):null;if(r)return URL.createObjectURL(r)}if(t===`sending`||t===`kept`||t===`dead`||t===`missing`||t===`unknown`){let t=await Iq(e);if(t)return URL.createObjectURL(t)}return null}var Rq=`app:open-attachment`;function Rxe(e){try{window.dispatchEvent(new CustomEvent(Rq,{detail:e}))}catch{}}function zxe(e){switch(e.state){case`host`:return`in the repo`;case`sending`:return`uploads before this message`;case`kept`:return`not uploaded — the file is still on this phone`;case`dead`:return e.why?`not uploaded — ${e.why}`:`not uploaded`;case`missing`:return`not in the repo, and not on this phone`;case`unknown`:return`can't check without a connection`}}var zq=e=>e.startsWith(Nq);async function Bxe(){return nx(`uploads`,zq)}var Vxe=96,Hxe={host:Xo,sending:Uo,kept:$c,dead:Js,missing:_s,unknown:gl};function Uxe({fref:e,state:t,repoId:n,localSrc:r}){let[i,a]=(0,H.useState)(!1),o=t.state===`host`?n:null,s=xj(o,e.relPath),c=!r&&e.image&&!i&&o?sg(U.artifactUrl(o,e.relPath),ag(Vxe),s):null,{src:l,live:u}=jj(c),d=r??l,f=!!d||!!o&&!e.image,p=d?(0,J.jsx)(`img`,{src:d,alt:e.name,loading:`lazy`,onLoad:()=>{c&&u&&s&&Oj(c)},onError:()=>a(!0)}):(0,J.jsx)(`span`,{className:`attach-noimg`,children:(0,J.jsx)(Nl,{size:16})});return f?(0,J.jsx)(`button`,{type:`button`,className:`attach-thumb tap`,title:`${e.relPath} — tap to open`,onClick:()=>Rxe({relPath:e.relPath,repoId:n,state:t.state}),children:p}):(0,J.jsx)(`div`,{className:`attach-thumb`,children:p})}function Bq({text:e,repoId:t,outbox:n,online:r,nonce:i,onStates:a,onReattach:o,onReplace:s,onForget:c,onRemove:l,compact:u,debounceMs:d=0}){let[f,p]=(0,H.useState)(e);(0,H.useEffect)(()=>{if(!d){p(e);return}let t=window.setTimeout(()=>p(e),d);return()=>window.clearTimeout(t)},[e,d]);let[m,h]=(0,H.useState)([]),g=(0,H.useRef)([]),[_,v]=(0,H.useState)({}),y=k(n);return(0,H.useEffect)(()=>{let e=new AbortController;return(async()=>{let{refs:i,states:o}=await Lxe(f,t,n,r,e.signal);if(e.signal.aborted)return;h(i.map((e,t)=>({ref:e,state:o[t]}))),a?.(o);let s={},c=[];for(let e=0;e<i.length;e++){if(!i[e].image)continue;let t=await Lq(i[e].relPath,o[e].state,n);t&&(s[i[e].relPath]=t,c.push(t))}e.signal.aborted?c.forEach(e=>URL.revokeObjectURL(e)):(g.current.forEach(e=>URL.revokeObjectURL(e)),g.current=c,v(s))})(),()=>e.abort()},[f,t,r,i,y]),(0,H.useEffect)(()=>()=>{g.current.forEach(e=>URL.revokeObjectURL(e))},[]),m.length?(0,J.jsx)(`div`,{className:`attach-strip ${u?`compact`:``}`,children:m.map(({ref:e,state:n})=>{let r=Hxe[n.state],i=_[e.relPath],a=n.state!==`host`&&n.state!==`sending`,d=l?()=>{h(t=>t.filter(t=>t.ref.relPath!==e.relPath)),l(e.relPath)}:null;return(0,J.jsxs)(`div`,{className:`attach-item ${n.state}`,children:[(0,J.jsx)(Uxe,{fref:e,state:n,repoId:t,localSrc:i}),(0,J.jsxs)(`div`,{className:`attach-body`,children:[(0,J.jsx)(`span`,{className:`attach-name`,title:e.relPath,children:e.name}),(0,J.jsxs)(`span`,{className:`attach-state`,children:[(0,J.jsx)(r,{size:11}),` `,zxe(n)]}),!u&&a&&(0,J.jsxs)(`div`,{className:`attach-acts`,children:[n.state===`kept`&&o&&(0,J.jsxs)(Y,{title:`put this phone's copy back in the send queue, under the same path — the message needs no change`,onClick:()=>o(e.relPath),children:[(0,J.jsx)($c,{size:14}),` re-attach`]}),s&&(0,J.jsxs)(Y,{title:`pick a different file for this mention — the path in the message is rewritten to the new one`,onClick:()=>s(e.relPath),children:[(0,J.jsx)(Xo,{size:14}),` pick a file`]}),c&&(0,J.jsxs)(Y,{variant:`danger`,title:`take this mention out of the message and send the words without it`,onClick:()=>c(e.relPath),children:[(0,J.jsx)(ic,{size:14}),` drop mention`]})]})]}),d&&(0,J.jsx)(`button`,{type:`button`,className:`attach-x`,"aria-label":`remove ${e.name} from the prompt`,onPointerDown:e=>e.preventDefault(),onClick:d,children:(0,J.jsx)(V,{size:16})})]},e.relPath)})}):null}function Vq(e){let[t,n]=(0,H.useState)(!1),r=(0,H.useRef)(null);return(0,H.useEffect)(()=>{if(!e||t)return;let i=r.current;if(!i||typeof IntersectionObserver>`u`){n(!0);return}let a=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(n(!0),a.disconnect())},{rootMargin:`300px`});return a.observe(i),()=>a.disconnect()},[e,t]),[t,r]}function Hq({steps:e}){return e.length?(0,J.jsx)(`div`,{className:`assess-log`,children:e.map((e,t)=>{let n=kxe[e.kind]??$s;return(0,J.jsxs)(`div`,{className:`assess-step${e.kind===`say`?` assess-step-say`:``}`,children:[(0,J.jsx)(n,{size:12}),(0,J.jsx)(`span`,{className:`assess-step-label`,children:e.label}),e.detail?(0,J.jsx)(`span`,{className:`assess-step-detail`,children:e.detail}):null]},`${e.at}:${t}`)})}):null}function Uq({headline:e,suggested:t,category:n}){if(!e&&!n)return null;let r=n?XK[n]:null;return(0,J.jsxs)(J.Fragment,{children:[n&&r?(0,J.jsxs)(`span`,{className:`bl-chip bl-cat`,children:[(0,J.jsx)(r,{size:11}),` `,n]}):null,e?(0,J.jsxs)(`span`,{className:`act-where asr-headline`,children:[t?(0,J.jsx)(Gl,{size:11}):null,e]}):null]})}function Wq({text:e,repoId:t,outbox:n,online:r}){let i=(0,H.useMemo)(()=>!!e&&rj(e).length>0,[e]),[a,o]=Vq(i);return i?(0,J.jsx)(`div`,{ref:o,children:a?(0,J.jsx)(Bq,{compact:!0,text:e,repoId:t,outbox:n,online:r}):null}):null}function Wxe({m:e}){let{p:t,proposal:n,pickedNews:r,setPickedNews:i,rejected:a,toggleNew:o,toggleReject:s}=e;return(0,J.jsx)(J.Fragment,{children:n&&n.news.length?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`section section-head`,children:[(0,J.jsx)(`span`,{children:n.news.some(e=>e.fromNote)?`what it proposes to add`:`missing pieces it proposes`}),(0,J.jsx)(`span`,{className:`section-hint`,children:n.news.some(e=>e.fromNote)?`new items the run wrote, and pad notes of yours it says are still worth doing — offered in your own words`:`prose and a position, and nothing else — these are new items, not verdicts on yours`})]}),n.news.some(e=>!e.fromNote)?(0,J.jsx)(`div`,{className:`act-verdict assess-effect`,children:dye(t.repoName)}):null,n.news.map((e,n)=>{let c=!!e.fromNote,l=c?fye:uye;return(0,J.jsxs)(`div`,{className:`q-card${c?` asr-offer`:``}${a.has(`new:${n}`)?` act-filed`:``}`,children:[(0,J.jsxs)(`div`,{className:`q-head`,children:[c?(0,J.jsx)(Po,{size:14}):(0,J.jsx)(os,{size:14}),(0,J.jsx)(`span`,{className:`bl-group-title`,children:c?`from your pad`:`a new item`}),e.rank==null?null:(0,J.jsxs)(`span`,{className:`act-count`,children:[`position `,e.rank]})]}),e.headline||e.category?(0,J.jsx)(`div`,{className:`act-head asr-namehead`,children:(0,J.jsx)(Uq,{headline:e.headline,suggested:!!e.headline,category:e.category})}):null,c?(0,J.jsx)(`div`,{className:`act-verdict assess-effect`,children:pye(t.repoName)}):null,(0,J.jsx)(`div`,{className:`act-text act-text-full`,children:e.prompt}),(0,J.jsx)(Wq,{text:e.prompt,repoId:t.repoId,outbox:t.outbox,online:t.online}),(0,J.jsxs)(`div`,{className:`act-acts`,children:[(0,J.jsxs)(Y,{className:r.has(n)?`primary`:void 0,title:r.has(n)?l.pickedTitle:l.title,onClick:()=>{q(c?`action:assess.accept.note`:`action:assess.accept.new`),o(n)},children:[(0,J.jsx)(ys,{size:16}),` `,r.has(n)?l.picked:l.label]}),(0,J.jsxs)(Y,{className:a.has(`new:${n}`)?`active`:void 0,title:a.has(`new:${n}`)?lK.pickedTitle:c?`leave the note on the pad — nothing is filed and nothing is removed`:`do not add this`,onClick:()=>{q(`action:assess.leave`),s(`new:${n}`,()=>i(e=>{let t=new Set(e);return t.delete(n),t}))},children:[(0,J.jsx)(V,{size:16}),` `,a.has(`new:${n}`)?lK.picked:lK.label]})]})]},n)})]}):null})}function Gq({row:e,m:t}){let{p:n}=t;return e.text==null?(0,J.jsxs)(`span`,{className:`act-stale`,children:[(0,J.jsx)(Js,{size:11}),` `,e.id,` — its words are not on this phone`]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`act-text act-text-full`,children:e.text}),(0,J.jsx)(Wq,{text:e.text,repoId:n.repoId,outbox:n.outbox,online:n.online})]})}function Gxe({m:e}){let{p:t,conflicts:n,splits:r,pickedSplits:i,setPickedSplits:a,rejected:o,setRejected:s,acceptSplit:c,itemsById:l}=e;if(!n.length&&!r.length)return null;let u=e=>s(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n});return(0,J.jsxs)(J.Fragment,{children:[n.length?(0,J.jsxs)(`div`,{className:`act-group`,children:[(0,J.jsxs)(`div`,{className:`act-group-head`,children:[(0,J.jsx)(yE,{className:`tag-failed`,children:`contradict`}),(0,J.jsx)(`span`,{className:`act-group-n`,children:n.length})]}),(0,J.jsx)(`div`,{className:`act-verdict assess-effect`,children:Bye}),n.map(n=>{let r=o.has(`conflict:${n.cid}`);return(0,J.jsxs)(`div`,{className:`q-card${r?` act-filed`:``}`,children:[(0,J.jsxs)(`div`,{className:`q-head`,children:[(0,J.jsx)(gc,{size:14}),(0,J.jsx)(`span`,{className:`bl-group-title`,children:n.sentence})]}),n.rows.map(n=>{let r=l.get(n.id);return(0,J.jsx)(`div`,{className:`act-row`,children:(0,J.jsxs)(`div`,{className:`act-body`,children:[(0,J.jsx)(`span`,{className:`act-head`,children:(0,J.jsx)(`span`,{className:`act-when mono`,children:n.id})}),(0,J.jsx)(Gq,{row:n,m:e}),t.online||r&&t.onOpenItem?(0,J.jsxs)(`div`,{className:`act-acts`,children:[r&&t.onOpenItem?(0,J.jsxs)(Y,{title:`show it where its words live`,onClick:()=>{q(`action:assess.conflict.open`),t.onOpenItem?.(r)},children:[(0,J.jsx)(mo,{size:16}),` open`]}):null,t.online&&t.onEditItem?(0,J.jsxs)(Y,{title:`change its words or its time — the send sheet, with this row in it`,onClick:()=>{q(`action:assess.conflict.edit`),t.onEditItem?.(n.id)},children:[(0,J.jsx)(us,{size:16}),` edit`]}):null,t.online&&t.onDropItem?(0,J.jsxs)(uT,{confirm:Hye,title:Uye,onConfirm:()=>{q(`action:assess.conflict.drop`),t.onDropItem?.(n.id)},children:[(0,J.jsx)(V,{size:16}),` `,Vye]}):null]}):null]})},n.id)}),t.online?null:(0,J.jsx)(Z,{children:`No connection — edit and drop wait for the link.`}),(0,J.jsx)(`div`,{className:`act-acts`,children:(0,J.jsxs)(Y,{className:r?`active`:void 0,title:r?`un-mark it`:`leave every row here as it is — nothing is sent either way`,onClick:()=>{q(`action:assess.conflict.ignore`),u(`conflict:${n.cid}`)},children:[(0,J.jsx)(ys,{size:16}),` `,r?`left as they are`:Wye]})})]},n.cid)})]}):null,r.length?(0,J.jsxs)(`div`,{className:`act-group`,children:[(0,J.jsxs)(`div`,{className:`act-group-head`,children:[(0,J.jsx)(yE,{className:`tag-running`,children:`split`}),(0,J.jsx)(`span`,{className:`act-group-n`,children:r.length})]}),r.map(n=>{let r=i.has(n.sid),s=o.has(`split:${n.sid}`);return(0,J.jsxs)(`div`,{className:`q-card${s?` act-filed`:``}`,children:[(0,J.jsxs)(`div`,{className:`q-head`,children:[(0,J.jsx)(ps,{size:14}),(0,J.jsx)(`span`,{className:`bl-group-title`,children:n.sentence})]}),(0,J.jsxs)(`div`,{className:`section section-head`,children:[(0,J.jsx)(`span`,{children:`the item as written`}),(0,J.jsx)(`span`,{className:`section-hint mono`,children:n.id})]}),(0,J.jsx)(`div`,{className:`act-row`,children:(0,J.jsx)(`div`,{className:`act-body`,children:(0,J.jsx)(Gq,{row:n.original,m:e})})}),(0,J.jsxs)(`div`,{className:`section section-head`,children:[(0,J.jsx)(`span`,{children:`the two it would become`}),(0,J.jsx)(`span`,{className:`section-hint`,children:`written by the assessment, not by you`})]}),n.texts.map((e,n)=>(0,J.jsx)(`div`,{className:`act-row`,children:(0,J.jsxs)(`div`,{className:`act-body`,children:[(0,J.jsx)(`span`,{className:`act-text act-text-full`,children:e}),(0,J.jsx)(Wq,{text:e,repoId:t.repoId,outbox:t.outbox,online:t.online})]})},n)),(0,J.jsxs)(`div`,{className:`act-acts`,children:[(0,J.jsxs)(Y,{className:r?`primary`:void 0,title:r?`approved — tap to un-approve`:`approve: the original is archived (words kept) and these two are posted on its clock`,onClick:()=>c(n),children:[(0,J.jsx)(ys,{size:16}),` `,r?`approved`:`approve the split`]}),(0,J.jsxs)(Y,{className:s?`active`:void 0,title:s?`un-mark it`:`keep it as one item`,onClick:()=>{q(`action:assess.split.leave`),u(`split:${n.sid}`),a(e=>{let t=new Set(e);return t.delete(n.sid),t})},children:[(0,J.jsx)(V,{size:16}),` keep it as one`]})]})]},n.sid)})]}):null]})}function Kxe({r:e,accepted:t,rejected:n,onAccept:r,onReject:i,onOpen:a,repoId:o,outbox:s,online:c}){let l=cK(e.verdict,e.source,e.failed),u=uK(e),d=e.acceptBlocked;return(0,J.jsxs)(`div`,{className:`act-row${n?` act-filed`:``}${t?` act-running`:``}`,children:[(0,J.jsxs)(`div`,{className:`act-body`,children:[(0,J.jsxs)(`span`,{className:`act-head`,children:[u.headline?null:(0,J.jsx)(`span`,{className:`act-when`,children:u.kind}),(0,J.jsx)(Uq,{headline:u.headline,suggested:u.suggested,category:u.category}),u.id?(0,J.jsx)(`span`,{className:`act-when mono`,children:u.id}):null]}),e.missing?(0,J.jsxs)(`span`,{className:`act-stale`,children:[(0,J.jsx)(Js,{size:11}),` `,Bve(e.id)]}):(0,J.jsx)(`span`,{className:`act-text act-text-full`,children:e.text}),(0,J.jsx)(Wq,{text:e.text,repoId:o,outbox:s,online:c}),(0,J.jsxs)(`span`,{className:`act-verdict${e.downgraded?` act-last-bad`:``}`,children:[e.downgraded?(0,J.jsx)(Js,{size:11}):null,e.sentence]}),(()=>{let t=Wve(e);return t?(0,J.jsx)(`span`,{className:`act-verdict`,children:t}):null})(),e.supersededByText?(0,J.jsxs)(`span`,{className:`act-verdict`,children:[`the item said to cover it: “`,e.supersededByText,`”`]}):null,d?(0,J.jsx)(wE,{children:d}):null,n?(0,J.jsx)(`span`,{className:`act-filed-note`,children:`left exactly as it is — nothing will happen to it`}):null]}),(0,J.jsxs)(`div`,{className:`act-acts`,children:[d?null:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(Y,{className:t?`primary`:void 0,title:t?l.pickedTitle:l.title,onClick:r,children:[(0,J.jsx)(ys,{size:16}),` `,t?l.picked:l.label]}),(0,J.jsxs)(Y,{className:n?`active`:void 0,title:n?lK.pickedTitle:lK.title,onClick:i,children:[(0,J.jsx)(V,{size:16}),` `,n?lK.picked:lK.label]})]}),a?(0,J.jsxs)(Y,{title:`show this item where it lives`,onClick:a,children:[(0,J.jsx)(Nl,{size:16}),` open`]}):null]})]})}function qxe({card:e,accepted:t,rejected:n,onAccept:r,onReject:i,repoId:a,outbox:o,online:s}){let c=e.originals.length||e.ids.length;return(0,J.jsxs)(`div`,{className:`q-card${n?` act-filed`:``}`,children:[(0,J.jsxs)(`div`,{className:`q-head`,children:[(0,J.jsx)(dc,{size:14}),(0,J.jsxs)(`span`,{className:`bl-group-title`,children:[`one prompt in place of `,c]}),e.rank==null?null:(0,J.jsxs)(`span`,{className:`act-count`,children:[`position `,e.rank]})]}),(0,J.jsx)(`div`,{className:`act-verdict`,children:e.rationale||`no rationale was given — the prompt and the originals below are all there is to judge it on`}),(0,J.jsxs)(`div`,{className:`section section-head`,children:[(0,J.jsx)(`span`,{children:`the prompt it would run`}),(0,J.jsx)(`span`,{className:`section-hint`,children:`written by the assessment, not by you`})]}),e.headline||e.category?(0,J.jsx)(`div`,{className:`act-head asr-namehead`,children:(0,J.jsx)(Uq,{headline:e.headline,suggested:!!e.headline,category:e.category})}):null,(0,J.jsx)(`div`,{className:`act-text act-text-full`,children:e.prompt}),(0,J.jsx)(Wq,{text:e.prompt,repoId:a,outbox:o,online:s}),(0,J.jsxs)(`div`,{className:`section section-head`,children:[(0,J.jsxs)(`span`,{children:[`it replaces these `,c,`, in full`]}),(0,J.jsx)(`span`,{className:`section-hint mono`,children:e.ids.join(` · `)})]}),e.originals.map(e=>{let t=uK(e);return(0,J.jsx)(`div`,{className:`act-row`,children:(0,J.jsxs)(`div`,{className:`act-body`,children:[(0,J.jsxs)(`span`,{className:`act-head`,children:[t.headline?null:(0,J.jsx)(`span`,{className:`act-when`,children:t.kind}),(0,J.jsx)(Uq,{headline:t.headline,suggested:t.suggested,category:t.category}),t.id?(0,J.jsx)(`span`,{className:`act-when mono`,children:t.id}):null]}),e.missing?(0,J.jsxs)(`span`,{className:`act-stale`,children:[(0,J.jsx)(Js,{size:11}),` not on this phone`]}):(0,J.jsx)(`span`,{className:`act-text act-text-full`,children:e.text}),(0,J.jsx)(Wq,{text:e.text,repoId:a,outbox:o,online:s})]})},e.id)}),e.missingIds.length?(0,J.jsxs)(`div`,{className:`act-stale`,children:[(0,J.jsx)(Js,{size:11}),` `,e.missingIds.length,` of the items this merge names`,e.missingIds.length===1?` is`:` are`,` not on this phone, so`,e.missingIds.length===1?` its words are`:` their words are`,` not shown above.`]}):null,(0,J.jsxs)(`div`,{className:`act-acts`,children:[(0,J.jsxs)(Y,{className:t?`primary`:void 0,title:t?`approved — tap to un-approve`:`approve this merge: one new item, and all ${c} retired with a reason`,onClick:r,children:[(0,J.jsx)(ys,{size:16}),` `,t?`approved`:`approve the merge`]}),(0,J.jsxs)(Y,{className:n?`active`:void 0,title:n?`un-mark it`:`leave all of them exactly as they are`,onClick:i,children:[(0,J.jsx)(V,{size:16}),` leave all `,c]})]})]})}function Jxe({m:e}){let{p:t,pickedRows:n,setPickedRows:r,pickedMerges:i,setPickedMerges:a,rejected:o,flipped:s,setFlipped:c,groups:l,itemsById:u,toggleRow:d,toggleReject:f,bulkGroup:p,acceptMerge:m}=e;return(0,J.jsx)(J.Fragment,{children:l.map(e=>{let l=e.fixedOpen||(s.has(e.verdict)?!e.defaultOpen:e.defaultOpen),h=e.verdict===`unclear`?Jve(e.rows):[],g=e.rows.filter(e=>!e.acceptBlocked&&n.has(e.id)).length,_=Zve(e,g,{repoName:t.repoName});return(0,J.jsxs)(`div`,{className:`act-group`,children:[(0,J.jsxs)(`div`,{className:`act-group-head`,children:[(0,J.jsx)(yE,{className:Mq[e.verdict],children:e.label}),(0,J.jsx)(`span`,{className:`act-group-n`,children:e.count}),_?(0,J.jsxs)(Y,{title:_.title,onClick:()=>p(e,_),children:[(0,J.jsx)(Bl,{size:14}),` `,_.label]}):null,e.fixedOpen?null:(0,J.jsx)(Y,{className:`act-group-more`,title:l?`collapse this`:`show these`,onClick:()=>{q(`action:assess.strip.${e.verdict}`),c(t=>{let n=new Set(t);return n.delete(e.verdict)||n.add(e.verdict),n})},children:l?(0,J.jsx)(Ys,{size:14}):(0,J.jsx)(ac,{size:14})})]}),l&&e.verdict!==`merged`?(0,J.jsx)(`div`,{className:`act-verdict assess-effect`,children:cK(e.verdict,void 0,e.failed>0).effect}):null,l&&h.length?(0,J.jsx)(`div`,{className:`act-group-head`,children:h.map(e=>(0,J.jsxs)(`span`,{className:`act-count`,children:[e.n,` × `,e.text]},e.down))}):null,l?e.merges.map(e=>(0,J.jsx)(qxe,{card:e,accepted:i.has(e.gid),rejected:o.has(`merge:${e.gid}`),repoId:t.repoId,outbox:t.outbox,online:t.online,onAccept:()=>m(e),onReject:()=>f(`merge:${e.gid}`,()=>a(t=>{let n=new Set(t);return n.delete(e.gid),n}))},e.gid)):null,l?e.rows.map(e=>{let i=u.get(e.id);return(0,J.jsx)(Kxe,{r:e,accepted:n.has(e.id),rejected:o.has(`row:${e.id}`),repoId:t.repoId,outbox:t.outbox,online:t.online,onAccept:()=>{q(`action:assess.accept.${e.verdict}`),d(e.id)},onReject:()=>{q(`action:assess.leave`),f(`row:${e.id}`,()=>r(t=>{let n=new Set(t);return n.delete(e.id),n}))},onOpen:i&&t.onOpenItem?()=>{q(`action:assess.open`),t.onOpenItem?.(i)}:void 0},e.id)}):null]},e.verdict)})})}function Yxe({m:e}){let{rankedN:t,pinRanks:n,setPinRanks:r,nameCount:i,writeNames:a,setWriteNames:o}=e;return t>0||i>0?(0,J.jsxs)(`div`,{className:`asr-asks`,children:[t>0&&(0,J.jsxs)(Z,{className:`asr-pin`,children:[xt(t),(0,J.jsx)(`div`,{className:`asr-answer`,children:(0,J.jsx)(Bw,{label:`the order of the rows`,value:n?`keep`:`free`,options:[{key:`keep`,label:`keep this order`},{key:`free`,label:`leave it unmarked`}],onChange:e=>{e===`keep`?(q(`action:assess.pin`),r(!0)):(q(`action:assess.pin.free`),r(!1))}})}),(0,J.jsx)(`div`,{children:ite(n)})]}),i>0&&(0,J.jsxs)(Z,{className:`asr-pin`,children:[g(i),(0,J.jsx)(`div`,{className:`asr-answer`,children:(0,J.jsx)(Bw,{label:`the run's titles`,value:a?`write`:`skip`,options:[{key:`write`,label:`write them`},{key:`skip`,label:`leave the rows as they are`}],onChange:e=>{e===`write`?(q(`action:assess.name`),o(!0)):(q(`action:assess.name.skip`),o(!1))}})}),(0,J.jsx)(`div`,{children:cte(a)})]})]}):null}function Xxe({m:e}){let{logOpen:t,setLogOpen:n,pastSteps:r}=e;return(0,J.jsxs)(J.Fragment,{children:[r&&r.tail.length?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`section section-head`,children:[(0,J.jsx)(`span`,{children:`what it looked at`}),(0,J.jsxs)(Y,{title:t?`collapse this`:`show these`,onClick:()=>{q(`action:assess.log`),n(e=>!e)},children:[t?(0,J.jsx)(Ys,{size:14}):(0,J.jsx)(ac,{size:14}),` `,_K(r.steps,r.tail.length).button]})]}),t?(0,J.jsx)(Hq,{steps:r.tail}):null]}):null,(0,J.jsx)(Yxe,{m:e})]})}function Zxe({m:e}){let{p:t,run:n,proposal:r,counts:i,watch:a,guideOpen:o,setGuideOpen:s,res:c,nothing:l,guide:u}=e;return(0,J.jsxs)(J.Fragment,{children:[i?(0,J.jsx)(`div`,{className:`act-filters`,children:cn.map(e=>(0,J.jsxs)(yE,{className:Mq[e],children:[ve(e),` `,(0,J.jsx)(`span`,{className:`act-count`,children:i[e]})]},e))}):null,n?(0,J.jsxs)(`div`,{className:`assess-intro`,children:[e.slotIntro?(0,J.jsx)(`div`,{className:`assess-guide-lead`,children:e.slotIntro}):null,(0,J.jsx)(`div`,{className:`assess-guide-lead`,children:u.lead}),(0,J.jsx)(`div`,{className:`act-group-head`,children:(0,J.jsxs)(Y,{title:o?`hide this`:`what accepting and applying on this screen actually do`,onClick:()=>{q(`action:assess.guide`),s(e=>!e)},children:[o?(0,J.jsx)(Ys,{size:14}):(0,J.jsx)(ac,{size:14}),` how this works`]})}),o?(0,J.jsx)(`ul`,{className:`assess-guide`,children:u.lines.map((e,t)=>(0,J.jsx)(`li`,{children:e},t))}):null]}):null,n?.detail?(0,J.jsx)(Z,{tone:n.status===`failed`?`warn`:void 0,children:n.detail}):null,n?.status===`failed`&&n.envelope?(0,J.jsx)(`div`,{className:`hist-out mono`,children:n.envelope}):null,a?(0,J.jsxs)(`div`,{className:`assess-watch`,children:[(0,J.jsxs)(`div`,{className:`assess-doing`,children:[(0,J.jsx)(Ml,{size:16,className:`spin`}),(0,J.jsx)(`span`,{children:a.doing})]}),(0,J.jsxs)(`div`,{className:`act-triage`,children:[(0,J.jsx)(`span`,{className:`act-count`,children:a.elapsed}),a.counts?(0,J.jsx)(`span`,{className:`act-count`,children:a.counts}):null,n?.progress?.model?(0,J.jsx)(`span`,{className:`act-count`,children:n.progress.model}):null,a.quiet?(0,J.jsx)(`span`,{className:`act-count warn`,children:a.quiet}):null]}),a.say?(0,J.jsx)(Z,{className:`assess-say`,children:a.say}):null,(0,J.jsx)(Hq,{steps:n?.progress?.tail??[]})]}):null,t.online?null:(0,J.jsx)(Z,{tone:`warn`,children:`No connection — this is the last proposal this phone was told about. Applying starts work on the desktop, so it waits for the link; nothing here expires while it is down.`}),(0,J.jsx)($,{res:c,empty:l,thing:`the assessment`,noun:`proposal`,children:n==null?`Nothing has been assessed in ${t.repoName} yet. An assessment reads the repo and says, of everything still open here, what is already done, what no longer applies, what is covered elsewhere and what is still worth doing — with evidence, and nothing is applied until you approve it.`:n.status===`running`?`The assessment is reading the repo — what it is doing is above. It leaves a proposal here when it finishes; you can close this and come back.`:n.status===`failed`?`The run did not produce a proposal, so nothing was decided and nothing was touched.`:`The run came back with nothing to decide — there was nothing still open in this repo.`}),r&&r.notes.length?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`section section-head`,children:[(0,J.jsx)(`span`,{children:`what the app refused`}),(0,J.jsx)(`span`,{className:`section-hint`,children:`shown, not swallowed — a dropped group and a group nobody proposed look identical otherwise`})]}),(0,J.jsx)(`div`,{className:`list`,children:r.notes.map((e,t)=>(0,J.jsxs)(`div`,{className:`act-verdict`,children:[(0,J.jsx)(Js,{size:11}),` `,e]},t))})]}):null]})}function Qxe(e){let t=Exe(e),{run:n,proposal:r}=t;return(0,J.jsx)(hE,{className:`assess-sheet`,title:(0,J.jsx)(`span`,{title:e.repoDir,children:e.repoName}),icon:(0,J.jsx)(uo,{size:18}),onClose:e.onClose,footer:r?(0,J.jsx)(jxe,{m:t}):null,actions:(0,J.jsx)(Axe,{m:t}),head:n?(0,J.jsx)(Mxe,{m:t}):null,children:(0,J.jsxs)(`div`,{className:`sheet-scroll`,children:[(0,J.jsx)(Zxe,{m:t}),(0,J.jsxs)(`div`,{className:`list act-list`,children:[(0,J.jsx)(Gxe,{m:t}),(0,J.jsx)(Jxe,{m:t}),(0,J.jsx)(Wxe,{m:t}),(0,J.jsx)(Xxe,{m:t})]})]})})}function $xe({repo:e}){let t=_h(),{liveSend:n}=t.conn,{budget:r}=t.world,i=e.worktreePath,a=K(hq).get(i)??null,o=K(yq),s=K(_q),c=K(vq),l=K(pq).items,u=vh();return(0,J.jsx)(Qxe,{repoDir:i,repoName:e.repoName,repoId:e.id,outbox:u,run:a,online:t.conn.status===`open`,busy:o.size>0,budgetNote:r?.verdict.blocked?Gi(r.verdict):null,scope:s,slot:c,onRun:()=>Cq(i,s??void 0,c),onEditItem:e=>{let n=t.world.intents.find(t=>t.id===e);n?t.nav.openSend(t.send.seedFromIntent(n)):t.say.toast(`that row is gone`)},onDropItem:e=>n({t:`backlog.archive`,id:e,archived:!0},`archived — its words are kept; the backlog's archived cut brings it back`,`no connection — archiving waits for the link`),onApply:e=>{a&&bxe(a,e)},onDiscard:()=>n({t:`assess.discard`,runId:a?.runId??``},`proposal discarded — nothing was applied`,`no connection — the proposal lives on the desktop`),onOpenPlan:n=>t.files.openFileFrom({repoId:e.id,relPath:n,mtime:a?.planMtime},`assess`),onOpenItem:e=>{e.source===`note`?t.nav.openPadAt(e.id):t.nav.openActivity()},backlog:l.filter(e=>e.repoDir===i),onOpenBacklog:(e,t)=>xq(i,e,t),onClose:xxe})}var eSe={id:`backlog`,boot:()=>(KK(wq),()=>KK(null)),sheets:[{id:`backlog`,persisted:!0,render:()=>(0,H.createElement)(wxe),onLeave:yxe,keep:mh(mq)},{id:`assess`,persisted:!1,render:()=>{let e=gq.get();return e?(0,H.createElement)($xe,{repo:e}):null}}],messages:{welcome:()=>mxe(),"backlog.list":e=>fxe(e),"assess.state":e=>pxe(e.repoDir,e.run)}};function tSe({m:e,p:t}){let{selecting:n,pickedRows:r,shown:i,selectVisible:a,clearSelection:o,refire:s,file:c,restorable:l,filter:u}=e;if(!n)return null;let d=u===`dismissed`,f=r.length?[...s.go.length?[]:[{label:`send again`,reason:`none of the selected rows can be sent again — each says why on its own row`}],...d||c.go.length?[]:[{label:`file away`,reason:`the selected rows are running — stopping one is “cancel”`}]]:[];return(0,J.jsxs)(`div`,{className:`act-bulk`,children:[(0,J.jsx)(`span`,{className:`act-bulk-n`,children:r.length?`${r.length} selected`:`none selected — tick rows to act on them`}),i.length?(0,J.jsxs)(Y,{title:`select all ${i.length} rows on screen`,onClick:a,children:[(0,J.jsx)(Do,{size:14}),` all `,i.length]}):null,r.length?(0,J.jsxs)(Y,{title:`clear the selection`,onClick:o,children:[(0,J.jsx)(Rc,{size:14}),` none`]}):null,s.go.length?(0,J.jsxs)(Y,{variant:`primary`,"data-hint":`activity.bulkRefire`,title:`send ${s.go.length} again as backlog items, each in the repo it was written for${s.skip.length?` — ${s.skip.length} left alone`:``}`,onClick:()=>{q(`action:activity.bulk.refire`),t.onBulk(`refire`,s.go)},children:[(0,J.jsx)(_l,{size:14}),` send `,s.go.length,` again`]}):null,d?l.length?(0,J.jsxs)(Y,{title:`put ${l.length} back in the list`,onClick:()=>{q(`action:activity.bulk.restore`),t.onBulk(`restore`,l)},children:[(0,J.jsx)(_c,{size:14}),` bring `,l.length,` back`]}):null:c.go.length?(0,J.jsxs)(Y,{"data-hint":`activity.bulkDismiss`,title:`file ${c.go.length} away as dealt with — nothing is deleted, and “dismissed” brings them back`,onClick:()=>{q(`action:activity.bulk.dismiss`),t.onBulk(`dismiss`,c.go)},children:[(0,J.jsx)(ko,{size:14}),` file `,c.go.length,` away`]}):null,(0,J.jsx)(CE,{cants:f})]})}function nSe(e,t,n){if(e.all+e.dismissed===0)return{chips:[],none:null};let r=[],i=[],a=null;for(let o of XU){let s=!n&&t===o.id;if(o.id===`open`){(s||e.open>0&&e.open<e.all)&&r.push({id:o.id,text:uE(o.label,{count:e.open}),on:s});continue}let c=o.id!==`all`&&o.id!==`dismissed`&&e[o.id]===e.all;o.id===`all`||s||e[o.id]>0&&!c?r.push({id:o.id,text:uE(o.label,{count:e[o.id]}),on:s}):e[o.id]>0?a=o.id===`needsYou`?`all need you`:`all ${o.label}`:i.push(o.label)}return{chips:r,none:[a,i.length?`nothing ${rSe(i)}`:null].filter(Boolean).join(` · `)||null}}function rSe(e){return e.length<2?e.join(``):`${e.slice(0,-1).join(`, `)} or ${e[e.length-1]}`}function iSe({m:e}){let{filter:t,focus:n,setFocus:r,setFilter:i,counts:a,selecting:o,setSelecting:s,setSelected:c,grouped:l,setGrouped:u,sort:d,setSort:f,debrisCount:p,hideDebris:m,setHideDebris:h}=e,{chips:g,none:_}=nSe(a,t,!!n);return(0,J.jsxs)(J.Fragment,{children:[g.length?(0,J.jsx)(`div`,{className:`fchips wrap act-fchips`,children:g.map(e=>(0,J.jsx)(pE,{on:e.on,clears:!1,onClick:()=>{q(`action:activity.filter.${e.id}`),r(null),i(e.id)},children:e.text},e.id))}):null,_?(0,J.jsx)(`div`,{className:`act-none`,children:_}):null,(0,J.jsxs)(`div`,{className:`fchips wrap act-toggles`,children:[(0,J.jsx)(pE,{on:o,title:o?`leave selection mode`:`select rows — deal with many at once`,onClick:()=>{q(`action:activity.select`),s(e=>!e),o&&c(new Set)},children:`select`}),(0,J.jsx)(`span`,{className:`act-hint`,"data-hint":`activity.group`,title:l?`show every copy separately`:`collapse rows that say the same thing`,children:(0,J.jsx)(pE,{on:l,onClick:()=>{q(`action:activity.group`),u(e=>!e)},children:`grouped`})}),(0,J.jsx)(pE,{on:d===`oldest`,title:d===`oldest`?`back to attention order — what needs you first`:`oldest first — the ones that have been waiting longest`,onClick:()=>{q(`action:activity.sort`),f(e=>e===`oldest`?`ranked`:`oldest`)},children:`oldest first`}),p>0||m?(0,J.jsx)(`span`,{className:`act-hint`,"data-hint":`activity.debris`,title:`hide one-word replies — “continue please”, “done?”, a bare /cost. Nothing is deleted.`,children:(0,J.jsx)(pE,{on:m,onClick:()=>{q(`action:activity.debris`),h(e=>!e)},children:p?uE(`hide chatter`,{count:p}):`hide chatter`})}):null]})]})}function Kq({s:e}){let t=rt(e);return t?(0,J.jsxs)(`span`,{className:`row-name`,title:`what the desktop called this conversation`,children:[(0,J.jsx)(Gl,{size:11,"aria-hidden":`true`}),` `,t]}):null}var aSe={sendNow:_l,hold:Kl,retarget:jo,edit:us,fix:Zs,retry:_l,answer:bl,check:rc,open:xo,runNow:Hc,cancel:V,toggle:Do,download:rs,save:Ec,discard:ic,dismiss:Ks,confirmDone:Bl,openSchedule:Ss},oSe={prompt:bl,answer:Do,upload:Zs,action:Hc,sweep:ds,build:No,download:rs},sSe={queued:Hs,blocked:Kl,starting:Ml,running:Ml,done:Bl,failed:Js,canceled:V},cSe={landed:`it reached the session`,unconfirmed:`it was written into the session, and nothing confirmed it submitted — do not retype it`,unsubmitted:`it is sitting in the composer, unsent — do not retype it`,refused:`the desktop answered and refused it, so nothing was written`,unreachable:`the desktop never answered — it may have run`,unknown:`nobody recorded whether it ran`};function lSe(e,t){let n=Math.round((e-t)/1e3);if(n<=0)return`now`;let r=Math.floor(n/60);if(r<60)return`in ${r||1}m`;let i=Math.floor(r/60);return i<24?r%60?`in ${i}h ${r%60}m`:`in ${i}h`:`in ${Math.floor(i/24)}d`}function qq({a:e,onPress:t}){let n=aSe[e.id];return(0,J.jsxs)(Y,{className:e.danger?`danger`:void 0,title:e.label,"data-hint":`activity.${e.id}`,onClick:t,children:[(0,J.jsx)(n,{size:16}),` `,e.label]})}function Jq({row:e,now:t,sessions:n,repos:r,pick:i,outbox:a,online:o,review:s,repoIdForCwd:c,onAction:l,onRetarget:u,onOpenSession:d}){let[f,p]=(0,H.useState)(!1),[m,h]=(0,H.useState)(!1),[g,_]=(0,H.useState)(!1),[v,y]=(0,H.useState)(!1),b=s??null,x=b?.checkStatus&&b.checkStatus!==`checking`?b.checkDetail:void 0,S=(0,H.useMemo)(()=>!!e.attachText&&rj(e.attachText).length>0,[e.attachText]),[C,w]=Vq(S),T=oSe[e.kind],E=sSe[e.state],D=e.actions.filter(e=>!e.disabledReason),O=e.actions.filter(e=>e.disabledReason),k=D.find(e=>e.primary)??D[0]??null,A=D.filter(e=>e!==k&&e.alwaysShown),j=D.filter(e=>e!==k&&!e.alwaysShown),M=e.state===`running`||e.state===`starting`,N=t=>{q(`action:activity.${t.id}`),t.id===`retarget`?(_(e=>!e),p(!1)):l(t.id,e)};return(0,J.jsxs)(`div`,{ref:w,className:`act-row act-${e.bucket}${g?` act-aiming`:``}${i?` act-picking`:``}${e.dismissedAt==null?``:` act-filed`}`,children:[i?(0,J.jsx)(`button`,{className:`act-pick${i.checked?` on`:``}`,"aria-label":i.checked?`deselect`:`select`,title:i.checked?`deselect this row`:`select this row`,onClick:i.onToggle,children:i.checked?(0,J.jsx)(Do,{size:18}):(0,J.jsx)(Rc,{size:18})}):null,(0,J.jsxs)(`div`,{className:`act-rowmain`,children:[(0,J.jsxs)(`button`,{className:`act-body`,onClick:()=>h(e=>!e),title:e.clipped||e.fullText?`tap for the whole thing`:e.title,children:[(0,J.jsxs)(`span`,{className:`act-head`,children:[(0,J.jsx)(T,{size:12}),(0,J.jsx)(`span`,{className:`act-where`,children:e.where}),(0,J.jsx)(`span`,{className:`act-when`,children:Gp(e.at)})]}),(0,J.jsx)(`span`,{className:`act-text${m?` act-text-full`:``}`,children:m&&e.fullText?e.fullText:e.title}),(0,J.jsxs)(`span`,{className:`act-verdict`,children:[(0,J.jsx)(E,{size:12,className:M?`spin`:void 0}),e.verdict]}),e.delivery?(0,J.jsxs)(`span`,{className:`act-delivery`,children:[(0,J.jsx)(gl,{size:11}),` `,cSe[e.delivery]]}):null,e.asOf==null?null:(0,J.jsxs)(`span`,{className:`act-stale`,children:[`last known `,Gp(e.asOf),` — the desktop is not reachable`]}),e.dismissedAt==null?null:(0,J.jsxs)(`span`,{className:`act-filed-note`,children:[(0,J.jsx)(ko,{size:11}),` filed `,Gp(e.dismissedAt),` — the words are still here`]}),e.dueAt!=null&&e.dueAt>t?(0,J.jsxs)(`span`,{className:`act-due`,children:[(0,J.jsx)(Ss,{size:11}),` `,lSe(e.dueAt,t),` · `,new Date(e.dueAt).toLocaleString()]}):null,e.progress&&e.progress.total>0?(0,J.jsxs)(`span`,{className:`act-prog`,children:[(0,J.jsx)(`span`,{className:`act-bar`,children:(0,J.jsx)(`i`,{style:{width:`${Math.min(100,Math.round(e.progress.done/e.progress.total*100))}%`}})}),(0,J.jsx)(`span`,{className:`act-prog-n`,children:e.progress.label===`bytes`?`${yU(e.progress.done)} of ${yU(e.progress.total)}`:`${e.progress.done} of ${e.progress.total} ${e.progress.label??``}`})]}):null,e.lastRun?(0,J.jsxs)(`span`,{className:`act-last${e.lastRun.ok?``:` act-last-bad`}`,children:[`last run `,Gp(e.lastRun.at),e.lastRun.late?` (late)`:``,e.lastRun.detail?` — ${e.lastRun.detail}`:``]}):null,e.attempts>1?(0,J.jsxs)(`span`,{className:`act-tries`,children:[e.attempts,` attempts`]}):null]}),e.fromSchedule?(0,J.jsxs)(`button`,{className:`linkish act-from-sched`,title:`open the schedule “${e.fromSchedule.name}” — the rule that ran this`,onClick:()=>l(`openSchedule`,e),children:[(0,J.jsx)(Ss,{size:11}),` `,KL(e.fromSchedule.name)]}):null,(0,J.jsx)(sq,{state:e.state,sessionId:e.sessionId,sessions:n}),S&&C?(0,J.jsx)(Bq,{compact:!0,text:e.attachText,repoId:e.cwd?c(e.cwd):null,outbox:a,online:o}):null,b?.checkStatus?(0,J.jsxs)(`div`,{className:`act-check`,children:[(0,J.jsxs)(`button`,{className:`bl-check bl-check-${b.checkStatus}`,disabled:!x,title:x?`tap for the whole check`:b.checkNote||``,onClick:()=>y(e=>!e),children:[(()=>{let e=JK(b.checkStatus).Icon;return(0,J.jsx)(e,{size:11,style:{verticalAlign:`-1px`}})})(),` `,JK(b.checkStatus).label,b.checkNote?` · ${b.checkNote}`:``,x?v?(0,J.jsx)(Ys,{size:11}):(0,J.jsx)(ac,{size:11}):null]}),x&&v?(0,J.jsxs)(`div`,{className:`bl-check-detail`,children:[(0,J.jsx)(`pre`,{children:x}),b.checkedAt?(0,J.jsxs)(`span`,{className:`bl-check-when`,children:[`checked `,new Date(b.checkedAt).toLocaleString()]}):null]}):null]}):null,e.targets.length?(0,J.jsx)(`div`,{className:`act-targets`,children:e.targets.map(e=>(0,J.jsxs)(`div`,{className:`act-target act-t-${e.state}`,children:[(0,J.jsx)(`span`,{className:`act-target-name`,children:e.label}),(0,J.jsx)(`span`,{className:`act-target-state`,children:e.detail??e.state}),e.sessionId?(0,J.jsx)(Y,{title:`open this repo's session`,onClick:()=>d(e.sessionId),children:(0,J.jsx)(xo,{size:14})}):(0,J.jsx)(wE,{children:`no session`})]},e.label))}):null,(0,J.jsxs)(`div`,{className:`act-acts`,children:[(0,J.jsxs)(`span`,{className:`act-acts-verbs`,children:[k?(0,J.jsx)(qq,{a:k,onPress:()=>N(k)}):null,A.map(e=>(0,J.jsx)(qq,{a:e,onPress:()=>N(e)},e.id))]}),j.length||O.length&&k?(0,J.jsxs)(Y,{className:`act-more`,title:f?`fewer options`:`more options`,onClick:()=>p(e=>!e),children:[f?(0,J.jsx)(Ys,{size:16}):(0,J.jsx)(ac,{size:16}),` more`]}):null]}),f&&j.length?(0,J.jsx)(`div`,{className:`act-acts act-acts-more`,children:j.map(e=>(0,J.jsx)(qq,{a:e,onPress:()=>N(e)},e.id))}):null,[k,...A,...f?j:[]].filter(e=>!!e?.note).map(e=>(0,J.jsx)(Z,{children:e.note},`note-${e.id}`)),O.length>0&&(f||!k)?(0,J.jsx)(CE,{cants:O.map(e=>({label:e.label,reason:e.disabledReason}))}):null,g?(0,J.jsxs)(`div`,{className:`act-aim`,children:[(0,J.jsx)(Z,{children:`Keep the words, change where they go.`}),n.filter(t=>t.running&&t.id!==e.sessionId).map(t=>(0,J.jsxs)(`button`,{className:`row`,onClick:()=>{_(!1),u(e,{sessionId:t.id,cwd:t.cwd,mode:`input`})},children:[(0,J.jsxs)(SE,{children:[(0,J.jsx)(_l,{size:12}),` `,t.title]}),(0,J.jsx)(Kq,{s:t}),(0,J.jsx)(Q,{children:t.turnActive?`working`:`idle`})]},t.id)),(0,J.jsx)(XO,{repos:r,listClass:``,home:e.cwd,subLead:`backlog item`,icon:(0,J.jsx)(Bl,{size:12}),onPick:t=>{_(!1),u(e,{sessionId:t.worktreePath,cwd:t.worktreePath,mode:`backlog`})}})]}):null]})]})}function uSe({g:e,now:t,sessions:n,repos:r,outbox:i,online:a,reviews:o,repoIdForCwd:s,selecting:c,selected:l,onToggleRow:u,onToggleGroup:d,onAction:f,onRetarget:p,onOpenSession:m}){let[h,g]=(0,H.useState)(!1),_=e.rows.length,v=e.elsewhere.done,y=e=>c?{checked:l.has(e.key),onToggle:()=>u(e.key)}:void 0;if(_===1&&v===0&&e.elsewhere.other===0)return(0,J.jsx)(Jq,{row:e.rows[0],now:t,sessions:n,repos:r,pick:y(e.rows[0]),outbox:i,online:a,review:o?.[e.rows[0].id],repoIdForCwd:s,onAction:f,onRetarget:p,onOpenSession:m});let b=e.rows.every(e=>l.has(e.key));return(0,J.jsxs)(`div`,{className:`act-group`,children:[(0,J.jsxs)(`div`,{className:`act-group-head`,children:[c?(0,J.jsx)(`button`,{className:`act-pick${b?` on`:``}`,"aria-label":b?`deselect these`:`select these`,title:b?`deselect all ${_}`:`select all ${_}`,onClick:()=>d(e),children:b?(0,J.jsx)(Do,{size:18}):(0,J.jsx)(Rc,{size:18})}):null,_>1?(0,J.jsxs)(`span`,{className:`act-group-n`,children:[(0,J.jsx)(Ds,{size:11}),` ×`,_]}):null,_>1?(0,J.jsxs)(`span`,{className:`act-group-span`,children:[Gp(e.oldestAt),` → `,Gp(e.newestAt)]}):null,v>0?(0,J.jsxs)(`span`,{className:`act-group-ran`,children:[(0,J.jsx)(Bl,{size:11}),` `,v===1?`one of these already ran`:`${v} of these already ran`]}):null,e.elsewhere.other>0?(0,J.jsxs)(`span`,{className:`act-group-else`,children:[e.elsewhere.other,` more elsewhere in the list`]}):null,_>1?(0,J.jsx)(Y,{className:`act-group-more`,title:h?`collapse these`:`show all ${_} copies`,onClick:()=>{q(`action:activity.expand`),g(e=>!e)},children:h?(0,J.jsx)(Ys,{size:14}):(0,J.jsx)(ac,{size:14})}):null]}),(h?e.rows:e.rows.slice(0,1)).map(e=>(0,J.jsx)(Jq,{row:e,now:t,sessions:n,repos:r,pick:y(e),outbox:i,online:a,review:o?.[e.id],repoIdForCwd:s,onAction:f,onRetarget:p,onOpenSession:m},e.key))]})}function dSe({m:e,p:t}){let{shown:n,focus:r,rows:i,filter:a,counts:o,groups:s,now:c,selecting:l,selected:u,toggleRow:d,toggleGroup:f}=e;return(0,J.jsx)(`div`,{className:`list act-list`,children:n.length===0?(0,J.jsx)(Z,{children:r?`Nothing left of ${r.label} — every one of them has moved on. They are under “all”.`:i.length===0?`Nothing has been posted yet. Everything you send, queue, schedule, build or download shows up here and stays here until it is finished.`:a===`dismissed`?`Nothing filed away yet. Rows you have read and dealt with land here — they keep their words and their buttons, and “bring back” returns them to the list.`:`Nothing under “${XU.find(e=>e.id===a)?.label}”. ${o.all} ${o.all===1?`row`:`rows`} under “all”${o.dismissed?`, ${o.dismissed} filed away`:``}.`}):s.map(e=>(0,J.jsx)(uSe,{g:e,now:c,sessions:t.sessions,repos:t.repos,outbox:t.outbox,online:t.online,reviews:t.reviews,repoIdForCwd:t.repoIdForCwd,selecting:l,selected:u,onToggleRow:d,onToggleGroup:f,onAction:t.onAction,onRetarget:t.onRetarget,onOpenSession:t.onOpenSession},e.key))})}function fSe({m:e,online:t}){let{focus:n,setFocus:r,focusMissing:i,headline:a,headlineCut:o,setFilter:s,hideDebris:c,debrisCount:l}=e;return(0,J.jsxs)(J.Fragment,{children:[n?(0,J.jsxs)(Z,{className:`act-focus`,children:[(0,J.jsx)(Ic,{size:12}),` showing `,n.label,i>0?` — ${i} of them ${i===1?`has`:`have`} moved on since and ${i===1?`is`:`are`} under “all”`:``,`.`,(0,J.jsxs)(Y,{onClick:()=>{q(`action:activity.focus.clear`),r(null)},children:[(0,J.jsx)(V,{size:14}),` show everything`]})]}):null,a?(0,J.jsxs)(Z,{tone:t?void 0:`warn`,children:[a,o?(0,J.jsxs)(`button`,{className:`link-btn`,onClick:()=>{q(`action:activity.headline.${o}`),s(o)},children:[`show `,a.startsWith(`1 `)?`it`:`them`]}):null]}):null,t?null:(0,J.jsxs)(Z,{tone:`warn`,children:[(0,J.jsx)(Hs,{size:12}),` no connection — rows the desktop owns are last known, and each one says when. Nothing here expires while the link is down.`]}),c&&l>0?(0,J.jsxs)(Z,{children:[l,` one-word `,l===1?`reply is`:`replies are`,` hidden — nothing was deleted, tap “hide chatter” again to see them.`]}):null]})}var Yq=G(null);function Xq(e){Yq.set(e?{Sheet:e}:null)}function pSe(){return K(Yq)?.Sheet??null}var Zq=G(null);function Qq(e){Zq.set(e?{Section:e}:null)}function mSe(){return K(Zq)?.Section??null}function hSe(e){let[t,n]=(0,H.useState)(null),[r,i]=(0,H.useState)(()=>e.focus&&e.focus.keys.length?{keys:new Set(e.focus.keys),label:e.focus.label}:null),[a,o]=(0,H.useState)(!1),[s,c]=(0,H.useState)(()=>new Set),[l,u]=(0,H.useState)(!0),[d,f]=(0,H.useState)(!1),[p,m]=(0,H.useState)(`ranked`),h=_E(1e4),g=(0,H.useMemo)(()=>JU({now:h,online:e.online,hostSeenAt:e.hostSeenAt,deps:{isEditableEntry:rh,isCreateOp:ih,laneLabel:e.laneLabel,repoName:e.repoName},outbox:e.outbox,queueBlocked:e.queueBlocked,goneLanes:new Set(e.goneLanes),intents:e.intents,pulls:e.pulls,sessions:e.sessions,dismissed:e.dismissed,confirmedDone:e.confirmedDone}),[h,e.online,e.hostSeenAt,e.laneLabel,e.repoName,e.outbox,e.queueBlocked,e.goneLanes,e.intents,e.pulls,e.sessions,e.dismissed,e.confirmedDone]),_=(0,H.useMemo)(()=>QU(g),[g]),v=(0,H.useRef)(null);v.current==null&&_.all>0&&(v.current=_.open>0?`open`:`all`);let y=t??v.current??`all`,b=(0,H.useMemo)(()=>rW(g.filter(e=>r?r.keys.has(e.key):ZU(e,y)),p),[g,y,p,r]),x=r?r.keys.size-b.length:0,S=(0,H.useMemo)(()=>b.filter(nW).length,[b]),C=(0,H.useMemo)(()=>d?b.filter(e=>!nW(e)):b,[b,d]),w=(0,H.useMemo)(()=>iW(C,g,{group:l}),[C,g,l]),T=$U(r?b:g,e.online),E=T?.text??null,D=T&&!r&&T.cut!==y?T.cut:null,O=mSe(),k=(0,H.useMemo)(()=>C.filter(e=>s.has(e.key)),[C,s]);return{filter:y,setFilter:n,focus:r,setFocus:i,selecting:a,setSelecting:o,selected:s,setSelected:c,grouped:l,setGrouped:u,hideDebris:d,setHideDebris:f,sort:p,setSort:m,now:h,rows:g,counts:_,shown:C,groups:w,headline:E,headlineCut:D,PeerJobs:O,debrisCount:S,focusMissing:x,pickedRows:k,toggleRow:e=>c(t=>{let n=new Set(t);return n.has(e)?n.delete(e):n.add(e),n}),toggleGroup:e=>c(t=>{let n=new Set(t),r=e.rows.every(e=>n.has(e.key));for(let t of e.rows)r?n.delete(t.key):n.add(t.key);return n}),selectVisible:()=>{q(`action:activity.selectall`),c(new Set(C.map(e=>e.key)))},clearSelection:()=>{q(`action:activity.selectnone`),c(new Set)},refire:uU(k,cU),file:uU(k,lU),restorable:k.filter(e=>e.dismissedAt!=null)}}function gSe(e){let t=hSe(e),{PeerJobs:n}=t;return(0,J.jsxs)(hE,{title:fM.activity,icon:(0,J.jsx)(Kl,{size:18}),onClose:e.onClose,footer:t.selecting?(0,J.jsx)(tSe,{m:t,p:e}):null,head:(0,J.jsx)(iSe,{m:t}),children:[(0,J.jsx)(fSe,{m:t,online:e.online}),(0,J.jsxs)(`div`,{className:`sheet-scroll`,children:[(0,J.jsx)(dSe,{m:t,p:e}),n&&!t.focus&&(t.filter===`all`||t.filter===`open`)&&(0,J.jsx)(n,{sessions:e.sessions,onOpenSession:e.onOpenSession})]})]})}var $q=1e3;function eJ(){let e=oo(B.activityDismissed,{});if(!e||typeof e!=`object`||Array.isArray(e))return{};let t={};for(let[n,r]of Object.entries(e))typeof r==`number`&&Number.isFinite(r)&&(t[n]=r);return t}function tJ(e){let t=Object.keys(e);if(t.length<=$q){$a(B.activityDismissed,e);return}let n={};for(let r of t.sort((t,n)=>e[n]-e[t]).slice(0,$q))n[r]=e[r];$a(B.activityDismissed,n)}function _Se(){return new Map(Object.entries(eJ()))}function nJ(e,t=Date.now()){let n=eJ();for(let r of e)n[r]??(n[r]=t);return tJ(n),new Map(Object.entries(n))}function vSe(e){let t=eJ();for(let n of e)delete t[n];return tJ(t),new Map(Object.entries(t))}var rJ=1e3;function iJ(){let e=oo(B.activityConfirmedDone,{});if(!e||typeof e!=`object`||Array.isArray(e))return{};let t={};for(let[n,r]of Object.entries(e))typeof r==`number`&&Number.isFinite(r)&&(t[n]=r);return t}function ySe(e){let t=Object.keys(e);if(t.length<=rJ){$a(B.activityConfirmedDone,e);return}let n={};for(let r of t.sort((t,n)=>e[n]-e[t]).slice(0,rJ))n[r]=e[r];$a(B.activityConfirmedDone,n)}function bSe(){return new Map(Object.entries(iJ()))}function xSe(e,t=Date.now()){let n=iJ();for(let r of e)n[r]??(n[r]=t);return ySe(n),new Map(Object.entries(n))}var aJ=G(_Se()),oJ=G(bSe()),sJ=G(null),cJ=G([]);function SSe(){return K(aJ)}function CSe(){return K(oJ)}function wSe(e,t){return e===`build`?`build:${t.cwd}`:e===`capture`?`capture:${t.cwd}`:e===`schedule`?`fanout`:`intent:${t.id}`}function TSe(e,t){return t?`queued — it runs when the link is back`:e===`launch`?`opening it now, without the files it was waiting for`:e===`build`?`starting the build…`:e===`capture`?`taking the capture…`:`firing it into the session…`}function ESe(e,t,n){let r=t-e;return`${e} ${e===1?`message`:`messages`} back as backlog items${n?` — added when the link is back`:``}${r?` · ${r} could not go`:``} · their rows are filed under “dismissed”`}var lJ=(e,t)=>{let n=e.world.repoForCwd(t);return n?Wn(n):Rp(t)};function uJ(e){sJ.set(e?`keys`in e?{keys:e.keys,label:e.label}:{keys:e.entries.map(e=>TH(e.ackId)),label:e.label}:null),W().nav.open(`activity`)}function DSe(e,t){uJ({entries:e,label:t})}function OSe(){sJ.set(null),W().nav.close(`activity`)}function kSe(){return gS.subscribe(e=>cJ.set(e))}function ASe(e,t){let n=W();n.say.track(`action:activity.retarget`),e.subject.source===`queue`?n.queue.verbs.retargetQueued(e.id,t)&&t.mode===`backlog`&&n.nav.openBacklogCut(t.cwd):e.subject.source===`intent`?(n.conn.liveSend({t:`intent.retarget`,id:e.id,cwd:t.cwd,target:t.mode===`input`?{kind:`session`,sessionId:t.sessionId}:{kind:`repo`}},`aimed at ${lJ(n,t.cwd)}`,bW),t.mode!==`input`&&n.nav.openBacklogCut(t.cwd)):n.say.toast(`that row cannot be re-aimed`)}function jSe(e,t){let n=W(),{liveSend:r}=n.conn,{queueOp:i}=n.queue,{sessionId:a}=t;n.say.track(`action:activity.${e}`);let o=t.subject,s=()=>{let e=a?n.world.sessions.find(e=>e.id===a):null;e?n.nav.attach(e):n.say.toast(`that session is no longer open`)};if(e===`dismiss`)aJ.set(nJ([t.key])),dJ([t]),n.say.toast(`filed away for later — it's under “dismissed”, nothing was deleted`);else if(e===`confirmDone`)oJ.set(xSe([t.key])),n.say.toast(`marked done — the desktop's own check never confirmed it, this is your call`);else if(e===`openSchedule`)t.fromSchedule&&n.nav.openScheduleCut([t.fromSchedule.id],qL(t.fromSchedule.name));else switch(o.source){case`queue`:{let t=o.entry,r=n.queue.verbs;if(e===`answer`){n.nav.open(`questions`),n.say.toast(`answer it here — the queued reply is bound to this question`);return}if(e===`sendNow`){r.sendQueuedNow(t.ackId);return}if(e===`hold`){r.toggleHoldQueued(t.ackId);return}if(e===`discard`){r.removeQueued(t.ackId),n.say.toast(`discarded`);return}if(e===`open`){s();return}n.nav.openSend({prompts:[t.op?.t===`session.create`&&t.op.prompt||t.text],target:n.send.targetFor(t.sessionId,t.cwd),cwdHint:t.cwd,repoId:n.queue.repoIdOf(t),ackId:t.ackId,repair:e===`fix`,origin:t.status===`failed`?`This one never went`:`Queued, not sent yet`,openAfter:!0});return}case`intent`:{let t=o.intent,a=gr(t);if(e===`open`){s();return}if(e===`runNow`||e===`sendNow`){if(a===`fanout`){n.nav.open(`fanout`),n.say.toast(`follow up from the run below — it picks which of its sessions get it`);return}let e=i({t:`intent.run`,id:t.id},wSe(a,t),t.label||t.title||`run it now`,{cwd:t.cwd});n.say.toast(TSe(a,e)),!e&&a===`work`&&n.nav.followFire(t.id);return}if(e===`cancel`||e===`discard`){if(a===`build`&&(t.state===`running`||t.state===`starting`)){r({t:`build.cancel`,runId:t.id},`cancelling the build…`,`no connection — the build is running on the desktop and can't be stopped from here`);return}if(a===`capture`&&(t.state===`running`||t.state===`starting`)){r({t:`capture.cancel`,runId:t.id},`stopping the capture…`,`no connection — the capture is running on the desktop and can't be stopped from here`);return}if(a===`schedule`){let e=n.queue.verbs.scheduleQueueRows(t.id);r({t:`schedule.remove`,id:t.id},$H(e.length),`no connection — this one lives on the desktop and can only be deleted there`)&&n.queue.verbs.dropScheduleQueue(e);return}r({t:`intent.cancel`,id:t.id},a===`launch`?`called off — that session will not open`:`removed`,xW);return}if(e===`toggle`){if(a===`schedule`){r({t:`schedule.setEnabled`,id:t.id,enabled:t.nextAt==null},t.nextAt==null?`armed`:`switched off`,`no connection — this one is armed on the desktop and can only be changed there`);return}n.nav.open(`backlog`),n.say.toast(`this one is a per-item switch — it is on the row, in the backlog`);return}if(e===`check`){r({t:`backlog.check`,id:t.id},`checking whether this is already done…`,bW);return}if(e===`download`){let e=t.result?.artifacts??[];if(!e.length){n.say.toast(`that run left no files`);return}let r=e.map(e=>({...e,repoDir:t.cwd,repoName:n.world.repoForCwd(t.cwd)?.repoName}));if(r.length===1){NO(r[0]);return}for(let e of r)NO(e,{silent:!0});n.say.toast(`downloading ${r.length} files — see Downloads`);return}if(a===`schedule`&&t.payload.kind===`build`){let e=n.world.schedules.find(e=>e.id===t.id),r=n.world.repoForCwd(t.cwd);if(e&&r){n.nav.openBuild(r,{schedule:e});return}n.say.toast(e?`that rule's repo is not listed on this phone — edit it from its card in ${fM.automation}`:`that rule is not in the list yet — try again in a moment`);return}if(a===`schedule`||ga(t)){n.nav.openSend(n.send.seedFromIntent(t));return}n.nav.open(`backlog`),n.say.toast(`rewrite it on its row, in the backlog`);return}case`pull`:if(e===`save`){PO(o.record.item.id);return}if(e===`retry`){gS.retry(o.record.item.id),n.say.toast(`fetching it now`);return}if(o.record.local){gS.remove(o.record.item.id),n.say.toast(`removed from Downloads`);return}gS.remove(o.record.item.id),r({t:`pull.dismiss`,id:o.record.item.id},`dropped from Downloads`,`removed here — the desktop's own queue still lists it until the link is back`);return}}function MSe(e,t,n){if(t.subject.source!==`queue`)return`nothing`;let r=t.subject.entry,i=r.cwd?e.world.repoForCwd(r.cwd):null;if(!i)return`norepo`;let a=kH(r).trim();if(!a)return`nothing`;let o=e.queue.queueBacklog({text:a,repoDir:i.worktreePath,label:a.slice(0,40)});return o===null?`nothing`:(e.queue.drop(r.ackId),n.add(i.worktreePath),o?`queued`:`sent`)}function dJ(e){let t=W();if(t.conn.status===`open`)for(let n of e)n.source!==`queue`&&n.source!==`pull`&&t.conn.send({t:`intent.dismiss`,id:n.id})}function NSe(e,t){let n=W();if(n.say.track(`action:activity.bulk.${e}`),!t.length){n.say.toast(`nothing selected`);return}let r=e=>lJ(n,e);(async()=>{if(e===`restore`){aJ.set(vSe(t.map(e=>e.key))),n.say.toast(`${t.length} back in the list`);return}if(!await n.say.confirm({title:e===`dismiss`?`File ${t.length} away?`:`Send ${t.length} again?`,lines:pU(t,{verb:e,repoName:r}),confirmLabel:e===`dismiss`?`File them away`:`Send them again`})){n.say.toast(`left alone`);return}if(e===`dismiss`){aJ.set(nJ(t.map(e=>e.key))),dJ(t),n.say.toast(`${t.length} filed away — nothing was deleted, they are under “dismissed”`);return}let i=0,a=!1,o=[],s=new Set;for(let e of t){let t=MSe(n,e,s);(t===`sent`||t===`queued`)&&(i++,o.push(e.key),t===`queued`&&(a=!0))}i?(aJ.set(nJ(o)),dJ(t.filter(e=>o.includes(e.key))),n.say.toast(ESe(i,t.length,a)),s.size===1&&n.nav.openBacklogCut([...s][0])):n.say.toast(`nothing left to send from those rows`)})()}function PSe(){let e=_h(),{sessions:t,visibleRepos:n,intents:r,backlog:i}=e.world,a=vh(),o=K(cJ),s=K(aJ),c=K(oJ),l=K(sJ),u=(0,H.useMemo)(()=>Object.fromEntries(i.map(e=>[e.id,e])),[i]);return(0,J.jsx)(gSe,{outbox:a,queueBlocked:e.queue.blocked,goneLanes:e.queue.goneLanes(),intents:r,reviews:u,pulls:o,sessions:t,repos:n,online:e.conn.status===`open`,hostSeenAt:gm().lastSeenAt,laneLabel:e.queue.laneLabel,repoName:t=>{let n=e.world.repoForCwd(t);return n?Wn(n):Rp(t)},repoIdForCwd:t=>e.world.repoForCwd(t)?.id??null,onAction:jSe,onRetarget:ASe,dismissed:s,confirmedDone:c,onBulk:NSe,focus:l,onOpenSession:n=>{let r=t.find(e=>e.id===n);r?e.nav.attach(r):e.say.toast(`that session is no longer open`)},onClose:OSe})}var FSe={id:`activity`,sheets:[{id:`activity`,persisted:!0,render:()=>(0,H.createElement)(PSe)}],boot:()=>kSe()},fJ=`pad.editor`;function ISe({repos:e,onDispatch:t,onFile:n,outbox:r,online:i,repoIdForCwd:a,focusId:o,onAttach:s,onAnnotate:c,onClose:l}){let[u,d]=(0,H.useState)(eh),f=(0,H.useRef)(null);(0,H.useEffect)(()=>{let e=f.current;if(!o||!e)return;e.scrollIntoView({block:`center`}),e.classList.add(`nh-flash`);let t=window.setTimeout(()=>e.classList.remove(`nh-flash`),1400);return()=>window.clearTimeout(t)},[o]),(0,H.useEffect)(()=>Gm(()=>d(eh()),[B.pad]),[]);let p=lh(fJ),[m,h]=(0,H.useState)(p?lh(`${fJ}.id`)||`new`:null),[g,_]=(0,H.useState)(null),[v,y]=(0,H.useState)(()=>p.split(`\f`)),b=(0,H.useRef)(v),x=(0,H.useRef)(0);function S(e){b.current=e,y(e),dh(fJ,e.join(`\f`))}let C=v[0]??``,[w,T]=(0,H.useState)(()=>lh(`${fJ}.cwd`)),E=e.find(e=>e.worktreePath===w)??null,D=(0,H.useRef)([]),[O,k]=(0,H.useState)(!1),[A,j]=(0,H.useState)(!1),[M,N]=(0,H.useState)([]);(0,H.useEffect)(()=>{if(m===null)return;let e=v.join(`\f`);dh(fJ,e),dh(`${fJ}.id`,e.trim()?m:``),dh(`${fJ}.cwd`,e.trim()?w:``)},[m,v,w]);function P(){dh(fJ,``),dh(`${fJ}.id`,``),dh(`${fJ}.cwd`,``),h(null),_(null),S([``]),T(``),N([]),k(!1),D.current=[]}function F(e,t=E){if(!e.length)return;if(!t){D.current=e,k(!0);return}T(t.worktreePath),dh(`${fJ}.cwd`,t.worktreePath);let n=e.filter(cg),r=e.filter(e=>!cg(e));r.length&&I(r,t),n.length&&c(n,t)}async function I(e,t){j(!0);try{let n=await s(e,t);if(!n.length)return;N(e=>[...e,...n]);let r=b.current.length?b.current.slice():[``],i=r[0]??``;r[0]=i?`${i}${/\s$/.test(i)?``:` `}${n.join(` `)}`:n.join(` `),S(r)}finally{j(!1)}}function ee(){q(`action:pad.new`),h(`new`),_(null),S([``]),T(``),N([])}function te(e){h(e.id),_(null),S([e.text,...e.steps??[]]),T(e.cwd??``),N([])}function ne(){let e=m,t=b.current.map(e=>e.trim()).filter(Boolean),n=w;if(!e){P();return}if(!t.length){e!==`new`&&nh([e]),P(),d(eh());return}q(`action:pad.save`);let[r,...i]=t,a=e===`new`,o=a?void 0:eh().find(t=>t.id===e),s={id:a?`p_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,6)}`:e,text:r,ts:Date.now()};i.length&&(s.steps=i);let c=n||o?.cwd;c&&(s.cwd=c);let l=a?th(s):iae(s);l?_(l):(P(),d(eh()))}function re(e){q(`action:pad.remove`),nh([e]),d(eh())}return m===null?(0,J.jsxs)(`div`,{className:`sheet`,children:[(0,J.jsx)(gE,{title:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Po,{size:16}),` Prompt pad`]}),onClose:l,children:(0,J.jsxs)(Y,{onClick:ee,children:[(0,J.jsx)(os,{size:16}),` new`]})}),(0,J.jsx)(JR,{keys:[B.pad],thing:`your notes`}),(0,J.jsx)(Z,{children:Rn}),(0,J.jsxs)(`div`,{className:`list`,children:[u.length===0&&(0,J.jsx)($,{children:`Nothing on the pad. Tap “new” to park a thought.`}),u.map(s=>{let c=s.cwd?e.find(e=>e.worktreePath===s.cwd):void 0;return(0,J.jsxs)(`div`,{className:`pad-item`,ref:s.id===o?f:void 0,children:[(0,J.jsxs)(`div`,{className:`queue-row`,children:[(0,J.jsxs)(`button`,{className:`queue-text`,onClick:()=>te(s),title:`tap to edit`,children:[(0,J.jsx)(`span`,{className:`queue-text-body`,children:s.text}),(0,J.jsxs)(`span`,{className:`queue-meta`,children:[(s.steps?.length??0)>0&&(0,J.jsxs)(J.Fragment,{children:[`+`,s.steps.length,` step`,s.steps.length>1?`s`:``,` · `]}),c?(0,J.jsxs)(J.Fragment,{children:[c.isPrimary?c.repoName:`${c.repoName} · ${c.branch}`,` · `]}):null,new Date(s.ts).toLocaleString([],{month:`short`,day:`numeric`,hour:`2-digit`,minute:`2-digit`})]})]}),(0,J.jsxs)(`div`,{className:`queue-row-acts`,children:[c&&(0,J.jsxs)(Y,{title:je.title(c.repoName),onClick:()=>{q(`action:pad.file`),n(s,c)},children:[(0,J.jsx)(bs,{size:16}),` `,je.label]}),(0,J.jsxs)(Y,{title:`send it — pick where and when in one sheet`,onClick:()=>{q(`action:pad.dispatch`),t(s)},children:[(0,J.jsx)(_l,{size:16}),` send…`]}),(0,J.jsx)(uT,{className:`key danger`,title:`discard`,confirmTitle:`tap again and this note is gone`,confirm:`discard?`,onConfirm:()=>re(s.id),children:(0,J.jsx)(ic,{size:16})})]})]}),(0,J.jsx)(Bq,{compact:!0,text:s.text,repoId:s.cwd?a(s.cwd):null,outbox:r,online:i})]},s.id)})]}),(0,J.jsxs)(`div`,{className:`sheet-actions`,children:[(0,J.jsxs)(Y,{onClick:l,children:[(0,J.jsx)(Hl,{size:16}),` back`]}),(0,J.jsx)(`span`,{className:`spacer`}),(0,J.jsxs)(X,{as:`span`,style:{padding:0},children:[u.length,` note`,u.length===1?``:`s`]})]})]}):(0,J.jsxs)(`div`,{className:`sheet`,children:[(0,J.jsx)(gE,{title:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Po,{size:16}),` `,m===`new`?`New note`:`Edit note`]}),onClose:P}),(0,J.jsxs)(Z,{children:[`Just the text. You pick where it goes when you get there.`,E&&(0,J.jsxs)(J.Fragment,{children:[` Files go to `,(0,J.jsx)(`strong`,{children:E.repoName}),`'s inbox — that much the note has decided.`]})]}),g&&(0,J.jsx)(Z,{tone:`warn`,children:g}),(0,J.jsxs)(uD,{prompts:v,onChange:S,placeholder:`What should someone do about this?`,chain:!0,stepHint:`then, once that step's turn finishes:`,trackAdd:`action:pad.addprompt`,focusRef:x,autoFocus:!0,children:[M.length>0&&(0,J.jsxs)(Z,{children:[(0,J.jsx)(Oc,{size:12}),` `,M.length,` file`,M.length>1?`s`:``,` queued for `,E?.repoName??`that repo`,`'s inbox — the paths are in the note above.`]}),(0,J.jsx)(Bq,{compact:!0,debounceMs:700,text:C,repoId:E?.id??null,outbox:r,online:i,onRemove:e=>S(b.current.map(t=>ij(t,e)))})]}),O&&(0,J.jsxs)(`div`,{className:`queue-aim attach-aim`,children:[(0,J.jsx)(Z,{children:`Whose inbox do these files go to?`}),(0,J.jsx)(XO,{repos:e,listClass:``,onPick:e=>{let t=D.current;D.current=[],k(!1),F(t,e)}})]}),(0,J.jsxs)(`div`,{className:`sheet-actions`,children:[(0,J.jsxs)(Y,{onClick:P,children:[(0,J.jsx)(V,{size:16}),` cancel`]}),(0,J.jsx)(dD,{prompts:b,onPrompts:S,focusRef:x,busy:A,onFiles:e=>F(e),unavailable:e.length?void 0:`no repos under the host root to upload into`,trackImage:`action:pad.attach`,trackFile:`action:pad.attachfile`}),(0,J.jsx)(`span`,{className:`spacer`}),(0,J.jsx)(`button`,{className:`send`,onClick:ne,children:`Save`})]})]})}var pJ=G(null);function LSe(e){pJ.set(e),W().nav.open(`pad`)}function RSe(){pJ.set(null),W().nav.close(`pad`)}function zSe(e){let t=W();t.say.track(`action:pad.dispatch`),t.nav.openSend({prompts:[e.text,...e.steps??[]],target:t.send.targetFor(void 0,e.cwd),cwdHint:e.cwd??null,repoId:e.cwd?t.world.repoForCwd(e.cwd)?.id??null:null,padId:e.id,repair:rj(e.text).length>0,origin:`From the pad`})}function BSe(e,t){if(!e.cwd)return;let n=W(),r=n.queue.queueBacklog({text:e.text,repoDir:e.cwd,steps:e.steps?.length?[e.text,...e.steps]:void 0});r!==null&&(n.compose.removePadNotes([e.id]),n.say.toast(Je(t.repoName,r)),n.nav.openBacklogCut(e.cwd))}function VSe(){let e=_h(),t=vh(),n=K(pJ);return(0,J.jsx)(ISe,{repos:e.world.visibleRepos,outbox:t,online:e.conn.status===`open`,focusId:n,repoIdForCwd:t=>e.world.repoForCwd(t)?.id??null,onClose:RSe,onAttach:(t,n)=>e.files.attachForInbox(n,t),onAnnotate:(t,n)=>e.files.annotate(n,t,`pad`),onDispatch:zSe,onFile:BSe})}var HSe={id:`pad`,sheets:[{id:`pad`,persisted:!1,render:()=>(0,H.createElement)(VSe)}]},mJ=G(null),hJ=G(0);function USe(){return K(hJ)}var gJ=G(null),_J=G(null),vJ=G(null),yJ=G(null),bJ=G(null),xJ=G(null),SJ=G(new Map(Object.entries(oo(B.newImages,{})))),CJ=G(new Set),wJ={ret:`session`,pickRepo:null,sendRepo:null,padRepo:null,backlogEdit:null};function TJ(e){return K(SJ).get(e)??WSe}var WSe=[];function GSe(e){return K(CJ).has(e)}function EJ(e,t){return{repoId:e.repoId,scope:`outbox`,allTime:!0,returnTo:t,openFile:{...e,name:e.name||e.relPath.split(`/`).pop()||e.relPath}}}var DJ=/\.(mp4|webm|mov|m4v|ogv|mkv)$/i,KSe=/\.(png|jpe?g|gif|webp|bmp|avif|heic|svg)$/i;function OJ(e){return DJ.test(e)}function kJ(e){return/\.(md|markdown|mdx)$/i.test(e)}function AJ(e){return DJ.test(e)||KSe.test(e)}function jJ(e){return e.filter(e=>AJ(e.relPath))}function qSe(e){let t=e.filter(e=>kJ(e.relPath)),n=t.filter(e=>e.changed).length,r=e.length-t.length,i=[];return r&&i.push(`${r} new image${r>1?`s`:``}`),t.length-n&&i.push(`${t.length-n} new markdown`),n&&i.push(`${n} markdown edited`),i.join(` · `)}function MJ(e,t,n){let r=n=>jJ(e.get(n)??[]).findIndex(e=>e.repoId===t.repoId&&e.relPath===t.relPath);if(n&&r(n)>=0)return{sessionId:n,i:r(n)};for(let t of e.keys()){let e=r(t);if(e>=0)return{sessionId:t,i:e}}return null}function JSe(e,t,n,r){let i=new Map(e),a=[...i.get(t)??[]];for(let e of r){let t=a.findIndex(t=>t.relPath===e.relPath);if(t<0){a.push({...e,repoId:n});continue}if(!kJ(e.relPath)||e.mtime<=a[t].mtime)continue;let[r]=a.splice(t,1),{changed:i,...o}=e;a.push(r.changed?{...e,repoId:n}:{...o,repoId:n})}return i.set(t,a),i}function YSe(e,t){if(!e.has(t))return e;let n=new Map(e);return n.delete(t),n}function XSe(e){let t={};for(let[n,r]of e)r.length&&(t[n]=r.slice(-60));return t}function NJ(e,t,n){let r=t.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`),i=RegExp(`${r}(?:\\s*\\(marked:(?:[^()]|\\([^()]*\\))*\\))?`);return i.test(e)?e.replace(i,n):`${e} ${n}`}function ZSe(e){let t=e.trim(),n=Math.max(2,...[...t.matchAll(/`+/g)].map(e=>e[0].length)),r="`".repeat(n+1);return`Text read off a photo (on-device OCR, the photo itself not sent — glyphs may be misread):\n${r}\n${t}\n${r}\n`}function QSe(e,t){return t?`${e} (marked: ${t})`:e}function PJ(e,t){return e===`backlog-item`?`backlog`:e===`send`?t?`send`:null:e===`pad`?`pad`:null}function $Se(e,t,n,r,i){return e===`session`?n??t:e===`send`?`create:${r??t}`:e===`pad`?`create:${i??t}`:t}function eCe(e){return e?.outboxSeenAt!=null&&e.outboxCount>0?{since:e.outboxSeenAt,count:e.outboxCount}:void 0}function tCe(e,t){let n=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]);return e.length>0&&e.every(e=>t.some(t=>n(e,t)))}function nCe(e){return e.handled||!e.files||!e.repoId||e.editable&&!e.inCompose?`ignore`:e.annotating?`ask`:e.sheet&&!e.inCompose?`ignore`:`route`}function FJ(e){let t=W().nav,n=Yae(e,t.overlay);n===`close`&&t.overlay?t.close(t.overlay):n===`open`&&e&&t.open(e)}function IJ(e){W().compose.insert(e),gp(e),W().say.toast(`path copied: ${e}`)}function LJ(e,t){let n=U.artifactUrl(e,t),r=OJ(t);bj(e,t);let i=gj(e,t);return{name:t.split(`/`).pop()||t,relPath:t,url:r?n:sg(n,og(),i),fullUrl:n,video:r,repoId:e}}var RJ=!1;function rCe(e,t){if(!RJ){if(RJ=!0,e.image){let t=MJ(SJ.get(),e.image);_J.set(t??{items:[LJ(e.image.repoId,e.image.relPath)],repoId:e.image.repoId,i:0})}e.file&&t&&vJ.set(EJ(e.file))}}function zJ(e){let t=_J.get()?.revoke;_J.set(e);let n=_J.get()?.revoke;t&&t!==n&&URL.revokeObjectURL(t)}function iCe(e,t){let n=MJ(SJ.get(),e,t);mJ.set(null),zJ(n??{items:[LJ(e.repoId,e.relPath)],repoId:e.repoId,i:0}),W().nav.open(`swipe`)}function BJ(e){W().say.track(`action:newimg.open`),zJ({sessionId:e,i:0}),W().nav.open(`swipe`)}function aCe(e,t){W().say.track(`action:newimg.open`);let n=jJ(SJ.get().get(e)??[]);zJ({sessionId:e,i:Math.max(0,n.findIndex(e=>e.relPath===t.relPath))}),W().nav.open(`swipe`)}function VJ(e,t,n){W().say.track(`action:read.fileref`),AJ(t)?(zJ({items:[LJ(e,t)],repoId:e,i:0,back:n}),W().nav.open(`swipe`)):(vJ.set(EJ({repoId:e,relPath:t},n)),W().nav.open(`gallery`))}function oCe(e){let t=W().nav.overlay;e.state===`host`&&e.repoId?VJ(e.repoId,e.relPath,t):Lq(e.relPath,e.state,[...W().queue.entries]).then(n=>{n?(W().say.track(`action:attach.openlocal`),zJ({items:[{name:e.relPath.split(`/`).pop()||e.relPath,relPath:e.relPath,url:n,repoId:e.repoId??void 0}],repoId:e.repoId??void 0,i:0,back:t,revoke:n}),W().nav.open(`swipe`)):W().say.toast(`no copy of this file on this phone`)})}function HJ(){FJ(_J.get()?.back??null),zJ(null)}function sCe(e,t,n){SJ.set(r=>JSe(r,e,t,n)),WJ(e),W().say.toast(qSe(n))}function UJ(e){W().say.track(`action:newimg.ref`),IJ(e.relPath)}function cCe(e){SJ.set(t=>YSe(t,e)),WJ(e)}function lCe(e){CJ.set(t=>t.has(e)?t:new Set(t).add(e))}function WJ(e){CJ.set(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})}function GJ(e,t,n,r){vJ.set({repoId:e,scope:t,allTime:n,newCut:r}),W().nav.open(`gallery`)}function KJ(e){GJ(e,`outbox`,!0,eCe(W().world.repos.find(t=>t.id===e)))}function uCe(e){vJ.set({repoId:e.id,scope:`outbox`,allTime:!0,returnTo:`send`,insertInto:`send`}),W().nav.open(`gallery`)}function dCe(e,t){t===void 0&&W().say.track(`notif:open-file`);let n=t??(W().nav.overlay===`notifications`?`notifications`:void 0);vJ.set(EJ(e,n)),W().nav.open(`gallery`)}function fCe(e){NO(e)}function pCe(){let e=vJ.get()?.returnTo??null;vJ.set(null),FJ(e),W().world.refreshRepos()}function qJ(e){vJ.get()?.insertInto===`send`?(W().compose.appendSheetDraft(Xj,e),W().say.toast(`added to the prompt`)):IJ(e)}function mCe(e){let t=W(),n=t.world.repos.find(t=>t.id===e);if(!n)return[];let r=t.world.active?.id;return t.world.sessions.filter(e=>e.cwd===n.worktreePath&&e.running).sort((e,t)=>Number(t.id===r)-Number(e.id===r)).map(e=>({id:e.id,label:v_(e,n.repoName),onScreen:e.id===r}))}function hCe(e,t,n){let r=W(),i=r.world.repos.find(e=>e.id===t);if(!i){r.say.toast(`unknown repo`);return}let a=n?r.world.sessions.find(e=>e.id===n&&e.running):void 0;if(n&&!a)r.say.toast(`that session has ended — pick another, or start a new one`);else if(vJ.set(null),FJ(null),gp(e),a)r.nav.attach(a),r.compose.seedDraft(a.id,e),r.say.toast(`opened session · ${e}`);else{let t=r.launch.openCwd(i.worktreePath,Te(i));t?r.compose.seedDraft(t,e):r.compose.insert(e),r.say.toast(`new session · ${e}`)}}function gCe(e,t){let n=W(),r=n.world.repos.find(t=>t.id===e);if(!r)return n.say.toast(`unknown repo — the remarks are kept on the file`),!1;bJ.set(null),xJ.set(null),FJ(null),gp(t);let i=[n.world.active,...n.world.sessions].find(e=>e&&e.cwd===r.worktreePath&&e.running);if(i)return i.id!==n.world.active?.id&&n.nav.attach(i),n.compose.seedDraft(i.id,t),n.say.toast(`remarks are in the prompt — read them over, then send`),!0;let a=n.launch.openCwd(r.worktreePath,Te(r),!0);return a?n.compose.seedDraft(a,t):n.compose.insert(t),n.say.toast(`new session · remarks are in the prompt`),!0}function JJ(e,t,n){W().say.track(`overlay:sweep`),yJ.set({repoId:e,scope:t,back:n}),W().nav.open(`sweep`)}function _Ce(e){let t=vJ.get()?.repoId??W().world.activeRepo?.id;t&&JJ(t,e,`gallery`)}function vCe(e){yJ.set(t=>t&&{...t,scope:e})}function yCe(){let e=yJ.get()?.back??null;yJ.set(null),FJ(e)}function bCe(){W().world.refreshRepos()}function xCe(e,t=null){bJ.set(e),t&&xJ.set({file:``,back:t}),W().nav.open(`browse`)}function YJ(e,t,n){bJ.set(e),xJ.set({file:t,back:n}),W().nav.open(`browse`)}function SCe(){W().nav.open(`gallery`)}function XJ(e){return t=>{let n=t.world.activeRepo?.id;n?e(n):t.say.toast(`not a known repo`)}}function CCe(){bJ.set(null),W().nav.open(`browse`)}function ZJ(){let e=xJ.get()?.back??null;bJ.set(null),xJ.set(null),FJ(e)}var QJ=null,$J=null;function eY(e){wJ.ret=`session`,wJ.pickRepo=e,QJ?.click()}function tY(e){wJ.ret=`session`,wJ.pickRepo=e,$J?.click()}function nY(e){let t=Array.from(e.files??[]);e.value=``;let n=wJ.pickRepo;return wJ.pickRepo=null,t.length&&n?{files:t,repoId:n}:null}function wCe(e){let t=nY(e);t&&(W().say.track(`action:attach.file`),rY(t.files,t.repoId))}function rY(e,t,n){if(wJ.ret=`session`,n?.annotate===!1){cY(e,t);return}let r=e.filter(cg),i=e.filter(e=>!cg(e));i.length&&cY(i,t),r.length&&(r.length===1?iY({source:r[0],repoId:t}):oY(r,t,e=>{wJ.ret===`session`?aY(e,t):cY(e,t)}))}function TCe(e){let t=nY(e);if(!t)return;let{files:n,repoId:r}=t;n.length===1?iY({source:n[0],repoId:r}):oY(n,r,e=>{wJ.ret===`session`?aY(e,r):cY(e,r)})}function ECe(){let e=(e,t)=>{let n=document.createElement(`input`);return n.type=`file`,n.multiple=!0,n.hidden=!0,e&&(n.accept=e),n.addEventListener(`change`,()=>t(n)),document.body.appendChild(n),n};return QJ=e(`image/*`,TCe),$J=e(null,wCe),()=>{QJ?.remove(),$J?.remove(),QJ=$J=null}}function iY(e){mJ.set(e),W().nav.open(`image`)}function aY(e,t){mJ.set({source:e[0],repoId:t,rest:e.slice(1),total:e.length,index:1}),W().nav.open(`image`)}function oY(e,t,n){gJ.set({files:e,repoId:t,separate:n}),W().nav.open(`collage`)}function sY(){let e=mJ.get();if(e?.rest&&e.rest.length){let[t,...n]=e.rest;mJ.set({source:t,repoId:e.repoId,rest:n,total:e.total,index:(e.index??1)+1})}else FJ(null),mJ.set(null)}function DCe(e,t){let n=gJ.get();n&&(gJ.set(null),iY({source:e,repoId:n.repoId,facts:t}))}function OCe(e){let t=gJ.get();t&&(gJ.set(null),t.separate(e))}function kCe(){let e=PJ(wJ.ret,W().nav.sendSeeded());wJ.ret=`session`,gJ.set(null),FJ(e)}async function cY(e,t){wJ.ret=`session`;let n=W(),r=[],i=n.world.repos.find(e=>e.id===t)?.worktreePath??t,a=n.world.active?.id??i,o=``;for(let s of e)try{let{width:e}=cH(),c=await fH(s,s.name,e),l=await n.queue.queueImageUpload(t,c.blob,c.name,a,i);l?r.push(l.relPath):o||=`this browser can't hold files offline — reconnect and re-attach`}catch{o||=`couldn't read that file`}let s=W().say;r.length?(r.forEach(e=>W().compose.insert(e)),await gp(r.join(` `)),FJ(null),mJ.set(null),s.toast(W().conn.status===`open`?`Sent ${r.length} · paths copied`:`${r.length} queued · they upload when the link is back`)):s.toast(o||`Upload failed`)}function ACe(){let e=hJ.get();return e?(hJ.set(0),Date.now()-e<jCe&&W().nav.overlay==null):!1}var jCe=3e3;async function MCe(e,t){let n=mJ.get();if(!n)return null;let r=W(),i=r.world.repos.find(e=>e.id===n.repoId)?.worktreePath??n.repoId,a=$Se(wJ.ret,i,r.world.active?.id??null,wJ.sendRepo?.worktreePath,wJ.padRepo?.worktreePath);return(await r.queue.queueImageUpload(n.repoId,e,t,a,i))?.relPath??null}function NCe(e,t){let n=mJ.get();if(!n)return;let r=W().queue.uploads,i=r.ensureUploadBuf(n.repoId);t===`run`&&(i.submit=!0),t===`queue`&&(i.queue=!0),r.queueUpload(i,e.blob,e.name,e.note,e.size),n.rest&&n.rest.length?(sY(),W().say.toast(`Sent ${n.index}/${n.total} · next…`)):(i.closed=!0,mJ.set(null),FJ(null),r.settleUploads(i))}function PCe(){let e=mJ.get();if(e?.rest&&e.rest.length){sY(),W().say.toast(`Skipped ${e.index}/${e.total}`);return}let t=W().queue.uploads,n=t.current();n&&(n.closed=!0,t.settleUploads(n));let r=PJ(wJ.ret,W().nav.sendSeeded());wJ.ret=`session`,mJ.set(null),FJ(r)}function FCe(e,t){let n=mJ.get();if(!n)return;let{repoId:r,rest:i=[]}=n,a=W().queue.uploads,o=a.ensureUploadBuf(r);t===`run`&&(o.submit=!0),t===`queue`&&(o.queue=!0),a.queueUpload(o,e.blob,e.name,e.note,e.size);for(let e of i){let t=e instanceof File?e:fetch(e.url).then(e=>e.blob());a.queueUpload(o,t,e.name)}o.closed=!0,mJ.set(null),FJ(null),a.settleUploads(o)}function lY(){let e=PJ(wJ.ret,W().nav.sendSeeded()),t=W().queue.uploads,n=t.current();wJ.ret===`session`&&n&&(n.closed=!0,t.settleUploads(n)),wJ.ret=`session`,wJ.backlogEdit=null,mJ.set(null),FJ(e)}async function ICe(e,t){let n=QSe(e,t),r=W().say;if(wJ.ret===`backlog-item`&&wJ.backlogEdit){let{id:t,oldPath:i,text:a}=wJ.backlogEdit;wJ.backlogEdit=null,wJ.ret=`session`;let o=NJ(a,i,n);mJ.set(null),FJ(`backlog`),o===a?r.toast(`updated image: ${e}`):W().conn.liveSend({t:`backlog.update`,id:t,text:o},`updated image: ${e}`,`no connection — the marked image will still upload (${e}), but the backlog row lives on the desktop and still names the old one`);return}if(wJ.ret===`send`){WCe(n);return}if(wJ.ret===`pad`){GCe(n);return}W().world.active&&W().compose.insert(n),await gp(n);let i=mJ.get();i?.rest&&i.rest.length?(sY(),r.toast(`Sent ${i.index}/${i.total} · next…`)):(FJ(null),mJ.set(null),r.toast(`Sent · path copied: ${e}`))}function LCe(e){let t=ZSe(e),n=W();if(wJ.ret===`backlog-item`&&wJ.backlogEdit){let{id:e,oldPath:r,text:i}=wJ.backlogEdit;wJ.backlogEdit=null,wJ.ret=`session`,mJ.set(null),FJ(`backlog`),n.conn.liveSend({t:`backlog.update`,id:e,text:NJ(i,r,t)},`the image is now its text`,`no connection — the backlog row lives on the desktop and still names the image`);return}wJ.ret===`send`?n.compose.appendSheetDraft(Xj,t):wJ.ret===`pad`?(n.compose.appendSheetDraft(`pad.editor`,t),n.compose.loadSheetDraft(`pad.editor.id`)||n.compose.seedSheetDraft(`pad.editor.id`,`new`)):n.world.active?n.compose.insert(t):gp(t);let r=mJ.get();r?.rest&&r.rest.length?(sY(),n.say.toast(`Text added ${r.index}/${r.total} · next…`)):(n.say.toast(wJ.ret===`session`&&!n.world.active?`text copied — no session open to put it in`:`text added — the photo was not sent`),lY())}function uY(e,t,n){iY({source:{url:e,name:t},repoId:n})}function dY(e,t,n){wJ.ret=`session`,uY(e,t,n)}function RCe(e){dY(U.artifactUrl(e.repoId,e.relPath),e.name,e.repoId)}function zCe(){return W().nav.overlay===`image`&&mJ.get()!=null}async function BCe(e){let t=mJ.get();if(!t||!e.length)return!1;let n=[t.source,...t.rest??[]].filter(e=>e instanceof File),r=new Set(n.map(e=>e.size));if(!e.every(e=>r.has(e.size)))return!1;let i=e=>e.arrayBuffer().then(e=>new Uint8Array(e));try{let[t,r]=await Promise.all([Promise.all(e.map(i)),Promise.all(n.filter(t=>e.some(e=>e.size===t.size)).map(i))]);return tCe(t,r)}catch{return!1}}function VCe(e){let t=mJ.get();if(!t)return;let n=e.filter(cg);e.length>n.length&&cY(e.filter(e=>!cg(e)),t.repoId),n.length&&mJ.set({...t,rest:[...t.rest??[],...n],total:(t.total??1)+n.length,index:t.index??1})}async function HCe(e,t,n=`create:${e.worktreePath}`){let r=[];for(let i of t){let t=i,a=i.name;try{let{width:e}=cH(),n=await fH(i,i.name,e);t=n.blob,a=n.name}catch{}let o=await W().queue.queueImageUpload(e.id,t,a,n,e.worktreePath);o?r.push(o.relPath):W().say.toast(`this browser can't hold files offline — reconnect and attach again`)}return r}function UCe(e,t,n){t.length&&(wJ.ret=n,n===`send`?wJ.sendRepo=e:wJ.padRepo=e,t.length===1?iY({source:t[0],repoId:e.id}):oY(t,e.id,t=>aY(t,e.id)))}function WCe(e){let t=W();t.compose.appendSheetDraft(Xj,e);let n=mJ.get();if(n?.rest&&n.rest.length){sY(),t.say.toast(`Attached ${n.index}/${n.total} · next…`);return}wJ.ret=`session`,mJ.set(null);let r=t.nav.sendSeeded();FJ(r?`send`:null),gp(e),t.say.toast(r?`attached · the path is in the prompt`:`path copied: ${e}`)}function GCe(e){let t=W();t.compose.appendSheetDraft(`pad.editor`,e),t.compose.loadSheetDraft(`pad.editor.id`)||t.compose.seedSheetDraft(`pad.editor.id`,`new`);let n=mJ.get();n?.rest&&n.rest.length?(sY(),t.say.toast(`Attached ${n.index}/${n.total} · next…`)):(wJ.ret=`session`,mJ.set(null),t.nav.open(`pad`),gp(e),t.say.toast(`attached · the path is in the note`))}function KCe(e,t){let n=W().world.repos.find(t=>t.worktreePath===e.repoDir)?.id;n?(wJ.ret=`backlog-item`,wJ.backlogEdit={id:n,oldPath:t,text:e.text},uY(U.artifactUrl(n,t),t.split(`/`).pop()||`image`,n)):W().say.toast(`unknown repo`)}function qCe(e,t){let n=t.find(t=>t.relPath===e.relPath),r=_J.get()?.back??null;zJ(null),n?RCe(n):e.repoId?dY(e.fullUrl??e.url,e.name,e.repoId):FJ(r)}function JCe(e,t){let n=t.find(t=>t.relPath===e.relPath);n?UJ(n):IJ(e.relPath),HJ()}function YCe(){let e=ECe(),t=e=>{let t=e.detail;t&&oCe(t)};window.addEventListener(Rq,t);let n=SJ.subscribe(()=>$a(B.newImages,XSe(SJ.get()))),r=!1,i=mJ.subscribe(()=>{mJ.get()==null?(r&&hJ.set(Date.now()),r=!1):r=wJ.ret===`session`});return()=>{e(),n(),i(),window.removeEventListener(Rq,t);let r=_J.get()?.revoke;r&&URL.revokeObjectURL(r)}}var XCe=`#0d1013`,ZCe=`#000000`,QCe=`#ffffff`,$Ce=`rgba(0,0,0,0.75)`;async function ewe(e){let t=[],n=[];for(let r of e){let e=await mH(vH(r),null),i=e?e.width:0,a=e?e.height:0;e&&i>0&&a>0?t.push({name:r.name,file:r,img:e,w:i,h:a}):n.push(r.name)}return{items:t,failed:n}}function fY(e){for(let t of e)typeof ImageBitmap<`u`&&t.img instanceof ImageBitmap&&t.img.close()}var pY=e=>e.map(e=>({w:e.w,h:e.h}));function mY(e,t){if(t===`none`)return 0;let n=Ui(pY(e));return t===`wide`?n*3:n}function twe(e,t){return wee(pY(e),mY(e,t))}function nwe(e){return Array.from({length:e},(e,t)=>t+1)}function rwe(e,t={}){return si(pY(e),{cols:t.cols,gap:mY(e,t.gap??`thin`),...t.maxWidth?{maxWidth:t.maxWidth}:{}})}var hY=[2600,1800,1200,800];async function gY(e,t={}){if(!e.length)return null;let n=t.maxSide?[t.maxSide,...hY.filter(e=>e<t.maxSide)]:[void 0,...hY];for(let r=0;r<n.length;r++){let i=n[r],a=si(pY(e),{cols:t.cols,gap:mY(e,t.gap??`thin`),...t.maxWidth?{maxWidth:t.maxWidth}:{},...i?{maxSide:i,maxPixels:i*i}:{}}),o=await iwe(e,a,t.labels!==!1&&e.length>1);if(o)return{blob:o,layout:a,label:oa(e.length,a.cols),reduced:r>0}}return null}async function iwe(e,t,n){let r=document.createElement(`canvas`);try{if(r.width=t.width,r.height=t.height,r.width!==t.width||r.height!==t.height)return null;let i=r.getContext(`2d`);if(!i)return null;i.fillStyle=XCe,i.fillRect(0,0,r.width,r.height),i.imageSmoothingQuality=`high`;for(let r of t.cells){let t=e[r.i];if(t){try{i.drawImage(t.img,r.x,r.y,r.w,r.h)}catch{}n&&awe(i,r.x,r.y,r.w,r.h,r.i+1)}}return await gH(r,`image/jpeg`,.9)}catch{return null}finally{r.width=0,r.height=0}}function awe(e,t,n,r,i,a){let o=Math.max(22,Math.round(Math.min(r,i)*.095)),s=Math.round(o*.5),c=String(a);e.font=`800 ${o}px system-ui, -apple-system, sans-serif`,e.textBaseline=`middle`,e.textAlign=`center`;let l=o+s,u=Math.max(l,e.measureText(c).width+s*2),d=Math.max(2,Math.round(o*.11)),f=t+Math.round(o*.35)+d,p=n+Math.round(o*.35)+d;owe(e,f,p,u,l,Math.round(o*.32)),e.fillStyle=ZCe,e.fill(),e.lineJoin=`round`,e.lineWidth=d*2.4,e.strokeStyle=$Ce,e.stroke(),e.lineWidth=d,e.strokeStyle=QCe,e.stroke(),e.fillStyle=`#ffffff`,e.fillText(c,f+u/2,p+l/2)}function owe(e,t,n,r,i,a){e.beginPath(),e.moveTo(t+a,n),e.arcTo(t+r,n,t+r,n+i,a),e.arcTo(t+r,n+i,t,n+i,a),e.arcTo(t,n+i,t,n,a),e.arcTo(t,n,t+r,n,a),e.closePath()}var _Y=B.collageGap,vY=B.collageLabels,swe=1200,cwe=()=>{let e=z(_Y);return e===`none`||e===`wide`?e:`thin`},lwe=()=>z(vY)!==`0`;function uwe({files:e,onCombine:t,onSeparate:n,onClose:r}){let[i,a]=(0,H.useState)(null),[o,s]=(0,H.useState)([]),[c,l]=(0,H.useState)(null),[u,d]=(0,H.useState)(cwe),[f,p]=(0,H.useState)(lwe),[m,h]=(0,H.useState)(null),[g,_]=(0,H.useState)(!0),[v,y]=(0,H.useState)(!1),[b,x]=(0,H.useState)(null),[S,C]=(0,H.useState)(!1),w=(0,H.useRef)(null),T=(0,H.useRef)(new Map),E=cH();(0,H.useEffect)(()=>{let t=!0,n=[];return ewe(e).then(({items:r,failed:i})=>{n=r,t?(a(r),s(e.filter(e=>i.includes(e.name))),r.length<2&&x(r.length?`Only one of these could be read as an image on this device.`:`None of these could be read as an image on this device.`)):fY(r)}),()=>{t=!1,fY(n),w.current&&URL.revokeObjectURL(w.current);for(let e of T.current.values())URL.revokeObjectURL(e);T.current.clear()}},[]),(0,H.useEffect)(()=>{if(!i||i.length<2){_(!1);return}let e=!0;return _(!0),gY(i,{cols:c??void 0,gap:u,labels:f,maxSide:swe}).then(t=>{e&&(_(!1),t?(x(null),w.current&&URL.revokeObjectURL(w.current),w.current=URL.createObjectURL(t.blob),h({url:w.current,bytes:t.blob.size})):x(`This device couldn't draw the combined image.`))}),()=>{e=!1}},[i,c,u,f]);let D=i?.length??e.length,O=i&&i.length>1?twe(i,u):1,k=c??O,A=i&&i.length>1?rwe(i,{cols:k,gap:u,...E.width?{maxWidth:E.width*k}:{}}):null;function j(e){let t=T.current.get(e);return t||(t=URL.createObjectURL(e.file),T.current.set(e,t)),t}function M(e,t){a(n=>{if(!n)return n;let r=e+t;if(r<0||r>=n.length)return n;let i=n.slice();return[i[e],i[r]]=[i[r],i[e]],i}),q(`action:collage.reorder`)}function N(e){q(`action:collage.layout`),l(e)}function P(e){d(e),Za(_Y,e)}function F(){let e=!f;p(e),Za(vY,e?`1`:`0`)}async function I(){if(!i||i.length<2)return;q(`action:collage.combine`),y(!0),x(null);let e=await gY(i,{cols:k,gap:u,labels:f,...E.width?{maxWidth:E.width*k}:{}});e?(C(e.reduced),t(new File([e.blob],JV(i.length,e.layout.cols),{type:`image/jpeg`}),Cte(i.length,e.layout.cols,f))):(y(!1),x(`This device couldn't draw the combined image at any size — send them separately instead.`))}return(0,J.jsxs)(`div`,{className:`sheet`,children:[(0,J.jsx)(gE,{title:(0,J.jsxs)(J.Fragment,{children:[D,` images`]}),onClose:r,children:(0,J.jsx)(`span`,{className:`upscale-note`,children:A?`${A.width} × ${A.height}`:``})}),(0,J.jsx)(Z,{children:`Put them on one canvas so a circle or an arrow can span them — that is the only way to point at something that crosses screens. Or keep them apart and mark each in turn.`}),i&&i.length>1&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`collage-strip`,children:i.map((e,t)=>(0,J.jsxs)(`div`,{className:`collage-chip`,children:[(0,J.jsx)(`img`,{src:j(e),alt:e.name}),(0,J.jsx)(`span`,{className:`collage-chip-n`,children:t+1}),(0,J.jsxs)(`div`,{className:`collage-chip-acts`,children:[(0,J.jsx)(Y,{disabled:t===0,title:`earlier`,onClick:()=>M(t,-1),children:(0,J.jsx)(Hl,{size:14})}),(0,J.jsx)(Y,{disabled:t===i.length-1,title:`later`,onClick:()=>M(t,1),children:(0,J.jsx)(jl,{size:14})})]})]},`${e.name}-${t}`))}),(0,J.jsxs)(`div`,{className:`upscale`,children:[(0,J.jsxs)(`span`,{className:`upscale-head`,children:[(0,J.jsx)(zne,{size:12}),` arrangement`]}),(0,J.jsxs)(Y,{className:c===null?`active`:``,title:`chosen from the shapes of these images`,onClick:()=>N(null),children:[(0,J.jsx)(Gl,{size:13}),` auto`]}),nwe(i.length).map(e=>(0,J.jsx)(Y,{className:c===e?`active`:``,onClick:()=>N(e),children:oa(i.length,e)},e)),(0,J.jsx)(`span`,{className:`upscale-note`,children:c===null?`auto → ${oa(i.length,O)}`:``})]}),(0,J.jsxs)(`div`,{className:`upscale`,children:[(0,J.jsxs)(`span`,{className:`upscale-head`,children:[(0,J.jsx)(Lne,{size:12}),` seam`]}),[`none`,`thin`,`wide`].map(e=>(0,J.jsx)(Y,{className:u===e?`active`:``,onClick:()=>P(e),children:e},e)),(0,J.jsxs)(Y,{className:f?`active`:``,title:`number each panel, so the prompt can say which screen it means`,onClick:F,children:[(0,J.jsx)(kne,{size:13}),` numbers`]})]})]}),(0,J.jsx)(`div`,{className:`collage-prev`,children:m?(0,J.jsx)(`img`,{src:m.url,alt:`combined preview`,className:g?`dim`:``}):(0,J.jsx)(`span`,{className:`upscale-note`,children:b?``:`preparing…`})}),(b||o.length>0)&&(0,J.jsxs)(Z,{tone:`warn`,children:[b,o.length>0&&` ${o.length} file${o.length===1?``:`s`} couldn't be decoded on this device and ${o.length===1?`is`:`are`} not in the picture: ${o.map(e=>e.name).join(`, `)}.`]}),m&&!b&&(0,J.jsxs)(Z,{children:[`One image, `,oa(D,k),f?`, panels numbered`:``,` · goes to the annotator next, and uploads at `,lH(E.width),E.width?` per panel`:``,E.auto?` (auto)`:``,`.`,S?` This device couldn't draw it at full size, so it was drawn smaller.`:``,` Preview is ${zp(m.bytes)}.`]}),(0,J.jsxs)(`div`,{className:`sheet-actions`,children:[(0,J.jsxs)(Y,{disabled:v,title:`mark each image on its own, one after another`,onClick:()=>{q(`action:collage.separate`),n(i?[...i.map(e=>e.file),...o]:e)},children:[(0,J.jsx)(Vo,{size:16}),` keep separate`]}),(0,J.jsxs)(`button`,{className:`send`,disabled:v||!i||i.length<2,onClick:()=>void I(),children:[(0,J.jsx)(ys,{size:16}),` `,v?`combining…`:`combine & mark`]})]})]})}var yY=e=>e===`arrow`||e===`line`||e===`marker`,dwe=e=>e===`arrow`||e===`line`;function bY(e){return e===`text`?[`move`,`turn`]:e===`marker`?[`move`,`size`]:dwe(e)?[`move`,`tail`,`head`]:[`move`,`size`,`turn`]}function fwe(e,t,n,r,i){let a=18/n,o=26/n,s=t.x+t.w/2,c=t.y+t.h/2,l=yY(e.tool)?0:e.angle??0,u=(e,t)=>SY({x:e,y:t},{x:s,y:c},l),d=[];for(let n of bY(e.tool))if(n===`move`){let e=Math.abs(t.w/2*Math.sin(l))+Math.abs(t.h/2*Math.cos(l)),r=c+e,u=c-e,f=r+o+a;d.push(f+a<=i?{knob:n,ax:s,ay:r,x:s,y:f}:{knob:n,ax:s,ay:u,x:s,y:u-o-a})}else if(n===`head`||n===`tail`){let t=xY(e.x1-e.x0,e.y1-e.y0),r=n===`head`?1:-1,i=n===`head`?e.x1:e.x0,s=n===`head`?e.y1:e.y0;d.push({knob:n,ax:i,ay:s,x:i+r*t.x*(o+a),y:s+r*t.y*(o+a)})}else if(n===`size`){if(yY(e.tool)){let t=xY(e.x1-e.x0,e.y1-e.y0);d.push({knob:n,ax:e.x1,ay:e.y1,x:e.x1+t.x*(o+a),y:e.y1+t.y*(o+a)})}else{let e=(o+a)*Math.SQRT1_2,r=u(t.x+t.w,t.y+t.h),i=u(t.x+t.w+e,t.y+t.h+e);d.push({knob:n,ax:r.x,ay:r.y,x:i.x,y:i.y})}}else if(yY(e.tool)){let t=xY(e.x1-e.x0,e.y1-e.y0),r=-t.y,i=t.x;(i>0||i===0&&r>0)&&(r=-r,i=-i);let s=(e.x0+e.x1)/2,c=(e.y0+e.y1)/2;d.push({knob:n,ax:s,ay:c,x:s+r*(o+a),y:c+i*(o+a)})}else{let e=u(s,t.y),r=u(s,t.y-o-a);d.push({knob:n,ax:e.x,ay:e.y,x:r.x,y:r.y})}let f=e=>({x:Math.min(Math.max(e.x,a),Math.max(a,r-a)),y:Math.min(Math.max(e.y,a),Math.max(a,i-a))}),p=[];for(let e of d){let t=e=>p.every(t=>Math.hypot(t.x-e.x,t.y-e.y)>=a*2.2),n=f(e);if(!t(n))search:for(let r=1;r<=12;r++)for(let i of[1,-1]){let a=f(SY(e,{x:s,y:c},i*r*20*Math.PI/180));if(t(a)){n=a;break search}}p.push({...e,x:n.x,y:n.y})}return p}function pwe(e,t,n,r){let i=24/r,a=null,o=1/0;for(let r of e){let e=Math.hypot(r.x-t,r.y-n);e<=i&&e<o&&(a=r,o=e)}return a?.knob??null}function mwe(e,t,n,r,i,a){let o=r.x-n.x,s=r.y-n.y,c=16/i;if(e===`move`)return{...t,x0:t.x0+o,y0:t.y0+s,x1:t.x1+o,y1:t.y1+s};if(e===`head`||e===`tail`){let n=e===`head`,r=n?t.x0:t.x1,i=n?t.y0:t.y1,a=(n?t.x1:t.x0)+o,l=(n?t.y1:t.y0)+s;if(Math.hypot(a-r,l-i)<c){let e=xY(a-r||(n?t.x1-t.x0:t.x0-t.x1),l-i||(n?t.y1-t.y0:t.y0-t.y1));a=r+e.x*c,l=i+e.y*c}return n?{...t,x1:a,y1:l}:{...t,x0:a,y0:l}}let l=a?.x??(t.x0+t.x1)/2,u=a?.y??(t.y0+t.y1)/2;if(e===`turn`){if(Math.hypot(n.x-l,n.y-u)<c||Math.hypot(r.x-l,r.y-u)<c)return t;let e=Math.atan2(r.y-u,r.x-l)-Math.atan2(n.y-u,n.x-l);if(!yY(t.tool))return{...t,angle:hwe((t.angle??0)+e)};let i=SY({x:t.x0,y:t.y0},{x:l,y:u},e),a=SY({x:t.x1,y:t.y1},{x:l,y:u},e);return{...t,x0:i.x,y0:i.y,x1:a.x,y1:a.y}}if(yY(t.tool)){let e=xY(t.x1-t.x0,t.y1-t.y0),n=Math.max(c/2,Math.hypot(t.x1-t.x0,t.y1-t.y0)/2+o*e.x+s*e.y);return{...t,x0:l-e.x*n,y0:u-e.y*n,x1:l+e.x*n,y1:u+e.y*n}}let d=t.angle??0,f=SY({x:o,y:s},{x:0,y:0},-d),p=Math.abs(t.x1-t.x0),m=Math.abs(t.y1-t.y0),h=Math.max(c,p+f.x),g=Math.max(c,m+f.y),_=SY({x:l-p/2,y:u-m/2},{x:l,y:u},d),v=SY({x:h/2,y:g/2},{x:0,y:0},d),y={x:_.x+v.x,y:_.y+v.y};return{...t,x0:y.x-h/2,y0:y.y-g/2,x1:y.x+h/2,y1:y.y+g/2}}function hwe(e){let t=e%(Math.PI*2);return t>Math.PI?t-Math.PI*2:t<=-Math.PI?t+Math.PI*2:t}function xY(e,t){let n=Math.hypot(e,t);return n>1e-6?{x:e/n,y:t/n}:{x:1,y:0}}function SY(e,t,n){let r=Math.cos(n),i=Math.sin(n),a=e.x-t.x,o=e.y-t.y;return{x:t.x+a*r-o*i,y:t.y+a*i+o*r}}var gwe={move:`#2f80ed`,size:`#f2994a`,turn:`#27ae60`,tail:`#f2994a`,head:`#f2994a`};function _we(e){let t={move:`blue moves`,size:yY(e)?`orange sets the length`:`orange sizes`,turn:`green turns`,tail:`orange drags that end`,head:`orange drags that end`},n=[...new Set(bY(e).map(e=>t[e]))];return n[0][0].toUpperCase()+n.join(` · `).slice(1)}function vwe(e,t,n,r,i,a){e.save(),e.strokeStyle=`#fff`,e.lineWidth=a,e.lineCap=`round`,e.lineJoin=`round`;let o=i*.35;if(e.beginPath(),t===`move`){e.moveTo(n-i,r),e.lineTo(n+i,r),e.moveTo(n,r-i),e.lineTo(n,r+i);for(let[t,a]of[[1,0],[-1,0],[0,1],[0,-1]]){let s=n+t*i,c=r+a*i;e.moveTo(s-t*o+a*o,c-a*o+t*o),e.lineTo(s,c),e.lineTo(s-t*o-a*o,c-a*o-t*o)}}else if(t===`head`||t===`tail`)e.arc(n,r,i*.55,0,Math.PI*2);else if(t===`size`){let t=i*.75;e.moveTo(n-t,r-t),e.lineTo(n+t,r+t),e.moveTo(n-t+o*1.4,r-t),e.lineTo(n-t,r-t),e.lineTo(n-t,r-t+o*1.4),e.moveTo(n+t-o*1.4,r+t),e.lineTo(n+t,r+t),e.lineTo(n+t,r+t-o*1.4)}else{let t=-Math.PI*.25;e.arc(n,r,i*.8,t,Math.PI*1.45);let a=n+Math.cos(t)*i*.8,s=r+Math.sin(t)*i*.8;e.moveTo(a-o*1.2,s-o*.2),e.lineTo(a,s),e.lineTo(a+o*.1,s-o*1.2)}e.stroke(),e.restore()}function ywe({m:e}){let{tool:t,shapes:n,moveMode:r,selected:i,target:a,setTarget:o,moveNote:s,knobs:c,err:l,cropMode:u,pendingCrop:d,pendingText:f,textDraft:p,setTextDraft:m,textInputRef:h,editRead:g,setEditRead:_,readDraft:v,setReadDraft:y,readInputRef:b,lastBand:x,applyCrop:S,toggleCrop:C,commitText:w,cancelText:T,startEditRead:E,commitRead:D,dropRead:O,hintHidden:k,hideHint:A}=e;return(0,J.jsxs)(J.Fragment,{children:[u?(0,J.jsxs)(`div`,{className:`annot-crop-bar`,children:[(0,J.jsx)(`span`,{className:`annot-hint`,children:d?`crop to ${Math.round(d.w)}×${Math.round(d.h)}`:`drag a box to crop`}),(0,J.jsx)(`button`,{className:`send`,disabled:!d,onClick:S,children:`Apply crop`}),(0,J.jsx)(Y,{onClick:C,children:`cancel`})]}):g==null?f?(0,J.jsxs)(`div`,{className:`annot-crop-bar`,children:[(0,J.jsx)(`input`,{className:`search annot-text-in`,ref:h,value:p,placeholder:`label text`,"aria-label":`label text`,onChange:e=>m(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),w())}}),(0,J.jsx)(`button`,{className:`send`,disabled:!p.trim(),onClick:w,children:`Place`}),(0,J.jsx)(Y,{onClick:T,children:`cancel`})]}):r&&i!=null&&n[i]&&c?(0,J.jsx)(`div`,{className:`annot-hint`,children:s??_we(n[i].tool)}):r&&i!=null&&n[i]?n[i].tool===`text`?(0,J.jsx)(`div`,{className:`annot-hint`,children:`Drag anywhere to move the label — from beside the picture too.`}):(0,J.jsxs)(`div`,{className:`annot-crop-bar`,children:[(0,J.jsx)(Y,{className:a===null?`active`:``,onClick:()=>o(null),"aria-pressed":a===null,children:`whole`}),(0,J.jsx)(Y,{className:a===0?`active`:``,onClick:()=>o(0),"aria-pressed":a===0,children:n[i].tool===`arrow`?`tail`:`A`}),(0,J.jsx)(Y,{className:a===1?`active`:``,onClick:()=>o(1),"aria-pressed":a===1,children:n[i].tool===`arrow`?`head`:`B`}),(0,J.jsx)(`span`,{className:`annot-hint`,children:s??`Drag anywhere — the finger needn't be on the mark · pinch to zoom for finer steps`})]}):k?null:(0,J.jsxs)(`div`,{className:`annot-hint annot-hint-x`,children:[(0,J.jsx)(`span`,{children:r?`Tap a mark to select it`:t===`text`?`Tap where the label goes, then type it · two fingers pinch-zoom & pan`:t===`marker`?`Swipe along a line of text to point at it · Claude reads the words off the picture`:`One finger draws, from beside the picture too · two fingers pinch-zoom & pan · crop trims the image`}),(0,J.jsx)(Y,{onClick:A,"aria-label":`hide this hint for good`,children:(0,J.jsx)(V,{size:14,"aria-hidden":!0})})]}):(0,J.jsxs)(`div`,{className:`annot-crop-bar`,children:[(0,J.jsx)(`input`,{className:`search annot-text-in`,ref:b,value:v,placeholder:`the highlighted words`,"aria-label":`the highlighted words`,onChange:e=>y(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),D())}}),(0,J.jsx)(`button`,{className:`send`,onClick:D,children:`Use`}),(0,J.jsx)(Y,{onClick:()=>{_(null),y(``)},children:`cancel`})]}),x&&!u&&f==null&&g==null&&(0,J.jsx)(`div`,{className:`annot-read`,children:x.read?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`span`,{className:`annot-hint annot-read-text`,children:[`reads: “`,x.read,`”`]}),(0,J.jsx)(Y,{onClick:()=>E(x),children:`edit`}),(0,J.jsx)(Y,{onClick:()=>O(x),children:`drop`})]}):x.reading?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`annot-hint`,children:`reading…`}),(0,J.jsx)(Y,{onClick:()=>E(x),children:`type its words`})]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`annot-hint`,children:x.readErr??`the mark says where to look · its words are optional`}),(0,J.jsx)(Y,{onClick:()=>E(x),children:`type its words`})]})}),l&&(0,J.jsx)(`div`,{className:`err`,children:l})]})}var bwe=`(min-width: 1280px)`,CY=G(!1),wY=G(!1);function TY(){return K(wY)}function EY(){return K(CY)}if(typeof window<`u`)try{let e=window.matchMedia?.(bwe);if(e){let t=()=>CY.set(e.matches);t(),e.addEventListener?.(`change`,t)}}catch{}var DY=null;function xwe(e){return DY=e,()=>{DY===e&&(DY=null)}}function Swe(){return DY}function Cwe({m:e}){let{view:t,fitRef:n,zoomed:r,resetZoom:i,configOpen:a,setConfigOpen:o}=e,s=EY(),c=TY(),l=s&&!!e.props.onDispatch,{send:u}=e;return(0,H.useEffect)(()=>l?xwe(e=>void u(e)):void 0,[l,u]),(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(Y,{className:r?`active`:``,onClick:i,title:`reset zoom`,"aria-label":`reset zoom`,children:[(0,J.jsx)(el,{size:16}),` `,(t.k/(n.current.k||1)).toFixed(1),`×`]}),(0,J.jsx)(Y,{className:a?`active`:``,onClick:()=>o(e=>!e),"aria-pressed":a,title:`customize the toolbar`,"aria-label":`customize the toolbar`,children:(0,J.jsx)(Os,{size:16})}),l&&(0,J.jsx)(Y,{className:c?`active`:``,onClick:()=>wY.set(!c),"aria-pressed":c,title:c?`back beside the session (Esc)`:`full screen — the session stays where it is`,"aria-label":c?`exit annotator full screen`:`annotator full screen`,children:c?(0,J.jsx)(yc,{size:16}):(0,J.jsx)(wc,{size:16})})]})}function wwe({prompt:e}){let[t,n]=(0,H.useState)(()=>io(B.annPrompt,!1)),r=()=>n(e=>(Za(B.annPrompt,e?`0`:`1`),!e)),i=e.value.trim().split(`
|
|
205
|
-
`)[0];return(0,J.jsxs)(`div`,{className:`ann-prompt`,children:[(0,J.jsxs)(`button`,{className:`ann-prompt-fold`,onClick:r,"aria-expanded":t,title:t?`fold the message box away`:`show the session's message box — typed here, sent with the picture on Send & run`,children:[t?(0,J.jsx)(ac,{size:14}):(0,J.jsx)(jl,{size:14}),(0,J.jsx)(Qne,{size:14}),(0,J.jsx)(`span`,{className:`ann-prompt-gist`,children:t?`message for the session`:i||`message for the session — empty`})]}),t&&(0,J.jsx)(uD,{inline:!0,rows:2,prompts:[e.value],onChange:t=>e.onChange(t[0]??``),placeholder:`Message for the session — Send & run sends it with the picture`})]})}function Twe({m:e}){let{busy:t,send:n,sendAll:r,readAll:i}=e,{index:a,total:o,onSkip:s,onSendAll:c,onDispatch:l,onText:u}=e.props;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(yH,{compact:!0}),(0,J.jsxs)(`div`,{className:`sheet-actions annot-send-bar`,"data-primary-key":``,children:[s&&(0,J.jsx)(Y,{onClick:s,disabled:t,children:`skip`}),c&&o&&o>1&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Y,{onClick:()=>r(`none`),disabled:t,title:`send this + every remaining image as-is`,children:`Send all`}),(0,J.jsx)(Y,{onClick:()=>r(`run`),disabled:t,title:`send all, then submit once uploads finish`,children:`Send all + submit`}),(0,J.jsxs)(Y,{onClick:()=>r(`queue`),disabled:t,title:`send all, then hand the prompt to the desktop — it goes in when this session is free`,children:[(0,J.jsx)(Kl,{size:14}),` Send all, then when it's free`]})]}),l&&(!o||o<=1)&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Y,{onClick:()=>n(`run`),disabled:t,title:`attach the image and run the prompt (uploads in the background)`,children:`Send & run`}),(0,J.jsxs)(Y,{onClick:()=>n(`queue`),disabled:t,title:`attach the image and hand the prompt to the desktop — it goes in when this session is free`,children:[(0,J.jsx)(Kl,{size:14}),` Send & when it's free`]})]}),u&&(0,J.jsxs)(Y,{onClick:()=>void i(),disabled:t,title:`read every word on the desktop and send only the text, not the photo`,children:[(0,J.jsx)(fc,{size:14}),` text only`]}),(0,J.jsx)(`button`,{className:`send`,onClick:()=>n(`none`),disabled:t,children:t?`Sending…`:o&&o>1&&(a??1)<o?`Send & next`:`Send to repo`})]})]})}var OY=[{id:`undo`,label:`undo`},{id:`circle`,label:`circle`},{id:`rect`,label:`rectangle`},{id:`arrow`,label:`arrow`},{id:`line`,label:`line`},{id:`text`,label:`text label`},{id:`marker`,label:`highlight text`},{id:`blur`,label:`blur / redact`},{id:`crop`,label:`crop`},{id:`move`,label:`move a mark`},{id:`style`,label:`colour & stroke`},{id:`clear`,label:`clear all marks`}],kY=OY.map(e=>e.id),Ewe=[`auto`,`left`,`top`],AY={order:kY.slice(),hidden:[],place:`auto`},jY=e=>typeof e==`string`&&kY.includes(e);function Dwe(e){if(!e||typeof e!=`object`)return{...AY,order:kY.slice()};let t=e,n=new Set,r=[];for(let e of Array.isArray(t.order)?t.order:[])jY(e)&&!n.has(e)&&(n.add(e),r.push(e));return kY.forEach((e,t)=>{if(n.has(e))return;let i=0;for(let e=t-1;e>=0;e--){let t=r.indexOf(kY[e]);if(t>=0){i=t+1;break}}r.splice(i,0,e),n.add(e)}),{order:r,hidden:(Array.isArray(t.hidden)?t.hidden:[]).filter(jY).filter((e,t,n)=>n.indexOf(e)===t),place:Ewe.includes(t.place)?t.place:`auto`}}function Owe(e){return e.order.filter(t=>!e.hidden.includes(t))}function kwe(e,t){let n=e.hidden.includes(t)?e.hidden.filter(e=>e!==t):[...e.hidden,t];return{...e,hidden:n}}function MY(e,t,n){let r=e.order.indexOf(t),i=r+n;if(r<0||i<0||i>=e.order.length)return e;let a=e.order.slice();return[a[r],a[i]]=[a[i],a[r]],{...e,order:a}}function Awe(e){return e.place===`auto`&&!e.hidden.length&&e.order.every((e,t)=>e===kY[t])}function jwe(e,t){if(!e||!t||e.w<1||e.h<1||t.w<1||t.h<1)return null;let n=(e,n)=>Math.min(Math.max(e,0)/t.w,Math.max(n,0)/t.h),r=n(e.w-57,e.h);return n(e.w,e.h-61)>r?`top`:`left`}var Mwe=[{v:`auto`,label:`auto`},{v:`left`,label:`left`},{v:`top`,label:`top`}];function Nwe({m:e}){let{layout:t,setLayout:n,setConfigOpen:r}=e,i=e=>OY.find(t=>t.id===e)?.label??e,a=t.order.length-1;return(0,J.jsxs)(`div`,{className:`annot-config`,role:`dialog`,"aria-label":`customize the toolbar`,children:[(0,J.jsxs)(`div`,{className:`annot-config-head`,children:[(0,J.jsx)(`span`,{children:`Toolbar`}),(0,J.jsxs)(Y,{onClick:()=>r(!1),"aria-label":`close the toolbar settings`,children:[(0,J.jsx)(V,{size:16}),` done`]})]}),(0,J.jsxs)(`div`,{className:`annot-config-row`,children:[(0,J.jsx)(`span`,{className:`annot-config-label`,children:`position`}),Mwe.map(e=>(0,J.jsx)(Y,{className:t.place===e.v?`active`:``,"aria-pressed":t.place===e.v,onClick:()=>n({...t,place:e.v}),children:e.label},e.v))]}),(0,J.jsx)(`div`,{className:`annot-config-hint`,children:t.place===`auto`?`auto: whichever side leaves this picture larger — a row on top for a wide one, a rail on the left for a tall one`:`always on the ${t.place}`}),(0,J.jsx)(`div`,{className:`annot-config-list`,children:t.order.map((e,r)=>{let o=!t.hidden.includes(e);return(0,J.jsxs)(`div`,{className:`annot-config-row ${o?``:`off`}`,children:[(0,J.jsx)(Y,{className:`annot-config-toggle${o?` active`:``}`,"aria-pressed":o,onClick:()=>n(kwe(t,e)),children:o?`shown`:`hidden`}),(0,J.jsx)(`span`,{className:`annot-config-label`,children:i(e)}),r>0?(0,J.jsx)(Y,{onClick:()=>n(MY(t,e,-1)),"aria-label":`move ${i(e)} up`,children:(0,J.jsx)(Ys,{size:16})}):(0,J.jsx)(`span`,{className:`annot-config-gap`}),r<a?(0,J.jsx)(Y,{onClick:()=>n(MY(t,e,1)),"aria-label":`move ${i(e)} down`,children:(0,J.jsx)(ac,{size:16})}):(0,J.jsx)(`span`,{className:`annot-config-gap`})]},e)})}),!Awe(t)&&(0,J.jsx)(`div`,{className:`annot-config-row`,children:(0,J.jsx)(Y,{onClick:()=>n({...AY,order:AY.order.slice()}),children:`reset to default`})})]})}var NY=[`#ff2d2d`,`#ffd400`,`#3fb950`,`#4c9aff`,`#ffffff`],Pwe=`#ffd400`,PY=[{label:`S`,factor:.6},{label:`M`,factor:1},{label:`L`,factor:1.8}];function Fwe(e){return e instanceof File,e.name}var Iwe={circle:{tool:`circle`,icon:(0,J.jsx)(vc,{size:16}),label:`circle`},rect:{tool:`rect`,icon:(0,J.jsx)(Rc,{size:16}),label:`rectangle`},arrow:{tool:`arrow`,icon:(0,J.jsx)(qne,{size:16}),label:`arrow`},line:{tool:`line`,icon:(0,J.jsx)(hs,{size:16}),label:`line`},text:{tool:`text`,icon:(0,J.jsx)(Dc,{size:16}),label:`text`},marker:{tool:`marker`,icon:(0,J.jsx)(bne,{size:16}),label:`highlight text`},blur:{tool:`blur`,icon:(0,J.jsx)(Gc,{size:16}),label:`blur or redact`}};function Lwe({m:e}){let{tool:t,color:n,setColor:r,factor:i,setFactor:a,shapes:o,setShapes:s,moveMode:c,selected:l,setSelected:u,setTarget:d,setMoveNote:f,knobs:p,cropMode:m,paletteOpen:h,setPaletteOpen:g,moveRef:_,toggleCrop:v,pickTool:y,undoShape:b,toggleMove:x,toggleKnobs:S,deleteSelected:C,layout:w}=e,T=PY.find(e=>e.factor===i)?.label??`M`;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`annot-tools annot-bar`,children:Owe(w).map(e=>{let r=Iwe[e];if(r)return(0,J.jsx)(Y,{className:t===r.tool?`active`:``,onClick:()=>y(r.tool),title:r.label,"aria-label":r.label,"aria-pressed":t===r.tool,children:r.icon},e);switch(e){case`undo`:return(0,J.jsx)(Y,{onClick:b,disabled:!o.length,title:`undo`,"aria-label":`undo the last mark`,children:(0,J.jsx)(Ac,{size:16})},e);case`crop`:return(0,J.jsx)(Y,{className:m?`active`:``,onClick:v,title:`crop`,"aria-label":`crop`,"aria-pressed":m,children:(0,J.jsx)(Fne,{size:16})},e);case`move`:return[(0,J.jsx)(Y,{className:c?`active`:``,onClick:x,disabled:!o.length,title:`move/reshape a mark`,"aria-label":`move a mark`,"aria-pressed":c,children:(0,J.jsx)(Pne,{size:16})},e),c&&(0,J.jsx)(Y,{onClick:C,disabled:l==null,title:`delete the selected mark`,"aria-label":`delete the selected mark`,children:(0,J.jsx)(ic,{size:16})},`del`),c&&(0,J.jsx)(Y,{className:p?`active`:``,onClick:S,"aria-pressed":p,title:`knobs: move, size and turn a mark (or drag an arrow's ends) by knobs on strings, instead of dragging from anywhere`,"aria-label":`knobs on the selected mark`,children:`knobs`},`knobs`)];case`style`:return(0,J.jsx)(`button`,{className:`swatch dot annot-style ${h?`on`:``}`,style:{background:n},onClick:()=>g(e=>!e),title:`mark colour and stroke`,"aria-label":`mark colour ${n}, stroke ${T} — tap to change`,"aria-expanded":h,children:T},e);case`clear`:return(0,J.jsx)(Y,{onClick:()=>{_.current=null,u(null),d(null),f(null),s([])},disabled:!o.length,title:`clear all marks`,"aria-label":`clear all marks`,children:(0,J.jsx)(Vc,{size:16})},e)}return null})}),h&&(0,J.jsxs)(`div`,{className:`annot-tools annot-palette`,children:[NY.map(e=>(0,J.jsx)(`button`,{className:`swatch ${n===e?`on`:``}`,style:{background:e},onClick:()=>{r(e),g(!1)},title:`colour ${e}`,"aria-label":`colour ${e}`,"aria-pressed":n===e},e)),PY.map(e=>(0,J.jsx)(Y,{className:i===e.factor?`active`:``,onClick:()=>{a(e.factor),g(!1)},title:`stroke ${e.label}`,"aria-label":`stroke ${e.label}`,"aria-pressed":i===e.factor,children:e.label},e.label))]})]})}function Rwe({m:e}){let{canvasRef:t,wrapRef:n,bodyRef:r,view:i,onDown:a,onMove:o,onUp:s,place:c,configOpen:l}=e;return(0,J.jsxs)(`div`,{className:`annot-body place-${c}`,ref:r,children:[(0,J.jsx)(Lwe,{m:e}),(0,J.jsx)(`div`,{className:`annot-canvas-wrap`,ref:n,onPointerDown:a,onPointerMove:o,onPointerUp:s,onPointerCancel:s,children:(0,J.jsx)(`canvas`,{ref:t,className:`annot-canvas`,style:{transform:`translate(${i.tx}px, ${i.ty}px) scale(${i.k})`,transformOrigin:`0 0`}})}),l&&(0,J.jsx)(Nwe,{m:e})]})}function zwe({m:e}){let{ocr:t,ocrDraft:n,setOcrDraft:r,readAll:i,closeOcr:a,sendText:o}=e;if(!t)return null;let s=!n.trim();return(0,J.jsxs)(`div`,{className:`annot-ocr`,children:[t.phase===`reading`&&(0,J.jsx)(`div`,{className:`annot-hint`,children:`Reading every word on your desktop… The photo goes no further than that machine.`}),t.phase===`error`&&(0,J.jsx)(`div`,{className:`annot-hint`,children:t.error}),t.phase===`ready`&&(0,J.jsxs)(`div`,{className:`annot-hint`,children:[`Read on your desktop (`,t.engine,`, `,(t.ms/1e3).toFixed(1),` s). Fix anything misread — only this text is sent, never the photo.`]}),(t.phase===`ready`||!s)&&(0,J.jsx)(`textarea`,{className:`annot-ocr-text`,value:n,onChange:e=>r(e.target.value),spellCheck:!1,autoCapitalize:`off`,"aria-label":`text read off the picture`}),t.phase===`ready`&&s&&(0,J.jsx)(`div`,{className:`annot-hint`,children:`Nothing left to send — read again, or go back to the picture.`}),(0,J.jsxs)(`div`,{className:`sheet-actions annot-send-bar`,"data-primary-key":``,children:[(0,J.jsxs)(Y,{onClick:a,children:[(0,J.jsx)(pl,{size:14}),` picture`]}),t.phase!==`reading`&&(0,J.jsxs)(Y,{onClick:()=>void i(),children:[(0,J.jsx)($c,{size:14}),` read again`]}),t.phase!==`reading`&&!s&&(0,J.jsxs)(`button`,{className:`send`,onClick:()=>o(n),children:[(0,J.jsx)(fc,{size:14}),` Send text only`]})]})]})}var Bwe={"#ff2d2d":`red`,"#ffd400":`yellow`,"#3fb950":`green`,"#4c9aff":`blue`,"#ffffff":`white`};function Vwe(e,t,n,r){let i=t/r,a=e/n,o=i<.34?`top`:i>.66?`bottom`:`middle`,s=a<.34?`left`:a>.66?`right`:`center`;return o===`middle`&&s===`center`?`center`:o===`middle`?s:s===`center`?o:`${o}-${s}`}function FY(e){return`${Math.round(Math.max(0,Math.min(1,e))*100)}%`}function IY(e,t,n,r){return`${Vwe(e,t,n,r)} (x ${FY(e/n)}, y ${FY(t/r)})`}function LY(e,t,n){let r=Math.min(e.x0,e.x1),i=Math.max(e.x0,e.x1),a=Math.min(e.y0,e.y1),o=Math.max(e.y0,e.y1);return`(x ${FY(r/t)}-${FY(i/t)}, y ${FY(a/n)}-${FY(o/n)})`}function RY(e){return`"${e.replace(/\s+/g,` `).trim().replace(/"/g,`''`)}"`}var Hwe=e=>Bwe[e.toLowerCase()]||e;function Uwe(e,t,n){return[e.tool,e.color.toLowerCase(),FY(Math.min(e.x0,e.x1)/t),FY(Math.min(e.y0,e.y1)/n),FY(Math.max(e.x0,e.x1)/t),FY(Math.max(e.y0,e.y1)/n),(e.text??``).trim(),(e.read??``).trim()].join(`|`)}function zY(e,t,n){if(t<=0||n<=0)return[];let r=new Set,i=[];for(let a of e){let e=Uwe(a,t,n);r.has(e)||(r.add(e),i.push(a))}return i}function Wwe(e,t,n){switch(e.tool){case`blur`:return`blurred/redacted region ${LY(e,t,n)}`;case`text`:return`text ${RY(e.text||``)} at ${IY(e.x0,e.y0,t,n)}`;case`marker`:return e.read?`highlight over ${RY(e.read)} ${LY(e,t,n)}`:`highlight ${LY(e,t,n)}`;case`arrow`:return`arrow pointing to ${IY(e.x1,e.y1,t,n)}`;case`line`:return`line from ${IY(e.x0,e.y0,t,n)} to ${IY(e.x1,e.y1,t,n)}`;case`rect`:return e.read?`box around ${RY(e.read)} ${LY(e,t,n)}`:`box ${LY(e,t,n)}`;default:return e.read?`circle around ${RY(e.read)} ${LY(e,t,n)}`:`circle ${LY(e,t,n)}`}}function Gwe(e,t,n,r){let i=zY(e,t,n),a=[];r&&a.push(r);let o=i.length>1,s=new Set(i.map(e=>e.color.toLowerCase())).size<=1;return i.forEach((e,r)=>{let i=o?`#${r+1} `:``,c=s||e.tool===`blur`?``:`${Hwe(e.color)} `;a.push(`${i}${c}${Wwe(e,t,n)}`)}),a.join(`; `)}function BY(e,t){return!e||!t||!(t.w>0)||!(t.h>0)?e:`${e}; image ${Math.round(t.w)}x${Math.round(t.h)}`}var Kwe=new Set([`rect`,`blur`,`marker`]),VY=(e,t)=>tm(e,0,t);function HY(e,t,n){return Math.max(e.x0,e.x1)>0&&Math.min(e.x0,e.x1)<t&&Math.max(e.y0,e.y1)>0&&Math.min(e.y0,e.y1)<n}function UY(e,t){let n=(e.x0+e.x1)/2,r=(e.y0+e.y1)/2,i=Math.abs(e.x1-e.x0)/2,a=Math.abs(e.y1-e.y0)/2,o=Math.abs(i*Math.cos(t))+Math.abs(a*Math.sin(t)),s=Math.abs(i*Math.sin(t))+Math.abs(a*Math.cos(t));return{x0:n-o,y0:r-s,x1:n+o,y1:r+s}}function qwe(e,t,n){let r=e.x1-e.x0,i=e.y1-e.y0,a=0,o=1,s=[[-r,e.x0-0],[r,t-e.x0],[-i,e.y0-0],[i,n-e.y0]];for(let[e,t]of s){if(e===0){if(t<0)return null;continue}let n=t/e;if(e<0){if(n>o)return null;n>a&&(a=n)}else{if(n<a)return null;n<o&&(o=n)}}return{x0:e.x0+a*r,y0:e.y0+a*i,x1:e.x0+o*r,y1:e.y0+o*i}}function WY(e,t,n){if(!(t>0&&n>0))return e;if(e.tool===`text`){let r=VY(e.x0,t),i=VY(e.y0,n);return{...e,x0:r,y0:i,x1:r,y1:i}}if(e.tool===`line`||e.tool===`arrow`){let r=qwe(e,t,n);return r?{...e,...r}:null}return e.angle?HY(UY(e,e.angle),t,n)?e:null:HY(e,t,n)?Kwe.has(e.tool)?{...e,x0:VY(e.x0,t),y0:VY(e.y0,n),x1:VY(e.x1,t),y1:VY(e.y1,n)}:e:null}function GY(e,t){return e.tool!==`text`&&Math.hypot(e.x1-e.x0,e.y1-e.y0)*t<48}function Jwe(e){let{sel:t,small:n,handleHit:r,pickHit:i,target:a}=e;return t!=null&&!n&&r!=null?{kind:`handle`,i:t,h:r}:i==null?t==null?{kind:`none`}:{kind:`relative`,i:t,h:a}:{kind:`pick`,i}}function Ywe(e,t,n,r){let i=WY(e,n,r);return i?{mark:i,refused:!1}:{mark:t,refused:!0}}function KY(e){return Math.max(4,Math.round(e.width/220))}function qY(e){return{x:Math.min(e.x0,e.x1),y:Math.min(e.y0,e.y1),w:Math.abs(e.x1-e.x0),h:Math.abs(e.y1-e.y0)}}function JY(e,t){if(!e)return t;let n=t=>Math.max(0,Math.min(t,e.width)),r=t=>Math.max(0,Math.min(t,e.height)),i=n(t.x),a=r(t.y);return{x:i,y:a,w:n(t.x+t.w)-i,h:r(t.y+t.h)-a}}function Xwe(e){let t=/^#?([0-9a-f]{6})$/i.exec(e.trim());if(!t)return`#fff`;let n=parseInt(t[1],16);return(.299*(n>>16&255)+.587*(n>>8&255)+.114*(n&255))/255>.6?`#111`:`#fff`}function Zwe(e){if(e.tool===`text`||e.tool===`arrow`||e.tool===`line`)return{x:e.x0,y:e.y0};let t=qY(e);if(!e.angle)return{x:t.x,y:t.y};let n=t.x+t.w/2,r=t.y+t.h/2,i=Math.cos(e.angle),a=Math.sin(e.angle);return{x:n+-t.w/2*i- -t.h/2*a,y:r+-t.w/2*a+-t.h/2*i}}function YY(e,t,n){if(n.tool===`text`){let r=Math.max(16,Math.round(t.width/26))*n.factor;e.save(),e.font=`bold ${r}px ui-sans-serif, system-ui, sans-serif`;let i=e.measureText(n.text||``).width;return e.restore(),{x:n.x0,y:n.y0,w:i,h:r*1.2}}return qY(n)}function Qwe(e,t,n,r,i,a){let o=i-n,s=a-r,c=o*o+s*s,l=c?Math.max(0,Math.min(1,((e-n)*o+(t-r)*s)/c)):0;return Math.hypot(e-(n+l*o),t-(r+l*s))}function $we(e,t,n,r,i){if(!e)return!1;if(t.tool===`arrow`||t.tool===`line`)return Qwe(n,r,t.x0,t.y0,t.x1,t.y1)<=i;let a=YY(e.getContext(`2d`),e,t);if(t.angle){let e=a.x+a.w/2,i=a.y+a.h/2,o=Math.cos(-t.angle),s=Math.sin(-t.angle),c=e+(n-e)*o-(r-i)*s,l=i+(n-e)*s+(r-i)*o;n=c,r=l}return n>=a.x-i&&n<=a.x+a.w+i&&r>=a.y-i&&r<=a.y+a.h+i}function eTe(e,t,n){if(!n)return;let r=KY(t);e.save(),e.fillStyle=`rgba(0,0,0,.55)`,e.beginPath(),e.rect(0,0,t.width,t.height),e.rect(n.x,n.y,n.w,n.h),e.fill(`evenodd`),e.strokeStyle=`#fff`,e.lineWidth=r,e.setLineDash([r*2.5,r*2.5]),e.strokeRect(n.x,n.y,n.w,n.h),e.restore()}function XY(e,t,n,r){if(!n)return;if(r.angle){let i=qY(r),a=i.x+i.w/2,o=i.y+i.h/2;e.save(),e.beginPath(),e.translate(a,o),e.rotate(r.angle),e.rect(-i.w/2,-i.h/2,i.w,i.h),e.setTransform(1,0,0,1,0,0),e.clip(),XY(e,t,n,{...r,angle:0,...UY(r,r.angle)}),e.restore();return}let{x:i,y:a,w:o,h:s}=JY(t,qY(r));if(o<1||s<1)return;let c=Math.max(8,Math.round(t.width/48)),l=Math.max(1,Math.round(o/c)),u=Math.max(1,Math.round(s/c)),d=document.createElement(`canvas`);d.width=l,d.height=u,d.getContext(`2d`).drawImage(n,i,a,o,s,0,0,l,u),e.save(),e.imageSmoothingEnabled=!1,e.drawImage(d,0,0,l,u,i,a,o,s),e.restore()}function tTe(e,t,n){let r=qY(n),i=KY(t)*5*n.factor,a=Math.max(r.h,i),o=r.h>=i?r.y:r.y-(i-r.h)/2;e.save(),e.globalAlpha=.38,e.globalCompositeOperation=`multiply`,e.fillStyle=n.color,e.fillRect(r.x,o,Math.max(r.w,i),a),e.restore()}function nTe(e,t,n){if(n.length<2)return;let r=Math.max(10,KY(t)*3.2);n.forEach((n,i)=>{let a=Zwe(n),o=Math.max(r+2,Math.min(t.width-r-2,a.x-r*.2)),s=Math.max(r+2,Math.min(t.height-r-2,a.y-r*.2));e.save(),e.beginPath(),e.arc(o,s,r,0,Math.PI*2),e.fillStyle=n.tool===`blur`?`#111`:n.color,e.fill(),e.lineWidth=Math.max(1,r*.14),e.strokeStyle=`rgba(0,0,0,.55)`,e.stroke(),e.fillStyle=n.tool===`blur`?`#fff`:Xwe(n.color),e.font=`bold ${Math.round(r*1.25)}px ui-sans-serif, system-ui, sans-serif`,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(String(i+1),o,s),e.restore()}),e.textAlign=`start`}function ZY(e,t,n,r){if(!r.angle||r.tool===`blur`||r.tool===`arrow`||r.tool===`line`){QY(e,t,n,r);return}let i=YY(e,t,r),a=i.x+i.w/2,o=i.y+i.h/2;e.save(),e.translate(a,o),e.rotate(r.angle),e.translate(-a,-o),QY(e,t,n,r),e.restore()}function QY(e,t,n,r){if(r.tool===`blur`){XY(e,t,n,r);return}if(r.tool===`marker`){tTe(e,t,r);return}let i=KY(t)*r.factor;if(e.strokeStyle=r.color,e.fillStyle=r.color,e.lineWidth=i,e.lineCap=`round`,e.lineJoin=`round`,r.tool===`rect`)e.strokeRect(r.x0,r.y0,r.x1-r.x0,r.y1-r.y0);else if(r.tool===`circle`)e.beginPath(),e.ellipse((r.x0+r.x1)/2,(r.y0+r.y1)/2,Math.abs(r.x1-r.x0)/2,Math.abs(r.y1-r.y0)/2,0,0,Math.PI*2),e.stroke();else if(r.tool===`arrow`||r.tool===`line`){let t=Math.atan2(r.y1-r.y0,r.x1-r.x0),n=i*4;if(e.beginPath(),e.moveTo(r.x0,r.y0),e.lineTo(r.x1,r.y1),e.stroke(),r.tool===`line`)return;e.beginPath(),e.moveTo(r.x1,r.y1),e.lineTo(r.x1-n*Math.cos(t-Math.PI/6),r.y1-n*Math.sin(t-Math.PI/6)),e.lineTo(r.x1-n*Math.cos(t+Math.PI/6),r.y1-n*Math.sin(t+Math.PI/6)),e.closePath(),e.fill()}else if(r.tool===`text`&&r.text){let n=Math.max(16,Math.round(t.width/26))*r.factor;e.font=`bold ${n}px ui-sans-serif, system-ui, sans-serif`,e.textBaseline=`top`,e.lineWidth=Math.max(2,n/8),e.strokeStyle=`rgba(0,0,0,.65)`,e.strokeText(r.text,r.x0,r.y0),e.fillText(r.text,r.x0,r.y0)}}function rTe(e,t,n,r,i,a){let o=YY(e,t,n),s=Math.max(1,KY(t)*.6),c=GY(n,r),l=c?Math.max(s*3,48/r/2):s*3;if(e.save(),n.angle&&n.tool!==`arrow`&&n.tool!==`line`){let t=o.x+o.w/2,r=o.y+o.h/2;e.translate(t,r),e.rotate(n.angle),e.translate(-t,-r)}if(e.strokeStyle=`#4c9aff`,e.lineWidth=s,e.setLineDash([s*3,s*3]),e.strokeRect(o.x-l,o.y-l,o.w+l*2,o.h+l*2),e.setLineDash([]),i)e.restore(),iTe(e,t,n,r);else if(n.angle)e.restore();else{if(n.tool!==`text`&&!c){let r=KY(t)*1.8;[[0,n.x0,n.y0],[1,n.x1,n.y1]].forEach(([t,n,i])=>{e.beginPath(),e.arc(n,i,r,0,Math.PI*2),e.fillStyle=a===t?`#4c9aff`:`#fff`,e.fill(),e.stroke()})}e.restore()}}function $Y(e,t,n){return fwe(t,YY(e.getContext(`2d`),e,t),n,e.width,e.height)}function iTe(e,t,n,r){let i=18/r,a=$Y(t,n,r);e.save(),e.lineCap=`round`;for(let t of a)e.beginPath(),e.moveTo(t.ax,t.ay),e.lineTo(t.x,t.y),e.strokeStyle=`rgba(255,255,255,0.85)`,e.lineWidth=4/r,e.stroke(),e.strokeStyle=`#4c9aff`,e.lineWidth=2/r,e.stroke();for(let t of a)e.beginPath(),e.arc(t.x,t.y,i,0,Math.PI*2),e.fillStyle=gwe[t.knob],e.fill(),e.lineWidth=2/r,e.strokeStyle=`#fff`,e.stroke(),vwe(e,t.knob,t.x,t.y,i*.5,2/r);e.restore()}function aTe(e){let{canvasRef:t,wrapRef:n,imgRef:r,setTool:i,color:a,setColor:o,factor:s,setShapes:c,setMoveMode:l,setSelected:u,selectedRef:d,setTarget:f,targetRef:p,setMoveNote:m,setKnobs:h,moveRef:g,setCropMode:_,pendingCrop:v,setPendingCrop:y,cropDrag:b,pendingText:x,setPendingText:S,textDraft:C,setTextDraft:w,textInputRef:T,idRef:E,setPaletteOpen:D,setView:O,viewRef:k,fitRef:A,redraw:j,clampToImage:M}=e;async function N(){let e=r.current,i=t.current;if(!e||!i||!v)return;let{x:a,y:o,w:s,h:l}=M(v);if(s<1||l<1){y(null);return}let u=document.createElement(`canvas`);u.width=Math.round(s),u.height=Math.round(l),u.getContext(`2d`).drawImage(e,a,o,s,l,0,0,u.width,u.height);try{r.current=await createImageBitmap(u)}catch{r.current=u}i.width=u.width,i.height=u.height,c(e=>e.map(e=>({...e,x0:e.x0-a,y0:e.y0-o,x1:e.x1-a,y1:e.y1-o})).map(e=>WY(e,u.width,u.height)).filter(e=>e!=null));let d=n.current?.getBoundingClientRect();if(d){let e=Math.min(d.width/u.width,d.height/u.height),t={k:e,tx:(d.width-u.width*e)/2,ty:(d.height-u.height*e)/2};A.current=t,O(t)}y(null),_(!1),j()}function P(){b.current=null,y(null),l(!1),u(null),f(null),m(null),g.current=null,ie(),_(e=>!e)}function F(e){e!==`text`&&ie(),D(!1),e===`marker`&&a.toLowerCase()===`#ffffff`&&o(Pwe),i(e)}function I(){g.current=null,u(null),f(null),m(null),c(e=>e.slice(0,-1))}function ee(){g.current=null,f(null),m(null),l(e=>(e?u(null):(b.current=null,y(null),_(!1)),!e))}function te(){g.current=null,f(null),p.current=null,m(null),h(e=>(ao(B.annKnobs,!e),!e))}function ne(){let e=d.current;e!=null&&(g.current=null,u(null),f(null),m(null),c(t=>t.filter((t,n)=>n!==e)))}function re(){let e=x,n=C.trim();if(S(null),w(``),T.current?.blur(),!e||!n)return;let r=t.current,i={tool:`text`,x0:e.x,y0:e.y,x1:e.x,y1:e.y,color:a,factor:s,text:n,id:E.current++};c(e=>[...e,r?WY(i,r.width,r.height):i])}function ie(){S(null),w(``),T.current?.blur()}function ae(){k.current=A.current,j(),O(A.current)}return{applyCrop:N,toggleCrop:P,pickTool:F,undoShape:I,toggleMove:ee,toggleKnobs:te,deleteSelected:ne,commitText:re,cancelText:ie,resetZoom:ae}}function oTe(e){let{canvasRef:t,wrapRef:n,tool:r,color:i,factor:a,setShapes:o,shapesRef:s,dragRef:c,moveMode:l,setSelected:u,selectedRef:d,setTarget:f,targetRef:p,setMoveNote:m,knobsRef:h,moveRef:g,cropMode:_,setPendingCrop:v,cropDrag:y,setPendingText:b,setTextDraft:x,textInputRef:S,idRef:C,setView:w,viewRef:T,fitRef:E,pointers:D,gesture:O,redraw:k,clampToImage:A}=e,j=(e,n,r,i)=>$we(t.current,e,n,r,i),M=(e,t)=>$Y(e,t,T.current.k||1);function N(){let e=t.current,n=T.current.k||1;return Math.max(6,24/n,e?e.width/90:0)}function P(e){let n=t.current,r=n.getBoundingClientRect();return{x:(e.clientX-r.left)/r.width*n.width,y:(e.clientY-r.top)/r.height*n.height}}function F(e){let t=n.current.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}function I(e,t,n){let r=s.current;for(let i=r.length-1;i>=0;i--)if(j(r[i],e,t,n))return i;return null}function ee(e){if(e.preventDefault(),D.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),e.currentTarget.setPointerCapture(e.pointerId),D.current.size===2){c.current=null,g.current=null;let e=[...D.current.values()],t=Math.hypot(e[0].x-e[1].x,e[0].y-e[1].y),n={x:(e[0].x+e[1].x)/2,y:(e[0].y+e[1].y)/2},r=F({clientX:n.x,clientY:n.y}),i=T.current;O.current={startDist:t,startK:i.k,cx:(r.x-i.tx)/i.k,cy:(r.y-i.ty)/i.k},y.current=null,k();return}if(_){let{x:t,y:n}=P(e);y.current={x0:t,y0:n,x1:t,y1:n},v(null);return}if(l){m(null);let{x:n,y:r}=P(e),i=N(),a=T.current.k||1,o=s.current,c=d.current,l=c!=null&&o[c]?c:null,_=l==null?void 0:o[l],v=_?GY(_,a)||!!_.angle:!1;if(h.current){let s=t.current,c=_?pwe(M(s,_),n,r,a):null;if(c){g.current={i:l,base:_,live:_,gx:n,gy:r,handle:null,sx:e.clientX,sy:e.clientY,fromEmpty:!1,knob:c};return}let f=I(n,r,i);if(f!=null){d.current=f,u(f),g.current={i:f,base:o[f],live:o[f],gx:n,gy:r,handle:null,sx:e.clientX,sy:e.clientY,fromEmpty:!1,knob:`move`},k();return}l!=null&&(g.current={i:l,base:_,live:_,gx:n,gy:r,handle:null,sx:e.clientX,sy:e.clientY,fromEmpty:!0,idle:!0});return}let y=null;if(_&&_.tool!==`text`&&!v){let e=1/0;for(let t of[0,1]){let a=t===0?_.x0:_.x1,o=t===0?_.y0:_.y1,s=Math.hypot(n-a,r-o);s<=i*1.4&&s<e&&(e=s,y=t)}}let b=I(n,r,i),x=Jwe({sel:l,small:v,handleHit:y,pickHit:b,target:p.current});if(x.kind===`handle`){g.current={i:x.i,base:_,live:_,gx:n,gy:r,handle:x.h,sx:e.clientX,sy:e.clientY,fromEmpty:!1};return}if(x.kind===`pick`){x.i!==l&&(f(null),p.current=null),d.current=x.i,u(x.i),g.current={i:x.i,base:o[x.i],live:o[x.i],gx:n,gy:r,handle:null,sx:e.clientX,sy:e.clientY,fromEmpty:!1},k();return}if(x.kind===`relative`){g.current={i:l,base:_,live:_,gx:n,gy:r,handle:x.h,sx:e.clientX,sy:e.clientY,fromEmpty:!0};return}return}if(r===`text`)return;let{x:n,y:o}=P(e);c.current={tool:r,x0:n,y0:o,x1:n,y1:o,color:i,factor:a,id:C.current++}}function te(e){if(D.current.has(e.pointerId)&&D.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),O.current&&D.current.size>=2){let e=[...D.current.values()],t=Math.hypot(e[0].x-e[1].x,e[0].y-e[1].y),n={x:(e[0].x+e[1].x)/2,y:(e[0].y+e[1].y)/2},r=F({clientX:n.x,clientY:n.y}),i=O.current,a=E.current.k,o=Math.min(a*8,Math.max(a,i.startK*(t/i.startDist)));w({k:o,tx:r.x-i.cx*o,ty:r.y-i.cy*o});return}if(_&&y.current){let{x:t,y:n}=P(e);y.current={...y.current,x1:t,y1:n},k();return}if(l){let n=g.current;if(!n||n.idle)return;let{x:r,y:i}=P(e);if(n.knob){let e=t.current,a=YY(e.getContext(`2d`),e,n.base);n.live=mwe(n.knob,n.base,{x:n.gx,y:n.gy},{x:r,y:i},T.current.k||1,{x:a.x+a.w/2,y:a.y+a.h/2}),k();return}let a=r-n.gx,o=i-n.gy;n.live=n.handle===0?{...n.base,x0:n.base.x0+a,y0:n.base.y0+o}:n.handle===1?{...n.base,x1:n.base.x1+a,y1:n.base.y1+o}:{...n.base,x0:n.base.x0+a,y0:n.base.y0+o,x1:n.base.x1+a,y1:n.base.y1+o},k();return}if(!c.current)return;let{x:n,y:r}=P(e);c.current={...c.current,x1:n,y1:r},k()}function ne(e){if(D.current.delete(e.pointerId),D.current.size<2&&(O.current=null),!(D.current.size>0)){if(_){if(y.current){let e=A(qY(y.current));y.current=null,v(e.w>12&&e.h>12?e:null),k()}}else if(l){let n=g.current;if(g.current=null,n){if(n.fromEmpty&&Math.hypot(e.clientX-n.sx,e.clientY-n.sy)<8){d.current=null,p.current=null,u(null),f(null),k();return}if(n.idle){k();return}let r=t.current,{mark:i,refused:a}=r?Ywe(n.live,n.base,r.width,r.height):{mark:n.live,refused:!1};a?k():o(e=>e.map((e,t)=>t===n.i?{...e,x0:i.x0,y0:i.y0,x1:i.x1,y1:i.y1,angle:i.angle}:e)),m(a?`That would take it off the picture — left where it was.`:null)}else k()}else if(r===`text`){let{x:t,y:n}=P(e);b({x:t,y:n}),x(``),requestAnimationFrame(()=>S.current?.focus())}else if(c.current){let e=c.current;c.current=null;let n=t.current,r=n?WY(e,n.width,n.height):e;r&&(Math.abs(r.x1-r.x0)>6||Math.abs(r.y1-r.y0)>6)?o(e=>[...e,r]):k()}}}return{onDown:ee,onMove:te,onUp:ne}}function sTe(e){let{setShapes:t,readTextRef:n,editRead:r,setEditRead:i,readDraft:a,setReadDraft:o,readInputRef:s}=e;function c(e,n){t(t=>t.map(t=>t.id===e?{...t,...n}:t))}function l(e){i(e.id),o(e.read??``),requestAnimationFrame(()=>s.current?.focus())}function u(){let e=r,t=a.trim();i(null),o(``),s.current?.blur(),e!=null&&(t?n.current.set(e,t):n.current.delete(e),c(e,{read:t||void 0,readErr:t?void 0:`no words on this mark`,readBy:`hand`,reading:!1}))}function d(e){n.current.delete(e.id),c(e.id,{read:void 0,readErr:`words dropped`,readBy:`hand`,reading:!1})}return{patchShape:c,startEditRead:l,commitRead:u,dropRead:d}}var cTe=new Set([`marker`,`rect`,`circle`]),eX=1e4,lTe=2e3;function tX(e){let t=e=>Math.round(e);return[e.tool,t(e.x0),t(e.y0),t(e.x1),t(e.y1),Math.round((e.angle??0)*1e3)].join(`|`)}function uTe(e,t,n){let r=new Map(e.map(e=>[e.id,e])),i=[];for(let e of t.keys()){let t=r.get(e);(!n||!t||t.readBy===`hand`)&&i.push(e)}return n?{start:e.filter(e=>cTe.has(e.tool)&&e.readBy!==`hand`&&t.get(e.id)!==tX(e)),abort:i}:{start:[],abort:i}}function dTe(e,t,n,r){let i={x0:Math.min(e.x0,e.x1),y0:Math.min(e.y0,e.y1),x1:Math.max(e.x0,e.x1),y1:Math.max(e.y0,e.y1)};if(e.tool===`marker`&&i.y1-i.y0<r){let e=(i.y0+i.y1)/2;i={...i,y0:e-r/2,y1:e+r/2}}e.angle&&e.tool!==`marker`&&(i=UY(i,e.angle));let a=Math.max(4,Math.round(Math.min(i.x1-i.x0,i.y1-i.y0)*.08)),o=Math.max(0,Math.floor(i.x0-a)),s=Math.max(0,Math.floor(i.y0-a)),c=Math.min(t,Math.ceil(i.x1+a)),l=Math.min(n,Math.ceil(i.y1+a));return c-o<2||l-s<2?null:{x:o,y:s,w:c-o,h:l-s}}function fTe(e,t){return Math.min(4,lTe/Math.max(e,t,1))}function pTe(e){return(e??``).replace(/\s+/g,` `).trim()||null}function mTe(e){let{canvasRef:t,imgRef:n,setShapes:r,genRef:i,readsRef:a}=e,o=(e,t)=>r(n=>n.map(n=>n.id===e?t(n):n));function s(e){a.current.get(e)?.ctl?.abort(),a.current.delete(e)}function c(){for(let e of[...a.current.keys()])s(e)}function l(e,t){let{start:n,abort:r}=uTe(e,new Map([...a.current].map(([e,t])=>[e,t.key])),!!t);for(let e of r){let t=!!a.current.get(e)?.ctl;s(e),t&&o(e,e=>e.reading?{...e,reading:!1}:e)}if(t)for(let r of n)u(r,e,t)}async function u(e,t,n){s(e.id);let r=new AbortController,c={key:tX(e),ctl:r};a.current.set(e.id,c);let l=i.current;o(e.id,e=>({...e,reading:!0,readErr:void 0,...e.readBy===`phone`?{read:void 0,readBy:void 0}:{}}));let u=setTimeout(()=>r.abort(),eX),f=null,p=`no words found in this mark`;try{let i=await d(e,t);i?f=pTe(await hTe(n.read(i,{signal:r.signal}),r.signal)):p=`this mark is too small to read`}catch{p=r.signal.aborted?`not read within ${eX/1e3} s`:`this phone could not read it`}finally{clearTimeout(u)}a.current.get(e.id)===c&&i.current===l&&(c.ctl=void 0,o(e.id,e=>e.readBy===`hand`?{...e,reading:!1}:f?{...e,reading:!1,read:f,readBy:`phone`,readErr:void 0}:{...e,reading:!1,read:void 0,readBy:void 0,readErr:p}))}async function d(e,r){let i=t.current,a=n.current;if(!i||!a)return null;let o=r.find(t=>t.id===e.id),s=dTe(e,i.width,i.height,KY(i)*5*(o?.factor??1));if(!s)return null;let c=a,l=r.filter(e=>e.tool===`blur`);if(l.length){let e=document.createElement(`canvas`);e.width=i.width,e.height=i.height;let t=e.getContext(`2d`);if(!t)return null;t.drawImage(a,0,0);for(let n of l)ZY(t,e,a,n);c=e}let u=fTe(s.w,s.h),d=document.createElement(`canvas`);d.width=Math.max(1,Math.round(s.w*u)),d.height=Math.max(1,Math.round(s.h*u));let f=d.getContext(`2d`);return f?(f.imageSmoothingEnabled=!0,f.imageSmoothingQuality=`high`,f.drawImage(c,s.x,s.y,s.w,s.h,0,0,d.width,d.height),gH(d,`image/png`)):null}return{sync:l,abortAll:c}}function hTe(e,t){return t.aborted?Promise.reject(Error(`aborted`)):new Promise((n,r)=>{let i=()=>r(Error(`aborted`));t.addEventListener(`abort`,i,{once:!0}),e.then(e=>{t.removeEventListener(`abort`,i),n(e)},e=>{t.removeEventListener(`abort`,i),r(e)})})}function gTe(e){let{source:t,repoId:n,facts:r,onUploaded:i,onDispatch:a,onPark:o,onSendAll:s,canvasRef:c,shapes:l,shapesRef:u,busy:d,setBusy:f,setErr:p,readTextRef:m,redraw:h}=e;function g(){let e=c.current;h(!0);let n=l.length>0,r=gH(e,`image/png`).then(e=>{if(!e)throw Error(`this device could not encode the marked-up image`);return e}),i=Fwe(t).replace(/\.[^.]+$/,``).replace(/[/\\]/g,`_`)||`image`;return{blob:r,name:n?`${i}-marked.png`:`${i}.png`,note:_(e.width,e.height),size:{w:e.width,h:e.height}}}function _(e,t){return Gwe(u.current.map(e=>({...e})).map(e=>({...e,read:m.current.get(e.id)??e.read})),e,t,r)||void 0}async function v(){let e=g();return{...e,blob:await e.blob}}async function y(e=`none`){if(c.current&&!d){if(q(e===`queue`?`action:image.queue`:`action:image.send`),p(null),a)f(!0),a(g(),e);else{f(!0);try{let{blob:e,name:t,note:r,size:a}=await v(),s=async()=>{let e=await Promise.resolve(r);return e?BY(e,a??null):void 0};if(o){let n=await o(e,t);if(n){i(n,await s());return}}try{let r=await U.uploadInbox(n,e,t);r.saved?.[0]&&_j(n,r.saved[0].relPath,r.saved[0].mtime),r.saved?.[0]?i(r.saved[0].relPath,await s()):p(r.skipped?.[0]?.error||`upload failed`)}catch(n){let r=o?await o(e,t):null;r?i(r,await s()):p(String(n))}}catch(e){p(String(e))}finally{f(!1)}}}}function b(e){c.current&&s&&!d&&(q(e===`queue`?`action:image.queue`:`action:image.send`),f(!0),p(null),s(g(),e))}return{send:y,sendAll:b}}function _Te(e){let{canvasRef:t,genRef:n,redraw:r,setOcr:i,setOcrDraft:a,onText:o}=e;async function s(){let e=t.current;if(!e)return;q(`action:image.ocr`);let o=n.current;i({phase:`reading`}),r(!0);let s=await gH(e,`image/jpeg`,.92);if(o!==n.current)return;if(!s){i({phase:`error`,error:`this device could not encode the picture`});return}let c=await U.ocrImage(s);o===n.current&&(`error`in c?i({phase:`error`,error:c.error}):(a(c.text),i({phase:`ready`,engine:c.engine,ms:c.ms})))}function c(){i(null)}function l(e){let t=e.trim();t&&o&&(q(`action:image.ocr.send`),o(t))}return{readAll:s,closeOcr:c,sendText:l}}function vTe(e){let t=(0,H.useRef)(null),[n,r]=(0,H.useState)(null);return(0,H.useEffect)(()=>{let n=t.current,i=e.current;if(!n||!i||typeof ResizeObserver>`u`)return;let a=new ResizeObserver(()=>{let e=n.getBoundingClientRect();r(jwe({w:e.width,h:e.height},i.width?{w:i.width,h:i.height}:null))});return a.observe(n),a.observe(i),()=>a.disconnect()},[e]),{bodyRef:t,side:n}}function yTe({source:e,repoId:t,index:n,total:r,facts:i,onUploaded:a,onDispatch:o,onPark:s,onSkip:c,onSendAll:l,onText:u,onClose:d}){let f=(0,H.useRef)(null),p=(0,H.useRef)(null),m=(0,H.useRef)(null),[h,g]=(0,H.useState)(`circle`),[_,v]=(0,H.useState)(NY[0]),[y,b]=(0,H.useState)(1),[x,S]=(0,H.useState)([]),C=(0,H.useRef)(x);C.current=x;let w=(0,H.useRef)(null),[T,E]=(0,H.useState)(!1),[D,O]=(0,H.useState)(null),k=(0,H.useRef)(D);k.current=D;let[A,j]=(0,H.useState)(null),M=(0,H.useRef)(A);M.current=A;let[N,P]=(0,H.useState)(null),[F,I]=(0,H.useState)(()=>io(B.annKnobs)),[ee,te]=(0,H.useState)(()=>io(B.annHintHidden)),ne=()=>{ao(B.annHintHidden,!0),te(!0)},re=(0,H.useRef)(F);re.current=F;let ie=(0,H.useRef)(null),[ae,oe]=(0,H.useState)(!1),[se,ce]=(0,H.useState)(null),[le,ue]=(0,H.useState)(!1),[de,fe]=(0,H.useState)(null),pe=(0,H.useRef)(null),[me,he]=(0,H.useState)(null),[ge,_e]=(0,H.useState)(``),ve=(0,H.useRef)(null),ye=(0,H.useRef)(1),be=(0,H.useRef)(new Map),xe=(0,H.useRef)(0),[Se,Ce]=(0,H.useState)(null),[we,Te]=(0,H.useState)(``),Ee=(0,H.useRef)(null),De=Ty(),Oe=(0,H.useRef)(new Map),[ke,Ae]=(0,H.useState)(!1),[je,Me]=(0,H.useState)(null),[Ne,Pe]=(0,H.useState)(``),[Fe,Ie]=(0,H.useState)(()=>Dwe(oo(B.annTools,null))),Le=e=>{Ie(e),$a(B.annTools,e)},[Re,ze]=(0,H.useState)(!1),{bodyRef:Be,side:Ve}=vTe(f),He=Fe.place===`auto`?Ve??`auto`:Fe.place,[Ue,We]=(0,H.useState)({k:1,tx:0,ty:0}),Ge=(0,H.useRef)(Ue);Ge.current=Ue;let Ke=(0,H.useRef)({k:1,tx:0,ty:0}),qe=(0,H.useRef)(new Map),Je=(0,H.useRef)(null);(0,H.useEffect)(()=>{let t=null,n=!1;S([]),Me(null),Pe(``),xe.current++,Ce(null),O(null),j(null),P(null),ie.current=null,ce(null),oe(!1);let r=(e,t)=>{let n=f.current;n.width=e,n.height=t;let r=p.current?.getBoundingClientRect();if(r){let n=Math.min(r.width/e,r.height/t),i={k:n,tx:(r.width-e*n)/2,ty:(r.height-t*n)/2};Ke.current=i,We(i)}Ye()},i=async e=>{try{let t=await createImageBitmap(e);return n?void 0:(m.current=t,r(t.width,t.height),!0)}catch{return!1}};return(async()=>{if(e instanceof File){if(await i(e))return;let a=new Image;t=URL.createObjectURL(e),a.onload=()=>{n||(m.current=a,r(a.naturalWidth,a.naturalHeight))},a.onerror=()=>!n&&ce(`Can't decode this image format on this device.`),a.src=t}else try{let t=await fetch(e.url).then(e=>e.blob());await i(t)||ce(`Can't load this image.`)}catch{ce(`Can't load this image.`)}})(),()=>{n=!0,t&&URL.revokeObjectURL(t)}},[e]),(0,H.useEffect)(()=>{document.activeElement?.blur()},[]),(0,H.useEffect)(()=>{let e=p.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{let t=f.current,n=e.getBoundingClientRect();if(!t||!t.width||!t.height||n.width<1||n.height<1)return;let r=Math.min(n.width/t.width,n.height/t.height),i={k:r,tx:(n.width-t.width*r)/2,ty:(n.height-t.height*r)/2},a=Math.abs(Ge.current.k-Ke.current.k)<=Ke.current.k*.02;Ke.current=i,a&&(Ge.current=i,Ye(),We(i))});return t.observe(e),()=>t.disconnect()},[]),(0,H.useEffect)(Ye,[x,le,de,D,T,A,F]),(0,H.useEffect)(()=>{!x.length&&T&&(E(!1),O(null),j(null))},[x.length,T]);function Ye(e=!1){let t=f.current,n=m.current;if(!t||!n)return;let r=t.getContext(`2d`);r.drawImage(n,0,0);let i=ie.current,a=i?C.current.map((e,t)=>t===i.i?i.live:e):C.current,o=w.current?[...a,w.current]:a;for(let e of o)ZY(r,t,n,e);nTe(r,t,zY(a,t.width,t.height)),le&&eTe(r,t,pe.current?qY(pe.current):de);let s=k.current;!e&&!le&&s!=null&&a[s]&&rTe(r,t,a[s],Ge.current.k||1,re.current,M.current)}function Xe(e){return JY(f.current,e)}let Ze={source:e,repoId:t,facts:i,onUploaded:a,onDispatch:o,onPark:s,onSendAll:l,canvasRef:f,wrapRef:p,imgRef:m,tool:h,setTool:g,color:_,setColor:v,factor:y,shapes:x,setShapes:S,shapesRef:C,dragRef:w,moveMode:T,setMoveMode:E,selected:D,setSelected:O,selectedRef:k,target:A,setTarget:j,targetRef:M,setMoveNote:P,setKnobs:I,knobsRef:re,moveRef:ie,busy:ae,setBusy:oe,setErr:ce,cropMode:le,setCropMode:ue,pendingCrop:de,setPendingCrop:fe,cropDrag:pe,pendingText:me,setPendingText:he,textDraft:ge,setTextDraft:_e,textInputRef:ve,idRef:ye,readTextRef:be,genRef:xe,editRead:Se,setEditRead:Ce,readDraft:we,setReadDraft:Te,readInputRef:Ee,setPaletteOpen:Ae,setView:We,viewRef:Ge,fitRef:Ke,pointers:qe,gesture:Je,redraw:Ye,clampToImage:Xe},Qe=aTe(Ze),$e=sTe(Ze),et=oTe(Ze),{send:tt,sendAll:nt}=gTe(Ze),rt=_Te({canvasRef:f,genRef:xe,redraw:Ye,setOcr:Me,setOcrDraft:Pe,onText:u}),it=mTe({canvasRef:f,imgRef:m,setShapes:S,genRef:xe,readsRef:Oe});(0,H.useEffect)(()=>it.sync(x,De),[x,De]),(0,H.useEffect)(()=>()=>it.abortAll(),[]);let at=Ue.k>Ke.current.k*1.02,ot=[...x].reverse().find(e=>e.tool===`marker`||!!De&&(e.tool===`rect`||e.tool===`circle`));return{props:{index:n,total:r,onSkip:c,onSendAll:l,onDispatch:o,onText:u,onClose:d},canvasRef:f,wrapRef:p,tool:h,color:_,setColor:v,factor:y,setFactor:b,shapes:x,setShapes:S,moveMode:T,selected:D,setSelected:O,target:A,setTarget:j,moveNote:N,setMoveNote:P,knobs:F,busy:ae,err:se,cropMode:le,pendingCrop:de,pendingText:me,textDraft:ge,setTextDraft:_e,textInputRef:ve,editRead:Se,setEditRead:Ce,readDraft:we,setReadDraft:Te,readInputRef:Ee,paletteOpen:ke,setPaletteOpen:Ae,view:Ue,fitRef:Ke,layout:Fe,setLayout:Le,configOpen:Re,setConfigOpen:ze,bodyRef:Be,place:He,moveRef:ie,zoomed:at,lastBand:ot,hintHidden:ee,hideHint:ne,...Qe,...$e,...et,send:tt,sendAll:nt,ocr:je,ocrDraft:Ne,setOcrDraft:Pe,...rt}}function bTe(e){let t=yTe(e);Ih(t.ocr!==null,t.closeOcr);let{index:n,total:r,onClose:i}=e;return(0,J.jsxs)(`div`,{className:`sheet`,children:[(0,J.jsx)(gE,{onClose:i,title:r&&r>1?`Mark & send · ${n??1}/${r}`:`Mark & send image`,children:(0,J.jsx)(Cwe,{m:t})}),e.prompt&&(0,J.jsx)(wwe,{prompt:e.prompt}),(0,J.jsx)(Rwe,{m:t}),t.ocr?(0,J.jsx)(zwe,{m:t}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(ywe,{m:t}),(0,J.jsx)(Twe,{m:t})]})]})}var nX=6,rX=0;function xTe(){if(rX)return rX;rX=4096;try{let e=document.createElement(`canvas`).getContext(`webgl`),t=e?.getParameter(e.MAX_TEXTURE_SIZE);typeof t==`number`&&t>0&&(rX=t)}catch{}return rX}function STe(e,t){let n=Math.max(e,t)*(window.devicePixelRatio||1);return n?tm(xTe()/n,2,nX):nX}function iX({src:e,alt:t,onNav:n,onError:r}){let i=(0,H.useRef)(null),a=(0,H.useRef)(null),[o,s]=(0,H.useState)({s:1,x:0,y:0}),[c,l]=(0,H.useState)(!1),u=(0,H.useRef)(o);u.current=o;let d=(0,H.useRef)(new Map),f=(0,H.useRef)(null),p=(0,H.useRef)(null),m=(0,H.useRef)(0),[h,g]=(0,H.useState)(null);(0,H.useEffect)(()=>{s({s:1,x:0,y:0})},[e]);function _(e,t=!1){let n=a.current,r=i.current,o=Number.isFinite(e.s)?tm(e.s,1,nX):1;n&&n.offsetWidth&&(o=Math.min(o,STe(n.offsetWidth,n.offsetHeight)));let s=Number.isFinite(e.x)?e.x:0,c=Number.isFinite(e.y)?e.y:0;if(n&&r){let e=Math.max(0,(n.offsetWidth*o-r.clientWidth)/2),i=Math.max(0,(n.offsetHeight*o-r.clientHeight)/2);t||(s=tm(s,-e,e)),c=tm(c,-i,i)}return{s:o,x:s,y:c}}let v=()=>{let e=[...d.current.values()];return e.length>=2?e:null};function y(){let e=v();if(!e)return;let t=Math.hypot(e[0].x-e[1].x,e[0].y-e[1].y),n=i.current?.getBoundingClientRect(),r=n?n.left+n.width/2:0,a=n?n.top+n.height/2:0;f.current={dist:t||1,mx:(e[0].x+e[1].x)/2-r,my:(e[0].y+e[1].y)/2-a,s:u.current.s,x:u.current.x,y:u.current.y},p.current=null}function b(e){if(e.target.setPointerCapture?.(e.pointerId),d.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),l(!0),d.current.size>=2)y();else{let t=e.timeStamp;t-m.current<300?(s(e=>_(e.s>1?{s:1,x:0,y:0}:{s:2.5,x:0,y:0})),m.current=0):m.current=t,p.current={x:e.clientX,y:e.clientY,tx:u.current.x,ty:u.current.y}}}function x(e){let t=d.current.get(e.pointerId);if(!t)return;t.x=e.clientX,t.y=e.clientY;let r=v();if(r&&f.current){e.stopPropagation();let t=f.current,n=Math.hypot(r[0].x-r[1].x,r[0].y-r[1].y),a=i.current?.getBoundingClientRect(),o=(r[0].x+r[1].x)/2-(a?a.left+a.width/2:0),c=(r[0].y+r[1].y)/2-(a?a.top+a.height/2:0),l=tm(t.s*n/t.dist,1,nX);s(_({s:l,x:o-(t.mx-t.x)*(l/t.s),y:c-(t.my-t.y)*(l/t.s)}))}else if(p.current&&u.current.s>1){e.stopPropagation();let t=p.current;s(n=>_({s:n.s,x:t.tx+(e.clientX-t.x),y:t.ty+(e.clientY-t.y)}))}else if(p.current&&n){let t=p.current;s(n=>({...n,x:t.tx+(e.clientX-t.x)}))}}function S(e){if(d.current.delete(e.pointerId),d.current.size<2&&(f.current=null),d.current.size===1){let[e]=[...d.current.values()];p.current={x:e.x,y:e.y,tx:u.current.x,ty:u.current.y}}if(d.current.size===0){if(l(!1),p.current&&u.current.s<=1&&n&&e.type!==`pointercancel`){let t=e.clientX-p.current.x,r=e.clientY-p.current.y;Math.abs(t)>60&&Math.abs(t)>Math.abs(r)*1.5&&n(t<0?1:-1)}s(e=>e.s<=1?{s:1,x:0,y:0}:_(e)),p.current=null}}let C=o.s>1.01;return(0,J.jsxs)(`div`,{ref:i,className:`zoom-stage`,onPointerDown:b,onPointerMove:x,onPointerUp:S,onPointerCancel:S,children:[h===e?(0,J.jsxs)(`div`,{className:`img-missing`,children:[(0,J.jsx)(_s,{size:22}),(0,J.jsx)(`span`,{className:`img-missing-name`,children:t}),(0,J.jsx)(`span`,{children:`couldn’t load this image — the host may be unreachable`})]}):(0,J.jsx)(`img`,{ref:a,src:e,alt:t,draggable:!1,onLoad:()=>s(e=>_(e)),onError:()=>{g(e),r?.()},style:{transform:`translate(${o.x}px, ${o.y}px) scale(${o.s})`,willChange:c?`transform`:`auto`}}),C&&(0,J.jsxs)(`button`,{className:`zoom-reset`,"aria-label":`reset zoom`,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),s({s:1,x:0,y:0})},children:[(0,J.jsx)(yc,{size:16}),` `,o.s.toFixed(1),`×`]})]})}function CTe({items:e,index:t,onIndex:n,onAnnotate:r,onReference:i,onClose:a}){let o=e[t],[s,c]=(0,H.useState)(!1);(0,H.useEffect)(()=>{c(!1)},[t]);let l=r=>{let i=t+r;i>=0&&i<e.length&&n(i)};return(0,H.useEffect)(()=>{let e=e=>{e.key===`ArrowRight`?l(1):e.key===`ArrowLeft`?l(-1):e.key===`Escape`&&(e.preventDefault(),a())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}),(0,H.useEffect)(()=>{o||a()},[o,a]),o?(0,J.jsxs)(`div`,{className:`viewer`,onClick:a,children:[(0,J.jsx)(`button`,{className:`viewer-close`,onClick:a,"aria-label":`close`,children:(0,J.jsx)(V,{size:22})}),(0,J.jsxs)(`div`,{className:`viewer-body`,onClick:e=>e.stopPropagation(),children:[o.video?(0,J.jsx)(`video`,{className:`viewer-video`,src:o.url,controls:!0,autoPlay:!0,playsInline:!0},o.relPath):(0,J.jsx)(iX,{src:s&&o.fullUrl?o.fullUrl:o.url,alt:o.name,onNav:e.length>1?l:void 0},`${o.relPath}:${s?`full`:`fit`}`),(0,J.jsx)(`div`,{className:`viewer-path mono`,children:o.relPath}),(0,J.jsxs)(`div`,{className:`sheet-actions`,children:[e.length>1&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Y,{onClick:()=>l(-1),disabled:t===0,"aria-label":`previous`,children:(0,J.jsx)(Hl,{size:16})}),(0,J.jsxs)(`span`,{className:`viewer-count`,children:[t+1,` / `,e.length]}),(0,J.jsx)(Y,{onClick:()=>l(1),disabled:t===e.length-1,"aria-label":`next`,children:(0,J.jsx)(jl,{size:16})})]}),!o.video&&o.fullUrl&&o.fullUrl!==o.url&&!s&&(0,J.jsx)(Y,{title:`load the original file instead of the screen-sized copy`,onClick:()=>c(!0),children:`full res`}),!o.video&&r&&(0,J.jsxs)(Y,{onClick:()=>r(o),children:[(0,J.jsx)(us,{size:16}),` mark`]}),o.repoId&&(0,J.jsx)(FO,{target:{repoId:o.repoId,relPath:o.relPath,name:o.name},trackId:`action:swipe.download`}),(0,J.jsx)(`button`,{className:`send`,onClick:()=>i(o),children:`ref path`})]})]})]}):null}function wTe(){let e=K(gJ);return e?(0,J.jsx)(uwe,{files:e.files,onCombine:DCe,onSeparate:OCe,onClose:kCe}):null}function aX(){let e=K(mJ);return EY()&&!!e&&wJ.ret===`session`&&!!W().world.active}function TTe(){let e=K(mJ),t=aX();if(!e)return null;let n=wJ.ret===`session`,r=!!e.total&&e.total>1,i=W(),a=n&&!t&&i.world.active?{value:i.compose.draft,onChange:e=>{W().compose.typeOn(W().compose.draft,e)||W().say.toast(`The message box changed meanwhile — that key was not applied`)}}:void 0;return(0,J.jsx)(bTe,{prompt:a,source:e.source,repoId:e.repoId,index:e.index,total:e.total,facts:e.facts,onUploaded:ICe,onDispatch:n?NCe:void 0,onPark:MCe,onSkip:r?PCe:void 0,onSendAll:r&&n?FCe:void 0,onText:LCe,onClose:lY})}function ETe(){let e=K(_J),t=K(SJ);if(!e)return null;let n=e.sessionId?jJ(t.get(e.sessionId)??[]):[],r=e.items??n.map(e=>({name:e.name,relPath:e.relPath,url:OJ(e.relPath)?U.artifactUrl(e.repoId,e.relPath):sg(U.artifactUrl(e.repoId,e.relPath),og(),e.mtime),fullUrl:U.artifactUrl(e.repoId,e.relPath),video:OJ(e.relPath)}));return(0,J.jsx)(CTe,{items:r,index:Math.min(e.i,Math.max(0,r.length-1)),onIndex:e=>zJ(t=>t&&{...t,i:e}),onAnnotate:e.revoke?void 0:e=>qCe(e,n),onReference:e=>JCe(e,n),onClose:HJ})}var oX=[{label:`10m`,long:`10 minutes`,secs:600},{label:`4h`,long:`4 hours`,secs:14400},{label:`24h`,long:`24 hours`,secs:86400}];function sX(e){return e===`outbox`?14400:void 0}var DTe=[{label:`images`,value:`image`},{label:`docs`,value:`doc`}],cX=4e5,OTe={new:`new — not opened on this device yet`,opened:`opened in ${L.name} on this device`,downloaded:`downloaded to this phone`};function lX(e){if(!e)return``;let t=Date.now()-e,n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function uX(e){return e?new Date(e).toLocaleString():``}var dX=(e,t)=>t.repoId??e,fX=(e,t,n)=>e===`inbox`?U.inboxUrl(dX(t,n),n.name):U.artifactUrl(dX(t,n),n.relPath),pX=(e,t,n)=>sg(fX(e,t,n),ag(140),n.mtime),kTe=(e,t,n,r)=>n?fX(e,t,r):sg(fX(e,t,r),og(),r.mtime),ATe=e=>nO(e.relPath)&&(e.size??0)>=49152;function jTe({openFile:e,onClose:t}){let[n,r]=(0,H.useState)(e?{...e,size:e.size??0,mtime:e.mtime??0,ctime:e.mtime??0}:null),i=(0,H.useRef)(!!e),a=e=>{i.current=!1,r(e)};return Ih(n!==null&&!i.current,()=>a(null)),{open:n,showFile:a,closeDoc:()=>{i.current?(i.current=!1,t()):a(null)}}}function MTe({repoId:e,repos:t,initialScope:n,initialAllTime:r,initialNew:i}){let a=!!e,o=n??(a?`outbox`:`all`),[s,c]=(0,H.useState)(o),l=i?Math.max(1,Math.ceil((Date.now()-i.since)/1e3)):void 0,[u,d]=(0,H.useState)(l??(r?void 0:sX(o))),[f,p]=(0,H.useState)(!!l),m=e=>{c(e),d(sX(e)),P(60),p(!1)},[h,g]=(0,H.useState)(`all`),[_,v]=(0,H.useState)(``),[y,b]=(0,H.useState)([]),[x,S]=(0,H.useState)(!1),[C,w]=(0,H.useState)(!0),[T,E]=(0,H.useState)(null),[D,O]=(0,H.useState)(null),[k,A]=(0,H.useState)(null),[j,M]=(0,H.useState)(0),[N,P]=(0,H.useState)(60),F=(t??[]).map(e=>e.id).join(`,`),I={kind:h,since:s===`inbox`?void 0:u},ee=lte(s,e,F);return(0,H.useEffect)(()=>{let t=!1,n=new AbortController,r=!1;w(!0),E(null),A(null);let i=(n,i,a)=>{if(!t&&(r=!0,b(n),S(i),w(!1),E(null),O(null),vj(n,e),!_.trim())){let e=a??{rows:n,cov:I,truncated:i};SC(ee,e.cov,e.rows,e.truncated)}},a=async n=>{let i=await CC(ee,I);if(t||r)return!1;if(!i)return n&&w(!1),!1;let a=Yi(i.rows,{...I,query:_},iO,Date.now());return vj(a,e),b(a.slice(0,N)),S(a.length>N||i.exact&&i.truncated),O(i.savedAt),n&&w(!1),!0};a(!1);let o=e=>{t||a(!0).then(n=>{if(t)return;w(!1);let r=Ba(e)?`the host didn't answer`:String(e?.message||e||`request failed`);A(n?r:null),E(n?null:r)})};return s===`all`?U.search({query:_,kind:h,scope:`repo`,sinceSeconds:u,repoIds:F?F.split(`,`):void 0,limit:N,signal:n.signal}).then(e=>i(e.hits,e.truncated)).catch(o):s===`inbox`?(U.markInboxSeen(e),U.inbox(e,n.signal).then(e=>{let t=Yi(e,{kind:h,query:_},iO,Date.now());i(t.slice(0,N),t.length>N,{rows:e,cov:{kind:`all`},truncated:!1})}).catch(o)):(s===`outbox`&&U.markOutboxSeen(e),U.artifacts(e,s,u,{query:_,kind:h,limit:N,signal:n.signal}).then(e=>i(e.files,e.truncated)).catch(o)),()=>{t=!0,n.abort()}},[e,F,s,u,h,_,j,N]),(0,H.useEffect)(()=>{D!=null||T||_ge(y.filter(e=>nO(e.relPath)||rO(e.relPath)).slice(0,24).map(t=>pX(s,e,t)))},[y,D,T]),(0,H.useEffect)(()=>{P(60)},[u,h,_,e]),{singleRepo:a,scope:s,changeScope:m,since:u,setSince:d,newSecs:l,onNewCut:f,setOnNewCut:p,kind:h,setKind:g,query:_,setQuery:v,files:y,truncated:x,loading:C,loadErr:T,cachedAt:D,staleWhy:k,setReload:M,setLimit:P}}function NTe({open:e,scope:t,repoId:n}){let[r,i]=(0,H.useState)(!1),[a,o]=(0,H.useState)(null),[s,c]=(0,H.useState)(null),[l,u]=(0,H.useState)(null),[d,f]=(0,H.useState)(!1),[p,m]=(0,H.useState)(0);return(0,H.useEffect)(()=>{i(!1)},[e?.relPath,e?.repoId]),(0,H.useEffect)(()=>{e&&t!==`inbox`&&(Qde(dX(n,e),e.relPath,e.mtime),m(e=>e+1))},[e?.relPath,e?.repoId,t]),(0,H.useEffect)(()=>{if(c(null),f(!1),u(null),!e||!uO(e.relPath)){o(null);return}let r=new AbortController,i=!1,a=e.relPath,s=dX(n,e),l=e.mtime,d=l>0,p=async()=>{let e=d?await FC(s,a,l):null;return r.signal.aborted||i||!e?!1:(o({path:a,text:e.text,truncated:e.truncated}),u(e.savedAt),!0)};return p(),fp(fX(t,n,e),{signal:r.signal}).then(e=>e.ok?e.text():Promise.reject(Error(`HTTP ${e.status}`))).then(e=>{if(r.signal.aborted)return;i=!0;let t={path:a,text:e.slice(0,cX),truncated:e.length>cX};o(t),u(null),d&&PC(s,a,l,t.text,t.truncated)}).catch(e=>{r.signal.aborted||p().then(t=>{r.signal.aborted||t||(o(null),c(Ba(e)?`the host didn't answer, and this device has no saved copy`:String(e?.message||e)))})}),()=>r.abort()},[e?.relPath,e?.repoId,t]),{fullRes:r,setFullRes:i,doc:a,docErr:s,docCachedAt:l,docRaw:d,setDocRaw:f,markTick:p,setMarkTick:m}}function PTe(e,t,n){let r=n(t);return e.some(e=>n(e)===r)?e.filter(e=>n(e)!==r):[...e,t]}function FTe(e){return e===0?`Tap the pictures to combine, in the order you want them numbered.`:e===1?`1 picked — tap one more: a combined picture needs at least two.`:`${e} picked, numbered in the order you tapped them.`}function ITe(e){let[t,n]=(0,H.useState)(null),r=t=>`${e.repoOf(t)}:${t.relPath}`;return{picked:t,pickIndex:e=>t?t.findIndex(t=>r(t)===r(e)):-1,canPick:!!e.onCombine&&e.singleRepo&&e.files.filter(e=>nO(e.relPath)).length>=2,startPick:()=>{q(`action:gallery.pick`),n([])},cancelPick:()=>n(null),togglePicked:e=>{nO(e.relPath)&&n(t=>PTe(t??[],e,r))},combinePicked:()=>{if(!t||t.length<2||!e.onCombine)return;q(`action:gallery.combine`);let r=t.map(t=>({url:e.urlFor(t),name:t.name,repoId:e.repoOf(t)}));n(null),e.onCombine(r)}}}function LTe(e){let{repoId:t,openFile:n,onClose:r}=e,{open:i,showFile:a,closeDoc:o}=jTe({openFile:n,onClose:r}),[s,c]=(0,H.useState)(null),[l,u]=(0,H.useState)(null),d=e=>{u(e),window.setTimeout(()=>u(t=>t===e?null:t),4e3)},[f,p]=(0,H.useState)(new Set),m=e=>p(t=>t.has(e)?t:new Set(t).add(e)),[h,g]=(0,H.useState)([]);(0,H.useEffect)(()=>gS.subscribe(g),[]);let _=MTe(e),{scope:v,files:y,loading:b,setReload:x}=_,S=NTe({open:i,scope:v,repoId:t}),{fullRes:C,docRaw:w,markTick:T}=S,E=e=>e&&b?(0,J.jsxs)(J.Fragment,{children:[` `,(0,J.jsx)(Ul,{size:12,className:`spin`})]}):null,D=e=>dX(t,e),O=e=>fX(v,t,e),k=e=>pX(v,t,e),A=e=>kTe(v,t,C,e),j=e=>v===`inbox`||e.relPath.startsWith(`.claude/inbox/`),M=e=>{if(v===`inbox`)return null;let t=OO(D(e),e.relPath,e.mtime);return t===`new`&&v!==`outbox`?null:t},N=e=>{let t=D(e);return h.find(n=>n.item.repoId===t&&n.item.relPath===e.relPath&&Math.round(n.item.mtime)===Math.round(e.mtime))},P=e=>({repoId:D(e),relPath:e.relPath,name:e.name,size:e.size,mtime:e.mtime,repoName:e.repoName}),F=e=>{let t=ix(e);return t.phase===`have`||t.phase===`saved`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(go,{size:11}),` on phone`]}):t.phase===`downloading`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Ul,{size:11,className:`spin`}),` `,t.pct,`%`]}):t.phase===`failed`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Js,{size:11}),` stopped`]}):t.phase===`idle`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(rs,{size:11}),` was here`]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Rs,{size:11}),` queued`]})},I=i?N(i):void 0,ee=I?.state===`done`?I.item.id:null,[te,ne]=(0,H.useState)(null);(0,H.useEffect)(()=>{if(ne(null),!ee)return;let e=null,t=!1;return gS.objectUrl(ee).then(n=>{n&&(t?URL.revokeObjectURL(n):(e=n,ne(n)))}),()=>{t=!0,e&&URL.revokeObjectURL(e)}},[ee]);let re=e=>te??A(e),ie=e=>te??O(e),ae=!!i&&sO(i.relPath)&&!w,oe=y.filter(e=>nO(e.relPath)),se=i?oe.findIndex(e=>e.relPath===i.relPath&&e.repoId===i.repoId):-1;function ce(e){let t=se>=0?oe[se+e]:void 0;t&&a(t)}(0,H.useEffect)(()=>{if(!i)return;let e=e=>{e.key===`ArrowRight`?ce(1):e.key===`ArrowLeft`?ce(-1):e.key===`Escape`&&(e.preventDefault(),o())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)});async function le(e){try{return await U.deleteInbox(D(e),e.name),x(e=>e+1),!0}catch(t){return d(Ba(t)?`Could not delete ${e.name} — the host didn't answer. The file is still on the desktop.`:`Could not delete ${e.name} — ${String(t?.message||t)}`),!1}}async function ue(e){q(`action:gallery.delete`),await le(e)&&a(null)}let de=ITe({onCombine:e.onCombine,singleRepo:_.singleRepo,files:y,repoOf:D,urlFor:O});async function fe(e){let t=await gp(e);c(t?e:null),setTimeout(()=>c(null),1500)}return{props:e,..._,...S,open:i,showFile:a,closeDoc:o,copied:s,note:l,badSrc:f,markBad:m,busyMark:E,repoOf:D,urlFor:O,thumbFor:k,canFullRes:ATe,isInboxFile:j,markOf:M,pullOf:N,dlTarget:P,pullBadge:F,localUrl:te,mediaSrc:re,fileSrc:ie,htmlLive:ae,imgs:oe,openIdx:se,nav:ce,removeInbox:le,del:ue,copy:fe,...de}}function RTe(e,t,n,r){let i=`${e} new since you last looked`;return n||t===e?i:r?`${i} · newest ${t} shown`:`${i} · ${t} still here`}function zTe(e){let t=oX.find(t=>t.secs===e);return t?`Nothing from the last ${t.long}.`:null}function BTe({m:e}){let{scope:t,loading:n,singleRepo:r,changeScope:i,kind:a,setKind:o,since:s,setSince:c,newSecs:l,onNewCut:u,setOnNewCut:d}=e,{initialNew:f}=e.props,p=(e,r)=>(0,J.jsxs)(`button`,{className:`seg${t===e?` on`:``}${t===e&&n?` busy`:``}`,"aria-pressed":t===e,onClick:()=>i(e),children:[r,t===e&&n?(0,J.jsx)(Ul,{size:13,className:`spin`}):null]}),m=(e,t,r,i)=>(0,J.jsx)(pE,{on:e,busy:e&&n,title:i,onClick:r,children:t}),h=()=>{c(void 0),d(!1)};return(0,J.jsxs)(J.Fragment,{children:[r&&(0,J.jsxs)(`div`,{className:`segmented gallery-scope`,children:[p(`inbox`,`inbox`),p(`outbox`,`outbox`),p(`repo`,`this repo`),p(`all`,`all repos`)]}),(0,J.jsxs)(`div`,{className:`fchips gallery-filters`,children:[DTe.map(e=>(0,J.jsx)(H.Fragment,{children:m(a===e.value,e.label,()=>o(a===e.value?`all`:e.value))},e.value)),t!==`inbox`&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`fchips-gap`,"aria-hidden":!0}),l!==void 0&&m(u,`${f.count} new`,()=>{u?h():(c(l),d(!0))},`the ${f.count} file${f.count>1?`s`:``} added since you last opened this outbox — the badge you tapped`),oX.map(e=>(0,J.jsx)(H.Fragment,{children:m(!u&&s===e.secs,e.label,()=>{!u&&s===e.secs?h():(c(e.secs),d(!1))},`only files from the last ${e.long}`)},e.label))]})]})]})}function VTe({m:e}){let{scope:t,loading:n,files:r,truncated:i,query:a,setQuery:o,singleRepo:s,setSince:c,onNewCut:l,setOnNewCut:u,loadErr:d,setReload:f,cachedAt:p,staleWhy:m,note:h,open:g}=e,{onClose:_,onSweep:v,onSurvey:y,initialNew:b}=e.props,x=r.length;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(gE,{title:`Images & documents`,onClose:_,children:[(x>0||n)&&(0,J.jsx)(`span`,{className:`gallery-meta`,title:no()?void 0:`build b3f990ff`,children:n&&!x?(0,J.jsx)(Ul,{size:12,className:`spin`}):`${x}${i?`+`:``} file${x===1&&!i?``:`s`}`}),v&&s&&(t===`inbox`||t===`outbox`)&&(0,J.jsx)(Y,{className:`gallery-head-btn`,title:`clear out old ${t} files`,"aria-label":`clear out old ${t} files`,onClick:()=>v(t),children:(0,J.jsx)(ic,{size:17})}),y&&t===`all`&&(0,J.jsx)(Y,{className:`gallery-head-btn`,title:`what is taking space, repo by repo`,"aria-label":`what is taking space`,onClick:y,children:(0,J.jsx)(Es,{size:17})})]}),(0,J.jsx)(`div`,{className:`form`,children:(0,J.jsxs)(`div`,{className:`search-row`,children:[(0,J.jsx)(Lc,{size:16}),(0,J.jsx)(`input`,{className:`search`,placeholder:t===`all`?`Search every repo by name`:`Search by name`,value:a,onChange:e=>o(e.target.value)}),a&&(0,J.jsx)(Y,{"aria-label":`clear the search`,onClick:()=>o(``),children:(0,J.jsx)(V,{size:14})})]})}),(0,J.jsx)(BTe,{m:e}),l&&(0,J.jsx)(cE,{onClear:()=>{c(void 0),u(!1)},clearLabel:`show all`,children:RTe(b.count,x,n,i)}),d&&(0,J.jsxs)(`div`,{className:`gallery-note err`,children:[(0,J.jsx)(Js,{size:14}),(0,J.jsxs)(`span`,{children:[`Could not load the list (`,d,`)`,x?` — showing what was already loaded`:``,`.`]}),(0,J.jsxs)(Y,{onClick:()=>f(e=>e+1),children:[(0,J.jsx)($c,{size:14}),` retry`]})]}),p!=null&&(0,J.jsxs)(`div`,{className:`gallery-note`,children:[(0,J.jsx)(Hs,{size:14}),(0,J.jsx)(`span`,{children:m?`Showing the list this phone last saw, ${lX(p)} — ${m}.`:`Showing the list this phone last saw, ${lX(p)} — refreshing…`}),m&&(0,J.jsxs)(Y,{onClick:()=>f(e=>e+1),children:[(0,J.jsx)($c,{size:14}),` retry`]})]}),h&&!g&&(0,J.jsx)(`div`,{className:`gallery-note`,children:h})]})}var HTe=[[/^(md|markdown|txt|log|rst|pdf)$/,Nl],[/^(html?|json|ya?ml|toml|xml|js|mjs|ts|tsx|css|sh|py|diff|patch)$/,ire],[/^(csv|tsv|xlsx?|ods)$/,cre],[/^(zip|tar|gz|tgz|7z|rar)$/,Dne],[/^(apk|aab|ipa)$/,ql],[/^(mp3|m4a|wav|ogg|opus|flac|aac)$/,Hne]];function UTe({name:e}){let t=e.lastIndexOf(`.`),n=t>0?e.slice(t+1).toLowerCase():``,r=HTe.find(([e])=>e.test(n))?.[1]??Mc;return(0,J.jsxs)(`span`,{className:`doc`,"aria-hidden":!0,children:[(0,J.jsx)(r,{size:30,strokeWidth:1.5}),n&&(0,J.jsx)(`span`,{className:`doc-ext`,children:n})]})}function WTe({url:e,name:t,missing:n,onMissing:r}){let{src:i,live:a}=jj(e);return n?(0,J.jsxs)(`span`,{className:`img-missing`,children:[(0,J.jsx)(_s,{size:18}),(0,J.jsx)(`span`,{className:`img-missing-name`,children:t})]}):i?(0,J.jsx)(`img`,{src:i,alt:t,loading:`lazy`,decoding:`async`,onLoad:()=>{a&&Oj(e)},onError:r}):(0,J.jsx)(`span`,{className:`thumb-blank`})}function GTe({src:e,poster:t,name:n}){let{src:r,live:i}=jj(t);return(0,H.useEffect)(()=>{i&&Oj(t)},[i,t]),(0,J.jsx)(`video`,{src:e,poster:r??void 0,title:n,muted:!0,playsInline:!0,preload:`none`})}function KTe({m:e}){let{picked:t,canPick:n,startPick:r,cancelPick:i,combinePicked:a}=e;return t?(0,J.jsxs)(`div`,{className:`annot-tools gallery-pick on`,children:[(0,J.jsx)(`span`,{className:`viewer-doc-note`,children:FTe(t.length)}),(0,J.jsxs)(Y,{onClick:i,children:[(0,J.jsx)(V,{size:14}),` cancel`]}),t.length>=2&&(0,J.jsxs)(`button`,{className:`send`,onClick:a,children:[(0,J.jsx)(Wc,{size:14}),` combine `,t.length]})]}):n?(0,J.jsx)(`div`,{className:`annot-tools gallery-pick`,children:(0,J.jsxs)(Y,{"aria-label":`pick pictures to combine`,onClick:r,children:[(0,J.jsx)(Wc,{size:14}),` combine pictures…`]})}):null}function qTe({m:e}){let{files:t,loading:n,loadErr:r,query:i,kind:a,scope:o,truncated:s,showFile:c,badSrc:l,markBad:u,urlFor:d,thumbFor:f,markOf:p,pullOf:m,pullBadge:h,isInboxFile:g,removeInbox:_,setLimit:v,onNewCut:y,since:b,setSince:x,setOnNewCut:S}=e,C=e=>y&&p(e)===`new`?null:p(e),w=o!==`inbox`&&!y?zTe(b):null,{picked:T,pickIndex:E,togglePicked:D}=e;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(KTe,{m:e}),(0,J.jsxs)(`div`,{className:`grid${n&&t.length?` stale`:``}`,children:[t.map(e=>(0,J.jsxs)(`div`,{className:`thumb-wrap${E(e)>=0?` picked`:``}`,children:[T&&E(e)>=0&&(0,J.jsx)(`span`,{className:`thumb-pick`,"aria-hidden":`true`,children:E(e)+1}),(0,J.jsxs)(`button`,{className:`thumb`,"aria-pressed":T&&nO(e.relPath)?E(e)>=0:void 0,onClick:()=>T?D(e):c(e),children:[nO(e.relPath)?(0,J.jsx)(WTe,{url:f(e),name:e.name,missing:l.has(f(e)),onMissing:()=>u(f(e))}):rO(e.relPath)?(0,J.jsx)(GTe,{src:d(e),poster:f(e),name:e.name}):(0,J.jsx)(UTe,{name:e.name}),(0,J.jsx)(`span`,{className:`thumb-name`,children:e.name}),(0,J.jsxs)(`span`,{className:`thumb-date`,title:uX(e.ctime??e.mtime),children:[lX(e.ctime??e.mtime),e.size?(0,J.jsxs)(`span`,{className:`thumb-size`,children:[` · `,zp(e.size)]}):null]}),e.repoName&&(0,J.jsx)(`span`,{className:`thumb-repo`,children:e.repoName}),(0,J.jsxs)(`span`,{className:`thumb-badges`,children:[C(e)&&!m(e)&&(0,J.jsx)(`span`,{className:`thumb-mark ${C(e)}`,title:OTe[C(e)],children:C(e)===`new`?(0,J.jsx)(`span`,{className:`sr-only`,children:`new`}):C(e)===`downloaded`?(0,J.jsx)(rs,{size:11}):(0,J.jsx)(as,{size:11})}),m(e)&&(0,J.jsx)(`span`,{className:`thumb-pull ${m(e).state}`,title:ix(m(e)).detail,children:h(m(e))})]})]}),g(e)&&(0,J.jsx)(uT,{className:`thumb-del`,title:`delete ${e.name}`,confirmTitle:`tap again to delete ${e.name}`,confirm:(0,J.jsx)(Js,{size:14}),onConfirm:()=>{_(e)},children:(0,J.jsx)(ic,{size:14})})]},`${e.repoId??``}:${e.relPath}`)),t.length===0&&n&&Array.from({length:8},(e,t)=>(0,J.jsx)(`div`,{className:`thumb-wrap`,children:(0,J.jsx)(`div`,{className:`thumb skel-thumb`})},`skel-${t}`)),t.length===0&&!n&&!r&&(0,J.jsx)($,{children:i||a!==`all`?`No matches.`:w?(0,J.jsxs)(J.Fragment,{children:[w,` `,(0,J.jsx)(`button`,{className:`link-btn`,onClick:()=>{x(void 0),S(!1)},children:`show older files`})]}):o===`outbox`?`The outbox is empty. Claude puts screenshots and files meant for your phone in .claude/outbox. To see images anywhere in the repo, switch to this repo.`:`Nothing here yet.`})]}),s&&(0,J.jsxs)(`div`,{className:`annot-tools`,children:[(0,J.jsxs)(Y,{onClick:()=>{q(`action:gallery.more`),v(e=>e+60)},children:[`load `,60,` more`]}),(0,J.jsxs)(`span`,{className:`viewer-doc-note`,children:[`showing the newest `,t.length]})]})]})}function mX(e){let{onContinueInSession:t,sessionsIn:n}=e.props;return t&&n?n(e.repoId):[]}function hX(e,t){q(t?`action:gallery.toSession`:`action:gallery.toNewSession`),e.setPicking(!1),e.props.onContinueInSession?.(e.relPath,e.repoId,t)}function JTe(e){if(!e.props.onContinueInSession)return null;let t=mX(e);return(0,J.jsxs)(J.Fragment,{children:[t.length===1&&(0,J.jsxs)(Y,{title:`put this file's path in that session's prompt`,onClick:()=>hX(e,t[0].id),children:[(0,J.jsx)(Go,{size:16}),` `,t[0].label]}),t.length>1&&(0,J.jsxs)(Y,{title:`pick which live session gets this file's path`,onClick:()=>e.setPicking(!e.picking),children:[(0,J.jsx)(Go,{size:16}),` session · `,t.length]}),(0,J.jsxs)(Y,{title:`start a new session in this repo with this file's path in its prompt`,onClick:()=>hX(e,null),children:[(0,J.jsx)(os,{size:16}),` new session`]})]})}function YTe(e){let t=mX(e);return!e.picking||t.length<2?null:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`viewer-doc-note`,children:[t.length,` live sessions in `,e.repoName||`this repo`,` — the path goes into the prompt of the one you pick`]}),(0,J.jsx)(`div`,{className:`list`,children:t.map(t=>(0,J.jsxs)(xE,{as:`button`,onClick:()=>hX(e,t.id),children:[(0,J.jsxs)(SE,{children:[(0,J.jsx)(xo,{size:14}),` `,t.label]}),t.onScreen&&(0,J.jsx)(Q,{children:`on screen behind the gallery`})]},t.id))})]})}function XTe({m:e}){let{open:t,closeDoc:n,repoOf:r,localUrl:i,fullRes:a,mediaSrc:o,fileSrc:s,imgs:c,nav:l,setDocRaw:u,docRaw:d,doc:f,docErr:p,docCachedAt:m,htmlLive:h,pullOf:g,dlTarget:_,files:v,showFile:y,openIdx:b,copied:x,copy:S,canFullRes:C,setFullRes:w,urlFor:T,setMarkTick:E,isInboxFile:D,del:O,note:k}=e,{onAnnotate:A,onInsertPath:j,onClose:M}=e.props,[N,P]=(0,H.useState)(null);if(!t)return null;let F={relPath:t.relPath,repoId:r(t),repoName:t.repoName,props:e.props,picking:N===t.relPath,setPicking:e=>P(e?t.relPath:null)};return(0,J.jsxs)(`div`,{className:`viewer`,onClick:()=>n(),children:[(0,J.jsx)(`button`,{className:`viewer-close`,onClick:()=>n(),"aria-label":`close`,children:(0,J.jsx)(V,{size:22})}),(0,J.jsxs)(`div`,{className:`viewer-body`,onClick:e=>e.stopPropagation(),children:[nO(t.relPath)?(0,J.jsx)(iX,{src:o(t),alt:t.name,onNav:c.length>1?l:void 0},`${r(t)}:${t.relPath}:${i?`local`:a?`full`:`fit`}`):rO(t.relPath)?(0,J.jsx)(`video`,{className:`viewer-video`,src:s(t),controls:!0,autoPlay:!0,playsInline:!0},`${r(t)}:${t.relPath}:${i?`local`:`net`}`):uO(t.relPath)?(0,J.jsxs)(`div`,{className:`viewer-doc`,children:[cO(t.relPath)&&(0,J.jsxs)(`div`,{className:`viewer-doc-bar`,children:[(0,J.jsx)(Y,{onClick:()=>u(e=>!e),children:d?`rendered`:`source`}),f?.truncated&&!h&&(0,J.jsxs)(`span`,{className:`viewer-doc-note`,children:[`showing the first `,400,` KB — download for the rest`]}),m!=null&&!h&&(0,J.jsxs)(`span`,{className:`viewer-doc-note`,children:[(0,J.jsx)(Hs,{size:12}),` saved copy from `,lX(m)]})]}),h?(0,J.jsx)(`iframe`,{className:`viewer-html`,src:s(t),title:t.name,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`},`${r(t)}:${t.relPath}:${i?`local`:`net`}`):p?(0,J.jsxs)($,{children:[`Could not load this file (`,p,`). `,(0,J.jsx)(FO,{rec:g(t),target:_(t)})]}):!f||f.path!==t.relPath?(0,J.jsx)($,{children:`Loading…`}):lO(t.relPath)&&!d?(0,J.jsx)(`div`,{className:`viewer-doc-body`,children:(0,J.jsx)(Rj,{src:f.text,q:``,onCopy:e=>gp(e),files:{repoId:r(t),url:(e,n,i)=>{let a=U.artifactUrl(r(t),e);return n?sg(a,n,i):a},open:e=>{let n=v.find(t=>t.relPath===e);n?y(n):NO({repoId:r(t),relPath:e})},known:v.filter(e=>r(e)===r(t)).map(e=>e.relPath),docPath:t.relPath}})}):(0,J.jsxs)(`pre`,{className:`viewer-doc-pre`,children:[f.text,f.truncated?`
|
|
205
|
+
`)[0];return(0,J.jsxs)(`div`,{className:`ann-prompt`,children:[(0,J.jsxs)(`button`,{className:`ann-prompt-fold`,onClick:r,"aria-expanded":t,title:t?`fold the message box away`:`show the session's message box — typed here, sent with the picture on Send & run`,children:[t?(0,J.jsx)(ac,{size:14}):(0,J.jsx)(jl,{size:14}),(0,J.jsx)(Qne,{size:14}),(0,J.jsx)(`span`,{className:`ann-prompt-gist`,children:t?`message for the session`:i||`message for the session — empty`})]}),t&&(0,J.jsx)(uD,{inline:!0,rows:2,prompts:[e.value],onChange:t=>e.onChange(t[0]??``),placeholder:`Message for the session — Send & run sends it with the picture`})]})}function Twe({m:e}){let{busy:t,send:n,sendAll:r,readAll:i}=e,{index:a,total:o,onSkip:s,onSendAll:c,onDispatch:l,onText:u}=e.props;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(yH,{compact:!0}),(0,J.jsxs)(`div`,{className:`sheet-actions annot-send-bar`,"data-primary-key":``,children:[s&&(0,J.jsx)(Y,{onClick:s,disabled:t,children:`skip`}),c&&o&&o>1&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Y,{onClick:()=>r(`none`),disabled:t,title:`send this + every remaining image as-is`,children:`Send all`}),(0,J.jsx)(Y,{onClick:()=>r(`run`),disabled:t,title:`send all, then submit once uploads finish`,children:`Send all + submit`}),(0,J.jsxs)(Y,{onClick:()=>r(`queue`),disabled:t,title:`send all, then hand the prompt to the desktop — it goes in when this session is free`,children:[(0,J.jsx)(Kl,{size:14}),` Send all, then when it's free`]})]}),l&&(!o||o<=1)&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Y,{onClick:()=>n(`run`),disabled:t,title:`attach the image and run the prompt (uploads in the background)`,children:`Send & run`}),(0,J.jsxs)(Y,{onClick:()=>n(`queue`),disabled:t,title:`attach the image and hand the prompt to the desktop — it goes in when this session is free`,children:[(0,J.jsx)(Kl,{size:14}),` Send & when it's free`]})]}),u&&(0,J.jsxs)(Y,{onClick:()=>void i(),disabled:t,title:`read every word on the desktop and send only the text, not the photo`,children:[(0,J.jsx)(fc,{size:14}),` text only`]}),(0,J.jsx)(`button`,{className:`send`,onClick:()=>n(`none`),disabled:t,children:t?`Sending…`:o&&o>1&&(a??1)<o?`Send & next`:`Send to repo`})]})]})}var OY=[{id:`undo`,label:`undo`},{id:`circle`,label:`circle`},{id:`rect`,label:`rectangle`},{id:`arrow`,label:`arrow`},{id:`line`,label:`line`},{id:`text`,label:`text label`},{id:`marker`,label:`highlight text`},{id:`blur`,label:`blur / redact`},{id:`crop`,label:`crop`},{id:`move`,label:`move a mark`},{id:`style`,label:`colour & stroke`},{id:`clear`,label:`clear all marks`}],kY=OY.map(e=>e.id),Ewe=[`auto`,`left`,`top`],AY={order:kY.slice(),hidden:[],place:`auto`},jY=e=>typeof e==`string`&&kY.includes(e);function Dwe(e){if(!e||typeof e!=`object`)return{...AY,order:kY.slice()};let t=e,n=new Set,r=[];for(let e of Array.isArray(t.order)?t.order:[])jY(e)&&!n.has(e)&&(n.add(e),r.push(e));return kY.forEach((e,t)=>{if(n.has(e))return;let i=0;for(let e=t-1;e>=0;e--){let t=r.indexOf(kY[e]);if(t>=0){i=t+1;break}}r.splice(i,0,e),n.add(e)}),{order:r,hidden:(Array.isArray(t.hidden)?t.hidden:[]).filter(jY).filter((e,t,n)=>n.indexOf(e)===t),place:Ewe.includes(t.place)?t.place:`auto`}}function Owe(e){return e.order.filter(t=>!e.hidden.includes(t))}function kwe(e,t){let n=e.hidden.includes(t)?e.hidden.filter(e=>e!==t):[...e.hidden,t];return{...e,hidden:n}}function MY(e,t,n){let r=e.order.indexOf(t),i=r+n;if(r<0||i<0||i>=e.order.length)return e;let a=e.order.slice();return[a[r],a[i]]=[a[i],a[r]],{...e,order:a}}function Awe(e){return e.place===`auto`&&!e.hidden.length&&e.order.every((e,t)=>e===kY[t])}function jwe(e,t){if(!e||!t||e.w<1||e.h<1||t.w<1||t.h<1)return null;let n=(e,n)=>Math.min(Math.max(e,0)/t.w,Math.max(n,0)/t.h),r=n(e.w-57,e.h);return n(e.w,e.h-61)>r?`top`:`left`}var Mwe=[{v:`auto`,label:`auto`},{v:`left`,label:`left`},{v:`top`,label:`top`}];function Nwe({m:e}){let{layout:t,setLayout:n,setConfigOpen:r}=e,i=e=>OY.find(t=>t.id===e)?.label??e,a=t.order.length-1;return(0,J.jsxs)(`div`,{className:`annot-config`,role:`dialog`,"aria-label":`customize the toolbar`,children:[(0,J.jsxs)(`div`,{className:`annot-config-head`,children:[(0,J.jsx)(`span`,{children:`Toolbar`}),(0,J.jsxs)(Y,{onClick:()=>r(!1),"aria-label":`close the toolbar settings`,children:[(0,J.jsx)(V,{size:16}),` done`]})]}),(0,J.jsxs)(`div`,{className:`annot-config-row`,children:[(0,J.jsx)(`span`,{className:`annot-config-label`,children:`position`}),Mwe.map(e=>(0,J.jsx)(Y,{className:t.place===e.v?`active`:``,"aria-pressed":t.place===e.v,onClick:()=>n({...t,place:e.v}),children:e.label},e.v))]}),(0,J.jsx)(`div`,{className:`annot-config-hint`,children:t.place===`auto`?`auto: whichever side leaves this picture larger — a row on top for a wide one, a rail on the left for a tall one`:`always on the ${t.place}`}),(0,J.jsx)(`div`,{className:`annot-config-list`,children:t.order.map((e,r)=>{let o=!t.hidden.includes(e);return(0,J.jsxs)(`div`,{className:`annot-config-row ${o?``:`off`}`,children:[(0,J.jsx)(Y,{className:`annot-config-toggle${o?` active`:``}`,"aria-pressed":o,onClick:()=>n(kwe(t,e)),children:o?`shown`:`hidden`}),(0,J.jsx)(`span`,{className:`annot-config-label`,children:i(e)}),r>0?(0,J.jsx)(Y,{onClick:()=>n(MY(t,e,-1)),"aria-label":`move ${i(e)} up`,children:(0,J.jsx)(Ys,{size:16})}):(0,J.jsx)(`span`,{className:`annot-config-gap`}),r<a?(0,J.jsx)(Y,{onClick:()=>n(MY(t,e,1)),"aria-label":`move ${i(e)} down`,children:(0,J.jsx)(ac,{size:16})}):(0,J.jsx)(`span`,{className:`annot-config-gap`})]},e)})}),!Awe(t)&&(0,J.jsx)(`div`,{className:`annot-config-row`,children:(0,J.jsx)(Y,{onClick:()=>n({...AY,order:AY.order.slice()}),children:`reset to default`})})]})}var NY=[`#ff2d2d`,`#ffd400`,`#3fb950`,`#4c9aff`,`#ffffff`],Pwe=`#ffd400`,PY=[{label:`S`,factor:.6},{label:`M`,factor:1},{label:`L`,factor:1.8}];function Fwe(e){return e instanceof File,e.name}var Iwe={circle:{tool:`circle`,icon:(0,J.jsx)(vc,{size:16}),label:`circle`},rect:{tool:`rect`,icon:(0,J.jsx)(Rc,{size:16}),label:`rectangle`},arrow:{tool:`arrow`,icon:(0,J.jsx)(qne,{size:16}),label:`arrow`},line:{tool:`line`,icon:(0,J.jsx)(hs,{size:16}),label:`line`},text:{tool:`text`,icon:(0,J.jsx)(Dc,{size:16}),label:`text`},marker:{tool:`marker`,icon:(0,J.jsx)(bne,{size:16}),label:`highlight text`},blur:{tool:`blur`,icon:(0,J.jsx)(Gc,{size:16}),label:`blur or redact`}};function Lwe({m:e}){let{tool:t,color:n,setColor:r,factor:i,setFactor:a,shapes:o,setShapes:s,moveMode:c,selected:l,setSelected:u,setTarget:d,setMoveNote:f,knobs:p,cropMode:m,paletteOpen:h,setPaletteOpen:g,moveRef:_,toggleCrop:v,pickTool:y,undoShape:b,toggleMove:x,toggleKnobs:S,deleteSelected:C,layout:w}=e,T=PY.find(e=>e.factor===i)?.label??`M`;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`div`,{className:`annot-tools annot-bar`,children:Owe(w).map(e=>{let r=Iwe[e];if(r)return(0,J.jsx)(Y,{className:t===r.tool?`active`:``,onClick:()=>y(r.tool),title:r.label,"aria-label":r.label,"aria-pressed":t===r.tool,children:r.icon},e);switch(e){case`undo`:return(0,J.jsx)(Y,{onClick:b,disabled:!o.length,title:`undo`,"aria-label":`undo the last mark`,children:(0,J.jsx)(Ac,{size:16})},e);case`crop`:return(0,J.jsx)(Y,{className:m?`active`:``,onClick:v,title:`crop`,"aria-label":`crop`,"aria-pressed":m,children:(0,J.jsx)(Fne,{size:16})},e);case`move`:return[(0,J.jsx)(Y,{className:c?`active`:``,onClick:x,disabled:!o.length,title:`move/reshape a mark`,"aria-label":`move a mark`,"aria-pressed":c,children:(0,J.jsx)(Pne,{size:16})},e),c&&(0,J.jsx)(Y,{onClick:C,disabled:l==null,title:`delete the selected mark`,"aria-label":`delete the selected mark`,children:(0,J.jsx)(ic,{size:16})},`del`),c&&(0,J.jsx)(Y,{className:p?`active`:``,onClick:S,"aria-pressed":p,title:`knobs: move, size and turn a mark (or drag an arrow's ends) by knobs on strings, instead of dragging from anywhere`,"aria-label":`knobs on the selected mark`,children:`knobs`},`knobs`)];case`style`:return(0,J.jsx)(`button`,{className:`swatch dot annot-style ${h?`on`:``}`,style:{background:n},onClick:()=>g(e=>!e),title:`mark colour and stroke`,"aria-label":`mark colour ${n}, stroke ${T} — tap to change`,"aria-expanded":h,children:T},e);case`clear`:return(0,J.jsx)(Y,{onClick:()=>{_.current=null,u(null),d(null),f(null),s([])},disabled:!o.length,title:`clear all marks`,"aria-label":`clear all marks`,children:(0,J.jsx)(Vc,{size:16})},e)}return null})}),h&&(0,J.jsxs)(`div`,{className:`annot-tools annot-palette`,children:[NY.map(e=>(0,J.jsx)(`button`,{className:`swatch ${n===e?`on`:``}`,style:{background:e},onClick:()=>{r(e),g(!1)},title:`colour ${e}`,"aria-label":`colour ${e}`,"aria-pressed":n===e},e)),PY.map(e=>(0,J.jsx)(Y,{className:i===e.factor?`active`:``,onClick:()=>{a(e.factor),g(!1)},title:`stroke ${e.label}`,"aria-label":`stroke ${e.label}`,"aria-pressed":i===e.factor,children:e.label},e.label))]})]})}function Rwe({m:e}){let{canvasRef:t,wrapRef:n,bodyRef:r,view:i,onDown:a,onMove:o,onUp:s,place:c,configOpen:l}=e;return(0,J.jsxs)(`div`,{className:`annot-body place-${c}`,ref:r,children:[(0,J.jsx)(Lwe,{m:e}),(0,J.jsx)(`div`,{className:`annot-canvas-wrap`,ref:n,onPointerDown:a,onPointerMove:o,onPointerUp:s,onPointerCancel:s,children:(0,J.jsx)(`canvas`,{ref:t,className:`annot-canvas`,style:{transform:`translate(${i.tx}px, ${i.ty}px) scale(${i.k})`,transformOrigin:`0 0`}})}),l&&(0,J.jsx)(Nwe,{m:e})]})}function zwe({m:e}){let{ocr:t,ocrDraft:n,setOcrDraft:r,readAll:i,closeOcr:a,sendText:o}=e;if(!t)return null;let s=!n.trim();return(0,J.jsxs)(`div`,{className:`annot-ocr`,children:[t.phase===`reading`&&(0,J.jsx)(`div`,{className:`annot-hint`,children:`Reading every word on your desktop… The photo goes no further than that machine.`}),t.phase===`error`&&(0,J.jsx)(`div`,{className:`annot-hint`,children:t.error}),t.phase===`ready`&&(0,J.jsxs)(`div`,{className:`annot-hint`,children:[`Read on your desktop (`,t.engine,`, `,(t.ms/1e3).toFixed(1),` s). Fix anything misread — only this text is sent, never the photo.`]}),(t.phase===`ready`||!s)&&(0,J.jsx)(`textarea`,{className:`annot-ocr-text`,value:n,onChange:e=>r(e.target.value),spellCheck:!1,autoCapitalize:`off`,"aria-label":`text read off the picture`}),t.phase===`ready`&&s&&(0,J.jsx)(`div`,{className:`annot-hint`,children:`Nothing left to send — read again, or go back to the picture.`}),(0,J.jsxs)(`div`,{className:`sheet-actions annot-send-bar`,"data-primary-key":``,children:[(0,J.jsxs)(Y,{onClick:a,children:[(0,J.jsx)(pl,{size:14}),` picture`]}),t.phase!==`reading`&&(0,J.jsxs)(Y,{onClick:()=>void i(),children:[(0,J.jsx)($c,{size:14}),` read again`]}),t.phase!==`reading`&&!s&&(0,J.jsxs)(`button`,{className:`send`,onClick:()=>o(n),children:[(0,J.jsx)(fc,{size:14}),` Send text only`]})]})]})}var Bwe={"#ff2d2d":`red`,"#ffd400":`yellow`,"#3fb950":`green`,"#4c9aff":`blue`,"#ffffff":`white`};function Vwe(e,t,n,r){let i=t/r,a=e/n,o=i<.34?`top`:i>.66?`bottom`:`middle`,s=a<.34?`left`:a>.66?`right`:`center`;return o===`middle`&&s===`center`?`center`:o===`middle`?s:s===`center`?o:`${o}-${s}`}function FY(e){return`${Math.round(Math.max(0,Math.min(1,e))*100)}%`}function IY(e,t,n,r){return`${Vwe(e,t,n,r)} (x ${FY(e/n)}, y ${FY(t/r)})`}function LY(e,t,n){let r=Math.min(e.x0,e.x1),i=Math.max(e.x0,e.x1),a=Math.min(e.y0,e.y1),o=Math.max(e.y0,e.y1);return`(x ${FY(r/t)}-${FY(i/t)}, y ${FY(a/n)}-${FY(o/n)})`}function RY(e){return`"${e.replace(/\s+/g,` `).trim().replace(/"/g,`''`)}"`}var Hwe=e=>Bwe[e.toLowerCase()]||e;function Uwe(e,t,n){return[e.tool,e.color.toLowerCase(),FY(Math.min(e.x0,e.x1)/t),FY(Math.min(e.y0,e.y1)/n),FY(Math.max(e.x0,e.x1)/t),FY(Math.max(e.y0,e.y1)/n),(e.text??``).trim(),(e.read??``).trim()].join(`|`)}function zY(e,t,n){if(t<=0||n<=0)return[];let r=new Set,i=[];for(let a of e){let e=Uwe(a,t,n);r.has(e)||(r.add(e),i.push(a))}return i}function Wwe(e,t,n){switch(e.tool){case`blur`:return`blurred/redacted region ${LY(e,t,n)}`;case`text`:return`text ${RY(e.text||``)} at ${IY(e.x0,e.y0,t,n)}`;case`marker`:return e.read?`highlight over ${RY(e.read)} ${LY(e,t,n)}`:`highlight ${LY(e,t,n)}`;case`arrow`:return`arrow pointing to ${IY(e.x1,e.y1,t,n)}`;case`line`:return`line from ${IY(e.x0,e.y0,t,n)} to ${IY(e.x1,e.y1,t,n)}`;case`rect`:return e.read?`box around ${RY(e.read)} ${LY(e,t,n)}`:`box ${LY(e,t,n)}`;default:return e.read?`circle around ${RY(e.read)} ${LY(e,t,n)}`:`circle ${LY(e,t,n)}`}}function Gwe(e,t,n,r){let i=zY(e,t,n),a=[];r&&a.push(r);let o=i.length>1,s=new Set(i.map(e=>e.color.toLowerCase())).size<=1;return i.forEach((e,r)=>{let i=o?`#${r+1} `:``,c=s||e.tool===`blur`?``:`${Hwe(e.color)} `;a.push(`${i}${c}${Wwe(e,t,n)}`)}),a.join(`; `)}function BY(e,t){return!e||!t||!(t.w>0)||!(t.h>0)?e:`${e}; image ${Math.round(t.w)}x${Math.round(t.h)}`}var Kwe=new Set([`rect`,`blur`,`marker`]),VY=(e,t)=>tm(e,0,t);function HY(e,t,n){return Math.max(e.x0,e.x1)>0&&Math.min(e.x0,e.x1)<t&&Math.max(e.y0,e.y1)>0&&Math.min(e.y0,e.y1)<n}function UY(e,t){let n=(e.x0+e.x1)/2,r=(e.y0+e.y1)/2,i=Math.abs(e.x1-e.x0)/2,a=Math.abs(e.y1-e.y0)/2,o=Math.abs(i*Math.cos(t))+Math.abs(a*Math.sin(t)),s=Math.abs(i*Math.sin(t))+Math.abs(a*Math.cos(t));return{x0:n-o,y0:r-s,x1:n+o,y1:r+s}}function qwe(e,t,n){let r=e.x1-e.x0,i=e.y1-e.y0,a=0,o=1,s=[[-r,e.x0-0],[r,t-e.x0],[-i,e.y0-0],[i,n-e.y0]];for(let[e,t]of s){if(e===0){if(t<0)return null;continue}let n=t/e;if(e<0){if(n>o)return null;n>a&&(a=n)}else{if(n<a)return null;n<o&&(o=n)}}return{x0:e.x0+a*r,y0:e.y0+a*i,x1:e.x0+o*r,y1:e.y0+o*i}}function WY(e,t,n){if(!(t>0&&n>0))return e;if(e.tool===`text`){let r=VY(e.x0,t),i=VY(e.y0,n);return{...e,x0:r,y0:i,x1:r,y1:i}}if(e.tool===`line`||e.tool===`arrow`){let r=qwe(e,t,n);return r?{...e,...r}:null}return e.angle?HY(UY(e,e.angle),t,n)?e:null:HY(e,t,n)?Kwe.has(e.tool)?{...e,x0:VY(e.x0,t),y0:VY(e.y0,n),x1:VY(e.x1,t),y1:VY(e.y1,n)}:e:null}function GY(e,t){return e.tool!==`text`&&Math.hypot(e.x1-e.x0,e.y1-e.y0)*t<48}function Jwe(e){let{sel:t,small:n,handleHit:r,pickHit:i,target:a}=e;return t!=null&&!n&&r!=null?{kind:`handle`,i:t,h:r}:i==null?t==null?{kind:`none`}:{kind:`relative`,i:t,h:a}:{kind:`pick`,i}}function Ywe(e,t,n,r){let i=WY(e,n,r);return i?{mark:i,refused:!1}:{mark:t,refused:!0}}function KY(e){return Math.max(4,Math.round(e.width/220))}function qY(e){return{x:Math.min(e.x0,e.x1),y:Math.min(e.y0,e.y1),w:Math.abs(e.x1-e.x0),h:Math.abs(e.y1-e.y0)}}function JY(e,t){if(!e)return t;let n=t=>Math.max(0,Math.min(t,e.width)),r=t=>Math.max(0,Math.min(t,e.height)),i=n(t.x),a=r(t.y);return{x:i,y:a,w:n(t.x+t.w)-i,h:r(t.y+t.h)-a}}function Xwe(e){let t=/^#?([0-9a-f]{6})$/i.exec(e.trim());if(!t)return`#fff`;let n=parseInt(t[1],16);return(.299*(n>>16&255)+.587*(n>>8&255)+.114*(n&255))/255>.6?`#111`:`#fff`}function Zwe(e){if(e.tool===`text`||e.tool===`arrow`||e.tool===`line`)return{x:e.x0,y:e.y0};let t=qY(e);if(!e.angle)return{x:t.x,y:t.y};let n=t.x+t.w/2,r=t.y+t.h/2,i=Math.cos(e.angle),a=Math.sin(e.angle);return{x:n+-t.w/2*i- -t.h/2*a,y:r+-t.w/2*a+-t.h/2*i}}function YY(e,t,n){if(n.tool===`text`){let r=Math.max(16,Math.round(t.width/26))*n.factor;e.save(),e.font=`bold ${r}px ui-sans-serif, system-ui, sans-serif`;let i=e.measureText(n.text||``).width;return e.restore(),{x:n.x0,y:n.y0,w:i,h:r*1.2}}return qY(n)}function Qwe(e,t,n,r,i,a){let o=i-n,s=a-r,c=o*o+s*s,l=c?Math.max(0,Math.min(1,((e-n)*o+(t-r)*s)/c)):0;return Math.hypot(e-(n+l*o),t-(r+l*s))}function $we(e,t,n,r,i){if(!e)return!1;if(t.tool===`arrow`||t.tool===`line`)return Qwe(n,r,t.x0,t.y0,t.x1,t.y1)<=i;let a=YY(e.getContext(`2d`),e,t);if(t.angle){let e=a.x+a.w/2,i=a.y+a.h/2,o=Math.cos(-t.angle),s=Math.sin(-t.angle),c=e+(n-e)*o-(r-i)*s,l=i+(n-e)*s+(r-i)*o;n=c,r=l}return n>=a.x-i&&n<=a.x+a.w+i&&r>=a.y-i&&r<=a.y+a.h+i}function eTe(e,t,n){if(!n)return;let r=KY(t);e.save(),e.fillStyle=`rgba(0,0,0,.55)`,e.beginPath(),e.rect(0,0,t.width,t.height),e.rect(n.x,n.y,n.w,n.h),e.fill(`evenodd`),e.strokeStyle=`#fff`,e.lineWidth=r,e.setLineDash([r*2.5,r*2.5]),e.strokeRect(n.x,n.y,n.w,n.h),e.restore()}function XY(e,t,n,r){if(!n)return;if(r.angle){let i=qY(r),a=i.x+i.w/2,o=i.y+i.h/2;e.save(),e.beginPath(),e.translate(a,o),e.rotate(r.angle),e.rect(-i.w/2,-i.h/2,i.w,i.h),e.setTransform(1,0,0,1,0,0),e.clip(),XY(e,t,n,{...r,angle:0,...UY(r,r.angle)}),e.restore();return}let{x:i,y:a,w:o,h:s}=JY(t,qY(r));if(o<1||s<1)return;let c=Math.max(8,Math.round(t.width/48)),l=Math.max(1,Math.round(o/c)),u=Math.max(1,Math.round(s/c)),d=document.createElement(`canvas`);d.width=l,d.height=u,d.getContext(`2d`).drawImage(n,i,a,o,s,0,0,l,u),e.save(),e.imageSmoothingEnabled=!1,e.drawImage(d,0,0,l,u,i,a,o,s),e.restore()}function tTe(e,t,n){let r=qY(n),i=KY(t)*5*n.factor,a=Math.max(r.h,i),o=r.h>=i?r.y:r.y-(i-r.h)/2;e.save(),e.globalAlpha=.38,e.globalCompositeOperation=`multiply`,e.fillStyle=n.color,e.fillRect(r.x,o,Math.max(r.w,i),a),e.restore()}function nTe(e,t,n){if(n.length<2)return;let r=Math.max(10,KY(t)*3.2);n.forEach((n,i)=>{let a=Zwe(n),o=Math.max(r+2,Math.min(t.width-r-2,a.x-r*.2)),s=Math.max(r+2,Math.min(t.height-r-2,a.y-r*.2));e.save(),e.beginPath(),e.arc(o,s,r,0,Math.PI*2),e.fillStyle=n.tool===`blur`?`#111`:n.color,e.fill(),e.lineWidth=Math.max(1,r*.14),e.strokeStyle=`rgba(0,0,0,.55)`,e.stroke(),e.fillStyle=n.tool===`blur`?`#fff`:Xwe(n.color),e.font=`bold ${Math.round(r*1.25)}px ui-sans-serif, system-ui, sans-serif`,e.textAlign=`center`,e.textBaseline=`middle`,e.fillText(String(i+1),o,s),e.restore()}),e.textAlign=`start`}function ZY(e,t,n,r){if(!r.angle||r.tool===`blur`||r.tool===`arrow`||r.tool===`line`){QY(e,t,n,r);return}let i=YY(e,t,r),a=i.x+i.w/2,o=i.y+i.h/2;e.save(),e.translate(a,o),e.rotate(r.angle),e.translate(-a,-o),QY(e,t,n,r),e.restore()}function QY(e,t,n,r){if(r.tool===`blur`){XY(e,t,n,r);return}if(r.tool===`marker`){tTe(e,t,r);return}let i=KY(t)*r.factor;if(e.strokeStyle=r.color,e.fillStyle=r.color,e.lineWidth=i,e.lineCap=`round`,e.lineJoin=`round`,r.tool===`rect`)e.strokeRect(r.x0,r.y0,r.x1-r.x0,r.y1-r.y0);else if(r.tool===`circle`)e.beginPath(),e.ellipse((r.x0+r.x1)/2,(r.y0+r.y1)/2,Math.abs(r.x1-r.x0)/2,Math.abs(r.y1-r.y0)/2,0,0,Math.PI*2),e.stroke();else if(r.tool===`arrow`||r.tool===`line`){let t=Math.atan2(r.y1-r.y0,r.x1-r.x0),n=i*4;if(e.beginPath(),e.moveTo(r.x0,r.y0),e.lineTo(r.x1,r.y1),e.stroke(),r.tool===`line`)return;e.beginPath(),e.moveTo(r.x1,r.y1),e.lineTo(r.x1-n*Math.cos(t-Math.PI/6),r.y1-n*Math.sin(t-Math.PI/6)),e.lineTo(r.x1-n*Math.cos(t+Math.PI/6),r.y1-n*Math.sin(t+Math.PI/6)),e.closePath(),e.fill()}else if(r.tool===`text`&&r.text){let n=Math.max(16,Math.round(t.width/26))*r.factor;e.font=`bold ${n}px ui-sans-serif, system-ui, sans-serif`,e.textBaseline=`top`,e.lineWidth=Math.max(2,n/8),e.strokeStyle=`rgba(0,0,0,.65)`,e.strokeText(r.text,r.x0,r.y0),e.fillText(r.text,r.x0,r.y0)}}function rTe(e,t,n,r,i,a){let o=YY(e,t,n),s=Math.max(1,KY(t)*.6),c=GY(n,r),l=c?Math.max(s*3,48/r/2):s*3;if(e.save(),n.angle&&n.tool!==`arrow`&&n.tool!==`line`){let t=o.x+o.w/2,r=o.y+o.h/2;e.translate(t,r),e.rotate(n.angle),e.translate(-t,-r)}if(e.strokeStyle=`#4c9aff`,e.lineWidth=s,e.setLineDash([s*3,s*3]),e.strokeRect(o.x-l,o.y-l,o.w+l*2,o.h+l*2),e.setLineDash([]),i)e.restore(),iTe(e,t,n,r);else if(n.angle)e.restore();else{if(n.tool!==`text`&&!c){let r=KY(t)*1.8;[[0,n.x0,n.y0],[1,n.x1,n.y1]].forEach(([t,n,i])=>{e.beginPath(),e.arc(n,i,r,0,Math.PI*2),e.fillStyle=a===t?`#4c9aff`:`#fff`,e.fill(),e.stroke()})}e.restore()}}function $Y(e,t,n){return fwe(t,YY(e.getContext(`2d`),e,t),n,e.width,e.height)}function iTe(e,t,n,r){let i=18/r,a=$Y(t,n,r);e.save(),e.lineCap=`round`;for(let t of a)e.beginPath(),e.moveTo(t.ax,t.ay),e.lineTo(t.x,t.y),e.strokeStyle=`rgba(255,255,255,0.85)`,e.lineWidth=4/r,e.stroke(),e.strokeStyle=`#4c9aff`,e.lineWidth=2/r,e.stroke();for(let t of a)e.beginPath(),e.arc(t.x,t.y,i,0,Math.PI*2),e.fillStyle=gwe[t.knob],e.fill(),e.lineWidth=2/r,e.strokeStyle=`#fff`,e.stroke(),vwe(e,t.knob,t.x,t.y,i*.5,2/r);e.restore()}function aTe(e){let{canvasRef:t,wrapRef:n,imgRef:r,setTool:i,color:a,setColor:o,factor:s,setShapes:c,setMoveMode:l,setSelected:u,selectedRef:d,setTarget:f,targetRef:p,setMoveNote:m,setKnobs:h,moveRef:g,setCropMode:_,pendingCrop:v,setPendingCrop:y,cropDrag:b,pendingText:x,setPendingText:S,textDraft:C,setTextDraft:w,textInputRef:T,idRef:E,setPaletteOpen:D,setView:O,viewRef:k,fitRef:A,redraw:j,clampToImage:M}=e;async function N(){let e=r.current,i=t.current;if(!e||!i||!v)return;let{x:a,y:o,w:s,h:l}=M(v);if(s<1||l<1){y(null);return}let u=document.createElement(`canvas`);u.width=Math.round(s),u.height=Math.round(l),u.getContext(`2d`).drawImage(e,a,o,s,l,0,0,u.width,u.height);try{r.current=await createImageBitmap(u)}catch{r.current=u}i.width=u.width,i.height=u.height,c(e=>e.map(e=>({...e,x0:e.x0-a,y0:e.y0-o,x1:e.x1-a,y1:e.y1-o})).map(e=>WY(e,u.width,u.height)).filter(e=>e!=null));let d=n.current?.getBoundingClientRect();if(d){let e=Math.min(d.width/u.width,d.height/u.height),t={k:e,tx:(d.width-u.width*e)/2,ty:(d.height-u.height*e)/2};A.current=t,O(t)}y(null),_(!1),j()}function P(){b.current=null,y(null),l(!1),u(null),f(null),m(null),g.current=null,ie(),_(e=>!e)}function F(e){e!==`text`&&ie(),D(!1),e===`marker`&&a.toLowerCase()===`#ffffff`&&o(Pwe),i(e)}function I(){g.current=null,u(null),f(null),m(null),c(e=>e.slice(0,-1))}function ee(){g.current=null,f(null),m(null),l(e=>(e?u(null):(b.current=null,y(null),_(!1)),!e))}function te(){g.current=null,f(null),p.current=null,m(null),h(e=>(ao(B.annKnobs,!e),!e))}function ne(){let e=d.current;e!=null&&(g.current=null,u(null),f(null),m(null),c(t=>t.filter((t,n)=>n!==e)))}function re(){let e=x,n=C.trim();if(S(null),w(``),T.current?.blur(),!e||!n)return;let r=t.current,i={tool:`text`,x0:e.x,y0:e.y,x1:e.x,y1:e.y,color:a,factor:s,text:n,id:E.current++};c(e=>[...e,r?WY(i,r.width,r.height):i])}function ie(){S(null),w(``),T.current?.blur()}function ae(){k.current=A.current,j(),O(A.current)}return{applyCrop:N,toggleCrop:P,pickTool:F,undoShape:I,toggleMove:ee,toggleKnobs:te,deleteSelected:ne,commitText:re,cancelText:ie,resetZoom:ae}}function oTe(e){let{canvasRef:t,wrapRef:n,tool:r,color:i,factor:a,setShapes:o,shapesRef:s,dragRef:c,moveMode:l,setSelected:u,selectedRef:d,setTarget:f,targetRef:p,setMoveNote:m,knobsRef:h,moveRef:g,cropMode:_,setPendingCrop:v,cropDrag:y,setPendingText:b,setTextDraft:x,textInputRef:S,idRef:C,setView:w,viewRef:T,fitRef:E,pointers:D,gesture:O,redraw:k,clampToImage:A}=e,j=(e,n,r,i)=>$we(t.current,e,n,r,i),M=(e,t)=>$Y(e,t,T.current.k||1);function N(){let e=t.current,n=T.current.k||1;return Math.max(6,24/n,e?e.width/90:0)}function P(e){let n=t.current,r=n.getBoundingClientRect();return{x:(e.clientX-r.left)/r.width*n.width,y:(e.clientY-r.top)/r.height*n.height}}function F(e){let t=n.current.getBoundingClientRect();return{x:e.clientX-t.left,y:e.clientY-t.top}}function I(e,t,n){let r=s.current;for(let i=r.length-1;i>=0;i--)if(j(r[i],e,t,n))return i;return null}function ee(e){if(e.preventDefault(),D.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),e.currentTarget.setPointerCapture(e.pointerId),D.current.size===2){c.current=null,g.current=null;let e=[...D.current.values()],t=Math.hypot(e[0].x-e[1].x,e[0].y-e[1].y),n={x:(e[0].x+e[1].x)/2,y:(e[0].y+e[1].y)/2},r=F({clientX:n.x,clientY:n.y}),i=T.current;O.current={startDist:t,startK:i.k,cx:(r.x-i.tx)/i.k,cy:(r.y-i.ty)/i.k},y.current=null,k();return}if(_){let{x:t,y:n}=P(e);y.current={x0:t,y0:n,x1:t,y1:n},v(null);return}if(l){m(null);let{x:n,y:r}=P(e),i=N(),a=T.current.k||1,o=s.current,c=d.current,l=c!=null&&o[c]?c:null,_=l==null?void 0:o[l],v=_?GY(_,a)||!!_.angle:!1;if(h.current){let s=t.current,c=_?pwe(M(s,_),n,r,a):null;if(c){g.current={i:l,base:_,live:_,gx:n,gy:r,handle:null,sx:e.clientX,sy:e.clientY,fromEmpty:!1,knob:c};return}let f=I(n,r,i);if(f!=null){d.current=f,u(f),g.current={i:f,base:o[f],live:o[f],gx:n,gy:r,handle:null,sx:e.clientX,sy:e.clientY,fromEmpty:!1,knob:`move`},k();return}l!=null&&(g.current={i:l,base:_,live:_,gx:n,gy:r,handle:null,sx:e.clientX,sy:e.clientY,fromEmpty:!0,idle:!0});return}let y=null;if(_&&_.tool!==`text`&&!v){let e=1/0;for(let t of[0,1]){let a=t===0?_.x0:_.x1,o=t===0?_.y0:_.y1,s=Math.hypot(n-a,r-o);s<=i*1.4&&s<e&&(e=s,y=t)}}let b=I(n,r,i),x=Jwe({sel:l,small:v,handleHit:y,pickHit:b,target:p.current});if(x.kind===`handle`){g.current={i:x.i,base:_,live:_,gx:n,gy:r,handle:x.h,sx:e.clientX,sy:e.clientY,fromEmpty:!1};return}if(x.kind===`pick`){x.i!==l&&(f(null),p.current=null),d.current=x.i,u(x.i),g.current={i:x.i,base:o[x.i],live:o[x.i],gx:n,gy:r,handle:null,sx:e.clientX,sy:e.clientY,fromEmpty:!1},k();return}if(x.kind===`relative`){g.current={i:l,base:_,live:_,gx:n,gy:r,handle:x.h,sx:e.clientX,sy:e.clientY,fromEmpty:!0};return}return}if(r===`text`)return;let{x:n,y:o}=P(e);c.current={tool:r,x0:n,y0:o,x1:n,y1:o,color:i,factor:a,id:C.current++}}function te(e){if(D.current.has(e.pointerId)&&D.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),O.current&&D.current.size>=2){let e=[...D.current.values()],t=Math.hypot(e[0].x-e[1].x,e[0].y-e[1].y),n={x:(e[0].x+e[1].x)/2,y:(e[0].y+e[1].y)/2},r=F({clientX:n.x,clientY:n.y}),i=O.current,a=E.current.k,o=Math.min(a*8,Math.max(a,i.startK*(t/i.startDist)));w({k:o,tx:r.x-i.cx*o,ty:r.y-i.cy*o});return}if(_&&y.current){let{x:t,y:n}=P(e);y.current={...y.current,x1:t,y1:n},k();return}if(l){let n=g.current;if(!n||n.idle)return;let{x:r,y:i}=P(e);if(n.knob){let e=t.current,a=YY(e.getContext(`2d`),e,n.base);n.live=mwe(n.knob,n.base,{x:n.gx,y:n.gy},{x:r,y:i},T.current.k||1,{x:a.x+a.w/2,y:a.y+a.h/2}),k();return}let a=r-n.gx,o=i-n.gy;n.live=n.handle===0?{...n.base,x0:n.base.x0+a,y0:n.base.y0+o}:n.handle===1?{...n.base,x1:n.base.x1+a,y1:n.base.y1+o}:{...n.base,x0:n.base.x0+a,y0:n.base.y0+o,x1:n.base.x1+a,y1:n.base.y1+o},k();return}if(!c.current)return;let{x:n,y:r}=P(e);c.current={...c.current,x1:n,y1:r},k()}function ne(e){if(D.current.delete(e.pointerId),D.current.size<2&&(O.current=null),!(D.current.size>0)){if(_){if(y.current){let e=A(qY(y.current));y.current=null,v(e.w>12&&e.h>12?e:null),k()}}else if(l){let n=g.current;if(g.current=null,n){if(n.fromEmpty&&Math.hypot(e.clientX-n.sx,e.clientY-n.sy)<8){d.current=null,p.current=null,u(null),f(null),k();return}if(n.idle){k();return}let r=t.current,{mark:i,refused:a}=r?Ywe(n.live,n.base,r.width,r.height):{mark:n.live,refused:!1};a?k():o(e=>e.map((e,t)=>t===n.i?{...e,x0:i.x0,y0:i.y0,x1:i.x1,y1:i.y1,angle:i.angle}:e)),m(a?`That would take it off the picture — left where it was.`:null)}else k()}else if(r===`text`){let{x:t,y:n}=P(e);b({x:t,y:n}),x(``),requestAnimationFrame(()=>S.current?.focus())}else if(c.current){let e=c.current;c.current=null;let n=t.current,r=n?WY(e,n.width,n.height):e;r&&(Math.abs(r.x1-r.x0)>6||Math.abs(r.y1-r.y0)>6)?o(e=>[...e,r]):k()}}}return{onDown:ee,onMove:te,onUp:ne}}function sTe(e){let{setShapes:t,readTextRef:n,editRead:r,setEditRead:i,readDraft:a,setReadDraft:o,readInputRef:s}=e;function c(e,n){t(t=>t.map(t=>t.id===e?{...t,...n}:t))}function l(e){i(e.id),o(e.read??``),requestAnimationFrame(()=>s.current?.focus())}function u(){let e=r,t=a.trim();i(null),o(``),s.current?.blur(),e!=null&&(t?n.current.set(e,t):n.current.delete(e),c(e,{read:t||void 0,readErr:t?void 0:`no words on this mark`,readBy:`hand`,reading:!1}))}function d(e){n.current.delete(e.id),c(e.id,{read:void 0,readErr:`words dropped`,readBy:`hand`,reading:!1})}return{patchShape:c,startEditRead:l,commitRead:u,dropRead:d}}var cTe=new Set([`marker`,`rect`,`circle`]),eX=1e4,lTe=2e3;function tX(e){let t=e=>Math.round(e);return[e.tool,t(e.x0),t(e.y0),t(e.x1),t(e.y1),Math.round((e.angle??0)*1e3)].join(`|`)}function uTe(e,t,n){let r=new Map(e.map(e=>[e.id,e])),i=[];for(let e of t.keys()){let t=r.get(e);(!n||!t||t.readBy===`hand`)&&i.push(e)}return n?{start:e.filter(e=>cTe.has(e.tool)&&e.readBy!==`hand`&&t.get(e.id)!==tX(e)),abort:i}:{start:[],abort:i}}function dTe(e,t,n,r){let i={x0:Math.min(e.x0,e.x1),y0:Math.min(e.y0,e.y1),x1:Math.max(e.x0,e.x1),y1:Math.max(e.y0,e.y1)};if(e.tool===`marker`&&i.y1-i.y0<r){let e=(i.y0+i.y1)/2;i={...i,y0:e-r/2,y1:e+r/2}}e.angle&&e.tool!==`marker`&&(i=UY(i,e.angle));let a=Math.max(4,Math.round(Math.min(i.x1-i.x0,i.y1-i.y0)*.08)),o=Math.max(0,Math.floor(i.x0-a)),s=Math.max(0,Math.floor(i.y0-a)),c=Math.min(t,Math.ceil(i.x1+a)),l=Math.min(n,Math.ceil(i.y1+a));return c-o<2||l-s<2?null:{x:o,y:s,w:c-o,h:l-s}}function fTe(e,t){return Math.min(4,lTe/Math.max(e,t,1))}function pTe(e){return(e??``).replace(/\s+/g,` `).trim()||null}function mTe(e){let{canvasRef:t,imgRef:n,setShapes:r,genRef:i,readsRef:a}=e,o=(e,t)=>r(n=>n.map(n=>n.id===e?t(n):n));function s(e){a.current.get(e)?.ctl?.abort(),a.current.delete(e)}function c(){for(let e of[...a.current.keys()])s(e)}function l(e,t){let{start:n,abort:r}=uTe(e,new Map([...a.current].map(([e,t])=>[e,t.key])),!!t);for(let e of r){let t=!!a.current.get(e)?.ctl;s(e),t&&o(e,e=>e.reading?{...e,reading:!1}:e)}if(t)for(let r of n)u(r,e,t)}async function u(e,t,n){s(e.id);let r=new AbortController,c={key:tX(e),ctl:r};a.current.set(e.id,c);let l=i.current;o(e.id,e=>({...e,reading:!0,readErr:void 0,...e.readBy===`phone`?{read:void 0,readBy:void 0}:{}}));let u=setTimeout(()=>r.abort(),eX),f=null,p=`no words found in this mark`;try{let i=await d(e,t);i?f=pTe(await hTe(n.read(i,{signal:r.signal}),r.signal)):p=`this mark is too small to read`}catch{p=r.signal.aborted?`not read within ${eX/1e3} s`:`this phone could not read it`}finally{clearTimeout(u)}a.current.get(e.id)===c&&i.current===l&&(c.ctl=void 0,o(e.id,e=>e.readBy===`hand`?{...e,reading:!1}:f?{...e,reading:!1,read:f,readBy:`phone`,readErr:void 0}:{...e,reading:!1,read:void 0,readBy:void 0,readErr:p}))}async function d(e,r){let i=t.current,a=n.current;if(!i||!a)return null;let o=r.find(t=>t.id===e.id),s=dTe(e,i.width,i.height,KY(i)*5*(o?.factor??1));if(!s)return null;let c=a,l=r.filter(e=>e.tool===`blur`);if(l.length){let e=document.createElement(`canvas`);e.width=i.width,e.height=i.height;let t=e.getContext(`2d`);if(!t)return null;t.drawImage(a,0,0);for(let n of l)ZY(t,e,a,n);c=e}let u=fTe(s.w,s.h),d=document.createElement(`canvas`);d.width=Math.max(1,Math.round(s.w*u)),d.height=Math.max(1,Math.round(s.h*u));let f=d.getContext(`2d`);return f?(f.imageSmoothingEnabled=!0,f.imageSmoothingQuality=`high`,f.drawImage(c,s.x,s.y,s.w,s.h,0,0,d.width,d.height),gH(d,`image/png`)):null}return{sync:l,abortAll:c}}function hTe(e,t){return t.aborted?Promise.reject(Error(`aborted`)):new Promise((n,r)=>{let i=()=>r(Error(`aborted`));t.addEventListener(`abort`,i,{once:!0}),e.then(e=>{t.removeEventListener(`abort`,i),n(e)},e=>{t.removeEventListener(`abort`,i),r(e)})})}function gTe(e){let{source:t,repoId:n,facts:r,onUploaded:i,onDispatch:a,onPark:o,onSendAll:s,canvasRef:c,shapes:l,shapesRef:u,busy:d,setBusy:f,setErr:p,readTextRef:m,redraw:h}=e;function g(){let e=c.current;h(!0);let n=l.length>0,r=gH(e,`image/png`).then(e=>{if(!e)throw Error(`this device could not encode the marked-up image`);return e}),i=Fwe(t).replace(/\.[^.]+$/,``).replace(/[/\\]/g,`_`)||`image`;return{blob:r,name:n?`${i}-marked.png`:`${i}.png`,note:_(e.width,e.height),size:{w:e.width,h:e.height}}}function _(e,t){return Gwe(u.current.map(e=>({...e})).map(e=>({...e,read:m.current.get(e.id)??e.read})),e,t,r)||void 0}async function v(){let e=g();return{...e,blob:await e.blob}}async function y(e=`none`){if(c.current&&!d){if(q(e===`queue`?`action:image.queue`:`action:image.send`),p(null),a)f(!0),a(g(),e);else{f(!0);try{let{blob:e,name:t,note:r,size:a}=await v(),s=async()=>{let e=await Promise.resolve(r);return e?BY(e,a??null):void 0};if(o){let n=await o(e,t);if(n){i(n,await s());return}}try{let r=await U.uploadInbox(n,e,t);r.saved?.[0]&&_j(n,r.saved[0].relPath,r.saved[0].mtime),r.saved?.[0]?i(r.saved[0].relPath,await s()):p(r.skipped?.[0]?.error||`upload failed`)}catch(n){let r=o?await o(e,t):null;r?i(r,await s()):p(String(n))}}catch(e){p(String(e))}finally{f(!1)}}}}function b(e){c.current&&s&&!d&&(q(e===`queue`?`action:image.queue`:`action:image.send`),f(!0),p(null),s(g(),e))}return{send:y,sendAll:b}}function _Te(e){let{canvasRef:t,genRef:n,redraw:r,setOcr:i,setOcrDraft:a,onText:o}=e;async function s(){let e=t.current;if(!e)return;q(`action:image.ocr`);let o=n.current;i({phase:`reading`}),r(!0);let s=await gH(e,`image/jpeg`,.92);if(o!==n.current)return;if(!s){i({phase:`error`,error:`this device could not encode the picture`});return}let c=await U.ocrImage(s);o===n.current&&(`error`in c?i({phase:`error`,error:c.error}):(a(c.text),i({phase:`ready`,engine:c.engine,ms:c.ms})))}function c(){i(null)}function l(e){let t=e.trim();t&&o&&(q(`action:image.ocr.send`),o(t))}return{readAll:s,closeOcr:c,sendText:l}}function vTe(e){let t=(0,H.useRef)(null),[n,r]=(0,H.useState)(null);return(0,H.useEffect)(()=>{let n=t.current,i=e.current;if(!n||!i||typeof ResizeObserver>`u`)return;let a=new ResizeObserver(()=>{let e=n.getBoundingClientRect();r(jwe({w:e.width,h:e.height},i.width?{w:i.width,h:i.height}:null))});return a.observe(n),a.observe(i),()=>a.disconnect()},[e]),{bodyRef:t,side:n}}function yTe({source:e,repoId:t,index:n,total:r,facts:i,onUploaded:a,onDispatch:o,onPark:s,onSkip:c,onSendAll:l,onText:u,onClose:d}){let f=(0,H.useRef)(null),p=(0,H.useRef)(null),m=(0,H.useRef)(null),[h,g]=(0,H.useState)(`circle`),[_,v]=(0,H.useState)(NY[0]),[y,b]=(0,H.useState)(1),[x,S]=(0,H.useState)([]),C=(0,H.useRef)(x);C.current=x;let w=(0,H.useRef)(null),[T,E]=(0,H.useState)(!1),[D,O]=(0,H.useState)(null),k=(0,H.useRef)(D);k.current=D;let[A,j]=(0,H.useState)(null),M=(0,H.useRef)(A);M.current=A;let[N,P]=(0,H.useState)(null),[F,I]=(0,H.useState)(()=>io(B.annKnobs)),[ee,te]=(0,H.useState)(()=>io(B.annHintHidden)),ne=()=>{ao(B.annHintHidden,!0),te(!0)},re=(0,H.useRef)(F);re.current=F;let ie=(0,H.useRef)(null),[ae,oe]=(0,H.useState)(!1),[se,ce]=(0,H.useState)(null),[le,ue]=(0,H.useState)(!1),[de,fe]=(0,H.useState)(null),pe=(0,H.useRef)(null),[me,he]=(0,H.useState)(null),[ge,_e]=(0,H.useState)(``),ve=(0,H.useRef)(null),ye=(0,H.useRef)(1),be=(0,H.useRef)(new Map),xe=(0,H.useRef)(0),[Se,Ce]=(0,H.useState)(null),[we,Te]=(0,H.useState)(``),Ee=(0,H.useRef)(null),De=Ty(),Oe=(0,H.useRef)(new Map),[ke,Ae]=(0,H.useState)(!1),[je,Me]=(0,H.useState)(null),[Ne,Pe]=(0,H.useState)(``),[Fe,Ie]=(0,H.useState)(()=>Dwe(oo(B.annTools,null))),Le=e=>{Ie(e),$a(B.annTools,e)},[Re,ze]=(0,H.useState)(!1),{bodyRef:Be,side:Ve}=vTe(f),He=Fe.place===`auto`?Ve??`auto`:Fe.place,[Ue,We]=(0,H.useState)({k:1,tx:0,ty:0}),Ge=(0,H.useRef)(Ue);Ge.current=Ue;let Ke=(0,H.useRef)({k:1,tx:0,ty:0}),qe=(0,H.useRef)(new Map),Je=(0,H.useRef)(null);(0,H.useEffect)(()=>{let t=null,n=!1;S([]),Me(null),Pe(``),xe.current++,Ce(null),O(null),j(null),P(null),ie.current=null,ce(null),oe(!1);let r=(e,t)=>{let n=f.current;n.width=e,n.height=t;let r=p.current?.getBoundingClientRect();if(r){let n=Math.min(r.width/e,r.height/t),i={k:n,tx:(r.width-e*n)/2,ty:(r.height-t*n)/2};Ke.current=i,We(i)}Ye()},i=async e=>{try{let t=await createImageBitmap(e);return n?void 0:(m.current=t,r(t.width,t.height),!0)}catch{return!1}};return(async()=>{if(e instanceof File){if(await i(e))return;let a=new Image;t=URL.createObjectURL(e),a.onload=()=>{n||(m.current=a,r(a.naturalWidth,a.naturalHeight))},a.onerror=()=>!n&&ce(`Can't decode this image format on this device.`),a.src=t}else try{let t=await fetch(e.url).then(e=>e.blob());await i(t)||ce(`Can't load this image.`)}catch{ce(`Can't load this image.`)}})(),()=>{n=!0,t&&URL.revokeObjectURL(t)}},[e]),(0,H.useEffect)(()=>{document.activeElement?.blur()},[]),(0,H.useEffect)(()=>{let e=p.current;if(!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>{let t=f.current,n=e.getBoundingClientRect();if(!t||!t.width||!t.height||n.width<1||n.height<1)return;let r=Math.min(n.width/t.width,n.height/t.height),i={k:r,tx:(n.width-t.width*r)/2,ty:(n.height-t.height*r)/2},a=Math.abs(Ge.current.k-Ke.current.k)<=Ke.current.k*.02;Ke.current=i,a&&(Ge.current=i,Ye(),We(i))});return t.observe(e),()=>t.disconnect()},[]),(0,H.useEffect)(Ye,[x,le,de,D,T,A,F]),(0,H.useEffect)(()=>{!x.length&&T&&(E(!1),O(null),j(null))},[x.length,T]);function Ye(e=!1){let t=f.current,n=m.current;if(!t||!n)return;let r=t.getContext(`2d`);r.drawImage(n,0,0);let i=ie.current,a=i?C.current.map((e,t)=>t===i.i?i.live:e):C.current,o=w.current?[...a,w.current]:a;for(let e of o)ZY(r,t,n,e);nTe(r,t,zY(a,t.width,t.height)),le&&eTe(r,t,pe.current?qY(pe.current):de);let s=k.current;!e&&!le&&s!=null&&a[s]&&rTe(r,t,a[s],Ge.current.k||1,re.current,M.current)}function Xe(e){return JY(f.current,e)}let Ze={source:e,repoId:t,facts:i,onUploaded:a,onDispatch:o,onPark:s,onSendAll:l,canvasRef:f,wrapRef:p,imgRef:m,tool:h,setTool:g,color:_,setColor:v,factor:y,shapes:x,setShapes:S,shapesRef:C,dragRef:w,moveMode:T,setMoveMode:E,selected:D,setSelected:O,selectedRef:k,target:A,setTarget:j,targetRef:M,setMoveNote:P,setKnobs:I,knobsRef:re,moveRef:ie,busy:ae,setBusy:oe,setErr:ce,cropMode:le,setCropMode:ue,pendingCrop:de,setPendingCrop:fe,cropDrag:pe,pendingText:me,setPendingText:he,textDraft:ge,setTextDraft:_e,textInputRef:ve,idRef:ye,readTextRef:be,genRef:xe,editRead:Se,setEditRead:Ce,readDraft:we,setReadDraft:Te,readInputRef:Ee,setPaletteOpen:Ae,setView:We,viewRef:Ge,fitRef:Ke,pointers:qe,gesture:Je,redraw:Ye,clampToImage:Xe},Qe=aTe(Ze),$e=sTe(Ze),et=oTe(Ze),{send:tt,sendAll:nt}=gTe(Ze),rt=_Te({canvasRef:f,genRef:xe,redraw:Ye,setOcr:Me,setOcrDraft:Pe,onText:u}),it=mTe({canvasRef:f,imgRef:m,setShapes:S,genRef:xe,readsRef:Oe});(0,H.useEffect)(()=>it.sync(x,De),[x,De]),(0,H.useEffect)(()=>()=>it.abortAll(),[]);let at=Ue.k>Ke.current.k*1.02,ot=[...x].reverse().find(e=>e.tool===`marker`||!!De&&(e.tool===`rect`||e.tool===`circle`));return{props:{index:n,total:r,onSkip:c,onSendAll:l,onDispatch:o,onText:u,onClose:d},canvasRef:f,wrapRef:p,tool:h,color:_,setColor:v,factor:y,setFactor:b,shapes:x,setShapes:S,moveMode:T,selected:D,setSelected:O,target:A,setTarget:j,moveNote:N,setMoveNote:P,knobs:F,busy:ae,err:se,cropMode:le,pendingCrop:de,pendingText:me,textDraft:ge,setTextDraft:_e,textInputRef:ve,editRead:Se,setEditRead:Ce,readDraft:we,setReadDraft:Te,readInputRef:Ee,paletteOpen:ke,setPaletteOpen:Ae,view:Ue,fitRef:Ke,layout:Fe,setLayout:Le,configOpen:Re,setConfigOpen:ze,bodyRef:Be,place:He,moveRef:ie,zoomed:at,lastBand:ot,hintHidden:ee,hideHint:ne,...Qe,...$e,...et,send:tt,sendAll:nt,ocr:je,ocrDraft:Ne,setOcrDraft:Pe,...rt}}function bTe(e){let t=yTe(e);Ih(t.ocr!==null,t.closeOcr);let{index:n,total:r,onClose:i}=e;return(0,J.jsxs)(`div`,{className:`sheet`,children:[(0,J.jsx)(gE,{onClose:i,title:r&&r>1?`Mark & send · ${n??1}/${r}`:`Mark & send image`,children:(0,J.jsx)(Cwe,{m:t})}),e.prompt&&(0,J.jsx)(wwe,{prompt:e.prompt}),(0,J.jsx)(Rwe,{m:t}),t.ocr?(0,J.jsx)(zwe,{m:t}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(ywe,{m:t}),(0,J.jsx)(Twe,{m:t})]})]})}var nX=6,rX=0;function xTe(){if(rX)return rX;rX=4096;try{let e=document.createElement(`canvas`).getContext(`webgl`),t=e?.getParameter(e.MAX_TEXTURE_SIZE);typeof t==`number`&&t>0&&(rX=t)}catch{}return rX}function STe(e,t){let n=Math.max(e,t)*(window.devicePixelRatio||1);return n?tm(xTe()/n,2,nX):nX}function iX({src:e,alt:t,onNav:n,onError:r}){let i=(0,H.useRef)(null),a=(0,H.useRef)(null),[o,s]=(0,H.useState)({s:1,x:0,y:0}),[c,l]=(0,H.useState)(!1),u=(0,H.useRef)(o);u.current=o;let d=(0,H.useRef)(new Map),f=(0,H.useRef)(null),p=(0,H.useRef)(null),m=(0,H.useRef)(0),[h,g]=(0,H.useState)(null);(0,H.useEffect)(()=>{s({s:1,x:0,y:0})},[e]);function _(e,t=!1){let n=a.current,r=i.current,o=Number.isFinite(e.s)?tm(e.s,1,nX):1;n&&n.offsetWidth&&(o=Math.min(o,STe(n.offsetWidth,n.offsetHeight)));let s=Number.isFinite(e.x)?e.x:0,c=Number.isFinite(e.y)?e.y:0;if(n&&r){let e=Math.max(0,(n.offsetWidth*o-r.clientWidth)/2),i=Math.max(0,(n.offsetHeight*o-r.clientHeight)/2);t||(s=tm(s,-e,e)),c=tm(c,-i,i)}return{s:o,x:s,y:c}}let v=()=>{let e=[...d.current.values()];return e.length>=2?e:null};function y(){let e=v();if(!e)return;let t=Math.hypot(e[0].x-e[1].x,e[0].y-e[1].y),n=i.current?.getBoundingClientRect(),r=n?n.left+n.width/2:0,a=n?n.top+n.height/2:0;f.current={dist:t||1,mx:(e[0].x+e[1].x)/2-r,my:(e[0].y+e[1].y)/2-a,s:u.current.s,x:u.current.x,y:u.current.y},p.current=null}function b(e){if(e.target.setPointerCapture?.(e.pointerId),d.current.set(e.pointerId,{x:e.clientX,y:e.clientY}),l(!0),d.current.size>=2)y();else{let t=e.timeStamp;t-m.current<300?(s(e=>_(e.s>1?{s:1,x:0,y:0}:{s:2.5,x:0,y:0})),m.current=0):m.current=t,p.current={x:e.clientX,y:e.clientY,tx:u.current.x,ty:u.current.y}}}function x(e){let t=d.current.get(e.pointerId);if(!t)return;t.x=e.clientX,t.y=e.clientY;let r=v();if(r&&f.current){e.stopPropagation();let t=f.current,n=Math.hypot(r[0].x-r[1].x,r[0].y-r[1].y),a=i.current?.getBoundingClientRect(),o=(r[0].x+r[1].x)/2-(a?a.left+a.width/2:0),c=(r[0].y+r[1].y)/2-(a?a.top+a.height/2:0),l=tm(t.s*n/t.dist,1,nX);s(_({s:l,x:o-(t.mx-t.x)*(l/t.s),y:c-(t.my-t.y)*(l/t.s)}))}else if(p.current&&u.current.s>1){e.stopPropagation();let t=p.current;s(n=>_({s:n.s,x:t.tx+(e.clientX-t.x),y:t.ty+(e.clientY-t.y)}))}else if(p.current&&n){let t=p.current;s(n=>({...n,x:t.tx+(e.clientX-t.x)}))}}function S(e){if(d.current.delete(e.pointerId),d.current.size<2&&(f.current=null),d.current.size===1){let[e]=[...d.current.values()];p.current={x:e.x,y:e.y,tx:u.current.x,ty:u.current.y}}if(d.current.size===0){if(l(!1),p.current&&u.current.s<=1&&n&&e.type!==`pointercancel`){let t=e.clientX-p.current.x,r=e.clientY-p.current.y;Math.abs(t)>60&&Math.abs(t)>Math.abs(r)*1.5&&n(t<0?1:-1)}s(e=>e.s<=1?{s:1,x:0,y:0}:_(e)),p.current=null}}let C=o.s>1.01;return(0,J.jsxs)(`div`,{ref:i,className:`zoom-stage`,onPointerDown:b,onPointerMove:x,onPointerUp:S,onPointerCancel:S,children:[h===e?(0,J.jsxs)(`div`,{className:`img-missing`,children:[(0,J.jsx)(_s,{size:22}),(0,J.jsx)(`span`,{className:`img-missing-name`,children:t}),(0,J.jsx)(`span`,{children:`couldn’t load this image — the host may be unreachable`})]}):(0,J.jsx)(`img`,{ref:a,src:e,alt:t,draggable:!1,onLoad:()=>s(e=>_(e)),onError:()=>{g(e),r?.()},style:{transform:`translate(${o.x}px, ${o.y}px) scale(${o.s})`,willChange:c?`transform`:`auto`}}),C&&(0,J.jsxs)(`button`,{className:`zoom-reset`,"aria-label":`reset zoom`,onPointerDown:e=>e.stopPropagation(),onClick:e=>{e.stopPropagation(),s({s:1,x:0,y:0})},children:[(0,J.jsx)(yc,{size:16}),` `,o.s.toFixed(1),`×`]})]})}function CTe({items:e,index:t,onIndex:n,onAnnotate:r,onReference:i,onClose:a}){let o=e[t],[s,c]=(0,H.useState)(!1);(0,H.useEffect)(()=>{c(!1)},[t]);let l=r=>{let i=t+r;i>=0&&i<e.length&&n(i)};return(0,H.useEffect)(()=>{let e=e=>{e.key===`ArrowRight`?l(1):e.key===`ArrowLeft`?l(-1):e.key===`Escape`&&(e.preventDefault(),a())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)}),(0,H.useEffect)(()=>{o||a()},[o,a]),o?(0,J.jsxs)(`div`,{className:`viewer`,onClick:a,children:[(0,J.jsx)(`button`,{className:`viewer-close`,onClick:a,"aria-label":`close`,children:(0,J.jsx)(V,{size:22})}),(0,J.jsxs)(`div`,{className:`viewer-body`,onClick:e=>e.stopPropagation(),children:[o.video?(0,J.jsx)(`video`,{className:`viewer-video`,src:o.url,controls:!0,autoPlay:!0,playsInline:!0},o.relPath):(0,J.jsx)(iX,{src:s&&o.fullUrl?o.fullUrl:o.url,alt:o.name,onNav:e.length>1?l:void 0},`${o.relPath}:${s?`full`:`fit`}`),(0,J.jsx)(`div`,{className:`viewer-path mono`,children:o.relPath}),(0,J.jsxs)(`div`,{className:`sheet-actions`,children:[e.length>1&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Y,{onClick:()=>l(-1),disabled:t===0,"aria-label":`previous`,children:(0,J.jsx)(Hl,{size:16})}),(0,J.jsxs)(`span`,{className:`viewer-count`,children:[t+1,` / `,e.length]}),(0,J.jsx)(Y,{onClick:()=>l(1),disabled:t===e.length-1,"aria-label":`next`,children:(0,J.jsx)(jl,{size:16})})]}),!o.video&&o.fullUrl&&o.fullUrl!==o.url&&!s&&(0,J.jsx)(Y,{title:`load the original file instead of the screen-sized copy`,onClick:()=>c(!0),children:`full res`}),!o.video&&r&&(0,J.jsxs)(Y,{onClick:()=>r(o),children:[(0,J.jsx)(us,{size:16}),` mark`]}),o.repoId&&(0,J.jsx)(FO,{target:{repoId:o.repoId,relPath:o.relPath,name:o.name},trackId:`action:swipe.download`}),(0,J.jsx)(`button`,{className:`send`,onClick:()=>i(o),children:`ref path`})]})]})]}):null}function wTe(){let e=K(gJ);return e?(0,J.jsx)(uwe,{files:e.files,onCombine:DCe,onSeparate:OCe,onClose:kCe}):null}function aX(){let e=K(mJ);return EY()&&!!e&&wJ.ret===`session`&&!!W().world.active}function TTe(){let e=K(mJ),t=aX();if(!e)return null;let n=wJ.ret===`session`,r=!!e.total&&e.total>1,i=W(),a=n&&!t&&i.world.active?{value:i.compose.draft,onChange:e=>{W().compose.typeOn(W().compose.draft,e)||W().say.toast(`The message box changed meanwhile — that key was not applied`)}}:void 0;return(0,J.jsx)(bTe,{prompt:a,source:e.source,repoId:e.repoId,index:e.index,total:e.total,facts:e.facts,onUploaded:ICe,onDispatch:n?NCe:void 0,onPark:MCe,onSkip:r?PCe:void 0,onSendAll:r&&n?FCe:void 0,onText:LCe,onClose:lY})}function ETe(){let e=K(_J),t=K(SJ);if(!e)return null;let n=e.sessionId?jJ(t.get(e.sessionId)??[]):[],r=e.items??n.map(e=>({name:e.name,relPath:e.relPath,url:OJ(e.relPath)?U.artifactUrl(e.repoId,e.relPath):sg(U.artifactUrl(e.repoId,e.relPath),og(),e.mtime),fullUrl:U.artifactUrl(e.repoId,e.relPath),video:OJ(e.relPath)}));return(0,J.jsx)(CTe,{items:r,index:Math.min(e.i,Math.max(0,r.length-1)),onIndex:e=>zJ(t=>t&&{...t,i:e}),onAnnotate:e.revoke?void 0:e=>qCe(e,n),onReference:e=>JCe(e,n),onClose:HJ})}var oX=[{label:`10m`,long:`10 minutes`,secs:600},{label:`4h`,long:`4 hours`,secs:14400},{label:`24h`,long:`24 hours`,secs:86400}];function sX(e){return e===`outbox`?14400:void 0}var DTe=[{label:`images`,value:`image`},{label:`docs`,value:`doc`}],cX=4e5,OTe={new:`new — not opened on this device yet`,opened:`opened in ${L.name} on this device`,downloaded:`downloaded to this phone`};function lX(e){if(!e)return``;let t=Date.now()-e,n=Math.floor(t/6e4);if(n<1)return`just now`;if(n<60)return`${n}m ago`;let r=Math.floor(n/60);return r<24?`${r}h ago`:new Date(e).toLocaleDateString(void 0,{month:`short`,day:`numeric`})}function uX(e){return e?new Date(e).toLocaleString():``}var dX=(e,t)=>t.repoId??e,fX=(e,t,n)=>e===`inbox`?U.inboxUrl(dX(t,n),n.name):U.artifactUrl(dX(t,n),n.relPath),pX=(e,t,n)=>sg(fX(e,t,n),ag(140),n.mtime),kTe=(e,t,n,r)=>n?fX(e,t,r):sg(fX(e,t,r),og(),r.mtime),ATe=e=>nO(e.relPath)&&(e.size??0)>=49152;function jTe({openFile:e,onClose:t}){let[n,r]=(0,H.useState)(e?{...e,size:e.size??0,mtime:e.mtime??0,ctime:e.mtime??0}:null),i=(0,H.useRef)(!!e),a=e=>{i.current=!1,r(e)};return Ih(n!==null&&!i.current,()=>a(null)),{open:n,showFile:a,closeDoc:()=>{i.current?(i.current=!1,t()):a(null)}}}function MTe({repoId:e,repos:t,initialScope:n,initialAllTime:r,initialNew:i}){let a=!!e,o=n??(a?`outbox`:`all`),[s,c]=(0,H.useState)(o),l=i?Math.max(1,Math.ceil((Date.now()-i.since)/1e3)):void 0,[u,d]=(0,H.useState)(l??(r?void 0:sX(o))),[f,p]=(0,H.useState)(!!l),m=e=>{c(e),d(sX(e)),P(60),p(!1)},[h,g]=(0,H.useState)(`all`),[_,v]=(0,H.useState)(``),[y,b]=(0,H.useState)([]),[x,S]=(0,H.useState)(!1),[C,w]=(0,H.useState)(!0),[T,E]=(0,H.useState)(null),[D,O]=(0,H.useState)(null),[k,A]=(0,H.useState)(null),[j,M]=(0,H.useState)(0),[N,P]=(0,H.useState)(60),F=(t??[]).map(e=>e.id).join(`,`),I={kind:h,since:s===`inbox`?void 0:u},ee=lte(s,e,F);return(0,H.useEffect)(()=>{let t=!1,n=new AbortController,r=!1;w(!0),E(null),A(null);let i=(n,i,a)=>{if(!t&&(r=!0,b(n),S(i),w(!1),E(null),O(null),vj(n,e),!_.trim())){let e=a??{rows:n,cov:I,truncated:i};SC(ee,e.cov,e.rows,e.truncated)}},a=async n=>{let i=await CC(ee,I);if(t||r)return!1;if(!i)return n&&w(!1),!1;let a=Yi(i.rows,{...I,query:_},iO,Date.now());return vj(a,e),b(a.slice(0,N)),S(a.length>N||i.exact&&i.truncated),O(i.savedAt),n&&w(!1),!0};a(!1);let o=e=>{t||a(!0).then(n=>{if(t)return;w(!1);let r=Ba(e)?`the host didn't answer`:String(e?.message||e||`request failed`);A(n?r:null),E(n?null:r)})};return s===`all`?U.search({query:_,kind:h,scope:`repo`,sinceSeconds:u,repoIds:F?F.split(`,`):void 0,limit:N,signal:n.signal}).then(e=>i(e.hits,e.truncated)).catch(o):s===`inbox`?(U.markInboxSeen(e),U.inbox(e,n.signal).then(e=>{let t=Yi(e,{kind:h,query:_},iO,Date.now());i(t.slice(0,N),t.length>N,{rows:e,cov:{kind:`all`},truncated:!1})}).catch(o)):(s===`outbox`&&U.markOutboxSeen(e),U.artifacts(e,s,u,{query:_,kind:h,limit:N,signal:n.signal}).then(e=>i(e.files,e.truncated)).catch(o)),()=>{t=!0,n.abort()}},[e,F,s,u,h,_,j,N]),(0,H.useEffect)(()=>{D!=null||T||_ge(y.filter(e=>nO(e.relPath)||rO(e.relPath)).slice(0,24).map(t=>pX(s,e,t)))},[y,D,T]),(0,H.useEffect)(()=>{P(60)},[u,h,_,e]),{singleRepo:a,scope:s,changeScope:m,since:u,setSince:d,newSecs:l,onNewCut:f,setOnNewCut:p,kind:h,setKind:g,query:_,setQuery:v,files:y,truncated:x,loading:C,loadErr:T,cachedAt:D,staleWhy:k,setReload:M,setLimit:P}}function NTe({open:e,scope:t,repoId:n}){let[r,i]=(0,H.useState)(!1),[a,o]=(0,H.useState)(null),[s,c]=(0,H.useState)(null),[l,u]=(0,H.useState)(null),[d,f]=(0,H.useState)(!1),[p,m]=(0,H.useState)(0);return(0,H.useEffect)(()=>{i(!1)},[e?.relPath,e?.repoId]),(0,H.useEffect)(()=>{e&&t!==`inbox`&&(Qde(dX(n,e),e.relPath,e.mtime),m(e=>e+1))},[e?.relPath,e?.repoId,t]),(0,H.useEffect)(()=>{if(c(null),f(!1),u(null),!e||!uO(e.relPath)){o(null);return}let r=new AbortController,i=!1,a=e.relPath,s=dX(n,e),l=e.mtime,d=l>0,p=async()=>{let e=d?await FC(s,a,l):null;return r.signal.aborted||i||!e?!1:(o({path:a,text:e.text,truncated:e.truncated}),u(e.savedAt),!0)};return p(),fp(fX(t,n,e),{signal:r.signal}).then(e=>e.ok?e.text():Promise.reject(Error(`HTTP ${e.status}`))).then(e=>{if(r.signal.aborted)return;i=!0;let t={path:a,text:e.slice(0,cX),truncated:e.length>cX};o(t),u(null),d&&PC(s,a,l,t.text,t.truncated)}).catch(e=>{r.signal.aborted||p().then(t=>{r.signal.aborted||t||(o(null),c(Ba(e)?`the host didn't answer, and this device has no saved copy`:String(e?.message||e)))})}),()=>r.abort()},[e?.relPath,e?.repoId,t]),{fullRes:r,setFullRes:i,doc:a,docErr:s,docCachedAt:l,docRaw:d,setDocRaw:f,markTick:p,setMarkTick:m}}function PTe(e,t,n){let r=n(t);return e.some(e=>n(e)===r)?e.filter(e=>n(e)!==r):[...e,t]}function FTe(e){return e===0?`Tap the pictures to combine, in the order you want them numbered.`:e===1?`1 picked — tap one more: a combined picture needs at least two.`:`${e} picked, numbered in the order you tapped them.`}function ITe(e){let[t,n]=(0,H.useState)(null),r=t=>`${e.repoOf(t)}:${t.relPath}`;return{picked:t,pickIndex:e=>t?t.findIndex(t=>r(t)===r(e)):-1,canPick:!!e.onCombine&&e.singleRepo&&e.files.filter(e=>nO(e.relPath)).length>=2,startPick:()=>{q(`action:gallery.pick`),n([])},cancelPick:()=>n(null),togglePicked:e=>{nO(e.relPath)&&n(t=>PTe(t??[],e,r))},combinePicked:()=>{if(!t||t.length<2||!e.onCombine)return;q(`action:gallery.combine`);let r=t.map(t=>({url:e.urlFor(t),name:t.name,repoId:e.repoOf(t)}));n(null),e.onCombine(r)}}}function LTe(e){let{repoId:t,openFile:n,onClose:r}=e,{open:i,showFile:a,closeDoc:o}=jTe({openFile:n,onClose:r}),[s,c]=(0,H.useState)(null),[l,u]=(0,H.useState)(null),d=e=>{u(e),window.setTimeout(()=>u(t=>t===e?null:t),4e3)},[f,p]=(0,H.useState)(new Set),m=e=>p(t=>t.has(e)?t:new Set(t).add(e)),[h,g]=(0,H.useState)([]);(0,H.useEffect)(()=>gS.subscribe(g),[]);let _=MTe(e),{scope:v,files:y,loading:b,setReload:x}=_,S=NTe({open:i,scope:v,repoId:t}),{fullRes:C,docRaw:w,markTick:T}=S,E=e=>e&&b?(0,J.jsxs)(J.Fragment,{children:[` `,(0,J.jsx)(Ul,{size:12,className:`spin`})]}):null,D=e=>dX(t,e),O=e=>fX(v,t,e),k=e=>pX(v,t,e),A=e=>kTe(v,t,C,e),j=e=>v===`inbox`||e.relPath.startsWith(`.claude/inbox/`),M=e=>{if(v===`inbox`)return null;let t=OO(D(e),e.relPath,e.mtime);return t===`new`&&v!==`outbox`?null:t},N=e=>{let t=D(e);return h.find(n=>n.item.repoId===t&&n.item.relPath===e.relPath&&Math.round(n.item.mtime)===Math.round(e.mtime))},P=e=>({repoId:D(e),relPath:e.relPath,name:e.name,size:e.size,mtime:e.mtime,repoName:e.repoName}),F=e=>{let t=ix(e);return t.phase===`have`||t.phase===`saved`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(go,{size:11}),` on phone`]}):t.phase===`downloading`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Ul,{size:11,className:`spin`}),` `,t.pct,`%`]}):t.phase===`failed`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Js,{size:11}),` stopped`]}):t.phase===`idle`?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(rs,{size:11}),` was here`]}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Rs,{size:11}),` queued`]})},I=i?N(i):void 0,ee=I?.state===`done`?I.item.id:null,[te,ne]=(0,H.useState)(null);(0,H.useEffect)(()=>{if(ne(null),!ee)return;let e=null,t=!1;return gS.objectUrl(ee).then(n=>{n&&(t?URL.revokeObjectURL(n):(e=n,ne(n)))}),()=>{t=!0,e&&URL.revokeObjectURL(e)}},[ee]);let re=e=>te??A(e),ie=e=>te??O(e),ae=!!i&&sO(i.relPath)&&!w,oe=y.filter(e=>nO(e.relPath)),se=i?oe.findIndex(e=>e.relPath===i.relPath&&e.repoId===i.repoId):-1;function ce(e){let t=se>=0?oe[se+e]:void 0;t&&a(t)}(0,H.useEffect)(()=>{if(!i)return;let e=e=>{e.key===`ArrowRight`?ce(1):e.key===`ArrowLeft`?ce(-1):e.key===`Escape`&&(e.preventDefault(),o())};return window.addEventListener(`keydown`,e),()=>window.removeEventListener(`keydown`,e)});async function le(e){try{return await U.deleteInbox(D(e),e.name),x(e=>e+1),!0}catch(t){return d(Ba(t)?`Could not delete ${e.name} — the host didn't answer. The file is still on the desktop.`:`Could not delete ${e.name} — ${String(t?.message||t)}`),!1}}async function ue(e){q(`action:gallery.delete`),await le(e)&&a(null)}let de=ITe({onCombine:e.onCombine,singleRepo:_.singleRepo,files:y,repoOf:D,urlFor:O});async function fe(e){let t=await gp(e);c(t?e:null),setTimeout(()=>c(null),1500)}return{props:e,..._,...S,open:i,showFile:a,closeDoc:o,copied:s,note:l,badSrc:f,markBad:m,busyMark:E,repoOf:D,urlFor:O,thumbFor:k,canFullRes:ATe,isInboxFile:j,markOf:M,pullOf:N,dlTarget:P,pullBadge:F,localUrl:te,mediaSrc:re,fileSrc:ie,htmlLive:ae,imgs:oe,openIdx:se,nav:ce,removeInbox:le,del:ue,copy:fe,...de}}function RTe(e,t,n,r){let i=`${e} new since you last looked`;return n||t===e?i:r?`${i} · newest ${t} shown`:`${i} · ${t} still here`}function zTe(e){let t=oX.find(t=>t.secs===e);return t?`Nothing from the last ${t.long}.`:null}function BTe({m:e}){let{scope:t,loading:n,singleRepo:r,changeScope:i,kind:a,setKind:o,since:s,setSince:c,newSecs:l,onNewCut:u,setOnNewCut:d}=e,{initialNew:f}=e.props,p=(e,r)=>(0,J.jsxs)(`button`,{className:`seg${t===e?` on`:``}${t===e&&n?` busy`:``}`,"aria-pressed":t===e,onClick:()=>i(e),children:[r,t===e&&n?(0,J.jsx)(Ul,{size:13,className:`spin`}):null]}),m=(e,t,r,i)=>(0,J.jsx)(pE,{on:e,busy:e&&n,title:i,onClick:r,children:t}),h=()=>{c(void 0),d(!1)};return(0,J.jsxs)(J.Fragment,{children:[r&&(0,J.jsxs)(`div`,{className:`segmented gallery-scope`,children:[p(`inbox`,`inbox`),p(`outbox`,`outbox`),p(`repo`,`this repo`),p(`all`,`all repos`)]}),(0,J.jsxs)(`div`,{className:`fchips gallery-filters`,children:[DTe.map(e=>(0,J.jsx)(H.Fragment,{children:m(a===e.value,e.label,()=>o(a===e.value?`all`:e.value))},e.value)),t!==`inbox`&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`span`,{className:`fchips-gap`,"aria-hidden":!0}),l!==void 0&&m(u,`${f.count} new`,()=>{u?h():(c(l),d(!0))},`the ${f.count} file${f.count>1?`s`:``} added since you last opened this outbox — the badge you tapped`),oX.map(e=>(0,J.jsx)(H.Fragment,{children:m(!u&&s===e.secs,e.label,()=>{!u&&s===e.secs?h():(c(e.secs),d(!1))},`only files from the last ${e.long}`)},e.label))]})]})]})}function VTe({m:e}){let{scope:t,loading:n,files:r,truncated:i,query:a,setQuery:o,singleRepo:s,setSince:c,onNewCut:l,setOnNewCut:u,loadErr:d,setReload:f,cachedAt:p,staleWhy:m,note:h,open:g}=e,{onClose:_,onSweep:v,onSurvey:y,initialNew:b}=e.props,x=r.length;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(gE,{title:`Images & documents`,onClose:_,children:[(x>0||n)&&(0,J.jsx)(`span`,{className:`gallery-meta`,title:no()?void 0:`build cc85ddc9`,children:n&&!x?(0,J.jsx)(Ul,{size:12,className:`spin`}):`${x}${i?`+`:``} file${x===1&&!i?``:`s`}`}),v&&s&&(t===`inbox`||t===`outbox`)&&(0,J.jsx)(Y,{className:`gallery-head-btn`,title:`clear out old ${t} files`,"aria-label":`clear out old ${t} files`,onClick:()=>v(t),children:(0,J.jsx)(ic,{size:17})}),y&&t===`all`&&(0,J.jsx)(Y,{className:`gallery-head-btn`,title:`what is taking space, repo by repo`,"aria-label":`what is taking space`,onClick:y,children:(0,J.jsx)(Es,{size:17})})]}),(0,J.jsx)(`div`,{className:`form`,children:(0,J.jsxs)(`div`,{className:`search-row`,children:[(0,J.jsx)(Lc,{size:16}),(0,J.jsx)(`input`,{className:`search`,placeholder:t===`all`?`Search every repo by name`:`Search by name`,value:a,onChange:e=>o(e.target.value)}),a&&(0,J.jsx)(Y,{"aria-label":`clear the search`,onClick:()=>o(``),children:(0,J.jsx)(V,{size:14})})]})}),(0,J.jsx)(BTe,{m:e}),l&&(0,J.jsx)(cE,{onClear:()=>{c(void 0),u(!1)},clearLabel:`show all`,children:RTe(b.count,x,n,i)}),d&&(0,J.jsxs)(`div`,{className:`gallery-note err`,children:[(0,J.jsx)(Js,{size:14}),(0,J.jsxs)(`span`,{children:[`Could not load the list (`,d,`)`,x?` — showing what was already loaded`:``,`.`]}),(0,J.jsxs)(Y,{onClick:()=>f(e=>e+1),children:[(0,J.jsx)($c,{size:14}),` retry`]})]}),p!=null&&(0,J.jsxs)(`div`,{className:`gallery-note`,children:[(0,J.jsx)(Hs,{size:14}),(0,J.jsx)(`span`,{children:m?`Showing the list this phone last saw, ${lX(p)} — ${m}.`:`Showing the list this phone last saw, ${lX(p)} — refreshing…`}),m&&(0,J.jsxs)(Y,{onClick:()=>f(e=>e+1),children:[(0,J.jsx)($c,{size:14}),` retry`]})]}),h&&!g&&(0,J.jsx)(`div`,{className:`gallery-note`,children:h})]})}var HTe=[[/^(md|markdown|txt|log|rst|pdf)$/,Nl],[/^(html?|json|ya?ml|toml|xml|js|mjs|ts|tsx|css|sh|py|diff|patch)$/,ire],[/^(csv|tsv|xlsx?|ods)$/,cre],[/^(zip|tar|gz|tgz|7z|rar)$/,Dne],[/^(apk|aab|ipa)$/,ql],[/^(mp3|m4a|wav|ogg|opus|flac|aac)$/,Hne]];function UTe({name:e}){let t=e.lastIndexOf(`.`),n=t>0?e.slice(t+1).toLowerCase():``,r=HTe.find(([e])=>e.test(n))?.[1]??Mc;return(0,J.jsxs)(`span`,{className:`doc`,"aria-hidden":!0,children:[(0,J.jsx)(r,{size:30,strokeWidth:1.5}),n&&(0,J.jsx)(`span`,{className:`doc-ext`,children:n})]})}function WTe({url:e,name:t,missing:n,onMissing:r}){let{src:i,live:a}=jj(e);return n?(0,J.jsxs)(`span`,{className:`img-missing`,children:[(0,J.jsx)(_s,{size:18}),(0,J.jsx)(`span`,{className:`img-missing-name`,children:t})]}):i?(0,J.jsx)(`img`,{src:i,alt:t,loading:`lazy`,decoding:`async`,onLoad:()=>{a&&Oj(e)},onError:r}):(0,J.jsx)(`span`,{className:`thumb-blank`})}function GTe({src:e,poster:t,name:n}){let{src:r,live:i}=jj(t);return(0,H.useEffect)(()=>{i&&Oj(t)},[i,t]),(0,J.jsx)(`video`,{src:e,poster:r??void 0,title:n,muted:!0,playsInline:!0,preload:`none`})}function KTe({m:e}){let{picked:t,canPick:n,startPick:r,cancelPick:i,combinePicked:a}=e;return t?(0,J.jsxs)(`div`,{className:`annot-tools gallery-pick on`,children:[(0,J.jsx)(`span`,{className:`viewer-doc-note`,children:FTe(t.length)}),(0,J.jsxs)(Y,{onClick:i,children:[(0,J.jsx)(V,{size:14}),` cancel`]}),t.length>=2&&(0,J.jsxs)(`button`,{className:`send`,onClick:a,children:[(0,J.jsx)(Wc,{size:14}),` combine `,t.length]})]}):n?(0,J.jsx)(`div`,{className:`annot-tools gallery-pick`,children:(0,J.jsxs)(Y,{"aria-label":`pick pictures to combine`,onClick:r,children:[(0,J.jsx)(Wc,{size:14}),` combine pictures…`]})}):null}function qTe({m:e}){let{files:t,loading:n,loadErr:r,query:i,kind:a,scope:o,truncated:s,showFile:c,badSrc:l,markBad:u,urlFor:d,thumbFor:f,markOf:p,pullOf:m,pullBadge:h,isInboxFile:g,removeInbox:_,setLimit:v,onNewCut:y,since:b,setSince:x,setOnNewCut:S}=e,C=e=>y&&p(e)===`new`?null:p(e),w=o!==`inbox`&&!y?zTe(b):null,{picked:T,pickIndex:E,togglePicked:D}=e;return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(KTe,{m:e}),(0,J.jsxs)(`div`,{className:`grid${n&&t.length?` stale`:``}`,children:[t.map(e=>(0,J.jsxs)(`div`,{className:`thumb-wrap${E(e)>=0?` picked`:``}`,children:[T&&E(e)>=0&&(0,J.jsx)(`span`,{className:`thumb-pick`,"aria-hidden":`true`,children:E(e)+1}),(0,J.jsxs)(`button`,{className:`thumb`,"aria-pressed":T&&nO(e.relPath)?E(e)>=0:void 0,onClick:()=>T?D(e):c(e),children:[nO(e.relPath)?(0,J.jsx)(WTe,{url:f(e),name:e.name,missing:l.has(f(e)),onMissing:()=>u(f(e))}):rO(e.relPath)?(0,J.jsx)(GTe,{src:d(e),poster:f(e),name:e.name}):(0,J.jsx)(UTe,{name:e.name}),(0,J.jsx)(`span`,{className:`thumb-name`,children:e.name}),(0,J.jsxs)(`span`,{className:`thumb-date`,title:uX(e.ctime??e.mtime),children:[lX(e.ctime??e.mtime),e.size?(0,J.jsxs)(`span`,{className:`thumb-size`,children:[` · `,zp(e.size)]}):null]}),e.repoName&&(0,J.jsx)(`span`,{className:`thumb-repo`,children:e.repoName}),(0,J.jsxs)(`span`,{className:`thumb-badges`,children:[C(e)&&!m(e)&&(0,J.jsx)(`span`,{className:`thumb-mark ${C(e)}`,title:OTe[C(e)],children:C(e)===`new`?(0,J.jsx)(`span`,{className:`sr-only`,children:`new`}):C(e)===`downloaded`?(0,J.jsx)(rs,{size:11}):(0,J.jsx)(as,{size:11})}),m(e)&&(0,J.jsx)(`span`,{className:`thumb-pull ${m(e).state}`,title:ix(m(e)).detail,children:h(m(e))})]})]}),g(e)&&(0,J.jsx)(uT,{className:`thumb-del`,title:`delete ${e.name}`,confirmTitle:`tap again to delete ${e.name}`,confirm:(0,J.jsx)(Js,{size:14}),onConfirm:()=>{_(e)},children:(0,J.jsx)(ic,{size:14})})]},`${e.repoId??``}:${e.relPath}`)),t.length===0&&n&&Array.from({length:8},(e,t)=>(0,J.jsx)(`div`,{className:`thumb-wrap`,children:(0,J.jsx)(`div`,{className:`thumb skel-thumb`})},`skel-${t}`)),t.length===0&&!n&&!r&&(0,J.jsx)($,{children:i||a!==`all`?`No matches.`:w?(0,J.jsxs)(J.Fragment,{children:[w,` `,(0,J.jsx)(`button`,{className:`link-btn`,onClick:()=>{x(void 0),S(!1)},children:`show older files`})]}):o===`outbox`?`The outbox is empty. Claude puts screenshots and files meant for your phone in .claude/outbox. To see images anywhere in the repo, switch to this repo.`:`Nothing here yet.`})]}),s&&(0,J.jsxs)(`div`,{className:`annot-tools`,children:[(0,J.jsxs)(Y,{onClick:()=>{q(`action:gallery.more`),v(e=>e+60)},children:[`load `,60,` more`]}),(0,J.jsxs)(`span`,{className:`viewer-doc-note`,children:[`showing the newest `,t.length]})]})]})}function mX(e){let{onContinueInSession:t,sessionsIn:n}=e.props;return t&&n?n(e.repoId):[]}function hX(e,t){q(t?`action:gallery.toSession`:`action:gallery.toNewSession`),e.setPicking(!1),e.props.onContinueInSession?.(e.relPath,e.repoId,t)}function JTe(e){if(!e.props.onContinueInSession)return null;let t=mX(e);return(0,J.jsxs)(J.Fragment,{children:[t.length===1&&(0,J.jsxs)(Y,{title:`put this file's path in that session's prompt`,onClick:()=>hX(e,t[0].id),children:[(0,J.jsx)(Go,{size:16}),` `,t[0].label]}),t.length>1&&(0,J.jsxs)(Y,{title:`pick which live session gets this file's path`,onClick:()=>e.setPicking(!e.picking),children:[(0,J.jsx)(Go,{size:16}),` session · `,t.length]}),(0,J.jsxs)(Y,{title:`start a new session in this repo with this file's path in its prompt`,onClick:()=>hX(e,null),children:[(0,J.jsx)(os,{size:16}),` new session`]})]})}function YTe(e){let t=mX(e);return!e.picking||t.length<2?null:(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`div`,{className:`viewer-doc-note`,children:[t.length,` live sessions in `,e.repoName||`this repo`,` — the path goes into the prompt of the one you pick`]}),(0,J.jsx)(`div`,{className:`list`,children:t.map(t=>(0,J.jsxs)(xE,{as:`button`,onClick:()=>hX(e,t.id),children:[(0,J.jsxs)(SE,{children:[(0,J.jsx)(xo,{size:14}),` `,t.label]}),t.onScreen&&(0,J.jsx)(Q,{children:`on screen behind the gallery`})]},t.id))})]})}function XTe({m:e}){let{open:t,closeDoc:n,repoOf:r,localUrl:i,fullRes:a,mediaSrc:o,fileSrc:s,imgs:c,nav:l,setDocRaw:u,docRaw:d,doc:f,docErr:p,docCachedAt:m,htmlLive:h,pullOf:g,dlTarget:_,files:v,showFile:y,openIdx:b,copied:x,copy:S,canFullRes:C,setFullRes:w,urlFor:T,setMarkTick:E,isInboxFile:D,del:O,note:k}=e,{onAnnotate:A,onInsertPath:j,onClose:M}=e.props,[N,P]=(0,H.useState)(null);if(!t)return null;let F={relPath:t.relPath,repoId:r(t),repoName:t.repoName,props:e.props,picking:N===t.relPath,setPicking:e=>P(e?t.relPath:null)};return(0,J.jsxs)(`div`,{className:`viewer`,onClick:()=>n(),children:[(0,J.jsx)(`button`,{className:`viewer-close`,onClick:()=>n(),"aria-label":`close`,children:(0,J.jsx)(V,{size:22})}),(0,J.jsxs)(`div`,{className:`viewer-body`,onClick:e=>e.stopPropagation(),children:[nO(t.relPath)?(0,J.jsx)(iX,{src:o(t),alt:t.name,onNav:c.length>1?l:void 0},`${r(t)}:${t.relPath}:${i?`local`:a?`full`:`fit`}`):rO(t.relPath)?(0,J.jsx)(`video`,{className:`viewer-video`,src:s(t),controls:!0,autoPlay:!0,playsInline:!0},`${r(t)}:${t.relPath}:${i?`local`:`net`}`):uO(t.relPath)?(0,J.jsxs)(`div`,{className:`viewer-doc`,children:[cO(t.relPath)&&(0,J.jsxs)(`div`,{className:`viewer-doc-bar`,children:[(0,J.jsx)(Y,{onClick:()=>u(e=>!e),children:d?`rendered`:`source`}),f?.truncated&&!h&&(0,J.jsxs)(`span`,{className:`viewer-doc-note`,children:[`showing the first `,400,` KB — download for the rest`]}),m!=null&&!h&&(0,J.jsxs)(`span`,{className:`viewer-doc-note`,children:[(0,J.jsx)(Hs,{size:12}),` saved copy from `,lX(m)]})]}),h?(0,J.jsx)(`iframe`,{className:`viewer-html`,src:s(t),title:t.name,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`},`${r(t)}:${t.relPath}:${i?`local`:`net`}`):p?(0,J.jsxs)($,{children:[`Could not load this file (`,p,`). `,(0,J.jsx)(FO,{rec:g(t),target:_(t)})]}):!f||f.path!==t.relPath?(0,J.jsx)($,{children:`Loading…`}):lO(t.relPath)&&!d?(0,J.jsx)(`div`,{className:`viewer-doc-body`,children:(0,J.jsx)(Rj,{src:f.text,q:``,onCopy:e=>gp(e),files:{repoId:r(t),url:(e,n,i)=>{let a=U.artifactUrl(r(t),e);return n?sg(a,n,i):a},open:e=>{let n=v.find(t=>t.relPath===e);n?y(n):NO({repoId:r(t),relPath:e})},known:v.filter(e=>r(e)===r(t)).map(e=>e.relPath),docPath:t.relPath}})}):(0,J.jsxs)(`pre`,{className:`viewer-doc-pre`,children:[f.text,f.truncated?`
|
|
206
206
|
… (truncated — download for the rest)`:``]})]}):aO(t.relPath)?(0,J.jsx)(`audio`,{className:`viewer-audio`,src:s(t),controls:!0,preload:`metadata`},`${r(t)}:${t.relPath}:${i?`local`:`net`}`):oO(t.relPath)?(0,J.jsxs)(`div`,{className:`viewer-doc`,children:[(0,J.jsx)(`iframe`,{className:`viewer-pdf`,src:s(t),title:t.name}),(0,J.jsxs)(`div`,{className:`viewer-doc-note`,children:[(0,J.jsx)(FO,{rec:g(t),target:_(t)}),` if the preview stays blank`]})]}):(0,J.jsxs)(`div`,{className:`viewer-none`,children:[(0,J.jsx)(sc,{size:28}),(0,J.jsx)(`span`,{children:`no preview for this kind of file — the actions below download it or copy its path`})]}),(0,J.jsxs)(`div`,{className:`viewer-path mono`,children:[t.repoName?`${t.repoName} · `:``,t.relPath]}),(0,J.jsxs)(`div`,{className:`viewer-path`,children:[`created `,uX(t.ctime??t.mtime),b>=0&&c.length>1?` · ${b+1} / ${c.length}`:``]}),i&&(0,J.jsxs)(`div`,{className:`viewer-doc-note`,children:[(0,J.jsx)(go,{size:12}),` shown from the copy already on this phone — no host needed`]}),m!=null&&!cO(t.relPath)&&(0,J.jsxs)(`div`,{className:`viewer-doc-note`,children:[(0,J.jsx)(Hs,{size:12}),` saved copy from `,lX(m)]}),(0,J.jsxs)(`div`,{className:`sheet-actions`,children:[(0,J.jsxs)(Y,{onClick:()=>n(),children:[(0,J.jsx)(Hl,{size:16}),` back`]}),(0,J.jsx)(Y,{onClick:()=>S(t.relPath),children:x===t.relPath?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(ys,{size:16}),` copied`]}):`copy path`}),C(t)&&!a&&!i&&(0,J.jsxs)(Y,{"data-hint":`gallery.fullres`,title:`load the original file instead of the screen-sized copy`,onClick:()=>{q(`action:gallery.fullres`),w(!0)},children:[`full res`,t.size?` (${Math.round(t.size/1024)} KB)`:``]}),nO(t.relPath)&&(0,J.jsxs)(Y,{onClick:()=>{q(`action:gallery.annotate`),A(T(t),t.name,r(t))},children:[(0,J.jsx)(us,{size:16}),` annotate`]}),(0,J.jsx)(FO,{rec:g(t),target:_(t),trackId:`action:gallery.download`,onStart:()=>E(e=>e+1)}),D(t)&&(0,J.jsx)(Y,{variant:`danger`,onClick:()=>O(t),children:`delete`}),(0,J.jsx)(JTe,{...F}),(0,J.jsx)(`button`,{className:`send`,onClick:()=>{j(t.relPath),M()},children:`insert path`})]}),(0,J.jsx)(YTe,{...F}),k&&(0,J.jsx)(`div`,{className:`viewer-doc-note`,children:k})]})]})}function ZTe(e){let t=LTe(e);return(0,J.jsxs)(`div`,{className:`sheet`,children:[(0,J.jsx)(VTe,{m:t}),(0,J.jsx)(qTe,{m:t}),(0,J.jsx)(XTe,{m:t})]})}function QTe(e,t,n=t){let r=Math.min(t,n),i=Math.max(t,n);return!e||!e.open?{from:r,to:i,open:!0}:e.from===r&&e.to===i?null:{from:Math.min(e.from,r),to:Math.max(e.to,i),open:!1}}function $Te(e,t){return e===t?`${e}`:`${e}-${t}`}function gX(e,t){return e===t?`line ${e}`:`lines ${e}–${t}`}function _X(e){return e.slice().sort((e,t)=>e.from-t.from||e.to-t.to)}function vX(e,t,n=t){let r=[];return e.forEach((e,i)=>{e.from<=n&&e.to>=t&&r.push(i+1)}),r}function eEe(e,t,n){return e.slice(Math.max(0,t-1),Math.max(0,n))}function yX(e,t,n){if(t<1||t-1+n.length>e.length)return!1;for(let r=0;r<n.length;r++)if(e[t-1+r]!==n[r])return!1;return!0}function bX(e,t){return e.map(e=>{if(!e.quote.length)return e;if(yX(t,e.from,e.quote))return e.moved?{...e,moved:!1}:e;let n=-1;for(let r=1;r+e.quote.length-1<=t.length;r++)t[r-1]===e.quote[0]&&yX(t,r,e.quote)&&(n<0||Math.abs(r-e.from)<Math.abs(n-e.from))&&(n=r);return n<0?e.moved?e:{...e,moved:!0}:{...e,from:n,to:n+e.quote.length-1,moved:!1}})}function xX(e){return e.length>160?`${e.slice(0,159)}…`:e}function tEe(e){return(e.length>4?[...e.slice(0,3).map(xX),`… ${e.length-4} more lines …`,xX(e[e.length-1])]:e.map(xX)).map(e=>e.trim()?`> ${e}`:`>`)}function nEe(e,t){let n=_X(t).filter(e=>e.text.trim());if(!n.length)return null;let r=n.map((t,n)=>[`${n+1}. ${e}:${$Te(t.from,t.to)}${t.moved?` (these lines have changed since — quoted as they read then)`:``}`,...tEe(t.quote),t.text.trim()].join(`
|
|
207
207
|
`));return`Remarks on ${e} (${n.length}):\n\n${r.join(`
|
|
208
208
|
|