@gbasin/agentboard-linux-x64 0.43.3 → 0.43.4
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.
|
@@ -308,4 +308,4 @@ ${s.join(`
|
|
|
308
308
|
`),[m]),g=u?.cols??0,_=(0,y.useMemo)(()=>a&&g>0?Q2(h,g):[],[h,g,a]),v=(0,y.useMemo)(()=>A2(h,_),[h,_]),b=(0,y.useRef)({selected:!1,started:0,x:0,y:0,moved:!1}),x=(0,y.useRef)({lines:h,joins:_,onCopied:o});x.current={lines:h,joins:_,onCopied:o},(0,y.useEffect)(()=>{let e=s.current;if(!e)return;let t=e=>e.stopPropagation();for(let n of t4)e.addEventListener(n,t,{passive:!0});return()=>{for(let n of t4)e.removeEventListener(n,t)}},[]),(0,y.useEffect)(()=>{if(typeof document>`u`)return;let e=e=>{let t=l.current,{lines:n,joins:r,onCopied:i}=x.current;t&&H2(e,window.getSelection(),t,n,r,i)};return document.addEventListener(`copy`,e,!0),()=>document.removeEventListener(`copy`,e,!0)},[]),(0,y.useEffect)(()=>{let e=n.current;if(!e)return;let t=e.options.disableStdin??!1;return e.options.disableStdin=!0,()=>{e.options.disableStdin=t}},[n]),(0,y.useLayoutEffect)(()=>{let e=t.current;if(!e)return;let r=()=>{let t=n.current;t&&d($2(e,t))};r();let i=typeof ResizeObserver>`u`?null:new ResizeObserver(r);return i?.observe(e),()=>i?.disconnect()},[t,n]),(0,y.useLayoutEffect)(()=>{l.current&&u&&p(e4(l.current,u.cellWidth))},[u,m]),(0,y.useLayoutEffect)(()=>{let e=typeof window>`u`?null:window.getSelection?.(),t=s.current;!e||!t||e.rangeCount===0||e.anchorNode&&t.contains(e.anchorNode)&&e.removeAllRanges()},[m]);let S=e.status===`ready`?e.scrollPosition:0;return(0,y.useLayoutEffect)(()=>{let e=c.current;!e||!u||m===null||(e.scrollTop=e.scrollHeight-e.clientHeight-S*u.cellHeight)},[u,m,S,f]),(0,k.jsxs)(`div`,{ref:s,"data-testid":`terminal-snapshot-layer`,className:`absolute inset-0 z-[45]`,style:{backgroundColor:r},children:[e.status===`ready`&&u&&(0,k.jsx)(`div`,{ref:c,"data-testid":`terminal-snapshot-scroller`,className:`absolute overflow-y-auto overflow-x-hidden`,style:{left:u.left,top:u.top,width:u.width,height:u.height,overscrollBehavior:`contain`,WebkitOverflowScrolling:`touch`},children:(0,k.jsx)(`div`,{ref:l,"data-testid":`terminal-snapshot-text`,onPointerDownCapture:e=>{b.current={selected:window.getSelection()?.isCollapsed===!1,started:Date.now(),x:e.clientX,y:e.clientY,moved:!1}},onPointerMoveCapture:e=>{Math.hypot(e.clientX-b.current.x,e.clientY-b.current.y)>8&&(b.current.moved=!0)},onClickCapture:e=>{if(!(e.target instanceof Element)||!e.target.closest(`a`))return;let t=b.current;(window.getSelection()?.isCollapsed===!1||e.detail!==0&&(t.selected||t.moved||Date.now()-t.started>500))&&e.preventDefault()},style:{width:u.width+u.cellWidth/2,margin:0,color:i,fontFamily:u.fontFamily,fontSize:u.fontSize,lineHeight:`${u.cellHeight}px`,letterSpacing:f,fontKerning:`none`,fontVariantLigatures:`none`,WebkitUserSelect:`text`,userSelect:`text`,WebkitTouchCallout:`default`,WebkitTextSizeAdjust:`100%`},children:h.map((e,t)=>(0,k.jsx)(`div`,{"data-snapshot-line":t,style:[...e].length>u.cols?{whiteSpace:`break-spaces`,wordBreak:`break-all`,lineBreak:`anywhere`}:{whiteSpace:`pre`,overflow:`hidden`},children:e===``?(0,k.jsx)(`br`,{}):(()=>{let n=0;return[...v[t].flatMap(t=>{let r=e.slice(n,t.start);return n=t.end,[r,(0,k.jsx)(`a`,{href:t.href,target:`_blank`,rel:`noopener noreferrer`,className:`underline decoration-current underline-offset-2 hover:decoration-2 focus-visible:outline focus-visible:outline-2`,style:{color:`inherit`},draggable:!1,children:e.slice(t.start,t.end)},t.start)]}),e.slice(n)]})()},t))})}),e.status!==`ready`&&(0,k.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center gap-2 text-sm text-muted`,children:e.status===`loading`?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(pt,{width:K.pill,height:K.pill,className:`animate-spin`}),` Capturing text`]}):`Could not capture the pane text`})]})}function r4({sessionId:e,sendMessage:t,subscribe:n}){let[r,i]=(0,y.useState)({status:`closed`}),a=(0,y.useRef)(0);(0,y.useEffect)(()=>{a.current+=1,i({status:`closed`})},[e]);let o=r.status===`loading`||r.status===`ready`&&r.refreshing;(0,y.useEffect)(()=>o?n(t=>{if(t.type===`terminal-snapshot`&&!(t.sessionId!==e||t.requestId!==a.current)){if(!t.ok||typeof t.text!=`string`){i({status:`error`});return}i({status:`ready`,text:t.text,scrollPosition:t.scrollPosition??0,historyLines:t.historyLines??0,captureMs:t.captureMs??0,altScreen:t.altScreen??!1,refreshing:!1})}}):void 0,[o,e,n]);let s=(0,y.useRef)(null),c=()=>{s.current!==null&&clearTimeout(s.current),s.current=null};(0,y.useEffect)(()=>c,[e]);let l=(0,y.useCallback)((n,r=0)=>{if(!e)return;c();let o=++a.current,l=()=>{s.current=null,o===a.current&&t({type:`terminal-snapshot-request`,sessionId:e,requestId:o})===!1&&i({status:`error`})};i(e=>n&&e.status===`ready`?{...e,refreshing:!0}:{status:`loading`}),r>0?s.current=setTimeout(l,r):l()},[e,t]);return{state:r,open:(0,y.useCallback)((e=0)=>l(!1,e),[l]),refresh:(0,y.useCallback)(()=>l(!0),[l]),close:(0,y.useCallback)(()=>{c(),a.current+=1,i({status:`closed`})},[])}}function i4(e,t){return(0,y.useCallback)(()=>{let n=typeof document>`u`?null:document.activeElement,r=!!n?.classList?.contains(`xterm-helper-textarea`);n?.blur?.(),t.current?.(),e(r?600:0)},[e,t])}function a4(e,t){return e.status===`ready`&&e.altScreen||!!t}async function o4(e,t){let n=e.body?.getReader();if(!n)throw Error(`Empty media response.`);let r=e.headers.get(`content-type`)?.includes(`application/x-ndjson`),i=new TextDecoder(`utf-8`,{fatal:!0}),a=0,o=0,s=``,c=!1,l=e=>{if(!e.trim())return;if(c)throw Error(`Unexpected data after media completion.`);let n=JSON.parse(e);if(!n||![`snapshot`,`progress`,`error`,`done`].includes(n.type))throw Error(`Invalid media response.`);t(n),n.type===`done`&&(c=!0)};try{for(;;){let{value:e,done:t}=await n.read();if(t)break;if(a+=e.byteLength,a>(r?524288:65536))throw Error(`Media response exceeded its size limit.`);let c=0;for(let t=0;t<e.length;t++)if(!(!r||e[t]!==10)){if(o+=t-c,o>65536)throw Error(`Media frame exceeded its size limit.`);s+=i.decode(e.subarray(c,t),{stream:!0})+i.decode(),l(s),s=``,o=0,c=t+1}if(o+=e.length-c,o>65536)throw Error(`Media frame exceeded its size limit.`);s+=i.decode(e.subarray(c),{stream:!0})}if(s+=i.decode(),r){if(s.trim()&&l(s),!c)throw Error(`Media discovery was interrupted. Retry to continue.`)}else{let e=JSON.parse(s);t({type:`snapshot`,page:{...e,discovery:e.discovery??{status:`ready`}}}),t({type:`done`})}}finally{await n.cancel().catch(()=>{}),n.releaseLock()}}var s4=3,c4=128,l4=64*1024,u4=()=>({pages:[],status:`idle`,error:null,requestedRevision:null,scrollShift:0});function d4(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.status===`pending`||t.status===`ready`?!0:t.status===`failed`?typeof t.message==`string`:t.status===`indexing`&&[t.bytesRead,t.bytesTotal,t.filesDone,t.filesTotal].every(e=>Number.isFinite(e)&&e>=0)}function f4(e,t){if(!e||typeof e!=`object`)return!1;let n=e;return typeof n.identity==`string`&&(!t||n.identity===t)&&typeof n.revision==`string`&&Number.isSafeInteger(n.total)&&n.total>=0&&(n.nextCursor===null||typeof n.nextCursor==`string`&&n.nextCursor.length<=8192)&&Array.isArray(n.items)&&n.items.length<=40&&n.items.every(e=>e&&[`image`,`document`,`link`,`html`,`localhost`,`visualization`].includes(e.kind)&&typeof e.url==`string`)}function p4(e,t,n,r,i={}){let[a,o]=(0,y.useState)(u4),[s,c]=(0,y.useState)(()=>typeof document>`u`||document.visibilityState!==`hidden`),l=(0,y.useRef)(a);l.current=a;let u=(0,y.useRef)(t);u.current=t;let d=(0,y.useRef)(null),f=(0,y.useRef)(0),p=(0,y.useRef)(0),m=(0,y.useRef)(new Map),h=t?.identity,g=i.kind,_=i.search,v=JSON.stringify([g,_]),b=(0,y.useRef)(v);b.current=v;let x=(0,y.useCallback)(()=>{f.current++,d.current?.controller.abort(),d.current=null},[]);(0,y.useEffect)(()=>{let e=()=>{x(),c(!1),o(e=>e.status===`loading`||e.status===`streaming`?{...e,status:`idle`}:e)},t=()=>c(document.visibilityState!==`hidden`),n=()=>document.visibilityState===`hidden`?e():t();return document.addEventListener(`visibilitychange`,n),window.addEventListener(`pagehide`,e),window.addEventListener(`pageshow`,t),()=>{document.removeEventListener(`visibilitychange`,n),window.removeEventListener(`pagehide`,e),window.removeEventListener(`pageshow`,t),x()}},[x]),(0,y.useEffect)(()=>{x(),m.current.clear(),p.current=0,o(u4())},[e,v,x]),(0,y.useEffect)(()=>{let e=l.current.pages[0]?.page.identity;h&&e&&h!==e&&(x(),m.current.clear(),o(u4()))},[h,x]),(0,y.useEffect)(()=>{n||(p.current=0),!(n&&r&&s)&&(x(),o(e=>e.status===`loading`||e.status===`streaming`?{...e,status:`idle`}:e))},[n,r,s,x]);let S=(0,y.useCallback)(async(t,i=!1)=>{let a=u.current;if(!n||!r||!s||!e)return;d.current&&x();let c=l.current,h=c.pages[0],y=c.pages.at(-1),S=t===`first`?0:t===`next`?(y?.number??-1)+1:(h?.number??1)-1,C=t===`first`?null:t===`next`?y?.page.nextCursor:m.current.get(S);if(t!==`first`&&(C===void 0||t===`next`&&C===null))return;let w=new AbortController,T=++f.current;d.current={controller:w,token:T},o(e=>({...e,status:`loading`,error:null,latestSummary:t===`first`?void 0:e.latestSummary}));let E=setTimeout(()=>w.abort(`timeout`),Wh+5e3);try{let n=new URLSearchParams;n.set(`stream`,`1`),C&&n.set(`cursor`,C),g&&n.set(`kind`,g),_&&n.set(`search`,_);let r=n.size?`?${n}`:``,s=await fetch(`/api/session-media/${encodeURIComponent(e)}/items${r}`,{signal:w.signal,cache:`no-store`});if(!s.ok)throw Error(s.status===409?`Media changed. Refresh to continue.`:`Could not load media. Try again.`);let l=i&&c.pages.some(e=>e.page.items.length>0),u=!1,y,x=a?.identity??h?.page.identity,E=()=>d.current?.token===T&&f.current===T&&b.current===v&&!w.signal.aborted;if(await o4(s,e=>{if(!E())return;if(e.type===`error`)throw Error(typeof e.message==`string`?e.message:`Could not load media.`);if(e.type===`done`)return;if(e.type===`progress`){let t=e.summary;if(!t||t.identity!==x||typeof t.revision!=`string`||![t.total,t.images,t.documents,t.links,t.additions].every(e=>Number.isSafeInteger(e)&&e>=0)||!d4(t.discovery))throw Error(`Invalid discovery progress.`);y=t.discovery,o(e=>({...e,discovery:y,latestSummary:t}));return}let n=e.page;if(!f4(n,x)||!d4(n.discovery))throw Error(`Media identity changed. Refresh to continue.`);if(y=n.discovery,x=n.identity,u=!0,l){o(e=>({...e,discovery:y,status:`streaming`}));return}if(t!==`first`&&n.revision!==h?.page.revision)throw Error(`Media changed. Refresh to continue.`);for(l=n.items.length>0,m.current.set(S,C??null),n.nextCursor&&m.current.set(S+1,n.nextCursor);m.current.size>c4||[...m.current.values()].reduce((e,t)=>e+(t?.length??0)*2,0)>l4;)m.current.delete(m.current.keys().next().value);let r={number:S,cursor:C??null,page:n};o(e=>{let i=t===`first`?[r]:t===`next`?[...c.pages,r]:[r,...c.pages],o=c.scrollShift;return t===`previous`&&(o+=n.items.length),i.length>s4&&(t===`next`?(o-=i[0].page.items.length,i=i.slice(1)):i=i.slice(0,s4)),{...e,pages:i,discovery:y,status:`streaming`,error:null,scrollShift:t===`first`?0:o,requestedRevision:t===`first`?a?.revision??n.revision:e.requestedRevision}})}),!E())return;if(!u)throw Error(`Empty media response.`);if(y?.status===`failed`)throw Error(y.message);if(y?.status!==`ready`){if(p.current>=3)throw Error(`Discovery is still incomplete. Retry to continue.`);if(p.current++,await new Promise(e=>setTimeout(e,250*p.current)),!E())return}o(e=>({...e,status:`idle`}))}catch(e){if(d.current?.token!==T||f.current!==T)return;o(t=>({...t,status:`error`,error:w.signal.aborted?`Media discovery timed out. Retry to continue.`:e instanceof Error?e.message:`Could not load media.`}))}finally{clearTimeout(E),d.current?.token===T&&(d.current=null)}},[n,r,s,e,g,_,v,x]);(0,y.useEffect)(()=>{n&&r&&s&&a.status===`idle`&&(!a.pages.length||a.discovery?.status===`pending`||a.discovery?.status===`indexing`)&&S(`first`,a.pages.length>0)},[n,r,s,a.pages.length,a.status,a.discovery?.status,S]);let C=a.pages[0]?.page.revision,w=(a.status===`idle`||a.status===`error`)&&t&&t.revision!==a.requestedRevision?t:a.latestSummary??t,T=!!(C&&[a.latestSummary,t].some(e=>e&&e.revision!==C&&e.revision!==a.requestedRevision)),E=a.discovery??w?.discovery??(t?{status:`ready`}:{status:`pending`});return{...a,visible:s,changed:T,discovery:E,latestSummary:w,identity:a.pages[0]?.page.identity??t?.identity,items:a.pages.flatMap(e=>e.page.items),hasNext:!!a.pages.at(-1)?.page.nextCursor,hasEarlier:(a.pages[0]?.number??0)>0,canLoadEarlier:m.current.has((a.pages[0]?.number??0)-1),firstItem:a.pages[0]?.number??0,loadNext:()=>S(`next`),loadPrevious:()=>S(`previous`),refresh:()=>(x(),p.current=0,m.current.clear(),S(`first`))}}var m4=128*1024,h4=3,g4=0,_4=[];function v4(e){return new Promise((t,n)=>{let r=()=>{let e=_4.indexOf(i);e>=0&&_4.splice(e,1),n(new DOMException(`Aborted`,`AbortError`))},i={signal:e,start:()=>{e.removeEventListener(`abort`,r),g4++,t(()=>{g4--;let e=_4.shift();e&&e.start()})}};if(e.aborted)return r();g4<h4?i.start():_4.length>=32?n(Error(`Thumbnail queue full`)):(_4.push(i),e.addEventListener(`abort`,r,{once:!0}))})}async function y4(e,t){let n=await v4(t);try{let n=await fetch(e,{signal:t,redirect:`error`});if(!n.ok||n.headers.get(`content-type`)?.split(`;`)[0]!==`image/png`)throw await n.body?.cancel(),Error(`Preview unavailable`);let r=n.body?.getReader();if(!r)throw Error(`Empty preview`);let i=0,a=[];try{for(;;){let{done:e,value:t}=await r.read();if(e)break;if(i+=t.byteLength,i>m4)throw Error(`Preview too large`);a.push(new Uint8Array(t))}}finally{await r.cancel().catch(()=>{}),r.releaseLock()}if(!i)throw Error(`Empty preview`);return new Blob(a,{type:`image/png`})}finally{n()}}function b4(e,t,n){let r=(0,y.useRef)(null),[i,a]=(0,y.useState)(!1),[o,s]=(0,y.useState)({status:`idle`}),c=(0,y.useRef)(o);c.current=o;let l=(0,y.useRef)(null);return(0,y.useEffect)(()=>{if(!r.current||!n.current||typeof IntersectionObserver>`u`)return;let e=new IntersectionObserver(e=>a(e.some(e=>e.isIntersecting)),{root:n.current,rootMargin:`0px 64px`});return e.observe(r.current),()=>e.disconnect()},[n]),(0,y.useEffect)(()=>(c.current={status:`idle`},s(c.current),()=>{l.current&&URL.revokeObjectURL(l.current),l.current=null}),[e]),(0,y.useEffect)(()=>{if(!t||!i||c.current.status===`ready`||c.current.status===`error`)return;let n=new AbortController,r=!0,a=setTimeout(()=>n.abort(),15e3);return s({status:`loading`}),y4(`${e}${e.includes(`?`)?`&`:`?`}thumbnail=1`,n.signal).then(e=>{if(!r||n.signal.aborted)return;let t=URL.createObjectURL(e);l.current=t,s({status:`ready`,src:t})}).catch(()=>{r&&s({status:`error`})}).finally(()=>clearTimeout(a)),()=>{r=!1,clearTimeout(a),n.abort(),s(e=>e.status===`loading`?{status:`idle`}:e)}},[e,t,i]),{target:r,preview:o,fail:()=>{l.current&&URL.revokeObjectURL(l.current),l.current=null,s({status:`error`})}}}function x4({discovery:e,kind:t,hasItems:n}){if(e.status!==`pending`&&e.status!==`indexing`)return null;let r=e.status===`indexing`&&e.bytesTotal>0?` ${Math.min(99,Math.floor(e.bytesRead/e.bytesTotal*100))}%`:``;return(0,k.jsxs)(`p`,{role:`status`,className:`px-3 py-2 text-xs text-secondary`,children:[`Finding `,n?`more `:``,t,`…`,r,n?` Results are partial.`:``]})}function S4({item:e,ready:t,root:n,onSelect:r}){let{target:i,preview:a,fail:o}=b4(e.url+`&format=thumbnail`,t,n);return(0,k.jsxs)(`button`,{ref:i,type:`button`,"data-testid":`output-item`,onClick:()=>r(e),className:`flex min-h-[44px] w-full items-center gap-2 rounded px-1 py-2 text-left text-secondary hover:bg-hover hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[a.status===`ready`?(0,k.jsx)(`img`,{src:a.src,onError:o,alt:`Saved preview`,title:`Screenshot saved when first opened`,className:`h-12 w-20 shrink-0 rounded object-cover object-top`}):(0,k.jsx)(ft,{width:K.primary,height:K.primary,className:`shrink-0`}),(0,k.jsxs)(`span`,{className:`min-w-0`,children:[(0,k.jsx)(`span`,{className:`block truncate text-[12px] text-primary`,children:e.label||`Preview`}),(0,k.jsx)(`span`,{className:`block text-[12px] text-muted`,children:e.kind===`localhost`?`Live app`:e.kind===`visualization`?`Codex visualization`:`HTML report`})]})]})}function C4({session:e,ready:t,onSelect:n}){let r=(0,y.useRef)(null),i=p4(e.agentSessionId,e.mediaSummary,!0,t,{kind:`previews`});return(0,k.jsxs)(`div`,{ref:r,className:`min-h-0 overflow-y-auto px-3 py-2`,"data-testid":`preview-list`,children:[i.changed&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>void i.refresh(),className:`min-h-[44px] text-[12px] text-accent`,children:`Previews changed · Refresh`}),i.hasEarlier&&(0,k.jsx)(`button`,{type:`button`,disabled:!t||i.status===`loading`,onClick:()=>void i.refresh(),className:`min-h-[44px] text-[12px] text-accent`,children:`Back to newest previews`}),i.items.map(e=>(0,k.jsx)(S4,{item:e,ready:t,root:r,onSelect:n},e.url)),!t&&(0,k.jsx)(`p`,{role:`status`,className:`text-[12px] text-muted`,children:`Waiting for terminal recovery…`}),!i.error&&(0,k.jsx)(x4,{discovery:i.discovery,kind:`previews`,hasItems:i.items.length>0}),i.status===`loading`&&i.discovery.status===`ready`&&(0,k.jsx)(`p`,{role:`status`,className:`text-[12px] text-muted`,children:`Loading previews…`}),i.pages.length>0&&!i.items.length&&i.discovery.status===`ready`&&(0,k.jsx)(`p`,{className:`py-2 text-[12px] text-secondary`,children:`No previews in this session yet.`}),i.error&&(0,k.jsxs)(`div`,{role:`alert`,className:`text-[12px] text-muted`,children:[i.error,` `,(0,k.jsx)(`button`,{onClick:()=>void i.refresh(),className:`min-h-[44px] text-accent`,children:`Retry`})]}),i.hasNext&&(0,k.jsx)(`button`,{type:`button`,disabled:!t||i.status===`loading`,onClick:()=>void i.loadNext(),className:`min-h-[44px] text-[12px] text-accent`,children:`Load older previews`})]})}async function w4(e){if(typeof document<`u`&&typeof document.execCommand==`function`){let t=document.activeElement,n=document.getSelection?.(),r=n?Array.from({length:n.rangeCount},(e,t)=>n.getRangeAt(t).cloneRange()):[],i=document.createElement(`textarea`);i.value=e,i.readOnly=!0,i.style.position=`fixed`,i.style.opacity=`0`,i.style.pointerEvents=`none`,i.style.fontSize=`16px`,document.body.appendChild(i);let a=!1;try{i.focus({preventScroll:!0}),i.select(),i.setSelectionRange(0,e.length),a=document.execCommand(`copy`)}catch{}finally{if(i.remove(),t?.focus?.({preventScroll:!0}),n){n.removeAllRanges();for(let e of r)n.addRange(e)}}if(a)return!0}try{return typeof navigator>`u`||!navigator.clipboard?.writeText?!1:(await navigator.clipboard.writeText(e),!0)}catch{return!1}}function T4({url:e,label:t}){let[n,r]=(0,y.useState)(`idle`),i=(0,y.useRef)(0),a=(0,y.useRef)();(0,y.useEffect)(()=>(r(`idle`),()=>{i.current++,clearTimeout(a.current)}),[e]);let o=n===`copied`?U:oe;return(0,k.jsxs)(`span`,{className:`relative shrink-0`,children:[(0,k.jsx)(`button`,{type:`button`,"aria-label":`Copy link for ${t}`,title:n===`copied`?`Copied`:`Copy link`,"aria-busy":n===`copying`,"data-copy-state":n,onKeyDown:e=>e.stopPropagation(),onKeyUp:e=>e.stopPropagation(),onClick:t=>{t.preventDefault(),t.stopPropagation(),t.currentTarget.focus({preventScroll:!0}),clearTimeout(a.current);let n=++i.current;r(`copying`),w4(e).then(e=>{n===i.current&&(r(e?`copied`:`failed`),e&&(a.current=setTimeout(()=>r(`idle`),2e3)))})},className:`flex h-[44px] w-[44px] items-center justify-center rounded text-secondary hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:(0,k.jsx)(o,{"aria-hidden":`true`,width:K.primary,height:K.primary})}),(0,k.jsx)(`span`,{role:`status`,"aria-live":`polite`,className:n===`failed`?`absolute right-0 top-full z-10 w-48 rounded border border-border bg-surface p-2 text-xs text-secondary shadow-sm`:`sr-only`,children:n===`copied`?`Link copied`:n===`failed`?`Could not copy. Touch and hold the link to copy it.`:``})]})}function E4(e,t){let n=e.replace(/^https:\/\//i,``),r;try{r=new URL(e)}catch{return{title:t||e,subtitle:t&&t!==e?e:void 0,detail:``}}let i=r.host+(r.pathname===`/`?``:r.pathname),a=t?.trim(),o=a&&![e,n,e.replace(/^https?:\/\//i,``),i].includes(a),s=e.search(/[?#]/),c=s<0?``:e.slice(s),l=r.hostname===`github.com`&&r.protocol===`https:`&&!r.port&&!r.username&&!r.password?/^\/([^/]+)\/([^/]+)\/pull\/(\d+)(\/.*)?$/.exec(r.pathname):null;if(l&&!o){let e=/^#issuecomment-(\d+)$/.exec(r.hash);return{title:`${l[2]} · PR #${l[3]}`,subtitle:`github.com/${l[1]}`,detail:[l[4],r.search,e?`Comment #${e[1]}`:r.hash].filter(Boolean).join(` · `)}}let u=(c?e.slice(0,-c.length):e).replace(/^https:\/\//i,``);return{title:o?a:u,subtitle:o?u:void 0,detail:c}}function D4({item:e,onPreview:t}){let[n,r]=(0,y.useState)(!1),i=e.externalUrl??e.url,{title:a,subtitle:o,detail:s}=E4(i,e.label);return(0,k.jsxs)(`div`,{className:`border-b border-border/60`,children:[(0,k.jsxs)(`div`,{className:`flex min-h-[60px] items-center gap-2 px-3 py-2`,children:[(0,k.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noopener noreferrer`,"aria-label":a,"aria-description":i,title:i,className:`min-w-0 flex-1 rounded text-[12px] leading-[18px] text-primary hover:text-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:[(0,k.jsx)(`span`,{className:`line-clamp-2 break-words [overflow-wrap:anywhere]`,children:a}),o&&(0,k.jsx)(`span`,{className:`mt-0.5 line-clamp-2 break-words text-[11px] leading-[16px] text-secondary [overflow-wrap:anywhere]`,children:o}),s&&(0,k.jsx)(`span`,{className:`mt-0.5 line-clamp-2 break-all text-[11px] leading-[16px] text-secondary`,children:s})]}),t&&(0,k.jsx)(`button`,{type:`button`,"aria-label":`Preview ${a}`,onClick:()=>t(e),className:`min-h-[44px] shrink-0 rounded px-2 text-[12px] text-secondary hover:bg-hover hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:`Preview`}),e.externalUrl&&(0,k.jsx)(T4,{url:e.externalUrl,label:a}),e.sourceText&&(0,k.jsx)(`button`,{type:`button`,"aria-label":`Source for ${a}`,"aria-expanded":n,onClick:()=>r(e=>!e),className:`flex h-[44px] w-[36px] shrink-0 items-center justify-center rounded text-secondary hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:(0,k.jsx)(H,{width:K.primary,height:K.primary,className:n?`rotate-90`:``})})]}),n&&(0,k.jsxs)(`p`,{className:`whitespace-pre-wrap break-words bg-surface px-3 py-2 text-[11px] leading-[17px] text-secondary`,"data-testid":`link-source`,children:[(0,k.jsx)(`span`,{className:`block text-muted`,children:`Agent reply excerpt`}),e.sourceText]})]})}function O4({session:e,ready:t,search:n,onRefresh:r,onPreview:i}){let a=p4(e.agentSessionId,e.mediaSummary,!0,t,{kind:`links`,search:n}),o=(0,y.useRef)(null),s=a.pages.at(-1),[c,l]=(0,y.useState)(0),u=a.pages.find(e=>e.number===c)??s;return(0,y.useEffect)(()=>{o.current&&(o.current.scrollTop=0)},[u?.number]),(0,k.jsxs)(k.Fragment,{children:[a.changed&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>{l(0),r(),a.refresh()},disabled:!t,"aria-label":`Refresh media`,className:`shrink-0 px-3 py-2 text-left text-xs text-accent`,children:`Links changed · Refresh`}),(0,k.jsxs)(`div`,{ref:o,"data-testid":`links-scroll`,role:`region`,"aria-label":`Session links, newest first`,className:`min-h-0 flex-1 overflow-y-auto overscroll-contain`,children:[!!u?.page.omittedItems&&!e.mediaSummary?.omittedItems&&(0,k.jsxs)(`p`,{className:`px-3 py-2 text-xs text-secondary`,children:[`Some items could not be listed because their details are too large (`,u.page.omittedItems,`).`]}),u?.page.items.map(e=>(0,k.jsx)(D4,{item:e,onPreview:i},e.url)),u&&!u.page.items.length&&a.discovery.status===`ready`&&(0,k.jsx)(`p`,{className:`px-3 py-4 text-xs text-secondary`,children:n?`No matching links.`:`No web links in this session yet.`}),a.error&&(0,k.jsxs)(`p`,{role:`alert`,className:`px-3 py-2 text-xs text-secondary`,children:[a.error,` `,(0,k.jsx)(`button`,{type:`button`,onClick:()=>{l(0),r(),a.refresh()},className:`text-accent`,children:`Retry`})]}),!a.error&&(0,k.jsx)(x4,{discovery:a.discovery,kind:`links`,hasItems:!!u?.page.items.length}),a.status===`loading`&&a.discovery.status===`ready`&&(0,k.jsx)(`p`,{role:`status`,className:`px-3 py-2 text-xs text-secondary`,children:`Loading links…`}),!t&&(0,k.jsx)(`p`,{role:`status`,className:`px-3 py-2 text-xs text-secondary`,children:`Waiting for terminal recovery…`}),(0,k.jsxs)(`div`,{className:`flex justify-between gap-2 px-3 text-xs text-accent`,children:[u&&u.number>0&&(0,k.jsx)(`button`,{type:`button`,disabled:a.status===`loading`||!t,className:`min-h-[44px]`,onClick:()=>{a.pages.some(e=>e.number===u.number-1)?l(u.number-1):a.canLoadEarlier?(l(u.number-1),a.loadPrevious()):(l(0),a.refresh())},children:`Newer links`}),u?.page.nextCursor&&(0,k.jsx)(`button`,{type:`button`,disabled:a.status===`loading`||!t,className:`ml-auto min-h-[44px]`,onClick:()=>{l(u.number+1),a.pages.some(e=>e.number===u.number+1)||a.loadNext()},children:`Older links`})]})]}),(0,k.jsxs)(`div`,{className:`flex shrink-0 justify-between border-t border-border/60 px-3 py-1.5 text-[11px] text-secondary`,children:[(0,k.jsx)(`span`,{children:`This session`}),(0,k.jsx)(`span`,{children:`Newest first`})]})]})}function k4(e){return e.startsWith(`/api/session-media/`)?`${e}${e.includes(`?`)?`&`:`?`}delivery=2`:e}var A4=[`a[href]`,`button:not([disabled])`,`input:not([disabled]):not([type="hidden"])`,`select:not([disabled])`,`textarea:not([disabled])`,`[tabindex]:not([tabindex="-1"])`].join(`,`);function j4(e){return Array.from(e.querySelectorAll(A4)).filter(e=>e.getAttribute(`aria-hidden`)!==`true`&&e.tabIndex!==-1)}function M4(e,t,n){if(e.length===0)return null;let r=e[0],i=e[e.length-1],a=t===null?-1:e.indexOf(t);return a===-1?n?i:r:n&&a===0?i:!n&&a===e.length-1?r:null}var N4=`.xterm-helper-textarea`,P4=300,F4=`[data-suspends-terminal]`,I4=null;function L4(e){return!e||typeof document>`u`||e===document.body?null:typeof e.focus==`function`?e:null}function R4(e,t){if(e.isConnected)return e;if(!t)return null;let n=t.replace(/["\\]/g,`\\$&`);return document.querySelector(`button[aria-label="${n}"]`)}function z4(e){let t=e?.restoreFocus??`terminal`;(0,y.useEffect)(()=>{if(typeof document>`u`||typeof document.querySelector!=`function`)return;I4&&=(clearTimeout(I4),null);let e=L4(document.activeElement),n=document.querySelector(N4);n&&(n.blur(),n.setAttribute(`disabled`,`true`));let r=e?.getAttribute?.(`aria-label`)??null;return()=>{I4=setTimeout(()=>{if(I4=null,document.querySelector(F4))return;let i=document.querySelector(N4);if(i&&(i.removeAttribute(`disabled`),t===`terminal`)){i.focus();return}(e&&e!==n?R4(e,r):null)?.focus()},P4)}},[t])}function B4(e,t){let n=(0,y.useRef)(t);n.current=t,(0,y.useEffect)(()=>{if(typeof document>`u`||typeof document.addEventListener!=`function`)return;let t=t=>{if(t.key===`Escape`){if(t.defaultPrevented)return;t.preventDefault(),t.stopPropagation(),n.current();return}if(t.key!==`Tab`)return;let r=e.current;if(!r)return;let i=document.activeElement,a=M4(j4(r),i,t.shiftKey);a&&(t.preventDefault(),a.focus())},r=t=>{let n=e.current,r=t.target;n&&r&&!n.contains(r)&&n.focus()};return document.addEventListener(`keydown`,t),document.addEventListener(`focusin`,r),()=>{document.removeEventListener(`keydown`,t),document.removeEventListener(`focusin`,r)}},[e])}var V4=`flex min-h-[44px] min-w-[44px] items-center justify-center gap-1 rounded-md px-3 text-sm text-white hover:bg-white/10 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent disabled:opacity-35`,H4=e=>e.url.startsWith(`/api/session-media/`);function U4(e){let{media:t,enabled:n,onClose:r,canPrevious:i,canNext:a,navigating:o,navigationError:s,onRetryNavigation:c,label:l}=e,u=(0,y.useRef)(null),d=(0,y.useRef)(null),f=(0,y.useRef)(e);f.current=e,z4({restoreFocus:`opener`}),B4(u,r),(0,y.useEffect)(()=>{d.current?.focus()},[]);let p=e=>{let t=f.current;!t.enabled||t.navigating||!(e===`previous`?t.canPrevious:t.canNext)||(u.current?.focus(),e===`previous`?t.onPrevious():t.onNext())},m=(0,y.useRef)(o);(0,y.useLayoutEffect)(()=>{let e=o&&!m.current;m.current=o,e&&u.current&&!u.current.contains(document.activeElement)&&u.current.focus()},[o]),(0,y.useEffect)(()=>{let e=e=>{if(e.key===`Escape`)e.preventDefault(),e.stopImmediatePropagation(),f.current.onClose();else if((e.key===`ArrowLeft`||e.key===`ArrowRight`)&&!e.ctrlKey&&!e.metaKey&&!e.altKey)e.preventDefault(),e.stopImmediatePropagation(),p(e.key===`ArrowLeft`?`previous`:`next`);else if(u.current&&(!e.target||typeof e.target.nodeType!=`number`||!u.current.contains(e.target)))if(e.preventDefault(),e.stopImmediatePropagation(),e.key===`Tab`){let t=M4(j4(u.current),null,e.shiftKey);t?t.focus():u.current.focus()}else u.current.focus()};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[]);let h=(0,k.jsx)(`div`,{className:`media-lightbox-backdrop fixed inset-0 z-[80] flex items-center justify-center bg-black/80`,onClick:e=>{e.stopPropagation(),e.target===e.currentTarget&&r()},onPointerDown:e=>e.stopPropagation(),children:(0,k.jsxs)(`div`,{ref:u,"data-testid":`media-lightbox`,role:`dialog`,"aria-modal":`true`,"aria-label":`Media preview`,"data-suspends-terminal":``,tabIndex:-1,onKeyDown:e=>{if(e.stopPropagation(),e.key===`Tab`&&u.current){let t=M4(j4(u.current),document.activeElement,e.shiftKey);t&&(e.preventDefault(),t.focus())}},className:`media-lightbox-panel flex flex-col overflow-hidden border border-white/15 bg-neutral-950 text-white shadow-2xl outline-none`,children:[(0,k.jsxs)(`header`,{className:`flex shrink-0 items-center gap-2 border-b border-white/10 px-3`,children:[(0,k.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm`,title:t.label,children:t.label||`Image`}),l&&(0,k.jsx)(`span`,{className:`shrink-0 text-xs text-white/60`,children:l}),(0,k.jsx)(`button`,{ref:d,type:`button`,className:V4,"aria-label":`Close image viewer`,onClick:r,children:(0,k.jsx)(ot,{width:K.primary,height:K.primary,"aria-hidden":`true`})})]}),(0,k.jsx)(W4,{media:t,previewSrc:e.previewSrc,enabled:n},t.url),!n&&(0,k.jsx)(`p`,{role:`status`,className:`px-4 py-2 text-center text-sm text-white/70`,children:`Waiting for terminal recovery…`}),s&&(0,k.jsxs)(`div`,{role:`alert`,className:`px-4 py-2 text-center text-sm text-white/70`,children:[s,` `,c&&(0,k.jsx)(`button`,{type:`button`,className:`min-h-[44px] text-accent underline`,disabled:!n||o,onClick:c,children:`Retry navigation`})]}),(0,k.jsxs)(`nav`,{"aria-label":`Image navigation`,className:`flex shrink-0 items-center justify-between gap-2 border-t border-white/10 p-2`,children:[(0,k.jsxs)(`button`,{type:`button`,className:V4,"aria-label":`Previous image`,onClick:()=>p(`previous`),disabled:!n||o||!i,children:[(0,k.jsx)(H,{width:K.primary,height:K.primary,className:`rotate-180`,"aria-hidden":`true`}),`Previous`]}),(0,k.jsx)(`span`,{role:`status`,className:`text-xs text-white/60`,children:o?`Loading images…`:``}),(0,k.jsxs)(`button`,{type:`button`,className:V4,"aria-label":`Next image`,onClick:()=>p(`next`),disabled:!n||o||!a,children:[`Next`,(0,k.jsx)(H,{width:K.primary,height:K.primary,"aria-hidden":`true`})]})]})]})});return typeof document<`u`&&document.body?.nodeType===1?(0,_f.createPortal)(h,document.body):h}function W4({media:e,previewSrc:t,enabled:n}){let[r,i]=(0,y.useState)(t?{status:`ready`,src:t}:{status:`idle`}),[a,o]=(0,y.useState)(n?`loading`:`idle`),s=(0,y.useRef)(r);s.current=r;let c=(0,y.useRef)(null),l=(0,y.useRef)(t),u=(0,y.useRef)(0),d=(0,y.useRef)(n);d.current!==n&&(u.current++,d.current=n),(0,y.useEffect)(()=>()=>{c.current&&URL.revokeObjectURL(c.current)},[]),(0,y.useEffect)(()=>{o(n?`loading`:`idle`)},[n]),(0,y.useEffect)(()=>{if(!n||!H4(e)||c.current||!l.current||s.current.status===`error`)return;let t=new AbortController,r=!0,a=setTimeout(()=>t.abort(),15e3);return l.current||i({status:`loading`}),(async()=>{let n;if(l.current?.startsWith(`blob:`))try{n=await y4(l.current,t.signal)}catch{}t.signal.aborted||(n||=await y4(`${e.url}${e.url.includes(`?`)?`&`:`?`}thumbnail=1`,t.signal),!(!r||t.signal.aborted)&&(c.current=URL.createObjectURL(n),i({status:`ready`,src:c.current})))})().catch(()=>{r&&i({status:`error`})}).finally(()=>clearTimeout(a)),()=>{r=!1,clearTimeout(a),t.abort()}},[e.url,n]);let f=u.current,p=n&&(a===`loading`||a===`ready`);return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{"data-testid":`media-lightbox-stage`,className:`media-lightbox-stage`,children:(0,k.jsxs)(`div`,{className:`media-lightbox-canvas`,children:[r.status===`ready`&&a!==`ready`&&(0,k.jsx)(`img`,{"data-testid":`media-lightbox-preview`,src:r.src,alt:`${e.label||`Image`} preview`,className:`media-lightbox-image`,onError:()=>{l.current=void 0,i({status:`error`})}}),p&&(0,k.jsx)(`img`,{"data-testid":`media-lightbox-original`,src:k4(e.url),alt:e.label||`Image`,className:`media-lightbox-image ${a===`ready`?``:`invisible`}`,onLoad:()=>{d.current&&u.current===f&&o(`ready`)},onError:()=>{d.current&&u.current===f&&o(`error`)}},f),r.status!==`ready`&&a!==`ready`&&(0,k.jsxs)(`div`,{className:`col-start-1 row-start-1 flex flex-col items-center justify-center gap-2 text-sm text-white/60`,children:[(0,k.jsx)(be,{width:K.primary,height:K.primary,"aria-hidden":`true`}),(0,k.jsx)(`span`,{role:`status`,children:a===`loading`?`Loading image…`:r.status===`loading`?`Loading preview…`:`Preview unavailable`})]})]})}),(0,k.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center justify-center gap-x-4 gap-y-1 px-3 text-sm`,children:[a===`loading`&&n&&(0,k.jsx)(`span`,{role:`status`,className:`text-white/60`,children:`Loading full image…`}),a===`error`&&(0,k.jsx)(`span`,{role:`alert`,className:`text-white/60`,children:`Could not load the full image.`}),a===`error`&&(0,k.jsx)(`button`,{type:`button`,className:`${V4} border border-white/20`,disabled:!n,onClick:()=>{u.current++,o(`loading`)},children:`Retry full image`}),(0,k.jsx)(`a`,{href:k4(e.url),target:`_blank`,rel:`noreferrer noopener`,"aria-disabled":!n,tabIndex:n?0:-1,onClick:e=>{n||e.preventDefault()},className:`flex min-h-[44px] items-center text-accent underline underline-offset-2 ${n?``:`opacity-35`}`,children:`Open original`})]})]})}function G4(e,t,n){let[r,i]=(0,y.useState)(null),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(0),l=(0,y.useRef)(r);l.current=r;let u=!!r?.media.url.startsWith(`/api/session-media/`),d=(0,y.useRef)(0),f=(0,y.useRef)(null),p=(0,y.useCallback)(()=>{d.current++,f.current?.abort(),f.current=null},[]),m=(0,y.useCallback)(()=>{p(),l.current=null,i(null),o(null)},[p]),h=(0,y.useCallback)((e,t)=>{p();let n={media:e,previewSrc:t};l.current=n,i(n),o(null)},[p]);(0,y.useEffect)(()=>{m()},[e,t,m]),(0,y.useEffect)(()=>{if(!r||!u||!n||!e||!t)return;let i=new AbortController,a=++d.current,s=r.media.url;f.current=i,o({anchor:s,status:`loading`});let c=setTimeout(()=>i.abort(),15e3);return(async()=>{try{let n=await fetch(`/api/session-media/${encodeURIComponent(e)}/neighbors?anchor=${encodeURIComponent(s)}`,{signal:i.signal,cache:`no-store`});if(!n.ok)throw Error(n.status===409?`Media changed. Close this image and refresh Media.`:`Could not load image navigation.`);let r=n.body?.getReader();if(!r)throw Error(`Empty navigation response.`);let c=[],u=new TextDecoder,f=0;try{for(;;){let{done:e,value:t}=await r.read();if(e)break;if(f+=t.byteLength,f>65536)throw Error(`Navigation response exceeded its size limit.`);c.push(u.decode(t,{stream:!0}))}c.push(u.decode())}finally{await r.cancel().catch(()=>{}),r.releaseLock()}let p=JSON.parse(c.join(``)),m=e=>e===null||e&&e.kind===`image`&&typeof e.url==`string`;if(!p||p.identity!==t||typeof p.revision!=`string`||p.current?.url!==s||!m(p.current)||!m(p.previous)||!m(p.next))throw Error(`Invalid image navigation response.`);d.current===a&&l.current?.media.url===s&&!i.signal.aborted&&o({anchor:s,status:`ready`,value:p})}catch(e){d.current===a&&l.current?.media.url===s&&o({anchor:s,status:`error`,error:i.signal.aborted?`Image navigation timed out. Try again.`:e instanceof Error?e.message:`Could not load image navigation.`})}finally{clearTimeout(c),f.current===i&&(f.current=null)}})(),()=>{clearTimeout(c),p()}},[r,u,e,t,n,s,p]);let g=a?.anchor===r?.media.url?a:null,_=g?.status===`ready`?g.value:null;return{selection:r,open:h,close:m,navigating:n&&u&&(!g||g.status===`loading`),navigationError:g?.status===`error`?g.error:void 0,canPrevious:n&&!!_?.previous,canNext:n&&!!_?.next,previous:()=>{n&&_?.previous&&h(_.previous)},next:()=>{n&&_?.next&&h(_.next)},retry:()=>c(e=>e+1)}}var K4=`h-[56px] w-[56px] shrink-0 overflow-hidden rounded-md border border-border bg-surface hover:border-accent/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,q4=`${K4} flex flex-col items-center justify-center gap-[3px] p-[4px] text-center text-secondary hover:text-primary`,J4=`line-clamp-2 w-full break-words text-[10px] leading-[12px]`;function Y4(e){return e<1024?`${e} B`:e<1024*1024?`${Math.round(e/1024)} KB`:`${(e/(1024*1024)).toFixed(1)} MB`}function X4(e){return[e.label,e.mediaType,e.bytes==null?null:Y4(e.bytes)].filter(Boolean).join(` · `)}function Z4({media:e,onOpen:t,previewEnabled:n,scrollRoot:r}){let i=X4(e);if(e.kind===`link`)return(0,k.jsxs)(`a`,{href:e.url,target:`_blank`,rel:`noreferrer noopener`,title:[i,e.url].filter(Boolean).join(` · `),"aria-label":e.label||e.url,className:q4,children:[(0,k.jsx)(Se,{width:K.primary,height:K.primary,className:`shrink-0`}),(0,k.jsx)(`span`,{className:J4,children:e.label||`Link`})]});let a=e.kind===`image`,o=e.url.startsWith(`/api/session-media/`)&&!e.url.startsWith(`//`);return a&&o?(0,k.jsx)(Q4,{media:e,caption:i,enabled:n,root:r,onOpen:t}):(0,k.jsxs)(`button`,{type:`button`,"data-testid":`media-chip`,onClick:n=>{a?(n.currentTarget.focus({preventScroll:!0}),t(e)):window.open(k4(e.url),`_blank`,`noopener`)},title:i||e.kind,"aria-label":i||(a?`Image`:`Document`),className:q4,children:[a?(0,k.jsx)(be,{width:K.primary,height:K.primary,className:`shrink-0`}):(0,k.jsx)(ve,{width:K.primary,height:K.primary,className:`shrink-0`}),(0,k.jsx)(`span`,{className:J4,children:e.label??(a?`Image`:`Document`)})]})}function Q4({media:e,caption:t,enabled:n,root:r,onOpen:i}){let{target:a,preview:o,fail:s}=b4(e.url,n,r),c=o.status===`error`?`No preview`:o.status===`loading`?`Loading…`:`Open image`;return(0,k.jsx)(`button`,{ref:a,type:`button`,"data-testid":`media-thumb`,"data-preview-state":o.status,onClick:t=>{t.currentTarget.focus({preventScroll:!0}),i(e,o.status===`ready`?o.src:void 0)},title:t||`Image`,"aria-label":`${t||`Image`} · ${o.status===`error`?`Preview unavailable. `:``}Open image`,"aria-busy":o.status===`loading`,className:o.status===`ready`?K4:q4,children:o.status===`ready`?(0,k.jsx)(`img`,{"data-testid":`media-thumbnail`,src:o.src,alt:t||`session image`,onError:s,className:`h-full w-full object-cover`}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(be,{width:K.primary,height:K.primary,className:`shrink-0`}),(0,k.jsx)(`span`,{className:J4,children:c})]})})}function $4({session:e,ready:t=!1,onPreview:n,choosePreview:r=0,chooseTab:i=`previews`}){let a=JSON.stringify([e.id,e.agentSessionId,e.logFilePath,e.remote,e.agentType]);return(0,k.jsx)(e3,{session:e,ready:t,onPreview:n,choosePreview:r,chooseTab:i},a)}function e3({session:e,ready:t=!1,onPreview:n,choosePreview:r=0,chooseTab:i=`previews`}){let[a,o]=(0,y.useState)(!1),[s,c]=(0,y.useState)(`idle`),l=e.mediaSummary,[u,d]=(0,y.useState)(()=>l?.previews&&l.images+l.documents+l.links===0?`previews`:l&&l.links>0&&l.images+l.documents===0?`links`:`media`),f=(0,y.useRef)(r);(0,y.useEffect)(()=>{r!==f.current&&(d(i),o(!0)),f.current=r},[r,i]);let[p,m]=(0,y.useState)(!1),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(``),b=p4(e.agentSessionId,l,a&&u===`media`,t,{kind:`media`}),x=G4(e.agentSessionId,b.identity,b.visible&&t),S=(0,y.useRef)(null),C=(0,y.useRef)(null),w=(0,y.useRef)(null),T=()=>{x.close(),o(!1),queueMicrotask(()=>w.current?.focus())};(0,y.useEffect)(()=>{let e=setTimeout(()=>v(h.trim()),200);return()=>clearTimeout(e)},[h]),(0,y.useEffect)(()=>{p&&C.current?.focus()},[p]),(0,y.useEffect)(()=>{if(!a||x.selection)return;let e=e=>{e.target instanceof Node&&!S.current?.contains(e.target)&&o(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[a,x.selection]);let E=(0,y.useRef)(l?.additions),D=(0,y.useRef)(null),O=(0,y.useRef)(0),A=(0,y.useRef)(0);(0,y.useEffect)(()=>{l?.images===0&&(!l.discovery||l.discovery.status===`ready`)&&x.close()},[l?.images,l?.discovery?.status,x.close]),(0,y.useLayoutEffect)(()=>{D.current&&(D.current.scrollLeft+=(b.scrollShift-O.current)*64),O.current=b.scrollShift},[b.scrollShift]),(0,y.useEffect)(()=>{if(!l)return;let t=E.current;E.current=l.additions,l.total===0?c(`idle`):t!==void 0&&l.additions>t&&!e.remote&&c(a?`unread`:`pulsing`)},[l,e.remote,a]);let j=()=>{D.current&&(D.current.scrollLeft=0),A.current=0,O.current=0,x.close(),c(`idle`),b.refresh()};if((0,y.useEffect)(()=>{if(s!==`pulsing`)return;let e=setTimeout(()=>c(`unread`),1600);return()=>clearTimeout(e)},[s]),(0,y.useEffect)(()=>{if(!a||x.selection)return;let e=e=>{e.key===`Escape`&&(e.stopPropagation(),T())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[a,x.selection]),e.remote||!e.agentSessionId)return null;let M=b.latestSummary??l,N=!M||M.total===0&&(b.discovery.status===`pending`||b.discovery.status===`indexing`),P=M?M.images+M.documents:void 0;return(0,k.jsxs)(k.Fragment,{children:[a?(0,k.jsxs)(`div`,{ref:S,"data-testid":`media-rail`,onKeyDown:e=>e.stopPropagation(),className:`absolute top-2 right-2 z-[60] flex max-h-[min(280px,65%)] w-[calc(100%-16px)] flex-col overflow-hidden rounded-xl border border-border bg-elevated shadow-xl md:max-h-[320px] md:w-[400px]`,children:[(0,k.jsxs)(`div`,{className:`flex shrink-0 items-center gap-1 border-b border-border/60 px-2`,children:[(0,k.jsx)(`div`,{className:`scrollbar-none flex min-w-0 flex-1 items-center gap-1 overflow-x-auto`,children:[`media`,`links`,`previews`].map(e=>(0,k.jsxs)(`button`,{type:`button`,"aria-pressed":u===e,onClick:()=>{d(e),x.close()},className:`flex h-[44px] shrink-0 items-center gap-[6px] whitespace-nowrap px-2 text-[12px] ${u===e?`text-primary shadow-[inset_0_-2px_var(--accent)]`:`text-secondary hover:text-primary`} focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,children:[(0,k.jsx)(e===`media`?be:e===`links`?ut:ft,{width:K.primary,height:K.primary}),e===`media`?`Media${P===void 0?``:` ${P}`}`:e===`links`?`Links${M?` ${M.links}`:``}`:`Previews${M?` ${M.previews??0}`:``}`]},e))}),u===`links`&&(0,k.jsx)(`button`,{type:`button`,"aria-label":`Search links`,"aria-expanded":p,onClick:()=>m(e=>!e),className:`ml-auto flex h-[44px] w-[36px] shrink-0 items-center justify-center rounded text-secondary hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:(0,k.jsx)(Qe,{width:K.primary,height:K.primary})}),(0,k.jsx)(`button`,{type:`button`,"aria-label":`Collapse media rail`,onClick:T,className:`ml-auto flex h-[44px] w-[36px] shrink-0 items-center justify-center rounded text-secondary hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,children:(0,k.jsx)(ot,{width:K.primary,height:K.primary})})]}),u===`links`&&p&&(0,k.jsx)(`div`,{className:`shrink-0 border-b border-border/60 px-3 py-2`,children:(0,k.jsx)(`input`,{ref:C,type:`search`,"aria-label":`Find link`,placeholder:`Find a link…`,value:h,maxLength:200,onChange:e=>g(e.target.value),className:`w-full rounded border border-border bg-surface px-2 py-1.5 text-[16px] text-primary placeholder:text-secondary focus:outline-none focus:ring-2 focus:ring-accent md:text-[12px]`})}),!!M?.omittedRecords&&(0,k.jsxs)(`p`,{"data-testid":`media-incomplete`,className:`px-3 py-2 text-xs text-muted`,children:[`Some media may be unavailable: `,M?.omittedRecords,` oversized transcript `,M?.omittedRecords===1?`entry was`:`entries were`,` skipped.`]}),!!(M?.omittedItems||b.pages[0]?.page.omittedItems)&&(0,k.jsxs)(`p`,{"data-testid":`media-omitted-items`,className:`px-3 py-2 text-xs text-muted`,children:[`Some items could not be listed because their details are too large (`,Math.max(M?.omittedItems??0,b.pages[0]?.page.omittedItems??0),`).`]}),u===`previews`?(0,k.jsx)(C4,{session:e,ready:t,onSelect:e=>{n?.(e),o(!1)}}):u===`links`?(0,k.jsx)(O4,{onPreview:n?e=>{o(!1),n(e)}:void 0,session:e,ready:t,search:_,onRefresh:()=>c(`idle`)},_):(0,k.jsxs)(k.Fragment,{children:[b.changed&&(0,k.jsx)(`button`,{type:`button`,onClick:j,disabled:!t||b.status===`loading`,className:`px-3 py-2 text-xs text-accent`,"aria-label":`Refresh media`,children:`Media changed · Refresh`}),b.hasEarlier&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>{b.canLoadEarlier?b.loadPrevious():j()},disabled:!t||b.status===`loading`,className:`px-3 py-1 text-xs text-accent`,children:b.canLoadEarlier?`Newer media`:`Back to newest media`}),(0,k.jsx)(`div`,{ref:D,"data-testid":`media-scroll`,tabIndex:0,role:`region`,"aria-label":`Session media, newest first`,onScroll:e=>{let t=e.currentTarget,n=t.scrollLeft>A.current;A.current=t.scrollLeft,n&&t.clientWidth>0&&t.scrollWidth-t.clientWidth-t.scrollLeft<128&&b.hasNext&&(b.status===`idle`||b.status===`streaming`)&&b.loadNext()},className:`scrollbar-none flex gap-2 overflow-x-auto px-3 py-2`,children:b.items.map((e,n)=>(0,k.jsx)(Z4,{media:e,onOpen:x.open,previewEnabled:b.visible&&t,scrollRoot:D},`${e.url}:${n}`))}),!t&&(0,k.jsx)(`p`,{role:`status`,className:`px-3 pb-2 text-xs text-muted`,children:`Waiting for terminal recovery…`}),!b.error&&(0,k.jsx)(x4,{discovery:b.discovery,kind:`media`,hasItems:b.items.length>0}),b.status===`loading`&&b.discovery.status===`ready`&&(0,k.jsx)(`p`,{role:`status`,className:`px-3 pb-2 text-xs text-muted`,children:`Loading media…`}),b.pages.length>0&&!b.items.length&&b.discovery.status===`ready`&&(0,k.jsx)(`p`,{className:`px-3 py-2 text-xs text-secondary`,children:`No media in this session yet.`}),b.error&&(0,k.jsxs)(`div`,{role:`alert`,className:`px-3 pb-2 text-xs text-muted`,children:[b.error,` `,(0,k.jsx)(`button`,{type:`button`,onClick:j,disabled:!t,className:`text-accent`,"aria-label":`Refresh media`,children:`Refresh`})]}),b.hasNext&&!b.error&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>void b.loadNext(),disabled:!t||b.status===`loading`,className:`px-3 pb-2 text-xs text-accent`,children:`Load older media`})]})]}):(0,k.jsxs)(`button`,{type:`button`,ref:w,"data-testid":`media-rail-pill`,"aria-expanded":!1,onClick:()=>{c(`idle`),o(!0)},"aria-label":`Open media, links and previews${M&&!N?`: ${M.total} ${M.total===1?`item`:`items`}`:``}${s===`idle`?``:`, new media`}`,className:`absolute top-2 right-2 z-40 flex items-center gap-[12px] whitespace-nowrap rounded-full border border-border bg-elevated/90 px-3 py-1.5 text-xs text-secondary shadow-lg backdrop-blur transition-colors hover:text-primary md:min-h-[30px] md:gap-[16px] md:px-[12px] md:py-[5px] md:text-[12px] md:leading-[18px] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent ${s===`pulsing`?`media-attention`:``} ${Zt}`,children:[(0,k.jsxs)(`span`,{className:`inline-flex items-center gap-[6px]`,children:[(0,k.jsx)(be,{width:K.pill,height:K.pill,className:`md:h-[16px] md:w-[16px]`}),(0,k.jsx)(`span`,{className:`hidden md:inline`,children:`Media`}),(0,k.jsx)(`span`,{className:`tabular-nums`,children:N?`…`:P??`…`})]}),!!M?.links&&(0,k.jsxs)(`span`,{className:`inline-flex items-center gap-[6px]`,children:[(0,k.jsx)(ut,{width:K.pill,height:K.pill}),(0,k.jsx)(`span`,{className:`hidden md:inline`,children:`Links`}),(0,k.jsx)(`span`,{className:`tabular-nums`,children:M.links})]}),!!M?.previews&&(0,k.jsxs)(`span`,{className:`inline-flex items-center gap-[6px]`,children:[(0,k.jsx)(ft,{width:K.pill,height:K.pill}),(0,k.jsx)(`span`,{className:`hidden md:inline`,children:`Previews`}),(0,k.jsx)(`span`,{className:`tabular-nums`,children:M.previews})]}),s!==`idle`&&(0,k.jsx)(`span`,{"data-testid":`media-rail-new-dot`,"aria-hidden":`true`,className:`h-[6px] w-[6px] shrink-0 rounded-full bg-accent`})]}),x.selection&&(0,k.jsx)(U4,{media:x.selection.media,previewSrc:x.selection.previewSrc,enabled:b.visible&&t,onClose:x.close,onPrevious:x.previous,onNext:x.next,canPrevious:x.canPrevious,canNext:x.canNext,navigating:x.navigating,navigationError:x.navigationError,onRetryNavigation:x.retry})]})}var t3=`flex min-h-[44px] items-center justify-center rounded px-3 text-[12px] text-secondary hover:bg-hover hover:text-primary`;function n3(){return z4(),(0,k.jsx)(`span`,{"data-suspends-terminal":!0,className:`hidden`})}function r3({item:e,mobile:t,open:n,onClose:r,onChoose:i,status:a}){let[o,s]=(0,y.useState)(null),[c,l]=(0,y.useState)(48),[u,d]=(0,y.useState)(0),[f,p]=(0,y.useState)(!0),[m,h]=(0,y.useState)(!1),g=(0,y.useRef)(null);return(0,y.useEffect)(()=>{let t=new AbortController;if(s(null),p(!0),h(!1),e.kind===`link`){try{let t=new URL(e.externalUrl??e.url,window.location.href);if(![`http:`,`https:`].includes(t.protocol)||t.username||t.password||t.origin===window.location.origin)throw Error(`Open this link in a new tab to view it.`);if(window.location.protocol===`https:`&&t.protocol===`http:`)throw Error(`This HTTP page cannot be embedded in an HTTPS dashboard. Open the original to view it.`);s({url:t.href})}catch(e){s({error:e instanceof Error?e.message:`Invalid preview address`})}return()=>t.abort()}return fetch(e.url+`&format=json`,{signal:t.signal}).then(async e=>{let n=await e.json();if(!e.ok)throw Error(n.error||`Preview unavailable`);if(typeof n.url!=`string`||!/^https?:\/\//.test(n.url))throw Error(`Invalid preview address`);t.signal.aborted||s({url:n.url})}).catch(e=>{t.signal.aborted||s({error:e.message||`Preview unavailable`})}),()=>t.abort()},[e.url,e.externalUrl,e.kind,u]),(0,y.useEffect)(()=>{if(!f)return;let e=setTimeout(()=>h(!0),12e3);return()=>clearTimeout(e)},[f,u]),(0,y.useEffect)(()=>{if(!n)return;let e=e=>{e.key!==`Escape`||!t&&!g.current?.contains(e.target)||(e.stopPropagation(),e.preventDefault(),r())};return window.addEventListener(`keydown`,e,!0),()=>window.removeEventListener(`keydown`,e,!0)},[n,t,r]),(0,k.jsxs)(`section`,{ref:g,hidden:!n,style:n?t?void 0:{width:`${c}%`,position:`relative`}:{display:`none`},"data-testid":`output-preview`,"aria-label":e.label||`Output preview`,className:t?`fixed inset-0 z-[55] flex flex-col bg-base pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)]`:`flex min-w-0 w-[48%] min-h-0 flex-col border-l border-border bg-base`,children:[!t&&(0,k.jsx)(`div`,{role:`separator`,"aria-label":`Resize output preview`,"aria-orientation":`vertical`,"aria-valuemin":30,"aria-valuemax":70,"aria-valuenow":c,tabIndex:0,className:`absolute -left-1 top-0 bottom-0 z-10 w-2 cursor-col-resize touch-none hover:bg-accent/30 focus-visible:bg-accent/30`,onPointerDown:e=>e.currentTarget.setPointerCapture(e.pointerId),onPointerMove:e=>{if(!e.currentTarget.hasPointerCapture(e.pointerId))return;let t=e.currentTarget.parentElement?.parentElement?.getBoundingClientRect();t&&l(Math.min(70,Math.max(30,Math.round((t.right-e.clientX)/t.width*100))))},onKeyDown:e=>{e.key!==`ArrowLeft`&&e.key!==`ArrowRight`||(e.preventDefault(),e.stopPropagation(),l(t=>Math.min(70,Math.max(30,t+(e.key===`ArrowLeft`?2:-2)))))}}),t&&n&&(0,k.jsx)(n3,{}),(0,k.jsxs)(`div`,{className:`flex shrink-0 flex-wrap items-center gap-1 border-b border-border px-2 py-1`,children:[t&&(0,k.jsx)(`button`,{type:`button`,onClick:r,className:t3,children:`← Terminal`}),(0,k.jsxs)(`div`,{className:`min-w-0 flex-1 px-1 ${t?`order-last basis-full py-1`:``}`,children:[(0,k.jsx)(`div`,{className:`truncate text-[13px] font-medium text-primary`,children:e.label||`Output preview`}),(0,k.jsx)(`div`,{className:`text-[12px] text-muted`,children:e.kind===`link`?`Web page`:e.kind===`visualization`?`Codex visualization`:e.kind===`html`?`HTML report`:`Live app`})]}),(0,k.jsx)(`button`,{type:`button`,onClick:i,className:t3,children:e.kind===`link`?`Links`:`Previews`}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>d(e=>e+1),className:t3,children:`Reload`}),(0,k.jsxs)(`a`,{href:o&&`url`in o?o.url:e.externalUrl??e.url,target:`_blank`,rel:`noopener noreferrer`,"aria-label":`Open output in new tab`,className:t3,children:[(0,k.jsx)(Se,{width:K.primary,height:K.primary}),(0,k.jsx)(`span`,{className:`ml-1`,children:`Open original`})]}),!t&&(0,k.jsx)(`button`,{type:`button`,onClick:r,"aria-label":`Close preview`,className:t3,children:(0,k.jsx)(ot,{width:K.primary,height:K.primary})})]}),e.kind===`link`&&(0,k.jsx)(`p`,{className:`shrink-0 border-b border-border px-3 py-2 text-[12px] text-muted`,children:`If this page stays blank or refuses to connect, use Open original.`}),o&&`error`in o?(0,k.jsxs)(`div`,{role:`alert`,className:`p-5 text-[13px] text-secondary`,children:[(0,k.jsx)(`p`,{children:o.error}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>d(e=>e+1),className:`mt-3 rounded border border-border px-3 py-2`,children:`Try again`})]}):(0,k.jsxs)(k.Fragment,{children:[f&&(0,k.jsx)(`div`,{role:`status`,className:`px-4 py-3 text-[12px] text-muted`,children:m?`Still connecting. Preview ports must be reachable from this device. Try opening in a new tab or check your network.`:`Opening preview…`}),o&&`url`in o&&(0,k.jsx)(`iframe`,{title:e.label||`Output preview`,src:o.url,className:`min-h-0 w-full flex-1 border-0 bg-white`,sandbox:`allow-scripts allow-same-origin allow-forms allow-downloads`,referrerPolicy:`no-referrer`,onLoad:()=>p(!1)},u)]}),t&&(0,k.jsxs)(`div`,{className:`shrink-0 border-t border-border px-3 py-2 text-[12px] text-muted`,children:[`Agent `,a===`working`?`is still working`:a===`permission`?`needs permission`:`status: `+(a||`unknown`)]})]})}function i3({session:e,ready:t,children:n}){let r=ag(),i=JSON.stringify([e?.id,e?.agentSessionId,e?.logFilePath]),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(0),l=a?.identity===i?a:null,u=(0,y.useCallback)(()=>o(e=>e?{...e,open:!1}:null),[]);return(0,k.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1`,"data-testid":`session-outputs`,children:[(0,k.jsxs)(`div`,{className:`relative flex min-h-0 min-w-0 flex-1`,children:[n,e&&(0,k.jsx)($4,{session:e,ready:t,choosePreview:s,chooseTab:l?.item.kind===`link`?`links`:`previews`,onPreview:e=>o({identity:i,item:e,open:!0})})]}),l&&(0,k.jsx)(r3,{item:l.item,mobile:r,open:l.open,onClose:u,onChoose:()=>c(e=>e+1),status:e?.status},l.item.url)]})}function a3({text:e,sessionName:t,ready:n,atLimit:r,truncated:i,persistence:a,onSave:o,onDiscardOthers:s,onEdit:c,onSend:l,onDiscard:u}){return(0,k.jsxs)(`section`,{"aria-label":a===`sent-remove-failed`?`Saved copy of sent terminal text`:`Unsent terminal text`,className:`absolute bottom-2 left-2 right-2 z-50 mx-auto max-w-xl rounded-lg border border-border bg-elevated p-3 shadow-lg`,children:[(0,k.jsxs)(`label`,{htmlFor:`recovery-draft`,className:`mb-2 block text-sm text-primary`,children:[a===`sent-remove-failed`?`Saved copy of sent text for`:`Unsent text for`,` `,t]}),(0,k.jsx)(`textarea`,{id:`recovery-draft`,value:e,onChange:e=>c(e.target.value),rows:3,readOnly:a===`sent-remove-failed`,spellCheck:!1,className:`w-full resize-y rounded border border-border bg-base p-2 font-mono text-base text-primary focus:outline-accent`,"aria-describedby":`recovery-draft-hint`}),(0,k.jsx)(`p`,{id:`recovery-draft-hint`,className:`mt-1 text-xs text-secondary`,children:i?`Some text could not be saved: the draft limit was reached. Review before sending.`:r?`Draft limit reached. Edit or discard text to make room.`:a===`saved`?`Saved on this device until sent or discarded. Never sent automatically.`:`Never sent automatically.`}),(0,k.jsx)(`p`,{className:`mt-1 text-xs text-secondary`,children:`Terminal keys are paused until this draft is sent or discarded. You can keep editing here.`}),a!==`saved`&&(0,k.jsx)(`p`,{role:`status`,className:`mt-1 text-xs text-primary`,children:a===`sent-remove-failed`?`Text was sent, but its saved copy could not be removed. Discard the saved copy before continuing; it may return after reload.`:a===`conflict`?`Another tab changed this draft. Your version is kept here; save it explicitly to replace the saved version.`:a===`remove-failed`?`Could not remove the saved draft. It may return after reload; retry Discard text.`:`Local saving is unavailable. This version is only in this tab and may be lost on reload.`}),(0,k.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center justify-end gap-2`,children:[(a===`memory`||a===`conflict`)&&(0,k.jsx)(`button`,{type:`button`,onClick:o,className:`min-h-11 rounded px-3 text-sm text-secondary hover:bg-hover`,children:`Save this version`}),r&&s&&(0,k.jsx)(`button`,{type:`button`,onClick:s,className:`min-h-11 rounded px-3 text-sm text-secondary hover:bg-hover`,children:`Discard other terminal drafts`}),(0,k.jsx)(`button`,{type:`button`,onClick:u,className:`min-h-11 rounded px-3 text-sm text-secondary hover:bg-hover`,children:`Discard text`}),(0,k.jsx)(`button`,{type:`button`,onClick:l,disabled:!n||!e||a===`sent-remove-failed`,className:`min-h-11 rounded bg-accent px-3 text-sm text-white disabled:cursor-not-allowed disabled:opacity-50`,children:`Send text`})]})]})}var o3=64*1024,s3=`agentboard:recovery-draft:v1:`,c3=()=>globalThis.localStorage;function l3(){return globalThis.crypto?.randomUUID?.()??`${Date.now()}-${Math.random()}`}function u3(e){return s3+e}function d3(e){if(!e||e.length>394240)return null;try{let t=JSON.parse(e);return t?.version!==1||typeof t.revision!=`string`||t.revision.length>100||!(t.parentRevision===null||typeof t.parentRevision==`string`&&t.parentRevision.length<=100)||typeof t.text!=`string`||t.text.length>65536||typeof t.truncated!=`boolean`||/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f]/.test(t.text)?null:t}catch{return null}}function f3(e,t){let n=e.slice(0,Math.max(0,t));return/[\uD800-\uDBFF]$/.test(n)?n.slice(0,-1):n}var p3=class{select(e){return this.preferred=e,this.read()}constructor(e=c3){this.access=e,this.fallback=new Map,this.failures=new Map,this.lastWritten=new Map,this.lastRead={},this.overflow=!1,this.preferred=null}read(){let e;try{let t=this.access();e=Object.create(null),this.overflow=!1;let n=0,r=0,i=(t,i)=>{if(!(t.length>4096||!i)){if(r>=128||n+i.text.length>65536){this.overflow=!0;return}e[t]=i,n+=i.text.length,r++}};this.preferred&&i(this.preferred,d3(t.getItem(u3(this.preferred))));for(let e=0;e<t.length;e++){let n=t.key(e);if(!n?.startsWith(`agentboard:recovery-draft:v1:`))continue;let r=n.slice(29);r!==this.preferred&&i(r,d3(t.getItem(n)))}this.lastRead=e;for(let[e,t]of this.failures)t===`memory`&&!this.fallback.has(e)&&this.failures.delete(e)}catch{e=this.lastRead;for(let t of Object.keys(e))this.failures.has(t)||this.failures.set(t,`memory`)}return{drafts:{...e,...Object.fromEntries(this.fallback)},failures:Object.fromEntries(this.failures),overflow:this.overflow}}storageChanged(e,t){if(e?.startsWith(`agentboard:recovery-draft:v1:`)){let n=e.slice(29),r=this.lastWritten.get(n),i=d3(t);try{if(this.access().getItem(e)!==t)return this.read()}catch{return this.read()}r&&i&&i.revision!==r.revision&&i.parentRevision!==r.revision&&(this.fallback.set(n,r),this.failures.set(n,`conflict`)),this.lastWritten.delete(n)}else e===null&&this.lastWritten.clear();return this.read()}update(e,t,n,r=!1,i=!1){let a=this.read(),o=a.drafts[e],s=t(o?.text??``),c=Object.entries(a.drafts).filter(([t])=>t!==e),l=f3(s,a.overflow?o?.text.length??0:c.length>=128?0:o3-c.reduce((e,[,t])=>e+t.text.length,0)),u=this.fallback.has(e)?o?.parentRevision??null:o?.revision??null,d={version:1,revision:l3(),parentRevision:u,text:l,truncated:l!==s||!r&&!!o?.truncated},f=r&&(o?.revision??null)!==n;if(!i&&(f||this.failures.get(e)===`conflict`))return this.fallback.set(e,d),this.failures.set(e,`conflict`),this.read();try{let t=this.access(),n=d3(t.getItem(u3(e)));if(!i&&(n?.revision??null)!==u)return this.fallback.set(e,d),this.failures.set(e,`conflict`),this.read();if(c.length>=128&&!o)throw Error(`Draft capacity reached`);d.parentRevision=n?.revision??null,!l&&!d.truncated?t.removeItem(u3(e)):t.setItem(u3(e),JSON.stringify(d)),this.fallback.delete(e),this.failures.delete(e),l||d.truncated?this.lastWritten.set(e,d):this.lastWritten.delete(e)}catch{this.fallback.set(e,d),this.failures.set(e,`memory`)}return this.read()}remove(e,t,n=!1){let r=this.read(),i=r.drafts[e];if(!i)return r;try{let a=this.access(),o=d3(a.getItem(u3(e))),s=this.fallback.has(e)?i.parentRevision:t;if(this.failures.get(e)!==`conflict`&&(o?.revision??null)!==s)return n||r.failures[e]===`sent-remove-failed`?(this.fallback.delete(e),this.failures.delete(e),this.lastWritten.delete(e),this.read()):(this.failures.set(e,`conflict`),this.read());this.failures.get(e)!==`conflict`&&a.removeItem(u3(e)),this.fallback.delete(e),this.failures.delete(e),this.lastWritten.delete(e)}catch{this.fallback.set(e,{...i,parentRevision:this.fallback.has(e)?i.parentRevision:i.revision}),this.failures.set(e,n||r.failures[e]===`sent-remove-failed`?`sent-remove-failed`:`remove-failed`)}return this.read()}removeOthers(e){let t=this.read();try{let t=this.access(),n=[];for(let r=0;r<t.length;r++){let i=t.key(r);i?.startsWith(`agentboard:recovery-draft:v1:`)&&i!==u3(e??``)&&n.push(i)}for(let e of n)t.removeItem(e),this.lastWritten.delete(e.slice(29));for(let t of this.fallback.keys())t!==e&&(this.fallback.delete(t),this.failures.delete(t),this.lastWritten.delete(t))}catch{for(let[n,r]of Object.entries(t.drafts))n!==e&&this.remove(n,r.revision)}return this.read()}};function m3(e,t,n){if(/[\x00-\x07\x0b\x0c\x0e-\x1f\x80-\x9f]/.test(t)||n===`typing`&&t.includes(` `))return e;if(n===`paste`)return/[\x08\x7f]/.test(t)?e:e+t.replace(/\r\n?/g,`
|
|
309
309
|
`);let r=e;for(let e of t.replace(/\r\n?/g,`
|
|
310
310
|
`))r=e===`\b`||e===``?Array.from(r).slice(0,-1).join(``):r+e;return r}function h3(e){let[t]=(0,y.useState)(()=>new p3),[n,r]=(0,y.useState)(()=>t.select(e));(0,y.useEffect)(()=>{r(t.select(e))},[t,e]),(0,y.useEffect)(()=>{let e=e=>{(e.key===null||e.key.startsWith(`agentboard:recovery-draft:v1:`))&&r(t.storageChanged(e.key,e.newValue))};if(!(typeof window>`u`))return window.addEventListener(`storage`,e),r(t.read()),()=>window.removeEventListener(`storage`,e)},[t]);let i=e?n.drafts[e]:void 0,a=e?n.failures[e]??`saved`:`saved`,o=(0,y.useCallback)((n,o=!1,s=!1)=>{a!==`sent-remove-failed`&&e&&r(t.update(e,n,i?.revision??null,o,s))},[t,e,i?.revision,a]),s=(0,y.useCallback)((e,t)=>{o(n=>m3(n,e,t))},[o]),c=(0,y.useCallback)(e=>o(()=>e.replace(/[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f]/g,``).replace(/\r\n?/g,`
|
|
311
|
-
`),!0),[o]),l=(0,y.useCallback)(()=>{e&&r(t.remove(e,i?.revision??null))},[t,e,i?.revision]),u=(0,y.useCallback)(()=>{e&&r(t.remove(e,i?.revision??null,!0))},[t,e,i?.revision]),d=(0,y.useCallback)(()=>r(t.removeOthers(e)),[t,e]),f=(0,y.useCallback)(()=>o(()=>i?.text??``,!1,!0),[o,i?.text]);return{text:i?.text??``,pending:!!i,truncated:!!i?.truncated,persistence:a,hasOtherDrafts:n.overflow||Object.keys(n.drafts).some(t=>t!==e),atLimit:n.overflow||Object.values(n.drafts).reduce((e,t)=>e+t.text.length,0)>=65535||Object.keys(n.drafts).length>=128,capture:s,edit:c,discard:l,discardOthers:d,save:f,sent:u}}function g3(e){let t=e.agentboardTags?.serverPid,n=typeof t==`number`&&Number.isSafeInteger(t)&&t>0?t:null;return JSON.stringify([e.id,e.tmuxWindow,e.host??null,e.remote===!0,n,n===null?e.createdAt:null])}function _3({isOpen:e,onClose:t,sessions:n,hibernatingSessions:r=[],historySessions:i=[],selectedSessionId:a,selectedHibernatingSessionId:o=null,onSelect:s,onSelectHibernating:c,onRename:l,onResume:u,onHibernate:d,onMoveToHistory:f,onNewSession:p,onOpenHistory:m,subscribe:h,loading:g,error:_}){let v=gf(),b=(0,y.useRef)(null),x=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!e||typeof document>`u`)return;let{body:t}=document,n=window.scrollY,r={position:t.style.position,top:t.style.top,width:t.style.width};return t.style.position=`fixed`,t.style.top=`-${n}px`,t.style.width=`100%`,()=>{t.style.position=r.position,t.style.top=r.top,t.style.width=r.width,window.scrollTo(0,n)}},[e]),(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(e.preventDefault(),t())};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t]),(0,y.useEffect)(()=>{e?(x.current=document.activeElement,b.current?.focus({preventScroll:!0})):x.current&&=(x.current.focus({preventScroll:!0}),null)},[e]),(0,y.useEffect)(()=>{if(!e)return;let n=b.current;if(!n)return;let r=0,i=0,a=e=>{let t=e.touches[0];r=t.clientX,i=t.clientY},o=e=>{let n=e.changedTouches[0],a=r-n.clientX,o=Math.abs(n.clientY-i);a>=50&&a>o*1.5&&(`vibrate`in navigator&&navigator.vibrate(10),t())};return n.addEventListener(`touchstart`,a,{passive:!0}),n.addEventListener(`touchend`,o,{passive:!0}),()=>{n.removeEventListener(`touchstart`,a),n.removeEventListener(`touchend`,o)}},[e,t]);let S=e=>{s(e),t()},C=e=>{c?.(e),t()},w=m?()=>{t(),m()}:void 0,T=v?{transition:`none`}:void 0;return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:`session-drawer-backdrop ${e?`open`:``}`,style:T,onClick:t,"aria-hidden":`true`}),(0,k.jsxs)(`div`,{ref:b,className:`session-drawer ${e?`open`:``}`,style:T,role:`dialog`,"aria-modal":e?!0:void 0,"aria-label":`Session list`,tabIndex:-1,children:[(0,k.jsx)(iR,{sessions:n,hibernatingSessions:r,historySessions:i,selectedSessionId:a,selectedHibernatingSessionId:o,onSelect:S,onSelectHibernating:C,onRename:l,onResume:u,onHibernate:d,onMoveToHistory:f,scrollSelectionActive:e,onNewSession:()=>{p()!==!1&&t()},loading:g,error:_,notice:w&&(0,k.jsx)(N,{onOpen:w,subscribe:h})}),(0,k.jsxs)(`div`,{className:`flex shrink-0 gap-2 border-t border-border px-2 pt-2`,style:{paddingBottom:`max(0.5rem, env(safe-area-inset-bottom, 0.5rem))`},children:[(0,k.jsx)(`button`,{onClick:()=>{p()!==!1&&t()},className:`btn btn-primary min-h-[44px] flex-1 py-2 text-sm`,children:`New Session`}),w&&(0,k.jsx)(`button`,{type:`button`,onClick:w,className:Jt(`neutral`),title:`Session recovery`,"aria-label":`Session recovery`,children:(0,k.jsx)(ce,{width:K.primary,height:K.primary})})]})]})]})}var v3={working:`bg-working/45`,waiting:`bg-waiting/45`,permission:`bg-approval`,unknown:`bg-muted/40`};function y3({sessions:e,selectedId:t,isOpen:n,onOpen:r}){let i=(0,y.useId)();return(0,k.jsxs)(`button`,{type:`button`,"data-testid":`session-peek`,className:`absolute inset-y-0 left-0 z-10 flex w-[8px] flex-col gap-1 overflow-hidden bg-elevated py-1 md:hidden focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-[-2px]`,"aria-label":`Open session overview`,"aria-expanded":n,"aria-describedby":i,onClick:r,children:[(0,k.jsx)(`span`,{id:i,className:`sr-only`,children:e.map(e=>`${e.name}: ${E0[e.status]}${e.id===t?`, current session`:``}`).join(`; `)}),e.map(e=>(0,k.jsx)(`span`,{"data-session-id":e.id,"data-status":e.status,"data-selected":e.id===t,"aria-hidden":`true`,className:`relative min-h-0 max-h-12 w-full flex-1 rounded-r-sm ${v3[e.status]}`,children:e.id===t&&(0,k.jsx)(`span`,{className:`absolute inset-y-1/3 left-0 w-1 rounded-r-sm bg-primary`})},e.id))]})}function b3(){`vibrate`in navigator&&navigator.vibrate(10)}function x3({session:e,sessions:t,drawerSessions:n,hibernatingSession:r=null,hibernatingSessions:i=[],historySessions:a=[],connectionStatus:o,connectionEpoch:s=0,sendMessage:c,subscribe:l,onClose:u,onSelectSession:d,onSelectHibernatingSession:f,onNewSession:p,onKillSession:m,onRenameSession:h,onDuplicateSession:g,onResumeSession:_,onHibernateSession:v,onMoveToHistory:b,onOpenSettings:x,onOpenHistory:S,loading:C=!1,error:w=null}){let T=(0,y.useRef)(void 0),E=(0,y.useCallback)(e=>((e.type===`terminal-input`||e.type===`terminal-paste`)&&T.current?.(),c(e)),[c]),D=_0[h0()],O=G(e=>e.compactMobileControls),A=G(e=>e.showMobileSessionPeek),j=G(e=>e.useWebGL),M=G(e=>e.fontSize),N=G(e=>e.lineHeight),P=G(e=>e.letterSpacing),F=Ft(G(e=>e.fontOption),G(e=>e.customFontFamily)),I=kt(Dt(G(e=>e.shortcutModifier))),R=Ct(),B=ag(),[V,ee]=(0,y.useState)(!1),[H,te]=(0,y.useState)(!1),[U,ne]=(0,y.useState)(!1),[W,re]=(0,y.useState)(!1),[ie,ae]=(0,y.useState)(!1),[se,ce]=(0,y.useState)(!1),[le,ue]=(0,y.useState)(``),de=(0,y.useRef)(!1),fe=(0,y.useRef)(null),pe=(0,y.useRef)(null),he=(0,y.useRef)(null),_e=(0,y.useRef)(null),ve=(0,y.useRef)(()=>{}),ye=(0,y.useRef)(()=>{}),be=e?.remote===!0,xe=Qh(e=>e.remoteAllowControl),Se=Qh(e=>e.remoteAllowAttach),Ce=be&&!Se,we=!be||xe&&e?.source===`managed`,Te=r?r.displayName||Bh(r.projectPath)||r.sessionId.slice(0,8):``,Ee=r?Bh(r.projectPath):``,De=r?zh(r.lastActivityAt):``,Oe=!!e&&!!v&&e.source===`managed`&&!e.remote&&!!e.agentSessionId?.trim(),ke=(0,y.useMemo)(()=>{let e=new Set;for(let n of t)n.host?.trim()&&e.add(n.host.trim());for(let t of i)t.host?.trim()&&e.add(t.host.trim());return e.size>1},[t,i]),Ae=e&&!Ce?g3(e):null,je=h3(Ae),{resetNativeInput:Me,containerRef:Ne,terminalRef:Pe,inTmuxCopyModeRef:Fe,isTmuxCopyMode:Le,appMouseRef:Re,setTmuxCopyMode:ze,isSwitching:Ve,isInputReady:He,pendingClipboardOffer:Ue,copyPendingClipboardOffer:We,dismissPendingClipboardOffer:Ge}=o0({sessionId:e?.id??null,tmuxTarget:e?.tmuxWindow??null,agentType:e?.agentType,onPasteFiles:e=>ve.current(e),onPasteError:e=>ye.current(e),allowAttach:!Ce,deferInput:je.pending,onDeferredInput:je.capture,connectionStatus:o,connectionEpoch:s,sendMessage:E,subscribe:l,theme:D,fontSize:M,lineHeight:N,letterSpacing:P,fontFamily:F,useWebGL:j,onScrollChange:e=>{ee(!e)}});T.current=Me;let Ke=r4({sessionId:e?.id??null,sendMessage:E,subscribe:l}),qe=Ke.state.status!==`closed`,Ye=i4(Ke.open,fe),Xe=a4(Ke.state,e?.agentType),Ze=(0,y.useCallback)(()=>{!e||Ce||(E({type:`tmux-cancel-copy-mode`,sessionId:e.id}),ze(!1),Pe.current?.scrollToBottom())},[e,Ce,E,ze,Pe]),Qe=(0,y.useCallback)(()=>{ae(!0),b3()},[]),$e=u0({enabled:B||R,isOpen:ie,onOpen:Qe});(0,y.useEffect)(()=>{!B&&!R&&ie&&ae(!1)},[ie,B,R]),s0(pe,W,(0,y.useCallback)(()=>re(!1),[])),(0,y.useEffect)(()=>{se&&he.current&&(he.current.focus(),he.current.select())},[se]),(0,y.useEffect)(()=>{U&&_e.current&&_e.current.focus()},[U]),c0(U,(0,y.useCallback)(()=>ne(!1),[]));let tt=()=>{e&&(m(e.id,`terminal_confirm_modal`),ne(!1))},nt=()=>{!e||!Oe||(v?.(e.agentSessionId.trim()),re(!1))},rt=()=>{e&&(ue(e.agentSessionName||e.name),ce(!0),re(!1))},it=()=>{if(!e)return;let t=le.trim(),n=e.agentSessionName||e.name;t&&t!==n&&h(e.id,t),ce(!1)},at=e=>{e.key===`Enter`?(e.preventDefault(),it()):e.key===`Escape`&&(e.preventDefault(),ce(!1))};(0,y.useEffect)(()=>{if(!R||!e){te(!1);return}let t=Ne.current;if(!t)return;let n=e=>{let n=t.querySelector(`.xterm-accessibility-tree`);if(!n)return!1;let r=e.anchorNode,i=e.focusNode;return!!r&&n.contains(r)||!!i&&n.contains(i)},r=()=>{let e=t.querySelector(`.xterm-accessibility`),n=t.querySelector(`.xterm-accessibility-tree`);!e||!n||(e.style.setProperty(`opacity`,`0`),n.style.setProperty(`opacity`,`0`),e.style.setProperty(`-webkit-user-select`,`none`),e.style.setProperty(`user-select`,`none`),n.style.setProperty(`-webkit-user-select`,`none`),n.style.setProperty(`user-select`,`none`),e.offsetHeight,requestAnimationFrame(()=>{e.style.removeProperty(`opacity`),n.style.removeProperty(`opacity`),e.style.removeProperty(`-webkit-user-select`),e.style.removeProperty(`user-select`),n.style.removeProperty(`-webkit-user-select`),n.style.removeProperty(`user-select`)}))},i=null,a=()=>{i?.(),i=null},o=()=>{a(),de.current=!1;let e=window.getSelection();try{e?.removeAllRanges()}catch{}Pe.current?.clearSelection(),r(),te(!1)};fe.current=o;let s=()=>{let e=window.getSelection();if(!e||e.rangeCount===0||e.isCollapsed){de.current?o():(a(),te(e=>e&&!1));return}let r=n(e);if(!r&&de.current){o();return}if(de.current=r,r&&!i){let e=t.querySelector(`.xterm-accessibility-tree`);e&&(i=k1(e,()=>window.getSelection(),o))}let s=r;te(e=>e===s?e:s)},c=()=>{let e=window.getSelection();!e||e.isCollapsed||n(e)&&setTimeout(o,0)},l=null,u=!1,d=e=>{if(e.touches.length===1){let t=e.touches[0];l={x:t.clientX,y:t.clientY},u=!1}},f=e=>{if(u||!l||e.touches.length!==1)return;let t=e.touches[0],n=Math.abs(t.clientX-l.x),r=Math.abs(t.clientY-l.y);(n>10||r>10)&&(u=!0)},p=e=>{let r=u;l=null,u=!1;let i=window.getSelection();if(!i||i.rangeCount===0||i.isCollapsed){te(!1);return}let a=t.querySelector(`.xterm-accessibility-tree`);if(!a)return;if(!n(i)){te(!1);return}if(r)return;let s=e.target,c=s?a.contains(s):!1,d=!1;if(c&&s)try{d=i.containsNode(s,!0)}catch{d=!1}(!c||!d)&&setTimeout(o,0)};return document.addEventListener(`selectionchange`,s),document.addEventListener(`copy`,c),document.addEventListener(`touchstart`,d,{passive:!0}),document.addEventListener(`touchmove`,f,{passive:!0}),document.addEventListener(`touchend`,p,{passive:!0}),()=>{document.removeEventListener(`selectionchange`,s),document.removeEventListener(`copy`,c),document.removeEventListener(`touchstart`,d),document.removeEventListener(`touchmove`,f),document.removeEventListener(`touchend`,p),a(),fe.current=null,de.current=!1}},[Ne,R,e?.id]),(0,y.useEffect)(()=>{if(!R)return;let t=Ne.current;if(!t)return;let n=null,r=()=>{let e=Pe.current,r=t.querySelector(`.xterm`);if(!e||!r)return;let i=r.querySelector(`.xterm-screen`),a=r.querySelector(`.xterm-accessibility`),o=r.querySelector(`.xterm-accessibility-tree`);if(!i||!a||!o)return;n||=T0(o);let s=r.getBoundingClientRect(),c=i.getBoundingClientRect(),l=c.left-s.left,u=c.top-s.top;Object.assign(a.style,{left:`${l}px`,top:`${u}px`,right:`auto`,bottom:`auto`,width:`${c.width}px`,height:`${c.height}px`});let d=c.width/e.cols,f=c.height/e.rows,p=document.createElement(`span`);p.textContent=`0`.repeat(200),p.style.cssText=`position:absolute;visibility:hidden;white-space:pre;pointer-events:none;letter-spacing:0px`,p.setAttribute(D1,``),o.appendChild(p);let m=p.getBoundingClientRect().width/200;p.remove();let h=Math.max(-2,Math.min(2,d-m));t.style.setProperty(`--xterm-font-size`,`${e.options.fontSize}px`),t.style.setProperty(`--xterm-cell-height`,`${f}px`),t.style.setProperty(`--xterm-a11y-letter-spacing`,`${h}px`)},i=performance.now();r();let a=Math.round(performance.now()-i);a>10&&uR(`switch_a11y_overlay`,{sessionId:e?.id,a11yMs:a});let o=window.requestAnimationFrame(r),s=window.setTimeout(r,100),c=()=>window.requestAnimationFrame(r);return window.visualViewport?.addEventListener(`resize`,c),window.addEventListener(`orientationchange`,c),()=>{window.cancelAnimationFrame(o),window.clearTimeout(s),window.visualViewport?.removeEventListener(`resize`,c),window.removeEventListener(`orientationchange`,c),n?.()}},[Ne,M,R,e?.id,Pe]);let st=(0,y.useRef)(H);(0,y.useEffect)(()=>{st.current=H},[H]);let ct=(0,y.useRef)(e?.id);(0,y.useEffect)(()=>{ct.current=e?.id},[e?.id]);let lt=(0,y.useRef)(E);(0,y.useEffect)(()=>{lt.current=E},[E]);let ut=(0,y.useRef)(!1),dt=(0,y.useRef)(`idle`);(0,y.useEffect)(()=>{if(!R)return;let e=Ne.current;if(!e)return;let t=null,n=()=>e.querySelector(`.xterm-helper-textarea`),r=e=>{e.target===n()&&(dt.current=`focused`)},i=e=>{e.target===n()&&(t!==null&&window.clearTimeout(t),t=window.setTimeout(()=>{t=null;let e=n(),r=typeof document.hasFocus!=`function`||document.hasFocus();document.activeElement!==e&&document.visibilityState!==`hidden`&&r&&(dt.current=`idle`)},0))},a=()=>{let e=n();(document.activeElement===e||dt.current===`focused`)&&(dt.current=`interrupted`)},o=()=>{dt.current===`interrupted`&&(dt.current=`armed`)},s=()=>{document.visibilityState===`hidden`?a():o()},c=e=>{e.persisted&&o()};return document.addEventListener(`focusin`,r),document.addEventListener(`focusout`,i),document.addEventListener(`visibilitychange`,s),window.addEventListener(`blur`,a),window.addEventListener(`focus`,o),window.addEventListener(`pageshow`,c),()=>{document.removeEventListener(`focusin`,r),document.removeEventListener(`focusout`,i),document.removeEventListener(`visibilitychange`,s),window.removeEventListener(`blur`,a),window.removeEventListener(`focus`,o),window.removeEventListener(`pageshow`,c),t!==null&&window.clearTimeout(t),dt.current=`idle`}},[Ne,R,e?.id]),(0,y.useEffect)(()=>{let t=Ne.current;if(!t||!e?.id||!B&&!R)return;let n={x:0,y:0},r=0,i=!1,a=null,o=0,s=0,c=0,l=Math.round(M*N),u=null,d=null,f=!1,p=null,m=()=>{let e=window.getComputedStyle(t).getPropertyValue(`--xterm-cell-height`).trim(),n=Number.parseFloat(e);return!Number.isNaN(n)&&n>0?n:Math.round(M*N)},h=()=>t.querySelector(`.xterm-helper-textarea`),g=e=>{let n=Pe.current;if(!n)return null;let r=(t.querySelector(`.xterm`)?.querySelector(`.xterm-screen`))?.getBoundingClientRect();if(!r||r.width<=0||r.height<=0)return null;let i=r.width/n.cols,a=r.height/n.rows;return i<=0||a<=0?null:{col:Math.min(n.cols,Math.max(1,Math.floor((e.clientX-r.left)/i)+1)),row:Math.min(n.rows,Math.max(1,Math.floor((e.clientY-r.top)/a)+1))}},_=()=>{let e=h();e&&document.activeElement!==e&&(e.disabled=!0)},v=()=>{let e=h();e&&(e.disabled=!1)};_();let y=()=>{if(Fe.current)return;let e=h();e&&(e.disabled=!1,e.focus())},b=()=>{u!==null&&(cancelAnimationFrame(u),u=null),s=0},x=()=>{d!==null&&(clearTimeout(d),d=null)},S=(e,t,n)=>{let r=ct.current;return r?(lt.current({type:`terminal-input`,sessionId:r,data:`\x1b[<${e};${t.col};${t.row}${n}`}),!0):!1},C=e=>{let t=ct.current;if(!t||e===0)return!1;let n=Pe.current,r=n?.cols??80,i=n?.rows??24,a=Math.floor(r/2),o=Math.floor(i/2),s=e>0?65:64,c=Math.abs(e),l=e<0;for(let e=0;e<c;e++)lt.current({type:`terminal-input`,sessionId:t,data:`\x1b[<${s};${a};${o}M`});return l&&!Re.current&&ze(!0),l},w=e=>{let t=ct.current,n=g(e);return!t||!n?!1:(lt.current({type:`terminal-input`,sessionId:t,data:`\x1b[<0;${n.col};${n.row}M\x1b[<0;${n.col};${n.row}m`}),!0)},T=e=>{if(!R||!Re.current)return!1;let t=g(e);return t?(f=!0,p=t,_(),b3(),S(0,t,`M`)):!1},E=e=>{let t=g(e);return t?p&&p.col===t.col&&p.row===t.row?!0:(p=t,S(32,t,`M`)):!1},D=e=>{let t=e?g(e):p;return f=!1,p=null,t?S(0,t,`m`):!1},O=()=>{x(),f=!1,p=null,a=null,s=0,c=0},k=()=>{if(!R)return!1;let e=window.getSelection();if(!e||e.isCollapsed)return!1;let n=t.querySelector(`.xterm-accessibility-tree`);if(!n)return!1;let r=e.anchorNode,i=e.focusNode;return!!r&&n.contains(r)||!!i&&n.contains(i)},A=()=>{!R||!de.current||k()||fe.current?.()},j=e=>{if(b(),A(),$e.current||ie){O();return}if(st.current){O();return}if(dt.current===`armed`&&!Fe.current&&(dt.current=`idle`,y()),e.touches.length===1){let t=e.touches[0];if(n={x:t.clientX,y:t.clientY},r=performance.now(),i=!1,a=t.clientY,o=r,s=0,c=0,l=m(),v(),R&&Re.current&&e.target!==h()){let e={clientX:t.clientX,clientY:t.clientY};d=setTimeout(()=>{d=null,!(i||$e.current||ie)&&(st.current||k()||T(e))},350)}}},P=e=>{if(e.touches.length!==1||a===null)return;if(A(),$e.current||ie){O();return}let t=performance.now(),r=e.touches[0],u=r.clientX,d=r.clientY;if(f){e.preventDefault(),e.stopPropagation(),E(r),a=d,o=t;return}if(st.current||k()){O();return}e.preventDefault(),e.stopPropagation();let p=Math.abs(u-n.x),m=Math.abs(d-n.y);!i&&(p>6||m>6)&&(i=!0,x(),_());let h=a-d,g=t-o;if(a=d,o=t,g>0){let e=h/g;s=s*.7+e*.3}c+=h;let v=Math.max(6,l*.6),y=Math.trunc(c/v);y!==0&&(C(y),c-=y*v)},F=e=>{let t=s,n=performance.now()-r;if(x(),f){D(e.changedTouches[0]),O(),e.preventDefault(),e.stopPropagation();return}if(O(),$e.current||ie)return;let a=k();if(st.current&&!a&&fe.current?.(),st.current||a){Fe.current&&(ut.current=!0);return}if(!i){if(R&&e.target===h()||R&&n>=350)return;if(Re.current){let t=e.changedTouches[0];if(t&&w(t)){y(),e.preventDefault(),e.stopPropagation();return}}if(Fe.current){e.preventDefault(),e.stopPropagation(),ut.current=!0;return}y();return}if(Math.abs(t)>.12){let e=t,n=performance.now(),r=()=>{let t=performance.now(),i=t-n;n=t;let a=e*i;c+=a;let o=Math.max(6,l*.6),s=Math.trunc(c/o);s!==0&&(C(s),c-=s*o),e*=.95**(i/16.67),u=Math.abs(e)>.02?requestAnimationFrame(r):null};u=requestAnimationFrame(r)}},I=()=>{x(),f&&D(void 0),O()},L=e=>{ut.current&&=(e.preventDefault(),e.stopPropagation(),!1)},z={passive:!0,capture:!0},V={passive:!1,capture:!0},ee={passive:!1,capture:!0},H={capture:!0};return t.addEventListener(`touchstart`,j,z),t.addEventListener(`touchmove`,P,V),t.addEventListener(`touchend`,F,ee),t.addEventListener(`touchcancel`,I,z),t.addEventListener(`mousedown`,L,H),()=>{t.removeEventListener(`touchstart`,j,z),t.removeEventListener(`touchmove`,P,V),t.removeEventListener(`touchend`,F,ee),t.removeEventListener(`touchcancel`,I,z),t.removeEventListener(`mousedown`,L,H),x();let e=h();e&&(e.disabled=!1)}},[e?.id,Ne,Pe,R,B,ie,M,N]);let ft=(0,y.useCallback)(t=>{if(!(!e||Ce)){if(je.pending||!He){je.capture(t,`typing`);return}E({type:`terminal-input`,sessionId:e.id,data:t})===!1&&je.capture(t,`typing`)}},[e,Ce,He,E,je]),mt=(0,y.useCallback)(t=>{if(!(!e||Ce)){if(je.pending||!He){je.capture(t,`paste`);return}Fe.current&&(E({type:`tmux-cancel-copy-mode`,sessionId:e.id}),ze(!1)),E({type:`terminal-paste`,sessionId:e.id,data:t})===!1&&je.capture(t,`paste`)}},[e,Ce,He,E,Fe,ze,je]),ht=(0,y.useCallback)(t=>{!e||Ce||!He||je.pending||(Fe.current&&(E({type:`tmux-cancel-copy-mode`,sessionId:e.id}),ze(!1)),E({type:`terminal-input`,sessionId:e.id,data:t}))},[e,Ce,He,E,Fe,ze,je.pending]),gt=(0,y.useCallback)(()=>{let e=Ne.current;if(!e)return;let t=e.querySelector(`.xterm-helper-textarea`);t&&(t.removeAttribute(`disabled`),t.focus())},[Ne]),_t=m2({sessionId:e?.id??null,disabled:o!==`connected`||Ce||!He||je.pending,fileUploadsAllowed:!be,agentType:e?.agentType,onPasteText:mt,onPasteImage:ht,onRefocus:gt});ve.current=_t.paste,ye.current=_t.fail;let vt=()=>{!e||Ce||!He||!je.text||je.persistence===`sent-remove-failed`||(Fe.current&&(E({type:`tmux-cancel-copy-mode`,sessionId:e.id}),ze(!1)),E({type:`terminal-paste`,sessionId:e.id,data:je.text})!==!1&&(je.sent(),gt()))},yt=(0,y.useCallback)(()=>{if(typeof document>`u`)return!1;let e=Ne.current;if(!e)return!1;let t=e.querySelector(`.xterm-helper-textarea`);if(t&&document.activeElement===t)return!0;let n=document.activeElement,r=typeof HTMLInputElement<`u`&&n instanceof HTMLInputElement,i=typeof HTMLTextAreaElement<`u`&&n instanceof HTMLTextAreaElement;return r||i||n&&n.isContentEditable?!1:!!document.documentElement?.classList?.contains(`keyboard-visible`)},[Ne]);(0,y.useEffect)(()=>{if(!R)return;let e=Ne.current;if(!e)return;let t=e.querySelector(`.xterm-accessibility`),n=e.querySelector(`.xterm-accessibility-tree`);if(!t||!n)return;let r=()=>{let r=e.querySelector(`.xterm-helper-textarea`);r&&document.activeElement===r&&!st.current?(t.style.pointerEvents=`none`,n.style.pointerEvents=`none`):(t.style.removeProperty(`pointer-events`),n.style.removeProperty(`pointer-events`))};return r(),document.addEventListener(`focusin`,r),document.addEventListener(`focusout`,r),()=>{document.removeEventListener(`focusin`,r),document.removeEventListener(`focusout`,r)}},[Ne,R,H]),(0,y.useEffect)(()=>{let e=Ne.current;e&&(e.inert=!!r)},[Ne,r]);let bt=A&&!!e&&t.length>1;return(0,k.jsxs)(`section`,{className:`flex min-w-0 flex-1 flex-col bg-base terminal-mobile-overlay md:relative md:inset-auto ${R?`ios-native-term-selection`:``} ${R?`ios-native-paste-prototype`:``}`,"data-testid":`terminal-panel`,"data-compact-mobile-controls":O,onDragOver:t=>{Array.from(t.dataTransfer.types).includes(`Files`)&&(t.preventDefault(),t.dataTransfer.dropEffect=e&&!Ce&&He&&!be&&o===`connected`?`copy`:`none`)},onDrop:t=>{if(!Array.from(t.dataTransfer.types).includes(`Files`)||(t.preventDefault(),t.stopPropagation(),!e||Ce||!He||be||o!==`connected`))return;let n=v1(t.dataTransfer);n.length&&_t.paste({text:``,files:n})},children:[(0,k.jsxs)(`div`,{className:`mobile-terminal-header flex min-h-[52px] shrink-0 items-center justify-between border-b border-border bg-elevated px-[6px] md:hidden`,children:[(0,k.jsxs)(`div`,{className:`flex min-w-0 items-center gap-[7px]`,children:[(0,k.jsx)(`button`,{onClick:()=>ae(!0),className:Jt(`neutral`),"aria-label":`Open session menu`,"aria-expanded":ie,children:(0,k.jsx)(Ie,{width:K.primary,height:K.primary})}),e?(0,k.jsxs)(`div`,{className:`flex min-w-[72px] flex-col items-start gap-px leading-none`,children:[se?(0,k.jsx)(`input`,{ref:he,type:`text`,value:le,onChange:e=>ue(e.target.value),onBlur:it,onKeyDown:at,className:`w-full max-w-[112px] rounded border border-border bg-surface px-2 py-0.5 text-sm font-medium text-primary outline-none focus:border-accent`}):(0,k.jsx)(`span`,{className:`max-w-[112px] truncate text-sm font-medium text-primary`,children:e.agentSessionName||e.name}),(0,k.jsx)(`span`,{className:`shrink-0 text-[10px] ${o===`connected`?D0[e.status]:`text-approval`}`,children:o===`connected`?E0[e.status]:o})]}):r?(0,k.jsxs)(`div`,{className:`flex min-w-0 flex-col items-start gap-px leading-none`,children:[(0,k.jsx)(`span`,{className:`max-w-[112px] truncate text-sm font-medium text-primary`,children:Te}),(0,k.jsx)(`span`,{className:`text-[10px] font-medium text-blue-400`,children:`Hibernating`})]}):(0,k.jsx)(`span`,{className:`text-sm font-medium text-primary`,children:`Sessions`})]}),(0,k.jsxs)(`div`,{className:`flex shrink-0 items-center gap-[4px]`,children:[(0,k.jsx)(`button`,{onClick:p,className:Jt(`primary`),title:`New session (${I}N)`,"aria-label":`New session`,children:(0,k.jsx)(Je,{width:K.primary,height:K.primary})}),e&&we&&(0,k.jsx)(`button`,{disabled:Ve,onClick:()=>ne(!0),className:Jt(`danger`),title:`Kill session (${I}X)`,"aria-label":`Kill session`,children:(0,k.jsx)(ot,{width:K.primary,height:K.primary})}),Oe&&(0,k.jsx)(`button`,{onClick:nt,className:`${Jt(`neutral`,`hidden`)} min-[360px]:flex`,title:`Hibernate session`,"aria-label":`Hibernate session`,children:(0,k.jsx)(Be,{width:K.primary,height:K.primary})}),r&&(0,k.jsx)(`button`,{onClick:()=>_(r.sessionId),className:`mobile-header-wake btn btn-primary h-[44px] px-3 text-xs`,children:`Wake`}),e&&(0,k.jsxs)(`div`,{className:`relative`,ref:pe,children:[(0,k.jsx)(`button`,{onClick:()=>re(!W),className:Jt(`neutral`),title:`More options`,"aria-label":`More options`,children:(0,k.jsx)(me,{width:K.primary,height:K.primary})}),W&&(0,k.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-20 min-w-[140px] rounded-md border border-border bg-elevated shadow-lg py-1`,children:[we&&(0,k.jsxs)(`button`,{onClick:rt,className:`flex min-h-[44px] w-full items-center gap-2 px-3 py-2 text-left text-sm text-secondary hover:bg-hover hover:text-primary`,children:[(0,k.jsx)(ge,{width:K.default,height:K.default}),`Rename`]}),Oe&&(0,k.jsxs)(`button`,{onClick:nt,className:`flex min-h-[44px] w-full items-center gap-2 px-3 py-2 text-left text-sm text-secondary hover:bg-hover hover:text-primary`,children:[(0,k.jsx)(Be,{width:K.default,height:K.default}),`Hibernate`]}),(0,k.jsxs)(`button`,{onClick:()=>{x(),re(!1)},className:`flex min-h-[44px] w-full items-center gap-2 px-3 py-2 text-left text-sm text-secondary hover:bg-hover hover:text-primary`,children:[(0,k.jsx)(et,{width:K.default,height:K.default}),`Settings`]})]})]})]})]}),(0,k.jsx)(i3,{session:e,ready:o===`connected`&&He,children:(0,k.jsxs)(`div`,{className:`relative min-w-0 flex-1`,"data-testid":`terminal-content`,children:[bt&&(0,k.jsx)(y3,{sessions:t,selectedId:e.id,isOpen:ie,onOpen:()=>ae(!0)}),(0,k.jsx)(`div`,{ref:Ne,className:`absolute inset-0 overflow-clip ${bt?`left-[8px] md:left-0`:``}`,style:{backgroundColor:D.background}}),e&&Ke.state.status!==`closed`&&(0,k.jsx)(n4,{state:Ke.state,containerRef:Ne,terminalRef:Pe,background:D.background??`#000`,foreground:D.foreground??`#fff`,rejoinWrapped:Xe,onCopied:Ke.close}),e&&!Ce&&!He&&(0,k.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":`terminal-recovery-status`,className:`absolute top-2 left-2 z-50 flex items-center gap-1.5 rounded-lg bg-black/60 px-2.5 py-1.5 text-xs text-white/90 shadow-lg backdrop-blur-md`,children:[(0,k.jsx)(pt,{width:K.pill,height:K.pill,className:Ve||o!==`connected`?`animate-spin`:``}),o===`connected`?Ve?`Restoring terminal`:`Terminal unavailable`:o===`disconnected`?`Disconnected`:`Reconnecting`,(0,k.jsx)(`span`,{className:`text-white/70`,children:`· Input paused`})]}),je.pending&&e&&!Ce&&(0,k.jsx)(a3,{text:je.text,sessionName:e.name,ready:He,atLimit:je.atLimit,truncated:je.truncated,persistence:je.persistence,onSave:je.save,onDiscardOthers:je.hasOtherDrafts?je.discardOthers:void 0,onEdit:je.edit,onSend:vt,onDiscard:()=>{je.discard(),gt()}},Ae),Ue&&e&&(0,k.jsxs)(`div`,{className:`absolute ${V&&!H?`bottom-20`:`bottom-8`} left-1/2 z-30 flex max-w-[calc(100%-2rem)] -translate-x-1/2 items-center gap-2 rounded-lg border border-border bg-elevated/95 px-2 py-2 shadow-lg backdrop-blur-sm md:hidden`,children:[(0,k.jsx)(`span`,{className:`max-w-[12rem] truncate text-xs text-secondary md:max-w-[18rem]`,children:`Selection ready`}),(0,k.jsxs)(`button`,{type:`button`,onClick:We,className:`relative flex h-8 shrink-0 items-center justify-center gap-1.5 rounded bg-accent px-2.5 text-xs font-medium text-white hover:bg-accent/90 active:scale-95 transition-all [@media(pointer:coarse)]:before:absolute [@media(pointer:coarse)]:before:inset-[calc(50%-22px)] [@media(pointer:coarse)]:before:content-['']`,title:`Copy selection`,"aria-label":`Copy selection`,children:[(0,k.jsx)(oe,{width:K.default,height:K.default}),`Copy`]}),(0,k.jsx)(`button`,{type:`button`,onClick:Ge,className:`relative flex h-8 w-8 shrink-0 items-center justify-center rounded border border-border text-secondary hover:bg-hover hover:text-primary active:scale-95 transition-all [@media(pointer:coarse)]:before:absolute [@media(pointer:coarse)]:before:inset-[calc(50%-22px)] [@media(pointer:coarse)]:before:content-['']`,title:`Dismiss`,"aria-label":`Dismiss`,children:(0,k.jsx)(ot,{width:K.default,height:K.default})})]}),!e&&(0,k.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center text-sm text-muted`,children:r?null:`Select a session to view terminal`}),e&&Ce&&(0,k.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center text-center text-sm text-muted`,children:`Remote session (read-only). Use SSH to attach on the host.`}),r&&(0,k.jsx)(`div`,{className:`absolute inset-0 z-10 overflow-y-auto bg-base`,children:(0,k.jsxs)(`div`,{className:`mx-auto flex min-h-full w-full max-w-5xl flex-col gap-4 p-4 md:p-6`,children:[(0,k.jsx)(`div`,{className:`border-b border-border pb-4`,children:(0,k.jsxs)(`div`,{className:`flex flex-col gap-3 md:flex-row md:items-start md:justify-between`,children:[(0,k.jsxs)(`div`,{className:`min-w-0 space-y-2`,children:[(0,k.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-sm`,children:[(0,k.jsx)(`h2`,{className:`min-w-0 truncate text-lg font-semibold text-primary`,children:Te}),(0,k.jsx)(`span`,{className:`rounded-full bg-blue-500/15 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-blue-400`,children:`Hibernating`}),Ee&&(0,k.jsx)(`span`,{className:`text-muted`,children:Ee}),(0,k.jsxs)(`span`,{className:`text-muted`,children:[`Last active `,De]})]}),r.lastResumeError&&(0,k.jsxs)(`div`,{className:`inline-flex items-center gap-1 rounded bg-amber-500/15 px-2 py-1 text-xs text-amber-400`,title:`Last wake failed: ${r.lastResumeError}`,children:[(0,k.jsx)(L,{width:K.pill,height:K.pill}),`Last wake failed`]}),r.lastUserMessage&&(0,k.jsx)(`p`,{className:`max-h-28 max-w-3xl overflow-y-auto whitespace-pre-wrap break-words pr-2 text-sm leading-6 text-secondary`,children:r.lastUserMessage})]}),(0,k.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,k.jsx)(`button`,{type:`button`,onClick:()=>_(r.sessionId),className:`btn btn-primary hidden md:inline-flex`,children:`Wake`}),b&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>b(r.sessionId),className:`btn btn-secondary`,children:`Move to History`})]})]})}),(0,k.jsx)(GL,{session:r})]})}),Le&&e&&!H?(0,k.jsxs)(`button`,{type:`button`,onClick:Ze,className:`absolute bottom-14 left-1/2 z-20 flex h-10 items-center justify-center rounded-full border border-amber-400/35 bg-amber-500/20 text-amber-100 shadow-lg backdrop-blur-sm transition-all hover:bg-amber-500/30 active:scale-95 md:hidden ${Zt}`,style:{transform:`translateX(-50%)`},title:`Exit tmux copy mode and return to live output`,"aria-label":`Exit copy mode`,children:[(0,k.jsx)(`span`,{className:`px-3 text-[11px] font-semibold uppercase tracking-wide`,children:`Copy mode`}),(0,k.jsx)(`span`,{className:`self-stretch border-l border-amber-400/25`,"aria-hidden":`true`}),(0,k.jsx)(`span`,{className:`px-3 text-sm font-medium`,children:`Exit`})]}):V&&e&&!H?(0,k.jsxs)(`button`,{type:`button`,onClick:Ze,className:`absolute bottom-8 left-1/2 z-20 flex h-10 px-4 items-center justify-center gap-1.5 rounded-full bg-blue-600/90 text-white shadow-lg hover:bg-blue-600 active:scale-95 transition-all md:hidden ${Zt}`,style:{transform:`translateX(-50%)`},title:`Scroll to bottom`,"aria-label":`Scroll to bottom`,children:[(0,k.jsx)(z,{width:K.primary,height:K.primary}),(0,k.jsx)(`span`,{className:`text-sm font-medium`,children:`Jump to bottom`})]}):null]})}),(0,k.jsx)(d2,{..._t}),(0,k.jsx)(I0,{session:e,hibernatingSession:r,hibernatingDisplayName:Te,showHostBadge:ke,sessionCount:t.length,connectionStatus:o,isSwitching:Ve,canControl:we,canHibernate:Oe,modDisplay:I,onKill:()=>ne(!0),onHibernate:nt,onWake:()=>r&&_(r.sessionId),onRename:t=>{let n=e?.id??r?.sessionId;n&&h(n,t)},onDuplicate:e&&g?()=>g(e.id):void 0,onMoveToHistory:r&&b?()=>b(r.sessionId):void 0,isTmuxCopyMode:Le,showJumpToBottom:V&&!H,onJumpToBottom:Ze,selectionReady:!!Ue,onCopySelection:We,onDismissSelection:Ge}),e&&(0,k.jsx)(k2,{onSendKey:ft,onPasteText:mt,onPasteImage:ht,disabled:o!==`connected`||Ce||!He||je.pending,sessions:t.map(e=>({id:e.id,name:e.name,status:e.status})),currentSessionId:e.id,agentType:e.agentType,fileUploadsAllowed:!be,onSelectSession:d,hideSessionSwitcher:!0,onRefocus:gt,isKeyboardVisible:yt,onSelectText:Ce?void 0:Ye,snapshotActions:qe?{onDone:Ke.close,onRefresh:Ke.refresh,busy:Ke.state.status===`loading`||Ke.state.status===`ready`&&Ke.state.refreshing}:void 0}),(B||R)&&(0,k.jsx)(_3,{isOpen:ie,onClose:()=>ae(!1),sessions:n??t,hibernatingSessions:i,historySessions:a,selectedSessionId:e?.id??null,selectedHibernatingSessionId:r?.sessionId??null,onSelect:d,onSelectHibernating:f,onRename:h,onResume:_,onHibernate:v,onMoveToHistory:b,onNewSession:p,onOpenHistory:S,subscribe:l,loading:C,error:w}),U&&e&&(0,k.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50`,children:(0,k.jsxs)(`div`,{className:`mx-4 w-full max-w-sm rounded-lg border border-border bg-elevated p-4 shadow-xl`,children:[(0,k.jsx)(`h3`,{className:`text-base font-medium text-primary mb-2 text-balance`,children:`Kill Session`}),(0,k.jsxs)(`p`,{className:`text-sm text-secondary mb-4 text-pretty`,children:[`Kill "`,e.agentSessionName||e.name,`"? The process will be terminated. Conversation history is preserved in logs.`]}),(0,k.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,k.jsx)(`button`,{onClick:()=>ne(!1),className:`btn py-1.5 px-3 text-sm`,children:`Cancel`}),(0,k.jsx)(`button`,{ref:_e,onClick:tt,className:`btn btn-danger py-1.5 px-3 text-sm`,children:`Kill Session`})]})]})})]})}function S3({onSelect:e,onCancel:t,initialPath:n}){let[r,i]=(0,y.useState)(n||`~`),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!0),[d,f]=(0,y.useState)(-1),p=(0,y.useRef)(null),m=G(e=>e.recentPaths),h=(0,y.useCallback)(async e=>{p.current?.abort();let t=new AbortController;p.current=t;let{signal:n}=t;u(!0),c(null),o(null),f(-1),i(e);try{let r=await fetch(`/api/directories?path=${encodeURIComponent(e)}`,{signal:n});if(!r.ok){let e=await r.json();throw Error(e.message||`Failed to load directory`)}let a=await r.json();if(p.current!==t)return;o(a),i(a.path)}catch(e){if(p.current!==t)return;let n=e;n?.name!==`AbortError`&&c(n?.message||`Failed to load directory`)}finally{p.current===t&&u(!1)}},[]);(0,y.useEffect)(()=>(h(n||`~`),()=>{p.current?.abort()}),[h,n]);let g=a?.directories??[],_=a?.path||r,v=a?.parent;return(0,y.useEffect)(()=>{let n=n=>{if(n.key===`Escape`){n.preventDefault(),t();return}if(!l){if(n.key===`ArrowDown`){n.preventDefault(),f(e=>g.length===0?-1:e<0?0:Math.min(e+1,g.length-1));return}if(n.key===`ArrowUp`){n.preventDefault(),f(e=>g.length===0?-1:e<0?g.length-1:Math.max(e-1,0));return}if(n.key===`Enter`){n.preventDefault();let t=g[d];t?h(t.path):_&&e(_);return}n.key===`Backspace`&&v&&(n.preventDefault(),h(v))}};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[g,_,h,d,l,t,e,v]),(0,k.jsx)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":`Directory browser`,className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/60 p-4`,onClick:e=>{e.target===e.currentTarget&&t()},"data-testid":`directory-browser`,children:(0,k.jsxs)(`div`,{className:`w-full max-w-lg border border-border bg-elevated p-4`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-3 border-b border-border pb-2`,children:[(0,k.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>{v&&h(v)},disabled:!v||l,children:`Up`}),(0,k.jsx)(`div`,{className:`min-w-0 flex-1 truncate text-xs font-mono text-secondary`,title:_,"data-testid":`directory-current-path`,children:_})]}),(0,k.jsx)(`div`,{className:`mt-3 max-h-60 overflow-y-auto border border-border bg-surface`,children:l?(0,k.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted`,"data-testid":`directory-loading`,children:`Loading directories...`}):s?(0,k.jsxs)(`div`,{className:`px-3 py-4 text-xs`,"data-testid":`directory-error`,children:[(0,k.jsx)(`p`,{className:`text-danger`,children:s}),(0,k.jsx)(`button`,{type:`button`,className:`btn mt-3`,onClick:()=>h(r),children:`Retry`})]}):g.length===0?(0,k.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted`,"data-testid":`directory-empty`,children:`No subdirectories`}):(0,k.jsx)(`div`,{className:`py-1`,children:g.map((e,t)=>(0,k.jsxs)(`button`,{type:`button`,onClick:()=>h(e.path),onMouseEnter:()=>f(t),className:`flex w-full items-center gap-2 px-3 py-2 text-left text-xs ${t===d?`bg-hover text-primary`:`text-secondary`}`,"data-testid":`directory-entry`,"data-entry-name":e.name,"data-entry-path":e.path,children:[(0,k.jsx)(Ee,{width:K.default,height:K.default,className:`shrink-0 text-muted`,"aria-hidden":`true`}),(0,k.jsx)(`span`,{className:`truncate`,children:e.name})]},e.path))})}),a?.truncated?(0,k.jsx)(`p`,{className:`mt-2 text-[10px] text-muted`,children:`Showing first 200 directories.`}):null,(0,k.jsxs)(`div`,{className:`mt-4 border-t border-border pt-3`,children:[(0,k.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-secondary`,children:`Recent`}),m.length===0?(0,k.jsx)(`p`,{className:`mt-2 text-xs text-muted`,children:`No recent paths yet.`}):(0,k.jsx)(`div`,{className:`mt-2 space-y-1`,children:m.map(e=>(0,k.jsx)(`button`,{type:`button`,className:`block w-full truncate text-left text-xs text-secondary hover:text-primary`,onClick:()=>h(e),title:e,"data-testid":`directory-recent`,"data-recent-path":e,children:e},e))})]}),(0,k.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,k.jsx)(`button`,{type:`button`,onClick:t,className:`btn`,children:`Cancel`}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>{_&&e(_)},className:`btn btn-primary`,disabled:l||!_,children:`Select`})]})]})})}function C3(e){let t=e.trim();if(t.length>=2){let e=t[0],n=t[t.length-1];if(e===`'`&&n===`'`)return t.slice(1,-1).replace(/'\\''/g,`'`);if(e===`"`&&n===`"`)return t.slice(1,-1).replace(/\\"/g,`"`).replace(/\\\\/g,`\\`)}return t}function w3(e){let t=e.trim(),n=t.search(/\s/);if(n===-1||t.slice(0,n).split(`/`).pop()!==`bash`)return null;let r=n;for(;r<t.length&&/\s/.test(t[r]);)r++;let i=!1,a=!1;for(;r<t.length;){let e=r;for(;r<t.length&&!/\s/.test(t[r]);)r++;let n=t.slice(e,r);for(;r<t.length&&/\s/.test(t[r]);)r++;if(!n.startsWith(`-`)||n===`-`)return null;if(n===`--`)break;if(n.startsWith(`--`)||!/^-[a-zA-Z]+$/.test(n))continue;let o=n.slice(1);if(o.includes(`l`)&&(i=!0),o.includes(`c`)){a=!0;break}}if(!i||!a)return null;let o=t.slice(r).trim();return o?C3(o):null}function T3(e){return e?e===`claude-rp`?`claude`:e:null}function E3(e){let t=e.trim();if(!t)return``;let n=C3(t);return w3(n)??n}function D3(e){if(e===`claude`)return`claude`;if(e===`codex`)return`codex`;if(e===`pi`)return`pi`;if(e===`devin`||e===`devin-cli`)return`devin`;if(e===`grok`||e.startsWith(`grok-`))return`grok`;if(e===`omp`)return`omp`}function O3(e){let t=/\S+/g,n;for(;n=t.exec(e);){let e=n[0].toLowerCase().replace(/^["']+|["']+$/g,``);if([`npx`,`bunx`,`pnpm`,`yarn`,`env`].includes(e)||e.includes(`=`)||e.startsWith(`-`))continue;let t=e.includes(`@oh-my-pi/`)?`omp`:D3(e.split(`/`).pop()||e);return t?{agentType:t,end:n.index+n[0].length}:void 0}}function k3(e){let t=E3(e);if(t)return O3(t.toLowerCase().trim().replace(/^["']|["']$/g,``))?.agentType}var A3={claude:`--dangerously-skip-permissions`,codex:`--yolo`,grok:`--always-approve`,devin:`--permission-mode dangerous`,pi:null,omp:`--auto-approve`},j3={claude:[`--dangerously-skip-permissions`,`--permission-mode bypassPermissions`,`--permission-mode=bypassPermissions`],codex:[`--yolo`,`--dangerously-bypass-approvals-and-sandbox`],grok:[`--always-approve`,`--yolo`,`--dangerously-skip-permissions`,`--permission-mode bypassPermissions`,`--permission-mode=bypassPermissions`],devin:[`--permission-mode dangerous`,`--permission-mode=dangerous`],pi:[],omp:[`--auto-approve`,`--approval-mode yolo`,`--approval-mode=yolo`]};function M3(e){let t=T3(e);return t?A3[t]:null}function N3(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function P3(e){return RegExp(`(^|\\s)${N3(e)}(?=\\s|$)`,`g`)}function F3(e,t){return(t?[T3(t)].filter(e=>e!==null):Object.keys(j3)).some(t=>j3[t].some(t=>P3(t).test(e)))}function I3(e,t){let n=O3(e);return n?`${e.slice(0,n.end)} ${t}${e.slice(n.end)}`:null}function L3(e,t){let n=M3(t);if(!n)return e;let r=e.trim();if(!r||F3(r,t))return r;let i=I3(r,n);if(i)return i;let a=E3(r);if(a&&a!==r){let e=I3(a,n);if(e)return`bash -lc '${e.replace(/'/g,`'\\''`)}'`}return`${r} ${n}`}function R3(e,t){let n=T3(t);if(!n||F3(e,t))return null;if(n===`codex`){let t=/(^|\s)(--full-auto|--ask-for-approval|-a)(?=\s|=|$)/.exec(e);if(t)return`conflicts with ${t[2]}`}if(n===`omp`){let t=/(^|\s)--approval-mode(?:\s+|=)(always-ask|write)/.exec(e);if(t)return`conflicts with --approval-mode ${t[2]}`}let r=/(^|\s)--permission-mode(?:\s+|=)(\S+)/.exec(e);return r&&n!==`codex`?`conflicts with --permission-mode ${r[2]}`:null}function z3(e,t){let n=T3(t);if(!n)return e;let r=e;for(let e of j3[n])r=r.replace(P3(e),` `);return r.replace(/\s+/g,` `).trim()}function B3({isOpen:e,onClose:t,onCreate:n,defaultProjectDir:r,commandPresets:i,defaultPresetId:a,lastProjectPath:o,activeProjectPath:s,remoteHosts:c=[],remoteAllowControl:l=!1,initialHost:u,initialPath:d,initialCommand:f}){let[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(``),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(``),E=G(e=>e.yoloMode),D=G(e=>e.setYoloMode),O=(0,y.useRef)(null),A=(0,y.useRef)(null),j=(0,y.useRef)(null),M=(0,y.useRef)(!1),N=l&&c.length>0,P=e=>{if(!E)return e;let t=k3(e);return t&&!R3(e,t)?L3(e,t):e},F=e=>{let t=i.find(t=>t.id===e);t&&(v(e),x(P(zt(t))))},I=()=>{v(null),x(``)};if((0,y.useEffect)(()=>{let t=M.current;if(M.current=e,!e){m(``),g(``),v(null),x(``),C(!1),T(u??``),t&&setTimeout(()=>{if(typeof document>`u`||typeof document.querySelector!=`function`)return;let e=document.querySelector(`.xterm-helper-textarea`);e&&(e.removeAttribute(`disabled`),e.focus())},300);return}if(t)return;if(typeof document<`u`&&typeof document.querySelector==`function`){let e=document.querySelector(`.xterm-helper-textarea`);e&&typeof e.setAttribute==`function`&&(typeof e.blur==`function`&&e.blur(),e.setAttribute(`disabled`,`true`))}m(d?.trim()||s?.trim()||o||r||``),g(``),T(u??``);let n=f?.trim();if(n){let e=i.find(e=>zt(e)===n);e?(v(e.id),x(zt(e))):(v(null),x(n))}else{let e=i.find(e=>e.id===a);e?(v(a),x(P(zt(e)))):i.length>0?(v(i[0].id),x(P(zt(i[0])))):(v(null),x(``))}setTimeout(()=>{if(j.current?.focus(),A.current){let e=A.current;e.scrollLeft=e.scrollWidth}},50)},[s,i,a,r,e,o,u,d,f]),(0,y.useEffect)(()=>{if(!e||typeof window>`u`||typeof window.addEventListener!=`function`)return;let n=()=>O.current?Array.from(O.current.querySelectorAll(`input:not([disabled]), select:not([disabled]), button:not([disabled]):not([tabindex="-1"]), [tabindex="0"]`)):[],r=e=>{if(!S){if(e.key===`Escape`){typeof e.stopPropagation==`function`&&e.stopPropagation(),t();return}if(e.key===`Enter`){let t=document.activeElement;if(!t||t.tagName===`INPUT`||t.closest(`[data-testid="host-select"]`)||!t.closest(`[data-testid="command-select"]`))return;e.preventDefault(),typeof e.stopPropagation==`function`&&e.stopPropagation(),O.current?.requestSubmit();return}if(/^[0-9]$/.test(e.key)&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=document.activeElement;if(t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.tagName===`SELECT`||t.isContentEditable))return;let n;if(e.key===`0`)n=i.length;else if(n=Number(e.key)-1,n>=i.length)return;e.preventDefault(),typeof e.stopPropagation==`function`&&e.stopPropagation(),n===i.length?I():F(i[n].id),(O.current?.querySelectorAll?.(`[data-testid="command-select"] [role="radio"]`))?.[n]?.focus();return}if(e.key===`Tab`){e.preventDefault(),typeof e.stopPropagation==`function`&&e.stopPropagation();let t=n();if(t.length===0)return;let r=document.activeElement,i=t.indexOf(r),a;a=i===-1?e.shiftKey?t.length-1:0:e.shiftKey?i<=0?t.length-1:i-1:i>=t.length-1?0:i+1,t[a]?.focus()}}};return window.addEventListener(`keydown`,r),()=>window.removeEventListener(`keydown`,r)},[e,t,S,i,E]),!e)return null;let L=_===null,R=w!==``,z=k3(b),B=M3(z)!==null,V=z?F3(b,z):!1,ee=z&&!V?R3(b,z):null,H=!B||ee!==null,te=z?z===`pi`?`Pi has no permission prompts — nothing to enable`:ee??`Append ${M3(z)}`:`Enter a supported agent command (claude, codex, grok, devin)`,U=e=>{D(e),z&&x(e?L3(b,z):z3(b,z))},ne=e=>{e.preventDefault();let r=p.trim();if(!r)return;let i=b.trim();n(r,h.trim()||void 0,i||void 0,R?w:void 0),t()},W=[...i.map(e=>({id:e.id,label:e.label,isCustom:!1,agentType:e.agentType,command:e.command})),{id:`custom`,label:`Custom`,isCustom:!0,agentType:void 0,command:void 0}],re=[{id:``,label:`Local`,ok:!0,error:void 0},...c.map(e=>({id:e.host,label:e.host,ok:e.ok,error:e.error}))],ie=p.trim()||`~`;return(0,k.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`new-session-title`,"data-suspends-terminal":``,className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:e=>{e.target===e.currentTarget&&t()},children:[(0,k.jsxs)(`form`,{ref:O,onSubmit:ne,className:`w-full max-w-md border border-border bg-elevated p-6`,children:[(0,k.jsx)(`h2`,{id:`new-session-title`,className:`text-sm font-semibold uppercase tracking-wider text-primary text-balance`,children:`New Session`}),(0,k.jsxs)(`div`,{className:`mt-4 space-y-4`,children:[N&&(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`mb-1.5 block text-xs text-secondary`,children:`Host`}),(0,k.jsx)(`div`,{className:`flex flex-wrap gap-2`,role:`radiogroup`,"aria-label":`Host`,"data-testid":`host-select`,children:re.map((e,t)=>{let n=w===e.id,r=!e.ok&&!n;return(0,k.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":n,"aria-label":e.label,title:e.ok?void 0:e.error||`Unreachable`,tabIndex:n?0:-1,onClick:()=>T(e.id),onKeyDown:e=>{let n=t;if(e.key===`ArrowRight`||e.key===`ArrowDown`)e.preventDefault(),n=(t+1)%re.length;else if(e.key===`ArrowLeft`||e.key===`ArrowUp`)e.preventDefault(),n=(t-1+re.length)%re.length;else return;let r=re[n];T(r.id),(e.currentTarget.parentElement?.querySelectorAll(`[role="radio"]`))?.[n]?.focus()},className:`btn text-xs focus:outline-none focus:ring-2 focus:ring-primary ${n?`btn-primary`:``} ${r?`opacity-60`:``}`,children:e.label},e.id||`local`)})})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`mb-1.5 block text-xs text-secondary`,children:`Command`}),(0,k.jsx)(`div`,{className:`flex flex-wrap gap-2`,role:`radiogroup`,"aria-label":`Command preset`,"data-testid":`command-select`,children:W.map((e,t)=>{let n=e.isCustom?L:_===e.id,r=e.isCustom?`0`:t<9?String(t+1):null;return(0,k.jsxs)(`button`,{ref:n?j:void 0,type:`button`,role:`radio`,"aria-checked":n,"aria-keyshortcuts":r??void 0,tabIndex:n?0:-1,onClick:()=>{e.isCustom?I():F(e.id)},onKeyDown:e=>{let n=t;if(e.key===`ArrowRight`||e.key===`ArrowDown`)e.preventDefault(),n=(t+1)%W.length;else if(e.key===`ArrowLeft`||e.key===`ArrowUp`)e.preventDefault(),n=(t-1+W.length)%W.length;else return;let r=W[n];r.isCustom?I():F(r.id),(e.currentTarget.parentElement?.querySelectorAll(`[role="radio"]`))?.[n]?.focus()},className:`btn text-xs focus:outline-none focus:ring-2 focus:ring-primary ${n?`btn-primary`:``}`,children:[r&&(0,k.jsx)(`kbd`,{"aria-hidden":`true`,className:`shortcut-badge`,children:r}),(0,k.jsx)(_g,{agentType:e.agentType,command:e.command,className:`inline-block h-3.5 w-3.5 shrink-0`}),e.label]},e.id)})}),(0,k.jsx)(`input`,{value:b,onChange:e=>x(e.target.value),placeholder:`Enter command...`,className:`input mt-2 font-mono text-xs`}),(0,k.jsxs)(`label`,{className:`mt-2 flex items-center gap-2 text-xs ${H?`text-muted opacity-60`:`text-secondary`}`,title:te,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:V,disabled:H,onChange:e=>U(e.target.checked)}),`yolo mode — skip permission prompts`]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`mb-1.5 block text-xs text-secondary`,children:`Project Path`}),(0,k.jsxs)(`div`,{className:`flex gap-2`,children:[(0,k.jsx)(`input`,{ref:A,value:p,onChange:e=>m(e.target.value),placeholder:R?`/home/user/project`:s||o||r||`/Users/you/code/my-project`,className:`input flex-1 text-sm`}),!R&&(0,k.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>C(!0),children:`Browse`})]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`mb-1.5 block text-xs text-secondary`,children:`Display Name`}),(0,k.jsx)(`input`,{value:h,onChange:e=>g(e.target.value),placeholder:`auto-generated`,className:`input text-sm placeholder:italic`})]})]}),(0,k.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[(0,k.jsx)(`button`,{type:`button`,onClick:t,className:`btn`,children:`Cancel`}),(0,k.jsx)(`button`,{type:`submit`,className:`btn btn-primary`,children:`Create`})]})]}),S&&!R&&(0,k.jsx)(S3,{initialPath:ie,onSelect:e=>{m(e),C(!1)},onCancel:()=>C(!1)})]})}var V3=[{id:`new-sessions`,label:`New sessions`},{id:`session-list`,label:`Session list`},{id:`appearance`,label:`Appearance`},{id:`terminal`,label:`Terminal`},{id:`notifications`,label:`Notifications`}];function H3(e){return V3.some(t=>t.id===e)}function U3(e){return V3.find(t=>t.id===e)?.label??e}var W3=`agentboard-settings-page`,G3=`new-sessions`;function K3(){let e=w.getItem(W3);return H3(e)?e:G3}function q3(e){w.setItem(W3,e)}var J3=`h-[32px] max-md:h-[44px]`,Y3=`${J3} inline-flex shrink-0 items-center justify-center border text-[12px] transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent disabled:cursor-not-allowed disabled:opacity-50`,X3=`${Y3} border-border bg-surface px-3 text-secondary hover:bg-hover hover:text-primary`,Z3=`${Y3} w-[32px] max-md:w-[44px] border-border bg-surface text-secondary hover:bg-hover hover:text-primary`,Q3=`input ${J3} px-2 py-0 text-[13px] max-md:text-[16px] focus-visible:ring-2 focus-visible:ring-accent/40 disabled:opacity-50 aria-[invalid=true]:border-danger`;function $3(e,t){let[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(null),o=(0,y.useRef)({draft:n,stored:e,commit:t});o.current={draft:n,stored:e,commit:t},(0,y.useEffect)(()=>()=>{let{draft:e,stored:t,commit:n}=o.current;e!==null&&e!==t&&n(e)},[]);let s=()=>{if(n===null)return;if(n===e){r(null),a(null);return}let i=t(n);if(i){a(i);return}r(null),a(null)};return{value:n??e,error:i,dirty:n!==null,onChange:e=>{r(e.target.value),a(null)},onBlur:s,onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),s()):e.key===`Escape`&&n!==null&&(e.preventDefault(),r(null),a(null))}}}var e6=(0,y.forwardRef)(function({value:e,onCommit:t,describedBy:n,id:r,className:i,wrapperClassName:a,...o},s){let c=$3(e,t),l=r?`${r}-error`:void 0,u=[n,c.error?l:void 0].filter(Boolean).join(` `);return(0,k.jsxs)(`div`,{className:xE(`min-w-0`,a),children:[(0,k.jsx)(`input`,{...o,ref:s,id:r,value:c.value,onChange:c.onChange,onBlur:c.onBlur,onKeyDown:c.onKeyDown,"aria-invalid":c.error?!0:void 0,"aria-describedby":u||void 0,className:xE(Q3,i)}),c.error&&(0,k.jsx)(`p`,{id:l,className:xE(`text-[12px] leading-snug text-danger`,`mt-1`),role:`alert`,children:c.error})]})});function t6(e,t,n){let r=e.trim();return/^-?\d+$/.test(r)?Math.min(n,Math.max(t,Number.parseInt(r,10))):null}function n6({value:e,min:t,max:n,onChange:r,noun:i,labelledBy:a,describedBy:o}){return(0,k.jsxs)(`div`,{role:`group`,"aria-labelledby":a,"aria-describedby":o,className:`flex items-center`,children:[(0,k.jsx)(`button`,{type:`button`,className:Z3,"aria-label":`Decrease ${i}`,disabled:e<=t,onClick:()=>r(Math.max(t,e-1)),children:(0,k.jsx)(Re,{width:K.default,height:K.default})}),(0,k.jsx)(`output`,{"aria-live":`polite`,className:xE(J3,`flex w-10 items-center justify-center border-y border-border bg-base text-[13px] tabular-nums text-primary`),children:e}),(0,k.jsx)(`button`,{type:`button`,className:Z3,"aria-label":`Increase ${i}`,disabled:e>=n,onClick:()=>r(Math.min(n,e+1)),children:(0,k.jsx)(Je,{width:K.default,height:K.default})})]})}function r6({id:e,value:t,min:n,max:r,step:i,onChange:a,format:o,labelledBy:s,describedBy:c}){return(0,k.jsxs)(`div`,{className:xE(J3,`flex items-center gap-3`),children:[(0,k.jsx)(`input`,{id:e,type:`range`,min:n,max:r,step:i,value:t,"aria-labelledby":s,"aria-describedby":c,"aria-valuetext":o(t),onChange:e=>{let t=Number.parseFloat(e.target.value);Number.isFinite(t)&&a(Math.min(r,Math.max(n,t)))},className:`h-1 w-28 max-md:w-36 cursor-pointer appearance-none bg-border accent-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`}),(0,k.jsx)(`span`,{className:`w-10 text-right text-[13px] tabular-nums text-secondary`,children:o(t)})]})}function i6({options:e,value:t,onChange:n,labelledBy:r,describedBy:i,fill:a=!1}){let o=(0,y.useRef)([]),s=Math.max(0,e.findIndex(e=>e.value===t)),c=t=>{let r=e[t];r&&(n(r.value),o.current[t]?.focus())},l=(t,n)=>{let r=e.length-1,i=null;t.key===`ArrowRight`||t.key===`ArrowDown`?i=n===r?0:n+1:t.key===`ArrowLeft`||t.key===`ArrowUp`?i=n===0?r:n-1:t.key===`Home`?i=0:t.key===`End`&&(i=r),i!==null&&(t.preventDefault(),c(i))};return(0,k.jsx)(`div`,{role:`radiogroup`,"aria-labelledby":r,"aria-describedby":i,className:xE(`flex border border-border bg-base p-[2px]`,a?`w-full`:`w-max max-w-full`),children:e.map((e,t)=>{let n=t===s;return(0,k.jsx)(`button`,{ref:e=>{o.current[t]=e},type:`button`,role:`radio`,"aria-checked":n,tabIndex:n?0:-1,onClick:()=>c(t),onKeyDown:e=>l(e,t),className:xE(`h-[26px] max-md:h-[38px] min-w-0 whitespace-nowrap px-3 text-[12px] transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,a&&`flex-1`,n?`bg-hover text-primary shadow-[inset_0_0_0_1px_var(--border)]`:`text-muted hover:text-primary`),children:e.label},e.value)})})}function a6({controlled:e,default:t,name:n,state:r=`value`}){let{current:i}=y.useRef(e!==void 0),[a,o]=y.useState(t);return[i?e:a,y.useCallback(e=>{i||o(e)},[])]}var o6=y.createContext(void 0);function s6(){let e=y.useContext(o6);if(e===void 0)throw Error(mb(63));return e}var c6=function(e){return e.disabled=`data-disabled`,e.valid=`data-valid`,e.invalid=`data-invalid`,e.touched=`data-touched`,e.dirty=`data-dirty`,e.filled=`data-filled`,e.focused=`data-focused`,e}({}),l6={badInput:!1,customError:!1,patternMismatch:!1,rangeOverflow:!1,rangeUnderflow:!1,stepMismatch:!1,tooLong:!1,tooShort:!1,typeMismatch:!1,valid:null,valueMissing:!1},u6={valid(e){return e===null?null:e?{[c6.valid]:``}:{[c6.invalid]:``}}},d6=function(e){return e.checked=`data-checked`,e.unchecked=`data-unchecked`,e.disabled=`data-disabled`,e.readonly=`data-readonly`,e.required=`data-required`,e.valid=`data-valid`,e.invalid=`data-invalid`,e.touched=`data-touched`,e.dirty=`data-dirty`,e.filled=`data-filled`,e.focused=`data-focused`,e}({}),f6={...u6,checked(e){return e?{[d6.checked]:``}:{[d6.unchecked]:``}}};function p6(e,t){return{...e,state:{...e.state,valid:!t&&e.state.valid}}}var m6=y.createContext({formRef:{current:{fields:new Map}},errors:{},clearErrors:__,validationMode:`onSubmit`,submitAttemptedRef:{current:!1}});function h6(){return y.useContext(m6)}var g6=y.createContext({invalid:void 0,name:void 0,validityData:{state:l6,errors:[],error:``,value:``,initialValue:null},setValidityData:__,disabled:void 0,touched:!1,setTouched:__,dirty:!1,setDirty:__,filled:!1,setFilled:__,focused:!1,setFocused:__,validate:()=>null,validationMode:`onSubmit`,validationDebounceTime:0,shouldValidateOnChange:()=>!1,state:{disabled:!1,valid:null,touched:!1,dirty:!1,filled:!1,focused:!1},markedDirtyRef:{current:!1},validation:{getValidationProps:(e=v_)=>e,getInputValidationProps:(e=v_)=>e,inputRef:{current:null},commit:async()=>{}}});function _6(e=!0){let t=y.useContext(g6);if(t.setValidityData===__&&!e)throw Error(mb(28));return t}function v6(e){let{enabled:t=!0,value:n,id:r,name:i,controlRef:a,commit:o}=e,{formRef:s}=h6(),{invalid:c,markedDirtyRef:l,validityData:u,setValidityData:d}=_6(),f=N_(e.getValue);a_(()=>{if(!t)return;let e=n;e===void 0&&(e=f()),u.initialValue===null&&e!==null&&d(t=>({...t,initialValue:e}))},[t,d,n,u.initialValue,f]),a_(()=>{!t||!r||s.current.fields.set(r,{getValue:f,name:i,controlRef:a,validityData:p6(u,c),validate(e=!0){let t=n;t===void 0&&(t=f()),l.current=!0,e?_f.flushSync(()=>o(t)):o(t)}})},[o,a,t,s,f,r,c,l,i,u,n]),a_(()=>{let e=s.current.fields;return()=>{r&&e.delete(r)}},[s,r])}var y6=y.createContext({controlId:void 0,registerControlId:__,labelId:void 0,setLabelId:__,messageIds:[],setMessageIds:__,getDescriptionProps:e=>e});function b6(){return y.useContext(y6)}function x6(e={}){let{id:t,implicit:n=!1,controlRef:r}=e,{controlId:i,registerControlId:a}=b6(),o=dw(t),s=n?i:void 0,c=s_(()=>Symbol(`labelable-control`)),l=y.useRef(!1),u=y.useRef(t!=null),d=N_(()=>{!l.current||a===__||(l.current=!1,a(c.current,void 0))});return a_(()=>{if(a===__)return;let e;if(n){let n=r?.current;e=Cg(n)&&n.closest(`label`)!=null?t??null:s??o}else if(t!=null)u.current=!0,e=t;else if(u.current)e=o;else{d();return}if(e===void 0){d();return}l.current=!0,a(c.current,e)},[t,r,s,a,n,o,c,d]),y.useEffect(()=>d,[d]),i??o}function S6(e,t){let n=y.useRef(e),r=N_(t);a_(()=>{n.current!==e&&r(n.current)},[e,r]),a_(()=>{n.current=e},[e])}var C6=y.forwardRef(function(e,t){let{checked:n,className:r,defaultChecked:i,id:a,inputRef:o,name:s,nativeButton:c=!1,onCheckedChange:l,readOnly:u=!1,required:d=!1,disabled:f=!1,render:p,uncheckedValue:m,value:h,...g}=e,{clearErrors:_}=h6(),{state:v,setTouched:b,setDirty:x,validityData:S,setFilled:C,setFocused:w,shouldValidateOnChange:T,validationMode:E,disabled:D,name:O,validation:A}=_6(),{labelId:j}=b6(),M=D||f,N=O??s,P=N_(l),F=y.useRef(null),I=qy(F,o,A.inputRef),L=y.useRef(null),R=dw(),z=x6({id:a,implicit:!1,controlRef:L}),B=c?void 0:z,[V,ee]=a6({controlled:n,default:!!i,name:`Switch`,state:`checked`});v6({id:R,commit:A.commit,value:V,controlRef:L,name:N,getValue:()=>V}),a_(()=>{F.current&&C(F.current.checked)},[F,C]),S6(V,()=>{_(N),x(V!==S.initialValue),C(V),T()?A.commit(V):A.commit(V,!0)});let{getButtonProps:H,buttonRef:te}=$C({disabled:M,native:c}),U={id:c?z:R,role:`switch`,"aria-checked":V,"aria-readonly":u||void 0,"aria-required":d||void 0,"aria-labelledby":j,onFocus(){M||w(!0)},onBlur(){let e=F.current;!e||M||(b(!0),w(!1),E===`onBlur`&&A.commit(e.checked))},onClick(e){u||M||(e.preventDefault(),F.current?.dispatchEvent(new PointerEvent(`click`,{bubbles:!0,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey})))}},ne=y.useMemo(()=>Cb({checked:V,disabled:M,id:B,name:N,required:d,style:N?tb:eb,tabIndex:-1,type:`checkbox`,"aria-hidden":!0,ref:I,onChange(e){if(e.nativeEvent.defaultPrevented)return;let t=e.target.checked,n=Wy(Iy,e.nativeEvent);P?.(t,n),!n.isCanceled&&ee(t)},onFocus(){L.current?.focus()}},A.getInputValidationProps,h===void 0?v_:{value:h}),[V,M,I,B,N,P,d,ee,A,h]),W=y.useMemo(()=>({...v,checked:V,disabled:M,readOnly:u,required:d}),[v,V,M,u,d]),re=Pb(`span`,e,{state:W,ref:[t,L,te],props:[U,A.getValidationProps,g,H],stateAttributesMapping:f6});return(0,k.jsxs)(o6.Provider,{value:W,children:[re,!V&&N&&m!==void 0&&(0,k.jsx)(`input`,{type:`hidden`,name:N,value:m}),(0,k.jsx)(`input`,{...ne})]})}),w6=y.forwardRef(function(e,t){let{render:n,className:r,...i}=e,{state:a}=_6(),o=s6();return Pb(`span`,e,{state:{...a,...o},ref:t,stateAttributesMapping:f6,props:i})});function T6({checked:e,onCheckedChange:t,disabled:n,className:r,ariaLabel:i,id:a,ariaLabelledBy:o,ariaDescribedBy:s}){return(0,k.jsx)(C6,{checked:e,onCheckedChange:t,disabled:n,"aria-label":i,id:a,"aria-labelledby":o,"aria-describedby":s,className:xE(`group relative inline-flex h-6 w-10 shrink-0 cursor-pointer items-center rounded-full transition-colors`,`bg-border data-[checked]:bg-accent`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-bg-base`,`disabled:cursor-not-allowed disabled:opacity-50`,r),children:(0,k.jsx)(w6,{className:xE(`pointer-events-none block size-4 rounded-full bg-white shadow-sm transition-transform`,`translate-x-1 group-data-[checked]:translate-x-5`)})})}function E6({ids:e}){return(0,k.jsx)(i6,{options:[{value:`light`,label:`Light`},{value:`dark`,label:`Dark`},{value:`system`,label:`System`}],value:m0(e=>e.theme),onChange:m0(e=>e.setTheme),labelledBy:e.label,describedBy:e.description})}function D6({ids:e}){let t=G(e=>e.fontOption),n=G(e=>e.setFontOption);return(0,k.jsx)(`select`,{id:e.control,value:t,"aria-describedby":e.description,onChange:e=>n(e.target.value),className:`${Q3} w-44 max-md:w-full`,children:Pt.map(e=>(0,k.jsx)(`option`,{value:e.id,children:e.label},e.id))})}function O6({ids:e}){let t=G(e=>e.customFontFamily);return(0,k.jsx)(e6,{id:e.control,value:t,placeholder:`"Fira Code", monospace`,describedBy:e.description,spellCheck:!1,autoCapitalize:`off`,autoCorrect:`off`,maxLength:256,wrapperClassName:`w-60 max-md:w-full`,onCommit:e=>(G.getState().setCustomFontFamily(e.trim()),null)})}function k6({ids:e}){return(0,k.jsx)(n6,{value:G(e=>e.fontSize),min:6,max:24,onChange:G(e=>e.setFontSize),noun:`font size`,labelledBy:e.label,describedBy:e.description})}function A6({ids:e}){let t=G(e=>e.lineHeight),n=G(e=>e.setLineHeight);return(0,k.jsx)(r6,{id:e.control,value:t,min:1,max:2,step:.1,onChange:e=>n(Math.round(e*10)/10),format:e=>e.toFixed(1),labelledBy:e.label,describedBy:e.description})}function j6({ids:e}){let t=G(e=>e.letterSpacing),n=G(e=>e.setLetterSpacing);return(0,k.jsx)(r6,{id:e.control,value:t,min:-3,max:3,step:1,onChange:e=>n(Math.round(e)),format:e=>`${e}px`,labelledBy:e.label,describedBy:e.description})}function M6({ids:e}){let t=G(e=>e.compactMobileControls),n=G(e=>e.setCompactMobileControls);return(0,k.jsx)(T6,{className:Zt,id:e.control,checked:t,onCheckedChange:n,ariaLabelledBy:e.label,ariaDescribedBy:e.description})}var N6=[{id:`theme`,page:`appearance`,label:`Theme`,description:`Light, dark, or follow the system setting.`,keywords:[`dark mode`,`light mode`,`color`,`colour`,`system`],Control:E6},{id:`compact-mobile-controls`,page:`appearance`,label:`Compact mobile controls`,description:`Smaller header buttons and quick keys on phones. More terminal space, smaller tap targets.`,keywords:[`mobile`,`size`,`buttons`,`compact`,`toolbar`,`density`],tags:[`device`],Control:M6},{id:`font-family`,page:`appearance`,label:`Font family`,description:`Terminal typeface. Default JetBrains Mono.`,keywords:[`font`,`typeface`,`monospace`],tags:[`device`],Control:D6},{id:`custom-font-family`,page:`appearance`,label:`Custom font family`,description:`A CSS font-family list. Empty falls back to JetBrains Mono.`,keywords:[`font`,`typeface`,`css`],tags:[`device`],layout:`wide`,visibleWhen:e=>e.fontOption===`custom`,Control:O6},{id:`font-size`,page:`appearance`,label:`Font size`,description:`Terminal text size in pixels (6–24). Default 13.`,keywords:[`font`,`text`,`zoom`,`size`],tags:[`device`],Control:k6},{id:`line-height`,page:`appearance`,label:`Line height`,description:`Vertical spacing, 1.0 compact to 2.0 spacious. Default 1.0.`,keywords:[`spacing`,`leading`,`line`],tags:[`device`],Control:A6},{id:`letter-spacing`,page:`appearance`,label:`Letter spacing`,description:`Extra space between characters in pixels (−3 to 3). Default 0.`,keywords:[`spacing`,`tracking`,`kerning`],tags:[`device`],Control:j6}],P6=1024,F6=[{value:``,label:`Terminal`},{value:`claude`,label:`Claude`},{value:`codex`,label:`Codex`},{value:`pi`,label:`Pi`},{value:`devin`,label:`Devin`},{value:`grok`,label:`Grok`},{value:`omp`,label:`OMP`}];function I6(e,t){let n=t.trim();return e===`label`?n?n.length>64?`Name is at most 64 characters`:null:`Name is required`:n?n.length>1024?`Command is at most ${P6} characters`:null:`Command is required`}function L6(e){return I6(`label`,e.label)===null&&I6(`command`,e.command)===null}function R6(e,t,n){return e.map(e=>e.id===t?Rt({...e,...n}):e)}var z6=`grid items-start gap-2 grid-cols-[56px_92px_minmax(0,0.8fr)_minmax(0,1.3fr)_auto] max-md:grid-cols-[minmax(0,1fr)_minmax(0,auto)_auto] max-md:gap-y-2`,B6=4e3;function V6({preset:e,index:t,isDefault:n,pending:r=!1,autoFocusName:i=!1,onSetDefault:a,onCommitField:o,onIconChange:s,onDelete:c}){let[l,u]=(0,y.useState)(!1),d=(0,y.useRef)(null),f=`settings-preset-${e.id}`,p=e.label.trim()||`preset ${t+1}`;return(0,y.useEffect)(()=>{i&&d.current?.focus()},[i]),(0,y.useEffect)(()=>{if(!l)return;let e=setTimeout(()=>u(!1),B6);return()=>clearTimeout(e)},[l]),(0,k.jsxs)(`div`,{role:`listitem`,"data-preset-id":e.id,className:xE(z6,`py-2`),children:[(0,k.jsxs)(`label`,{className:xE(J3,`flex cursor-pointer items-center gap-2 md:justify-center`),children:[(0,k.jsx)(`input`,{type:`radio`,name:`settings-default-preset`,checked:n,disabled:r,onChange:a,"aria-label":`Default preset: ${p}`,className:`size-4 cursor-pointer accent-accent disabled:cursor-not-allowed`}),(0,k.jsx)(`span`,{"aria-hidden":`true`,className:`text-[12px] text-secondary md:hidden`,children:`Default`})]}),e.isBuiltIn?(0,k.jsxs)(`div`,{className:xE(J3,`flex items-center gap-2 text-muted`),children:[(0,k.jsx)(_g,{agentType:e.agentType,command:e.command,className:`size-4`}),(0,k.jsx)(`span`,{className:`text-[11px]`,children:`Built-in`})]}):(0,k.jsx)(`select`,{id:`${f}-icon`,value:e.agentType??``,"aria-label":`Icon for ${p}`,onChange:e=>s(e.target.value||void 0),className:xE(Q3,`w-full px-1`),children:F6.map(e=>(0,k.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,k.jsx)(e6,{ref:d,id:`${f}-label`,value:e.label,placeholder:`Name`,"aria-label":`Name of preset ${t+1}`,maxLength:64,onCommit:e=>o(`label`,e),wrapperClassName:`max-md:order-4 max-md:col-span-3`}),(0,k.jsx)(e6,{id:`${f}-command`,value:e.command,placeholder:`command --flags`,"aria-label":`Command for ${p}`,maxLength:P6,spellCheck:!1,autoCapitalize:`off`,autoCorrect:`off`,onCommit:e=>o(`command`,e),wrapperClassName:`max-md:order-5 max-md:col-span-3`}),e.isBuiltIn?(0,k.jsx)(`span`,{"aria-hidden":`true`,className:`w-[32px] max-md:order-3 max-md:w-[44px]`}):(0,k.jsx)(`button`,{type:`button`,onClick:()=>{if(r||l){c();return}u(!0)},onPointerDown:r?e=>e.preventDefault():void 0,onBlur:()=>u(!1),"aria-label":l?`Confirm delete ${p}`:r?`Discard new preset`:`Delete ${p}`,title:l?`Click again to delete`:void 0,className:xE(Y3,`max-md:order-3`,l?`border-danger bg-danger/10 px-2 text-danger hover:bg-danger/20`:`w-[32px] border-border bg-surface text-secondary hover:bg-hover hover:text-danger max-md:w-[44px]`),children:l?`Delete?`:(0,k.jsx)(fe,{width:K.default,height:K.default})})]})}function H6({ids:e}){let t=G(e=>e.commandPresets),n=G(e=>e.defaultPresetId),[r,i]=(0,y.useState)(null),a=(0,y.useRef)(null),o=(0,y.useRef)(null),s=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(!s.current)return;s.current=!1;let e=o.current;if(e&&!e.disabled){e.focus();return}let t=a.current?.id;t&&typeof document<`u`&&document.getElementById(`settings-preset-${t}-label`)?.focus()});let c=e=>{a.current=e,i(e)},l=!r&&t.length<50,u=r?[...t,r]:t,d=(e,t,n)=>{let r=I6(t,n);if(r)return r;let{commandPresets:i,setCommandPresets:a}=G.getState();return a(R6(i,e,{[t]:n})),null},f=(e,t)=>{let n=a.current;if(!n)return null;let r={...n,[e]:t},{commandPresets:i,setCommandPresets:o}=G.getState();return L6(r)&&i.length<50?(o([...i,Rt(r)]),c(null)):c(r),null},p=(e,t)=>{if(r?.id===e){c({...r,agentType:t});return}let{commandPresets:n,setCommandPresets:i}=G.getState();i(R6(n,e,{agentType:t}))},m=()=>{l&&c({id:Bt(new Set(t.map(e=>e.id))),label:``,command:``,isBuiltIn:!1})},h=e=>{s.current=!0,a.current?.id===e?c(null):G.getState().removePreset(e)};return(0,k.jsxs)(`div`,{className:`w-full min-w-0`,children:[(0,k.jsxs)(`div`,{"aria-hidden":`true`,className:xE(z6,`border-b border-border pb-1 text-[11px] uppercase tracking-wide text-muted max-md:hidden`),children:[(0,k.jsx)(`span`,{className:`text-center`,children:`Default`}),(0,k.jsx)(`span`,{children:`Icon`}),(0,k.jsx)(`span`,{children:`Name`}),(0,k.jsx)(`span`,{children:`Command`}),(0,k.jsx)(`span`,{className:`w-[32px]`})]}),(0,k.jsx)(`div`,{role:`list`,"aria-labelledby":e.label,"aria-describedby":e.description,className:`divide-y divide-border-subtle`,children:u.map((e,t)=>{let i=e.id===r?.id;return(0,k.jsx)(V6,{preset:e,index:t,isDefault:e.id===n,pending:i,autoFocusName:i,onSetDefault:()=>G.getState().setDefaultPresetId(e.id),onCommitField:(t,n)=>i?f(t,n):d(e.id,t,n),onIconChange:t=>p(e.id,t),onDelete:()=>h(e.id)},e.id)})}),r&&(0,k.jsx)(`p`,{className:xE(`text-[12px] leading-snug text-muted`,`pb-2`),role:`status`,children:`Enter a name and a command to add the preset.`}),(0,k.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,k.jsxs)(`button`,{ref:o,type:`button`,className:X3,onClick:m,disabled:!l,children:[(0,k.jsx)(Je,{width:K.default,height:K.default,className:`mr-1.5`}),`Add preset`]}),t.length>=50&&(0,k.jsxs)(`span`,{className:`text-[12px] leading-snug text-muted`,children:[`Maximum of `,50,` presets.`]})]})]})}function U6({ids:e}){let t=G(e=>e.defaultProjectDir);return(0,k.jsx)(e6,{id:e.control,value:t,placeholder:jt,describedBy:e.description,spellCheck:!1,autoCapitalize:`off`,autoCorrect:`off`,maxLength:4096,wrapperClassName:`w-72 max-md:w-full`,onCommit:e=>(G.getState().setDefaultProjectDir(e.trim()||`~/Documents/GitHub`),null)})}var W6=[{id:`default-project-dir`,page:`new-sessions`,label:`Default project directory`,description:`Folder the new session dialog starts in. Default ${jt}.`,keywords:[`path`,`folder`,`cwd`,`directory`],layout:`wide`,Control:U6},{id:`command-presets`,page:`new-sessions`,label:`Command presets`,description:`Commands offered when creating a session. The default preset is pre-selected.`,keywords:[`preset`,`command`,`agent`,`claude`,`codex`,`default`,`icon`],layout:`block`,Control:H6}],G6=null,K6=!1,q6={},J6=500;function Y6(){if(typeof window>`u`)return null;if(G6?.state===`closed`&&(G6=null),!G6){let e=window.AudioContext??window.webkitAudioContext;if(!e)return null;G6=new e}return G6}function X6(){G6&&=(G6.close().catch(()=>{}),null),Y6()}function Z6(){return K6}function Q6(){G6&&(X6(),K6=!0)}if(typeof window<`u`){window.addEventListener(`pageshow`,e=>{e.persisted&&Q6()}),document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`visible`&&Q6()});let e=Date.now();setInterval(()=>{let t=Date.now();t-e>15e3&&Q6(),e=t},5e3)}async function $6(){let e=Y6();e&&e.state===`suspended`&&await e.resume().catch(()=>{}),K6=!1}async function e8(e){e.state===`suspended`&&await e.resume().catch(()=>{})}async function t8(e){let t=Y6();if(!t||(await e8(t),t.state!==`running`))return;let{frequencies:n,durationMs:r,attackMs:i,peakGain:a,type:o=`sine`}=e,s=t.currentTime,c=r/1e3,l=i/1e3,u=t.createGain();u.connect(t.destination);let d=s+c*.7;u.gain.setValueAtTime(0,s),u.gain.linearRampToValueAtTime(a,s+l),u.gain.setValueAtTime(a,d),u.gain.linearRampToValueAtTime(0,s+c);let f=n.map(e=>{let n=t.createOscillator();return n.type=o,n.frequency.setValueAtTime(e,s),n.connect(u),n});for(let e of f)e.start(s),e.stop(s+c);let p=f[f.length-1];p.onended=()=>{for(let e of f)e.disconnect();u.disconnect()}}async function n8(){let e=Date.now();if(!(e-(q6.permission||0)<J6)){q6.permission=e;try{await t8({frequencies:[880],durationMs:150,attackMs:5,peakGain:.15,type:`sine`})}catch{}}}async function r8(){let e=Date.now();if(!(e-(q6.idle||0)<J6)){q6.idle=e;try{await t8({frequencies:[440,550],durationMs:300,attackMs:10,peakGain:.08,type:`sine`})}catch{}}}function i8(e,t,n,r){return function({ids:i}){let a=G(t=>t[e]),o=G(e=>e[t]);return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{type:`button`,className:X3,"aria-label":`Test ${r}`,onClick:()=>void n(),children:`Test`}),(0,k.jsx)(T6,{className:Zt,id:i.control,checked:a,onCheckedChange:e=>{o(e),e&&$6()},ariaLabelledBy:i.label,ariaDescribedBy:i.description})]})}}var a8=[{id:`sound-permission`,page:`notifications`,label:`Permission sound`,description:`Play a ping when any session needs permission.`,keywords:[`sound`,`audio`,`alert`,`ping`,`approval`],Control:i8(`soundOnPermission`,`setSoundOnPermission`,n8,`permission sound`)},{id:`sound-idle`,page:`notifications`,label:`Idle sound`,description:`Play a chime when a session finishes working.`,keywords:[`sound`,`audio`,`alert`,`chime`,`done`,`finished`],Control:i8(`soundOnIdle`,`setSoundOnIdle`,r8,`idle sound`)}];function o8(e,t,n){let r=`/api/settings/${e}`,[i,a]=(0,y.useState)(n),[o,s]=(0,y.useState)(!0),[c,l]=(0,y.useState)(!1),u=(0,y.useRef)(n),d=(0,y.useRef)(Promise.resolve()),f=(0,y.useRef)(0),p=(0,y.useRef)(!0),m=(0,y.useRef)(!1);return(0,y.useEffect)(()=>{p.current=!0;let e=!0;return fetch(r).then(e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}).then(n=>{if(!e)return;let r=n[t];f.current===0&&!m.current&&(u.current=r),m.current||a(r)}).catch(()=>{}).finally(()=>{e&&(l(!0),f.current===0&&s(!1))}),()=>{e=!1,p.current=!1}},[r,t]),{value:i,loading:o,loaded:c,set:(0,y.useCallback)(e=>{m.current=!0,f.current+=1,a(e),s(!0),d.current=d.current.then(()=>fetch(r,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({[t]:e})}).then(t=>{if(!t.ok)throw Error(`HTTP ${t.status}`);u.current=e}).catch(()=>{p.current&&f.current===1&&a(u.current)}).finally(()=>{--f.current,p.current&&f.current===0&&s(!1)}))},[r,t])}}function s8(e,t){return function({ids:n}){let r=G(t=>t[e]),i=G(e=>e[t]);return(0,k.jsx)(T6,{className:Zt,id:n.control,checked:r,onCheckedChange:i,ariaLabelledBy:n.label,ariaDescribedBy:n.description})}}function c8({ids:e}){return(0,k.jsx)(i6,{options:[{value:`created`,label:`Created`},{value:`status`,label:`Status`},{value:`manual`,label:`Manual`}],value:G(e=>e.sessionSortMode),onChange:G(e=>e.setSessionSortMode),labelledBy:e.label,describedBy:e.description})}function l8(){let e=G(e=>e.sessionSortMode);return e===`status`?(0,k.jsx)(k.Fragment,{children:`Permission sessions come first; the rest sort by newest activity.`}):e===`manual`?(0,k.jsx)(k.Fragment,{children:`Drag sessions in the sidebar to reorder them.`}):(0,k.jsx)(k.Fragment,{children:`Sessions stay in the order they were created.`})}function u8({ids:e}){return(0,k.jsx)(i6,{options:[{value:`desc`,label:`Newest first`},{value:`asc`,label:`Oldest first`}],value:G(e=>e.sessionSortDirection),onChange:G(e=>e.setSessionSortDirection),labelledBy:e.label,describedBy:e.description})}function d8({ids:e}){return(0,k.jsx)(i6,{options:[{value:`top`,label:`Top`},{value:`bottom`,label:`Bottom`}],value:G(e=>e.sidebarAnchor),onChange:G(e=>e.setSidebarAnchor),labelledBy:e.label,describedBy:e.description})}function f8(){return G(e=>e.sidebarAnchor)===`bottom`?(0,k.jsx)(k.Fragment,{children:`The sidebar is mirrored: the first session sits at the bottom, next to the prompt.`}):(0,k.jsx)(k.Fragment,{children:`The first session sits at the top of the sidebar.`})}function p8({ids:e}){let{value:t,loaded:n,set:r}=o8(`history-max-age-hours`,`hours`,24);return(0,k.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,k.jsx)(e6,{id:e.control,type:`text`,inputMode:`numeric`,value:String(t),disabled:!n,describedBy:e.description,wrapperClassName:`w-20`,className:`text-center tabular-nums`,onCommit:e=>{let n=t6(e,1,168);return n===null?`Enter 1–168`:(n!==t&&r(n),null)}}),(0,k.jsx)(`span`,{className:`flex h-[32px] items-center text-[12px] text-muted max-md:h-[44px]`,children:`hours`})]})}function m8({ids:e}){let{value:t,loaded:n,set:r}=o8(`prefer-window-name`,`enabled`,!1);return(0,k.jsx)(T6,{className:Zt,id:e.control,checked:t,onCheckedChange:r,disabled:!n,ariaLabelledBy:e.label,ariaDescribedBy:e.description})}var h8=[{id:`sort-order`,page:`session-list`,label:`Sort order`,description:`Created keeps creation order, Status re-sorts by status, Manual lets you drag.`,keywords:[`sort`,`order`,`created`,`status`,`manual`,`drag`],layout:`wide`,Description:l8,Control:c8},{id:`sort-direction`,page:`session-list`,label:`Sort direction`,description:`Newest or oldest sessions first.`,keywords:[`sort`,`newest`,`oldest`,`ascending`,`descending`],layout:`wide`,visibleWhen:e=>e.sessionSortMode===`created`,Control:u8},{id:`sidebar-anchor`,page:`session-list`,label:`Sidebar anchor`,description:`Top lists the first session at the top; Bottom mirrors the sidebar.`,keywords:[`sidebar`,`mirror`,`top`,`bottom`],tags:[`desktop`],Description:f8,Control:d8},{id:`mobile-session-peek`,page:`session-list`,label:`Mobile session peek`,description:`Show the colored status strip at the left edge of the mobile terminal. Turn off to use the full width.`,keywords:[`phone`,`sidebar`,`status`,`rail`],tags:[`device`],Control:s8(`showMobileSessionPeek`,`setShowMobileSessionPeek`)},{id:`show-project-name`,page:`session-list`,label:`Project name`,description:`Show the project folder name under each session.`,keywords:[`folder`,`details`],Control:s8(`showProjectName`,`setShowProjectName`)},{id:`show-last-user-message`,page:`session-list`,label:`Last user message`,description:`Show the most recent prompt next to the project name.`,keywords:[`prompt`,`input`,`details`],Control:s8(`showLastUserMessage`,`setShowLastUserMessage`)},{id:`show-session-id-prefix`,page:`session-list`,label:`Session ID prefix`,description:`Show the first 5 characters of the agent session ID.`,keywords:[`id`,`uuid`,`details`],Control:s8(`showSessionIdPrefix`,`setShowSessionIdPrefix`)},{id:`history-lookback`,page:`session-list`,label:`History lookback`,description:`Show history sessions from the last N hours (1–168), up to the 100 most recent. Default 24.`,keywords:[`history`,`hours`,`age`,`inactive`,`past`],Control:p8},{id:`prefer-window-name`,page:`session-list`,label:`Prefer window names`,description:`Label discovered sessions with their tmux window name instead of the session name.`,keywords:[`tmux`,`window`,`name`,`title`],Control:m8}],g8=`1-9 [ ] N X ,`;function _8({ids:e}){let t=G(e=>e.useWebGL),n=G(e=>e.setUseWebGL);return(0,k.jsx)(T6,{className:Zt,id:e.control,checked:t,onCheckedChange:n,ariaLabelledBy:e.label,ariaDescribedBy:e.description})}function v8({ids:e}){let t=G(e=>e.mobileAutocorrect),n=G(e=>e.setMobileAutocorrect);return(0,k.jsx)(T6,{className:Zt,id:e.control,checked:t,onCheckedChange:n,ariaLabelledBy:e.label,ariaDescribedBy:e.description})}function y8(e,t){return function({ids:n}){let{value:r,loaded:i,set:a}=o8(e,`enabled`,t);return(0,k.jsx)(T6,{className:Zt,id:n.control,checked:r,onCheckedChange:a,disabled:!i,ariaLabelledBy:n.label,ariaDescribedBy:n.description})}}var b8=[`auto`,`ctrl-option`,`ctrl-shift`,`cmd-option`,`cmd-shift`];function x8({ids:e}){let t=G(e=>e.shortcutModifier),n=G(e=>e.setShortcutModifier);return(0,k.jsx)(i6,{options:b8.map(e=>({value:e,label:e===`auto`?`Auto`:kt(e)})),value:t,onChange:n,labelledBy:e.label,describedBy:e.description})}function S8(){return(0,k.jsxs)(k.Fragment,{children:[`Shortcuts: `,kt(Dt(G(e=>e.shortcutModifier))),` + `,g8,` (sessions, navigate, new, kill, settings).`]})}var C8=[{id:`mobile-autocorrect`,page:`terminal`,label:`Mobile autocorrect`,description:`Keyboard suggestions and corrections on iOS and Android. Experimental; turn off for complex text editing.`,keywords:[`keyboard`,`spelling`,`predictive`,`typing`,`gboard`,`iphone`,`ipad`],tags:[`device`],Control:v8},{id:`webgl`,page:`terminal`,label:`WebGL acceleration`,description:`GPU rendering for better performance. Turn off if text looks fuzzy or flickers (common in Safari).`,keywords:[`gpu`,`renderer`,`canvas`,`blurry`,`performance`],tags:[`device`],Control:_8},{id:`mouse-mode`,page:`terminal`,label:`Mouse mode`,description:`tmux mouse mode for trackpad and scroll wheel support.`,keywords:[`tmux`,`scroll`,`trackpad`,`mouse`],Control:y8(`tmux-mouse-mode`,!0)},{id:`terminal-colors`,page:`terminal`,label:`Terminal colors`,description:`Preserve ANSI colors in terminal output. Hibernate then Wake running agents after changing this.`,keywords:[`ansi`,`color`,`colour`],Control:y8(`terminal-colors`,!0)},{id:`shortcut-modifier`,page:`terminal`,label:`Keyboard shortcut modifier`,description:`Modifier keys for the app shortcuts. Auto picks ⌃⌥ on macOS, ⌃⇧ elsewhere.`,keywords:[`keyboard`,`shortcut`,`hotkey`,`ctrl`,`cmd`,`option`,`shift`],tags:[`desktop`,`device`],layout:`wide`,Description:S8,Control:x8}],w8=[...W6,...h8,...N6,...C8,...a8];function T8(e,t=w8){return t.filter(t=>t.page===e)}function E8(e){return[e.label,e.description,...e.keywords??[]].join(` `).toLowerCase()}function D8(e,t=w8){let n=e.trim().toLowerCase().split(/\s+/).filter(Boolean);return n.length===0?[]:t.filter(e=>{let t=E8(e);return n.every(e=>t.includes(e))})}function O8(e){return V3.map(t=>({page:t.id,label:t.label,rows:e.filter(e=>e.page===t.id)})).filter(e=>e.rows.length>0)}var k8={desktop:`Desktop`,device:`This device`},A8={desktop:`Only affects the desktop layout`,device:`Stored in this browser only; not synced to other devices`};function j8({tag:e}){return(0,k.jsx)(`span`,{title:A8[e],className:`shrink-0 border border-border px-1 py-px text-[10px] uppercase leading-none tracking-wide text-muted`,children:k8[e]})}function M8(e){let t=`settings-${e}`;return{control:`${t}-control`,label:`${t}-label`,description:`${t}-desc`}}function N8({row:e}){let t=M8(e.id),n=e.layout??`inline`,{Control:r,Description:i}=e;return(0,k.jsxs)(`div`,{"data-setting-row":e.id,className:xE(`flex gap-x-6 gap-y-3 py-4`,n===`block`&&`flex-col`,n===`wide`&&`items-center max-md:flex-col max-md:items-stretch`,n===`inline`&&`items-center`),children:[(0,k.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,k.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,k.jsx)(`label`,{id:t.label,htmlFor:t.control,className:`text-[14px] leading-snug text-primary`,children:e.label}),e.tags?.map(e=>(0,k.jsx)(j8,{tag:e},e))]}),(0,k.jsx)(`div`,{id:t.description,className:`mt-1 text-[12px] leading-snug text-muted text-pretty`,children:i?(0,k.jsx)(i,{}):e.description})]}),(0,k.jsx)(`div`,{className:xE(`flex min-w-0 items-center gap-2`,n===`inline`?`shrink-0`:`max-w-full`),children:(0,k.jsx)(r,{ids:t})})]})}function P8(e,t){return e.visibleWhen?e.visibleWhen(t):!0}function F8({rows:e}){let t=G(t=>e.map(e=>P8(e,t)?`1`:`0`).join(``));return(0,k.jsx)(`div`,{className:`divide-y divide-border`,children:e.filter((e,n)=>t[n]===`1`).map(e=>(0,k.jsx)(N8,{row:e},e.id))})}function I8({page:e,showTitle:t}){let n=(0,y.useMemo)(()=>T8(e),[e]);return(0,k.jsxs)(`section`,{"aria-labelledby":t?`settings-page-${e}-title`:void 0,children:[t&&(0,k.jsx)(`h3`,{id:`settings-page-${e}-title`,className:`pb-1 text-[18px] font-semibold leading-tight text-primary`,children:U3(e)}),(0,k.jsx)(F8,{rows:n})]})}function L8({query:e}){let t=(0,y.useMemo)(()=>D8(e),[e]),n=G(e=>t.some(t=>P8(t,e))),r=(0,y.useMemo)(()=>O8(t),[t]);return n?(0,k.jsx)(`div`,{className:`flex flex-col gap-6`,children:r.map(e=>(0,k.jsx)(R8,{label:e.label,rows:e.rows},e.page))}):(0,k.jsxs)(`div`,{role:`status`,className:`flex flex-col items-center gap-1 py-16 text-center`,children:[(0,k.jsxs)(`p`,{className:`text-[14px] text-primary`,children:[`No settings match “`,e.trim(),`”`]}),(0,k.jsx)(`p`,{className:`text-[12px] text-muted`,children:`Try a different word, like “font” or “sound”.`})]})}function R8({label:e,rows:t}){return G(e=>t.some(t=>P8(t,e)))?(0,k.jsxs)(`section`,{"aria-label":e,children:[(0,k.jsx)(`h3`,{className:`border-b border-border pb-1 text-[11px] font-medium uppercase tracking-wider text-muted`,children:e}),(0,k.jsx)(F8,{rows:t})]}):null}function z8(e){return`settings-tab-${e}`}function B8(e,t,n){return e===`ArrowDown`?(t+1)%n:e===`ArrowUp`?(t-1+n)%n:e===`Home`?0:e===`End`?n-1:null}function V8({variant:e,current:t,onSelect:n,panelId:r}){let i=(0,y.useRef)([]),a=Math.max(0,V3.findIndex(e=>e.id===t)),o=(t,r)=>{let a=B8(t.key,r,V3.length);a!==null&&(t.preventDefault(),i.current[a]?.focus(),e===`tabs`&&n(V3[a].id))};return e===`list`?(0,k.jsx)(`nav`,{"aria-label":`Settings pages`,children:(0,k.jsx)(`ul`,{className:`divide-y divide-border border-y border-border`,children:V3.map((e,t)=>(0,k.jsx)(`li`,{children:(0,k.jsxs)(`button`,{ref:e=>{i.current[t]=e},type:`button`,"data-page-id":e.id,onClick:()=>n(e.id),onKeyDown:e=>o(e,t),className:`flex min-h-[52px] w-full items-center justify-between gap-3 px-4 text-left text-[15px] text-primary active:bg-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,children:[e.label,(0,k.jsx)(H,{width:K.primary,height:K.primary,className:`text-muted`,"aria-hidden":`true`})]})},e.id))})}):(0,k.jsx)(`div`,{role:`tablist`,"aria-orientation":`vertical`,"aria-label":`Settings pages`,className:`flex flex-col gap-px`,children:V3.map((e,s)=>{let c=e.id===t;return(0,k.jsx)(`button`,{ref:e=>{i.current[s]=e},id:z8(e.id),type:`button`,role:`tab`,"aria-selected":c,"aria-controls":r,tabIndex:s===a?0:-1,onClick:()=>n(e.id),onKeyDown:e=>o(e,s),className:xE(`flex h-[32px] w-full items-center border-l-2 px-3 text-left text-[13px] transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,c?`border-primary bg-hover font-medium text-primary`:`border-transparent text-secondary hover:text-primary`),children:e.label},e.id)})})}var H8=(0,y.forwardRef)(function({value:e,onChange:t,className:n},r){return(0,k.jsxs)(`div`,{className:n,children:[(0,k.jsx)(`label`,{htmlFor:`settings-search`,className:`sr-only`,children:`Search settings`}),(0,k.jsx)(`input`,{ref:r,id:`settings-search`,type:`search`,value:e,placeholder:`Search settings`,autoComplete:`off`,spellCheck:!1,onChange:e=>t(e.target.value),onKeyDown:n=>{n.key===`Escape`&&e&&(n.preventDefault(),t(``))},className:`input h-[32px] px-2 py-0 text-[13px] max-md:h-[44px] max-md:text-[16px] focus-visible:ring-2 focus-visible:ring-accent/40`})]})});function U8({isOpen:e,onClose:t}){return e?(0,k.jsx)(K8,{onClose:t}):null}var W8=`settings-panel`,G8=`flex shrink-0 items-center justify-center text-secondary transition-colors hover:bg-hover hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`;function K8({onClose:e}){let t=ag(),[n,r]=(0,y.useState)(()=>t?null:K3()),[i,a]=(0,y.useState)(``),o=(0,y.useRef)(null),s=(0,y.useRef)(null),c=(0,y.useRef)(null),l=(0,y.useRef)(!1),u=(0,y.useRef)(null),d=()=>{u.current=n,r(null)};l0({enabled:t&&n!==null,targetRef:o,onBack:d}),z4(),B4(o,e),(0,y.useEffect)(()=>{t?o.current?.focus():s.current?.focus()},[]),(0,y.useEffect)(()=>{if(t){if(n)c.current?.focus();else if(u.current){let e=o.current?.querySelector(`[data-page-id="${u.current}"]`);u.current=null,e?.focus()}}},[t,n]);let f=e=>{r(e),q3(e),a(``)},p=i.trim().length>0,m=(0,k.jsx)(`button`,{type:`button`,onClick:e,"aria-label":`Close settings`,className:xE(G8,`size-[32px] max-md:size-[44px]`),children:(0,k.jsx)(ot,{width:K.primary,height:K.primary})});if(t)return(0,k.jsxs)(`div`,{ref:o,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`settings-title`,"data-suspends-terminal":``,tabIndex:-1,className:`fixed inset-0 z-50 flex flex-col bg-elevated outline-none`,style:{paddingTop:`env(safe-area-inset-top)`,paddingLeft:`env(safe-area-inset-left)`,paddingRight:`env(safe-area-inset-right)`},children:[(0,k.jsxs)(`header`,{className:`flex h-[52px] shrink-0 items-center gap-1 border-b border-border px-1`,children:[n?(0,k.jsx)(`button`,{ref:c,type:`button`,onClick:d,"aria-label":`Back to settings`,className:xE(G8,`size-[44px]`),children:(0,k.jsx)(H,{width:K.primary,height:K.primary,className:`rotate-180`})}):(0,k.jsx)(`span`,{"aria-hidden":`true`,className:`size-[44px] shrink-0`}),(0,k.jsx)(`h2`,{id:`settings-title`,className:`min-w-0 flex-1 truncate text-center text-[16px] font-semibold text-primary`,children:n?U3(n):`Settings`}),m]}),(0,k.jsx)(`div`,{id:W8,className:`min-h-0 flex-1 overflow-y-auto overflow-x-hidden overscroll-contain px-4`,style:{paddingBottom:`calc(24px + env(safe-area-inset-bottom))`},children:n?(0,k.jsx)(I8,{page:n,showTitle:!1}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(H8,{ref:s,value:i,onChange:a,className:`py-3`}),p?(0,k.jsx)(L8,{query:i}):(0,k.jsx)(`div`,{className:`-mx-4`,children:(0,k.jsx)(V8,{variant:`list`,current:null,onSelect:f})})]})})]});let h=n??K3();return(0,k.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/30 p-4`,onMouseDown:e=>{l.current=e.target===e.currentTarget},onClick:t=>{l.current&&t.target===t.currentTarget&&e(),l.current=!1},children:(0,k.jsxs)(`div`,{ref:o,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`settings-title`,"data-suspends-terminal":``,tabIndex:-1,className:`flex h-[600px] max-h-full w-[760px] max-w-full flex-col border border-border bg-elevated shadow-2xl outline-none`,children:[(0,k.jsxs)(`header`,{className:`flex h-[48px] shrink-0 items-center justify-between border-b border-border pl-5 pr-2`,children:[(0,k.jsx)(`h2`,{id:`settings-title`,className:`text-[13px] font-semibold uppercase tracking-wider text-primary`,children:`Settings`}),m]}),(0,k.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,k.jsxs)(`div`,{className:`flex w-[192px] shrink-0 flex-col gap-3 border-r border-border p-3`,children:[(0,k.jsx)(H8,{ref:s,value:i,onChange:a}),(0,k.jsx)(V8,{variant:`tabs`,current:p?null:h,onSelect:f,panelId:W8})]}),(0,k.jsx)(`div`,{id:W8,role:p?`region`:`tabpanel`,"aria-label":p?`Search results`:void 0,"aria-labelledby":p?void 0:z8(h),className:`min-w-0 flex-1 overflow-y-auto overflow-x-hidden px-6 py-5`,children:p?(0,k.jsx)(L8,{query:i}):(0,k.jsx)(I8,{page:h,showTitle:!0})})]})]})})}var q8=y.createContext(void 0);function J8(){let e=y.useContext(q8);if(!e)throw Error(mb(73));return e}var Y8=0;function X8(e){return Y8+=1,`${e}-${Math.random().toString(36).slice(2,6)}-${Y8}`}function Z8(e,t){if(typeof e==`string`)return{description:e};if(typeof e==`function`){let n=e(t);return typeof n==`string`?{description:n}:n}return e}var Q8=LS(e=>e.toasts,e=>{let t=new Map,n=0,r=0;return e.forEach((e,i)=>{let a=e.transitionStatus===`ending`;t.set(e.id,{value:e,domIndex:i,visibleIndex:a?-1:n,offsetY:r}),r+=e.height||0,a||(n+=1)}),t}),$8={toasts:IS(e=>e.toasts),isEmpty:IS(e=>e.toasts.length===0),toast:IS(Q8,(e,t)=>e.get(t)?.value),toastIndex:IS(Q8,(e,t)=>e.get(t)?.domIndex??-1),toastOffsetY:IS(Q8,(e,t)=>e.get(t)?.offsetY??0),toastVisibleIndex:IS(Q8,(e,t)=>e.get(t)?.visibleIndex??-1),hovering:IS(e=>e.hovering),focused:IS(e=>e.focused),expanded:IS(e=>e.hovering||e.focused),expandedOrOutOfFocus:IS(e=>e.hovering||e.focused||!e.isWindowFocused),prevFocusElement:IS(e=>e.prevFocusElement)},e5=class extends eC{timers=new Map;areTimersPaused=!1;constructor(e){super(e,{},$8)}setFocused(e){this.set(`focused`,e)}setHovering(e){this.set(`hovering`,e)}setIsWindowFocused(e){this.set(`isWindowFocused`,e)}setPrevFocusElement(e){this.set(`prevFocusElement`,e)}setViewport=e=>{this.set(`viewport`,e)};disposeEffect=()=>()=>{this.timers.forEach(e=>{e.timeout?.clear()}),this.timers.clear()};removeToast(e){let t=$8.toastIndex(this.state,e);if(t===-1)return;this.state.toasts[t]?.onRemove?.();let n=[...this.state.toasts];n.splice(t,1),this.setToasts(n)}addToast=e=>{let{toasts:t,timeout:n,limit:r}=this.state,i=e.id||X8(`toast`),a={...e,id:i,transitionStatus:`starting`},o=[a,...t],s=o.filter(e=>e.transitionStatus!==`ending`);if(s.length>r){let e=s.length-r,t=s.slice(-e),n=new Set(t.map(e=>e.id));this.setToasts(o.map(e=>{let t=n.has(e.id);return e.limited===t?e:{...e,limited:t}}))}else this.setToasts(o.map(e=>e.limited?{...e,limited:!1}:e));let c=a.timeout??n;return a.type!==`loading`&&c>0&&this.scheduleTimer(i,c,()=>this.closeToast(i)),$8.expandedOrOutOfFocus(this.state)&&this.pauseTimers(),i};updateToast=(e,t)=>{this.updateToastInternal(e,t)};updateToastInternal=(e,t)=>{let{timeout:n,toasts:r}=this.state,i=$8.toast(this.state,e)??null;if(!i||i.transitionStatus===`ending`)return;let a={...i,...t};this.setToasts(r.map(n=>n.id===e?{...n,...t}:n));let o=a.timeout??n,s=i?.timeout??n,c=Object.hasOwn(t,`timeout`),l=a.transitionStatus!==`ending`&&a.type!==`loading`&&o>0,u=this.timers.has(e),d=s!==o,f=i?.type===`loading`;if(!l&&u){this.timers.get(e)?.timeout?.clear(),this.timers.delete(e);return}if(l&&(!u||d||c||f)){let t=this.timers.get(e);t&&(t.timeout?.clear(),this.timers.delete(e)),this.scheduleTimer(e,o,()=>this.closeToast(e)),$8.expandedOrOutOfFocus(this.state)&&this.pauseTimers()}};closeToast=e=>{$8.toast(this.state,e)?.onClose?.();let{limit:t,toasts:n}=this.state,r=0,i=n.map(n=>{if(n.id===e)return{...n,transitionStatus:`ending`,height:0};if(n.transitionStatus===`ending`)return n;let i=r>=t;return r+=1,n.limited===i?n:{...n,limited:i}}),a=this.timers.get(e);a&&a.timeout&&(a.timeout.clear(),this.timers.delete(e)),this.handleFocusManagement(e),this.setToasts(i)};promiseToast=(e,t)=>{let n=Z8(t.loading),r=this.addToast({...n,type:`loading`}),i=e.then(e=>{let n=Z8(t.success,e);return this.updateToast(r,{...n,type:`success`,timeout:n.timeout}),e}).catch(e=>{let n=Z8(t.error,e);return this.updateToast(r,{...n,type:`error`,timeout:n.timeout}),Promise.reject(e)});return{}.hasOwnProperty.call(t,`setPromise`)&&t.setPromise(i),i};pauseTimers(){this.areTimersPaused||(this.areTimersPaused=!0,this.timers.forEach(e=>{if(e.timeout){e.timeout.clear();let t=Date.now()-e.start,n=e.delay-t;e.remaining=n>0?n:0}}))}resumeTimers(){this.areTimersPaused&&(this.areTimersPaused=!1,this.timers.forEach((e,t)=>{e.remaining=e.remaining>0?e.remaining:e.delay,e.timeout??=d_.create(),e.timeout.start(e.remaining,()=>{this.timers.delete(t),e.callback()}),e.start=Date.now()}))}restoreFocusToPrevElement(){this.state.prevFocusElement?.focus({preventScroll:!0})}handleDocumentPointerDown=e=>{if(e.pointerType!==`touch`)return;let t=V_(e);z_(this.state.viewport,t)||(this.resumeTimers(),this.update({hovering:!1,focused:!1}))};scheduleTimer(e,t,n){let r=Date.now(),i=!$8.expandedOrOutOfFocus(this.state),a=i?d_.create():void 0;a?.start(t,()=>{this.timers.delete(e),n()}),this.timers.set(e,{timeout:a,start:i?r:0,delay:t,remaining:t,callback:n})}setToasts(e){let t={toasts:e};e.length===0&&(t.hovering=!1,t.focused=!1),this.update(t)}handleFocusManagement(e){let t=R_(i_(this.state.viewport));if(!this.state.viewport||!z_(this.state.viewport,t)||!K_(t))return;let n=$8.toasts(this.state),r=$8.toastIndex(this.state,e),i=null,a=r+1;for(;a<n.length;){if(n[a].transitionStatus!==`ending`){i=n[a];break}a+=1}if(!i)for(a=r-1;a>=0;){if(n[a].transitionStatus!==`ending`){i=n[a];break}--a}i?i.ref?.current?.focus():this.restoreFocusToPrevElement()}},t5=function(e){let{children:t,timeout:n=5e3,limit:r=3,toastManager:i}=e,a=s_(()=>new e5({timeout:n,limit:r,viewport:null,toasts:[],hovering:!1,focused:!1,isWindowFocused:!0,prevFocusElement:null})).current;return l_(a.disposeEffect),y.useEffect(function(){if(i)return i[` subscribe`](({action:e,options:t})=>{let n=t.id;e===`promise`&&t.promise?a.promiseToast(t.promise,t):e===`update`&&n?a.updateToast(n,t):e===`close`&&n?a.closeToast(n):a.addToast(t)})},[a,n,i]),a.useSyncedValues({timeout:n,limit:r}),(0,k.jsx)(q8.Provider,{value:a,children:t})},n5=function(e){return e.frontmostHeight=`--toast-frontmost-height`,e}({}),r5=y.forwardRef(function(e,t){let{render:n,className:r,children:i,...a}=e,o=J8(),s=f_(),c=y.useRef(!1),l=y.useRef(!1),u=o.useState(`isEmpty`),d=o.useState(`toasts`),f=o.useState(`focused`),p=o.useState(`expanded`),m=o.useState(`prevFocusElement`),h=d[0]?.height??0,g=y.useMemo(()=>d.some(e=>e.transitionStatus===`ending`),[d]);y.useEffect(()=>{let e=o.state.viewport;if(!e)return;function t(t){u||t.key===`F6`&&t.target!==e&&(t.preventDefault(),o.setPrevFocusElement(R_(i_(e))),e?.focus({preventScroll:!0}),o.pauseTimers(),o.setFocused(!0))}let n=bg(e);return n.addEventListener(`keydown`,t),()=>{n.removeEventListener(`keydown`,t)}},[o,u]),y.useEffect(()=>{let e=o.state.viewport;if(!e||u)return;let t=bg(e);function n(e){e.target===t&&(o.setIsWindowFocused(!1),o.pauseTimers())}function r(n){if(n.relatedTarget||n.target===t)return;let r=V_(n),i=R_(i_(e));(!z_(e,r)||!K_(i))&&o.resumeTimers(),s.start(0,()=>o.setIsWindowFocused(!0))}return t.addEventListener(`blur`,n,!0),t.addEventListener(`focus`,r,!0),()=>{t.removeEventListener(`blur`,n,!0),t.removeEventListener(`focus`,r,!0)}},[o,s,u]),y.useEffect(()=>{let e=o.state.viewport;if(!e||u)return;let t=i_(e);return t.addEventListener(`pointerdown`,o.handleDocumentPointerDown,!0),()=>{t.removeEventListener(`pointerdown`,o.handleDocumentPointerDown,!0)}},[u,o]);function _(e){let t=o.state.viewport;t&&(c.current=!0,e.relatedTarget===t?d[0]?.ref?.current?.focus():o.restoreFocusToPrevElement())}function v(e){e.key===`Tab`&&e.shiftKey&&e.target===o.state.viewport&&(e.preventDefault(),o.restoreFocusToPrevElement(),o.resumeTimers())}y.useEffect(()=>{!o.state.isWindowFocused||g||!l.current||(o.resumeTimers(),o.setHovering(!1),l.current=!1)},[g,o]);function b(){o.pauseTimers(),o.setHovering(!0),l.current=!1}function x(){g?l.current=!0:(o.resumeTimers(),o.setHovering(!1))}function S(){if(c.current){c.current=!1;return}f||K_(i_(o.state.viewport).activeElement)&&(o.setFocused(!0),o.pauseTimers())}function C(e){!f||z_(o.state.viewport,e.relatedTarget)||(o.setFocused(!1),o.resumeTimers())}let w={tabIndex:-1,role:`region`,"aria-live":`polite`,"aria-atomic":!1,"aria-relevant":`additions text`,"aria-label":`Notifications`,onMouseEnter:b,onMouseMove:b,onMouseLeave:x,onFocus:S,onBlur:C,onKeyDown:v,onClick:S},T={expanded:p},E=Pb(`div`,e,{ref:[t,o.setViewport],state:T,props:[w,{style:{[n5.frontmostHeight]:h?`${h}px`:void 0}},a,{children:(0,k.jsxs)(y.Fragment,{children:[!u&&m&&(0,k.jsx)(nb,{onFocus:_}),i,!u&&m&&(0,k.jsx)(nb,{onFocus:_})]})}]}),D=y.useMemo(()=>d.filter(e=>e.priority===`high`),[d]);return(0,k.jsxs)(y.Fragment,{children:[!u&&m&&(0,k.jsx)(nb,{onFocus:_}),E,!f&&D.length>0&&(0,k.jsx)(`div`,{style:eb,children:D.map(e=>(0,k.jsxs)(`div`,{role:`alert`,"aria-atomic":!0,children:[(0,k.jsx)(`div`,{children:e.title}),(0,k.jsx)(`div`,{children:e.description})]},e.id))})]})}),i5=y.createContext(void 0);function a5(){let e=y.useContext(i5);if(!e)throw Error(mb(66));return e}var o5=function(e){return e.index=`--toast-index`,e.offsetY=`--toast-offset-y`,e.height=`--toast-height`,e.swipeMovementX=`--toast-swipe-movement-x`,e.swipeMovementY=`--toast-swipe-movement-y`,e}({}),s5={...sC,swipeDirection(e){return e?{"data-swipe-direction":e}:null}},c5=40,l5=10,u5=.5,d5=1;function f5(e,t,n){switch(e){case`up`:return-n;case`down`:return n;case`left`:return-t;case`right`:return t;default:return 0}}function p5(e){let t=window.getComputedStyle(e).transform,n=0,r=0,i=1;if(t&&t!==`none`){let e=t.match(/matrix(?:3d)?\(([^)]+)\)/);if(e){let t=e[1].split(`, `).map(parseFloat);t.length===6?(n=t[4],r=t[5],i=Math.sqrt(t[0]*t[0]+t[1]*t[1])):t.length===16&&(n=t[12],r=t[13],i=t[0])}}return{x:n,y:r,scale:i}}var m5=y.forwardRef(function(e,t){let{toast:n,render:r,className:i,swipeDirection:a=[`down`,`right`],...o}=e,s=n.positionerProps?.anchor!==void 0,c=[];s||(c=Array.isArray(a)?a:[a]);let l=c.length>0,u=J8(),[d,f]=y.useState(void 0),[p,m]=y.useState(!1),[h,g]=y.useState(!1),[_,v]=y.useState(!1),[b,x]=y.useState({x:0,y:0}),[S,C]=y.useState({x:0,y:0,scale:1}),[w,T]=y.useState(),[E,D]=y.useState(),[O,A]=y.useState(null),j=y.useRef(null),M=y.useRef({x:0,y:0}),N=y.useRef({x:0,y:0,scale:1}),P=y.useRef(void 0),F=y.useRef(0),I=y.useRef(!1),L=y.useRef({x:0,y:0}),R=y.useRef(!1),z=u.useState(`toastIndex`,n.id),B=u.useState(`toastVisibleIndex`,n.id),V=u.useState(`toastOffsetY`,n.id),ee=u.useState(`focused`),H=u.useState(`expanded`);lC({open:n.transitionStatus!==`ending`,ref:j,onComplete(){n.transitionStatus===`ending`&&u.removeToast(n.id)}});let te=N_((e=!1)=>{let t=j.current;if(!t)return;let r=t.style.height;t.style.height=`auto`;let i=t.offsetHeight;t.style.height=r;function a(){u.updateToastInternal(n.id,{ref:j,height:i,...n.transitionStatus===`starting`?{transitionStatus:void 0}:{}})}e?_f.flushSync(a):a()});a_(te,[te]);function U(e,t){let n=e,r=t;return!c.includes(`left`)&&!c.includes(`right`)?n=e>0?e**u5:-(Math.abs(e)**u5):(!c.includes(`right`)&&e>0&&(n=e**u5),!c.includes(`left`)&&e<0&&(n=-(Math.abs(e)**u5))),!c.includes(`up`)&&!c.includes(`down`)?r=t>0?t**u5:-(Math.abs(t)**u5):(!c.includes(`down`)&&t>0&&(r=t**u5),!c.includes(`up`)&&t<0&&(r=-(Math.abs(t)**u5))),{x:n,y:r}}function ne(e){if(e.button!==0)return;e.pointerType===`touch`&&u.pauseTimers();let t=V_(e.nativeEvent);if(!(t&&t.closest(`button,a,input,textarea,[role="button"],[data-swipe-ignore]`))){if(I.current=!1,P.current=void 0,F.current=0,M.current={x:e.clientX,y:e.clientY},L.current=M.current,j.current){let e=p5(j.current);N.current=e,C(e),x({x:e.x,y:e.y})}u.setHovering(!0),m(!0),g(!1),A(null),R.current=!0,j.current?.setPointerCapture(e.pointerId)}}function W(e){if(!p)return;e.preventDefault(),R.current&&=(M.current={x:e.clientX,y:e.clientY},!1);let{clientY:t,clientX:n,movementX:r,movementY:i}=e;(i<0&&t>L.current.y||i>0&&t<L.current.y)&&(L.current={x:L.current.x,y:t}),(r<0&&n>L.current.x||r>0&&n<L.current.x)&&(L.current={x:n,y:L.current.y});let a=n-M.current.x,o=t-M.current.y,s=t-L.current.y,l=n-L.current.x;if(!h&&Math.sqrt(a*a+o*o)>=d5&&(g(!0),O===null)){let e=c.includes(`left`)||c.includes(`right`),t=c.includes(`up`)||c.includes(`down`);e&&t&&A(Math.abs(a)>Math.abs(o)?`horizontal`:`vertical`)}let u;if(!P.current)O===`vertical`?o>0?u=`down`:o<0&&(u=`up`):O===`horizontal`?a>0?u=`right`:a<0&&(u=`left`):u=Math.abs(a)>=Math.abs(o)?a>0?`right`:`left`:o>0?`down`:`up`,u&&c.includes(u)&&(P.current=u,F.current=f5(u,a,o),f(u));else{let e=P.current,t=f5(e,l,s);t>c5?(I.current=!1,f(e)):!(c.includes(`left`)&&c.includes(`right`))&&!(c.includes(`up`)&&c.includes(`down`))&&F.current-t>=l5&&(I.current=!0)}let d=U(a,o),m=N.current.x,_=N.current.y;O===`horizontal`?(c.includes(`left`)||c.includes(`right`))&&(m+=d.x):(O===`vertical`||(c.includes(`left`)||c.includes(`right`))&&(m+=d.x),(c.includes(`up`)||c.includes(`down`))&&(_+=d.y)),x({x:m,y:_})}function re(e){if(!p)return;if(m(!1),g(!1),A(null),j.current?.releasePointerCapture(e.pointerId),I.current){x({x:S.x,y:S.y}),f(void 0);return}let t=!1,r=b.x-S.x,i=b.y-S.y,a;for(let e of c){switch(e){case`right`:r>c5&&(t=!0,a=`right`);break;case`left`:r<-c5&&(t=!0,a=`left`);break;case`down`:i>c5&&(t=!0,a=`down`);break;case`up`:i<-c5&&(t=!0,a=`up`);break;default:break}if(t)break}t?(f(a),v(!0),u.closeToast(n.id)):(x({x:S.x,y:S.y}),f(void 0))}function ie(e){if(e.key===`Escape`){if(!j.current||!z_(j.current,R_(i_(j.current))))return;u.closeToast(n.id)}}y.useEffect(()=>{if(!l)return;let e=j.current;if(!e)return;function t(t){z_(e,t.target)&&t.preventDefault()}return e.addEventListener(`touchmove`,t,{passive:!1}),()=>{e.removeEventListener(`touchmove`,t)}},[l]);function ae(){if(!p&&b.x===S.x&&b.y===S.y&&!_)return{[o5.swipeMovementX]:`0px`,[o5.swipeMovementY]:`0px`};let e=b.x-S.x,t=b.y-S.y;return{transition:p?`none`:void 0,transform:p?`translateX(${b.x}px) translateY(${b.y}px) scale(${S.scale})`:void 0,[o5.swipeMovementX]:`${e}px`,[o5.swipeMovementY]:`${t}px`}}let oe=n.priority===`high`,se={role:oe?`alertdialog`:`dialog`,tabIndex:0,"aria-modal":!1,"aria-labelledby":w,"aria-describedby":E,"aria-hidden":oe&&!ee?!0:void 0,onPointerDown:l?ne:void 0,onPointerMove:l?W:void 0,onPointerUp:l?re:void 0,onKeyDown:ie,inert:gw(n.limited),style:{...ae(),[o5.index]:n.transitionStatus===`ending`?z:B,[o5.offsetY]:`${V}px`,[o5.height]:n.height?`${n.height}px`:void 0}},ce=y.useMemo(()=>({rootRef:j,toast:n,titleId:w,setTitleId:T,descriptionId:E,setDescriptionId:D,swiping:p,swipeDirection:d,recalculateHeight:te,index:z,visibleIndex:B,expanded:H}),[n,w,E,p,d,te,z,B,H]),le={transitionStatus:n.transitionStatus,expanded:H,limited:n.limited||!1,type:n.type,swiping:ce.swiping,swipeDirection:ce.swipeDirection},ue=Pb(`div`,e,{ref:[t,ce.rootRef],state:le,stateAttributesMapping:s5,props:[se,o]});return(0,k.jsx)(i5.Provider,{value:ce,children:ue})}),h5=y.forwardRef(function(e,t){let{render:n,className:r,id:i,children:a,...o}=e,{toast:s,setDescriptionId:c}=a5(),l=a??s.description,u=!!l,d=Sy(i);a_(()=>{if(u)return c(d),()=>{c(void 0)}},[u,d,c]);let f=Pb(`p`,e,{ref:t,state:{type:s.type},props:{...o,id:d,children:l}});return u?f:null}),g5=y.forwardRef(function(e,t){let{render:n,className:r,id:i,children:a,...o}=e,{toast:s,setTitleId:c}=a5(),l=a??s.title,u=!!l,d=Sy(i);a_(()=>{if(u)return c(d),()=>{c(void 0)}},[u,d,c]);let f=Pb(`h2`,e,{ref:t,state:{type:s.type},props:{...o,id:d,children:l}});return u?f:null}),_5=y.forwardRef(function(e,t){let{render:n,className:r,disabled:i,nativeButton:a=!0,...o}=e,s=J8(),{toast:c}=a5(),l=s.useState(`expanded`),[u,d]=y.useState(!1),{getButtonProps:f,buttonRef:p}=$C({disabled:i,native:a}),m={type:c.type};return Pb(`button`,e,{ref:[t,p],state:m,props:[{"aria-hidden":!l&&!u,onClick(){s.closeToast(c.id)},onFocus(){d(!0)},onBlur(){d(!1)}},o,f]})});function v5(){let e=y.useContext(q8);if(!e)throw Error(mb(73));let t=e.useState(`toasts`);return y.useMemo(()=>({toasts:t,add:e.addToast,close:e.closeToast,update:e.updateToast,promise:e.promiseToast}),[t,e])}function y5(){let e=new Set;function t(t){e.forEach(e=>e(t))}return{" subscribe":function(t){return e.add(t),()=>{e.delete(t)}},add(e){let n=e.id||X8(`toast`);return t({action:`add`,options:{...e,id:n,transitionStatus:`starting`}}),n},close(e){t({action:`close`,options:{id:e}})},update(e,n){t({action:`update`,options:{...n,id:e}})},promise(e,n){let r=e;return t({action:`promise`,options:{...n,promise:e,setPromise(e){r=e}}}),r}}}var b5=5e3,x5=y5();function S5({toast:e}){return(0,k.jsxs)(m5,{toast:e,className:xE(`relative flex w-80 items-start gap-3 border bg-elevated p-4 shadow-lg`,`data-[swipe=move]:translate-x-[var(--toast-swipe-move-x)]`,`data-[ending-style]:translate-x-[var(--toast-swipe-end-x)]`,`data-[ending-style]:opacity-0`,`data-[starting-style]:translate-y-2 data-[starting-style]:opacity-0`,`transition-all duration-200`,e.type===`error`&&`border-danger/50`,e.type===`success`&&`border-approval/50`,(!e.type||e.type===`info`)&&`border-border`),children:[(0,k.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,k.jsx)(g5,{className:xE(`text-sm font-medium`,e.type===`error`&&`text-danger`,e.type===`success`&&`text-approval`,(!e.type||e.type===`info`)&&`text-primary`),children:e.title}),e.description&&(0,k.jsx)(h5,{className:`mt-1 text-xs text-muted line-clamp-2`,children:e.description})]}),(0,k.jsx)(_5,{className:`shrink-0 text-muted hover:text-primary transition-colors`,"aria-label":`Close`,children:(0,k.jsx)(ot,{width:K.default,height:K.default})})]})}function C5(){let{toasts:e}=v5();return(0,k.jsx)(k.Fragment,{children:e.map(e=>(0,k.jsx)(S5,{toast:e},e.id))})}function w5(){return(0,k.jsxs)(t5,{timeout:b5,toastManager:x5,children:[(0,k.jsx)(C5,{}),(0,k.jsx)(r5,{className:`fixed bottom-4 right-4 z-[100] flex flex-col gap-2`})]})}var T5=`Agentboard was updated. Reload this tab to reconnect. Your saved recovery drafts remain on this device.`,E5=[`CONNECTING`,`OPEN`,`CLOSING`,`CLOSED`],D5=3e3,O5=3e4,k5=8e3,A5=15e3,j5=5e3,M5=2e4,N5=3e4,P5=1e4,F5=1500,I5=5e3,L5=750,R5=4,z5=5e3,B5=new class{constructor(){this.ws=null,this.listeners=new Set,this.statusListeners=new Set,this.status=`connecting`,this.error=null,this.reconnectAttempts=0,this.overloadFailures=0,this.overloadRetryAt=0,this.overloadProgressSince=null,this.reconnectTimer=null,this.connectTimer=null,this.manualClose=!1,this.protocolMismatch=!1,this.protocolReady=!1,this.lastTick=Date.now(),this.wakeCheckInterval=null,this.lifecycleStarted=!1,this.heartbeatTimer=null,this.pongTimer=null,this.lastForceReconnectTs=0,this.lastConnectTs=0,this.traceId=`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,this.lastMessageAt=null,this.lastPongSeq=null,this.lastPingAt=null,this.lastMessageType=null,this.pingSeq=0,this.connectionEpoch=0,this.consecutiveFailures=0,this.stallCount=0,this.isResumeAttempt=!1,this.leakedSockets=new Set,this.verifyTimer=null,this.pageSuspended=!1,this.resumeClaim=0,this.attachId=0,this.attachedSessionId=null,this.readyAttachId=null,this.lastResumeAt=0,this.onVisibilityChange=()=>{uR(`ws_visibility`,{state:document.visibilityState,...this.wsSnap()},`info`),document.visibilityState===`visible`?(this.pageSuspended=!1,this.resumeConnection(`visibilitychange`)):this.suspendConnection()},this.onPageShow=e=>{uR(`ws_pageshow`,{persisted:e.persisted,...this.wsSnap()},`info`),e.persisted&&(this.pageSuspended=!1,this.resumeConnection(`pageshow`))},this.onPageHide=()=>{this.pageSuspended=!0,this.suspendConnection()}}wsSnap(){return{traceId:this.traceId,clientTimeMs:Date.now(),clientUptimeMs:Math.round(performance.now()),epoch:this.connectionEpoch,pingSeq:this.pingSeq,lastPongSeq:this.lastPongSeq,lastPingAgeMs:this.lastPingAt===null?null:Date.now()-this.lastPingAt,lastMessageType:this.lastMessageType,lastMessageAgeMs:this.lastMessageAt===null?null:Date.now()-this.lastMessageAt,visibility:typeof document>`u`?void 0:document.visibilityState,status:this.status,ws:this.ws?E5[this.ws.readyState]:null,attempt:this.reconnectAttempts,failures:this.consecutiveFailures,stalls:this.stallCount,overloads:this.overloadFailures,overloadDelayMs:Math.max(0,this.overloadRetryAt-Date.now()),leaked:this.leakedSockets.size,online:typeof navigator<`u`?navigator.onLine:void 0,verifying:this.verifyTimer!==null,buffered:this.ws?this.ws.bufferedAmount:void 0}}connect(){if(this.protocolMismatch||this.isHidden()||this.waitForOverloadCooldown())return;if(this.ws){let e=this.ws.readyState===WebSocket.OPEN;if(e&&this.status===`connected`){uR(`ws_connect_skip`,{reason:`already_open`,...this.wsSnap()});return}let t=Date.now();if(this.ws.readyState===WebSocket.CONNECTING&&t-this.lastConnectTs<200){uR(`ws_connect_skip`,{reason:`already_connecting`,...this.wsSnap()});return}uR(`ws_connect_destroy_zombie`,{reason:e?`open_desynced`:`not_open`,...this.wsSnap()}),this.destroySocket()}this.manualClose=!1,this.clearConnectTimer(),this.setStatus(`connecting`);let e=`${window.location.protocol===`https:`?`wss`:`ws`}://${window.location.host}/ws?catalog=2`;uR(`ws_connect`,{url:e,resume:this.isResumeAttempt,...this.wsSnap()},`info`);let t=new WebSocket(e),n=!1;this.ws=t,this.protocolReady=!1,this.lastMessageAt=null,this.lastPongSeq=null,this.lastPingAt=null,this.lastMessageType=null,this.lastConnectTs=Date.now(),this.leakedSockets.add(t);let r=this.isResumeAttempt?k5:D5;this.isResumeAttempt=!1,this.connectTimer=window.setTimeout(()=>{this.ws===t&&(this.connectTimer=null,t.readyState===WebSocket.OPEN&&this.status===`connected`||(uR(`ws_connect_timeout`,{wsState:E5[t.readyState],managerStatus:this.status,timeoutMs:r,...this.wsSnap()},`info`),this.consecutiveFailures+=1,this.destroySocket(),this.scheduleReconnect()))},r),t.onopen=()=>{if(this.ws!==t){uR(`ws_onopen_stale`,this.wsSnap(),`info`);return}uR(`ws_onopen`,this.wsSnap(),`info`),this.reconnectAttempts=0,this.consecutiveFailures=0,this.stallCount=0,this.connectionEpoch+=1,this.leakedSockets.delete(t),this.clearConnectTimer(),this.connectTimer=window.setTimeout(()=>{this.ws!==t||this.protocolReady||(this.connectTimer=null,this.consecutiveFailures+=1,this.destroySocket(),this.scheduleReconnect(),this.setStatus(`reconnecting`,`Server handshake timed out. Retrying…`))},O5)},t.onmessage=e=>{if(this.ws===t){this.lastMessageAt=Date.now(),this.lastMessageType=`unparsed`;try{let r=e.data,i=performance.now(),a=JSON.parse(r);if(this.lastMessageType=a.type,!this.protocolReady&&a.type!==`server-config`){this.requireCatalogReload();return}if(a.type===`server-config`){if(a.catalogVersion!==2){this.requireCatalogReload();return}if(!this.protocolReady){if(this.protocolReady=!0,this.clearConnectTimer(),!this.send({type:`terminal-resume`,token:this.resumeToken,claim:++this.resumeClaim}))return;this.lastTick=Date.now(),this.setStatus(this.isHidden()?`reconnecting`:`connected`),this.isHidden()||this.startHeartbeat()}}let o=performance.now()-i,s=a;if(s._parseMs=Math.round(o),s._rawLength=r.length,s._connectionEpoch=this.connectionEpoch,a.type===`terminal-lease`){this.resumeToken=a.token;return}if(a.type===`terminal-overload`){n=!0,this.stopHeartbeat(),this.cancelVerify(),this.setStatus(`reconnecting`),t.close();return}if(a.type===`pong`){if(this.lastPongSeq=a.seq??null,uR(`ws_pong_received`,{receivedSeq:a.seq,matchesPendingPing:a.seq===this.pingSeq,...this.wsSnap()}),a.seq===this.pingSeq){if(this.clearPongTimer(),this.verifyTimer!==null){if(this.cancelVerify(),uR(`ws_verify_ok`,this.wsSnap(),`info`),this.isHidden())return;this.connectionEpoch+=1,this.setStatus(`connected`),this.startHeartbeat(I5)}this.recordOverloadRecovery()}return}if(a.type===`terminal-output`||a.type===`terminal-ready`||a.type===`tmux-copy-mode-status`||a.type===`clipboard-offer`||a.type===`terminal-error`){if(!(this.status===`connected`&&!this.isHidden()&&(!a.sessionId||a.sessionId===this.attachedSessionId)&&(a.attachId===this.attachId||a.attachId===void 0&&!this.resumeToken))){a.type===`terminal-output`&&a.outputSeq!==void 0&&this.send({type:`terminal-ack`,outputSeq:a.outputSeq});return}a.type===`terminal-ready`&&(this.readyAttachId=this.attachId,this.recordOverloadRecovery())}this.listeners.forEach(e=>e(a))}catch{}}},t.onerror=()=>{this.ws===t&&(uR(`ws_onerror`,this.wsSnap(),`info`),this.clearConnectTimer())},t.onclose=e=>{if(this.leakedSockets.delete(t),this.ws!==t){uR(`ws_onclose_stale`,{code:e.code,...this.wsSnap()},`info`);return}uR(`ws_onclose`,{code:e.code,reason:e.reason,clean:e.wasClean,...this.wsSnap()},`info`),this.clearConnectTimer(),this.cancelVerify(),this.consecutiveFailures+=1,this.overloadProgressSince=null,(n||e.code===1013)&&(this.overloadFailures=Math.min(this.overloadFailures+1,6),this.overloadRetryAt=Date.now()+Math.min(1e3*2**(this.overloadFailures-1),3e4)),this.ws=null,this.manualClose?this.setStatus(`disconnected`):this.scheduleReconnect()}}requireCatalogReload(){this.protocolMismatch=!0,this.disconnect(),this.setStatus(`disconnected`,T5),this.listeners.forEach(e=>e({type:`error`,message:T5}))}disconnect(){this.overloadFailures=0,this.overloadRetryAt=0,this.overloadProgressSince=null,this.manualClose=!0,this.clearConnectTimer(),this.cancelVerify(),this.reconnectTimer&&=(window.clearTimeout(this.reconnectTimer),null),this.destroySocket(),this.setStatus(`disconnected`)}startLifecycleListeners(){this.lifecycleStarted||typeof document>`u`||typeof window>`u`||(this.lifecycleStarted=!0,document.addEventListener(`visibilitychange`,this.onVisibilityChange),window.addEventListener(`pageshow`,this.onPageShow),window.addEventListener(`pagehide`,this.onPageHide),this.lastTick=Date.now(),this.wakeCheckInterval=window.setInterval(()=>{let e=Date.now(),t=e-this.lastTick;this.isHidden()||(t>A5&&(uR(`ws_time_jump`,{gapMs:t,...this.wsSnap()},`info`),this.resumeConnection(`time_jump`)),this.lastTick=e)},j5))}stopLifecycleListeners(){this.lifecycleStarted&&(this.lifecycleStarted=!1,document.removeEventListener(`visibilitychange`,this.onVisibilityChange),window.removeEventListener(`pageshow`,this.onPageShow),window.removeEventListener(`pagehide`,this.onPageHide),this.wakeCheckInterval!==null&&(window.clearInterval(this.wakeCheckInterval),this.wakeCheckInterval=null))}send(e){if(this.protocolMismatch||!this.protocolReady||this.ws?.readyState!==WebSocket.OPEN)return!1;if(e.type===`terminal-ack`&&e.connectionEpoch!==void 0){if(e.connectionEpoch!==this.connectionEpoch)return!1;e={type:`terminal-ack`,outputSeq:e.outputSeq}}let t=e.type.startsWith(`terminal-`)||e.type.startsWith(`tmux-`),n=e.type===`terminal-resume`||e.type===`terminal-ack`;if(t&&!n){if(e.type!==`terminal-detach`){if(this.isHidden())return!1;if(Date.now()-this.lastTick>A5)return this.resumeConnection(`input_time_jump`),!1;if(this.status!==`connected`)return!1}if(e.type===`terminal-attach`)this.attachId+=1,this.attachedSessionId=e.sessionId,this.readyAttachId=null;else if(e.type===`terminal-input`||e.type===`terminal-paste`){if(this.readyAttachId!==this.attachId||e.sessionId!==this.attachedSessionId)return!1}else e.type===`terminal-detach`&&(this.readyAttachId=null,this.attachedSessionId=null);e={...e,attachId:this.attachId}}try{return this.ws.send(JSON.stringify(e)),e.type===`ping`&&(this.lastPingAt=Date.now(),uR(`ws_ping_sent`,this.wsSnap())),e.type===`terminal-ack`&&this.recordOverloadRecovery(),!0}catch(t){return uR(`ws_send_error`,{messageType:e.type,error:t instanceof Error?t.message:String(t),...this.wsSnap()},`info`),this.destroySocket(),this.scheduleReconnect(),!1}}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}subscribeStatus(e){return this.statusListeners.add(e),e(this.status,this.error,this.connectionEpoch),()=>this.statusListeners.delete(e)}getStatus(){return this.status}getConnectionEpoch(){return this.connectionEpoch}suspendConnection(){this.attachedSessionId&&this.send({type:`terminal-detach`,sessionId:this.attachedSessionId,attachId:this.attachId}),this.stopHeartbeat(),this.cancelVerify(),this.clearConnectTimer(),this.reconnectTimer!==null&&window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.manualClose||this.setStatus(`reconnecting`)}resumeConnection(e){if(this.manualClose||this.isHidden())return;let t=Date.now()-this.lastTick;this.lastTick=Date.now(),uR(`ws_resume`,{trigger:e,gapMs:t,...this.wsSnap()},`info`),!this.waitForOverloadCooldown()&&this.verifyTimer===null&&(Date.now()-this.lastResumeAt<200&&this.reconnectTimer!==null||this.ws?.readyState===WebSocket.CONNECTING&&this.connectTimer!==null&&t<A5||(this.lastResumeAt=Date.now(),this.reconnectTimer!==null&&window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.ws?.readyState===WebSocket.OPEN?this.verifyConnection():this.forceReconnect(e,!0)))}verifyConnection(){this.cancelVerify(),this.stopHeartbeat(),this.setStatus(`reconnecting`),this.pingSeq+=1;let e=this.pingSeq,t=this.ws;if(uR(`ws_verify`,{seq:e,...this.wsSnap()},`info`),!this.send({type:`ping`,seq:e})){uR(`ws_verify_send_fail`,this.wsSnap(),`info`),this.forceReconnect(`verify_send_fail`,!0);return}this.verifyTimer=window.setTimeout(()=>{this.verifyTimer=null,this.ws===t&&(uR(`ws_verify_timeout`,this.wsSnap(),`info`),this.forceReconnect(`verify_timeout`,!0))},F5)}cancelVerify(){this.verifyTimer!==null&&(window.clearTimeout(this.verifyTimer),this.verifyTimer=null)}forceReconnect(e=`unknown`,t=!1){if(this.protocolMismatch)return;if(this.manualClose){uR(`ws_force_skip`,{trigger:e,reason:`manual_close`});return}if(this.waitForOverloadCooldown())return;let n=Date.now(),r=t?200:500;if(n-this.lastForceReconnectTs<r){uR(`ws_force_skip`,{trigger:e,reason:`debounce`,force:t});return}if(!t&&this.ws?.readyState===WebSocket.OPEN&&this.status===`connected`){uR(`ws_force_skip`,{trigger:e,reason:`already_connected`});return}this.lastForceReconnectTs=n,uR(`ws_force_reconnect`,{trigger:e,force:t,...this.wsSnap()},`info`),this.reconnectAttempts=0,this.consecutiveFailures=0,this.stallCount=0,this.reconnectTimer&&=(window.clearTimeout(this.reconnectTimer),null),this.destroySocket(),t?(this.purgeLeakedSockets(),this.isResumeAttempt=!0,this.setStatus(`reconnecting`),this.reconnectTimer=window.setTimeout(()=>{this.reconnectTimer=null,this.connect()},L5)):this.connect()}startHeartbeat(e){if(this.stopHeartbeat(),this.isHidden())return;let t=()=>{this.isHidden()||this.ws?.readyState===WebSocket.OPEN&&(this.pingSeq+=1,this.send({type:`ping`,seq:this.pingSeq})&&(this.clearPongTimer(),this.pongTimer=window.setTimeout(()=>{this.pongTimer=null,uR(`ws_pong_timeout`,this.wsSnap(),`info`),this.destroySocket(),this.scheduleReconnect()},P5)))};e!==void 0&&e<M5?this.heartbeatTimer=window.setTimeout(()=>{t(),this.heartbeatTimer=window.setInterval(t,M5)},e):this.heartbeatTimer=window.setInterval(t,M5)}stopHeartbeat(){this.heartbeatTimer!==null&&(window.clearTimeout(this.heartbeatTimer),this.heartbeatTimer=null),this.clearPongTimer()}clearPongTimer(){this.pongTimer!==null&&(window.clearTimeout(this.pongTimer),this.pongTimer=null)}setStatus(e,t=null){this.protocolMismatch&&(e=`disconnected`,t=T5),e!==`connected`&&(this.readyAttachId=null,this.overloadProgressSince=null),this.status=e,this.error=t,this.statusListeners.forEach(n=>n(e,t,this.connectionEpoch))}recordOverloadRecovery(){if(this.overloadFailures===0||this.status!==`connected`||this.isHidden()||this.readyAttachId!==this.attachId)return;let e=Date.now();e-this.lastTick>A5&&(this.overloadProgressSince=null),this.overloadProgressSince??=e,e-this.overloadProgressSince>=N5&&(this.overloadFailures=0,this.overloadRetryAt=0,this.overloadProgressSince=null)}waitForOverloadCooldown(){let e=this.overloadRetryAt-Date.now();return e<=0?!1:(this.reconnectTimer!==null&&window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.setStatus(`reconnecting`),this.isHidden()||(this.reconnectTimer=window.setTimeout(()=>{this.reconnectTimer=null,this.connect()},e)),!0)}scheduleReconnect(){if(this.protocolMismatch)return;if(this.stopHeartbeat(),this.isHidden()){uR(`ws_schedule_skip`,{reason:`hidden`,...this.wsSnap()}),this.setStatus(`reconnecting`);return}if(this.waitForOverloadCooldown())return;if(this.consecutiveFailures>=R5){uR(`ws_stall_detected`,this.wsSnap(),`info`),this.purgeLeakedSockets();let e=Math.min(z5*2**this.stallCount,3e4);this.stallCount+=1,this.consecutiveFailures=0,this.reconnectAttempts=0,this.isResumeAttempt=!0,this.setStatus(`reconnecting`),this.reconnectTimer=window.setTimeout(()=>{this.reconnectTimer=null,this.connect()},e);return}this.reconnectAttempts+=1;let e=Math.min(1e3*2**(this.reconnectAttempts-1),3e4);uR(`ws_schedule_reconnect`,{delay:e,...this.wsSnap()}),this.setStatus(`reconnecting`),this.reconnectTimer&&window.clearTimeout(this.reconnectTimer),this.reconnectTimer=window.setTimeout(()=>{this.reconnectTimer=null,this.connect()},e)}isHidden(){return this.pageSuspended||typeof document<`u`&&document.visibilityState===`hidden`}clearConnectTimer(){this.connectTimer&&=(window.clearTimeout(this.connectTimer),null)}destroySocket(){if(this.clearConnectTimer(),this.stopHeartbeat(),this.cancelVerify(),!this.ws)return;let e=this.ws;this.ws=null,this.leakedSockets.add(e),e.onopen=null,e.onmessage=null,e.onerror=null,e.onclose=()=>{this.leakedSockets.delete(e),e.onclose=null};try{e.close()}catch{}e.readyState===WebSocket.CLOSED&&(this.leakedSockets.delete(e),e.onclose=null)}purgeLeakedSockets(){if(this.leakedSockets.size!==0){uR(`ws_purge_leaked`,{count:this.leakedSockets.size},`info`);for(let e of this.leakedSockets)try{e.onopen=null,e.onmessage=null,e.onerror=null,e.onclose=null,e.close()}catch{}this.leakedSockets.clear()}}};function V5(){let e=Qh(e=>e.setConnectionState);return(0,y.useEffect)(()=>{B5.connect(),B5.startLifecycleListeners();let t=B5.subscribeStatus((t,n,r)=>{e(t,n,r)});return()=>{t(),B5.stopLifecycleListeners()}},[e]),{sendMessage:(0,y.useMemo)(()=>e=>B5.send(e),[]),subscribe:(0,y.useMemo)(()=>B5.subscribe.bind(B5),[]),getConnectionEpoch:(0,y.useMemo)(()=>()=>B5.getConnectionEpoch(),[])}}var H5=100;function U5({viewport:e,win:t,doc:n}){if(!e)return!1;let r=Math.max(0,e.offsetTop||0),i=Math.max(0,e.offsetLeft||0),a=t.innerHeight-(e.height+r),o=Math.max(0,a),s=Math.max(0,e.height||0),c=Math.max(0,e.width||0);return n.documentElement.style.setProperty(`--keyboard-inset`,`${o}px`),n.documentElement.style.setProperty(`--viewport-offset-top`,`${r}px`),n.documentElement.style.setProperty(`--viewport-offset-left`,`${i}px`),n.documentElement.style.setProperty(`--visual-viewport-height`,`${s}px`),n.documentElement.style.setProperty(`--visual-viewport-width`,`${c}px`),o>H5?n.documentElement.classList.add(`keyboard-visible`):n.documentElement.classList.remove(`keyboard-visible`),!0}function W5(e){e.documentElement.style.removeProperty(`--keyboard-inset`),e.documentElement.style.removeProperty(`--viewport-offset-top`),e.documentElement.style.removeProperty(`--viewport-offset-left`),e.documentElement.style.removeProperty(`--visual-viewport-height`),e.documentElement.style.removeProperty(`--visual-viewport-width`),e.documentElement.classList.remove(`keyboard-visible`)}function G5(){(0,y.useEffect)(()=>{let e=window.visualViewport;if(!e)return;let t=null,n=null,r=()=>{let e=document.activeElement;if(!e)return!1;let t=e.tagName?.toLowerCase();return t===`input`||t===`textarea`?!0:!!e.isContentEditable},i=()=>{U5({viewport:e,win:window,doc:document})},a=()=>{if(typeof window.requestAnimationFrame!=`function`){i();return}t!==null&&window.cancelAnimationFrame(t);let e=performance.now(),n=()=>{i(),t=performance.now()-e<1500?window.requestAnimationFrame(n):null};t=window.requestAnimationFrame(n)},o=()=>{if(!r()){c();return}i()},s=()=>{n!==null||typeof window.setInterval!=`function`||(n=window.setInterval(o,250),o())},c=()=>{n===null||typeof window.clearInterval!=`function`||(window.clearInterval(n),n=null)},l=()=>{r()?(a(),s(),i()):c()},u=()=>{l()},d=()=>{l()},f=()=>{a()};return i(),l(),e.addEventListener(`resize`,i),e.addEventListener(`scroll`,i),typeof window.addEventListener==`function`&&(window.addEventListener(`resize`,i),window.addEventListener(`orientationchange`,f)),typeof document.addEventListener==`function`&&(document.addEventListener(`focusin`,u),document.addEventListener(`focusout`,d),document.addEventListener(`focus`,u,!0),document.addEventListener(`blur`,d,!0)),()=>{e.removeEventListener(`resize`,i),e.removeEventListener(`scroll`,i),typeof window.removeEventListener==`function`&&(window.removeEventListener(`resize`,i),window.removeEventListener(`orientationchange`,f)),typeof document.removeEventListener==`function`&&(document.removeEventListener(`focusin`,u),document.removeEventListener(`focusout`,d),document.removeEventListener(`focus`,u,!0),document.removeEventListener(`blur`,d,!0)),t!==null&&typeof window.cancelAnimationFrame==`function`&&window.cancelAnimationFrame(t),c(),W5(document)}},[])}var K5=[`theme`,`commandPresets`,`defaultPresetId`,`defaultProjectDir`,`lastProjectPath`,`recentPaths`,`sessionSortMode`,`sessionSortDirection`,`manualSessionOrder`,`sidebarAnchor`,`projectFilters`,`hostFilters`,`showProjectName`,`showLastUserMessage`,`showSessionIdPrefix`,`soundOnPermission`,`soundOnIdle`],q5=[`claude`,`claude-rp`,`codex`,`pi`,`devin`,`grok`,`omp`];function J5(e){return typeof e==`boolean`}function Y5(e,t){return Array.isArray(e)&&e.length<=t&&e.every(e=>typeof e==`string`)}function X5(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.id==`string`&&t.id.length>=1&&t.id.length<=128&&typeof t.label==`string`&&t.label.trim().length>=1&&t.label.length<=64&&typeof t.command==`string`&&t.command.trim().length>=1&&t.command.length<=1024&&typeof t.isBuiltIn==`boolean`&&(t.agentType===void 0||q5.includes(t.agentType))}var Z5={theme:e=>e===`dark`||e===`light`||e===`system`,commandPresets:e=>Array.isArray(e)&&e.length<=50&&e.every(X5),defaultPresetId:e=>typeof e==`string`&&e.length<=128,defaultProjectDir:e=>typeof e==`string`&&e.length<=4096,lastProjectPath:e=>e===null||typeof e==`string`&&e.length<=4096,recentPaths:e=>Y5(e,50),sessionSortMode:e=>e===`status`||e===`created`||e===`manual`,sessionSortDirection:e=>e===`asc`||e===`desc`,manualSessionOrder:e=>Y5(e,1e3),sidebarAnchor:e=>e===`top`||e===`bottom`,projectFilters:e=>Y5(e,500),hostFilters:e=>Y5(e,500),showProjectName:J5,showLastUserMessage:J5,showSessionIdPrefix:J5,soundOnPermission:J5,soundOnIdle:J5};function Q5(e){return K5.includes(e)}function $5(e,t){return Z5[e](t)}var e7=`agentboard-theme`,t7=`agentboard-settings`,n7=200,r7=new Map,i7=new Map,a7=new Set;function o7(e){return i7.has(e)||a7.has(e)}var s7=null,c7=!1;function l7(e){return e===`theme`?m0.getState().theme:G.getState()[e]}function u7(e){let t=e===`theme`?e7:t7;return w.getItem(t)!==null}function d7(){if(s7=null,i7.size===0)return;let e={},t=new Map,n=new Map;for(let[r,i]of i7)e[r]=JSON.parse(i),t.set(r,i),n.set(r,r7.get(r)),r7.set(r,i),a7.add(r);i7.clear();let r=()=>{for(let[e,r]of t){if(r7.get(e)!==r)continue;let t=n.get(e);t===void 0?r7.delete(e):r7.set(e,t)}},i=e=>{for(let n of t.keys()){if(a7.delete(n),!e||i7.has(n))continue;let t=r7.get(n);t!==void 0&&t!==JSON.stringify(l7(n))&&f7(n,JSON.parse(t))}},a=!1;try{fetch(`/api/settings/synced`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({settings:e})}).then(e=>{a=e.ok,e.ok||(uR(`synced_settings_push_rejected`,{status:e.status},`warn`),r())}).catch(e=>{uR(`synced_settings_push_failed`,{message:e instanceof Error?e.message:String(e)},`warn`),r()}).finally(()=>i(a))}catch(e){r(),i(!1),uR(`synced_settings_push_failed`,{message:e instanceof Error?e.message:String(e)},`warn`)}}function f7(e,t){e===`theme`?m0.setState({theme:t}):G.setState({[e]:t})}function p7(e,t){if(r7.get(e)===JSON.stringify(t)){i7.delete(e);return}m7(e,t)}function m7(e,t){i7.set(e,JSON.stringify(t)),!s7&&(s7=setTimeout(d7,n7))}function h7(e){let t=new Map;for(let e of K5)t.set(e,u7(e));let n={},r;for(let[t,i]of Object.entries(e))!Q5(t)||!$5(t,i)||(r7.set(t,JSON.stringify(i)),!o7(t)&&(t===`theme`?r=i:n[t]=i));r!==void 0&&m0.setState({theme:r}),Object.keys(n).length>0&&G.setState(n);for(let n of K5){if(n in e||!t.get(n))continue;let r=l7(n);$5(n,r)&&r7.get(n)!==JSON.stringify(r)&&m7(n,r)}}function g7(){if(c7)return()=>{};c7=!0;let e=G.subscribe((e,t)=>{let n=e,r=t;for(let e of K5)e!==`theme`&&n[e]!==r[e]&&p7(e,n[e])}),t=m0.subscribe((e,t)=>{e.theme!==t.theme&&p7(`theme`,e.theme)});return()=>{e(),t(),c7=!1,s7&&=(clearTimeout(s7),null),i7.clear(),a7.clear(),r7.clear()}}function _7(e,t,n){let r=e;return t.length>0&&(r=r.filter(e=>t.includes(e.projectPath))),n.length>0&&(r=r.filter(e=>n.includes(e.host??``))),r}function v7(){let[e,t]=(0,y.useState)(!1),[n,r]=(0,y.useState)(void 0),[i,a]=(0,y.useState)(void 0),[o,s]=(0,y.useState)(void 0),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),v=Qh(e=>e.sessions),b=Qh(e=>e.agentSessions),S=Qh(e=>e.agentSessionsEpoch),C=Qh(e=>e.selectedSessionId),w=Qh(e=>e.selectedHibernatingSessionId),T=Qh(e=>e.setSessions),E=Qh(e=>e.setAgentSessions),D=Qh(e=>e.setActiveAgentSessions),O=Qh(e=>e.setHostStatuses),A=Qh(e=>e.updateSession),j=Qh(e=>e.setSelectedSessionId),M=Qh(e=>e.setSelectedHibernatingSessionId),P=Qh(e=>e.hasLoaded),I=Qh(e=>e.connectionStatus),L=Qh(e=>e.connectionError),R=Qh(e=>e.clearExitingSession),z=Qh(e=>e.markSessionExiting),B=Qh(e=>e.setRemoteAllowControl),V=Qh(e=>e.setRemoteAllowAttach),ee=Qh(e=>e.setHostLabel),H=Qh(e=>e.setPreferWindowName),te=Qh(e=>e.hostStatuses),U=Qh(e=>e.remoteAllowControl),ne=Qh(e=>e.hostLabel),W=h0(),re=Ht(),ie=G(e=>e.defaultProjectDir),ae=G(e=>e.commandPresets),oe=G(e=>e.defaultPresetId),se=G(e=>e.lastProjectPath),ce=G(e=>e.setLastProjectPath),le=G(e=>e.addRecentPath),ue=G(e=>e.shortcutModifier),de=G(e=>e.sidebarWidth),fe=G(e=>e.sidebarAnchor),pe=G(e=>e.setSidebarWidth),me=G(e=>e.projectFilters),he=G(e=>e.hostFilters),ge=G(e=>e.soundOnPermission),_e=G(e=>e.soundOnIdle),ve=Qh(e=>e.connectionEpoch),{sendMessage:ye,subscribe:be,getConnectionEpoch:xe}=V5();(0,y.useEffect)(()=>g7(),[]),G5(),(0,y.useEffect)(()=>{if(typeof document>`u`||!ge&&!_e)return;let e=!1,t=()=>{e&&!Z6()||(e=!0,$6())};return document.addEventListener(`click`,t,{passive:!0}),document.addEventListener(`keydown`,t,{passive:!0}),document.addEventListener(`touchstart`,t,{passive:!0}),()=>{document.removeEventListener(`click`,t),document.removeEventListener(`keydown`,t),document.removeEventListener(`touchstart`,t)}},[ge,_e]);let Se=(0,y.useRef)(!1),Ce=(0,y.useCallback)(e=>{e.preventDefault(),Se.current=!0,document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`},[]);(0,y.useEffect)(()=>{if(typeof document>`u`||typeof document.addEventListener!=`function`)return;let e=e=>{if(!Se.current)return;let t=e.clientX;pe(Math.max(180,Math.min(400,t)))},t=()=>{Se.current&&(Se.current=!1,document.body.style.cursor=``,document.body.style.userSelect=``)};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t)}},[pe]),(0,y.useEffect)(()=>{let e=be(e=>{if(e.type!==`terminal-output`){if(e.type===`sessions`){let t=Qh.getState().sessions,{soundOnPermission:n,soundOnIdle:r}=G.getState();if(n||r)for(let i of e.sessions){let e=t.find(e=>e.id===i.id);e&&e.status!==i.status&&(e.status!==`permission`&&i.status===`permission`&&n&&n8(),e.status===`working`&&i.status===`waiting`&&r&&r8())}if(ze.current.size>0){let e=xe();for(let[t,n]of ze.current)n.epoch!==e&&ze.current.delete(t)}let i=ze.current.size>0?e.sessions.filter(e=>!ze.current.has(e.id)):e.sessions,{selectedSessionId:a,selectedHibernatingSessionId:o}=Qh.getState(),s=a!==null&&o===null&&!i.some(e=>e.id===a)?t.find(e=>e.id===a)?.agentSessionId?.trim()??null:null;s&&(Fe.current=s),T(i);let c=Ie.current,{selectedSessionId:l,selectedHibernatingSessionId:u}=Qh.getState(),{projectFilters:d,hostFilters:f}=G.getState();if(c&&l===null&&u===null){let e=i.find(e=>!(e.agentSessionId?.trim()!==c||d.length>0&&!d.includes(e.projectPath)||f.length>0&&!f.includes(e.host??``)));e&&(Ie.current=null,j(e.id))}}if(e.type===`host-status`&&O(e.hosts),e.type===`server-config`&&(B(e.remoteAllowControl),V(e.remoteAllowAttach),ee(e.hostLabel),H(e.preferWindowName),e.clientLogLevel&&lR(e.clientLogLevel)),e.type===`synced-settings`&&h7(e.settings),e.type===`session-update`){let t=Qh.getState().sessions.find(t=>t.id===e.session.id)?.status,n=e.session.status;if(A(e.session),t){let{soundOnPermission:e,soundOnIdle:r}=G.getState();t!==`permission`&&n===`permission`&&e&&n8(),t===`working`&&n===`waiting`&&r&&r8()}}if(e.type===`session-created`){let t=Qh.getState().sessions;t.some(t=>t.id===e.session.id)||T([e.session,...t]),j(e.session.id),le(e.session.projectPath);let{projectFilters:n,setProjectFilters:r}=G.getState();n.length>0&&!n.includes(e.session.projectPath)&&r([...n,e.session.projectPath])}if(e.type===`session-removed`){M1(e.sessionId);let t=Qh.getState().sessions,n=t.filter(t=>t.id!==e.sessionId);n.length!==t.length&&T(n)}if(e.type===`agent-sessions`){let t=Array.isArray(e.active)?e.active:[],n=Array.isArray(e.hibernating)?e.hibernating:[],r=Array.isArray(e.history)?e.history:[],{selectedHibernatingSessionId:i}=Qh.getState(),a=Fe.current;i&&!n.some(e=>e.sessionId===i)&&(Ie.current=i),E(t,n,r),_(e=>e&&n.some(t=>t.sessionId===e.sessionId)?null:e),a&&n.some(e=>e.sessionId===a)?(Fe.current=null,M(a)):a&&(Fe.current=null)}if(e.type===`agent-sessions-active`&&D(Array.isArray(e.active)?e.active:[]),e.type===`session-orphaned`&&!e.supersededBy){let t=Qh.getState().sessions,n=t.filter(t=>t.agentSessionId?.trim()!==e.session.sessionId);n.length!==t.length&&T(n)}if(e.type===`session-activated`){let t=Qh.getState().sessions.find(t=>t.tmuxWindow===e.window);t&&A({...t,agentSessionId:e.session.sessionId,agentSessionName:e.session.displayName,mediaSummary:e.session.mediaSummary,media:void 0,logFilePath:e.session.logFilePath,isHibernating:e.session.isHibernating,lastUserMessage:e.session.lastUserMessage??t.lastUserMessage})}if(e.type===`session-wake-result`)if(e.ok&&e.session){_(t=>t?.sessionId===e.sessionId?null:t);let t=Qh.getState().sessions;t.some(t=>t.id===e.session.id)||T([e.session,...t]),j(e.session.id)}else e.ok||(p(`${e.error?.code}: ${e.error?.message}`),window.setTimeout(()=>p(null),6e3));if(e.type===`session-hibernate-result`&&(e.ok?(e.session&&_(e.session),M(e.sessionId)):(p(e.error??`Failed to hibernate session`),window.setTimeout(()=>p(null),6e3))),e.type===`terminal-error`&&(!e.sessionId||e.sessionId===C)&&(p(`${e.code}: ${e.message}`),window.setTimeout(()=>p(null),6e3)),e.type===`terminal-ready`&&e.sessionId===C&&p(null),e.type===`error`&&(p(e.message),window.setTimeout(()=>p(null),6e3)),e.type===`kill-failed`){let t=ze.current.get(e.sessionId);if(t){let n=Qh.getState().sessions;n.some(t=>t.id===e.sessionId)||T([t.session,...n]),t.wasSelected&&j(e.sessionId),ze.current.delete(e.sessionId)}R(e.sessionId),p(e.message),window.setTimeout(()=>p(null),6e3)}e.type===`session-move-to-history-result`&&!e.ok&&e.error&&(p(e.error),window.setTimeout(()=>p(null),6e3))}});return()=>{e()}},[C,w,le,R,ye,j,M,_,T,E,D,O,B,V,ee,H,be,A]);let we=(0,y.useMemo)(()=>v.find(e=>e.id===C)||null,[C,v]),Te=b.hibernating??[],Ee=b.history??[],De=(0,y.useMemo)(()=>_7(Te,me,he),[Te,me,he]),Oe=(0,y.useMemo)(()=>De.find(e=>e.sessionId===w)||(g?.sessionId===w?g:null),[De,g,w]);(0,y.useEffect)(()=>{we?.projectPath&&!we.remote&&ce(we.projectPath)},[we?.projectPath,we?.remote,ce]);let ke=G(e=>e.sessionSortMode),Ae=G(e=>e.sessionSortDirection),je=G(e=>e.manualSessionOrder),Me=(0,y.useMemo)(()=>Fh(v,{mode:ke,direction:Ae,manualOrder:je}),[v,ke,Ae,je]),Ne=(0,y.useMemo)(()=>{let e=Me;return me.length>0&&(e=e.filter(e=>me.includes(e.projectPath))),he.length>0&&(e=e.filter(e=>he.includes(e.host??``))),e},[Me,me,he]),Pe=(0,y.useRef)(w),Fe=(0,y.useRef)(null),Ie=(0,y.useRef)(null),Le=(0,y.useRef)(ve),Re=(0,y.useCallback)(()=>Ne.length>0?(j(Ne[0].id),!0):De.length>0?(M(De[0].sessionId),!0):!1,[Ne,De,j,M]);(0,y.useEffect)(()=>{let e=Pe.current;e&&w===null&&!Te.some(t=>t.sessionId===e)?Ie.current=e:w!==null&&(Ie.current=null),Pe.current=w},[Te,w]),(0,y.useEffect)(()=>{g&&w!==g.sessionId&&_(null)},[g,w]),(0,y.useEffect)(()=>{Le.current!==ve&&(Le.current=ve,Fe.current=null,Ie.current=null,_(null))},[ve]),(0,y.useEffect)(()=>{P&&(w||C&&(Ne.some(e=>e.id===C)||Re()||j(null)))},[P,C,w,Re,j]),(0,y.useEffect)(()=>{if(!w||g?.sessionId===w||S!==ve||De.some(e=>e.sessionId===w))return;let e=Ne.find(e=>e.agentSessionId?.trim()===w);if(e){j(e.id);return}Re()||M(null)},[De,Ne,S,g,w,Re,j,M,ve]),(0,y.useEffect)(()=>{let e=Ie.current;if(!e)return;if(w!==null){Ie.current=null;return}let t=Ne.find(t=>t.agentSessionId?.trim()===e);if(t){Ie.current=null,j(t.id);return}if(C!==null){Ie.current=null;return}Re()&&(Ie.current=null)},[Ne,C,w,Re,j]),(0,y.useEffect)(()=>{window.matchMedia(`(max-width: 767px)`).matches&&P&&C===null&&w===null&&(Ne.length>0||De.length>0)&&Re()},[De.length,Ne.length,P,Re,C,w]);let ze=(0,y.useRef)(new Map),Be=(0,y.useCallback)((e,t=`unknown`)=>{M1(e);let{sessions:n,selectedSessionId:r}=Qh.getState(),i=n.find(t=>t.id===e);i&&ze.current.set(e,{session:i,wasSelected:r===e,epoch:xe()}),(0,_f.flushSync)(()=>{z(e),T(n.filter(t=>t.id!==e))}),ye({type:`session-kill`,sessionId:e,source:t})},[z,T,ye]);(0,y.useEffect)(()=>{let n=Dt(ue),r=r=>{if(r.defaultPrevented)return;let i=r.code,a=At(r,n);if(a&&(i===`BracketLeft`||i===`BracketRight`)){r.preventDefault();let e=fe===`bottom`&&!window.matchMedia(`(max-width: 767px)`).matches,t=(i===`BracketLeft`?-1:1)*(e?-1:1),n=Ne;if(n.length===0){let e=De;if(e.length===0)return;let n=e.findIndex(e=>e.sessionId===w);if(n===-1){M(e[0].sessionId);return}M(e[(n+t+e.length)%e.length].sessionId);return}let a=n.findIndex(e=>e.id===C);if(a===-1){j(n[0].id);return}j(n[(a+t+n.length)%n.length].id);return}if(a&&/^Digit[1-9]$/.test(i)){let e=Number(i.slice(5))-1;if(Ne.length>0){let t=Ne[e];if(!t)return;r.preventDefault(),j(t.id);return}let t=De[e];if(!t)return;r.preventDefault(),M(t.sessionId);return}if(a&&i===`KeyN`){r.preventDefault(),!e&&!c&&re&&t(!0);return}if(a&&i===`Comma`){r.preventDefault(),l(t=>t?!1:!e);return}if(a&&i===`KeyX`){r.preventDefault(),C&&!e&&!c&&Be(C,`keyboard_shortcut`);return}};return window.addEventListener(`keydown`,r),()=>window.removeEventListener(`keydown`,r)},[e,c,C,w,j,M,Ne,De,Be,fe,ue,re]);let Ve=()=>re?(r(void 0),a(void 0),s(void 0),t(!0),!0):!1,He=()=>l(!0),Ue=(e,t,n,r)=>{ye({type:`session-create`,operationId:x(),projectPath:e,name:t,command:n,host:r}),r||ce(e)},We=e=>{ye({type:`session-wake`,sessionId:e})},Ge=(0,y.useCallback)(e=>{ye({type:`session-hibernate`,sessionId:e})},[ye]),Ke=(e,t)=>{ye({type:`session-rename`,sessionId:e,newName:t})},qe=(0,y.useCallback)(e=>{let t=v.find(t=>t.id===e);t&&ye({type:`session-create`,operationId:x(),projectPath:t.projectPath,command:t.command||void 0,host:t.remote&&t.host?t.host:void 0})},[v,ye]),Je=(0,y.useCallback)(e=>{ye({type:`session-move-to-history`,sessionId:e})},[ye]);(0,y.useEffect)(()=>g0(),[]),(0,y.useEffect)(()=>{document.documentElement.setAttribute(`data-theme`,W)},[W]),(0,y.useEffect)(()=>{fetch(`/api/server-info`).then(e=>e.json()).then(e=>h(e)).catch(()=>{})},[]);let Ye=(0,y.useMemo)(()=>ne?te.filter(e=>e.host!==ne):te,[te,ne]);return(0,k.jsxs)(`div`,{className:`flex h-full overflow-clip`,children:[(0,k.jsx)(`div`,{className:`hidden h-full flex-col md:flex md:shrink-0`,style:{width:de},children:(0,k.jsx)(iR,{sessions:v,hibernatingSessions:Te,historySessions:Ee,selectedSessionId:C,selectedHibernatingSessionId:w,onSelect:j,onSelectHibernating:M,onRename:Ke,onResume:We,onHibernate:Ge,onKill:Be,onDuplicate:qe,onMoveToHistory:Je,onNewSession:Ve,loading:!P,error:L||f,anchor:fe,showAnchorControl:!0,notice:(0,k.jsx)(N,{onOpen:()=>d(!0),subscribe:be}),filterBarControls:(0,k.jsx)(tn,{connectionStatus:I,onNewSession:Ve,onOpenSettings:He,onOpenHistory:()=>d(!0),tailscaleIp:m?.tailscaleIp??null,placement:fe===`bottom`?`up`:`down`})})}),(0,k.jsx)(`div`,{className:`hidden md:block w-1 shrink-0 cursor-col-resize bg-transparent transition-colors hover:bg-white/10 active:bg-white/20`,onMouseDown:Ce}),(0,k.jsx)(x3,{session:we,sessions:Ne,drawerSessions:v,hibernatingSession:Oe,hibernatingSessions:Te,connectionStatus:I,connectionEpoch:ve,sendMessage:ye,subscribe:be,onClose:()=>j(null),onSelectSession:j,onSelectHibernatingSession:M,onNewSession:Ve,onKillSession:Be,onRenameSession:Ke,onDuplicateSession:qe,onOpenSettings:He,onOpenHistory:()=>d(!0),onResumeSession:We,onHibernateSession:Ge,onMoveToHistory:Je,historySessions:Ee,loading:!P,error:L||f}),(0,k.jsx)(B3,{isOpen:e,onClose:()=>t(!1),onCreate:Ue,defaultProjectDir:ie,commandPresets:ae,defaultPresetId:oe,lastProjectPath:se,activeProjectPath:we&&!we.remote?we.projectPath:void 0,remoteHosts:Ye,remoteAllowControl:U,initialHost:n,initialPath:i,initialCommand:o}),(0,k.jsx)(U8,{isOpen:c,onClose:()=>l(!1)}),(0,k.jsx)(F,{open:u,subscribe:be,onClose:()=>d(!1),onOpenSession:e=>{T([e,...v.filter(t=>t.id!==e.id)]),M(null),j(e.id)}}),(0,k.jsx)(w5,{})]})}var y7=`modulepreload`,b7=function(e){return`/`+e},x7={},S7=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}r=o(t.map(t=>{if(t=b7(t,n),t in x7)return;x7[t]=!0;let r=t.endsWith(`.css`),i=r?`[rel="stylesheet"]`:``;if(n)for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}else if(document.querySelector(`link[href="${t}"]${i}`))return;let o=document.createElement(`link`);if(o.rel=r?`stylesheet`:y7,r||(o.as=`script`),o.crossOrigin=``,o.href=t,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),r)return new Promise((e,n)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},C7=`true`,w7=`false`,T7=C7===`true`,E7=w7===`true`;function D7(e={}){let{immediate:t=!1,onNeedRefresh:n,onOfflineReady:r,onRegistered:i,onRegisteredSW:a,onRegisterError:o}=e,s,c,l,u=async(e=!0)=>{await c,T7||l?.()};async function d(){if(`serviceWorker`in navigator){if(s=await S7(async()=>{let{Workbox:e}=await import(`./workbox-window.prod.es5-Bq4GJJid.js`);return{Workbox:e}},[]).then(({Workbox:e})=>new e(`/sw.js`,{scope:`/`,type:`classic`})).catch(e=>{o?.(e)}),!s)return;if(l=()=>{s?.messageSkipWaiting()},!E7)if(T7)s.addEventListener(`activated`,e=>{(e.isUpdate||e.isExternal)&&window.location.reload()}),s.addEventListener(`installed`,e=>{e.isUpdate||r?.()});else{let e=!1,t=()=>{e=!0,s?.addEventListener(`controlling`,e=>{e.isUpdate&&window.location.reload()}),n?.()};s.addEventListener(`installed`,n=>{n.isUpdate===void 0?n.isExternal===void 0?!e&&r?.():n.isExternal?t():!e&&r?.():n.isUpdate||r?.()}),s.addEventListener(`waiting`,t)}s.register({immediate:t}).then(e=>{a?a(`/sw.js`,e):i?.(e)}).catch(e=>{o?.(e)})}}return c=d(),u}Ct()&&document.documentElement.classList.add(`ios`),Tt()&&document.documentElement.classList.add(`ios-pwa`),D7({immediate:!0,onRegisteredSW(e,t){t&&(setInterval(()=>{t.update()},300*1e3),document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`visible`&&t.update()}))}});var O7=document.getElementById(`root`);if(!O7)throw Error(`Root element not found`);(0,b.createRoot)(O7).render((0,k.jsx)(y.StrictMode,{children:(0,k.jsx)(v7,{})}));
|
|
311
|
+
`),!0),[o]),l=(0,y.useCallback)(()=>{e&&r(t.remove(e,i?.revision??null))},[t,e,i?.revision]),u=(0,y.useCallback)(()=>{e&&r(t.remove(e,i?.revision??null,!0))},[t,e,i?.revision]),d=(0,y.useCallback)(()=>r(t.removeOthers(e)),[t,e]),f=(0,y.useCallback)(()=>o(()=>i?.text??``,!1,!0),[o,i?.text]);return{text:i?.text??``,pending:!!i,truncated:!!i?.truncated,persistence:a,hasOtherDrafts:n.overflow||Object.keys(n.drafts).some(t=>t!==e),atLimit:n.overflow||Object.values(n.drafts).reduce((e,t)=>e+t.text.length,0)>=65535||Object.keys(n.drafts).length>=128,capture:s,edit:c,discard:l,discardOthers:d,save:f,sent:u}}function g3(e){let t=e.agentboardTags?.serverPid,n=typeof t==`number`&&Number.isSafeInteger(t)&&t>0?t:null;return JSON.stringify([e.id,e.tmuxWindow,e.host??null,e.remote===!0,n,n===null?e.createdAt:null])}function _3({isOpen:e,onClose:t,sessions:n,hibernatingSessions:r=[],historySessions:i=[],selectedSessionId:a,selectedHibernatingSessionId:o=null,onSelect:s,onSelectHibernating:c,onRename:l,onResume:u,onHibernate:d,onMoveToHistory:f,onNewSession:p,onOpenHistory:m,subscribe:h,loading:g,error:_}){let v=gf(),b=(0,y.useRef)(null),x=(0,y.useRef)(null);(0,y.useEffect)(()=>{if(!e||typeof document>`u`)return;let{body:t}=document,n=window.scrollY,r={position:t.style.position,top:t.style.top,width:t.style.width};return t.style.position=`fixed`,t.style.top=`-${n}px`,t.style.width=`100%`,()=>{t.style.position=r.position,t.style.top=r.top,t.style.width=r.width,window.scrollTo(0,n)}},[e]),(0,y.useEffect)(()=>{if(!e)return;let n=e=>{e.key===`Escape`&&(e.preventDefault(),t())};return document.addEventListener(`keydown`,n),()=>document.removeEventListener(`keydown`,n)},[e,t]),(0,y.useEffect)(()=>{e?(x.current=document.activeElement,b.current?.focus({preventScroll:!0})):x.current&&=(x.current.focus({preventScroll:!0}),null)},[e]),(0,y.useEffect)(()=>{if(!e)return;let n=b.current;if(!n)return;let r=0,i=0,a=e=>{let t=e.touches[0];r=t.clientX,i=t.clientY},o=e=>{let n=e.changedTouches[0],a=r-n.clientX,o=Math.abs(n.clientY-i);a>=50&&a>o*1.5&&(`vibrate`in navigator&&navigator.vibrate(10),t())};return n.addEventListener(`touchstart`,a,{passive:!0}),n.addEventListener(`touchend`,o,{passive:!0}),()=>{n.removeEventListener(`touchstart`,a),n.removeEventListener(`touchend`,o)}},[e,t]);let S=e=>{s(e),t()},C=e=>{c?.(e),t()},w=m?()=>{t(),m()}:void 0,T=v?{transition:`none`}:void 0;return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:`session-drawer-backdrop ${e?`open`:``}`,style:T,onClick:t,"aria-hidden":`true`}),(0,k.jsxs)(`div`,{ref:b,className:`session-drawer ${e?`open`:``}`,style:T,role:`dialog`,"aria-modal":e?!0:void 0,"aria-label":`Session list`,tabIndex:-1,children:[(0,k.jsx)(iR,{sessions:n,hibernatingSessions:r,historySessions:i,selectedSessionId:a,selectedHibernatingSessionId:o,onSelect:S,onSelectHibernating:C,onRename:l,onResume:u,onHibernate:d,onMoveToHistory:f,scrollSelectionActive:e,onNewSession:()=>{p()!==!1&&t()},loading:g,error:_,notice:w&&(0,k.jsx)(N,{onOpen:w,subscribe:h})}),(0,k.jsxs)(`div`,{className:`flex shrink-0 gap-2 border-t border-border px-2 pt-2`,style:{paddingBottom:`max(0.5rem, env(safe-area-inset-bottom, 0.5rem))`},children:[(0,k.jsx)(`button`,{onClick:()=>{p()!==!1&&t()},className:`btn btn-primary min-h-[44px] flex-1 py-2 text-sm`,children:`New Session`}),w&&(0,k.jsx)(`button`,{type:`button`,onClick:w,className:Jt(`neutral`),title:`Session recovery`,"aria-label":`Session recovery`,children:(0,k.jsx)(ce,{width:K.primary,height:K.primary})})]})]})]})}var v3={working:`bg-working/45`,waiting:`bg-waiting/45`,permission:`bg-approval`,unknown:`bg-muted/40`};function y3({sessions:e,selectedId:t,isOpen:n,onOpen:r}){let i=(0,y.useId)();return(0,k.jsxs)(`button`,{type:`button`,"data-testid":`session-peek`,className:`absolute inset-y-0 left-0 z-10 flex w-[8px] flex-col gap-1 overflow-hidden bg-elevated py-1 md:hidden focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent focus-visible:outline-offset-[-2px]`,"aria-label":`Open session overview`,"aria-expanded":n,"aria-describedby":i,onClick:r,children:[(0,k.jsx)(`span`,{id:i,className:`sr-only`,children:e.map(e=>`${e.name}: ${E0[e.status]}${e.id===t?`, current session`:``}`).join(`; `)}),e.map(e=>(0,k.jsx)(`span`,{"data-session-id":e.id,"data-status":e.status,"data-selected":e.id===t,"aria-hidden":`true`,className:`relative min-h-0 max-h-12 w-full flex-1 rounded-r-sm ${v3[e.status]}`,children:e.id===t&&(0,k.jsx)(`span`,{className:`absolute inset-y-1/3 left-0 w-1 rounded-r-sm bg-primary`})},e.id))]})}function b3(){`vibrate`in navigator&&navigator.vibrate(10)}function x3({session:e,sessions:t,drawerSessions:n,hibernatingSession:r=null,hibernatingSessions:i=[],historySessions:a=[],connectionStatus:o,connectionEpoch:s=0,sendMessage:c,subscribe:l,onClose:u,onSelectSession:d,onSelectHibernatingSession:f,onNewSession:p,onKillSession:m,onRenameSession:h,onDuplicateSession:g,onResumeSession:_,onHibernateSession:v,onMoveToHistory:b,onOpenSettings:x,onOpenHistory:S,loading:C=!1,error:w=null}){let T=(0,y.useRef)(void 0),E=(0,y.useCallback)(e=>((e.type===`terminal-input`||e.type===`terminal-paste`)&&T.current?.(),c(e)),[c]),D=_0[h0()],O=G(e=>e.compactMobileControls),A=G(e=>e.showMobileSessionPeek),j=G(e=>e.useWebGL),M=G(e=>e.fontSize),N=G(e=>e.lineHeight),P=G(e=>e.letterSpacing),F=Ft(G(e=>e.fontOption),G(e=>e.customFontFamily)),I=kt(Dt(G(e=>e.shortcutModifier))),R=Ct(),B=ag(),[V,ee]=(0,y.useState)(!1),[H,te]=(0,y.useState)(!1),[U,ne]=(0,y.useState)(!1),[W,re]=(0,y.useState)(!1),[ie,ae]=(0,y.useState)(!1),[se,ce]=(0,y.useState)(!1),[le,ue]=(0,y.useState)(``),de=(0,y.useRef)(!1),fe=(0,y.useRef)(null),pe=(0,y.useRef)(null),he=(0,y.useRef)(null),_e=(0,y.useRef)(null),ve=(0,y.useRef)(()=>{}),ye=(0,y.useRef)(()=>{}),be=e?.remote===!0,xe=Qh(e=>e.remoteAllowControl),Se=Qh(e=>e.remoteAllowAttach),Ce=be&&!Se,we=!be||xe&&e?.source===`managed`,Te=r?r.displayName||Bh(r.projectPath)||r.sessionId.slice(0,8):``,Ee=r?Bh(r.projectPath):``,De=r?zh(r.lastActivityAt):``,Oe=!!e&&!!v&&e.source===`managed`&&!e.remote&&!!e.agentSessionId?.trim(),ke=(0,y.useMemo)(()=>{let e=new Set;for(let n of t)n.host?.trim()&&e.add(n.host.trim());for(let t of i)t.host?.trim()&&e.add(t.host.trim());return e.size>1},[t,i]),Ae=e&&!Ce?g3(e):null,je=h3(Ae),{resetNativeInput:Me,containerRef:Ne,terminalRef:Pe,inTmuxCopyModeRef:Fe,isTmuxCopyMode:Le,appMouseRef:Re,setTmuxCopyMode:ze,isSwitching:Ve,isInputReady:He,pendingClipboardOffer:Ue,copyPendingClipboardOffer:We,dismissPendingClipboardOffer:Ge}=o0({sessionId:e?.id??null,tmuxTarget:e?.tmuxWindow??null,agentType:e?.agentType,onPasteFiles:e=>ve.current(e),onPasteError:e=>ye.current(e),allowAttach:!Ce,deferInput:je.pending,onDeferredInput:je.capture,connectionStatus:o,connectionEpoch:s,sendMessage:E,subscribe:l,theme:D,fontSize:M,lineHeight:N,letterSpacing:P,fontFamily:F,useWebGL:j,onScrollChange:e=>{ee(!e)}});T.current=Me;let Ke=r4({sessionId:e?.id??null,sendMessage:E,subscribe:l}),qe=Ke.state.status!==`closed`,Ye=i4(Ke.open,fe),Xe=a4(Ke.state,e?.agentType),Ze=(0,y.useCallback)(()=>{!e||Ce||(E({type:`tmux-cancel-copy-mode`,sessionId:e.id}),ze(!1),Pe.current?.scrollToBottom())},[e,Ce,E,ze,Pe]),Qe=(0,y.useCallback)(()=>{ae(!0),b3()},[]),$e=u0({enabled:B||R,isOpen:ie,onOpen:Qe});(0,y.useEffect)(()=>{!B&&!R&&ie&&ae(!1)},[ie,B,R]),s0(pe,W,(0,y.useCallback)(()=>re(!1),[])),(0,y.useEffect)(()=>{se&&he.current&&(he.current.focus(),he.current.select())},[se]),(0,y.useEffect)(()=>{U&&_e.current&&_e.current.focus()},[U]),c0(U,(0,y.useCallback)(()=>ne(!1),[]));let tt=()=>{e&&(m(e.id,`terminal_confirm_modal`),ne(!1))},nt=()=>{!e||!Oe||(v?.(e.agentSessionId.trim()),re(!1))},rt=()=>{e&&(ue(e.agentSessionName||e.name),ce(!0),re(!1))},it=()=>{if(!e)return;let t=le.trim(),n=e.agentSessionName||e.name;t&&t!==n&&h(e.id,t),ce(!1)},at=e=>{e.key===`Enter`?(e.preventDefault(),it()):e.key===`Escape`&&(e.preventDefault(),ce(!1))};(0,y.useEffect)(()=>{if(!R||!e){te(!1);return}let t=Ne.current;if(!t)return;let n=e=>{let n=t.querySelector(`.xterm-accessibility-tree`);if(!n)return!1;let r=e.anchorNode,i=e.focusNode;return!!r&&n.contains(r)||!!i&&n.contains(i)},r=()=>{let e=t.querySelector(`.xterm-accessibility`),n=t.querySelector(`.xterm-accessibility-tree`);!e||!n||(e.style.setProperty(`opacity`,`0`),n.style.setProperty(`opacity`,`0`),e.style.setProperty(`-webkit-user-select`,`none`),e.style.setProperty(`user-select`,`none`),n.style.setProperty(`-webkit-user-select`,`none`),n.style.setProperty(`user-select`,`none`),e.offsetHeight,requestAnimationFrame(()=>{e.style.removeProperty(`opacity`),n.style.removeProperty(`opacity`),e.style.removeProperty(`-webkit-user-select`),e.style.removeProperty(`user-select`),n.style.removeProperty(`-webkit-user-select`),n.style.removeProperty(`user-select`)}))},i=null,a=()=>{i?.(),i=null},o=()=>{a(),de.current=!1;let e=window.getSelection();try{e?.removeAllRanges()}catch{}Pe.current?.clearSelection(),r(),te(!1)};fe.current=o;let s=()=>{let e=window.getSelection();if(!e||e.rangeCount===0||e.isCollapsed){de.current?o():(a(),te(e=>e&&!1));return}let r=n(e);if(!r&&de.current){o();return}if(de.current=r,r&&!i){let e=t.querySelector(`.xterm-accessibility-tree`);e&&(i=k1(e,()=>window.getSelection(),o))}let s=r;te(e=>e===s?e:s)},c=()=>{let e=window.getSelection();!e||e.isCollapsed||n(e)&&setTimeout(o,0)},l=null,u=!1,d=e=>{if(e.touches.length===1){let t=e.touches[0];l={x:t.clientX,y:t.clientY},u=!1}},f=e=>{if(u||!l||e.touches.length!==1)return;let t=e.touches[0],n=Math.abs(t.clientX-l.x),r=Math.abs(t.clientY-l.y);(n>10||r>10)&&(u=!0)},p=e=>{let r=u;l=null,u=!1;let i=window.getSelection();if(!i||i.rangeCount===0||i.isCollapsed){te(!1);return}let a=t.querySelector(`.xterm-accessibility-tree`);if(!a)return;if(!n(i)){te(!1);return}if(r)return;let s=e.target,c=s?a.contains(s):!1,d=!1;if(c&&s)try{d=i.containsNode(s,!0)}catch{d=!1}(!c||!d)&&setTimeout(o,0)};return document.addEventListener(`selectionchange`,s),document.addEventListener(`copy`,c),document.addEventListener(`touchstart`,d,{passive:!0}),document.addEventListener(`touchmove`,f,{passive:!0}),document.addEventListener(`touchend`,p,{passive:!0}),()=>{document.removeEventListener(`selectionchange`,s),document.removeEventListener(`copy`,c),document.removeEventListener(`touchstart`,d),document.removeEventListener(`touchmove`,f),document.removeEventListener(`touchend`,p),a(),fe.current=null,de.current=!1}},[Ne,R,e?.id]),(0,y.useEffect)(()=>{if(!R)return;let t=Ne.current;if(!t)return;let n=null,r=()=>{let e=Pe.current,r=t.querySelector(`.xterm`);if(!e||!r)return;let i=r.querySelector(`.xterm-screen`),a=r.querySelector(`.xterm-accessibility`),o=r.querySelector(`.xterm-accessibility-tree`);if(!i||!a||!o)return;n||=T0(o);let s=r.getBoundingClientRect(),c=i.getBoundingClientRect(),l=c.left-s.left,u=c.top-s.top;Object.assign(a.style,{left:`${l}px`,top:`${u}px`,right:`auto`,bottom:`auto`,width:`${c.width}px`,height:`${c.height}px`});let d=c.width/e.cols,f=c.height/e.rows,p=document.createElement(`span`);p.textContent=`0`.repeat(200),p.style.cssText=`position:absolute;visibility:hidden;white-space:pre;pointer-events:none;letter-spacing:0px`,p.setAttribute(D1,``),o.appendChild(p);let m=p.getBoundingClientRect().width/200;p.remove();let h=Math.max(-2,Math.min(2,d-m));t.style.setProperty(`--xterm-font-size`,`${e.options.fontSize}px`),t.style.setProperty(`--xterm-cell-height`,`${f}px`),t.style.setProperty(`--xterm-a11y-letter-spacing`,`${h}px`)},i=performance.now();r();let a=Math.round(performance.now()-i);a>10&&uR(`switch_a11y_overlay`,{sessionId:e?.id,a11yMs:a});let o=window.requestAnimationFrame(r),s=window.setTimeout(r,100),c=()=>window.requestAnimationFrame(r);return window.visualViewport?.addEventListener(`resize`,c),window.addEventListener(`orientationchange`,c),()=>{window.cancelAnimationFrame(o),window.clearTimeout(s),window.visualViewport?.removeEventListener(`resize`,c),window.removeEventListener(`orientationchange`,c),n?.()}},[Ne,M,R,e?.id,Pe]);let st=(0,y.useRef)(H);(0,y.useEffect)(()=>{st.current=H},[H]);let ct=(0,y.useRef)(e?.id);(0,y.useEffect)(()=>{ct.current=e?.id},[e?.id]);let lt=(0,y.useRef)(E);(0,y.useEffect)(()=>{lt.current=E},[E]);let ut=(0,y.useRef)(!1),dt=(0,y.useRef)(`idle`);(0,y.useEffect)(()=>{if(!R)return;let e=Ne.current;if(!e)return;let t=null,n=()=>e.querySelector(`.xterm-helper-textarea`),r=e=>{e.target===n()&&(dt.current=`focused`)},i=e=>{e.target===n()&&(t!==null&&window.clearTimeout(t),t=window.setTimeout(()=>{t=null;let e=n(),r=typeof document.hasFocus!=`function`||document.hasFocus();document.activeElement!==e&&document.visibilityState!==`hidden`&&r&&(dt.current=`idle`)},0))},a=()=>{let e=n();(document.activeElement===e||dt.current===`focused`)&&(dt.current=`interrupted`)},o=()=>{dt.current===`interrupted`&&(dt.current=`armed`)},s=()=>{document.visibilityState===`hidden`?a():o()},c=e=>{e.persisted&&o()};return document.addEventListener(`focusin`,r),document.addEventListener(`focusout`,i),document.addEventListener(`visibilitychange`,s),window.addEventListener(`blur`,a),window.addEventListener(`focus`,o),window.addEventListener(`pageshow`,c),()=>{document.removeEventListener(`focusin`,r),document.removeEventListener(`focusout`,i),document.removeEventListener(`visibilitychange`,s),window.removeEventListener(`blur`,a),window.removeEventListener(`focus`,o),window.removeEventListener(`pageshow`,c),t!==null&&window.clearTimeout(t),dt.current=`idle`}},[Ne,R,e?.id]),(0,y.useEffect)(()=>{let t=Ne.current;if(!t||!e?.id||!B&&!R)return;let n={x:0,y:0},r=0,i=!1,a=null,o=0,s=0,c=0,l=Math.round(M*N),u=null,d=null,f=!1,p=null,m=()=>{let e=window.getComputedStyle(t).getPropertyValue(`--xterm-cell-height`).trim(),n=Number.parseFloat(e);return!Number.isNaN(n)&&n>0?n:Math.round(M*N)},h=()=>t.querySelector(`.xterm-helper-textarea`),g=e=>{let n=Pe.current;if(!n)return null;let r=(t.querySelector(`.xterm`)?.querySelector(`.xterm-screen`))?.getBoundingClientRect();if(!r||r.width<=0||r.height<=0)return null;let i=r.width/n.cols,a=r.height/n.rows;return i<=0||a<=0?null:{col:Math.min(n.cols,Math.max(1,Math.floor((e.clientX-r.left)/i)+1)),row:Math.min(n.rows,Math.max(1,Math.floor((e.clientY-r.top)/a)+1))}},_=()=>{let e=h();e&&document.activeElement!==e&&(e.disabled=!0)},v=()=>{let e=h();e&&(e.disabled=!1)};_();let y=()=>{if(Fe.current)return;let e=h();e&&(e.disabled=!1,e.focus())},b=()=>{u!==null&&(cancelAnimationFrame(u),u=null),s=0},x=()=>{d!==null&&(clearTimeout(d),d=null)},S=(e,t,n)=>{let r=ct.current;return r?(lt.current({type:`terminal-input`,sessionId:r,data:`\x1b[<${e};${t.col};${t.row}${n}`}),!0):!1},C=e=>{let t=ct.current;if(!t||e===0)return!1;let n=Pe.current,r=n?.cols??80,i=n?.rows??24,a=Math.floor(r/2),o=Math.floor(i/2),s=e>0?65:64,c=Math.abs(e),l=e<0;for(let e=0;e<c;e++)lt.current({type:`terminal-input`,sessionId:t,data:`\x1b[<${s};${a};${o}M`});return l&&!Re.current&&ze(!0),l},w=e=>{let t=ct.current,n=g(e);return!t||!n?!1:(lt.current({type:`terminal-input`,sessionId:t,data:`\x1b[<0;${n.col};${n.row}M\x1b[<0;${n.col};${n.row}m`}),!0)},T=e=>{if(!R||!Re.current)return!1;let t=g(e);return t?(f=!0,p=t,_(),b3(),S(0,t,`M`)):!1},E=e=>{let t=g(e);return t?p&&p.col===t.col&&p.row===t.row?!0:(p=t,S(32,t,`M`)):!1},D=e=>{let t=e?g(e):p;return f=!1,p=null,t?S(0,t,`m`):!1},O=()=>{x(),f=!1,p=null,a=null,s=0,c=0},k=()=>{if(!R)return!1;let e=window.getSelection();if(!e||e.isCollapsed)return!1;let n=t.querySelector(`.xterm-accessibility-tree`);if(!n)return!1;let r=e.anchorNode,i=e.focusNode;return!!r&&n.contains(r)||!!i&&n.contains(i)},A=()=>{!R||!de.current||k()||fe.current?.()},j=e=>{if(b(),A(),$e.current||ie){O();return}if(st.current){O();return}if(dt.current===`armed`&&!Fe.current&&(dt.current=`idle`,y()),e.touches.length===1){let t=e.touches[0];if(n={x:t.clientX,y:t.clientY},r=performance.now(),i=!1,a=t.clientY,o=r,s=0,c=0,l=m(),v(),R&&Re.current&&e.target!==h()){let e={clientX:t.clientX,clientY:t.clientY};d=setTimeout(()=>{d=null,!(i||$e.current||ie)&&(st.current||k()||T(e))},350)}}},P=e=>{if(e.touches.length!==1||a===null)return;if(A(),$e.current||ie){O();return}let t=performance.now(),r=e.touches[0],u=r.clientX,d=r.clientY;if(f){e.preventDefault(),e.stopPropagation(),E(r),a=d,o=t;return}if(st.current||k()){O();return}e.preventDefault(),e.stopPropagation();let p=Math.abs(u-n.x),m=Math.abs(d-n.y);!i&&(p>6||m>6)&&(i=!0,x(),_());let h=a-d,g=t-o;if(a=d,o=t,g>0){let e=h/g;s=s*.7+e*.3}c+=h;let v=Math.max(6,l*.6),y=Math.trunc(c/v);y!==0&&(C(y),c-=y*v)},F=e=>{let t=s,n=performance.now()-r;if(x(),f){D(e.changedTouches[0]),O(),e.preventDefault(),e.stopPropagation();return}if(O(),$e.current||ie)return;let a=k();if(st.current&&!a&&fe.current?.(),st.current||a){Fe.current&&(ut.current=!0);return}if(!i){if(R&&e.target===h()||R&&n>=350)return;if(Re.current){let t=e.changedTouches[0];if(t&&w(t)){y(),e.preventDefault(),e.stopPropagation();return}}if(Fe.current){e.preventDefault(),e.stopPropagation(),ut.current=!0;return}y();return}if(Math.abs(t)>.12){let e=t,n=performance.now(),r=()=>{let t=performance.now(),i=t-n;n=t;let a=e*i;c+=a;let o=Math.max(6,l*.6),s=Math.trunc(c/o);s!==0&&(C(s),c-=s*o),e*=.95**(i/16.67),u=Math.abs(e)>.02?requestAnimationFrame(r):null};u=requestAnimationFrame(r)}},I=()=>{x(),f&&D(void 0),O()},L=e=>{ut.current&&=(e.preventDefault(),e.stopPropagation(),!1)},z={passive:!0,capture:!0},V={passive:!1,capture:!0},ee={passive:!1,capture:!0},H={capture:!0};return t.addEventListener(`touchstart`,j,z),t.addEventListener(`touchmove`,P,V),t.addEventListener(`touchend`,F,ee),t.addEventListener(`touchcancel`,I,z),t.addEventListener(`mousedown`,L,H),()=>{t.removeEventListener(`touchstart`,j,z),t.removeEventListener(`touchmove`,P,V),t.removeEventListener(`touchend`,F,ee),t.removeEventListener(`touchcancel`,I,z),t.removeEventListener(`mousedown`,L,H),x();let e=h();e&&(e.disabled=!1)}},[e?.id,Ne,Pe,R,B,ie,M,N]);let ft=(0,y.useCallback)(t=>{if(!(!e||Ce)){if(je.pending||!He){je.capture(t,`typing`);return}E({type:`terminal-input`,sessionId:e.id,data:t})===!1&&je.capture(t,`typing`)}},[e,Ce,He,E,je]),mt=(0,y.useCallback)(t=>{if(!(!e||Ce)){if(je.pending||!He){je.capture(t,`paste`);return}Fe.current&&(E({type:`tmux-cancel-copy-mode`,sessionId:e.id}),ze(!1)),E({type:`terminal-paste`,sessionId:e.id,data:t})===!1&&je.capture(t,`paste`)}},[e,Ce,He,E,Fe,ze,je]),ht=(0,y.useCallback)(t=>{!e||Ce||!He||je.pending||(Fe.current&&(E({type:`tmux-cancel-copy-mode`,sessionId:e.id}),ze(!1)),E({type:`terminal-input`,sessionId:e.id,data:t}))},[e,Ce,He,E,Fe,ze,je.pending]),gt=(0,y.useCallback)(()=>{let e=Ne.current;if(!e)return;let t=e.querySelector(`.xterm-helper-textarea`);t&&(t.removeAttribute(`disabled`),t.focus())},[Ne]),_t=m2({sessionId:e?.id??null,disabled:o!==`connected`||Ce||!He||je.pending,fileUploadsAllowed:!be,agentType:e?.agentType,onPasteText:mt,onPasteImage:ht,onRefocus:gt});ve.current=_t.paste,ye.current=_t.fail;let vt=()=>{!e||Ce||!He||!je.text||je.persistence===`sent-remove-failed`||(Fe.current&&(E({type:`tmux-cancel-copy-mode`,sessionId:e.id}),ze(!1)),E({type:`terminal-paste`,sessionId:e.id,data:je.text})!==!1&&(je.sent(),gt()))},yt=(0,y.useCallback)(()=>{if(typeof document>`u`)return!1;let e=Ne.current;if(!e)return!1;let t=e.querySelector(`.xterm-helper-textarea`);if(t&&document.activeElement===t)return!0;let n=document.activeElement,r=typeof HTMLInputElement<`u`&&n instanceof HTMLInputElement,i=typeof HTMLTextAreaElement<`u`&&n instanceof HTMLTextAreaElement;return r||i||n&&n.isContentEditable?!1:!!document.documentElement?.classList?.contains(`keyboard-visible`)},[Ne]);(0,y.useEffect)(()=>{if(!R)return;let e=Ne.current;if(!e)return;let t=e.querySelector(`.xterm-accessibility`),n=e.querySelector(`.xterm-accessibility-tree`);if(!t||!n)return;let r=()=>{let r=e.querySelector(`.xterm-helper-textarea`);r&&document.activeElement===r&&!st.current?(t.style.pointerEvents=`none`,n.style.pointerEvents=`none`):(t.style.removeProperty(`pointer-events`),n.style.removeProperty(`pointer-events`))};return r(),document.addEventListener(`focusin`,r),document.addEventListener(`focusout`,r),()=>{document.removeEventListener(`focusin`,r),document.removeEventListener(`focusout`,r)}},[Ne,R,H]),(0,y.useEffect)(()=>{let e=Ne.current;e&&(e.inert=!!r)},[Ne,r]);let bt=A&&!!e&&t.length>1;return(0,k.jsxs)(`section`,{className:`flex min-w-0 flex-1 flex-col bg-base terminal-mobile-overlay md:relative md:inset-auto ${R?`ios-native-term-selection`:``} ${R?`ios-native-paste-prototype`:``}`,"data-testid":`terminal-panel`,"data-compact-mobile-controls":O,onDragOver:t=>{Array.from(t.dataTransfer.types).includes(`Files`)&&(t.preventDefault(),t.dataTransfer.dropEffect=e&&!Ce&&He&&!be&&o===`connected`?`copy`:`none`)},onDrop:t=>{if(!Array.from(t.dataTransfer.types).includes(`Files`)||(t.preventDefault(),t.stopPropagation(),!e||Ce||!He||be||o!==`connected`))return;let n=v1(t.dataTransfer);n.length&&_t.paste({text:``,files:n})},children:[(0,k.jsxs)(`div`,{className:`mobile-terminal-header flex min-h-[52px] shrink-0 items-center justify-between border-b border-border bg-elevated px-[6px] md:hidden`,children:[(0,k.jsxs)(`div`,{className:`flex min-w-0 items-center gap-[7px]`,children:[(0,k.jsx)(`button`,{onClick:()=>ae(!0),className:Jt(`neutral`),"aria-label":`Open session menu`,"aria-expanded":ie,children:(0,k.jsx)(Ie,{width:K.primary,height:K.primary})}),e?(0,k.jsxs)(`div`,{className:`flex min-w-[72px] flex-col items-start gap-px leading-none`,children:[se?(0,k.jsx)(`input`,{ref:he,type:`text`,value:le,onChange:e=>ue(e.target.value),onBlur:it,onKeyDown:at,className:`w-full max-w-[112px] rounded border border-border bg-surface px-2 py-0.5 text-sm font-medium text-primary outline-none focus:border-accent`}):(0,k.jsx)(`span`,{className:`max-w-[112px] truncate text-sm font-medium text-primary`,children:e.agentSessionName||e.name}),(0,k.jsx)(`span`,{className:`shrink-0 text-[10px] ${o===`connected`?D0[e.status]:`text-approval`}`,children:o===`connected`?E0[e.status]:o})]}):r?(0,k.jsxs)(`div`,{className:`flex min-w-0 flex-col items-start gap-px leading-none`,children:[(0,k.jsx)(`span`,{className:`max-w-[112px] truncate text-sm font-medium text-primary`,children:Te}),(0,k.jsx)(`span`,{className:`text-[10px] font-medium text-blue-400`,children:`Hibernating`})]}):(0,k.jsx)(`span`,{className:`text-sm font-medium text-primary`,children:`Sessions`})]}),(0,k.jsxs)(`div`,{className:`flex shrink-0 items-center gap-[4px]`,children:[(0,k.jsx)(`button`,{onClick:p,className:Jt(`primary`),title:`New session (${I}N)`,"aria-label":`New session`,children:(0,k.jsx)(Je,{width:K.primary,height:K.primary})}),e&&we&&(0,k.jsx)(`button`,{disabled:Ve,onClick:()=>ne(!0),className:Jt(`danger`),title:`Kill session (${I}X)`,"aria-label":`Kill session`,children:(0,k.jsx)(ot,{width:K.primary,height:K.primary})}),Oe&&(0,k.jsx)(`button`,{onClick:nt,className:`${Jt(`neutral`,`hidden`)} min-[360px]:flex`,title:`Hibernate session`,"aria-label":`Hibernate session`,children:(0,k.jsx)(Be,{width:K.primary,height:K.primary})}),r&&(0,k.jsx)(`button`,{onClick:()=>_(r.sessionId),className:`mobile-header-wake btn btn-primary h-[44px] px-3 text-xs`,children:`Wake`}),e&&(0,k.jsxs)(`div`,{className:`relative`,ref:pe,children:[(0,k.jsx)(`button`,{onClick:()=>re(!W),className:Jt(`neutral`),title:`More options`,"aria-label":`More options`,children:(0,k.jsx)(me,{width:K.primary,height:K.primary})}),W&&(0,k.jsxs)(`div`,{className:`absolute right-0 top-full mt-1 z-20 min-w-[140px] rounded-md border border-border bg-elevated shadow-lg py-1`,children:[we&&(0,k.jsxs)(`button`,{onClick:rt,className:`flex min-h-[44px] w-full items-center gap-2 px-3 py-2 text-left text-sm text-secondary hover:bg-hover hover:text-primary`,children:[(0,k.jsx)(ge,{width:K.default,height:K.default}),`Rename`]}),Oe&&(0,k.jsxs)(`button`,{onClick:nt,className:`flex min-h-[44px] w-full items-center gap-2 px-3 py-2 text-left text-sm text-secondary hover:bg-hover hover:text-primary`,children:[(0,k.jsx)(Be,{width:K.default,height:K.default}),`Hibernate`]}),(0,k.jsxs)(`button`,{onClick:()=>{x(),re(!1)},className:`flex min-h-[44px] w-full items-center gap-2 px-3 py-2 text-left text-sm text-secondary hover:bg-hover hover:text-primary`,children:[(0,k.jsx)(et,{width:K.default,height:K.default}),`Settings`]})]})]})]})]}),(0,k.jsx)(i3,{session:e,ready:o===`connected`&&He,children:(0,k.jsxs)(`div`,{className:`relative min-w-0 flex-1`,"data-testid":`terminal-content`,children:[bt&&(0,k.jsx)(y3,{sessions:t,selectedId:e.id,isOpen:ie,onOpen:()=>ae(!0)}),(0,k.jsx)(`div`,{ref:Ne,className:`absolute inset-0 overflow-clip ${bt?`left-[8px] md:left-0`:``}`,style:{backgroundColor:D.background}}),e&&Ke.state.status!==`closed`&&(0,k.jsx)(n4,{state:Ke.state,containerRef:Ne,terminalRef:Pe,background:D.background??`#000`,foreground:D.foreground??`#fff`,rejoinWrapped:Xe,onCopied:Ke.close}),e&&!Ce&&!He&&(0,k.jsxs)(`div`,{role:`status`,"aria-live":`polite`,"data-testid":`terminal-recovery-status`,className:`absolute top-2 left-2 z-50 flex items-center gap-1.5 rounded-lg bg-black/60 px-2.5 py-1.5 text-xs text-white/90 shadow-lg backdrop-blur-md`,children:[(0,k.jsx)(pt,{width:K.pill,height:K.pill,className:Ve||o!==`connected`?`animate-spin`:``}),o===`connected`?Ve?`Restoring terminal`:`Terminal unavailable`:o===`disconnected`?`Disconnected`:`Reconnecting`,(0,k.jsx)(`span`,{className:`text-white/70`,children:`· Input paused`})]}),je.pending&&e&&!Ce&&(0,k.jsx)(a3,{text:je.text,sessionName:e.name,ready:He,atLimit:je.atLimit,truncated:je.truncated,persistence:je.persistence,onSave:je.save,onDiscardOthers:je.hasOtherDrafts?je.discardOthers:void 0,onEdit:je.edit,onSend:vt,onDiscard:()=>{je.discard(),gt()}},Ae),Ue&&e&&(0,k.jsxs)(`div`,{className:`absolute ${V&&!H?`bottom-20`:`bottom-8`} left-1/2 z-30 flex max-w-[calc(100%-2rem)] -translate-x-1/2 items-center gap-2 rounded-lg border border-border bg-elevated/95 px-2 py-2 shadow-lg backdrop-blur-sm md:hidden`,children:[(0,k.jsx)(`span`,{className:`max-w-[12rem] truncate text-xs text-secondary md:max-w-[18rem]`,children:`Selection ready`}),(0,k.jsxs)(`button`,{type:`button`,onClick:We,className:`relative flex h-8 shrink-0 items-center justify-center gap-1.5 rounded bg-accent px-2.5 text-xs font-medium text-white hover:bg-accent/90 active:scale-95 transition-all [@media(pointer:coarse)]:before:absolute [@media(pointer:coarse)]:before:inset-[calc(50%-22px)] [@media(pointer:coarse)]:before:content-['']`,title:`Copy selection`,"aria-label":`Copy selection`,children:[(0,k.jsx)(oe,{width:K.default,height:K.default}),`Copy`]}),(0,k.jsx)(`button`,{type:`button`,onClick:Ge,className:`relative flex h-8 w-8 shrink-0 items-center justify-center rounded border border-border text-secondary hover:bg-hover hover:text-primary active:scale-95 transition-all [@media(pointer:coarse)]:before:absolute [@media(pointer:coarse)]:before:inset-[calc(50%-22px)] [@media(pointer:coarse)]:before:content-['']`,title:`Dismiss`,"aria-label":`Dismiss`,children:(0,k.jsx)(ot,{width:K.default,height:K.default})})]}),!e&&(0,k.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center text-sm text-muted`,children:r?null:`Select a session to view terminal`}),e&&Ce&&(0,k.jsx)(`div`,{className:`absolute inset-0 flex items-center justify-center text-center text-sm text-muted`,children:`Remote session (read-only). Use SSH to attach on the host.`}),r&&(0,k.jsx)(`div`,{className:`absolute inset-0 z-10 overflow-y-auto bg-base`,children:(0,k.jsxs)(`div`,{className:`mx-auto flex min-h-full w-full max-w-5xl flex-col gap-4 p-4 md:p-6`,children:[(0,k.jsx)(`div`,{className:`border-b border-border pb-4`,children:(0,k.jsxs)(`div`,{className:`flex flex-col gap-3 md:flex-row md:items-start md:justify-between`,children:[(0,k.jsxs)(`div`,{className:`min-w-0 space-y-2`,children:[(0,k.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1 text-sm`,children:[(0,k.jsx)(`h2`,{className:`min-w-0 truncate text-lg font-semibold text-primary`,children:Te}),(0,k.jsx)(`span`,{className:`rounded-full bg-blue-500/15 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-blue-400`,children:`Hibernating`}),Ee&&(0,k.jsx)(`span`,{className:`text-muted`,children:Ee}),(0,k.jsxs)(`span`,{className:`text-muted`,children:[`Last active `,De]})]}),r.lastResumeError&&(0,k.jsxs)(`div`,{className:`inline-flex items-center gap-1 rounded bg-amber-500/15 px-2 py-1 text-xs text-amber-400`,title:`Last wake failed: ${r.lastResumeError}`,children:[(0,k.jsx)(L,{width:K.pill,height:K.pill}),`Last wake failed`]}),r.lastUserMessage&&(0,k.jsx)(`p`,{className:`max-h-28 max-w-3xl overflow-y-auto whitespace-pre-wrap break-words pr-2 text-sm leading-6 text-secondary`,children:r.lastUserMessage})]}),(0,k.jsxs)(`div`,{className:`flex shrink-0 items-center gap-2`,children:[(0,k.jsx)(`button`,{type:`button`,onClick:()=>_(r.sessionId),className:`btn btn-primary hidden md:inline-flex`,children:`Wake`}),b&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>b(r.sessionId),className:`btn btn-secondary`,children:`Move to History`})]})]})}),(0,k.jsx)(GL,{session:r})]})}),Le&&e&&!H?(0,k.jsxs)(`button`,{type:`button`,onClick:Ze,className:`absolute bottom-14 left-1/2 z-20 flex h-10 items-center justify-center rounded-full border border-amber-400/35 bg-amber-500/20 text-amber-100 shadow-lg backdrop-blur-sm transition-all hover:bg-amber-500/30 active:scale-95 md:hidden ${Zt}`,style:{transform:`translateX(-50%)`},title:`Exit tmux copy mode and return to live output`,"aria-label":`Exit copy mode`,children:[(0,k.jsx)(`span`,{className:`px-3 text-[11px] font-semibold uppercase tracking-wide`,children:`Copy mode`}),(0,k.jsx)(`span`,{className:`self-stretch border-l border-amber-400/25`,"aria-hidden":`true`}),(0,k.jsx)(`span`,{className:`px-3 text-sm font-medium`,children:`Exit`})]}):V&&e&&!H?(0,k.jsxs)(`button`,{type:`button`,onClick:Ze,className:`absolute bottom-8 left-1/2 z-20 flex h-10 px-4 items-center justify-center gap-1.5 rounded-full bg-blue-600/90 text-white shadow-lg hover:bg-blue-600 active:scale-95 transition-all md:hidden ${Zt}`,style:{transform:`translateX(-50%)`},title:`Scroll to bottom`,"aria-label":`Scroll to bottom`,children:[(0,k.jsx)(z,{width:K.primary,height:K.primary}),(0,k.jsx)(`span`,{className:`text-sm font-medium`,children:`Jump to bottom`})]}):null]})}),(0,k.jsx)(d2,{..._t}),(0,k.jsx)(I0,{session:e,hibernatingSession:r,hibernatingDisplayName:Te,showHostBadge:ke,sessionCount:t.length,connectionStatus:o,isSwitching:Ve,canControl:we,canHibernate:Oe,modDisplay:I,onKill:()=>ne(!0),onHibernate:nt,onWake:()=>r&&_(r.sessionId),onRename:t=>{let n=e?.id??r?.sessionId;n&&h(n,t)},onDuplicate:e&&g?()=>g(e.id):void 0,onMoveToHistory:r&&b?()=>b(r.sessionId):void 0,isTmuxCopyMode:Le,showJumpToBottom:V&&!H,onJumpToBottom:Ze,selectionReady:!!Ue,onCopySelection:We,onDismissSelection:Ge}),e&&(0,k.jsx)(k2,{onSendKey:ft,onPasteText:mt,onPasteImage:ht,disabled:o!==`connected`||Ce||!He||je.pending,sessions:t.map(e=>({id:e.id,name:e.name,status:e.status})),currentSessionId:e.id,agentType:e.agentType,fileUploadsAllowed:!be,onSelectSession:d,hideSessionSwitcher:!0,onRefocus:gt,isKeyboardVisible:yt,onSelectText:Ce?void 0:Ye,snapshotActions:qe?{onDone:Ke.close,onRefresh:Ke.refresh,busy:Ke.state.status===`loading`||Ke.state.status===`ready`&&Ke.state.refreshing}:void 0}),(B||R)&&(0,k.jsx)(_3,{isOpen:ie,onClose:()=>ae(!1),sessions:n??t,hibernatingSessions:i,historySessions:a,selectedSessionId:e?.id??null,selectedHibernatingSessionId:r?.sessionId??null,onSelect:d,onSelectHibernating:f,onRename:h,onResume:_,onHibernate:v,onMoveToHistory:b,onNewSession:p,onOpenHistory:S,subscribe:l,loading:C,error:w}),U&&e&&(0,k.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/50`,children:(0,k.jsxs)(`div`,{className:`mx-4 w-full max-w-sm rounded-lg border border-border bg-elevated p-4 shadow-xl`,children:[(0,k.jsx)(`h3`,{className:`text-base font-medium text-primary mb-2 text-balance`,children:`Kill Session`}),(0,k.jsxs)(`p`,{className:`text-sm text-secondary mb-4 text-pretty`,children:[`Kill "`,e.agentSessionName||e.name,`"? The process will be terminated. Conversation history is preserved in logs.`]}),(0,k.jsxs)(`div`,{className:`flex justify-end gap-2`,children:[(0,k.jsx)(`button`,{onClick:()=>ne(!1),className:`btn py-1.5 px-3 text-sm`,children:`Cancel`}),(0,k.jsx)(`button`,{ref:_e,onClick:tt,className:`btn btn-danger py-1.5 px-3 text-sm`,children:`Kill Session`})]})]})})]})}function S3({onSelect:e,onCancel:t,initialPath:n}){let[r,i]=(0,y.useState)(n||`~`),[a,o]=(0,y.useState)(null),[s,c]=(0,y.useState)(null),[l,u]=(0,y.useState)(!0),[d,f]=(0,y.useState)(-1),p=(0,y.useRef)(null),m=G(e=>e.recentPaths),h=(0,y.useCallback)(async e=>{p.current?.abort();let t=new AbortController;p.current=t;let{signal:n}=t;u(!0),c(null),o(null),f(-1),i(e);try{let r=await fetch(`/api/directories?path=${encodeURIComponent(e)}`,{signal:n});if(!r.ok){let e=await r.json();throw Error(e.message||`Failed to load directory`)}let a=await r.json();if(p.current!==t)return;o(a),i(a.path)}catch(e){if(p.current!==t)return;let n=e;n?.name!==`AbortError`&&c(n?.message||`Failed to load directory`)}finally{p.current===t&&u(!1)}},[]);(0,y.useEffect)(()=>(h(n||`~`),()=>{p.current?.abort()}),[h,n]);let g=a?.directories??[],_=a?.path||r,v=a?.parent;return(0,y.useEffect)(()=>{let n=n=>{if(n.key===`Escape`){n.preventDefault(),t();return}if(!l){if(n.key===`ArrowDown`){n.preventDefault(),f(e=>g.length===0?-1:e<0?0:Math.min(e+1,g.length-1));return}if(n.key===`ArrowUp`){n.preventDefault(),f(e=>g.length===0?-1:e<0?g.length-1:Math.max(e-1,0));return}if(n.key===`Enter`){n.preventDefault();let t=g[d];t?h(t.path):_&&e(_);return}n.key===`Backspace`&&v&&(n.preventDefault(),h(v))}};return window.addEventListener(`keydown`,n),()=>window.removeEventListener(`keydown`,n)},[g,_,h,d,l,t,e,v]),(0,k.jsx)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-label":`Directory browser`,className:`fixed inset-0 z-[60] flex items-center justify-center bg-black/60 p-4`,onClick:e=>{e.target===e.currentTarget&&t()},"data-testid":`directory-browser`,children:(0,k.jsxs)(`div`,{className:`w-full max-w-lg border border-border bg-elevated p-4`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-3 border-b border-border pb-2`,children:[(0,k.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>{v&&h(v)},disabled:!v||l,children:`Up`}),(0,k.jsx)(`div`,{className:`min-w-0 flex-1 truncate text-xs font-mono text-secondary`,title:_,"data-testid":`directory-current-path`,children:_})]}),(0,k.jsx)(`div`,{className:`mt-3 max-h-60 overflow-y-auto border border-border bg-surface`,children:l?(0,k.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted`,"data-testid":`directory-loading`,children:`Loading directories...`}):s?(0,k.jsxs)(`div`,{className:`px-3 py-4 text-xs`,"data-testid":`directory-error`,children:[(0,k.jsx)(`p`,{className:`text-danger`,children:s}),(0,k.jsx)(`button`,{type:`button`,className:`btn mt-3`,onClick:()=>h(r),children:`Retry`})]}):g.length===0?(0,k.jsx)(`div`,{className:`px-3 py-4 text-xs text-muted`,"data-testid":`directory-empty`,children:`No subdirectories`}):(0,k.jsx)(`div`,{className:`py-1`,children:g.map((e,t)=>(0,k.jsxs)(`button`,{type:`button`,onClick:()=>h(e.path),onMouseEnter:()=>f(t),className:`flex w-full items-center gap-2 px-3 py-2 text-left text-xs ${t===d?`bg-hover text-primary`:`text-secondary`}`,"data-testid":`directory-entry`,"data-entry-name":e.name,"data-entry-path":e.path,children:[(0,k.jsx)(Ee,{width:K.default,height:K.default,className:`shrink-0 text-muted`,"aria-hidden":`true`}),(0,k.jsx)(`span`,{className:`truncate`,children:e.name})]},e.path))})}),a?.truncated?(0,k.jsx)(`p`,{className:`mt-2 text-[10px] text-muted`,children:`Showing first 200 directories.`}):null,(0,k.jsxs)(`div`,{className:`mt-4 border-t border-border pt-3`,children:[(0,k.jsx)(`div`,{className:`text-[10px] uppercase tracking-wider text-secondary`,children:`Recent`}),m.length===0?(0,k.jsx)(`p`,{className:`mt-2 text-xs text-muted`,children:`No recent paths yet.`}):(0,k.jsx)(`div`,{className:`mt-2 space-y-1`,children:m.map(e=>(0,k.jsx)(`button`,{type:`button`,className:`block w-full truncate text-left text-xs text-secondary hover:text-primary`,onClick:()=>h(e),title:e,"data-testid":`directory-recent`,"data-recent-path":e,children:e},e))})]}),(0,k.jsxs)(`div`,{className:`mt-4 flex justify-end gap-2`,children:[(0,k.jsx)(`button`,{type:`button`,onClick:t,className:`btn`,children:`Cancel`}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>{_&&e(_)},className:`btn btn-primary`,disabled:l||!_,children:`Select`})]})]})})}function C3(e){let t=e.trim();if(t.length>=2){let e=t[0],n=t[t.length-1];if(e===`'`&&n===`'`)return t.slice(1,-1).replace(/'\\''/g,`'`);if(e===`"`&&n===`"`)return t.slice(1,-1).replace(/\\"/g,`"`).replace(/\\\\/g,`\\`)}return t}function w3(e){let t=e.trim(),n=t.search(/\s/);if(n===-1||t.slice(0,n).split(`/`).pop()!==`bash`)return null;let r=n;for(;r<t.length&&/\s/.test(t[r]);)r++;let i=!1,a=!1;for(;r<t.length;){let e=r;for(;r<t.length&&!/\s/.test(t[r]);)r++;let n=t.slice(e,r);for(;r<t.length&&/\s/.test(t[r]);)r++;if(!n.startsWith(`-`)||n===`-`)return null;if(n===`--`)break;if(n.startsWith(`--`)||!/^-[a-zA-Z]+$/.test(n))continue;let o=n.slice(1);if(o.includes(`l`)&&(i=!0),o.includes(`c`)){a=!0;break}}if(!i||!a)return null;let o=t.slice(r).trim();return o?C3(o):null}function T3(e){return e?e===`claude-rp`?`claude`:e:null}function E3(e){let t=e.trim();if(!t)return``;let n=C3(t);return w3(n)??n}function D3(e){if(e===`claude`)return`claude`;if(e===`codex`)return`codex`;if(e===`pi`)return`pi`;if(e===`devin`||e===`devin-cli`)return`devin`;if(e===`grok`||e.startsWith(`grok-`))return`grok`;if(e===`omp`)return`omp`}function O3(e){let t=/\S+/g,n;for(;n=t.exec(e);){let e=n[0].toLowerCase().replace(/^["']+|["']+$/g,``);if([`npx`,`bunx`,`pnpm`,`yarn`,`env`].includes(e)||e.includes(`=`)||e.startsWith(`-`))continue;let t=e.includes(`@oh-my-pi/`)?`omp`:D3(e.split(`/`).pop()||e);return t?{agentType:t,end:n.index+n[0].length}:void 0}}function k3(e){let t=E3(e);if(t)return O3(t.toLowerCase().trim().replace(/^["']|["']$/g,``))?.agentType}var A3={claude:`--dangerously-skip-permissions`,codex:`--yolo`,grok:`--always-approve`,devin:`--permission-mode dangerous`,pi:null,omp:`--auto-approve`},j3={claude:[`--dangerously-skip-permissions`,`--permission-mode bypassPermissions`,`--permission-mode=bypassPermissions`],codex:[`--yolo`,`--dangerously-bypass-approvals-and-sandbox`],grok:[`--always-approve`,`--yolo`,`--dangerously-skip-permissions`,`--permission-mode bypassPermissions`,`--permission-mode=bypassPermissions`],devin:[`--permission-mode dangerous`,`--permission-mode=dangerous`],pi:[],omp:[`--auto-approve`,`--approval-mode yolo`,`--approval-mode=yolo`]};function M3(e){let t=T3(e);return t?A3[t]:null}function N3(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function P3(e){return RegExp(`(^|\\s)${N3(e)}(?=\\s|$)`,`g`)}function F3(e,t){return(t?[T3(t)].filter(e=>e!==null):Object.keys(j3)).some(t=>j3[t].some(t=>P3(t).test(e)))}function I3(e,t){let n=O3(e);return n?`${e.slice(0,n.end)} ${t}${e.slice(n.end)}`:null}function L3(e,t){let n=M3(t);if(!n)return e;let r=e.trim();if(!r||F3(r,t))return r;let i=I3(r,n);if(i)return i;let a=E3(r);if(a&&a!==r){let e=I3(a,n);if(e)return`bash -lc '${e.replace(/'/g,`'\\''`)}'`}return`${r} ${n}`}function R3(e,t){let n=T3(t);if(!n||F3(e,t))return null;if(n===`codex`){let t=/(^|\s)(--full-auto|--ask-for-approval|-a)(?=\s|=|$)/.exec(e);if(t)return`conflicts with ${t[2]}`}if(n===`omp`){let t=/(^|\s)--approval-mode(?:\s+|=)(always-ask|write)/.exec(e);if(t)return`conflicts with --approval-mode ${t[2]}`}let r=/(^|\s)--permission-mode(?:\s+|=)(\S+)/.exec(e);return r&&n!==`codex`?`conflicts with --permission-mode ${r[2]}`:null}function z3(e,t){let n=T3(t);if(!n)return e;let r=e;for(let e of j3[n])r=r.replace(P3(e),` `);return r.replace(/\s+/g,` `).trim()}function B3({isOpen:e,onClose:t,onCreate:n,defaultProjectDir:r,commandPresets:i,defaultPresetId:a,lastProjectPath:o,activeProjectPath:s,remoteHosts:c=[],remoteAllowControl:l=!1,initialHost:u,initialPath:d,initialCommand:f}){let[p,m]=(0,y.useState)(``),[h,g]=(0,y.useState)(``),[_,v]=(0,y.useState)(null),[b,x]=(0,y.useState)(``),[S,C]=(0,y.useState)(!1),[w,T]=(0,y.useState)(``),E=G(e=>e.yoloMode),D=G(e=>e.setYoloMode),O=(0,y.useRef)(null),A=(0,y.useRef)(null),j=(0,y.useRef)(null),M=(0,y.useRef)(!1),N=l&&c.length>0,P=e=>{if(!E)return e;let t=k3(e);return t&&!R3(e,t)?L3(e,t):e},F=e=>{let t=i.find(t=>t.id===e);t&&(v(e),x(P(zt(t))))},I=()=>{v(null),x(``)};if((0,y.useEffect)(()=>{let t=M.current;if(M.current=e,!e){m(``),g(``),v(null),x(``),C(!1),T(u??``),t&&setTimeout(()=>{if(typeof document>`u`||typeof document.querySelector!=`function`)return;let e=document.querySelector(`.xterm-helper-textarea`);e&&(e.removeAttribute(`disabled`),e.focus())},300);return}if(t)return;if(typeof document<`u`&&typeof document.querySelector==`function`){let e=document.querySelector(`.xterm-helper-textarea`);e&&typeof e.setAttribute==`function`&&(typeof e.blur==`function`&&e.blur(),e.setAttribute(`disabled`,`true`))}m(d?.trim()||s?.trim()||o||r||``),g(``),T(u??``);let n=f?.trim();if(n){let e=i.find(e=>zt(e)===n);e?(v(e.id),x(zt(e))):(v(null),x(n))}else{let e=i.find(e=>e.id===a);e?(v(a),x(P(zt(e)))):i.length>0?(v(i[0].id),x(P(zt(i[0])))):(v(null),x(``))}setTimeout(()=>{if(j.current?.focus(),A.current){let e=A.current;e.scrollLeft=e.scrollWidth}},50)},[s,i,a,r,e,o,u,d,f]),(0,y.useEffect)(()=>{if(!e||typeof window>`u`||typeof window.addEventListener!=`function`)return;let n=()=>O.current?Array.from(O.current.querySelectorAll(`input:not([disabled]), select:not([disabled]), button:not([disabled]):not([tabindex="-1"]), [tabindex="0"]`)):[],r=e=>{if(!S){if(e.key===`Escape`){typeof e.stopPropagation==`function`&&e.stopPropagation(),t();return}if(e.key===`Enter`){let t=document.activeElement;if(!t||t.tagName===`INPUT`||t.closest(`[data-testid="host-select"]`)||!t.closest(`[data-testid="command-select"]`))return;e.preventDefault(),typeof e.stopPropagation==`function`&&e.stopPropagation(),O.current?.requestSubmit();return}if(/^[0-9]$/.test(e.key)&&!e.metaKey&&!e.ctrlKey&&!e.altKey){let t=document.activeElement;if(t&&(t.tagName===`INPUT`||t.tagName===`TEXTAREA`||t.tagName===`SELECT`||t.isContentEditable))return;let n;if(e.key===`0`)n=i.length;else if(n=Number(e.key)-1,n>=i.length)return;e.preventDefault(),typeof e.stopPropagation==`function`&&e.stopPropagation(),n===i.length?I():F(i[n].id),(O.current?.querySelectorAll?.(`[data-testid="command-select"] [role="radio"]`))?.[n]?.focus();return}if(e.key===`Tab`){e.preventDefault(),typeof e.stopPropagation==`function`&&e.stopPropagation();let t=n();if(t.length===0)return;let r=document.activeElement,i=t.indexOf(r),a;a=i===-1?e.shiftKey?t.length-1:0:e.shiftKey?i<=0?t.length-1:i-1:i>=t.length-1?0:i+1,t[a]?.focus()}}};return window.addEventListener(`keydown`,r),()=>window.removeEventListener(`keydown`,r)},[e,t,S,i,E]),!e)return null;let L=_===null,R=w!==``,z=k3(b),B=M3(z)!==null,V=z?F3(b,z):!1,ee=z&&!V?R3(b,z):null,H=!B||ee!==null,te=z?z===`pi`?`Pi has no permission prompts — nothing to enable`:ee??`Append ${M3(z)}`:`Enter a supported agent command (claude, codex, grok, devin)`,U=e=>{D(e),z&&x(e?L3(b,z):z3(b,z))},ne=e=>{e.preventDefault();let r=p.trim();if(!r)return;let i=b.trim();n(r,h.trim()||void 0,i||void 0,R?w:void 0),t()},W=[...i.map(e=>({id:e.id,label:e.label,isCustom:!1,agentType:e.agentType,command:e.command})),{id:`custom`,label:`Custom`,isCustom:!0,agentType:void 0,command:void 0}],re=[{id:``,label:`Local`,ok:!0,error:void 0},...c.map(e=>({id:e.host,label:e.host,ok:e.ok,error:e.error}))],ie=p.trim()||`~`;return(0,k.jsxs)(`div`,{role:`dialog`,"aria-modal":`true`,"aria-labelledby":`new-session-title`,"data-suspends-terminal":``,className:`fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4`,onClick:e=>{e.target===e.currentTarget&&t()},children:[(0,k.jsxs)(`form`,{ref:O,onSubmit:ne,className:`w-full max-w-md border border-border bg-elevated p-6`,children:[(0,k.jsx)(`h2`,{id:`new-session-title`,className:`text-sm font-semibold uppercase tracking-wider text-primary text-balance`,children:`New Session`}),(0,k.jsxs)(`div`,{className:`mt-4 space-y-4`,children:[N&&(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`mb-1.5 block text-xs text-secondary`,children:`Host`}),(0,k.jsx)(`div`,{className:`flex flex-wrap gap-2`,role:`radiogroup`,"aria-label":`Host`,"data-testid":`host-select`,children:re.map((e,t)=>{let n=w===e.id,r=!e.ok&&!n;return(0,k.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":n,"aria-label":e.label,title:e.ok?void 0:e.error||`Unreachable`,tabIndex:n?0:-1,onClick:()=>T(e.id),onKeyDown:e=>{let n=t;if(e.key===`ArrowRight`||e.key===`ArrowDown`)e.preventDefault(),n=(t+1)%re.length;else if(e.key===`ArrowLeft`||e.key===`ArrowUp`)e.preventDefault(),n=(t-1+re.length)%re.length;else return;let r=re[n];T(r.id),(e.currentTarget.parentElement?.querySelectorAll(`[role="radio"]`))?.[n]?.focus()},className:`btn text-xs focus:outline-none focus:ring-2 focus:ring-primary ${n?`btn-primary`:``} ${r?`opacity-60`:``}`,children:e.label},e.id||`local`)})})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`mb-1.5 block text-xs text-secondary`,children:`Command`}),(0,k.jsx)(`div`,{className:`flex flex-wrap gap-2`,role:`radiogroup`,"aria-label":`Command preset`,"data-testid":`command-select`,children:W.map((e,t)=>{let n=e.isCustom?L:_===e.id,r=e.isCustom?`0`:t<9?String(t+1):null;return(0,k.jsxs)(`button`,{ref:n?j:void 0,type:`button`,role:`radio`,"aria-checked":n,"aria-keyshortcuts":r??void 0,tabIndex:n?0:-1,onClick:()=>{e.isCustom?I():F(e.id)},onKeyDown:e=>{let n=t;if(e.key===`ArrowRight`||e.key===`ArrowDown`)e.preventDefault(),n=(t+1)%W.length;else if(e.key===`ArrowLeft`||e.key===`ArrowUp`)e.preventDefault(),n=(t-1+W.length)%W.length;else return;let r=W[n];r.isCustom?I():F(r.id),(e.currentTarget.parentElement?.querySelectorAll(`[role="radio"]`))?.[n]?.focus()},className:`btn text-xs focus:outline-none focus:ring-2 focus:ring-primary ${n?`btn-primary`:``}`,children:[r&&(0,k.jsx)(`kbd`,{"aria-hidden":`true`,className:`shortcut-badge`,children:r}),(0,k.jsx)(_g,{agentType:e.agentType,command:e.command,className:`inline-block h-3.5 w-3.5 shrink-0`}),e.label]},e.id)})}),(0,k.jsx)(`input`,{value:b,onChange:e=>x(e.target.value),placeholder:`Enter command...`,className:`input mt-2 font-mono text-xs`}),(0,k.jsxs)(`label`,{className:`mt-2 flex items-center gap-2 text-xs ${H?`text-muted opacity-60`:`text-secondary`}`,title:te,children:[(0,k.jsx)(`input`,{type:`checkbox`,checked:V,disabled:H,onChange:e=>U(e.target.checked)}),`yolo mode — skip permission prompts`]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`mb-1.5 block text-xs text-secondary`,children:`Project Path`}),(0,k.jsxs)(`div`,{className:`flex gap-2`,children:[(0,k.jsx)(`input`,{ref:A,value:p,onChange:e=>m(e.target.value),placeholder:R?`/home/user/project`:s||o||r||`/Users/you/code/my-project`,className:`input flex-1 text-sm`}),!R&&(0,k.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>C(!0),children:`Browse`})]})]}),(0,k.jsxs)(`div`,{children:[(0,k.jsx)(`label`,{className:`mb-1.5 block text-xs text-secondary`,children:`Display Name`}),(0,k.jsx)(`input`,{value:h,onChange:e=>g(e.target.value),placeholder:`auto-generated`,className:`input text-sm placeholder:italic`})]})]}),(0,k.jsxs)(`div`,{className:`mt-6 flex justify-end gap-2`,children:[(0,k.jsx)(`button`,{type:`button`,onClick:t,className:`btn`,children:`Cancel`}),(0,k.jsx)(`button`,{type:`submit`,className:`btn btn-primary`,children:`Create`})]})]}),S&&!R&&(0,k.jsx)(S3,{initialPath:ie,onSelect:e=>{m(e),C(!1)},onCancel:()=>C(!1)})]})}var V3=[{id:`new-sessions`,label:`New sessions`},{id:`session-list`,label:`Session list`},{id:`appearance`,label:`Appearance`},{id:`terminal`,label:`Terminal`},{id:`notifications`,label:`Notifications`}];function H3(e){return V3.some(t=>t.id===e)}function U3(e){return V3.find(t=>t.id===e)?.label??e}var W3=`agentboard-settings-page`,G3=`new-sessions`;function K3(){let e=w.getItem(W3);return H3(e)?e:G3}function q3(e){w.setItem(W3,e)}var J3=`h-[32px] max-md:h-[44px]`,Y3=`${J3} inline-flex shrink-0 items-center justify-center border text-[12px] transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent disabled:cursor-not-allowed disabled:opacity-50`,X3=`${Y3} border-border bg-surface px-3 text-secondary hover:bg-hover hover:text-primary`,Z3=`${Y3} w-[32px] max-md:w-[44px] border-border bg-surface text-secondary hover:bg-hover hover:text-primary`,Q3=`input ${J3} px-2 py-0 text-[13px] max-md:text-[16px] focus-visible:ring-2 focus-visible:ring-accent/40 disabled:opacity-50 aria-[invalid=true]:border-danger`;function $3(e,t){let[n,r]=(0,y.useState)(null),[i,a]=(0,y.useState)(null),o=(0,y.useRef)({draft:n,stored:e,commit:t});o.current={draft:n,stored:e,commit:t},(0,y.useEffect)(()=>()=>{let{draft:e,stored:t,commit:n}=o.current;e!==null&&e!==t&&n(e)},[]);let s=()=>{if(n===null)return;if(n===e){r(null),a(null);return}let i=t(n);if(i){a(i);return}r(null),a(null)};return{value:n??e,error:i,dirty:n!==null,onChange:e=>{r(e.target.value),a(null)},onBlur:s,onKeyDown:e=>{e.key===`Enter`?(e.preventDefault(),s()):e.key===`Escape`&&n!==null&&(e.preventDefault(),r(null),a(null))}}}var e6=(0,y.forwardRef)(function({value:e,onCommit:t,describedBy:n,id:r,className:i,wrapperClassName:a,...o},s){let c=$3(e,t),l=r?`${r}-error`:void 0,u=[n,c.error?l:void 0].filter(Boolean).join(` `);return(0,k.jsxs)(`div`,{className:xE(`min-w-0`,a),children:[(0,k.jsx)(`input`,{...o,ref:s,id:r,value:c.value,onChange:c.onChange,onBlur:c.onBlur,onKeyDown:c.onKeyDown,"aria-invalid":c.error?!0:void 0,"aria-describedby":u||void 0,className:xE(Q3,i)}),c.error&&(0,k.jsx)(`p`,{id:l,className:xE(`text-[12px] leading-snug text-danger`,`mt-1`),role:`alert`,children:c.error})]})});function t6(e,t,n){let r=e.trim();return/^-?\d+$/.test(r)?Math.min(n,Math.max(t,Number.parseInt(r,10))):null}function n6({value:e,min:t,max:n,onChange:r,noun:i,labelledBy:a,describedBy:o}){return(0,k.jsxs)(`div`,{role:`group`,"aria-labelledby":a,"aria-describedby":o,className:`flex items-center`,children:[(0,k.jsx)(`button`,{type:`button`,className:Z3,"aria-label":`Decrease ${i}`,disabled:e<=t,onClick:()=>r(Math.max(t,e-1)),children:(0,k.jsx)(Re,{width:K.default,height:K.default})}),(0,k.jsx)(`output`,{"aria-live":`polite`,className:xE(J3,`flex w-10 items-center justify-center border-y border-border bg-base text-[13px] tabular-nums text-primary`),children:e}),(0,k.jsx)(`button`,{type:`button`,className:Z3,"aria-label":`Increase ${i}`,disabled:e>=n,onClick:()=>r(Math.min(n,e+1)),children:(0,k.jsx)(Je,{width:K.default,height:K.default})})]})}function r6({id:e,value:t,min:n,max:r,step:i,onChange:a,format:o,labelledBy:s,describedBy:c}){return(0,k.jsxs)(`div`,{className:xE(J3,`flex items-center gap-3`),children:[(0,k.jsx)(`input`,{id:e,type:`range`,min:n,max:r,step:i,value:t,"aria-labelledby":s,"aria-describedby":c,"aria-valuetext":o(t),onChange:e=>{let t=Number.parseFloat(e.target.value);Number.isFinite(t)&&a(Math.min(r,Math.max(n,t)))},className:`h-1 w-28 max-md:w-36 cursor-pointer appearance-none bg-border accent-accent focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`}),(0,k.jsx)(`span`,{className:`w-10 text-right text-[13px] tabular-nums text-secondary`,children:o(t)})]})}function i6({options:e,value:t,onChange:n,labelledBy:r,describedBy:i,fill:a=!1}){let o=(0,y.useRef)([]),s=Math.max(0,e.findIndex(e=>e.value===t)),c=t=>{let r=e[t];r&&(n(r.value),o.current[t]?.focus())},l=(t,n)=>{let r=e.length-1,i=null;t.key===`ArrowRight`||t.key===`ArrowDown`?i=n===r?0:n+1:t.key===`ArrowLeft`||t.key===`ArrowUp`?i=n===0?r:n-1:t.key===`Home`?i=0:t.key===`End`&&(i=r),i!==null&&(t.preventDefault(),c(i))};return(0,k.jsx)(`div`,{role:`radiogroup`,"aria-labelledby":r,"aria-describedby":i,className:xE(`flex border border-border bg-base p-[2px]`,a?`w-full`:`w-max max-w-full`),children:e.map((e,t)=>{let n=t===s;return(0,k.jsx)(`button`,{ref:e=>{o.current[t]=e},type:`button`,role:`radio`,"aria-checked":n,tabIndex:n?0:-1,onClick:()=>c(t),onKeyDown:e=>l(e,t),className:xE(`h-[26px] max-md:h-[38px] min-w-0 whitespace-nowrap px-3 text-[12px] transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent`,a&&`flex-1`,n?`bg-hover text-primary shadow-[inset_0_0_0_1px_var(--border)]`:`text-muted hover:text-primary`),children:e.label},e.value)})})}function a6({controlled:e,default:t,name:n,state:r=`value`}){let{current:i}=y.useRef(e!==void 0),[a,o]=y.useState(t);return[i?e:a,y.useCallback(e=>{i||o(e)},[])]}var o6=y.createContext(void 0);function s6(){let e=y.useContext(o6);if(e===void 0)throw Error(mb(63));return e}var c6=function(e){return e.disabled=`data-disabled`,e.valid=`data-valid`,e.invalid=`data-invalid`,e.touched=`data-touched`,e.dirty=`data-dirty`,e.filled=`data-filled`,e.focused=`data-focused`,e}({}),l6={badInput:!1,customError:!1,patternMismatch:!1,rangeOverflow:!1,rangeUnderflow:!1,stepMismatch:!1,tooLong:!1,tooShort:!1,typeMismatch:!1,valid:null,valueMissing:!1},u6={valid(e){return e===null?null:e?{[c6.valid]:``}:{[c6.invalid]:``}}},d6=function(e){return e.checked=`data-checked`,e.unchecked=`data-unchecked`,e.disabled=`data-disabled`,e.readonly=`data-readonly`,e.required=`data-required`,e.valid=`data-valid`,e.invalid=`data-invalid`,e.touched=`data-touched`,e.dirty=`data-dirty`,e.filled=`data-filled`,e.focused=`data-focused`,e}({}),f6={...u6,checked(e){return e?{[d6.checked]:``}:{[d6.unchecked]:``}}};function p6(e,t){return{...e,state:{...e.state,valid:!t&&e.state.valid}}}var m6=y.createContext({formRef:{current:{fields:new Map}},errors:{},clearErrors:__,validationMode:`onSubmit`,submitAttemptedRef:{current:!1}});function h6(){return y.useContext(m6)}var g6=y.createContext({invalid:void 0,name:void 0,validityData:{state:l6,errors:[],error:``,value:``,initialValue:null},setValidityData:__,disabled:void 0,touched:!1,setTouched:__,dirty:!1,setDirty:__,filled:!1,setFilled:__,focused:!1,setFocused:__,validate:()=>null,validationMode:`onSubmit`,validationDebounceTime:0,shouldValidateOnChange:()=>!1,state:{disabled:!1,valid:null,touched:!1,dirty:!1,filled:!1,focused:!1},markedDirtyRef:{current:!1},validation:{getValidationProps:(e=v_)=>e,getInputValidationProps:(e=v_)=>e,inputRef:{current:null},commit:async()=>{}}});function _6(e=!0){let t=y.useContext(g6);if(t.setValidityData===__&&!e)throw Error(mb(28));return t}function v6(e){let{enabled:t=!0,value:n,id:r,name:i,controlRef:a,commit:o}=e,{formRef:s}=h6(),{invalid:c,markedDirtyRef:l,validityData:u,setValidityData:d}=_6(),f=N_(e.getValue);a_(()=>{if(!t)return;let e=n;e===void 0&&(e=f()),u.initialValue===null&&e!==null&&d(t=>({...t,initialValue:e}))},[t,d,n,u.initialValue,f]),a_(()=>{!t||!r||s.current.fields.set(r,{getValue:f,name:i,controlRef:a,validityData:p6(u,c),validate(e=!0){let t=n;t===void 0&&(t=f()),l.current=!0,e?_f.flushSync(()=>o(t)):o(t)}})},[o,a,t,s,f,r,c,l,i,u,n]),a_(()=>{let e=s.current.fields;return()=>{r&&e.delete(r)}},[s,r])}var y6=y.createContext({controlId:void 0,registerControlId:__,labelId:void 0,setLabelId:__,messageIds:[],setMessageIds:__,getDescriptionProps:e=>e});function b6(){return y.useContext(y6)}function x6(e={}){let{id:t,implicit:n=!1,controlRef:r}=e,{controlId:i,registerControlId:a}=b6(),o=dw(t),s=n?i:void 0,c=s_(()=>Symbol(`labelable-control`)),l=y.useRef(!1),u=y.useRef(t!=null),d=N_(()=>{!l.current||a===__||(l.current=!1,a(c.current,void 0))});return a_(()=>{if(a===__)return;let e;if(n){let n=r?.current;e=Cg(n)&&n.closest(`label`)!=null?t??null:s??o}else if(t!=null)u.current=!0,e=t;else if(u.current)e=o;else{d();return}if(e===void 0){d();return}l.current=!0,a(c.current,e)},[t,r,s,a,n,o,c,d]),y.useEffect(()=>d,[d]),i??o}function S6(e,t){let n=y.useRef(e),r=N_(t);a_(()=>{n.current!==e&&r(n.current)},[e,r]),a_(()=>{n.current=e},[e])}var C6=y.forwardRef(function(e,t){let{checked:n,className:r,defaultChecked:i,id:a,inputRef:o,name:s,nativeButton:c=!1,onCheckedChange:l,readOnly:u=!1,required:d=!1,disabled:f=!1,render:p,uncheckedValue:m,value:h,...g}=e,{clearErrors:_}=h6(),{state:v,setTouched:b,setDirty:x,validityData:S,setFilled:C,setFocused:w,shouldValidateOnChange:T,validationMode:E,disabled:D,name:O,validation:A}=_6(),{labelId:j}=b6(),M=D||f,N=O??s,P=N_(l),F=y.useRef(null),I=qy(F,o,A.inputRef),L=y.useRef(null),R=dw(),z=x6({id:a,implicit:!1,controlRef:L}),B=c?void 0:z,[V,ee]=a6({controlled:n,default:!!i,name:`Switch`,state:`checked`});v6({id:R,commit:A.commit,value:V,controlRef:L,name:N,getValue:()=>V}),a_(()=>{F.current&&C(F.current.checked)},[F,C]),S6(V,()=>{_(N),x(V!==S.initialValue),C(V),T()?A.commit(V):A.commit(V,!0)});let{getButtonProps:H,buttonRef:te}=$C({disabled:M,native:c}),U={id:c?z:R,role:`switch`,"aria-checked":V,"aria-readonly":u||void 0,"aria-required":d||void 0,"aria-labelledby":j,onFocus(){M||w(!0)},onBlur(){let e=F.current;!e||M||(b(!0),w(!1),E===`onBlur`&&A.commit(e.checked))},onClick(e){u||M||(e.preventDefault(),F.current?.dispatchEvent(new PointerEvent(`click`,{bubbles:!0,shiftKey:e.shiftKey,ctrlKey:e.ctrlKey,altKey:e.altKey,metaKey:e.metaKey})))}},ne=y.useMemo(()=>Cb({checked:V,disabled:M,id:B,name:N,required:d,style:N?tb:eb,tabIndex:-1,type:`checkbox`,"aria-hidden":!0,ref:I,onChange(e){if(e.nativeEvent.defaultPrevented)return;let t=e.target.checked,n=Wy(Iy,e.nativeEvent);P?.(t,n),!n.isCanceled&&ee(t)},onFocus(){L.current?.focus()}},A.getInputValidationProps,h===void 0?v_:{value:h}),[V,M,I,B,N,P,d,ee,A,h]),W=y.useMemo(()=>({...v,checked:V,disabled:M,readOnly:u,required:d}),[v,V,M,u,d]),re=Pb(`span`,e,{state:W,ref:[t,L,te],props:[U,A.getValidationProps,g,H],stateAttributesMapping:f6});return(0,k.jsxs)(o6.Provider,{value:W,children:[re,!V&&N&&m!==void 0&&(0,k.jsx)(`input`,{type:`hidden`,name:N,value:m}),(0,k.jsx)(`input`,{...ne})]})}),w6=y.forwardRef(function(e,t){let{render:n,className:r,...i}=e,{state:a}=_6(),o=s6();return Pb(`span`,e,{state:{...a,...o},ref:t,stateAttributesMapping:f6,props:i})});function T6({checked:e,onCheckedChange:t,disabled:n,className:r,ariaLabel:i,id:a,ariaLabelledBy:o,ariaDescribedBy:s}){return(0,k.jsx)(C6,{checked:e,onCheckedChange:t,disabled:n,"aria-label":i,id:a,"aria-labelledby":o,"aria-describedby":s,className:xE(`group relative inline-flex h-6 w-10 shrink-0 cursor-pointer items-center rounded-full transition-colors`,`bg-border data-[checked]:bg-accent`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent focus-visible:ring-offset-2 focus-visible:ring-offset-bg-base`,`disabled:cursor-not-allowed disabled:opacity-50`,r),children:(0,k.jsx)(w6,{className:xE(`pointer-events-none block size-4 rounded-full bg-white shadow-sm transition-transform`,`translate-x-1 group-data-[checked]:translate-x-5`)})})}function E6({ids:e}){return(0,k.jsx)(i6,{options:[{value:`light`,label:`Light`},{value:`dark`,label:`Dark`},{value:`system`,label:`System`}],value:m0(e=>e.theme),onChange:m0(e=>e.setTheme),labelledBy:e.label,describedBy:e.description})}function D6({ids:e}){let t=G(e=>e.fontOption),n=G(e=>e.setFontOption);return(0,k.jsx)(`select`,{id:e.control,value:t,"aria-describedby":e.description,onChange:e=>n(e.target.value),className:`${Q3} w-44 max-md:w-full`,children:Pt.map(e=>(0,k.jsx)(`option`,{value:e.id,children:e.label},e.id))})}function O6({ids:e}){let t=G(e=>e.customFontFamily);return(0,k.jsx)(e6,{id:e.control,value:t,placeholder:`"Fira Code", monospace`,describedBy:e.description,spellCheck:!1,autoCapitalize:`off`,autoCorrect:`off`,maxLength:256,wrapperClassName:`w-60 max-md:w-full`,onCommit:e=>(G.getState().setCustomFontFamily(e.trim()),null)})}function k6({ids:e}){return(0,k.jsx)(n6,{value:G(e=>e.fontSize),min:6,max:24,onChange:G(e=>e.setFontSize),noun:`font size`,labelledBy:e.label,describedBy:e.description})}function A6({ids:e}){let t=G(e=>e.lineHeight),n=G(e=>e.setLineHeight);return(0,k.jsx)(r6,{id:e.control,value:t,min:1,max:2,step:.1,onChange:e=>n(Math.round(e*10)/10),format:e=>e.toFixed(1),labelledBy:e.label,describedBy:e.description})}function j6({ids:e}){let t=G(e=>e.letterSpacing),n=G(e=>e.setLetterSpacing);return(0,k.jsx)(r6,{id:e.control,value:t,min:-3,max:3,step:1,onChange:e=>n(Math.round(e)),format:e=>`${e}px`,labelledBy:e.label,describedBy:e.description})}function M6({ids:e}){let t=G(e=>e.compactMobileControls),n=G(e=>e.setCompactMobileControls);return(0,k.jsx)(T6,{className:Zt,id:e.control,checked:t,onCheckedChange:n,ariaLabelledBy:e.label,ariaDescribedBy:e.description})}var N6=[{id:`theme`,page:`appearance`,label:`Theme`,description:`Light, dark, or follow the system setting.`,keywords:[`dark mode`,`light mode`,`color`,`colour`,`system`],Control:E6},{id:`compact-mobile-controls`,page:`appearance`,label:`Compact mobile controls`,description:`Smaller header buttons and quick keys on phones. More terminal space, smaller tap targets.`,keywords:[`mobile`,`size`,`buttons`,`compact`,`toolbar`,`density`],tags:[`device`],Control:M6},{id:`font-family`,page:`appearance`,label:`Font family`,description:`Terminal typeface. Default JetBrains Mono.`,keywords:[`font`,`typeface`,`monospace`],tags:[`device`],Control:D6},{id:`custom-font-family`,page:`appearance`,label:`Custom font family`,description:`A CSS font-family list. Empty falls back to JetBrains Mono.`,keywords:[`font`,`typeface`,`css`],tags:[`device`],layout:`wide`,visibleWhen:e=>e.fontOption===`custom`,Control:O6},{id:`font-size`,page:`appearance`,label:`Font size`,description:`Terminal text size in pixels (6–24). Default 13.`,keywords:[`font`,`text`,`zoom`,`size`],tags:[`device`],Control:k6},{id:`line-height`,page:`appearance`,label:`Line height`,description:`Vertical spacing, 1.0 compact to 2.0 spacious. Default 1.0.`,keywords:[`spacing`,`leading`,`line`],tags:[`device`],Control:A6},{id:`letter-spacing`,page:`appearance`,label:`Letter spacing`,description:`Extra space between characters in pixels (−3 to 3). Default 0.`,keywords:[`spacing`,`tracking`,`kerning`],tags:[`device`],Control:j6}],P6=1024,F6=[{value:``,label:`Terminal`},{value:`claude`,label:`Claude`},{value:`codex`,label:`Codex`},{value:`pi`,label:`Pi`},{value:`devin`,label:`Devin`},{value:`grok`,label:`Grok`},{value:`omp`,label:`OMP`}];function I6(e,t){let n=t.trim();return e===`label`?n?n.length>64?`Name is at most 64 characters`:null:`Name is required`:n?n.length>1024?`Command is at most ${P6} characters`:null:`Command is required`}function L6(e){return I6(`label`,e.label)===null&&I6(`command`,e.command)===null}function R6(e,t,n){return e.map(e=>e.id===t?Rt({...e,...n}):e)}var z6=`grid items-start gap-2 grid-cols-[56px_92px_minmax(0,0.8fr)_minmax(0,1.3fr)_auto] max-md:grid-cols-[minmax(0,1fr)_minmax(0,auto)_auto] max-md:gap-y-2`,B6=4e3;function V6({preset:e,index:t,isDefault:n,pending:r=!1,autoFocusName:i=!1,onSetDefault:a,onCommitField:o,onIconChange:s,onDelete:c}){let[l,u]=(0,y.useState)(!1),d=(0,y.useRef)(null),f=`settings-preset-${e.id}`,p=e.label.trim()||`preset ${t+1}`;return(0,y.useEffect)(()=>{i&&d.current?.focus()},[i]),(0,y.useEffect)(()=>{if(!l)return;let e=setTimeout(()=>u(!1),B6);return()=>clearTimeout(e)},[l]),(0,k.jsxs)(`div`,{role:`listitem`,"data-preset-id":e.id,className:xE(z6,`py-2`),children:[(0,k.jsxs)(`label`,{className:xE(J3,`flex cursor-pointer items-center gap-2 md:justify-center`),children:[(0,k.jsx)(`input`,{type:`radio`,name:`settings-default-preset`,checked:n,disabled:r,onChange:a,"aria-label":`Default preset: ${p}`,className:`size-4 cursor-pointer accent-accent disabled:cursor-not-allowed`}),(0,k.jsx)(`span`,{"aria-hidden":`true`,className:`text-[12px] text-secondary md:hidden`,children:`Default`})]}),e.isBuiltIn?(0,k.jsxs)(`div`,{className:xE(J3,`flex items-center gap-2 text-muted`),children:[(0,k.jsx)(_g,{agentType:e.agentType,command:e.command,className:`size-4`}),(0,k.jsx)(`span`,{className:`text-[11px]`,children:`Built-in`})]}):(0,k.jsx)(`select`,{id:`${f}-icon`,value:e.agentType??``,"aria-label":`Icon for ${p}`,onChange:e=>s(e.target.value||void 0),className:xE(Q3,`w-full px-1`),children:F6.map(e=>(0,k.jsx)(`option`,{value:e.value,children:e.label},e.value))}),(0,k.jsx)(e6,{ref:d,id:`${f}-label`,value:e.label,placeholder:`Name`,"aria-label":`Name of preset ${t+1}`,maxLength:64,onCommit:e=>o(`label`,e),wrapperClassName:`max-md:order-4 max-md:col-span-3`}),(0,k.jsx)(e6,{id:`${f}-command`,value:e.command,placeholder:`command --flags`,"aria-label":`Command for ${p}`,maxLength:P6,spellCheck:!1,autoCapitalize:`off`,autoCorrect:`off`,onCommit:e=>o(`command`,e),wrapperClassName:`max-md:order-5 max-md:col-span-3`}),e.isBuiltIn?(0,k.jsx)(`span`,{"aria-hidden":`true`,className:`w-[32px] max-md:order-3 max-md:w-[44px]`}):(0,k.jsx)(`button`,{type:`button`,onClick:()=>{if(r||l){c();return}u(!0)},onPointerDown:r?e=>e.preventDefault():void 0,onBlur:()=>u(!1),"aria-label":l?`Confirm delete ${p}`:r?`Discard new preset`:`Delete ${p}`,title:l?`Click again to delete`:void 0,className:xE(Y3,`max-md:order-3`,l?`border-danger bg-danger/10 px-2 text-danger hover:bg-danger/20`:`w-[32px] border-border bg-surface text-secondary hover:bg-hover hover:text-danger max-md:w-[44px]`),children:l?`Delete?`:(0,k.jsx)(fe,{width:K.default,height:K.default})})]})}function H6({ids:e}){let t=G(e=>e.commandPresets),n=G(e=>e.defaultPresetId),[r,i]=(0,y.useState)(null),a=(0,y.useRef)(null),o=(0,y.useRef)(null),s=(0,y.useRef)(!1);(0,y.useEffect)(()=>{if(!s.current)return;s.current=!1;let e=o.current;if(e&&!e.disabled){e.focus();return}let t=a.current?.id;t&&typeof document<`u`&&document.getElementById(`settings-preset-${t}-label`)?.focus()});let c=e=>{a.current=e,i(e)},l=!r&&t.length<50,u=r?[...t,r]:t,d=(e,t,n)=>{let r=I6(t,n);if(r)return r;let{commandPresets:i,setCommandPresets:a}=G.getState();return a(R6(i,e,{[t]:n})),null},f=(e,t)=>{let n=a.current;if(!n)return null;let r={...n,[e]:t},{commandPresets:i,setCommandPresets:o}=G.getState();return L6(r)&&i.length<50?(o([...i,Rt(r)]),c(null)):c(r),null},p=(e,t)=>{if(r?.id===e){c({...r,agentType:t});return}let{commandPresets:n,setCommandPresets:i}=G.getState();i(R6(n,e,{agentType:t}))},m=()=>{l&&c({id:Bt(new Set(t.map(e=>e.id))),label:``,command:``,isBuiltIn:!1})},h=e=>{s.current=!0,a.current?.id===e?c(null):G.getState().removePreset(e)};return(0,k.jsxs)(`div`,{className:`w-full min-w-0`,children:[(0,k.jsxs)(`div`,{"aria-hidden":`true`,className:xE(z6,`border-b border-border pb-1 text-[11px] uppercase tracking-wide text-muted max-md:hidden`),children:[(0,k.jsx)(`span`,{className:`text-center`,children:`Default`}),(0,k.jsx)(`span`,{children:`Icon`}),(0,k.jsx)(`span`,{children:`Name`}),(0,k.jsx)(`span`,{children:`Command`}),(0,k.jsx)(`span`,{className:`w-[32px]`})]}),(0,k.jsx)(`div`,{role:`list`,"aria-labelledby":e.label,"aria-describedby":e.description,className:`divide-y divide-border-subtle`,children:u.map((e,t)=>{let i=e.id===r?.id;return(0,k.jsx)(V6,{preset:e,index:t,isDefault:e.id===n,pending:i,autoFocusName:i,onSetDefault:()=>G.getState().setDefaultPresetId(e.id),onCommitField:(t,n)=>i?f(t,n):d(e.id,t,n),onIconChange:t=>p(e.id,t),onDelete:()=>h(e.id)},e.id)})}),r&&(0,k.jsx)(`p`,{className:xE(`text-[12px] leading-snug text-muted`,`pb-2`),role:`status`,children:`Enter a name and a command to add the preset.`}),(0,k.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,k.jsxs)(`button`,{ref:o,type:`button`,className:X3,onClick:m,disabled:!l,children:[(0,k.jsx)(Je,{width:K.default,height:K.default,className:`mr-1.5`}),`Add preset`]}),t.length>=50&&(0,k.jsxs)(`span`,{className:`text-[12px] leading-snug text-muted`,children:[`Maximum of `,50,` presets.`]})]})]})}function U6({ids:e}){let t=G(e=>e.defaultProjectDir);return(0,k.jsx)(e6,{id:e.control,value:t,placeholder:jt,describedBy:e.description,spellCheck:!1,autoCapitalize:`off`,autoCorrect:`off`,maxLength:4096,wrapperClassName:`w-72 max-md:w-full`,onCommit:e=>(G.getState().setDefaultProjectDir(e.trim()||`~/Documents/GitHub`),null)})}var W6=[{id:`default-project-dir`,page:`new-sessions`,label:`Default project directory`,description:`Folder the new session dialog starts in. Default ${jt}.`,keywords:[`path`,`folder`,`cwd`,`directory`],layout:`wide`,Control:U6},{id:`command-presets`,page:`new-sessions`,label:`Command presets`,description:`Commands offered when creating a session. The default preset is pre-selected.`,keywords:[`preset`,`command`,`agent`,`claude`,`codex`,`default`,`icon`],layout:`block`,Control:H6}],G6=null,K6=!1,q6={},J6=500;function Y6(){if(typeof window>`u`)return null;if(G6?.state===`closed`&&(G6=null),!G6){let e=window.AudioContext??window.webkitAudioContext;if(!e)return null;G6=new e}return G6}function X6(){G6&&=(G6.close().catch(()=>{}),null),Y6()}function Z6(){return K6}function Q6(){G6&&(X6(),K6=!0)}if(typeof window<`u`){window.addEventListener(`pageshow`,e=>{e.persisted&&Q6()}),document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`visible`&&Q6()});let e=Date.now();setInterval(()=>{let t=Date.now();t-e>15e3&&Q6(),e=t},5e3)}async function $6(){let e=Y6();e&&e.state===`suspended`&&await e.resume().catch(()=>{}),K6=!1}async function e8(e){e.state===`suspended`&&await e.resume().catch(()=>{})}async function t8(e){let t=Y6();if(!t||(await e8(t),t.state!==`running`))return;let{frequencies:n,durationMs:r,attackMs:i,peakGain:a,type:o=`sine`}=e,s=t.currentTime,c=r/1e3,l=i/1e3,u=t.createGain();u.connect(t.destination);let d=s+c*.7;u.gain.setValueAtTime(0,s),u.gain.linearRampToValueAtTime(a,s+l),u.gain.setValueAtTime(a,d),u.gain.linearRampToValueAtTime(0,s+c);let f=n.map(e=>{let n=t.createOscillator();return n.type=o,n.frequency.setValueAtTime(e,s),n.connect(u),n});for(let e of f)e.start(s),e.stop(s+c);let p=f[f.length-1];p.onended=()=>{for(let e of f)e.disconnect();u.disconnect()}}async function n8(){let e=Date.now();if(!(e-(q6.permission||0)<J6)){q6.permission=e;try{await t8({frequencies:[880],durationMs:150,attackMs:5,peakGain:.15,type:`sine`})}catch{}}}async function r8(){let e=Date.now();if(!(e-(q6.idle||0)<J6)){q6.idle=e;try{await t8({frequencies:[440,550],durationMs:300,attackMs:10,peakGain:.08,type:`sine`})}catch{}}}function i8(e,t,n,r){return function({ids:i}){let a=G(t=>t[e]),o=G(e=>e[t]);return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`button`,{type:`button`,className:X3,"aria-label":`Test ${r}`,onClick:()=>void n(),children:`Test`}),(0,k.jsx)(T6,{className:Zt,id:i.control,checked:a,onCheckedChange:e=>{o(e),e&&$6()},ariaLabelledBy:i.label,ariaDescribedBy:i.description})]})}}var a8=[{id:`sound-permission`,page:`notifications`,label:`Permission sound`,description:`Play a ping when any session needs permission.`,keywords:[`sound`,`audio`,`alert`,`ping`,`approval`],Control:i8(`soundOnPermission`,`setSoundOnPermission`,n8,`permission sound`)},{id:`sound-idle`,page:`notifications`,label:`Idle sound`,description:`Play a chime when a session finishes working.`,keywords:[`sound`,`audio`,`alert`,`chime`,`done`,`finished`],Control:i8(`soundOnIdle`,`setSoundOnIdle`,r8,`idle sound`)}];function o8(e,t,n){let r=`/api/settings/${e}`,[i,a]=(0,y.useState)(n),[o,s]=(0,y.useState)(!0),[c,l]=(0,y.useState)(!1),u=(0,y.useRef)(n),d=(0,y.useRef)(Promise.resolve()),f=(0,y.useRef)(0),p=(0,y.useRef)(!0),m=(0,y.useRef)(!1);return(0,y.useEffect)(()=>{p.current=!0;let e=!0;return fetch(r).then(e=>{if(!e.ok)throw Error(`HTTP ${e.status}`);return e.json()}).then(n=>{if(!e)return;let r=n[t];f.current===0&&!m.current&&(u.current=r),m.current||a(r)}).catch(()=>{}).finally(()=>{e&&(l(!0),f.current===0&&s(!1))}),()=>{e=!1,p.current=!1}},[r,t]),{value:i,loading:o,loaded:c,set:(0,y.useCallback)(e=>{m.current=!0,f.current+=1,a(e),s(!0),d.current=d.current.then(()=>fetch(r,{method:`PUT`,headers:{"Content-Type":`application/json`},body:JSON.stringify({[t]:e})}).then(t=>{if(!t.ok)throw Error(`HTTP ${t.status}`);u.current=e}).catch(()=>{p.current&&f.current===1&&a(u.current)}).finally(()=>{--f.current,p.current&&f.current===0&&s(!1)}))},[r,t])}}function s8(e,t){return function({ids:n}){let r=G(t=>t[e]),i=G(e=>e[t]);return(0,k.jsx)(T6,{className:Zt,id:n.control,checked:r,onCheckedChange:i,ariaLabelledBy:n.label,ariaDescribedBy:n.description})}}function c8({ids:e}){return(0,k.jsx)(i6,{options:[{value:`created`,label:`Created`},{value:`status`,label:`Status`},{value:`manual`,label:`Manual`}],value:G(e=>e.sessionSortMode),onChange:G(e=>e.setSessionSortMode),labelledBy:e.label,describedBy:e.description})}function l8(){let e=G(e=>e.sessionSortMode);return e===`status`?(0,k.jsx)(k.Fragment,{children:`Permission sessions come first; the rest sort by newest activity.`}):e===`manual`?(0,k.jsx)(k.Fragment,{children:`Drag sessions in the sidebar to reorder them.`}):(0,k.jsx)(k.Fragment,{children:`Sessions stay in the order they were created.`})}function u8({ids:e}){return(0,k.jsx)(i6,{options:[{value:`desc`,label:`Newest first`},{value:`asc`,label:`Oldest first`}],value:G(e=>e.sessionSortDirection),onChange:G(e=>e.setSessionSortDirection),labelledBy:e.label,describedBy:e.description})}function d8({ids:e}){return(0,k.jsx)(i6,{options:[{value:`top`,label:`Top`},{value:`bottom`,label:`Bottom`}],value:G(e=>e.sidebarAnchor),onChange:G(e=>e.setSidebarAnchor),labelledBy:e.label,describedBy:e.description})}function f8(){return G(e=>e.sidebarAnchor)===`bottom`?(0,k.jsx)(k.Fragment,{children:`The sidebar is mirrored: the first session sits at the bottom, next to the prompt.`}):(0,k.jsx)(k.Fragment,{children:`The first session sits at the top of the sidebar.`})}function p8({ids:e}){let{value:t,loaded:n,set:r}=o8(`history-max-age-hours`,`hours`,24);return(0,k.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,k.jsx)(e6,{id:e.control,type:`text`,inputMode:`numeric`,value:String(t),disabled:!n,describedBy:e.description,wrapperClassName:`w-20`,className:`text-center tabular-nums`,onCommit:e=>{let n=t6(e,1,168);return n===null?`Enter 1–168`:(n!==t&&r(n),null)}}),(0,k.jsx)(`span`,{className:`flex h-[32px] items-center text-[12px] text-muted max-md:h-[44px]`,children:`hours`})]})}function m8({ids:e}){let{value:t,loaded:n,set:r}=o8(`prefer-window-name`,`enabled`,!1);return(0,k.jsx)(T6,{className:Zt,id:e.control,checked:t,onCheckedChange:r,disabled:!n,ariaLabelledBy:e.label,ariaDescribedBy:e.description})}var h8=[{id:`sort-order`,page:`session-list`,label:`Sort order`,description:`Created keeps creation order, Status re-sorts by status, Manual lets you drag.`,keywords:[`sort`,`order`,`created`,`status`,`manual`,`drag`],layout:`wide`,Description:l8,Control:c8},{id:`sort-direction`,page:`session-list`,label:`Sort direction`,description:`Newest or oldest sessions first.`,keywords:[`sort`,`newest`,`oldest`,`ascending`,`descending`],layout:`wide`,visibleWhen:e=>e.sessionSortMode===`created`,Control:u8},{id:`sidebar-anchor`,page:`session-list`,label:`Sidebar anchor`,description:`Top lists the first session at the top; Bottom mirrors the sidebar.`,keywords:[`sidebar`,`mirror`,`top`,`bottom`],tags:[`desktop`],Description:f8,Control:d8},{id:`mobile-session-peek`,page:`session-list`,label:`Mobile session peek`,description:`Show the colored status strip at the left edge of the mobile terminal. Turn off to use the full width.`,keywords:[`phone`,`sidebar`,`status`,`rail`],tags:[`device`],Control:s8(`showMobileSessionPeek`,`setShowMobileSessionPeek`)},{id:`show-project-name`,page:`session-list`,label:`Project name`,description:`Show the project folder name under each session.`,keywords:[`folder`,`details`],Control:s8(`showProjectName`,`setShowProjectName`)},{id:`show-last-user-message`,page:`session-list`,label:`Last user message`,description:`Show the most recent prompt next to the project name.`,keywords:[`prompt`,`input`,`details`],Control:s8(`showLastUserMessage`,`setShowLastUserMessage`)},{id:`show-session-id-prefix`,page:`session-list`,label:`Session ID prefix`,description:`Show the first 5 characters of the agent session ID.`,keywords:[`id`,`uuid`,`details`],Control:s8(`showSessionIdPrefix`,`setShowSessionIdPrefix`)},{id:`history-lookback`,page:`session-list`,label:`History lookback`,description:`Show history sessions from the last N hours (1–168), up to the 100 most recent. Default 24.`,keywords:[`history`,`hours`,`age`,`inactive`,`past`],Control:p8},{id:`prefer-window-name`,page:`session-list`,label:`Prefer window names`,description:`Label discovered sessions with their tmux window name instead of the session name.`,keywords:[`tmux`,`window`,`name`,`title`],Control:m8}],g8=`1-9 [ ] N X ,`;function _8({ids:e}){let t=G(e=>e.useWebGL),n=G(e=>e.setUseWebGL);return(0,k.jsx)(T6,{className:Zt,id:e.control,checked:t,onCheckedChange:n,ariaLabelledBy:e.label,ariaDescribedBy:e.description})}function v8({ids:e}){let t=G(e=>e.mobileAutocorrect),n=G(e=>e.setMobileAutocorrect);return(0,k.jsx)(T6,{className:Zt,id:e.control,checked:t,onCheckedChange:n,ariaLabelledBy:e.label,ariaDescribedBy:e.description})}function y8(e,t){return function({ids:n}){let{value:r,loaded:i,set:a}=o8(e,`enabled`,t);return(0,k.jsx)(T6,{className:Zt,id:n.control,checked:r,onCheckedChange:a,disabled:!i,ariaLabelledBy:n.label,ariaDescribedBy:n.description})}}var b8=[`auto`,`ctrl-option`,`ctrl-shift`,`cmd-option`,`cmd-shift`];function x8({ids:e}){let t=G(e=>e.shortcutModifier),n=G(e=>e.setShortcutModifier);return(0,k.jsx)(i6,{options:b8.map(e=>({value:e,label:e===`auto`?`Auto`:kt(e)})),value:t,onChange:n,labelledBy:e.label,describedBy:e.description})}function S8(){return(0,k.jsxs)(k.Fragment,{children:[`Shortcuts: `,kt(Dt(G(e=>e.shortcutModifier))),` + `,g8,` (sessions, navigate, new, kill, settings).`]})}var C8=[{id:`mobile-autocorrect`,page:`terminal`,label:`Mobile autocorrect`,description:`Keyboard suggestions and corrections on iOS and Android. Experimental; turn off for complex text editing.`,keywords:[`keyboard`,`spelling`,`predictive`,`typing`,`gboard`,`iphone`,`ipad`],tags:[`device`],Control:v8},{id:`webgl`,page:`terminal`,label:`WebGL acceleration`,description:`GPU rendering for better performance. Turn off if text looks fuzzy or flickers (common in Safari).`,keywords:[`gpu`,`renderer`,`canvas`,`blurry`,`performance`],tags:[`device`],Control:_8},{id:`mouse-mode`,page:`terminal`,label:`Mouse mode`,description:`tmux mouse mode for trackpad and scroll wheel support.`,keywords:[`tmux`,`scroll`,`trackpad`,`mouse`],Control:y8(`tmux-mouse-mode`,!0)},{id:`terminal-colors`,page:`terminal`,label:`Terminal colors`,description:`Preserve ANSI colors in terminal output. Hibernate then Wake running agents after changing this.`,keywords:[`ansi`,`color`,`colour`],Control:y8(`terminal-colors`,!0)},{id:`shortcut-modifier`,page:`terminal`,label:`Keyboard shortcut modifier`,description:`Modifier keys for the app shortcuts. Auto picks ⌃⌥ on macOS, ⌃⇧ elsewhere.`,keywords:[`keyboard`,`shortcut`,`hotkey`,`ctrl`,`cmd`,`option`,`shift`],tags:[`desktop`,`device`],layout:`wide`,Description:S8,Control:x8}],w8=[...W6,...h8,...N6,...C8,...a8];function T8(e,t=w8){return t.filter(t=>t.page===e)}function E8(e){return[e.label,e.description,...e.keywords??[]].join(` `).toLowerCase()}function D8(e,t=w8){let n=e.trim().toLowerCase().split(/\s+/).filter(Boolean);return n.length===0?[]:t.filter(e=>{let t=E8(e);return n.every(e=>t.includes(e))})}function O8(e){return V3.map(t=>({page:t.id,label:t.label,rows:e.filter(e=>e.page===t.id)})).filter(e=>e.rows.length>0)}var k8={desktop:`Desktop`,device:`This device`},A8={desktop:`Only affects the desktop layout`,device:`Stored in this browser only; not synced to other devices`};function j8({tag:e}){return(0,k.jsx)(`span`,{title:A8[e],className:`shrink-0 border border-border px-1 py-px text-[10px] uppercase leading-none tracking-wide text-muted`,children:k8[e]})}function M8(e){let t=`settings-${e}`;return{control:`${t}-control`,label:`${t}-label`,description:`${t}-desc`}}function N8({row:e}){let t=M8(e.id),n=e.layout??`inline`,{Control:r,Description:i}=e;return(0,k.jsxs)(`div`,{"data-setting-row":e.id,className:xE(`flex gap-x-6 gap-y-3 py-4`,n===`block`&&`flex-col`,n===`wide`&&`items-center max-md:flex-col max-md:items-stretch`,n===`inline`&&`items-center`),children:[(0,k.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,k.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,k.jsx)(`label`,{id:t.label,htmlFor:t.control,className:`text-[14px] leading-snug text-primary`,children:e.label}),e.tags?.map(e=>(0,k.jsx)(j8,{tag:e},e))]}),(0,k.jsx)(`div`,{id:t.description,className:`mt-1 text-[12px] leading-snug text-muted text-pretty`,children:i?(0,k.jsx)(i,{}):e.description})]}),(0,k.jsx)(`div`,{className:xE(`flex min-w-0 items-center gap-2`,n===`inline`?`shrink-0`:`max-w-full`),children:(0,k.jsx)(r,{ids:t})})]})}function P8(e,t){return e.visibleWhen?e.visibleWhen(t):!0}function F8({rows:e}){let t=G(t=>e.map(e=>P8(e,t)?`1`:`0`).join(``));return(0,k.jsx)(`div`,{className:`divide-y divide-border`,children:e.filter((e,n)=>t[n]===`1`).map(e=>(0,k.jsx)(N8,{row:e},e.id))})}function I8({page:e,showTitle:t}){let n=(0,y.useMemo)(()=>T8(e),[e]);return(0,k.jsxs)(`section`,{"aria-labelledby":t?`settings-page-${e}-title`:void 0,children:[t&&(0,k.jsx)(`h3`,{id:`settings-page-${e}-title`,className:`pb-1 text-[18px] font-semibold leading-tight text-primary`,children:U3(e)}),(0,k.jsx)(F8,{rows:n})]})}function L8({query:e}){let t=(0,y.useMemo)(()=>D8(e),[e]),n=G(e=>t.some(t=>P8(t,e))),r=(0,y.useMemo)(()=>O8(t),[t]);return n?(0,k.jsx)(`div`,{className:`flex flex-col gap-6`,children:r.map(e=>(0,k.jsx)(R8,{label:e.label,rows:e.rows},e.page))}):(0,k.jsxs)(`div`,{role:`status`,className:`flex flex-col items-center gap-1 py-16 text-center`,children:[(0,k.jsxs)(`p`,{className:`text-[14px] text-primary`,children:[`No settings match “`,e.trim(),`”`]}),(0,k.jsx)(`p`,{className:`text-[12px] text-muted`,children:`Try a different word, like “font” or “sound”.`})]})}function R8({label:e,rows:t}){return G(e=>t.some(t=>P8(t,e)))?(0,k.jsxs)(`section`,{"aria-label":e,children:[(0,k.jsx)(`h3`,{className:`border-b border-border pb-1 text-[11px] font-medium uppercase tracking-wider text-muted`,children:e}),(0,k.jsx)(F8,{rows:t})]}):null}function z8(e){return`settings-tab-${e}`}function B8(e,t,n){return e===`ArrowDown`?(t+1)%n:e===`ArrowUp`?(t-1+n)%n:e===`Home`?0:e===`End`?n-1:null}function V8({variant:e,current:t,onSelect:n,panelId:r}){let i=(0,y.useRef)([]),a=Math.max(0,V3.findIndex(e=>e.id===t)),o=(t,r)=>{let a=B8(t.key,r,V3.length);a!==null&&(t.preventDefault(),i.current[a]?.focus(),e===`tabs`&&n(V3[a].id))};return e===`list`?(0,k.jsx)(`nav`,{"aria-label":`Settings pages`,children:(0,k.jsx)(`ul`,{className:`divide-y divide-border border-y border-border`,children:V3.map((e,t)=>(0,k.jsx)(`li`,{children:(0,k.jsxs)(`button`,{ref:e=>{i.current[t]=e},type:`button`,"data-page-id":e.id,onClick:()=>n(e.id),onKeyDown:e=>o(e,t),className:`flex min-h-[52px] w-full items-center justify-between gap-3 px-4 text-left text-[15px] text-primary active:bg-hover focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,children:[e.label,(0,k.jsx)(H,{width:K.primary,height:K.primary,className:`text-muted`,"aria-hidden":`true`})]})},e.id))})}):(0,k.jsx)(`div`,{role:`tablist`,"aria-orientation":`vertical`,"aria-label":`Settings pages`,className:`flex flex-col gap-px`,children:V3.map((e,s)=>{let c=e.id===t;return(0,k.jsx)(`button`,{ref:e=>{i.current[s]=e},id:z8(e.id),type:`button`,role:`tab`,"aria-selected":c,"aria-controls":r,tabIndex:s===a?0:-1,onClick:()=>n(e.id),onKeyDown:e=>o(e,s),className:xE(`flex h-[32px] w-full items-center border-l-2 px-3 text-left text-[13px] transition-colors`,`focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`,c?`border-primary bg-hover font-medium text-primary`:`border-transparent text-secondary hover:text-primary`),children:e.label},e.id)})})}var H8=(0,y.forwardRef)(function({value:e,onChange:t,className:n},r){return(0,k.jsxs)(`div`,{className:n,children:[(0,k.jsx)(`label`,{htmlFor:`settings-search`,className:`sr-only`,children:`Search settings`}),(0,k.jsx)(`input`,{ref:r,id:`settings-search`,type:`search`,value:e,placeholder:`Search settings`,autoComplete:`off`,spellCheck:!1,onChange:e=>t(e.target.value),onKeyDown:n=>{n.key===`Escape`&&e&&(n.preventDefault(),t(``))},className:`input h-[32px] px-2 py-0 text-[13px] max-md:h-[44px] max-md:text-[16px] focus-visible:ring-2 focus-visible:ring-accent/40`})]})});function U8({isOpen:e,onClose:t}){return e?(0,k.jsx)(K8,{onClose:t}):null}var W8=`settings-panel`,G8=`flex shrink-0 items-center justify-center text-secondary transition-colors hover:bg-hover hover:text-primary focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-accent`;function K8({onClose:e}){let t=ag(),[n,r]=(0,y.useState)(()=>t?null:K3()),[i,a]=(0,y.useState)(``),o=(0,y.useRef)(null),s=(0,y.useRef)(null),c=(0,y.useRef)(null),l=(0,y.useRef)(!1),u=(0,y.useRef)(null),d=()=>{u.current=n,r(null)};l0({enabled:t&&n!==null,targetRef:o,onBack:d}),z4(),B4(o,e),(0,y.useEffect)(()=>{t?o.current?.focus():s.current?.focus()},[]),(0,y.useEffect)(()=>{if(t){if(n)c.current?.focus();else if(u.current){let e=o.current?.querySelector(`[data-page-id="${u.current}"]`);u.current=null,e?.focus()}}},[t,n]);let f=e=>{r(e),q3(e),a(``)},p=i.trim().length>0,m=(0,k.jsx)(`button`,{type:`button`,onClick:e,"aria-label":`Close settings`,className:xE(G8,`size-[32px] max-md:size-[44px]`),children:(0,k.jsx)(ot,{width:K.primary,height:K.primary})});if(t)return(0,k.jsxs)(`div`,{ref:o,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`settings-title`,"data-suspends-terminal":``,tabIndex:-1,className:`fixed inset-0 z-50 flex flex-col bg-elevated outline-none`,style:{paddingTop:`env(safe-area-inset-top)`,paddingLeft:`env(safe-area-inset-left)`,paddingRight:`env(safe-area-inset-right)`},children:[(0,k.jsxs)(`header`,{className:`flex h-[52px] shrink-0 items-center gap-1 border-b border-border px-1`,children:[n?(0,k.jsx)(`button`,{ref:c,type:`button`,onClick:d,"aria-label":`Back to settings`,className:xE(G8,`size-[44px]`),children:(0,k.jsx)(H,{width:K.primary,height:K.primary,className:`rotate-180`})}):(0,k.jsx)(`span`,{"aria-hidden":`true`,className:`size-[44px] shrink-0`}),(0,k.jsx)(`h2`,{id:`settings-title`,className:`min-w-0 flex-1 truncate text-center text-[16px] font-semibold text-primary`,children:n?U3(n):`Settings`}),m]}),(0,k.jsx)(`div`,{id:W8,className:`min-h-0 flex-1 overflow-y-auto overflow-x-hidden overscroll-contain px-4`,style:{paddingBottom:`calc(24px + env(safe-area-inset-bottom))`},children:n?(0,k.jsx)(I8,{page:n,showTitle:!1}):(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(H8,{ref:s,value:i,onChange:a,className:`py-3`}),p?(0,k.jsx)(L8,{query:i}):(0,k.jsx)(`div`,{className:`-mx-4`,children:(0,k.jsx)(V8,{variant:`list`,current:null,onSelect:f})})]})})]});let h=n??K3();return(0,k.jsx)(`div`,{className:`fixed inset-0 z-50 flex items-center justify-center bg-black/30 p-4`,onMouseDown:e=>{l.current=e.target===e.currentTarget},onClick:t=>{l.current&&t.target===t.currentTarget&&e(),l.current=!1},children:(0,k.jsxs)(`div`,{ref:o,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`settings-title`,"data-suspends-terminal":``,tabIndex:-1,className:`flex h-[600px] max-h-full w-[760px] max-w-full flex-col border border-border bg-elevated shadow-2xl outline-none`,children:[(0,k.jsxs)(`header`,{className:`flex h-[48px] shrink-0 items-center justify-between border-b border-border pl-5 pr-2`,children:[(0,k.jsx)(`h2`,{id:`settings-title`,className:`text-[13px] font-semibold uppercase tracking-wider text-primary`,children:`Settings`}),m]}),(0,k.jsxs)(`div`,{className:`flex min-h-0 flex-1`,children:[(0,k.jsxs)(`div`,{className:`flex w-[192px] shrink-0 flex-col gap-3 border-r border-border p-3`,children:[(0,k.jsx)(H8,{ref:s,value:i,onChange:a}),(0,k.jsx)(V8,{variant:`tabs`,current:p?null:h,onSelect:f,panelId:W8})]}),(0,k.jsx)(`div`,{id:W8,role:p?`region`:`tabpanel`,"aria-label":p?`Search results`:void 0,"aria-labelledby":p?void 0:z8(h),className:`min-w-0 flex-1 overflow-y-auto overflow-x-hidden px-6 py-5`,children:p?(0,k.jsx)(L8,{query:i}):(0,k.jsx)(I8,{page:h,showTitle:!0})})]})]})})}var q8=y.createContext(void 0);function J8(){let e=y.useContext(q8);if(!e)throw Error(mb(73));return e}var Y8=0;function X8(e){return Y8+=1,`${e}-${Math.random().toString(36).slice(2,6)}-${Y8}`}function Z8(e,t){if(typeof e==`string`)return{description:e};if(typeof e==`function`){let n=e(t);return typeof n==`string`?{description:n}:n}return e}var Q8=LS(e=>e.toasts,e=>{let t=new Map,n=0,r=0;return e.forEach((e,i)=>{let a=e.transitionStatus===`ending`;t.set(e.id,{value:e,domIndex:i,visibleIndex:a?-1:n,offsetY:r}),r+=e.height||0,a||(n+=1)}),t}),$8={toasts:IS(e=>e.toasts),isEmpty:IS(e=>e.toasts.length===0),toast:IS(Q8,(e,t)=>e.get(t)?.value),toastIndex:IS(Q8,(e,t)=>e.get(t)?.domIndex??-1),toastOffsetY:IS(Q8,(e,t)=>e.get(t)?.offsetY??0),toastVisibleIndex:IS(Q8,(e,t)=>e.get(t)?.visibleIndex??-1),hovering:IS(e=>e.hovering),focused:IS(e=>e.focused),expanded:IS(e=>e.hovering||e.focused),expandedOrOutOfFocus:IS(e=>e.hovering||e.focused||!e.isWindowFocused),prevFocusElement:IS(e=>e.prevFocusElement)},e5=class extends eC{timers=new Map;areTimersPaused=!1;constructor(e){super(e,{},$8)}setFocused(e){this.set(`focused`,e)}setHovering(e){this.set(`hovering`,e)}setIsWindowFocused(e){this.set(`isWindowFocused`,e)}setPrevFocusElement(e){this.set(`prevFocusElement`,e)}setViewport=e=>{this.set(`viewport`,e)};disposeEffect=()=>()=>{this.timers.forEach(e=>{e.timeout?.clear()}),this.timers.clear()};removeToast(e){let t=$8.toastIndex(this.state,e);if(t===-1)return;this.state.toasts[t]?.onRemove?.();let n=[...this.state.toasts];n.splice(t,1),this.setToasts(n)}addToast=e=>{let{toasts:t,timeout:n,limit:r}=this.state,i=e.id||X8(`toast`),a={...e,id:i,transitionStatus:`starting`},o=[a,...t],s=o.filter(e=>e.transitionStatus!==`ending`);if(s.length>r){let e=s.length-r,t=s.slice(-e),n=new Set(t.map(e=>e.id));this.setToasts(o.map(e=>{let t=n.has(e.id);return e.limited===t?e:{...e,limited:t}}))}else this.setToasts(o.map(e=>e.limited?{...e,limited:!1}:e));let c=a.timeout??n;return a.type!==`loading`&&c>0&&this.scheduleTimer(i,c,()=>this.closeToast(i)),$8.expandedOrOutOfFocus(this.state)&&this.pauseTimers(),i};updateToast=(e,t)=>{this.updateToastInternal(e,t)};updateToastInternal=(e,t)=>{let{timeout:n,toasts:r}=this.state,i=$8.toast(this.state,e)??null;if(!i||i.transitionStatus===`ending`)return;let a={...i,...t};this.setToasts(r.map(n=>n.id===e?{...n,...t}:n));let o=a.timeout??n,s=i?.timeout??n,c=Object.hasOwn(t,`timeout`),l=a.transitionStatus!==`ending`&&a.type!==`loading`&&o>0,u=this.timers.has(e),d=s!==o,f=i?.type===`loading`;if(!l&&u){this.timers.get(e)?.timeout?.clear(),this.timers.delete(e);return}if(l&&(!u||d||c||f)){let t=this.timers.get(e);t&&(t.timeout?.clear(),this.timers.delete(e)),this.scheduleTimer(e,o,()=>this.closeToast(e)),$8.expandedOrOutOfFocus(this.state)&&this.pauseTimers()}};closeToast=e=>{$8.toast(this.state,e)?.onClose?.();let{limit:t,toasts:n}=this.state,r=0,i=n.map(n=>{if(n.id===e)return{...n,transitionStatus:`ending`,height:0};if(n.transitionStatus===`ending`)return n;let i=r>=t;return r+=1,n.limited===i?n:{...n,limited:i}}),a=this.timers.get(e);a&&a.timeout&&(a.timeout.clear(),this.timers.delete(e)),this.handleFocusManagement(e),this.setToasts(i)};promiseToast=(e,t)=>{let n=Z8(t.loading),r=this.addToast({...n,type:`loading`}),i=e.then(e=>{let n=Z8(t.success,e);return this.updateToast(r,{...n,type:`success`,timeout:n.timeout}),e}).catch(e=>{let n=Z8(t.error,e);return this.updateToast(r,{...n,type:`error`,timeout:n.timeout}),Promise.reject(e)});return{}.hasOwnProperty.call(t,`setPromise`)&&t.setPromise(i),i};pauseTimers(){this.areTimersPaused||(this.areTimersPaused=!0,this.timers.forEach(e=>{if(e.timeout){e.timeout.clear();let t=Date.now()-e.start,n=e.delay-t;e.remaining=n>0?n:0}}))}resumeTimers(){this.areTimersPaused&&(this.areTimersPaused=!1,this.timers.forEach((e,t)=>{e.remaining=e.remaining>0?e.remaining:e.delay,e.timeout??=d_.create(),e.timeout.start(e.remaining,()=>{this.timers.delete(t),e.callback()}),e.start=Date.now()}))}restoreFocusToPrevElement(){this.state.prevFocusElement?.focus({preventScroll:!0})}handleDocumentPointerDown=e=>{if(e.pointerType!==`touch`)return;let t=V_(e);z_(this.state.viewport,t)||(this.resumeTimers(),this.update({hovering:!1,focused:!1}))};scheduleTimer(e,t,n){let r=Date.now(),i=!$8.expandedOrOutOfFocus(this.state),a=i?d_.create():void 0;a?.start(t,()=>{this.timers.delete(e),n()}),this.timers.set(e,{timeout:a,start:i?r:0,delay:t,remaining:t,callback:n})}setToasts(e){let t={toasts:e};e.length===0&&(t.hovering=!1,t.focused=!1),this.update(t)}handleFocusManagement(e){let t=R_(i_(this.state.viewport));if(!this.state.viewport||!z_(this.state.viewport,t)||!K_(t))return;let n=$8.toasts(this.state),r=$8.toastIndex(this.state,e),i=null,a=r+1;for(;a<n.length;){if(n[a].transitionStatus!==`ending`){i=n[a];break}a+=1}if(!i)for(a=r-1;a>=0;){if(n[a].transitionStatus!==`ending`){i=n[a];break}--a}i?i.ref?.current?.focus():this.restoreFocusToPrevElement()}},t5=function(e){let{children:t,timeout:n=5e3,limit:r=3,toastManager:i}=e,a=s_(()=>new e5({timeout:n,limit:r,viewport:null,toasts:[],hovering:!1,focused:!1,isWindowFocused:!0,prevFocusElement:null})).current;return l_(a.disposeEffect),y.useEffect(function(){if(i)return i[` subscribe`](({action:e,options:t})=>{let n=t.id;e===`promise`&&t.promise?a.promiseToast(t.promise,t):e===`update`&&n?a.updateToast(n,t):e===`close`&&n?a.closeToast(n):a.addToast(t)})},[a,n,i]),a.useSyncedValues({timeout:n,limit:r}),(0,k.jsx)(q8.Provider,{value:a,children:t})},n5=function(e){return e.frontmostHeight=`--toast-frontmost-height`,e}({}),r5=y.forwardRef(function(e,t){let{render:n,className:r,children:i,...a}=e,o=J8(),s=f_(),c=y.useRef(!1),l=y.useRef(!1),u=o.useState(`isEmpty`),d=o.useState(`toasts`),f=o.useState(`focused`),p=o.useState(`expanded`),m=o.useState(`prevFocusElement`),h=d[0]?.height??0,g=y.useMemo(()=>d.some(e=>e.transitionStatus===`ending`),[d]);y.useEffect(()=>{let e=o.state.viewport;if(!e)return;function t(t){u||t.key===`F6`&&t.target!==e&&(t.preventDefault(),o.setPrevFocusElement(R_(i_(e))),e?.focus({preventScroll:!0}),o.pauseTimers(),o.setFocused(!0))}let n=bg(e);return n.addEventListener(`keydown`,t),()=>{n.removeEventListener(`keydown`,t)}},[o,u]),y.useEffect(()=>{let e=o.state.viewport;if(!e||u)return;let t=bg(e);function n(e){e.target===t&&(o.setIsWindowFocused(!1),o.pauseTimers())}function r(n){if(n.relatedTarget||n.target===t)return;let r=V_(n),i=R_(i_(e));(!z_(e,r)||!K_(i))&&o.resumeTimers(),s.start(0,()=>o.setIsWindowFocused(!0))}return t.addEventListener(`blur`,n,!0),t.addEventListener(`focus`,r,!0),()=>{t.removeEventListener(`blur`,n,!0),t.removeEventListener(`focus`,r,!0)}},[o,s,u]),y.useEffect(()=>{let e=o.state.viewport;if(!e||u)return;let t=i_(e);return t.addEventListener(`pointerdown`,o.handleDocumentPointerDown,!0),()=>{t.removeEventListener(`pointerdown`,o.handleDocumentPointerDown,!0)}},[u,o]);function _(e){let t=o.state.viewport;t&&(c.current=!0,e.relatedTarget===t?d[0]?.ref?.current?.focus():o.restoreFocusToPrevElement())}function v(e){e.key===`Tab`&&e.shiftKey&&e.target===o.state.viewport&&(e.preventDefault(),o.restoreFocusToPrevElement(),o.resumeTimers())}y.useEffect(()=>{!o.state.isWindowFocused||g||!l.current||(o.resumeTimers(),o.setHovering(!1),l.current=!1)},[g,o]);function b(){o.pauseTimers(),o.setHovering(!0),l.current=!1}function x(){g?l.current=!0:(o.resumeTimers(),o.setHovering(!1))}function S(){if(c.current){c.current=!1;return}f||K_(i_(o.state.viewport).activeElement)&&(o.setFocused(!0),o.pauseTimers())}function C(e){!f||z_(o.state.viewport,e.relatedTarget)||(o.setFocused(!1),o.resumeTimers())}let w={tabIndex:-1,role:`region`,"aria-live":`polite`,"aria-atomic":!1,"aria-relevant":`additions text`,"aria-label":`Notifications`,onMouseEnter:b,onMouseMove:b,onMouseLeave:x,onFocus:S,onBlur:C,onKeyDown:v,onClick:S},T={expanded:p},E=Pb(`div`,e,{ref:[t,o.setViewport],state:T,props:[w,{style:{[n5.frontmostHeight]:h?`${h}px`:void 0}},a,{children:(0,k.jsxs)(y.Fragment,{children:[!u&&m&&(0,k.jsx)(nb,{onFocus:_}),i,!u&&m&&(0,k.jsx)(nb,{onFocus:_})]})}]}),D=y.useMemo(()=>d.filter(e=>e.priority===`high`),[d]);return(0,k.jsxs)(y.Fragment,{children:[!u&&m&&(0,k.jsx)(nb,{onFocus:_}),E,!f&&D.length>0&&(0,k.jsx)(`div`,{style:eb,children:D.map(e=>(0,k.jsxs)(`div`,{role:`alert`,"aria-atomic":!0,children:[(0,k.jsx)(`div`,{children:e.title}),(0,k.jsx)(`div`,{children:e.description})]},e.id))})]})}),i5=y.createContext(void 0);function a5(){let e=y.useContext(i5);if(!e)throw Error(mb(66));return e}var o5=function(e){return e.index=`--toast-index`,e.offsetY=`--toast-offset-y`,e.height=`--toast-height`,e.swipeMovementX=`--toast-swipe-movement-x`,e.swipeMovementY=`--toast-swipe-movement-y`,e}({}),s5={...sC,swipeDirection(e){return e?{"data-swipe-direction":e}:null}},c5=40,l5=10,u5=.5,d5=1;function f5(e,t,n){switch(e){case`up`:return-n;case`down`:return n;case`left`:return-t;case`right`:return t;default:return 0}}function p5(e){let t=window.getComputedStyle(e).transform,n=0,r=0,i=1;if(t&&t!==`none`){let e=t.match(/matrix(?:3d)?\(([^)]+)\)/);if(e){let t=e[1].split(`, `).map(parseFloat);t.length===6?(n=t[4],r=t[5],i=Math.sqrt(t[0]*t[0]+t[1]*t[1])):t.length===16&&(n=t[12],r=t[13],i=t[0])}}return{x:n,y:r,scale:i}}var m5=y.forwardRef(function(e,t){let{toast:n,render:r,className:i,swipeDirection:a=[`down`,`right`],...o}=e,s=n.positionerProps?.anchor!==void 0,c=[];s||(c=Array.isArray(a)?a:[a]);let l=c.length>0,u=J8(),[d,f]=y.useState(void 0),[p,m]=y.useState(!1),[h,g]=y.useState(!1),[_,v]=y.useState(!1),[b,x]=y.useState({x:0,y:0}),[S,C]=y.useState({x:0,y:0,scale:1}),[w,T]=y.useState(),[E,D]=y.useState(),[O,A]=y.useState(null),j=y.useRef(null),M=y.useRef({x:0,y:0}),N=y.useRef({x:0,y:0,scale:1}),P=y.useRef(void 0),F=y.useRef(0),I=y.useRef(!1),L=y.useRef({x:0,y:0}),R=y.useRef(!1),z=u.useState(`toastIndex`,n.id),B=u.useState(`toastVisibleIndex`,n.id),V=u.useState(`toastOffsetY`,n.id),ee=u.useState(`focused`),H=u.useState(`expanded`);lC({open:n.transitionStatus!==`ending`,ref:j,onComplete(){n.transitionStatus===`ending`&&u.removeToast(n.id)}});let te=N_((e=!1)=>{let t=j.current;if(!t)return;let r=t.style.height;t.style.height=`auto`;let i=t.offsetHeight;t.style.height=r;function a(){u.updateToastInternal(n.id,{ref:j,height:i,...n.transitionStatus===`starting`?{transitionStatus:void 0}:{}})}e?_f.flushSync(a):a()});a_(te,[te]);function U(e,t){let n=e,r=t;return!c.includes(`left`)&&!c.includes(`right`)?n=e>0?e**u5:-(Math.abs(e)**u5):(!c.includes(`right`)&&e>0&&(n=e**u5),!c.includes(`left`)&&e<0&&(n=-(Math.abs(e)**u5))),!c.includes(`up`)&&!c.includes(`down`)?r=t>0?t**u5:-(Math.abs(t)**u5):(!c.includes(`down`)&&t>0&&(r=t**u5),!c.includes(`up`)&&t<0&&(r=-(Math.abs(t)**u5))),{x:n,y:r}}function ne(e){if(e.button!==0)return;e.pointerType===`touch`&&u.pauseTimers();let t=V_(e.nativeEvent);if(!(t&&t.closest(`button,a,input,textarea,[role="button"],[data-swipe-ignore]`))){if(I.current=!1,P.current=void 0,F.current=0,M.current={x:e.clientX,y:e.clientY},L.current=M.current,j.current){let e=p5(j.current);N.current=e,C(e),x({x:e.x,y:e.y})}u.setHovering(!0),m(!0),g(!1),A(null),R.current=!0,j.current?.setPointerCapture(e.pointerId)}}function W(e){if(!p)return;e.preventDefault(),R.current&&=(M.current={x:e.clientX,y:e.clientY},!1);let{clientY:t,clientX:n,movementX:r,movementY:i}=e;(i<0&&t>L.current.y||i>0&&t<L.current.y)&&(L.current={x:L.current.x,y:t}),(r<0&&n>L.current.x||r>0&&n<L.current.x)&&(L.current={x:n,y:L.current.y});let a=n-M.current.x,o=t-M.current.y,s=t-L.current.y,l=n-L.current.x;if(!h&&Math.sqrt(a*a+o*o)>=d5&&(g(!0),O===null)){let e=c.includes(`left`)||c.includes(`right`),t=c.includes(`up`)||c.includes(`down`);e&&t&&A(Math.abs(a)>Math.abs(o)?`horizontal`:`vertical`)}let u;if(!P.current)O===`vertical`?o>0?u=`down`:o<0&&(u=`up`):O===`horizontal`?a>0?u=`right`:a<0&&(u=`left`):u=Math.abs(a)>=Math.abs(o)?a>0?`right`:`left`:o>0?`down`:`up`,u&&c.includes(u)&&(P.current=u,F.current=f5(u,a,o),f(u));else{let e=P.current,t=f5(e,l,s);t>c5?(I.current=!1,f(e)):!(c.includes(`left`)&&c.includes(`right`))&&!(c.includes(`up`)&&c.includes(`down`))&&F.current-t>=l5&&(I.current=!0)}let d=U(a,o),m=N.current.x,_=N.current.y;O===`horizontal`?(c.includes(`left`)||c.includes(`right`))&&(m+=d.x):(O===`vertical`||(c.includes(`left`)||c.includes(`right`))&&(m+=d.x),(c.includes(`up`)||c.includes(`down`))&&(_+=d.y)),x({x:m,y:_})}function re(e){if(!p)return;if(m(!1),g(!1),A(null),j.current?.releasePointerCapture(e.pointerId),I.current){x({x:S.x,y:S.y}),f(void 0);return}let t=!1,r=b.x-S.x,i=b.y-S.y,a;for(let e of c){switch(e){case`right`:r>c5&&(t=!0,a=`right`);break;case`left`:r<-c5&&(t=!0,a=`left`);break;case`down`:i>c5&&(t=!0,a=`down`);break;case`up`:i<-c5&&(t=!0,a=`up`);break;default:break}if(t)break}t?(f(a),v(!0),u.closeToast(n.id)):(x({x:S.x,y:S.y}),f(void 0))}function ie(e){if(e.key===`Escape`){if(!j.current||!z_(j.current,R_(i_(j.current))))return;u.closeToast(n.id)}}y.useEffect(()=>{if(!l)return;let e=j.current;if(!e)return;function t(t){z_(e,t.target)&&t.preventDefault()}return e.addEventListener(`touchmove`,t,{passive:!1}),()=>{e.removeEventListener(`touchmove`,t)}},[l]);function ae(){if(!p&&b.x===S.x&&b.y===S.y&&!_)return{[o5.swipeMovementX]:`0px`,[o5.swipeMovementY]:`0px`};let e=b.x-S.x,t=b.y-S.y;return{transition:p?`none`:void 0,transform:p?`translateX(${b.x}px) translateY(${b.y}px) scale(${S.scale})`:void 0,[o5.swipeMovementX]:`${e}px`,[o5.swipeMovementY]:`${t}px`}}let oe=n.priority===`high`,se={role:oe?`alertdialog`:`dialog`,tabIndex:0,"aria-modal":!1,"aria-labelledby":w,"aria-describedby":E,"aria-hidden":oe&&!ee?!0:void 0,onPointerDown:l?ne:void 0,onPointerMove:l?W:void 0,onPointerUp:l?re:void 0,onKeyDown:ie,inert:gw(n.limited),style:{...ae(),[o5.index]:n.transitionStatus===`ending`?z:B,[o5.offsetY]:`${V}px`,[o5.height]:n.height?`${n.height}px`:void 0}},ce=y.useMemo(()=>({rootRef:j,toast:n,titleId:w,setTitleId:T,descriptionId:E,setDescriptionId:D,swiping:p,swipeDirection:d,recalculateHeight:te,index:z,visibleIndex:B,expanded:H}),[n,w,E,p,d,te,z,B,H]),le={transitionStatus:n.transitionStatus,expanded:H,limited:n.limited||!1,type:n.type,swiping:ce.swiping,swipeDirection:ce.swipeDirection},ue=Pb(`div`,e,{ref:[t,ce.rootRef],state:le,stateAttributesMapping:s5,props:[se,o]});return(0,k.jsx)(i5.Provider,{value:ce,children:ue})}),h5=y.forwardRef(function(e,t){let{render:n,className:r,id:i,children:a,...o}=e,{toast:s,setDescriptionId:c}=a5(),l=a??s.description,u=!!l,d=Sy(i);a_(()=>{if(u)return c(d),()=>{c(void 0)}},[u,d,c]);let f=Pb(`p`,e,{ref:t,state:{type:s.type},props:{...o,id:d,children:l}});return u?f:null}),g5=y.forwardRef(function(e,t){let{render:n,className:r,id:i,children:a,...o}=e,{toast:s,setTitleId:c}=a5(),l=a??s.title,u=!!l,d=Sy(i);a_(()=>{if(u)return c(d),()=>{c(void 0)}},[u,d,c]);let f=Pb(`h2`,e,{ref:t,state:{type:s.type},props:{...o,id:d,children:l}});return u?f:null}),_5=y.forwardRef(function(e,t){let{render:n,className:r,disabled:i,nativeButton:a=!0,...o}=e,s=J8(),{toast:c}=a5(),l=s.useState(`expanded`),[u,d]=y.useState(!1),{getButtonProps:f,buttonRef:p}=$C({disabled:i,native:a}),m={type:c.type};return Pb(`button`,e,{ref:[t,p],state:m,props:[{"aria-hidden":!l&&!u,onClick(){s.closeToast(c.id)},onFocus(){d(!0)},onBlur(){d(!1)}},o,f]})});function v5(){let e=y.useContext(q8);if(!e)throw Error(mb(73));let t=e.useState(`toasts`);return y.useMemo(()=>({toasts:t,add:e.addToast,close:e.closeToast,update:e.updateToast,promise:e.promiseToast}),[t,e])}function y5(){let e=new Set;function t(t){e.forEach(e=>e(t))}return{" subscribe":function(t){return e.add(t),()=>{e.delete(t)}},add(e){let n=e.id||X8(`toast`);return t({action:`add`,options:{...e,id:n,transitionStatus:`starting`}}),n},close(e){t({action:`close`,options:{id:e}})},update(e,n){t({action:`update`,options:{...n,id:e}})},promise(e,n){let r=e;return t({action:`promise`,options:{...n,promise:e,setPromise(e){r=e}}}),r}}}var b5=5e3,x5=y5();function S5({toast:e}){return(0,k.jsxs)(m5,{toast:e,className:xE(`relative flex w-80 items-start gap-3 border bg-elevated p-4 shadow-lg`,`data-[swipe=move]:translate-x-[var(--toast-swipe-move-x)]`,`data-[ending-style]:translate-x-[var(--toast-swipe-end-x)]`,`data-[ending-style]:opacity-0`,`data-[starting-style]:translate-y-2 data-[starting-style]:opacity-0`,`transition-all duration-200`,e.type===`error`&&`border-danger/50`,e.type===`success`&&`border-approval/50`,(!e.type||e.type===`info`)&&`border-border`),children:[(0,k.jsxs)(`div`,{className:`flex-1 min-w-0`,children:[(0,k.jsx)(g5,{className:xE(`text-sm font-medium`,e.type===`error`&&`text-danger`,e.type===`success`&&`text-approval`,(!e.type||e.type===`info`)&&`text-primary`),children:e.title}),e.description&&(0,k.jsx)(h5,{className:`mt-1 text-xs text-muted line-clamp-2`,children:e.description})]}),(0,k.jsx)(_5,{className:`shrink-0 text-muted hover:text-primary transition-colors`,"aria-label":`Close`,children:(0,k.jsx)(ot,{width:K.default,height:K.default})})]})}function C5(){let{toasts:e}=v5();return(0,k.jsx)(k.Fragment,{children:e.map(e=>(0,k.jsx)(S5,{toast:e},e.id))})}function w5(){return(0,k.jsxs)(t5,{timeout:b5,toastManager:x5,children:[(0,k.jsx)(C5,{}),(0,k.jsx)(r5,{className:`fixed bottom-4 right-4 z-[100] flex flex-col gap-2`})]})}var T5=`Agentboard was updated. Reload this tab to reconnect. Your saved recovery drafts remain on this device.`,E5=[`CONNECTING`,`OPEN`,`CLOSING`,`CLOSED`],D5=3e3,O5=3e4,k5=8e3,A5=15e3,j5=5e3,M5=2e4,N5=3e4,P5=1e4,F5=1500,I5=5e3,L5=750,R5=4,z5=5e3,B5=new class{constructor(){this.ws=null,this.listeners=new Set,this.statusListeners=new Set,this.status=`connecting`,this.error=null,this.reconnectAttempts=0,this.overloadFailures=0,this.overloadRetryAt=0,this.overloadProgressSince=null,this.reconnectTimer=null,this.connectTimer=null,this.manualClose=!1,this.protocolMismatch=!1,this.protocolReady=!1,this.lastTick=Date.now(),this.wakeCheckInterval=null,this.lifecycleStarted=!1,this.heartbeatTimer=null,this.pongTimer=null,this.lastForceReconnectTs=0,this.lastConnectTs=0,this.traceId=`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,this.lastMessageAt=null,this.lastPongSeq=null,this.lastPingAt=null,this.lastMessageType=null,this.pingSeq=0,this.connectionEpoch=0,this.consecutiveFailures=0,this.stallCount=0,this.isResumeAttempt=!1,this.leakedSockets=new Set,this.verifyTimer=null,this.pageSuspended=!1,this.resumeClaim=0,this.attachId=0,this.attachedSessionId=null,this.readyAttachId=null,this.lastResumeAt=0,this.onVisibilityChange=()=>{uR(`ws_visibility`,{state:document.visibilityState,...this.wsSnap()},`info`),document.visibilityState===`visible`?(this.pageSuspended=!1,this.resumeConnection(`visibilitychange`)):this.suspendConnection()},this.onPageShow=e=>{uR(`ws_pageshow`,{persisted:e.persisted,...this.wsSnap()},`info`),e.persisted&&(this.pageSuspended=!1,this.resumeConnection(`pageshow`))},this.onPageHide=()=>{this.pageSuspended=!0,this.suspendConnection()}}wsSnap(){return{traceId:this.traceId,clientTimeMs:Date.now(),clientUptimeMs:Math.round(performance.now()),epoch:this.connectionEpoch,pingSeq:this.pingSeq,lastPongSeq:this.lastPongSeq,lastPingAgeMs:this.lastPingAt===null?null:Date.now()-this.lastPingAt,lastMessageType:this.lastMessageType,lastMessageAgeMs:this.lastMessageAt===null?null:Date.now()-this.lastMessageAt,visibility:typeof document>`u`?void 0:document.visibilityState,status:this.status,ws:this.ws?E5[this.ws.readyState]:null,attempt:this.reconnectAttempts,failures:this.consecutiveFailures,stalls:this.stallCount,overloads:this.overloadFailures,overloadDelayMs:Math.max(0,this.overloadRetryAt-Date.now()),leaked:this.leakedSockets.size,online:typeof navigator<`u`?navigator.onLine:void 0,verifying:this.verifyTimer!==null,buffered:this.ws?this.ws.bufferedAmount:void 0}}connect(){if(this.protocolMismatch||this.isHidden()||this.waitForOverloadCooldown())return;if(this.ws){let e=this.ws.readyState===WebSocket.OPEN;if(e&&this.status===`connected`){uR(`ws_connect_skip`,{reason:`already_open`,...this.wsSnap()});return}let t=Date.now();if(this.ws.readyState===WebSocket.CONNECTING&&t-this.lastConnectTs<200){uR(`ws_connect_skip`,{reason:`already_connecting`,...this.wsSnap()});return}uR(`ws_connect_destroy_zombie`,{reason:e?`open_desynced`:`not_open`,...this.wsSnap()}),this.destroySocket()}this.manualClose=!1,this.clearConnectTimer(),this.setStatus(`connecting`);let e=`${window.location.protocol===`https:`?`wss`:`ws`}://${window.location.host}/ws?catalog=2`;uR(`ws_connect`,{url:e,resume:this.isResumeAttempt,...this.wsSnap()},`info`);let t=new WebSocket(e),n=!1;this.ws=t,this.protocolReady=!1,this.lastMessageAt=null,this.lastPongSeq=null,this.lastPingAt=null,this.lastMessageType=null,this.lastConnectTs=Date.now(),this.leakedSockets.add(t);let r=this.isResumeAttempt?k5:D5;this.isResumeAttempt=!1,this.connectTimer=window.setTimeout(()=>{this.ws===t&&(this.connectTimer=null,t.readyState===WebSocket.OPEN&&this.status===`connected`||(uR(`ws_connect_timeout`,{wsState:E5[t.readyState],managerStatus:this.status,timeoutMs:r,...this.wsSnap()},`info`),this.consecutiveFailures+=1,this.destroySocket(),this.scheduleReconnect()))},r),t.onopen=()=>{if(this.ws!==t){uR(`ws_onopen_stale`,this.wsSnap(),`info`);return}uR(`ws_onopen`,this.wsSnap(),`info`),this.reconnectAttempts=0,this.consecutiveFailures=0,this.stallCount=0,this.connectionEpoch+=1,this.leakedSockets.delete(t),this.clearConnectTimer(),this.connectTimer=window.setTimeout(()=>{this.ws!==t||this.protocolReady||(this.connectTimer=null,this.consecutiveFailures+=1,this.destroySocket(),this.scheduleReconnect(),this.setStatus(`reconnecting`,`Server handshake timed out. Retrying…`))},O5)},t.onmessage=e=>{if(this.ws===t){this.lastMessageAt=Date.now(),this.lastMessageType=`unparsed`;try{let r=e.data,i=performance.now(),a=JSON.parse(r);if(this.lastMessageType=a.type,!this.protocolReady&&a.type!==`server-config`){this.requireCatalogReload();return}if(a.type===`server-config`){if(a.catalogVersion!==2){this.requireCatalogReload();return}if(!this.protocolReady){if(this.protocolReady=!0,this.clearConnectTimer(),!this.send({type:`terminal-resume`,token:this.resumeToken,claim:++this.resumeClaim}))return;this.lastTick=Date.now(),this.setStatus(this.isHidden()?`reconnecting`:`connected`),this.isHidden()||this.startHeartbeat()}}let o=performance.now()-i,s=a;if(s._parseMs=Math.round(o),s._rawLength=r.length,s._connectionEpoch=this.connectionEpoch,a.type===`terminal-lease`){this.resumeToken=a.token;return}if(a.type===`terminal-overload`){n=!0,this.stopHeartbeat(),this.cancelVerify(),this.setStatus(`reconnecting`),t.close();return}if(a.type===`pong`){if(this.lastPongSeq=a.seq??null,uR(`ws_pong_received`,{receivedSeq:a.seq,matchesPendingPing:a.seq===this.pingSeq,...this.wsSnap()}),a.seq===this.pingSeq){if(this.clearPongTimer(),this.verifyTimer!==null){if(this.cancelVerify(),uR(`ws_verify_ok`,this.wsSnap(),`info`),this.isHidden())return;this.connectionEpoch+=1,this.setStatus(`connected`),this.startHeartbeat(I5)}this.recordOverloadRecovery()}return}if(a.type===`terminal-output`||a.type===`terminal-ready`||a.type===`tmux-copy-mode-status`||a.type===`clipboard-offer`||a.type===`terminal-error`){if(!(this.status===`connected`&&!this.isHidden()&&(!a.sessionId||a.sessionId===this.attachedSessionId)&&(a.attachId===this.attachId||a.attachId===void 0&&!this.resumeToken))){a.type===`terminal-output`&&a.outputSeq!==void 0&&this.send({type:`terminal-ack`,outputSeq:a.outputSeq});return}a.type===`terminal-ready`&&(this.readyAttachId=this.attachId,this.recordOverloadRecovery())}this.listeners.forEach(e=>e(a))}catch{}}},t.onerror=()=>{this.ws===t&&(uR(`ws_onerror`,this.wsSnap(),`info`),this.clearConnectTimer())},t.onclose=e=>{if(this.leakedSockets.delete(t),this.ws!==t){uR(`ws_onclose_stale`,{code:e.code,...this.wsSnap()},`info`);return}uR(`ws_onclose`,{code:e.code,reason:e.reason,clean:e.wasClean,...this.wsSnap()},`info`),this.clearConnectTimer(),this.cancelVerify(),this.consecutiveFailures+=1,this.overloadProgressSince=null,(n||e.code===1013)&&(this.overloadFailures=Math.min(this.overloadFailures+1,6),this.overloadRetryAt=Date.now()+Math.min(1e3*2**(this.overloadFailures-1),3e4)),this.ws=null,this.manualClose?this.setStatus(`disconnected`):this.scheduleReconnect()}}requireCatalogReload(){this.protocolMismatch=!0,this.disconnect(),this.setStatus(`disconnected`,T5),this.listeners.forEach(e=>e({type:`error`,message:T5}))}disconnect(){this.overloadFailures=0,this.overloadRetryAt=0,this.overloadProgressSince=null,this.manualClose=!0,this.clearConnectTimer(),this.cancelVerify(),this.reconnectTimer&&=(window.clearTimeout(this.reconnectTimer),null),this.destroySocket(),this.setStatus(`disconnected`)}startLifecycleListeners(){this.lifecycleStarted||typeof document>`u`||typeof window>`u`||(this.lifecycleStarted=!0,document.addEventListener(`visibilitychange`,this.onVisibilityChange),window.addEventListener(`pageshow`,this.onPageShow),window.addEventListener(`pagehide`,this.onPageHide),this.lastTick=Date.now(),this.wakeCheckInterval=window.setInterval(()=>{let e=Date.now(),t=e-this.lastTick;this.isHidden()||(t>A5&&(uR(`ws_time_jump`,{gapMs:t,...this.wsSnap()},`info`),this.resumeConnection(`time_jump`)),this.lastTick=e)},j5))}stopLifecycleListeners(){this.lifecycleStarted&&(this.lifecycleStarted=!1,document.removeEventListener(`visibilitychange`,this.onVisibilityChange),window.removeEventListener(`pageshow`,this.onPageShow),window.removeEventListener(`pagehide`,this.onPageHide),this.wakeCheckInterval!==null&&(window.clearInterval(this.wakeCheckInterval),this.wakeCheckInterval=null))}send(e){if(this.protocolMismatch||!this.protocolReady||this.ws?.readyState!==WebSocket.OPEN)return!1;if(e.type===`terminal-ack`&&e.connectionEpoch!==void 0){if(e.connectionEpoch!==this.connectionEpoch)return!1;e={type:`terminal-ack`,outputSeq:e.outputSeq}}let t=e.type.startsWith(`terminal-`)||e.type.startsWith(`tmux-`),n=e.type===`terminal-resume`||e.type===`terminal-ack`;if(t&&!n){if(e.type!==`terminal-detach`){if(this.isHidden())return!1;if(Date.now()-this.lastTick>A5)return this.resumeConnection(`input_time_jump`),!1;if(this.status!==`connected`)return!1}if(e.type===`terminal-attach`)this.attachId+=1,this.attachedSessionId=e.sessionId,this.readyAttachId=null;else if(e.type===`terminal-input`||e.type===`terminal-paste`){if(this.readyAttachId!==this.attachId||e.sessionId!==this.attachedSessionId)return!1}else e.type===`terminal-detach`&&(this.readyAttachId=null,this.attachedSessionId=null);e={...e,attachId:this.attachId}}try{return this.ws.send(JSON.stringify(e)),e.type===`ping`&&(this.lastPingAt=Date.now(),uR(`ws_ping_sent`,this.wsSnap())),e.type===`terminal-ack`&&this.recordOverloadRecovery(),!0}catch(t){return uR(`ws_send_error`,{messageType:e.type,error:t instanceof Error?t.message:String(t),...this.wsSnap()},`info`),this.destroySocket(),this.scheduleReconnect(),!1}}subscribe(e){return this.listeners.add(e),()=>this.listeners.delete(e)}subscribeStatus(e){return this.statusListeners.add(e),e(this.status,this.error,this.connectionEpoch),()=>this.statusListeners.delete(e)}getStatus(){return this.status}getConnectionEpoch(){return this.connectionEpoch}suspendConnection(){this.attachedSessionId&&this.send({type:`terminal-detach`,sessionId:this.attachedSessionId,attachId:this.attachId}),this.stopHeartbeat(),this.cancelVerify(),this.clearConnectTimer(),this.reconnectTimer!==null&&window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.manualClose||this.setStatus(`reconnecting`)}resumeConnection(e){if(this.manualClose||this.isHidden())return;let t=Date.now()-this.lastTick;this.lastTick=Date.now(),uR(`ws_resume`,{trigger:e,gapMs:t,...this.wsSnap()},`info`),!this.waitForOverloadCooldown()&&this.verifyTimer===null&&(Date.now()-this.lastResumeAt<200&&this.reconnectTimer!==null||this.ws?.readyState===WebSocket.CONNECTING&&this.connectTimer!==null&&t<A5||(this.lastResumeAt=Date.now(),this.reconnectTimer!==null&&window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.ws?.readyState===WebSocket.OPEN?this.verifyConnection():this.forceReconnect(e,!0)))}verifyConnection(){this.cancelVerify(),this.stopHeartbeat(),this.setStatus(`reconnecting`),this.pingSeq+=1;let e=this.pingSeq,t=this.ws;if(uR(`ws_verify`,{seq:e,...this.wsSnap()},`info`),!this.send({type:`ping`,seq:e})){uR(`ws_verify_send_fail`,this.wsSnap(),`info`),this.forceReconnect(`verify_send_fail`,!0);return}this.verifyTimer=window.setTimeout(()=>{this.verifyTimer=null,this.ws===t&&(uR(`ws_verify_timeout`,this.wsSnap(),`info`),this.forceReconnect(`verify_timeout`,!0))},F5)}cancelVerify(){this.verifyTimer!==null&&(window.clearTimeout(this.verifyTimer),this.verifyTimer=null)}forceReconnect(e=`unknown`,t=!1){if(this.protocolMismatch)return;if(this.manualClose){uR(`ws_force_skip`,{trigger:e,reason:`manual_close`});return}if(this.waitForOverloadCooldown())return;let n=Date.now(),r=t?200:500;if(n-this.lastForceReconnectTs<r){uR(`ws_force_skip`,{trigger:e,reason:`debounce`,force:t});return}if(!t&&this.ws?.readyState===WebSocket.OPEN&&this.status===`connected`){uR(`ws_force_skip`,{trigger:e,reason:`already_connected`});return}this.lastForceReconnectTs=n,uR(`ws_force_reconnect`,{trigger:e,force:t,...this.wsSnap()},`info`),this.reconnectAttempts=0,this.consecutiveFailures=0,this.stallCount=0,this.reconnectTimer&&=(window.clearTimeout(this.reconnectTimer),null),this.destroySocket(),t?(this.purgeLeakedSockets(),this.isResumeAttempt=!0,this.setStatus(`reconnecting`),this.reconnectTimer=window.setTimeout(()=>{this.reconnectTimer=null,this.connect()},L5)):this.connect()}startHeartbeat(e){if(this.stopHeartbeat(),this.isHidden())return;let t=()=>{this.isHidden()||this.ws?.readyState===WebSocket.OPEN&&(this.pingSeq+=1,this.send({type:`ping`,seq:this.pingSeq})&&(this.clearPongTimer(),this.pongTimer=window.setTimeout(()=>{this.pongTimer=null,uR(`ws_pong_timeout`,this.wsSnap(),`info`),this.destroySocket(),this.scheduleReconnect()},P5)))};e!==void 0&&e<M5?this.heartbeatTimer=window.setTimeout(()=>{t(),this.heartbeatTimer=window.setInterval(t,M5)},e):this.heartbeatTimer=window.setInterval(t,M5)}stopHeartbeat(){this.heartbeatTimer!==null&&(window.clearTimeout(this.heartbeatTimer),this.heartbeatTimer=null),this.clearPongTimer()}clearPongTimer(){this.pongTimer!==null&&(window.clearTimeout(this.pongTimer),this.pongTimer=null)}setStatus(e,t=null){this.protocolMismatch&&(e=`disconnected`,t=T5),e!==`connected`&&(this.readyAttachId=null,this.overloadProgressSince=null),this.status=e,this.error=t,this.statusListeners.forEach(n=>n(e,t,this.connectionEpoch))}recordOverloadRecovery(){if(this.overloadFailures===0||this.status!==`connected`||this.isHidden()||this.readyAttachId!==this.attachId)return;let e=Date.now();e-this.lastTick>A5&&(this.overloadProgressSince=null),this.overloadProgressSince??=e,e-this.overloadProgressSince>=N5&&(this.overloadFailures=0,this.overloadRetryAt=0,this.overloadProgressSince=null)}waitForOverloadCooldown(){let e=this.overloadRetryAt-Date.now();return e<=0?!1:(this.reconnectTimer!==null&&window.clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.setStatus(`reconnecting`),this.isHidden()||(this.reconnectTimer=window.setTimeout(()=>{this.reconnectTimer=null,this.connect()},e)),!0)}scheduleReconnect(){if(this.protocolMismatch)return;if(this.stopHeartbeat(),this.isHidden()){uR(`ws_schedule_skip`,{reason:`hidden`,...this.wsSnap()}),this.setStatus(`reconnecting`);return}if(this.waitForOverloadCooldown())return;if(this.consecutiveFailures>=R5){uR(`ws_stall_detected`,this.wsSnap(),`info`),this.purgeLeakedSockets();let e=Math.min(z5*2**this.stallCount,3e4);this.stallCount+=1,this.consecutiveFailures=0,this.reconnectAttempts=0,this.isResumeAttempt=!0,this.setStatus(`reconnecting`),this.reconnectTimer=window.setTimeout(()=>{this.reconnectTimer=null,this.connect()},e);return}this.reconnectAttempts+=1;let e=Math.min(1e3*2**(this.reconnectAttempts-1),3e4);uR(`ws_schedule_reconnect`,{delay:e,...this.wsSnap()}),this.setStatus(`reconnecting`),this.reconnectTimer&&window.clearTimeout(this.reconnectTimer),this.reconnectTimer=window.setTimeout(()=>{this.reconnectTimer=null,this.connect()},e)}isHidden(){return this.pageSuspended||typeof document<`u`&&document.visibilityState===`hidden`}clearConnectTimer(){this.connectTimer&&=(window.clearTimeout(this.connectTimer),null)}destroySocket(){if(this.clearConnectTimer(),this.stopHeartbeat(),this.cancelVerify(),!this.ws)return;let e=this.ws;this.ws=null,this.leakedSockets.add(e),e.onopen=null,e.onmessage=null,e.onerror=null,e.onclose=()=>{this.leakedSockets.delete(e),e.onclose=null};try{e.close()}catch{}e.readyState===WebSocket.CLOSED&&(this.leakedSockets.delete(e),e.onclose=null)}purgeLeakedSockets(){if(this.leakedSockets.size!==0){uR(`ws_purge_leaked`,{count:this.leakedSockets.size},`info`);for(let e of this.leakedSockets)try{e.onopen=null,e.onmessage=null,e.onerror=null,e.onclose=null,e.close()}catch{}this.leakedSockets.clear()}}};function V5(){let e=Qh(e=>e.setConnectionState);return(0,y.useEffect)(()=>{B5.connect(),B5.startLifecycleListeners();let t=B5.subscribeStatus((t,n,r)=>{e(t,n,r)});return()=>{t(),B5.stopLifecycleListeners()}},[e]),{sendMessage:(0,y.useMemo)(()=>e=>B5.send(e),[]),subscribe:(0,y.useMemo)(()=>B5.subscribe.bind(B5),[]),getConnectionEpoch:(0,y.useMemo)(()=>()=>B5.getConnectionEpoch(),[])}}var H5=100;function U5({viewport:e,win:t,doc:n}){if(!e)return!1;let r=Math.max(0,e.offsetTop||0),i=Math.max(0,e.offsetLeft||0),a=(n.documentElement.clientHeight||t.innerHeight)-e.height*(e.scale||1),o=Math.max(0,a),s=Math.max(0,e.height||0),c=Math.max(0,e.width||0);return n.documentElement.style.setProperty(`--keyboard-inset`,`${o}px`),n.documentElement.style.setProperty(`--viewport-offset-top`,`${r}px`),n.documentElement.style.setProperty(`--viewport-offset-left`,`${i}px`),n.documentElement.style.setProperty(`--visual-viewport-height`,`${s}px`),n.documentElement.style.setProperty(`--visual-viewport-width`,`${c}px`),o>H5?n.documentElement.classList.add(`keyboard-visible`):n.documentElement.classList.remove(`keyboard-visible`),!0}function W5(e){e.documentElement.style.removeProperty(`--keyboard-inset`),e.documentElement.style.removeProperty(`--viewport-offset-top`),e.documentElement.style.removeProperty(`--viewport-offset-left`),e.documentElement.style.removeProperty(`--visual-viewport-height`),e.documentElement.style.removeProperty(`--visual-viewport-width`),e.documentElement.classList.remove(`keyboard-visible`)}function G5(){(0,y.useEffect)(()=>{let e=window.visualViewport;if(!e)return;let t=null,n=null,r=()=>{let e=document.activeElement;if(!e)return!1;let t=e.tagName?.toLowerCase();return t===`input`||t===`textarea`?!0:!!e.isContentEditable},i=()=>{U5({viewport:e,win:window,doc:document})},a=()=>{if(typeof window.requestAnimationFrame!=`function`){i();return}t!==null&&window.cancelAnimationFrame(t);let e=performance.now(),n=()=>{i(),t=performance.now()-e<1500?window.requestAnimationFrame(n):null};t=window.requestAnimationFrame(n)},o=()=>{if(!r()){c();return}i()},s=()=>{n!==null||typeof window.setInterval!=`function`||(n=window.setInterval(o,250),o())},c=()=>{n===null||typeof window.clearInterval!=`function`||(window.clearInterval(n),n=null)},l=()=>{r()?(a(),s(),i()):c()},u=()=>{l()},d=()=>{l()},f=()=>{a()};return i(),l(),e.addEventListener(`resize`,i),e.addEventListener(`scroll`,i),typeof window.addEventListener==`function`&&(window.addEventListener(`resize`,i),window.addEventListener(`orientationchange`,f)),typeof document.addEventListener==`function`&&(document.addEventListener(`focusin`,u),document.addEventListener(`focusout`,d),document.addEventListener(`focus`,u,!0),document.addEventListener(`blur`,d,!0)),()=>{e.removeEventListener(`resize`,i),e.removeEventListener(`scroll`,i),typeof window.removeEventListener==`function`&&(window.removeEventListener(`resize`,i),window.removeEventListener(`orientationchange`,f)),typeof document.removeEventListener==`function`&&(document.removeEventListener(`focusin`,u),document.removeEventListener(`focusout`,d),document.removeEventListener(`focus`,u,!0),document.removeEventListener(`blur`,d,!0)),t!==null&&typeof window.cancelAnimationFrame==`function`&&window.cancelAnimationFrame(t),c(),W5(document)}},[])}var K5=[`theme`,`commandPresets`,`defaultPresetId`,`defaultProjectDir`,`lastProjectPath`,`recentPaths`,`sessionSortMode`,`sessionSortDirection`,`manualSessionOrder`,`sidebarAnchor`,`projectFilters`,`hostFilters`,`showProjectName`,`showLastUserMessage`,`showSessionIdPrefix`,`soundOnPermission`,`soundOnIdle`],q5=[`claude`,`claude-rp`,`codex`,`pi`,`devin`,`grok`,`omp`];function J5(e){return typeof e==`boolean`}function Y5(e,t){return Array.isArray(e)&&e.length<=t&&e.every(e=>typeof e==`string`)}function X5(e){if(typeof e!=`object`||!e)return!1;let t=e;return typeof t.id==`string`&&t.id.length>=1&&t.id.length<=128&&typeof t.label==`string`&&t.label.trim().length>=1&&t.label.length<=64&&typeof t.command==`string`&&t.command.trim().length>=1&&t.command.length<=1024&&typeof t.isBuiltIn==`boolean`&&(t.agentType===void 0||q5.includes(t.agentType))}var Z5={theme:e=>e===`dark`||e===`light`||e===`system`,commandPresets:e=>Array.isArray(e)&&e.length<=50&&e.every(X5),defaultPresetId:e=>typeof e==`string`&&e.length<=128,defaultProjectDir:e=>typeof e==`string`&&e.length<=4096,lastProjectPath:e=>e===null||typeof e==`string`&&e.length<=4096,recentPaths:e=>Y5(e,50),sessionSortMode:e=>e===`status`||e===`created`||e===`manual`,sessionSortDirection:e=>e===`asc`||e===`desc`,manualSessionOrder:e=>Y5(e,1e3),sidebarAnchor:e=>e===`top`||e===`bottom`,projectFilters:e=>Y5(e,500),hostFilters:e=>Y5(e,500),showProjectName:J5,showLastUserMessage:J5,showSessionIdPrefix:J5,soundOnPermission:J5,soundOnIdle:J5};function Q5(e){return K5.includes(e)}function $5(e,t){return Z5[e](t)}var e7=`agentboard-theme`,t7=`agentboard-settings`,n7=200,r7=new Map,i7=new Map,a7=new Set;function o7(e){return i7.has(e)||a7.has(e)}var s7=null,c7=!1;function l7(e){return e===`theme`?m0.getState().theme:G.getState()[e]}function u7(e){let t=e===`theme`?e7:t7;return w.getItem(t)!==null}function d7(){if(s7=null,i7.size===0)return;let e={},t=new Map,n=new Map;for(let[r,i]of i7)e[r]=JSON.parse(i),t.set(r,i),n.set(r,r7.get(r)),r7.set(r,i),a7.add(r);i7.clear();let r=()=>{for(let[e,r]of t){if(r7.get(e)!==r)continue;let t=n.get(e);t===void 0?r7.delete(e):r7.set(e,t)}},i=e=>{for(let n of t.keys()){if(a7.delete(n),!e||i7.has(n))continue;let t=r7.get(n);t!==void 0&&t!==JSON.stringify(l7(n))&&f7(n,JSON.parse(t))}},a=!1;try{fetch(`/api/settings/synced`,{method:`PUT`,headers:{"content-type":`application/json`},body:JSON.stringify({settings:e})}).then(e=>{a=e.ok,e.ok||(uR(`synced_settings_push_rejected`,{status:e.status},`warn`),r())}).catch(e=>{uR(`synced_settings_push_failed`,{message:e instanceof Error?e.message:String(e)},`warn`),r()}).finally(()=>i(a))}catch(e){r(),i(!1),uR(`synced_settings_push_failed`,{message:e instanceof Error?e.message:String(e)},`warn`)}}function f7(e,t){e===`theme`?m0.setState({theme:t}):G.setState({[e]:t})}function p7(e,t){if(r7.get(e)===JSON.stringify(t)){i7.delete(e);return}m7(e,t)}function m7(e,t){i7.set(e,JSON.stringify(t)),!s7&&(s7=setTimeout(d7,n7))}function h7(e){let t=new Map;for(let e of K5)t.set(e,u7(e));let n={},r;for(let[t,i]of Object.entries(e))!Q5(t)||!$5(t,i)||(r7.set(t,JSON.stringify(i)),!o7(t)&&(t===`theme`?r=i:n[t]=i));r!==void 0&&m0.setState({theme:r}),Object.keys(n).length>0&&G.setState(n);for(let n of K5){if(n in e||!t.get(n))continue;let r=l7(n);$5(n,r)&&r7.get(n)!==JSON.stringify(r)&&m7(n,r)}}function g7(){if(c7)return()=>{};c7=!0;let e=G.subscribe((e,t)=>{let n=e,r=t;for(let e of K5)e!==`theme`&&n[e]!==r[e]&&p7(e,n[e])}),t=m0.subscribe((e,t)=>{e.theme!==t.theme&&p7(`theme`,e.theme)});return()=>{e(),t(),c7=!1,s7&&=(clearTimeout(s7),null),i7.clear(),a7.clear(),r7.clear()}}function _7(e,t,n){let r=e;return t.length>0&&(r=r.filter(e=>t.includes(e.projectPath))),n.length>0&&(r=r.filter(e=>n.includes(e.host??``))),r}function v7(){let[e,t]=(0,y.useState)(!1),[n,r]=(0,y.useState)(void 0),[i,a]=(0,y.useState)(void 0),[o,s]=(0,y.useState)(void 0),[c,l]=(0,y.useState)(!1),[u,d]=(0,y.useState)(!1),[f,p]=(0,y.useState)(null),[m,h]=(0,y.useState)(null),[g,_]=(0,y.useState)(null),v=Qh(e=>e.sessions),b=Qh(e=>e.agentSessions),S=Qh(e=>e.agentSessionsEpoch),C=Qh(e=>e.selectedSessionId),w=Qh(e=>e.selectedHibernatingSessionId),T=Qh(e=>e.setSessions),E=Qh(e=>e.setAgentSessions),D=Qh(e=>e.setActiveAgentSessions),O=Qh(e=>e.setHostStatuses),A=Qh(e=>e.updateSession),j=Qh(e=>e.setSelectedSessionId),M=Qh(e=>e.setSelectedHibernatingSessionId),P=Qh(e=>e.hasLoaded),I=Qh(e=>e.connectionStatus),L=Qh(e=>e.connectionError),R=Qh(e=>e.clearExitingSession),z=Qh(e=>e.markSessionExiting),B=Qh(e=>e.setRemoteAllowControl),V=Qh(e=>e.setRemoteAllowAttach),ee=Qh(e=>e.setHostLabel),H=Qh(e=>e.setPreferWindowName),te=Qh(e=>e.hostStatuses),U=Qh(e=>e.remoteAllowControl),ne=Qh(e=>e.hostLabel),W=h0(),re=Ht(),ie=G(e=>e.defaultProjectDir),ae=G(e=>e.commandPresets),oe=G(e=>e.defaultPresetId),se=G(e=>e.lastProjectPath),ce=G(e=>e.setLastProjectPath),le=G(e=>e.addRecentPath),ue=G(e=>e.shortcutModifier),de=G(e=>e.sidebarWidth),fe=G(e=>e.sidebarAnchor),pe=G(e=>e.setSidebarWidth),me=G(e=>e.projectFilters),he=G(e=>e.hostFilters),ge=G(e=>e.soundOnPermission),_e=G(e=>e.soundOnIdle),ve=Qh(e=>e.connectionEpoch),{sendMessage:ye,subscribe:be,getConnectionEpoch:xe}=V5();(0,y.useEffect)(()=>g7(),[]),G5(),(0,y.useEffect)(()=>{if(typeof document>`u`||!ge&&!_e)return;let e=!1,t=()=>{e&&!Z6()||(e=!0,$6())};return document.addEventListener(`click`,t,{passive:!0}),document.addEventListener(`keydown`,t,{passive:!0}),document.addEventListener(`touchstart`,t,{passive:!0}),()=>{document.removeEventListener(`click`,t),document.removeEventListener(`keydown`,t),document.removeEventListener(`touchstart`,t)}},[ge,_e]);let Se=(0,y.useRef)(!1),Ce=(0,y.useCallback)(e=>{e.preventDefault(),Se.current=!0,document.body.style.cursor=`col-resize`,document.body.style.userSelect=`none`},[]);(0,y.useEffect)(()=>{if(typeof document>`u`||typeof document.addEventListener!=`function`)return;let e=e=>{if(!Se.current)return;let t=e.clientX;pe(Math.max(180,Math.min(400,t)))},t=()=>{Se.current&&(Se.current=!1,document.body.style.cursor=``,document.body.style.userSelect=``)};return document.addEventListener(`mousemove`,e),document.addEventListener(`mouseup`,t),()=>{document.removeEventListener(`mousemove`,e),document.removeEventListener(`mouseup`,t)}},[pe]),(0,y.useEffect)(()=>{let e=be(e=>{if(e.type!==`terminal-output`){if(e.type===`sessions`){let t=Qh.getState().sessions,{soundOnPermission:n,soundOnIdle:r}=G.getState();if(n||r)for(let i of e.sessions){let e=t.find(e=>e.id===i.id);e&&e.status!==i.status&&(e.status!==`permission`&&i.status===`permission`&&n&&n8(),e.status===`working`&&i.status===`waiting`&&r&&r8())}if(ze.current.size>0){let e=xe();for(let[t,n]of ze.current)n.epoch!==e&&ze.current.delete(t)}let i=ze.current.size>0?e.sessions.filter(e=>!ze.current.has(e.id)):e.sessions,{selectedSessionId:a,selectedHibernatingSessionId:o}=Qh.getState(),s=a!==null&&o===null&&!i.some(e=>e.id===a)?t.find(e=>e.id===a)?.agentSessionId?.trim()??null:null;s&&(Fe.current=s),T(i);let c=Ie.current,{selectedSessionId:l,selectedHibernatingSessionId:u}=Qh.getState(),{projectFilters:d,hostFilters:f}=G.getState();if(c&&l===null&&u===null){let e=i.find(e=>!(e.agentSessionId?.trim()!==c||d.length>0&&!d.includes(e.projectPath)||f.length>0&&!f.includes(e.host??``)));e&&(Ie.current=null,j(e.id))}}if(e.type===`host-status`&&O(e.hosts),e.type===`server-config`&&(B(e.remoteAllowControl),V(e.remoteAllowAttach),ee(e.hostLabel),H(e.preferWindowName),e.clientLogLevel&&lR(e.clientLogLevel)),e.type===`synced-settings`&&h7(e.settings),e.type===`session-update`){let t=Qh.getState().sessions.find(t=>t.id===e.session.id)?.status,n=e.session.status;if(A(e.session),t){let{soundOnPermission:e,soundOnIdle:r}=G.getState();t!==`permission`&&n===`permission`&&e&&n8(),t===`working`&&n===`waiting`&&r&&r8()}}if(e.type===`session-created`){let t=Qh.getState().sessions;t.some(t=>t.id===e.session.id)||T([e.session,...t]),j(e.session.id),le(e.session.projectPath);let{projectFilters:n,setProjectFilters:r}=G.getState();n.length>0&&!n.includes(e.session.projectPath)&&r([...n,e.session.projectPath])}if(e.type===`session-removed`){M1(e.sessionId);let t=Qh.getState().sessions,n=t.filter(t=>t.id!==e.sessionId);n.length!==t.length&&T(n)}if(e.type===`agent-sessions`){let t=Array.isArray(e.active)?e.active:[],n=Array.isArray(e.hibernating)?e.hibernating:[],r=Array.isArray(e.history)?e.history:[],{selectedHibernatingSessionId:i}=Qh.getState(),a=Fe.current;i&&!n.some(e=>e.sessionId===i)&&(Ie.current=i),E(t,n,r),_(e=>e&&n.some(t=>t.sessionId===e.sessionId)?null:e),a&&n.some(e=>e.sessionId===a)?(Fe.current=null,M(a)):a&&(Fe.current=null)}if(e.type===`agent-sessions-active`&&D(Array.isArray(e.active)?e.active:[]),e.type===`session-orphaned`&&!e.supersededBy){let t=Qh.getState().sessions,n=t.filter(t=>t.agentSessionId?.trim()!==e.session.sessionId);n.length!==t.length&&T(n)}if(e.type===`session-activated`){let t=Qh.getState().sessions.find(t=>t.tmuxWindow===e.window);t&&A({...t,agentSessionId:e.session.sessionId,agentSessionName:e.session.displayName,mediaSummary:e.session.mediaSummary,media:void 0,logFilePath:e.session.logFilePath,isHibernating:e.session.isHibernating,lastUserMessage:e.session.lastUserMessage??t.lastUserMessage})}if(e.type===`session-wake-result`)if(e.ok&&e.session){_(t=>t?.sessionId===e.sessionId?null:t);let t=Qh.getState().sessions;t.some(t=>t.id===e.session.id)||T([e.session,...t]),j(e.session.id)}else e.ok||(p(`${e.error?.code}: ${e.error?.message}`),window.setTimeout(()=>p(null),6e3));if(e.type===`session-hibernate-result`&&(e.ok?(e.session&&_(e.session),M(e.sessionId)):(p(e.error??`Failed to hibernate session`),window.setTimeout(()=>p(null),6e3))),e.type===`terminal-error`&&(!e.sessionId||e.sessionId===C)&&(p(`${e.code}: ${e.message}`),window.setTimeout(()=>p(null),6e3)),e.type===`terminal-ready`&&e.sessionId===C&&p(null),e.type===`error`&&(p(e.message),window.setTimeout(()=>p(null),6e3)),e.type===`kill-failed`){let t=ze.current.get(e.sessionId);if(t){let n=Qh.getState().sessions;n.some(t=>t.id===e.sessionId)||T([t.session,...n]),t.wasSelected&&j(e.sessionId),ze.current.delete(e.sessionId)}R(e.sessionId),p(e.message),window.setTimeout(()=>p(null),6e3)}e.type===`session-move-to-history-result`&&!e.ok&&e.error&&(p(e.error),window.setTimeout(()=>p(null),6e3))}});return()=>{e()}},[C,w,le,R,ye,j,M,_,T,E,D,O,B,V,ee,H,be,A]);let we=(0,y.useMemo)(()=>v.find(e=>e.id===C)||null,[C,v]),Te=b.hibernating??[],Ee=b.history??[],De=(0,y.useMemo)(()=>_7(Te,me,he),[Te,me,he]),Oe=(0,y.useMemo)(()=>De.find(e=>e.sessionId===w)||(g?.sessionId===w?g:null),[De,g,w]);(0,y.useEffect)(()=>{we?.projectPath&&!we.remote&&ce(we.projectPath)},[we?.projectPath,we?.remote,ce]);let ke=G(e=>e.sessionSortMode),Ae=G(e=>e.sessionSortDirection),je=G(e=>e.manualSessionOrder),Me=(0,y.useMemo)(()=>Fh(v,{mode:ke,direction:Ae,manualOrder:je}),[v,ke,Ae,je]),Ne=(0,y.useMemo)(()=>{let e=Me;return me.length>0&&(e=e.filter(e=>me.includes(e.projectPath))),he.length>0&&(e=e.filter(e=>he.includes(e.host??``))),e},[Me,me,he]),Pe=(0,y.useRef)(w),Fe=(0,y.useRef)(null),Ie=(0,y.useRef)(null),Le=(0,y.useRef)(ve),Re=(0,y.useCallback)(()=>Ne.length>0?(j(Ne[0].id),!0):De.length>0?(M(De[0].sessionId),!0):!1,[Ne,De,j,M]);(0,y.useEffect)(()=>{let e=Pe.current;e&&w===null&&!Te.some(t=>t.sessionId===e)?Ie.current=e:w!==null&&(Ie.current=null),Pe.current=w},[Te,w]),(0,y.useEffect)(()=>{g&&w!==g.sessionId&&_(null)},[g,w]),(0,y.useEffect)(()=>{Le.current!==ve&&(Le.current=ve,Fe.current=null,Ie.current=null,_(null))},[ve]),(0,y.useEffect)(()=>{P&&(w||C&&(Ne.some(e=>e.id===C)||Re()||j(null)))},[P,C,w,Re,j]),(0,y.useEffect)(()=>{if(!w||g?.sessionId===w||S!==ve||De.some(e=>e.sessionId===w))return;let e=Ne.find(e=>e.agentSessionId?.trim()===w);if(e){j(e.id);return}Re()||M(null)},[De,Ne,S,g,w,Re,j,M,ve]),(0,y.useEffect)(()=>{let e=Ie.current;if(!e)return;if(w!==null){Ie.current=null;return}let t=Ne.find(t=>t.agentSessionId?.trim()===e);if(t){Ie.current=null,j(t.id);return}if(C!==null){Ie.current=null;return}Re()&&(Ie.current=null)},[Ne,C,w,Re,j]),(0,y.useEffect)(()=>{window.matchMedia(`(max-width: 767px)`).matches&&P&&C===null&&w===null&&(Ne.length>0||De.length>0)&&Re()},[De.length,Ne.length,P,Re,C,w]);let ze=(0,y.useRef)(new Map),Be=(0,y.useCallback)((e,t=`unknown`)=>{M1(e);let{sessions:n,selectedSessionId:r}=Qh.getState(),i=n.find(t=>t.id===e);i&&ze.current.set(e,{session:i,wasSelected:r===e,epoch:xe()}),(0,_f.flushSync)(()=>{z(e),T(n.filter(t=>t.id!==e))}),ye({type:`session-kill`,sessionId:e,source:t})},[z,T,ye]);(0,y.useEffect)(()=>{let n=Dt(ue),r=r=>{if(r.defaultPrevented)return;let i=r.code,a=At(r,n);if(a&&(i===`BracketLeft`||i===`BracketRight`)){r.preventDefault();let e=fe===`bottom`&&!window.matchMedia(`(max-width: 767px)`).matches,t=(i===`BracketLeft`?-1:1)*(e?-1:1),n=Ne;if(n.length===0){let e=De;if(e.length===0)return;let n=e.findIndex(e=>e.sessionId===w);if(n===-1){M(e[0].sessionId);return}M(e[(n+t+e.length)%e.length].sessionId);return}let a=n.findIndex(e=>e.id===C);if(a===-1){j(n[0].id);return}j(n[(a+t+n.length)%n.length].id);return}if(a&&/^Digit[1-9]$/.test(i)){let e=Number(i.slice(5))-1;if(Ne.length>0){let t=Ne[e];if(!t)return;r.preventDefault(),j(t.id);return}let t=De[e];if(!t)return;r.preventDefault(),M(t.sessionId);return}if(a&&i===`KeyN`){r.preventDefault(),!e&&!c&&re&&t(!0);return}if(a&&i===`Comma`){r.preventDefault(),l(t=>t?!1:!e);return}if(a&&i===`KeyX`){r.preventDefault(),C&&!e&&!c&&Be(C,`keyboard_shortcut`);return}};return window.addEventListener(`keydown`,r),()=>window.removeEventListener(`keydown`,r)},[e,c,C,w,j,M,Ne,De,Be,fe,ue,re]);let Ve=()=>re?(r(void 0),a(void 0),s(void 0),t(!0),!0):!1,He=()=>l(!0),Ue=(e,t,n,r)=>{ye({type:`session-create`,operationId:x(),projectPath:e,name:t,command:n,host:r}),r||ce(e)},We=e=>{ye({type:`session-wake`,sessionId:e})},Ge=(0,y.useCallback)(e=>{ye({type:`session-hibernate`,sessionId:e})},[ye]),Ke=(e,t)=>{ye({type:`session-rename`,sessionId:e,newName:t})},qe=(0,y.useCallback)(e=>{let t=v.find(t=>t.id===e);t&&ye({type:`session-create`,operationId:x(),projectPath:t.projectPath,command:t.command||void 0,host:t.remote&&t.host?t.host:void 0})},[v,ye]),Je=(0,y.useCallback)(e=>{ye({type:`session-move-to-history`,sessionId:e})},[ye]);(0,y.useEffect)(()=>g0(),[]),(0,y.useEffect)(()=>{document.documentElement.setAttribute(`data-theme`,W)},[W]),(0,y.useEffect)(()=>{fetch(`/api/server-info`).then(e=>e.json()).then(e=>h(e)).catch(()=>{})},[]);let Ye=(0,y.useMemo)(()=>ne?te.filter(e=>e.host!==ne):te,[te,ne]);return(0,k.jsxs)(`div`,{className:`flex h-full overflow-clip`,children:[(0,k.jsx)(`div`,{className:`hidden h-full flex-col md:flex md:shrink-0`,style:{width:de},children:(0,k.jsx)(iR,{sessions:v,hibernatingSessions:Te,historySessions:Ee,selectedSessionId:C,selectedHibernatingSessionId:w,onSelect:j,onSelectHibernating:M,onRename:Ke,onResume:We,onHibernate:Ge,onKill:Be,onDuplicate:qe,onMoveToHistory:Je,onNewSession:Ve,loading:!P,error:L||f,anchor:fe,showAnchorControl:!0,notice:(0,k.jsx)(N,{onOpen:()=>d(!0),subscribe:be}),filterBarControls:(0,k.jsx)(tn,{connectionStatus:I,onNewSession:Ve,onOpenSettings:He,onOpenHistory:()=>d(!0),tailscaleIp:m?.tailscaleIp??null,placement:fe===`bottom`?`up`:`down`})})}),(0,k.jsx)(`div`,{className:`hidden md:block w-1 shrink-0 cursor-col-resize bg-transparent transition-colors hover:bg-white/10 active:bg-white/20`,onMouseDown:Ce}),(0,k.jsx)(x3,{session:we,sessions:Ne,drawerSessions:v,hibernatingSession:Oe,hibernatingSessions:Te,connectionStatus:I,connectionEpoch:ve,sendMessage:ye,subscribe:be,onClose:()=>j(null),onSelectSession:j,onSelectHibernatingSession:M,onNewSession:Ve,onKillSession:Be,onRenameSession:Ke,onDuplicateSession:qe,onOpenSettings:He,onOpenHistory:()=>d(!0),onResumeSession:We,onHibernateSession:Ge,onMoveToHistory:Je,historySessions:Ee,loading:!P,error:L||f}),(0,k.jsx)(B3,{isOpen:e,onClose:()=>t(!1),onCreate:Ue,defaultProjectDir:ie,commandPresets:ae,defaultPresetId:oe,lastProjectPath:se,activeProjectPath:we&&!we.remote?we.projectPath:void 0,remoteHosts:Ye,remoteAllowControl:U,initialHost:n,initialPath:i,initialCommand:o}),(0,k.jsx)(U8,{isOpen:c,onClose:()=>l(!1)}),(0,k.jsx)(F,{open:u,subscribe:be,onClose:()=>d(!1),onOpenSession:e=>{T([e,...v.filter(t=>t.id!==e.id)]),M(null),j(e.id)}}),(0,k.jsx)(w5,{})]})}var y7=`modulepreload`,b7=function(e){return`/`+e},x7={},S7=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}r=o(t.map(t=>{if(t=b7(t,n),t in x7)return;x7[t]=!0;let r=t.endsWith(`.css`),i=r?`[rel="stylesheet"]`:``;if(n)for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}else if(document.querySelector(`link[href="${t}"]${i}`))return;let o=document.createElement(`link`);if(o.rel=r?`stylesheet`:y7,r||(o.as=`script`),o.crossOrigin=``,o.href=t,a&&o.setAttribute(`nonce`,a),document.head.appendChild(o),r)return new Promise((e,n)=>{o.addEventListener(`load`,e),o.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},C7=`true`,w7=`false`,T7=C7===`true`,E7=w7===`true`;function D7(e={}){let{immediate:t=!1,onNeedRefresh:n,onOfflineReady:r,onRegistered:i,onRegisteredSW:a,onRegisterError:o}=e,s,c,l,u=async(e=!0)=>{await c,T7||l?.()};async function d(){if(`serviceWorker`in navigator){if(s=await S7(async()=>{let{Workbox:e}=await import(`./workbox-window.prod.es5-Bq4GJJid.js`);return{Workbox:e}},[]).then(({Workbox:e})=>new e(`/sw.js`,{scope:`/`,type:`classic`})).catch(e=>{o?.(e)}),!s)return;if(l=()=>{s?.messageSkipWaiting()},!E7)if(T7)s.addEventListener(`activated`,e=>{(e.isUpdate||e.isExternal)&&window.location.reload()}),s.addEventListener(`installed`,e=>{e.isUpdate||r?.()});else{let e=!1,t=()=>{e=!0,s?.addEventListener(`controlling`,e=>{e.isUpdate&&window.location.reload()}),n?.()};s.addEventListener(`installed`,n=>{n.isUpdate===void 0?n.isExternal===void 0?!e&&r?.():n.isExternal?t():!e&&r?.():n.isUpdate||r?.()}),s.addEventListener(`waiting`,t)}s.register({immediate:t}).then(e=>{a?a(`/sw.js`,e):i?.(e)}).catch(e=>{o?.(e)})}}return c=d(),u}Ct()&&document.documentElement.classList.add(`ios`),Tt()&&document.documentElement.classList.add(`ios-pwa`),D7({immediate:!0,onRegisteredSW(e,t){t&&(setInterval(()=>{t.update()},300*1e3),document.addEventListener(`visibilitychange`,()=>{document.visibilityState===`visible`&&t.update()}))}});var O7=document.getElementById(`root`);if(!O7)throw Error(`Root element not found`);(0,b.createRoot)(O7).render((0,k.jsx)(y.StrictMode,{children:(0,k.jsx)(v7,{})}));
|
package/dist/client/index.html
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<title>Agentboard</title>
|
|
9
9
|
<link rel="apple-touch-icon" href="/icons/pwa-192x192.png" />
|
|
10
10
|
<meta name="theme-color" content="#0f172a" />
|
|
11
|
-
<script type="module" crossorigin src="/assets/index-
|
|
11
|
+
<script type="module" crossorigin src="/assets/index-BJIGQ9hS.js"></script>
|
|
12
12
|
<link rel="stylesheet" crossorigin href="/assets/index-DlwBtD0X.css">
|
|
13
13
|
<link rel="manifest" href="/manifest.webmanifest"></head>
|
|
14
14
|
<body>
|
package/dist/client/sw.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
if(!self.define){let e,n={};const i=(i,o)=>(i=new URL(i+".js",o).href,n[i]||new Promise(n=>{if("document"in self){const e=document.createElement("script");e.src=i,e.onload=n,document.head.appendChild(e)}else e=i,importScripts(i),n()}).then(()=>{let e=n[i];if(!e)throw new Error(`Module ${i} didn’t register its module`);return e}));self.define=(o,s)=>{const r=e||("document"in self?document.currentScript.src:"")||location.href;if(n[r])return;let
|
|
1
|
+
if(!self.define){let e,n={};const i=(i,o)=>(i=new URL(i+".js",o).href,n[i]||new Promise(n=>{if("document"in self){const e=document.createElement("script");e.src=i,e.onload=n,document.head.appendChild(e)}else e=i,importScripts(i),n()}).then(()=>{let e=n[i];if(!e)throw new Error(`Module ${i} didn’t register its module`);return e}));self.define=(o,s)=>{const r=e||("document"in self?document.currentScript.src:"")||location.href;if(n[r])return;let t={};const f=e=>i(e,r),d={module:{uri:r},exports:t,require:f};n[r]=Promise.all(o.map(e=>d[e]||f(e))).then(e=>(s(...e),t))}}define(["./workbox-8c29f6e4"],function(e){"use strict";self.skipWaiting(),e.clientsClaim(),e.precacheAndRoute([{url:"index.html",revision:"038127241b84d01108168b08a30436ce"},{url:"favicon.svg",revision:"12048a608dedfc53518ddc59c07e41b6"},{url:"icons/pwa-512x512.png",revision:"eb82042b3e4ed505f3efe1b79622d998"},{url:"icons/pwa-192x192.png",revision:"affb57c15619ee7223d1adea372ad514"},{url:"fonts/jetbrains-mono-vietnamese-wght-normal.woff2",revision:"ddf99e6e35c6ee9f00a41d2567b0e77f"},{url:"fonts/jetbrains-mono-latin-wght-normal.woff2",revision:"b058178d7f309414f8f856b99fd80d9b"},{url:"fonts/jetbrains-mono-latin-ext-wght-normal.woff2",revision:"e36841ed93d5bfe6b1d487d18ad7e90b"},{url:"fonts/jetbrains-mono-greek-wght-normal.woff2",revision:"51671ed9eb64e29390d4791ab0023c8e"},{url:"fonts/jetbrains-mono-cyrillic-wght-normal.woff2",revision:"615bf869ebeb5998734d81fc8958116c"},{url:"fonts/jetbrains-mono-cyrillic-ext-wght-normal.woff2",revision:"742dd0628e0118d32dccf0437900670b"},{url:"assets/workbox-window.prod.es5-Bq4GJJid.js",revision:null},{url:"assets/index-DlwBtD0X.css",revision:null},{url:"assets/index-BJIGQ9hS.js",revision:null},{url:"icons/pwa-192x192.png",revision:"affb57c15619ee7223d1adea372ad514"},{url:"icons/pwa-512x512.png",revision:"eb82042b3e4ed505f3efe1b79622d998"},{url:"manifest.webmanifest",revision:"b6d4b3666a548fa0f0c6919d31ec2eee"}],{}),e.cleanupOutdatedCaches(),e.registerRoute(new e.NavigationRoute(e.createHandlerBoundToURL("/index.html"),{denylist:[/^\/api(?:\/|$)/,/^\/ws(?:\/|$)/]}))});
|