agent-lookout 0.2.8 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/HistoryPanel-C5-cd24R.js","assets/react-C2DiJaR6.js","assets/motion-DlYOyClL.js","assets/radix-BH0JH8UU.js","assets/SessionPanel-CO5qG2uH.js"])))=>i.map(i=>d[i]);
2
+ import{j as n,r as p,d as ec}from"./react-C2DiJaR6.js";import{A as tc,m as nc,L as sc,d as oc,M as rc}from"./motion-DlYOyClL.js";import{S as ac,P as ic,R as lc,T as cc,a as dc,C as uc,b as fc,c as hc,d as mc,e as pc,D as Xr,f as Jr,g as Qr,h as Zr,i as ea,j as xc,k as gc}from"./radix-BH0JH8UU.js";(function(){const t=document.createElement("link").relList;if(t&&t.supports&&t.supports("modulepreload"))return;for(const r of document.querySelectorAll('link[rel="modulepreload"]'))o(r);new MutationObserver(r=>{for(const a of r)if(a.type==="childList")for(const i of a.addedNodes)i.tagName==="LINK"&&i.rel==="modulepreload"&&o(i)}).observe(document,{childList:!0,subtree:!0});function s(r){const a={};return r.integrity&&(a.integrity=r.integrity),r.referrerPolicy&&(a.referrerPolicy=r.referrerPolicy),r.crossOrigin==="use-credentials"?a.credentials="include":r.crossOrigin==="anonymous"?a.credentials="omit":a.credentials="same-origin",a}function o(r){if(r.ep)return;r.ep=!0;const a=s(r);fetch(r.href,a)}})();const wc="modulepreload",bc=function(e){return"/"+e},Mo={},ta=function(t,s,o){let r=Promise.resolve();if(s&&s.length>0){let d=function(c){return Promise.all(c.map(u=>Promise.resolve(u).then(f=>({status:"fulfilled",value:f}),f=>({status:"rejected",reason:f}))))};document.getElementsByTagName("link");const i=document.querySelector("meta[property=csp-nonce]"),l=i?.nonce||i?.getAttribute("nonce");r=d(s.map(c=>{if(c=bc(c),c in Mo)return;Mo[c]=!0;const u=c.endsWith(".css"),f=u?'[rel="stylesheet"]':"";if(document.querySelector(`link[href="${c}"]${f}`))return;const m=document.createElement("link");if(m.rel=u?"stylesheet":wc,u||(m.as="script"),m.crossOrigin="",m.href=c,l&&m.setAttribute("nonce",l),document.head.appendChild(m),u)return new Promise((w,x)=>{m.addEventListener("load",w),m.addEventListener("error",()=>x(new Error(`Unable to preload CSS for ${c}`)))})}))}function a(i){const l=new Event("vite:preloadError",{cancelable:!0});if(l.payload=i,window.dispatchEvent(l),!l.defaultPrevented)throw i}return r.then(i=>{for(const l of i||[])l.status==="rejected"&&a(l.reason);return t().catch(a)})},Ye=1440*60*1e3,na=3600*1e3,Co=24*na;function In(e){if(e%Co===0){const s=e/Co;return s===1?"a day":`${s} days`}const t=Math.max(1,Math.round(e/na));return t===1?"an hour":`${t} hours`}const ct=["mon","tue","wed","thu","fri","sat","sun"],Io=["longWait","idle","quietHours"],Lt={min:1,max:1440,default:10},$t={min:5,max:1440,default:30},dt={min:1,max:720,default:48},gn={longWait:{on:!1,minutes:Lt.default},idle:{on:!1,hours:dt.default},quietHours:{on:!1,from:"22:00",to:"08:00",days:[...ct],leaveOutAnswered:!1}},yc=36e5,kc=/^([01]\d|2[0-3]):([0-5]\d)$/;function Wt(e){const t=kc.exec(e);return t?Number(t[1])*60+Number(t[2]):null}function zt(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function On(e,t,s){return t.every(o=>o in e)?!s||Object.keys(e).length===t.length:!1}function Bs(e,t){return Number.isSafeInteger(e)&&e>=t.min&&e<=t.max}function jc(e,t){if(!zt(e)||!On(e,["on","minutes"],t))return null;const{on:s,minutes:o}=e;return typeof s!="boolean"||!Bs(o,$t)?null:{on:s,minutes:o}}function Nc(e,t){if(!zt(e))return null;const s=e.repeat===void 0?["on","minutes"]:["on","minutes","repeat"];if(!On(e,s,t))return null;const{on:o,minutes:r}=e;if(typeof o!="boolean"||!Bs(r,Lt))return null;if(e.repeat===void 0)return{on:o,minutes:r};const a=jc(e.repeat,t);return a===null?null:{on:o,minutes:r,repeat:a}}function vc(e,t){if(!zt(e)||!On(e,["on","hours"],t))return null;const{on:s,hours:o}=e;return typeof s!="boolean"||!Bs(o,dt)?null:{on:s,hours:o}}function Sc(e){return!Array.isArray(e)||!e.every(t=>ct.includes(t))||new Set(e).size!==e.length?null:ct.filter(t=>e.includes(t))}function Ac(e,t){const s=["on","from","to","days","leaveOutAnswered"];if(!zt(e)||!On(e,s,t))return null;const{on:o,from:r,to:a,leaveOutAnswered:i}=e;if(typeof o!="boolean"||typeof i!="boolean"||typeof r!="string"||typeof a!="string")return null;const l=Wt(r),d=Wt(a);if(l===null||d===null||l===d)return null;const c=Sc(e.days);return c===null?null:{on:o,from:r,to:a,days:c,leaveOutAnswered:i}}const Ec={longWait:Nc,idle:vc,quietHours:Ac};function qs(e){const t={longWait:{...gn.longWait},idle:{...gn.idle},quietHours:{...gn.quietHours,days:[...ct]}},s=[];if(!zt(e))return{rules:t,unread:e===void 0?[]:[...Io]};for(const o of Io){if(e[o]===void 0)continue;const r=Ec[o](e[o],!1);r===null?s.push(o):Object.assign(t,{[o]:r})}return{rules:t,unread:s}}function Tc(e){return e?.idle.on?e.idle.hours*yc:Ye}function sa(e){return e.timeRules??gn}function oa(e){var t,s,o="";if(typeof e=="string"||typeof e=="number")o+=e;else if(typeof e=="object")if(Array.isArray(e)){var r=e.length;for(t=0;t<r;t++)e[t]&&(s=oa(e[t]))&&(o&&(o+=" "),o+=s)}else for(s in e)e[s]&&(o&&(o+=" "),o+=s);return o}function ra(){for(var e,t,s=0,o="",r=arguments.length;s<r;s++)(e=arguments[s])&&(t=oa(e))&&(o&&(o+=" "),o+=t);return o}const Oo=e=>typeof e=="boolean"?`${e}`:e===0?"0":e,_o=ra,aa=(e,t)=>s=>{var o;if(t?.variants==null)return _o(e,s?.class,s?.className);const{variants:r,defaultVariants:a}=t,i=Object.keys(r).map(c=>{const u=s?.[c],f=a?.[c];if(u===null)return null;const m=Oo(u)||Oo(f);return r[c][m]}),l=s&&Object.entries(s).reduce((c,u)=>{let[f,m]=u;return m===void 0||(c[f]=m),c},{}),d=t==null||(o=t.compoundVariants)===null||o===void 0?void 0:o.reduce((c,u)=>{let{class:f,className:m,...w}=u;return Object.entries(w).every(x=>{let[g,h]=x;return Array.isArray(h)?h.includes({...a,...l}[g]):{...a,...l}[g]===h})?[...c,f,m]:c},[]);return _o(e,i,d,s?.class,s?.className)},Mc=(e,t)=>{const s=new Array(e.length+t.length);for(let o=0;o<e.length;o++)s[o]=e[o];for(let o=0;o<t.length;o++)s[e.length+o]=t[o];return s},Cc=(e,t)=>({classGroupId:e,validator:t}),ia=(e=new Map,t=null,s)=>({nextPart:e,validators:t,classGroupId:s}),yn="-",Ro=[],Ic="arbitrary..",Oc=e=>{const t=Rc(e),{conflictingClassGroups:s,conflictingClassGroupModifiers:o}=e;return{getClassGroupId:i=>{if(i.startsWith("[")&&i.endsWith("]"))return _c(i);const l=i.split(yn),d=l[0]===""&&l.length>1?1:0;return la(l,d,t)},getConflictingClassGroupIds:(i,l)=>{if(l){const d=o[i],c=s[i];return d?c?Mc(c,d):d:c||Ro}return s[i]||Ro}}},la=(e,t,s)=>{if(e.length-t===0)return s.classGroupId;const r=e[t],a=s.nextPart.get(r);if(a){const c=la(e,t+1,a);if(c)return c}const i=s.validators;if(i===null)return;const l=t===0?e.join(yn):e.slice(t).join(yn),d=i.length;for(let c=0;c<d;c++){const u=i[c];if(u.validator(l))return u.classGroupId}},_c=e=>e.slice(1,-1).indexOf(":")===-1?void 0:(()=>{const t=e.slice(1,-1),s=t.indexOf(":"),o=t.slice(0,s);return o?Ic+o:void 0})(),Rc=e=>{const{theme:t,classGroups:s}=e;return Lc(s,t)},Lc=(e,t)=>{const s=ia();for(const o in e){const r=e[o];Gs(r,s,o,t)}return s},Gs=(e,t,s,o)=>{const r=e.length;for(let a=0;a<r;a++){const i=e[a];$c(i,t,s,o)}},$c=(e,t,s,o)=>{if(typeof e=="string"){Wc(e,t,s);return}if(typeof e=="function"){Pc(e,t,s,o);return}Dc(e,t,s,o)},Wc=(e,t,s)=>{const o=e===""?t:ca(t,e);o.classGroupId=s},Pc=(e,t,s,o)=>{if(Uc(e)){Gs(e(o),t,s,o);return}t.validators===null&&(t.validators=[]),t.validators.push(Cc(s,e))},Dc=(e,t,s,o)=>{const r=Object.entries(e),a=r.length;for(let i=0;i<a;i++){const[l,d]=r[i];Gs(d,ca(t,l),s,o)}},ca=(e,t)=>{let s=e;const o=t.split(yn),r=o.length;for(let a=0;a<r;a++){const i=o[a];let l=s.nextPart.get(i);l||(l=ia(),s.nextPart.set(i,l)),s=l}return s},Uc=e=>"isThemeGetter"in e&&e.isThemeGetter===!0,Fc=e=>{if(e<1)return{get:()=>{},set:()=>{}};let t=0,s=Object.create(null),o=Object.create(null);const r=(a,i)=>{s[a]=i,t++,t>e&&(t=0,o=s,s=Object.create(null))};return{get(a){let i=s[a];if(i!==void 0)return i;if((i=o[a])!==void 0)return r(a,i),i},set(a,i){a in s?s[a]=i:r(a,i)}}},vs="!",Lo=":",Hc=[],$o=(e,t,s,o,r)=>({modifiers:e,hasImportantModifier:t,baseClassName:s,maybePostfixModifierPosition:o,isExternal:r}),zc=e=>{const{prefix:t,experimentalParseClassName:s}=e;let o=r=>{const a=[];let i=0,l=0,d=0,c;const u=r.length;for(let g=0;g<u;g++){const h=r[g];if(i===0&&l===0){if(h===Lo){a.push(r.slice(d,g)),d=g+1;continue}if(h==="/"){c=g;continue}}h==="["?i++:h==="]"?i--:h==="("?l++:h===")"&&l--}const f=a.length===0?r:r.slice(d);let m=f,w=!1;f.endsWith(vs)?(m=f.slice(0,-1),w=!0):f.startsWith(vs)&&(m=f.slice(1),w=!0);const x=c&&c>d?c-d:void 0;return $o(a,w,m,x)};if(t){const r=t+Lo,a=o;o=i=>i.startsWith(r)?a(i.slice(r.length)):$o(Hc,!1,i,void 0,!0)}if(s){const r=o;o=a=>s({className:a,parseClassName:r})}return o},Bc=e=>{const t=new Map;return e.orderSensitiveModifiers.forEach((s,o)=>{t.set(s,1e6+o)}),s=>{const o=[];let r=[];for(let a=0;a<s.length;a++){const i=s[a],l=i[0]==="[",d=t.has(i);l||d?(r.length>0&&(r.sort(),o.push(...r),r=[]),o.push(i)):r.push(i)}return r.length>0&&(r.sort(),o.push(...r)),o}},qc=e=>({cache:Fc(e.cacheSize),parseClassName:zc(e),sortModifiers:Bc(e),postfixLookupClassGroupIds:Gc(e),...Oc(e)}),Gc=e=>{const t=Object.create(null),s=e.postfixLookupClassGroups;if(s)for(let o=0;o<s.length;o++)t[s[o]]=!0;return t},Kc=/\s+/,Vc=(e,t)=>{const{parseClassName:s,getClassGroupId:o,getConflictingClassGroupIds:r,sortModifiers:a,postfixLookupClassGroupIds:i}=t,l=[],d=e.trim().split(Kc);let c="";for(let u=d.length-1;u>=0;u-=1){const f=d[u],{isExternal:m,modifiers:w,hasImportantModifier:x,baseClassName:g,maybePostfixModifierPosition:h}=s(f);if(m){c=f+(c.length>0?" "+c:c);continue}let j=!!h,y;if(j){const v=g.substring(0,h);y=o(v);const b=y&&i[y]?o(g):void 0;b&&b!==y&&(y=b,j=!1)}else y=o(g);if(!y){if(!j){c=f+(c.length>0?" "+c:c);continue}if(y=o(g),!y){c=f+(c.length>0?" "+c:c);continue}j=!1}const k=w.length===0?"":w.length===1?w[0]:a(w).join(":"),N=x?k+vs:k,E=N+y;if(l.indexOf(E)>-1)continue;l.push(E);const S=r(y,j);for(let v=0;v<S.length;++v){const b=S[v];l.push(N+b)}c=f+(c.length>0?" "+c:c)}return c},Yc=(...e)=>{let t=0,s,o,r="";for(;t<e.length;)(s=e[t++])&&(o=da(s))&&(r&&(r+=" "),r+=o);return r},da=e=>{if(typeof e=="string")return e;let t,s="";for(let o=0;o<e.length;o++)e[o]&&(t=da(e[o]))&&(s&&(s+=" "),s+=t);return s},Wo=(e,...t)=>{let s,o,r,a;const i=d=>{const c=t.reduce((u,f)=>f(u),e());return s=qc(c),o=s.cache.get,r=s.cache.set,a=l,l(d)},l=d=>{const c=o(d);if(c)return c;const u=Vc(d,s);return r(d,u),u};return a=i,(...d)=>a(Yc(...d))},Xc=[],J=e=>{const t=s=>s[e]||Xc;return t.isThemeGetter=!0,t.themeKey=e,t},ua=/^\[(?:(\w[\w-]*):)?(.+)\]$/i,fa=/^\((?:(\w[\w-]*):)?(.+)\)$/i,Jc=/^\d+(?:\.\d+)?\/\d+(?:\.\d+)?$/,Qc=/^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/,Zc=/\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/,ed=/^(rgba?|hsla?|hwb|(ok)?(lab|lch)|color-mix|color|light-dark)\(.+\)$/,td=/^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/,nd=/^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/,_e=e=>Jc.test(e),$=e=>!!e&&!Number.isNaN(Number(e)),be=e=>!!e&&Number.isInteger(Number(e)),es=e=>e.endsWith("%")&&$(e.slice(0,-1)),Ce=e=>Qc.test(e),ha=()=>!0,sd=e=>Zc.test(e)&&!ed.test(e),Ks=()=>!1,od=e=>td.test(e),rd=e=>nd.test(e),ad=e=>!C(e)&&!I(e),id=e=>e.startsWith("@container")&&(e[10]==="/"&&e[11]!==void 0||e[11]==="s"&&e[16]!==void 0&&e.startsWith("-size/",10)||e[11]==="n"&&e[18]!==void 0&&e.startsWith("-normal/",10)),ld=e=>Pe(e,xa,Ks),C=e=>ua.test(e),He=e=>Pe(e,ga,sd),Po=e=>Pe(e,xd,$),cd=e=>Pe(e,ba,ha),dd=e=>Pe(e,wa,Ks),Do=e=>Pe(e,ma,Ks),ud=e=>Pe(e,pa,rd),rn=e=>Pe(e,ya,od),I=e=>fa.test(e),wt=e=>Xe(e,ga),fd=e=>Xe(e,wa),Uo=e=>Xe(e,ma),hd=e=>Xe(e,xa),md=e=>Xe(e,pa),an=e=>Xe(e,ya,!0),pd=e=>Xe(e,ba,!0),Pe=(e,t,s)=>{const o=ua.exec(e);return o?o[1]?t(o[1]):s(o[2]):!1},Xe=(e,t,s=!1)=>{const o=fa.exec(e);return o?o[1]?t(o[1]):s:!1},ma=e=>e==="position"||e==="percentage",pa=e=>e==="image"||e==="url",xa=e=>e==="length"||e==="size"||e==="bg-size",ga=e=>e==="length",xd=e=>e==="number",wa=e=>e==="family-name",ba=e=>e==="number"||e==="weight",ya=e=>e==="shadow",Fo=()=>{const e=J("color"),t=J("font"),s=J("text"),o=J("font-weight"),r=J("tracking"),a=J("leading"),i=J("breakpoint"),l=J("container"),d=J("spacing"),c=J("radius"),u=J("shadow"),f=J("inset-shadow"),m=J("text-shadow"),w=J("drop-shadow"),x=J("blur"),g=J("perspective"),h=J("aspect"),j=J("ease"),y=J("animate"),k=()=>["auto","avoid","all","avoid-page","page","left","right","column"],N=()=>["center","top","bottom","left","right","top-left","left-top","top-right","right-top","bottom-right","right-bottom","bottom-left","left-bottom"],E=()=>[...N(),I,C],S=()=>["auto","hidden","clip","visible","scroll"],v=()=>["auto","contain","none"],b=()=>[I,C,d],O=()=>[_e,"full","auto",...b()],H=()=>[be,"none","subgrid",I,C],K=()=>["auto",{span:["full",be,I,C]},be,I,C],V=()=>[be,"auto",I,C],R=()=>["auto","min","max","fr",I,C],P=()=>["start","end","center","between","around","evenly","stretch","baseline","center-safe","end-safe"],T=()=>["start","end","center","stretch","center-safe","end-safe"],M=()=>["auto",...b()],z=()=>[_e,"auto","full","dvw","dvh","lvw","lvh","svw","svh","min","max","fit",...b()],ie=()=>[l,_e,"screen","full","dvw","lvw","svw","min","max","fit",...b()],gt=()=>[_e,"screen","full","lh","dvh","lvh","svh","min","max","fit",...b()],_=()=>[e,I,C],X=()=>[...N(),Uo,Do,{position:[I,C]}],Fe=()=>["no-repeat",{repeat:["","x","y","space","round"]}],he=()=>["auto","cover","contain",hd,ld,{size:[I,C]}],Qn=()=>[es,wt,He],le=()=>["","none","full",c,I,C],ce=()=>["",$,wt,He],tn=()=>["solid","dashed","dotted","double"],Eo=()=>["normal","multiply","screen","overlay","darken","lighten","color-dodge","color-burn","hard-light","soft-light","difference","exclusion","hue","saturation","color","luminosity"],Z=()=>[$,es,Uo,Do],To=()=>["","none",x,I,C],nn=()=>["none",$,I,C],sn=()=>["none",$,I,C],Zn=()=>[$,I,C],on=()=>[_e,"full",...b()];return{cacheSize:500,theme:{animate:["spin","ping","pulse","bounce"],aspect:["video"],blur:[Ce],breakpoint:[Ce],color:[ha],container:[Ce],"drop-shadow":[Ce],ease:["in","out","in-out"],font:[ad],"font-weight":["thin","extralight","light","normal","medium","semibold","bold","extrabold","black"],"inset-shadow":[Ce],leading:["none","tight","snug","normal","relaxed","loose"],perspective:["dramatic","near","normal","midrange","distant","none"],radius:[Ce],shadow:[Ce],spacing:["px",$],text:[Ce],"text-shadow":[Ce],tracking:["tighter","tight","normal","wide","wider","widest"]},classGroups:{aspect:[{aspect:["auto","square",_e,C,I,h]}],container:["container"],"container-type":[{"@container":["","normal","size",I,C]}],"container-named":[id],columns:[{columns:[$,"auto",C,I,l]}],"break-after":[{"break-after":k()}],"break-before":[{"break-before":k()}],"break-inside":[{"break-inside":["auto","avoid","avoid-page","avoid-column"]}],"box-decoration":[{"box-decoration":["slice","clone"]}],box:[{box:["border","content"]}],display:["block","inline-block","inline","flex","inline-flex","table","inline-table","table-caption","table-cell","table-column","table-column-group","table-footer-group","table-header-group","table-row-group","table-row","flow-root","grid","inline-grid","contents","list-item","hidden"],sr:["sr-only","not-sr-only"],float:[{float:["right","left","none","start","end"]}],clear:[{clear:["left","right","both","none","start","end"]}],isolation:["isolate","isolation-auto"],"object-fit":[{object:["contain","cover","fill","none","scale-down"]}],"object-position":[{object:E()}],overflow:[{overflow:S()}],"overflow-x":[{"overflow-x":S()}],"overflow-y":[{"overflow-y":S()}],overscroll:[{overscroll:v()}],"overscroll-x":[{"overscroll-x":v()}],"overscroll-y":[{"overscroll-y":v()}],position:["static","fixed","absolute","relative","sticky"],inset:[{inset:O()}],"inset-x":[{"inset-x":O()}],"inset-y":[{"inset-y":O()}],start:[{"inset-s":O(),start:O()}],end:[{"inset-e":O(),end:O()}],"inset-bs":[{"inset-bs":O()}],"inset-be":[{"inset-be":O()}],top:[{top:O()}],right:[{right:O()}],bottom:[{bottom:O()}],left:[{left:O()}],visibility:["visible","invisible","collapse"],z:[{z:[be,"auto",I,C]}],basis:[{basis:[_e,"full","auto",l,...b()]}],"flex-direction":[{flex:["row","row-reverse","col","col-reverse"]}],"flex-wrap":[{flex:["nowrap","wrap","wrap-reverse"]}],flex:[{flex:[$,_e,"auto","initial","none",C]}],grow:[{grow:["",$,I,C]}],shrink:[{shrink:["",$,I,C]}],order:[{order:[be,"first","last","none",I,C]}],"grid-cols":[{"grid-cols":H()}],"col-start-end":[{col:K()}],"col-start":[{"col-start":V()}],"col-end":[{"col-end":V()}],"grid-rows":[{"grid-rows":H()}],"row-start-end":[{row:K()}],"row-start":[{"row-start":V()}],"row-end":[{"row-end":V()}],"grid-flow":[{"grid-flow":["row","col","dense","row-dense","col-dense"]}],"auto-cols":[{"auto-cols":R()}],"auto-rows":[{"auto-rows":R()}],gap:[{gap:b()}],"gap-x":[{"gap-x":b()}],"gap-y":[{"gap-y":b()}],"justify-content":[{justify:[...P(),"normal"]}],"justify-items":[{"justify-items":[...T(),"normal"]}],"justify-self":[{"justify-self":["auto",...T()]}],"align-content":[{content:["normal",...P()]}],"align-items":[{items:[...T(),{baseline:["","last"]}]}],"align-self":[{self:["auto",...T(),{baseline:["","last"]}]}],"place-content":[{"place-content":P()}],"place-items":[{"place-items":[...T(),"baseline"]}],"place-self":[{"place-self":["auto",...T()]}],p:[{p:b()}],px:[{px:b()}],py:[{py:b()}],ps:[{ps:b()}],pe:[{pe:b()}],pbs:[{pbs:b()}],pbe:[{pbe:b()}],pt:[{pt:b()}],pr:[{pr:b()}],pb:[{pb:b()}],pl:[{pl:b()}],m:[{m:M()}],mx:[{mx:M()}],my:[{my:M()}],ms:[{ms:M()}],me:[{me:M()}],mbs:[{mbs:M()}],mbe:[{mbe:M()}],mt:[{mt:M()}],mr:[{mr:M()}],mb:[{mb:M()}],ml:[{ml:M()}],"space-x":[{"space-x":b()}],"space-x-reverse":["space-x-reverse"],"space-y":[{"space-y":b()}],"space-y-reverse":["space-y-reverse"],size:[{size:z()}],"inline-size":[{inline:["auto",...ie()]}],"min-inline-size":[{"min-inline":["auto",...ie()]}],"max-inline-size":[{"max-inline":["none",...ie()]}],"block-size":[{block:["auto",...gt()]}],"min-block-size":[{"min-block":["auto",...gt()]}],"max-block-size":[{"max-block":["none",...gt()]}],w:[{w:[l,"screen",...z()]}],"min-w":[{"min-w":[l,"screen","none",...z()]}],"max-w":[{"max-w":[l,"screen","none","prose",{screen:[i]},...z()]}],h:[{h:["screen","lh",...z()]}],"min-h":[{"min-h":["screen","lh","none",...z()]}],"max-h":[{"max-h":["screen","lh","none",...z()]}],"font-size":[{text:["base",s,wt,He]}],"font-smoothing":["antialiased","subpixel-antialiased"],"font-style":["italic","not-italic"],"font-weight":[{font:[o,pd,cd]}],"font-stretch":[{"font-stretch":["ultra-condensed","extra-condensed","condensed","semi-condensed","normal","semi-expanded","expanded","extra-expanded","ultra-expanded",es,C]}],"font-family":[{font:[fd,dd,t]}],"font-features":[{"font-features":[C]}],"fvn-normal":["normal-nums"],"fvn-ordinal":["ordinal"],"fvn-slashed-zero":["slashed-zero"],"fvn-figure":["lining-nums","oldstyle-nums"],"fvn-spacing":["proportional-nums","tabular-nums"],"fvn-fraction":["diagonal-fractions","stacked-fractions"],tracking:[{tracking:[r,I,C]}],"line-clamp":[{"line-clamp":[$,"none",I,Po]}],leading:[{leading:["none",a,...b()]}],"list-image":[{"list-image":["none",I,C]}],"list-style-position":[{list:["inside","outside"]}],"list-style-type":[{list:["disc","decimal","none",I,C]}],"text-alignment":[{text:["left","center","right","justify","start","end"]}],"placeholder-color":[{placeholder:_()}],"text-color":[{text:_()}],"text-decoration":["underline","overline","line-through","no-underline"],"text-decoration-style":[{decoration:[...tn(),"wavy"]}],"text-decoration-thickness":[{decoration:[$,"from-font","auto",I,He]}],"text-decoration-color":[{decoration:_()}],"underline-offset":[{"underline-offset":[$,"auto",I,C]}],"text-transform":["uppercase","lowercase","capitalize","normal-case"],"text-overflow":["truncate","text-ellipsis","text-clip"],"text-wrap":[{text:["wrap","nowrap","balance","pretty"]}],indent:[{indent:b()}],"tab-size":[{tab:[be,I,C]}],"vertical-align":[{align:["baseline","top","middle","bottom","text-top","text-bottom","sub","super",I,C]}],whitespace:[{whitespace:["normal","nowrap","pre","pre-line","pre-wrap","break-spaces"]}],break:[{break:["normal","words","all","keep"]}],wrap:[{wrap:["break-word","anywhere","normal"]}],hyphens:[{hyphens:["none","manual","auto"]}],content:[{content:["none",I,C]}],"bg-attachment":[{bg:["fixed","local","scroll"]}],"bg-clip":[{"bg-clip":["border","padding","content","text"]}],"bg-origin":[{"bg-origin":["border","padding","content"]}],"bg-position":[{bg:X()}],"bg-repeat":[{bg:Fe()}],"bg-size":[{bg:he()}],"bg-image":[{bg:["none",{linear:[{to:["t","tr","r","br","b","bl","l","tl"]},be,I,C],radial:["",I,C],conic:["",be,I,C]},md,ud]}],"bg-color":[{bg:_()}],"gradient-from-pos":[{from:Qn()}],"gradient-via-pos":[{via:Qn()}],"gradient-to-pos":[{to:Qn()}],"gradient-from":[{from:_()}],"gradient-via":[{via:_()}],"gradient-to":[{to:_()}],rounded:[{rounded:le()}],"rounded-s":[{"rounded-s":le()}],"rounded-e":[{"rounded-e":le()}],"rounded-t":[{"rounded-t":le()}],"rounded-r":[{"rounded-r":le()}],"rounded-b":[{"rounded-b":le()}],"rounded-l":[{"rounded-l":le()}],"rounded-ss":[{"rounded-ss":le()}],"rounded-se":[{"rounded-se":le()}],"rounded-ee":[{"rounded-ee":le()}],"rounded-es":[{"rounded-es":le()}],"rounded-tl":[{"rounded-tl":le()}],"rounded-tr":[{"rounded-tr":le()}],"rounded-br":[{"rounded-br":le()}],"rounded-bl":[{"rounded-bl":le()}],"border-w":[{border:ce()}],"border-w-x":[{"border-x":ce()}],"border-w-y":[{"border-y":ce()}],"border-w-s":[{"border-s":ce()}],"border-w-e":[{"border-e":ce()}],"border-w-bs":[{"border-bs":ce()}],"border-w-be":[{"border-be":ce()}],"border-w-t":[{"border-t":ce()}],"border-w-r":[{"border-r":ce()}],"border-w-b":[{"border-b":ce()}],"border-w-l":[{"border-l":ce()}],"divide-x":[{"divide-x":ce()}],"divide-x-reverse":["divide-x-reverse"],"divide-y":[{"divide-y":ce()}],"divide-y-reverse":["divide-y-reverse"],"border-style":[{border:[...tn(),"hidden","none"]}],"divide-style":[{divide:[...tn(),"hidden","none"]}],"border-color":[{border:_()}],"border-color-x":[{"border-x":_()}],"border-color-y":[{"border-y":_()}],"border-color-s":[{"border-s":_()}],"border-color-e":[{"border-e":_()}],"border-color-bs":[{"border-bs":_()}],"border-color-be":[{"border-be":_()}],"border-color-t":[{"border-t":_()}],"border-color-r":[{"border-r":_()}],"border-color-b":[{"border-b":_()}],"border-color-l":[{"border-l":_()}],"divide-color":[{divide:_()}],"outline-style":[{outline:[...tn(),"none","hidden"]}],"outline-offset":[{"outline-offset":[$,I,C]}],"outline-w":[{outline:["",$,wt,He]}],"outline-color":[{outline:_()}],shadow:[{shadow:["","inner","none",u,an,rn]}],"shadow-color":[{shadow:_()}],"inset-shadow":[{"inset-shadow":["none",f,an,rn]}],"inset-shadow-color":[{"inset-shadow":_()}],"ring-w":[{ring:ce()}],"ring-w-inset":["ring-inset"],"ring-color":[{ring:_()}],"ring-offset-w":[{"ring-offset":[$,He]}],"ring-offset-color":[{"ring-offset":_()}],"inset-ring-w":[{"inset-ring":ce()}],"inset-ring-color":[{"inset-ring":_()}],"text-shadow":[{"text-shadow":["none",m,an,rn]}],"text-shadow-color":[{"text-shadow":_()}],opacity:[{opacity:[$,I,C]}],"mix-blend":[{"mix-blend":[...Eo(),"plus-darker","plus-lighter"]}],"bg-blend":[{"bg-blend":Eo()}],"mask-clip":[{"mask-clip":["border","padding","content","fill","stroke","view"]},"mask-no-clip"],"mask-composite":[{mask:["add","subtract","intersect","exclude"]}],"mask-image-linear-pos":[{"mask-linear":[$]}],"mask-image-linear-from-pos":[{"mask-linear-from":Z()}],"mask-image-linear-to-pos":[{"mask-linear-to":Z()}],"mask-image-linear-from-color":[{"mask-linear-from":_()}],"mask-image-linear-to-color":[{"mask-linear-to":_()}],"mask-image-t-from-pos":[{"mask-t-from":Z()}],"mask-image-t-to-pos":[{"mask-t-to":Z()}],"mask-image-t-from-color":[{"mask-t-from":_()}],"mask-image-t-to-color":[{"mask-t-to":_()}],"mask-image-r-from-pos":[{"mask-r-from":Z()}],"mask-image-r-to-pos":[{"mask-r-to":Z()}],"mask-image-r-from-color":[{"mask-r-from":_()}],"mask-image-r-to-color":[{"mask-r-to":_()}],"mask-image-b-from-pos":[{"mask-b-from":Z()}],"mask-image-b-to-pos":[{"mask-b-to":Z()}],"mask-image-b-from-color":[{"mask-b-from":_()}],"mask-image-b-to-color":[{"mask-b-to":_()}],"mask-image-l-from-pos":[{"mask-l-from":Z()}],"mask-image-l-to-pos":[{"mask-l-to":Z()}],"mask-image-l-from-color":[{"mask-l-from":_()}],"mask-image-l-to-color":[{"mask-l-to":_()}],"mask-image-x-from-pos":[{"mask-x-from":Z()}],"mask-image-x-to-pos":[{"mask-x-to":Z()}],"mask-image-x-from-color":[{"mask-x-from":_()}],"mask-image-x-to-color":[{"mask-x-to":_()}],"mask-image-y-from-pos":[{"mask-y-from":Z()}],"mask-image-y-to-pos":[{"mask-y-to":Z()}],"mask-image-y-from-color":[{"mask-y-from":_()}],"mask-image-y-to-color":[{"mask-y-to":_()}],"mask-image-radial":[{"mask-radial":[I,C]}],"mask-image-radial-from-pos":[{"mask-radial-from":Z()}],"mask-image-radial-to-pos":[{"mask-radial-to":Z()}],"mask-image-radial-from-color":[{"mask-radial-from":_()}],"mask-image-radial-to-color":[{"mask-radial-to":_()}],"mask-image-radial-shape":[{"mask-radial":["circle","ellipse"]}],"mask-image-radial-size":[{"mask-radial":[{closest:["side","corner"],farthest:["side","corner"]}]}],"mask-image-radial-pos":[{"mask-radial-at":N()}],"mask-image-conic-pos":[{"mask-conic":[$]}],"mask-image-conic-from-pos":[{"mask-conic-from":Z()}],"mask-image-conic-to-pos":[{"mask-conic-to":Z()}],"mask-image-conic-from-color":[{"mask-conic-from":_()}],"mask-image-conic-to-color":[{"mask-conic-to":_()}],"mask-mode":[{mask:["alpha","luminance","match"]}],"mask-origin":[{"mask-origin":["border","padding","content","fill","stroke","view"]}],"mask-position":[{mask:X()}],"mask-repeat":[{mask:Fe()}],"mask-size":[{mask:he()}],"mask-type":[{"mask-type":["alpha","luminance"]}],"mask-image":[{mask:["none",I,C]}],filter:[{filter:["","none",I,C]}],blur:[{blur:To()}],brightness:[{brightness:[$,I,C]}],contrast:[{contrast:[$,I,C]}],"drop-shadow":[{"drop-shadow":["","none",w,an,rn]}],"drop-shadow-color":[{"drop-shadow":_()}],grayscale:[{grayscale:["",$,I,C]}],"hue-rotate":[{"hue-rotate":[$,I,C]}],invert:[{invert:["",$,I,C]}],saturate:[{saturate:[$,I,C]}],sepia:[{sepia:["",$,I,C]}],"backdrop-filter":[{"backdrop-filter":["","none",I,C]}],"backdrop-blur":[{"backdrop-blur":To()}],"backdrop-brightness":[{"backdrop-brightness":[$,I,C]}],"backdrop-contrast":[{"backdrop-contrast":[$,I,C]}],"backdrop-grayscale":[{"backdrop-grayscale":["",$,I,C]}],"backdrop-hue-rotate":[{"backdrop-hue-rotate":[$,I,C]}],"backdrop-invert":[{"backdrop-invert":["",$,I,C]}],"backdrop-opacity":[{"backdrop-opacity":[$,I,C]}],"backdrop-saturate":[{"backdrop-saturate":[$,I,C]}],"backdrop-sepia":[{"backdrop-sepia":["",$,I,C]}],"border-collapse":[{border:["collapse","separate"]}],"border-spacing":[{"border-spacing":b()}],"border-spacing-x":[{"border-spacing-x":b()}],"border-spacing-y":[{"border-spacing-y":b()}],"table-layout":[{table:["auto","fixed"]}],caption:[{caption:["top","bottom"]}],transition:[{transition:["","all","colors","opacity","shadow","transform","none",I,C]}],"transition-behavior":[{transition:["normal","discrete"]}],duration:[{duration:[$,"initial",I,C]}],ease:[{ease:["linear","initial",j,I,C]}],delay:[{delay:[$,I,C]}],animate:[{animate:["none",y,I,C]}],backface:[{backface:["hidden","visible"]}],perspective:[{perspective:[g,I,C]}],"perspective-origin":[{"perspective-origin":E()}],rotate:[{rotate:nn()}],"rotate-x":[{"rotate-x":nn()}],"rotate-y":[{"rotate-y":nn()}],"rotate-z":[{"rotate-z":nn()}],scale:[{scale:sn()}],"scale-x":[{"scale-x":sn()}],"scale-y":[{"scale-y":sn()}],"scale-z":[{"scale-z":sn()}],"scale-3d":["scale-3d"],skew:[{skew:Zn()}],"skew-x":[{"skew-x":Zn()}],"skew-y":[{"skew-y":Zn()}],transform:[{transform:[I,C,"","none","gpu","cpu"]}],"transform-origin":[{origin:E()}],"transform-style":[{transform:["3d","flat"]}],translate:[{translate:on()}],"translate-x":[{"translate-x":on()}],"translate-y":[{"translate-y":on()}],"translate-z":[{"translate-z":on()}],"translate-none":["translate-none"],zoom:[{zoom:[be,I,C]}],accent:[{accent:_()}],appearance:[{appearance:["none","auto"]}],"caret-color":[{caret:_()}],"color-scheme":[{scheme:["normal","dark","light","light-dark","only-dark","only-light"]}],cursor:[{cursor:["auto","default","pointer","wait","text","move","help","not-allowed","none","context-menu","progress","cell","crosshair","vertical-text","alias","copy","no-drop","grab","grabbing","all-scroll","col-resize","row-resize","n-resize","e-resize","s-resize","w-resize","ne-resize","nw-resize","se-resize","sw-resize","ew-resize","ns-resize","nesw-resize","nwse-resize","zoom-in","zoom-out",I,C]}],"field-sizing":[{"field-sizing":["fixed","content"]}],"pointer-events":[{"pointer-events":["auto","none"]}],resize:[{resize:["none","","y","x"]}],"scroll-behavior":[{scroll:["auto","smooth"]}],"scrollbar-thumb-color":[{"scrollbar-thumb":_()}],"scrollbar-track-color":[{"scrollbar-track":_()}],"scrollbar-gutter":[{"scrollbar-gutter":["auto","stable","both"]}],"scrollbar-w":[{scrollbar:["auto","thin","none"]}],"scroll-m":[{"scroll-m":b()}],"scroll-mx":[{"scroll-mx":b()}],"scroll-my":[{"scroll-my":b()}],"scroll-ms":[{"scroll-ms":b()}],"scroll-me":[{"scroll-me":b()}],"scroll-mbs":[{"scroll-mbs":b()}],"scroll-mbe":[{"scroll-mbe":b()}],"scroll-mt":[{"scroll-mt":b()}],"scroll-mr":[{"scroll-mr":b()}],"scroll-mb":[{"scroll-mb":b()}],"scroll-ml":[{"scroll-ml":b()}],"scroll-p":[{"scroll-p":b()}],"scroll-px":[{"scroll-px":b()}],"scroll-py":[{"scroll-py":b()}],"scroll-ps":[{"scroll-ps":b()}],"scroll-pe":[{"scroll-pe":b()}],"scroll-pbs":[{"scroll-pbs":b()}],"scroll-pbe":[{"scroll-pbe":b()}],"scroll-pt":[{"scroll-pt":b()}],"scroll-pr":[{"scroll-pr":b()}],"scroll-pb":[{"scroll-pb":b()}],"scroll-pl":[{"scroll-pl":b()}],"snap-align":[{snap:["start","end","center","align-none"]}],"snap-stop":[{snap:["normal","always"]}],"snap-type":[{snap:["none","x","y","both"]}],"snap-strictness":[{snap:["mandatory","proximity"]}],touch:[{touch:["auto","none","manipulation"]}],"touch-x":[{"touch-pan":["x","left","right"]}],"touch-y":[{"touch-pan":["y","up","down"]}],"touch-pz":["touch-pinch-zoom"],select:[{select:["none","text","all","auto"]}],"will-change":[{"will-change":["auto","scroll","contents","transform",I,C]}],fill:[{fill:["none",..._()]}],"stroke-w":[{stroke:[$,wt,He,Po]}],stroke:[{stroke:["none",..._()]}],"forced-color-adjust":[{"forced-color-adjust":["auto","none"]}]},conflictingClassGroups:{"container-named":["container-type"],overflow:["overflow-x","overflow-y"],overscroll:["overscroll-x","overscroll-y"],inset:["inset-x","inset-y","inset-bs","inset-be","start","end","top","right","bottom","left"],"inset-x":["start","end","right","left"],"inset-y":["inset-bs","inset-be","top","bottom"],flex:["basis","grow","shrink"],gap:["gap-x","gap-y"],p:["px","py","ps","pe","pbs","pbe","pt","pr","pb","pl"],px:["ps","pe","pr","pl"],py:["pbs","pbe","pt","pb"],m:["mx","my","ms","me","mbs","mbe","mt","mr","mb","ml"],mx:["ms","me","mr","ml"],my:["mbs","mbe","mt","mb"],size:["w","h"],"font-size":["leading"],"fvn-normal":["fvn-ordinal","fvn-slashed-zero","fvn-figure","fvn-spacing","fvn-fraction"],"fvn-ordinal":["fvn-normal"],"fvn-slashed-zero":["fvn-normal"],"fvn-figure":["fvn-normal"],"fvn-spacing":["fvn-normal"],"fvn-fraction":["fvn-normal"],"line-clamp":["display","overflow"],rounded:["rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl"],"rounded-s":["rounded-ss","rounded-es"],"rounded-e":["rounded-se","rounded-ee"],"rounded-t":["rounded-tl","rounded-tr"],"rounded-r":["rounded-tr","rounded-br"],"rounded-b":["rounded-br","rounded-bl"],"rounded-l":["rounded-tl","rounded-bl"],"border-spacing":["border-spacing-x","border-spacing-y"],"border-w":["border-w-x","border-w-y","border-w-s","border-w-e","border-w-bs","border-w-be","border-w-t","border-w-r","border-w-b","border-w-l"],"border-w-x":["border-w-s","border-w-e","border-w-r","border-w-l"],"border-w-y":["border-w-bs","border-w-be","border-w-t","border-w-b"],"border-color":["border-color-x","border-color-y","border-color-s","border-color-e","border-color-bs","border-color-be","border-color-t","border-color-r","border-color-b","border-color-l"],"border-color-x":["border-color-s","border-color-e","border-color-r","border-color-l"],"border-color-y":["border-color-bs","border-color-be","border-color-t","border-color-b"],translate:["translate-x","translate-y","translate-none"],"translate-none":["translate","translate-x","translate-y","translate-z"],"scroll-m":["scroll-mx","scroll-my","scroll-ms","scroll-me","scroll-mbs","scroll-mbe","scroll-mt","scroll-mr","scroll-mb","scroll-ml"],"scroll-mx":["scroll-ms","scroll-me","scroll-mr","scroll-ml"],"scroll-my":["scroll-mbs","scroll-mbe","scroll-mt","scroll-mb"],"scroll-p":["scroll-px","scroll-py","scroll-ps","scroll-pe","scroll-pbs","scroll-pbe","scroll-pt","scroll-pr","scroll-pb","scroll-pl"],"scroll-px":["scroll-ps","scroll-pe","scroll-pr","scroll-pl"],"scroll-py":["scroll-pbs","scroll-pbe","scroll-pt","scroll-pb"],touch:["touch-x","touch-y","touch-pz"],"touch-x":["touch"],"touch-y":["touch"],"touch-pz":["touch"]},conflictingClassGroupModifiers:{"font-size":["leading"]},postfixLookupClassGroups:["container-type"],orderSensitiveModifiers:["*","**","after","backdrop","before","details-content","file","first-letter","first-line","marker","placeholder","selection"]}},gd=(e,{cacheSize:t,prefix:s,experimentalParseClassName:o,extend:r={},override:a={}})=>(et(e,"cacheSize",t),et(e,"prefix",s),et(e,"experimentalParseClassName",o),ln(e.theme,a.theme),ln(e.classGroups,a.classGroups),ln(e.conflictingClassGroups,a.conflictingClassGroups),ln(e.conflictingClassGroupModifiers,a.conflictingClassGroupModifiers),et(e,"postfixLookupClassGroups",a.postfixLookupClassGroups),et(e,"orderSensitiveModifiers",a.orderSensitiveModifiers),cn(e.theme,r.theme),cn(e.classGroups,r.classGroups),cn(e.conflictingClassGroups,r.conflictingClassGroups),cn(e.conflictingClassGroupModifiers,r.conflictingClassGroupModifiers),Ss(e,r,"postfixLookupClassGroups"),Ss(e,r,"orderSensitiveModifiers"),e),et=(e,t,s)=>{s!==void 0&&(e[t]=s)},ln=(e,t)=>{if(t)for(const s in t)et(e,s,t[s])},cn=(e,t)=>{if(t)for(const s in t)Ss(e,t,s)},Ss=(e,t,s)=>{const o=t[s];o!==void 0&&(e[s]=e[s]?e[s].concat(o):o)},wd=(e,...t)=>typeof e=="function"?Wo(Fo,e,...t):Wo(()=>gd(Fo(),e),...t),bd=["wait","name","stat","unit","wordmark","lead","title","row","body","fact","caption","micro"],yd=["window","rail","header","row","group","log-row","control","button","button-hero","mark","icon","track","label-col","bar-needs-you","bar-working","bar-idle","waited-name"],kd=wd({extend:{theme:{text:bd,spacing:yd,leading:["tight","body"],radius:["panel","chrome","inner","row","capsule","tube","bar"],shadow:["thumb","glow","edge"],"inset-shadow":["top","well","lit"],ease:["out"],animate:["lamp","spin-loader","rise-fast","fade-in","fade-out","drop"]}}});function A(...e){return kd(ra(e))}const jd=aa(["inline-flex shrink-0 cursor-pointer items-center justify-center gap-1.5 whitespace-nowrap","rounded-capsule text-body font-medium","transition-[background-color,color,filter] duration-120","disabled:pointer-events-none disabled:opacity-50"],{variants:{variant:{quiet:["bg-fill-quiet text-ink-secondary inset-ring inset-ring-control-rim inset-shadow-top","hover:bg-fill-selected hover:text-ink","focus-visible:bg-fill-selected focus-visible:text-ink"],"needs-you":["bg-status-needs-you font-semibold text-on-needs-you","inset-ring inset-ring-status-needs-you-edge inset-shadow-lit shadow-glow","hover:brightness-105 active:brightness-97"]},size:{sm:"h-button min-w-16 px-4",hero:"h-button-hero px-6.5 text-row",icon:"size-button"}},defaultVariants:{variant:"quiet",size:"sm"}});function D({className:e,variant:t,size:s,asChild:o=!1,...r}){const a=o?ac:"button";return n.jsx(a,{"data-slot":"button","data-variant":t??"quiet",...o?{}:{type:"button"},className:A(jd({variant:t,size:s}),e),...r})}const Nd=e=>e?.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase();function vd(e,t,s=[]){if(t==null)throw new Error("[lucide]: iconNode is required when icon name is used");return{name:Nd(e),size:24,node:t,...s.length>0?{aliases:s}:{}}}const Sd=e=>{let t="",s=!1;for(const o of e){if(o==="-"||o==="_"||o<=" "){s=t.length>0;continue}t.length===0?t+=o.toLowerCase():t+=s?o.toUpperCase():o,s=!1}return t};const Ad=e=>{const t=Sd(e);return t.charAt(0).toUpperCase()+t.slice(1)};const As=(...e)=>e.filter((t,s,o)=>!!t&&t.trim()!==""&&o.indexOf(t)===s).join(" ").trim();const ze={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor","stroke-width":2,"stroke-linecap":"round","stroke-linejoin":"round"};function ts(e){return e!=null}function Ed(e,t={}){const s=t.attributeNames??{},o=m=>s[m]??m,r=e.size??e.width??ze.width,a=e.size??e.height??ze.height,i=e.aliases?.filter(m=>typeof m=="string"&&m.trim()!=="").map(m=>`lucide-${m}`)??[],l=[...e.name?[`lucide-${e.name}`]:[],...i],d=t.className?.split(" ").filter(Boolean)??[],c=t.includeDefaultClasses===!1?As(...d):As("lucide",...l,...d),u=t.absoluteStrokeWidth?Number(t.strokeWidth??ze["stroke-width"])*Number(e.size??e.width??ze.width)/Number(t.size??t.width??ze.width):t.strokeWidth??ze["stroke-width"];return["svg",{...Object.entries(ze).reduce((m,[w,x])=>(m[o(w)]=x,m),{}),..."color"in t&&t.color&&{[o("stroke")]:t.color},..."size"in t&&ts(t.size)&&{[o("width")]:t.size,[o("height")]:t.size},..."width"in t&&ts(t.width)&&{[o("width")]:t.width},..."height"in t&&ts(t.height)&&{[o("height")]:t.height},[o("stroke-width")]:u,...c&&{[o("class")]:c},[o("viewBox")]:`0 0 ${r} ${a}`,...t.hasA11yProp===!1?{[o("aria-hidden")]:"true"}:{},..."attributes"in t&&t.attributes},e.node.map(m=>{const[w,x,g]=m,h=t.nonScalingStroke?{[o("vector-effect")]:"non-scaling-stroke",...x}:x;return g?[w,h,g]:[w,h]})]}function Td(e,t={}){return Ed(e,{...t,attributeNames:{...t.attributeNames,class:"className","stroke-width":"strokeWidth","stroke-linecap":"strokeLinecap","stroke-linejoin":"strokeLinejoin","vector-effect":"vectorEffect"}})}const Md=e=>{for(const t in e)if(t.startsWith("aria-")||t==="role"||t==="title")return!0;return!1},Cd=p.createContext({}),Id=()=>p.useContext(Cd),Od=p.forwardRef(({color:e,size:t,width:s,height:o,strokeWidth:r,absoluteStrokeWidth:a,nonScalingStroke:i,className:l="",children:d,iconNode:c=[],icon:u={node:c,aliases:[],size:24},...f},m)=>{const{size:w=24,strokeWidth:x=2,absoluteStrokeWidth:g=!1,nonScalingStroke:h=!1,color:j="currentColor",className:y=""}=Id()??{},k=!!d||Md(f),[N,E,S=[]]=Td(u,{color:e??j,width:s??t??w,height:o??t??w,strokeWidth:r??x,absoluteStrokeWidth:a??g,nonScalingStroke:i??h,className:As(y,l),hasA11yProp:k,attributes:f});return p.createElement(N,{ref:m,...E},[...S.map(([v,b])=>p.createElement(v,b)),...Array.isArray(d)?d:[d]])});function Te(e,t=[],s=[]){const o=typeof e=="string"?vd(e,t,s):e,r=p.forwardRef(({className:a,...i},l)=>p.createElement(Od,{ref:l,icon:o,className:a,...i}));return o.name&&(r.displayName=Ad(o.name)),r}const ka={name:"arrow-down",size:24,node:[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]};ka.node;const ja=Te(ka);const Na={name:"arrow-left",size:24,node:[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]};Na.node;const _d=Te(Na);const va={name:"arrow-right",size:24,node:[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]};va.node;const Rd=Te(va);const Sa={name:"arrow-up",size:24,node:[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]};Sa.node;const Aa=Te(Sa);const Ea={name:"check",size:24,node:[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]};Ea.node;const Ld=Te(Ea);const Ta={name:"circle-alert",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]],aliases:["alert-circle"]};Ta.node;const $d=Te(Ta);const Ma={name:"command",size:24,node:[["path",{d:"M15 6v12a3 3 0 1 0 3-3H6a3 3 0 1 0 3 3V6a3 3 0 1 0-3 3h12a3 3 0 1 0-3-3",key:"11bfej"}]]};Ma.node;const Wd=Te(Ma);const Ca={name:"info",size:24,node:[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]};Ca.node;const Pd=Te(Ca);const Ia={name:"search",size:24,node:[["path",{d:"m21 21-4.34-4.34",key:"14j7rj"}],["circle",{cx:"11",cy:"11",r:"8",key:"4ej97u"}]]};Ia.node;const Oa=Te(Ia);const _a={name:"x",size:24,node:[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]};_a.node;const Dd=Te(_a),Ud={info:{box:"bg-fill-quiet inset-ring inset-ring-hairline",icon:"text-ink-muted",Icon:Pd},error:{box:"bg-fill-selected inset-ring inset-ring-rule-strong shadow-edge",icon:"text-ink",Icon:$d}};function F({tone:e="info",title:t,titleId:s,live:o=!0,children:r,action:a,className:i}){const{box:l,icon:d,Icon:c}=Ud[e];return n.jsxs("div",{"data-slot":"callout","data-tone":e,role:o?e==="info"?"status":"alert":void 0,className:A("flex items-start gap-3 rounded-inner px-4 py-3",l,i),children:[n.jsx(c,{"aria-hidden":!0,className:A("mt-px size-4.5 shrink-0",d),strokeWidth:1.75}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsx("p",{id:s,className:"text-row font-semibold text-ink",children:t}),r&&n.jsx("div",{className:"mt-0.5 text-body wrap-break-word text-ink-secondary",children:r})]}),a&&n.jsx("div",{className:"shrink-0 self-center",children:a})]})}function Fd(e){const t=[];let s="";for(const o of e.match(/[^/\\]+[/\\]*|[/\\]+/g)??[])/[\p{L}\p{N}]/u.test(o)?(t.push(s+o),s=""):s+=o;return s!==""&&t.push(s),t}function Me({children:e,...t}){const s=[];return e.split(/(\s+)/).forEach((o,r)=>{if(o==="")return;if(/^\s+$/.test(o)){s.push(o);return}const a=Fd(o);a.forEach((i,l)=>{s.push(n.jsxs(p.Fragment,{children:[n.jsx("span",{"data-part":"word",className:"inline-block max-w-full wrap-anywhere",children:i}),l<a.length-1&&n.jsx("wbr",{})]},`${r}-${l}`))})}),n.jsx("span",{"data-slot":"literal",...t,children:s})}function De({children:e,className:t}){return n.jsx("dl",{"data-slot":"fact-list",className:A("flex flex-col",t),children:e})}function te({label:e,children:t,mono:s=!1,note:o}){return n.jsxs("div",{"data-slot":"fact-row",className:A("items-baseline border-b border-hairline py-2.5 last:border-b-0",o===void 0?A("flex justify-between gap-x-6",s&&"flex-wrap gap-y-1"):"grid grid-cols-[auto_minmax(0,1fr)] gap-x-6"),children:[n.jsx("dt",{className:"shrink-0 text-body text-ink-secondary",children:e}),n.jsx("dd",{className:A("min-w-0 text-right text-pretty text-ink",s?"ml-auto font-mono text-fact":"text-body font-medium"),children:s&&typeof t=="string"?n.jsx(Me,{children:t}):t}),o!==void 0&&n.jsx("dd",{"data-part":"note",className:"col-span-2 mt-1 text-caption text-ink-secondary",children:o})]})}const Hd=["claude","gh"],zd=new RegExp([String.raw`\b[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+\b`,String.raw`\bPATH\b`,String.raw`(?<![\w.:/~])(?:~|\.{1,2})?(?:/[\w.@%+~-]+)+/?`,String.raw`\b[A-Za-z]:\\[^\s,;]+`,String.raw`\bgh auth login\b`,String.raw`\b(?:${Hd.join("|")})\b(?![\w-]|\.\w)(?:(?: [a-z][\w-]*)*(?: --?[a-z][\w-]*)+)?`,String.raw`(?<![\w-])--[a-z][\w-]*`].join("|"),"g"),Bd=/[.,;:!?]+$/;function qd(e){const t=[],s=(r,a)=>{if(r==="")return;const i=t[t.length-1];i&&i.fact===a?i.text+=r:t.push({text:r,fact:a})};let o=0;for(const r of e.matchAll(zd)){const a=r.index,i=r[0].replace(Bd,"");i!==""&&(s(e.slice(o,a),!1),s(i,!0),o=a+i.length)}return s(e.slice(o),!1),t}function B({children:e}){return n.jsx(n.Fragment,{children:qd(e).map((t,s)=>t.fact?n.jsx("code",{"data-slot":"fact",className:"font-mono text-fact",children:n.jsx(Me,{children:t.text})},s):t.text)})}const Es="remote:",Gd=24,Kd=new RegExp(`^[A-Za-z0-9][A-Za-z0-9-]{0,${Gd-1}}$`);function kn(e){return typeof e=="string"&&Kd.test(e)}function ge(e){return e.startsWith(Es)}function ut(e){if(!e.startsWith(Es))return null;const t=e.slice(Es.length),s=t.indexOf(":");if(s<0)return null;const o=t.slice(0,s);return kn(o)?o:null}function Bt(e,t){return t==null?e:`${e} on ${t}`}const Vd=["terminal","vscode","desktop","cloud","browser","unknown"],Yd={terminal:"Terminal",vscode:"VS Code",desktop:"Desktop app",cloud:"Cloud",browser:"Browser"};function qt(e){return e==="unknown"?null:Yd[e]}const jn=["needs-you","working","idle","finished","failed","unknown"],Xd=["permission","question","other"],Vs=["Terminal","iTerm2"],Jd=["signal","background"],Ra=["allow","deny"],Qd=["edit","too-long","hidden-characters","not-yes-or-no","right-to-left","blank-lines"],Zd=["Edit","Write","MultiEdit","NotebookEdit"],eu=["ExitPlanMode","AskUserQuestion"],tu=["open","draft","merged","closed"],nu=["failing","pending","passing","none"],su=["ok","searching","unavailable","not-set-up","error"],La={ok:"Watching",searching:"Searching",unavailable:"Not found","not-set-up":"Not set up",error:"Not working"},at=["working-and-idle","needs-you","finished","failed","names","jump","quiet-for","tokens","stop","answer"],$a={"working-and-idle":"Working and idle","needs-you":"Needs you",finished:"Finished",failed:"Failed",names:"Names",jump:"Jump","quiet-for":"Quiet for",tokens:"Tokens",stop:"Stop",answer:"Answer"},nt={yes:"Yes",no:"No",partly:"Partly"},ou=["appeared","status-changed","ended","stopped","answered"],ru=["appeared","status-changed","ended"];function Ys(e){return ru.includes(e.kind)}const au=["agent-lookout"],iu=["advisory","warning","critical"];function Mt(e){if(e.waitingText===void 0&&e.ask===void 0)return e;const{waitingText:t,ask:s,...o}=e;return o}function lu(e,t){return e.agent??t.find(s=>s.id===e.source)?.label??null}function fe(e){return e.status==="needs-you"&&e.answered!==!0}const cu=new Map;function du(e,t){return e===null?t:t===null?e:t>e?t:e}function uu(e,t){const s=new Map;for(const i of t.sources)(i.state==="ok"||i.state==="not-set-up")&&s.set(i.id,new Map);const o=[],r=[];for(const i of t.sessions){if(!fe(i))continue;const l=s.get(i.source);if(!l||l.has(i.id))continue;const d=e.get(i.source);if(!d?.has(i.id)){d&&o.push(i),l.set(i.id,i.statusSince);continue}const c=d.get(i.id)??null,u=i.statusSince;c!==null&&u!==null&&u>c&&(r.push(i.id),o.push(i)),l.set(i.id,du(c,u))}const a=new Map(e);for(const[i,l]of s){for(const d of e.get(i)?.keys()??[])l.has(d)||r.push(d);a.set(i,l)}return{memory:a,started:o,stopped:r}}const mt=["needs-you","finished","failed","ended"],Ts=["needs-you"];function fu(e){return mt.includes(e)}function hu(e){const t=e.trim().toLowerCase();if(t==="")return[];const s=t.split(",").map(o=>o.trim());return s.every(fu)?mt.filter(o=>s.includes(o)):null}function Pt(e){return mt.filter(t=>e.includes(t)).join(",")}const Ho={waits:cu,seen:new Map,over:new Map};function dn(e){return e==="finished"||e==="failed"}function mu(e,t){return t===void 0?!1:e==="ended"||t==="ended"||t===e}function pu(e,t){const s=uu(e.waits,t),o=new Set(s.started),r=new Map;for(const u of t.sources)(u.state==="ok"||u.state==="not-set-up")&&r.set(u.id,{basis:u.basis??"",sessions:new Map});const a=[];for(const u of t.sessions){const f=r.get(u.source);if(!f||f.sessions.has(u.id))continue;if(f.sessions.set(u.id,Mt(u)),o.has(u)){a.push({event:"needs-you",session:u});continue}const m=e.seen.get(u.source)?.get(f.basis)?.get(u.id);m&&m.status!==u.status&&dn(u.status)&&a.push({event:u.status,session:u})}for(const[u,{basis:f,sessions:m}]of r)for(const[w,x]of e.seen.get(u)?.get(f)??[])!m.has(w)&&!dn(x.status)&&a.push({event:"ended",session:x});const i=new Map;for(const[u,{sessions:f}]of r){const m=new Map(e.over.get(u));for(const[w,x]of f)dn(x.status)||m.delete(w);i.set(u,m)}const l=a.filter(({event:u,session:f})=>{const m=i.get(f.source);return u==="needs-you"||!m?!0:mu(u,m.get(f.id))?!1:(m.set(f.id,u),!0)}),d=new Map(e.seen),c=new Map(e.over);for(const[u,{basis:f,sessions:m}]of r){const w=new Map(e.seen.get(u));w.set(f,m),d.set(u,w);const x=i.get(u);for(const[g,h]of m)dn(h.status)&&!x.has(g)&&x.set(g,h.status);for(const g of x.keys())[...w.values()].some(h=>h.has(g))||x.delete(g);c.set(u,x)}return{memory:{waits:s.memory,seen:d,over:c},changes:l,stopped:s.stopped}}const xu=["started","cleared","trimmed"],gu="clear-history",wu="/api/sessions/last-message",bu=["off","not-read","not-found","unreadable","nothing-yet","too-far-back"],yu=["AGENT_LOOKOUT_LAST_MESSAGE","AGENT_LOOKOUT_WAITING_TEXT"],ku=6e4,ju=1e3,Nu="stop",vu="clean-up",Wa=1e4,st=20,Su=["ended","became-active","not-stale","gone","unsupported","cannot-confirm","not-allowed","still-running","failed"],Au="answer",Eu="/api/settings",Tu="/api/settings/time-rules",Mu="time-rules",Cu="/api/settings/permission-rules",Iu="permission-rules",Ou=100,we="X-Agent-Lookout-Action",_u=200,Ru="X-Agent-Lookout-Notifications";function Pa(e){const t=Pt(e);return t===""?"off":t===Pt(Ts)?"on":`on; events=${t}`}const Nn=20,Lu=/^(?:[A-Za-z0-9_-]+(?:\.[A-Za-z0-9_-]+)*\.?|\[[0-9A-Fa-f:.]+\])$/,$u=253;function Da(e){return e.length<=$u&&Lu.test(e)}const Wu="/api/phone/test",Pu="phone-test",Du=["unknown","ready","not-found","signed-out"],Uu=900*1e3;function Se(e){return e.since??{at:e.startedAt,by:"started"}}function ns(){return typeof window>"u"?null:window.Notification??null}const Ua={permission(){const e=ns();if(!e)return"unsupported";const{permission:t}=e;return t==="granted"||t==="denied"?t:"default"},requestPermission(){const e=ns();return e?new Promise(t=>{const s=()=>t(Ua.permission());try{e.requestPermission(s)?.then(s,s)}catch{s()}}):Promise.resolve("unsupported")},show({title:e,body:t,tag:s}){const o=ns();if(!o)return null;try{const r=new o(e,{body:t,tag:s});return r.addEventListener("click",()=>window.focus()),{close(){try{r.close()}catch{}},onClosed(a){r.addEventListener("close",a)}}}catch{return null}}};let Fu=Ua;function Xs(){return Fu}const Js="agent-lookout-notifications",Qs="agent-lookout-notification-events";function Fa(){try{const e=localStorage.getItem(Js);return e===null?null:e==="on"?"on":"off"}catch{return null}}function Ha(){try{const e=localStorage.getItem(Qs);return(e===null?null:hu(e))??Ts}catch{return Ts}}let ot,Ke=null,Be=null,Ms=null,ss=null;const St=new Set;let Ct=null;function pt(){ot===void 0&&(ot=Fa()),Ke??=Ha();const e=Xs().permission(),t=ot!==null,s=ot??"off";return(!Be||Be.choice!==s||Be.chosen!==t||Be.permission!==e||Be.events!==Ke)&&(Be={choice:s,chosen:t,permission:e,on:s==="on"&&e==="granted",events:Ke}),Be}function Zs(){const e=pt();return e.on?e.events:[]}function Re(){const e=pt();if(e!==Ms){Ms=e;for(const t of St)t()}}function za(e){ot=e;try{localStorage.setItem(Js,e)}catch{}}function Hu(){if(Ct)return;const e=t=>{if((t.key===null||t.key===Js)&&(ot=Fa()),t.key===null||t.key===Qs){const s=Ha();(Ke===null||Pt(s)!==Pt(Ke))&&(Ke=s)}Re()};window.addEventListener("storage",e),window.addEventListener("focus",Re),document.addEventListener("visibilitychange",Re),Ct=()=>{window.removeEventListener("storage",e),window.removeEventListener("focus",Re),document.removeEventListener("visibilitychange",Re)}}function Ba(e){return St.size===0&&(Ms=pt()),St.add(e),Hu(),()=>{St.delete(e),St.size===0&&Ct&&(Ct(),Ct=null)}}async function zu(){const e=Xs();let t=e.permission();if(t==="default")try{t=await e.requestPermission()}catch{t=e.permission()}t==="granted"&&za("on"),Re()}function qa(){return ss??=zu().finally(()=>{ss=null}),ss}function Bu(){za("off"),Re()}function qu(e,t){const s=pt().events;if(s.includes(e)===t)return;const o=mt.filter(r=>r===e?t:s.includes(r));Ke=o;try{localStorage.setItem(Qs,Pt(o))}catch{}Re()}const Gu=(e,t)=>fetch(e,t);let Ku=Gu;const zo="http://app.invalid";function Vu(e){if(!e.startsWith("/"))return!1;try{return new URL(e,zo).origin===zo}catch{return!1}}function Yu(){return Pa(Zs())}function Y(e,t){if(!Vu(e))return Promise.reject(new TypeError(`apiRequest takes a path on this app's own server, not ${JSON.stringify(e)}.`));const s=new Headers(t?.headers);return s.set(Ru,Yu()),Ku(e,{...t,headers:s})}const Ga=(e,t)=>{const s=setInterval(e,t);return()=>clearInterval(s)},Xu=1e4,Ju=5,Qu=(e,t)=>{let s=null,o=null,r=!1,a=!1,i;const l=()=>{clearTimeout(i),s?.terminate(),s=null,!(r||o)&&(o=Ga(e,t))};try{s=new Worker(new URL("/assets/beatWorker-zHI4d3P9.js",import.meta.url),{type:"module"}),s.addEventListener("message",()=>{a=!0,e()}),s.addEventListener("error",l),s.postMessage(t),i=setTimeout(()=>{a||l()},Math.max(Xu,t*Ju))}catch{l()}return()=>{r=!0,clearTimeout(i),s?.terminate(),s=null,o?.(),o=null}},it=6e4;function Nj(e,t){return e.map(s=>({at:s.at,value:s[t]}))}const vj=[{id:"15m",label:"15 min",ms:15*it,words:"the last 15 minutes"},{id:"1h",label:"1 hour",ms:60*it,words:"the last hour"},{id:"6h",label:"6 hours",ms:360*it,words:"the last 6 hours"}],Zu=[1,2,5,10,20,25,50,100,200,250,500,1e3];function ef(e){const t=Math.max(1,Math.ceil(e)),s=Zu.find(a=>t/a<=4)??Math.ceil(t/4),o=Math.ceil(t/s)*s,r=[];for(let a=0;a<=o;a+=s)r.push(a);return{ceiling:o,ticks:r}}const tf=[1,2,5,10,15,30,60,120,180,360];function Ka(e,t,s){const o=t-e;if(o<=0||s<1)return[];const r=(tf.find(l=>o/(l*it)<=s)??720)*it,a=new Date(e).getTimezoneOffset()*it,i=[];for(let l=Math.ceil((e-a)/r)*r+a;l<=t;l+=r)i.push(l);return i}function nf(e,t){if(!t)return e;if(Va(e,t))return t;const s=t.points[0];if(!s||t.startedAt!==e.startedAt)return e;const o=e.points.filter(r=>r.at<s.at);return{...t,startedAt:e.startedAt,points:[...o,...t.points]}}function Va(e,t){const s=Se(t);return s.by==="cleared"&&s.at!==Se(e).at}const sf=/^[A-Za-z0-9][A-Za-z0-9-]{0,38}$/,of=/^[A-Za-z0-9._-]{1,100}$/,rf=1e9;function af(e,t){return sf.test(e)&&of.test(t)&&t!=="."&&t!==".."}function lf(e){return typeof e=="number"&&Number.isInteger(e)&&e>0&&e<=rf}const cf=/^https:\/\/github\.com\/([^/]+)\/([^/]+)\/pull\/(\d+)$/;function df(e,t){const s=cf.exec(e);if(s===null)return!1;const[,o="",r="",a=""]=s;return af(o,r)&&a===String(t)}function uf(e){return e.failing>0?"failing":e.pending>0?"pending":e.passing>0?"passing":"none"}const Ya="\\u061c\\u200e\\u200f\\u202a-\\u202e\\u2066-\\u2069",ff=new RegExp(`[\\u0000-\\u001f\\u007f-\\u009f\\u2028\\u2029${Ya}]`,"g"),_n=200,hf=80,Bo=2e3,mf=200,pf=/[^\P{Cc}\n]/gu,xf=new RegExp(`[${Ya}]`,"gu");function gf(e,t=hf){const s=e.replace(ff," ").replace(/\s+/g," ").trim(),o=Array.from(s);return o.length<=t?s:`${o.slice(0,t-1).join("").trimEnd()}…`}function wf(e){if(typeof e!="string")return;const s=e.replace(/\r\n?|[\u2028\u2029]/g,`
3
+ `).replace(/\t/g," ").replace(pf," ").replace(xf,"").split(`
4
+ `).map(l=>l.trimEnd()).join(`
5
+ `).replace(/\n{3,}/g,`
6
+
7
+ `).trim();if(s==="")return;const o=Array.from(s);if(o.length<=Bo)return{text:s,cut:!1};const r=o.slice(-Bo),a=r.indexOf(`
8
+ `),i=a!==-1&&a<mf?a+1:0;return{text:r.slice(i).join("").trimStart(),cut:!0}}function bf(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function os(e){return typeof e=="number"&&Number.isSafeInteger(e)&&e>=0}function yf(e){if(!bf(e))return null;const{input:t,cached:s,output:o}=e;return!os(t)||t===0||!os(o)?null:s===void 0?{input:t,output:o}:!os(s)||s>t?null:{input:t,cached:s,output:o}}const kf=[".","builtin","command","coproc","eval","exec","nocorrect","noglob","source","time","arch","bunx","caffeinate","chroot","doas","env","flock","gtimeout","ionice","nice","nix-shell","nohup","npx","parallel","pnpx","sandbox-exec","script","setsid","stdbuf","su","sudo","taskset","timeout","unbuffer","uvx","watch","xargs","xcrun","ash","bash","busybox","cmd","csh","dash","fish","ksh","powershell","pwsh","sh","tcsh","zsh"],jf=["aria2c","curl","elinks","ftp","grpcurl","http","https","httpx","links","lynx","nc","ncat","netcat","scp","sftp","socat","ssh","telnet","w3m","websocat","wget","xh","xhs","awk","bpython","bun","clj","clojure","dart","deno","elixir","erl","escript","esno","expect","gawk","ghci","groovy","guile","iex","ipython","irb","java","jshell","jrunscript","julia","kotlin","lua","luajit","mawk","nawk","node","nodejs","ocaml","osascript","perl","php","pypy","python","r","racket","raku","rakudo","rscript","ruby","runghc","runhaskell","sbcl","scala","swift","tclsh","ts-node","tsx","vite-node","wish","zx"],Nf=/\.(?:exe|com)$/,vf=/[a-z]/;function Rn(e){return e.slice(e.lastIndexOf("/")+1).toLowerCase().replace(Nf,"")}function Ln(e,t){let s;for(const o of t){if(e===o)return o;e.startsWith(o)&&!vf.test(e.charAt(o.length))&&o.length>(s?.length??0)&&(s=o)}return s}function Sf(e){return Ln(Rn(e),kf)!==void 0}function Af(e){return Ln(Rn(e),jf)!==void 0}const Xa={bundle:["e","ex","exe","exec"],bundler:["e","ex","exe","exec"],cargo:["r","run"],docker:["build","buildx","compose","container","create","exec","run","start"],"docker-compose":["create","exec","run","start","up"],dotnet:["exec","run","tool"],go:["generate","run","tool"],nix:["develop","run","shell"],npm:["create","exec","explore","init","innit","x"],pipx:["run"],pnpm:["create","dlx","exec","x"],podman:["build","compose","container","create","exec","run","start"],poetry:["run"],uv:["run","tool"],yarn:["create","dlx","exec","node"],yarnpkg:["create","dlx","exec","node"]},Ef=["npm"];function Ja(e){return Ln(Rn(e),Object.keys(Xa))}function Tf(e){const[t,s]=e;return t===void 0||Ja(t)===void 0?!1:s===void 0||s.startsWith("-")}function Mf(e){const[t,...s]=e;if(t===void 0)return!1;const o=Ja(t);if(o===void 0)return!1;const r=Xa[o]??[],a=Ef.includes(o);let i=!1;for(const l of s){if(l==="--"){if(i)return!1;continue}l.startsWith("-")||(i=!0);const d=l.toLowerCase();if(r.includes(d)||a&&d.length>=2&&r.some(c=>c.startsWith(d)))return!0}return!1}const qo={git:["c","config-env","exec-path","receive-pack","upload-pack"],go:["exec","toolexec","vettool"],npm:["call","node-options","script-shell"]};function Cf(e){const[t,...s]=e;if(t===void 0)return!1;const o=Ln(Rn(t),Object.keys(qo));if(o===void 0)return!1;const r=qo[o]??[];return s.some(a=>{if(!a.startsWith("-"))return!1;const[i=""]=a.replace(/^-+/,"").split("=");return r.includes(i)})}const Go=".agent-lookout",Ko="/.vol";function Vo(e){const t=e.toLowerCase();if(!t.startsWith("/"))return t;const s=[];for(const o of t.split("/"))o===""||o==="."||(o===".."?s.pop():s.push(o));return`/${s.join("/")}`}function If(e){const t=[];let s=e;for(;s!=="/"&&s!=="";)s=s.slice(0,s.lastIndexOf("/"))||"/",t.push(s);return t}function Of(e,t=[],s){const o=t.filter(i=>i.startsWith("/")).map(Vo),r=new Set(o.flatMap(If)),a=o.filter(i=>!i.includes(Go)).map(i=>i.slice(i.lastIndexOf("/")+1));return e.some(i=>{const l=i.toLowerCase();return l.includes(Go)?!0:[l,...l.split("=").slice(1)].flatMap(u=>[u]).some(u=>{const f=Vo(u);return f===Ko||f.startsWith(`${Ko}/`)||o.some(m=>f===m||f.startsWith(`${m}/`))||r.has(f)?!0:a.some(m=>f===m||f.endsWith(`/${m}`))})})}const _f=/^[A-Za-z0-9_\-.,/:=+@%]+$/,Qa=/^[A-Za-z_][A-Za-z0-9_]*=/;function Rf(e){if(e==="")return null;const t=e.split(" ");for(const s of t)if(s===""||!_f.test(s)||s.startsWith("="))return null;return Qa.test(t[0])?null:t}const Yo=":*",Za=["allow","ask","deny"],$n="*",lt="Bash",vn="mcp__",eo="__";function Lf(e){if(!e.startsWith(vn))return!1;const t=e.slice(vn.length);return t!==""&&!t.includes(eo)}const $f=100,Wf=128,Xo=200,Pf=/^[A-Za-z][A-Za-z0-9_-]*$/,Df=/^[A-Za-z0-9-]{1,40}$/,Uf=/^[\x21-\x7e]+(?: [\x21-\x7e]+)*$/,Ff=/[;&|<>()`'"\\{}$*]/;function ei(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function Hf(e,t,s=[]){const o=Object.keys(e);return t.every(r=>o.includes(r))&&o.every(r=>t.includes(r)||s.includes(r))}function zf(e){return e===$n?null:e===""?"Name a tool, such as Bash or WebFetch, or * for every tool.":e.includes("(")?"Write the tool's name alone, such as Bash, and the command in its own field.":e!==lt&&e.toLowerCase()===lt.toLowerCase()?`Claude Code writes this tool's name ${lt}.`:e.length>Wf||!Pf.test(e)||e===vn||e.startsWith(vn)&&e.endsWith(eo)?"A tool's name is written as Claude Code writes it: a letter, then letters, digits, _ and -, such as Bash, WebFetch or mcp__docs__search.":null}function Bf(e,t){if(e.length>Xo)return`A command in a rule is ${Xo} characters at most.`;if(!Uf.test(e))return"Write the command in plain ASCII letters, digits and marks, with one space between words and none at either end.";const o=e.endsWith(Yo)?e.slice(0,-Yo.length):e;if(o===""||o.endsWith(" "))return"Write :* straight after the words a command begins with, as in npm test:*.";if(e.endsWith(" *"))return"Write a prefix with :* straight after its words, as in npm test:*.";if(Ff.test(o))return"A rule names one command by its words: no ;, &, |, <, >, ( ), quotes, backslashes, $, { }, or * other than the :* that ends a prefix.";if(t==="allow"&&Rf(o)===null)return"An allow rule names one plain command: no ~, !, ^, #, ?, [ ], no word starting with =, and no variable set before it.";const[r=""]=o.split(" ");return Qa.test(r)?"Begin the command with the program's name: the variables set before a command are passed over when it is matched.":t==="allow"&&Sf(r)?`${r} runs another command, so an allow rule for it would let Claude Code run anything without asking you. Name the command it would run instead.`:t==="allow"&&Af(r)?`${r} is, or is named like, a program that can send requests or run code that does, so an allow rule for it would let Claude Code reach Agent Lookout on this computer and add a rule or answer its own prompts without asking you. Answer such commands by hand, or allow a script the project owns, such as ./scripts/test.sh, knowing Claude can edit it.`:t==="allow"&&Tf(o.split(" "))?`${r} does something different for each subcommand, and some run any code they are pointed at, so an allow rule for it names the subcommand too, such as ${r} test:*.`:t==="allow"&&Cf(o.split(" "))?`${o} names an option through which ${r} runs another program, so an allow rule for it would let Claude Code run anything without asking you.`:t==="allow"&&Mf(o.split(" "))?`${o} fetches or runs code that Claude Code can choose, so an allow rule for it would let it run anything without asking you. Name the script it should run instead, or answer such commands by hand.`:t==="allow"&&Of(o.split(" "))?"An allow rule may not name Agent Lookout's own folder, ~/.agent-lookout, which holds its settings and its rules.":null}function to(e){const{decision:t,tool:s,command:o}=e,r=zf(s);if(r!==null)return r;if(o!==void 0){if(s!==lt)return"A command goes with Bash only. Leave it empty for any other tool.";const a=Bf(o,t);if(a!==null)return a}return t!=="allow"?null:s===$n?"An allow rule names one tool. Allowing every tool would let Claude Code run anything without asking you.":s===lt&&o===void 0?"An allow rule for Bash names a command. Allowing every command would let Claude Code run anything without asking you.":Lf(s)?`An allow rule names one tool of a server, such as ${s}${eo}search. Allowing every tool of ${s} would let Claude Code use each without asking you.`:Zd.includes(s)?`Agent Lookout does not show the change ${s} makes, so it never allows one, by hand or by a rule.`:eu.includes(s)?`${s} is answered with more than yes or no, so Agent Lookout never allows it, by hand or by a rule.`:null}function ti(e){const t='A rule is {"decision": "allow", "ask" or "deny", "tool": "...", "command": "..."}, with the command for Bash only, and nothing else.';if(!ei(e)||!Hf(e,["decision","tool"],["command"]))return{ok:!1,problem:t};const{decision:s,tool:o,command:r}=e;if(!Za.includes(s))return{ok:!1,problem:t};if(typeof o!="string"||r!==void 0&&typeof r!="string")return{ok:!1,problem:t};const a={decision:s,tool:o,...r!==void 0&&{command:r}},i=to(a);return i===null?{ok:!0,words:a}:{ok:!1,problem:i}}function qf(e){return typeof e=="string"&&Df.test(e)}function Gf(e){if(!ei(e))return null;const{id:t,...s}=e;if(!qf(t))return null;const o=ti(s);return o.ok?{id:t,...o.words}:null}function ni(e){if(e===void 0)return{ok:!0,rules:[]};if(!Array.isArray(e)||e.length>$f)return{ok:!1};const t=[],s=new Set;for(const o of e){const r=Gf(o);if(r===null||s.has(r.id))return{ok:!1};s.add(r.id),t.push(r)}return{ok:!0,rules:t}}function Wn(e){return e.tool===$n?null:e.command===void 0?e.tool:`${e.tool}(${e.command})`}function L(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}function W(e){return typeof e=="string"&&e.trim()!==""?e:null}function U(e){return typeof e=="number"&&Number.isFinite(e)?e:null}function G(e,t){return e.includes(t)?t:null}function Cs(e,t){const s=new Set,o=[];for(const r of e){const a=t(r);!a||s.has(a.id)||(s.add(a.id),o.push(a))}return o}function Kf(e){if(!L(e))return null;const t=W(e.id),s=W(e.source);if(!t||!s)return null;const o=W(e.project),r=G(jn,e.status)??"unknown",a=!kn(e.machine),i={id:t,source:s,surface:G(Vd,e.surface)??"unknown",name:W(e.name)??o??t,cwd:W(e.cwd),project:o,status:r,startedAt:U(e.startedAt),statusSince:U(e.statusSince),links:{},stale:e.stale===!0};if(r==="needs-you"){const x=G(Xd,e.waitingReason);x&&(i.waitingReason=x);const g=W(e.waitingDetail);g&&(i.waitingDetail=g);const h=W(e.waitingText);h&&(i.waitingText=h);const j=a?Yf(e.ask):null;j&&(i.ask=j),e.answered===!0&&(i.answered=!0)}const l=W(e.agent);l&&(i.agent=l),kn(e.machine)&&(i.machine=e.machine);const d=U(e.lastWriteAt);d!==null&&(i.lastWriteAt=d);const c=yf(e.tokens);c&&(i.tokens=c);const u=U(e.pid);if(u!==null&&(i.pid=u),typeof e.alive=="boolean"&&(i.alive=e.alive),L(e.links)){const x=W(e.links.open);x&&(i.links.open=x)}const f=a?ih(e.jump):null;f&&(i.jump=f);const m=a&&L(e.stop)?G(Jd,e.stop.how):null;m&&(i.stop={how:m});const w=eh(e.git);return w&&(i.git=w),i}const Vf=/^[0-9a-f]{32}$/,si=8e3;function rs(e){return typeof e=="string"&&e!==""&&e.length<=si?e:null}function Yf(e){if(!L(e))return null;const{requestId:t}=e,s=W(e.tool),o=U(e.until);if(typeof t!="string"||!Vf.test(t)||!s||s.length>200||o===null||typeof e.allow!="boolean")return null;const r={requestId:t,tool:s,allow:e.allow,until:o};if(e.command!==void 0){const a=rs(e.command);if(a===null)return null;r.command=a}if(e.description!==void 0){const a=rs(e.description);if(a===null)return null;r.description=a}if(e.inputs!==void 0){if(!Array.isArray(e.inputs)||e.inputs.length>30)return null;const a=[];for(const i of e.inputs){if(!L(i)||typeof i.value!="string"||i.value.length>si)return null;const l=rs(i.name);if(l===null)return null;a.push({name:l,value:i.value})}r.inputs=a}if(!r.allow){const a=G(Qd,e.denyOnly);a&&(r.denyOnly=a)}return e.subagent===!0&&(r.subagent=!0),r}function Xf(e){if(!L(e))return null;const t=G(["on","off","unavailable"],e.state),s=G(["seen","missed","unknown"],e.plugin),o=U(e.holdMs);if(!t||!s||o===null)return null;const r={state:t,plugin:s,holdMs:o},a=W(e.problem);return a&&(r.problem=a),r}const Jf=_n,Qf=/^[0-9a-f]{7,64}$/,Zf=/^[0-9a-f]{16,64}$/;function eh(e){if(!L(e))return null;const t=oh(e);if(t===null)return null;const s=rh(e.repository),o=t.branch===void 0?null:sh(e.pullRequest);return{...t,...s!==null&&{repository:s},...o!==null&&{pullRequest:o}}}const th=1e4;function as(e){return typeof e=="number"&&Number.isInteger(e)&&e>=0&&e<=th?e:null}function nh(e){if(!L(e))return null;const t=as(e.passing),s=as(e.failing),o=as(e.pending),r=G(nu,e.state);if(t===null||s===null||o===null||r===null)return null;const a={passing:t,failing:s,pending:o};return uf(a)===r?{state:r,...a}:null}function sh(e){if(!L(e))return null;const{number:t,url:s}=e;if(!lf(t))return null;const o=W(e.title),r=G(tu,e.state),a=nh(e.checks);return o===null||Array.from(o).length>_n||r===null||a===null||typeof s!="string"||!df(s,t)?null:{number:t,title:o,state:r,checks:a,url:s}}function oh(e){if(e.commit===void 0){const s=W(e.branch);return s!==null&&Array.from(s).length<=Jf?{branch:s}:null}if(e.branch!==void 0)return null;const{commit:t}=e;return typeof t=="string"&&Qf.test(t)?{commit:t}:null}function rh(e){if(!L(e))return null;const t=W(e.name);if(t===null||Array.from(t).length>_n)return null;const{id:s}=e;return typeof s=="string"&&Zf.test(s)?{id:s,name:t}:null}const ah=200;function ih(e){if(!L(e))return null;const t=W(e.place);if(!t||t.length>ah)return null;if(e.kind==="tmux")return{kind:"tmux",place:t};const s=e.kind==="terminal"?G(Vs,e.app):null;return s?{kind:"terminal",app:s,place:t}:null}function lh(e,t){if(!L(e))return null;const s=W(e.id);if(!s)return null;const o={id:s,label:W(e.label)??s,state:G(su,e.state)??"error",checkedAt:U(e.checkedAt)??t},r=W(e.detail);if(r&&(o.detail=r),Array.isArray(e.watching)){const d=[];for(const c of e.watching){const u=fh(c);u&&d.push(u)}o.watching=d}const a=W(e.advice);a&&(o.advice=a);const i=W(e.basis);i&&(o.basis=i);const l=oi(e.capabilities);if(l&&(o.capabilities=l),kn(e.machine)&&(o.machine=e.machine),Array.isArray(e.agents)){const d=[];for(const c of e.agents.slice(0,ch)){const u=dh(c);u&&d.push(u)}d.length>0&&(o.agents=d)}return o}const ch=20;function dh(e){if(!L(e))return null;const t=W(e.label),s=oi(e.capabilities);return t&&s?{label:t,capabilities:s}:null}function uh(e){if(!L(e))return null;if(e.level==="yes")return{level:"yes"};const t=G(["no","partly"],e.level),s=W(e.reason);return t&&s?{level:t,reason:s}:null}function oi(e){if(!L(e))return null;const t={};for(const s of at){const o=uh(e[s]);if(!o)return null;t[s]=o}return t}function fh(e){if(!L(e))return null;const t=W(e.label),s=W(e.value);return t&&s?{label:t,value:s}:null}function hh(e){if(!L(e)||!Array.isArray(e.sessions)||!Array.isArray(e.sources))return null;const t=U(e.generatedAt);if(t===null)return null;const s=Xf(e.answering);return{generatedAt:t,sources:Cs(e.sources,o=>lh(o,t)),sessions:Cs(e.sessions,Kf),...s&&{answering:s},...e.timeRules!==void 0&&{timeRules:qs(e.timeRules).rules},...typeof e.quiet=="boolean"&&{quiet:e.quiet}}}function mh(e){if(!L(e))return null;const t=W(e.id),s=U(e.at),o=G(ou,e.kind);if(!t||s===null||!o)return null;const r=W(e.sessionId)??"",a={id:t,at:s,sessionId:r,sessionName:W(e.sessionName)??(r||"A session"),kind:o,severity:G(iu,e.severity)??"advisory"},i=G(jn,e.from);i&&(a.from=i);const l=G(jn,e.to);l&&(a.to=l);const d=G(au,e.by);d&&(a.by=d);const c=G(Ra,e.decision);c&&(a.decision=c);const u=Sn(e.tool);u&&(a.tool=u);const f=xh(e.rule);return f&&(a.rule=f),a}const ph=400;function Sn(e){const t=W(e);return t&&t.length<=ph?t:null}function xh(e){if(!L(e))return null;const t=Sn(e.tool);if(!t)return null;if(e.command===void 0)return{tool:t};const s=Sn(e.command);return s?{tool:t,command:s}:null}function gh(e){return!L(e)||!Array.isArray(e.events)?null:Cs(e.events,mh)}function wh(e){if(!L(e))return null;const t=U(e.at),s=U(e.needsYou),o=U(e.working),r=U(e.idle),a=U(e.total);return t===null||s===null||o===null||r===null||a===null?null:{at:t,needsYou:s,working:o,idle:r,total:a}}function ri(e){if(!L(e))return null;const t=U(e.at),s=G(xu,e.by);return t===null||s===null?null:{at:t,by:s}}const bh=1024;function Jo(e){const t=W(e);return t&&t.length<=bh?t:null}function Ne(e){const t=U(e);return t!==null&&t>=0&&Number.isInteger(t)?t:null}function yh(e){if(!L(e))return null;const t=G(["disk","memory"],e.where),s=Ne(e.maxBytes),o=Ne(e.maxAgeMs);if(t===null||s===null||o===null)return null;const r=t==="disk"?Jo(e.folder):null;return t==="disk"&&r===null?null:{where:t,folder:r,bytes:t==="disk"?Ne(e.bytes):null,maxBytes:s,maxAgeMs:o,canClear:t==="disk"&&e.canClear===!0,problem:Jo(e.problem)}}const kh=1e3;function jh(e){if(!L(e))return null;const t=U(e.at),s=U(e.lastBefore);return t===null||s===null||s>=t?null:{at:t,lastBefore:s}}function Nh(e){if(!Array.isArray(e))return[];const t=[];for(const s of e.slice(0,kh)){const o=jh(s);o&&t.push(o)}return t.sort((s,o)=>s.at-o.at)}function vh(e){if(!L(e)||!Array.isArray(e.points))return null;const t=U(e.startedAt);if(t===null)return null;const s=[];for(const i of e.points){const l=wh(i);l&&s.push(l)}const o=ri(e.since),r=yh(e.kept),a=Nh(e.restarts);return{points:s,startedAt:t,...o!==null&&{since:o},...r!==null&&{kept:r},...a.length>0&&{restarts:a}}}const Qo=50;function ai(e){const t=Ne(e.waitedMs),s=Ne(e.openMs),o=Ne(e.waits),r=Ne(e.measuredMs);return t===null||s===null||o===null||r===null?null:{waitedMs:t,openMs:Math.min(s,t),waits:o,measuredMs:r}}function Sh(e){if(!L(e))return null;const t=W(e.day),s=U(e.from),o=U(e.to),r=ai(e);return t===null||!/^\d{4}-\d{2}-\d{2}$/.test(t)||s===null||o===null?null:r&&o>=s?{day:t,from:s,to:o,...r}:null}function Ah(e){if(!L(e))return null;const t=W(e.sessionId),s=Ne(e.waitedMs),o=Ne(e.waits);if(t===null||s===null||o===null)return null;const r=W(e.name);return{sessionId:t,name:r!==null&&Array.from(r).length<=_n?r:t,waitedMs:s,waits:o,open:e.open===!0}}function Zo(e){if(!L(e)||!Array.isArray(e.days)||!Array.isArray(e.sessions))return null;const t=U(e.from),s=U(e.to),o=ai(e),r=Ne(e.sessionCount);if(t===null||s===null||s<t||o===null||r===null)return null;const a=[];for(const d of e.days.slice(0,Qo)){const c=Sh(d);c&&a.push(c)}const i=[],l=new Set;for(const d of e.sessions.slice(0,Qo)){const c=Ah(d);!c||l.has(c.sessionId)||(l.add(c.sessionId),i.push(c))}return{from:t,to:s,...o,days:a.sort((d,c)=>d.from-c.from),sessions:i.sort((d,c)=>c.waitedMs-d.waitedMs),sessionCount:Math.max(r,i.length)}}function Eh(e){if(!L(e))return null;const t=U(e.at),s=Zo(e.today),o=Zo(e.sevenDays),r=ri(e.since),a=G(["disk","memory"],e.where);return t===null||!s||!o||!r||!a?null:{at:t,today:s,sevenDays:o,since:r,where:a}}const Th=300;function Ae(e){const t=W(e);return t&&t.length<=Th?t:null}function Pn(e,t){if(!L(e))return null;const s=U(e.at);return s===null?null:e.sent===!0?{at:s,sent:!0}:{at:s,sent:!1,reason:Ae(e.reason)??t}}function Dn(e){if(!Array.isArray(e))return null;const t=e.filter(o=>typeof o=="string"),s=mt.filter(o=>t.includes(o));return s.length>0?s:null}function Mh(e){if(!L(e)||typeof e.on!="boolean")return null;const t=Ae(e.to),s=Dn(e.events),o=U(e.afterMs),r=e.on&&t!==null&&s!==null&&o!==null&&o>=0;return{on:r,to:r?t:null,events:r?s:null,afterMs:r?o:null,asking:r?e.asking===!0:null,problem:r?null:Ae(e.problem),last:r?Pn(e.last,"the email could not be sent"):null,limitedUntil:r?U(e.limitedUntil):null}}function Ch(e){if(!L(e))return null;const t=U(e.at);return t===null?null:e.ok===!0?{at:t,ok:!0}:{at:t,ok:!1,reason:Ae(e.reason)??"gh did not answer"}}function Ih(e){if(!L(e)||typeof e.on!="boolean")return null;const t=G(Du,e.gh),s=e.on&&t!==null;return{on:s,problem:s?null:Ae(e.problem),gh:s?t:null,last:s?Ch(e.last):null}}function Oh(e){if(!L(e)||typeof e.on!="boolean")return null;const t=Ae(e.host),s=Dn(e.events),o=U(e.afterMs),r=e.on&&t!==null&&Da(t)&&s!==null&&o!==null&&o>=0;return{on:r,host:r?t:null,events:r?s:null,afterMs:r?o:null,asking:r?e.asking===!0:null,problem:r?null:Ae(e.problem),last:r?Pn(e.last,"the post could not be sent"):null,limitedUntil:r?U(e.limitedUntil):null}}function _h(e){if(!L(e)||typeof e.on!="boolean")return null;const t=Ae(e.host),s=Dn(e.events),o=U(e.afterMs),r=e.on&&t!==null&&Da(t)&&s!==null&&o!==null&&o>=0;return{on:r,host:r?t:null,tokenSet:r?e.tokenSet===!0:null,events:r?s:null,afterMs:r?o:null,asking:r?e.asking===!0:null,problem:r?null:Ae(e.problem),last:r?Pn(e.last,"the push could not be sent"):null,limitedUntil:r?U(e.limitedUntil):null}}function Rh(e){if(!L(e)||typeof e.on!="boolean")return null;const t=Dn(e.events),s=U(e.afterMs),o=e.on&&t!==null&&s!==null&&s>=0;return{on:o,events:o?t:null,afterMs:o?s:null,asking:o?e.asking===!0:null,problem:o?null:Ae(e.problem),last:o?Pn(e.last,"the push could not be sent"):null,limitedUntil:o?U(e.limitedUntil):null}}function Lh(e){if(!L(e)||!L(e.timeRules))return null;const t=W(e.file);if(t===null)return null;const s=ni(e.permissionRules),o=Array.isArray(e.ruleAnswers)?e.ruleAnswers:[];return{timeRules:qs(e.timeRules).rules,file:t,problem:W(e.problem),permissionRules:s.ok?s.rules:[],permissionRulesProblem:s.ok?W(e.permissionRulesProblem):"The permission rules Agent Lookout sent could not be read.",ruleAnswers:o.slice(0,Ou).map($h).filter(r=>r!==null),ruleAnswersSince:U(e.ruleAnswersSince)}}function $h(e){if(!L(e))return null;const t=U(e.at),s=W(e.sessionId),o=Sn(e.tool),r=G(Ra,e.decision),a=ti(e.rule);return t===null||!s||!o||!r||!a.ok?null:{at:t,sessionId:s,sessionName:W(e.sessionName)??s,tool:o,decision:r,rule:a.words}}function Wh(e){if(!L(e))return null;const{message:t}=e;if(L(t)){const r=wf(t.text);return r===void 0||typeof t.cut!="boolean"?null:{message:{text:r.text,cut:t.cut||r.cut}}}if(t!==null)return null;const s=G(bu,e.reason);if(s===null)return null;if(e.setting===void 0)return{message:null,reason:s};const o=G(yu,e.setting);return o===null?null:{message:null,reason:s,setting:o}}const ii=2e3,Ph=4e3,er=5e3,tr=Uu,nr=3600*1e3,Dh=60*1e3,Un=_u,Uh=2,Fh={phase:"connecting",snapshot:null,events:[],history:null,lastOkAt:null,problem:null,problemKind:null};class Oe extends Error{kind;status;constructor(t,s,o=null){super(s),this.kind=t,this.status=o}}async function It(e){let t;try{t=await Y(e,{headers:{accept:"application/json"},signal:AbortSignal.timeout(Ph)})}catch(s){const o=s instanceof DOMException&&s.name==="TimeoutError";throw new Oe("no-answer",o?"The local server took too long to answer.":"The local server did not answer.")}if(!t.ok)throw new Oe("error-status",`The local server answered ${e} with error ${t.status}.`,t.status);try{return await t.json()}catch{throw new Oe("not-data",`The local server answered ${e} with something that is not data.`)}}function Hh(e){const t=hh(e);if(!t)throw new Oe("not-data","The local server sent session data in a shape this page cannot read.");return t}function zh(e){const t=gh(e);if(!t)throw new Oe("not-data","The local server sent events in a shape this page cannot read.");return t}function li(e){const t=vh(e);if(!t)throw new Oe("not-data","The local server sent history in a shape this page cannot read.");return t}function Sj(e){return It(`/api/history?windowMs=${Math.round(e)}`).then(li)}async function Aj(e){let t;try{t=await It(`${wu}?id=${encodeURIComponent(e)}`)}catch(o){if(o instanceof Oe&&o.status===429)return"busy";throw o}const s=Wh(t);if(!s)throw new Oe("not-data","The local server sent a last message in a shape this page cannot read.");return s}function Bh(e,t){if(t.length===0)return e;const s=new Set(e.map(r=>r.id)),o=t.filter(r=>!s.has(r.id));return o.length===0?e:[...o,...e].sort((r,a)=>a.at-r.at).slice(0,Un)}function qh(e={}){const t=e.now??Date.now,s=e.intervalMs??ii,o=e.beat??Ga,r=new Set;let a=Fh,i=null,l=!1,d=0,c=null;function u(x){a=x;for(const g of r)g()}async function f(){if(!l){l=!0;try{const x=a.events[0]?.at??0,g=t(),h=c===null||g-c>tr-er,[j,y,k]=await Promise.allSettled([It("/api/sessions").then(Hh),It(`/api/events?since=${x}`).then(zh),It(`/api/history?windowMs=${h?nr:tr}`).then(li)]);let N=a;if(k.status==="fulfilled"){const E=a.history!==null&&(a.history.startedAt!==k.value.startedAt||Va(a.history,k.value));let S;h?(S=k.value,c=g):E||a.history===null?(S=k.value,c=null):(S=nf(a.history,k.value),c=g);const v=t()-nr-Dh;N={...N,history:{...S,points:S.points.filter(b=>b.at>=v)},events:E?[]:N.events}}if(y.status==="fulfilled"&&(N={...N,events:Bh(N.events,y.value)}),j.status==="fulfilled")d=0,N={...N,phase:"live",snapshot:j.value,lastOkAt:t(),problem:null,problemKind:null};else{d+=1;const E=j.reason,S=E instanceof Oe?E:null,v=S?.message??"The local server did not answer.",b=S?.kind??"no-answer";let O;N.snapshot!==null&&N.lastOkAt!==null?O=t()-N.lastOkAt>er?"stalled":N.phase:O=d>=Uh?"unreachable":"connecting",N={...N,phase:O,problem:v,problemKind:b}}u(N)}finally{l=!1}}}function m(){i===null&&(f(),i=o(()=>{f()},s))}function w(){i!==null&&(i(),i=null)}return{subscribe(x){return r.add(x),m(),()=>{r.delete(x),r.size===0&&w()}},getState:()=>a,refresh:()=>{f()}}}const Is=1e3,At=60*Is,Et=60*At,is=24*Et;function Ot(e){return String(e).padStart(2,"0")}function xt(e){const t=Math.max(0,Math.floor(e));return t<At?[{value:String(Math.floor(t/Is)),unit:"s"}]:t<Et?[{value:String(Math.floor(t/At)),unit:"m"},{value:Ot(Math.floor(t%At/Is)),unit:"s"}]:t<is?[{value:String(Math.floor(t/Et)),unit:"h"},{value:Ot(Math.floor(t%Et/At)),unit:"m"}]:[{value:String(Math.floor(t/is)),unit:"d"},{value:Ot(Math.floor(t%is/Et)),unit:"h"}]}function ci(e){return e.map(t=>`${t.value}${t.unit}`).join(" ")}function Q(e){return ci(xt(e))}const Gh={s:"second",m:"minute",h:"hour",d:"day"};function no(e){return e.filter((s,o)=>o===0||Number(s.value)!==0).map(s=>{const o=Number(s.value);return`${o} ${Gh[s.unit]}${o===1?"":"s"}`}).join(" ")}function Ee(e){return no(xt(e))}function ne(e){const t=new Date(e);return`${Ot(t.getHours())}:${Ot(t.getMinutes())}`}function se(e){const t=new Date(e);return t.setHours(0,0,0,0),t.getTime()}const Kh=new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric"}),Vh=new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"numeric"});function so(e,t){return(new Date(e).getFullYear()===new Date(t).getFullYear()?Kh:Vh).format(new Date(e))}function ue(e,t){const s=ne(e);return se(e)===se(t)?s:`${s} on ${so(e,t)}`}const Yh=1e3;function $e(e){return e.charAt(0).toUpperCase()+e.slice(1)}function ls(e){return String(e).padStart(2,"0")}function di(e){const t=xt(e),s=t[0];return s&&(s.unit==="m"||s.unit==="d")?[s]:t}function Dt(e){return ci(di(e))}function ft(e){return no(di(e))}function oo(e){return e<Yh?"just now":`${Q(e)} ago`}function xe(e){const t=new Date(e);return`${ls(t.getHours())}:${ls(t.getMinutes())}:${ls(t.getSeconds())}`}const Xh=new Intl.DateTimeFormat(void 0,{year:"numeric",month:"short",day:"numeric"});function Jh(e,t){const s=new Date(e),o=new Date(t);return s.getFullYear()===o.getFullYear()&&s.getMonth()===o.getMonth()&&s.getDate()===o.getDate()}function Fn(e){return`${Xh.format(new Date(e))} ${xe(e)}`}function ui(e,t){return Jh(e,t)?xe(e):Fn(e)}const fi="status-files";function Qh(e){return e.id===fi?"status files":e.label}function de(e){const t=e.map(Qh);return t.length===0?"your agent tools":t.length===1?t[0]??"":`${t.slice(0,-1).join(", ")} and ${t[t.length-1]}`}function hi(e){return e.state!=="unavailable"&&e.state!=="not-set-up"}function Zh(e){const t=e.filter(o=>o.state!=="not-set-up"),s=t.filter(hi);return s.length>0?s:t}function mi(e,t=[]){const s=new Set;for(const o of e)hi(o)&&o.id!==fi&&!ge(o.id)&&s.add(o.label);for(const o of t)o.agent!==void 0&&s.add(o.agent);return s.size>1}function ro(e,t){return lu(e,t)??e.source}function pi(e){const t=e.filter(s=>ge(s.id));return{away:t.filter(s=>s.state==="unavailable"||s.state==="error"),connecting:t.filter(s=>s.state==="searching")}}function xi(e){const t=[];if(e.away.length>0){const s=e.away.length===1;t.push(`${de(e.away)} ${s?"is":"are"} not connected, so ${s?"its":"their"} sessions are not known.`)}if(e.connecting.length>0){const s=e.connecting.length===1;t.push(`${de(e.connecting)} ${s?"is":"are"} still connecting, so ${s?"its":"their"} sessions are not known yet.`)}return t.length>0?t.join(" "):null}const em=/^vscode:\/\/anthropic\.claude-code\/open\?session=[A-Za-z0-9\-_.!~*'()%]{1,200}$/,ao={"needs-you":"Needs you",working:"Working",idle:"Idle",finished:"Finished",failed:"Failed",unknown:"Unknown"};function tm(e){const t=e.waitingDetail?.trim();return!t||e.waitingReason==="permission"&&/^permission prompt$/i.test(t)||e.waitingReason==="question"&&/^input needed$/i.test(t)?null:t}const Ut="stopped waiting after",nm="was stopped from Agent Lookout",sm="had a request allowed from Agent Lookout",om="had a request denied from Agent Lookout";function gi(e){if(e.kind!=="answered"||e.rule===void 0)return null;const t=e.decision==="deny"?"denied":"allowed",s=`had ${e.tool??"a request"} ${t} by the rule`,o=Wn(e.rule);return o===null?{lead:`${s} for every tool`,rule:o}:{lead:s,rule:o}}function wi(e,t=null){if(e.kind==="appeared")return"appeared";if(e.kind==="ended")return"ended";if(e.kind==="stopped")return nm;if(e.kind==="answered"){const s=gi(e);return s?s.rule===null?s.lead:`${s.lead} ${s.rule}`:e.decision==="deny"?om:sm}if(e.from==="needs-you"&&e.to!=="needs-you"&&t!==null)return`${Ut} ${Q(t)}`;switch(e.to){case"needs-you":return"started waiting";case"working":return"started working";case"idle":return"went idle";case"finished":return"finished";case"failed":return"failed";default:return"changed status"}}const sr={"claude-code":em};function rm(e){const t=e.links.open;return typeof t!="string"?null:(Object.hasOwn(sr,e.source)?sr[e.source]:void 0)?.test(t)?t:null}function We(e){const t=rm(e);return t!==null?{by:"link",href:t,where:qt(e.surface)??"its app"}:e.jump?.kind==="tmux"?{by:"tmux",where:`tmux, ${e.jump.place}`}:e.jump?.kind==="terminal"?{by:"terminal",app:e.jump.app,where:e.jump.place}:null}const am={ok:"Last known: watching",searching:"Last known: searching",unavailable:"Last known: not found","not-set-up":"Last known: not set up",error:"Last known: not working"},im={ok:"Connected",searching:"Connecting",unavailable:"Not connected","not-set-up":"Not set up",error:"Not connected"},lm={ok:"Last known: connected",searching:"Last known: connecting",unavailable:"Last known: not connected","not-set-up":"Last known: not set up",error:"Last known: not connected"};function io(e){return Object.hasOwn(La,e)?e:"error"}function cm(e,t){const s=io(e.state),r=ge(e.id)?t?lm:im:t?am:La;return{key:e.id,name:e.label,state:r[s]}}const dm=[["vscode","VS Code"],["desktop","the desktop app"],["terminal","a terminal"],["cloud","the cloud"],["browser","a browser"],["unknown","another app"]];function um(e){return e.length<=1?e[0]??"":`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function fm(e){const t=new Set(e.map(s=>s.surface));return t.size===1&&t.has("unknown")?"":um(dm.filter(([s])=>t.has(s)).map(([,s])=>s))}function qe(e,t){return e.filter(s=>io(s.state)===t)}function hm(e,t,s,o=null){if(e==="connecting")return{key:"connecting",text:"Connecting to the local server",short:"Connecting",fact:null};if(e==="unreachable")return{key:"not-connected",text:"Not connected to the local server",short:"Not connected",fact:null};if(e==="stalled")return{key:"not-updating",text:"Not updating",short:"Not updating",fact:o===null?null:{text:`since ${xe(o)}`,ticking:!1}};const r=(t?.sources??[]).filter(k=>k.state!=="not-set-up"),a=t?.sessions??[];if(r.length===0)return{key:"no-sources",text:"Not watching any agent tool",short:"Not watching",fact:null};const i=Math.max(...r.map(k=>k.checkedAt)),l={text:`checked ${oo(s-i)}`,ticking:!0},d=r.filter(k=>!ge(k.id)),c=r.filter(k=>ge(k.id)),u=qe(c,"ok"),f=qe(c,"searching"),m=c.filter(k=>{const N=io(k.state);return N==="unavailable"||N==="error"}),w=u.length>0?`${de(u)} over SSH`:"",x=k=>{if(m.length===0)return{...k,fact:l};const N=`${de(m)} not connected`;return{...k,text:`${k.text} · ${N}`,short:`${k.short} · ${N}`,fact:l}};if(a.length>0){const k=`${a.length} ${a.length===1?"session":"sessions"}`,N=qe(d,"ok"),E=fm(a),S=N.length>1||N.length===1&&w?`from ${de(N)}`:E&&!w?`in ${E}`:"",v=w?`from ${w}`:"",b=[S,v].filter(Boolean).join(", and ");return x({key:"watching",text:`Watching ${k}${b?` ${b}`:""}`,short:k})}const g=qe(d,"searching");if(g.length>0||f.length>0){const k=g.length>0?`Looking for ${de(g)} sessions`:"",N=f.length>0?`connecting to ${de(f)} over SSH`:"";return x({key:"searching",text:k?[k,N].filter(Boolean).join(", and "):$e(N),short:k?"Looking for sessions":"Connecting over SSH"})}const h=qe(d,"ok");if(h.length>0||u.length>0){const k=[h.length>0?de(h):"",w].filter(Boolean).join(", and ");return x({key:"none-running",text:`Watching ${k}, no sessions running`,short:"No sessions"})}const j=qe(d,"error");if(j.length>0)return x({key:"not-working",text:`${$e(de(j))} could not be read`,short:j.length===1?"Source not working":"Sources not working"});const y=qe(d,"unavailable");if(y.length===0){const k=m.length===1;return{key:"not-found",text:`${de(m)} ${k?"is":"are"} not connected`,short:`${de(m)} not connected`,fact:l}}return x({key:"not-found",text:`${$e(de(y))} ${y.length===1?"was":"were"} not found`,short:y.length===1?"Source not found":"Sources not found"})}function bi(e){switch(e){case"error-status":return"Agent Lookout answered with an error";case"not-data":return"The answer was not session data";default:return"Agent Lookout is not answering"}}const mm=ii/1e3;function pm({lastOkAt:e,now:t,onRetry:s}){return n.jsx(F,{tone:"error",title:"Agent Lookout has stopped updating",action:n.jsx(D,{size:"sm",onClick:s,children:"Try now"}),children:n.jsxs("p",{children:["This is what it last saw, at"," ",n.jsxs("span",{className:"tabular-nums",children:[xe(e),n.jsxs("span",{"data-part":"age","aria-hidden":!0,"aria-live":"off",children:[" ","(",oo(t-e),")"]})]}),". Check that it is still running in your terminal. The page keeps trying and catches up on its own."]})})}const or="font-mono text-fact";function yi({kind:e}){return e==="error-status"?n.jsx("p",{children:"Its local server is running. Restart Agent Lookout in your terminal, and open the address it prints."}):e==="not-data"?n.jsxs("p",{children:["This page is being served without its collector. Start Agent Lookout with"," ",n.jsx("code",{className:or,children:"npm start"})," or ",n.jsx("code",{className:or,children:"npm run dev"}),", and open the address it prints."]}):n.jsx("p",{children:"Check that Agent Lookout is still running in your terminal."})}function xm({problem:e,kind:t,onRetry:s}){return n.jsxs("section",{"data-slot":"unreachable","data-kind":t??"no-answer","aria-label":"Connection problem",className:"glass-card mx-auto mt-10 w-full max-w-155 p-6 max-mid:p-5",children:[n.jsx(F,{tone:"error",title:bi(t),action:n.jsx(D,{size:"sm",onClick:s,children:"Try now"}),children:n.jsx(yi,{kind:t})}),n.jsxs(De,{className:"mt-3",children:[n.jsx(te,{label:"What happened",children:n.jsx(B,{children:e??"The local server did not answer."})}),n.jsx(te,{label:"Asked for",mono:!0,children:"/api/sessions"}),n.jsx(te,{label:"Trying again",children:n.jsxs("span",{className:"tabular-nums",children:["every ",mm,"s"]})})]})]})}function gm(){qa()}function ki(){return{...p.useSyncExternalStore(Ba,pt),turnOn:gm,turnOff:Bu,chooseEvent:qu}}const wm="/api/app/notifications",bm="/api/app/notifications/test",ym="notification-test",km=1e4,jm=4e3;function Nm(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;const{outcome:t,reason:s}=e;return t==="shown"||t==="unsupported"||t==="no-answer"?{outcome:t}:t==="refused"&&typeof s=="string"?{outcome:t,reason:s}:null}function vm(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;const{lastRefusal:t}=e;return t===null||typeof t=="string"?{lastRefusal:t}:null}async function ji(){try{const e=await Y(bm,{method:"POST",headers:{"Content-Type":"application/json",[we]:ym},body:"{}",signal:AbortSignal.timeout(km)});return e.ok?Nm(await e.json()):null}catch{return null}}async function Sm(){try{const e=await Y(wm,{signal:AbortSignal.timeout(jm)});return e.ok?vm(await e.json()):null}catch{return null}}const Am="agent-lookout",Em=`${Am}:`;function Ni(){return typeof location>"u"?"":location.protocol}function Gt(e=Ni()){return e===Em}function Tm(e=document.documentElement,t=Ni()){Gt(t)&&(e.dataset.host="app")}function Mm({inApp:e=Gt(),sendTest:t=ji}={}){return e?n.jsx(Om,{sendTest:t}):null}const rr="Sending a test…",Cm="Notifications are on in this app.";function cs(){return n.jsx("a",{href:"#settings",className:"rounded-bar underline decoration-rule-strong underline-offset-2 transition-colors duration-120 hover:text-ink",children:"Settings"})}function Im(e){return e===null?{title:"The test was not sent",body:n.jsxs(n.Fragment,{children:["Agent Lookout did not answer. ",n.jsx(cs,{})," can send another test, under Notifications."]}),said:"Agent Lookout did not answer. Settings can send another test, under Notifications."}:e.outcome==="no-answer"?{title:"macOS has not answered yet",body:n.jsxs(n.Fragment,{children:["If macOS asks whether Agent Lookout may show notifications, allow them. ",n.jsx(cs,{})," ","can send another test, under Notifications."]}),said:"If macOS asks whether Agent Lookout may show notifications, allow them. Settings can send another test, under Notifications."}:{title:"macOS did not show the test notification",body:n.jsxs(n.Fragment,{children:["Open ",n.jsx(cs,{})," and send a test under Notifications to see why and what to do."]}),said:"Open Settings and send a test under Notifications to see why and what to do."}}function ds(e){e.currentTarget.closest("main")?.focus({preventScroll:!0})}const us="mt-3 flex min-h-button flex-wrap items-center gap-2";function Om({sendTest:e}){const{chosen:t,turnOff:s}=ki(),[o]=p.useState(!t),[r,a]=p.useState({kind:"asking"}),[i,l]=p.useState(""),d=p.useId(),c=p.useRef(!0);if(p.useEffect(()=>(c.current=!0,()=>{c.current=!1}),[]),!o)return null;const u=g=>{ds(g),a({kind:"sending"}),l(rr);const h=qa();(async()=>{if(await h,!c.current)return;if(!pt().on){a({kind:"asking"}),l("");return}const j=await e();if(!c.current)return;if(j?.outcome==="shown"){a({kind:"shown"}),l(Cm);return}const y=Im(j);a({kind:"noted",note:y}),l(`${y.title}. ${y.said}`)})()},f=g=>{ds(g),s()},m=g=>{ds(g),a({kind:"dismissed"}),l("")},w=g=>n.jsxs(F,{title:"Get a notification when a session needs you?",titleId:d,live:!1,children:[n.jsx("p",{children:"macOS shows one from Agent Lookout each time a session starts waiting for you, with this window open or closed. You can change this in Settings."}),g]});let x=null;return r.kind==="asking"&&!t?x=w(n.jsxs("div",{role:"group","aria-labelledby":d,className:us,children:[n.jsx(D,{size:"sm",onClick:u,children:"Turn on"}),n.jsx(D,{size:"sm",onClick:f,children:"Not now"})]})):r.kind==="sending"?x=w(n.jsx("p",{"data-part":"sending",className:us,children:rr})):r.kind==="noted"&&(x=n.jsxs(F,{title:r.note.title,live:!1,children:[n.jsx("p",{children:r.note.body}),n.jsx("div",{className:us,children:n.jsx(D,{size:"sm",onClick:m,children:"Dismiss"})})]})),n.jsxs(n.Fragment,{children:[x&&n.jsx("div",{"data-slot":"notification-prompt",children:x}),n.jsx("p",{"data-part":"prompt-said",role:"status",className:"sr-only",children:i})]})}const _m=aa("inline-flex h-5 shrink-0 items-center rounded-capsule px-2 text-caption font-medium whitespace-nowrap",{variants:{tone:{neutral:"bg-fill-quiet text-ink-secondary inset-ring inset-ring-control-rim",outline:"text-ink-secondary inset-ring inset-ring-rule-strong"}},defaultVariants:{tone:"neutral"}});function Je({className:e,tone:t,...s}){return n.jsx("span",{"data-slot":"badge","data-tone":t??"neutral",className:A(_m({tone:t}),e),...s})}function Ft({session:e,className:t}){return e.machine===void 0?null:n.jsxs(Je,{"data-part":"machine",className:t,children:[n.jsx("span",{className:"sr-only",children:"on "}),e.machine]})}function Hn({machine:e,className:t}){return e===null?null:n.jsxs("span",{"data-part":"machine",className:A("font-normal",t),children:[" ","on ",e]})}function Kt({title:e,children:t,visual:s,compact:o=!1,className:r}){return n.jsxs("div",{"data-slot":"empty-state",className:A("flex flex-col items-center text-center",o?"px-5 py-8":"px-5 py-14",r),children:[s&&n.jsx("div",{className:"mb-4",children:s}),n.jsx("p",{className:"text-title font-semibold text-ink",children:e}),t&&n.jsx("div",{className:"mt-1.5 max-w-[52ch] text-body text-ink-secondary",children:t})]})}function q({title:e,count:t,sub:s,aside:o,titleRef:r,className:a,children:i,...l}){const d=p.useId();return n.jsxs("section",{"data-slot":"section-card","aria-labelledby":d,className:A("glass-card flex min-w-0 flex-col overflow-hidden",a),...l,children:[n.jsxs("header",{"data-part":"head",className:"flex items-baseline justify-between gap-x-4 gap-y-2 px-6 pt-5 pb-3 max-wide:flex-wrap",children:[n.jsxs("div",{className:"flex min-w-0 items-baseline gap-2",children:[n.jsx("h2",{ref:r,id:d,tabIndex:r?-1:void 0,className:"text-title font-semibold outline-none",children:e}),t!==void 0&&n.jsx("span",{"data-part":"count",className:"-ml-0.5 text-title font-medium text-ink-muted tabular-nums",children:t}),s!==void 0&&n.jsx("span",{"data-part":"sub",className:"text-caption text-ink-muted",children:s})]}),o!==void 0&&n.jsx("div",{"data-part":"aside",className:"min-w-0 text-caption text-ink-muted",children:o})]}),i]})}const Rm={...ao,stale:"Stale",answered:"Needed you, answered",ended:"Ended",lookout:"Agent Lookout"},Lm={"needs-you":"text-status-needs-you-edge",working:"text-status-working",idle:"text-status-idle",stale:"text-status-idle",unknown:"text-status-idle",answered:"text-status-idle",lookout:"text-status-idle",finished:"text-status-finished",failed:"text-status-finished",ended:"text-ink-muted"};function re({kind:e,labelled:t=!1,breathing:s=!1,unlit:o=!1,className:r}){const a=e==="needs-you",i=a&&!o;return n.jsxs("svg",{"data-slot":"status-mark","data-kind":e,"data-lit":a?i:void 0,"data-breathing":i&&s?!0:void 0,viewBox:"0 0 14 14",fill:"none",stroke:"currentColor",className:A("size-mark shrink-0",a&&o?"text-ink":Lm[e],r),...t?{role:"img","aria-label":Rm[e]}:{"aria-hidden":!0},children:[(a||e==="answered")&&n.jsxs(n.Fragment,{children:[n.jsx("circle",{"data-part":"halo",cx:"7",cy:"7",r:"6",strokeWidth:"1.2",strokeOpacity:"0.5",className:A(i&&s&&"motion-safe:animate-lamp")}),n.jsx("circle",{"data-part":"lamp",cx:"7",cy:"7",r:"3.1",strokeWidth:i?1:1.3,className:A(i&&"fill-status-needs-you")})]}),e==="working"&&n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"7",cy:"7",r:"5",strokeWidth:"1.5"}),n.jsx("path",{d:"M7 2a5 5 0 0 1 0 10z",fill:"currentColor",stroke:"none"})]}),e==="idle"&&n.jsx("circle",{cx:"7",cy:"7",r:"5",strokeWidth:"1.5"}),e==="stale"&&n.jsx("circle",{cx:"7",cy:"7",r:"5",strokeWidth:"1.5",strokeDasharray:"2.62 2.62"}),e==="unknown"&&n.jsxs(n.Fragment,{children:[n.jsx("circle",{cx:"7",cy:"7",r:"5",strokeWidth:"1.5"}),n.jsx("path",{d:"M5 7h4",strokeWidth:"1.5",strokeLinecap:"round"})]}),e==="finished"&&n.jsx("path",{d:"M2.6 7.5l2.9 2.9 5.9-6.4",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round"}),e==="failed"&&n.jsx("path",{d:"M3.8 3.8l6.4 6.4M10.2 3.8l-6.4 6.4",strokeWidth:"1.75",strokeLinecap:"round"}),e==="ended"&&n.jsx("path",{d:"M3.5 7h7",strokeWidth:"1.75",strokeLinecap:"round"}),e==="lookout"&&n.jsxs(n.Fragment,{children:[n.jsx("rect",{x:"2.5",y:"2.5",width:"9",height:"9",rx:"1.5",strokeWidth:"1.3"}),n.jsx("path",{d:"M5 11.2l6.2-6.2M2.8 9l6.2-6.2",strokeWidth:"1.1"})]})]})}const $m=250,Wm=250;let Os=!1;typeof window<"u"&&window.addEventListener("scroll",()=>{Os=!0,setTimeout(()=>{Os=!1})},{capture:!0,passive:!0});function ee({content:e,children:t,mono:s=!1,enabled:o=!0,side:r="top",align:a="center"}){const[i,l]=p.useState(!1),d=p.useRef(-1/0),c=o&&e!==null&&e!==void 0&&e!=="";return n.jsx(ic,{delayDuration:$m,children:n.jsxs(lc,{open:i&&c,onOpenChange:u=>{const f=Os&&performance.now()-d.current<Wm;!u&&f||l(u)},children:[n.jsx(cc,{asChild:!0,onFocus:u=>{if(!u.currentTarget.matches(":focus-visible")){u.preventDefault();return}d.current=performance.now()},onBlur:()=>{d.current=-1/0},children:t}),n.jsx(dc,{children:n.jsx(uc,{"data-slot":"tooltip",side:r,align:a,sideOffset:6,collisionPadding:12,className:A("glass-float glass-blur z-60 max-w-[min(26rem,calc(100vw-1.5rem))] animate-in rounded-row","px-2.5 py-1.5 wrap-anywhere text-ink duration-120 fade-in-0",s?"font-mono text-fact":"text-caption font-medium"),children:s&&typeof e=="string"?n.jsx(Me,{children:e}):e})})]})})}function Pm(e,t){if(e.scrollWidth>e.clientWidth)return!0;if(t===1)return!1;const s=Number.parseFloat(getComputedStyle(e).lineHeight),o=Number.isFinite(s)?s/2:1;return e.scrollHeight-e.clientHeight>o}function ae({children:e,lines:t=1,tooltip:s,mono:o=!1,href:r,target:a,className:i,...l}){const d=p.useRef(null),[c,u]=p.useState(!1),f=s??(typeof e=="string"?e:"");p.useEffect(()=>{const w=d.current;if(!w)return;const x=new ResizeObserver(()=>u(Pm(w,t)));return x.observe(w),()=>x.disconnect()},[f,t]);const m=A(t===1?"truncate":"line-clamp-2","rounded-bar",i);return n.jsx(ee,{content:f,enabled:c,mono:o,children:r!==void 0?n.jsx("a",{ref:d,href:r,target:a,"data-cut":c,className:m,...l,children:e}):n.jsx("span",{ref:d,"data-cut":c,tabIndex:c?0:void 0,className:m,...l,children:e})})}const Dm=8e3,ar=.75,Vt=Dm;function Qe(e){return Math.round(e*100)/100}function Ej(e,t,s){const{start:o,end:r}=t,a=t.gapMs??Vt,i=r-o,l=s.right-s.left,d=e.filter(E=>E.at>=o&&E.at<=r&&Number.isFinite(E.value)).sort((E,S)=>E.at-S.at);if(i<=0||d.length===0)return{lines:[],areas:[],unmeasured:[{x:s.left,width:l}],range:null,runs:[]};let c=1/0,u=-1/0;for(const E of d)E.value<c&&(c=E.value),E.value>u&&(u=E.value);const f=Math.max(1,s.ceiling??u),m=E=>Qe(s.left+(E-o)/i*l),w=E=>Qe(s.bottom-Math.min(E,f)/f*(s.bottom-s.top)),x=[];for(const E of d){const S=x[x.length-1],v=S?.[S.length-1];S&&v&&E.at-v.at<=a?S.push(E):x.push([E])}const g=[],h=[],j=[],y=[];x.forEach((E,S)=>{const v=E[0],b=E[E.length-1];if(!v||!b)return;const O=S===0&&v.at-o<=a?o:v.at,H=S===x.length-1&&r-b.at<=a?r:b.at,K=m(O),V=m(H);let R=`M${K} ${w(v.value)}`,P=v.value;for(const T of E)T.value!==P&&(R+=`H${m(T.at)}V${w(T.value)}`,P=T.value);R+=`H${V}`,g.push(R),h.push(`${R}V${s.bottom}H${K}Z`),j.push({x:K,width:V-K}),y.push({from:O,to:H,samples:E})});const k=[];let N=s.left;for(const E of j)E.x-N>=ar&&k.push({x:Qe(N),width:Qe(E.x-N)}),N=Math.max(N,E.x+E.width);return s.right-N>=ar&&k.push({x:Qe(N),width:Qe(s.right-N)}),{lines:g,areas:h,unmeasured:k,range:{min:c,max:u},runs:y}}function Tj(e,t){for(const s of e){if(t<s.from||t>s.to)continue;let o=0,r=s.samples.length-1;for(;o<r;){const a=Math.ceil((o+r)/2);s.samples[a].at<=t?o=a:r=a-1}return s.samples[o]??null}return null}function Um(e,t){const s=new Set(t.filter(fe).map(i=>i.id)),o=new Set,r=new Map,a=new Map;for(let i=e.length-1;i>=0;i-=1){const l=e[i];if(!l||!Ys(l))continue;const d=r.get(l.sessionId);d&&a.set(l,d),r.set(l.sessionId,l)}return e.map(i=>{const l=!o.has(i.sessionId);if(o.add(i.sessionId),i.to==="needs-you"){const f=l&&s.has(i.sessionId);return{event:i,mark:f?"needs-you":"answered",open:f,waitedMs:null}}if(i.kind==="stopped")return{event:i,mark:"ended",open:!1,waitedMs:null};if(i.kind==="answered")return{event:i,mark:"answered",open:!1,waitedMs:null};const d=a.get(i),c=i.from==="needs-you"&&d?.to==="needs-you"?i.at-d.at:null,u=i.to??(i.kind==="ended"?"ended":"unknown");return{event:i,mark:u,open:!1,waitedMs:c}})}function Fm(e,t,s){if(s){const r=e[e.length-1];return r?{at:r.at,started:!1}:null}if(!t)return null;const o=Se(t);return o.by==="trimmed"?{at:o.at,started:!1}:o.by==="cleared"?{at:o.at,started:!0,cleared:!0}:{at:o.at,started:!0}}function Hm(e,t=Vt){if(!e)return[];const s=Se(e).at,o=(e.points??[]).map(a=>a.at).filter(a=>a>=s).sort((a,i)=>a-i),r=[];o.forEach((a,i)=>{const l=o[i-1];l!==void 0&&a-l>t&&r.push({at:a,unmeasuredMs:a-l,before:l})});for(const a of e.restarts??[])a.at<=s||r.some(l=>l.before<a.at&&a.at<=l.at)||r.push({at:a.at,unmeasuredMs:a.at-a.lastBefore,before:a.lastBefore});return r.sort((a,i)=>i.at-a.at).map(({at:a,unmeasuredMs:i})=>({at:a,unmeasuredMs:i}))}function zm(e,t){const s=[];let o=0;for(const r of e){for(;o<t.length&&t[o].at>r.event.at;)s.push({kind:"resumed",gap:t[o]}),o+=1;s.push({kind:"event",entry:r})}for(;o<t.length;o+=1)s.push({kind:"resumed",gap:t[o]});return s}const Bm=1e4;function qm(e){return{away:!0,overview:!1,leftAt:e,since:null,inViewFrom:null}}function Gm(e,t){const s=!e.away&&e.overview,o=t.visible&&t.overview;let{leftAt:r,since:a,inViewFrom:i}=e;if(e.away&&t.visible){const c=a??r;a=c!==null&&t.newestAt!==null&&t.newestAt>c?c:null,i=null}else e.overview&&!t.overview&&t.visible&&(a=null);s&&!o&&(r=Math.max(t.now,t.newestAt??t.now)),a!==null&&(t.newestAt===null||t.newestAt<=a)&&(a=null),a!==null&&o&&t.lineInView?(i??=t.now,t.now-i>=Bm&&(a=null)):i=null,a===null&&(i=null);const l=!t.visible,d=t.overview;return l===e.away&&d===e.overview&&r===e.leftAt&&a===e.since&&i===e.inViewFrom?e:{away:l,overview:d,leftAt:r,since:a,inViewFrom:i}}function Km(e,t){if(t===null)return 0;let s=0;for(;s<e.length&&e[s].at>t;)s+=1;return s}const zn="w-16 shrink-0 self-center font-mono text-caption whitespace-nowrap";function ir({kind:e,side:t}){return n.jsx("span",{"aria-hidden":!0,"data-part":"thread","data-kind":e,className:A("absolute left-1/2 -translate-x-1/2",t==="above"?"top-0 bottom-1/2 mb-2.5":"top-1/2 bottom-0 mt-2.5",e==="line"?"w-px bg-rule":"w-0 border-l border-dotted border-ink-muted opacity-70")})}function lo({thread:e,children:t}){return n.jsxs("span",{className:"relative flex w-mark shrink-0 items-center justify-center",children:[e.above&&n.jsx(ir,{kind:e.above,side:"above"}),t,e.below&&n.jsx(ir,{kind:e.below,side:"below"})]})}function An({at:e,mark:t,thread:s,lit:o=!1,wraps:r=!1,className:a,children:i,...l}){return n.jsxs("li",{...l,"data-lit":o||void 0,className:A("flex min-h-log-row shrink-0 items-stretch gap-3.5 px-6 text-body",o?"text-ink":"text-ink-secondary",a),children:[n.jsx(ee,{content:Fn(e),mono:!0,align:"start",children:n.jsx("time",{dateTime:new Date(e).toISOString(),className:A(zn,"rounded-bar",o?"text-ink-secondary":"text-ink-muted"),children:xe(e)})}),n.jsx(lo,{thread:s,children:t}),n.jsx("div",{className:A("flex min-w-0 flex-1 items-baseline gap-x-1 self-center py-2 max-mid:flex-wrap",r&&"flex-wrap"),children:i})]})}const Vm=p.memo(function({event:t,mark:s,open:o,waitedMs:r,above:a,below:i}){const l=wi(t,r),d=ut(t.sessionId),c=Bt(t.sessionName,d);return n.jsxs(An,{"data-slot":"event-row",at:t.at,lit:o,wraps:t.kind==="answered",thread:{above:a,below:i},mark:n.jsx(re,{kind:s,labelled:!0}),children:[n.jsx(ae,{"data-part":"name",tooltip:`${c} ${l}`,className:"font-semibold text-ink",children:t.sessionName}),n.jsx(Hn,{machine:d,className:"shrink-0 whitespace-nowrap"}),n.jsx("span",{"data-part":"phrase",className:"max-w-full shrink-0",children:t.rule!==void 0?n.jsx(vi,{event:t}):r!==null&&l.startsWith(Ut)?n.jsxs(n.Fragment,{children:[Ut," ",n.jsx("span",{className:"whitespace-nowrap tabular-nums",children:Q(r)})]}):l})]})});function _s(e){return e.charAt(0).toUpperCase()+e.slice(1)}function vi({event:e,start:t=!1}){const s=gi(e);if(s===null)return null;const o=t?_s(s.lead):s.lead;return s.rule===null?n.jsx(n.Fragment,{children:o}):n.jsxs(n.Fragment,{children:[o," ",n.jsx("code",{"data-part":"rule",className:"font-mono text-fact",children:n.jsx(Me,{children:s.rule})})]})}const Ym=6;function Mj({entries:e,now:t,className:s}){const o=[];let r=se(t);for(const i of e){const l=se(i.event.at);l!==r&&(r=l,o.push({kind:"day",day:r})),o.push({kind:"event",entry:i})}const a=e.length>Ym;return n.jsx("ol",{"data-slot":"own-events","aria-label":"Its events, newest first",tabIndex:a?0:void 0,className:A("thin-scroll flex flex-col",a&&"max-h-57 overflow-y-auto focus-visible:-outline-offset-2",s),children:o.map((i,l)=>{const d={above:l===0?null:"line",below:l===o.length-1?null:"line"};if(i.kind==="day")return n.jsx(Si,{day:i.day,now:t,thread:d,className:"px-0"},`day-${i.day}`);const{entry:c}=i,u=wi(c.event,c.waitedMs);return n.jsx(An,{"data-slot":"event-row",at:c.event.at,lit:c.open,thread:d,mark:n.jsx(re,{kind:c.mark,labelled:!0}),className:"px-0",children:n.jsx("span",{"data-part":"phrase",children:c.event.rule!==void 0?n.jsx(vi,{event:c.event,start:!0}):c.waitedMs!==null&&u.startsWith(Ut)?n.jsxs(n.Fragment,{children:[_s(Ut)," ",n.jsx("span",{className:"whitespace-nowrap tabular-nums",children:Q(c.waitedMs)})]}):_s(u)})},c.event.id)})})}function Si({day:e,now:t,thread:s,className:o}){return n.jsxs("li",{"data-slot":"event-day",className:A("flex shrink-0 items-stretch gap-3.5 px-6",o),children:[n.jsx("span",{className:A(zn,"pt-3 pb-1 font-medium text-ink-muted"),children:so(e,t)}),n.jsx(lo,{thread:s})]})}function Xm({since:e,now:t,thread:s,ref:o}){const r=xe(e),a=se(e)===se(t)?r:`${so(e,t)} ${r}`;return n.jsxs("li",{ref:o,"data-slot":"event-new",className:"flex shrink-0 items-stretch gap-3.5 px-6",children:[n.jsx("span",{"aria-hidden":!0,className:zn}),n.jsx(lo,{thread:s}),n.jsxs("span",{className:"flex min-w-0 flex-1 items-center gap-3 py-2",children:[n.jsxs("span",{"data-part":"words",className:"min-w-0 text-caption font-medium text-ink-muted",children:["New since"," ",n.jsx("time",{dateTime:new Date(e).toISOString(),className:"whitespace-nowrap tabular-nums",children:a})]}),n.jsx("span",{"aria-hidden":!0,"data-part":"rule",className:"h-px min-w-4 flex-1 bg-rule max-mid:hidden"})]})]})}function Jm(e,t,s){const[o,r]=p.useState(null);return p.useLayoutEffect(()=>{const a=e.current,i=t.current;if(!a||!i)return;const l=()=>{const c=getComputedStyle(i),u=c.position==="absolute"?a.getBoundingClientRect().height:Number.parseFloat(c.maxHeight);let f=null;if(Number.isFinite(u)&&i.scrollHeight>u+.5){const m=u-Number.parseFloat(c.paddingBottom||"0"),w=i.getBoundingClientRect().top-i.scrollTop;for(const x of i.children){const g=x.getBoundingClientRect().bottom-w;if(g>m+.01)break;f=g}}r(f)};l();const d=new ResizeObserver(l);return d.observe(a),()=>d.disconnect()},[e,t,s]),o}function Qm(e,t){const s=p.useRef(null);return p.useEffect(()=>{const o=s.current;if(!e||!o||!t)return;const r=new IntersectionObserver(a=>{const i=a.at(-1);i&&t(i.isIntersecting&&i.intersectionRatio>=.5)},{threshold:[0,.5,1]});return r.observe(o),()=>{r.disconnect(),t(!1)}},[e,t]),s}function Zm({events:e,sessions:t=[],history:s=null,now:o,newSince:r=null,onNewLineInView:a,className:i}){const l=se(o),d=Fm(e,s,e.length>=Un),c=Hm(s).filter(b=>!d||b.at>=d.at),u=Km(e,r),f=[];let m=u>0?r:null,w=l;const x=b=>{m!==null&&b<=m&&(f.push({kind:"new",key:"new",since:m}),m=null);const O=se(b);O!==w&&(w=O,f.push({kind:"day",key:`day-${w}`,day:w}))};for(const b of zm(Um(e,t),c))b.kind==="event"?(x(b.entry.event.at),f.push({kind:"event",key:b.entry.event.id,...b.entry})):(x(b.gap.at),f.push({kind:"resumed",key:`resumed-${b.gap.at}`,at:b.gap.at,unmeasuredMs:b.gap.unmeasuredMs}));d?.started&&(x(d.at),f.push({kind:"started",key:"started",at:d.at,cleared:d.cleared===!0})),m!==null&&f.push({kind:"new",key:"new",since:m});const g=u>0,h=e.length>0||c.length>0,j=p.useRef(null),y=p.useRef(null),k=Jm(j,y,h?f.map(b=>b.key).join(" "):""),N=Qm(g,a);let E=!1;const S=f.map((b,O)=>{const H=O===0?null:E?"dots":"line";E=b.kind==="resumed"||(b.kind==="day"||b.kind==="new")&&E;const K=O===f.length-1?null:E?"dots":"line",V={above:H,below:K};switch(b.kind){case"day":return n.jsx(Si,{day:b.day,now:o,thread:V},b.key);case"event":return n.jsx(Vm,{event:b.event,mark:b.mark,open:b.open,waitedMs:b.waitedMs,above:H,below:K},b.key);case"resumed":return n.jsx(An,{"data-slot":"event-resumed",at:b.at,thread:V,mark:n.jsx(re,{kind:"lookout",labelled:!0}),children:n.jsxs("span",{children:["Watching resumed,"," ",n.jsx("span",{className:"tabular-nums",children:Q(b.unmeasuredMs)})," not measured"]})},b.key);case"started":return n.jsx(An,{"data-slot":"event-start",at:b.at,thread:V,mark:n.jsx(re,{kind:"lookout",labelled:!0}),children:n.jsx("span",{children:b.cleared?"History cleared":"Started watching"})},b.key);case"new":return n.jsx(Xm,{ref:N,since:b.since,now:o,thread:V},b.key)}});let v;return h?v=n.jsx("div",{ref:j,className:"relative min-h-65 flex-1 max-wide:min-h-0",children:n.jsx("ol",{ref:y,"data-slot":"event-list","data-whole-rows":k!==null||void 0,"aria-label":"Event log, newest first",tabIndex:0,className:A("thin-scroll flex flex-col overflow-y-auto pt-0.5 pb-3.5 focus-visible:-outline-offset-2","wide:absolute wide:inset-0 max-wide:max-h-120"),style:k!==null?{bottom:"auto",height:k}:void 0,children:S})}):d?.started?v=n.jsxs("div",{className:"pb-4",children:[n.jsx("ol",{"data-slot":"event-list","aria-label":"Event log, newest first",className:"flex flex-col",children:S}),n.jsxs("p",{"data-part":"unchanged",className:"flex gap-3.5 px-6 text-caption text-ink-muted",children:[n.jsx("span",{"aria-hidden":!0,className:A(zn,"invisible"),children:xe(d.at)}),n.jsx("span",{"aria-hidden":!0,className:"w-mark shrink-0"}),n.jsx("span",{children:"Nothing has changed since."})]})]}):v=n.jsx(Kt,{compact:!0,title:"No events yet",className:"my-auto",children:n.jsx("p",{children:"When a session starts, finishes or needs you, it is logged here."})}),n.jsx(q,{title:"Events",count:g?n.jsxs(n.Fragment,{children:[u," new",n.jsx("span",{className:"sr-only",children:", the log"})]}):void 0,aside:d?n.jsxs("span",{"data-part":"since",children:["since ",n.jsx("span",{className:"tabular-nums",children:ue(d.at,o)})]}):void 0,className:A("flex flex-col",i),children:v})}const ep={permission:"Waiting for permission",question:"Asked you a question",other:"Waiting for you"};function Ai(e){return ep[e.waitingReason??"other"]}function co(e){return e.name.trim()!==""?e.name:e.project||e.id}function Bn(e){return Bt(co(e),e.machine)}function tp(e){const t=Ai(e),s=e.waitingText?.trim();return{title:Bn(e),body:s?`${t}: ${s}`:t}}const Rs={"needs-you":"Needs you",finished:"Finished",failed:"Failed",ended:"Ended"},np={finished:"finished",failed:"failed",ended:"ended"};function lr(e){return np[e]}function sp(e){return e.event==="needs-you"?tp(e.session):{title:Bn(e.session),body:Rs[e.event]}}const Yt="–",je={working:"busy with a task",idle:"ready for a prompt",sessions:"all sessions found",noneWorking:"none working",justAnswered:"just answered",noneIdle:"none idle",noneRunning:"none running",timeNotReported:"time not reported",notCountedYet:"not counted yet",noSource:"no source to count"};function Ei(e,t,s,o){return e?n.jsxs(n.Fragment,{children:["longest"," ",n.jsx("span",{"data-part":"note-value",className:"whitespace-nowrap tabular-nums",children:Q(s-e.since)})]}):t>0?je.timeNotReported:o}function op(e,t){return e.longestWorking===null&&e.working>0&&e.working===e.answered?je.justAnswered:Ei(e.longestWorking,e.working,t,je.noneWorking)}function rp(e){if(e.total===0)return je.noneRunning;const t=[`${e.open} open`];return e.finished>0&&t.push(`${e.finished} finished`),e.failed>0&&t.push(`${e.failed} failed`),t.join(", ")}function un({kind:e,label:t,mark:s,value:o,note:r,onOpen:a}){return n.jsxs("div",{"data-slot":"count","data-kind":e,"data-opens":a?"":void 0,role:"group","aria-label":t,className:a?"relative -m-2 flex min-w-0 cursor-pointer items-center gap-3 rounded-inner p-2 transition-colors duration-120 hover:bg-fill-hover has-[button:focus-visible]:outline-2 has-[button:focus-visible]:outline-offset-2 has-[button:focus-visible]:outline-focus":"flex min-w-0 items-center gap-3",children:[o===null?n.jsx("span",{"data-part":"placeholder","aria-hidden":!0,className:"block h-7 w-5.5 shrink-0 rounded-bar bg-fill-selected"}):n.jsx("p",{"data-part":"value",className:"min-w-5.5 shrink-0 text-stat font-medium tabular-nums",...o===Yt?{role:"img","aria-label":"Not known"}:{},children:o}),n.jsxs("div",{className:"min-w-0",children:[n.jsxs("p",{"data-part":"label",className:"flex min-w-0 items-center gap-1.75 text-body leading-tight font-semibold text-ink",children:[s,a?n.jsx("button",{type:"button","aria-haspopup":"dialog","aria-label":`${t}: open history`,onClick:a,className:"min-w-0 cursor-pointer truncate text-left outline-none after:absolute after:inset-0 after:rounded-inner",children:t}):n.jsx("span",{className:"truncate",children:t})]}),n.jsx("p",{"data-part":"note",className:"mt-px text-caption text-pretty text-ink-secondary",children:r})]})]})}function ap({counts:e,asOf:t,onOpenHistory:s,staleAfterMs:o=Ye}){const{summary:r,counted:a,searching:i}=e,l=c=>r===null?null:a?c??0:Yt,d=c=>s&&a?()=>s(c):void 0;return n.jsxs("div",{"data-slot":"counts-row",role:"group","aria-label":"Summary",className:"grid grid-cols-4 gap-4 border-t border-hairline pt-4.5 max-wide:grid-cols-2 max-wide:gap-y-3.5",children:[n.jsx(un,{kind:"working",label:"Working",mark:n.jsx(re,{kind:"working"}),value:l(r?.working),note:r&&a?op(r,t):je.working,onOpen:d("working")}),n.jsx(un,{kind:"idle",label:"Idle",mark:n.jsx(re,{kind:"idle"}),value:l(r?.idle),note:r&&a?Ei(r.longestIdle,r.idle,t,je.noneIdle):je.idle,onOpen:d("idle")}),n.jsx(un,{kind:"stale",label:"Stale",mark:n.jsx(re,{kind:"stale"}),value:l(r?.stale),note:`idle ${In(o)} or more`}),n.jsx(un,{kind:"sessions",label:"Sessions",value:l(r?.total),note:r?a?rp(r):i?je.notCountedYet:je.noSource:je.sessions})]})}function ip(e){const t=new Set((e.restarts??[]).map(s=>s.at));return t.add(e.startedAt),[...t].sort((s,o)=>s-o)}function uo(e,t,s){const o=[];if(!e)return o;const r=e.points.map(d=>d.at).sort((d,c)=>d-c),a=ip(e);let i=0,l=null;for(const d of r){let c=!1;for(;i<a.length&&a[i]<=d;)l&&a[i]>l.to&&(c=!0),i+=1;l&&!c&&d-l.to<=s?l.to=d:o.push(l={from:d,to:d})}return l&&t>l.to&&t-l.to<=s&&(l.to=t),o}function fo(e,t,s,o,r){const a=[];return e.forEach((i,l)=>{const d=l===0&&i.from>t.from&&i.from-t.from<=r?t.from:i.from,c=Math.max(d,t.from,o),u=Math.min(i.to,t.to,s);u>c&&a.push({from:c,to:u})}),a}function ho(e,t){const s=[];let o=t.from;for(const r of[...e].sort((a,i)=>a.from-i.from))if(!(r.to<=o)&&(r.from>o&&s.push({from:o,to:Math.min(r.from,t.to)}),o=Math.max(o,r.to),o>=t.to))break;return o<t.to&&s.push({from:o,to:t.to}),s.filter(r=>r.to>r.from)}function cr(e,t){const s=[];for(const o of e)for(const r of t){const a=Math.max(o.from,r.from),i=Math.min(o.to,r.to);i>a&&s.push({from:a,to:i})}return s.sort((o,r)=>o.from-r.from)}function mo(e){return e.reduce((t,s)=>t+(s.to-s.from),0)}function Ti(e,t,s="in the last hour"){if(t.length===0)return s;const o=t[0];return mo(t)>=e.to-e.from?null:t.length===1&&o.from<=e.from?`since ${ne(o.to)}`:"in the time measured"}const Mi=jn,lp=new Map(Mi.map((e,t)=>[e,t]));function dr(e){return lp.get(e)??Mi.length}function ur(e,t){const s=e.toLowerCase(),o=t.toLowerCase();return s<o?-1:s>o?1:0}function cp(e,t){const s=dr(e.status)-dr(t.status);if(s!==0)return s;if(e.statusSince!==t.statusSince){if(e.statusSince===null)return 1;if(t.statusSince===null)return-1;const o=e.statusSince-t.statusSince;return e.status==="needs-you"?o:-o}return ur(e.name,t.name)||ur(e.id,t.id)}function qn(e){return e.stale&&e.status==="idle"}const dp="Answered";function Xt(e){return e.status==="needs-you"&&!fe(e)}function po(e){const t=e.status==="finished"||e.status==="failed",s=e.alive===!1,o=qn(e),r=Xt(e);return{mark:o?"stale":r?"answered":e.status,word:o?"Stale":r?dp:ao[e.status],ended:t,stale:o,answered:r,quiet:o||t||s,orphaned:s&&!t}}const up={"needs-you":"Needs you",working:"Working",idle:"Idle",unknown:"Status unknown"},fp=["needs-you","working","idle","ended","unknown"];function hp(e){switch(e.status){case"needs-you":return fe(e)?"needs-you":"working";case"working":return"working";case"idle":return"idle";case"finished":case"failed":return"ended";default:return"unknown"}}function mp(e,t){if(e!=="ended")return up[e];const s=t.some(r=>r.status==="failed"),o=t.some(r=>r.status==="finished");return s&&o?"Finished or failed":s?"Failed":"Finished"}function pp(e,t){return+(t.status==="failed")-+(e.status==="failed")||cp(e,t)}function Jt(e){const t=new Map;for(const o of e){const r=hp(o),a=t.get(r);a?a.push(o):t.set(r,[o])}const s=[];for(const o of fp){const r=t.get(o);if(!r)continue;const a=r.filter(qn).length;s.push({id:o,label:mp(o,r),sessions:[...r].sort(pp),count:r.length-a,stale:a})}return s}function Ls(e){return Jt(e).filter(t=>t.id!=="needs-you")}function xp(e){return Jt(e).find(t=>t.id==="needs-you")?.sessions??[]}function gp(e){return e?.filter(fe).length??0}function fs(e,t){const s=t.statusSince;return s===null?e:e===null||s<e.since?{session:t,since:s}:e}function wp(e){const t={total:e.length,needsYou:0,working:0,answered:0,idle:0,stale:0,open:0,finished:0,failed:0,longestWait:null,longestWorking:null,longestIdle:null};for(const s of e){if(qn(s)){t.stale+=1;continue}switch(s.status){case"needs-you":fe(s)?(t.needsYou+=1,t.longestWait=fs(t.longestWait,s)):(t.working+=1,t.answered+=1);break;case"working":t.working+=1,t.longestWorking=fs(t.longestWorking,s);break;case"idle":t.idle+=1,t.longestIdle=fs(t.longestIdle,s);break;case"finished":t.finished+=1;break;case"failed":t.failed+=1;break}}return t.open=t.total-t.finished-t.failed,t}function xo(e,t=[]){const s=e?wp(e):null,o=s!==null&&(s.total>0||t.some(r=>r.state==="ok"));return{summary:s,counted:o,searching:t.some(r=>r.state==="searching")}}function Ci(e){return!e.summary||!e.counted?null:e.summary.needsYou>0?"lamp":"rest"}const Ii=3600*1e3;function bp(e,t,s,o,r,a){const i=[],l=e?.startedAt??null,d=t[0];if(d){const f=l!==null&&l<d.at?l:-1/0;d.kind!=="appeared"?i.push({from:f,to:d.at,status:d.from??"unknown",startObserved:f!==-1/0,reaches:!1}):i.push({from:f,to:d.at,status:"unseen",startObserved:f!==-1/0,reaches:!1}),t.forEach((m,w)=>{const x=t[w-1];m.kind==="appeared"&&x?.kind==="ended"&&m.at>x.at&&i.push({from:x.at,to:m.at,status:"unseen",startObserved:!0,reaches:!1});const g=t[w+1]?.at??s.to;m.kind==="ended"||g<=m.at||i.push({from:m.at,to:g,status:m.to??"unknown",startObserved:!0,reaches:!1})})}else if(e){const f=l??-1/0,m=Math.max(f,Math.min(a,e.statusSince??1/0));m>f&&i.push({from:f,to:m,status:"unknown",startObserved:l!==null,reaches:!1,notKnown:!0}),i.push({from:m,to:s.to,status:e.status,startObserved:m!==-1/0,reaches:!1})}if(!e)return i;let c=i[i.length-1];(!c||c.to!==s.to||c.status==="unseen")&&(c={from:t[t.length-1]?.at??-1/0,to:s.to,status:e.status,startObserved:!0,reaches:!1},i.push(c)),c.status=e.status;const u=e.statusSince;return u!==null&&u<o&&(u>c.from+r?(c.to=u,c={from:u,to:s.to,status:e.status,startObserved:!0,reaches:!0},i.push(c)):c.reaches=!0),o<s.to&&c.from<o&&(c.to=o,i.push({from:o,to:s.to,status:e.status,startObserved:!0,reaches:!1})),i}function yp(e,t,s,o){const r=[],a=l=>s.some(d=>d.from<l&&l<=d.to),i=(l,d,c)=>{if(d<=l)return;const u=r[r.length-1];if(u?.kind==="unmeasured"&&u.to===l){u.to=d;return}const f=!(l===o.from&&c.from<l);r.push({from:l,to:d,kind:"unmeasured",startKnown:f})};for(const l of e){const d=Math.max(l.from,o.from),c=Math.min(l.to,o.to);if(c<=d)continue;if(l.notKnown){i(d,c,l);continue}if(l.reaches&&l.status!=="unseen"){const f=l.startObserved&&d===l.from;r.push({from:d,to:c,kind:l.status,startKnown:f});continue}let u=d;for(const f of t){if(f.to<=u)continue;if(f.from>=c)break;const m=Math.max(f.from,u),w=Math.min(f.to,c);if(i(u,m,l),l.status!=="unseen"&&w>m){const x=l.startObserved&&m===l.from&&a(m);r.push({from:m,to:w,kind:l.status,startKnown:x})}u=w}i(u,c,l)}return r}function kp(e,t){return e.flatMap(s=>s.kind!=="idle"||s.to<=t?[s]:s.from>=t?[{...s,kind:"stale"}]:[{...s,to:t},{...s,from:t,kind:"stale",startKnown:!0}])}function jp(e,t){return e.at-t.at}function Np(e,t){if(!Xt(e))return e;const s=t[t.length-1];return s?.to==="needs-you"?e:{...e,status:s?.to??"working",statusSince:s?.at??null}}function Oi(e){const{sessions:t,events:s,history:o,now:r}=e,a=e.gapMs??Vt,i={from:r-(e.windowMs??Ii),to:r},l=Math.min(e.asOf??r,r),d=new Map;let c=1/0;for(const y of s){if(y.at<c&&(c=y.at),!Ys(y))continue;const k=d.get(y.sessionId);k?k.push(y):d.set(y.sessionId,[y])}for(const y of d.values())y.sort(jp);const u=uo(o,l,a),f=Math.max(o?Se(o).at:-1/0,e.eventsFull&&c!==1/0?c:-1/0),m=fo(u,i,l,f,a),w=(y,k,N)=>{const E=d.get(y)??[],S=N&&Np(N,E),v=bp(S,E,i,l,a,o?.startedAt??-1/0);let b=yp(v,m,u,i);S?.stale&&S.status==="idle"&&S.statusSince!==null&&(b=kp(b,S.statusSince+(e.staleAfterMs??Ye)));const O=b[b.length-1];if(S&&O&&O.to===i.to&&(O.ongoing=!0),S&&fe(S))for(const H of b)H.kind==="needs-you"&&H.to===l&&(H.open=!0);return{id:y,name:k,ended:S===void 0,status:S?.status??null,stale:S?.stale??!1,answered:N!==void 0&&Xt(N),segments:b}},x=Jt(t).flatMap(y=>y.sessions),g=x.map(y=>w(y.id,y.name,y)),h=new Set(x.map(y=>y.id)),j=[];for(const[y,k]of d){const N=k[k.length-1];!N||h.has(y)||N.kind!=="ended"||N.at<=i.from||j.push({at:N.at,row:w(y,N.sessionName,void 0)})}return j.sort((y,k)=>k.at-y.at||y.row.name.localeCompare(k.row.name)),{start:i.from,end:i.to,rows:[...g,...j.map(y=>y.row)],unmeasured:ho(m,i)}}function vp(e,t){const{now:s,events:o}=e,r=e.heldMs??Ii;let a=1/0;for(const f of t.points)f.at<a&&(a=f.at);let i=1/0;for(const f of o)f.at<i&&(i=f.at);const l=[[Se(t).at,"started"],[Math.max(a===1/0?s:a,s-r),"held"]];e.eventsFull&&i!==1/0&&l.push([i,"events"]);let[d,c]=l[0];for(const[f,m]of l)f>d&&([d,c]=[f,m]);d=Math.min(d,s);const u=se(s);return d<=u?{from:u,to:s,bound:"midnight",today:!0}:{from:d,to:s,bound:c,today:!1}}function Sp(e,t,s){const o=new Map;for(const a of e){if(!Ys(a))continue;const i=o.get(a.sessionId);i?i.push(a):o.set(a.sessionId,[a])}let r=null;for(const a of o.values())a.sort((i,l)=>i.at-l.at),a.forEach((i,l)=>{const d=a[l-1];if(!(d?d.to==="needs-you":i.from==="needs-you")||i.to==="needs-you"||i.at<t.from||i.at>s||d&&i.at<=d.at||r&&i.at<=r.at)return;const u=i.kind==="ended"||i.to==="finished"||i.to==="failed";r={id:i.sessionId,name:i.sessionName,ms:i.at-(d?d.at:t.from),startKnown:d!==void 0,at:i.at,how:u?"ended":"answered"}});return r}function Ap(e){const{history:t,now:s}=e;if(!t)return null;const o=e.gapMs??Vt,r=Math.min(e.asOf??s,s),a=vp(e,t),i=Oi({sessions:e.sessions,events:e.events,history:t,now:s,asOf:r,eventsFull:e.eventsFull,windowMs:s-a.from,gapMs:o}),l=[];for(const f of i.rows){let m=0,w=0,x=!1,g=!0,h=!1,j=-1/0;for(const y of f.segments)if(y.from>j&&(h=!1),j=y.to,y.kind!=="unmeasured"){if(y.kind!=="needs-you"){h=!1;continue}h||(w+=1),h=!0,m+=y.to-y.from,y.open&&(x=!0),y.startKnown===!1&&(g=!1)}m>0&&l.push({id:f.id,name:f.name,ms:m,times:w,open:x,startKnown:g})}l.sort((f,m)=>m.ms-f.ms||f.name.localeCompare(m.name));const d={from:a.from,to:Math.max(a.from,r)},c=fo(uo(t,r,o),d,r,Se(t).at,o),u=ho(c,d);return{period:a,sessions:l,totalMs:l.reduce((f,m)=>f+m.ms,0),gaps:u,unmeasuredMs:mo(u),lastWait:Sp(e.events,a,r)}}function Ep(e){return e.period.today?"Waited on you today":`Waited on you since ${ne(e.period.from)}`}function fr(e){const t=`Measured since ${ne(e.period.from)}`,s=_i(e);return s?`${t}, with ${s}.`:`${t}.`}function _i(e){const t=e.gaps[0];if(!t||e.unmeasuredMs<=0)return null;const s=Q(e.unmeasuredMs);return e.gaps.length===1?`${s} not measured after ${ne(t.from)}`:`${s} not measured in ${e.gaps.length} breaks, the first after ${ne(t.from)}`}const Tp=7*6e4;function Mp({waits:e}){const t=e?Ep(e):"Waited on you",s=e?.sessions[0]?.ms??0,o=Math.max(Tp,s);return n.jsxs("div",{"data-slot":"waited-on-you",role:"group","aria-label":t,className:"grid grid-cols-1 gap-2.5 border-t border-hairline pt-4.5",children:[n.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1",children:[n.jsx("h3",{className:"min-w-0 text-body font-semibold text-ink",children:t}),e&&e.totalMs>0&&n.jsxs("p",{"data-part":"total",className:"shrink-0 text-caption text-ink-secondary",children:[n.jsx("span",{className:"text-body font-semibold text-ink tabular-nums",children:Q(e.totalMs)})," ","in all"]})]}),e&&e.sessions.length>0&&n.jsx("ul",{"data-part":"bars",className:"grid grid-cols-1 gap-1.75",children:e.sessions.map(r=>{const a=`${r.startKnown?"":"at least "}${Ee(r.ms)}`,i=ut(r.id),l=Bt(r.name,i);return n.jsxs("li",{"data-part":"waited","data-open":r.open,className:"flex items-center gap-4 text-body leading-5 max-mid:flex-wrap max-mid:gap-y-1",children:[n.jsxs(ae,{"data-part":"who",tooltip:l,className:A("w-waited-name shrink-0 max-mid:w-auto max-mid:min-w-0 max-mid:flex-1",r.open?"font-semibold text-ink":"font-medium text-ink-secondary"),children:[r.name,n.jsx(Hn,{machine:i,className:"text-ink-muted"})]}),n.jsx("span",{"data-part":"track",role:"img","aria-label":r.open?`${l} has waited ${a}, still waiting`:`${l} waited ${a}, answered`,className:"relative h-2.5 min-w-0 flex-1 before:absolute before:inset-x-0 before:top-1/2 before:h-px before:bg-hairline max-mid:order-last max-mid:basis-full",children:n.jsx("i",{"data-part":"bar",className:A("absolute inset-y-0 left-0 rounded-bar",r.open?"bar-open bar-glow":"bar-answered"),style:{width:`${Math.round(r.ms/o*1e4)/100}%`}})}),n.jsx("span",{"data-part":"value","aria-hidden":!0,className:A("w-16 shrink-0 text-right whitespace-nowrap tabular-nums",r.open?"font-semibold text-label-needs-you":"text-ink-secondary"),children:Q(r.ms)})]},r.id)})}),n.jsx("p",{"data-part":"note",className:"text-caption text-ink-secondary",children:e===null?"The history could not be read, so how long sessions waited is not known.":e.sessions.length===0?`No session waited on you. ${fr(e)}`:fr(e)})]})}function Cp(e){switch(e){case"allowed":return"Allowed from Agent Lookout.";case"denied":return"Denied from Agent Lookout. Claude carries on without it.";case"gone":return"It was answered in the session, or is no longer waiting, so nothing was sent.";case"no-ask":return"That request is no longer held, so nothing was sent.";case"not-allowable":return"Only Deny is offered for this request.";case"too-soon":return"That request is being answered.";case"failed":return"The answer could not be handed to the session.";case"no-answer":return"Agent Lookout did not answer in time. The session shows whether it went on."}}function Ip(e){switch(e){case"edit":return"Allow is not offered for a change to a file here, since the change itself is not shown. Answer in the session to allow it.";case"too-long":return"It is too long to show whole here, so only Deny is offered. Answer in the session to allow it.";case"hidden-characters":return"It holds characters that cannot be shown as they are, written here as their codes, so only Deny is offered.";case"not-yes-or-no":return"It is answered with more than yes or no, so only Deny is offered here.";case"right-to-left":return"It holds right-to-left letters, which can draw a command in another order than it runs, so only Deny is offered. Answer in the session to allow it.";case"blank-lines":return"It has blank lines in a row that could hide what follows them, so only Deny is offered. Answer in the session to allow it."}}function Op(e,t=!1){const s=e.subagent?t?"A subagent now asks":"A subagent asks":t?"It now asks":"Asks";return e.command!==void 0?`${s} to run`:`${s} to use ${e.tool}`}const _p=1e3,Rp=1e4,Lp=["no-ask","not-allowable","gone","too-soon","failed"];async function $p(e,t,s,o=Rp){try{const r=await Y("/api/permission/answer",{method:"POST",headers:{"Content-Type":"application/json",[we]:Au},body:JSON.stringify({sessionId:e,requestId:t,decision:s}),signal:AbortSignal.timeout(o)}),a=await r.json(),i=typeof a=="object"&&a!==null&&!Array.isArray(a)?a:{};return r.status===200?i.ok!==!0?"failed":i.decision==="deny"?"denied":i.decision==="allow"?"allowed":"failed":Lp.find(l=>l===i.reason)??"failed"}catch{return"no-answer"}}function Wp(e,t={}){const{onAnswered:s,request:o=$p,settleMs:r=_p}=t,[a,i]=p.useState({kind:"idle"}),l=e.ask?.requestId??null,[d,c]=p.useState(null),u=l!==null&&d!==l,f=`${p.useId()}-answer-outcome`,m=p.useRef(!1),w=p.useRef(!1),x=p.useRef(!0);p.useEffect(()=>(x.current=!0,()=>{x.current=!1}),[]),p.useEffect(()=>{if(l===null)return;const h=setTimeout(()=>c(l),r);return()=>clearTimeout(h)},[l,r]),p.useEffect(()=>{!w.current||a.kind!=="answered"||(w.current=!1,document.getElementById(f)?.focus())},[a,f]);const g=p.useCallback(h=>{m.current||l===null||u||(m.current=!0,i({kind:"busy",decision:h,requestId:l}),o(e.id,l,h).then(j=>{m.current=!1,x.current&&((j==="allowed"||j==="denied")&&s?.(),w.current=!0,i({kind:"answered",outcome:j,requestId:l}))}))},[e.id,l,u,o,s]);return{step:a,press:g,settling:u,outcomeId:f}}function hr({text:e,label:t,part:s,whole:o}){return n.jsx("pre",{"data-part":s,"data-whole":o||void 0,tabIndex:0,"aria-label":t,className:A("rounded-row bg-fill-zebra px-3 py-2 font-mono text-fact whitespace-pre-wrap text-ink inset-ring inset-ring-hairline wrap-anywhere select-text [letter-spacing:0]! [word-spacing:normal]!",!o&&"thin-scroll max-h-60 overflow-y-auto"),children:e})}function Pp({ask:e,again:t}){return n.jsxs(n.Fragment,{children:[n.jsx("p",{"data-part":"ask-heading",className:"text-body font-medium text-ink",children:Op(e,t)}),e.command!==void 0&&n.jsx("div",{className:"mt-1.5",children:n.jsx(hr,{text:e.command,label:"The whole command",part:"command",whole:e.allow})}),e.inputs!==void 0&&e.inputs.length>0&&n.jsx("dl",{"data-part":"inputs",className:"mt-1.5 flex flex-col gap-1.5",children:e.inputs.map((s,o)=>n.jsxs("div",{className:"min-w-0",children:[n.jsx("dt",{className:"font-mono text-caption text-ink-secondary wrap-anywhere",children:s.name}),n.jsx("dd",{className:"mt-0.5",children:n.jsx(hr,{text:s.value,label:s.name,part:"input",whole:e.allow})})]},o))}),e.description!==void 0&&n.jsx("p",{"data-part":"description",className:"mt-1.5 text-body text-ink-secondary",children:e.description}),!e.allow&&e.denyOnly!==void 0&&n.jsx("p",{"data-part":"deny-only",className:"mt-1.5 text-body text-ink-secondary",children:Ip(e.denyOnly)})]})}function Ri({session:e,onAnswered:t,request:s,settleMs:o,focusOnLeave:r,className:a}){const i=Wp(e,{onAnswered:t,request:s,settleMs:o}),l=p.useRef(null),d=p.useRef(r);return p.useEffect(()=>{d.current=r},[r]),p.useLayoutEffect(()=>()=>{const c=l.current?.contains(document.activeElement)??!1,u=d.current;!c||u===void 0||setTimeout(()=>{const f=document.activeElement;(f===null||f===document.body||!f.isConnected)&&document.getElementById(u)?.focus()},0)},[]),n.jsx(Dp,{session:e,answer:i,className:a,blockRef:l})}function Dp({session:e,answer:t,className:s,blockRef:o}){const{ask:r}=e,{step:a}=t,i=a.kind==="answered"?a:null,l=r!==void 0&&r.requestId!==i?.requestId?r:null;if(l===null&&i===null)return null;const d=a.kind==="busy",c=d||t.settling;return n.jsxs("section",{ref:o,"data-slot":"answer","aria-label":`Permission request of ${e.name}`,className:A("flex min-w-0 flex-col",s),children:[i!==null&&n.jsx("p",{id:t.outcomeId,tabIndex:-1,role:"status","data-part":"answer-outcome","data-outcome":i.outcome,className:A("text-body text-ink outline-none",l!==null&&"mb-2.5"),children:Cp(i.outcome)}),l!==null&&n.jsxs(n.Fragment,{children:[n.jsx(Pp,{ask:l,again:i!==null}),n.jsxs("div",{className:"mt-2.5 flex flex-wrap items-center gap-3",children:[n.jsx(D,{size:"sm","data-part":"deny","aria-label":`Deny, for ${e.name}`,"aria-disabled":c||void 0,onClick:()=>t.press("deny"),children:"Deny"}),l.allow&&n.jsx(D,{size:"sm","data-part":"allow","aria-label":`Allow, for ${e.name}`,"aria-disabled":c||void 0,onClick:()=>t.press("allow"),children:"Allow"})]}),n.jsx("p",{"data-part":"answering","aria-live":"polite",className:"sr-only",children:d?a.decision==="allow"?"Allowing…":"Denying…":""})]})]})}const Li=4e3,Up=ku+5e3,Fp=["no-pane","pane-gone","tmux-stopped","tab-gone","not-allowed","too-soon","failed"],Hp={selected:"Selected in tmux","no-pane":"No tmux pane found","pane-gone":"That pane has closed","tmux-stopped":"tmux has stopped","tab-gone":"That tab has closed","not-allowed":"macOS did not allow it","too-soon":"Try again in a moment",failed:"Jump did not work"};function zp(e,t=null){return t!==null&&e==="selected"?`Switched to ${t}`:t!==null&&e==="no-pane"?"No tab found":Hp[e]}function Bp(e,t=Gt()){return`macOS will ask once whether ${t?"Agent Lookout":"the app you started Agent Lookout from"} may control ${e}. Allow it to let Jump switch tabs.`}const qp="To let Jump switch tabs, allow it in System Settings, Privacy & Security, Automation.";async function Gp(e,t=Li){try{const s=await Y("/api/jump",{method:"POST",headers:{"Content-Type":"application/json",[we]:"jump"},body:JSON.stringify({sessionId:e}),signal:AbortSignal.timeout(t)}),o=await s.json(),r=typeof o=="object"&&o!==null?o:{};return s.ok?r.ok===!0?"selected":"failed":Fp.find(a=>a===r.reason)??"failed"}catch{return"failed"}}function Gn({session:e,jump:t,variant:s,size:o="sm",className:r}){const a=We(e);if(!a)return null;const i=`Jump to ${e.name} in ${a.where}`,l=A(o==="sm"&&"w-16",r);return a.by==="link"?n.jsx(D,{asChild:!0,variant:s,size:o,className:l,children:n.jsx("a",{href:a.href,"data-part":"jump","aria-label":i,children:"Jump"})}):n.jsx(ee,{content:a.where,align:"end",children:n.jsx(D,{variant:s,size:o,className:l,"data-part":"jump","data-way":a.by,"aria-label":i,onClick:t.press,children:"Jump"})})}function Ht({session:e,jump:t,className:s}){const{outcome:o,asking:r}=t,a=We(e);if(o===null&&r===null&&(a===null||a.by==="link"))return null;const i=o===null?null:zp(o,a?.by==="terminal"?a.app:null),l=o==="not-allowed"?qp:o===null&&r!==null?Bp(r):null;return n.jsxs(n.Fragment,{children:[n.jsx("span",{role:"status","data-part":"jump-said",className:"sr-only",children:i!==null&&l!==null?`${i}. ${l}`:i??l}),i!==null&&n.jsx(Je,{"aria-hidden":!0,"data-part":"jump-note","data-outcome":o,tone:o==="selected"?"neutral":"outline",className:s,children:i}),l!==null&&n.jsx("span",{"aria-hidden":!0,"data-part":"jump-line",className:"basis-full text-caption text-ink-secondary",children:l})]})}function go({git:e,inSentence:t=!1,className:s}){const o=e.branch;if(o===void 0&&e.commit===void 0)return null;const r=o!==void 0?"on":"at",a=o!==void 0?"branch":"commit";return n.jsxs(n.Fragment,{children:[t?n.jsxs(n.Fragment,{children:[r," ",n.jsxs("span",{className:"sr-only",children:[a," "]})]}):n.jsxs("span",{className:"sr-only",children:[r," ",a," "]}),o!==void 0?n.jsx(ae,{"data-part":"branch",className:s,children:o}):n.jsx("span",{"data-part":"commit",className:A("font-mono text-fact",s),children:e.commit})]})}function $i({parts:e,className:t}){return n.jsx("span",{"data-slot":"duration-figure",className:A("inline-flex items-baseline gap-1.5 tabular-nums",t),children:e.map(s=>n.jsxs("span",{className:"inline-flex items-baseline",children:[s.value,n.jsx("span",{"data-part":"unit",className:"ml-0.5 text-unit font-medium text-ink-secondary",children:s.unit})]},s.unit))})}function ve({label:e,className:t}){return n.jsxs("div",{"data-slot":"loading",role:"status",className:A("flex items-center justify-center gap-2.5 px-6 py-14",t),children:[n.jsx("span",{"aria-hidden":!0,className:"size-mark animate-spin-loader rounded-capsule border-[1.5px] border-rule-strong border-t-ink-secondary"}),n.jsx("span",{className:"text-body font-medium text-ink-secondary",children:e})]})}const Wi="agent-lookout-automation-note",Pi=new Set;function Di(){try{const e=localStorage.getItem(Wi)??"";return Vs.filter(t=>e.split(",").includes(t))}catch{return[]}}function Kp(e){return!Pi.has(e)&&!Di().includes(e)}function Vp(e){const t=new Set([...Di(),e]);try{localStorage.setItem(Wi,Vs.filter(s=>t.has(s)).join(","))}catch{Pi.add(e)}}const Yp=4e3,Xp=12e3,Jp=1e3;function Kn(e){const t=e.id,s=We(e),o=s?.by==="terminal"?s.app:null,[r,a]=p.useState(null),[i,l]=p.useState(null),d=p.useRef(!1),c=p.useRef(-1/0),u=p.useRef(!0),f=p.useRef(void 0),m=p.useRef(void 0);return p.useEffect(()=>(u.current=!0,()=>{u.current=!1,clearTimeout(f.current),clearTimeout(m.current)}),[]),{press:p.useCallback(()=>{d.current||performance.now()-c.current<ju||(d.current=!0,clearTimeout(f.current),a(null),o!==null&&Kp(o)&&(m.current=setTimeout(()=>{Vp(o),l(o)},Jp)),Gp(t,o!==null?Up:Li).then(x=>{d.current=!1,c.current=performance.now(),clearTimeout(m.current),u.current&&(l(null),a(x),f.current=setTimeout(()=>a(null),x==="not-allowed"?Xp:Yp))}))},[t,o]),outcome:r,asking:i}}const $s="#overview/session/";function Qp(e){return`${$s}${encodeURIComponent(e).replace(/%3A/gi,":")}`}function Zp(e){if(!e.startsWith($s))return null;const t=e.slice($s.length);if(t==="")return null;try{return decodeURIComponent(t)}catch{return t}}const ex={go(e){return window.location.hash=e,!0}};let tx=ex;function Ui(e){return tx.go(e)}const Fi="agent-lookout-details";function Qt(e){return Qp(e)}function Hi(e){return Zp(e)}function En(e){const t=Qt(e);window.location.hash!==t&&Ui(t)&&window.history.replaceState({[Fi]:!0},"")}let hs=!1;function nx(){if(Hi(window.location.hash)===null)return;const e=window.history.state;if(typeof e=="object"&&e!==null&&Fi in e){if(hs)return;hs=!0,window.addEventListener("hashchange",()=>{hs=!1},{once:!0}),window.history.back()}else window.location.replace("#overview")}function zi(e,t){if(e.defaultPrevented||!(e.target instanceof Element))return;const s=e.target.closest("a, button, [tabindex]");s&&s!==e.currentTarget&&e.currentTarget.contains(s)||window.getSelection()?.isCollapsed!==!1&&En(t)}function Vn(e,t){e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||(e.preventDefault(),En(t))}function Bi({onOpen:e,children:t}){const s=p.useId();return n.jsxs(n.Fragment,{children:[n.jsx("button",{type:"button","aria-haspopup":"dialog","aria-describedby":s,onClick:e,className:"-mx-1.5 -my-0.5 cursor-pointer rounded-row px-1.5 py-0.5 text-left transition-colors duration-120 hover:bg-fill-hover",children:t}),n.jsx("span",{id:s,hidden:!0,children:"Opens the history of how many sessions needed you"})]})}function sx({id:e,count:t,onOpen:s}){return n.jsxs("h2",{id:e,"data-part":"title",tabIndex:-1,className:"flex items-center gap-2.5 text-row leading-tight font-semibold text-ink outline-none",children:[n.jsx(re,{kind:"needs-you",breathing:!0,className:"size-4.5"}),s?n.jsx(Bi,{onOpen:s,children:"Needs you"}):n.jsx("span",{children:"Needs you"}),n.jsx("span",{"data-part":"count",className:"font-medium text-ink-secondary tabular-nums",children:t})]})}function qi({session:e,className:t}){const s=Ai(e),o=tm(e);return o?n.jsx(ee,{content:`${s}: ${o}`,children:n.jsxs("span",{"data-part":"reason-text",tabIndex:0,className:A("rounded-bar text-label-needs-you",t),children:[s,n.jsxs("span",{className:"sr-only",children:[": ",o]})]})}):n.jsx("span",{"data-part":"reason-text",className:A("text-label-needs-you",t),children:s})}function Gi({session:e,className:t}){const s=e.waitingText?.trim();return!s||e.ask?null:n.jsx(ae,{"data-part":"asking",lines:2,className:A("min-w-0 text-body wrap-anywhere text-ink-secondary",t),children:s})}function Ki({session:e,agent:t,className:s}){const o=qt(e.surface),r=!!e.project||o!==null;return!r&&t===void 0?null:n.jsxs("span",{"data-part":"place",className:A("relative min-w-0 text-body text-ink-secondary",s),children:[e.project?n.jsxs(n.Fragment,{children:[n.jsx(ee,{content:e.cwd,mono:!0,children:n.jsx("span",{"data-part":"project",tabIndex:e.cwd?0:void 0,className:"rounded-bar font-medium text-ink",children:e.project})}),e.git&&n.jsxs(n.Fragment,{children:[" ",n.jsx("span",{"data-part":"git",children:n.jsx(go,{git:e.git,inSentence:!0,className:"inline-block max-w-full align-top font-medium text-ink"})})]}),o!==null&&n.jsxs(n.Fragment,{children:[" ","in ",n.jsx("span",{"data-part":"app",children:o})]})]}):o!==null&&n.jsxs(n.Fragment,{children:["In ",n.jsx("span",{"data-part":"app",children:o})]}),t!==void 0&&n.jsxs(n.Fragment,{children:[r&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"sr-only",children:", "}),n.jsx("span",{"aria-hidden":!0,className:"mx-1.5",children:"·"})]}),n.jsx("span",{"data-part":"agent",children:t})]})]})}function Vi({session:e}){return e.alive===!1?n.jsx(Je,{tone:"outline",children:"Process ended"}):null}function Yi(e,t){return e.statusSince===null?null:Math.max(0,t-e.statusSince)}function Xi({session:e,className:t}){return n.jsx(ae,{"data-part":"name",href:Qt(e.id),onClick:s=>Vn(s,e.id),"aria-label":`${e.name}, details`,"aria-haspopup":"dialog",className:A("-mx-1.5 -my-0.5 rounded-row px-1.5 py-0.5 transition-colors duration-120 hover:bg-fill-hover",t),children:e.name})}function ox({session:e,asOf:t,agent:s,onAnswered:o,titleId:r}){const a=Yi(e,t),i=Kn(e);return n.jsxs("div",{"data-slot":"hero-session","data-session":e.id,className:"mt-3.5 flex items-end justify-between gap-6 max-mid:flex-col max-mid:items-stretch max-mid:gap-4",children:[n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1",children:[n.jsxs("div",{className:"flex max-w-full min-w-0 items-center gap-3",children:[n.jsx(Xi,{session:e,className:"text-name font-semibold"}),n.jsx(Vi,{session:e})]}),n.jsx(Ft,{session:e}),n.jsx(Ht,{session:e,jump:i})]}),n.jsx("p",{"data-part":"reason",className:"mt-2 flex min-w-0 text-lead font-medium",children:n.jsx(qi,{session:e,className:"truncate"})}),n.jsx(Gi,{session:e,className:"mt-1"}),n.jsx(Ki,{session:e,agent:s,className:"mt-1.5 block wrap-anywhere"}),n.jsx(Ri,{session:e,onAnswered:o,focusOnLeave:r,className:"mt-3"})]}),n.jsxs("div",{className:"flex shrink-0 items-end gap-6 max-mid:flex-wrap max-mid:justify-between max-mid:gap-y-3",children:[n.jsxs("div",{"data-part":"wait",className:"text-right max-mid:text-left",children:[n.jsx("p",{className:"text-wait font-medium whitespace-nowrap text-label-needs-you",children:a!==null?n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:"sr-only",children:["Waiting ",Ee(a)]}),n.jsx("span",{"aria-hidden":!0,children:n.jsx($i,{parts:xt(a)})})]}):n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"sr-only",children:"How long it has waited was not reported"}),n.jsx("span",{"aria-hidden":!0,children:Yt})]})}),n.jsx("p",{"data-part":"since",className:"mt-2 text-caption text-ink-secondary",children:e.statusSince!==null?n.jsxs(n.Fragment,{children:["waiting since"," ",n.jsx("span",{className:"font-semibold text-ink tabular-nums",children:ne(e.statusSince)})]}):"time not reported"})]}),n.jsx(Gn,{session:e,jump:i,variant:"needs-you",size:"hero"})]})]})}function rx({session:e,asOf:t,agent:s,onAnswered:o,titleId:r}){const a=Yi(e,t),i=Kn(e);return n.jsxs("li",{"data-slot":"hero-session","data-session":e.id,className:"flex items-center gap-5 border-t border-hairline py-3 max-mid:flex-wrap max-mid:gap-x-4 max-mid:gap-y-2",children:[n.jsxs("div",{className:"min-w-0 flex-1 max-mid:basis-full",children:[n.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1",children:[n.jsxs("div",{className:"flex max-w-full min-w-0 items-center gap-2",children:[n.jsx(Xi,{session:e,className:"text-lead font-semibold text-ink"}),n.jsx(Vi,{session:e})]}),n.jsx(Ft,{session:e}),n.jsx(Ht,{session:e,jump:i})]}),n.jsxs("p",{"data-part":"reason",className:"mt-1 flex min-w-0 flex-wrap items-baseline gap-x-3 text-body",children:[n.jsx(qi,{session:e,className:"font-medium"}),n.jsx(Ki,{session:e,agent:s,className:"block min-w-0 wrap-anywhere"})]}),n.jsx(Gi,{session:e,className:"mt-1"}),n.jsx(Ri,{session:e,onAnswered:o,focusOnLeave:r,className:"mt-2"})]}),n.jsx("p",{"data-part":"wait",className:"shrink-0 text-right text-lead font-semibold whitespace-nowrap text-label-needs-you tabular-nums max-mid:mr-auto max-mid:text-left",children:a!==null?n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:"sr-only",children:["Waiting ",Ee(a)]}),n.jsx("span",{"aria-hidden":!0,children:Q(a)})]}):n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"sr-only",children:"How long it has waited was not reported"}),n.jsx("span",{"aria-hidden":!0,children:Yt})]})}),n.jsx(Gn,{session:e,jump:i,variant:"needs-you",size:"sm"})]})}function ax(e,t){const s=ut(e.id);return n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"font-semibold text-ink",children:e.name}),s!==null&&` on ${s}`,", ",e.how==="ended"?"ended at":"answered at"," ",n.jsx("span",{className:"tabular-nums",children:ne(e.at)}),!e.startKnown&&n.jsxs(n.Fragment,{children:[", waiting since before ",n.jsx("span",{className:"tabular-nums",children:ne(t)})]})]})}function ix({id:e,waits:t,onOpen:s,seen:o}){const r=["this computer",...o.connected.map(f=>f.label)],a=r.length>1?`${r.slice(0,-1).join(", ")} or ${r.at(-1)}`:r[0],i=o.unseen===null?"Nothing needs you":`Nothing on ${a} needs you`,l=t?.lastWait??null,d=t!==null&&t.sessions.length===0,c=t?t.period.today?"today":`since ${ne(t.period.from)}`:null,u=t&&t.sessions.length===0?_i(t):null;return n.jsxs("div",{className:"flex items-end justify-between gap-6 max-mid:flex-col max-mid:items-start max-mid:gap-4",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsxs("h2",{id:e,"data-part":"title",tabIndex:-1,className:"mt-1 flex items-center gap-3.5 text-name font-semibold text-ink outline-none",children:[n.jsx(re,{kind:"needs-you",unlit:!0,className:"size-6.5"}),s?n.jsx(Bi,{onOpen:s,children:i}):n.jsx("span",{children:i})]}),o.unseen===null?n.jsx("p",{className:"mt-2.5 max-w-md text-row text-ink-secondary",children:"When a session stops to ask for something, it will show here."}):n.jsxs("p",{"data-part":"unseen",className:"mt-2.5 max-w-md text-row text-ink-secondary",children:[o.unseen," ",n.jsx("a",{href:"#sources",className:"rounded-bar underline decoration-rule-strong underline-offset-2 transition-colors duration-120 hover:text-ink",children:"Sources"})," ","says why."]})]}),n.jsxs("div",{"data-part":"last-wait",className:"shrink-0 text-right max-mid:text-left",children:[n.jsx("p",{className:"mb-2.5 text-caption font-semibold text-ink-secondary",children:"Last wait"}),l?n.jsxs(n.Fragment,{children:[n.jsxs("p",{className:"text-wait font-normal whitespace-nowrap text-ink",children:[n.jsxs("span",{className:"sr-only",children:["The last wait lasted ",l.startKnown?"":"at least ",Ee(l.ms)]}),n.jsx("span",{"aria-hidden":!0,children:n.jsx($i,{parts:xt(l.ms)})})]}),n.jsx("p",{"data-part":"last-note",className:"mt-2 text-caption text-ink-secondary",children:ax(l,t?.period.from??l.at)})]}):n.jsxs(n.Fragment,{children:[n.jsx("p",{"data-part":"last-note",className:"text-body text-ink-secondary",children:c&&d?`None ${c}`:"Not known"}),u&&n.jsx("p",{"data-part":"last-gaps",className:"mt-1 text-caption text-ink-secondary",children:u})]})]})]})}function lx({id:e,counts:t,connecting:s}){return n.jsxs("div",{children:[n.jsxs("h2",{id:e,"data-part":"title",tabIndex:-1,className:"flex items-center gap-2.5 text-row leading-tight font-semibold text-ink outline-none",children:[n.jsx(re,{kind:"needs-you",unlit:!0,className:"size-4.5"}),"Needs you"]}),t.summary===null?n.jsx(ve,{label:"Reading sessions",className:"justify-start px-0 pt-5 pb-1"}):n.jsxs(n.Fragment,{children:[n.jsx("p",{"data-part":"value",role:"img","aria-label":"Not known",className:"mt-3.5 text-name font-semibold text-ink",children:Yt}),n.jsx("p",{"data-part":"uncounted",className:"mt-2 max-w-md text-row text-ink-secondary",children:t.searching?s.length>0?`Agent Lookout is still connecting to ${de(s)} over SSH. The count follows as soon as ${s.length===1?"it is":"one is"} read.`:"Agent Lookout is still looking for agents on this computer. The count follows as soon as one is read.":"No agent tool could be read, so nothing could be counted. The Sessions card says why."})]})]})}function cx({sessions:e,sources:t=[],events:s=[],history:o=null,now:r,asOf:a=r,onOpenHistory:i,onAnswered:l,staleAfterMs:d,className:c}){const u=p.useId(),f=xo(e,t),m=Ci(f),w=p.useMemo(()=>e?xp(e):[],[e]),x=mi(t,e??[]),g=O=>x?ro(O,t):void 0,h=pi(t),j={connected:t.filter(O=>ge(O.id)&&O.state==="ok"),unseen:xi(h)},y=t.some(O=>O.state==="searching"&&!ge(O.id)),k=p.useMemo(()=>e&&m?Ap({sessions:e,events:s,history:o,now:r,asOf:a,eventsFull:s.length>=Un}):null,[e,m,s,o,r,a]),N=i&&o&&m?i:void 0,[E,...S]=w;let v,b;return m?E?(b=S.length>0?"several":"one",v=n.jsxs("div",{children:[n.jsx(sx,{id:u,count:w.length,onOpen:N&&(()=>N("needsYou"))}),n.jsx(ox,{session:E,asOf:a,agent:g(E),onAnswered:l,titleId:u},E.id),S.length>0&&n.jsx("ul",{"data-part":"others","aria-label":"Also waiting, longest first",className:"mt-5",children:S.map(O=>n.jsx(rx,{session:O,asOf:a,agent:g(O),onAnswered:l,titleId:u},O.id))})]})):(b="quiet",v=n.jsx(ix,{id:u,waits:k,onOpen:N&&(()=>N("needsYou")),seen:j})):(b=f.summary===null?"loading":"uncounted",v=n.jsx(lx,{id:u,counts:f,connecting:y?[]:h.connecting})),n.jsxs("section",{"data-slot":"hero","data-state":b,"data-light":m??void 0,"aria-labelledby":u,className:A("glass-raised flex min-w-0 flex-col justify-between gap-5 px-7 pt-6 pb-5.5 max-mid:px-5",c),children:[v,m&&(k===null||k.sessions.length>0)&&n.jsx(Mp,{waits:k}),n.jsx(ap,{counts:f,asOf:a,onOpenHistory:N,staleAfterMs:d})]})}function Ji(){const e=p.useRef(null),[t,s]=p.useState(0);return p.useEffect(()=>{const o=e.current;if(!o)return;const r=new ResizeObserver(([a])=>{a&&s(Math.floor(a.contentRect.width))});return r.observe(o),()=>r.disconnect()},[]),[e,t]}const wo=6e4,dx=60*wo,Tn=5*wo;function ux(e){const t=new Date(e).getTimezoneOffset()*wo;return Math.floor((e-t)/Tn)*Tn+t}function fx(e,t){const s=[];for(const o of e){if(!fe(o))continue;if(o.statusSince!==null){s.push(o.statusSince);continue}let r=-1/0;for(const a of t)a.sessionId===o.id&&a.to==="needs-you"&&a.at>r&&(r=a.at);s.push(r)}return s.sort((o,r)=>o-r)}function hx(e,t,s){const o=[...e.points].sort((i,l)=>i.at-l.at),r=[],a=o[0];return a&&r.push({...a,from:-1/0,to:a.at}),o.forEach((i,l)=>{const d=o[l+1];let c=i.at;d&&d.at-i.at<=s?c=d.at:!d&&t>i.at&&t-i.at<=s&&(c=t),c>i.at&&r.push({...i,from:i.at,to:c})}),r}function mx(e){const{history:t,now:s}=e,o=e.gapMs??Vt,r=s-(e.windowMs??dx),a={from:r,to:s},i=Math.min(e.asOf??s,s),l=uo(t,i,o),d=fo(l,a,i,t?Se(t).at:-1/0,o),c=[];for(let h=ux(r);h<s;h+=Tn){const j=Math.max(h,r),y=Math.min(h+Tn,s);if(y<=j)continue;const k=cr(d,[{from:j,to:y}]);c.push({from:j,to:y,measured:k,measuredMs:mo(k),means:null})}const u=c.map(()=>({open:0,answered:0,working:0,idle:0})),f=fx(e.sessions,e.events),m=h=>f.filter(j=>j<=h).length;let w=0,x=0;if(t)for(const h of hx(t,i,o))for(const j of cr([h],d)){const y=[j.from,...f.filter(k=>k>j.from&&k<j.to),j.to];for(let k=0;k<y.length-1;k+=1){const N=y[k],E=y[k+1],S=Math.min(h.needsYou,m(N)),v=h.needsYou-S;w+=h.needsYou*(E-N),x+=S*(E-N),c.forEach((b,O)=>{const H=Math.min(E,b.to)-Math.max(N,b.from);if(H<=0)return;const K=u[O];K.open+=S*H,K.answered+=v*H,K.working+=h.working*H,K.idle+=h.idle*H})}}let g=0;return c.forEach((h,j)=>{if(h.measuredMs<=0)return;const y=u[j],k=E=>E/h.measuredMs,N={open:k(y.open),answered:k(y.answered),working:k(y.working),idle:k(y.idle),total:0};N.total=N.open+N.answered+N.working+N.idle,h.means=N,N.total>g&&(g=N.total)}),{start:r,end:s,buckets:c,unmeasured:ho(d,a),waitedMs:w,openMs:x,axis:ef(g)}}const px=.02,rt=.05,xx=96;function me(e){return`${Math.round(e*1e5)/1e3}%`}function Ws(e,t){return`${ne(e.from)} to ${e.to>=t?"now":ne(e.to)}`}function Le(e){return e.toFixed(1)}function gx(e){const t=[e.open>=rt&&`needs you ${Le(e.open)}`,e.answered>=rt&&`answered ${Le(e.answered)}`,e.working>=rt&&`working ${Le(e.working)}`,e.idle>=rt&&`idle ${Le(e.idle)}`].filter(Boolean);return t.length>0?t.join(", "):"no sessions"}function Qi(e,t){if(!e.means)return`${Ws(e,t)}: not measured`;const s=e.measuredMs<e.to-e.from-1e3;return`${Ws(e,t)}: ${gx(e.means)}${s?`, measured for ${Q(e.measuredMs)}`:""}`}function wx(e){const t=e.unmeasured.map(s=>`from ${ne(s.from)} to ${s.to>=e.end?"now":ne(s.to)}`);return["The average number of sessions in each status, every five minutes over the last hour.",t.length>0?`Not measured ${t.join(", and ")}.`:"",...e.buckets.map(s=>`${Qi(s,e.end)}.`)].filter(Boolean).join(" ")}function bx(e){const t=new Set,s=e[0],o=e[e.length-1];if(s!==void 0&&t.add(s),o!==void 0&&t.add(o),e.length%2===1){const r=e[(e.length-1)/2];r!==void 0&&t.add(r)}return t}function yx({means:e,ceiling:t,from:s,to:o,hour:r}){if(e.total<=0)return null;const a=r.end-r.start,i=[["open",e.open,"bar-open"],["answered",e.answered,"bar-answered"],["working",e.working,"bar-working"]];return n.jsx("div",{"aria-hidden":!0,"data-part":"bar",className:"bar-tube absolute bottom-0 z-10 flex flex-col-reverse gap-0.5 overflow-hidden rounded-t-tube rounded-b-bar",style:{left:me((s-r.start)/a),width:`max(2px, calc(${me((o-s)/a)} - 4px))`,height:me(Math.min(1,e.total/t))},children:i.map(([l,d,c])=>d>=px?n.jsx("i",{"data-part":"segment","data-kind":l,className:A("block shrink-0",c),style:{height:me(d/e.total)}},l):null)})}function kx({fill:e}){return n.jsx("i",{"aria-hidden":!0,className:A("block h-2.5 w-3.5 rounded-bar",e)})}function jx({hour:e}){const t=p.useId(),[s,o]=Ji(),[r,a]=p.useState(null),i=e.end-e.start,l=e.axis.ceiling,d=e.buckets.length-1,c=r===null?d:Math.min(r,d),u=e.buckets[c],f=u?Qi(u,e.end):"",m=bx(e.axis.ticks),w=o>0?Ka(e.start,e.end,Math.max(1,Math.floor(o/xx))).map(h=>({at:h,share:(h-e.start)/i})).filter(({share:h})=>h*o>=16&&h*o<=o-52):[],x=(h,j)=>{const y=e.start+(h-j.left)/j.width*i,k=e.buckets.findIndex(N=>y<N.to);a(k===-1?d:k)},g=h=>{const y={ArrowLeft:k=>k-1,ArrowDown:k=>k-1,ArrowRight:k=>k+1,ArrowUp:k=>k+1,Home:()=>0,End:()=>d}[h.key];y&&(h.preventDefault(),a(Math.min(d,Math.max(0,y(c)))))};return n.jsxs(n.Fragment,{children:[n.jsxs("div",{"data-slot":"last-hour-chart",role:"slider",tabIndex:0,"aria-label":"Last hour, every five minutes. Arrow keys read each five minutes.","aria-describedby":t,"aria-orientation":"horizontal","aria-valuemin":0,"aria-valuemax":Math.max(0,d),"aria-valuenow":c,"aria-valuetext":f,onPointerMove:h=>x(h.clientX,h.currentTarget.getBoundingClientRect()),onPointerLeave:()=>a(null),onBlur:()=>a(null),onFocus:h=>{h.currentTarget.matches(":focus-visible")&&a(j=>j??d)},onKeyDown:g,className:"relative mt-4 mr-11.5 ml-6 min-h-28 flex-1 cursor-crosshair rounded-bar max-wide:h-50 max-wide:flex-none",children:[e.axis.ticks.map(h=>n.jsx("span",{"aria-hidden":!0,"data-part":"grid",className:A("absolute inset-x-0 block h-px",h===0?"bg-rule-strong":"bg-hairline"),style:{bottom:me(h/l)},children:m.has(h)&&n.jsx("span",{className:"absolute -top-1.75 -right-7.5 w-5.5 font-mono text-micro leading-3.5 text-ink-muted",children:h})},h)),r!==null&&u&&n.jsx("i",{"aria-hidden":!0,"data-part":"chosen",className:"absolute inset-y-0 block rounded-bar bg-fill-selected inset-ring inset-ring-rule",style:{left:me((u.from-e.start)/i),width:`calc(${me((u.to-u.from)/i)} - 2px)`}}),e.unmeasured.map(h=>n.jsx("i",{"aria-hidden":!0,"data-part":"unmeasured",className:"unmeasured-hatch absolute inset-y-0 z-0 block",style:{left:me((h.from-e.start)/i),width:me((h.to-h.from)/i)}},h.from)),e.buckets.flatMap(h=>h.means?h.measured.map(j=>n.jsx(yx,{means:h.means,ceiling:l,from:j.from,to:j.to,hour:e},j.from)):[]),r!==null&&u&&n.jsxs("div",{"aria-hidden":!0,"data-part":"reading",className:"pointer-events-none absolute top-0 z-20 rounded-row bg-glass-float px-2.5 py-1.5 font-mono text-fact whitespace-nowrap inset-ring inset-ring-rule",style:(u.from-e.start)/i>.55?{right:`calc(${me((e.end-u.from)/i)} + 6px)`}:{left:`calc(${me((u.to-e.start)/i)} + 2px)`},children:[n.jsx("span",{className:"block text-ink-secondary",children:Ws(u,e.end)}),u.means?n.jsxs(n.Fragment,{children:[u.means.open>=rt&&n.jsxs("span",{className:"block text-label-needs-you",children:["Needs you ",Le(u.means.open)]}),u.means.answered>=rt&&n.jsxs("span",{className:"block text-ink",children:["Answered ",Le(u.means.answered)]}),n.jsxs("span",{className:"block text-ink",children:["Working ",Le(u.means.working)]}),n.jsxs("span",{className:"block text-ink",children:["Idle ",Le(u.means.idle)]})]}):n.jsx("span",{className:"block text-ink",children:"Not measured"})]})]}),n.jsx("p",{id:t,className:"sr-only",children:wx(e)}),n.jsxs("div",{ref:s,"aria-hidden":!0,"data-slot":"last-hour-axis",className:"relative mr-11.5 ml-6 h-5.5 font-mono text-micro leading-none text-ink-muted",children:[w.map(h=>n.jsx("span",{"data-part":"time-tick",className:"absolute top-1.75 -translate-x-1/2 whitespace-nowrap",style:{left:me(h.share)},children:ne(h.at)},h.at)),n.jsx("span",{"data-part":"now",className:"absolute top-1.75 right-0 whitespace-nowrap text-ink-secondary",children:"now"})]})]})}function Nx({open:e}){const t=[["working","bar-working","Working"],...e?[["needs-you","bar-open","Needs you"]]:[],["answered","bar-answered","Answered"],["idle","bar-tube","Idle"],["unmeasured","unmeasured-hatch","Not measured"]];return n.jsx("ul",{"data-slot":"last-hour-legend","aria-label":"Legend",className:"flex flex-wrap items-center gap-x-3.5 gap-y-1.5 px-6 pt-2 pb-5 text-caption text-ink-secondary",children:t.map(([s,o,r])=>n.jsxs("li",{"data-kind":s,className:"flex items-center gap-1.5 whitespace-nowrap",children:[n.jsx(kx,{fill:o}),r]},s))})}function vx({sessions:e,sources:t=[],events:s=[],history:o,now:r,asOf:a=r,className:i}){const l=p.useMemo(()=>e&&o?mx({history:o,sessions:e,events:s,now:r,asOf:a}):null,[e,o,s,r,a]),d=l?.buckets.some(f=>(f.means?.total??0)>0)??!1;let c,u="every 5 minutes";if(e===null)c=n.jsx(ve,{label:"Reading the last hour"});else if(l===null)u=void 0,c=n.jsx("div",{className:"px-6 pb-5",children:n.jsx(F,{tone:"error",title:"The last hour could not be read",children:n.jsx("p",{children:"Agent Lookout did not answer when asked for its history. The page asks again every two seconds."})})});else if(d||e.length>0)c=n.jsxs(n.Fragment,{children:[n.jsx("p",{"data-part":"sum",className:"px-6 text-body text-ink-secondary",children:l.waitedMs>0?n.jsxs(n.Fragment,{children:["Sessions waited on you for"," ",n.jsx("span",{className:"font-semibold text-ink tabular-nums",children:Q(l.waitedMs)})," ","in all"]}):l.unmeasured.length>0?"No session waited on you in the time measured":"No session waited on you in the last hour"}),n.jsx(jx,{hour:l}),n.jsx(Nx,{open:l.openMs>0})]});else if(t.some(f=>f.state==="searching"))c=n.jsx(ve,{label:"Looking for sessions"});else if(!t.some(f=>f.state==="ok"))u=void 0,c=n.jsx("div",{className:"px-6 pb-5",children:n.jsx(F,{title:"The last hour was not measured",children:n.jsx("p",{children:"No source could be read, so there is nothing to count. The Sessions card says why."})})});else{const f=Ti({from:l.start,to:l.end},l.unmeasured);c=n.jsx(Kt,{compact:!0,title:f?`No sessions ${f}`:"Nothing was measured in the last hour",children:n.jsx("p",{children:"When a session runs, how many waited, worked or sat idle is drawn here."})})}return n.jsx(q,{title:"Last hour",aside:u,className:A("flex flex-col",i),children:c})}function Sx(e){return(e.status==="finished"||e.status==="failed")&&e.alive!==!0}const Ax=/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i,Ex=/[\p{Cc}\\\u061c\u200e\u200f\u2028\u2029\u202a-\u202e\u2066-\u2069]/u,mr="claude-code:";function Tx(e){return`'${e.replaceAll("'","'\\''")}'`}function Mx(e,t){return!Ax.test(e)||typeof t!="string"||!t.startsWith("/")||Ex.test(t)?null:`cd ${Tx(t)} && claude --resume ${e}`}function Cx(e){return e.source!=="claude-code"||!e.id.startsWith(mr)?null:e.id.slice(mr.length)}function Zi(e,t=Sx(e)){if(e.machine!==void 0)return null;const s=Cx(e);return s===null||!t?null:Mx(s,e.cwd)}async function Ix(e){try{const t=navigator.clipboard;return typeof t?.writeText!="function"?"refused":(await t.writeText(e),"copied")}catch{return"refused"}}const Ox=2e3;function _x({text:e,children:t,copiedSaid:s,refusedSaid:o,onCopied:r,copy:a=Ix,tooltip:i,tooltipMono:l=!1,className:d,...c}){const[u,f]=p.useState(!1),[m,w]=p.useState(""),x=p.useRef(!1),g=p.useRef(!0),h=p.useRef(void 0);p.useEffect(()=>(g.current=!0,()=>{g.current=!1,clearTimeout(h.current)}),[]);const j=()=>{x.current||(x.current=!0,clearTimeout(h.current),w(""),f(!1),a(e).then(k=>{x.current=!1,g.current&&(w(k==="copied"?s:o),k==="copied"&&(f(!0),h.current=setTimeout(()=>f(!1),Ox)),r?.(k))}))},y=n.jsxs(D,{"data-copied":u||void 0,className:A("inline-grid",d),onClick:j,...c,children:[n.jsx("span",{"aria-hidden":u||void 0,className:A("col-start-1 row-start-1",u&&"invisible"),children:t}),n.jsx("span",{"aria-hidden":!0,className:A("col-start-1 row-start-1",!u&&"invisible"),children:"Copied"})]});return n.jsxs(n.Fragment,{children:[i?n.jsx(ee,{content:i,mono:l,align:"end",children:y}):y,n.jsx("span",{"aria-live":"polite","aria-atomic":"true","data-part":"copy-said",className:"sr-only",children:m})]})}const Rx="The command was not copied. It is shown on the page, to select and copy.";function el({command:e,className:t}){return n.jsx("code",{"data-part":"resume-command",tabIndex:0,className:A("font-mono text-fact whitespace-pre-wrap text-ink select-all",t),children:n.jsx(Me,{children:e})})}function tl({session:e,resume:t,tooltip:s=!0,className:o}){return t.command===null?null:n.jsx(_x,{text:t.command,size:"sm","data-part":"resume","aria-label":`Copy the command that resumes ${e.name}`,copiedSaid:`Copied the command that resumes ${e.name}. Paste it in a terminal.`,refusedSaid:Rx,onCopied:t.onCopied,tooltip:s?t.command:void 0,tooltipMono:!0,className:A("w-16 px-2",o),children:"Resume"})}function nl({resume:e,className:t}){return!e.refused||e.command===null?null:n.jsxs("span",{"data-part":"resume-line",className:A("basis-full text-caption text-ink-secondary",t),children:["Not copied. Select the command to copy it:"," ",n.jsx(el,{command:e.command,className:"rounded-bar"})]})}function Cj({resume:e,className:t}){return e.command===null?null:n.jsxs("section",{"data-part":"resume-block","aria-label":"Resume",className:A("grid gap-1.5",t),children:[n.jsx("p",{className:"text-body text-ink-secondary",children:"Resume copies this command, which goes to the session's folder and opens its conversation again. Paste it in a terminal."}),n.jsx(el,{command:e.command,className:"block w-fit max-w-full rounded-row bg-fill-zebra px-3 py-1.5 inset-ring inset-ring-hairline"}),e.refused&&n.jsx("p",{"data-part":"resume-refused",className:"text-body text-ink-secondary",children:"Not copied. Select the command and copy it."})]})}const Lx={open:"Open",draft:"Draft",merged:"Merged",closed:"Closed"},$x=["failing","pending","passing"];function sl(e){const t=[];for(const s of $x){const o=e[s];o!==0&&t.push(t.length===0?`${o} ${o===1?"check":"checks"} ${s}`:`${o} ${s}`)}return t.length===0?"no checks":t.join(", ")}function Ij(e){return`${Lx[e.state]}, ${sl(e.checks)}`}function Wx(e){return e!==void 0&&(e.state==="open"||e.state==="draft")&&e.checks.state==="failing"}function pr(e){return`#${e.number}: ${sl(e.checks)}`}function ol({git:e,className:t}){const s=e.pullRequest;if(!Wx(s))return null;const o=`Pull request ${pr(s)}`;return n.jsx(ee,{content:o,children:n.jsxs("span",{"data-part":"checks",tabIndex:0,className:A("inline-flex shrink-0 items-center self-center rounded-bar text-status-finished",t),children:[n.jsx("svg",{"data-slot":"checks-mark",viewBox:"0 0 12 12",fill:"none",stroke:"currentColor","aria-hidden":!0,className:"size-3",children:n.jsx("path",{d:"M3.2 3.2l5.6 5.6M8.8 3.2l-5.6 5.6",strokeWidth:"1.6",strokeLinecap:"round"})}),n.jsxs("span",{className:"sr-only",children:[", pull request ",pr(s)]})]})})}const Px=5*6e4;function rl(e,t){if(e.status!=="working"||e.lastWriteAt===void 0)return null;const s=t-e.lastWriteAt;return s>=Px?s:null}function Dx(e){return`quiet for ${Dt(e)}`}function Ux(e){return`quiet for ${ft(e)}`}function al({session:e,now:t,quiet:s}){if(Xt(e))return null;const o=e.status==="finished"||e.status==="failed",r=e.statusSince,a=r!==null?t-r:null;return n.jsx(ee,{content:r!==null?`Since ${ui(r,t)}`:"The source did not report a time",mono:r!==null,align:"end",children:n.jsx("span",{"data-part":"duration",className:A("shrink-0 rounded-bar whitespace-nowrap tabular-nums",s?"text-ink-secondary":"text-ink"),children:a!==null?n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"sr-only",children:o?`${ft(a)} ago`:`for ${ft(a)}`}),n.jsxs("span",{"aria-hidden":!0,children:[Dt(a),o&&" ago"]})]}):n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"sr-only",children:"time not reported"}),n.jsx("span",{"aria-hidden":!0,children:"–"})]})})})}function il({session:e,now:t}){const s=rl(e,t);return s===null||e.lastWriteAt===void 0?null:n.jsx(ee,{content:`Last write at ${ui(e.lastWriteAt,t)}`,mono:!0,align:"end",children:n.jsxs("span",{"data-part":"quiet",tabIndex:0,className:"block w-fit rounded-bar leading-tight whitespace-nowrap text-ink-muted tabular-nums",children:[n.jsx("span",{className:"sr-only",children:Ux(s)}),n.jsx("span",{"aria-hidden":!0,children:Dx(s)})]})})}function ll(e,t){const s=Zi(e,t),[o,r]=p.useState(!1),a=p.useCallback(i=>r(i==="refused"),[]);return{command:s,refused:o&&s!==null,onCopied:a}}const Ze="px-3 first:pl-6 last:pr-4.5";function Fx({session:e,now:t,actionColumn:s,narrow:o=!1,agent:r,folderColumn:a=!0,appColumn:i=!0}){const{mark:l,word:d,stale:c,quiet:u,orphaned:f}=po(e),m=Kn(e),w=ll(e),x=qt(e.surface),g=n.jsx(al,{session:e,now:t,quiet:u}),h=rl(e,t)!==null&&n.jsx(il,{session:e,now:t}),j=y=>n.jsxs("p",{"data-part":"status-under",className:"flex min-w-0 flex-wrap items-baseline gap-x-3 gap-y-px overflow-x-clip leading-tight",children:[r!==void 0&&n.jsxs(n.Fragment,{children:[n.jsx(ae,{"data-part":"agent",className:"min-w-0",children:r}),n.jsx("span",{className:"sr-only",children:", "})]}),n.jsxs("span",{"data-part":"status-time",className:"relative flex min-w-0 grow flex-wrap items-baseline justify-between gap-x-3 gap-y-px",children:[r!==void 0&&n.jsx("span",{"aria-hidden":!0,"data-part":"dot",className:"absolute right-full mr-1",children:"·"}),y,g]}),h&&n.jsxs(n.Fragment,{children:[n.jsx("span",{className:"sr-only",children:", "}),n.jsx("span",{className:"basis-full",children:h})]})]});return n.jsxs("tr",{"data-slot":"session-row","data-session":e.id,"data-status":e.status,"data-stale":c||void 0,onClick:y=>zi(y,e.id),className:"group relative cursor-pointer text-body text-ink-secondary",children:[n.jsx("td",{className:A(Ze,"h-row",o&&"py-2","before:pointer-events-none before:absolute before:inset-x-2.5 before:inset-y-px before:-z-10 before:rounded-inner before:transition-colors before:duration-120 group-hover:before:bg-fill-hover","group-has-[a[data-part=name]:focus-visible]:before:outline-2 group-has-[a[data-part=name]:focus-visible]:before:outline-offset-2 group-has-[a[data-part=name]:focus-visible]:before:outline-focus"),children:n.jsxs("div",{className:"flex min-w-0 items-center gap-3",children:[n.jsx(re,{kind:l}),n.jsxs("div",{className:"grid min-w-0 flex-1 gap-px",children:[n.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-px",children:[n.jsxs("div",{className:"flex max-w-full min-w-0 items-center gap-2",children:[n.jsx(ae,{"data-part":"name",href:Qt(e.id),onClick:y=>Vn(y,e.id),"aria-label":`${e.name}, details`,"aria-haspopup":"dialog",className:A("text-row focus-visible:outline-none",u?"font-medium text-ink-secondary":"font-semibold text-ink"),children:e.name}),f&&n.jsx(Je,{tone:"outline",children:"Process ended"})]}),!o&&n.jsx(Ft,{session:e}),!o&&n.jsx(Ht,{session:e,jump:m}),n.jsx(nl,{resume:w})]}),o&&n.jsx(Ft,{session:e,className:"justify-self-start"}),o&&n.jsx(Ht,{session:e,jump:m,className:"justify-self-start"}),o&&j(n.jsx("span",{"data-part":"status",className:"whitespace-nowrap",children:d}))]})]})}),r!==void 0&&!o&&n.jsx("td",{"data-part":"agent",className:Ze,children:n.jsx(ae,{className:"block min-w-0",children:r})}),a&&n.jsxs("td",{className:A(Ze,"max-mid:hidden"),children:[n.jsx(ee,{content:e.cwd,mono:!0,children:n.jsx("span",{"data-part":"project",tabIndex:e.cwd?0:void 0,className:A("block truncate rounded-bar text-ink-secondary",e.git&&"leading-tight"),children:e.project??"–"})}),e.git&&n.jsxs("span",{"data-part":"git",className:"flex min-w-0 items-center gap-1 leading-tight text-ink-muted",children:[n.jsx(go,{git:e.git,className:"min-w-0"}),n.jsx(ol,{git:e.git})]})]}),i&&n.jsx("td",{"data-part":"app",className:A(Ze,"truncate max-mid:hidden"),children:x??n.jsxs(n.Fragment,{children:[n.jsx("span",{"aria-hidden":!0,children:"–"}),n.jsx("span",{className:"sr-only",children:"app not known"})]})}),!o&&n.jsxs("td",{className:Ze,children:[n.jsxs("div",{className:A("flex items-baseline justify-between gap-2 whitespace-nowrap",h&&"leading-tight"),children:[n.jsx("span",{"data-part":"status",children:d}),g]}),h]}),s&&n.jsxs("td",{className:A(Ze,"overflow-visible text-right"),children:[n.jsx(Gn,{session:e,jump:m,className:"group-hover:bg-fill-selected group-hover:text-ink"}),n.jsx(tl,{session:e,resume:w,className:"group-hover:bg-fill-selected group-hover:text-ink"})]})]})}const Hx="No repository",xr=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});function zx(e){const t=new Map,s=[];for(const r of e){const a=r.git?.repository;if(a===void 0){s.push(r);continue}const i=t.get(a.id);i?(i.sessions.push(r),xr.compare(a.name,i.label)<0&&(i.label=a.name)):t.set(a.id,{id:a.id,label:a.name,sessions:[r]})}const o=[...t.values()].sort((r,a)=>xr.compare(r.label,a.label)||(r.id<a.id?-1:r.id>a.id?1:0));return s.length>0?[...o,{id:null,label:Hx,sessions:s}]:o}function Bx(e){const t=e.git?.repository?.name;return t!==void 0&&t!==e.project?t:null}function qx({session:e,now:t,agent:s}){const{mark:o,word:r,stale:a,quiet:i,orphaned:l}=po(e),d=Kn(e),c=ll(e),u=qt(e.surface),f=Bx(e);return n.jsxs("li",{"data-slot":"board-card","data-session":e.id,"data-status":e.status,"data-stale":a||void 0,draggable:!1,onClick:m=>zi(m,e.id),className:A("group flex min-w-0 cursor-pointer flex-col rounded-inner bg-fill-zebra px-3.5 pt-3 pb-3 text-body text-ink-secondary inset-ring inset-ring-hairline","transition-colors duration-120 hover:bg-fill-hover","has-[a[data-part=name]:focus-visible]:outline-2 has-[a[data-part=name]:focus-visible]:outline-offset-2 has-[a[data-part=name]:focus-visible]:outline-focus"),children:[n.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1",children:[n.jsxs("div",{className:"flex max-w-full min-w-0 items-center gap-3",children:[n.jsx(re,{kind:o}),n.jsx(ae,{"data-part":"name",href:Qt(e.id),onClick:m=>Vn(m,e.id),"aria-label":`${e.name}, details`,"aria-haspopup":"dialog",className:A("text-row focus-visible:outline-none",i?"font-medium text-ink-secondary":"font-semibold text-ink"),children:e.name})]}),n.jsx(Ft,{session:e}),l&&n.jsx(Je,{tone:"outline",children:"Process ended"}),n.jsx(Ht,{session:e,jump:d}),n.jsx(nl,{resume:c})]}),e.project&&n.jsxs("p",{"data-part":"place",className:"mt-1.5 min-w-0 leading-tight",children:[f!==null&&n.jsxs(n.Fragment,{children:[n.jsxs("span",{className:"inline-flex max-w-full align-top",children:[n.jsx(ae,{"data-part":"repository",className:"min-w-0",children:f}),n.jsx("span",{"aria-hidden":!0,className:"whitespace-pre",children:" ·"})]}),n.jsx("span",{className:"sr-only",children:","})," "]}),n.jsx(ee,{content:e.cwd,mono:!0,children:n.jsx("span",{"data-part":"project",tabIndex:e.cwd?0:void 0,className:"inline-block max-w-full truncate rounded-bar align-top",children:e.project})}),e.git&&n.jsxs(n.Fragment,{children:[" ",n.jsxs("span",{"data-part":"git",className:"inline-flex max-w-full gap-1 align-top whitespace-nowrap text-ink-muted",children:[n.jsx(go,{git:e.git,inSentence:!0,className:"min-w-0"}),n.jsx(ol,{git:e.git})]})]})]}),(u!==null||s!==void 0)&&n.jsxs("p",{"data-part":"where",className:"mt-1 flex min-w-0 flex-wrap gap-x-3 gap-y-px overflow-x-clip leading-tight",children:[u!==null&&n.jsx("span",{"data-part":"app",className:"whitespace-nowrap",children:u}),s!==void 0&&n.jsxs(n.Fragment,{children:[u!==null&&n.jsx("span",{className:"sr-only",children:", "}),n.jsxs("span",{className:"relative flex min-w-0",children:[u!==null&&n.jsx("span",{"aria-hidden":!0,className:"absolute right-full mr-1",children:"·"}),n.jsx(ae,{"data-part":"agent",className:"min-w-0",children:s})]})]})]}),n.jsxs("div",{className:"mt-3 flex min-w-0 flex-wrap items-center gap-2",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsxs("p",{className:"flex items-baseline gap-1.5 leading-tight whitespace-nowrap",children:[n.jsx("span",{"data-part":"status",children:r}),n.jsx(al,{session:e,now:t,quiet:i})]}),n.jsx(il,{session:e,now:t})]}),n.jsx(Gn,{session:e,jump:d,className:"ml-auto group-hover:bg-fill-selected group-hover:text-ink"}),n.jsx(tl,{session:e,resume:c,className:"ml-auto group-hover:bg-fill-selected group-hover:text-ink"})]})]})}const Gx=[{id:"needs-you",label:"Needs you",empty:"Nothing waiting"},{id:"working",label:"Working",empty:"Nothing working"},{id:"idle",label:"Idle",empty:"Nothing idle"},{id:"ended",label:"Finished or failed",empty:"Nothing finished or failed"}],Kx=5;function Vx(e){const t=Jt(e);return{columns:Gx.map(o=>{const r=t.find(a=>a.id===o.id);return{...o,sessions:r?.sessions??[],count:r?.count??0,stale:r?.stale??0}}),unknown:t.find(o=>o.id==="unknown")?.sessions??[]}}function ht({children:e}){return n.jsx("span",{"data-part":"count",className:"font-medium text-ink-muted tabular-nums",children:e})}function Yx({column:e,now:t,agentOf:s}){const o=p.useId(),r=e.sessions.slice(0,Kx),a=e.sessions.length-r.length;return n.jsxs("div",{"data-slot":"board-column","data-column":e.id,className:"flex min-w-0 flex-col",children:[n.jsxs("h3",{id:o,className:"flex h-group items-end gap-3.5 px-3.5 pb-2 text-caption font-semibold text-ink-secondary",children:[n.jsxs("span",{className:"inline-flex items-baseline gap-1.5",children:[e.label,n.jsx(ht,{children:e.count})]}),e.stale>0&&n.jsxs("span",{"data-part":"stale",className:"inline-flex items-baseline gap-1.5",children:["Stale",n.jsx(ht,{children:e.stale})]})]}),r.length>0?n.jsx("ul",{"aria-labelledby":o,className:"flex flex-col gap-2",children:r.map(i=>n.jsx(qx,{session:i,now:t,agent:s?.(i)},i.id))}):n.jsx("p",{"data-part":"empty",className:"px-3.5 py-2.5 text-caption text-ink-muted",children:e.empty}),a>0&&n.jsxs("p",{"data-part":"more",className:"rounded-row px-3.5 pt-2.5 text-caption text-ink-muted",children:["and ",n.jsx("span",{className:"tabular-nums",children:a})," more in the list"]})]})}function Xx({sessions:e,now:t,agentOf:s}){const{columns:o,unknown:r}=Vx(e);return n.jsxs("div",{"data-slot":"session-board",className:"@container px-2.5 pb-2.5",children:[n.jsx("div",{className:"grid grid-cols-1 gap-x-2.5 gap-y-2 @min-[26rem]:grid-cols-2 @min-[47rem]:grid-cols-4",children:o.map(a=>n.jsx(Yx,{column:a,now:t,agentOf:s},a.id))}),r.length>0&&n.jsx("p",{"data-part":"unknown",className:"rounded-row px-3.5 pt-3 pb-1 text-caption text-ink-muted",children:r.length===1?"The status of 1 session is not known. The list shows it.":`The status of ${r.length} sessions is not known. The list shows them.`})]})}const Jx=Wa+2e4,Qx=["gone","unsupported","cannot-confirm","not-allowed","still-running","too-soon","failed"];async function cl(e){const t=await e.json();return typeof t=="object"&&t!==null&&!Array.isArray(t)?t:{}}async function Oj(e,t=Jx){try{const s=await Y("/api/sessions/stop",{method:"POST",headers:{"Content-Type":"application/json",[we]:Nu},body:JSON.stringify({sessionId:e}),signal:AbortSignal.timeout(t)}),o=await cl(s);return s.status===200?o.ok===!0?"stopped":"failed":Qx.find(r=>r===o.reason)??"failed"}catch{return"no-answer"}}function dl(e){return Wa+2e4+e*11e3}async function Zx(e,t=dl(0)){try{const s=await Y("/api/sessions/clean-up",{method:"POST",headers:{"Content-Type":"application/json",[we]:vu},body:JSON.stringify({sessions:[...e]}),signal:AbortSignal.timeout(t)}),o=await cl(s);if(s.status===429)return{ok:!1,reason:"too-soon"};if(s.status!==200||!Array.isArray(o.results))return{ok:!1,reason:"failed"};const r=new Map;for(const a of o.results){if(typeof a!="object"||a===null)continue;const{sessionId:i,outcome:l}=a;typeof i=="string"&&r.set(i,Su.find(d=>d===l)??"failed")}return{ok:!0,results:r}}catch{return{ok:!1,reason:"no-answer"}}}function eg(e,t){switch(e){case"stopped":return t==="background"?"Stopped. Claude Code stopped the background job, and its conversation is kept.":"Stopped. Its process has ended, and its conversation is kept.";case"gone":return"That session has already ended.";case"unsupported":return"Agent Lookout does not stop this session.";case"cannot-confirm":return"Agent Lookout cannot confirm this process is that session, so it did not stop it.";case"not-allowed":return"Agent Lookout is not allowed to stop this process.";case"still-running":return"Asked to stop, still running. It had not ended 10 seconds later.";case"too-soon":return"Another session is being stopped. Try again in a moment.";case"failed":return t==="background"?"Claude Code did not stop the background job.":"The session could not be stopped.";case"no-answer":return"Agent Lookout did not answer in time. The list shows whether it stopped."}}const tg={ended:"Ended","became-active":"Became active","not-stale":"Idle less than a day",gone:"Had already ended",unsupported:"Not stopped from here","cannot-confirm":"Could not confirm","not-allowed":"Not allowed","still-running":"Still running",failed:"Did not stop"};function ng(e,t=Ye){return e==="not-stale"?`Idle less than ${In(t)}`:tg[e]}const gr="claude-code:";function sg(e){if(e.source!=="claude-code"||!e.id.startsWith(gr))return null;const t=e.id.slice(gr.length);return t===""?null:t}const ul={text:"claude --resume",fact:!0,whole:!0};function wr(e){return`Stop ${e.name}?`}const Ie=e=>({text:e,fact:!1}),fl=e=>({text:e,fact:!0});function og(e){const t=sg(e);return t===null?null:[ul,Ie(" "),fl(t)]}function rg(e){const t=og(e),s=t?[Ie("The conversation is kept, and "),...t,Ie(" opens it again.")]:[Ie("The conversation is kept.")];return e.stop?.how==="background"?[Ie("Agent Lookout asks Claude Code to stop this background job with "),{...fl("claude stop"),whole:!0},Ie(". "),...s]:e.surface==="vscode"&&t?[Ie("Its process ends now. The conversation is kept: open it again from the session history in VS Code, or with "),...t,Ie(".")]:[Ie("Its process ends now. "),...s]}function ag(e){return e.status==="working"?"It is working now. What it is doing will stop part-way.":fe(e)?"It is waiting for you. The question is left unanswered.":null}const _j="Stop it in the desktop app. Agent Lookout does not stop the desktop app's sessions, because that app looks after their processes.",ig="Stop it in the desktop app.";function hl({runs:e}){return n.jsx(n.Fragment,{children:e.map((t,s)=>t.fact?n.jsx("code",{"data-slot":"fact",className:A("font-mono text-fact",t.whole?"whitespace-nowrap":"wrap-anywhere"),children:t.text},s):t.text)})}function Rj({session:e,stop:t}){if(!e.stop)return null;const s=t.step.kind==="confirming"&&t.step.busy;return n.jsx(D,{id:t.ids.stop,size:"sm","data-part":"stop","aria-label":`Stop ${e.name}`,"aria-expanded":t.step.kind==="confirming","aria-disabled":s||void 0,onClick:t.step.kind==="confirming"?void 0:t.ask,children:"Stop"})}function Lj({session:e,stop:t,className:s}){const{step:o}=t;if(o.kind==="idle")return null;if(o.kind==="answered")return n.jsx("p",{id:t.ids.outcome,tabIndex:-1,role:"status","data-part":"stop-outcome","data-outcome":o.outcome,className:A("text-body text-ink outline-none",s),children:eg(o.outcome,e.stop?.how??"signal")});const r=ag(e);return n.jsxs("section",{"data-part":"stop-confirm","aria-label":wr(e),className:A("flex flex-col gap-1",s),children:[n.jsx("p",{"data-part":"question","aria-live":"polite",className:"text-body font-medium text-ink",children:o.busy?`Stopping ${e.name}…`:wr(e)}),n.jsx("p",{"data-part":"does",className:"text-body text-ink-secondary",children:n.jsx(hl,{runs:rg(e)})}),r&&n.jsx("p",{"data-part":"interrupts",className:"text-body text-ink-secondary",children:r}),n.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-3",children:[n.jsx(D,{size:"sm","data-part":"confirm-stop",onClick:t.confirm,"aria-disabled":o.busy||void 0,children:"Stop session"}),n.jsx(D,{id:t.ids.cancel,size:"sm","data-part":"cancel-stop",onClick:t.cancel,"aria-disabled":o.busy||void 0,children:"Cancel"})]})]})}function ml({checked:e,onCheckedChange:t,disabled:s,className:o,...r}){return n.jsx(fc,{"data-slot":"checkbox",checked:e,onCheckedChange:a=>t(a===!0),disabled:s,className:A("relative inline-flex size-4 shrink-0 cursor-pointer items-center justify-center rounded-bar","after:absolute after:-inset-1","bg-well text-ink inset-ring inset-ring-rule-strong inset-shadow-well","data-[state=checked]:bg-fill-selected data-[state=checked]:inset-ring-control-rim data-[state=checked]:inset-shadow-top","transition-colors duration-120 hover:data-[state=unchecked]:bg-fill-quiet","disabled:cursor-default disabled:opacity-50",o),...r,children:n.jsx(hc,{children:n.jsx(Ld,{"aria-hidden":!0,className:"size-3",strokeWidth:2.5})})})}const pl="agent-lookout-hidden-sessions",lg=100,xl=new Set;function gl(e){return`${e.statusSince??""} ${e.id}`}function wl(){try{const e=JSON.parse(localStorage.getItem(pl)??"[]");return Array.isArray(e)?e.filter(t=>typeof t=="string"):[]}catch{return[]}}function bl(){return new Set([...wl(),...xl])}function cg(e){const t=gl(e),s=wl().filter(o=>o!==t);s.push(t);try{localStorage.setItem(pl,JSON.stringify(s.slice(-lg)))}catch{xl.add(t)}return bl()}function dg(e,t){const s=[];for(const o of e){if(o.source!=="claude-code"||o.alive!==!0||!qn(o)||o.statusSince===null)continue;const r=o.stop!==void 0;!r&&o.surface!=="desktop"||s.push({session:o,idleMs:Math.max(0,t-o.statusSince),endable:r})}return s.sort((o,r)=>o.session.statusSince-r.session.statusSince)}function ug(e){return e.filter(t=>t.endable).slice(0,st).map(t=>({sessionId:t.session.id,statusSince:t.session.statusSince}))}const fn=(e,t,s)=>e===1?t:s;function fg(e,t=Ye){const s=f=>e.filter(m=>m===f).length,o=s("ended"),r=[`Ended ${o===0?"none":o}.`],a=s("became-active");a>0&&r.push(`Left ${a} running because ${fn(a,"it","they")} became active.`);const i=s("not-stale");i>0&&r.push(`Left ${i} running because ${fn(i,"it has","they have")} been idle less than ${In(t)}.`);const l=s("cannot-confirm");l>0&&r.push(`Left ${l} running because Agent Lookout could not confirm ${fn(l,"its process","their processes")}.`);const d=s("still-running");d>0&&r.push(`${d} asked to stop ${fn(d,"is","are")} still running.`);const c=s("gone");c>0&&r.push(`${c} had already ended.`);const u=s("failed")+s("unsupported")+s("not-allowed");return u>0&&r.push(`${u} could not be stopped.`),r.join(" ")}const br="End the sessions left running?",hg=[{text:"Each chosen session's process ends now. Its conversation is kept, and ",fact:!1},ul,{text:" opens it again. A session that has done anything since this list was drawn is left running.",fact:!1}];function mg(e){return`End ${e} ${e===1?"session":"sessions"}`}function pg(e){return new Set(e.filter(t=>t.endable).slice(0,st).map(t=>t.session.id))}function xg(e){return e.reason==="too-soon"?"Another session is being stopped. Try again in a moment.":e.reason==="no-answer"?"Agent Lookout did not answer in time. The list shows which have ended.":"The sessions could not be ended."}function ms({one:e,checkbox:t,outcome:s,action:o,staleAfterMs:r=Ye}){const{session:a}=e,i=qt(a.surface),l=[a.project,i].filter(c=>c!==null),d=s==null||s==="ended";return n.jsxs("li",{"data-slot":"left-running-row","data-session":a.id,"data-endable":e.endable||void 0,className:"flex items-start gap-3 py-1.5",children:[t?n.jsx(ml,{checked:t.checked,onCheckedChange:t.onChange,disabled:t.disabled,"aria-label":`End ${a.name}`,className:"mt-0.5"}):n.jsx(re,{kind:s==="ended"?"ended":"stale",className:"mt-0.5"}),n.jsxs("div",{className:"flex min-w-0 flex-1 flex-wrap items-center justify-between gap-x-3 gap-y-1.5",children:[n.jsxs("div",{className:"min-w-0 grow basis-40",children:[n.jsxs("div",{className:"flex min-w-0 flex-wrap items-center gap-x-2 gap-y-px",children:[n.jsx(ae,{"data-part":"name",href:Qt(a.id),onClick:c=>Vn(c,a.id),"aria-label":`${a.name}, details`,"aria-haspopup":"dialog",className:"max-w-full text-row font-medium text-ink-secondary",children:a.name}),s&&n.jsx(Je,{"data-part":"outcome","data-outcome":s,tone:s==="ended"?"neutral":"outline",children:ng(s,r)})]}),n.jsxs("p",{"data-part":"place",className:"text-caption leading-tight text-ink-secondary",children:[l.join(" · "),l.length>0&&d&&" · ",d&&n.jsxs("span",{className:"tabular-nums",children:[n.jsxs("span",{"aria-hidden":!0,children:["idle ",Dt(e.idleMs)]}),n.jsxs("span",{className:"sr-only",children:["idle ",ft(e.idleMs)]})]})]}),!e.endable&&n.jsx("p",{"data-part":"desktop",className:"mt-0.5 text-caption leading-tight text-ink-secondary",children:ig})]}),o]})]})}function gg({sessions:e,now:t,onEnded:s,onGone:o,end:r=Zx,staleAfterMs:a=Ye}){const i=`idle ${In(a)} or more`,[l,d]=p.useState(bl),[c,u]=p.useState({kind:"list"}),[f,m]=p.useState(!1),[w,x]=p.useState(null),g=p.useRef(null),h=p.useRef(null),j=p.useRef(null),y=p.useRef(null),k=p.useRef(null),N=p.useRef(null),E=p.useRef(!0),S=p.useId();p.useEffect(()=>(E.current=!0,()=>{E.current=!1}),[]),p.useEffect(()=>{const R=N.current;if(N.current=null,R===null)return;let P;R==="cancel"?P=y.current:R==="summary"?P=k.current:R==="toggle"?P=h.current:R==="end"?P=j.current??h.current:P=[...g.current?.querySelectorAll('[data-slot="left-running-row"]')??[]].find(z=>z.dataset.session===R.hide)?.querySelector('[data-part="hide"]'),P?P.focus():g.current||o?.()},[c,l,f,o]);const v=dg(e,t).filter(R=>!l.has(gl(R.session)));f&&c.kind==="list"&&v.length===0&&m(!1);const b=()=>{x(null),N.current="cancel",u({kind:"confirming",shown:v,chosen:pg(v),busy:!1})},O=()=>{N.current="end",u({kind:"list"})},H=R=>{const P=v.indexOf(R),T=v.filter(z=>z!==R),M=T[P]??T[P-1];N.current=M?{hide:M.session.id}:"end",d(cg(R.session))},K=()=>{N.current="toggle",m(!f)};if(c.kind==="list"&&v.length===0)return null;if(c.kind==="done"){const R=c.rows.filter(({outcome:P})=>P!=="ended").length;return n.jsxs(ps,{ref:g,count:R,note:i,open:!0,children:[n.jsx("p",{ref:k,tabIndex:-1,role:"status","data-part":"summary",className:"mt-1 text-body text-ink outline-none",children:c.summary}),n.jsx("ul",{className:"mt-1.5",children:c.rows.map(({one:P,outcome:T})=>n.jsx(ms,{one:P,outcome:T,staleAfterMs:a},P.session.id))}),n.jsx("div",{className:"mt-2",children:n.jsx(D,{size:"sm","data-part":"done",onClick:()=>{N.current="end",u({kind:"list"})},children:"Done"})})]})}if(c.kind==="confirming"){const{shown:R,chosen:P,busy:T}=c,M=ug(R.filter(X=>P.has(X.session.id))),z=P.size>=st,ie=R.filter(X=>X.endable).length>st,gt=R.filter(X=>P.has(X.session.id)&&X.session.stop?.how==="background").length,_=()=>{T||M.length===0||(u({...c,busy:!0}),r(M,dl(gt)).then(X=>{if(!E.current)return;if(!X.ok){x(xg(X)),N.current="cancel",u({...c,busy:!1});return}const Fe=M.map(he=>X.results.get(he.sessionId)??"failed");N.current="summary",u({kind:"done",rows:R.map(he=>({one:he,outcome:P.has(he.session.id)?X.results.get(he.session.id)??null:null})),summary:fg(Fe,a)}),Fe.includes("ended")&&s?.()}))};return n.jsx(ps,{ref:g,count:R.length,note:i,open:!0,children:n.jsxs("section",{"data-part":"end-confirm","aria-label":br,children:[n.jsx("p",{"data-part":"question","aria-live":"polite",className:"mt-1 text-body font-medium text-ink",children:T?`Ending ${M.length===1?"1 session":`${M.length} sessions`}…`:br}),n.jsx("p",{"data-part":"does",className:"mt-1 text-body text-ink-secondary",children:n.jsx(hl,{runs:hg})}),ie&&n.jsxs("p",{"data-part":"limit",className:"mt-1 text-body text-ink-secondary",children:["Up to ",st," at a time."]}),n.jsx("ul",{className:"mt-1.5",children:R.map(X=>n.jsx(ms,{one:X,checkbox:X.endable?{checked:P.has(X.session.id),disabled:T||z&&!P.has(X.session.id),onChange:Fe=>{const he=new Set(P);Fe?he.size<st&&he.add(X.session.id):he.delete(X.session.id),u({...c,chosen:he})}}:void 0},X.session.id))}),w&&n.jsx("p",{"data-part":"problem",role:"status",className:"mt-1.5 text-body text-ink",children:w}),n.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-3",children:[n.jsx(D,{size:"sm","data-part":"confirm-end",onClick:_,"aria-disabled":T||M.length===0||void 0,children:mg(M.length)}),n.jsx(D,{ref:y,size:"sm","data-part":"cancel-end",onClick:T?void 0:O,"aria-disabled":T||void 0,children:"Cancel"})]})]})})}const V=v.some(R=>R.endable);return n.jsx(ps,{ref:g,count:v.length,note:i,open:f,action:n.jsxs(n.Fragment,{children:[f&&V&&n.jsx(D,{ref:j,size:"sm","data-part":"end-all",onClick:b,children:"End all…"}),n.jsx(D,{ref:h,size:"sm","data-part":"review","aria-expanded":f,"aria-controls":f?S:void 0,onClick:K,children:f?"Close":"Review…"})]}),children:f&&n.jsx("ul",{id:S,className:"mt-1.5",children:v.map(R=>n.jsx(ms,{one:R,action:n.jsx(D,{size:"sm","data-part":"hide","aria-label":`Hide ${R.session.name} until it changes`,onClick:()=>H(R),children:"Hide until it changes"})},R.session.id))})})}function ps({ref:e,count:t,note:s,open:o,action:r,children:a}){return n.jsxs("section",{ref:e,"data-slot":"left-running","data-open":o||void 0,"aria-labelledby":"left-running-head",className:A("mx-2.5 mb-3 rounded-inner bg-fill-zebra px-3.5 pt-2 inset-ring inset-ring-hairline",o?"pb-3":"pb-2"),children:[n.jsxs("div",{className:"flex min-h-button flex-wrap items-center justify-between gap-x-3 gap-y-2",children:[n.jsxs("div",{className:"flex min-w-0 grow basis-32 flex-wrap items-baseline gap-x-2 gap-y-px",children:[n.jsxs("h3",{id:"left-running-head",className:"inline-flex items-baseline gap-1.5 text-caption font-semibold text-ink-secondary",children:["Left running",n.jsx(ht,{children:t})]}),n.jsx("span",{"data-part":"note",className:"text-caption text-ink-secondary",children:s})]}),r&&n.jsx("div",{className:"flex items-center gap-3",children:r})]}),a]})}function pe({value:e,onValueChange:t,options:s,label:o,className:r}){const a=s.findIndex(i=>i.value===e);return n.jsxs(mc,{"data-slot":"segmented-control","aria-label":o,orientation:"horizontal",value:e,onValueChange:i=>t(i),className:A("relative inline-grid rounded-capsule bg-well p-0.75","inset-ring inset-ring-control-rim inset-shadow-well",r),style:{gridTemplateColumns:`repeat(${s.length}, minmax(0, 1fr))`},children:[a!==-1&&n.jsx("span",{"aria-hidden":!0,"data-part":"thumb",className:A("pointer-events-none absolute inset-y-0.75 left-0.75 rounded-capsule bg-thumb","inset-ring inset-ring-control-rim inset-shadow-top shadow-thumb","motion-safe:transition-transform motion-safe:duration-220 motion-safe:ease-out"),style:{width:`calc((100% - 6px) / ${s.length})`,transform:`translateX(${a*100}%)`}}),s.map(i=>n.jsxs(pc,{value:i.value,"aria-label":i.name,onFocus:()=>{i.value!==e&&t(i.value)},className:A("relative flex h-control cursor-pointer items-center justify-center gap-2 rounded-capsule px-4","text-body font-medium whitespace-nowrap text-ink-secondary transition-colors duration-120","hover:text-ink data-[state=checked]:text-ink",i.icon!==void 0&&"pl-3"),children:[i.icon,i.label]},i.value))]})}function wg(e){const t=p.useCallback(s=>{const o=window.matchMedia(e);return o.addEventListener("change",s),()=>o.removeEventListener("change",s)},[e]);return p.useSyncExternalStore(t,()=>window.matchMedia(e).matches)}const bg="(max-width: 760px)";function Yn(){return wg(bg)}const yg=["list","repositories","board"],yl="agent-lookout-sessions-layout",yr="list";let Mn=null;function kg(){if(Mn!==null)return Mn;try{const e=localStorage.getItem(yl);return yg.find(t=>t===e)??yr}catch{return yr}}function jg(e){try{localStorage.setItem(yl,e),Mn=null}catch{Mn=e}}function Ng(){const[e,t]=p.useState(kg),s=p.useCallback(o=>{jg(o),t(o)},[]);return[e,s]}const vg=[{value:"list",label:"List"},{value:"repositories",label:"Repos"},{value:"board",label:"Board"}];function Sg({source:e}){const t=e.state==="unavailable",s=ge(e.id)?`${e.label} is not connected`:t?`${e.label} was not found`:`${e.label} could not be read`;return n.jsxs(F,{tone:t?"info":"error",title:s,children:[n.jsx("p",{children:n.jsx(B,{children:e.detail??(t?`Agent Lookout could not find ${e.label} on this computer.`:`Agent Lookout found ${e.label} but could not read its sessions.`)})}),n.jsx("p",{"data-part":"advice",children:e.advice?n.jsx(B,{children:e.advice}):t?`Install ${e.label} or start a session. It will show up here on its own.`:"It keeps trying. If this stays, restart Agent Lookout."})]})}function bt({sources:e,last:t}){return n.jsx("div",{className:A("flex flex-col gap-2 px-6",t?"pb-6":"pb-3"),children:e.map(s=>n.jsx(Sg,{source:s},s.id))})}function Ag(e,t){const s=e.filter(i=>!ge(i.id)),o=e.filter(i=>ge(i.id)),r=[];(s.length>0||o.length===0)&&r.push(`${de(s)} on this computer`),o.length>0&&r.push(`the sessions on ${de(o)}`);const a=xi(pi(t));return[`Agent Lookout is watching ${r.join(" and ")}.`,a].filter(Boolean).join(" ")}function Eg({sources:e}){const t=e.filter(s=>s.state==="searching");return n.jsxs(Kt,{title:"Looking for agents",children:[t.map(s=>n.jsx("p",{children:n.jsx(B,{children:s.detail??`Looking for ${s.label} sessions on this computer.`})},s.id)),n.jsx("p",{className:"mt-2 text-ink-muted",children:"It checks every two seconds. There is nothing you need to do."})]})}function kr({head:e,sessions:t,now:s,actionColumn:o,columns:r,narrow:a,agentOf:i,folderColumn:l,appColumn:d,...c}){return n.jsxs("tbody",{"data-slot":"session-group",...c,children:[n.jsx("tr",{"data-slot":"group-row",children:n.jsx("th",{scope:"rowgroup",colSpan:r,className:"h-group px-6 pt-2.5 pb-1.5 text-left align-bottom text-caption font-semibold text-ink-secondary",children:e})}),t.map(u=>n.jsx(Fx,{session:u,now:s,actionColumn:o,narrow:a,agent:i?.(u),folderColumn:l,appColumn:d},u.id))]})}function Tg({group:e}){const t=e.id!=="idle"||e.count>0;return n.jsxs("span",{className:"flex items-baseline gap-3.5",children:[t&&n.jsxs("span",{className:"inline-flex items-baseline gap-1.5",children:[e.label,n.jsx(ht,{children:e.count})]}),e.id==="idle"&&e.stale>0&&n.jsxs("span",{"data-part":"stale",className:"inline-flex items-baseline gap-1.5",children:["Stale",n.jsx(ht,{children:e.stale})]})]})}function Mg({sessions:e,byRepository:t,...s}){if(!t)return Ls(e).map(r=>n.jsx(kr,{"data-group":r.id,head:n.jsx(Tg,{group:r}),sessions:r.sessions,...s},r.id));const o=Ls(e).flatMap(r=>r.sessions);return zx(o).map(r=>n.jsx(kr,{"data-group":r.id===null?"no-repository":"repository","data-repository":r.id??void 0,head:n.jsxs("span",{className:"flex min-w-0 items-baseline gap-1.5",children:[n.jsx(ae,{"data-part":"repository",className:"min-w-0",children:r.label}),n.jsx(ht,{children:r.sessions.length})]}),sessions:r.sessions,...s},r.id??""))}const ke={agent:6.25,folder:7,app:7,status:10,actions:6},Cg=12.5,Ig=12,jr={folder:!0,app:!0,folderRem:ke.folder};function Og(e,t,s,o){const[r,a]=p.useState(jr);return p.useLayoutEffect(()=>{const i=e.current?.parentElement;if(!t||!i)return;const l=()=>{const c=parseFloat(getComputedStyle(document.documentElement).fontSize)||16,u=Cg+ke.status+(s?ke.agent:0)+(o?ke.actions:0),f=i.clientWidth/c,m=f>=u+ke.folder,w=m&&f>=u+ke.folder+ke.app,x=f-(u+ke.folder+(w?ke.app:0)),g=Math.round(Math.min(Ig,ke.folder+Math.max(0,x)/2)*4)/4;a(h=>h.folder===m&&h.app===w&&h.folderRem===g?h:{folder:m,app:w,folderRem:g})};l();const d=new ResizeObserver(l);return d.observe(i),()=>d.disconnect()},[e,t,s,o]),t?r:jr}function _g({sessions:e,sources:t,now:s,onEnded:o,staleAfterMs:r,className:a}){const i=p.useRef(null),l=p.useRef(null),d=Zh(t),c=d.filter(M=>M.state==="unavailable"||M.state==="error"),u=d.some(M=>M.state==="searching"),f=Ls(e).flatMap(M=>M.sessions),[m,w]=Ng(),x=m==="board"&&e.length>0,g=f.some(M=>We(M)!==null),h=f.some(M=>Zi(M)!==null),j=g||h,y=(x?e:f).map(We).filter(M=>M!==null),k=y.some(M=>M.by==="tmux")?y.some(M=>M.by!=="tmux")?"Jump opens the session, or selects its pane in tmux":"Jump selects the session's pane in tmux":"Jump opens the session where it runs",N=mi(t,e),E=N?M=>ro(M,t):void 0,S=Yn(),v=N&&!S,{folder:b,app:O,folderRem:H}=Og(i,f.length>0&&!S&&!x,v,j),K=(S?1:2+(v?1:0)+(b?1:0)+(O?1:0))+(j?1:0),{counted:V}=xo(e,t);let R;if(x)R=n.jsxs(n.Fragment,{children:[c.length>0&&n.jsx(bt,{sources:c,last:!1}),n.jsx(Xx,{sessions:e,now:s,agentOf:E})]});else if(f.length>0)R=n.jsxs(n.Fragment,{children:[c.length>0&&n.jsx(bt,{sources:c,last:!1}),n.jsxs("table",{ref:i,"data-slot":"session-list",className:"mb-2.5 w-full table-fixed border-separate border-spacing-0",children:[n.jsxs("colgroup",{children:[n.jsx("col",{}),v&&n.jsx("col",{className:"w-25"}),b&&!S&&n.jsx("col",{style:{width:`${H}rem`}}),O&&!S&&n.jsx("col",{className:"w-28"}),!S&&n.jsx("col",{className:"w-40"}),j&&n.jsx("col",{className:"w-24"})]}),n.jsx("thead",{className:"sr-only",children:n.jsxs("tr",{children:[n.jsx("th",{scope:"col",children:"Session"}),v&&n.jsx("th",{scope:"col",children:"Agent"}),b&&!S&&n.jsx("th",{scope:"col",children:"Folder"}),O&&!S&&n.jsx("th",{scope:"col",children:"App"}),!S&&n.jsx("th",{scope:"col",children:"Status and time"}),j&&n.jsx("th",{scope:"col",children:g&&h?"Jump or resume":g?"Jump":"Resume"})]})}),n.jsx(Mg,{sessions:e,byRepository:m==="repositories",now:s,actionColumn:j,columns:K,narrow:S,agentOf:E,folderColumn:b,appColumn:O})]})]});else if(e.length>0)R=n.jsxs(n.Fragment,{children:[c.length>0&&n.jsx(bt,{sources:c,last:!1}),n.jsx("p",{"data-part":"all-waiting",className:"px-6 pb-6 text-body text-ink-secondary",children:"Every session needs you. They are at the top of the page, longest wait first."})]});else if(u)R=n.jsx(Eg,{sources:d});else if(c.length>0&&c.length===d.length)R=n.jsx(bt,{sources:c,last:!0});else{const M=d.filter(z=>z.state==="ok");R=n.jsxs(n.Fragment,{children:[c.length>0&&n.jsx(bt,{sources:c,last:!1}),n.jsx(Kt,{title:"No agents are running",children:n.jsxs("p",{children:[Ag(M,t)," A session shows up here within a few seconds of starting."]})})]})}const P=y.length>0&&n.jsx("span",{"data-part":"hint",className:"max-mid:hidden @max-[42rem]:hidden",children:k}),T=e.length>0&&n.jsx(pe,{label:"Show sessions as",value:m,onValueChange:w,options:vg,className:S?void 0:"-my-2.5"});return n.jsxs(q,{title:"Sessions",titleRef:l,count:V?e.length:void 0,aside:T&&!S?n.jsxs("div",{className:"flex items-center gap-4",children:[P,T]}):P||void 0,className:A("@container",a),children:[T&&S&&n.jsx("div",{"data-part":"layout",className:"flex px-6 pb-1",children:T}),n.jsx(gg,{sessions:e,now:s,onEnded:o,onGone:()=>l.current?.focus(),staleAfterMs:r}),R]})}const Rg={...ao,stale:"Stale",unmeasured:"Not measured"};function Lg({segment:e,from:t,share:s}){switch(e.kind){case"needs-you":return n.jsx("span",{"aria-hidden":!0,"data-part":"mark",className:A("block h-bar-needs-you w-full rounded-bar",e.open?"bar-open bar-glow":"bar-answered")});case"working":return n.jsx("span",{"aria-hidden":!0,"data-part":"mark",className:"bar-working block h-bar-working w-full rounded-capsule"});case"idle":return n.jsx("span",{"aria-hidden":!0,"data-part":"mark",className:"bar-idle block h-bar-idle w-full rounded-capsule"});case"stale":return n.jsx("span",{"aria-hidden":!0,"data-part":"mark",className:"stale-dots block h-bar-idle w-full"});case"unknown":return n.jsx("span",{"aria-hidden":!0,"data-part":"mark",className:"block h-1.5 w-full rounded-bar inset-ring inset-ring-status-idle"});case"finished":return n.jsx("span",{"aria-hidden":!0,"data-part":"mark",className:"absolute left-0 h-3 w-0.5 rounded-bar bg-status-finished"});case"failed":return n.jsx("svg",{"aria-hidden":!0,"data-part":"mark",viewBox:"0 0 10 10",fill:"none",className:"absolute left-0 size-2.5 -translate-x-1/2 text-status-finished",children:n.jsx("path",{d:"M2 2l6 6M8 2l-6 6",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round"})});case"unmeasured":return n.jsx("span",{"aria-hidden":!0,"data-part":"hatch",className:"absolute inset-0",style:{clipPath:"inset(3px 2px 3px 0 round var(--radius-bar))"},children:n.jsx("span",{className:"unmeasured-hatch absolute inset-y-0",style:{left:Ve(-t/s),width:Ve(1/s)}})})}}const $g=.01,Wg={ArrowLeft:e=>Math.max(0,e-1),ArrowRight:(e,t)=>Math.min(t,e+1),Home:()=>0,End:(e,t)=>t};function Pg(e){const t=e.to-e.from,s=e.kind==="needs-you"&&e.open===!0,o=e.startKnown===!1||s&&!e.ongoing,r=a=>[o&&"at least",a,e.ongoing&&"so far"].filter(Boolean).join(" ");return{status:e.kind==="needs-you"&&!s?"Needed you":Rg[e.kind],lasted:r(Q(t)),lastedInWords:r(Ee(t)),clock:`${xe(e.from)} to ${e.ongoing?"now":xe(e.to)}`}}function Ve(e){return`${Math.round(e*1e5)/1e3}%`}function Dg(e,t,s){const o=s-t,r=e.filter(a=>a.kind==="unmeasured").map(a=>{const i=Ve((Math.max(a.from,t)-t)/o),l=`calc(${Ve((Math.min(a.to,s)-t)/o)} - 2px)`;return`black ${i}, transparent ${i} ${l}, black ${l}`});return`linear-gradient(to right, black, ${r.join(", ")}${r.length?", ":""}black)`}function Ug({segments:e,start:t,end:s,label:o,rules:r=[],className:a}){const i=p.useRef(null),[l,d]=p.useState(null),c=s-t,u=c>0?e.filter(g=>g.to>g.from&&g.to>t&&g.from<s):[],f=u.length-1,m=l===null?-1:u.findIndex(g=>g.to===l),w=m===-1?f:m,x=g=>{const h=Wg[g.key];if(!h||f<0)return;g.preventDefault(),i.current?.querySelectorAll('[data-part="segment"]')?.[h(w,f)]?.focus()};return n.jsxs("div",{ref:i,"data-slot":"status-track",role:"group","aria-label":`${o}: status over time. Arrow keys move along it.`,onKeyDown:x,className:A("relative h-track w-full",a),children:[c>0&&r.some(g=>g>t&&g<s)&&n.jsx("span",{"aria-hidden":!0,"data-part":"rules",className:"pointer-events-none absolute inset-0",style:{maskImage:Dg(u,t,s)},children:r.filter(g=>g>t&&g<s).map(g=>n.jsx("span",{className:"absolute inset-y-0 w-px bg-hairline",style:{left:Ve((g-t)/c)}},g))}),u.map((g,h)=>{const j=Math.max(g.from,t),k=(Math.min(g.to,s)-j)/c,N=Pg(g);return n.jsx(ee,{content:n.jsxs("span",{className:"flex flex-col",children:[n.jsx("span",{children:N.status}),n.jsx("span",{className:"font-mono text-fact text-ink-secondary",children:N.lasted}),n.jsx("span",{className:"font-mono text-fact text-ink-muted",children:N.clock})]}),children:n.jsx("span",{"data-part":"segment","data-kind":g.kind,"data-open":g.kind==="needs-you"?!!g.open:void 0,role:"img","aria-label":`${N.status}, ${N.lastedInWords}, ${N.clock}`,tabIndex:h===w?0:-1,onFocus:()=>d(h===f?null:g.to),className:A("absolute inset-y-0 flex min-w-0.75 items-center pr-0.5 focus-visible:z-20",k<$g&&"z-10 before:absolute before:inset-y-0 before:-inset-x-1"),style:{left:`min(${Ve((j-t)/c)}, calc(100% - 3px))`,width:Ve(k)},children:n.jsx(Lg,{segment:g,from:(j-t)/c,share:k})})},h===f?"present":g.to)})]})}const Fg=6,Hg=96,zg=20,Bg=100;function qg(e,t){return(e-t.start)/(t.end-t.start)}function Gg(e){return`${Math.round(e*1e5)/1e3}%`}function Kg(e){return e.status===null?null:e.answered?"answered":e.stale&&e.status==="idle"?"stale":e.status}function Vg({row:e,timeline:t,rules:s,named:o}){const r=Kg(e),a=e.status==="needs-you"&&!e.answered,i=ut(e.id),l=Bt(e.name,i);return n.jsxs("li",{"data-slot":"timeline-row","data-ended":e.ended,className:"flex h-track items-center rounded-row odd:bg-fill-zebra",children:[o&&n.jsxs("div",{className:A("flex w-label-col shrink-0 items-center gap-3 px-3 text-body",a?"font-semibold text-ink":"font-medium text-ink-secondary"),children:[r?n.jsx(re,{kind:r}):n.jsx("span",{"aria-hidden":!0,"data-part":"no-mark",className:"size-mark shrink-0"}),n.jsxs(ae,{"data-part":"name",tooltip:l,children:[e.name,n.jsx(Hn,{machine:i,className:"text-ink-muted"})]})]}),n.jsx(Ug,{segments:e.segments,start:t.start,end:t.end,label:e.ended?`${l}, ended`:l,rules:s,className:"min-w-0 flex-1"})]})}const hn="block h-2.5 w-3.5 rounded-bar",Nr="block h-bar-idle w-3.5",Yg=[{kind:"needs-you",label:"Needs you",swatch:n.jsx("i",{className:A(hn,"bar-open")})},{kind:"answered",label:"Answered",swatch:n.jsx("i",{className:A(hn,"bar-answered")})},{kind:"working",label:"Working",swatch:n.jsx("i",{className:A(hn,"bar-working")})},{kind:"idle",label:"Idle",swatch:n.jsx("i",{className:A(Nr,"bar-idle rounded-capsule")})},{kind:"stale",label:"Stale",swatch:n.jsx("i",{className:A(Nr,"stale-dots")})},{kind:"finished",label:"Finished",swatch:n.jsx("i",{className:"mx-1.5 block h-3 w-0.5 rounded-bar bg-status-finished"})},{kind:"failed",label:"Failed",swatch:n.jsx(re,{kind:"failed",className:"size-2.5"})},{kind:"unknown",label:"Unknown",swatch:n.jsx("i",{className:"block h-1.5 w-3.5 rounded-bar inset-ring inset-ring-status-idle"})},{kind:"unmeasured",label:"Not measured",swatch:n.jsx("i",{className:A(hn,"unmeasured-hatch")})}];function Xg({timeline:e}){const t=new Set(["answered","working","idle","stale","finished","unmeasured"]);for(const s of e.rows)for(const o of s.segments)o.kind==="needs-you"&&o.open&&t.add("needs-you"),(o.kind==="failed"||o.kind==="unknown")&&t.add(o.kind);return n.jsx("ul",{"data-slot":"timeline-legend","aria-label":"Legend",className:"flex flex-wrap items-center gap-x-3.5 gap-y-1.5 text-caption text-ink-secondary",children:Yg.filter(s=>t.has(s.kind)).map(s=>n.jsxs("li",{"data-kind":s.kind,className:"flex items-center gap-1.5 whitespace-nowrap",children:[n.jsx("span",{"aria-hidden":!0,className:"flex items-center",children:s.swatch}),s.label]},s.kind))})}function Jg(e,t){if(t<=0)return[];const s=Math.max(1,Math.min(Fg,Math.floor(t/Hg)));return Ka(e.start,e.end,s).map(o=>({at:o,share:qg(o,e)})).filter(({share:o})=>o*t>=zg&&o*t<=t-Bg).map(({at:o,share:r})=>({at:o,left:Gg(r)}))}function Qg({timeline:e,rows:t=e.rows,named:s=!0,label:o="Sessions over the last hour",className:r="px-6 pb-4.5"}){const[a,i]=Ji(),l=Jg(e,i),d=l.map(c=>c.at);return n.jsxs("div",{className:r,children:[n.jsx("ul",{"data-slot":"timeline-rows","aria-label":o,children:t.map(c=>n.jsx(Vg,{row:c,timeline:e,rules:d,named:s},c.id))}),n.jsxs("div",{ref:a,"data-slot":"timeline-axis","aria-hidden":!0,className:A("relative mt-2 h-5.5 border-t border-rule font-mono text-micro leading-none text-ink-muted",s&&"ml-label-col"),children:[l.map(c=>n.jsx("span",{"data-part":"time-tick",className:"absolute top-2 -translate-x-1/2 whitespace-nowrap before:absolute before:-top-2 before:left-1/2 before:h-1 before:w-px before:bg-rule-strong",style:{left:c.left},children:ne(c.at)},c.at)),n.jsxs("span",{"data-part":"now",className:"absolute top-2 right-0 whitespace-nowrap text-ink-secondary before:absolute before:-top-2 before:right-0 before:h-1 before:w-px before:bg-rule-strong",children:[ne(e.end)," now"]})]})]})}function Zg({sessions:e,sources:t=[],events:s,history:o,now:r,asOf:a=r,staleAfterMs:i,className:l}){const d=p.useMemo(()=>e&&o?Oi({sessions:e,events:s,history:o,now:r,asOf:a,eventsFull:s.length>=Un,staleAfterMs:i}):null,[e,s,o,r,a,i]);let c;if(e===null)c=n.jsx(ve,{label:"Reading the last hour"});else if(d===null)c=n.jsx("div",{className:"px-6 pb-6",children:n.jsx(F,{tone:"error",title:"The last hour could not be read",children:n.jsx("p",{children:"Agent Lookout did not answer when asked for its history. The page asks again every two seconds."})})});else if(d.rows.length>0)c=n.jsx(Qg,{timeline:d});else if(t.some(u=>u.state==="searching"))c=n.jsx(ve,{label:"Looking for sessions"});else if(!t.some(u=>u.state==="ok"))c=n.jsx("div",{className:"px-6 pb-6",children:n.jsx(F,{title:"The last hour was not measured",children:n.jsx("p",{children:"No source could be read, so there is no status to draw. The Sessions card says why."})})});else{const u=Ti({from:d.start,to:d.end},d.unmeasured);c=n.jsx(Kt,{compact:!0,title:u?`No sessions ${u}`:"Nothing was measured in the last hour",children:n.jsx("p",{children:"When a session runs, its status over time is drawn here."})})}return n.jsx(q,{title:"Timeline",sub:"last hour, one row per session",aside:d&&d.rows.length>0?n.jsx(Xg,{timeline:d}):void 0,className:l,children:c})}const ew=3e4,tw=4e3;async function nw(){try{const e=await Y("/api/waits",{headers:{accept:"application/json"},signal:AbortSignal.timeout(tw)});return e.ok?Eh(await e.json()):null}catch{return null}}function Ue(e){return e.measuredMs>0}function bo(e){return Ue(e)?e.waits===0?"No waits":`${e.waits} ${e.waits===1?"wait":"waits"}`:"Not measured"}const sw=new Intl.DateTimeFormat(void 0,{weekday:"short",month:"short",day:"numeric"}),ow=new Intl.DateTimeFormat(void 0,{weekday:"long",month:"long",day:"numeric"});function Ps(e,t,s=!1){const o=se(t),r=se(e.from);if(r===o)return"Today";const a=new Date(o);return a.setDate(a.getDate()-1),r===a.getTime()?"Yesterday":(s?ow:sw).format(new Date(e.from))}function kl(e,t){return se(e.from)===se(t)?e.openMs:0}function rw(e,t){const s=Ps(e,t,!0);if(!Ue(e))return`${s}: not measured`;const o=e.waits===0?"no session waited":`waited ${Ee(e.waitedMs)} in ${bo(e).toLowerCase()}`,r=kl(e,t)>0?", still waiting":"";return`${s}: ${o}${r}, measured for ${Ee(e.measuredMs)}`}function mn(e,t){return Ue(e)?`${Q(e.measuredMs)} of ${t}`:`none of ${t}`}function aw(e){const{today:t,sevenDays:s,since:o,at:r}=e;if(e.where==="memory"){const i=s.measuredMs===t.measuredMs?"":`, and ${mn(s,"the last 7 days")}`;return`History is kept in memory only, because AGENT_LOOKOUT_HISTORY is set to off, so only the time since Agent Lookout started at ${ue(o.at,r)} is counted: ${mn(t,"today")} so far${i}.`}const a=`Only the time Agent Lookout was running is counted: ${mn(t,"today")} so far, and ${mn(s,"the last 7 days")}.`;return o.at<=s.from?a:o.by==="cleared"?`${a} The history was cleared at ${ue(o.at,r)}.`:`${a} The history it keeps begins at ${ue(o.at,r)}.`}function iw(e,t){const s=t-e.at;if(s<=0||se(t)!==se(e.at)||!Ue(e.today))return e;const o=new Set([...e.today.sessions,...e.sevenDays.sessions].filter(l=>l.open).map(l=>l.sessionId)),r=l=>({...l,waitedMs:l.waitedMs+o.size*s,openMs:l.openMs+o.size*s,measuredMs:l.measuredMs+s}),a=l=>l.open?{...l,waitedMs:l.waitedMs+s}:l,i=l=>({...r(l),to:t,days:l.days.map((d,c)=>c===l.days.length-1?{...r(d),to:t}:d),sessions:l.sessions.map(a).sort((d,c)=>c.waitedMs-d.waitedMs||d.name.localeCompare(c.name))});return{...e,at:t,today:i(e.today),sevenDays:i(e.sevenDays)}}function lw(e,t){const s=t==="today"?"today":"in the last 7 days";return Ue(e)?`No session waited on you ${s}.`:`Nothing was measured ${s}.`}function cw(e,t){const[s,o]=p.useState(null),[r,a]=p.useState(!1),i=e?.startedAt??null,l=e?Se(e).at:null,d=[...t].sort().join(" ");return p.useEffect(()=>{let c=!0;const u=()=>{nw().then(w=>{c&&(w&&o(w),a(w===null))})},f=()=>{document.hidden||u()};u();const m=setInterval(f,ew);return document.addEventListener("visibilitychange",f),()=>{c=!1,clearInterval(m),document.removeEventListener("visibilitychange",f)}},[i,l,d]),s?{waits:s,status:"ready"}:{waits:null,status:r?"failed":"loading"}}const jl="–",dw=15*6e4,uw=5,fw=[{value:"today",label:"Today"},{value:"sevenDays",label:"7 days"}];function hw(e){return`${Math.round(e*1e5)/1e3}%`}function mw({today:e}){return n.jsx("p",{"data-part":"sum",className:"text-body text-ink-secondary",children:Ue(e)?e.waits===0?"No session waited on you today":n.jsxs(n.Fragment,{children:["Sessions waited on you for"," ",n.jsx("span",{className:"font-semibold text-ink tabular-nums",children:Q(e.waitedMs)})," ","today, in ",bo(e).toLowerCase()]}):"Nothing was measured today"})}function vr({label:e,total:t,className:s}){const o=Ue(t);return n.jsxs("div",{"data-part":"figure",className:A("min-w-0",s),children:[n.jsx("dt",{className:"text-body font-medium text-ink-secondary",children:e}),n.jsxs("dd",{"data-part":"value",className:"mt-2 text-stat font-medium whitespace-nowrap tabular-nums",children:[n.jsx("span",{className:"sr-only",children:o?Ee(t.waitedMs):"Not measured"}),n.jsx("span",{"aria-hidden":!0,children:o?Q(t.waitedMs):jl})]}),n.jsx("dd",{"data-part":"count",className:"mt-2 text-caption text-ink-muted",children:bo(t)})]})}function pw({day:e,scale:t,now:s}){const o=Ue(e),r=Ps(e,s)==="Today",a=kl(e,s),i=e.waitedMs-a;return n.jsxs("li",{"data-part":"day","data-day":e.day,"data-open":a>0,className:"flex items-center gap-4 text-body leading-5 max-mid:grid max-mid:grid-cols-[minmax(0,1fr)_auto] max-mid:gap-x-4 max-mid:gap-y-1.5",children:[n.jsx("span",{"data-part":"label",className:A("w-waited-name shrink-0 max-mid:col-start-1 max-mid:row-start-1 max-mid:w-auto",r?"font-semibold text-ink":"font-medium text-ink-secondary"),children:Ps(e,s)}),n.jsx("span",{"data-part":"track",role:"img","aria-label":rw(e,s),className:"relative h-2.5 min-w-0 flex-1 before:absolute before:inset-x-0 before:top-1/2 before:h-px before:bg-hairline max-mid:col-start-1 max-mid:row-start-2",children:o?e.waitedMs>0?n.jsxs("span",{"data-part":"bar",className:"absolute inset-y-0 left-0 flex min-w-0.5 gap-0.5",style:{width:hw(Math.min(1,e.waitedMs/t))},children:[i>0&&n.jsx("i",{"data-kind":"answered",className:"block h-full min-w-0.5 rounded-bar bar-answered",style:{flexGrow:i,flexBasis:0}}),a>0&&n.jsx("i",{"data-kind":"open",className:"block h-full min-w-0.5 rounded-bar bar-open",style:{flexGrow:a,flexBasis:0}})]}):null:n.jsx("i",{"data-part":"unmeasured",className:"unmeasured-hatch absolute inset-0 block rounded-bar"})}),n.jsx("span",{"data-part":"value","aria-hidden":!0,className:"w-16 shrink-0 text-right whitespace-nowrap text-ink tabular-nums max-mid:col-start-2 max-mid:row-start-1 max-mid:justify-self-end",children:o?Q(e.waitedMs):jl}),n.jsx("span",{"data-part":"measured","aria-hidden":!0,className:"w-30 shrink-0 text-right text-caption whitespace-nowrap text-ink-muted tabular-nums max-mid:col-start-2 max-mid:row-start-2",children:o?`measured ${Q(e.measuredMs)}`:"not measured"})]})}function xw({period:e,now:t}){const s=p.useId(),o=Math.max(0,...e.days.map(a=>a.waitedMs)),r=Math.max(dw,o);return n.jsxs("section",{"data-part":"by-day","aria-labelledby":s,className:"min-w-0",children:[n.jsx("h3",{id:s,className:"text-caption font-semibold text-ink-secondary",children:"By day"}),n.jsx("ul",{className:"mt-3 grid grid-cols-1 gap-2.5",children:e.days.map(a=>n.jsx(pw,{day:a,scale:r,now:t},a.day))})]})}function gw({waits:e,period:t,onPeriod:s}){const o=p.useId(),r=e[t],a=r.sessions.slice(0,uw),i=r.sessionCount-a.length;return n.jsxs("section",{"data-part":"longest","aria-labelledby":o,className:"min-w-0",children:[n.jsxs("div",{className:"flex items-center justify-between gap-4 max-mid:flex-col max-mid:items-start max-mid:gap-2.5",children:[n.jsx("h3",{id:o,className:"text-caption font-semibold text-ink-secondary",children:"Longest waits"}),n.jsx(pe,{label:"Longest waits over",value:t,onValueChange:s,options:fw,className:"-my-2.5 max-mid:my-0"})]}),a.length>0?n.jsxs(n.Fragment,{children:[n.jsx("ul",{className:"mt-1.5",children:a.map(l=>n.jsxs("li",{"data-part":"session","data-open":l.open,className:"flex items-start justify-between gap-4 border-b border-hairline py-2.5 last:border-b-0",children:[n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs(ae,{"data-part":"name",tooltip:Bt(l.name,ut(l.sessionId)),className:"block text-body font-semibold text-ink",children:[l.name,n.jsx(Hn,{machine:ut(l.sessionId),className:"text-ink-secondary"})]}),n.jsxs("p",{"data-part":"times",className:"mt-0.5 text-caption text-ink-secondary",children:[l.waits," ",l.waits===1?"wait":"waits",l.open&&", waiting now"]})]}),n.jsxs("p",{"data-part":"value",className:"shrink-0 text-body font-medium whitespace-nowrap text-ink tabular-nums",children:[n.jsx("span",{className:"sr-only",children:Ee(l.waitedMs)}),n.jsx("span",{"aria-hidden":!0,children:Q(l.waitedMs)})]})]},l.sessionId))}),i>0&&n.jsxs("p",{"data-part":"more",className:"mt-1 text-caption text-ink-muted",children:["and ",i," more"]})]}):n.jsx("p",{"data-part":"none",className:"mt-4 text-body text-ink-secondary",children:lw(r,t)})]})}function ww({waits:e}){const[t,s]=p.useState("today");return n.jsxs("div",{"data-part":"waits",className:"px-6 pb-5.5",children:[n.jsx(mw,{today:e.today}),n.jsxs("dl",{className:"mt-4 flex items-start gap-6 max-mid:flex-col max-mid:gap-4",children:[n.jsx(vr,{label:"Today",total:e.today}),n.jsx(vr,{label:"Last 7 days",total:e.sevenDays,className:"border-l border-rule pl-6 max-mid:border-l-0 max-mid:pl-0"})]}),n.jsx("p",{"data-part":"coverage",className:"mt-4 max-w-3xl text-caption text-pretty text-ink-secondary",children:aw(e)}),n.jsxs("div",{className:"mt-6 grid grid-cols-2 gap-x-12 gap-y-7 max-wide:grid-cols-1",children:[n.jsx(xw,{period:e.sevenDays,now:e.at}),n.jsx(gw,{waits:e,period:t,onPeriod:s})]})]})}function bw({history:e,sessions:t,asOf:s,className:o}){const r=t.filter(fe).map(i=>i.id),a=cw(e,r);return n.jsx(q,{title:"Waits",className:o,children:a.waits?n.jsx(ww,{waits:iw(a.waits,s)}):a.status==="failed"?n.jsx("div",{className:"px-6 pb-5",children:n.jsx(F,{tone:"error",title:"How long sessions waited could not be read",children:n.jsx("p",{children:"Agent Lookout did not answer when asked for it. The page asks again every 30 seconds."})})}):n.jsx(ve,{label:"Reading waits"})})}function yw(e){return e!==null&&e.isConnected&&e.tabIndex>=0}function kw(e,t,s="jump"){const o=p.useRef(null),r=p.useRef(null);return p.useLayoutEffect(()=>{const l=r.current,d=o.current;if(!l||!d)return;const c=document.activeElement;if(c===l.element)return;if(c!==null&&c!==document.body){r.current=null;return}let u=l.element.isConnected?l.element:null;if(!u){const f=[...d.querySelectorAll(e)].filter(x=>x.getAttribute(t)===l.key),m=f.find(x=>x.getAttribute("data-slot")===l.slot)??f[0],w=x=>x===null?null:m?.querySelector(`[data-part="${x}"]`)??null;u=[w(l.part),w(s)].find(yw)??null}u?u.focus():r.current=null}),[o,{onFocus:l=>{const d=l.target,c=d.closest(e),u=c?.getAttribute(t);r.current=u?{key:u,slot:c?.getAttribute("data-slot")??null,part:d.getAttribute("data-part"),element:d}:null},onBlur:l=>{const d=l.relatedTarget;if(d instanceof Node&&o.current?.contains(d))return;if(d!==null){r.current=null;return}const c=l.target;setTimeout(()=>{r.current?.element===c&&c.isConnected&&(r.current=null)})}}]}const Nl=['[data-slot="hero-session"]','[data-slot="session-row"]','[data-slot="board-card"]'],jw=Nl.join(", ");function Sr(e,t){if(We(t)===null){En(t.id);return}if(!e)return;const s=CSS.escape(t.id),o=e.querySelector(Nl.map(a=>`${a}[data-session="${s}"]`).join(", ")),r=o?.querySelector('[data-part="jump"]');if(!o||!r){En(t.id);return}o.scrollIntoView({block:"center"}),r.focus({preventScroll:!0,focusVisible:!0}),r.click()}function Nw(e,t){const s=p.useRef(null);return p.useEffect(()=>{if(t!=="overview"||s.current===null)return;const o=s.current;s.current=null,Sr(e.current,o)},[e,t]),p.useCallback(o=>{if(t==="overview"){Sr(e.current,o);return}s.current=o,Ui("#overview")},[e,t])}const ye={hero:"col-start-1 row-start-1",lastHour:"col-start-2 row-start-1 max-wide:col-start-1 max-wide:row-start-2",sessions:"col-start-1 row-start-2 max-wide:row-start-3",events:"col-start-2 row-start-2 max-wide:col-start-1 max-wide:row-start-4",timeline:"col-span-2 col-start-1 row-start-3 max-wide:col-span-1 max-wide:row-start-5",waits:"col-span-2 col-start-1 row-start-4 max-wide:col-span-1 max-wide:row-start-6"};function vw({state:e,now:t,onRetry:s,onEnded:o,onAnswered:r,onOpenHistory:a,newSince:i=null,onNewLineInView:l,inApp:d=Gt()}){const{snapshot:c,phase:u}=e,[f,m]=kw(jw,"data-session");if(!c&&u==="unreachable")return n.jsx(xm,{problem:e.problem,kind:e.problemKind,onRetry:s});const w=u==="stalled"&&e.lastOkAt!==null?e.lastOkAt:t,x=c?.sessions??null,g=c?.sources??[],h=Tc(c?.timeRules),j=Ci(xo(x,g));return n.jsxs("div",{"data-slot":"dashboard","data-phase":u,className:"flex flex-col gap-4",children:[c&&u==="stalled"&&e.lastOkAt!==null&&n.jsx(pm,{lastOkAt:e.lastOkAt,now:t,onRetry:s}),n.jsx(Mm,{inApp:d}),n.jsxs("div",{ref:f,...m,"data-slot":"overview-grid",className:"relative isolate grid grid-cols-[minmax(0,1.75fr)_minmax(0,1fr)] gap-4 max-wide:grid-cols-1",children:[j&&n.jsx("div",{"aria-hidden":!0,"data-slot":"hero-light","data-light":j,className:A(j==="lamp"?"lamp-light":"rest-light",ye.hero)},j),n.jsx(cx,{sessions:x,sources:g,events:e.events,history:e.history,now:t,asOf:w,onOpenHistory:a,onAnswered:r,staleAfterMs:h,className:A("z-1",ye.hero)}),n.jsx(vx,{sessions:x,sources:g,events:e.events,history:e.history,now:t,asOf:w,className:A("z-1",ye.lastHour)}),c?n.jsxs(n.Fragment,{children:[n.jsx(_g,{sessions:c.sessions,sources:c.sources,now:w,onEnded:o,staleAfterMs:h,className:A("z-1",ye.sessions)}),n.jsx(Zm,{events:e.events,sessions:c.sessions,history:e.history,now:t,newSince:i,onNewLineInView:l,className:A("z-1",ye.events)})]}):n.jsxs(n.Fragment,{children:[n.jsx(q,{title:"Sessions",className:A("z-1",ye.sessions),children:n.jsx(ve,{label:"Reading sessions"})}),n.jsx(q,{title:"Events",className:A("z-1",ye.events),children:n.jsx(ve,{label:"Reading events"})})]}),n.jsx(Zg,{sessions:x,sources:g,events:e.events,history:e.history,now:t,asOf:w,staleAfterMs:h,className:A("z-1",ye.timeline)}),c?n.jsx(bw,{history:e.history,sessions:c.sessions,asOf:w,className:A("z-1",ye.waits)}):n.jsx(q,{title:"Waits",className:A("z-1",ye.waits),children:n.jsx(ve,{label:"Reading waits"})})]})]})}function Sw({className:e}){return n.jsxs("svg",{"data-slot":"icon",viewBox:"0 0 20 20","aria-hidden":!0,fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinejoin:"round",className:A("size-icon shrink-0",e),children:[n.jsx("rect",{x:"2.75",y:"3.25",width:"14.5",height:"4",rx:"1"}),n.jsx("rect",{x:"2.75",y:"10.25",width:"8.5",height:"6.5",rx:"1"}),n.jsx("rect",{x:"14.25",y:"10.25",width:"3",height:"6.5",rx:"1"})]})}function Aw({className:e}){return n.jsxs("svg",{"data-slot":"icon",viewBox:"0 0 20 20","aria-hidden":!0,fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",className:A("size-icon shrink-0",e),children:[n.jsx("path",{d:"M2.75 4.5h4l3.4 4.2M2.75 10h7.5M2.75 15.5h4l3.4-4.2"}),n.jsx("circle",{cx:"13.75",cy:"10",r:"3.25"})]})}function Ew({className:e}){return n.jsxs("svg",{"data-slot":"icon",viewBox:"0 0 20 20","aria-hidden":!0,fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",className:A("size-icon shrink-0",e),children:[n.jsx("path",{d:"M2.75 6.25h7M14.75 6.25h2.5M2.75 13.75h2.5M10.25 13.75h7"}),n.jsx("circle",{cx:"12.25",cy:"6.25",r:"2.25"}),n.jsx("circle",{cx:"7.75",cy:"13.75",r:"2.25"})]})}function vl({className:e}){return n.jsx("svg",{"data-slot":"icon",viewBox:"0 0 14 14","aria-hidden":!0,fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinejoin:"round",className:A("size-mark shrink-0",e),children:n.jsx("path",{d:"M11.9 8.4A5.2 5.2 0 0 1 5.6 2.1a5.2 5.2 0 1 0 6.3 6.3z"})})}function Sl({className:e}){return n.jsxs("svg",{"data-slot":"icon",viewBox:"0 0 14 14","aria-hidden":!0,fill:"none",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",className:A("size-mark shrink-0",e),children:[n.jsx("circle",{cx:"7",cy:"7",r:"2.6"}),n.jsx("path",{d:"M7 1v1.4M7 11.6V13M1 7h1.4M11.6 7H13M2.8 2.8l1 1M10.2 10.2l1 1M2.8 11.2l1-1M10.2 3.8l1-1"})]})}const Al="agent-lookout-theme",Ar="dark",El="(prefers-color-scheme: light)";function Tw(e){return e==="light"||e==="dark"||e==="system"}function Mw(){try{const e=localStorage.getItem(Al);return Tw(e)?e:Ar}catch{return Ar}}function Tl(){return window.matchMedia(El).matches?"light":"dark"}function Ml(e){return e==="system"?Tl():e}let _t=null;const wn=new Set;let Rt=null;function Cl(){const e=getComputedStyle(document.documentElement).getPropertyValue("--ground-top").trim();if(e==="")return;let t=document.head.querySelector('meta[name="theme-color"]');t||(t=document.createElement("meta"),t.name="theme-color",document.head.append(t)),t.content!==e&&(t.content=e)}function Il(e){_t=e,document.documentElement.setAttribute("data-theme",e.resolved),Cl();for(const t of wn)t()}function Cw(){if(Rt)return;const e=window.matchMedia(El),t=()=>{_t?.preference==="system"&&Il({preference:"system",resolved:Tl()})};e.addEventListener("change",t),Rt=()=>e.removeEventListener("change",t)}function Ol(){if(!_t){const e=Mw();_t={preference:e,resolved:Ml(e)}}return _t}function Iw(e){wn.add(e),Cw();const{resolved:t}=Ol();return document.documentElement.getAttribute("data-theme")!==t&&document.documentElement.setAttribute("data-theme",t),Cl(),()=>{wn.delete(e),wn.size===0&&Rt&&(Rt(),Rt=null)}}function Ow(e){try{localStorage.setItem(Al,e)}catch{}Il({preference:e,resolved:Ml(e)})}function _l(){return{...p.useSyncExternalStore(Iw,Ol),setPreference:Ow}}const _w=[{value:"dark",label:"Night",name:"Dark theme",icon:n.jsx(vl,{})},{value:"light",label:"Day",name:"Light theme",icon:n.jsx(Sl,{})}];function Rw({className:e}){const{resolved:t,setPreference:s}=_l();if(Yn()){const r=t==="dark"?"light":"dark",a=r==="light"?"Switch to Day":"Switch to Night";return n.jsx(ee,{content:a,align:"end",children:n.jsx(D,{size:"icon","aria-label":a,"data-part":"theme",onClick:()=>s(r),className:e,children:t==="dark"?n.jsx(vl,{}):n.jsx(Sl,{})})})}return n.jsx(pe,{label:"Theme",value:t,onValueChange:s,options:_w,className:e})}const Lw=new Set(["button","checkbox","color","file","hidden","image","radio","range","reset","submit"]);function $w(e){if(!e)return!1;if(e.isContentEditable===!0)return!0;switch(e.tagName){case"TEXTAREA":case"SELECT":return!0;case"INPUT":return!Lw.has((e.type??"text").toLowerCase());default:return!1}}function yo(e=typeof navigator>"u"?"":navigator.platform||navigator.userAgent||""){return/Mac|iPhone|iPad|iPod/.test(e)}function Ww(e){return/^[a-z]$/i.test(e.key)?e.key.toLowerCase():e.code?.startsWith("Key")?e.code.slice(3).toLowerCase():e.key}function Pw(e,{mac:t,typing:s}){return(t?e.metaKey&&!e.ctrlKey:e.ctrlKey&&!e.metaKey)&&!e.altKey&&!e.shiftKey&&Ww(e)==="k"?"search":s||e.metaKey||e.ctrlKey||e.altKey?null:e.key==="/"?"search":e.key==="?"?"shortcuts":null}function Rl(e){return e?{shown:"⌘K",said:"Command K"}:{shown:"Ctrl+K",said:"Control K"}}function Dw(e){return e?"/ Meta+K":"/ Control+K"}const Er=[{shown:"←",said:"Left arrow"},{shown:"→",said:"Right arrow"}];function Uw(e){return[{title:"On every view",rows:[{does:"Find a session",keys:[{shown:"/"},Rl(e)]},{does:"Show these shortcuts",keys:[{shown:"?"}]},{does:"Close a dialog",keys:[{shown:"Esc",said:"Escape"}]}]},{title:"In the search",rows:[{does:"Move through the sessions",keys:[{shown:"↑",said:"Up arrow"},{shown:"↓",said:"Down arrow"}]},{does:"Jump to the session, or open its details",keys:[{shown:"Enter"}]}]},{title:"In a chart or the timeline",rows:[{does:"Move along it",keys:Er},{does:"Go to the first or the last",keys:[{shown:"Home"},{shown:"End"}]},{does:"Ten steps in a history chart",keys:[{shown:"Page Up"},{shown:"Page Down"}]}]},{title:"In a switch",rows:[{does:"Choose the next or the previous option",keys:Er}]}]}function Fw({onSearch:e}){const t=yo();return n.jsx(ee,{content:`Find a session: / or ${Rl(t).shown}`,align:"end",children:n.jsx(D,{size:"icon","aria-label":"Find a session","aria-haspopup":"dialog","aria-keyshortcuts":Dw(t),"data-part":"search",onClick:e,children:n.jsx(Oa,{"aria-hidden":!0,className:"size-4",strokeWidth:1.75})})})}function Hw({phase:e,snapshot:t,lastOkAt:s,now:o,onSearch:r}){const a=hm(e,t,o,s),i=Yn();return n.jsxs("header",{"data-slot":"header",className:"glass-chrome glass-blur sticky top-window z-30 flex h-header shrink-0 items-center gap-5 pr-2.5 pl-6 max-mid:gap-2 max-mid:pl-4",children:[n.jsxs("div",{className:"flex min-w-0 items-center gap-5 max-mid:flex-col max-mid:items-start max-mid:gap-0.5",children:[n.jsx("h1",{className:"shrink-0 text-wordmark font-semibold whitespace-nowrap",children:"Agent Lookout"}),n.jsxs("p",{"data-slot":"status-line","data-status":a.key,className:"flex max-w-full min-w-0 items-baseline gap-3 border-l border-rule pl-5 text-body text-ink-secondary max-mid:border-l-0 max-mid:pl-0",children:[n.jsx("a",{href:"#sources",className:"truncate rounded-bar transition-colors duration-120 hover:text-ink",children:i?a.short:a.text}),a.fact&&n.jsx("span",{"data-part":"checked","aria-hidden":a.fact.ticking||void 0,className:A("shrink-0 text-caption whitespace-nowrap text-ink-muted tabular-nums",a.fact.ticking&&"max-wide:hidden"),children:a.fact.text})]})]}),n.jsxs("div",{className:"ml-auto flex shrink-0 items-center gap-2.5 max-mid:gap-1.5",children:[r&&n.jsx(Fw,{onSearch:r}),n.jsx(Rw,{})]})]})}function Ll(e){return e.normalize("NFKD").replace(new RegExp("\\p{M}","gu"),"").toLowerCase()}function zw(e){return Ll(e).split(/\s+/u).filter(Boolean)}function Bw(e,t){return Ll([e.name,e.project,e.git?.branch,e.git?.commit,t,e.machine].filter(s=>typeof s=="string").join(" "))}function qw(e,t,s){const o=Jt(e).flatMap(a=>a.sessions),r=zw(t);return r.length===0?o:o.filter(a=>{const i=Bw(a,s(a));return r.every(l=>i.includes(l))})}function Gw(e,t){if(Xt(e))return null;if(e.statusSince===null)return{shown:"–",said:"time not reported"};const s=Math.max(0,t-e.statusSince);return e.status==="finished"||e.status==="failed"?{shown:`${Dt(s)} ago`,said:`${ft(s)} ago`}:{shown:Dt(s),said:`for ${ft(s)}`}}function Kw(e){if(e.project===null)return null;const{branch:t,commit:s}=e.git??{};return t!==void 0?`${e.project} on branch ${t}`:s!==void 0?`${e.project} at commit ${s}`:e.project}function Vw({session:e,agent:t,asOf:s,id:o,active:r,onPoint:a,onPick:i}){const{mark:l,word:d,quiet:c}=po(e),u=Gw(e,s),f=We(e),m=[e.name,u===null?d:`${d} ${u.said}`,Kw(e),e.machine===void 0?t:`${t} on ${e.machine}`,f&&`Jump to ${f.where}`].filter(Boolean).join(", "),{branch:w,commit:x}=e.git??{};return n.jsxs("li",{id:o,role:"option","aria-selected":r,"aria-label":m,"data-slot":"search-result","data-session":e.id,"data-status":e.status,onPointerMove:a,onClick:i,className:A("flex cursor-pointer items-start gap-3 rounded-inner px-3.5 py-2.5",r&&"bg-fill-selected"),children:[n.jsx(re,{kind:l,className:"mt-0.75"}),n.jsxs("div",{className:"min-w-0 flex-1",children:[n.jsxs("p",{className:"flex items-baseline justify-between gap-3",children:[n.jsx("span",{"data-part":"name",className:A("min-w-0 text-row wrap-anywhere",c?"font-medium text-ink-secondary":"font-semibold text-ink"),children:e.name}),n.jsxs("span",{"data-part":"status",className:"shrink-0 text-body whitespace-nowrap text-ink-secondary",children:[d,u!==null&&n.jsxs(n.Fragment,{children:[" ",n.jsx("span",{"data-part":"duration",className:A("tabular-nums",c?"text-ink-secondary":"text-ink"),children:u.shown})]})]})]}),n.jsxs("p",{"data-part":"place",className:"text-body wrap-break-word text-ink-secondary",children:[e.project!==null&&n.jsxs(n.Fragment,{children:[n.jsx("span",{"data-part":"project",children:e.project}),w!==void 0?n.jsxs(n.Fragment,{children:[" ","on ",n.jsx("span",{"data-part":"branch",children:w})]}):x!==void 0?n.jsxs(n.Fragment,{children:[" ","at"," ",n.jsx("span",{"data-part":"commit",className:"font-mono text-fact",children:x})]}):null," "]}),n.jsxs("span",{className:"whitespace-nowrap",children:[e.project!==null&&n.jsx("span",{"aria-hidden":!0,className:"mr-1.5 ml-0.5",children:"·"}),n.jsx("span",{"data-part":"agent",children:t}),e.machine!==void 0&&n.jsxs(n.Fragment,{children:[" ","on ",n.jsx("span",{"data-part":"machine",children:e.machine})]})]})]})]})]})}function Yw({state:e,now:t,onChoose:s,onShortcuts:o}){const[r,a]=p.useState(""),[i,l]=p.useState(null),d=p.useId(),c=e.snapshot?.sessions??[],u=e.snapshot?.sources??[],f=e.phase==="stalled"&&e.lastOkAt!==null?e.lastOkAt:t,m=v=>ro(v,u),w=qw(c,r,m),x=w.findIndex(v=>v.id===i),g=w.length===0?-1:Math.max(0,x),h=w[g],j=v=>`${d}-${encodeURIComponent(v.id)}`,y=h?j(h):void 0,k=h?We(h):null;p.useEffect(()=>{y&&document.getElementById(y)?.scrollIntoView({block:"nearest"})},[y]);const N=v=>{if(!v.nativeEvent.isComposing)if(v.key==="ArrowDown"||v.key==="ArrowUp"){v.preventDefault();const b=w[(g+(v.key==="ArrowDown"?1:-1)+w.length)%w.length];b&&l(b.id)}else v.key==="Enter"&&(v.preventDefault(),h&&s(h))},E=e.snapshot?c.length===0?"No agents are running.":w.length===0?`No session matches “${r.trim()}”.`:null:"Agent Lookout has not read any sessions yet.",S=w.length===0?E??"":`${w.length} ${w.length===1?"session":"sessions"}`;return n.jsxs(n.Fragment,{children:[n.jsx(ea,{className:"sr-only",children:"Find a session"}),n.jsxs("div",{className:"relative",children:[n.jsx(Oa,{"aria-hidden":!0,strokeWidth:1.75,className:"pointer-events-none absolute top-1/2 left-3.5 size-4 -translate-y-1/2 text-ink-muted"}),n.jsx("input",{type:"text",role:"combobox","aria-label":"Find a session","aria-expanded":!0,"aria-controls":d,"aria-autocomplete":"list","aria-activedescendant":y,"data-part":"field",placeholder:"Name, folder, branch or agent",autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,enterKeyHint:"go",value:r,onChange:v=>{a(v.target.value),l(null)},onKeyDown:N,className:"h-11 w-full rounded-inner bg-transparent pr-3.5 pl-10 text-row text-ink placeholder:text-ink-muted"})]}),n.jsx("ul",{id:d,role:"listbox","aria-label":"Sessions","data-part":"results",tabIndex:-1,onPointerDown:v=>v.preventDefault(),className:"thin-scroll mt-2 max-h-[min(26rem,55vh)] overflow-y-auto border-t border-hairline pt-2",children:w.map((v,b)=>n.jsx(Vw,{session:v,agent:m(v),asOf:f,id:j(v),active:b===g,onPoint:()=>{v.id!==h?.id&&l(v.id)},onPick:()=>s(v)},v.id))}),E&&n.jsx("p",{"data-part":"empty",className:"px-3.5 pt-4 pb-6 text-center text-body text-ink-secondary",children:E}),n.jsxs("div",{className:"mt-2 flex items-baseline justify-between gap-4 border-t border-hairline px-3.5 pt-2.5 pb-1 text-caption text-ink-muted",children:[n.jsx("p",{"data-part":"enter",className:"min-w-0",children:h&&n.jsxs(n.Fragment,{children:[n.jsx("kbd",{className:"font-mono",children:"Enter"})," ",k?`jumps to it in ${k.where}`:"opens its details"]})}),n.jsxs("button",{type:"button","aria-haspopup":"dialog","data-part":"shortcuts",onClick:o,className:"-mx-1.5 -my-0.5 shrink-0 cursor-pointer rounded-row px-1.5 py-0.5 whitespace-nowrap transition-colors duration-120 hover:bg-fill-hover hover:text-ink-secondary",children:[n.jsx("kbd",{className:"font-mono",children:"?"})," for shortcuts"]})]}),n.jsx("p",{role:"status","data-part":"count",className:"sr-only",children:S})]})}function Xw({open:e,onOpenChange:t,state:s,now:o,onChoose:r,onShortcuts:a}){const i=p.useRef(null),l=p.useRef(null),d=c=>{l.current=c,t(!1)};return n.jsx(Xr,{open:e,onOpenChange:t,children:n.jsxs(Jr,{children:[n.jsx("div",{"aria-hidden":!0,"data-slot":"scrim","data-state":e?"open":"closed",className:"fixed inset-0 z-40 bg-scrim data-[state=closed]:animate-fade-out data-[state=open]:animate-fade-in"}),n.jsx(Qr,{className:"fixed inset-0 z-50 overflow-y-auto px-4 pt-[12vh] pb-24 data-[state=closed]:animate-fade-out",children:n.jsx(Zr,{"data-slot":"search-dialog","aria-describedby":void 0,className:A("glass-float glass-blur mx-auto w-[min(600px,100%)] p-2.5","data-[state=closed]:animate-drop data-[state=open]:animate-rise-fast"),onOpenAutoFocus:()=>{i.current=document.activeElement instanceof HTMLElement?document.activeElement:null,l.current=null},onCloseAutoFocus:c=>{c.preventDefault();const u=l.current,f=i.current;if(l.current=null,i.current=null,u!==null&&u!=="shortcuts"){r(u.session);return}f?.focus(),u==="shortcuts"&&a()},onKeyDown:c=>{const u=c.target instanceof HTMLInputElement&&c.target.value!=="";c.key!=="?"||u||(c.preventDefault(),d("shortcuts"))},children:n.jsx(Yw,{state:s,now:o,onChoose:c=>d({session:c}),onShortcuts:()=>d("shortcuts")})})})]})})}const Jw={sm:"w-[min(440px,100%)]",default:"w-[min(600px,100%)]",wide:"w-[min(760px,100%)]"};function Qw({open:e,onOpenChange:t,title:s,description:o,size:r="default",actions:a,focusTitle:i=!1,returnFocus:l,children:d}){const c=p.useRef(null),u=p.useRef(null);return n.jsx(Xr,{open:e,onOpenChange:t,children:n.jsxs(Jr,{children:[n.jsx("div",{"aria-hidden":!0,"data-slot":"scrim","data-state":e?"open":"closed",className:"fixed inset-0 z-40 bg-scrim data-[state=closed]:animate-fade-out data-[state=open]:animate-fade-in"}),n.jsx(Qr,{className:"fixed inset-0 z-50 overflow-y-auto px-4 pt-[6vh] pb-24 data-[state=closed]:animate-fade-out",children:n.jsxs(Zr,{"data-slot":"details-modal",className:A("glass-float glass-blur mx-auto px-6 pt-5 pb-6","data-[state=closed]:animate-drop data-[state=open]:animate-rise-fast",Jw[r]),...o?{}:{"aria-describedby":void 0},onOpenAutoFocus:f=>{c.current=document.activeElement instanceof HTMLElement?document.activeElement:null,i&&(f.preventDefault(),u.current?.focus())},onCloseAutoFocus:f=>{f.preventDefault();const m=l?.(c.current)??c.current;m?.isConnected&&m.focus(),c.current=null},children:[n.jsxs("header",{className:"flex items-start justify-between gap-4",children:[n.jsxs("div",{className:"min-w-0",children:[n.jsx(ea,{ref:u,tabIndex:i?-1:void 0,className:"text-title font-semibold wrap-anywhere outline-none",children:s}),o&&n.jsx(xc,{className:"mt-1 max-w-[56ch] text-body text-ink-secondary",children:o})]}),n.jsxs("div",{className:"flex shrink-0 items-center gap-2",children:[a,n.jsx(gc,{asChild:!0,children:n.jsx(D,{size:"icon","aria-label":"Close",children:n.jsx(Dd,{"aria-hidden":!0,className:"size-4",strokeWidth:1.75})})})]})]}),d]})})]})})}const Zw={"⌘":Wd,"↑":Aa,"↓":ja,"←":_d,"→":Rd};function eb({shown:e}){return e.split(/([⌘↑↓←→])/).filter(Boolean).map((t,s)=>{const o=Zw[t];return o?n.jsx(o,{"aria-hidden":!0,"data-sign":t,strokeWidth:1.75,className:"inline-block size-3.5"},s):t})}function tb({keys:e}){return n.jsx(n.Fragment,{children:e.map((t,s)=>n.jsxs(p.Fragment,{children:[s>0&&n.jsx("span",{className:"font-normal text-ink-secondary",children:" or "}),t.said?n.jsxs("kbd",{className:"font-mono text-fact whitespace-nowrap",children:[n.jsx("span",{"aria-hidden":!0,children:n.jsx(eb,{shown:t.shown})}),n.jsx("span",{className:"sr-only",children:t.said})]}):n.jsx("kbd",{className:"font-mono text-fact whitespace-nowrap",children:t.shown})]},t.shown))})}function nb({open:e,onOpenChange:t}){const s=Uw(yo());return n.jsx(Qw,{open:e,onOpenChange:t,title:"Keyboard shortcuts",description:n.jsxs(n.Fragment,{children:[n.jsx("kbd",{className:"font-mono text-fact",children:"/"})," and"," ",n.jsx("kbd",{className:"font-mono text-fact",children:"?"})," work wherever you are not typing."]}),size:"sm",children:n.jsx("div",{"data-slot":"shortcuts",className:"mt-2",children:s.map(o=>n.jsxs("div",{"data-part":"group",className:"mt-4",children:[n.jsx("h3",{className:"text-caption font-semibold text-ink-secondary",children:o.title}),n.jsx(De,{className:"mt-0.5",children:o.rows.map(r=>n.jsx(te,{label:r.does,children:n.jsx(tb,{keys:r.keys})},r.does))})]},o.title))})})}function sb({lit:e=!1,className:t}){return n.jsxs("svg",{"data-slot":"lookout-mark","data-lit":e,viewBox:"0 0 32 32","aria-hidden":!0,fill:"none",className:A("size-7.5 shrink-0",t),children:[n.jsx("path",{d:"M3.63 20a13 13 0 0 0 24.74 0z",fill:"currentColor",opacity:"0.13"}),n.jsx("circle",{cx:"16",cy:"16",r:"13",stroke:"currentColor",strokeWidth:"1.75"}),n.jsx("path",{d:"M3.63 20h24.74",stroke:"currentColor",strokeWidth:"1.75"}),e?n.jsxs(n.Fragment,{children:[n.jsx("circle",{"data-part":"lamp",cx:"20.6",cy:"15.1",r:"2.7",strokeWidth:"1",className:"fill-status-needs-you stroke-status-needs-you-edge"}),n.jsx("path",{"data-part":"glint",d:"M18.9 23.6h3.4",strokeWidth:"1.5",strokeLinecap:"round",className:"stroke-status-needs-you-edge"})]}):n.jsx("circle",{"data-part":"lamp",cx:"20.6",cy:"15.1",r:"2.7",stroke:"currentColor",strokeWidth:"1.4"})]})}const ob="/api/app/update",rb="/api/app/update/check",ab="/api/app/update/install",ib="/api/app/update/setting",ko={check:"check-for-updates",install:"install-update",setting:"update-setting"},lb={translocated:"macOS runs this copy from a read-only place, because it was opened where it was downloaded. Move Agent Lookout to the Applications folder, open it from there, and check again.","disk-image":"This copy runs from its disk image or another disk. Drag Agent Lookout to the Applications folder, open it from there, and check again.","read-only":"This copy is in a folder it cannot change. Move Agent Lookout to the Applications folder, open it from there, and check again.",development:"This is a development run, which never installs an update."},$l="#settings/updates",Ds=[{id:"overview",label:"Overview",href:"#overview"},{id:"sources",label:"Sources",href:"#sources"},{id:"settings",label:"Settings",href:"#settings"}];function cb(e){switch(e){case"#sources":return"sources";case"#settings":case $l:return"settings";default:return"overview"}}function db(e){return Ds.find(t=>t.id===e)?.label??"Overview"}const ub={overview:Sw,sources:Aw,settings:Ew};function fb(e){return e===null?"Agent Lookout":e===0?"Agent Lookout, no session needs you":`Agent Lookout, ${e} ${e===1?"session needs":"sessions need"} you`}function hb({current:e,needsYou:t}){const s=t!==null&&t>0;return n.jsx("nav",{"data-slot":"rail","aria-label":"Views",className:"glass-chrome z-20 w-rail shrink-0 max-mid:w-14 in-app:w-rail",children:n.jsxs("div",{className:"sticky top-window flex flex-col items-center",children:[n.jsx("div",{"data-slot":"rail-buttons","aria-hidden":!0,className:"hidden h-header w-full in-app-windowed:block"}),n.jsx("a",{href:Ds[0]?.href,"data-slot":"rail-mark","data-lit":s,"aria-label":fb(t),className:"grid h-header w-full place-items-center rounded-t-chrome text-ink focus-visible:-outline-offset-2 in-app-windowed:rounded-inner",children:n.jsx(sb,{lit:s})}),n.jsx("ul",{className:"flex w-full flex-col items-center gap-1 py-3",children:Ds.map(o=>{const r=ub[o.id],a=o.id===e;return n.jsx("li",{children:n.jsxs("a",{href:o.href,"data-slot":"rail-link","data-view":o.id,"aria-current":a?"page":void 0,className:A("flex w-15.5 flex-col items-center gap-1.25 rounded-inner pt-2.5 pb-2.25","text-micro leading-none font-medium transition-colors duration-120","max-mid:w-11 max-mid:py-2.5",a?"bg-fill-selected text-ink inset-ring inset-ring-control-rim inset-shadow-top":"text-ink-secondary hover:bg-fill-hover hover:text-ink"),children:[n.jsx(r,{}),n.jsx("span",{className:"max-mid:sr-only",children:o.label})]})},o.id)})})]})})}function Tr({children:e}){return n.jsx("code",{"data-slot":"fact","data-part":"install-command",className:"block w-fit max-w-full rounded-row bg-fill-zebra px-3 py-1.5 font-mono text-fact text-ink inset-ring inset-ring-hairline select-all wrap-break-word",children:n.jsx(Me,{children:e})})}function mb(){return n.jsxs("div",{"data-part":"install",className:"mt-3 flex flex-col gap-2",children:[n.jsx("p",{className:"text-body text-ink-secondary",children:"In Claude Code, run these two commands:"}),n.jsx(Tr,{children:"/plugin marketplace add Olanetsoft/agent-lookout"}),n.jsx(Tr,{children:"/plugin install agent-lookout@agent-lookout"})]})}function pb(e){switch(e.state){case"on":return"Permission prompts of Claude Code sessions with the plugin can be answered from here.";case"off":return"Permission prompts are not answered from here.";case"unavailable":return"Permission prompts cannot be answered from here."}}function xb({answering:e}){let t=null,s=!1;return e?.state==="on"?(s=e.plugin!=="seen",t=e.plugin==="missed"?n.jsx(n.Fragment,{children:"A Claude Code session asked for permission, but its request did not reach Agent Lookout. The plugin may not be installed for it."}):e.plugin==="seen"?n.jsxs(n.Fragment,{children:["Requests from the plugin reach Agent Lookout. Each is held for"," ",Ee(e.holdMs),", and the session's own prompt can still be answered meanwhile. Deny is always offered, and Allow when all of what it allows is shown."]}):n.jsx(n.Fragment,{children:"Answering needs the Agent Lookout plugin in Claude Code. Without it, a session's prompts are answered in the session only."})):e?.state==="off"?t=n.jsx(B,{children:"AGENT_LOOKOUT_ANSWER is off, so no request is held."}):e?.state==="unavailable"&&e.problem&&(t=n.jsx(B,{children:e.problem})),n.jsx(q,{title:"Permission prompts",children:n.jsxs("div",{"data-slot":"answer-card",className:"px-6 pb-6",children:[n.jsx("p",{"data-part":"state","aria-live":"polite",className:"text-body font-medium text-ink",children:e&&pb(e)}),t&&n.jsx("p",{"data-part":"plugin","data-plugin":e?.plugin,className:"mt-3 text-body text-ink-secondary",children:t}),s&&n.jsx(mb,{})]})})}const gb=1e4,wb=["memory-only","not-writing","failed"],bb=300;async function yb(e=gb){try{const t=await Y("/api/history/clear",{method:"POST",headers:{"Content-Type":"application/json",[we]:gu},body:"{}",signal:AbortSignal.timeout(e)}),s=await t.json(),o=typeof s=="object"&&s!==null?s:{};if(t.ok&&o.ok===!0&&typeof o.clearedAt=="number")return{ok:!0,at:o.clearedAt};const r=typeof o.error=="string"&&o.error.length<=bb?o.error:null;return{ok:!1,reason:wb.find(a=>a===o.reason)??"failed",error:r}}catch{return{ok:!1,reason:"no-answer",error:null}}}const kb=1024,Mr=1024*1024;function Cr(e){return e<=0?"0 KB":e<Mr?`${Math.max(1,Math.round(e/kb))} KB`:`${(e/Mr).toFixed(1).replace(/\.0$/,"")} MB`}function jb(e){const t=Math.round(e/864e5);return`${t} ${t===1?"day":"days"}`}function Nb(e,t,s){const o=jb(e.maxAgeMs),r=Cr(e.maxBytes);return e.where==="memory"||e.folder===null?{state:"History is kept in memory only.",facts:null,note:null,explanation:["The Events log and the charts start empty each time Agent Lookout starts, because AGENT_LOOKOUT_HISTORY is set to off.",`Without it, they are kept on this computer for ${o}, so they are still there after a restart.`]}:{state:e.problem===null?`History is kept on this computer for ${o}.`:"History is kept in memory for now.",facts:{folder:e.folder,holds:e.bytes===null?"–":`${Cr(e.bytes)} of ${r}`,since:ue(t.at,s)},note:e.problem===null?null:{title:"This copy is not writing history",detail:e.problem},explanation:[e.problem===null?"The Events log and the counts behind the charts are written to this folder every few seconds, so they are still there when Agent Lookout starts again. It holds no prompt and nothing a waiting session is asking.":"The copy that writes the history writes the Events log and the counts behind the charts to this folder every few seconds, so they are still there when Agent Lookout starts again. It holds no prompt and nothing a waiting session is asking.",`A day's history is deleted ${o} after the day ends, and the oldest goes first once the files would hold more than ${r}.`]}}function vb(e){return e.reason==="no-answer"?"Agent Lookout did not answer. Try again in a moment.":e.error??"Agent Lookout could not clear it. Try again in a moment."}const Sb="Clear the Events log and the charts? This cannot be undone.";function Ab({history:e=null,now:t,onCleared:s,clear:o=yb}){const[r,a]=p.useState({kind:"idle"}),i=p.useRef(null),l=p.useRef(null),d=p.useRef(null);p.useEffect(()=>{const h=d.current;d.current=null,h==="cancel"?l.current?.focus():h==="clear"&&i.current?.focus()},[r]);const c=e?.kept??null;if(e===null||c===null)return n.jsx(q,{title:"History",children:n.jsx("div",{className:"px-6 pb-6",children:n.jsx("p",{"data-part":"state","aria-live":"polite",className:"text-body font-medium text-ink",children:e===null?null:"Where the history is kept could not be read."})})});const u=Nb(c,Se(e),t),f=c.canClear,m=r.kind==="confirming"&&f,w=()=>{d.current="cancel",a({kind:"confirming",busy:!1})},x=()=>{d.current="clear",a({kind:"idle"})},g=()=>{r.kind!=="confirming"||r.busy||(a({kind:"confirming",busy:!0}),o().then(h=>{d.current="clear",h.ok?(a({kind:"cleared",at:h.at}),s?.()):a({kind:"failed",words:vb(h)})}))};return n.jsx(q,{title:"History",children:n.jsxs("div",{className:"px-6 pb-6",children:[n.jsxs("div",{className:"flex min-h-button flex-wrap items-center gap-x-3 gap-y-2",children:[n.jsx("p",{"data-part":"state","aria-live":"polite",className:"text-body font-medium text-ink",children:m?Sb:u.state}),f&&(m?n.jsxs(n.Fragment,{children:[n.jsx(D,{size:"sm",onClick:g,"aria-disabled":r.busy||void 0,children:"Clear history"}),n.jsx(D,{ref:l,size:"sm",onClick:x,children:"Cancel"})]}):n.jsx(D,{ref:i,size:"sm",onClick:w,children:"Clear history"}))]}),u.facts&&n.jsxs(De,{className:"mt-3",children:[n.jsx(te,{label:"Folder",mono:!0,children:n.jsx(Me,{"data-part":"folder",className:"select-text",children:u.facts.folder})}),n.jsx(te,{label:"Holds",children:n.jsx("span",{className:"tabular-nums",children:u.facts.holds})}),n.jsx(te,{label:"Since",children:n.jsx("span",{className:"tabular-nums",children:u.facts.since})})]}),u.note&&n.jsx(F,{title:u.note.title,className:"mt-3",children:n.jsx("p",{children:n.jsx(B,{children:u.note.detail})})}),r.kind==="failed"&&n.jsx(F,{title:"The history could not be cleared",className:"mt-3",children:n.jsx("p",{children:n.jsx(B,{children:r.words})})}),r.kind==="cleared"&&n.jsxs("p",{"data-part":"outcome",role:"status",className:"mt-3 text-body text-ink",children:["History cleared at ",n.jsx("span",{className:"tabular-nums",children:ue(r.at,t)}),"."]}),u.explanation.map((h,j)=>n.jsx("p",{className:j===0?"mt-3 text-body text-ink-secondary":"mt-2 text-body text-ink-secondary",children:n.jsx(B,{children:h})},h))]})})}const Eb="/api/app/menu-bar",Tb="/api/app/menu-bar/setting",Mb="menu-bar-setting",Wl=4e3;function Pl(e){if(typeof e!="object"||e===null||Array.isArray(e))return null;const{show:t}=e;return typeof t=="boolean"?{show:t}:null}async function Cb(){try{const e=await Y(Eb,{signal:AbortSignal.timeout(Wl)});return e.ok?Pl(await e.json()):null}catch{return null}}async function Ib(e){try{const t=await Y(Tb,{method:"POST",headers:{"Content-Type":"application/json",[we]:Mb},body:JSON.stringify({show:e}),signal:AbortSignal.timeout(Wl)});return t.ok?Pl(await t.json()):null}catch{return null}}function Ob(){const[e,t]=p.useState(null),s=p.useRef(!0);p.useEffect(()=>(s.current=!0,Cb().then(r=>{s.current&&t(r??"unknown")}),()=>{s.current=!1}),[]);const o=p.useCallback(r=>{Ib(r).then(a=>{s.current&&a!==null&&t(a)})},[]);return{reading:e,setShown:o}}const _b=[{value:"off",label:"Off"},{value:"on",label:"On"}],Ir="Show in menu bar";function Rb(){const{reading:e,setShown:t}=Ob();return n.jsx(q,{title:"Menu bar","data-part":"menu-bar",children:n.jsxs("div",{className:"px-6 pb-6",children:[n.jsxs("div",{"data-part":"row",className:"flex min-h-9 items-center justify-between gap-6",children:[e==="unknown"&&n.jsx("p",{"data-part":"state",className:"text-body font-medium text-ink",children:"Whether Agent Lookout is in the menu bar could not be read."}),e!==null&&e!=="unknown"&&n.jsxs(n.Fragment,{children:[n.jsx("span",{"aria-hidden":!0,className:"text-body text-ink",children:Ir}),n.jsx(pe,{label:Ir,value:e.show?"on":"off",onValueChange:s=>t(s==="on"),options:_b})]})]}),n.jsx("p",{className:"mt-3 text-body text-ink-secondary",children:"While it is on, Agent Lookout's icon in the menu bar shows how many sessions need you, with the window open or closed. Click it to list them, with how long each has waited and what it is asking, and choose one to open its details."})]})})}function Us({className:e,...t}){return n.jsx("input",{"data-slot":"text-field",type:"text",autoComplete:"off",autoCorrect:"off",autoCapitalize:"off",spellCheck:!1,className:A("h-control min-w-0 rounded-capsule bg-well px-3 text-center text-body text-ink tabular-nums","inset-ring inset-ring-control-rim inset-shadow-well","placeholder:text-ink-muted aria-invalid:inset-ring-rule-strong","disabled:opacity-50",e),...t})}const Lb=1e3;let jo=Date.now(),yt=null;const bn=new Set;function Dl(){jo=Date.now();for(const e of bn)e()}function Or(){document.hidden||Dl()}function $b(e){return bn.add(e),yt===null&&(jo=Date.now(),yt=setInterval(Dl,Lb),document.addEventListener("visibilitychange",Or)),()=>{bn.delete(e),bn.size===0&&yt!==null&&(clearInterval(yt),yt=null,document.removeEventListener("visibilitychange",Or))}}function Wb(){return jo}function Zt(){return p.useSyncExternalStore($b,Wb)}const Pb=5e3,Db=400,Ub=["invalid","no-rule","full","duplicate","not-saved"];async function Fb(e){try{const t=await Y(Cu,{method:"POST",headers:{"Content-Type":"application/json",[we]:Iu},body:JSON.stringify(e),signal:AbortSignal.timeout(Pb)}),s=await t.json(),o=typeof s=="object"&&s!==null?s:{};if(t.ok&&o.ok===!0){const i=ni(o.permissionRules);return i.ok?{ok:!0,rules:i.rules}:{ok:!1,error:null,reason:null}}const r=typeof o.error=="string"&&o.error.length<=Db?o.error:null,a=Ub.find(i=>i===o.reason)??null;return{ok:!1,error:r,reason:a}}catch{return{ok:!1,error:null,reason:null}}}const Ul=5e3,Hb=400;async function Fl(){try{const e=await Y(Eu,{signal:AbortSignal.timeout(Ul)});return e.ok?Lh(await e.json()):null}catch{return null}}async function zb(e){try{const t=await Y(Tu,{method:"POST",headers:{"Content-Type":"application/json",[we]:Mu},body:JSON.stringify(e),signal:AbortSignal.timeout(Ul)}),s=await t.json(),o=typeof s=="object"&&s!==null?s:{};return t.ok&&o.ok===!0&&o.timeRules!==void 0?{ok:!0,rules:qs(o.timeRules).rules}:{ok:!1,error:typeof o.error=="string"&&o.error.length<=Hb?o.error:null}}catch{return{ok:!1,error:null}}}const Bb=5e3,qb="Agent Lookout did not answer, so nothing changed.";function Gb(){const[e,t]=p.useState(null),[s,o]=p.useState(null),r=p.useRef(!0),a=p.useRef(0),i=p.useRef(Promise.resolve());p.useEffect(()=>{r.current=!0;const d=()=>{Fl().then(u=>{!r.current||a.current>0||t(f=>u??(f!==null&&f!=="unknown"?f:"unknown"))})};d();const c=setInterval(d,Bb);return()=>{r.current=!1,clearInterval(c)}},[]);const l=p.useCallback((d,c="list")=>{a.current+=1;const u=i.current.then(async()=>{try{const f=await Fb(d);if(f.ok)return r.current?(o(null),t(w=>w!==null&&w!=="unknown"?{...w,permissionRules:f.rules,permissionRulesProblem:null}:w),{taken:!0}):{taken:!0};const m=f.error??qb;return r.current&&c==="list"&&o(m),{taken:!1,problem:m}}finally{a.current-=1}});return i.current=u,u},[]);return{reading:e,refused:s,change:l}}const No={allow:"Allow",ask:"Ask",deny:"Deny"},Kb={allow:"Allow: Claude Code runs it without asking you. Only what you could allow here by hand, and for Bash one plain command.",ask:"Ask: the prompt waits for you, even when an allow rule matches it too.",deny:"Deny: Claude Code is told no, and carries on without it."};function Vb(e){const t=Kb[e.decision],s=e.tool.trim();return e.decision!=="allow"||s===lt||to({decision:"allow",tool:s})!==null?t:`${t} A rule for ${s} allows every ${s} request, whatever it asks for.`}const pn={decision:"allow",tool:"",command:""};function Yb(e){return{decision:e.decision,tool:e.tool,command:e.command??""}}function Xb(e){const t=e.tool.trim(),s=e.command.trim();return{decision:e.decision,tool:t,...s!==""&&{command:s}}}function Jb(e){const t=Xb(e),s=to(t);return s===null?{ok:!0,words:t}:{ok:!1,problem:s}}function Ge(e){return`${No[e.decision]} ${Wn(e)??"every tool"}`}function Hl(e){return e.tool===$n}function Qb(e){const s=`${e.decision==="deny"?"Denied":"Allowed"} ${e.tool} by the rule`;return Hl(e.rule)?`${s} for every tool`:s}const Zb=Za.map(e=>({value:e,label:No[e]}));function oe({children:e}){return n.jsx("code",{"data-slot":"fact",className:"font-mono text-fact",children:n.jsx(Me,{children:e})})}function xs({title:e,aside:t,first:s=!1,children:o,...r}){return n.jsxs("section",{...r,"aria-label":e,className:s?void 0:"mt-6",children:[n.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-4 gap-y-1 border-b border-hairline pb-2",children:[n.jsx("h3",{className:"text-body font-semibold text-ink",children:e}),t!==void 0&&n.jsx("p",{className:"text-caption text-ink-muted",children:t})]}),o]})}function ey({rule:e}){const t=Wn(e);return t===null?n.jsx("span",{className:"text-body text-ink",children:"Every tool"}):n.jsx("code",{"data-part":"rule-text",className:"min-w-0 font-mono text-fact text-ink",children:n.jsx(Me,{children:t})})}function _r({to:e,rule:t,first:s,last:o,onMove:r}){const a=e==="up"?"Move up":"Move down",i=e==="up"?s:o;return n.jsx(ee,{content:a,children:n.jsx(D,{size:"icon","data-action":e,"aria-label":`${a}: ${Ge(t)}`,"aria-disabled":i||void 0,onClick:()=>{i||r(t,e)},className:"aria-disabled:cursor-default aria-disabled:opacity-50",children:e==="up"?n.jsx(Aa,{"aria-hidden":!0,className:"size-3.5",strokeWidth:1.75}):n.jsx(ja,{"aria-hidden":!0,className:"size-3.5",strokeWidth:1.75})})})}function ty({answer:e,now:t}){const s=Hl(e.rule)?null:Wn(e.rule);return n.jsxs("li",{"data-part":"rule-answer",className:"border-b border-hairline py-2 last:border-b-0",children:[n.jsxs("div",{className:"flex items-baseline justify-between gap-3",children:[n.jsx(ae,{className:"min-w-0 text-body font-semibold text-ink",children:e.sessionName}),n.jsx(ee,{content:Fn(e.at),mono:!0,align:"end",children:n.jsx("time",{dateTime:new Date(e.at).toISOString(),className:"shrink-0 rounded-bar font-mono text-caption text-ink-muted",children:se(e.at)===se(t)?xe(e.at):ue(e.at,t)})})]}),n.jsxs("p",{className:"mt-0.5 text-caption text-ink-secondary",children:[Qb(e),s!==null&&n.jsxs(n.Fragment,{children:[" ",n.jsx(oe,{children:s})]})]})]})}function ny(e){return e===null||e.state==="on"?null:e.state==="off"?"AGENT_LOOKOUT_ANSWER is off, so no permission prompt is answered from here, by hand or by a rule.":"Permission prompts cannot be answered from here now, so no rule answers one. Permission prompts, above, says why."}function sy({answering:e=null,now:t}){const s=Zt(),o=t??s,{reading:r,refused:a,change:i}=Gb(),[l,d]=p.useState(pn),[c,u]=p.useState(null),[f,m]=p.useState(null),[w,x]=p.useState(""),g=p.useRef(!1),h=p.useRef(null),j=p.useRef(null),y=p.useRef(null),k={tool:p.useId(),command:p.useId(),decision:p.useId()};if(r===null||r==="unknown")return n.jsx(q,{title:"Permission rules",children:n.jsx("div",{"data-slot":"permission-rules-card",className:"px-6 pb-6",children:n.jsx("p",{"data-part":"state","aria-live":"polite",className:"text-body font-medium text-ink",children:r===null?null:"The permission rules could not be read."})})});const N=r.permissionRules,E=r.ruleAnswers,S=ny(e),v=(T,M)=>{requestAnimationFrame(()=>{j.current?.querySelector(`[data-rule-id="${CSS.escape(T)}"]`)?.querySelector(`[data-action="${M}"]`)?.focus()})},b=async(T,M="list")=>{if(g.current)return null;g.current=!0;try{return await i(T,M)}finally{g.current=!1}},O=async(T,M)=>{(await b({move:{id:T.id,to:M}}))?.taken&&(x(`${Ge(T)} moved ${M}.`),v(T.id,M))},H=async T=>{const M=N.findIndex(ie=>ie.id===T.id),z=N[M+1]??N[M-1];(await b({remove:{id:T.id}}))?.taken&&(x(`${Ge(T)} removed.`),c===T.id&&(u(null),d(pn)),z?v(z.id,"remove"):requestAnimationFrame(()=>h.current?.focus()))},K=T=>{u(T.id),d(Yb(T)),m(null),requestAnimationFrame(()=>y.current?.focus())},V=()=>{const T=c;u(null),d(pn),m(null),T!==null&&v(T,"edit")},R=async T=>{T.preventDefault();const M=Jb(l);if(!M.ok){m(M.problem);return}const z=c,ie=await b(z===null?{add:M.words}:{edit:{id:z,...M.words}},"form");if(ie!==null){if(!ie.taken){m(ie.problem);return}d({...pn,decision:M.words.decision}),u(null),m(z===null?`Added ${Ge(M.words)}.`:`Saved ${Ge(M.words)}.`),z!==null&&v(z,"edit")}},P=T=>{d(M=>({...M,...T})),m(null)};return n.jsx(q,{title:"Permission rules",count:N.length,titleRef:h,children:n.jsxs("div",{"data-slot":"permission-rules-card",className:"px-6 pb-6",children:[S!==null&&n.jsx(F,{title:"No rule is used now",className:"mb-3",children:n.jsx("p",{children:n.jsx(B,{children:S})})}),a!==null&&n.jsx(F,{title:"The permission rules could not be changed",className:"mb-3",children:n.jsx("p",{children:n.jsx(B,{children:a})})}),a===null&&r.permissionRulesProblem!==null&&n.jsx(F,{title:"The settings file could not be used",className:"mb-3",children:n.jsx("p",{children:n.jsx(B,{children:r.permissionRulesProblem})})}),n.jsxs(xs,{"data-part":"rules",title:"Rules",aside:"deny, then ask, then allow",first:!0,children:[N.length===0?n.jsx("p",{className:"mt-3 text-body text-ink-secondary",children:"No rule yet, so every permission prompt waits for you."}):n.jsx("ol",{ref:j,"aria-label":"Permission rules, in order",className:"flex flex-col",children:N.map((T,M)=>n.jsxs("li",{"data-part":"rule","data-rule-id":T.id,className:"border-b border-hairline py-2.5 last:border-b-0",children:[n.jsxs("p",{className:"flex flex-wrap items-baseline gap-x-2 gap-y-1",children:[n.jsx(Je,{"data-part":"decision",className:"self-center",children:No[T.decision]}),n.jsx(ey,{rule:T})]}),n.jsxs("div",{className:"mt-2 flex flex-wrap items-center gap-2",children:[n.jsx(_r,{to:"up",rule:T,first:M===0,last:M===N.length-1,onMove:(z,ie)=>{O(z,ie)}}),n.jsx(_r,{to:"down",rule:T,first:M===0,last:M===N.length-1,onMove:(z,ie)=>{O(z,ie)}}),n.jsx(D,{size:"sm","data-action":"edit","aria-label":`Edit: ${Ge(T)}`,onClick:()=>K(T),children:"Edit"}),n.jsx(D,{size:"sm","data-action":"remove","aria-label":`Remove: ${Ge(T)}`,onClick:()=>{H(T)},children:"Remove"})]})]},T.id))}),n.jsx("p",{"data-part":"rules-said",role:"status",className:"sr-only",children:w})]}),n.jsx(xs,{"data-part":"rule-form",title:c===null?"Add a rule":"Edit the rule",children:n.jsxs("form",{onSubmit:T=>{R(T)},className:"mt-3 flex flex-col gap-3",children:[n.jsxs("div",{className:"flex flex-col gap-2",children:[n.jsx(pe,{label:"Decision",value:l.decision,onValueChange:T=>P({decision:T}),options:Zb,className:"self-start"}),n.jsx("p",{id:k.decision,"data-part":"decision-sentence",className:"text-body text-ink-secondary",children:Vb(l)})]}),n.jsxs("div",{className:"flex flex-col gap-1.5",children:[n.jsx("label",{htmlFor:k.tool,className:"text-body text-ink-secondary",children:"Tool, as Claude Code names it, or * for every tool"}),n.jsx(Us,{ref:y,id:k.tool,value:l.tool,placeholder:"Bash",enterKeyHint:"done",onChange:T=>P({tool:T.target.value}),onKeyDown:T=>{T.key==="Escape"&&c!==null&&V()},className:"w-full max-w-60 text-left"})]}),n.jsxs("div",{className:"flex flex-col gap-1.5",children:[n.jsx("label",{htmlFor:k.command,className:"text-body text-ink-secondary",children:"Command, for Bash only: one, or a prefix ending in :*"}),n.jsx(Us,{id:k.command,value:l.command,placeholder:"npm test:*",enterKeyHint:"done",onChange:T=>P({command:T.target.value}),onKeyDown:T=>{T.key==="Escape"&&c!==null&&V()},className:"w-full text-left font-mono text-fact"})]}),n.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[n.jsx(D,{type:"submit",size:"sm","data-action":"save",children:c===null?"Add rule":"Save rule"}),c!==null&&n.jsx(D,{size:"sm","data-action":"cancel",onClick:V,children:"Cancel"})]}),n.jsx("p",{"data-part":"take",role:"status",className:"text-body text-ink-secondary empty:hidden",children:f})]})}),n.jsx(xs,{"data-part":"rule-answers",title:"Recent automatic answers",aside:r.ruleAnswersSince===null?void 0:`since ${ue(r.ruleAnswersSince,o)}`,children:E.length===0?n.jsx("p",{className:"mt-3 text-body text-ink-secondary",children:"No request was answered by a rule yet."}):n.jsx("ol",{"aria-label":"Recent automatic answers, newest first",tabIndex:0,className:"thin-scroll flex max-h-60 flex-col overflow-y-auto rounded-bar pr-1",children:E.map(T=>n.jsx(ty,{answer:T,now:o},`${T.sessionId}@${T.at}`))})}),n.jsx("p",{className:"mt-6 text-body text-ink-secondary",children:"A rule answers a permission prompt for you in a Claude Code session with the Agent Lookout plugin, the one agent Agent Lookout can answer for. The session can still be seen waiting for a moment first, so a notification of that wait may still come."}),n.jsxs("p",{className:"mt-2 text-body text-ink-secondary",children:["Deny goes first, then ask, then allow, as in Claude Code's own rules."," ",n.jsx(oe,{children:"npm test:*"})," matches ",n.jsx(oe,{children:"npm test"})," and ",n.jsx(oe,{children:"npm test --watch"}),", not ",n.jsx(oe,{children:"npm testing"}),". An allow rule never answers a command with ",n.jsx(oe,{children:";"}),","," ",n.jsx(oe,{children:"&&"}),", ",n.jsx(oe,{children:"|"}),", ",n.jsx(oe,{children:"$( )"}),", quotes or a redirection in it. A deny or an ask rule finds its words in any command of the line, with options between them, so"," ",n.jsx(oe,{children:"git push:*"})," also holds back ",n.jsx(oe,{children:"git -C . push"}),"."]}),n.jsxs("p",{className:"mt-2 text-body text-ink-secondary",children:["An allow rule trusts what it names. Claude can reach Agent Lookout on this computer, so no allow rule may begin with a program that sends requests or runs the code it is given, such as ",n.jsx(oe,{children:"curl"})," or ",n.jsx(oe,{children:"python"}),", and a saved list that holds one is not used at all. A rule for a package manager names its subcommand, such as ",n.jsx(oe,{children:"npm test:*"}),", and no allow rule answers a subcommand that runs code, such as ",n.jsx(oe,{children:"npm exec"}),", or a command that names Agent Lookout's own files. A rule for a program that runs a file Claude can edit, such as ",n.jsx(oe,{children:"npm test"}),", still lets Claude change these rules and answer its own prompts."]}),n.jsx("p",{className:"mt-2 text-body text-ink-secondary",children:"Claude Code's own deny and allow rules decide first: Claude Code does not ask Agent Lookout about a request they settle. An ask rule there does not hold back an allow rule here, since it is what brings the request here."}),n.jsx("p",{className:"mt-2 text-body text-ink-secondary",children:n.jsx(B,{children:`Agent Lookout keeps the rules in ${r.file}. The Events log says what each rule answered, never the command.`})})]})})}const oy=15e3,ry=["off","too-soon","limited","not-sent"],ay=300;async function iy(e,t=oy){try{const s=await Y(Wu,{method:"POST",headers:{"Content-Type":"application/json",[we]:Pu},body:JSON.stringify({channel:e}),signal:AbortSignal.timeout(t)}),o=await s.json(),r=typeof o=="object"&&o!==null?o:{};if(s.ok&&r.ok===!0&&typeof r.sentAt=="number")return{ok:!0,at:r.sentAt};const a=typeof r.error=="string"&&r.error.length<=ay?r.error:null;return{ok:!1,reason:ry.find(i=>i===r.reason)??"not-sent",error:a,limitedUntil:typeof r.limitedUntil=="number"&&Number.isFinite(r.limitedUntil)?r.limitedUntil:null}}catch{return{ok:!1,reason:"no-answer",error:null,limitedUntil:null}}}function ly(e,t){switch(e.reason){case"no-answer":return"Agent Lookout did not answer. Try again in a moment.";case"too-soon":return"A test is already on its way. Try again in a moment.";case"limited":return e.limitedUntil===null?`${Nn} pushes were tried in the last hour, the most it tries. Try again later.`:`${Nn} pushes were tried in the last hour, the most it tries. The next can go at ${ue(e.limitedUntil,t)}.`;case"off":return e.error??"It is not set up. Start Agent Lookout again with its settings.";case"not-sent":return e.error??"It could not be sent. Try again in a moment."}}function cy(e,t=iy){const[s,o]=p.useState({kind:"idle"}),r=p.useRef(!1),a=p.useRef(!0);p.useEffect(()=>(a.current=!0,()=>{a.current=!1}),[]);const i=p.useCallback(()=>{r.current||(r.current=!0,o({kind:"sending"}),t(e).then(l=>{r.current=!1,a.current&&o(l.ok?{kind:"sent",at:l.at}:{kind:"failed",words:ly(l,Date.now())})}))},[e,t]);return{step:s,send:i}}function dy({channel:e,now:t,request:s}){const{step:o,send:r}=cy(e,s),a=o.kind==="sending";return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"mt-3 flex min-h-button flex-wrap items-center gap-x-3 gap-y-2",children:[n.jsx(D,{size:"sm",onClick:r,"aria-disabled":a||void 0,children:"Send a test"}),n.jsxs("p",{"data-part":"test",role:"status",className:"text-body text-ink",children:[a&&"Sending a test…",o.kind==="sent"&&n.jsxs(n.Fragment,{children:["Test sent at ",n.jsx("span",{className:"tabular-nums",children:ue(o.at,t)}),"."]}),o.kind==="failed"&&n.jsxs("span",{className:"sr-only",children:["The test was not sent. ",o.words]})]})]}),o.kind==="failed"&&n.jsx(F,{title:"The test was not sent",className:"mt-3",children:n.jsx("p",{children:n.jsx(B,{children:o.words})})})]})}const uy="Agent Lookout did not answer, so nothing changed.",gs=(e,t)=>JSON.stringify(e)===JSON.stringify(t);function fy(e,t){const[s,o]=p.useState(null),[r,a]=p.useState(null),i=p.useRef(!0),l=p.useRef(e),d=p.useRef(null),c=p.useRef(null),u=p.useRef(0),f=p.useRef(0),m=p.useRef(Promise.resolve());p.useEffect(()=>{l.current=e}),p.useEffect(()=>(i.current=!0,Fl().then(h=>{i.current&&(o(h??"unknown"),h&&(d.current=h.timeRules,c.current=h.timeRules,u.current=Date.now()))}),()=>{i.current=!1}),[]);const w=t?.timeRules,x=t?.generatedAt;p.useEffect(()=>{w===void 0||x===void 0||c.current===null||f.current>0||x<=u.current||gs(w,c.current)||(c.current=w,d.current=w,o(h=>h!==null&&h!=="unknown"?{...h,timeRules:w}:h))},[w,x]);const g=p.useCallback(h=>{if(d.current===null)return;const j=h(d.current);gs(j,d.current)||(d.current=j,f.current+=1,m.current=m.current.then(async()=>{try{const y=c.current;if(!i.current||y===null)return;const k=h(y);if(gs(k,y))return;const N=await zb(k);if(!i.current)return;u.current=Date.now(),N.ok?(c.current=N.rules,a(null),o(E=>E!==null&&E!=="unknown"?{...E,timeRules:N.rules,problem:null}:E),l.current?.()):a(N.error??uy)}finally{f.current-=1,f.current===0&&c.current!==null&&(d.current=c.current)}}))},[]);return{reading:s,refused:r,change:g}}const ws={longWait:"Remind me of a long wait",idle:"Mark idle sessions stale",quietHours:"Quiet hours"},Rr="Remind again while it waits",Lr="Leave answered waits out of the summary";function Cn(e,t){const s=e.trim();if(!/^\d{1,5}$/.test(s))return null;const o=Number(s);return o>=t.min&&o<=t.max?o:null}function hy(e){return Cn(e,Lt)}const my=`Type a whole number of minutes from ${Lt.min} to ${Lt.max}.`;function py(e){return Cn(e,$t)}const xy=`Type a whole number of minutes from ${$t.min} to ${$t.max}.`;function zl(e){return e.repeat??{on:!1,minutes:$t.default}}function $r(e,t){return{...e,repeat:{...zl(e),...t}}}const Bl=dt.max/24;function gy(e){return e%24===0?{value:e/24,unit:"days"}:{value:e,unit:"hours"}}function wy(e,t){if(t==="hours")return Cn(e,dt);const s=Cn(e,{min:1,max:Bl});return s===null?null:s*24}const by=`Type a whole number of hours from ${dt.min} to ${dt.max}, or of days from 1 to ${Bl}.`;function yy(e){return`${e} ${e===1?"hour is":"hours is"} not a whole number of days.`}function ky(e){const t=e.trim(),s=/^(\d{1,2})(?::?(\d{2}))?$/.exec(t);if(!s)return null;const o=`${s[1].padStart(2,"0")}:${s[2]??"00"}`;return Wt(o)===null?null:o}const jy="Type a time on the 24-hour clock, such as 22:00.";function Ny(e){return`Quiet now, until ${e}. Notifications, emails, posts and pushes are held.`}const vy="Quiet hours must begin and end at different times.",Sy={mon:"Mon",tue:"Tue",wed:"Wed",thu:"Thu",fri:"Fri",sat:"Sat",sun:"Sun"},Ay={mon:"Monday",tue:"Tuesday",wed:"Wednesday",thu:"Thursday",fri:"Friday",sat:"Saturday",sun:"Sunday"};function Ey(e,t,s){return ct.filter(o=>o===t?s:e.includes(o))}const Fs=[{value:"off",label:"Off"},{value:"on",label:"On"}],Ty=[{value:"hours",label:"hours"},{value:"days",label:"days"}];function kt({value:e,label:t,onCommit:s,className:o}){const[r,a]=p.useState(null),i=()=>{r!==null&&(a(null),r.trim()!==e&&s(r))};return n.jsx(Us,{"aria-label":t,inputMode:"numeric",enterKeyHint:"done",value:r??e,onChange:l=>a(l.target.value),onBlur:i,onKeyDown:l=>{l.key==="Enter"?i():l.key==="Escape"&&r!==null&&(l.preventDefault(),a(null))},className:o})}function bs({name:e,on:t,onSwitch:s,children:o}){return n.jsxs("li",{"data-part":"rule",className:"border-b border-hairline py-2 last:border-b-0",children:[n.jsxs("div",{className:"flex items-center justify-between gap-6",children:[n.jsx("span",{"aria-hidden":!0,className:"text-body text-ink",children:e}),n.jsx(pe,{label:e,value:t?"on":"off",onValueChange:r=>s(r==="on"),options:Fs,className:"shrink-0"})]}),t&&n.jsx("div",{"data-part":"set-to",className:"mt-2 mb-1 flex flex-col gap-2 text-body text-ink-secondary",children:o})]})}function xn({take:e,children:t}){return n.jsxs("div",{children:[n.jsx("div",{className:"flex flex-wrap items-center gap-x-2 gap-y-2",children:t}),n.jsx("p",{"data-part":"take",role:"status",className:"mt-1 empty:hidden",children:e})]})}function Wr({children:e}){return n.jsx("span",{className:"inline-flex flex-wrap items-center gap-x-2 gap-y-2",children:e})}const Pr=e=>e==="repeat"?"longWait":e;function My({onChanged:e,snapshot:t=null}){const s=t?.timeRules?{timeRules:t.timeRules,generatedAt:t.generatedAt}:null,{reading:o,refused:r,change:a}=fy(e,s),[i,l]=p.useState(null),[d,c]=p.useState(null),u=p.useId();if(o===null||o==="unknown")return n.jsx(q,{title:"Time rules",children:n.jsx("div",{className:"px-6 pb-6",children:n.jsx("p",{"data-part":"state","aria-live":"polite",className:"text-body font-medium text-ink",children:o===null?null:"The time rules could not be read."})})});const{longWait:f,idle:m,quietHours:w}=o.timeRules,x=zl(f),g=d==="days"&&m.hours%24!==0?"hours":d??gy(m.hours).unit,h=g==="hours"?m.hours:m.hours/24,j=w.on&&t?.quiet===!0,y=(S,v)=>{l(b=>b!==null&&Pr(b.line)===S?null:b),a(v)},k=(S,v,b)=>O=>{const H=b(O,o.timeRules);return H===null||typeof H=="string"?(l({line:S,words:H??v}),!1):(y(Pr(S),K=>{const V=b(O,K);return V===null||typeof V=="string"?K:V}),!0)},N=S=>i?.line===S?i.words:null,E=S=>k("quietHours",jy,(v,b)=>{const O=ky(v);if(O===null)return null;const H=S==="from"?b.quietHours.to:b.quietHours.from;return O===H?vy:{...b,quietHours:{...b.quietHours,[S]:O}}});return n.jsx(q,{title:"Time rules",children:n.jsxs("div",{className:"px-6 pb-6",children:[n.jsxs("ul",{"data-part":"rules","aria-label":"Time rules",className:"flex flex-col",children:[n.jsxs(bs,{name:ws.longWait,on:f.on,onSwitch:S=>y("longWait",v=>({...v,longWait:{...v.longWait,on:S}})),children:[n.jsxs(xn,{take:N("longWait"),children:[n.jsx("span",{children:"After"}),n.jsx(kt,{label:"Minutes of waiting before the reminder",value:String(f.minutes),onCommit:k("longWait",my,(S,v)=>{const b=hy(S);return b===null?null:{...v,longWait:{...v.longWait,minutes:b}}}),className:"w-16"}),n.jsxs("span",{children:[f.minutes===1?"minute":"minutes"," of waiting"]})]}),n.jsxs("div",{className:"flex items-center justify-between gap-6",children:[n.jsx("span",{"aria-hidden":!0,children:Rr}),n.jsx(pe,{label:Rr,value:x.on?"on":"off",onValueChange:S=>y("longWait",v=>({...v,longWait:$r(v.longWait,{on:S==="on"})})),options:Fs,className:"shrink-0"})]}),x.on&&n.jsxs(xn,{take:N("repeat"),children:[n.jsx("span",{children:"Every"}),n.jsxs(Wr,{children:[n.jsx(kt,{label:"Minutes between reminders",value:String(x.minutes),onCommit:k("repeat",xy,(S,v)=>{const b=py(S);return b===null?null:{...v,longWait:$r(v.longWait,{minutes:b})}}),className:"w-16"}),n.jsx("span",{children:"minutes"})]})]})]}),n.jsx(bs,{name:ws.idle,on:m.on,onSwitch:S=>y("idle",v=>({...v,idle:{...v.idle,on:S}})),children:n.jsxs(xn,{take:N("idle"),children:[n.jsx("span",{children:"After"}),n.jsxs(Wr,{children:[n.jsx(kt,{label:g==="days"?"Days idle before stale":"Hours idle before stale",value:String(h),onCommit:k("idle",by,(S,v)=>{const b=wy(S,g);return b===null?null:{...v,idle:{...v.idle,hours:b}}}),className:"w-14"}),n.jsx(pe,{label:"Idle for",value:g,onValueChange:S=>{if(S==="days"&&m.hours%24!==0){c("hours"),l({line:"idle",words:yy(m.hours)});return}c(S),l(v=>v?.line==="idle"?null:v)},options:Ty,className:"shrink-0"}),n.jsx("span",{children:"idle"})]})]})}),n.jsxs(bs,{name:ws.quietHours,on:w.on,onSwitch:S=>y("quietHours",v=>({...v,quietHours:{...v.quietHours,on:S}})),children:[n.jsxs(xn,{take:N("quietHours"),children:[n.jsx("span",{children:"From"}),n.jsx(kt,{label:"Quiet from",value:w.from,onCommit:E("from"),className:"w-20"}),n.jsx("span",{children:"to"}),n.jsx(kt,{label:"Quiet until",value:w.to,onCommit:E("to"),className:"w-20"})]}),n.jsx("p",{"data-part":"quiet-now",role:"status",className:"empty:hidden",children:j?Ny(w.to):null}),n.jsxs("div",{role:"group","aria-labelledby":u,className:"flex flex-wrap items-center gap-x-3 gap-y-2",children:[n.jsx("span",{id:u,className:"max-mid:basis-full",children:"Beginning on"}),ct.map(S=>n.jsxs("label",{className:"inline-flex cursor-pointer items-center gap-1.5 text-ink",children:[n.jsx(ml,{checked:w.days.includes(S),onCheckedChange:v=>y("quietHours",b=>({...b,quietHours:{...b.quietHours,days:Ey(b.quietHours.days,S,v)}})),"aria-label":Ay[S]}),n.jsx("span",{"aria-hidden":!0,children:Sy[S]})]},S))]}),w.days.length===0&&n.jsx("p",{children:"No day is ticked, so quiet hours never begin."}),n.jsxs("div",{className:"flex items-center justify-between gap-6",children:[n.jsx("span",{"aria-hidden":!0,children:Lr}),n.jsx(pe,{label:Lr,value:w.leaveOutAnswered?"on":"off",onValueChange:S=>y("quietHours",v=>({...v,quietHours:{...v.quietHours,leaveOutAnswered:S==="on"}})),options:Fs,className:"shrink-0"})]})]})]}),r!==null&&n.jsx(F,{title:"The time rules could not be changed",className:"mt-3",children:n.jsx("p",{children:n.jsx(B,{children:r})})}),r===null&&o.problem!==null&&n.jsx(F,{title:"The settings file could not be read",className:"mt-3",children:n.jsx("p",{children:n.jsx(B,{children:o.problem})})}),n.jsx("p",{className:"mt-3 text-body text-ink-secondary",children:"A reminder goes by each channel that is on for waits: a notification, an email, a webhook post or a push to your phone. It says how long the session has waited, as in “checkout-flow has waited 10 minutes for permission”. It goes once per wait, and with Remind again on, again every so many minutes while the session still waits. None goes once the wait is answered or the session ends."}),n.jsx("p",{className:"mt-2 text-body text-ink-secondary",children:"A session idle longer than the idle rule says is stale, and a Claude Code session among them whose process still runs is listed under Left running. With the rule off, that is a day."}),n.jsx("p",{className:"mt-2 text-body text-ink-secondary",children:"During quiet hours no notification, email, post or push goes. When they end, a session still waiting is notified as usual, and everything else comes as one summary on each channel. Hours that run past midnight belong to the day they begin."}),n.jsx("p",{className:"mt-2 text-body text-ink-secondary",children:n.jsx(B,{children:`Agent Lookout keeps these in ${o.file}, so they hold with no dashboard open. The switches under Notifications, and the email, webhook, ntfy and Pushover settings, still choose what is sent.`})})]})})}const vo=4e3,Cy=3e4,Iy=["translocated","disk-image","read-only","development"];function So(e){return typeof e=="object"&&e!==null&&!Array.isArray(e)}const tt=e=>typeof e=="string"&&e!=="",Tt=e=>typeof e=="string"&&e.startsWith("https://"),Hs=e=>typeof e=="number"&&Number.isSafeInteger(e)&&e>=0;function Oy(e){if(!So(e))return null;switch(e.phase){case"idle":case"checking":case"up-to-date":case"no-release":return{phase:e.phase};case"downloading":return tt(e.version)&&Tt(e.notesUrl)&&Hs(e.received)&&Hs(e.total)?{phase:"downloading",version:e.version,notesUrl:e.notesUrl,received:e.received,total:e.total}:null;case"ready":case"installing":return tt(e.version)&&Tt(e.notesUrl)?{phase:e.phase,version:e.version,notesUrl:e.notesUrl}:null;case"cannot-install":{const t=Iy.find(s=>s===e.refusal);return tt(e.version)&&Tt(e.notesUrl)&&t!==void 0?{phase:"cannot-install",version:e.version,notesUrl:e.notesUrl,refusal:t}:null}case"failed":{const t=e.step==="check"||e.step==="download"||e.step==="install"?e.step:null;return t===null||!tt(e.reason)?null:{phase:"failed",step:t,reason:e.reason,version:tt(e.version)?e.version:null,notesUrl:Tt(e.notesUrl)?e.notesUrl:null}}default:return null}}function zs(e){if(!So(e))return null;const t=Oy(e.update);if(t===null||!tt(e.version)||typeof e.automatic!="boolean"||!Tt(e.releasesUrl))return null;const s=e.lastCheckedAt;return{version:e.version,automatic:e.automatic,lastCheckedAt:Hs(s)&&s>0?s:null,releasesUrl:e.releasesUrl,update:t}}async function _y(e){const t=await e.json();return e.ok?zs(t):So(t)?zs(t.status):null}async function Dr(){try{const e=await Y(ob,{signal:AbortSignal.timeout(vo)});return e.ok?zs(await e.json()):null}catch{return null}}async function Ao(e,t,s,o){try{const r=await Y(e,{method:"POST",headers:{"Content-Type":"application/json",[we]:t},body:JSON.stringify(s),signal:AbortSignal.timeout(o)});return await _y(r)}catch{return null}}function Ry(){return Ao(rb,ko.check,{},Cy)}function Ly(){return Ao(ab,ko.install,{},vo)}function $y(e){return Ao(ib,ko.setting,{automatic:e},vo)}const Wy=1e3,Py=5e3;function Dy(e){const{phase:t}=e.update;return t==="downloading"||t==="ready"||t==="installing"}function Uy(e){if(e===null||e==="unknown")return!1;const{phase:t}=e.update;return t==="checking"||t==="downloading"||t==="installing"}function Fy(){const[e,t]=p.useState(null),[s,o]=p.useState(null),r=p.useRef(!0),a=p.useCallback(u=>{r.current&&t(u??"unknown")},[]);p.useEffect(()=>(r.current=!0,Dr().then(a),()=>{r.current=!1}),[a]);const i=Uy(e);p.useEffect(()=>{if(e===null)return;const u=setTimeout(()=>{Dr().then(a)},i?Wy:Py);return()=>clearTimeout(u)},[e,i,a]);const l=p.useCallback(()=>{o("check"),t(u=>u===null||u==="unknown"||Dy(u)?u:{...u,update:{phase:"checking"}}),Ry().then(u=>{r.current&&(o(null),u!==null&&t(u))})},[]),d=p.useCallback(()=>{o("install"),Ly().then(u=>{r.current&&(o(null),u!==null&&t(u))})},[]),c=p.useCallback(u=>{$y(u).then(f=>{r.current&&f!==null&&t(f)})},[]);return{reading:e,pressed:s,check:l,install:d,setAutomatic:c}}const Hy=1024*1024;function Ur(e){return`${Math.round(e/Hy)} MB`}function zy(e,t){return e.lastCheckedAt===null?"Not yet":ue(e.lastCheckedAt,t)}function By(e){const{update:t}=e,s={detail:null,install:!1,canCheck:!0,notesUrl:null,note:null};switch(t.phase){case"idle":return{...s,state:e.automatic?"Agent Lookout checks about once a day.":"Agent Lookout checks only when you ask."};case"checking":return{...s,state:"Checking for updates…",canCheck:!1};case"up-to-date":return{...s,state:"You're up to date."};case"no-release":return{...s,state:"The latest release has no Mac app yet."};case"not-for-this-mac":return{...s,state:"The latest release has no app for this kind of Mac."};case"downloading":return{...s,state:`Version ${t.version} is available.`,detail:t.total>0?`Downloading it: ${Ur(t.received)} of ${Ur(t.total)}.`:"Downloading it.",notesUrl:t.notesUrl};case"ready":return{...s,state:`Version ${t.version} is available.`,detail:"Downloaded and checked.",install:!0,notesUrl:t.notesUrl};case"installing":return{...s,state:`Installing version ${t.version}…`,detail:"Agent Lookout quits and opens again as the new version.",canCheck:!1,notesUrl:t.notesUrl};case"cannot-install":return{...s,state:`Version ${t.version} is available.`,note:{title:"Agent Lookout cannot update itself here",detail:lb[t.refusal],link:t.notesUrl}};case"failed":return t.step==="check"?{...s,state:"The last check did not work.",note:{title:"Agent Lookout could not check for updates",detail:`${$e(t.reason)}. Check again in a while.`,link:e.releasesUrl}}:{...s,state:t.version===null?"A newer version is available.":`Version ${t.version} is available.`,note:{title:`${t.version===null?"The new version":`Version ${t.version}`} could not be ${t.step==="install"?"installed":"downloaded"}`,detail:`${$e(t.reason)}. Check again to try once more.`,link:t.notesUrl??e.releasesUrl}}}}const qy=[{value:"off",label:"Off"},{value:"on",label:"On"}],Fr="Check for updates automatically",Hr="rounded-bar underline decoration-rule-strong underline-offset-2 transition-colors duration-120 hover:text-ink";function Gy(){const{reading:e,pressed:t,check:s,install:o,setAutomatic:r}=Fy(),a=Zt(),i=p.useRef(null);p.useEffect(()=>{const c=()=>{window.location.hash===$l&&i.current?.scrollIntoView({block:"nearest"})};return c(),window.addEventListener("hashchange",c),()=>window.removeEventListener("hashchange",c)},[]);const l=e===null||e==="unknown"?null:e,d=l===null?null:By(l);return n.jsx(q,{ref:i,title:"Updates","data-part":"updates",children:n.jsxs("div",{className:"px-6 pb-6",children:[n.jsxs("div",{className:"flex min-h-button flex-wrap items-center gap-x-3 gap-y-2",children:[n.jsx("p",{"data-part":"state","aria-live":"polite",className:"text-body font-medium text-ink",children:e==="unknown"?"Whether a newer version is out could not be read.":d?.state}),d!==null&&(d.install?n.jsx(D,{size:"sm",onClick:o,disabled:t!==null,children:"Install and Restart"}):n.jsx(D,{size:"sm",onClick:s,disabled:!d.canCheck||t!==null,children:"Check for Updates…"}))]}),d!==null&&(d.detail!==null||d.notesUrl!==null)&&n.jsxs("p",{"data-part":"found",className:"mt-1 text-body text-ink-secondary",children:[d.detail,d.detail!==null&&d.notesUrl!==null&&" ",d.notesUrl!==null&&n.jsx("a",{href:d.notesUrl,target:"_blank",rel:"noreferrer",className:Hr,children:"Release notes"})]}),d?.note&&n.jsx(F,{title:d.note.title,className:"mt-3",children:n.jsxs("p",{children:[d.note.detail," ",n.jsx("a",{href:d.note.link,target:"_blank",rel:"noreferrer",className:Hr,children:"Release page"})]})}),l!==null&&n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"mt-3 flex items-center justify-between gap-6 border-b border-hairline py-2",children:[n.jsx("span",{"aria-hidden":!0,className:"text-body text-ink",children:Fr}),n.jsx(pe,{label:Fr,value:l.automatic?"on":"off",onValueChange:c=>r(c==="on"),options:qy})]}),n.jsxs(De,{children:[n.jsxs(te,{label:"Version",mono:!0,children:["v",l.version]}),n.jsx(te,{label:"Last checked",children:n.jsx("span",{className:"tabular-nums",children:zy(l,a)})})]})]}),n.jsx("p",{className:"mt-3 text-body text-ink-secondary",children:"Agent Lookout asks GitHub whether a newer version has been released when you press Check for Updates…, and about once a day while Check for updates automatically is on. It sends nothing about your sessions: GitHub sees the app's version number and your IP address, as with any web request."}),n.jsx("p",{className:"mt-2 text-body text-ink-secondary",children:"A newer version is downloaded and checked first, and installed only when you press Install and Restart. To update itself, Agent Lookout must be in a folder it can change, such as Applications."})]})})}function Ky(e){const[t,s]=p.useState({kind:"idle"}),[o,r]=p.useState(null),a=p.useRef(!1),i=p.useRef(!0),l=p.useRef(!1);p.useEffect(()=>(i.current=!0,e&&Sm().then(c=>{i.current&&!l.current&&c!==null&&r(c.lastRefusal)}),()=>{i.current=!1}),[e]);const d=p.useCallback(()=>{!e||a.current||(a.current=!0,s({kind:"sending"}),ji().then(c=>{a.current=!1,i.current&&((c?.outcome==="refused"||c?.outcome==="shown")&&(l.current=!0,r(c.outcome==="refused"?c.reason:null)),s(c===null?{kind:"failed"}:{kind:"answered",answer:c,at:Date.now()}))}))},[e]);return{step:t,lastRefusal:o,send:d}}const Vy=5e3;function jt(e){const[t,s]=p.useState(null);return p.useEffect(()=>{let o=!0;const r=()=>{e().then(i=>{o&&s({status:i??"unknown",readAt:Date.now()})})};r();const a=setInterval(r,Vy);return()=>{o=!1,clearInterval(a)}},[e]),t}const en=4e3;function Xn(e,t,s){const{last:o,limitedUntil:r}=e;if(r!==null){const a=ue(r,t);return o!==null&&!o.sent?{title:s.failed,detail:`${$e(o.reason)}. No more will be tried until ${a}, as ${Nn} were tried in the last hour.`}:{title:s.held,detail:`${Nn} ${s.plural} were tried in the last hour, the most it tries. The next can go at ${a}.`}}return o===null?{title:null,detail:null}:o.sent?{title:null,detail:`${s.lastAt} ${ue(o.at,t)}.`}:{title:s.failed,detail:`${$e(o.reason)}.`}}function ql(e){const t=Math.round(e/1e3),s=(o,r)=>`${o} ${r}${o===1?"":"s"}`;return t>=3600&&t%3600===0?s(t/3600,"hour"):t>=60&&t%60===0?s(t/60,"minute"):s(t,"second")}function Yy(e){return e.length<=1?e.join(""):`${e.slice(0,-1).join(", ")} or ${e[e.length-1]}`}function Xy(e,t){switch(e){case"needs-you":return t===0?"starts waiting":`has waited ${ql(t)}`;case"finished":return"finishes";case"failed":return"fails";case"ended":return"ends"}}function Jn(e,t,s,o){return s.length===1&&s[0]==="needs-you"?o===0?`${e} go to ${t} as soon as a session waits.`:`${e} go to ${t} after a wait of ${ql(o)}.`:`${e} go to ${t} when a session ${Yy(s.map(r=>Xy(r,o)))}.`}async function Jy(){try{const e=await Y("/api/email",{signal:AbortSignal.timeout(en)});return e.ok?Mh(await e.json()):null}catch{return null}}const Qy={plural:"emails",failed:"The last email could not be sent",held:"Emails are held back",lastAt:"Last sent at"};function Zy(e,t){return!e.on||e.to===null||e.events===null||e.afterMs===null?e.problem===null?{state:"Email is off.",asking:null,title:null,detail:"Set AGENT_LOOKOUT_EMAIL_TO and AGENT_LOOKOUT_SMTP_URL to turn it on."}:{state:"Email is off.",asking:null,title:"Email is not set up correctly",detail:`${e.problem} Correct it and start Agent Lookout again.`}:{...{state:Jn("Emails",e.to,e.events,e.afterMs),asking:e.asking?"Emails for a wait say what the session is asking.":"Emails leave out what a waiting session is asking."},...Xn(e,t,Qy)}}async function ek(){try{const e=await Y("/api/webhook",{signal:AbortSignal.timeout(en)});return e.ok?Oh(await e.json()):null}catch{return null}}const tk={plural:"posts",failed:"The last post failed",held:"Posts are held back",lastAt:"Last posted at"};function nk(e,t){return!e.on||e.host===null||e.events===null||e.afterMs===null?e.problem===null?{state:"The webhook is off.",asking:null,title:null,detail:"Set AGENT_LOOKOUT_WEBHOOK_URL to turn it on."}:{state:"The webhook is off.",asking:null,title:"The webhook is not set up correctly",detail:`${e.problem} Correct it and start Agent Lookout again.`}:{...{state:Jn("Posts",e.host,e.events,e.afterMs),asking:e.asking?"Posts for a wait say what the session is asking.":"Posts leave out what a waiting session is asking."},...Xn(e,t,tk)}}async function sk(){try{const e=await Y("/api/ntfy",{signal:AbortSignal.timeout(en)});return e.ok?_h(await e.json()):null}catch{return null}}const Gl={plural:"pushes",failed:"The last push failed",held:"Pushes are held back",lastAt:"Last sent at"};function ok(e,t){return!e.on||e.host===null||e.events===null||e.afterMs===null?e.problem===null?{state:"ntfy is off.",asking:null,title:null,detail:"Set AGENT_LOOKOUT_NTFY_URL to turn it on."}:{state:"ntfy is off.",asking:null,title:"ntfy is not set up correctly",detail:`${e.problem} Correct it and start Agent Lookout again.`}:{...{state:Jn("Pushes",e.host,e.events,e.afterMs),asking:e.asking?"Pushes for a wait say what the session is asking.":"Pushes leave out what a waiting session is asking.",note:e.tokenSet?"An access token is set.":"No access token is set, so the topic alone guards the pushes: keep it secret."},...Xn(e,t,Gl)}}async function rk(){try{const e=await Y("/api/pushover",{signal:AbortSignal.timeout(en)});return e.ok?Rh(await e.json()):null}catch{return null}}function ak(e,t){return!e.on||e.events===null||e.afterMs===null?e.problem===null?{state:"Pushover is off.",asking:null,title:null,detail:"Set AGENT_LOOKOUT_PUSHOVER_TOKEN and AGENT_LOOKOUT_PUSHOVER_USER to turn it on."}:{state:"Pushover is off.",asking:null,title:"Pushover is not set up correctly",detail:`${e.problem} Correct it and start Agent Lookout again.`}:{...{state:Jn("Pushes","Pushover",e.events,e.afterMs),asking:e.asking?"Pushes for a wait say what the session is asking.":"Pushes leave out what a waiting session is asking."},...Xn(e,t,Gl)}}async function ik(){try{const e=await Y("/api/pull-requests",{signal:AbortSignal.timeout(en)});return e.ok?Ih(await e.json()):null}catch{return null}}const lk="Your own gh sends GitHub the name of each repository and branch it is asked about, with its own login.";function ck(e){return e.on&&e.gh!==null&&e.gh!=="not-found"&&e.gh!=="signed-out"}function dk(e,t){if(!e.on||e.gh===null)return e.problem===null?{state:"Pull requests are off.",asking:null,title:null,detail:"Set AGENT_LOOKOUT_PULL_REQUESTS=on to show each session's pull request and its checks, through your own gh."}:{state:"Pull requests are off.",asking:null,title:"Pull requests are not set up correctly",detail:`${e.problem} Correct it and start Agent Lookout again.`};switch(e.gh){case"not-found":return{state:"No pull request is shown.",asking:null,title:"The GitHub CLI was not found",detail:"Install gh, then sign in with gh auth login."};case"signed-out":return{state:"No pull request is shown.",asking:null,title:"The GitHub CLI is not signed in",detail:"Run gh auth login in a terminal to sign in to github.com."}}const s={state:"Pull requests are shown for branches of repositories on github.com.",asking:lk},{last:o}=e;return o===null?{...s,title:null,detail:"No session is on a branch to ask about yet."}:o.ok?{...s,title:null,detail:`Last checked at ${ue(o.at,t)}.`}:{...s,title:"The last check did not work",detail:`${o.reason.startsWith("gh")?o.reason:$e(o.reason)}. It is tried again within 2 minutes.`}}const uk=[{value:"dark",label:"Night",name:"Dark theme"},{value:"light",label:"Day",name:"Light theme"},{value:"system",label:"System",name:"Follow the computer's setting"}],fk=[{value:"off",label:"Off"},{value:"on",label:"On"}];function hk({events:e,chooseEvent:t}){return n.jsx("ul",{"data-part":"events","aria-label":"What sends a notification",className:"mt-3 flex flex-col",children:mt.map(s=>n.jsxs("li",{className:"flex items-center justify-between gap-6 border-b border-hairline py-2 last:border-b-0",children:[n.jsx("span",{"aria-hidden":!0,className:"text-body text-ink",children:Rs[s]}),n.jsx(pe,{label:Rs[s],value:e.includes(s)?"on":"off",onValueChange:o=>t(s,o==="on"),options:fk})]},s))})}const zr="Quit Agent Lookout, open it again, and send another test.",Br="Quit Agent Lookout, open it again, and turn them on here.",Kl="Open System Settings, choose Notifications, then Agent Lookout, and turn on Allow notifications. Then send a test again.";function qr({reason:e}){return n.jsxs(n.Fragment,{children:[n.jsx("p",{children:Kl}),n.jsxs("p",{className:"mt-2",children:["macOS said: ",n.jsx(B,{children:e})]})]})}function mk({test:e,now:t}){const{step:s,lastRefusal:o,send:r}=e,a=s.kind==="sending",i=s.kind==="answered"?s.answer:null;return n.jsxs(n.Fragment,{children:[n.jsxs("div",{className:"mt-3 flex min-h-button flex-wrap items-center gap-x-3 gap-y-2",children:[n.jsx(D,{size:"sm",onClick:r,"aria-disabled":a||void 0,children:"Send a test"}),n.jsxs("p",{"data-part":"test",role:"status",className:"text-body text-ink",children:[a&&"Sending a test…",s.kind==="answered"&&i?.outcome==="shown"&&n.jsxs(n.Fragment,{children:["macOS took the test at ",n.jsx("span",{className:"tabular-nums",children:ue(s.at,t)}),"."]}),i?.outcome==="no-answer"&&"macOS has not answered yet. If it asks whether Agent Lookout may show notifications, allow them, then send a test again.",i?.outcome==="refused"&&n.jsxs("span",{className:"sr-only",children:["macOS did not allow it. ",Kl]}),i?.outcome==="unsupported"&&n.jsxs("span",{className:"sr-only",children:["Agent Lookout could not show a notification. ",zr]}),s.kind==="failed"&&n.jsx("span",{className:"sr-only",children:"The test was not sent. Agent Lookout did not answer. Try again in a moment."})]})]}),i?.outcome==="refused"&&n.jsx(F,{title:"macOS did not allow it",className:"mt-3",children:n.jsx(qr,{reason:i.reason})}),i?.outcome==="unsupported"&&n.jsx(F,{title:"Agent Lookout could not show a notification",className:"mt-3",children:n.jsx("p",{children:zr})}),s.kind==="failed"&&n.jsx(F,{title:"The test was not sent",className:"mt-3",children:n.jsx("p",{children:"Agent Lookout did not answer. Try again in a moment."})}),s.kind!=="answered"&&o!==null&&n.jsx(F,{title:"macOS did not show the last notification",className:"mt-3",children:n.jsx(qr,{reason:o})})]})}function pk({step:e,lastRefusal:t}){return e.kind==="answered"?e.answer.outcome==="refused":t!==null}function xk({inApp:e,now:t}){const{on:s,permission:o,events:r,turnOn:a,turnOff:i,chooseEvent:l}=ki(),d=Ky(e),c=e&&pk(d),u=()=>{a(),e&&d.send()},f=e?s?c?"Notifications are on in this app, but macOS is not showing them.":"Notifications are on in this app.":"Notifications are off in this app.":s?"Notifications are on.":"Notifications are off.";return n.jsx(q,{title:"Notifications",children:n.jsxs("div",{className:"px-6 pb-6",children:[n.jsxs("div",{className:"flex min-h-button flex-wrap items-center gap-x-3 gap-y-2",children:[n.jsx("p",{"data-part":"state","aria-live":"polite",className:"text-body font-medium text-ink",children:f}),o!=="unsupported"&&n.jsx(D,{size:"sm",onClick:s?i:u,children:s?"Turn off notifications":"Turn on notifications"})]}),s&&n.jsx(hk,{events:r,chooseEvent:l}),s&&r.length===0&&n.jsx("p",{className:"mt-3 text-body text-ink-secondary",children:"No event is switched on, so none is sent."}),e&&n.jsx(mk,{test:d,now:t}),o==="denied"&&(e?n.jsx(F,{title:"This window is not allowed to show notifications",className:"mt-3",children:n.jsx("p",{children:Br})}):n.jsx(F,{title:"Notifications are blocked",className:"mt-3",children:n.jsx("p",{children:"Your browser is blocking notifications from this address. Allow them for this address in the browser's site settings, then turn them on here."})})),o==="unsupported"&&(e?n.jsx(F,{title:"This window cannot show notifications",className:"mt-3",children:n.jsx("p",{children:Br})}):n.jsx(F,{title:"This browser cannot show notifications",className:"mt-3",children:n.jsx("p",{children:"Open Agent Lookout in a browser that can, then turn them on here."})})),e&&n.jsx("p",{className:"mt-3 text-body text-ink-secondary",children:"This setting is the app's own. Turning notifications on in a browser does not turn them on here."}),n.jsx("p",{className:A("text-body text-ink-secondary",e?"mt-2":"mt-3"),children:"With Needs you on, a notification appears each time a session starts waiting for you. It names the session and the reason, and is cleared when the session moves on."}),!s&&n.jsx("p",{className:"mt-2 text-body text-ink-secondary",children:"Once they are on, you can also be told when a session finishes or fails, or ends without saying whether it finished, as when its process stops. Those name the session and what happened, and stay until you clear them."}),n.jsxs("p",{className:"mt-2 text-body text-ink-secondary",children:[e?"They also arrive while this window is closed, for as long as Agent Lookout keeps running, and those stay until you clear them.":"On a Mac they also arrive when no dashboard tab is open, for as long as Agent Lookout keeps running, and those stay until you clear them."," ","What each agent can report, under"," ",n.jsx("a",{href:"#sources",className:"rounded-bar underline decoration-rule-strong underline-offset-2 transition-colors duration-120 hover:text-ink",children:"Sources"}),", says which agents can be seen waiting."]}),e&&n.jsx("p",{className:"mt-2 text-body text-ink-secondary",children:"macOS hides their banners while the display is shared or mirrored, unless Allow notifications when mirroring or sharing the display is on, in System Settings under Notifications."})]})})}function Nt(e,t,s){return e===null?null:e.status==="unknown"?{state:t,asking:null,title:null,detail:null}:s(e.status,e.readAt)}function vt({title:e,words:t,test:s}){return n.jsx(q,{title:e,children:n.jsxs("div",{className:"px-6 pb-6",children:[n.jsx("p",{"data-part":"state","aria-live":"polite",className:"text-body font-medium text-ink",children:t?.state}),t?.asking&&n.jsx("p",{"data-part":"asking",className:"mt-3 text-body text-ink-secondary",children:n.jsx(B,{children:t.asking})}),t?.note&&n.jsx("p",{"data-part":"note",className:"mt-3 text-body text-ink-secondary",children:n.jsx(B,{children:t.note})}),t?.detail&&(t.title?n.jsx(F,{title:t.title,className:"mt-3",children:n.jsx("p",{children:n.jsx(B,{children:t.detail})})}):n.jsx("p",{className:"mt-3 text-body text-ink-secondary",children:n.jsx(B,{children:t.detail})})),s&&n.jsx(dy,{channel:s.channel,now:s.now})]})})}function gk(e){return e.length<=1?e.join(""):`${e.slice(0,-1).join(", ")} and ${e[e.length-1]}`}function wk({emailing:e,posting:t,pushing:s},o){const r=[...e?["emails"]:[],...t?["posts"]:[],...s?["pushes"]:[]],a=r.length===0?null:r.length===1&&t?"the webhook posts you set up":`the ${gk(r)} you set up`;return o?a===null?"Sent only as repository and branch names, to GitHub through gh":`Sent only in ${a}, and repository and branch names to GitHub`:a===null?"Agent Lookout sends it nowhere":`Sent only in ${a}`}function bk({history:e=null,now:t,onHistoryCleared:s,onTimeRulesChanged:o,snapshot:r=null,inApp:a=Gt(),answering:i=null}={}){const{preference:l,setPreference:d}=_l(),c=Zt(),u=jt(Jy),f=jt(ek),m=jt(sk),w=jt(rk),x=jt(ik),g=typeof m?.status=="object"&&m.status.on,h=typeof w?.status=="object"&&w.status.on,j={emailing:typeof u?.status=="object"&&u.status.on,posting:typeof f?.status=="object"&&f.status.on,pushing:g||h},y=typeof x?.status=="object"&&ck(x.status),k=t??c;return n.jsxs("div",{"data-slot":"settings-view",className:"grid grid-cols-12 items-start gap-4 max-wide:flex max-wide:flex-col",children:[n.jsxs("div",{className:"col-span-8 flex min-w-0 flex-col gap-4 max-wide:w-full",children:[n.jsx(q,{title:"Theme",children:n.jsxs("div",{className:"px-6 pb-6",children:[n.jsx(pe,{label:"Theme",value:l,onValueChange:d,options:uk}),n.jsx("p",{className:"mt-3 text-body text-ink-secondary",children:"Night is the default. System follows the setting on your computer, and changes when it does."})]})}),n.jsx(xk,{inApp:a,now:k}),n.jsx(My,{onChanged:o,snapshot:r}),n.jsx(Ab,{history:e,now:k,onCleared:s}),a&&n.jsx(Rb,{}),a&&n.jsx(Gy,{})]}),n.jsxs("div",{className:"col-span-4 flex min-w-0 flex-col gap-4 max-wide:w-full",children:[n.jsx(vt,{title:"Email",words:Nt(u,"Whether email is set up could not be read.",Zy)}),n.jsx(vt,{title:"Webhook",words:Nt(f,"Whether the webhook is set up could not be read.",nk)}),n.jsx(vt,{title:"ntfy",words:Nt(m,"Whether ntfy is set up could not be read.",ok),test:g?{channel:"ntfy",now:k}:null}),n.jsx(vt,{title:"Pushover",words:Nt(w,"Whether Pushover is set up could not be read.",ak),test:h?{channel:"pushover",now:k}:null}),n.jsx(vt,{title:"Pull requests",words:Nt(x,"Whether pull requests are shown could not be read.",dk)}),n.jsx(xb,{answering:i}),n.jsx(sy,{answering:i,now:k}),n.jsx(q,{title:"This copy",children:n.jsxs(De,{className:"px-6 pb-3",children:[n.jsxs(te,{label:"Version",mono:!0,children:["v","0.2.10"]}),n.jsx(te,{label:"Your data",children:n.jsx(B,{children:wk(j,y)})})]})})]})]})}function yk(e){const t=[];for(const s of e){s.capabilities&&t.push({key:s.id,source:s.id,label:s.label,capabilities:s.capabilities});for(const o of s.agents??[])t.push({key:`${s.id}
9
+ ${o.label}`,source:s.id,agent:o.label,label:`${o.label} on ${s.label}`,capabilities:o.capabilities})}return t}function kk({cell:e}){return e.level==="yes"?n.jsx("span",{"data-part":"capability","data-level":"yes",className:"text-ink-secondary",children:nt.yes}):n.jsx(ee,{content:e.reason,children:n.jsxs("span",{"data-part":"capability","data-level":e.level,tabIndex:0,className:"rounded-bar font-medium text-ink",children:[nt[e.level],n.jsxs("span",{className:"sr-only",children:[": ",e.reason]})]})})}function jk({rows:e}){const t="pr-2 pb-2 align-bottom text-caption font-medium text-ink-secondary";return n.jsxs("table",{"data-part":"table",className:"mt-3 w-full table-fixed border-collapse text-left",children:[n.jsxs("colgroup",{children:[n.jsx("col",{className:"w-28"}),at.map(s=>n.jsx("col",{},s))]}),n.jsx("thead",{children:n.jsxs("tr",{className:"border-b border-hairline",children:[n.jsx("th",{scope:"col",className:t,children:"Agent"}),at.map(s=>n.jsx("th",{scope:"col",className:t,children:$a[s]},s))]})}),n.jsx("tbody",{children:e.map(s=>n.jsxs("tr",{"data-source":s.source,"data-agent":s.agent,className:"border-b border-hairline last:border-b-0",children:[n.jsx("th",{scope:"row",className:"py-2.5 pr-2 text-body font-semibold text-ink",children:s.label}),at.map(o=>n.jsx("td",{className:"py-2.5 pr-2 text-body",children:n.jsx(kk,{cell:s.capabilities[o]})},o))]},s.key))})]})}function Nk(e,t){return e.level==="yes"||t.level==="yes"?e.level===t.level:e.level===t.level&&e.reason===t.reason}const vk=["jump","stop","answer"];function Sk(e,t){if(e.agent===void 0)return null;const s=t.find(r=>r.agent===void 0&&r.label===e.agent);return s&&at.every(r=>vk.includes(r)||Nk(s.capabilities[r],e.capabilities[r]))?s:null}function Ak({rows:e}){return n.jsx("div",{"data-part":"blocks",className:"mt-3 flex flex-col gap-4",children:e.map(t=>{const s=Sk(t,e);return s?n.jsxs("div",{"data-source":t.source,"data-agent":t.agent,children:[n.jsx("h3",{className:"text-row font-semibold text-ink",children:t.label}),n.jsxs("p",{"data-part":"same-as",className:"mt-1 text-body text-ink-secondary",children:["As ",s.label," on this computer, but"," ",n.jsxs("span",{className:"font-medium text-ink",children:["Jump: ",nt[t.capabilities.jump.level]]}),","," ",n.jsxs("span",{className:"font-medium text-ink",children:["Stop: ",nt[t.capabilities.stop.level]]})," ","and"," ",n.jsxs("span",{className:"font-medium text-ink",children:["Answer: ",nt[t.capabilities.answer.level]]}),", which act on this computer only."]})]},t.key):n.jsxs("div",{"data-source":t.source,"data-agent":t.agent,children:[n.jsx("h3",{className:"text-row font-semibold text-ink",children:t.label}),n.jsx(De,{className:"mt-1",children:at.map(o=>{const r=t.capabilities[o];return n.jsx(te,{label:$a[o],note:r.level==="yes"?void 0:r.reason,children:n.jsx("span",{"data-part":"capability","data-level":r.level,className:r.level==="yes"?"font-normal text-ink-secondary":void 0,children:nt[r.level]})},o)})})]},t.key)})})}function Ek({sources:e}){const t=Yn(),s=yk(e);return s.length===0?null:n.jsx(q,{"data-slot":"capabilities",title:"What each agent can report",children:n.jsxs("div",{className:"px-6 pb-3",children:[n.jsxs("p",{"data-part":"lead",className:"text-body text-ink-secondary",children:["A signal marked No never appears for that agent, so not seeing it is not good news.",!t&&" Point at No or Partly, or move to it with Tab, to read why."]}),t?n.jsx(Ak,{rows:s}):n.jsx(jk,{rows:s})]})})}function Tk(e){return e.includes("/")||e.startsWith("~")||/^[A-Za-z]:\\/.test(e)||/ --?\w/.test(e)}function Mk(e){return/^\d+$/.test(e)}function Ck({source:e,sessions:t,now:s,stalled:o}){const r=cm(e,o),a=t.filter(i=>i.source===e.id).length;return n.jsx(q,{"data-slot":"source","data-state":e.state,"data-stalled":o,title:e.label,aside:n.jsx("span",{"data-part":"state",className:"text-body font-medium text-ink-secondary",children:r.state}),children:n.jsxs("div",{className:"px-6 pb-3",children:[e.detail&&n.jsx("p",{"data-part":"detail",className:"text-body wrap-break-word text-ink-secondary",children:n.jsx(B,{children:e.detail})}),e.advice&&n.jsx("p",{"data-part":"advice",className:A("text-body wrap-break-word text-ink-secondary",e.detail&&"mt-2"),children:n.jsx(B,{children:e.advice})}),n.jsxs(De,{className:"mt-2",children:[e.watching?.map((i,l)=>Tk(i.value)?n.jsx(te,{label:i.label,mono:!0,children:n.jsx(Me,{"data-part":"watching",children:i.value})},`${l}-${i.label}`):n.jsx(te,{label:i.label,children:n.jsx("span",{"data-part":"watching",className:A("wrap-anywhere",Mk(i.value)&&"tabular-nums"),children:i.value})},`${l}-${i.label}`)),n.jsx(te,{label:"Sessions found",children:n.jsx("span",{className:"tabular-nums",children:a})}),n.jsx(te,{label:"Last checked",children:o?n.jsx("span",{className:"tabular-nums",children:xe(e.checkedAt)}):n.jsx(ee,{content:Fn(e.checkedAt),mono:!0,align:"end",children:n.jsx("span",{className:"tabular-nums",children:oo(s-e.checkedAt)})})})]})]})})}function Gr({children:e}){return n.jsx(q,{title:"Sources",children:n.jsx("div",{className:"px-6 pb-6",children:e})})}const Ik="Another machine is one named in AGENT_LOOKOUT_REMOTES, with Agent Lookout running there. It is read over SSH, with your own ssh, and asked for its sessions and nothing else. Its sessions carry its name, and Jump, Stop, Allow and Deny act on this computer only.";function Ok({state:e,now:t}){const{snapshot:s,phase:o}=e,r=o==="stalled",a=s?.sources.some(l=>ge(l.id))??!1;let i;return s?i=s.sources.length>0?s.sources.map(l=>n.jsx(Ck,{source:l,sessions:s.sessions,now:t,stalled:r},l.id)):n.jsx(Gr,{children:n.jsx(F,{title:"No sources are set up",children:n.jsx("p",{children:"Agent Lookout is running but is not watching any agent tool."})})}):o==="unreachable"?i=n.jsx(Gr,{children:n.jsx(F,{tone:"error",title:bi(e.problemKind),children:n.jsx(yi,{kind:e.problemKind})})}):i=n.jsx(q,{title:"Sources",children:n.jsx(ve,{label:"Waiting for the first answer"})}),n.jsxs("div",{"data-slot":"sources-view",className:"grid grid-cols-3 items-start gap-4 max-wide:flex max-wide:flex-col",children:[n.jsxs("div",{className:"col-span-2 flex min-w-0 flex-col gap-4 max-wide:w-full",children:[r&&e.lastOkAt!==null&&n.jsx(F,{tone:"error",title:"Agent Lookout has stopped updating",children:n.jsxs("p",{children:["What follows is from"," ",n.jsx("span",{className:"tabular-nums",children:xe(e.lastOkAt)}),". Check that it is still running in your terminal."]})}),i,s&&n.jsx(Ek,{sources:s.sources})]}),n.jsx(q,{title:"About sources",className:"col-span-1 max-wide:w-full",children:n.jsxs("div",{className:"flex flex-col gap-2 px-6 pb-6 text-body text-ink-secondary",children:[n.jsx("p",{children:"A source is an agent tool Agent Lookout finds sessions in. It reads its files and never writes to them. Agent Lookout stops a Claude Code session only when you press Stop and confirm."}),n.jsx("p",{children:"Status files are how any other agent appears: it writes a small file for each of its sessions in a folder that Agent Lookout reads."}),n.jsx("p",{children:"By default Agent Lookout itself sends nothing anywhere. Email, a webhook, pushes through ntfy or Pushover, pull requests through your own gh and other machines through your own ssh are off until you set them up. The Mac app asks GitHub about once a day whether a newer version is out, unless you turn that off in its Settings. A command listed under a source is that tool's own program, and may reach the tool's own servers, as it does whenever it runs."}),a&&n.jsx("p",{"data-part":"machines",children:n.jsx(B,{children:Ik})})]})})]})}class Vl extends p.Component{state={error:null};static getDerivedStateFromError(t){return{error:t instanceof Error?t:new Error(String(t))}}componentDidCatch(t,s){console.error("Agent Lookout could not draw the page.",t,s.componentStack)}render(){const{error:t}=this.state;return t?n.jsxs("section",{"data-slot":"page-error","aria-label":"Page problem",className:"glass-card mx-auto mt-[6vh] w-full max-w-[620px] p-5",children:[n.jsx(F,{tone:"error",title:"Agent Lookout could not draw this page",action:n.jsx(D,{onClick:()=>this.setState({error:null}),children:"Try again"}),children:n.jsx("p",{children:"Something in the page itself went wrong. Your sessions are not affected: the page changes nothing in them unless you press Stop and confirm. If trying again does not help, reload the page."})}),n.jsx(De,{className:"mt-3",children:n.jsx(te,{label:"What happened",mono:!0,children:t.message||t.name})})]}):this.props.children}}function _k(e){return p.useSyncExternalStore(e.subscribe,e.getState)}function Rk(e){return document.addEventListener("visibilitychange",e),()=>document.removeEventListener("visibilitychange",e)}function Lk(){return document.hidden}function Yl(){return p.useSyncExternalStore(Rk,Lk)}const ys="Agent Lookout";function $k(e){p.useEffect(()=>(document.title=e>0?`(${e}) ${ys}`:ys,()=>{document.title=ys}),[e])}const Xl="agent-lookout-last-looked";function Wk(){try{const e=Number(localStorage.getItem(Xl));return Number.isSafeInteger(e)&&e>0?e:null}catch{return null}}function Pk(e){try{localStorage.setItem(Xl,String(e))}catch{}}function Dk(e,t,s){const o=Yl(),r=Zt(),[a,i]=p.useState(!1),[l,d]=p.useState(()=>qm(Wk())),c=Gm(l,{now:r,visible:!o&&s,overview:t,lineInView:a,newestAt:e[0]?.at??null});c!==l&&d(c);const u=p.useRef(c);return p.useEffect(()=>{u.current=c}),p.useEffect(()=>{const f=()=>{const{away:w,overview:x,leftAt:g,since:h}=u.current,j=h??(!w&&x?Date.now():g);j!==null&&Pk(j)},m=()=>{document.hidden&&f()};return document.addEventListener("visibilitychange",m),window.addEventListener("pagehide",f),()=>{document.removeEventListener("visibilitychange",m),window.removeEventListener("pagehide",f)}},[]),{since:c.since,onLineInView:i}}function Uk(e){const t=p.useEffectEvent(s=>{if(s.defaultPrevented||s.repeat||s.isComposing)return;const o=$w(s.target),r=Pw(s,{mac:yo(),typing:o});r!==null&&e(r)&&s.preventDefault()});p.useEffect(()=>{const s=o=>t(o);return document.addEventListener("keydown",s),()=>document.removeEventListener("keydown",s)},[])}function Jl(e){return window.addEventListener("hashchange",e),()=>window.removeEventListener("hashchange",e)}function Fk(){return cb(window.location.hash)}function Hk(){return Hi(window.location.hash)}function zk(){return p.useSyncExternalStore(Jl,Fk)}function Bk(){return p.useSyncExternalStore(Jl,Hk)}const qk="agent-lookout-notifications";function Gk(e){if(typeof e!="object"||e===null)return[];const{handedOver:t}=e;return Array.isArray(t)?t.filter(s=>typeof s=="string"):[]}function Kk(e){let t;try{t=new BroadcastChannel(qk),t.addEventListener("message",s=>{const o=Gk(s.data);o.length>0&&e(o)})}catch{t=null}return{handOver(s){if(!t||s.length===0)return;const o={handedOver:[...s]};try{t.postMessage(o)}catch{}},close(){t?.close(),t=null}}}function Vk(){let e=null,t=[],s=[];const o=a=>t.find(i=>i.session.id===a&&i.endedAt===null),r=a=>{for(let i=t.length-1;i>=0;i-=1){const l=t[i];if(l.session.id===a)return l}};return{holding:()=>e!==null,begin(a){e??=a},holdWait(a,i){const l=r(a.id);if(l?.begunAt===i){l.endedAt=null,l.reminderOnly=!1;return}l&&l.endedAt===null&&(l.endedAt=i),t.push({session:Mt(a),begunAt:i,endedAt:null,reminderOnly:!1})},holdReminder(a,i){const l=r(a.id);if(l?.begunAt===i){l.endedAt=null;return}l&&l.endedAt===null&&(l.endedAt=i),t.push({session:Mt(a),begunAt:i,endedAt:null,reminderOnly:!0})},holdOver(a,i,l){s.push({event:a,session:Mt(i),at:l})},waitEnded(a,i){const l=o(a);l&&(l.endedAt=i)},holdsWait:a=>o(a)!==void 0,end(a,i,l){const d=new Map(a.sessions.map(h=>[h.id,h])),c=new Map;for(const h of t){const j=d.get(h.session.id);j===void 0||!fe(j)||(h.endedAt===null||j.statusSince===h.begunAt)&&c.set(h.session.id,h)}const u=[];for(const[h,j]of c)j.reminderOnly||u.push({session:d.get(h),begunAt:j.begunAt});const f=new Map,m=new Map;for(const h of t){if(c.get(h.session.id)?.begunAt===h.begunAt||l)continue;const j=Math.max(0,(h.endedAt??i)-h.begunAt);m.set(h.session.id,h.begunAt);const y=f.get(h.session.id);y?(y.waitedMs+=j,y.times+=1):f.set(h.session.id,{event:"needs-you",session:h.session,at:h.begunAt,waitedMs:j,times:1})}const w=[];for(const h of s){const j=f.get(h.session.id),y=m.get(h.session.id);j&&j.then===void 0&&y!==void 0&&h.at>=y?j.then={event:h.event,at:h.at}:w.push(h)}const x=[...f.values(),...w].sort((h,j)=>h.at-j.at),g=e??i;return e=null,t=[],s=[],{summary:x.length>0?{from:g,to:i,items:x}:null,open:u}}}}const Kr=["sun","mon","tue","wed","thu","fri","sat"];function Yk(e,t){if(!e.on)return!1;const s=Wt(e.from),o=Wt(e.to);if(s===null||o===null||s===o)return!1;const r=new Date(t),a=r.getHours()*60+r.getMinutes(),i=Kr[r.getDay()];if(s<o)return a>=s&&a<o&&e.days.includes(i);if(a>=s)return e.days.includes(i);if(a<o){const l=Kr[(r.getDay()+6)%7];return e.days.includes(l)}return!1}function Xk(e){return e.quiet??Yk(sa(e).quietHours,e.generatedAt)}const Vr=6e4;function Jk(e){return{thresholdMs:e.minutes*Vr,everyMs:e.repeat?.on?e.repeat.minutes*Vr:null}}function ks(e,t){return e<t.thresholdMs?-1:t.everyMs===null?0:Math.floor((e-t.thresholdMs)/t.everyMs)}function Qk(e){return new Set(e.sources.filter(t=>t.state==="ok"||t.state==="not-set-up").map(t=>t.id))}function Zk(){const e=new Map;return{observe(t,s,o){for(const a of s)e.delete(a);const r=Qk(t);for(const a of t.sessions){if(!fe(a)||!r.has(a.source))continue;const i=a.statusSince!==null&&a.statusSince<=o?a.statusSince:null,l=e.get(a.id);l&&(i===null||i===l.begunAt)||e.set(a.id,{begunAt:i??o,seenAfterMs:i===null?0:o-i,toldAfterMs:null})}},due(t,s,o,r=()=>!0){const a=[];for(const i of t.sessions){if(!fe(i))continue;const l=e.get(i.id);if(!l||!r(i.id))continue;const d=s-l.begunAt,c=ks(d,o);if(c<0||c<=ks(l.seenAfterMs,o))continue;const u=l.toldAfterMs;if(u!==null&&c<=ks(u,o))continue;const{thresholdMs:f,everyMs:m}=o;u!==null&&m!==null&&c>0&&f+c*m-u<m/2||a.push({session:i,begunAt:l.begunAt,waitedMs:d,repeat:c})}return a},told(t,s){const o=e.get(t);o&&(o.toldAfterMs=Math.max(o.toldAfterMs??0,s-o.begunAt))},clear(){e.clear()}}}const ej=6e4;function Ql(e){return e<ej?"under a minute":no(xt(e).filter(t=>t.unit!=="s"))}const tj={permission:"for permission",question:"for an answer",other:"for you"};function nj(e,t){return`has waited ${Ql(t)} ${tj[e.waitingReason??"other"]}`}function sj(e,t){const s=nj(e,t),o=`${s.charAt(0).toUpperCase()}${s.slice(1)}`,r=e.waitingText?.trim();return{title:Bn(e),body:r?`${o}: ${r}`:o}}const oj="While quiet";function rj(e){const t=Ql(e.waitedMs);return e.times===1?`waited ${t}`:`waited ${t} over ${e.times} waits`}function aj(e,t=co){const s=gf(t(e.session));if(e.event!=="needs-you")return`${s} ${lr(e.event)}`;const o=`${s} ${rj(e)}`;return e.then?`${o} then ${lr(e.then.event)}`:o}function ij(e,t=4,s=co){const o=e.slice(0,t).map(a=>aj(a,s)),r=e.length-o.length;return r===0?o.length<=1?o[0]??"":`${o.slice(0,-1).join(", ")} and ${o[o.length-1]}`:`${o.join(", ")} and ${r} more`}function lj(e){return{title:oj,body:ij(e,void 0,Bn)}}const cj="agent-lookout:while-quiet";function dj(e){return`agent-lookout:${e.id}`}function js(e){try{e.close()}catch{}}function uj({host:e,isOn:t}){let s=Ho,o=null,r=null;const a=new Map,i=new Map,l=Zk(),d=Vk();let c=!1;function u(x){const g=a.get(x);g&&(a.delete(x),js(g.notification))}function f(x,g=sp(x)){const{session:h}=x;u(h.id);const j=i.get(h.id);j&&(i.delete(h.id),js(j));let y;try{y=e.show({...g,tag:dj(h)})}catch{y=null}if(!y)return;const k=y;if(x.event!=="needs-you"){i.set(h.id,k),k.onClosed(()=>{i.get(h.id)===k&&i.delete(h.id)});return}a.set(h.id,{notification:k,source:h.source}),k.onClosed(()=>{a.get(h.id)?.notification===k&&a.delete(h.id)})}function m(x){try{e.show({...x,tag:cj})}catch{}}function w(x,g){const{event:h,session:j}=x;if(h==="needs-you"){const y=j.statusSince;d.holdWait(j,y!==null&&y<=g?y:g)}else d.holdOver(h,Mt(j),g)}return{handle(x,g=null){if(!x)return;r=x,g!==null&&(o!==null&&o!==g&&(s=Ho,l.clear()),o=g);const h=x.generatedAt,j=sa(x),y=Xk(x);c=y;const k=Jk(j.longWait),N=pu(s,x);s=N.memory;for(const E of N.stopped)u(E),d.waitEnded(E,h);l.observe(x,N.stopped,h);for(const[E,{source:S}]of a){const v=s.waits.get(S);v&&!v.has(E)&&u(E)}if(d.holding()&&!y){const E=d.end(x,h,j.quietHours.leaveOutAnswered),S=E.summary?.items.filter(v=>t(v.event))??[];if(S.length>0&&m(lj(S)),t("needs-you"))for(const{session:v}of E.open)f({event:"needs-you",session:v}),j.longWait.on&&l.told(v.id,h)}y&&d.begin(h);for(const E of N.changes)t(E.event)&&(y?w(E,h):f(E));if(j.longWait.on&&t("needs-you"))for(const E of l.due(x,h,k)){if(y){d.holdReminder(E.session,E.begunAt);continue}l.told(E.session.id,h),f({event:"needs-you",session:E.session},sj(E.session,E.waitedMs))}},closeAll(){const x=[...a.keys()],g=[...a.values()];a.clear();for(const{notification:h}of g)js(h);return x},showAgain(x){if(!r||c)return;const g=new Set(x);for(const h of r.sessions)!g.has(h.id)||!fe(h)||s.waits.get(h.source)?.has(h.id)&&(g.delete(h.id),t("needs-you")&&f({event:"needs-you",session:h}))}}}const Ns=e=>Zs().includes(e),Yr=()=>Pa(Zs());async function fj(){try{await Y("/api/health",{keepalive:!0})}catch{}}function hj(e){p.useEffect(()=>{const t=uj({host:{show:c=>Xs().show(c)},isOn:Ns}),s=()=>{const{snapshot:c,history:u}=e.getState();t.handle(c,u?.startedAt??null)};s();const o=e.subscribe(s);let r=Yr(),a=Ns("needs-you");const i=Ba(()=>{const c=Yr();c!==r&&fj(),r=c;const u=Ns("needs-you");a&&!u&&t.closeAll(),a=u}),l=Kk(c=>t.showAgain(c)),d=()=>l.handOver(t.closeAll());return window.addEventListener("pagehide",d),()=>{o(),i(),window.removeEventListener("pagehide",d),d(),l.close()}},[e])}const mj=p.lazy(()=>ta(()=>import("./HistoryPanel-C5-cd24R.js"),__vite__mapDeps([0,1,2,3])).then(e=>({default:e.HistoryPanel}))),pj=p.lazy(()=>ta(()=>import("./SessionPanel-CO5qG2uH.js"),__vite__mapDeps([4,1,2,3])).then(e=>({default:e.SessionPanel})));function xj({children:e}){return n.jsx(sc,{features:oc,children:n.jsx(rc,{reducedMotion:"user",children:e})})}const gj=["needsYou","working","idle"];function wj(){const e=Yl(),t=(s,o)=>n.jsxs("div",{"aria-hidden":!0,"data-slot":s,"data-drift":e?"paused":void 0,className:o,children:[n.jsx("i",{className:"ground-main"}),n.jsx("i",{className:"ground-deep"}),n.jsx("i",{className:"ground-far"})]});return n.jsxs(n.Fragment,{children:[t("ground","ground"),t("ground-above","ground bottom-auto z-10 h-window bg-fixed")]})}function bj({store:e}){const[t]=p.useState(()=>e??qh({beat:Qu})),s=_k(t);hj(t);const o=Zt(),r=zk(),a=Bk(),[i,l]=p.useState(null),[d,c]=p.useState(!1),[u,f]=p.useState(!1),m=p.useRef(null),w=p.useRef(r),x=Dk(s.events,r==="overview",s.snapshot!==null),g=gp(s.snapshot?.sessions);$k(g);const h=s.snapshot?g:null;p.useEffect(()=>{w.current!==r&&(w.current=r,m.current?.focus({preventScroll:!0}),window.scrollTo({top:0}))},[r]);const j=Nw(m,r);Uk(k=>{if(i!==null||u||a!==null)return!1;if(k==="search")c(N=>!N);else{if(d)return!1;f(!0)}return!0});const y=s.snapshot?"dashboard":s.phase==="unreachable"?"problem":"loading";return n.jsxs(xj,{children:[n.jsx(wj,{}),n.jsxs("div",{"data-slot":"frame",className:"flex min-h-screen gap-window p-window",children:[n.jsx(hb,{current:r,needsYou:h}),n.jsxs("div",{className:"flex min-w-0 flex-1 flex-col gap-4 pb-7",children:[n.jsx(Hw,{phase:s.phase,snapshot:s.snapshot,lastOkAt:s.lastOkAt,now:o,onSearch:()=>c(!0)}),n.jsx("main",{ref:m,tabIndex:-1,"aria-label":db(r),"data-view":r,className:"flex-1 outline-none",children:n.jsx(Vl,{children:r==="sources"?n.jsx(Ok,{state:s,now:o}):r==="settings"?n.jsx(bk,{history:s.history,now:o,onHistoryCleared:t.refresh,onTimeRulesChanged:t.refresh,snapshot:s.snapshot,answering:s.snapshot?.answering??null}):n.jsx(tc,{mode:"wait",initial:!1,children:n.jsx(nc.div,{initial:{opacity:0},animate:{opacity:1},exit:{opacity:0},transition:{duration:.18,ease:"easeOut"},children:n.jsx(vw,{state:s,now:o,onRetry:t.refresh,onEnded:t.refresh,onAnswered:t.refresh,onOpenHistory:l,newSince:x.since,onNewLineInView:x.onLineInView})},y)})},r)})]})]}),n.jsxs(p.Suspense,{fallback:null,children:[gj.map(k=>n.jsx(mj,{metric:k,open:i===k,onOpenChange:N=>l(N?k:null),state:s,now:o},k)),n.jsx(pj,{sessionId:a,onClose:nx,state:s,now:o,onStopped:t.refresh,onAnswered:t.refresh})]}),n.jsx(Xw,{open:d,onOpenChange:c,state:s,now:o,onChoose:j,onShortcuts:()=>f(!0)}),n.jsx(nb,{open:u,onOpenChange:f})]})}Tm();const Zl=document.getElementById("root");if(!Zl)throw new Error("index.html has no #root element to render into.");ec.createRoot(Zl).render(n.jsx(p.StrictMode,{children:n.jsx(Vl,{children:n.jsx(bj,{})})}));export{rl as $,Ri as A,Gn as B,F as C,Qw as D,fe as E,te as F,Rj as G,tr as H,tl as I,Ht as J,qt as K,ve as L,Un as M,Um as N,Fm as O,Oi as P,De as Q,Cj as R,pe as S,ae as T,ro as U,ui as V,_j as W,Mj as X,Qg as Y,qn as Z,Xt as _,xe as a,tm as a0,Ai as a1,Dx as a2,re as a3,dp as a4,ao as a5,Ee as a6,Q as a7,Ap as a8,D as a9,Ej as b,A as c,ef as d,Sj as e,ne as f,vj as g,Se as h,Vt as i,gp as j,$e as k,In as l,nf as m,Tc as n,Me as o,Ij as p,Oj as q,Tj as r,Nj as s,Ka as t,Aj as u,Yl as v,Mt as w,Kn as x,ll as y,Lj as z};